Skip to content

Commit c234dab

Browse files
committed
selftests: netfilter: conntrack_resize.sh: extend resize test
JIRA: https://issues.redhat.com/browse/RHEL-106441 Upstream Status: commit b085905 commit b085905 Author: Florian Westphal <fw@strlen.de> Date: Fri Jun 27 16:27:50 2025 +0200 selftests: netfilter: conntrack_resize.sh: extend resize test Extend the resize test: - continuously dump table both via /proc and ctnetlink interfaces while table is resized in a loop. - if socat is available, send udp packets in additon to ping requests. - increase/decrease the icmp and udp timeouts while resizes are happening. This makes sure we also exercise the 'ct has expired' check that happens on conntrack lookup. Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: Florian Westphal <fwestpha@redhat.com>
1 parent 09e34b3 commit c234dab

File tree

1 file changed

+75
-5
lines changed

1 file changed

+75
-5
lines changed

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

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ tmpfile=""
1212
tmpfile_proc=""
1313
tmpfile_uniq=""
1414
ret=0
15+
have_socat=0
16+
17+
socat -h > /dev/null && have_socat=1
1518

1619
insert_count=2000
1720
[ "$KSFT_MACHINE_SLOW" = "yes" ] && insert_count=400
@@ -123,7 +126,7 @@ ctflush() {
123126
done
124127
}
125128

126-
ctflood()
129+
ct_pingflood()
127130
{
128131
local ns="$1"
129132
local duration="$2"
@@ -152,6 +155,28 @@ ctflood()
152155
wait
153156
}
154157

158+
ct_udpflood()
159+
{
160+
local ns="$1"
161+
local duration="$2"
162+
local now=$(date +%s)
163+
local end=$((now + duration))
164+
165+
[ $have_socat -ne "1" ] && return
166+
167+
while [ $now -lt $end ]; do
168+
ip netns exec "$ns" bash<<"EOF"
169+
for i in $(seq 1 100);do
170+
dport=$(((RANDOM%65536)+1))
171+
172+
echo bar | socat -u STDIN UDP:"127.0.0.1:$dport" &
173+
done > /dev/null 2>&1
174+
wait
175+
EOF
176+
now=$(date +%s)
177+
done
178+
}
179+
155180
# dump to /dev/null. We don't want dumps to cause infinite loops
156181
# or use-after-free even when conntrack table is altered while dumps
157182
# are in progress.
@@ -169,6 +194,48 @@ ct_nulldump()
169194
wait
170195
}
171196

197+
ct_nulldump_loop()
198+
{
199+
local ns="$1"
200+
local duration="$2"
201+
local now=$(date +%s)
202+
local end=$((now + duration))
203+
204+
while [ $now -lt $end ]; do
205+
ct_nulldump "$ns"
206+
sleep $((RANDOM%2))
207+
now=$(date +%s)
208+
done
209+
}
210+
211+
change_timeouts()
212+
{
213+
local ns="$1"
214+
local r1=$((RANDOM%2))
215+
local r2=$((RANDOM%2))
216+
217+
[ "$r1" -eq 1 ] && ip netns exec "$ns" sysctl -q net.netfilter.nf_conntrack_icmp_timeout=$((RANDOM%5))
218+
[ "$r2" -eq 1 ] && ip netns exec "$ns" sysctl -q net.netfilter.nf_conntrack_udp_timeout=$((RANDOM%5))
219+
}
220+
221+
ct_change_timeouts_loop()
222+
{
223+
local ns="$1"
224+
local duration="$2"
225+
local now=$(date +%s)
226+
local end=$((now + duration))
227+
228+
while [ $now -lt $end ]; do
229+
change_timeouts "$ns"
230+
sleep $((RANDOM%2))
231+
now=$(date +%s)
232+
done
233+
234+
# restore defaults
235+
ip netns exec "$ns" sysctl -q net.netfilter.nf_conntrack_icmp_timeout=30
236+
ip netns exec "$ns" sysctl -q net.netfilter.nf_conntrack_udp_timeout=30
237+
}
238+
172239
check_taint()
173240
{
174241
local tainted_then="$1"
@@ -198,10 +265,13 @@ insert_flood()
198265

199266
r=$((RANDOM%$insert_count))
200267

201-
ctflood "$n" "$timeout" "floodresize" &
268+
ct_pingflood "$n" "$timeout" "floodresize" &
269+
ct_udpflood "$n" "$timeout" &
270+
202271
insert_ctnetlink "$n" "$r" &
203272
ctflush "$n" "$timeout" &
204-
ct_nulldump "$n" &
273+
ct_nulldump_loop "$n" "$timeout" &
274+
ct_change_timeouts_loop "$n" "$timeout" &
205275

206276
wait
207277
}
@@ -306,7 +376,7 @@ test_dump_all()
306376

307377
ip netns exec "$nsclient1" sysctl -q net.netfilter.nf_conntrack_icmp_timeout=3600
308378

309-
ctflood "$nsclient1" $timeout "dumpall" &
379+
ct_pingflood "$nsclient1" $timeout "dumpall" &
310380
insert_ctnetlink "$nsclient2" $insert_count
311381

312382
wait
@@ -368,7 +438,7 @@ test_conntrack_disable()
368438
ct_flush_once "$nsclient1"
369439
ct_flush_once "$nsclient2"
370440

371-
ctflood "$nsclient1" "$timeout" "conntrack disable"
441+
ct_pingflood "$nsclient1" "$timeout" "conntrack disable"
372442
ip netns exec "$nsclient2" ping -q -c 1 127.0.0.1 >/dev/null 2>&1
373443

374444
# Disabled, should not have picked up any connection.

0 commit comments

Comments
 (0)