Skip to content

Commit 31f6c75

Browse files
author
Ralph Castain
authored
Merge pull request #5819 from bosilca/fix/local_bind
Fix/local bind
2 parents a25df3f + a3a492b commit 31f6c75

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

opal/mca/btl/tcp/btl_tcp_component.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,9 @@ static int mca_btl_tcp_component_open(void)
361361
#if OPAL_ENABLE_IPV6
362362
mca_btl_tcp_component.tcp6_listen_sd = -1;
363363
#endif
364-
mca_btl_tcp_component.tcp_num_btls=0;
364+
mca_btl_tcp_component.tcp_num_btls = 0;
365365
mca_btl_tcp_component.tcp_addr_count = 0;
366-
mca_btl_tcp_component.tcp_btls=NULL;
366+
mca_btl_tcp_component.tcp_btls = NULL;
367367

368368
/* initialize objects */
369369
OBJ_CONSTRUCT(&mca_btl_tcp_component.tcp_lock, opal_mutex_t);

opal/mca/btl/tcp/btl_tcp_endpoint.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -728,34 +728,39 @@ static int mca_btl_tcp_endpoint_start_connect(mca_btl_base_endpoint_t* btl_endpo
728728

729729
/* start the connect - will likely fail with EINPROGRESS */
730730
mca_btl_tcp_proc_tosocks(btl_endpoint->endpoint_addr, &endpoint_addr);
731-
731+
732732
/* Bind the socket to one of the addresses associated with
733733
* this btl module. This sets the source IP to one of the
734734
* addresses shared in modex, so that the destination rank
735735
* can properly pair btl modules, even in cases where Linux
736736
* might do something unexpected with routing */
737-
opal_socklen_t sockaddr_addrlen = sizeof(struct sockaddr_storage);
738737
if (endpoint_addr.ss_family == AF_INET) {
739738
assert(NULL != &btl_endpoint->endpoint_btl->tcp_ifaddr);
740739
if (bind(btl_endpoint->endpoint_sd, (struct sockaddr*) &btl_endpoint->endpoint_btl->tcp_ifaddr,
741-
sockaddr_addrlen) < 0) {
742-
BTL_ERROR(("bind() failed: %s (%d)", strerror(opal_socket_errno), opal_socket_errno));
740+
sizeof(struct sockaddr_in)) < 0) {
741+
BTL_ERROR(("bind on local address (%s:%d) failed: %s (%d)",
742+
opal_net_get_hostname((struct sockaddr*) &btl_endpoint->endpoint_btl->tcp_ifaddr),
743+
htons(((struct sockaddr_in*)&btl_endpoint->endpoint_btl->tcp_ifaddr)->sin_port),
744+
strerror(opal_socket_errno), opal_socket_errno));
743745

744-
CLOSE_THE_SOCKET(btl_endpoint->endpoint_sd);
745-
return OPAL_ERROR;
746-
}
746+
CLOSE_THE_SOCKET(btl_endpoint->endpoint_sd);
747+
return OPAL_ERROR;
748+
}
747749
}
748750
#if OPAL_ENABLE_IPV6
749751
if (endpoint_addr.ss_family == AF_INET6) {
750752
assert(NULL != &btl_endpoint->endpoint_btl->tcp_ifaddr_6);
751753
if (bind(btl_endpoint->endpoint_sd, (struct sockaddr*) &btl_endpoint->endpoint_btl->tcp_ifaddr_6,
752-
sockaddr_addrlen) < 0) {
753-
BTL_ERROR(("bind() failed: %s (%d)", strerror(opal_socket_errno), opal_socket_errno));
754+
sizeof(struct sockaddr_in6)) < 0) {
755+
BTL_ERROR(("bind on local address (%s:%d) failed: %s (%d)",
756+
opal_net_get_hostname((struct sockaddr*) &btl_endpoint->endpoint_btl->tcp_ifaddr),
757+
htons(((struct sockaddr_in*)&btl_endpoint->endpoint_btl->tcp_ifaddr)->sin_port),
758+
strerror(opal_socket_errno), opal_socket_errno));
754759

755-
CLOSE_THE_SOCKET(btl_endpoint->endpoint_sd);
756-
return OPAL_ERROR;
757-
}
758-
}
760+
CLOSE_THE_SOCKET(btl_endpoint->endpoint_sd);
761+
return OPAL_ERROR;
762+
}
763+
}
759764
#endif
760765
opal_output_verbose(10, opal_btl_base_framework.framework_output,
761766
"btl: tcp: attempting to connect() to %s address %s on port %d",

opal/mca/btl/tcp/btl_tcp_proc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -732,12 +732,12 @@ int mca_btl_tcp_proc_insert( mca_btl_tcp_proc_t* btl_proc,
732732
}
733733
free(proc_data->local_interfaces[i]);
734734
}
735-
free(proc_data->local_interfaces);
735+
free(proc_data->local_interfaces); proc_data->local_interfaces = NULL;
736736
proc_data->max_local_interfaces = 0;
737737

738-
free(proc_data->weights);
739-
free(proc_data->best_addr);
740-
free(proc_data->best_assignment);
738+
free(proc_data->weights); proc_data->weights = NULL;
739+
free(proc_data->best_addr); proc_data->best_addr = NULL;
740+
free(proc_data->best_assignment); proc_data->best_assignment = NULL;
741741

742742
OBJ_DESTRUCT(&_proc_data.local_kindex_to_index);
743743
OBJ_DESTRUCT(&_proc_data.peer_kindex_to_index);

0 commit comments

Comments
 (0)