Skip to content

Commit 4f19221

Browse files
committed
btl tcp: Simplify module address storage
Today, a btl tcp module is associated with exactly one IP address (IPv4 or IPv6). There's no need to reserve space for both an IPv4 and IPv6 address in the module structure, since the module will only be associated with one or the other. Signed-off-by: Brian Barrett <bbarrett@amazon.com>
1 parent a435bfe commit 4f19221

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

opal/mca/btl/tcp/btl_tcp.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,11 @@ OPAL_MODULE_DECLSPEC extern mca_btl_tcp_component_t mca_btl_tcp_component;
164164
struct mca_btl_tcp_module_t {
165165
mca_btl_base_module_t super; /**< base BTL interface */
166166
uint16_t tcp_ifkindex; /** <BTL kernel interface index */
167-
#if 0
168-
int tcp_ifindex; /**< BTL interface index */
169-
#endif
170-
struct sockaddr_storage tcp_ifaddr; /**< First IPv4 address discovered for this interface, bound as sending address for this BTL */
171-
#if OPAL_ENABLE_IPV6
172-
struct sockaddr_storage tcp_ifaddr_6; /**< First IPv6 address discovered for this interface, bound as sending address for this BTL */
173-
#endif
167+
struct sockaddr_storage tcp_ifaddr; /**< First address
168+
discovered for this
169+
interface, bound as
170+
sending address for this
171+
BTL */
174172
uint32_t tcp_ifmask; /**< BTL interface netmask */
175173

176174
opal_mutex_t tcp_endpoints_mutex;

opal/mca/btl/tcp/btl_tcp_component.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -513,17 +513,12 @@ static int mca_btl_tcp_create(int if_kindex, const char* if_name)
513513
btl->tcp_send_handler = 0;
514514
#endif
515515

516-
struct sockaddr_storage addr;
517-
opal_ifkindextoaddr(if_kindex, (struct sockaddr*) &addr,
518-
sizeof (struct sockaddr_storage));
519-
#if OPAL_ENABLE_IPV6
520-
if (addr.ss_family == AF_INET6) {
521-
btl->tcp_ifaddr_6 = addr;
522-
}
523-
#endif
524-
if (addr.ss_family == AF_INET) {
525-
btl->tcp_ifaddr = addr;
526-
}
516+
/* save the address associated with this kindex in the module
517+
to publish in the modex and use as the source of all packets
518+
from this module */
519+
opal_ifkindextoaddr(if_kindex, (struct sockaddr*)&btl->tcp_ifaddr,
520+
sizeof (struct sockaddr_storage));
521+
527522
/* allow user to specify interface bandwidth */
528523
sprintf(param, "bandwidth_%s", if_name);
529524
mca_btl_tcp_param_register_uint(param, NULL, btl->super.btl_bandwidth, OPAL_INFO_LVL_5, &btl->super.btl_bandwidth);
@@ -567,8 +562,8 @@ static int mca_btl_tcp_create(int if_kindex, const char* if_name)
567562
opal_output_verbose(5, opal_btl_base_framework.framework_output,
568563
"btl:tcp: %p: if %s kidx %d cnt %i addr %s %s bw %d lt %d\n",
569564
(void*)btl, if_name, (int) btl->tcp_ifkindex, i,
570-
opal_net_get_hostname((struct sockaddr*)&addr),
571-
(addr.ss_family == AF_INET) ? "IPv4" : "IPv6",
565+
opal_net_get_hostname((struct sockaddr*)&btl->tcp_ifaddr),
566+
(btl->tcp_ifaddr.ss_family == AF_INET) ? "IPv4" : "IPv6",
572567
btl->super.btl_bandwidth, btl->super.btl_latency);
573568
}
574569
return OPAL_SUCCESS;
@@ -721,6 +716,7 @@ static int mca_btl_tcp_component_create_instances(void)
721716
*/
722717
for(if_index = opal_ifbegin(); if_index >= 0; if_index = opal_ifnext(if_index)){
723718
int index = opal_ifindextokindex (if_index);
719+
724720
if (index > 0) {
725721
bool want_this_if = true;
726722

@@ -1172,7 +1168,7 @@ static int mca_btl_tcp_component_exchange(void)
11721168
(6 != mca_btl_tcp_component.tcp_disable_family)) {
11731169
memcpy(&addrs[current_addr].addr_inet,
11741170
&((struct sockaddr_in6*)&my_ss)->sin6_addr,
1175-
sizeof(addrs[0].addr_inet));
1171+
sizeof(addrs[0].addr_inet));
11761172
addrs[current_addr].addr_port =
11771173
mca_btl_tcp_component.tcp6_listen_port;
11781174
addrs[current_addr].addr_family = MCA_BTL_TCP_AF_INET6;

opal/mca/btl/tcp/btl_tcp_endpoint.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,11 +743,11 @@ static int mca_btl_tcp_endpoint_start_connect(mca_btl_base_endpoint_t* btl_endpo
743743
#if OPAL_ENABLE_IPV6
744744
if (endpoint_addr.ss_family == AF_INET6) {
745745
assert(NULL != &btl_endpoint->endpoint_btl->tcp_ifaddr_6);
746-
if (bind(btl_endpoint->endpoint_sd, (struct sockaddr*) &btl_endpoint->endpoint_btl->tcp_ifaddr_6,
746+
if (bind(btl_endpoint->endpoint_sd, (struct sockaddr*) &btl_endpoint->endpoint_btl->tcp_ifaddr,
747747
sizeof(struct sockaddr_in6)) < 0) {
748748
BTL_ERROR(("bind on local address (%s:%d) failed: %s (%d)",
749749
opal_net_get_hostname((struct sockaddr*) &btl_endpoint->endpoint_btl->tcp_ifaddr),
750-
htons(((struct sockaddr_in*)&btl_endpoint->endpoint_btl->tcp_ifaddr)->sin_port),
750+
htons(((struct sockaddr_in6*)&btl_endpoint->endpoint_btl->tcp_ifaddr)->sin6_port),
751751
strerror(opal_socket_errno), opal_socket_errno));
752752

753753
CLOSE_THE_SOCKET(btl_endpoint->endpoint_sd);

0 commit comments

Comments
 (0)