This commit looks much bigger than it is. There are only 2
substantive changes in this commit; the rest are minor style changes: 1. Change an OBJ_NEW(opal_list_item_t) to OBJ_NEW(opal_if_t). This was causing memory corruption in the BSD code paths. 1. Move some local variables from the top of opal_if_init() to inside the non-BSD code paths so that we avoid bunches of warnings about unused variables when compiling on BSD. In doing so, I indented the whole non-BSD section one level deeper, making the commit look huge. I also added a few {} around 1-line blocks, added some spaces, broke a few lines, re-formatted a few comments, ...etc. Trivial stuff. This commit was SVN r23501.
Этот коммит содержится в:
родитель
b3a8a394f0
Коммит
0ce1a82cde
@ -147,13 +147,7 @@ static int prefix (uint32_t netmask)
|
|||||||
static int opal_ifinit(void)
|
static int opal_ifinit(void)
|
||||||
{
|
{
|
||||||
#ifndef __WINDOWS__
|
#ifndef __WINDOWS__
|
||||||
|
int flag;
|
||||||
int sd;
|
|
||||||
int lastlen, num, rem;
|
|
||||||
char *ptr;
|
|
||||||
struct ifconf ifconf;
|
|
||||||
int ifc_len;
|
|
||||||
bool successful_locate = false;
|
|
||||||
|
|
||||||
if (already_done) {
|
if (already_done) {
|
||||||
return OPAL_SUCCESS;
|
return OPAL_SUCCESS;
|
||||||
@ -162,8 +156,8 @@ static int opal_ifinit(void)
|
|||||||
|
|
||||||
mca_base_param_reg_int_name("opal", "if_do_not_resolve",
|
mca_base_param_reg_int_name("opal", "if_do_not_resolve",
|
||||||
"If nonzero, do not attempt to resolve interfaces",
|
"If nonzero, do not attempt to resolve interfaces",
|
||||||
false, false, (int)false, &sd);
|
false, false, (int)false, &flag);
|
||||||
do_not_resolve = OPAL_INT_TO_BOOL(sd);
|
do_not_resolve = OPAL_INT_TO_BOOL(flag);
|
||||||
|
|
||||||
OBJ_CONSTRUCT(&opal_if_list, opal_list_t);
|
OBJ_CONSTRUCT(&opal_if_list, opal_list_t);
|
||||||
|
|
||||||
@ -214,7 +208,7 @@ static int opal_ifinit(void)
|
|||||||
|
|
||||||
sin_addr = (struct sockaddr_in *) cur_ifaddrs->ifa_addr;
|
sin_addr = (struct sockaddr_in *) cur_ifaddrs->ifa_addr;
|
||||||
|
|
||||||
intf = OBJ_NEW(opal_list_item_t);
|
intf = OBJ_NEW(opal_if_t);
|
||||||
if (NULL == intf) {
|
if (NULL == intf) {
|
||||||
opal_output(0, "opal_ifinit: unable to allocate %lu bytes\n",
|
opal_output(0, "opal_ifinit: unable to allocate %lu bytes\n",
|
||||||
sizeof(opal_if_t));
|
sizeof(opal_if_t));
|
||||||
@ -230,43 +224,32 @@ static int opal_ifinit(void)
|
|||||||
((struct sockaddr_in*) &intf->if_addr)->sin_family = AF_INET;
|
((struct sockaddr_in*) &intf->if_addr)->sin_family = AF_INET;
|
||||||
((struct sockaddr_in*) &intf->if_addr)->sin_len = cur_ifaddrs->ifa_addr->sa_len;
|
((struct sockaddr_in*) &intf->if_addr)->sin_len = cur_ifaddrs->ifa_addr->sa_len;
|
||||||
|
|
||||||
/* since every scope != 0 is ignored, we just set the scope to 0 */
|
|
||||||
/* There's no scope_id in the non-ipv6 stuff
|
|
||||||
((struct sockaddr_in6*) &intf->if_addr)->sin6_scope_id = 0;
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* hardcoded netmask, adrian says that's ok
|
|
||||||
*/
|
|
||||||
/* Non-NetBSD uses intf->if_mask = prefix(((struct sockaddr_in*) &ifr->ifr_addr)->sin_addr.s_addr); */
|
|
||||||
/* intf->if_mask = 64; */
|
|
||||||
intf->if_mask = prefix( sin_addr->sin_addr.s_addr);
|
intf->if_mask = prefix( sin_addr->sin_addr.s_addr);
|
||||||
intf->if_flags = cur_ifaddrs->ifa_flags;
|
intf->if_flags = cur_ifaddrs->ifa_flags;
|
||||||
|
|
||||||
/*
|
|
||||||
* FIXME: figure out how to gain access to the kernel index
|
|
||||||
* (or create our own), getifaddrs() does not contain such
|
|
||||||
* data
|
|
||||||
*/
|
|
||||||
intf->if_kernel_index =
|
intf->if_kernel_index =
|
||||||
(uint16_t) if_nametoindex(cur_ifaddrs->ifa_name);
|
(uint16_t) if_nametoindex(cur_ifaddrs->ifa_name);
|
||||||
|
|
||||||
opal_list_append(&opal_if_list, &(intf->super));
|
opal_list_append(&opal_if_list, &(intf->super));
|
||||||
} /* of for loop over ifaddrs list */
|
} /* of for loop over ifaddrs list */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/* End of various flavors of BSD */
|
||||||
#else
|
#else
|
||||||
/* create the internet socket to test off */
|
/* Beginning of !(various flavors of BSD) */
|
||||||
/*
|
{
|
||||||
Change AF_INET to AF_UNSPEC (or AF_INET6) and everything will fail.
|
int sd;
|
||||||
|
int lastlen, num, rem;
|
||||||
|
char *ptr;
|
||||||
|
struct ifconf ifconf;
|
||||||
|
int ifc_len;
|
||||||
|
bool successful_locate = false;
|
||||||
|
|
||||||
Note that Linux does not support AF_INET6 here, but *BSD (and OSX)
|
/* Create the internet socket to test with. Must use AF_INET;
|
||||||
probably would.
|
using AF_UNSPEC or AF_INET6 will cause everything to
|
||||||
|
fail. */
|
||||||
ifconf would be replaced by lifconf, SIOCG* by SIOCGL*.
|
|
||||||
*/
|
|
||||||
if ((sd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
|
if ((sd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
|
||||||
opal_output(0, "opal_ifinit: socket() failed with errno=%d\n", errno);
|
opal_output(0, "opal_ifinit: socket() failed with errno=%d\n",
|
||||||
|
errno);
|
||||||
return OPAL_ERROR;
|
return OPAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,8 +299,9 @@ static int opal_ifinit(void)
|
|||||||
return OPAL_ERROR;
|
return OPAL_ERROR;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* if ifc_len is 0 or different than what we set it to at
|
/* if ifc_len is 0 or different than what we set it to
|
||||||
call to ioctl, try again with a bigger buffer. else stop */
|
at call to ioctl, try again with a bigger buffer.
|
||||||
|
else stop */
|
||||||
if (ifconf.ifc_len == lastlen && ifconf.ifc_len > 0) {
|
if (ifconf.ifc_len == lastlen && ifconf.ifc_len > 0) {
|
||||||
/* we didn't expand. we're done */
|
/* we didn't expand. we're done */
|
||||||
successful_locate = true;
|
successful_locate = true;
|
||||||
@ -326,8 +310,8 @@ static int opal_ifinit(void)
|
|||||||
lastlen = ifconf.ifc_len;
|
lastlen = ifconf.ifc_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Yes, we overflowed (or had an EINVAL on the ioctl). Loop
|
/* Yes, we overflowed (or had an EINVAL on the ioctl).
|
||||||
back around and try again with a bigger buffer */
|
Loop back around and try again with a bigger buffer */
|
||||||
free(ifconf.ifc_req);
|
free(ifconf.ifc_req);
|
||||||
ifc_len = (ifc_len == 0) ? 1 : ifc_len * 2;
|
ifc_len = (ifc_len == 0) ? 1 : ifc_len * 2;
|
||||||
} while (ifc_len < MAX_IFCONF_SIZE);
|
} while (ifc_len < MAX_IFCONF_SIZE);
|
||||||
@ -382,17 +366,20 @@ static int opal_ifinit(void)
|
|||||||
opal_output(0, "opal_ifinit: ioctl(SIOCGIFFLAGS) failed with errno=%d", errno);
|
opal_output(0, "opal_ifinit: ioctl(SIOCGIFFLAGS) failed with errno=%d", errno);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ((ifr->ifr_flags & IFF_UP) == 0)
|
if ((ifr->ifr_flags & IFF_UP) == 0) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
#ifdef IFF_SLAVE
|
#ifdef IFF_SLAVE
|
||||||
/* Is this a slave to a load balancer or bonded channel?
|
/* Is this a slave to a load balancer or bonded channel?
|
||||||
If so, don't use it -- pick up the master instead */
|
If so, don't use it -- pick up the master instead */
|
||||||
if ((ifr->ifr_flags & IFF_SLAVE) != 0)
|
if ((ifr->ifr_flags & IFF_SLAVE) != 0) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#if 0
|
#if 0
|
||||||
if ((ifr->ifr_flags & IFF_LOOPBACK) != 0)
|
if ((ifr->ifr_flags & IFF_LOOPBACK) != 0) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* copy entry over into our data structure */
|
/* copy entry over into our data structure */
|
||||||
@ -419,7 +406,8 @@ static int opal_ifinit(void)
|
|||||||
#endif
|
#endif
|
||||||
#endif /* SIOCGIFINDEX */
|
#endif /* SIOCGIFINDEX */
|
||||||
|
|
||||||
/* This call returns IPv4 addresses only. Use SIOCGLIFADDR instead */
|
/* This call returns IPv4 addresses only. Use SIOCGLIFADDR
|
||||||
|
instead */
|
||||||
if (ioctl(sd, SIOCGIFADDR, ifr) < 0) {
|
if (ioctl(sd, SIOCGIFADDR, ifr) < 0) {
|
||||||
opal_output(0, "opal_ifinit: ioctl(SIOCGIFADDR) failed with errno=%d", errno);
|
opal_output(0, "opal_ifinit: ioctl(SIOCGIFADDR) failed with errno=%d", errno);
|
||||||
break;
|
break;
|
||||||
@ -443,10 +431,9 @@ static int opal_ifinit(void)
|
|||||||
}
|
}
|
||||||
free(ifconf.ifc_req);
|
free(ifconf.ifc_req);
|
||||||
close(sd);
|
close(sd);
|
||||||
|
}
|
||||||
#endif /* anything other than {Net,Open,Free}BSD and DragonFly */
|
#endif /* anything other than {Net,Open,Free}BSD and DragonFly */
|
||||||
|
|
||||||
|
|
||||||
#if OPAL_WANT_IPV6
|
#if OPAL_WANT_IPV6
|
||||||
#ifdef __linux__ /* Linux does not have SIOCGL*, so parse
|
#ifdef __linux__ /* Linux does not have SIOCGL*, so parse
|
||||||
/proc/net/if_inet6 instead */
|
/proc/net/if_inet6 instead */
|
||||||
@ -639,7 +626,6 @@ static int opal_ifinit(void)
|
|||||||
(uint16_t) if_nametoindex(cur_ifaddrs->ifa_name);
|
(uint16_t) if_nametoindex(cur_ifaddrs->ifa_name);
|
||||||
opal_list_append(&opal_if_list, &(intf->super));
|
opal_list_append(&opal_if_list, &(intf->super));
|
||||||
} /* of for loop over ifaddrs list */
|
} /* of for loop over ifaddrs list */
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif /* bsd, macosx */
|
#endif /* bsd, macosx */
|
||||||
|
|
||||||
@ -1382,8 +1368,9 @@ bool opal_ifisloopback(int if_index)
|
|||||||
{
|
{
|
||||||
opal_if_t* intf;
|
opal_if_t* intf;
|
||||||
int rc = opal_ifinit();
|
int rc = opal_ifinit();
|
||||||
if(rc != OPAL_SUCCESS)
|
if (rc != OPAL_SUCCESS) {
|
||||||
return rc;
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
for (intf = (opal_if_t*)opal_list_get_first(&opal_if_list);
|
for (intf = (opal_if_t*)opal_list_get_first(&opal_if_list);
|
||||||
intf != (opal_if_t*)opal_list_get_end(&opal_if_list);
|
intf != (opal_if_t*)opal_list_get_end(&opal_if_list);
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user