From aba89f3595d9c40634ad65fd96103a328a1eea2a Mon Sep 17 00:00:00 2001 From: Sean Hefty Date: Mon, 2 Mar 2020 06:26:33 -0800 Subject: [PATCH 1/6] prov/util: Store interface and network names for IP addresses When obtaining a list of IP addresses available in the system, also record which interface is associated with the name, along with the network address. This data will be needed to fix a regression in the socket provider's fabric and domain names. But can also be used to set the fabric and domain names for the tcp and udp providers. Signed-off-by: Sean Hefty --- include/ofi_net.h | 16 ++++-- src/common.c | 134 +++++++++++++++++++++++++++++----------------- 2 files changed, 96 insertions(+), 54 deletions(-) diff --git a/include/ofi_net.h b/include/ofi_net.h index 59ff11d82db..4d52030fac8 100644 --- a/include/ofi_net.h +++ b/include/ofi_net.h @@ -125,6 +125,8 @@ int ofi_discard_socket(SOCKET sock, size_t len); #define AF_IB 27 #endif +#define OFI_ADDRSTRLEN (INET6_ADDRSTRLEN + 50) + union ofi_sock_ip { struct sockaddr sa; struct sockaddr_in sin; @@ -133,15 +135,20 @@ union ofi_sock_ip { }; struct ofi_addr_list_entry { - char ipstr[INET6_ADDRSTRLEN]; - union ofi_sock_ip ipaddr; - size_t speed; - struct slist_entry entry; + struct slist_entry entry; + char ipstr[INET6_ADDRSTRLEN]; + union ofi_sock_ip ipaddr; + size_t speed; + char net_name[OFI_ADDRSTRLEN]; + char ifa_name[OFI_ADDRSTRLEN]; }; int ofi_addr_cmp(const struct fi_provider *prov, const struct sockaddr *sa1, const struct sockaddr *sa2); int ofi_getifaddrs(struct ifaddrs **ifap); + +void ofi_set_netmask_str(char *netstr, size_t len, struct ifaddrs *ifa); + void ofi_get_list_of_addr(struct fi_provider *prov, const char *env_name, struct slist *addr_list); void ofi_free_list_of_addr(struct slist *addr_list); @@ -153,7 +160,6 @@ void ofi_free_list_of_addr(struct slist *addr_list); #define ofi_sin6_addr(addr) (((struct sockaddr_in6 *)(addr))->sin6_addr) #define ofi_sin6_port(addr) (((struct sockaddr_in6 *)(addr))->sin6_port) -#define OFI_ADDRSTRLEN (INET6_ADDRSTRLEN + 50) static inline size_t ofi_sizeofaddr(const struct sockaddr *addr) { diff --git a/src/common.c b/src/common.c index bc8d3709bcf..34432db093f 100644 --- a/src/common.c +++ b/src/common.c @@ -1097,6 +1097,8 @@ void ofi_insert_loopback_addr(struct fi_provider *prov, struct slist *addr_list) "available addr: ", &addr_entry->ipaddr); strncpy(addr_entry->ipstr, "127.0.0.1", sizeof(addr_entry->ipstr)); + strncpy(addr_entry->net_name, "127.0.0.1/32", sizeof(addr_entry->net_name)); + strncpy(addr_entry->ifa_name, "lo", sizeof(addr_entry->ifa_name)); slist_insert_tail(&addr_entry->entry, addr_list); addr_entry = calloc(1, sizeof(struct ofi_addr_list_entry)); @@ -1109,6 +1111,8 @@ void ofi_insert_loopback_addr(struct fi_provider *prov, struct slist *addr_list) "available addr: ", &addr_entry->ipaddr); strncpy(addr_entry->ipstr, "::1", sizeof(addr_entry->ipstr)); + strncpy(addr_entry->net_name, "::1/128", sizeof(addr_entry->net_name)); + strncpy(addr_entry->ifa_name, "lo", sizeof(addr_entry->ifa_name)); slist_insert_tail(&addr_entry->entry, addr_list); } @@ -1154,6 +1158,32 @@ ofi_addr_list_entry_comp_speed(struct slist_entry *cur, const void *insert) return (cur_addr->speed < insert_addr->speed); } +void ofi_set_netmask_str(char *netstr, size_t len, struct ifaddrs *ifa) +{ + union ofi_sock_ip addr; + size_t prefix_len; + + netstr[0] = '\0'; + prefix_len = ofi_mask_addr(&addr.sa, ifa->ifa_addr, ifa->ifa_netmask); + + switch (addr.sa.sa_family) { + case AF_INET: + inet_ntop(AF_INET, &addr.sin.sin_addr, netstr, len); + break; + case AF_INET6: + inet_ntop(AF_INET6, &addr.sin6.sin6_addr, netstr, len); + break; + default: + snprintf(netstr, len, "%s", ""); + netstr[len - 1] = '\0'; + break; + } + + snprintf(netstr + strlen(netstr), len - strlen(netstr), + "%s%d", "/", (int) prefix_len); + netstr[len - 1] = '\0'; +} + void ofi_get_list_of_addr(struct fi_provider *prov, const char *env_name, struct slist *addr_list) { @@ -1165,63 +1195,69 @@ void ofi_get_list_of_addr(struct fi_provider *prov, const char *env_name, fi_param_get_str(prov, env_name, &iface); ret = ofi_getifaddrs(&ifaddrs); - if (!ret) { - if (iface) { - for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) { - if (strncmp(iface, ifa->ifa_name, - strlen(iface)) == 0) { - break; - } - } - if (ifa == NULL) { - FI_INFO(prov, FI_LOG_CORE, - "Can't set filter to unknown interface: (%s)\n", - iface); - iface = NULL; - } - } - for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) { - if (ifa->ifa_addr == NULL || - !(ifa->ifa_flags & IFF_UP) || - (ifa->ifa_flags & IFF_LOOPBACK) || - ((ifa->ifa_addr->sa_family != AF_INET) && - (ifa->ifa_addr->sa_family != AF_INET6))) - continue; - if (iface && strncmp(iface, ifa->ifa_name, strlen(iface)) != 0) { - FI_DBG(prov, FI_LOG_CORE, - "Skip (%s) interface\n", ifa->ifa_name); - continue; - } + if (ret) + goto insert_lo; - addr_entry = calloc(1, sizeof(struct ofi_addr_list_entry)); - if (!addr_entry) - continue; - - memcpy(&addr_entry->ipaddr, ifa->ifa_addr, - ofi_sizeofaddr(ifa->ifa_addr)); - - if (!inet_ntop(ifa->ifa_addr->sa_family, - ofi_get_ipaddr(ifa->ifa_addr), - addr_entry->ipstr, - sizeof(addr_entry->ipstr))) { - FI_DBG(prov, FI_LOG_CORE, - "inet_ntop failed: %d\n", errno); - free(addr_entry); - continue; + if (iface) { + for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) { + if (strncmp(iface, ifa->ifa_name, + strlen(iface)) == 0) { + break; } + } + if (ifa == NULL) { + FI_INFO(prov, FI_LOG_CORE, + "Can't set filter to unknown interface: (%s)\n", + iface); + iface = NULL; + } + } + for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) { + if (ifa->ifa_addr == NULL || + !(ifa->ifa_flags & IFF_UP) || + (ifa->ifa_flags & IFF_LOOPBACK) || + ((ifa->ifa_addr->sa_family != AF_INET) && + (ifa->ifa_addr->sa_family != AF_INET6))) + continue; + if (iface && strncmp(iface, ifa->ifa_name, strlen(iface)) != 0) { + FI_DBG(prov, FI_LOG_CORE, + "Skip (%s) interface\n", ifa->ifa_name); + continue; + } - addr_entry->speed = ofi_ifaddr_get_speed(ifa); - FI_INFO(prov, FI_LOG_CORE, "Available addr: %s, " - "iface name: %s, speed: %zu\n", - addr_entry->ipstr, ifa->ifa_name, addr_entry->speed); + addr_entry = calloc(1, sizeof(*addr_entry)); + if (!addr_entry) + continue; - slist_insert_before_first_match(addr_list, ofi_addr_list_entry_comp_speed, - &addr_entry->entry); + memcpy(&addr_entry->ipaddr, ifa->ifa_addr, + ofi_sizeofaddr(ifa->ifa_addr)); + strncpy(addr_entry->ifa_name, ifa->ifa_name, + sizeof(addr_entry->ifa_name)); + ofi_set_netmask_str(addr_entry->net_name, + sizeof(addr_entry->net_name), ifa); + + if (!inet_ntop(ifa->ifa_addr->sa_family, + ofi_get_ipaddr(ifa->ifa_addr), + addr_entry->ipstr, + sizeof(addr_entry->ipstr))) { + FI_DBG(prov, FI_LOG_CORE, + "inet_ntop failed: %d\n", errno); + free(addr_entry); + continue; } - freeifaddrs(ifaddrs); + addr_entry->speed = ofi_ifaddr_get_speed(ifa); + FI_INFO(prov, FI_LOG_CORE, "Available addr: %s, " + "iface name: %s, speed: %zu\n", + addr_entry->ipstr, ifa->ifa_name, addr_entry->speed); + + slist_insert_before_first_match(addr_list, ofi_addr_list_entry_comp_speed, + &addr_entry->entry); } + freeifaddrs(ifaddrs); + +insert_lo: /* Always add loopback address at the end */ ofi_insert_loopback_addr(prov, addr_list); } From 7fb47c1d74b668c461548ae24c1fc726543ad8bb Mon Sep 17 00:00:00 2001 From: Sean Hefty Date: Tue, 3 Mar 2020 04:30:49 -0800 Subject: [PATCH 2/6] core: Add const to prov param in ofi_get_list_of_addr() Carry const provider through calls to avoid compile warnings. Signed-off-by: Sean Hefty --- include/ofi_net.h | 2 +- src/common.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/ofi_net.h b/include/ofi_net.h index 4d52030fac8..7a924df2ac5 100644 --- a/include/ofi_net.h +++ b/include/ofi_net.h @@ -149,7 +149,7 @@ int ofi_getifaddrs(struct ifaddrs **ifap); void ofi_set_netmask_str(char *netstr, size_t len, struct ifaddrs *ifa); -void ofi_get_list_of_addr(struct fi_provider *prov, const char *env_name, +void ofi_get_list_of_addr(const struct fi_provider *prov, const char *env_name, struct slist *addr_list); void ofi_free_list_of_addr(struct slist *addr_list); diff --git a/src/common.c b/src/common.c index 34432db093f..29bb0db0290 100644 --- a/src/common.c +++ b/src/common.c @@ -1083,7 +1083,7 @@ void ofi_free_list_of_addr(struct slist *addr_list) } static inline -void ofi_insert_loopback_addr(struct fi_provider *prov, struct slist *addr_list) +void ofi_insert_loopback_addr(const struct fi_provider *prov, struct slist *addr_list) { struct ofi_addr_list_entry *addr_entry; @@ -1184,7 +1184,7 @@ void ofi_set_netmask_str(char *netstr, size_t len, struct ifaddrs *ifa) netstr[len - 1] = '\0'; } -void ofi_get_list_of_addr(struct fi_provider *prov, const char *env_name, +void ofi_get_list_of_addr(const struct fi_provider *prov, const char *env_name, struct slist *addr_list) { int ret; @@ -1192,7 +1192,7 @@ void ofi_get_list_of_addr(struct fi_provider *prov, const char *env_name, struct ofi_addr_list_entry *addr_entry; struct ifaddrs *ifaddrs, *ifa; - fi_param_get_str(prov, env_name, &iface); + fi_param_get_str((struct fi_provider *) prov, env_name, &iface); ret = ofi_getifaddrs(&ifaddrs); if (ret) @@ -1264,7 +1264,7 @@ void ofi_get_list_of_addr(struct fi_provider *prov, const char *env_name, #elif defined HAVE_MIB_IPADDRTABLE -void ofi_get_list_of_addr(struct fi_provider *prov, const char *env_name, +void ofi_get_list_of_addr(const struct fi_provider *prov, const char *env_name, struct slist *addr_list) { struct ofi_addr_list_entry *addr_entry; @@ -1313,7 +1313,7 @@ void ofi_get_list_of_addr(struct fi_provider *prov, const char *env_name, #else /* !HAVE_MIB_IPADDRTABLE && !HAVE_MIB_IPADDRTABLE */ -void ofi_get_list_of_addr(struct fi_provider *prov, const char *env_name, +void ofi_get_list_of_addr(const struct fi_provider *prov, const char *env_name, struct slist *addr_list) { ofi_insert_loopback_addr(prov, addr_list); From 77b79aeb7f12c6c7748f8fd8eefd46a8134c5d24 Mon Sep 17 00:00:00 2001 From: Sean Hefty Date: Wed, 4 Mar 2020 09:32:23 -0800 Subject: [PATCH 3/6] core: Remove name check from domain attributes The domain name may be generated automatically based on the network interface being used. When validating the domain attributes, skip the name as part of the common checks. Signed-off-by: Sean Hefty --- prov/util/src/util_attr.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/prov/util/src/util_attr.c b/prov/util/src/util_attr.c index 5bee1035292..251f46ed918 100644 --- a/prov/util/src/util_attr.c +++ b/prov/util/src/util_attr.c @@ -520,13 +520,6 @@ int ofi_check_domain_attr(const struct fi_provider *prov, uint32_t api_version, { const struct fi_domain_attr *user_attr = user_info->domain_attr; - if (prov_attr->name && user_attr->name && - strcasecmp(user_attr->name, prov_attr->name)) { - FI_INFO(prov, FI_LOG_CORE, "Unknown domain name\n"); - FI_INFO_NAME(prov, prov_attr, user_attr); - return -FI_ENODATA; - } - if (fi_thread_level(user_attr->threading) < fi_thread_level(prov_attr->threading)) { FI_INFO(prov, FI_LOG_CORE, "Invalid threading model\n"); From 44dd84dc5d30565c4cd522d21a48f83ad50f7e24 Mon Sep 17 00:00:00 2001 From: Sean Hefty Date: Tue, 3 Mar 2020 04:01:20 -0800 Subject: [PATCH 4/6] prov/util: Create a common getinfo handler for IP based providers The tcp and udp providers take the same action when handing getinfo. Move the duplicated code into the util code. The same code can be used by the sockets provider. This fixes a regression in the sockets provider reporting the correct domain and fabric names when calling fi_getinfo with NULL hints. Signed-off-by: Sean Hefty --- include/ofi_util.h | 3 + prov/tcp/src/tcpx_init.c | 77 +---------------------- prov/udp/src/udpx_init.c | 71 +-------------------- prov/util/src/util_attr.c | 8 +-- prov/util/src/util_main.c | 127 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 138 insertions(+), 148 deletions(-) diff --git a/include/ofi_util.h b/include/ofi_util.h index 41b7de4cbb8..cda3f4e981f 100644 --- a/include/ofi_util.h +++ b/include/ofi_util.h @@ -891,6 +891,9 @@ struct fi_info *ofi_allocinfo_internal(void); int util_getinfo(const struct util_prov *util_prov, uint32_t version, const char *node, const char *service, uint64_t flags, const struct fi_info *hints, struct fi_info **info); +int ofi_ip_getinfo(const struct util_prov *prov, uint32_t version, + const char *node, const char *service, uint64_t flags, + const struct fi_info *hints, struct fi_info **info); struct fid_list_entry { diff --git a/prov/tcp/src/tcpx_init.c b/prov/tcp/src/tcpx_init.c index d6443ce6f96..a3ed427064b 100644 --- a/prov/tcp/src/tcpx_init.c +++ b/prov/tcp/src/tcpx_init.c @@ -36,88 +36,15 @@ #include "tcpx.h" #include -#include -#include #include #include -#if HAVE_GETIFADDRS -static void tcpx_getinfo_ifs(struct fi_info **info) -{ - struct fi_info *head = NULL, *tail = NULL, *cur; - struct slist addr_list; - size_t addrlen; - uint32_t addr_format; - struct slist_entry *entry, *prev; - struct ofi_addr_list_entry *addr_entry; - - slist_init(&addr_list); - - ofi_get_list_of_addr(&tcpx_prov, "iface", &addr_list); - - (void) prev; /* Makes compiler happy */ - slist_foreach(&addr_list, entry, prev) { - addr_entry = container_of(entry, struct ofi_addr_list_entry, entry); - - cur = fi_dupinfo(*info); - if (!cur) - break; - - if (!head) { - head = cur; - FI_INFO(&tcpx_prov, FI_LOG_CORE, "Chosen addr for using: %s," - " speed %zu\n", addr_entry->ipstr, addr_entry->speed); - } - else - tail->next = cur; - tail = cur; - - switch (addr_entry->ipaddr.sin.sin_family) { - case AF_INET: - addrlen = sizeof(struct sockaddr_in); - addr_format = FI_SOCKADDR_IN; - break; - case AF_INET6: - addrlen = sizeof(struct sockaddr_in6); - addr_format = FI_SOCKADDR_IN6; - break; - default: - continue; - } - - cur->src_addr = mem_dup(&addr_entry->ipaddr, addrlen); - if (cur->src_addr) { - cur->src_addrlen = addrlen; - cur->addr_format = addr_format; - } - /* TODO: rework util code - util_set_fabric_domain(&tcpx_prov, cur); - */ - } - - ofi_free_list_of_addr(&addr_list); - fi_freeinfo(*info); - *info = head; -} -#else -#define tcpx_getinfo_ifs(info) do{ } while(0) -#endif - static int tcpx_getinfo(uint32_t version, const char *node, const char *service, uint64_t flags, const struct fi_info *hints, struct fi_info **info) { - int ret; - - ret = util_getinfo(&tcpx_util_prov, version, node, service, flags, - hints, info); - if (ret) - return ret; - - if (!(*info)->src_addr && !(*info)->dest_addr) - tcpx_getinfo_ifs(info); - - return 0; + return ofi_ip_getinfo(&tcpx_util_prov, version, node, service, flags, + hints, info); } struct tcpx_port_range port_range = { diff --git a/prov/udp/src/udpx_init.c b/prov/udp/src/udpx_init.c index 89521478a11..020c54cf4d6 100644 --- a/prov/udp/src/udpx_init.c +++ b/prov/udp/src/udpx_init.c @@ -36,81 +36,14 @@ #include "udpx.h" #include -#include -#include -#if HAVE_GETIFADDRS -static void udpx_getinfo_ifs(struct fi_info **info) -{ - struct fi_info *head = NULL, *tail = NULL, *cur; - struct slist addr_list; - size_t addrlen; - uint32_t addr_format; - struct slist_entry *entry, *prev; - struct ofi_addr_list_entry *addr_entry; - - slist_init(&addr_list); - - ofi_get_list_of_addr(&udpx_prov, "iface", &addr_list); - - (void) prev; /* Makes compiler happy */ - slist_foreach(&addr_list, entry, prev) { - addr_entry = container_of(entry, struct ofi_addr_list_entry, entry); - - cur = fi_dupinfo(*info); - if (!cur) - break; - - if (!head) - head = cur; - else - tail->next = cur; - tail = cur; - - switch (addr_entry->ipaddr.sin.sin_family) { - case AF_INET: - addrlen = sizeof(struct sockaddr_in); - addr_format = FI_SOCKADDR_IN; - break; - case AF_INET6: - addrlen = sizeof(struct sockaddr_in6); - addr_format = FI_SOCKADDR_IN6; - break; - default: - continue; - } - - cur->src_addr = mem_dup(&addr_entry->ipaddr, addrlen); - if (cur->src_addr) { - cur->src_addrlen = addrlen; - cur->addr_format = addr_format; - } - } - - ofi_free_list_of_addr(&addr_list); - fi_freeinfo(*info); - *info = head; -} -#else -#define udpx_getinfo_ifs(info) do{}while(0) -#endif - static int udpx_getinfo(uint32_t version, const char *node, const char *service, uint64_t flags, const struct fi_info *hints, struct fi_info **info) { - int ret; - - ret = util_getinfo(&udpx_util_prov, version, node, service, flags, - hints, info); - if (ret) - return ret; - - if (!(*info)->src_addr && !(*info)->dest_addr) - udpx_getinfo_ifs(info); - - return 0; + return ofi_ip_getinfo(&udpx_util_prov, version, node, service, flags, + hints, info); } static void udpx_fini(void) diff --git a/prov/util/src/util_attr.c b/prov/util/src/util_attr.c index 251f46ed918..562f83a5ffb 100644 --- a/prov/util/src/util_attr.c +++ b/prov/util/src/util_attr.c @@ -902,7 +902,7 @@ int ofi_check_tx_attr(const struct fi_provider *prov, return 0; } -/* if there are multiple fi_info in the provider: +/* Use if there are multiple fi_info in the provider: * check provider's info */ int ofi_prov_check_info(const struct util_prov *util_prov, uint32_t api_version, @@ -925,7 +925,7 @@ int ofi_prov_check_info(const struct util_prov *util_prov, return (!success_info ? -FI_ENODATA : FI_SUCCESS); } -/* if there are multiple fi_info in the provider: +/* Use if there are multiple fi_info in the provider: * check and duplicate provider's info */ int ofi_prov_check_dup_info(const struct util_prov *util_prov, uint32_t api_version, @@ -958,7 +958,7 @@ int ofi_prov_check_dup_info(const struct util_prov *util_prov, tail = fi; } - return (!*info ? -FI_ENODATA : FI_SUCCESS); + return !*info ? -FI_ENODATA : FI_SUCCESS; err: fi_freeinfo(*info); FI_INFO(prov, FI_LOG_CORE, @@ -966,7 +966,7 @@ int ofi_prov_check_dup_info(const struct util_prov *util_prov, return ret; } -/* if there is only single fi_info in the provider */ +/* Use if there is only single fi_info in the provider */ int ofi_check_info(const struct util_prov *util_prov, const struct fi_info *prov_info, uint32_t api_version, const struct fi_info *user_info) diff --git a/prov/util/src/util_main.c b/prov/util/src/util_main.c index 504a522d9ee..87b3477d19d 100644 --- a/prov/util/src/util_main.c +++ b/prov/util/src/util_main.c @@ -127,6 +127,11 @@ static int util_find_domain(struct dlist_entry *item, const void *arg) ((info->domain_attr->mr_mode & domain->mr_mode) == domain->mr_mode); } +/* + * Produces 1 fi_info output for each fi_info entry in the provider's base + * list (stored with util_prov), subject to the base fi_info meeting the + * user's hints. + */ int util_getinfo(const struct util_prov *util_prov, uint32_t version, const char *node, const char *service, uint64_t flags, const struct fi_info *hints, struct fi_info **info) @@ -254,3 +259,125 @@ int util_getinfo(const struct util_prov *util_prov, uint32_t version, fi_freeinfo(*info); return ret; } + +static void util_set_netif_names(struct fi_info *info, + struct ofi_addr_list_entry *addr_entry) +{ + char *name; + + name = strdup(addr_entry->net_name); + if (name) { + free(info->fabric_attr->name); + info->fabric_attr->name = name; + } + + name = strdup(addr_entry->ifa_name); + if (name) { + free(info->domain_attr->name); + info->domain_attr->name = name; + } +} + +/* + * Produces 1 fi_info output for each usable IP address in the system for the + * given fi_info input. + */ +#if HAVE_GETIFADDRS +static void util_getinfo_ifs(const struct util_prov *prov, struct fi_info *src_info, + struct fi_info **head, struct fi_info **tail) +{ + struct fi_info *cur; + struct slist addr_list; + size_t addrlen; + uint32_t addr_format; + struct slist_entry *entry, *prev; + struct ofi_addr_list_entry *addr_entry; + + *head = *tail = NULL; + slist_init(&addr_list); + + ofi_get_list_of_addr(prov->prov, "iface", &addr_list); + + (void) prev; /* Makes compiler happy */ + slist_foreach(&addr_list, entry, prev) { + addr_entry = container_of(entry, struct ofi_addr_list_entry, entry); + + cur = fi_dupinfo(src_info); + if (!cur) + break; + + if (!*head) { + *head = cur; + FI_INFO(prov->prov, FI_LOG_CORE, "Chosen addr for using: %s," + " speed %zu\n", addr_entry->ipstr, addr_entry->speed); + } else { + (*tail)->next = cur; + } + *tail = cur; + + switch (addr_entry->ipaddr.sin.sin_family) { + case AF_INET: + addrlen = sizeof(struct sockaddr_in); + addr_format = FI_SOCKADDR_IN; + break; + case AF_INET6: + addrlen = sizeof(struct sockaddr_in6); + addr_format = FI_SOCKADDR_IN6; + break; + default: + continue; + } + + cur->src_addr = mem_dup(&addr_entry->ipaddr, addrlen); + if (cur->src_addr) { + cur->src_addrlen = addrlen; + cur->addr_format = addr_format; + } + util_set_netif_names(cur, addr_entry); + } + + ofi_free_list_of_addr(&addr_list); + if (!*head) { + *head = src_info; + *tail = src_info; + } +} +#else +static void util_getinfo_ifs(const struct util_prov *prov, struct fi_info *src_info, + struct fi_info **head, struct fi_info **tail) +{ + *head = src_info; + *tail = src_info; +} +#endif + +int ofi_ip_getinfo(const struct util_prov *prov, uint32_t version, + const char *node, const char *service, uint64_t flags, + const struct fi_info *hints, struct fi_info **info) +{ + struct fi_info *head, *tail, *cur, **prev; + int ret; + + ret = util_getinfo(prov, version, node, service, flags, + hints, info); + if (ret) + return ret; + + prev = info; + for (cur = *info; cur; cur = cur->next) { + if (!cur->src_addr && !cur->dest_addr) { + util_getinfo_ifs(prov, cur, &head, &tail); + if (head != cur) { + tail->next = (*prev)->next; + *prev = head; + + cur->next = NULL; + fi_freeinfo(cur); + cur = tail; + } + } + prev = &cur->next; + } + + return 0; +} From 0b618791a8ed42f33ce7221cdb29f04bb76d3b3a Mon Sep 17 00:00:00 2001 From: Sean Hefty Date: Tue, 3 Mar 2020 05:23:40 -0800 Subject: [PATCH 5/6] prov/util: Map fabric and domain names to src_addr for IP providers If a src_addr has been specified in the hints to fi_getinfo, we need to map the address to get the correct network and interface names. Update the util getinfo code path for IP based providers to set the fabric and domain names. The code currently does this if hints is NULL. This adds the same functionality for non-null hints. Signed-off-by: Sean Hefty --- prov/util/src/util_main.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/prov/util/src/util_main.c b/prov/util/src/util_main.c index 87b3477d19d..345c74d73ce 100644 --- a/prov/util/src/util_main.c +++ b/prov/util/src/util_main.c @@ -351,11 +351,22 @@ static void util_getinfo_ifs(const struct util_prov *prov, struct fi_info *src_i } #endif +static int util_match_addr(struct slist_entry *entry, const void *addr) +{ + struct ofi_addr_list_entry *addr_entry; + + addr_entry = container_of(entry, struct ofi_addr_list_entry, entry); + return ofi_equals_ipaddr(&addr_entry->ipaddr.sa, addr); +} + int ofi_ip_getinfo(const struct util_prov *prov, uint32_t version, const char *node, const char *service, uint64_t flags, const struct fi_info *hints, struct fi_info **info) { struct fi_info *head, *tail, *cur, **prev; + struct ofi_addr_list_entry *addr_entry; + struct slist addr_list; + struct slist_entry *entry; int ret; ret = util_getinfo(prov, version, node, service, flags, @@ -375,6 +386,18 @@ int ofi_ip_getinfo(const struct util_prov *prov, uint32_t version, fi_freeinfo(cur); cur = tail; } + } else if (cur->src_addr) { + slist_init(&addr_list); + ofi_get_list_of_addr(prov->prov, "iface", &addr_list); + + entry = slist_find_first_match(&addr_list, util_match_addr, + (*info)->src_addr); + if (entry) { + addr_entry = container_of(entry, + struct ofi_addr_list_entry, entry); + util_set_netif_names(cur, addr_entry); + } + ofi_free_list_of_addr(&addr_list); } prev = &cur->next; } From 10558ffd72ff39304014aa422a632b3456e19e18 Mon Sep 17 00:00:00 2001 From: Sean Hefty Date: Wed, 26 Feb 2020 07:30:30 -0800 Subject: [PATCH 6/6] prov/sockets: Fix fabric and domain name settings Convert sockets to use the new IP provider getinfo code. This ensures that the fabric and domain names are set correctly based on the addresses used. Because the common code verifies and formats the fi_info output, we can remove a bunch of code in the socket provider that performs similar checks done by the common code. Signed-off-by: Sean Hefty --- prov/sockets/include/sock.h | 21 +- prov/sockets/src/sock_attr.c | 2 + prov/sockets/src/sock_dom.c | 125 +--------- prov/sockets/src/sock_ep.c | 84 +++---- prov/sockets/src/sock_ep_dgram.c | 151 +----------- prov/sockets/src/sock_ep_msg.c | 230 +++---------------- prov/sockets/src/sock_ep_rdm.c | 195 +--------------- prov/sockets/src/sock_fabric.c | 381 +------------------------------ 8 files changed, 89 insertions(+), 1100 deletions(-) diff --git a/prov/sockets/include/sock.h b/prov/sockets/include/sock.h index a4b25981360..3509c9318cd 100644 --- a/prov/sockets/include/sock.h +++ b/prov/sockets/include/sock.h @@ -151,12 +151,10 @@ enum { #define SOCK_WIRE_PROTO_VERSION (2) -extern struct fi_info sock_msg_info; -extern struct fi_info sock_rdm_info; extern struct fi_info sock_dgram_info; -extern struct util_prov sock_msg_util_prov; -extern struct util_prov sock_rdm_util_prov; -extern struct util_prov sock_dgram_util_prov; +extern struct fi_info sock_msg_info; + +extern struct util_prov sock_util_prov; extern struct fi_domain_attr sock_domain_attr; extern struct fi_fabric_attr sock_fabric_attr; extern struct fi_tx_attr sock_msg_tx_attr; @@ -989,20 +987,7 @@ union sock_tx_op { }; #define SOCK_EP_TX_ENTRY_SZ (sizeof(union sock_tx_op)) -int sock_verify_info(uint32_t version, const struct fi_info *hints); -int sock_verify_fabric_attr(const struct fi_fabric_attr *attr); -int sock_verify_domain_attr(uint32_t version, const struct fi_info *info); - size_t sock_get_tx_size(size_t size); -int sock_rdm_verify_ep_attr(const struct fi_ep_attr *ep_attr, - const struct fi_tx_attr *tx_attr, - const struct fi_rx_attr *rx_attr); -int sock_dgram_verify_ep_attr(const struct fi_ep_attr *ep_attr, - const struct fi_tx_attr *tx_attr, - const struct fi_rx_attr *rx_attr); -int sock_msg_verify_ep_attr(const struct fi_ep_attr *ep_attr, - const struct fi_tx_attr *tx_attr, - const struct fi_rx_attr *rx_attr); int sock_get_src_addr(union ofi_sock_ip *dest_addr, union ofi_sock_ip *src_addr); int sock_get_src_addr_from_hostname(union ofi_sock_ip *src_addr, diff --git a/prov/sockets/src/sock_attr.c b/prov/sockets/src/sock_attr.c index c3d056783af..c14dc39440a 100644 --- a/prov/sockets/src/sock_attr.c +++ b/prov/sockets/src/sock_attr.c @@ -230,6 +230,7 @@ struct fi_info sock_msg_info = { }; struct fi_info sock_rdm_info = { + .next = &sock_msg_info, .caps = SOCK_RDM_TX_CAPS | SOCK_RDM_RX_CAPS | SOCK_DOMAIN_CAPS, .addr_format = FI_SOCKADDR, .tx_attr = &sock_rdm_tx_attr, @@ -240,6 +241,7 @@ struct fi_info sock_rdm_info = { }; struct fi_info sock_dgram_info = { + .next = &sock_rdm_info, .caps = SOCK_DGRAM_TX_CAPS | SOCK_DGRAM_RX_CAPS | SOCK_DOMAIN_CAPS, .addr_format = FI_SOCKADDR, .tx_attr = &sock_dgram_tx_attr, diff --git a/prov/sockets/src/sock_dom.c b/prov/sockets/src/sock_dom.c index b46f10df8f9..8adec0ce371 100644 --- a/prov/sockets/src/sock_dom.c +++ b/prov/sockets/src/sock_dom.c @@ -46,109 +46,6 @@ extern struct fi_ops_mr sock_dom_mr_ops; -int sock_verify_domain_attr(uint32_t version, const struct fi_info *info) -{ - const struct fi_domain_attr *attr = info->domain_attr; - - if (!attr) - return 0; - - switch (attr->threading) { - case FI_THREAD_UNSPEC: - case FI_THREAD_SAFE: - case FI_THREAD_FID: - case FI_THREAD_DOMAIN: - case FI_THREAD_COMPLETION: - case FI_THREAD_ENDPOINT: - break; - default: - SOCK_LOG_DBG("Invalid threading model!\n"); - return -FI_ENODATA; - } - - switch (attr->control_progress) { - case FI_PROGRESS_UNSPEC: - case FI_PROGRESS_AUTO: - case FI_PROGRESS_MANUAL: - break; - - default: - SOCK_LOG_DBG("Control progress mode not supported!\n"); - return -FI_ENODATA; - } - - switch (attr->data_progress) { - case FI_PROGRESS_UNSPEC: - case FI_PROGRESS_AUTO: - case FI_PROGRESS_MANUAL: - break; - - default: - SOCK_LOG_DBG("Data progress mode not supported!\n"); - return -FI_ENODATA; - } - - switch (attr->resource_mgmt) { - case FI_RM_UNSPEC: - case FI_RM_DISABLED: - case FI_RM_ENABLED: - break; - - default: - SOCK_LOG_DBG("Resource mgmt not supported!\n"); - return -FI_ENODATA; - } - - switch (attr->av_type) { - case FI_AV_UNSPEC: - case FI_AV_MAP: - case FI_AV_TABLE: - break; - - default: - SOCK_LOG_DBG("AV type not supported!\n"); - return -FI_ENODATA; - } - - if (ofi_check_mr_mode(&sock_prov, version, - sock_domain_attr.mr_mode, info)) { - FI_INFO(&sock_prov, FI_LOG_CORE, - "Invalid memory registration mode\n"); - return -FI_ENODATA; - } - - if (attr->mr_key_size > sock_domain_attr.mr_key_size) - return -FI_ENODATA; - - if (attr->cq_data_size > sock_domain_attr.cq_data_size) - return -FI_ENODATA; - - if (attr->cq_cnt > sock_domain_attr.cq_cnt) - return -FI_ENODATA; - - if (attr->ep_cnt > sock_domain_attr.ep_cnt) - return -FI_ENODATA; - - if (attr->max_ep_tx_ctx > sock_domain_attr.max_ep_tx_ctx) - return -FI_ENODATA; - - if (attr->max_ep_rx_ctx > sock_domain_attr.max_ep_rx_ctx) - return -FI_ENODATA; - - if (attr->cntr_cnt > sock_domain_attr.cntr_cnt) - return -FI_ENODATA; - - if (attr->mr_iov_limit > sock_domain_attr.mr_iov_limit) - return -FI_ENODATA; - - if (attr->max_err_data > sock_domain_attr.max_err_data) - return -FI_ENODATA; - - if (attr->mr_cnt > sock_domain_attr.mr_cnt) - return -FI_ENODATA; - - return 0; -} static int sock_dom_close(struct fid *fid) { @@ -258,12 +155,8 @@ int sock_domain(struct fid_fabric *fabric, struct fi_info *info, struct sock_fabric *fab; int ret; + assert(info && info->domain_attr); fab = container_of(fabric, struct sock_fabric, fab_fid); - if (info && info->domain_attr) { - ret = sock_verify_domain_attr(fabric->api_version, info); - if (ret) - return -FI_EINVAL; - } sock_domain = calloc(1, sizeof(*sock_domain)); if (!sock_domain) @@ -272,12 +165,8 @@ int sock_domain(struct fid_fabric *fabric, struct fi_info *info, fastlock_init(&sock_domain->lock); ofi_atomic_initialize32(&sock_domain->ref, 0); - if (info) { - sock_domain->info = *info; - } else { - SOCK_LOG_ERROR("invalid fi_info\n"); - goto err1; - } + sock_domain->info = *info; + sock_domain->info.domain_attr = NULL; sock_domain->dom_fid.fid.fclass = FI_CLASS_DOMAIN; sock_domain->dom_fid.fid.context = context; @@ -285,8 +174,7 @@ int sock_domain(struct fid_fabric *fabric, struct fi_info *info, sock_domain->dom_fid.ops = &sock_dom_ops; sock_domain->dom_fid.mr = &sock_dom_mr_ops; - if (!info->domain_attr || - info->domain_attr->data_progress == FI_PROGRESS_UNSPEC) + if (info->domain_attr->data_progress == FI_PROGRESS_UNSPEC) sock_domain->progress_mode = FI_PROGRESS_AUTO; else sock_domain->progress_mode = info->domain_attr->data_progress; @@ -300,10 +188,7 @@ int sock_domain(struct fid_fabric *fabric, struct fi_info *info, sock_domain->fab = fab; *dom = &sock_domain->dom_fid; - if (info->domain_attr) - sock_domain->attr = *(info->domain_attr); - else - sock_domain->attr = sock_domain_attr; + sock_domain->attr = *(info->domain_attr); ret = ofi_mr_map_init(&sock_prov, sock_domain->attr.mr_mode, &sock_domain->mr_map); diff --git a/prov/sockets/src/sock_ep.c b/prov/sockets/src/sock_ep.c index df559a26908..c19d924b7c9 100644 --- a/prov/sockets/src/sock_ep.c +++ b/prov/sockets/src/sock_ep.c @@ -1598,16 +1598,10 @@ int sock_alloc_endpoint(struct fid_domain *domain, struct fi_info *info, struct sock_rx_ctx *rx_ctx; struct sock_domain *sock_dom; + assert(info); sock_dom = container_of(domain, struct sock_domain, dom_fid); - if (info) { - ret = sock_verify_info(sock_dom->fab->fab_fid.api_version, info); - if (ret) { - SOCK_LOG_DBG("Cannot support requested options!\n"); - return -FI_EINVAL; - } - } - sock_ep = (struct sock_ep *) calloc(1, sizeof(*sock_ep)); + sock_ep = calloc(1, sizeof(*sock_ep)); if (!sock_ep) return -FI_ENOMEM; @@ -1647,52 +1641,50 @@ int sock_alloc_endpoint(struct fid_domain *domain, struct fi_info *info, sock_ep->attr->fclass = fclass; *ep = sock_ep; - if (info) { - sock_ep->attr->info.caps = info->caps; - sock_ep->attr->info.addr_format = FI_SOCKADDR_IN; + sock_ep->attr->info.caps = info->caps; + sock_ep->attr->info.addr_format = info->addr_format; - if (info->ep_attr) { - sock_ep->attr->ep_type = info->ep_attr->type; - sock_ep->attr->ep_attr.tx_ctx_cnt = info->ep_attr->tx_ctx_cnt; - sock_ep->attr->ep_attr.rx_ctx_cnt = info->ep_attr->rx_ctx_cnt; - } - - if (info->src_addr) { - sock_ep->attr->src_addr = calloc(1, sizeof(*sock_ep-> - attr->src_addr)); - if (!sock_ep->attr->src_addr) { - ret = -FI_ENOMEM; - goto err2; - } - memcpy(sock_ep->attr->src_addr, info->src_addr, - info->src_addrlen); - } + if (info->ep_attr) { + sock_ep->attr->ep_type = info->ep_attr->type; + sock_ep->attr->ep_attr.tx_ctx_cnt = info->ep_attr->tx_ctx_cnt; + sock_ep->attr->ep_attr.rx_ctx_cnt = info->ep_attr->rx_ctx_cnt; + } - if (info->dest_addr) { - sock_ep->attr->dest_addr = calloc(1, sizeof(*sock_ep-> - attr->dest_addr)); - if (!sock_ep->attr->dest_addr) { - ret = -FI_ENOMEM; - goto err2; - } - memcpy(sock_ep->attr->dest_addr, info->dest_addr, - info->dest_addrlen); + if (info->src_addr) { + sock_ep->attr->src_addr = calloc(1, sizeof(*sock_ep-> + attr->src_addr)); + if (!sock_ep->attr->src_addr) { + ret = -FI_ENOMEM; + goto err2; } + memcpy(sock_ep->attr->src_addr, info->src_addr, + info->src_addrlen); + } - if (info->tx_attr) { - sock_ep->tx_attr = *info->tx_attr; - if (!(sock_ep->tx_attr.op_flags & (FI_INJECT_COMPLETE | - FI_TRANSMIT_COMPLETE | FI_DELIVERY_COMPLETE))) - sock_ep->tx_attr.op_flags |= FI_TRANSMIT_COMPLETE; - sock_ep->tx_attr.size = sock_ep->tx_attr.size ? - sock_ep->tx_attr.size : SOCK_EP_TX_SZ; + if (info->dest_addr) { + sock_ep->attr->dest_addr = calloc(1, sizeof(*sock_ep-> + attr->dest_addr)); + if (!sock_ep->attr->dest_addr) { + ret = -FI_ENOMEM; + goto err2; } + memcpy(sock_ep->attr->dest_addr, info->dest_addr, + info->dest_addrlen); + } - if (info->rx_attr) - sock_ep->rx_attr = *info->rx_attr; - sock_ep->attr->info.handle = info->handle; + if (info->tx_attr) { + sock_ep->tx_attr = *info->tx_attr; + if (!(sock_ep->tx_attr.op_flags & (FI_INJECT_COMPLETE | + FI_TRANSMIT_COMPLETE | FI_DELIVERY_COMPLETE))) + sock_ep->tx_attr.op_flags |= FI_TRANSMIT_COMPLETE; + sock_ep->tx_attr.size = sock_ep->tx_attr.size ? + sock_ep->tx_attr.size : SOCK_EP_TX_SZ; } + if (info->rx_attr) + sock_ep->rx_attr = *info->rx_attr; + sock_ep->attr->info.handle = info->handle; + if (!sock_ep->attr->src_addr && sock_ep_assign_src_addr(sock_ep, info)) { SOCK_LOG_ERROR("failed to get src_address\n"); ret = -FI_EINVAL; diff --git a/prov/sockets/src/sock_ep_dgram.c b/prov/sockets/src/sock_ep_dgram.c index d2cfa0e21a5..7a18532be90 100644 --- a/prov/sockets/src/sock_ep_dgram.c +++ b/prov/sockets/src/sock_ep_dgram.c @@ -56,153 +56,6 @@ #define SOCK_LOG_DBG(...) _SOCK_LOG_DBG(FI_LOG_EP_CTRL, __VA_ARGS__) #define SOCK_LOG_ERROR(...) _SOCK_LOG_ERROR(FI_LOG_EP_CTRL, __VA_ARGS__) -static int sock_dgram_verify_rx_attr(const struct fi_rx_attr *attr) -{ - if (!attr) - return 0; - - if ((attr->caps | sock_dgram_rx_attr.caps) != sock_dgram_rx_attr.caps) - return -FI_ENODATA; - - if ((attr->msg_order | SOCK_EP_MSG_ORDER) != SOCK_EP_MSG_ORDER) - return -FI_ENODATA; - - if ((attr->comp_order | SOCK_EP_COMP_ORDER) != SOCK_EP_COMP_ORDER) - return -FI_ENODATA; - - if (attr->total_buffered_recv > sock_dgram_rx_attr.total_buffered_recv) - return -FI_ENODATA; - - if (sock_get_tx_size(attr->size) > - sock_get_tx_size(sock_dgram_rx_attr.size)) - return -FI_ENODATA; - - if (attr->iov_limit > sock_dgram_rx_attr.iov_limit) - return -FI_ENODATA; - - return 0; -} - -static int sock_dgram_verify_tx_attr(const struct fi_tx_attr *attr) -{ - if (!attr) - return 0; - - if ((attr->caps | sock_dgram_tx_attr.caps) != sock_dgram_tx_attr.caps) - return -FI_ENODATA; - - if ((attr->msg_order | SOCK_EP_MSG_ORDER) != SOCK_EP_MSG_ORDER) - return -FI_ENODATA; - - if (attr->inject_size > sock_dgram_tx_attr.inject_size) - return -FI_ENODATA; - - if (sock_get_tx_size(attr->size) > - sock_get_tx_size(sock_dgram_tx_attr.size)) - return -FI_ENODATA; - - if (attr->iov_limit > sock_dgram_tx_attr.iov_limit) - return -FI_ENODATA; - - if (attr->rma_iov_limit > sock_dgram_tx_attr.rma_iov_limit) - return -FI_ENODATA; - - return 0; -} - -int sock_dgram_verify_ep_attr(const struct fi_ep_attr *ep_attr, - const struct fi_tx_attr *tx_attr, - const struct fi_rx_attr *rx_attr) -{ - if (ep_attr) { - switch (ep_attr->protocol) { - case FI_PROTO_UNSPEC: - case FI_PROTO_SOCK_TCP: - break; - default: - return -FI_ENODATA; - } - - if (ep_attr->protocol_version && - (ep_attr->protocol_version != sock_dgram_ep_attr.protocol_version)) - return -FI_ENODATA; - - if (ep_attr->max_msg_size > sock_dgram_ep_attr.max_msg_size) - return -FI_ENODATA; - - if (ep_attr->msg_prefix_size > sock_dgram_ep_attr.msg_prefix_size) - return -FI_ENODATA; - - if (ep_attr->max_order_raw_size > - sock_dgram_ep_attr.max_order_raw_size) - return -FI_ENODATA; - - if (ep_attr->max_order_war_size > - sock_dgram_ep_attr.max_order_war_size) - return -FI_ENODATA; - - if (ep_attr->max_order_waw_size > - sock_dgram_ep_attr.max_order_waw_size) - return -FI_ENODATA; - - if ((ep_attr->tx_ctx_cnt > SOCK_EP_MAX_TX_CNT) && - ep_attr->tx_ctx_cnt != FI_SHARED_CONTEXT) - return -FI_ENODATA; - - if ((ep_attr->rx_ctx_cnt > SOCK_EP_MAX_RX_CNT) && - ep_attr->rx_ctx_cnt != FI_SHARED_CONTEXT) - return -FI_ENODATA; - } - - if (sock_dgram_verify_tx_attr(tx_attr) || - sock_dgram_verify_rx_attr(rx_attr)) - return -FI_ENODATA; - - return 0; -} - -static int sock_dgram_endpoint(struct fid_domain *domain, struct fi_info *info, - struct sock_ep **ep, void *context, size_t fclass) -{ - int ret; - - if (info) { - if (info->ep_attr) { - ret = sock_dgram_verify_ep_attr(info->ep_attr, - info->tx_attr, - info->rx_attr); - if (ret) - return -FI_EINVAL; - } - - if (info->tx_attr) { - ret = sock_dgram_verify_tx_attr(info->tx_attr); - if (ret) - return -FI_EINVAL; - } - - if (info->rx_attr) { - ret = sock_dgram_verify_rx_attr(info->rx_attr); - if (ret) - return -FI_EINVAL; - } - } - - ret = sock_alloc_endpoint(domain, info, ep, context, fclass); - if (ret) - return ret; - - if (!info || !info->ep_attr) - (*ep)->attr->ep_attr = sock_dgram_ep_attr; - - if (!info || !info->tx_attr) - (*ep)->tx_attr = sock_dgram_tx_attr; - - if (!info || !info->rx_attr) - (*ep)->rx_attr = sock_dgram_rx_attr; - - return 0; -} int sock_dgram_ep(struct fid_domain *domain, struct fi_info *info, struct fid_ep **ep, void *context) @@ -210,7 +63,7 @@ int sock_dgram_ep(struct fid_domain *domain, struct fi_info *info, int ret; struct sock_ep *endpoint; - ret = sock_dgram_endpoint(domain, info, &endpoint, context, FI_CLASS_EP); + ret = sock_alloc_endpoint(domain, info, &endpoint, context, FI_CLASS_EP); if (ret) return ret; @@ -224,7 +77,7 @@ int sock_dgram_sep(struct fid_domain *domain, struct fi_info *info, int ret; struct sock_ep *endpoint; - ret = sock_dgram_endpoint(domain, info, &endpoint, context, FI_CLASS_SEP); + ret = sock_alloc_endpoint(domain, info, &endpoint, context, FI_CLASS_SEP); if (ret) return ret; diff --git a/prov/sockets/src/sock_ep_msg.c b/prov/sockets/src/sock_ep_msg.c index e4001112742..594650c9bbf 100644 --- a/prov/sockets/src/sock_ep_msg.c +++ b/prov/sockets/src/sock_ep_msg.c @@ -59,113 +59,6 @@ #define SOCK_LOG_DBG(...) _SOCK_LOG_DBG(FI_LOG_EP_CTRL, __VA_ARGS__) #define SOCK_LOG_ERROR(...) _SOCK_LOG_ERROR(FI_LOG_EP_CTRL, __VA_ARGS__) -static int sock_msg_verify_rx_attr(const struct fi_rx_attr *attr) -{ - if (!attr) - return 0; - - if ((attr->caps | sock_msg_rx_attr.caps) != sock_msg_rx_attr.caps) - return -FI_ENODATA; - - if ((attr->msg_order | SOCK_EP_MSG_ORDER) != SOCK_EP_MSG_ORDER) - return -FI_ENODATA; - - if ((attr->comp_order | SOCK_EP_COMP_ORDER) != SOCK_EP_COMP_ORDER) - return -FI_ENODATA; - - if (attr->total_buffered_recv > sock_msg_rx_attr.total_buffered_recv) - return -FI_ENODATA; - - if (sock_get_tx_size(attr->size) > - sock_get_tx_size(sock_msg_rx_attr.size)) - return -FI_ENODATA; - - if (attr->iov_limit > sock_msg_rx_attr.iov_limit) - return -FI_ENODATA; - - return 0; -} - -static int sock_msg_verify_tx_attr(const struct fi_tx_attr *attr) -{ - if (!attr) - return 0; - - if ((attr->caps | sock_msg_tx_attr.caps) != sock_msg_tx_attr.caps) - return -FI_ENODATA; - - if ((attr->msg_order | SOCK_EP_MSG_ORDER) != SOCK_EP_MSG_ORDER) - return -FI_ENODATA; - - if (attr->inject_size > sock_msg_tx_attr.inject_size) - return -FI_ENODATA; - - if (sock_get_tx_size(attr->size) > - sock_get_tx_size(sock_msg_tx_attr.size)) - return -FI_ENODATA; - - if (attr->iov_limit > sock_msg_tx_attr.iov_limit) - return -FI_ENODATA; - - if (attr->rma_iov_limit > sock_msg_tx_attr.rma_iov_limit) - return -FI_ENODATA; - - return 0; -} - -int sock_msg_verify_ep_attr(const struct fi_ep_attr *ep_attr, - const struct fi_tx_attr *tx_attr, - const struct fi_rx_attr *rx_attr) -{ - if (ep_attr) { - switch (ep_attr->protocol) { - case FI_PROTO_UNSPEC: - case FI_PROTO_SOCK_TCP: - break; - default: - return -FI_ENODATA; - } - - if (ep_attr->protocol_version && - (ep_attr->protocol_version != sock_msg_ep_attr.protocol_version)) - return -FI_ENODATA; - - if (ep_attr->max_msg_size > sock_msg_ep_attr.max_msg_size) - return -FI_ENODATA; - - if (ep_attr->msg_prefix_size > sock_msg_ep_attr.msg_prefix_size) - return -FI_ENODATA; - - if (ep_attr->max_order_raw_size > - sock_msg_ep_attr.max_order_raw_size) - return -FI_ENODATA; - - if (ep_attr->max_order_war_size > - sock_msg_ep_attr.max_order_war_size) - return -FI_ENODATA; - - if (ep_attr->max_order_waw_size > - sock_msg_ep_attr.max_order_waw_size) - return -FI_ENODATA; - - if ((ep_attr->tx_ctx_cnt > SOCK_EP_MAX_TX_CNT) && - ep_attr->tx_ctx_cnt != FI_SHARED_CONTEXT) - return -FI_ENODATA; - - if ((ep_attr->rx_ctx_cnt > SOCK_EP_MAX_RX_CNT) && - ep_attr->rx_ctx_cnt != FI_SHARED_CONTEXT) - return -FI_ENODATA; - - if (ep_attr->auth_key_size && - (ep_attr->auth_key_size != sock_msg_ep_attr.auth_key_size)) - return -FI_ENODATA; - } - - if (sock_msg_verify_tx_attr(tx_attr) || sock_msg_verify_rx_attr(rx_attr)) - return -FI_ENODATA; - - return 0; -} static int sock_ep_cm_getname(fid_t fid, void *addr, size_t *addrlen) { @@ -741,65 +634,22 @@ struct fi_ops_cm sock_ep_cm_ops = { .join = fi_no_join, }; -static int sock_msg_endpoint(struct fid_domain *domain, struct fi_info *info, - struct sock_ep **ep, void *context, size_t fclass) +int sock_msg_ep(struct fid_domain *domain, struct fi_info *info, + struct fid_ep **ep, void *context) { - int ret; + struct sock_ep *endpoint; struct sock_pep *pep; + int ret; - if (info) { - if (info->ep_attr) { - ret = sock_msg_verify_ep_attr(info->ep_attr, - info->tx_attr, - info->rx_attr); - if (ret) - return -FI_EINVAL; - } - - if (info->tx_attr) { - ret = sock_msg_verify_tx_attr(info->tx_attr); - if (ret) - return -FI_EINVAL; - } - - if (info->rx_attr) { - ret = sock_msg_verify_rx_attr(info->rx_attr); - if (ret) - return -FI_EINVAL; - } - } - - ret = sock_alloc_endpoint(domain, info, ep, context, fclass); + ret = sock_alloc_endpoint(domain, info, &endpoint, context, FI_CLASS_EP); if (ret) return ret; if (info && info->handle && info->handle->fclass == FI_CLASS_PEP) { pep = container_of(info->handle, struct sock_pep, pep.fid); - memcpy((*ep)->attr->src_addr, &pep->src_addr, sizeof *(*ep)->attr->src_addr); + *endpoint->attr->src_addr = pep->src_addr; } - if (!info || !info->ep_attr) - (*ep)->attr->ep_attr = sock_msg_ep_attr; - - if (!info || !info->tx_attr) - (*ep)->tx_attr = sock_msg_tx_attr; - - if (!info || !info->rx_attr) - (*ep)->rx_attr = sock_msg_rx_attr; - - return 0; -} - -int sock_msg_ep(struct fid_domain *domain, struct fi_info *info, - struct fid_ep **ep, void *context) -{ - int ret; - struct sock_ep *endpoint; - - ret = sock_msg_endpoint(domain, info, &endpoint, context, FI_CLASS_EP); - if (ret) - return ret; - *ep = &endpoint->ep; return 0; } @@ -1202,7 +1052,7 @@ int sock_msg_sep(struct fid_domain *domain, struct fi_info *info, int ret; struct sock_ep *endpoint; - ret = sock_msg_endpoint(domain, info, &endpoint, context, FI_CLASS_SEP); + ret = sock_alloc_endpoint(domain, info, &endpoint, context, FI_CLASS_SEP); if (ret) return ret; @@ -1217,52 +1067,40 @@ int sock_msg_passive_ep(struct fid_fabric *fabric, struct fi_info *info, struct sock_pep *_pep; struct addrinfo hints, *result; - if (info) { - ret = sock_verify_info(fabric->api_version, info); - if (ret) { - SOCK_LOG_DBG("Cannot support requested options!\n"); - return ret; - } - } - + assert(info); _pep = calloc(1, sizeof(*_pep)); if (!_pep) return -FI_ENOMEM; - if (info) { - if (info->src_addr) { - memcpy(&_pep->src_addr, info->src_addr, - info->src_addrlen); + if (info->src_addr) { + memcpy(&_pep->src_addr, info->src_addr, + info->src_addrlen); + } else { + memset(&hints, 0, sizeof(hints)); + hints.ai_socktype = SOCK_STREAM; + hints.ai_family = ofi_get_sa_family(info); + if (!hints.ai_family) + hints.ai_family = AF_INET; + + if (hints.ai_family == AF_INET) { + ret = getaddrinfo("127.0.0.1", NULL, &hints, + &result); + } else if (hints.ai_family == AF_INET6) { + ret = getaddrinfo("::1", NULL, &hints, &result); } else { - memset(&hints, 0, sizeof(hints)); - hints.ai_socktype = SOCK_STREAM; - hints.ai_family = ofi_get_sa_family(info); - if (!hints.ai_family) - hints.ai_family = AF_INET; - - if (hints.ai_family == AF_INET) { - ret = getaddrinfo("127.0.0.1", NULL, &hints, - &result); - } else if (hints.ai_family == AF_INET6) { - ret = getaddrinfo("::1", NULL, &hints, &result); - } else { - ret = getaddrinfo("localhost", NULL, &hints, - &result); - } - if (ret) { - ret = -FI_EINVAL; - SOCK_LOG_DBG("getaddrinfo failed!\n"); - goto err; - } - memcpy(&_pep->src_addr, result->ai_addr, - result->ai_addrlen); - freeaddrinfo(result); + ret = getaddrinfo("localhost", NULL, &hints, + &result); } - _pep->info = *info; - } else { - SOCK_LOG_ERROR("invalid fi_info\n"); - goto err; + if (ret) { + ret = -FI_EINVAL; + SOCK_LOG_DBG("getaddrinfo failed!\n"); + goto err; + } + memcpy(&_pep->src_addr, result->ai_addr, + result->ai_addrlen); + freeaddrinfo(result); } + _pep->info = *info; ret = socketpair(AF_UNIX, SOCK_STREAM, 0, _pep->cm.signal_fds); if (ret) { diff --git a/prov/sockets/src/sock_ep_rdm.c b/prov/sockets/src/sock_ep_rdm.c index bbb20412d2e..ede4bba67eb 100644 --- a/prov/sockets/src/sock_ep_rdm.c +++ b/prov/sockets/src/sock_ep_rdm.c @@ -57,196 +57,6 @@ #define SOCK_LOG_DBG(...) _SOCK_LOG_DBG(FI_LOG_EP_CTRL, __VA_ARGS__) #define SOCK_LOG_ERROR(...) _SOCK_LOG_ERROR(FI_LOG_EP_CTRL, __VA_ARGS__) -static int sock_rdm_verify_rx_attr(const struct fi_rx_attr *attr) -{ - if (!attr) - return 0; - - if ((attr->caps | sock_rdm_rx_attr.caps) != sock_rdm_rx_attr.caps) { - SOCK_LOG_DBG("Unsupported RDM rx caps\n"); - return -FI_ENODATA; - } - - if ((attr->msg_order | SOCK_EP_MSG_ORDER) != SOCK_EP_MSG_ORDER) { - SOCK_LOG_DBG("Unsuported rx message order\n"); - return -FI_ENODATA; - } - - if ((attr->comp_order | SOCK_EP_COMP_ORDER) != SOCK_EP_COMP_ORDER) { - SOCK_LOG_DBG("Unsuported rx completion order\n"); - return -FI_ENODATA; - } - - if (attr->total_buffered_recv > sock_rdm_rx_attr.total_buffered_recv) { - SOCK_LOG_DBG("Buffered receive size too large\n"); - return -FI_ENODATA; - } - - if (sock_get_tx_size(attr->size) > - sock_get_tx_size(sock_rdm_rx_attr.size)) { - SOCK_LOG_DBG("Rx size too large\n"); - return -FI_ENODATA; - } - - if (attr->iov_limit > sock_rdm_rx_attr.iov_limit) { - SOCK_LOG_DBG("Rx iov limit too large\n"); - return -FI_ENODATA; - } - - return 0; -} - -static int sock_rdm_verify_tx_attr(const struct fi_tx_attr *attr) -{ - if (!attr) - return 0; - - if ((attr->caps | sock_rdm_tx_attr.caps) != sock_rdm_tx_attr.caps) { - SOCK_LOG_DBG("Unsupported RDM tx caps\n"); - return -FI_ENODATA; - } - - if ((attr->msg_order | SOCK_EP_MSG_ORDER) != SOCK_EP_MSG_ORDER) { - SOCK_LOG_DBG("Unsupported tx message order\n"); - return -FI_ENODATA; - } - - if (attr->inject_size > sock_rdm_tx_attr.inject_size) { - SOCK_LOG_DBG("Inject size too large\n"); - return -FI_ENODATA; - } - - if (sock_get_tx_size(attr->size) > - sock_get_tx_size(sock_rdm_tx_attr.size)) { - SOCK_LOG_DBG("Tx size too large\n"); - return -FI_ENODATA; - } - - if (attr->iov_limit > sock_rdm_tx_attr.iov_limit) { - SOCK_LOG_DBG("Tx iov limit too large\n"); - return -FI_ENODATA; - } - - if (attr->rma_iov_limit > sock_rdm_tx_attr.rma_iov_limit) { - SOCK_LOG_DBG("RMA iov limit too large\n"); - return -FI_ENODATA; - } - - return 0; -} - -int sock_rdm_verify_ep_attr(const struct fi_ep_attr *ep_attr, - const struct fi_tx_attr *tx_attr, - const struct fi_rx_attr *rx_attr) -{ - int ret; - - if (ep_attr) { - switch (ep_attr->protocol) { - case FI_PROTO_UNSPEC: - case FI_PROTO_SOCK_TCP: - break; - default: - SOCK_LOG_DBG("Unsupported protocol\n"); - return -FI_ENODATA; - } - - if (ep_attr->protocol_version && - (ep_attr->protocol_version != sock_rdm_ep_attr.protocol_version)) { - SOCK_LOG_DBG("Invalid protocol version\n"); - return -FI_ENODATA; - } - - if (ep_attr->max_msg_size > sock_rdm_ep_attr.max_msg_size) { - SOCK_LOG_DBG("Message size too large\n"); - return -FI_ENODATA; - } - - if (ep_attr->msg_prefix_size > sock_rdm_ep_attr.msg_prefix_size) { - SOCK_LOG_DBG("Msg prefix size not supported\n"); - return -FI_ENODATA; - } - - if (ep_attr->max_order_raw_size > - sock_rdm_ep_attr.max_order_raw_size) { - SOCK_LOG_DBG("RAW order size too large\n"); - return -FI_ENODATA; - } - - if (ep_attr->max_order_war_size > - sock_rdm_ep_attr.max_order_war_size) { - SOCK_LOG_DBG("WAR order size too large\n"); - return -FI_ENODATA; - } - - if (ep_attr->max_order_waw_size > - sock_rdm_ep_attr.max_order_waw_size) { - SOCK_LOG_DBG("WAW order size too large\n"); - return -FI_ENODATA; - } - - if ((ep_attr->tx_ctx_cnt > SOCK_EP_MAX_TX_CNT) && - ep_attr->tx_ctx_cnt != FI_SHARED_CONTEXT) - return -FI_ENODATA; - - if ((ep_attr->rx_ctx_cnt > SOCK_EP_MAX_RX_CNT) && - ep_attr->rx_ctx_cnt != FI_SHARED_CONTEXT) - return -FI_ENODATA; - } - - ret = sock_rdm_verify_tx_attr(tx_attr); - if (ret) - return ret; - - ret = sock_rdm_verify_rx_attr(rx_attr); - if (ret) - return ret; - - return 0; -} - -static int sock_rdm_endpoint(struct fid_domain *domain, struct fi_info *info, - struct sock_ep **ep, void *context, size_t fclass) -{ - int ret; - - if (info) { - if (info->ep_attr) { - ret = sock_rdm_verify_ep_attr(info->ep_attr, - info->tx_attr, - info->rx_attr); - if (ret) - return -FI_EINVAL; - } - - if (info->tx_attr) { - ret = sock_rdm_verify_tx_attr(info->tx_attr); - if (ret) - return -FI_EINVAL; - } - - if (info->rx_attr) { - ret = sock_rdm_verify_rx_attr(info->rx_attr); - if (ret) - return -FI_EINVAL; - } - } - - ret = sock_alloc_endpoint(domain, info, ep, context, fclass); - if (ret) - return ret; - - if (!info || !info->ep_attr) - (*ep)->attr->ep_attr = sock_rdm_ep_attr; - - if (!info || !info->tx_attr) - (*ep)->tx_attr = sock_rdm_tx_attr; - - if (!info || !info->rx_attr) - (*ep)->rx_attr = sock_rdm_rx_attr; - - return 0; -} int sock_rdm_ep(struct fid_domain *domain, struct fi_info *info, struct fid_ep **ep, void *context) @@ -254,7 +64,7 @@ int sock_rdm_ep(struct fid_domain *domain, struct fi_info *info, int ret; struct sock_ep *endpoint; - ret = sock_rdm_endpoint(domain, info, &endpoint, context, FI_CLASS_EP); + ret = sock_alloc_endpoint(domain, info, &endpoint, context, FI_CLASS_EP); if (ret) return ret; @@ -268,11 +78,10 @@ int sock_rdm_sep(struct fid_domain *domain, struct fi_info *info, int ret; struct sock_ep *endpoint; - ret = sock_rdm_endpoint(domain, info, &endpoint, context, FI_CLASS_SEP); + ret = sock_alloc_endpoint(domain, info, &endpoint, context, FI_CLASS_SEP); if (ret) return ret; *sep = &endpoint->ep; return 0; } - diff --git a/prov/sockets/src/sock_fabric.c b/prov/sockets/src/sock_fabric.c index 87871004acb..53f459165e3 100644 --- a/prov/sockets/src/sock_fabric.c +++ b/prov/sockets/src/sock_fabric.c @@ -69,7 +69,6 @@ int sock_keepalive_probes = INT_MAX; static struct dlist_entry sock_fab_list; static struct dlist_entry sock_dom_list; static fastlock_t sock_list_lock; -static struct slist sock_addr_list; static int read_default_params; void sock_dom_add_to_list(struct sock_domain *domain) @@ -193,101 +192,6 @@ struct sock_fabric *sock_fab_list_head(void) return fabric; } -int sock_verify_fabric_attr(const struct fi_fabric_attr *attr) -{ - if (!attr) - return 0; - - if (attr->prov_version) { - if (attr->prov_version != - FI_VERSION(SOCK_MAJOR_VERSION, SOCK_MINOR_VERSION)) - return -FI_ENODATA; - } - - return 0; -} - -int sock_verify_info(uint32_t version, const struct fi_info *hints) -{ - uint64_t caps; - enum fi_ep_type ep_type; - int ret; - struct sock_domain *domain; - struct sock_fabric *fabric; - - if (!hints) - return 0; - - ep_type = hints->ep_attr ? hints->ep_attr->type : FI_EP_UNSPEC; - switch (ep_type) { - case FI_EP_UNSPEC: - case FI_EP_MSG: - caps = sock_msg_info.caps; - ret = sock_msg_verify_ep_attr(hints->ep_attr, - hints->tx_attr, - hints->rx_attr); - break; - case FI_EP_DGRAM: - caps = sock_dgram_info.caps; - ret = sock_dgram_verify_ep_attr(hints->ep_attr, - hints->tx_attr, - hints->rx_attr); - break; - case FI_EP_RDM: - caps = sock_rdm_info.caps; - ret = sock_rdm_verify_ep_attr(hints->ep_attr, - hints->tx_attr, - hints->rx_attr); - break; - default: - ret = -FI_ENODATA; - } - if (ret) - return ret; - - if ((caps | hints->caps) != caps) { - SOCK_LOG_DBG("Unsupported capabilities\n"); - return -FI_ENODATA; - } - - switch (hints->addr_format) { - case FI_FORMAT_UNSPEC: - case FI_SOCKADDR: - case FI_SOCKADDR_IN: - case FI_SOCKADDR_IN6: - break; - default: - SOCK_LOG_DBG("Unsupported address format\n"); - return -FI_ENODATA; - } - - if (hints->domain_attr && hints->domain_attr->domain) { - domain = container_of(hints->domain_attr->domain, - struct sock_domain, dom_fid); - if (!sock_dom_check_list(domain)) { - SOCK_LOG_DBG("no matching domain\n"); - return -FI_ENODATA; - } - } - ret = sock_verify_domain_attr(version, hints); - if (ret) - return ret; - - if (hints->fabric_attr && hints->fabric_attr->fabric) { - fabric = container_of(hints->fabric_attr->fabric, - struct sock_fabric, fab_fid); - if (!sock_fab_check_list(fabric)) { - SOCK_LOG_DBG("no matching fabric\n"); - return -FI_ENODATA; - } - } - ret = sock_verify_fabric_attr(hints->fabric_attr); - if (ret) - return ret; - - return 0; -} - static int sock_trywait(struct fid_fabric *fabric, struct fid **fids, int count) { /* we're always ready to wait! */ @@ -404,282 +308,16 @@ int sock_get_src_addr(union ofi_sock_ip *dest_addr, return ret; } -static int sock_fi_checkinfo(const struct fi_info *info, - const struct fi_info *hints) -{ - if (hints && hints->domain_attr && hints->domain_attr->name && - strcmp(info->domain_attr->name, hints->domain_attr->name)) - return -FI_ENODATA; - - if (hints && hints->fabric_attr && hints->fabric_attr->name && - strcmp(info->fabric_attr->name, hints->fabric_attr->name)) - return -FI_ENODATA; - - return 0; -} - -static int sock_ep_getinfo(uint32_t version, const char *node, - const char *service, uint64_t flags, - const struct fi_info *hints, enum fi_ep_type ep_type, - struct fi_info **info) -{ - struct addrinfo ai, *rai = NULL; - union ofi_sock_ip *src_addr = NULL, *dest_addr = NULL; - union ofi_sock_ip sip; - int ret; - - switch (ep_type) { - case FI_EP_MSG: - ret = util_getinfo(&sock_msg_util_prov, version, node, service, - flags, hints, info); - break; - case FI_EP_RDM: - ret = util_getinfo(&sock_rdm_util_prov, version, node, service, - flags, hints, info); - break; - case FI_EP_DGRAM: - ret = util_getinfo(&sock_dgram_util_prov, version, node, service, - flags, hints, info); - break; - default: - ret = -FI_ENODATA; - break; - } - if (ret) - return ret; - - memset(&ai, 0, sizeof(ai)); - ai.ai_socktype = SOCK_STREAM; - ai.ai_family = ofi_get_sa_family(hints); - if (flags & FI_NUMERICHOST) - ai.ai_flags |= AI_NUMERICHOST; - - if (flags & FI_SOURCE) { - ai.ai_flags |= AI_PASSIVE; - ret = getaddrinfo(node, service, &ai, &rai); - if (ret) { - SOCK_LOG_DBG("getaddrinfo failed!\n"); - return -FI_ENODATA; - } - src_addr = (union ofi_sock_ip *) rai->ai_addr; - if (hints && hints->dest_addr) - dest_addr = hints->dest_addr; - } else { - if (node || service) { - ret = getaddrinfo(node, service, &ai, &rai); - if (ret) { - SOCK_LOG_DBG("getaddrinfo failed!\n"); - return -FI_ENODATA; - } - dest_addr = (union ofi_sock_ip *) rai->ai_addr; - } else if (hints) { - dest_addr = hints->dest_addr; - } - - if (hints && hints->src_addr) - src_addr = hints->src_addr; - } - - if (dest_addr && !src_addr) { - ret = sock_get_src_addr(dest_addr, &sip); - if (!ret) - src_addr = &sip; - } - - if (dest_addr) { - ofi_straddr_log(&sock_prov, FI_LOG_INFO, FI_LOG_CORE, - "dest addr: ", dest_addr); - } - if (src_addr) { - ofi_straddr_log(&sock_prov, FI_LOG_INFO, FI_LOG_CORE, - "src addr: ", src_addr); - } - - if (rai) - freeaddrinfo(rai); - - if (ret == 0) { - ret = sock_fi_checkinfo(*info, hints); - if (ret) - fi_freeinfo(*info); - } - - return ret; -} - -static void sock_init_addrlist(void) -{ - fastlock_acquire(&sock_list_lock); - if (slist_empty(&sock_addr_list)) - ofi_get_list_of_addr(&sock_prov, "iface", &sock_addr_list); - fastlock_release(&sock_list_lock); -} - -int sock_node_getinfo(uint32_t version, const char *node, const char *service, - uint64_t flags, const struct fi_info *hints, struct fi_info **info, - struct fi_info **tail) -{ - enum fi_ep_type ep_type; - struct fi_info *cur; - int ret; - - if (hints && hints->ep_attr) { - switch (hints->ep_attr->type) { - case FI_EP_RDM: - case FI_EP_DGRAM: - case FI_EP_MSG: - ret = sock_ep_getinfo(version, node, service, flags, - hints, hints->ep_attr->type, &cur); - if (ret) { - if (ret == -FI_ENODATA) - return ret; - goto err; - } - - if (!*info) - *info = cur; - else - (*tail)->next = cur; - (*tail) = cur; - return 0; - default: - break; - } - } - - for (ep_type = FI_EP_MSG; ep_type <= FI_EP_RDM; ep_type++) { - ret = sock_ep_getinfo(version, node, service, flags, hints, - ep_type, &cur); - if (ret) { - if (ret == -FI_ENODATA) - continue; - goto err; - } - - if (!*info) - *info = cur; - else - (*tail)->next = cur; - (*tail) = cur; - } - if (!*info) { - ret = -FI_ENODATA; - goto err_no_free; - } - return 0; - -err: - fi_freeinfo(*info); - *info = NULL; -err_no_free: - return ret; -} - -static int sock_match_src_addr(struct slist_entry *entry, const void *src_addr) -{ - struct ofi_addr_list_entry *host_entry = - container_of(entry, struct ofi_addr_list_entry, entry); - - return ofi_equals_ipaddr(&host_entry->ipaddr.sa, src_addr); -} - -static int sock_addr_matches_interface(struct slist *addr_list, - struct sockaddr *src_addr) -{ - struct slist_entry *entry; - - /* Always match if it's localhost */ - if (ofi_is_loopback_addr(src_addr)) - return 1; - - entry = slist_find_first_match(addr_list, sock_match_src_addr, src_addr); - return entry ? 1 : 0; -} - -static int sock_node_matches_interface(struct slist *addr_list, const char *node) -{ - union ofi_sock_ip addr; - struct addrinfo *rai = NULL, ai = { - .ai_socktype = SOCK_STREAM, - }; - - if (getaddrinfo(node, 0, &ai, &rai)) { - SOCK_LOG_DBG("getaddrinfo failed!\n"); - return -FI_EINVAL; - } - if (rai->ai_addrlen > sizeof(addr)) { - freeaddrinfo(rai); - return -FI_EINVAL; - } - - memset(&addr, 0, sizeof addr); - memcpy(&addr, rai->ai_addr, rai->ai_addrlen); - freeaddrinfo(rai); - - return sock_addr_matches_interface(addr_list, &addr.sa); -} - static int sock_getinfo(uint32_t version, const char *node, const char *service, uint64_t flags, const struct fi_info *hints, struct fi_info **info) { - int ret = 0; - struct slist_entry *entry, *prev; - struct ofi_addr_list_entry *host_entry; - struct fi_info *tail; - - if (!(flags & FI_SOURCE) && hints && hints->src_addr && - (hints->src_addrlen != ofi_sizeofaddr(hints->src_addr))) - return -FI_ENODATA; - - if (((!node && !service) || (flags & FI_SOURCE)) && - hints && hints->dest_addr && - (hints->dest_addrlen != ofi_sizeofaddr(hints->dest_addr))) - return -FI_ENODATA; - - ret = sock_verify_info(version, hints); - if (ret) - return ret; - - ret = 1; - sock_init_addrlist(); - if ((flags & FI_SOURCE) && node) { - ret = sock_node_matches_interface(&sock_addr_list, node); - } else if (hints && hints->src_addr) { - ret = sock_addr_matches_interface(&sock_addr_list, - hints->src_addr); - } - if (!ret) { - SOCK_LOG_ERROR("Couldn't find a match with local interfaces\n"); - return -FI_ENODATA; - } - - *info = tail = NULL; - if (node || - (!(flags & FI_SOURCE) && hints && hints->src_addr) || - (!(flags & FI_SOURCE) && hints && hints->dest_addr)) - return sock_node_getinfo(version, node, service, flags, - hints, info, &tail); - - (void) prev; /* Makes compiler happy */ - slist_foreach(&sock_addr_list, entry, prev) { - host_entry = container_of(entry, struct ofi_addr_list_entry, entry); - node = host_entry->ipstr; - flags |= FI_SOURCE; - ret = sock_node_getinfo(version, node, service, flags, hints, info, &tail); - if (ret) { - if (ret == -FI_ENODATA) - continue; - return ret; - } - } - - return (!*info) ? ret : 0; + return ofi_ip_getinfo(&sock_util_prov, version, node, service, flags, + hints, info); } static void fi_sockets_fini(void) { - ofi_free_list_of_addr(&sock_addr_list); fastlock_destroy(&sock_list_lock); } @@ -692,19 +330,7 @@ struct fi_provider sock_prov = { .cleanup = fi_sockets_fini }; -struct util_prov sock_msg_util_prov = { - .prov = &sock_prov, - .info = &sock_msg_info, - .flags = 0, -}; - -struct util_prov sock_rdm_util_prov = { - .prov = &sock_prov, - .info = &sock_rdm_info, - .flags = 0, -}; - -struct util_prov sock_dgram_util_prov = { +struct util_prov sock_util_prov = { .prov = &sock_prov, .info = &sock_dgram_info, .flags = 0, @@ -759,7 +385,6 @@ SOCKETS_INI fastlock_init(&sock_list_lock); dlist_init(&sock_fab_list); dlist_init(&sock_dom_list); - slist_init(&sock_addr_list); #if ENABLE_DEBUG fi_param_define(&sock_prov, "dgram_drop_rate", FI_PARAM_INT, "Drop every Nth dgram frame (debug only)");