Debian Codegraph @

tests/shell/testcases/maps/vmap_timeout

raw
1 #!/bin/bash
2
3 # NFT_TEST_SKIP(NFT_TEST_SKIP_slow)
4
5 set -e
6
7 dumpfile=$(dirname $0)/dumps/$(basename $0).nft
8 $NFT -f $dumpfile
9
10 port=23
11 for i in $(seq 1 100) ; do
12 timeout=$((RANDOM % 5 + 1))
13 expire=$((RANDOM%timeout))
14 j=1
15
16 batched="{ $port timeout 3s : jump other_input "
17 ubatched="$batched"
18
19 timeout_str="timeout ${timeout}s"
20 expire_str=""
21 if [ "$expire" -gt 0 ]; then
22 expire_str="expires ${expire}s"
23 fi
24
25 batched_addr="{ 10.0.$((i%256)).$j . $port ${timeout_str} ${expire_str} : jump other_input "
26 ubatched_addr="$batched_addr"
27
28 port=$((port + 1))
29 for j in $(seq 2 400); do
30 timeout=$((RANDOM % 5 + 1))
31 expire=$((RANDOM%timeout))
32 utimeout=$((RANDOM % 5 + 1))
33
34 timeout_str="timeout ${timeout}s"
35 expire_str=""
36 if [ "$expire" -gt 0 ]; then
37 expire_str="expires ${expire}s"
38 fi
39
40 batched="$batched, $port ${timeout_str} ${expire_str} : jump other_input "
41 batched_addr="$batched_addr, 10.0.$((i%256)).$((j%256)) . $port ${timeout_str} ${expire_str} : jump other_input "
42 port=$((port + 1))
43
44 timeout_str="timeout ${utimeout}s"
45 expire=$((RANDOM%utimeout))
46
47 expire_str=""
48 if [ "$expire" -gt 0 ]; then
49 expire_str="expires ${expire}s"
50 fi
51
52 update=$((RANDOM%2))
53 if [ "$update" -ne 0 ]; then
54 ubatched="$batched, $port ${timeout_str} ${expire_str} : jump other_input "
55 ubatched_addr="$batched_addr, 10.0.$((i%256)).$((j%256)) . $port ${timeout_str} ${expire_str} : jump other_input "
56 fi
57 done
58
59 fail_addr="$batched_addr, 1.2.3.4 . 23 timeout 5m : jump other_input,
60 1.2.3.4 . 23 timeout 3m : jump other_input }"
61 fail="$batched, 23 timeout 1m : jump other_input, 23 : jump other_input }"
62
63 batched="$batched }"
64 batched_addr="$batched_addr }"
65
66 if [ $i -gt 90 ]; then
67 # must fail, we create and $fail/$fail_addr contain one element twice.
68 $NFT create element inet filter portmap "$fail" && exit 111
69 $NFT create element inet filter portaddrmap "$fail_addr" && exit 112
70 fi
71
72 $NFT add element inet filter portmap "$batched"
73 $NFT add element inet filter portaddrmap "$batched_addr"
74
75 update=$((RANDOM%2))
76 if [ "$update" -ne 0 ]; then
77 ubatched="$ubatched }"
78 ubatched_addr="$ubatched_addr }"
79 $NFT add element inet filter portmap "$ubatched"
80 $NFT add element inet filter portaddrmap "$ubatched_addr"
81 fi
82 done
83
84 if [ "$NFT_TEST_HAVE_catchall_element" = n ] ; then
85 echo "Partial test due to NFT_TEST_HAVE_catchall_element=n."
86 else
87 $NFT add element inet filter portaddrmap { "* timeout 2s : drop" }
88 $NFT add element inet filter portmap { "* timeout 3s : drop" }
89 fi
90
91 # wait for elements to time out
92 sleep 5