19
19
* Copyright (c) 2014-2015 Intel, Inc. All rights reserved.
20
20
* Copyright (c) 2014-2017 Research Organization for Information Science
21
21
* and Technology (RIST). All rights reserved.
22
- * Copyright (c) 2018 Amazon.com, Inc. or its affiliates. All Rights reserved.
22
+ * Copyright (c) 2018-2019 Amazon.com, Inc. or its affiliates. All Rights
23
+ * reserved.
23
24
* $COPYRIGHT$
24
25
*
25
26
* Additional copyrights may follow
69
70
#include "opal/util/net.h"
70
71
#include "opal/util/fd.h"
71
72
#include "opal/util/show_help.h"
73
+ #include "opal/util/string_copy.h"
72
74
#include "opal/util/printf.h"
73
75
#include "opal/constants.h"
74
76
#include "opal/mca/btl/btl.h"
75
77
#include "opal/mca/btl/base/base.h"
76
78
#include "opal/mca/mpool/base/base.h"
77
79
#include "opal/mca/btl/base/btl_base_error.h"
78
80
#include "opal/mca/pmix/pmix.h"
81
+ #include "opal/mca/reachable/base/base.h"
79
82
#include "opal/threads/threads.h"
80
83
81
84
#include "opal/constants.h"
@@ -368,6 +371,7 @@ static int mca_btl_tcp_component_open(void)
368
371
mca_btl_tcp_component .tcp_btls = NULL ;
369
372
370
373
/* initialize objects */
374
+ OBJ_CONSTRUCT (& mca_btl_tcp_component .local_ifs , opal_list_t );
371
375
OBJ_CONSTRUCT (& mca_btl_tcp_component .tcp_lock , opal_mutex_t );
372
376
OBJ_CONSTRUCT (& mca_btl_tcp_component .tcp_procs , opal_proc_table_t );
373
377
OBJ_CONSTRUCT (& mca_btl_tcp_component .tcp_events , opal_list_t );
@@ -477,6 +481,7 @@ static int mca_btl_tcp_component_close(void)
477
481
OBJ_DESTRUCT (& mca_btl_tcp_component .tcp_frag_max );
478
482
OBJ_DESTRUCT (& mca_btl_tcp_component .tcp_frag_user );
479
483
OBJ_DESTRUCT (& mca_btl_tcp_component .tcp_lock );
484
+ OBJ_DESTRUCT (& mca_btl_tcp_component .local_ifs );
480
485
481
486
#if OPAL_CUDA_SUPPORT
482
487
mca_common_cuda_fini ();
@@ -493,8 +498,9 @@ static int mca_btl_tcp_component_close(void)
493
498
static int mca_btl_tcp_create (const int if_kindex , const char * if_name )
494
499
{
495
500
struct mca_btl_tcp_module_t * btl ;
501
+ opal_if_t * copied_interface , * selected_interface ;
496
502
char param [256 ];
497
- int i ;
503
+ int i , if_index ;
498
504
struct sockaddr_storage addr ;
499
505
bool found = false;
500
506
@@ -515,18 +521,15 @@ static int mca_btl_tcp_create(const int if_kindex, const char* if_name)
515
521
* 10.1.0.1 as the one that is published in the modex and used for
516
522
* connection.
517
523
*/
518
- for (i = opal_ifbegin () ; i >= 0 ; i = opal_ifnext (i )) {
519
- int ret ;
520
-
521
- if (if_kindex != opal_ifindextokindex (i )) {
524
+ OPAL_LIST_FOREACH (selected_interface , & opal_if_list , opal_if_t ) {
525
+ if (if_kindex != selected_interface -> if_kernel_index ) {
522
526
continue ;
523
527
}
524
528
525
- ret = opal_ifindextoaddr (i , (struct sockaddr * )& addr ,
526
- sizeof (struct sockaddr_storage ));
527
- if (OPAL_SUCCESS != ret ) {
528
- return ret ;
529
- }
529
+ if_index = selected_interface -> if_index ;
530
+
531
+ memcpy ((struct sockaddr * )& addr , & selected_interface -> if_addr ,
532
+ MIN (sizeof (struct sockaddr_storage ), sizeof (selected_interface -> if_addr )));
530
533
531
534
if (addr .ss_family == AF_INET &&
532
535
4 != mca_btl_tcp_component .tcp_disable_family ) {
@@ -548,12 +551,19 @@ static int mca_btl_tcp_create(const int if_kindex, const char* if_name)
548
551
btl = (struct mca_btl_tcp_module_t * )malloc (sizeof (mca_btl_tcp_module_t ));
549
552
if (NULL == btl )
550
553
return OPAL_ERR_OUT_OF_RESOURCE ;
554
+ copied_interface = OBJ_NEW (opal_if_t );
555
+ if (NULL == copied_interface ) {
556
+ free (btl );
557
+ return OPAL_ERR_OUT_OF_RESOURCE ;
558
+ }
551
559
memcpy (btl , & mca_btl_tcp_module , sizeof (mca_btl_tcp_module ));
552
560
OBJ_CONSTRUCT (& btl -> tcp_endpoints , opal_list_t );
553
561
OBJ_CONSTRUCT (& btl -> tcp_endpoints_mutex , opal_mutex_t );
554
562
mca_btl_tcp_component .tcp_btls [mca_btl_tcp_component .tcp_num_btls ++ ] = btl ;
555
563
556
564
/* initialize the btl */
565
+ /* This index is used as a key for a hash table used for interface matching. */
566
+ btl -> btl_index = mca_btl_tcp_component .tcp_num_btls - 1 ;
557
567
btl -> tcp_ifkindex = (uint16_t ) if_kindex ;
558
568
#if MCA_BTL_TCP_STATISTICS
559
569
btl -> tcp_bytes_recv = 0 ;
@@ -562,6 +572,7 @@ static int mca_btl_tcp_create(const int if_kindex, const char* if_name)
562
572
#endif
563
573
564
574
memcpy (& btl -> tcp_ifaddr , & addr , sizeof (struct sockaddr_storage ));
575
+ btl -> tcp_ifmask = selected_interface -> if_mask ;
565
576
566
577
/* allow user to specify interface bandwidth */
567
578
sprintf (param , "bandwidth_%s" , if_name );
@@ -603,6 +614,21 @@ static int mca_btl_tcp_create(const int if_kindex, const char* if_name)
603
614
}
604
615
}
605
616
617
+ /* Add another entry to the local interface list */
618
+ opal_string_copy (copied_interface -> if_name , if_name , OPAL_IF_NAMESIZE );
619
+ copied_interface -> if_index = if_index ;
620
+ copied_interface -> if_kernel_index = btl -> tcp_ifkindex ;
621
+ copied_interface -> af_family = btl -> tcp_ifaddr .ss_family ;
622
+ copied_interface -> if_flags = selected_interface -> if_flags ;
623
+ copied_interface -> if_speed = selected_interface -> if_speed ;
624
+ memcpy (& copied_interface -> if_addr , & btl -> tcp_ifaddr , sizeof (struct sockaddr_storage ));
625
+ copied_interface -> if_mask = selected_interface -> if_mask ;
626
+ copied_interface -> if_bandwidth = btl -> super .btl_bandwidth ;
627
+ memcpy (& copied_interface -> if_mac , & selected_interface -> if_mac , sizeof (copied_interface -> if_mac ));
628
+ copied_interface -> ifmtu = selected_interface -> ifmtu ;
629
+
630
+ opal_list_append (& mca_btl_tcp_component .local_ifs , & (copied_interface -> super ));
631
+
606
632
opal_output_verbose (5 , opal_btl_base_framework .framework_output ,
607
633
"btl:tcp: %p: if %s kidx %d cnt %i addr %s %s bw %d lt %d\n" ,
608
634
(void * )btl , if_name , (int ) btl -> tcp_ifkindex , i ,
@@ -1188,7 +1214,6 @@ static int mca_btl_tcp_component_exchange(void)
1188
1214
memcpy (& addrs [i ].addr , & (inaddr6 -> sin6_addr ),
1189
1215
sizeof (struct in6_addr ));
1190
1216
addrs [i ].addr_port = mca_btl_tcp_component .tcp6_listen_port ;
1191
- addrs [i ].addr_ifkindex = btl -> tcp_ifkindex ;
1192
1217
addrs [i ].addr_family = MCA_BTL_TCP_AF_INET6 ;
1193
1218
opal_output_verbose (5 , opal_btl_base_framework .framework_output ,
1194
1219
"btl: tcp: exchange: %d %d IPv6 %s" ,
@@ -1202,7 +1227,6 @@ static int mca_btl_tcp_component_exchange(void)
1202
1227
memcpy (& addrs [i ].addr , & (inaddr -> sin_addr ),
1203
1228
sizeof (struct in_addr ));
1204
1229
addrs [i ].addr_port = mca_btl_tcp_component .tcp_listen_port ;
1205
- addrs [i ].addr_ifkindex = btl -> tcp_ifkindex ;
1206
1230
addrs [i ].addr_family = MCA_BTL_TCP_AF_INET ;
1207
1231
opal_output_verbose (5 , opal_btl_base_framework .framework_output ,
1208
1232
"btl: tcp: exchange: %d %d IPv4 %s" ,
@@ -1212,6 +1236,10 @@ static int mca_btl_tcp_component_exchange(void)
1212
1236
BTL_ERROR (("Unexpected address family: %d" , addr -> sa_family ));
1213
1237
return OPAL_ERR_BAD_PARAM ;
1214
1238
}
1239
+
1240
+ addrs [i ].addr_ifkindex = btl -> tcp_ifkindex ;
1241
+ addrs [i ].addr_mask = btl -> tcp_ifmask ;
1242
+ addrs [i ].addr_bandwidth = btl -> super .btl_bandwidth ;
1215
1243
}
1216
1244
1217
1245
OPAL_MODEX_SEND (rc , OPAL_PMIX_GLOBAL ,
0 commit comments