selftests: mptcp: join: code dup + new 'bind' tests
Subsystems (3)
Matthieu Baerts (NGI0)
maintainercover selftests: mptcp: join: code dup + new 'bind' tests
A clean-up patch, followed by a few new quick tests validating cases where the listener 'bind()' to a specific IP address.
---
Matthieu Baerts (NGI0) (2):
selftests: mptcp: join: do_transfer: reduce code dup
selftests: mptcp: join: validate extra bind cases
tools/testing/selftests/net/mptcp/mptcp_connect.c | 10 +- tools/testing/selftests/net/mptcp/mptcp_join.sh | 166 ++++++++++++++++++++-- 2 files changed, 166 insertions(+), 10 deletions(-)
---
base-commit: 3afc295b5e6e698696cf1fd75db194db2c7f64cd
change-id: 20251008-bind-extra-listen-7335e35454d2
Best regards,
Signature · 1 line
Matthieu Baerts (NGI0) <[email protected]>
Matthieu Baerts (NGI0)
maintainerPATCH 1/2 selftests: mptcp: join: do_transfer: reduce code dup
The same extra long command is present twice, with one small different:
the var for the stdin file is different.
Use a new dedicated var in one command to avoid this code duplication.
--- tools/testing/selftests/net/mptcp/mptcp_join.sh | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_join.sh +6 -9
@@ -951,6 +951,7 @@ do_transfer() local FAILING_LINKS=${FAILING_LINKS:-""} local fastclose=${fastclose:-""} local speed=${speed:-"fast"} + local in="${sin}" port=$(get_port) :> "$cout"
@@ -999,16 +1000,12 @@ do_transfer() extra_srv_args="$extra_args $extra_srv_args" if [ "$test_linkfail" -gt 1 ];then - timeout ${timeout_test} \ - ip netns exec ${listener_ns} \ - ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \ - $extra_srv_args "::" < "$sinfail" > "$sout" & - else - timeout ${timeout_test} \ - ip netns exec ${listener_ns} \ - ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \ - $extra_srv_args "::" < "$sin" > "$sout" & + in="${sinfail}" fi + timeout ${timeout_test} \ + ip netns exec ${listener_ns} \ + ./mptcp_connect -t ${timeout_poll} -l -p ${port} -s ${srv_proto} \ + ${extra_srv_args} "::" < "${in}" > "${sout}" & local spid=$! mptcp_lib_wait_local_port_listen "${listener_ns}" "${port}"
Signature · 1 line
2.51.0
Re: [PATCH mptcp-next 1/2] selftests: mptcp: join: do_transfer: reduce code dup
Hi Matt,
Quoted 8 lines · On Thu, 2025-10-09 at 19:33 +0200, Matthieu Baerts (NGI0) wrote:
The same extra long command is present twice, with one small different:
the var for the stdin file is different.Use a new dedicated var in one command to avoid this code duplication.
Signed-off-by Matthieu Baerts (NGI0) <[email protected]>
LGTM!
Thanks,
-Geliang
Quoted 46 lines
---
tools/testing/selftests/net/mptcp/mptcp_join.sh | 15 ++++++---------1 file changed, 6 insertions(+), 9 deletions(-)tools/testing/selftests/net/mptcp/mptcp_join.sh +1
-0@@ -951,6 +951,7 @@ do_transfer() local FAILING_LINKS=${FAILING_LINKS:-""} local fastclose=${fastclose:-""} local speed=${speed:-"fast"} + local in="${sin}" port=$(get_port)
:> "$cout"tools/testing/selftests/net/mptcp/mptcp_join.sh +0
-0@@ -999,16 +1000,12 @@ do_transfer()
extra_srv_args="$extra_args $extra_srv_args" if [ "$test_linkfail" -gt 1 ];thentools/testing/selftests/net/mptcp/mptcp_join.sh +0
-3- timeout ${timeout_test} \ - ip netns exec ${listener_ns} \ - ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \
tools/testing/selftests/net/mptcp/mptcp_join.sh +0
-1- $extra_srv_args "::" <"$sinfail" > "$sout" &
tools/testing/selftests/net/mptcp/mptcp_join.sh +0
-4- else - timeout ${timeout_test} \ - ip netns exec ${listener_ns} \ - ./mptcp_connect -t ${timeout_poll} -l -p $port -s ${srv_proto} \
tools/testing/selftests/net/mptcp/mptcp_join.sh +0
-1- $extra_srv_args "::" <"$sin" > "$sout" &
tools/testing/selftests/net/mptcp/mptcp_join.sh +1
-0+ in="${sinfail}"fi
tools/testing/selftests/net/mptcp/mptcp_join.sh +3
-0+ timeout ${timeout_test} \ + ip netns exec ${listener_ns} \ + ./mptcp_connect -t ${timeout_poll} -l -p${port} -s ${srv_proto} \
tools/testing/selftests/net/mptcp/mptcp_join.sh +1
-0+ ${extra_srv_args} "::" < "${in}" >"${sout}" &
local spid=$!
mptcp_lib_wait_local_port_listen"${listener_ns}" "${port}"
Matthieu Baerts (NGI0)
maintainerPATCH 2/2 selftests: mptcp: join: validate extra bind cases
In reply to Matthieu Baerts (NGI0)By design, an MPTCP connection will not accept extra subflows where no MPTCP listening sockets can accept such requests.
In other words, it means that if the 'server' listens on a specific address / device, it cannot accept MP_JOIN sent to a different address / device. Except if there is another MPTCP listening socket accepting them.
This is what the new tests are validating:
- Forcing a bind on the main v4/v6 address, and checking that MP_JOIN to announced addresses are not accepted.
- Also forcing a bind on the main v4/v6 address, but before, another listening socket is created to accept additional subflows. Note that 'mptcpize run nc -l' -- or something else only doing: socket(MPTCP), bind(<IP>), listen(0) -- would be enough, but here mptcp_connect is reused not to depend on another tool just for that.
- Same as the previous one, but using v6 link-local addresses: this is a bit particular because it is required to specify the outgoing network interface when connecting to a link-local address announced by the other peer. When using the routing rules, this doesn't work (the outgoing interface is not known) ; but it does work with a 'laminar' endpoint having a specified interface.
Note that extra small modifications are needed for these tests to work:
- mptcp_connect's check_getpeername_connect() check should strip the specified interface when comparing addresses.
- With IPv6 link-local addresses, it is required to wait for them to be ready (no longer in 'tentative' mode) before using them, otherwise the bind() will not be allowed.
--- tools/testing/selftests/net/mptcp/mptcp_connect.c | 10 +- tools/testing/selftests/net/mptcp/mptcp_join.sh | 153 +++++++++++++++++++++- 2 files changed, 161 insertions(+), 2 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_connect.c +9 -1
@@ -1064,6 +1064,8 @@ static void check_getpeername_connect(int fd)socklen_t salen =sizeof (ss);char a[INET6_ADDRSTRLEN ];char b[INET6_ADDRSTRLEN ]; +const char *iface; +size_t len;if (getpeername (fd, (struct sockaddr *)&ss, &salen) <0 ) {perror ("getpeername" );
@@ -1073,7 +1075,13 @@ static void check_getpeername_connect(int fd)xgetnameinfo ((struct sockaddr *)&ss, salen, a,sizeof (a), b,sizeof (b)); -if (strcmp (cfg_host, a) ||strcmp (cfg_port, b)) + iface =strchr (cfg_host,'%' ); +if (iface) + len = iface - cfg_host; +else + len =strlen (cfg_host) +1 ; + +if (strncmp (cfg_host, a, len) ||strcmp (cfg_port, b))fprintf (stderr,"%s: %s vs %s, %s vs %s\n" , __func__, cfg_host, a, cfg_port, b); }
tools/testing/selftests/net/mptcp/mptcp_join.sh +152 -1
189 lines not on this page · raw message
Signature · 1 line
2.51.0
Re: [PATCH mptcp-next 2/2] selftests: mptcp: join: validate extra bind cases
Hi Matt,
It took me some time to understand this test.
Quoted 71 lines · On Thu, 2025-10-09 at 19:33 +0200, Matthieu Baerts (NGI0) wrote:
By design, an MPTCP connection will not accept extra subflows where no
MPTCP listening sockets can accept such requests.In other words, it means that if the 'server' listens on a specific address / device, it cannot accept
MP_JOINsent to a different address /
device. Except if there is another MPTCP listening socket accepting them.This is what the new tests are validating:
- Forcing a bind on the main v4/v6 address, and checking that
MP_JOIN
to announced addresses are not accepted.- Also forcing a bind on the main v4/v6 address, but before, another listening socket is created to accept additional subflows. Note that
'mptcpize run nc -l' -- or something else only doing:
socket(MPTCP),
bind(<IP>), listen(0) -- would be enough, but heremptcp_connectis
reused not to depend on another tool just for that.- Same as the previous one, but using v6 link-local addresses: this is
a bit particular because it is required to specify the outgoing network interface when connecting to a link-local address announced
by the other peer. When using the routing rules, this doesn't work (the outgoing interface is not known) ; but it does work with a 'laminar' endpoint having a specified interface.Note that extra small modifications are needed for these tests to work:
- mptcp_connect's
check_getpeername_connect()check should strip the specified interface when comparing addresses.- With IPv6 link-local addresses, it is required to wait for them to be ready (no longer in 'tentative' mode) before using them, otherwise
thebind()will not be allowed.Signed-off-by Matthieu Baerts (NGI0) <[email protected]>---
tools/testing/selftests/net/mptcp/mptcp_connect.c | 10 +- tools/testing/selftests/net/mptcp/mptcp_join.sh | 153
+++++++++++++++++++++-2 files changed, 161 insertions(+), 2 deletions(-)tools/testing/selftests/net/mptcp/mptcp_connect.c +2
-0@@ -1064,6 +1064,8 @@ static void check_getpeername_connect(int fd) socklen_t salen = sizeof(ss); char a[INET6_ADDRSTRLEN]; char b[INET6_ADDRSTRLEN]; +const char *iface; +size_t len;
if (getpeername(fd, (struct sockaddr *)&ss, &salen)< 0) {perror("getpeername");tools/testing/selftests/net/mptcp/mptcp_connect.c +0
-0@@ -1073,7 +1075,13 @@ static void check_getpeername_connect(int fd) xgetnameinfo((struct sockaddr *)&ss, salen, a, sizeof(a), b, sizeof(b));
tools/testing/selftests/net/mptcp/mptcp_connect.c static void check_getpeername_connect(int fd) · line 1082
Quoted 6 lines
tools/testing/selftests/net/mptcp/mptcp_connect.c +5
-1-if (strcmp (cfg_host, a) ||strcmp (cfg_port, b)) + iface =strchr (cfg_host,'%' ); +if (iface) + len = iface - cfg_host; +else + len =strlen (cfg_host) +1 ;
Why do we need to add 1 here? I tested it and it works without adding 1.
Other than this minor comment, everything looks good to me. No need for a v2; it can be modified when applying if needed.
Thanks,
-Geliang
Quoted 230 lines
tools/testing/selftests/net/mptcp/mptcp_connect.c +2
-0+ +if (strncmp (cfg_host, a, len) ||strcmp (cfg_port, b))fprintf(stderr, "%s: %s vs %s, %s vs %s\n",
__func__,
cfg_host, a,cfg_port, b); }tools/testing/selftests/net/mptcp/mptcp_join.sh +0
-0@@ -62,6 +62,7 @@ unset sflagsunset fastclose
unset fullmesh
unset speed
+unsetbind_addr
unsetjoin_syn_rej
unsetjoin_csum_ns1
unsetjoin_csum_ns2tools/testing/selftests/net/mptcp/mptcp_join.sh +0
-0@@ -645,6 +646,27 @@ wait_mpj()done
}tools/testing/selftests/net/mptcp/mptcp_join.sh +7
-0+wait_ll_ready() +{ + local ns="${1}" + + local i + for i in $(seq 50); do + ip -n "${ns}" -6 addr show scope link | grep "inet6fe80" |
tools/testing/selftests/net/mptcp/mptcp_join.sh +14
-0+ grep -qw "tentative" || break + sleep 0.1 + done +} + +get_ll_addr() +{ + local ns="${1}" + local iface="${2}" + + ip -n "${ns}" -6 addr show dev "${iface}" scope link | + grep "inet6 fe80" | sed 's#.*\(fe80::.*\)/.*#\1#' +} +kill_events_pids()
{
mptcp_lib_kill_wait$evts_ns1_pidtools/testing/selftests/net/mptcp/mptcp_join.sh +0
-0@@ -952,6 +974,7 @@ do_transfer() local fastclose=${fastclose:-""} local speed=${speed:-"fast"}local in="${sin}"
tools/testing/selftests/net/mptcp/mptcp_join.sh +1
-0+ local bind_addr=${bind_addr:-"::"}port=$(get_port)
:> "$cout"tools/testing/selftests/net/mptcp/mptcp_join.sh +0
-0@@ -1005,7 +1028,7 @@ do_transfer() timeout ${timeout_test} \ ip netns exec ${listener_ns} \./mptcp_connect -t ${timeout_poll} -l -p ${port} -s ${srv_proto} \
tools/testing/selftests/net/mptcp/mptcp_join.sh +0
-1- ${extra_srv_args} "::" < "${in}" >"${sout}" &
tools/testing/selftests/net/mptcp/mptcp_join.sh +1
-0+ ${extra_srv_args} "${bind_addr}" <"${in}" > "${sout}" &
local spid=$!
mptcp_lib_wait_local_port_listen"${listener_ns}" "${port}"tools/testing/selftests/net/mptcp/mptcp_join.sh +0
-0@@ -3230,6 +3253,133 @@ add_addr_ports_tests()fi
}tools/testing/selftests/net/mptcp/mptcp_join.sh +3
-0+bind_tests() +{ + # bind to one address should not allow extra subflows toother addresses
tools/testing/selftests/net/mptcp/mptcp_join.sh +12
-0+ if reset "bind main address v4, no join v4"; then + pm_nl_set_limits $ns1 0 2 + pm_nl_set_limits $ns2 2 2 + pm_nl_add_endpoint $ns1 10.0.2.1 flags signal + bind_addr="10.0.1.1" \ + run_tests $ns1 $ns2 10.0.1.1 + join_syn_tx=1 \ + chk_join_nr 0 0 0 + chk_add_nr 1 1 + fi + + # bind to one address should not allow extra subflows toother addresses
tools/testing/selftests/net/mptcp/mptcp_join.sh +20
-0+ if reset "bind main address v6, no join v6"; then + pm_nl_set_limits $ns1 0 2 + pm_nl_set_limits $ns2 2 2 + pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal + bind_addr="dead:beef:1::1" \ + run_tests $ns1 $ns2 dead:beef:1::1 + join_syn_tx=1 \ + chk_join_nr 0 0 0 + chk_add_nr 1 1 + fi + + # multiple binds to allow extra subflows to other addresses + if reset "multiple bind to allow joins v4"; then + local extra_bind + + pm_nl_set_limits $ns1 0 2 + pm_nl_set_limits $ns2 2 2 + pm_nl_add_endpoint $ns1 10.0.2.1 flags signal + + # Launching another app listening on a differentaddress
tools/testing/selftests/net/mptcp/mptcp_join.sh +1
-0+ # Note: it could be a totally different app, e.g.nc, socat, ...
tools/testing/selftests/net/mptcp/mptcp_join.sh +1
-0+ ip netns exec ${ns1} ./mptcp_connect -l -p"$(get_port)" \
tools/testing/selftests/net/mptcp/mptcp_join.sh +20
-0+ -s MPTCP 10.0.2.1 & + extra_bind=$! + + bind_addr="10.0.1.1" \ + run_tests $ns1 $ns2 10.0.1.1 + chk_join_nr 1 1 1 + chk_add_nr 1 1 + + kill ${extra_bind} + fi + + # multiple binds to allow extra subflows to other addresses + if reset "multiple bind to allow joins v6"; then + local extra_bind + + pm_nl_set_limits $ns1 0 2 + pm_nl_set_limits $ns2 2 2 + pm_nl_add_endpoint $ns1 dead:beef:2::1 flags signal + + # Launching another app listening on a differentaddress
tools/testing/selftests/net/mptcp/mptcp_join.sh +1
-0+ # Note: it could be a totally different app, e.g.nc, socat, ...
tools/testing/selftests/net/mptcp/mptcp_join.sh +1
-0+ ip netns exec ${ns1} ./mptcp_connect -l -p"$(get_port)" \
tools/testing/selftests/net/mptcp/mptcp_join.sh +12
-0+ -s MPTCP dead:beef:2::1 & + extra_bind=$! + + bind_addr="dead:beef:1::1" \ + run_tests $ns1 $ns2 dead:beef:1::1 + chk_join_nr 1 1 1 + chk_add_nr 1 1 + + kill ${extra_bind} + fi + + # multiple binds to allow extra subflows to other addresses:v6 LL case
tools/testing/selftests/net/mptcp/mptcp_join.sh +1
-0+ if reset "multiple bind to allow joins v6 link-localrouting"; then
tools/testing/selftests/net/mptcp/mptcp_join.sh +11
-0+ local extra_bind ns1ll1 ns1ll2 + + ns1ll1="$(get_ll_addr $ns1 ns1eth1)" + ns1ll2="$(get_ll_addr $ns1 ns1eth2)" + + pm_nl_set_limits $ns1 0 2 + pm_nl_set_limits $ns2 2 2 + pm_nl_add_endpoint $ns1 "${ns1ll2}" flags signal + + wait_ll_ready $ns1 # to be able to bind + wait_ll_ready $ns2 # also needed to bind on theclient side
tools/testing/selftests/net/mptcp/mptcp_join.sh +1
-0+ ip netns exec ${ns1} ./mptcp_connect -l -p"$(get_port)" \
tools/testing/selftests/net/mptcp/mptcp_join.sh +6
-0+ -s MPTCP "${ns1ll2}%ns1eth2" & + extra_bind=$! + + bind_addr="${ns1ll1}%ns1eth1" \ + run_tests $ns1 $ns2 "${ns1ll1}%ns2eth1" + # it is not possible to connect to the announced LLaddr without
tools/testing/selftests/net/mptcp/mptcp_join.sh +9
-0+ # specifying the outgoing interface. + join_connect_err=1 \ + chk_join_nr 0 0 0 + chk_add_nr 1 1 + + kill ${extra_bind} + fi + + # multiple binds to allow extra subflows to v6 LL addresses:laminar
tools/testing/selftests/net/mptcp/mptcp_join.sh +1
-0+ if reset "multiple bind to allow joins v6 link-locallaminar" &&
tools/testing/selftests/net/mptcp/mptcp_join.sh +1
-0+ continue_if mptcp_lib_kallsyms_has"mptcp_pm_get_endp_laminar_max$"; then
tools/testing/selftests/net/mptcp/mptcp_join.sh +10
-0+ local extra_bind ns1ll1 ns1ll2 ns2ll2 + + ns1ll1="$(get_ll_addr $ns1 ns1eth1)" + ns1ll2="$(get_ll_addr $ns1 ns1eth2)" + ns2ll2="$(get_ll_addr $ns2 ns2eth2)" + + pm_nl_set_limits $ns1 0 2 + pm_nl_set_limits $ns2 2 2 + pm_nl_add_endpoint $ns1 "${ns1ll2}" flags signal + pm_nl_add_endpoint $ns2 "${ns2ll2}" flags laminardev ns2eth2
tools/testing/selftests/net/mptcp/mptcp_join.sh +3
-0+ + wait_ll_ready $ns1 # to be able to bind + wait_ll_ready $ns2 # also needed to bind on theclient side
tools/testing/selftests/net/mptcp/mptcp_join.sh +1
-0+ ip netns exec ${ns1} ./mptcp_connect -l -p"$(get_port)" \
tools/testing/selftests/net/mptcp/mptcp_join.sh +12
-0+ -s MPTCP "${ns1ll2}%ns1eth2" & + extra_bind=$! + + bind_addr="${ns1ll1}%ns1eth1" \ + run_tests $ns1 $ns2 "${ns1ll1}%ns2eth1" + chk_join_nr 1 1 1 + chk_add_nr 1 1 + + kill ${extra_bind} + fi +} +syncookies_tests()
{# single subflow, syncookiestools/testing/selftests/net/mptcp/mptcp_join.sh +0
-0@@ -4184,6 +4334,7 @@ all_tests_sorted=(M@mixed_tests
b@backup_tests
p@add_addr_ports_teststools/testing/selftests/net/mptcp/mptcp_join.sh +1
-0+ B@bind_testsk@syncookies_tests
S@checksum_tests
d@deny_join_id0_tests
Matthieu Baerts
maintainerRe: [PATCH mptcp-next 2/2] selftests: mptcp: join: validate extra bind cases
Hi Geliang,
Thank you for the review!
Quoted 1 line · Geliang Tang
It took me some time to understand this test.
Is there something I should add in the commit message to make this clearer?
Quoted 73 lines · On Thu, 2025-10-09 at 19:33 +0200, Matthieu Baerts (NGI0) wrote:
Quoted 72 lines
By design, an MPTCP connection will not accept extra subflows where no
MPTCP listening sockets can accept such requests.In other words, it means that if the 'server' listens on a specific address / device, it cannot accept
MP_JOINsent to a different address /
device. Except if there is another MPTCP listening socket accepting them.This is what the new tests are validating:
- Forcing a bind on the main v4/v6 address, and checking that
MP_JOIN
to announced addresses are not accepted.- Also forcing a bind on the main v4/v6 address, but before, another listening socket is created to accept additional subflows. Note that
'mptcpize run nc -l' -- or something else only doing:
socket(MPTCP),
bind(<IP>), listen(0) -- would be enough, but heremptcp_connectis
reused not to depend on another tool just for that.- Same as the previous one, but using v6 link-local addresses: this is
a bit particular because it is required to specify the outgoing network interface when connecting to a link-local address announced
by the other peer. When using the routing rules, this doesn't work (the outgoing interface is not known) ; but it does work with a 'laminar' endpoint having a specified interface.Note that extra small modifications are needed for these tests to work:
- mptcp_connect's
check_getpeername_connect()check should strip the specified interface when comparing addresses.- With IPv6 link-local addresses, it is required to wait for them to be ready (no longer in 'tentative' mode) before using them, otherwise
thebind()will not be allowed.Signed-off-by Matthieu Baerts (NGI0) <[email protected]>---
tools/testing/selftests/net/mptcp/mptcp_connect.c | 10 +- tools/testing/selftests/net/mptcp/mptcp_join.sh | 153
+++++++++++++++++++++-2 files changed, 161 insertions(+), 2 deletions(-)tools/testing/selftests/net/mptcp/mptcp_connect.c +2
-0@@ -1064,6 +1064,8 @@ static void check_getpeername_connect(int fd) socklen_t salen = sizeof(ss); char a[INET6_ADDRSTRLEN]; char b[INET6_ADDRSTRLEN]; +const char *iface; +size_t len;
if (getpeername(fd, (struct sockaddr *)&ss, &salen)< 0) {perror("getpeername");tools/testing/selftests/net/mptcp/mptcp_connect.c +0
-0@@ -1073,7 +1075,13 @@ static void check_getpeername_connect(int fd) xgetnameinfo((struct sockaddr *)&ss, salen, a, sizeof(a), b, sizeof(b));tools/testing/selftests/net/mptcp/mptcp_connect.c +0
-1-if (strcmp (cfg_host, a) ||strcmp (cfg_port, b))
Quoted 8 lines
tools/testing/selftests/net/mptcp/mptcp_connect.c static void check_getpeername_connect(int fd) · line 1082
Quoted 5 lines
tools/testing/selftests/net/mptcp/mptcp_connect.c +5
-0+ iface =strchr (cfg_host,'%' ); +if (iface) + len = iface - cfg_host; +else + len =strlen (cfg_host) +1 ;Why do we need to add 1 here? I tested it and it works without adding 1.
If I don't add 1, I will not include '\0' in the comparison with "a".
In other words, if you have:
cfg_host = "abc"; a = "abc123"; len = strlen(cfg_host); /* = 3 */
Then strncmp(cfg_host, a, len) will return 0 because the 3 first chars are "abc". With 4 chars, they are different: "abc\0" vs "abc1".
So it is important to take the delimiter into account, just in case one is the prefix of the other one.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Geliang Tang
reviewerRe: [PATCH mptcp-next 2/2] selftests: mptcp: join: validate extra bind cases
Hi Matt,
Quoted 115 lines · Matthieu Baerts
Hi Geliang,
Thank you for the review!
Quoted 1 line · Geliang Tang
It took me some time to understand this test.
Is there something I should add in the commit message to make this clearer?
Quoted 89 lines · On Thu, 2025-10-09 at 19:33 +0200, Matthieu Baerts (NGI0) wrote:
Quoted 88 lines
By design, an MPTCP connection will not accept extra subflows where
no
MPTCP listening sockets can accept such requests.In other words, it means that if the 'server' listens on a specific
address / device, it cannot acceptMP_JOINsent to a different address /
device. Except if there is another MPTCP listening socket accepting
them.This is what the new tests are validating:
- Forcing a bind on the main v4/v6 address, and checking that
MP_JOIN
to announced addresses are not accepted.- Also forcing a bind on the main v4/v6 address, but before, another
listening socket is created to accept additional subflows. Note
that
'mptcpize run nc -l' -- or something else only doing:
socket(MPTCP),
bind(<IP>), listen(0) -- would be enough, but heremptcp_connect
is
reused not to depend on another tool just for that.- Same as the previous one, but using v6 link-local addresses:
this
is
a bit particular because it is required to specify the outgoing
network interface when connecting to a link-local address announced
by the other peer. When using the routing rules, this doesn't work
(the outgoing interface is not known) ; but it does work with a
'laminar' endpoint having a specified interface.Note that extra small modifications are needed for these tests to work:
- mptcp_connect's
check_getpeername_connect()check should strip the
specified interface when comparing addresses.- With IPv6 link-local addresses, it is required to wait for them to
be ready (no longer in 'tentative' mode) before using them, otherwise
thebind()will not be allowed.Signed-off-by Matthieu Baerts (NGI0) <[email protected]>---
tools/testing/selftests/net/mptcp/mptcp_connect.c | 10 +- tools/testing/selftests/net/mptcp/mptcp_join.sh | 153
+++++++++++++++++++++-2 files changed, 161 insertions(+), 2 deletions(-)tools/testing/selftests/net/mptcp/mptcp_connect.c +2
-0@@ -1064,6 +1064,8 @@ static void check_getpeername_connect(int fd) socklen_t salen = sizeof(ss); char a[INET6_ADDRSTRLEN]; char b[INET6_ADDRSTRLEN]; +const char *iface; +size_t len;
if (getpeername(fd, (struct sockaddr *)&ss, &salen)< 0) {
perror("getpeername");tools/testing/selftests/net/mptcp/mptcp_connect.c +0
-0@@ -1073,7 +1075,13 @@ static void check_getpeername_connect(int fd) xgetnameinfo((struct sockaddr *)&ss, salen, a, sizeof(a), b, sizeof(b));tools/testing/selftests/net/mptcp/mptcp_connect.c +1
-1-if (strcmp (cfg_host, a) ||strcmp (cfg_port, b)) + iface =strchr (cfg_host,'%' );Quoted 8 lines
tools/testing/selftests/net/mptcp/mptcp_connect.c static void check_getpeername_connect(int fd) · line 1082
Quoted 4 lines
tools/testing/selftests/net/mptcp/mptcp_connect.c +4
-0+if (iface) + len = iface - cfg_host; +else + len =strlen (cfg_host) +1 ;Why do we need to add 1 here? I tested it and it works without adding
1.If I don't add 1, I will not include '\0' in the comparison with "a".
In other words, if you have:
cfg_host= "abc";
a = "abc123";
len =strlen(cfg_host); /* = 3 */
Quoted 7 lines
Then
strncmp(cfg_host, a, len)will return 0 because the 3 first chars
are "abc". With 4 chars, they are different: "abc\0" vs "abc1".So it is important to take the delimiter into account, just in case one
is the prefix of the other one.
Sure, thanks for your explanation. I have no other comments, let's apply this set.
Thanks,
-Geliang
Quoted 3 lines
Cheers,
Matt
Hi Matthieu,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal (except selftest_mptcp_join): Unstable: 1 failed test(s): selftest_simult_flows 🔴
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Success! ✅
- KVM Validation: debug (only selftest_mptcp_join): Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/18384474239
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/cb24879849d8
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1009827
If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-normalFor more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)
Matthieu Baerts
maintainerHi Geliang,
Quoted 2 lines · On 09/10/2025 19:33, Matthieu Baerts (NGI0) wrote:
A clean-up patch, followed by a few new quick tests validating cases where the listener '
bind()' to a specific IP address.
Thank you for the review!
Now in our tree (feat. for net-next):
New patches for t/upstream:
- f421ad2aa981: selftests: mptcp: join: do_transfer: reduce code dup
- 4fd0cfa3ab1a: selftests: mptcp: join: validate extra bind cases
- Results: fe9c3cb19630..f6f85b548772 (export)
Tests are now in progress:
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.