@@ -644,8 +644,8 @@ static int mca_btl_tcp_create(const int if_kindex, const char *if_name)
644644 */
645645static char * * split_and_resolve (char * * orig_str , char * name , bool reqd )
646646{
647- int i , ret , save , if_index ;
648- char * * argv , * str , * tmp ;
647+ int i , n , ret , if_index , match_count , interface_count ;
648+ char * * argv , * * interfaces , * str , * tmp ;
649649 char if_name [OPAL_IF_NAMESIZE ];
650650 struct sockaddr_storage argv_inaddr , if_inaddr ;
651651 uint32_t argv_prefix ;
@@ -659,9 +659,22 @@ static char **split_and_resolve(char **orig_str, char *name, bool reqd)
659659 if (NULL == argv ) {
660660 return NULL ;
661661 }
662- for (save = i = 0 ; NULL != argv [i ]; ++ i ) {
662+ interface_count = 0 ;
663+ interfaces = NULL ;
664+ for (i = 0 ; NULL != argv [i ]; ++ i ) {
663665 if (isalpha (argv [i ][0 ])) {
664- argv [save ++ ] = argv [i ];
666+ /* This is an interface name. If not already in the interfaces array, add it */
667+ for (n = 0 ; n < interface_count ; n ++ ) {
668+ if (0 == strcmp (argv [i ], interfaces [n ])) {
669+ break ;
670+ }
671+ }
672+ if (n == interface_count ) {
673+ opal_output_verbose (20 ,
674+ opal_btl_base_framework .framework_output ,
675+ "btl: tcp: Using interface: %s " , argv [i ]);
676+ opal_argv_append (& interface_count , & interfaces , argv [i ]);
677+ }
665678 continue ;
666679 }
667680
@@ -698,16 +711,37 @@ static char **split_and_resolve(char **orig_str, char *name, bool reqd)
698711 opal_net_get_hostname ((struct sockaddr * ) & argv_inaddr ), argv_prefix );
699712
700713 /* Go through all interfaces and see if we can find a match */
701- for (if_index = opal_ifbegin (); if_index >= 0 ; if_index = opal_ifnext (if_index )) {
702- opal_ifindextoaddr (if_index , (struct sockaddr * ) & if_inaddr , sizeof (if_inaddr ));
703- if (opal_net_samenetwork ((struct sockaddr * ) & argv_inaddr ,
704- (struct sockaddr * ) & if_inaddr , argv_prefix )) {
705- break ;
714+ match_count = 0 ;
715+ for (if_index = opal_ifbegin (); if_index >= 0 ;
716+ if_index = opal_ifnext (if_index )) {
717+ opal_ifindextoaddr (if_index ,
718+ (struct sockaddr * ) & if_inaddr ,
719+ sizeof (if_inaddr ));
720+ if (opal_net_samenetwork ((struct sockaddr * ) & argv_inaddr ,
721+ (struct sockaddr * ) & if_inaddr ,
722+ argv_prefix )) {
723+ /* We found a match. If it's not already in the interfaces array,
724+ add it. If it's already in the array, treat it as a match */
725+ match_count = match_count + 1 ;
726+ opal_ifindextoname (if_index , if_name , sizeof (if_name ));
727+ for (n = 0 ; n < interface_count ; n ++ ) {
728+ if (0 == strcmp (if_name , interfaces [n ])) {
729+ break ;
730+ }
731+ }
732+ if (n == interface_count ) {
733+ opal_output_verbose (20 ,
734+ opal_btl_base_framework .framework_output ,
735+ "btl: tcp: Found match: %s (%s)" ,
736+ opal_net_get_hostname ((struct sockaddr * ) & if_inaddr ),
737+ if_name );
738+ opal_argv_append (& interface_count , & interfaces , if_name );
739+ }
706740 }
707741 }
708742
709743 /* If we didn't find a match, keep trying */
710- if (if_index < 0 ) {
744+ if (0 == match_count ) {
711745 if (reqd || mca_btl_tcp_component .report_all_unfound_interfaces ) {
712746 opal_show_help ("help-mpi-btl-tcp.txt" , "invalid if_inexclude" , true, name ,
713747 opal_process_info .nodename , tmp ,
@@ -717,22 +751,17 @@ static char **split_and_resolve(char **orig_str, char *name, bool reqd)
717751 continue ;
718752 }
719753
720- /* We found a match; get the name and replace it in the
721- argv */
722- opal_ifindextoname (if_index , if_name , sizeof (if_name ));
723- opal_output_verbose (20 , opal_btl_base_framework .framework_output ,
724- "btl: tcp: Found match: %s (%s)" ,
725- opal_net_get_hostname ((struct sockaddr * ) & if_inaddr ), if_name );
726- argv [save ++ ] = strdup (if_name );
727754 free (tmp );
728755 }
729756
730- /* The list may have been compressed if there were invalid
731- entries, so ensure we end it with a NULL entry */
732- argv [save ] = NULL ;
757+ /* Mark the end of the interface name array with NULL */
758+ if (NULL != interfaces ) {
759+ interfaces [interface_count ] = NULL ;
760+ }
761+ free (argv );
733762 free (* orig_str );
734- * orig_str = opal_argv_join (argv , ',' );
735- return argv ;
763+ * orig_str = opal_argv_join (interfaces , ',' );
764+ return interfaces ;
736765}
737766
738767/*
0 commit comments