File: netdev_move_device

package info (click to toggle)
nftables 1.1.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,384 kB
  • sloc: ansic: 50,901; sh: 20,277; yacc: 5,861; python: 1,746; lex: 1,367; makefile: 392
file content (39 lines) | stat: -rwxr-xr-x 732 bytes parent folder | download | duplicates (2)
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
#!/bin/bash

set -e

rnd=$(mktemp -u XXXXXXXX)
ns1="nft1-$rnd"

cleanup() {
	ip netns del "$ns1"
	ip link del d0 &>/dev/null || :
}
trap 'cleanup' EXIT

RULESET="table netdev x {
	chain x {}
	chain w {
		ip daddr 8.7.6.0/24 counter
	}
	chain y {
		type filter hook ingress device d0 priority 0;
		ip saddr { 1.2.3.4, 2.3.4.5 } counter
		ip daddr vmap { 5.4.3.0/24 : jump w, 8.9.0.0/24 : jump x }
	}
}"

ip link add d0 type dummy
$NFT -f - <<< $RULESET

ip netns add $ns1
# move device to $ns1 triggers UNREGISTER event
ip link set d0 netns $ns1

cleanup
$NFT delete table netdev x

# a simple test that also triggers UNREGISTER event
ip netns add $ns1
ip -netns $ns1 link add d0 type dummy
ip netns exec $ns1 $NFT -f - <<< $RULESET