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",
81 define test1_subnets = { 10.0.0.0/8 }
82 define test2_subnets = { 2001:db8:1234::/64 }
83 define test3_subnets = { 2001:db8:1234::/64 }
84 define test4_subnets = { 2001:db8:1234::/64 }
85 define test5_devices = { "eth0" }
91 include "/etc/nftables.d/*.nft"
99 type filter hook input priority filter; policy drop;
101 iifname "lo" accept comment "!fw4: Accept traffic from loopback"
103 ct state established,related accept comment "!fw4: Allow inbound established and related flows"
104 meta nfproto ipv4 ip saddr 10.0.0.0/8 jump input_test1 comment "!fw4: Handle test1 IPv4 input traffic"
105 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 jump input_test2 comment "!fw4: Handle test2 IPv6 input traffic"
106 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 jump input_test3 comment "!fw4: Handle test3 IPv6 input traffic"
107 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 jump input_test4 comment "!fw4: Handle test4 IPv6 input traffic"
108 meta nfproto ipv6 iifname "eth0" jump input_test5 comment "!fw4: Handle test5 IPv6 input traffic"
112 type filter hook forward priority filter; policy drop;
114 ct state established,related accept comment "!fw4: Allow forwarded established and related flows"
115 meta nfproto ipv4 ip saddr 10.0.0.0/8 jump forward_test1 comment "!fw4: Handle test1 IPv4 forward traffic"
116 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 jump forward_test2 comment "!fw4: Handle test2 IPv6 forward traffic"
117 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 jump forward_test3 comment "!fw4: Handle test3 IPv6 forward traffic"
118 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 jump forward_test4 comment "!fw4: Handle test4 IPv6 forward traffic"
119 meta nfproto ipv6 iifname "eth0" jump forward_test5 comment "!fw4: Handle test5 IPv6 forward traffic"
123 type filter hook output priority filter; policy drop;
125 oifname "lo" accept comment "!fw4: Accept traffic towards loopback"
127 ct state established,related accept comment "!fw4: Allow outbound established and related flows"
128 meta nfproto ipv4 ip daddr 10.0.0.0/8 jump output_test1 comment "!fw4: Handle test1 IPv4 output traffic"
129 meta nfproto ipv6 ip6 daddr 2001:db8:1234::/64 jump output_test2 comment "!fw4: Handle test2 IPv6 output traffic"
130 meta nfproto ipv6 ip6 daddr 2001:db8:1234::/64 jump output_test3 comment "!fw4: Handle test3 IPv6 output traffic"
131 meta nfproto ipv6 ip6 daddr 2001:db8:1234::/64 jump output_test4 comment "!fw4: Handle test4 IPv6 output traffic"
132 meta nfproto ipv6 oifname "eth0" jump output_test5 comment "!fw4: Handle test5 IPv6 output traffic"
136 type filter hook prerouting priority filter; policy accept;
139 chain handle_reject {
140 meta l4proto tcp reject with tcp reset comment "!fw4: Reject TCP traffic"
141 reject with icmpx type port-unreachable comment "!fw4: Reject any other traffic"
152 chain forward_test1 {
156 chain drop_from_test1 {
157 meta nfproto ipv4 ip saddr 10.0.0.0/8 counter drop comment "!fw4: drop test1 IPv4 traffic"
160 chain drop_to_test1 {
161 meta nfproto ipv4 ip daddr 10.0.0.0/8 counter drop comment "!fw4: drop test1 IPv4 traffic"
172 chain forward_test2 {
176 chain drop_from_test2 {
177 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 counter drop comment "!fw4: drop test2 IPv6 traffic"
180 chain drop_to_test2 {
181 meta nfproto ipv6 ip6 daddr 2001:db8:1234::/64 counter drop comment "!fw4: drop test2 IPv6 traffic"
192 chain forward_test3 {
196 chain drop_from_test3 {
197 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 counter drop comment "!fw4: drop test3 IPv6 traffic"
200 chain drop_to_test3 {
201 meta nfproto ipv6 ip6 daddr 2001:db8:1234::/64 counter drop comment "!fw4: drop test3 IPv6 traffic"
212 chain forward_test4 {
216 chain drop_from_test4 {
217 meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 counter drop comment "!fw4: drop test4 IPv6 traffic"
220 chain drop_to_test4 {
221 meta nfproto ipv6 ip6 daddr 2001:db8:1234::/64 counter drop comment "!fw4: drop test4 IPv6 traffic"
232 chain forward_test5 {
236 chain drop_from_test5 {
237 meta nfproto ipv6 iifname "eth0" counter drop comment "!fw4: drop test5 IPv6 traffic"
240 chain drop_to_test5 {
241 meta nfproto ipv6 oifname "eth0" counter drop comment "!fw4: drop test5 IPv6 traffic"
250 type nat hook prerouting priority dstnat; policy accept;
254 type nat hook postrouting priority srcnat; policy accept;
259 # Raw rules (notrack)
262 chain raw_prerouting {
263 type filter hook prerouting priority raw; policy accept;
267 type filter hook output priority raw; policy accept;
275 chain mangle_prerouting {
276 type filter hook prerouting priority mangle; policy accept;
279 chain mangle_postrouting {
280 type filter hook postrouting priority mangle; policy accept;
284 type filter hook input priority mangle; policy accept;
287 chain mangle_output {
288 type route hook output priority mangle; policy accept;
291 chain mangle_forward {
292 type filter hook forward priority mangle; policy accept;