1 Test that the zone family is honoured regardless of whether subnets are
6 include("./root/usr/share/firewall4/main.uc", {
7 getenv: function(varname) {
17 -- File uci/helpers.json --
21 -- File uci/firewall.json --
25 ".description": "Family any with IPv4 subnet should emit only IPv4 rules",
28 "subnet": [ "10.0.0.0/8" ],
33 ".description": "Family any with IPv6 subnet should emit only IPv6 rules",
36 "subnet": [ "2001:db8:1234::1/64" ],
41 ".description": "Family IPv6 with IPv6 subnet should emit only IPv6 rules",
44 "subnet": [ "2001:db8:1234::1/64" ],
49 ".description": "Family IPv6 with IPv4 subnet should emit no rules",
52 "subnet": [ "2001:db8:1234::1/64" ],
57 ".description": "Family IPv6 with no subnets should emit only IPv6 rules",
76 define test1_devices = { }
77 define test1_subnets = { 10.0.0.0/8 }
79 define test2_devices = { }
80 define test2_subnets = { 2001:db8:1234::/64 }
82 define test3_devices = { }
83 define test3_subnets = { 2001:db8:1234::/64 }
85 define test4_devices = { }
86 define test4_subnets = { 2001:db8:1234::/64 }
88 define test5_devices = { "eth0" }
89 define test5_subnets = { }
96 include "/etc/nftables.d/*.nft"
104 type filter hook input priority filter; policy drop;
106 iifname "lo" accept comment "!fw4: Accept traffic from loopback"
108 ct state established,related accept comment "!fw4: Allow inbound established and related flows"
109 meta nfproto ipv4 ip saddr 10.0.0.0/8 jump input_test1 comment "!fw4: Handle test1 IPv4 input traffic"
110 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 jump input_test2 comment "!fw4: Handle test2 IPv6 input traffic"
111 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 jump input_test3 comment "!fw4: Handle test3 IPv6 input traffic"
112 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 jump input_test4 comment "!fw4: Handle test4 IPv6 input traffic"
113 meta nfproto ipv6 iifname "eth0" jump input_test5 comment "!fw4: Handle test5 IPv6 input traffic"
117 type filter hook forward priority filter; policy drop;
119 ct state established,related accept comment "!fw4: Allow forwarded established and related flows"
120 meta nfproto ipv4 ip saddr 10.0.0.0/8 jump forward_test1 comment "!fw4: Handle test1 IPv4 forward traffic"
121 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 jump forward_test2 comment "!fw4: Handle test2 IPv6 forward traffic"
122 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 jump forward_test3 comment "!fw4: Handle test3 IPv6 forward traffic"
123 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 jump forward_test4 comment "!fw4: Handle test4 IPv6 forward traffic"
124 meta nfproto ipv6 iifname "eth0" jump forward_test5 comment "!fw4: Handle test5 IPv6 forward traffic"
128 type filter hook output priority filter; policy drop;
130 oifname "lo" accept comment "!fw4: Accept traffic towards loopback"
132 ct state established,related accept comment "!fw4: Allow outbound established and related flows"
133 meta nfproto ipv4 ip daddr 10.0.0.0/8 jump output_test1 comment "!fw4: Handle test1 IPv4 output traffic"
134 meta nfproto ipv6 ip6 daddr 2001:db8:1234::/64 jump output_test2 comment "!fw4: Handle test2 IPv6 output traffic"
135 meta nfproto ipv6 ip6 daddr 2001:db8:1234::/64 jump output_test3 comment "!fw4: Handle test3 IPv6 output traffic"
136 meta nfproto ipv6 ip6 daddr 2001:db8:1234::/64 jump output_test4 comment "!fw4: Handle test4 IPv6 output traffic"
137 meta nfproto ipv6 oifname "eth0" jump output_test5 comment "!fw4: Handle test5 IPv6 output traffic"
141 type filter hook prerouting priority filter; policy accept;
144 chain handle_reject {
145 meta l4proto tcp reject with tcp reset comment "!fw4: Reject TCP traffic"
146 reject with icmpx type port-unreachable comment "!fw4: Reject any other traffic"
157 chain forward_test1 {
161 chain drop_from_test1 {
162 meta nfproto ipv4 ip saddr 10.0.0.0/8 counter drop comment "!fw4: drop test1 IPv4 traffic"
165 chain drop_to_test1 {
166 meta nfproto ipv4 ip daddr 10.0.0.0/8 counter drop comment "!fw4: drop test1 IPv4 traffic"
177 chain forward_test2 {
181 chain drop_from_test2 {
182 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 counter drop comment "!fw4: drop test2 IPv6 traffic"
185 chain drop_to_test2 {
186 meta nfproto ipv6 ip6 daddr 2001:db8:1234::/64 counter drop comment "!fw4: drop test2 IPv6 traffic"
197 chain forward_test3 {
201 chain drop_from_test3 {
202 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 counter drop comment "!fw4: drop test3 IPv6 traffic"
205 chain drop_to_test3 {
206 meta nfproto ipv6 ip6 daddr 2001:db8:1234::/64 counter drop comment "!fw4: drop test3 IPv6 traffic"
217 chain forward_test4 {
221 chain drop_from_test4 {
222 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 counter drop comment "!fw4: drop test4 IPv6 traffic"
225 chain drop_to_test4 {
226 meta nfproto ipv6 ip6 daddr 2001:db8:1234::/64 counter drop comment "!fw4: drop test4 IPv6 traffic"
237 chain forward_test5 {
241 chain drop_from_test5 {
242 meta nfproto ipv6 iifname "eth0" counter drop comment "!fw4: drop test5 IPv6 traffic"
245 chain drop_to_test5 {
246 meta nfproto ipv6 oifname "eth0" counter drop comment "!fw4: drop test5 IPv6 traffic"
255 type nat hook prerouting priority dstnat; policy accept;
259 type nat hook postrouting priority srcnat; policy accept;
264 # Raw rules (notrack)
267 chain raw_prerouting {
268 type filter hook prerouting priority raw; policy accept;
272 type filter hook output priority raw; policy accept;
280 chain mangle_prerouting {
281 type filter hook prerouting priority mangle; policy accept;
284 chain mangle_postrouting {
285 type filter hook postrouting priority mangle; policy accept;
289 type filter hook input priority mangle; policy accept;
292 chain mangle_output {
293 type route hook output priority mangle; policy accept;
296 chain mangle_forward {
297 type filter hook forward priority mangle; policy accept;