Skip to content

Commit dca56cc

Browse files
Florian Westphalkuba-moo
authored andcommitted
selftests: netfilter: tone-down conntrack clash test
The test is supposed to observe that the 'clash_resolve' stat counter incremented (i.e., the code path was covered). This check was incorrect, 'conntrack -S' needs to be called in the revevant namespace, not the initial netns. The clash resolution logic in conntrack is only exercised when multiple packets with the same udp quadruple race. Depending on kernel config, number of CPUs, scheduling policy etc. this might not trigger even after several retries. Thus the script eventually returns SKIP if the retry count is exceeded. The udpclash tool with also exit with a failure if it did not observe the expected number of replies. In the script, make a note of this but do not fail anymore, just check if the clash resolution logic triggered after all. Remove the 'single-core' test: while unlikely, with preemptible kernel it should be possible to also trigger clash resolution logic. With this change the test will either SKIP or pass. Hard error could be restored later once its clear whats going on, so also dump 'conntrack -S' when some packets went missing to see if conntrack dropped them on insert. Fixes: 78a5883 ("selftests: netfilter: add conntrack clash resolution test case") Signed-off-by: Florian Westphal <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 71c33df commit dca56cc

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

tools/testing/selftests/net/netfilter/conntrack_clash.sh

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -93,53 +93,52 @@ ping_test()
9393
run_one_clash_test()
9494
{
9595
local ns="$1"
96-
local daddr="$2"
97-
local dport="$3"
96+
local ctns="$2"
97+
local daddr="$3"
98+
local dport="$4"
9899
local entries
99100
local cre
100101

101102
if ! ip netns exec "$ns" ./udpclash $daddr $dport;then
102-
echo "FAIL: did not receive expected number of replies for $daddr:$dport"
103-
ret=1
104-
return 1
103+
echo "INFO: did not receive expected number of replies for $daddr:$dport"
104+
ip netns exec "$ctns" conntrack -S
105+
# don't fail: check if clash resolution triggered after all.
105106
fi
106107

107-
entries=$(conntrack -S | wc -l)
108-
cre=$(conntrack -S | grep -v "clash_resolve=0" | wc -l)
108+
entries=$(ip netns exec "$ctns" conntrack -S | wc -l)
109+
cre=$(ip netns exec "$ctns" conntrack -S | grep "clash_resolve=0" | wc -l)
109110

110-
if [ "$cre" -ne "$entries" ] ;then
111+
if [ "$cre" -ne "$entries" ];then
111112
clash_resolution_active=1
112113
return 0
113114
fi
114115

115-
# 1 cpu -> parallel insertion impossible
116-
if [ "$entries" -eq 1 ]; then
117-
return 0
118-
fi
119-
120-
# not a failure: clash resolution logic did not trigger, but all replies
121-
# were received. With right timing, xmit completed sequentially and
116+
# not a failure: clash resolution logic did not trigger.
117+
# With right timing, xmit completed sequentially and
122118
# no parallel insertion occurs.
123119
return $ksft_skip
124120
}
125121

126122
run_clash_test()
127123
{
128124
local ns="$1"
129-
local daddr="$2"
130-
local dport="$3"
125+
local ctns="$2"
126+
local daddr="$3"
127+
local dport="$4"
128+
local softerr=0
131129

132130
for i in $(seq 1 10);do
133-
run_one_clash_test "$ns" "$daddr" "$dport"
131+
run_one_clash_test "$ns" "$ctns" "$daddr" "$dport"
134132
local rv=$?
135133
if [ $rv -eq 0 ];then
136134
echo "PASS: clash resolution test for $daddr:$dport on attempt $i"
137135
return 0
138-
elif [ $rv -eq 1 ];then
139-
echo "FAIL: clash resolution test for $daddr:$dport on attempt $i"
140-
return 1
136+
elif [ $rv -eq $ksft_skip ]; then
137+
softerr=1
141138
fi
142139
done
140+
141+
[ $softerr -eq 1 ] && echo "SKIP: clash resolution for $daddr:$dport did not trigger"
143142
}
144143

145144
ip link add veth0 netns "$nsclient1" type veth peer name veth0 netns "$nsrouter"
@@ -161,11 +160,11 @@ spawn_servers "$nsclient2"
161160

162161
# exercise clash resolution with nat:
163162
# nsrouter is supposed to dnat to 10.0.2.1:900{0,1,2,3}.
164-
run_clash_test "$nsclient1" 10.0.1.99 "$dport"
163+
run_clash_test "$nsclient1" "$nsrouter" 10.0.1.99 "$dport"
165164

166165
# exercise clash resolution without nat.
167166
load_simple_ruleset "$nsclient2"
168-
run_clash_test "$nsclient2" 127.0.0.1 9001
167+
run_clash_test "$nsclient2" "$nsclient2" 127.0.0.1 9001
169168

170169
if [ $clash_resolution_active -eq 0 ];then
171170
[ "$ret" -eq 0 ] && ret=$ksft_skip

0 commit comments

Comments
 (0)