@@ -577,8 +577,8 @@ static int mca_btl_tcp_create(int if_kindex, const char* if_name)
577
577
*/
578
578
static char * * split_and_resolve (char * * orig_str , char * name , bool reqd )
579
579
{
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 ;
582
582
char if_name [IF_NAMESIZE ];
583
583
struct sockaddr_storage argv_inaddr , if_inaddr ;
584
584
uint32_t argv_prefix ;
@@ -592,9 +592,22 @@ static char **split_and_resolve(char **orig_str, char *name, bool reqd)
592
592
if (NULL == argv ) {
593
593
return NULL ;
594
594
}
595
- for (save = i = 0 ; NULL != argv [i ]; ++ i ) {
595
+ interface_count = 0 ;
596
+ interfaces = NULL ;
597
+ for (i = 0 ; NULL != argv [i ]; ++ i ) {
596
598
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
+ }
598
611
continue ;
599
612
}
600
613
@@ -634,6 +647,7 @@ static char **split_and_resolve(char **orig_str, char *name, bool reqd)
634
647
argv_prefix );
635
648
636
649
/* Go through all interfaces and see if we can find a match */
650
+ match_count = 0 ;
637
651
for (if_index = opal_ifbegin (); if_index >= 0 ;
638
652
if_index = opal_ifnext (if_index )) {
639
653
opal_ifindextoaddr (if_index ,
@@ -642,12 +656,28 @@ static char **split_and_resolve(char **orig_str, char *name, bool reqd)
642
656
if (opal_net_samenetwork ((struct sockaddr * ) & argv_inaddr ,
643
657
(struct sockaddr * ) & if_inaddr ,
644
658
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
+ }
646
676
}
647
677
}
648
678
649
679
/* If we didn't find a match, keep trying */
650
- if (if_index < 0 ) {
680
+ if (0 == match_count ) {
651
681
if (reqd || mca_btl_tcp_component .report_all_unfound_interfaces ) {
652
682
opal_show_help ("help-mpi-btl-tcp.txt" , "invalid if_inexclude" ,
653
683
true, name , opal_process_info .nodename , tmp ,
@@ -657,23 +687,17 @@ static char **split_and_resolve(char **orig_str, char *name, bool reqd)
657
687
continue ;
658
688
}
659
689
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 );
668
690
free (tmp );
669
691
}
670
692
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 );
674
698
free (* orig_str );
675
- * orig_str = opal_argv_join (argv , ',' );
676
- return argv ;
699
+ * orig_str = opal_argv_join (interfaces , ',' );
700
+ return interfaces ;
677
701
}
678
702
679
703
0 commit comments