diff --git a/ompi/mca/btl/tcp/btl_tcp_proc.c b/ompi/mca/btl/tcp/btl_tcp_proc.c index 07e21e6af3..cce2944b4e 100644 --- a/ompi/mca/btl/tcp/btl_tcp_proc.c +++ b/ompi/mca/btl/tcp/btl_tcp_proc.c @@ -224,7 +224,7 @@ int mca_btl_tcp_proc_insert( mca_btl_tcp_proc_tosocks (endpoint_addr, &endpoint_addr_ss); /* The best we could get is IPv4 public. So let's check */ - if (true == mca_oob_tcp_addr_isipv4public (&endpoint_addr_ss)) { + if (true == opal_addr_isipv4public (&endpoint_addr_ss)) { btl_endpoint->endpoint_addr = endpoint_addr; btl_endpoint->endpoint_addr->addr_inuse++; return OMPI_SUCCESS; @@ -280,7 +280,7 @@ int mca_btl_tcp_proc_insert( * Let's talk about IPv4 _private_, so isipv4public must * return false */ - if (false == mca_oob_tcp_addr_isipv4public (&local_ss)) { + if (false == opal_addr_isipv4public (&local_ss)) { if (opal_samenetwork(&local_ss, &endpoint_addr_ss, netmask)) { btl_endpoint->endpoint_addr = endpoint_addr; btl_endpoint->endpoint_addr->addr_inuse++; diff --git a/opal/util/if.c b/opal/util/if.c index 1078c7dab7..d41e0ed45e 100644 --- a/opal/util/if.c +++ b/opal/util/if.c @@ -1375,6 +1375,44 @@ opal_ifislocal(char *hostname) return false; } + +/** + * Returns true if the given address is a public IPv4 address. + */ +bool opal_addr_isipv4public (struct sockaddr_storage *addr) +{ + switch (addr->ss_family) { +#if OPAL_WANT_IPV6 + case AF_INET6: + return false; +#endif + case AF_INET: + { + struct sockaddr_in *inaddr = (struct sockaddr_in*) addr; + /* RFC1918 defines + - 10.0.0./8 + - 172.16.0.0/12 + - 192.168.0.0/16 + + RFC3330 also mentiones + - 169.254.0.0/16 for DHCP onlink iff there's no DHCP server + */ + if ((htonl(0x0a000000) == (inaddr->sin_addr.s_addr & opal_prefix2netmask(8))) || + (htonl(0xac100000) == (inaddr->sin_addr.s_addr & opal_prefix2netmask(12))) || + (htonl(0xc0a80000) == (inaddr->sin_addr.s_addr & opal_prefix2netmask(16))) || + (htonl(0xa9fe0000) == (inaddr->sin_addr.s_addr & opal_prefix2netmask(16)))) { + return false; + } + } + return true; + default: + opal_output (0, + "unhandled sa_family %d passed to mca_oob_tcp_addr_isipv4public\n", + addr->ss_family); + } + + return false; +} #else /* HAVE_STRUCT_SOCKADDR_IN */ /* if we don't have struct sockaddr_in, we don't have traditional @@ -1480,4 +1518,9 @@ opal_iffinalize(void) return OPAL_SUCCESS; } +bool +opal_addr_isipv4public (struct sockaddr_storage *addr) +{ + return false; +} #endif /* HAVE_STRUCT_SOCKADDR_IN */ diff --git a/opal/util/if.h b/opal/util/if.h index 0851435eac..7fa1221117 100644 --- a/opal/util/if.h +++ b/opal/util/if.h @@ -209,6 +209,14 @@ OPAL_DECLSPEC char* opal_sockaddr2str(struct sockaddr_in6 *addr1); */ OPAL_DECLSPEC int opal_iffinalize(void); +/** + * Is the given address a public IPv4 address? + * + * @param addr address as struct sockaddr_storage + * @return true, if \c addr is IPv4 public, false otherwise + */ +OPAL_DECLSPEC bool opal_addr_isipv4public(struct sockaddr_storage *addr); + #if defined(c_plusplus) || defined(__cplusplus) } #endif diff --git a/orte/mca/oob/tcp/oob_tcp_addr.c b/orte/mca/oob/tcp/oob_tcp_addr.c index 7d99a4b62a..616d36aa66 100644 --- a/orte/mca/oob/tcp/oob_tcp_addr.c +++ b/orte/mca/oob/tcp/oob_tcp_addr.c @@ -276,11 +276,11 @@ int mca_oob_tcp_addr_get_next(mca_oob_tcp_addr_t* addr, struct sockaddr_storage* - when IPv4private + IPv6, use IPv6 (this should be changed when there is something like a CellID) */ - if (true == mca_oob_tcp_addr_isipv4public (&inaddr)) { + if (true == opal_addr_isipv4public (&inaddr)) { i_have |= MCA_OOB_TCP_ADDR_IPV4public; } - if (true == mca_oob_tcp_addr_isipv4public ((struct sockaddr_storage*)&addr->addr_inet[i])) { + if (true == opal_addr_isipv4public ((struct sockaddr_storage*)&addr->addr_inet[i])) { addr->addr_matched |= MCA_OOB_TCP_ADDR_IPV4public; } @@ -365,38 +365,3 @@ int mca_oob_tcp_addr_insert(mca_oob_tcp_addr_t* addr, const struct sockaddr_in* addr->addr_count++; return ORTE_SUCCESS; } - -bool mca_oob_tcp_addr_isipv4public (struct sockaddr_storage *addr) -{ - switch (addr->ss_family) { -#if OPAL_WANT_IPV6 - case AF_INET6: - return false; -#endif - case AF_INET: - { - struct sockaddr_in *inaddr = (struct sockaddr_in*) addr; - /* RFC1918 defines - - 10.0.0./8 - - 172.16.0.0/12 - - 192.168.0.0/16 - - RFC3330 also mentiones - - 169.254.0.0/16 for DHCP onlink iff there's no DHCP server - */ - if ((htonl(0x0a000000) == (inaddr->sin_addr.s_addr & opal_prefix2netmask(8))) || - (htonl(0xac100000) == (inaddr->sin_addr.s_addr & opal_prefix2netmask(12))) || - (htonl(0xc0a80000) == (inaddr->sin_addr.s_addr & opal_prefix2netmask(16))) || - (htonl(0xa9fe0000) == (inaddr->sin_addr.s_addr & opal_prefix2netmask(16)))) { - return false; - } - } - return true; - default: - opal_output (0, - "unhandled sa_family %d passed to mca_oob_tcp_addr_isipv4public\n", - addr->ss_family); - } - - return false; -} diff --git a/orte/mca/oob/tcp/oob_tcp_addr.h b/orte/mca/oob/tcp/oob_tcp_addr.h index b6b1677052..a3f62e3e59 100644 --- a/orte/mca/oob/tcp/oob_tcp_addr.h +++ b/orte/mca/oob/tcp/oob_tcp_addr.h @@ -96,11 +96,6 @@ int mca_oob_tcp_addr_insert(mca_oob_tcp_addr_t*, const struct sockaddr_in*); int mca_oob_tcp_addr_get_next(mca_oob_tcp_addr_t*, struct sockaddr_storage*); -/** - * Returns true if the given address is a public IPv4 address. - */ -bool mca_oob_tcp_addr_isipv4public(struct sockaddr_storage*); - #if defined(c_plusplus) || defined(__cplusplus) }