--- /dev/null
+From 81ab772819da408977ac79c0a17d8be57283379f Mon Sep 17 00:00:00 2001
+From: Geliang Tang <geliang.tang@linux.dev>
+Date: Fri, 22 Dec 2023 13:47:25 +0100
+Subject: selftests: mptcp: diag: check CURRESTAB counters
+
+From: Geliang Tang <geliang.tang@linux.dev>
+
+commit 81ab772819da408977ac79c0a17d8be57283379f upstream.
+
+This patch adds a new helper chk_msk_cestab() to check the current
+established connections counter MIB_CURRESTAB in diag.sh. Invoke it
+to check the counter during the connection after every chk_msk_inuse().
+
+Signed-off-by: Geliang Tang <geliang.tang@linux.dev>
+Reviewed-by: Matthieu Baerts <matttbe@kernel.org>
+Signed-off-by: Matthieu Baerts <matttbe@kernel.org>
+Signed-off-by: David S. Miller <davem@davemloft.net>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/testing/selftests/net/mptcp/diag.sh | 17 ++++++++++++++++-
+ 1 file changed, 16 insertions(+), 1 deletion(-)
+
+--- a/tools/testing/selftests/net/mptcp/diag.sh
++++ b/tools/testing/selftests/net/mptcp/diag.sh
+@@ -56,7 +56,7 @@ __chk_nr()
+ local command="$1"
+ local expected=$2
+ local msg="$3"
+- local skip="${4:-SKIP}"
++ local skip="${4-SKIP}"
+ local nr
+
+ nr=$(eval $command)
+@@ -199,6 +199,15 @@ wait_local_port_listen()
+ done
+ }
+
++# $1: cestab nr
++chk_msk_cestab()
++{
++ local cestab=$1
++
++ __chk_nr "mptcp_lib_get_counter ${ns} MPTcpExtMPCurrEstab" \
++ "${cestab}" "....chk ${cestab} cestab" ""
++}
++
+ wait_connected()
+ {
+ local listener_ns="${1}"
+@@ -236,9 +245,11 @@ chk_msk_nr 2 "after MPC handshake "
+ chk_msk_remote_key_nr 2 "....chk remote_key"
+ chk_msk_fallback_nr 0 "....chk no fallback"
+ chk_msk_inuse 2 "....chk 2 msk in use"
++chk_msk_cestab 2
+ flush_pids
+
+ chk_msk_inuse 0 "....chk 0 msk in use after flush"
++chk_msk_cestab 0
+
+ echo "a" | \
+ timeout ${timeout_test} \
+@@ -254,9 +265,11 @@ echo "b" | \
+ wait_connected $ns 10001
+ chk_msk_fallback_nr 1 "check fallback"
+ chk_msk_inuse 1 "....chk 1 msk in use"
++chk_msk_cestab 1
+ flush_pids
+
+ chk_msk_inuse 0 "....chk 0 msk in use after flush"
++chk_msk_cestab 0
+
+ NR_CLIENTS=100
+ for I in `seq 1 $NR_CLIENTS`; do
+@@ -278,9 +291,11 @@ done
+
+ wait_msk_nr $((NR_CLIENTS*2)) "many msk socket present"
+ chk_msk_inuse $((NR_CLIENTS*2)) "....chk many msk in use"
++chk_msk_cestab $((NR_CLIENTS*2))
+ flush_pids
+
+ chk_msk_inuse 0 "....chk 0 msk in use after flush"
++chk_msk_cestab 0
+
+ mptcp_lib_result_print_all_tap
+ exit $ret
--- /dev/null
+From 694bd45980a61045eb5ec07799e3b94c76db830e Mon Sep 17 00:00:00 2001
+From: "Matthieu Baerts (NGI0)" <matttbe@kernel.org>
+Date: Thu, 15 Feb 2024 19:25:36 +0100
+Subject: selftests: mptcp: diag: fix bash warnings on older kernels
+
+From: Matthieu Baerts (NGI0) <matttbe@kernel.org>
+
+commit 694bd45980a61045eb5ec07799e3b94c76db830e upstream.
+
+Since the 'Fixes' commit mentioned below, the command that is executed
+in __chk_nr() helper can return nothing if the feature is not supported.
+This is the case when the MPTCP CURRESTAB counter is not supported.
+
+To avoid this warning ...
+
+ ./diag.sh: line 65: [: !=: unary operator expected
+
+... we just need to surround '$nr' with double quotes, to support an
+empty string when the feature is not supported.
+
+Fixes: 81ab772819da ("selftests: mptcp: diag: check CURRESTAB counters")
+Cc: stable@vger.kernel.org
+Reviewed-by: Geliang Tang <geliang@kernel.org>
+Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
+Signed-off-by: David S. Miller <davem@davemloft.net>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/testing/selftests/net/mptcp/diag.sh | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+--- a/tools/testing/selftests/net/mptcp/diag.sh
++++ b/tools/testing/selftests/net/mptcp/diag.sh
+@@ -62,8 +62,8 @@ __chk_nr()
+ nr=$(eval $command)
+
+ printf "%-50s" "$msg"
+- if [ $nr != $expected ]; then
+- if [ $nr = "$skip" ] && ! mptcp_lib_expect_all_features; then
++ if [ "$nr" != "$expected" ]; then
++ if [ "$nr" = "$skip" ] && ! mptcp_lib_expect_all_features; then
+ echo "[ skip ] Feature probably not supported"
+ mptcp_lib_result_skip "${msg}"
+ else
--- /dev/null
+From 4103d8480866fe5abb71ef0ed8af3a3b7b9625bf Mon Sep 17 00:00:00 2001
+From: "Matthieu Baerts (NGI0)" <matttbe@kernel.org>
+Date: Thu, 15 Feb 2024 19:25:40 +0100
+Subject: selftests: mptcp: diag: unique 'cestab' subtest names
+
+From: Matthieu Baerts (NGI0) <matttbe@kernel.org>
+
+commit 4103d8480866fe5abb71ef0ed8af3a3b7b9625bf upstream.
+
+It is important to have a unique (sub)test name in TAP, because some CI
+environments drop tests with duplicated name.
+
+Some 'cestab' subtests from the diag selftest had the same names, e.g.:
+
+ ....chk 0 cestab
+
+Now the previous value is taken, to have different names, e.g.:
+
+ ....chk 2->0 cestab after flush
+
+While at it, the 'after flush' info is added, similar to what is done
+with the 'in use' subtests. Also inspired by these 'in use' subtests,
+'many' is displayed instead of a large number:
+
+ many msk socket present [ ok ]
+ ....chk many msk in use [ ok ]
+ ....chk many cestab [ ok ]
+ ....chk many->0 msk in use after flush [ ok ]
+ ....chk many->0 cestab after flush [ ok ]
+
+Fixes: 81ab772819da ("selftests: mptcp: diag: check CURRESTAB counters")
+Cc: stable@vger.kernel.org
+Reviewed-by: Geliang Tang <geliang@kernel.org>
+Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
+Signed-off-by: David S. Miller <davem@davemloft.net>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/testing/selftests/net/mptcp/diag.sh | 17 +++++++++++------
+ 1 file changed, 11 insertions(+), 6 deletions(-)
+
+--- a/tools/testing/selftests/net/mptcp/diag.sh
++++ b/tools/testing/selftests/net/mptcp/diag.sh
+@@ -206,10 +206,15 @@ wait_local_port_listen()
+ # $1: cestab nr
+ chk_msk_cestab()
+ {
+- local cestab=$1
++ local expected=$1
++ local msg="....chk ${2:-${expected}} cestab"
++
++ if [ "${expected}" -eq 0 ]; then
++ msg+=" after flush"
++ fi
+
+ __chk_nr "mptcp_lib_get_counter ${ns} MPTcpExtMPCurrEstab" \
+- "${cestab}" "....chk ${cestab} cestab" ""
++ "${expected}" "${msg}" ""
+ }
+
+ wait_connected()
+@@ -253,7 +258,7 @@ chk_msk_cestab 2
+ flush_pids
+
+ chk_msk_inuse 0 "2->0"
+-chk_msk_cestab 0
++chk_msk_cestab 0 "2->0"
+
+ echo "a" | \
+ timeout ${timeout_test} \
+@@ -273,7 +278,7 @@ chk_msk_cestab 1
+ flush_pids
+
+ chk_msk_inuse 0 "1->0"
+-chk_msk_cestab 0
++chk_msk_cestab 0 "1->0"
+
+ NR_CLIENTS=100
+ for I in `seq 1 $NR_CLIENTS`; do
+@@ -295,11 +300,11 @@ done
+
+ wait_msk_nr $((NR_CLIENTS*2)) "many msk socket present"
+ chk_msk_inuse $((NR_CLIENTS*2)) "many"
+-chk_msk_cestab $((NR_CLIENTS*2))
++chk_msk_cestab $((NR_CLIENTS*2)) "many"
+ flush_pids
+
+ chk_msk_inuse 0 "many->0"
+-chk_msk_cestab 0
++chk_msk_cestab 0 "many->0"
+
+ mptcp_lib_result_print_all_tap
+ exit $ret
--- /dev/null
+From 645c1dc965ef6b5554e5e69737bb179c7a0f872f Mon Sep 17 00:00:00 2001
+From: "Matthieu Baerts (NGI0)" <matttbe@kernel.org>
+Date: Thu, 15 Feb 2024 19:25:39 +0100
+Subject: selftests: mptcp: diag: unique 'in use' subtest names
+
+From: Matthieu Baerts (NGI0) <matttbe@kernel.org>
+
+commit 645c1dc965ef6b5554e5e69737bb179c7a0f872f upstream.
+
+It is important to have a unique (sub)test name in TAP, because some CI
+environments drop tests with duplicated name.
+
+Some 'in use' subtests from the diag selftest had the same names, e.g.:
+
+ chk 0 msk in use after flush
+
+Now the previous value is taken, to have different names, e.g.:
+
+ chk 2->0 msk in use after flush
+
+While at it, avoid repeating the full message, declare it once in the
+helper.
+
+Fixes: ce9902573652 ("selftests: mptcp: diag: format subtests results in TAP")
+Cc: stable@vger.kernel.org
+Reviewed-by: Geliang Tang <geliang@kernel.org>
+Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
+Signed-off-by: David S. Miller <davem@davemloft.net>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/testing/selftests/net/mptcp/diag.sh | 20 ++++++++++++--------
+ 1 file changed, 12 insertions(+), 8 deletions(-)
+
+--- a/tools/testing/selftests/net/mptcp/diag.sh
++++ b/tools/testing/selftests/net/mptcp/diag.sh
+@@ -166,9 +166,13 @@ chk_msk_listen()
+ chk_msk_inuse()
+ {
+ local expected=$1
+- local msg="$2"
++ local msg="....chk ${2:-${expected}} msk in use"
+ local listen_nr
+
++ if [ "${expected}" -eq 0 ]; then
++ msg+=" after flush"
++ fi
++
+ listen_nr=$(ss -N "${ns}" -Ml | grep -c LISTEN)
+ expected=$((expected + listen_nr))
+
+@@ -179,7 +183,7 @@ chk_msk_inuse()
+ sleep 0.1
+ done
+
+- __chk_nr get_msk_inuse $expected "$msg" 0
++ __chk_nr get_msk_inuse $expected "${msg}" 0
+ }
+
+ # $1: ns, $2: port
+@@ -244,11 +248,11 @@ wait_connected $ns 10000
+ chk_msk_nr 2 "after MPC handshake "
+ chk_msk_remote_key_nr 2 "....chk remote_key"
+ chk_msk_fallback_nr 0 "....chk no fallback"
+-chk_msk_inuse 2 "....chk 2 msk in use"
++chk_msk_inuse 2
+ chk_msk_cestab 2
+ flush_pids
+
+-chk_msk_inuse 0 "....chk 0 msk in use after flush"
++chk_msk_inuse 0 "2->0"
+ chk_msk_cestab 0
+
+ echo "a" | \
+@@ -264,11 +268,11 @@ echo "b" | \
+ 127.0.0.1 >/dev/null &
+ wait_connected $ns 10001
+ chk_msk_fallback_nr 1 "check fallback"
+-chk_msk_inuse 1 "....chk 1 msk in use"
++chk_msk_inuse 1
+ chk_msk_cestab 1
+ flush_pids
+
+-chk_msk_inuse 0 "....chk 0 msk in use after flush"
++chk_msk_inuse 0 "1->0"
+ chk_msk_cestab 0
+
+ NR_CLIENTS=100
+@@ -290,11 +294,11 @@ for I in `seq 1 $NR_CLIENTS`; do
+ done
+
+ wait_msk_nr $((NR_CLIENTS*2)) "many msk socket present"
+-chk_msk_inuse $((NR_CLIENTS*2)) "....chk many msk in use"
++chk_msk_inuse $((NR_CLIENTS*2)) "many"
+ chk_msk_cestab $((NR_CLIENTS*2))
+ flush_pids
+
+-chk_msk_inuse 0 "....chk 0 msk in use after flush"
++chk_msk_inuse 0 "many->0"
+ chk_msk_cestab 0
+
+ mptcp_lib_result_print_all_tap
--- /dev/null
+From d2a2547565a9f1ad7989f7e21f97cbf065a9390d Mon Sep 17 00:00:00 2001
+From: "Matthieu Baerts (NGI0)" <matttbe@kernel.org>
+Date: Thu, 15 Feb 2024 19:25:34 +0100
+Subject: selftests: mptcp: pm nl: also list skipped tests
+
+From: Matthieu Baerts (NGI0) <matttbe@kernel.org>
+
+commit d2a2547565a9f1ad7989f7e21f97cbf065a9390d upstream.
+
+If the feature is not supported by older kernels, and instead of just
+ignoring some tests, we should mark them as skipped, so we can still
+track them.
+
+Fixes: d85555ac11f9 ("selftests: mptcp: pm_netlink: format subtests results in TAP")
+Cc: stable@vger.kernel.org
+Reviewed-by: Geliang Tang <geliang@kernel.org>
+Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
+Signed-off-by: David S. Miller <davem@davemloft.net>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/testing/selftests/net/mptcp/pm_netlink.sh | 6 ++++++
+ 1 file changed, 6 insertions(+)
+
+diff --git a/tools/testing/selftests/net/mptcp/pm_netlink.sh b/tools/testing/selftests/net/mptcp/pm_netlink.sh
+index 8f4ff123a7eb..79e83a2c95de 100755
+--- a/tools/testing/selftests/net/mptcp/pm_netlink.sh
++++ b/tools/testing/selftests/net/mptcp/pm_netlink.sh
+@@ -194,6 +194,12 @@ subflow 10.0.1.1" " (nofullmesh)"
+ ip netns exec $ns1 ./pm_nl_ctl set id 1 flags backup,fullmesh
+ check "ip netns exec $ns1 ./pm_nl_ctl dump" "id 1 flags \
+ subflow,backup,fullmesh 10.0.1.1" " (backup,fullmesh)"
++else
++ for st in fullmesh nofullmesh backup,fullmesh; do
++ st=" (${st})"
++ printf "%-50s%s\n" "${st}" "[SKIP]"
++ mptcp_lib_result_skip "${st}"
++ done
+ fi
+
+ mptcp_lib_result_print_all_tap
+--
+2.44.0
+
--- /dev/null
+From 662f084f3396d8a804d56cb53ac05c9e39902a7b Mon Sep 17 00:00:00 2001
+From: "Matthieu Baerts (NGI0)" <matttbe@kernel.org>
+Date: Thu, 15 Feb 2024 19:25:35 +0100
+Subject: selftests: mptcp: pm nl: avoid error msg on older kernels
+
+From: Matthieu Baerts (NGI0) <matttbe@kernel.org>
+
+commit 662f084f3396d8a804d56cb53ac05c9e39902a7b upstream.
+
+Since the 'Fixes' commit mentioned below, and if the kernel being tested
+doesn't support the 'fullmesh' flag, this error will be printed:
+
+ netlink error -22 (Invalid argument)
+ ./pm_nl_ctl: bailing out due to netlink error[s]
+
+But that can be normal if the kernel doesn't support the feature, no
+need to print this worrying error message while everything else looks
+OK. So we can mute stderr. Failures will still be detected if any.
+
+Fixes: 1dc88d241f92 ("selftests: mptcp: pm_nl_ctl: always look for errors")
+Cc: stable@vger.kernel.org
+Reviewed-by: Geliang Tang <geliang@kernel.org>
+Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
+Signed-off-by: David S. Miller <davem@davemloft.net>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/testing/selftests/net/mptcp/pm_netlink.sh | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/tools/testing/selftests/net/mptcp/pm_netlink.sh b/tools/testing/selftests/net/mptcp/pm_netlink.sh
+index 79e83a2c95de..71899a3ffa7a 100755
+--- a/tools/testing/selftests/net/mptcp/pm_netlink.sh
++++ b/tools/testing/selftests/net/mptcp/pm_netlink.sh
+@@ -183,7 +183,7 @@ check "ip netns exec $ns1 ./pm_nl_ctl dump" "id 1 flags \
+ subflow 10.0.1.1" " (nobackup)"
+
+ # fullmesh support has been added later
+-ip netns exec $ns1 ./pm_nl_ctl set id 1 flags fullmesh
++ip netns exec $ns1 ./pm_nl_ctl set id 1 flags fullmesh 2>/dev/null
+ if ip netns exec $ns1 ./pm_nl_ctl dump | grep -q "fullmesh" ||
+ mptcp_lib_expect_all_features; then
+ check "ip netns exec $ns1 ./pm_nl_ctl dump" "id 1 flags \
+--
+2.44.0
+
--- /dev/null
+From 4d8e0dde0403b5a86aa83e243f020711a9c3e31f Mon Sep 17 00:00:00 2001
+From: "Matthieu Baerts (NGI0)" <matttbe@kernel.org>
+Date: Thu, 15 Feb 2024 19:25:37 +0100
+Subject: selftests: mptcp: simult flows: fix some subtest names
+
+From: Matthieu Baerts (NGI0) <matttbe@kernel.org>
+
+commit 4d8e0dde0403b5a86aa83e243f020711a9c3e31f upstream.
+
+The selftest was correctly recording all the results, but the 'reverse
+direction' part was missing in the name when needed.
+
+It is important to have a unique (sub)test name in TAP, because some CI
+environments drop tests with duplicated name.
+
+Fixes: 675d99338e7a ("selftests: mptcp: simult flows: format subtests results in TAP")
+Cc: stable@vger.kernel.org
+Reviewed-by: Geliang Tang <geliang@kernel.org>
+Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
+Signed-off-by: David S. Miller <davem@davemloft.net>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/testing/selftests/net/mptcp/simult_flows.sh | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+--- a/tools/testing/selftests/net/mptcp/simult_flows.sh
++++ b/tools/testing/selftests/net/mptcp/simult_flows.sh
+@@ -267,7 +267,8 @@ run_test()
+ [ $bail -eq 0 ] || exit $ret
+ fi
+
+- printf "%-60s" "$msg - reverse direction"
++ msg+=" - reverse direction"
++ printf "%-60s" "${msg}"
+ do_transfer $large $small $time
+ lret=$?
+ mptcp_lib_result_code "${lret}" "${msg}"
--- /dev/null
+From 2ef0d804c090658960c008446523863fd7e3541e Mon Sep 17 00:00:00 2001
+From: "Matthieu Baerts (NGI0)" <matttbe@kernel.org>
+Date: Thu, 15 Feb 2024 19:25:38 +0100
+Subject: selftests: mptcp: userspace_pm: unique subtest names
+
+From: Matthieu Baerts (NGI0) <matttbe@kernel.org>
+
+commit 2ef0d804c090658960c008446523863fd7e3541e upstream.
+
+It is important to have a unique (sub)test name in TAP, because some CI
+environments drop tests with duplicated names.
+
+Some subtests from the userspace_pm selftest had the same names. That's
+because different subflows are created (and deleted) between the same
+pair of IP addresses.
+
+Simply adding the destination port in the name is then enough to have
+different names, because the destination port is always different.
+
+Note that adding such info takes a bit more space, so we need to
+increase a bit the width to print the name, simply to keep all the
+'[ OK ]' aligned as before.
+
+Fixes: f589234e1af0 ("selftests: mptcp: userspace_pm: format subtests results in TAP")
+Cc: stable@vger.kernel.org
+Reviewed-by: Geliang Tang <geliang@kernel.org>
+Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
+Signed-off-by: David S. Miller <davem@davemloft.net>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/testing/selftests/net/mptcp/userspace_pm.sh | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+--- a/tools/testing/selftests/net/mptcp/userspace_pm.sh
++++ b/tools/testing/selftests/net/mptcp/userspace_pm.sh
+@@ -75,7 +75,7 @@ print_test()
+ {
+ test_name="${1}"
+
+- _printf "%-63s" "${test_name}"
++ _printf "%-68s" "${test_name}"
+ }
+
+ print_results()
+@@ -555,7 +555,7 @@ verify_subflow_events()
+ local remid
+ local info
+
+- info="${e_saddr} (${e_from}) => ${e_daddr} (${e_to})"
++ info="${e_saddr} (${e_from}) => ${e_daddr}:${e_dport} (${e_to})"
+
+ if [ "$e_type" = "$SUB_ESTABLISHED" ]
+ then
mptcp-fix-data-races-on-local_id.patch
mptcp-fix-data-races-on-remote_id.patch
mptcp-fix-duplicate-subflow-creation.patch
+selftests-mptcp-userspace_pm-unique-subtest-names.patch
+selftests-mptcp-simult-flows-fix-some-subtest-names.patch
+selftests-mptcp-pm-nl-also-list-skipped-tests.patch
+selftests-mptcp-pm-nl-avoid-error-msg-on-older-kernels.patch
+selftests-mptcp-diag-check-currestab-counters.patch
+selftests-mptcp-diag-fix-bash-warnings-on-older-kernels.patch
+selftests-mptcp-diag-unique-in-use-subtest-names.patch
+selftests-mptcp-diag-unique-cestab-subtest-names.patch