Debian Codegraph @

tests/shell/testcases/netns/0002loosecommands_0

raw symbols SCIP
1 #!/bin/bash
2
3 # test a kernel netns loading a simple ruleset
4
5 IP=$(which ip)
6 if [ ! -x "$IP" ] ; then
7 echo "E: no ip binary" >&2
8 exit 1
9 fi
10
11 function netns_exec()
12 {
13 # $1: netns_name $2: command
14 $IP netns exec $1 $2
15 if [ $? -ne 0 ] ; then
16 echo "E: failed to execute command in netns $1: $2" >&2
17 $IP netns del $1
18 exit 1
19 fi
20 }
21
22 NETNS_NAME=$(basename "$0")
23 $IP netns add $NETNS_NAME
24 if [ $? -ne 0 ] ; then
25 echo "E: unable to create netns" >&2
26 exit 1
27 fi
28
29 netns_exec $NETNS_NAME "$NFT add table ip t"
30 netns_exec $NETNS_NAME "$NFT add chain ip t c"
31 netns_exec $NETNS_NAME "$NFT add chain ip t other"
32 netns_exec $NETNS_NAME "$NFT add set ip t s { type ipv4_addr; }"
33 netns_exec $NETNS_NAME "$NFT add element ip t s {1.1.0.0 }"
34 netns_exec $NETNS_NAME "$NFT add rule ip t c ct state new"
35 netns_exec $NETNS_NAME "$NFT add rule ip t c udp dport { 12345, 54321 }"
36 netns_exec $NETNS_NAME "$NFT add rule ip t c ip saddr @s drop"
37 netns_exec $NETNS_NAME "$NFT add rule ip t c jump other"
38
39 RULESET="table ip t {
40 set s {
41 type ipv4_addr
42 elements = { 1.1.0.0 }
43 }
44
45 chain c {
46 ct state new
47 udp dport { 12345, 54321 }
48 ip saddr @s drop
49 jump other
50 }
51
52 chain other {
53 }
54 }"
55
56 KERNEL_RULESET="$($IP netns exec $NETNS_NAME $NFT list ruleset)"
57 $IP netns del $NETNS_NAME
58 if [ "$RULESET" != "$KERNEL_RULESET" ] ; then
59 $DIFF -u <(echo "$RULESET") <(echo "$KERNEL_RULESET")
60 exit 1
61 fi