Testing that `option log 1` enables rule logging and sets the rule name as log prefix. Also testing that setting settin `option log` to a non-boolean string uses that string verbatim as log prefix. -- Testcase -- {% include("./root/usr/share/firewall4/main.uc", { getenv: function(varname) { switch (varname) { case 'ACTION': return 'print'; } } }) %} -- End -- -- File uci/helpers.json -- {} -- End -- -- File uci/firewall.json -- { "zone": [ { "name": "wan" } ], "rule": [ { "proto": "any", "log": "1" }, { "name": "Explicit rule name", "proto": "any", "log": "1" }, { "proto": "any", "log": "Explicit prefix: " } ], "redirect": [ { "proto": "tcp", "src": "wan", "dest_ip": "10.0.0.2", "dest_port": "22", "log": "1" }, { "name": "Explicit redirect name", "proto": "tcp", "src": "wan", "dest_ip": "10.0.0.3", "dest_port": "23", "log": "1" }, { "proto": "tcp", "src": "wan", "dest_ip": "10.0.0.4", "dest_port": "24", "log": "Explicit prefix: " } ], "nat": [ { "src": "wan", "target": "MASQUERADE", "log": "1" }, { "name": "Explicit nat name", "src": "wan", "target": "MASQUERADE", "log": "1" }, { "src": "wan", "target": "MASQUERADE", "log": "Explicit log prefix: " } ] } -- End -- -- Expect stdout -- table inet fw4 flush table inet fw4 table inet fw4 { # # Defines # define wan_devices = { } define wan_subnets = { } # # User includes # include "/etc/nftables.d/*.nft" # # Filter rules # chain input { type filter hook input priority filter; policy drop; iifname "lo" accept comment "!fw4: Accept traffic from loopback" ct state established,related accept comment "!fw4: Allow inbound established and related flows" } chain forward { type filter hook forward priority filter; policy drop; ct state established,related accept comment "!fw4: Allow forwarded established and related flows" } chain output { type filter hook output priority filter; policy drop; oifname "lo" accept comment "!fw4: Accept traffic towards loopback" ct state established,related accept comment "!fw4: Allow outbound established and related flows" counter log prefix "@rule[0]: " comment "!fw4: @rule[0]" counter log prefix "Explicit rule name: " comment "!fw4: Explicit rule name" counter log prefix "Explicit prefix: " comment "!fw4: @rule[2]" } chain prerouting { type filter hook prerouting priority filter; policy accept; } 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_wan { ct status dnat accept comment "!fw4: Accept port redirections" jump drop_from_wan } chain output_wan { jump drop_to_wan } chain forward_wan { ct status dnat accept comment "!fw4: Accept port forwards" jump drop_to_wan } chain helper_wan { } chain drop_from_wan { } chain drop_to_wan { } # # NAT rules # chain dstnat { type nat hook prerouting priority dstnat; policy accept; } chain srcnat { type nat hook postrouting priority srcnat; policy accept; } chain dstnat_wan { meta nfproto ipv4 counter log prefix "@redirect[0]: " dnat 10.0.0.2:22 comment "!fw4: @redirect[0]" meta nfproto ipv4 counter log prefix "Explicit redirect name: " dnat 10.0.0.3:23 comment "!fw4: Explicit redirect name" meta nfproto ipv4 counter log prefix "Explicit prefix: " dnat 10.0.0.4:24 comment "!fw4: @redirect[2]" } chain srcnat_wan { meta nfproto ipv4 counter log prefix "@nat[0]: " masquerade comment "!fw4: @nat[0]" meta nfproto ipv4 counter log prefix "Explicit nat name: " masquerade comment "!fw4: Explicit nat name" meta nfproto ipv4 counter log prefix "Explicit log prefix: " masquerade comment "!fw4: @nat[2]" } # # 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; } chain mangle_postrouting { type filter hook postrouting priority mangle; policy accept; } chain mangle_input { type filter hook input priority mangle; policy accept; } chain mangle_output { type route hook output priority mangle; policy accept; } chain mangle_forward { type filter hook forward priority mangle; policy accept; } } -- End --