123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360 |
- Ensure that DSCP and MARK target rules end up in the appropriate chains,
- depending on the src and dest options.
- -- Testcase --
- {%
- include("./root/usr/share/firewall4/main.uc", {
- getenv: function(varname) {
- switch (varname) {
- case 'ACTION':
- return 'print';
- }
- }
- })
- %}
- -- End --
- -- File uci/helpers.json --
- {}
- -- End --
- -- File fs/open~_sys_class_net_eth0_flags.txt --
- 0x1103
- -- End --
- -- File fs/open~_sys_class_net_eth1_flags.txt --
- 0x1103
- -- End --
- -- File fs/open~_sys_class_net_eth2_flags.txt --
- 0x1103
- -- End --
- -- File fs/open~_sys_class_net_eth3_flags.txt --
- 0x1103
- -- End --
- -- File uci/firewall.json --
- {
- "zone": [
- {
- "name": "lan",
- "device": [ "eth0", "eth1" ]
- },
- {
- "name": "wan",
- "device": [ "eth2", "eth3" ]
- }
- ],
- "rule": [
- {
- ".description": "Source '*' and destination '*' should result in a forward rule",
- "name": "Mangle rule #1",
- "src": "*",
- "dest": "*",
- "target": "DSCP",
- "set_dscp": "1"
- },
- {
- ".description": "Source zone and destination zone should result in a forward rule",
- "name": "Mangle rule #2",
- "src": "lan",
- "dest": "wan",
- "target": "DSCP",
- "set_dscp": "1"
- },
- {
- ".description": "Any source zone and specific destination zone should result in a postrouting rule",
- "name": "Mangle rule #3",
- "src": "*",
- "dest": "wan",
- "target": "DSCP",
- "set_dscp": "1"
- },
- {
- ".description": "Specific source zone and any destination zone should result in a prerouting rule",
- "name": "Mangle rule #4",
- "src": "lan",
- "dest": "*",
- "target": "DSCP",
- "set_dscp": "1"
- },
- {
- ".description": "Specific source zone and no destination zone should result in an input rule",
- "name": "Mangle rule #5",
- "src": "lan",
- "target": "DSCP",
- "set_dscp": "1"
- },
- {
- ".description": "Any source zone and no destination zone should result in an input rule",
- "name": "Mangle rule #6",
- "src": "*",
- "target": "DSCP",
- "set_dscp": "1"
- },
- {
- ".description": "No source zone and no destination zone should result in an output rule",
- "name": "Mangle rule #7",
- "target": "DSCP",
- "set_dscp": "1"
- },
- {
- ".description": "No source zone and any destination zone should result in an output rule",
- "name": "Mangle rule #8",
- "dest": "*",
- "target": "DSCP",
- "set_dscp": "1"
- },
- {
- ".description": "No source zone and specific destination zone should result in an output rule",
- "name": "Mangle rule #9",
- "dest": "wan",
- "target": "DSCP",
- "set_dscp": "1"
- },
- {
- ".description": "Option device with no direction should override inbound ifname match",
- "name": "Mangle rule #10",
- "src": "*",
- "dest": "wan",
- "target": "DSCP",
- "set_dscp": "1",
- "device": "eth4"
- },
- {
- ".description": "Option device with direction 'in' should override inbound ifname match",
- "name": "Mangle rule #11",
- "src": "*",
- "dest": "wan",
- "target": "DSCP",
- "set_dscp": "1",
- "device": "eth4",
- "direction": "in"
- },
- {
- ".description": "Option device with direction 'out' should override outbound ifname match",
- "name": "Mangle rule #12",
- "src": "*",
- "dest": "wan",
- "target": "DSCP",
- "set_dscp": "1",
- "device": "eth5",
- "direction": "out"
- }
- ]
- }
- -- End --
- -- Expect stdout --
- table inet fw4
- flush table inet fw4
- table inet fw4 {
- #
- # Defines
- #
- define lan_devices = { "eth0", "eth1" }
- define lan_subnets = { }
- define wan_devices = { "eth2", "eth3" }
- define wan_subnets = { }
- #
- # User includes
- #
- include "/etc/nftables.d/*.nft"
- #
- # Filter rules
- #
- chain input {
- type filter hook input priority filter; policy drop;
- iif "lo" accept comment "!fw4: Accept traffic from loopback"
- ct state vmap { established : accept, related : accept } comment "!fw4: Handle inbound flows"
- iifname { "eth0", "eth1" } jump input_lan comment "!fw4: Handle lan IPv4/IPv6 input traffic"
- iifname { "eth2", "eth3" } jump input_wan comment "!fw4: Handle wan IPv4/IPv6 input traffic"
- }
- chain forward {
- type filter hook forward priority filter; policy drop;
- ct state vmap { established : accept, related : accept } comment "!fw4: Handle forwarded flows"
- iifname { "eth0", "eth1" } jump forward_lan comment "!fw4: Handle lan IPv4/IPv6 forward traffic"
- iifname { "eth2", "eth3" } jump forward_wan comment "!fw4: Handle wan IPv4/IPv6 forward traffic"
- }
- chain output {
- type filter hook output priority filter; policy drop;
- oif "lo" accept comment "!fw4: Accept traffic towards loopback"
- ct state vmap { established : accept, related : accept } comment "!fw4: Handle outbound flows"
- oifname { "eth0", "eth1" } jump output_lan comment "!fw4: Handle lan IPv4/IPv6 output traffic"
- oifname { "eth2", "eth3" } jump output_wan comment "!fw4: Handle wan IPv4/IPv6 output traffic"
- }
- chain prerouting {
- type filter hook prerouting priority filter; policy accept;
- iifname { "eth0", "eth1" } jump helper_lan comment "!fw4: Handle lan IPv4/IPv6 helper assignment"
- iifname { "eth2", "eth3" } jump helper_wan comment "!fw4: Handle wan IPv4/IPv6 helper assignment"
- }
- chain handle_reject {
- meta l4proto tcp reject with tcp reset comment "!fw4: Reject TCP traffic"
- reject with icmpx type port-unreachable comment "!fw4: Reject any other traffic"
- }
- chain input_lan {
- jump drop_from_lan
- }
- chain output_lan {
- jump drop_to_lan
- }
- chain forward_lan {
- jump drop_to_lan
- }
- chain helper_lan {
- }
- chain drop_from_lan {
- iifname { "eth0", "eth1" } counter drop comment "!fw4: drop lan IPv4/IPv6 traffic"
- }
- chain drop_to_lan {
- oifname { "eth0", "eth1" } counter drop comment "!fw4: drop lan IPv4/IPv6 traffic"
- }
- chain input_wan {
- jump drop_from_wan
- }
- chain output_wan {
- jump drop_to_wan
- }
- chain forward_wan {
- jump drop_to_wan
- }
- chain helper_wan {
- }
- chain drop_from_wan {
- iifname { "eth2", "eth3" } counter drop comment "!fw4: drop wan IPv4/IPv6 traffic"
- }
- chain drop_to_wan {
- oifname { "eth2", "eth3" } counter drop comment "!fw4: drop wan IPv4/IPv6 traffic"
- }
- #
- # NAT rules
- #
- chain dstnat {
- type nat hook prerouting priority dstnat; policy accept;
- }
- chain srcnat {
- type nat hook postrouting priority srcnat; policy accept;
- }
- #
- # Raw rules (notrack)
- #
- chain raw_prerouting {
- type filter hook prerouting priority raw; policy accept;
- }
- chain raw_output {
- type filter hook output priority raw; policy accept;
- }
- #
- # Mangle rules
- #
- chain mangle_prerouting {
- type filter hook prerouting priority mangle; policy accept;
- meta nfproto ipv4 meta l4proto tcp iifname { "eth0", "eth1" } counter ip dscp set 0x1 comment "!fw4: Mangle rule #4"
- meta nfproto ipv6 meta l4proto tcp iifname { "eth0", "eth1" } counter ip6 dscp set 0x1 comment "!fw4: Mangle rule #4"
- meta nfproto ipv4 meta l4proto udp iifname { "eth0", "eth1" } counter ip dscp set 0x1 comment "!fw4: Mangle rule #4"
- meta nfproto ipv6 meta l4proto udp iifname { "eth0", "eth1" } counter ip6 dscp set 0x1 comment "!fw4: Mangle rule #4"
- }
- chain mangle_postrouting {
- type filter hook postrouting priority mangle; policy accept;
- meta nfproto ipv4 meta l4proto tcp oifname { "eth2", "eth3" } counter ip dscp set 0x1 comment "!fw4: Mangle rule #3"
- meta nfproto ipv6 meta l4proto tcp oifname { "eth2", "eth3" } counter ip6 dscp set 0x1 comment "!fw4: Mangle rule #3"
- meta nfproto ipv4 meta l4proto udp oifname { "eth2", "eth3" } counter ip dscp set 0x1 comment "!fw4: Mangle rule #3"
- meta nfproto ipv6 meta l4proto udp oifname { "eth2", "eth3" } counter ip6 dscp set 0x1 comment "!fw4: Mangle rule #3"
- meta nfproto ipv4 meta l4proto tcp iifname "eth4" oifname { "eth2", "eth3" } counter ip dscp set 0x1 comment "!fw4: Mangle rule #10"
- meta nfproto ipv6 meta l4proto tcp iifname "eth4" oifname { "eth2", "eth3" } counter ip6 dscp set 0x1 comment "!fw4: Mangle rule #10"
- meta nfproto ipv4 meta l4proto udp iifname "eth4" oifname { "eth2", "eth3" } counter ip dscp set 0x1 comment "!fw4: Mangle rule #10"
- meta nfproto ipv6 meta l4proto udp iifname "eth4" oifname { "eth2", "eth3" } counter ip6 dscp set 0x1 comment "!fw4: Mangle rule #10"
- meta nfproto ipv4 meta l4proto tcp iifname "eth4" oifname { "eth2", "eth3" } counter ip dscp set 0x1 comment "!fw4: Mangle rule #11"
- meta nfproto ipv6 meta l4proto tcp iifname "eth4" oifname { "eth2", "eth3" } counter ip6 dscp set 0x1 comment "!fw4: Mangle rule #11"
- meta nfproto ipv4 meta l4proto udp iifname "eth4" oifname { "eth2", "eth3" } counter ip dscp set 0x1 comment "!fw4: Mangle rule #11"
- meta nfproto ipv6 meta l4proto udp iifname "eth4" oifname { "eth2", "eth3" } counter ip6 dscp set 0x1 comment "!fw4: Mangle rule #11"
- meta nfproto ipv4 meta l4proto tcp oifname "eth5" counter ip dscp set 0x1 comment "!fw4: Mangle rule #12"
- meta nfproto ipv6 meta l4proto tcp oifname "eth5" counter ip6 dscp set 0x1 comment "!fw4: Mangle rule #12"
- meta nfproto ipv4 meta l4proto udp oifname "eth5" counter ip dscp set 0x1 comment "!fw4: Mangle rule #12"
- meta nfproto ipv6 meta l4proto udp oifname "eth5" counter ip6 dscp set 0x1 comment "!fw4: Mangle rule #12"
- }
- chain mangle_input {
- type filter hook input priority mangle; policy accept;
- meta nfproto ipv4 meta l4proto tcp iifname { "eth0", "eth1" } counter ip dscp set 0x1 comment "!fw4: Mangle rule #5"
- meta nfproto ipv6 meta l4proto tcp iifname { "eth0", "eth1" } counter ip6 dscp set 0x1 comment "!fw4: Mangle rule #5"
- meta nfproto ipv4 meta l4proto udp iifname { "eth0", "eth1" } counter ip dscp set 0x1 comment "!fw4: Mangle rule #5"
- meta nfproto ipv6 meta l4proto udp iifname { "eth0", "eth1" } counter ip6 dscp set 0x1 comment "!fw4: Mangle rule #5"
- meta nfproto ipv4 meta l4proto tcp counter ip dscp set 0x1 comment "!fw4: Mangle rule #6"
- meta nfproto ipv6 meta l4proto tcp counter ip6 dscp set 0x1 comment "!fw4: Mangle rule #6"
- meta nfproto ipv4 meta l4proto udp counter ip dscp set 0x1 comment "!fw4: Mangle rule #6"
- meta nfproto ipv6 meta l4proto udp counter ip6 dscp set 0x1 comment "!fw4: Mangle rule #6"
- }
- chain mangle_output {
- type route hook output priority mangle; policy accept;
- meta nfproto ipv4 meta l4proto tcp counter ip dscp set 0x1 comment "!fw4: Mangle rule #7"
- meta nfproto ipv6 meta l4proto tcp counter ip6 dscp set 0x1 comment "!fw4: Mangle rule #7"
- meta nfproto ipv4 meta l4proto udp counter ip dscp set 0x1 comment "!fw4: Mangle rule #7"
- meta nfproto ipv6 meta l4proto udp counter ip6 dscp set 0x1 comment "!fw4: Mangle rule #7"
- meta nfproto ipv4 meta l4proto tcp counter ip dscp set 0x1 comment "!fw4: Mangle rule #8"
- meta nfproto ipv6 meta l4proto tcp counter ip6 dscp set 0x1 comment "!fw4: Mangle rule #8"
- meta nfproto ipv4 meta l4proto udp counter ip dscp set 0x1 comment "!fw4: Mangle rule #8"
- meta nfproto ipv6 meta l4proto udp counter ip6 dscp set 0x1 comment "!fw4: Mangle rule #8"
- meta nfproto ipv4 meta l4proto tcp oifname { "eth2", "eth3" } counter ip dscp set 0x1 comment "!fw4: Mangle rule #9"
- meta nfproto ipv6 meta l4proto tcp oifname { "eth2", "eth3" } counter ip6 dscp set 0x1 comment "!fw4: Mangle rule #9"
- meta nfproto ipv4 meta l4proto udp oifname { "eth2", "eth3" } counter ip dscp set 0x1 comment "!fw4: Mangle rule #9"
- meta nfproto ipv6 meta l4proto udp oifname { "eth2", "eth3" } counter ip6 dscp set 0x1 comment "!fw4: Mangle rule #9"
- }
- chain mangle_forward {
- type filter hook forward priority mangle; policy accept;
- meta nfproto ipv4 meta l4proto tcp counter ip dscp set 0x1 comment "!fw4: Mangle rule #1"
- meta nfproto ipv6 meta l4proto tcp counter ip6 dscp set 0x1 comment "!fw4: Mangle rule #1"
- meta nfproto ipv4 meta l4proto udp counter ip dscp set 0x1 comment "!fw4: Mangle rule #1"
- meta nfproto ipv6 meta l4proto udp counter ip6 dscp set 0x1 comment "!fw4: Mangle rule #1"
- meta nfproto ipv4 meta l4proto tcp iifname { "eth0", "eth1" } oifname { "eth2", "eth3" } counter ip dscp set 0x1 comment "!fw4: Mangle rule #2"
- meta nfproto ipv6 meta l4proto tcp iifname { "eth0", "eth1" } oifname { "eth2", "eth3" } counter ip6 dscp set 0x1 comment "!fw4: Mangle rule #2"
- meta nfproto ipv4 meta l4proto udp iifname { "eth0", "eth1" } oifname { "eth2", "eth3" } counter ip dscp set 0x1 comment "!fw4: Mangle rule #2"
- meta nfproto ipv6 meta l4proto udp iifname { "eth0", "eth1" } oifname { "eth2", "eth3" } counter ip6 dscp set 0x1 comment "!fw4: Mangle rule #2"
- }
- }
- -- End --
|