1 Test various address selection rules in redirect rules.
5 include("./root/usr/share/firewall4/main.uc", {
6 getenv: function(varname) {
16 -- File uci/helpers.json --
20 -- File uci/firewall.json --
25 "network": [ "wan", "wan6" ],
36 "network": [ "noaddr" ],
43 ".description": "Ensure unspecified family with no src, dest or rewrite address is treated as IPv4 only",
44 "name": "Redirect test #1",
53 ".description": "Ensure that explicit family any with no src, dest or rewrite address is treated as IPv4/IPv6",
54 "name": "Redirect test #2",
64 ".description": "Ensure that a DNAT without explicit dest zone infers the zone from the rewrite address",
65 "name": "Redirect test #3",
69 "dest_ip": "192.168.26.100"
72 ".description": "Ensure that external reflection source uses the src zone addr as reflection source IP",
73 "name": "Redirect test #4",
77 "dest_ip": "192.168.26.100",
78 "reflection_src": "external"
81 ".description": "Ensure that reflection is disabled if external address cannot be determined",
82 "name": "Redirect test #5",
87 "dest_ip": "192.168.26.100"
94 [!] Section @redirect[2] (Redirect test #3) does not specify a destination, assuming 'lan'
95 [!] Section @redirect[3] (Redirect test #4) does not specify a destination, assuming 'lan'
96 [!] Section @redirect[4] (Redirect test #5) external address range cannot be determined, disabling reflection
113 define wan_devices = { "pppoe-wan" }
114 define wan_subnets = { 10.11.12.0/24, 2001:db8:54:321::/64 }
115 define lan_devices = { "br-lan" }
116 define lan_subnets = { 10.0.0.0/24, 192.168.26.0/24, 2001:db8:1000::/60, fd63:e2f:f706::/60 }
117 define noaddr_devices = { "wwan0" }
123 include "/etc/nftables.d/*.nft"
131 type filter hook input priority filter; policy drop;
133 iifname "lo" accept comment "!fw4: Accept traffic from loopback"
135 ct state established,related accept comment "!fw4: Allow inbound established and related flows"
136 iifname "pppoe-wan" jump input_wan comment "!fw4: Handle wan IPv4/IPv6 input traffic"
137 iifname "br-lan" jump input_lan comment "!fw4: Handle lan IPv4/IPv6 input traffic"
138 iifname "wwan0" jump input_noaddr comment "!fw4: Handle noaddr IPv4/IPv6 input traffic"
142 type filter hook forward priority filter; policy drop;
144 ct state established,related accept comment "!fw4: Allow forwarded established and related flows"
145 iifname "pppoe-wan" jump forward_wan comment "!fw4: Handle wan IPv4/IPv6 forward traffic"
146 iifname "br-lan" jump forward_lan comment "!fw4: Handle lan IPv4/IPv6 forward traffic"
147 iifname "wwan0" jump forward_noaddr comment "!fw4: Handle noaddr IPv4/IPv6 forward traffic"
151 type filter hook output priority filter; policy drop;
153 oifname "lo" accept comment "!fw4: Accept traffic towards loopback"
155 ct state established,related accept comment "!fw4: Allow outbound established and related flows"
156 oifname "pppoe-wan" jump output_wan comment "!fw4: Handle wan IPv4/IPv6 output traffic"
157 oifname "br-lan" jump output_lan comment "!fw4: Handle lan IPv4/IPv6 output traffic"
158 oifname "wwan0" jump output_noaddr comment "!fw4: Handle noaddr IPv4/IPv6 output traffic"
161 chain handle_reject {
162 meta l4proto tcp reject with tcp reset comment "!fw4: Reject TCP traffic"
163 reject with icmpx type port-unreachable comment "!fw4: Reject any other traffic"
167 ct status dnat accept comment "!fw4: Accept port redirections"
176 ct status dnat accept comment "!fw4: Accept port forwards"
180 chain drop_from_wan {
181 iifname "pppoe-wan" counter drop comment "!fw4: drop wan IPv4/IPv6 traffic"
185 oifname "pppoe-wan" counter drop comment "!fw4: drop wan IPv4/IPv6 traffic"
189 ct status dnat accept comment "!fw4: Accept port redirections"
198 ct status dnat accept comment "!fw4: Accept port forwards"
202 chain accept_to_lan {
203 oifname "br-lan" counter accept comment "!fw4: accept lan IPv4/IPv6 traffic"
206 chain drop_from_lan {
207 iifname "br-lan" counter drop comment "!fw4: drop lan IPv4/IPv6 traffic"
211 oifname "br-lan" counter drop comment "!fw4: drop lan IPv4/IPv6 traffic"
215 ct status dnat accept comment "!fw4: Accept port redirections"
216 jump drop_from_noaddr
219 chain output_noaddr {
223 chain forward_noaddr {
224 ct status dnat accept comment "!fw4: Accept port forwards"
228 chain drop_from_noaddr {
229 iifname "wwan0" counter drop comment "!fw4: drop noaddr IPv4/IPv6 traffic"
232 chain drop_to_noaddr {
233 oifname "wwan0" counter drop comment "!fw4: drop noaddr IPv4/IPv6 traffic"
242 type nat hook prerouting priority dstnat; policy accept;
243 iifname "pppoe-wan" jump dstnat_wan comment "!fw4: Handle wan IPv4/IPv6 dstnat traffic"
244 iifname "br-lan" jump dstnat_lan comment "!fw4: Handle lan IPv4/IPv6 dstnat traffic"
245 iifname "wwan0" jump dstnat_noaddr comment "!fw4: Handle noaddr IPv4/IPv6 dstnat traffic"
249 type nat hook postrouting priority srcnat; policy accept;
250 oifname "pppoe-wan" jump srcnat_wan comment "!fw4: Handle wan IPv4/IPv6 srcnat traffic"
251 oifname "br-lan" jump srcnat_lan comment "!fw4: Handle lan IPv4/IPv6 srcnat traffic"
252 oifname "wwan0" jump srcnat_noaddr comment "!fw4: Handle noaddr IPv4/IPv6 srcnat traffic"
256 meta nfproto ipv4 tcp dport 22 counter dnat 192.168.26.100:22 comment "!fw4: Redirect test #3"
257 meta nfproto ipv4 tcp dport 23 counter dnat 192.168.26.100:23 comment "!fw4: Redirect test #4"
261 meta nfproto ipv4 masquerade comment "!fw4: Masquerade IPv4 wan traffic"
262 meta nfproto ipv6 masquerade comment "!fw4: Masquerade IPv6 wan traffic"
266 meta nfproto ipv4 udp dport 53 counter redirect to 53 comment "!fw4: Redirect test #1"
267 udp dport 53 counter redirect to 53 comment "!fw4: Redirect test #2"
268 ip saddr { 10.0.0.0/24, 192.168.26.0/24 } ip daddr 10.11.12.194 tcp dport 22 dnat 192.168.26.100:22 comment "!fw4: Redirect test #3 (reflection)"
269 ip saddr { 10.0.0.0/24, 192.168.26.0/24 } ip daddr 10.11.12.194 tcp dport 23 dnat 192.168.26.100:23 comment "!fw4: Redirect test #4 (reflection)"
273 ip saddr { 10.0.0.0/24, 192.168.26.0/24 } ip daddr 192.168.26.100 tcp dport 22 snat 192.168.26.1 comment "!fw4: Redirect test #3 (reflection)"
274 ip saddr { 10.0.0.0/24, 192.168.26.0/24 } ip daddr 192.168.26.100 tcp dport 23 snat 10.11.12.194 comment "!fw4: Redirect test #4 (reflection)"
277 chain dstnat_noaddr {
278 meta nfproto ipv4 tcp dport 24 counter dnat 192.168.26.100:24 comment "!fw4: Redirect test #5"
281 chain srcnat_noaddr {
282 meta nfproto ipv4 masquerade comment "!fw4: Masquerade IPv4 noaddr traffic"
283 meta nfproto ipv6 masquerade comment "!fw4: Masquerade IPv6 noaddr traffic"
288 # Raw rules (notrack & helper)
291 chain raw_prerouting {
292 type filter hook prerouting priority raw; policy accept;
296 type filter hook output priority raw; policy accept;
304 chain mangle_prerouting {
305 type filter hook prerouting priority mangle; policy accept;
308 chain mangle_postrouting {
309 type filter hook postrouting priority mangle; policy accept;
313 type filter hook input priority mangle; policy accept;
316 chain mangle_output {
317 type filter hook output priority mangle; policy accept;
320 chain mangle_forward {
321 type filter hook forward priority mangle; policy accept;