1
1

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.
Этот коммит содержится в:
Jeff Squyres 2010-07-27 13:46:55 +00:00
родитель b3a8a394f0
Коммит 0ce1a82cde

Просмотреть файл

@ -147,13 +147,7 @@ static int prefix (uint32_t netmask)
static int opal_ifinit(void)
{
#ifndef __WINDOWS__
int sd;
int lastlen, num, rem;
char *ptr;
struct ifconf ifconf;
int ifc_len;
bool successful_locate = false;
int flag;
if (already_done) {
return OPAL_SUCCESS;
@ -162,8 +156,8 @@ static int opal_ifinit(void)
mca_base_param_reg_int_name("opal", "if_do_not_resolve",
"If nonzero, do not attempt to resolve interfaces",
false, false, (int)false, &sd);
do_not_resolve = OPAL_INT_TO_BOOL(sd);
false, false, (int)false, &flag);
do_not_resolve = OPAL_INT_TO_BOOL(flag);
OBJ_CONSTRUCT(&opal_if_list, opal_list_t);
@ -183,24 +177,24 @@ static int opal_ifinit(void)
ifadd_list = (struct ifaddrs **) malloc(sizeof(struct ifaddrs*));
/* create the linked list of ifaddrs structs */
if(getifaddrs(ifadd_list) < 0) {
if (getifaddrs(ifadd_list) < 0) {
opal_output(0, "opal_ifinit: getifaddrs() failed with error=%d\n",
errno);
return OPAL_ERROR;
}
for(cur_ifaddrs = *ifadd_list; NULL != cur_ifaddrs;
for (cur_ifaddrs = *ifadd_list; NULL != cur_ifaddrs;
cur_ifaddrs = cur_ifaddrs->ifa_next) {
opal_if_t *intf;
struct in_addr a4;
/* skip non- af_inet interface addresses */
if(AF_INET != cur_ifaddrs->ifa_addr->sa_family) {
if (AF_INET != cur_ifaddrs->ifa_addr->sa_family) {
continue;
}
/* skip interface if it is down (IFF_UP not set) */
if(0 == (cur_ifaddrs->ifa_flags & IFF_UP)) {
if (0 == (cur_ifaddrs->ifa_flags & IFF_UP)) {
continue;
}
@ -214,7 +208,7 @@ static int opal_ifinit(void)
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) {
opal_output(0, "opal_ifinit: unable to allocate %lu bytes\n",
sizeof(opal_if_t));
@ -230,223 +224,216 @@ static int opal_ifinit(void)
((struct sockaddr_in*) &intf->if_addr)->sin_family = AF_INET;
((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_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 =
(uint16_t) if_nametoindex(cur_ifaddrs->ifa_name);
opal_list_append(&opal_if_list, &(intf->super));
} /* of for loop over ifaddrs list */
}
/* End of various flavors of BSD */
#else
/* create the internet socket to test off */
/*
Change AF_INET to AF_UNSPEC (or AF_INET6) and everything will fail.
/* Beginning of !(various flavors of BSD) */
{
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)
probably would.
ifconf would be replaced by lifconf, SIOCG* by SIOCGL*.
*/
if((sd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
opal_output(0, "opal_ifinit: socket() failed with errno=%d\n", errno);
return OPAL_ERROR;
}
/*
* Get Network Interface configuration
*
* Some notes on the behavior of ioctl(..., SIOCGIFCONF,...)
* when not enough space is allocated for all the entries.
*
* - Solaris returns -1, errno EINVAL if there is not enough
* space
* - OS X returns 0, sets .ifc_len to the space used by the
* by the entries that did fit.
* - Linux returns 0, sets .ifc_len to the space required to
* hold all the entries (although it only writes what will
* fit in the buffer of .ifc_len passed to the function).
* - FreeBSD returns 0, sets .ifc_len to 0.
*
* Everyone else seems to do one of the four.
*/
lastlen = 0;
ifc_len = sizeof(struct ifreq) * DEFAULT_NUMBER_INTERFACES;
do {
ifconf.ifc_len = ifc_len;
ifconf.ifc_req = malloc(ifc_len);
if (NULL == ifconf.ifc_req) {
close(sd);
/* Create the internet socket to test with. Must use AF_INET;
using AF_UNSPEC or AF_INET6 will cause everything to
fail. */
if ((sd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
opal_output(0, "opal_ifinit: socket() failed with errno=%d\n",
errno);
return OPAL_ERROR;
}
/* initialize the memory so valgrind and purify won't
* complain. Since this isn't performance critical, just
* always memset.
/*
* Get Network Interface configuration
*
* Some notes on the behavior of ioctl(..., SIOCGIFCONF,...)
* when not enough space is allocated for all the entries.
*
* - Solaris returns -1, errno EINVAL if there is not enough
* space
* - OS X returns 0, sets .ifc_len to the space used by the
* by the entries that did fit.
* - Linux returns 0, sets .ifc_len to the space required to
* hold all the entries (although it only writes what will
* fit in the buffer of .ifc_len passed to the function).
* - FreeBSD returns 0, sets .ifc_len to 0.
*
* Everyone else seems to do one of the four.
*/
memset(ifconf.ifc_req, 0, ifconf.ifc_len);
if(ioctl(sd, SIOCGIFCONF, &ifconf) < 0) {
/* if we got an einval, we probably don't have enough
space. so we'll fall down and try to expand our
space */
if (errno != EINVAL && lastlen != 0) {
opal_output(0, "opal_ifinit: ioctl(SIOCGIFCONF) \
failed with errno=%d",
errno);
free(ifconf.ifc_req);
lastlen = 0;
ifc_len = sizeof(struct ifreq) * DEFAULT_NUMBER_INTERFACES;
do {
ifconf.ifc_len = ifc_len;
ifconf.ifc_req = malloc(ifc_len);
if (NULL == ifconf.ifc_req) {
close(sd);
return OPAL_ERROR;
}
} else {
/* if ifc_len is 0 or different than what we set it to at
call to ioctl, try again with a bigger buffer. else stop */
if (ifconf.ifc_len == lastlen && ifconf.ifc_len > 0) {
/* we didn't expand. we're done */
successful_locate = true;
break;
/* initialize the memory so valgrind and purify won't
* complain. Since this isn't performance critical, just
* always memset.
*/
memset(ifconf.ifc_req, 0, ifconf.ifc_len);
if (ioctl(sd, SIOCGIFCONF, &ifconf) < 0) {
/* if we got an einval, we probably don't have enough
space. so we'll fall down and try to expand our
space */
if (errno != EINVAL && lastlen != 0) {
opal_output(0, "opal_ifinit: ioctl(SIOCGIFCONF) \
failed with errno=%d",
errno);
free(ifconf.ifc_req);
close(sd);
return OPAL_ERROR;
}
} else {
/* if ifc_len is 0 or different than what we set it to
at call to ioctl, try again with a bigger buffer.
else stop */
if (ifconf.ifc_len == lastlen && ifconf.ifc_len > 0) {
/* we didn't expand. we're done */
successful_locate = true;
break;
}
lastlen = ifconf.ifc_len;
}
lastlen = ifconf.ifc_len;
}
/* Yes, we overflowed (or had an EINVAL on the ioctl). Loop
back around and try again with a bigger buffer */
free(ifconf.ifc_req);
ifc_len = (ifc_len == 0) ? 1 : ifc_len * 2;
} while (ifc_len < MAX_IFCONF_SIZE);
if (!successful_locate) {
opal_output(0, "opal_ifinit: unable to find network interfaces.");
return OPAL_ERR_FATAL;
}
/*
* Setup indexes
*/
ptr = (char*) ifconf.ifc_req;
rem = ifconf.ifc_len;
num = 0;
/* loop through all interfaces */
while (rem > 0) {
struct ifreq* ifr = (struct ifreq*) ptr;
opal_if_t *intf;
int length;
intf = OBJ_NEW(opal_if_t);
if (NULL == intf) {
opal_output(0, "opal_ifinit: unable to allocated %lu bytes\n", (unsigned long)sizeof(opal_if_t));
/* Yes, we overflowed (or had an EINVAL on the ioctl).
Loop back around and try again with a bigger buffer */
free(ifconf.ifc_req);
close(sd);
return OPAL_ERR_OUT_OF_RESOURCE;
ifc_len = (ifc_len == 0) ? 1 : ifc_len * 2;
} while (ifc_len < MAX_IFCONF_SIZE);
if (!successful_locate) {
opal_output(0, "opal_ifinit: unable to find network interfaces.");
return OPAL_ERR_FATAL;
}
/* compute offset for entries */
/*
* Setup indexes
*/
ptr = (char*) ifconf.ifc_req;
rem = ifconf.ifc_len;
num = 0;
/* loop through all interfaces */
while (rem > 0) {
struct ifreq* ifr = (struct ifreq*) ptr;
opal_if_t *intf;
int length;
intf = OBJ_NEW(opal_if_t);
if (NULL == intf) {
opal_output(0, "opal_ifinit: unable to allocated %lu bytes\n", (unsigned long)sizeof(opal_if_t));
free(ifconf.ifc_req);
close(sd);
return OPAL_ERR_OUT_OF_RESOURCE;
}
/* compute offset for entries */
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
length = sizeof(struct sockaddr);
if (ifr->ifr_addr.sa_len > length) {
length = ifr->ifr_addr.sa_len;
}
length += sizeof(ifr->ifr_name);
length = sizeof(struct sockaddr);
if (ifr->ifr_addr.sa_len > length) {
length = ifr->ifr_addr.sa_len;
}
length += sizeof(ifr->ifr_name);
#else
length = sizeof(struct ifreq);
length = sizeof(struct ifreq);
#endif
rem -= length;
ptr += length;
/* see if we like this entry */
if(AF_INET != ifr->ifr_addr.sa_family) {
continue;
}
if(ioctl(sd, SIOCGIFFLAGS, ifr) < 0) {
opal_output(0, "opal_ifinit: ioctl(SIOCGIFFLAGS) failed with errno=%d", errno);
continue;
}
if ((ifr->ifr_flags & IFF_UP) == 0)
continue;
rem -= length;
ptr += length;
/* see if we like this entry */
if (AF_INET != ifr->ifr_addr.sa_family) {
continue;
}
if (ioctl(sd, SIOCGIFFLAGS, ifr) < 0) {
opal_output(0, "opal_ifinit: ioctl(SIOCGIFFLAGS) failed with errno=%d", errno);
continue;
}
if ((ifr->ifr_flags & IFF_UP) == 0) {
continue;
}
#ifdef IFF_SLAVE
/* Is this a slave to a load balancer or bonded channel?
If so, don't use it -- pick up the master instead */
if ((ifr->ifr_flags & IFF_SLAVE) != 0)
continue;
/* Is this a slave to a load balancer or bonded channel?
If so, don't use it -- pick up the master instead */
if ((ifr->ifr_flags & IFF_SLAVE) != 0) {
continue;
}
#endif
#if 0
if ((ifr->ifr_flags & IFF_LOOPBACK) != 0)
continue;
if ((ifr->ifr_flags & IFF_LOOPBACK) != 0) {
continue;
}
#endif
/* copy entry over into our data structure */
strcpy(intf->if_name, ifr->ifr_name);
intf->if_flags = ifr->ifr_flags;
/* every new address gets its own internal if_index */
intf->if_index = opal_list_get_size(&opal_if_list)+1;
/* assign the kernel index to distinguish different NICs */
/* copy entry over into our data structure */
strcpy(intf->if_name, ifr->ifr_name);
intf->if_flags = ifr->ifr_flags;
/* every new address gets its own internal if_index */
intf->if_index = opal_list_get_size(&opal_if_list)+1;
/* assign the kernel index to distinguish different NICs */
#ifndef SIOCGIFINDEX
intf->if_kernel_index = intf->if_index;
intf->if_kernel_index = intf->if_index;
#else
if(ioctl(sd, SIOCGIFINDEX, ifr) < 0) {
opal_output(0,"opal_ifinit: ioctl(SIOCGIFINDEX) failed with errno=%d", errno);
continue;
}
if (ioctl(sd, SIOCGIFINDEX, ifr) < 0) {
opal_output(0,"opal_ifinit: ioctl(SIOCGIFINDEX) failed with errno=%d", errno);
continue;
}
#if defined(ifr_ifindex)
intf->if_kernel_index = ifr->ifr_ifindex;
intf->if_kernel_index = ifr->ifr_ifindex;
#elif defined(ifr_index)
intf->if_kernel_index = ifr->ifr_index;
intf->if_kernel_index = ifr->ifr_index;
#else
intf->if_kernel_index = -1;
intf->if_kernel_index = -1;
#endif
#endif /* SIOCGIFINDEX */
/* This call returns IPv4 addresses only. Use SIOCGLIFADDR instead */
if(ioctl(sd, SIOCGIFADDR, ifr) < 0) {
opal_output(0, "opal_ifinit: ioctl(SIOCGIFADDR) failed with errno=%d", errno);
break;
/* This call returns IPv4 addresses only. Use SIOCGLIFADDR
instead */
if (ioctl(sd, SIOCGIFADDR, ifr) < 0) {
opal_output(0, "opal_ifinit: ioctl(SIOCGIFADDR) failed with errno=%d", errno);
break;
}
if (AF_INET != ifr->ifr_addr.sa_family) {
continue;
}
/* based on above, we know this is an IPv4 address... */
memcpy(&intf->if_addr, &ifr->ifr_addr, sizeof(struct sockaddr_in));
if (ioctl(sd, SIOCGIFNETMASK, ifr) < 0) {
opal_output(0, "opal_ifinit: ioctl(SIOCGIFNETMASK) failed with errno=%d", errno);
continue;
}
/* generate CIDR and assign to netmask */
intf->if_mask = prefix(((struct sockaddr_in*) &ifr->ifr_addr)->sin_addr.s_addr);
opal_list_append(&opal_if_list, &(intf->super));
}
if(AF_INET != ifr->ifr_addr.sa_family) {
continue;
}
/* based on above, we know this is an IPv4 address... */
memcpy(&intf->if_addr, &ifr->ifr_addr, sizeof(struct sockaddr_in));
if(ioctl(sd, SIOCGIFNETMASK, ifr) < 0) {
opal_output(0, "opal_ifinit: ioctl(SIOCGIFNETMASK) failed with errno=%d", errno);
continue;
}
/* generate CIDR and assign to netmask */
intf->if_mask = prefix(((struct sockaddr_in*) &ifr->ifr_addr)->sin_addr.s_addr);
opal_list_append(&opal_if_list, &(intf->super));
}
free(ifconf.ifc_req);
close(sd);
free(ifconf.ifc_req);
close(sd);
}
#endif /* anything other than {Net,Open,Free}BSD and DragonFly */
#if OPAL_WANT_IPV6
#ifdef __linux__ /* Linux does not have SIOCGL*, so parse
/proc/net/if_inet6 instead */
@ -539,19 +526,19 @@ static int opal_ifinit(void)
ifadd_list = (struct ifaddrs **) malloc(sizeof(struct ifaddrs*));
/* create the linked list of ifaddrs structs */
if(getifaddrs(ifadd_list) < 0) {
if (getifaddrs(ifadd_list) < 0) {
opal_output(0, "opal_ifinit: getifaddrs() failed with error=%d\n",
errno);
return OPAL_ERROR;
}
for(cur_ifaddrs = *ifadd_list; NULL != cur_ifaddrs;
for (cur_ifaddrs = *ifadd_list; NULL != cur_ifaddrs;
cur_ifaddrs = cur_ifaddrs->ifa_next) {
opal_if_t *intf;
struct in6_addr a6;
/* skip non-ipv6 interface addresses */
if(AF_INET6 != cur_ifaddrs->ifa_addr->sa_family) {
if (AF_INET6 != cur_ifaddrs->ifa_addr->sa_family) {
#if 0
printf("skipping non-ipv6 interface %s.\n", cur_ifaddrs->ifa_name);
#endif
@ -559,7 +546,7 @@ static int opal_ifinit(void)
}
/* skip interface if it is down (IFF_UP not set) */
if(0 == (cur_ifaddrs->ifa_flags & IFF_UP)) {
if (0 == (cur_ifaddrs->ifa_flags & IFF_UP)) {
#if 0
printf("skipping non-up interface %s.\n", cur_ifaddrs->ifa_name);
#endif
@ -569,7 +556,7 @@ static int opal_ifinit(void)
/* skip interface if it is a loopback device (IFF_LOOPBACK set) */
/* or if it is a point-to-point interface */
/* TODO: do we really skip p2p? */
if(0 != (cur_ifaddrs->ifa_flags & IFF_LOOPBACK)
if (0 != (cur_ifaddrs->ifa_flags & IFF_LOOPBACK)
|| 0!= (cur_ifaddrs->ifa_flags & IFF_POINTOPOINT)) {
#if 0
printf("skipping loopback interface %s.\n", cur_ifaddrs->ifa_name);
@ -596,7 +583,7 @@ static int opal_ifinit(void)
* so the scope returned by getifaddrs() isn't working properly
*/
if((IN6_IS_ADDR_LINKLOCAL (&sin_addr->sin6_addr))) {
if ((IN6_IS_ADDR_LINKLOCAL (&sin_addr->sin6_addr))) {
#if 0
printf("skipping link-local ipv6 address on interface \
%s with scope %d.\n",
@ -639,7 +626,6 @@ static int opal_ifinit(void)
(uint16_t) if_nametoindex(cur_ifaddrs->ifa_name);
opal_list_append(&opal_if_list, &(intf->super));
} /* of for loop over ifaddrs list */
}
#endif /* bsd, macosx */
@ -890,13 +876,13 @@ int opal_ifnametoaddr(const char* if_name, struct sockaddr* addr, int length)
{
opal_if_t* intf;
int rc = opal_ifinit();
if(rc != OPAL_SUCCESS)
if (rc != OPAL_SUCCESS)
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_next(intf)) {
if(strcmp(intf->if_name, if_name) == 0) {
if (strcmp(intf->if_name, if_name) == 0) {
memcpy(addr, &intf->if_addr, length);
return OPAL_SUCCESS;
}
@ -914,13 +900,13 @@ int opal_ifnametoindex(const char* if_name)
{
opal_if_t* intf;
int rc = opal_ifinit();
if(rc != OPAL_SUCCESS)
if (rc != OPAL_SUCCESS)
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_next(intf)) {
if(strcmp(intf->if_name, if_name) == 0) {
if (strcmp(intf->if_name, if_name) == 0) {
return intf->if_index;
}
}
@ -937,13 +923,13 @@ int16_t opal_ifnametokindex(const char* if_name)
{
opal_if_t* intf;
int rc = opal_ifinit();
if(rc != OPAL_SUCCESS)
if (rc != OPAL_SUCCESS)
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_next(intf)) {
if(strcmp(intf->if_name, if_name) == 0) {
if (strcmp(intf->if_name, if_name) == 0) {
return intf->if_kernel_index;
}
}
@ -960,13 +946,13 @@ int opal_ifindextokindex(int if_index)
{
opal_if_t* intf;
int rc = opal_ifinit();
if(rc != OPAL_SUCCESS)
if (rc != OPAL_SUCCESS)
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_next(intf)) {
if(if_index == intf->if_index) {
if (if_index == intf->if_index) {
return intf->if_kernel_index;
}
}
@ -1022,7 +1008,7 @@ int opal_ifaddrtoname(const char* if_addr, char* if_name, int length)
}
for (r = res; r != NULL; r = r->ai_next) {
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_next(intf)) {
@ -1052,18 +1038,18 @@ int opal_ifaddrtoname(const char* if_addr, char* if_name, int length)
#else
inaddr = inet_addr(if_addr);
if(INADDR_NONE == inaddr) {
if (INADDR_NONE == inaddr) {
h = gethostbyname(if_addr);
if(0 == h) {
if (0 == h) {
return OPAL_ERR_NOT_FOUND;
}
memcpy(&inaddr, h->h_addr, sizeof(inaddr));
}
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_next(intf)) {
if(((struct sockaddr_in*) &intf->if_addr)->sin_addr.s_addr == inaddr) {
if (((struct sockaddr_in*) &intf->if_addr)->sin_addr.s_addr == inaddr) {
strncpy(if_name, intf->if_name, length);
return OPAL_SUCCESS;
}
@ -1078,7 +1064,7 @@ int opal_ifaddrtoname(const char* if_addr, char* if_name, int length)
int opal_ifcount(void)
{
if(opal_ifinit() != OPAL_SUCCESS)
if (opal_ifinit() != OPAL_SUCCESS)
return (-1);
return opal_list_get_size(&opal_if_list);
}
@ -1092,10 +1078,10 @@ int opal_ifcount(void)
int opal_ifbegin(void)
{
opal_if_t *intf;
if(opal_ifinit() != OPAL_SUCCESS)
if (opal_ifinit() != OPAL_SUCCESS)
return (-1);
intf = (opal_if_t*)opal_list_get_first(&opal_if_list);
if(NULL != intf)
if (NULL != intf)
return intf->if_index;
return (-1);
}
@ -1110,13 +1096,13 @@ int opal_ifbegin(void)
int opal_ifnext(int if_index)
{
opal_if_t *intf;
if(opal_ifinit() != OPAL_SUCCESS)
if (opal_ifinit() != OPAL_SUCCESS)
return (-1);
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_next(intf)) {
if(intf->if_index == if_index) {
if (intf->if_index == if_index) {
do {
opal_if_t* if_next = (opal_if_t*)opal_list_get_next(intf);
opal_if_t* if_end = (opal_if_t*)opal_list_get_end(&opal_if_list);
@ -1141,13 +1127,13 @@ int opal_ifindextoaddr(int if_index, struct sockaddr* if_addr, unsigned int leng
{
opal_if_t* intf;
int rc = opal_ifinit();
if(rc != OPAL_SUCCESS)
if (rc != OPAL_SUCCESS)
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_next(intf)) {
if(intf->if_index == if_index) {
if (intf->if_index == if_index) {
memcpy(if_addr, &intf->if_addr, MIN(length, sizeof (intf->if_addr)));
return OPAL_SUCCESS;
}
@ -1165,13 +1151,13 @@ int opal_ifindextomask(int if_index, uint32_t* if_mask, int length)
{
opal_if_t* intf;
int rc = opal_ifinit();
if(rc != OPAL_SUCCESS)
if (rc != OPAL_SUCCESS)
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_next(intf)) {
if(intf->if_index == if_index) {
if (intf->if_index == if_index) {
memcpy(if_mask, &intf->if_mask, length);
return OPAL_SUCCESS;
}
@ -1190,13 +1176,13 @@ int opal_ifindextoflags(int if_index, uint32_t* if_flags)
{
opal_if_t* intf;
int rc = opal_ifinit();
if(rc != OPAL_SUCCESS)
if (rc != OPAL_SUCCESS)
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_next(intf)) {
if(intf->if_index == if_index) {
if (intf->if_index == if_index) {
memcpy(if_flags, &intf->if_flags, sizeof(uint32_t));
return OPAL_SUCCESS;
}
@ -1215,13 +1201,13 @@ int opal_ifindextoname(int if_index, char* if_name, int length)
{
opal_if_t *intf;
int rc = opal_ifinit();
if(rc != OPAL_SUCCESS)
if (rc != OPAL_SUCCESS)
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_next(intf)) {
if(intf->if_index == if_index) {
if (intf->if_index == if_index) {
strncpy(if_name, intf->if_name, length);
return OPAL_SUCCESS;
}
@ -1239,13 +1225,13 @@ int opal_ifkindextoname(int if_kindex, char* if_name, int length)
{
opal_if_t *intf;
int rc = opal_ifinit();
if(rc != OPAL_SUCCESS)
if (rc != OPAL_SUCCESS)
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_next(intf)) {
if(intf->if_kernel_index == if_kindex) {
if (intf->if_kernel_index == if_kindex) {
strncpy(if_name, intf->if_name, length);
return OPAL_SUCCESS;
}
@ -1382,13 +1368,14 @@ bool opal_ifisloopback(int if_index)
{
opal_if_t* intf;
int rc = opal_ifinit();
if(rc != OPAL_SUCCESS)
if (rc != OPAL_SUCCESS) {
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_next(intf)) {
if(intf->if_index == if_index) {
if (intf->if_index == if_index) {
if ((intf->if_flags & IFF_LOOPBACK) != 0) {
return true;
}