Skip to content

Commit 4f3d324

Browse files
authored
Merge pull request #10749 from amastbaum/routing_table_check_in_tcp
UCT/TCP: check the routing table during reachability check in TCP
2 parents 9e1c034 + 6bae8c5 commit 4f3d324

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

src/uct/tcp/tcp_iface.c

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "tcp.h"
1212

1313
#include <ucs/async/async.h>
14+
#include <ucs/sys/netlink.h>
1415
#include <ucs/sys/string.h>
1516
#include <ucs/config/types.h>
1617
#include <sys/socket.h>
@@ -201,6 +202,10 @@ uct_tcp_iface_is_reachable_v2(const uct_iface_h tl_iface,
201202
uct_iface_local_addr_ns_t *local_addr_ns;
202203
uct_tcp_device_addr_t *tcp_dev_addr;
203204
int is_local_loopback, is_remote_loopback;
205+
struct sockaddr_storage remote_addr;
206+
char remote_addr_str[UCS_SOCKADDR_STRING_LEN];
207+
unsigned ndev_index;
208+
ucs_status_t status;
204209

205210
if (!uct_iface_is_reachable_params_valid(
206211
params, UCT_IFACE_IS_REACHABLE_FIELD_DEVICE_ADDR)) {
@@ -236,9 +241,38 @@ uct_tcp_iface_is_reachable_v2(const uct_iface_h tl_iface,
236241
}
237242
}
238243

239-
/* Later connect() call can still fail if the peer is actually unreachable
240-
* at UCT/TCP EP creation time */
241-
return uct_iface_scope_is_reachable(tl_iface, params);
244+
if ((params->field_mask & UCT_IFACE_IS_REACHABLE_FIELD_SCOPE) &&
245+
(params->scope == UCT_IFACE_REACHABILITY_SCOPE_DEVICE)) {
246+
return uct_iface_scope_is_reachable(tl_iface, params);
247+
}
248+
249+
/* Check if the remote address is routable */
250+
status = ucs_ifname_to_index(iface->if_name, &ndev_index);
251+
if (status != UCS_OK) {
252+
uct_iface_fill_info_str_buf(
253+
params, "failed to get interface index");
254+
return 0;
255+
}
256+
257+
remote_addr.ss_family = tcp_dev_addr->sa_family;
258+
status = ucs_sockaddr_set_inet_addr((struct sockaddr *)&remote_addr,
259+
tcp_dev_addr + 1);
260+
if (status != UCS_OK) {
261+
uct_iface_fill_info_str_buf(
262+
params, "failed to set inet address");
263+
return 0;
264+
}
265+
266+
if (!ucs_netlink_route_exists(ndev_index,
267+
(const struct sockaddr *)&remote_addr)) {
268+
uct_iface_fill_info_str_buf(
269+
params, "no route to %s",
270+
ucs_sockaddr_str((const struct sockaddr *)&remote_addr,
271+
remote_addr_str, UCS_SOCKADDR_STRING_LEN));
272+
return 0;
273+
}
274+
275+
return 1;
242276
}
243277

244278
static const char *

0 commit comments

Comments
 (0)