Skip to content

Commit a287f09

Browse files
authored
Merge pull request #9756 from drwootton/fix_subnet_adapters_v41x
v4.1.x: Select all adapters with IPV4 addresses within specified subnet ranges.
2 parents 273a0f3 + c16540b commit a287f09

File tree

2 files changed

+86
-39
lines changed

2 files changed

+86
-39
lines changed

opal/mca/btl/tcp/btl_tcp_component.c

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,8 @@ static int mca_btl_tcp_create(int if_kindex, const char* if_name)
577577
*/
578578
static char **split_and_resolve(char **orig_str, char *name, bool reqd)
579579
{
580-
int i, ret, save, if_index;
581-
char **argv, *str, *tmp;
580+
int i, n, ret, if_index, match_count, interface_count;
581+
char **argv, **interfaces, *str, *tmp;
582582
char if_name[IF_NAMESIZE];
583583
struct sockaddr_storage argv_inaddr, if_inaddr;
584584
uint32_t argv_prefix;
@@ -592,9 +592,22 @@ static char **split_and_resolve(char **orig_str, char *name, bool reqd)
592592
if (NULL == argv) {
593593
return NULL;
594594
}
595-
for (save = i = 0; NULL != argv[i]; ++i) {
595+
interface_count = 0;
596+
interfaces = NULL;
597+
for (i = 0; NULL != argv[i]; ++i) {
596598
if (isalpha(argv[i][0])) {
597-
argv[save++] = argv[i];
599+
/* This is an interface name. If not already in the interfaces array, add it */
600+
for (n = 0; n < interface_count; n++) {
601+
if (0 == strcmp(argv[i], interfaces[n])) {
602+
break;
603+
}
604+
}
605+
if (n == interface_count) {
606+
opal_output_verbose(20,
607+
opal_btl_base_framework.framework_output,
608+
"btl: tcp: Using interface: %s ", argv[i]);
609+
opal_argv_append(&interface_count, &interfaces, argv[i]);
610+
}
598611
continue;
599612
}
600613

@@ -634,6 +647,7 @@ static char **split_and_resolve(char **orig_str, char *name, bool reqd)
634647
argv_prefix);
635648

636649
/* Go through all interfaces and see if we can find a match */
650+
match_count = 0;
637651
for (if_index = opal_ifbegin(); if_index >= 0;
638652
if_index = opal_ifnext(if_index)) {
639653
opal_ifindextoaddr(if_index,
@@ -642,12 +656,28 @@ static char **split_and_resolve(char **orig_str, char *name, bool reqd)
642656
if (opal_net_samenetwork((struct sockaddr*) &argv_inaddr,
643657
(struct sockaddr*) &if_inaddr,
644658
argv_prefix)) {
645-
break;
659+
/* We found a match. If it's not already in the interfaces array,
660+
add it. If it's already in the array, treat it as a match */
661+
match_count = match_count + 1;
662+
opal_ifindextoname(if_index, if_name, sizeof(if_name));
663+
for (n = 0; n < interface_count; n++) {
664+
if (0 == strcmp(if_name, interfaces[n])) {
665+
break;
666+
}
667+
}
668+
if (n == interface_count) {
669+
opal_output_verbose(20,
670+
opal_btl_base_framework.framework_output,
671+
"btl: tcp: Found match: %s (%s)",
672+
opal_net_get_hostname((struct sockaddr*) &if_inaddr),
673+
if_name);
674+
opal_argv_append(&interface_count, &interfaces, if_name);
675+
}
646676
}
647677
}
648678

649679
/* If we didn't find a match, keep trying */
650-
if (if_index < 0) {
680+
if (0 == match_count) {
651681
if (reqd || mca_btl_tcp_component.report_all_unfound_interfaces) {
652682
opal_show_help("help-mpi-btl-tcp.txt", "invalid if_inexclude",
653683
true, name, opal_process_info.nodename, tmp,
@@ -657,23 +687,17 @@ static char **split_and_resolve(char **orig_str, char *name, bool reqd)
657687
continue;
658688
}
659689

660-
/* We found a match; get the name and replace it in the
661-
argv */
662-
opal_ifindextoname(if_index, if_name, sizeof(if_name));
663-
opal_output_verbose(20, opal_btl_base_framework.framework_output,
664-
"btl: tcp: Found match: %s (%s)",
665-
opal_net_get_hostname((struct sockaddr*) &if_inaddr),
666-
if_name);
667-
argv[save++] = strdup(if_name);
668690
free(tmp);
669691
}
670692

671-
/* The list may have been compressed if there were invalid
672-
entries, so ensure we end it with a NULL entry */
673-
argv[save] = NULL;
693+
/* Mark the end of the interface name array with NULL */
694+
if (NULL != interfaces) {
695+
interfaces[interface_count] = NULL;
696+
}
697+
free(argv);
674698
free(*orig_str);
675-
*orig_str = opal_argv_join(argv, ',');
676-
return argv;
699+
*orig_str = opal_argv_join(interfaces, ',');
700+
return interfaces;
677701
}
678702

679703

orte/mca/oob/tcp/oob_tcp_component.c

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,8 +1237,8 @@ void mca_oob_tcp_component_failed_to_connect(int fd, short args, void *cbdata)
12371237
*/
12381238
static char **split_and_resolve(char **orig_str, char *name)
12391239
{
1240-
int i, ret, save, if_index;
1241-
char **argv, *str, *tmp;
1240+
int i, n, ret, if_index, match_count, interface_count;
1241+
char **argv, **interfaces, *str, *tmp;
12421242
char if_name[IF_NAMESIZE];
12431243
struct sockaddr_storage argv_inaddr, if_inaddr;
12441244
uint32_t argv_prefix;
@@ -1252,9 +1252,22 @@ static char **split_and_resolve(char **orig_str, char *name)
12521252
if (NULL == argv) {
12531253
return NULL;
12541254
}
1255-
for (save = i = 0; NULL != argv[i]; ++i) {
1255+
interface_count = 0;
1256+
interfaces = NULL;
1257+
for (i = 0; NULL != argv[i]; ++i) {
12561258
if (isalpha(argv[i][0])) {
1257-
argv[save++] = argv[i];
1259+
/* This is an interface name. If not already in the interfaces array, add it */
1260+
for (n = 0; n < interface_count; n++) {
1261+
if (0 == strcmp(argv[i], interfaces[n])) {
1262+
break;
1263+
}
1264+
}
1265+
if (n == interface_count) {
1266+
opal_output_verbose(20,
1267+
orte_oob_base_framework.framework_output,
1268+
"oob:tcp: Using interface: %s ", argv[i]);
1269+
opal_argv_append(&interface_count, &interfaces, argv[i]);
1270+
}
12581271
continue;
12591272
}
12601273

@@ -1295,6 +1308,7 @@ static char **split_and_resolve(char **orig_str, char *name)
12951308
argv_prefix);
12961309

12971310
/* Go through all interfaces and see if we can find a match */
1311+
match_count = 0;
12981312
for (if_index = opal_ifbegin(); if_index >= 0;
12991313
if_index = opal_ifnext(if_index)) {
13001314
opal_ifindextoaddr(if_index,
@@ -1303,36 +1317,45 @@ static char **split_and_resolve(char **orig_str, char *name)
13031317
if (opal_net_samenetwork((struct sockaddr*) &argv_inaddr,
13041318
(struct sockaddr*) &if_inaddr,
13051319
argv_prefix)) {
1306-
break;
1320+
/* We found a match. If it's not already in the interfaces array,
1321+
add it. If it's already in the array, treat it as a match */
1322+
match_count = match_count + 1;
1323+
opal_ifindextoname(if_index, if_name, sizeof(if_name));
1324+
for (n = 0; n < interface_count; n++) {
1325+
if (0 == strcmp(if_name, interfaces[n])) {
1326+
break;
1327+
}
1328+
}
1329+
if (n == interface_count) {
1330+
opal_output_verbose(20,
1331+
orte_oob_base_framework.framework_output,
1332+
"oob:tcp: Found match: %s (%s)",
1333+
opal_net_get_hostname((struct sockaddr*) &if_inaddr),
1334+
if_name);
1335+
opal_argv_append(&interface_count, &interfaces, if_name);
1336+
}
13071337
}
13081338
}
13091339
/* If we didn't find a match, keep trying */
1310-
if (if_index < 0) {
1340+
if (0 == match_count) {
13111341
orte_show_help("help-oob-tcp.txt", "invalid if_inexclude",
13121342
true, name, orte_process_info.nodename, tmp,
13131343
"Did not find interface matching this subnet");
13141344
free(tmp);
13151345
continue;
13161346
}
13171347

1318-
/* We found a match; get the name and replace it in the
1319-
argv */
1320-
opal_ifindextoname(if_index, if_name, sizeof(if_name));
1321-
opal_output_verbose(20, orte_oob_base_framework.framework_output,
1322-
"%s oob:tcp: Found match: %s (%s)",
1323-
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
1324-
opal_net_get_hostname((struct sockaddr*) &if_inaddr),
1325-
if_name);
1326-
argv[save++] = strdup(if_name);
13271348
free(tmp);
13281349
}
13291350

1330-
/* The list may have been compressed if there were invalid
1331-
entries, so ensure we end it with a NULL entry */
1332-
argv[save] = NULL;
1351+
/* Mark the end of the interface name array with NULL */
1352+
if (NULL != interfaces) {
1353+
interfaces[interface_count] = NULL;
1354+
}
1355+
free(argv);
13331356
free(*orig_str);
1334-
*orig_str = opal_argv_join(argv, ',');
1335-
return argv;
1357+
*orig_str = opal_argv_join(interfaces, ',');
1358+
return interfaces;
13361359
}
13371360

13381361
/* OOB TCP Class instances */

0 commit comments

Comments
 (0)