Skip to content

Commit 88f404a

Browse files
zx2c4davem330
authored andcommitted
wireguard: selftests: tie socket waiting to target pid
Without this, we wind up proceeding too early sometimes when the previous process has just used the same listening port. So, we tie the listening socket query to the specific pid we're interested in. Signed-off-by: Jason A. Donenfeld <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4a2ef72 commit 88f404a

File tree

1 file changed

+8
-9
lines changed
  • tools/testing/selftests/wireguard

1 file changed

+8
-9
lines changed

tools/testing/selftests/wireguard/netns.sh

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ ip0() { pretty 0 "ip $*"; ip -n $netns0 "$@"; }
3838
ip1() { pretty 1 "ip $*"; ip -n $netns1 "$@"; }
3939
ip2() { pretty 2 "ip $*"; ip -n $netns2 "$@"; }
4040
sleep() { read -t "$1" -N 1 || true; }
41-
waitiperf() { pretty "${1//*-}" "wait for iperf:5201"; while [[ $(ss -N "$1" -tlp 'sport = 5201') != *iperf3* ]]; do sleep 0.1; done; }
42-
waitncatudp() { pretty "${1//*-}" "wait for udp:1111"; while [[ $(ss -N "$1" -ulp 'sport = 1111') != *ncat* ]]; do sleep 0.1; done; }
43-
waitncattcp() { pretty "${1//*-}" "wait for tcp:1111"; while [[ $(ss -N "$1" -tlp 'sport = 1111') != *ncat* ]]; do sleep 0.1; done; }
41+
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; }
42+
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; }
4443
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;"; }
4544

4645
cleanup() {
@@ -119,22 +118,22 @@ tests() {
119118

120119
# TCP over IPv4
121120
n2 iperf3 -s -1 -B 192.168.241.2 &
122-
waitiperf $netns2
121+
waitiperf $netns2 $!
123122
n1 iperf3 -Z -t 3 -c 192.168.241.2
124123

125124
# TCP over IPv6
126125
n1 iperf3 -s -1 -B fd00::1 &
127-
waitiperf $netns1
126+
waitiperf $netns1 $!
128127
n2 iperf3 -Z -t 3 -c fd00::1
129128

130129
# UDP over IPv4
131130
n1 iperf3 -s -1 -B 192.168.241.1 &
132-
waitiperf $netns1
131+
waitiperf $netns1 $!
133132
n2 iperf3 -Z -t 3 -b 0 -u -c 192.168.241.1
134133

135134
# UDP over IPv6
136135
n2 iperf3 -s -1 -B fd00::2 &
137-
waitiperf $netns2
136+
waitiperf $netns2 $!
138137
n1 iperf3 -Z -t 3 -b 0 -u -c fd00::2
139138
}
140139

@@ -207,7 +206,7 @@ n1 ping -W 1 -c 1 192.168.241.2
207206
n1 wg set wg0 peer "$pub2" allowed-ips 192.168.241.0/24
208207
exec 4< <(n1 ncat -l -u -p 1111)
209208
ncat_pid=$!
210-
waitncatudp $netns1
209+
waitncatudp $netns1 $ncat_pid
211210
n2 ncat -u 192.168.241.1 1111 <<<"X"
212211
read -r -N 1 -t 1 out <&4 && [[ $out == "X" ]]
213212
kill $ncat_pid
@@ -216,7 +215,7 @@ n1 wg set wg0 peer "$more_specific_key" allowed-ips 192.168.241.2/32
216215
n2 wg set wg0 listen-port 9997
217216
exec 4< <(n1 ncat -l -u -p 1111)
218217
ncat_pid=$!
219-
waitncatudp $netns1
218+
waitncatudp $netns1 $ncat_pid
220219
n2 ncat -u 192.168.241.1 1111 <<<"X"
221220
! read -r -N 1 -t 1 out <&4 || false
222221
kill $ncat_pid

0 commit comments

Comments
 (0)