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" ],
37 ".description": "Ensure unspecified family with no src, dest or rewrite address is treated as IPv4 only",
38 "name": "Redirect test #1",
47 ".description": "Ensure that explicit family any with no src, dest or rewrite address is treated as IPv4/IPv6",
48 "name": "Redirect test #2",
58 ".description": "Ensure that a DNAT without explicit dest zone infers the zone from the rewrite address",
59 "name": "Redirect test #3",
63 "dest_ip": "192.168.26.100"
66 ".description": "Ensure that external reflection source uses the src zone addr as reflection source IP",
67 "name": "Redirect test #4",
71 "dest_ip": "192.168.26.100",
72 "reflection_src": "external"
79 [!] Section @redirect[2] (Redirect test #3) does not specify a destination, assuming 'lan'
80 [!] Section @redirect[3] (Redirect test #4) does not specify a destination, assuming 'lan'
97 define wan_devices = { "eth1" }
98 define wan_subnets = { 10.11.12.0/24, 2001:db8:54:321::/64 }
99 define lan_devices = { "br-lan" }
100 define lan_subnets = { 10.0.0.0/24, 192.168.26.0/24, 2001:db8:1000::/60, fd63:e2f:f706::/60 }
106 include "/etc/nftables.d/*.nft"
114 type filter hook input priority filter; policy drop;
116 iifname "lo" accept comment "!fw4: Accept traffic from loopback"
118 ct state established,related accept comment "!fw4: Allow inbound established and related flows"
119 iifname "eth1" jump input_wan comment "!fw4: Handle wan IPv4/IPv6 input traffic"
120 iifname "br-lan" jump input_lan comment "!fw4: Handle lan IPv4/IPv6 input traffic"
124 type filter hook forward priority filter; policy drop;
126 ct state established,related accept comment "!fw4: Allow forwarded established and related flows"
127 iifname "eth1" jump forward_wan comment "!fw4: Handle wan IPv4/IPv6 forward traffic"
128 iifname "br-lan" jump forward_lan comment "!fw4: Handle lan IPv4/IPv6 forward traffic"
132 type filter hook output priority filter; policy drop;
134 oifname "lo" accept comment "!fw4: Accept traffic towards loopback"
136 ct state established,related accept comment "!fw4: Allow outbound established and related flows"
137 oifname "eth1" jump output_wan comment "!fw4: Handle wan IPv4/IPv6 output traffic"
138 oifname "br-lan" jump output_lan comment "!fw4: Handle lan IPv4/IPv6 output traffic"
141 chain handle_reject {
142 meta l4proto tcp reject with tcp reset comment "!fw4: Reject TCP traffic"
143 reject with icmpx type port-unreachable comment "!fw4: Reject any other traffic"
147 ct status dnat accept comment "!fw4: Accept port redirections"
156 ct status dnat accept comment "!fw4: Accept port forwards"
160 chain drop_from_wan {
161 iifname "eth1" counter drop comment "!fw4: drop wan IPv4/IPv6 traffic"
165 oifname "eth1" counter drop comment "!fw4: drop wan IPv4/IPv6 traffic"
169 ct status dnat accept comment "!fw4: Accept port redirections"
178 ct status dnat accept comment "!fw4: Accept port forwards"
182 chain accept_to_lan {
183 oifname "br-lan" counter accept comment "!fw4: accept lan IPv4/IPv6 traffic"
186 chain drop_from_lan {
187 iifname "br-lan" counter drop comment "!fw4: drop lan IPv4/IPv6 traffic"
191 oifname "br-lan" counter drop comment "!fw4: drop lan IPv4/IPv6 traffic"
200 type nat hook prerouting priority dstnat; policy accept;
201 iifname "eth1" jump dstnat_wan comment "!fw4: Handle wan IPv4/IPv6 dstnat traffic"
202 iifname "br-lan" jump dstnat_lan comment "!fw4: Handle lan IPv4/IPv6 dstnat traffic"
206 type nat hook postrouting priority srcnat; policy accept;
207 oifname "eth1" jump srcnat_wan comment "!fw4: Handle wan IPv4/IPv6 srcnat traffic"
208 oifname "br-lan" jump srcnat_lan comment "!fw4: Handle lan IPv4/IPv6 srcnat traffic"
212 meta nfproto ipv4 tcp dport 22 counter dnat 192.168.26.100:22 comment "!fw4: Redirect test #3"
213 meta nfproto ipv4 tcp dport 23 counter dnat 192.168.26.100:23 comment "!fw4: Redirect test #4"
217 meta nfproto ipv4 masquerade comment "!fw4: Masquerade IPv4 wan traffic"
218 meta nfproto ipv6 masquerade comment "!fw4: Masquerade IPv6 wan traffic"
222 meta nfproto ipv4 udp dport 53 counter redirect to 53 comment "!fw4: Redirect test #1"
223 udp dport 53 counter redirect to 53 comment "!fw4: Redirect test #2"
224 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)"
225 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)"
229 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)"
230 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)"
235 # Raw rules (notrack & helper)
238 chain raw_prerouting {
239 type filter hook prerouting priority raw; policy accept;
243 type filter hook output priority raw; policy accept;
251 chain mangle_prerouting {
252 type filter hook prerouting priority mangle; policy accept;
255 chain mangle_postrouting {
256 type filter hook postrouting priority mangle; policy accept;
260 type filter hook input priority mangle; policy accept;
263 chain mangle_output {
264 type filter hook output priority mangle; policy accept;
267 chain mangle_forward {
268 type filter hook forward priority mangle; policy accept;