kernel: 5.4: import wireguard backport
[openwrt/openwrt.git] / target / linux / generic / backport-5.4 / 080-wireguard-0119-wireguard-selftests-test-multiple-parallel-streams.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: "Jason A. Donenfeld" <Jason@zx2c4.com>
3 Date: Mon, 22 Feb 2021 17:25:45 +0100
4 Subject: [PATCH] wireguard: selftests: test multiple parallel streams
5
6 commit d5a49aa6c3e264a93a7d08485d66e346be0969dd upstream.
7
8 In order to test ndo_start_xmit being called in parallel, explicitly add
9 separate tests, which should all run on different cores. This should
10 help tease out bugs associated with queueing up packets from different
11 cores in parallel. Currently, it hasn't found those types of bugs, but
12 given future planned work, this is a useful regression to avoid.
13
14 Fixes: e7096c131e51 ("net: WireGuard secure network tunnel")
15 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
16 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
17 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
18 ---
19 tools/testing/selftests/wireguard/netns.sh | 15 ++++++++++++++-
20 1 file changed, 14 insertions(+), 1 deletion(-)
21
22 --- a/tools/testing/selftests/wireguard/netns.sh
23 +++ b/tools/testing/selftests/wireguard/netns.sh
24 @@ -39,7 +39,7 @@ ip0() { pretty 0 "ip $*"; ip -n $netns0
25 ip1() { pretty 1 "ip $*"; ip -n $netns1 "$@"; }
26 ip2() { pretty 2 "ip $*"; ip -n $netns2 "$@"; }
27 sleep() { read -t "$1" -N 1 || true; }
28 -waitiperf() { pretty "${1//*-}" "wait for iperf:5201 pid $2"; while [[ $(ss -N "$1" -tlpH 'sport = 5201') != *\"iperf3\",pid=$2,fd=* ]]; do sleep 0.1; done; }
29 +waitiperf() { pretty "${1//*-}" "wait for iperf:${3:-5201} pid $2"; while [[ $(ss -N "$1" -tlpH "sport = ${3:-5201}") != *\"iperf3\",pid=$2,fd=* ]]; do sleep 0.1; done; }
30 waitncatudp() { pretty "${1//*-}" "wait for udp:1111 pid $2"; while [[ $(ss -N "$1" -ulpH 'sport = 1111') != *\"ncat\",pid=$2,fd=* ]]; do sleep 0.1; done; }
31 waitiface() { pretty "${1//*-}" "wait for $2 to come up"; ip netns exec "$1" bash -c "while [[ \$(< \"/sys/class/net/$2/operstate\") != up ]]; do read -t .1 -N 0 || true; done;"; }
32
33 @@ -141,6 +141,19 @@ tests() {
34 n2 iperf3 -s -1 -B fd00::2 &
35 waitiperf $netns2 $!
36 n1 iperf3 -Z -t 3 -b 0 -u -c fd00::2
37 +
38 + # TCP over IPv4, in parallel
39 + for max in 4 5 50; do
40 + local pids=( )
41 + for ((i=0; i < max; ++i)) do
42 + n2 iperf3 -p $(( 5200 + i )) -s -1 -B 192.168.241.2 &
43 + pids+=( $! ); waitiperf $netns2 $! $(( 5200 + i ))
44 + done
45 + for ((i=0; i < max; ++i)) do
46 + n1 iperf3 -Z -t 3 -p $(( 5200 + i )) -c 192.168.241.2 &
47 + done
48 + wait "${pids[@]}"
49 + done
50 }
51
52 [[ $(ip1 link show dev wg0) =~ mtu\ ([0-9]+) ]] && orig_mtu="${BASH_REMATCH[1]}"