summaryrefslogtreecommitdiffstats
path: root/tests/shell/testcases/rule_management/0001addinsertposition_0
blob: 237e9e3204c932f1f4d8d3eaf67a1afb9a3c2ee3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash

# tests for Netfilter bug #965 and the related fix
# (regarding rule management with a given position/handle spec)

set -e

RULESET="flush ruleset
table ip t {
	chain c {
		accept
		accept
	}
}"

EXPECTED="table ip t {
	chain c {
		accept
		drop
		accept
	}
}"

for arg in "position 2" "handle 2" "index 0"; do
	$NFT -f - <<< "$RULESET"
	$NFT add rule t c $arg drop || {
		$NFT list ruleset
		exit 1
	}

	GET="$($NFT list ruleset)"
	if [ "$EXPECTED" != "$GET" ] ; then
		$DIFF -u <(echo "$EXPECTED") <(echo "$GET")
		exit 1
	fi
done

for arg in "position 3" "handle 3" "index 1"; do
	$NFT -f - <<< "$RULESET"
	$NFT insert rule t c $arg drop

	GET="$($NFT list ruleset)"
	if [ "$EXPECTED" != "$GET" ] ; then
		$DIFF -u <(echo "$EXPECTED") <(echo "$GET")
		exit 1
	fi
done

EXPECTED="table ip t {
	chain c {
		accept
		accept
		drop
	}
}"

for arg in "position 3" "handle 3" "index 1"; do
	$NFT -f - <<< "$RULESET"
	$NFT add rule t c $arg drop

	GET="$($NFT list ruleset)"
	if [ "$EXPECTED" != "$GET" ] ; then
		$DIFF -u <(echo "$EXPECTED") <(echo "$GET")
		exit 1
	fi
done

EXPECTED="table ip t {
	chain c {
		drop
		accept
		accept
	}
}"

for arg in "position 2" "handle 2" "index 0"; do
	$NFT -f - <<< "$RULESET"
	$NFT insert rule t c $arg drop

	GET="$($NFT list ruleset)"
	if [ "$EXPECTED" != "$GET" ] ; then
		$DIFF -u <(echo "$EXPECTED") <(echo "$GET")
		exit 1
	fi
done