@@ -12,10 +12,11 @@ nft --version >/dev/null 2>&1 || {
12
12
}
13
13
14
14
logfile=$( mktemp)
15
+ rulefile=$( mktemp)
15
16
echo " logging into $logfile "
16
17
./audit_logread > " $logfile " &
17
18
logread_pid=$!
18
- trap ' kill $logread_pid; rm -f $logfile' EXIT
19
+ trap ' kill $logread_pid; rm -f $logfile $rulefile ' EXIT
19
20
exec 3< " $logfile "
20
21
21
22
do_test () { # (cmd, log)
@@ -26,12 +27,14 @@ do_test() { # (cmd, log)
26
27
res=$( diff -a -u <( echo " $2 " ) - < & 3)
27
28
[ $? -eq 0 ] && { echo " OK" ; return ; }
28
29
echo " FAIL"
29
- echo " $res "
30
- (( RC++ ))
30
+ grep -v ' ^\(---\|+++\|@@\) ' <<< " $res"
31
+ (( RC-- ))
31
32
}
32
33
33
34
nft flush ruleset
34
35
36
+ # adding tables, chains and rules
37
+
35
38
for table in t1 t2; do
36
39
do_test " nft add table $table " \
37
40
" table=$table family=2 entries=1 op=nft_register_table"
@@ -62,6 +65,28 @@ for table in t1 t2; do
62
65
" table=$table family=2 entries=6 op=nft_register_rule"
63
66
done
64
67
68
+ for (( i = 0 ; i < 500 ; i++ )) ; do
69
+ echo " add rule t2 c3 counter accept comment \" rule $i \" "
70
+ done > $rulefile
71
+ do_test " nft -f $rulefile " \
72
+ ' table=t2 family=2 entries=500 op=nft_register_rule'
73
+
74
+ # adding sets and elements
75
+
76
+ settype=' type inet_service; counter'
77
+ setelem=' { 22, 80, 443 }'
78
+ setblock=" { $settype ; elements = $setelem ; }"
79
+ do_test " nft add set t1 s $setblock " \
80
+ " table=t1 family=2 entries=4 op=nft_register_set"
81
+
82
+ do_test " nft add set t1 s2 $setblock ; add set t1 s3 { $settype ; }" \
83
+ " table=t1 family=2 entries=5 op=nft_register_set"
84
+
85
+ do_test " nft add element t1 s3 $setelem " \
86
+ " table=t1 family=2 entries=3 op=nft_register_setelem"
87
+
88
+ # resetting rules
89
+
65
90
do_test ' nft reset rules t1 c2' \
66
91
' table=t1 family=2 entries=3 op=nft_reset_rule'
67
92
@@ -70,19 +95,6 @@ do_test 'nft reset rules table t1' \
70
95
table=t1 family=2 entries=3 op=nft_reset_rule
71
96
table=t1 family=2 entries=3 op=nft_reset_rule'
72
97
73
- do_test ' nft reset rules' \
74
- ' table=t1 family=2 entries=3 op=nft_reset_rule
75
- table=t1 family=2 entries=3 op=nft_reset_rule
76
- table=t1 family=2 entries=3 op=nft_reset_rule
77
- table=t2 family=2 entries=3 op=nft_reset_rule
78
- table=t2 family=2 entries=3 op=nft_reset_rule
79
- table=t2 family=2 entries=3 op=nft_reset_rule'
80
-
81
- for (( i = 0 ; i < 500 ; i++ )) ; do
82
- echo " add rule t2 c3 counter accept comment \" rule $i \" "
83
- done | do_test ' nft -f -' \
84
- ' table=t2 family=2 entries=500 op=nft_register_rule'
85
-
86
98
do_test ' nft reset rules t2 c3' \
87
99
' table=t2 family=2 entries=189 op=nft_reset_rule
88
100
table=t2 family=2 entries=188 op=nft_reset_rule
@@ -105,4 +117,57 @@ table=t2 family=2 entries=180 op=nft_reset_rule
105
117
table=t2 family=2 entries=188 op=nft_reset_rule
106
118
table=t2 family=2 entries=135 op=nft_reset_rule'
107
119
120
+ # resetting sets and elements
121
+
122
+ elem=(22 ,80 ,443)
123
+ relem=" "
124
+ for i in {1..3}; do
125
+ relem+=" ${elem[((i - 1))]} "
126
+ do_test " nft reset element t1 s { $relem }" \
127
+ " table=t1 family=2 entries=$i op=nft_reset_setelem"
128
+ done
129
+
130
+ do_test ' nft reset set t1 s' \
131
+ ' table=t1 family=2 entries=3 op=nft_reset_setelem'
132
+
133
+ # deleting rules
134
+
135
+ readarray -t handles < <( nft -a list chain t1 c1 | \
136
+ sed -n ' s/.*counter.* handle \(.*\)$/\1/p' )
137
+
138
+ do_test " nft delete rule t1 c1 handle ${handles[0]} " \
139
+ ' table=t1 family=2 entries=1 op=nft_unregister_rule'
140
+
141
+ cmd=' delete rule t1 c1 handle'
142
+ do_test " nft $cmd ${handles[1]} ; $cmd ${handles[2]} " \
143
+ ' table=t1 family=2 entries=2 op=nft_unregister_rule'
144
+
145
+ do_test ' nft flush chain t1 c2' \
146
+ ' table=t1 family=2 entries=3 op=nft_unregister_rule'
147
+
148
+ do_test ' nft flush table t2' \
149
+ ' table=t2 family=2 entries=509 op=nft_unregister_rule'
150
+
151
+ # deleting chains
152
+
153
+ do_test ' nft delete chain t2 c2' \
154
+ ' table=t2 family=2 entries=1 op=nft_unregister_chain'
155
+
156
+ # deleting sets and elements
157
+
158
+ do_test ' nft delete element t1 s { 22 }' \
159
+ ' table=t1 family=2 entries=1 op=nft_unregister_setelem'
160
+
161
+ do_test ' nft delete element t1 s { 80, 443 }' \
162
+ ' table=t1 family=2 entries=2 op=nft_unregister_setelem'
163
+
164
+ do_test ' nft flush set t1 s2' \
165
+ ' table=t1 family=2 entries=3 op=nft_unregister_setelem'
166
+
167
+ do_test ' nft delete set t1 s2' \
168
+ ' table=t1 family=2 entries=1 op=nft_unregister_set'
169
+
170
+ do_test ' nft delete set t1 s3' \
171
+ ' table=t1 family=2 entries=1 op=nft_unregister_set'
172
+
108
173
exit $RC
0 commit comments