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 "description" : "An example IPv4-only conntrack helper",
23 "module" : "nf_conntrack_dummy",
32 -- File uci/firewall.json --
36 ".description": "Family any with IPv4 subnet should emit only IPv4 rules",
39 "subnet": [ "10.0.0.0/8" ],
44 ".description": "Family any with IPv6 subnet should emit only IPv6 rules",
47 "subnet": [ "2001:db8:1234::1/64" ],
52 ".description": "Family IPv6 with IPv6 subnet should emit only IPv6 rules",
55 "subnet": [ "2001:db8:1234::1/64" ],
60 ".description": "Family IPv6 with IPv4 subnet should emit no rules",
63 "subnet": [ "2001:db8:1234::1/64" ],
68 ".description": "Family IPv6 with no subnets should emit only IPv6 rules",
76 ".description": "Family restrictions of associated ct helpers should not influence zone family selection",
79 "device": [ "br-lan" ],
92 # CT helper definitions
96 type "test" protocol tcp;
104 define test1_devices = { }
105 define test1_subnets = { 10.0.0.0/8 }
107 define test2_devices = { }
108 define test2_subnets = { 2001:db8:1234::/64 }
110 define test3_devices = { }
111 define test3_subnets = { 2001:db8:1234::/64 }
113 define test4_devices = { }
114 define test4_subnets = { 2001:db8:1234::/64 }
116 define test5_devices = { "eth0" }
117 define test5_subnets = { }
119 define test6_devices = { "br-lan" }
120 define test6_subnets = { }
127 include "/etc/nftables.d/*.nft"
135 type filter hook input priority filter; policy drop;
137 iifname "lo" accept comment "!fw4: Accept traffic from loopback"
139 ct state established,related accept comment "!fw4: Allow inbound established and related flows"
140 meta nfproto ipv4 ip saddr 10.0.0.0/8 jump input_test1 comment "!fw4: Handle test1 IPv4 input traffic"
141 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 jump input_test2 comment "!fw4: Handle test2 IPv6 input traffic"
142 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 jump input_test3 comment "!fw4: Handle test3 IPv6 input traffic"
143 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 jump input_test4 comment "!fw4: Handle test4 IPv6 input traffic"
144 meta nfproto ipv6 iifname "eth0" jump input_test5 comment "!fw4: Handle test5 IPv6 input traffic"
145 iifname "br-lan" jump input_test6 comment "!fw4: Handle test6 IPv4/IPv6 input traffic"
149 type filter hook forward priority filter; policy drop;
151 ct state established,related accept comment "!fw4: Allow forwarded established and related flows"
152 meta nfproto ipv4 ip saddr 10.0.0.0/8 jump forward_test1 comment "!fw4: Handle test1 IPv4 forward traffic"
153 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 jump forward_test2 comment "!fw4: Handle test2 IPv6 forward traffic"
154 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 jump forward_test3 comment "!fw4: Handle test3 IPv6 forward traffic"
155 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 jump forward_test4 comment "!fw4: Handle test4 IPv6 forward traffic"
156 meta nfproto ipv6 iifname "eth0" jump forward_test5 comment "!fw4: Handle test5 IPv6 forward traffic"
157 iifname "br-lan" jump forward_test6 comment "!fw4: Handle test6 IPv4/IPv6 forward traffic"
161 type filter hook output priority filter; policy drop;
163 oifname "lo" accept comment "!fw4: Accept traffic towards loopback"
165 ct state established,related accept comment "!fw4: Allow outbound established and related flows"
166 meta nfproto ipv4 ip daddr 10.0.0.0/8 jump output_test1 comment "!fw4: Handle test1 IPv4 output traffic"
167 meta nfproto ipv6 ip6 daddr 2001:db8:1234::/64 jump output_test2 comment "!fw4: Handle test2 IPv6 output traffic"
168 meta nfproto ipv6 ip6 daddr 2001:db8:1234::/64 jump output_test3 comment "!fw4: Handle test3 IPv6 output traffic"
169 meta nfproto ipv6 ip6 daddr 2001:db8:1234::/64 jump output_test4 comment "!fw4: Handle test4 IPv6 output traffic"
170 meta nfproto ipv6 oifname "eth0" jump output_test5 comment "!fw4: Handle test5 IPv6 output traffic"
171 oifname "br-lan" jump output_test6 comment "!fw4: Handle test6 IPv4/IPv6 output traffic"
175 type filter hook prerouting priority filter; policy accept;
176 iifname "br-lan" jump helper_test6 comment "!fw4: Handle test6 IPv4/IPv6 helper assignment"
179 chain handle_reject {
180 meta l4proto tcp reject with tcp reset comment "!fw4: Reject TCP traffic"
181 reject with icmpx type port-unreachable comment "!fw4: Reject any other traffic"
192 chain forward_test1 {
196 chain drop_from_test1 {
197 meta nfproto ipv4 ip saddr 10.0.0.0/8 counter drop comment "!fw4: drop test1 IPv4 traffic"
200 chain drop_to_test1 {
201 meta nfproto ipv4 ip daddr 10.0.0.0/8 counter drop comment "!fw4: drop test1 IPv4 traffic"
212 chain forward_test2 {
216 chain drop_from_test2 {
217 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 counter drop comment "!fw4: drop test2 IPv6 traffic"
220 chain drop_to_test2 {
221 meta nfproto ipv6 ip6 daddr 2001:db8:1234::/64 counter drop comment "!fw4: drop test2 IPv6 traffic"
232 chain forward_test3 {
236 chain drop_from_test3 {
237 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 counter drop comment "!fw4: drop test3 IPv6 traffic"
240 chain drop_to_test3 {
241 meta nfproto ipv6 ip6 daddr 2001:db8:1234::/64 counter drop comment "!fw4: drop test3 IPv6 traffic"
252 chain forward_test4 {
256 chain drop_from_test4 {
257 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 counter drop comment "!fw4: drop test4 IPv6 traffic"
260 chain drop_to_test4 {
261 meta nfproto ipv6 ip6 daddr 2001:db8:1234::/64 counter drop comment "!fw4: drop test4 IPv6 traffic"
272 chain forward_test5 {
276 chain drop_from_test5 {
277 meta nfproto ipv6 iifname "eth0" counter drop comment "!fw4: drop test5 IPv6 traffic"
280 chain drop_to_test5 {
281 meta nfproto ipv6 oifname "eth0" counter drop comment "!fw4: drop test5 IPv6 traffic"
292 chain forward_test6 {
297 meta nfproto ipv4 meta l4proto tcp tcp dport 1234 ct helper set "test" comment "!fw4: An example IPv4-only conntrack helper"
300 chain drop_from_test6 {
301 iifname "br-lan" counter drop comment "!fw4: drop test6 IPv4/IPv6 traffic"
304 chain drop_to_test6 {
305 oifname "br-lan" counter drop comment "!fw4: drop test6 IPv4/IPv6 traffic"
314 type nat hook prerouting priority dstnat; policy accept;
318 type nat hook postrouting priority srcnat; policy accept;
323 # Raw rules (notrack)
326 chain raw_prerouting {
327 type filter hook prerouting priority raw; policy accept;
331 type filter hook output priority raw; policy accept;
339 chain mangle_prerouting {
340 type filter hook prerouting priority mangle; policy accept;
343 chain mangle_postrouting {
344 type filter hook postrouting priority mangle; policy accept;
348 type filter hook input priority mangle; policy accept;
351 chain mangle_output {
352 type route hook output priority mangle; policy accept;
355 chain mangle_forward {
356 type filter hook forward priority mangle; policy accept;