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.
23 echo "SKIP: Could not create net namespace $gw"
29 conntrack -V > /dev/null 2>&1
34 ip -net "$ns" link set lo up
39 ip netns exec $ns sysctl -q net.netfilter.nf_conntrack_udp_timeout=3600
40 ip netns exec $ns nft -f /dev/stdin<<EOF
44 typeof numgen inc mod $max_zones : ct zone
48 type filter hook output priority -64000; policy accept;
49 udp dport 12345 ct zone set numgen inc mod 65536 map @rndzone
54 echo "add element inet raw rndzone {"
55 for i in $(seq 1 $max_zones);do
57 if [ $i -lt $max_zones ]; then
63 ) | ip netns exec $ns nft -f /dev/stdin
67 local outerstart=$(date +%s%3N)
68 local stop=$outerstart
70 while [ $i -lt $max_zones ]; do
71 local start=$(date +%s%3N)
74 dd if=/dev/zero of=/dev/stdout bs=8k count=10000 2>/dev/null | ip netns exec "$ns" nc -w 1 -q 1 -u -p 12345 127.0.0.1 12345 > /dev/null
81 local duration=$((stop-start))
82 echo "PASS: added 10000 entries in $duration ms (now $i total, loop $j)"
85 if [ $have_ct_tool -eq 1 ]; then
86 local count=$(ip netns exec "$ns" conntrack -C)
87 local duration=$((stop-outerstart))
89 if [ $count -eq $max_zones ]; then
90 echo "PASS: inserted $count entries from packet path in $duration ms total"
92 ip netns exec $ns conntrack -S 1>&2
93 echo "FAIL: inserted $count entries from packet path in $duration ms total, expected $max_zones entries"
98 if [ $ret -ne 0 ];then
99 echo "FAIL: insert $max_zones entries from packet path" 1>&2
103 test_conntrack_tool() {
106 ip netns exec $ns conntrack -F >/dev/null 2>/dev/null
108 local outerstart=$(date +%s%3N)
109 local start=$(date +%s%3N)
112 while [ $i -lt $max_zones ]; do
114 ip netns exec "$ns" conntrack -I -s 1.1.1.1 -d 2.2.2.2 --protonum 6 \
115 --timeout 3600 --state ESTABLISHED --sport 12345 --dport 1000 --zone $i >/dev/null 2>&1
117 ip netns exec "$ns" conntrack -I -s 1.1.1.1 -d 2.2.2.2 --protonum 6 \
118 --timeout 3600 --state ESTABLISHED --sport 12345 --dport 1000 --zone $i > /dev/null
119 echo "FAIL: conntrack -I returned an error"
124 if [ $((i%10000)) -eq 0 ];then
127 local duration=$((stop-start))
128 echo "PASS: added 10000 entries in $duration ms (now $i total)"
133 local count=$(ip netns exec "$ns" conntrack -C)
134 local duration=$((stop-outerstart))
136 if [ $count -eq $max_zones ]; then
137 echo "PASS: inserted $count entries via ctnetlink in $duration ms"
139 ip netns exec $ns conntrack -S 1>&2
140 echo "FAIL: inserted $count entries via ctnetlink in $duration ms, expected $max_zones entries ($duration ms)"
147 if [ $have_ct_tool -eq 1 ];then
148 test_conntrack_tool $zones
150 echo "SKIP: Could not run ctnetlink insertion test without conntrack tool"
151 if [ $ret -eq 0 ];then