]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
tests: shell: rate_limit: also check byte-based limit master
authorFlorian Westphal <fw@strlen.de>
Mon, 4 May 2026 07:33:33 +0000 (09:33 +0200)
committerFlorian Westphal <fw@strlen.de>
Sat, 30 May 2026 06:13:36 +0000 (08:13 +0200)
Existing test case covered packets, also check the byte-based
rate-limiter.

Signed-off-by: Florian Westphal <fw@strlen.de>
tests/shell/testcases/packetpath/rate_limit

index e0a8abc96ae3d00cd87bdf415edc09a2071dc95c..e39ce5a42d364b57e2b51b12928b6f36c557f25c 100755 (executable)
@@ -134,3 +134,19 @@ assert_fail result "tcp connection limit rate 1/sec burst 1 reject"
 sleep 1
 ip netns exec $C socat -u - TCP:${ip_sc}:80,reuseport,connect-timeout=1 <<< 'AAA'
 assert_pass result "tcp connection limit rate 1/sec burst 1 accept"
+
+ip netns exec $S $NFT flush chain filter in_tcp
+assert_pass "flush chain"
+
+ip netns exec $S $NFT add rule filter in_tcp iifname s_c tcp dport 80 limit rate over 1 mbytes/second drop
+assert_pass "limit rate"
+
+s=(date +%s)
+dd if=/dev/zero bs=1M count=4 | ip netns exec $C socat -u - TCP:${ip_sc}:80,reuseport,connect-timeout=1
+e=(date +%s)
+d=$((e-s))
+if [ $d -ge 4 ] && [ $d -le 5 ];then
+       echo "FAIL: limit not effective (xfer took $d s)"; exit 1
+else
+       echo "PASS: socat xfer took $d seconds"
+fi