0001-ebtables-basic_0 2.06 KB
Newer Older
1
2
#!/bin/sh

3
4
5
6
7
8
9
10
11
case "$XT_MULTI" in
*xtables-nft-multi)
	;;
*)
	echo "skip $XT_MULTI"
	exit 0
	;;
esac

12
13
14
15
get_entries_count() { # (chain)
	$XT_MULTI ebtables -L $1 | sed -n 's/.*entries: \([0-9]*\).*/\1/p'
}

16
17
set -x

18
19
20
21
22
for t in filter nat;do
	$XT_MULTI ebtables -t $t -L || exit 1
	$XT_MULTI ebtables -t $t -X || exit 1
	$XT_MULTI ebtables -t $t -F || exit 1
done
23

24
25
26
27
for t in broute foobar ;do
	$XT_MULTI ebtables -t $t -L &&
	$XT_MULTI ebtables -t $t -X &&
	$XT_MULTI ebtables -t $t -F
28
	if [ $? -eq 0 ]; then
29
		echo "Expect nonzero return for unsupported table"
30
31
		exit 1
	fi
32
done
33

34

35
36
37
38
39
40
41
$XT_MULTI ebtables -t filter -N FOO || exit 1
$XT_MULTI ebtables -t filter -N FOO
if [ $? -eq 0 ]; then
	echo "Duplicate chain FOO"
	$XT_MULTI ebtables -t filter -L
	exit 1
fi
42

43
44
45
46
47
48
entries=$(get_entries_count FOO)
if [ $entries -ne 0 ]; then
	echo "Unexpected entries count in empty unreferenced chain (expected 0, have $entries)"
	$XT_MULTI ebtables -L
	exit 1
fi
49

50
51
52
53
54
55
56
$XT_MULTI ebtables -A FORWARD -j FOO
entries=$(get_entries_count FORWARD)
if [ $entries -ne 1 ]; then
	echo "Unexpected entries count in FORWARD chain (expected 1, have $entries)"
	$XT_MULTI ebtables -L
	exit 1
fi
57

58
59
60
61
62
63
entries=$(get_entries_count FOO)
if [ $entries -ne 0 ]; then
	echo "Unexpected entries count in empty referenced chain (expected 0, have $entries)"
	$XT_MULTI ebtables -L
	exit 1
fi
64

65
66
67
68
69
70
71
$XT_MULTI ebtables -A FOO -j ACCEPT
entries=$(get_entries_count FOO)
if [ $entries -ne 1 ]; then
	echo "Unexpected entries count in non-empty referenced chain (expected 1, have $entries)"
	$XT_MULTI ebtables -L
	exit 1
fi
72

73
74
$XT_MULTI ebtables -t filter -N BAR || exit 1
$XT_MULTI ebtables -t filter -N BAZ || exit 1
75

76
77
78
79
80
81
82
83
84
85
86
87
88
89
$XT_MULTI ebtables -t filter -L | grep -q FOO || exit 1
$XT_MULTI ebtables -t filter -L | grep -q BAR || exit 1
$XT_MULTI ebtables -t filter -L | grep -q BAZ || exit 1

$XT_MULTI ebtables -t filter -L BAZ || exit 1
$XT_MULTI ebtables -t filter -X BAZ || exit 1
$XT_MULTI ebtables -t filter -L BAZ | grep -q BAZ
if [ $? -eq 0 ]; then
	echo "Deleted chain -L BAZ ok, expected failure"
	$XT_MULTI ebtables -t filter -L
	exit 1
fi

$XT_MULTI ebtables -t $t -F || exit 0