From f7a6c2c4c77e905da732be4a9af729e6f9933119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20R=C3=B6nnblom?= Date: Mon, 31 Jul 2023 13:04:53 +0200 Subject: [PATCH] Disallow configuring scope on IPv4 sockets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new 'tconnect' module failed to maintain legacy semantics in regards to scope usage configuration on IPv4 sockets. Signed-off-by: Mattias Rönnblom --- libxcm/tp/tcp/tconnect.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/libxcm/tp/tcp/tconnect.c b/libxcm/tp/tcp/tconnect.c index 922fae8c1..5fee800bd 100644 --- a/libxcm/tp/tcp/tconnect.c +++ b/libxcm/tp/tcp/tconnect.c @@ -433,7 +433,7 @@ static int tconnect_connect_happy(struct tconnect *tconnect, struct track *track4 = NULL; if (has_ipv4) { - track4 = track_create(tconnect->fd4, -1, local_ip, local_port, scope, + track4 = track_create(tconnect->fd4, -1, local_ip, local_port, -1, tcp_connect_timeout, tcp_opts, remote_ips, num_remote_ips, remote_port, initial_ipv4_delay, tconnect->timer_mgr, tconnect->xpoll, @@ -497,6 +497,18 @@ static int tconnect_connect_sequential(struct tconnect *tconnect, return 0; } +/* For historical reasons, disallow link-local scope configuration in + cases where a single IPv4 address is provided */ +static int check_scope_conf(int64_t scope, const struct xcm_addr_ip *remote_ips, + size_t num_remote_ips) +{ + if (scope >= 0 && num_remote_ips == 1 && remote_ips[0].family == AF_INET) { + errno = EINVAL; + return -1; + } + return 0; +} + int tconnect_connect(struct tconnect *tconnect, const struct xcm_addr_ip *local_ip, uint16_t local_port, int64_t scope, @@ -507,6 +519,9 @@ int tconnect_connect(struct tconnect *tconnect, { ut_assert(num_remote_ips > 0); + if (check_scope_conf(scope, remote_ips, num_remote_ips) < 0) + return -1; + switch (tconnect->algorithm) { case tconnect_algorithm_single: return tconnect_connect_sequential(tconnect, local_ip, local_port,