3 # Test insertion speed for packets with identical addresses/ports
4 # that are all placed in distinct conntrack zones.
6 sfx=$(mktemp -u "XXXXXXXX")
9 # Kselftest framework requirement - SKIP code is 4.
22 if ! $1 > /dev/null 2>&1; then
23 echo "SKIP: Could not $2"
28 checktool "nft --version" "run test without nft tool"
29 checktool "ip -Version" "run test without ip tool"
30 checktool "socat -V" "run test without socat tool"
31 checktool "ip netns add $ns" "create net namespace"
35 conntrack -V > /dev/null 2>&1
40 ip -net "$ns" link set lo up
45 ip netns exec $ns sysctl -q net.netfilter.nf_conntrack_udp_timeout=3600
46 ip netns exec $ns nft -f /dev/stdin<<EOF
50 typeof numgen inc mod $max_zones : ct zone
54 type filter hook output priority -64000; policy accept;
55 udp dport 12345 ct zone set numgen inc mod 65536 map @rndzone
60 echo "add element inet raw rndzone {"
61 for i in $(seq 1 $max_zones);do
63 if [ $i -lt $max_zones ]; then
69 ) | ip netns exec $ns nft -f /dev/stdin
73 local outerstart=$(date +%s%3N)
74 local stop=$outerstart
76 while [ $i -lt $max_zones ]; do
77 local start=$(date +%s%3N)
80 # nft rule in output places each packet in a different zone.
81 dd if=/dev/zero of=/dev/stdout bs=8k count=10000 2>/dev/null | ip netns exec "$ns" socat STDIN UDP:127.0.0.1:12345,sourceport=12345
88 local duration=$((stop-start))
89 echo "PASS: added 10000 entries in $duration ms (now $i total, loop $j)"
92 if [ $have_ct_tool -eq 1 ]; then
93 local count=$(ip netns exec "$ns" conntrack -C)
94 local duration=$((stop-outerstart))
96 if [ $count -eq $max_zones ]; then
97 echo "PASS: inserted $count entries from packet path in $duration ms total"
99 ip netns exec $ns conntrack -S 1>&2
100 echo "FAIL: inserted $count entries from packet path in $duration ms total, expected $max_zones entries"
105 if [ $ret -ne 0 ];then
106 echo "FAIL: insert $max_zones entries from packet path" 1>&2
110 test_conntrack_tool() {
113 ip netns exec $ns conntrack -F >/dev/null 2>/dev/null
115 local outerstart=$(date +%s%3N)
116 local start=$(date +%s%3N)
119 while [ $i -lt $max_zones ]; do
121 ip netns exec "$ns" conntrack -I -s 1.1.1.1 -d 2.2.2.2 --protonum 6 \
122 --timeout 3600 --state ESTABLISHED --sport 12345 --dport 1000 --zone $i >/dev/null 2>&1
124 ip netns exec "$ns" conntrack -I -s 1.1.1.1 -d 2.2.2.2 --protonum 6 \
125 --timeout 3600 --state ESTABLISHED --sport 12345 --dport 1000 --zone $i > /dev/null
126 echo "FAIL: conntrack -I returned an error"
131 if [ $((i%10000)) -eq 0 ];then
134 local duration=$((stop-start))
135 echo "PASS: added 10000 entries in $duration ms (now $i total)"
140 local count=$(ip netns exec "$ns" conntrack -C)
141 local duration=$((stop-outerstart))
143 if [ $count -eq $max_zones ]; then
144 echo "PASS: inserted $count entries via ctnetlink in $duration ms"
146 ip netns exec $ns conntrack -S 1>&2
147 echo "FAIL: inserted $count entries via ctnetlink in $duration ms, expected $max_zones entries ($duration ms)"
154 if [ $have_ct_tool -eq 1 ];then
155 test_conntrack_tool $zones
157 echo "SKIP: Could not run ctnetlink insertion test without conntrack tool"
158 if [ $ret -eq 0 ];then