1
1

Cleanup the IPv4 address parsing, and correct the error message.

This commit was SVN r24750.
Этот коммит содержится в:
George Bosilca 2011-06-06 03:08:02 +00:00
родитель 6b52d8f519
Коммит 7ebd094ecf
3 изменённых файлов: 37 добавлений и 45 удалений

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

@ -24,7 +24,7 @@ install its own signal handler for this signal by setting the
Signal: %d Signal: %d
Current opal_signal value: %s Current opal_signal value: %s
* *
[malformed IP address or netmask] [malformed net_private_ipv4]
Open MPI has detected at least one malformed IP address or netmask in Open MPI has detected at least one malformed IP address or netmask in
the value of the opal_net_private_ipv4 MCA parameter. The the value of the opal_net_private_ipv4 MCA parameter. The
opal_net_private_ipv4 MCA parameter accepts a semicolon-delimited list opal_net_private_ipv4 MCA parameter accepts a semicolon-delimited list
@ -37,16 +37,11 @@ All malformed entries will be ignored; Open MPI will attempt to continue
your job. The first detected malformed entry was %s. your job. The first detected malformed entry was %s.
# #
[invalid-net-mask] [invalid-net-mask]
We were unable to parse the provided network interface: Open MPI has detected an malformed IPv4 address or netmask
in %s. Accepted values follows the Classless Inter-Domain
Routing (CIDR) notation specifications. For example:
Interface: %s 10.0.0.0/8;172.16/12;192.168;169.254.0.0/16
The interface must be one of the following forms: All malformed entries will be ignored; Open MPI will attempt to continue
your job.
123.456.789.123
123.456/16
123.456.789
The system can parse any one of these, and will find an interface
that matches within the provided scope. Please revise your input
and try again.

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

@ -490,29 +490,37 @@ opal_ifislocal(const char *hostname)
return false; return false;
} }
static uint32_t parse_dots(const char *addr) static uint32_t parse_ipv4_dots(const char *addr, uint32_t* net, int* dots)
{ {
char **tuple; const char *start = addr, *end;
uint32_t n[]={0,0,0,0}; uint32_t n[]={0,0,0,0};
uint32_t net; int i, rc = OPAL_SUCCESS;
int i;
tuple = opal_argv_split(addr, '.');
/* now assemble the address */ /* now assemble the address */
for (i=0; NULL != tuple[i]; i++) { for( i = 0; i < 4; i++ ) {
n[i] = strtoul(tuple[i], NULL, 10); n[i] = strtoul(start, (char**)&end, 10);
if( end == start ) { /* error case: use what we have so far */
rc = OPAL_ERROR;
break;
} }
net = OPAL_IF_ASSEMBLE_NETWORK(n[0], n[1], n[2], n[3]); /* skip all the . */
opal_argv_free(tuple); for( start = end; '\0' != *start; start++ )
return net; if( '.' != *start ) break;
/* did we read something sensible? */
if( n[i] > 255 ) {
return OPAL_ERROR;
}
}
*dots = i;
*net = OPAL_IF_ASSEMBLE_NETWORK(n[0], n[1], n[2], n[3]);
return OPAL_SUCCESS;
} }
int int
opal_iftupletoaddr(const char *inaddr, uint32_t *net, uint32_t *mask) opal_iftupletoaddr(const char *inaddr, uint32_t *net, uint32_t *mask)
{ {
char **tuple; int pval, dots, rc = OPAL_SUCCESS;
int pval; const char *ptr;
char *msk, *ptr;
/* if a mask was desired... */ /* if a mask was desired... */
if (NULL != mask) { if (NULL != mask) {
@ -520,19 +528,17 @@ opal_iftupletoaddr(const char *inaddr, uint32_t *net, uint32_t *mask)
*mask = 0xFFFFFFFF; *mask = 0xFFFFFFFF;
/* if entry includes mask, split that off */ /* if entry includes mask, split that off */
msk = NULL;
if (NULL != (ptr = strchr(inaddr, '/'))) { if (NULL != (ptr = strchr(inaddr, '/'))) {
*ptr = '\0'; ptr = ptr + 1; /* skip the / */
msk = ptr + 1;
/* is the mask a tuple? */ /* is the mask a tuple? */
if (NULL != strchr(msk, '.')) { if (NULL != strchr(ptr, '.')) {
/* yes - extract mask from it */ /* yes - extract mask from it */
*mask = parse_dots(msk); rc = parse_ipv4_dots(ptr, mask, &dots);
} else { } else {
/* no - must be an int telling us how much of the addr to use: e.g., /16 /* no - must be an int telling us how much of the addr to use: e.g., /16
* For more information please read http://en.wikipedia.org/wiki/Subnetwork. * For more information please read http://en.wikipedia.org/wiki/Subnetwork.
*/ */
pval = strtol(msk, NULL, 10); pval = strtol(ptr, NULL, 10);
if ((pval > 31) || (pval < 1)) { if ((pval > 31) || (pval < 1)) {
opal_output(0, "opal_iftupletoaddr: unknown mask"); opal_output(0, "opal_iftupletoaddr: unknown mask");
return OPAL_ERROR; return OPAL_ERROR;
@ -541,8 +547,8 @@ opal_iftupletoaddr(const char *inaddr, uint32_t *net, uint32_t *mask)
} }
} else { } else {
/* use the number of dots to determine it */ /* use the number of dots to determine it */
tuple = opal_argv_split(inaddr, '.'); for( ptr = inaddr, pval = 0; '\0'!= *ptr; ptr++ )
pval = opal_argv_count(tuple); if( '.' == *ptr ) pval++;
/* if we have three dots, then we have four /* if we have three dots, then we have four
* fields since it is a full address, so the * fields since it is a full address, so the
* default netmask is fine * default netmask is fine
@ -559,24 +565,16 @@ opal_iftupletoaddr(const char *inaddr, uint32_t *net, uint32_t *mask)
return OPAL_ERROR; return OPAL_ERROR;
} }
} }
opal_argv_free(tuple);
} }
} }
/* if network addr is desired... */ /* if network addr is desired... */
if (NULL != net) { if (NULL != net) {
/* set default */
*net = 0;
/* if entry includes mask, split that off */
if (NULL != (ptr = strchr(inaddr, '/'))) {
*ptr = '\0';
}
/* now assemble the address */ /* now assemble the address */
*net = parse_dots(inaddr); rc = parse_ipv4_dots(inaddr, net, &dots);
} }
return OPAL_SUCCESS; return rc;
} }
/* /*

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

@ -155,9 +155,8 @@ opal_net_init()
* get added to the trunk. * get added to the trunk.
*/ */
if (0 == found_bad) { if (0 == found_bad) {
opal_output(0, "FOUND BAD!\n");
opal_show_help("help-opal-util.txt", opal_show_help("help-opal-util.txt",
"malformed IP address or netmask", "malformed net_private_ipv4",
true, args[i]); true, args[i]);
found_bad = 1; found_bad = 1;
} }