Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions root/usr/share/firewall4/templates/ruleset.uc
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,9 @@ table inet fw4 {
chain input {
type filter hook input priority filter; policy {{ fw4.input_policy(true) }};

iif "lo" accept comment "!fw4: Accept traffic from loopback"

{% fw4.includes('chain-prepend', 'input') %}
ct state vmap { established : accept, related : accept{% if (fw4.default_option("drop_invalid")): %}, invalid : drop{% endif %} } comment "!fw4: Handle inbound flows"
iif "lo" accept comment "!fw4: Accept traffic from loopback"
{% if (fw4.default_option("synflood_protect") && fw4.default_option("synflood_rate")): %}
tcp flags & (fin | syn | rst | ack) == syn jump syn_flood comment "!fw4: Rate limit TCP syn packets"
{% endif %}
Expand Down Expand Up @@ -154,10 +153,9 @@ table inet fw4 {
chain output {
type filter hook output priority filter; policy {{ fw4.output_policy(true) }};

oif "lo" accept comment "!fw4: Accept traffic towards loopback"

{% fw4.includes('chain-prepend', 'output') %}
ct state vmap { established : accept, related : accept{% if (fw4.default_option("drop_invalid")): %}, invalid : drop{% endif %} } comment "!fw4: Handle outbound flows"
oif "lo" accept comment "!fw4: Accept traffic towards loopback"
{% for (let rule in fw4.rules("output")): %}
{%+ include("rule.uc", { fw4, zone: null, rule }) %}
{% endfor %}
Expand Down
6 changes: 2 additions & 4 deletions tests/01_configuration/01_ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ table inet fw4 {
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"
iif "lo" accept comment "!fw4: Accept traffic from loopback"
tcp flags & (fin | syn | rst | ack) == syn jump syn_flood comment "!fw4: Rate limit TCP syn packets"
iifname "br-lan" jump input_lan comment "!fw4: Handle lan IPv4/IPv6 input traffic"
iifname "pppoe-wan" jump input_wan comment "!fw4: Handle wan IPv4/IPv6 input traffic"
Expand All @@ -132,9 +131,8 @@ table inet fw4 {
chain output {
type filter hook output priority filter; policy accept;

oif "lo" accept comment "!fw4: Accept traffic towards loopback"

ct state vmap { established : accept, related : accept } comment "!fw4: Handle outbound flows"
oif "lo" accept comment "!fw4: Accept traffic towards loopback"
meta l4proto tcp counter comment "!fw4: Test-Deprecated-Rule-Option"
oifname "br-lan" jump output_lan comment "!fw4: Handle lan IPv4/IPv6 output traffic"
oifname "pppoe-wan" jump output_wan comment "!fw4: Handle wan IPv4/IPv6 output traffic"
Expand Down
6 changes: 2 additions & 4 deletions tests/01_configuration/02_rule_order
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ table inet fw4 {
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"
iif "lo" accept comment "!fw4: Accept traffic from loopback"
iifname "br-lan" jump input_lan comment "!fw4: Handle lan IPv4/IPv6 input traffic"
iifname "pppoe-wan" jump input_wan comment "!fw4: Handle wan IPv4/IPv6 input traffic"
}
Expand All @@ -109,9 +108,8 @@ table inet fw4 {
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"
oif "lo" accept comment "!fw4: Accept traffic towards loopback"
oifname "br-lan" jump output_lan comment "!fw4: Handle lan IPv4/IPv6 output traffic"
oifname "pppoe-wan" jump output_wan comment "!fw4: Handle wan IPv4/IPv6 output traffic"
}
Expand Down
6 changes: 2 additions & 4 deletions tests/02_zones/01_policies
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ table inet fw4 {
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"
iif "lo" accept comment "!fw4: Accept traffic from loopback"
iifname "zone1" jump input_test1 comment "!fw4: Handle test1 IPv4/IPv6 input traffic"
iifname "zone2" jump input_test2 comment "!fw4: Handle test2 IPv4/IPv6 input traffic"
iifname "zone3" jump input_test3 comment "!fw4: Handle test3 IPv4/IPv6 input traffic"
Expand All @@ -113,9 +112,8 @@ table inet fw4 {
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"
oif "lo" accept comment "!fw4: Accept traffic towards loopback"
oifname "zone1" jump output_test1 comment "!fw4: Handle test1 IPv4/IPv6 output traffic"
oifname "zone2" jump output_test2 comment "!fw4: Handle test2 IPv4/IPv6 output traffic"
oifname "zone3" jump output_test3 comment "!fw4: Handle test3 IPv4/IPv6 output traffic"
Expand Down
6 changes: 2 additions & 4 deletions tests/02_zones/02_masq
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ table inet fw4 {
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"
iif "lo" accept comment "!fw4: Accept traffic from loopback"
iifname "zone1" jump input_test1 comment "!fw4: Handle test1 IPv4/IPv6 input traffic"
iifname "zone2" jump input_test2 comment "!fw4: Handle test2 IPv4/IPv6 input traffic"
iifname "zone3" jump input_test3 comment "!fw4: Handle test3 IPv4/IPv6 input traffic"
Expand All @@ -117,9 +116,8 @@ table inet fw4 {
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"
oif "lo" accept comment "!fw4: Accept traffic towards loopback"
oifname "zone1" jump output_test1 comment "!fw4: Handle test1 IPv4/IPv6 output traffic"
oifname "zone2" jump output_test2 comment "!fw4: Handle test2 IPv4/IPv6 output traffic"
oifname "zone3" jump output_test3 comment "!fw4: Handle test3 IPv4/IPv6 output traffic"
Expand Down
6 changes: 2 additions & 4 deletions tests/02_zones/03_masq_src_dest_restrictions
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@ table inet fw4 {
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"
iif "lo" accept comment "!fw4: Accept traffic from loopback"
iifname "zone1" jump input_test1 comment "!fw4: Handle test1 IPv4/IPv6 input traffic"
iifname "zone2" jump input_test2 comment "!fw4: Handle test2 IPv4/IPv6 input traffic"
}
Expand All @@ -138,9 +137,8 @@ table inet fw4 {
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"
oif "lo" accept comment "!fw4: Accept traffic towards loopback"
oifname "zone1" jump output_test1 comment "!fw4: Handle test1 IPv4/IPv6 output traffic"
oifname "zone2" jump output_test2 comment "!fw4: Handle test2 IPv4/IPv6 output traffic"
}
Expand Down
6 changes: 2 additions & 4 deletions tests/02_zones/04_masq_allow_invalid
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ table inet fw4 {
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"
iif "lo" accept comment "!fw4: Accept traffic from loopback"
iifname "zone1" jump input_test1 comment "!fw4: Handle test1 IPv4/IPv6 input traffic"
}

Expand All @@ -85,9 +84,8 @@ table inet fw4 {
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"
oif "lo" accept comment "!fw4: Accept traffic towards loopback"
oifname "zone1" jump output_test1 comment "!fw4: Handle test1 IPv4/IPv6 output traffic"
}

Expand Down
6 changes: 2 additions & 4 deletions tests/02_zones/04_wildcard_devices
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@ table inet fw4 {
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"
iif "lo" accept comment "!fw4: Accept traffic from loopback"
jump input_test1 comment "!fw4: Handle test1 IPv4/IPv6 input traffic"
iifname "/never/" jump input_test2 comment "!fw4: Handle test2 IPv4/IPv6 input traffic"
iifname "test*" jump input_test3 comment "!fw4: Handle test3 IPv4/IPv6 input traffic"
Expand Down Expand Up @@ -152,9 +151,8 @@ table inet fw4 {
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"
oif "lo" accept comment "!fw4: Accept traffic towards loopback"
jump output_test1 comment "!fw4: Handle test1 IPv4/IPv6 output traffic"
oifname "/never/" jump output_test2 comment "!fw4: Handle test2 IPv4/IPv6 output traffic"
oifname "test*" jump output_test3 comment "!fw4: Handle test3 IPv4/IPv6 output traffic"
Expand Down
6 changes: 2 additions & 4 deletions tests/02_zones/05_subnet_mask_matches
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ table inet fw4 {
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"
iif "lo" accept comment "!fw4: Accept traffic from loopback"
meta nfproto ipv6 ip6 saddr & ::ffff == ::1 ip6 saddr & ::ffff != ::2 jump input_test1 comment "!fw4: Handle test1 IPv6 input traffic"
meta nfproto ipv6 ip6 saddr != { ::7, ::8 } ip6 saddr & ::ffff == ::1 ip6 saddr & ::ffff != ::5 ip6 saddr & ::ffff != ::6 jump input_test2 comment "!fw4: Handle test2 IPv6 input traffic"
meta nfproto ipv6 ip6 saddr != { ::7, ::8 } ip6 saddr & ::ffff == ::2 ip6 saddr & ::ffff != ::5 ip6 saddr & ::ffff != ::6 jump input_test2 comment "!fw4: Handle test2 IPv6 input traffic"
Expand All @@ -101,9 +100,8 @@ table inet fw4 {
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"
oif "lo" accept comment "!fw4: Accept traffic towards loopback"
meta nfproto ipv6 ip6 daddr & ::ffff == ::1 ip6 daddr & ::ffff != ::2 jump output_test1 comment "!fw4: Handle test1 IPv6 output traffic"
meta nfproto ipv6 ip6 daddr != { ::7, ::8 } ip6 daddr & ::ffff == ::1 ip6 daddr & ::ffff != ::5 ip6 daddr & ::ffff != ::6 jump output_test2 comment "!fw4: Handle test2 IPv6 output traffic"
meta nfproto ipv6 ip6 daddr != { ::7, ::8 } ip6 daddr & ::ffff == ::2 ip6 daddr & ::ffff != ::5 ip6 daddr & ::ffff != ::6 jump output_test2 comment "!fw4: Handle test2 IPv6 output traffic"
Expand Down
6 changes: 2 additions & 4 deletions tests/02_zones/06_family_selections
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,8 @@ table inet fw4 {
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"
iif "lo" accept comment "!fw4: Accept traffic from loopback"
meta nfproto ipv4 ip saddr 10.0.0.0/8 jump input_test1 comment "!fw4: Handle test1 IPv4 input traffic"
meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 jump input_test2 comment "!fw4: Handle test2 IPv6 input traffic"
meta nfproto ipv6 ip6 saddr 2001:db8:1234::/64 jump input_test3 comment "!fw4: Handle test3 IPv6 input traffic"
Expand All @@ -160,9 +159,8 @@ table inet fw4 {
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"
oif "lo" accept comment "!fw4: Accept traffic towards loopback"
meta nfproto ipv4 ip daddr 10.0.0.0/8 jump output_test1 comment "!fw4: Handle test1 IPv4 output traffic"
meta nfproto ipv6 ip6 daddr 2001:db8:1234::/64 jump output_test2 comment "!fw4: Handle test2 IPv6 output traffic"
meta nfproto ipv6 ip6 daddr 2001:db8:1234::/64 jump output_test3 comment "!fw4: Handle test3 IPv6 output traffic"
Expand Down
6 changes: 2 additions & 4 deletions tests/02_zones/07_helpers
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,8 @@ table inet fw4 {
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"
iif "lo" accept comment "!fw4: Accept traffic from loopback"
iifname "zone1" jump input_test1 comment "!fw4: Handle test1 IPv4/IPv6 input traffic"
iifname "zone2" jump input_test2 comment "!fw4: Handle test2 IPv4/IPv6 input traffic"
iifname "zone3" jump input_test3 comment "!fw4: Handle test3 IPv4/IPv6 input traffic"
Expand All @@ -188,9 +187,8 @@ table inet fw4 {
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"
oif "lo" accept comment "!fw4: Accept traffic towards loopback"
oifname "zone1" jump output_test1 comment "!fw4: Handle test1 IPv4/IPv6 output traffic"
oifname "zone2" jump output_test2 comment "!fw4: Handle test2 IPv4/IPv6 output traffic"
oifname "zone3" jump output_test3 comment "!fw4: Handle test3 IPv4/IPv6 output traffic"
Expand Down
6 changes: 2 additions & 4 deletions tests/02_zones/08_log_limit
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,8 @@ table inet fw4 {
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"
iif "lo" accept comment "!fw4: Accept traffic from loopback"
tcp dport 1007 counter log prefix "@rule[6]: " comment "!fw4: @rule[6]"
tcp dport 1008 counter comment "!fw4: @rule[7]"
tcp dport 1009 limit rate 5/minute log prefix "@rule[12]: "
Expand All @@ -267,9 +266,8 @@ table inet fw4 {
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"
oif "lo" accept comment "!fw4: Accept traffic towards loopback"
oifname "br-lan" jump output_lan comment "!fw4: Handle lan IPv4/IPv6 output traffic"
meta nfproto ipv4 oifname "pppoe-wan" jump output_wan comment "!fw4: Handle wan IPv4 output traffic"
oifname "br-guest" jump output_guest comment "!fw4: Handle guest IPv4/IPv6 output traffic"
Expand Down
6 changes: 2 additions & 4 deletions tests/03_rules/01_direction
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ table inet fw4 {
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"
iif "lo" accept comment "!fw4: Accept traffic from loopback"
counter comment "!fw4: @rule[1]"
}

Expand All @@ -85,9 +84,8 @@ table inet fw4 {
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"
oif "lo" accept comment "!fw4: Accept traffic towards loopback"
counter comment "!fw4: @rule[0]"
counter comment "!fw4: @rule[2]"
}
Expand Down
6 changes: 2 additions & 4 deletions tests/03_rules/02_enabled
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ table inet fw4 {
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"
iif "lo" accept comment "!fw4: Accept traffic from loopback"
}

chain forward {
Expand All @@ -80,9 +79,8 @@ table inet fw4 {
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"
oif "lo" accept comment "!fw4: Accept traffic towards loopback"
counter comment "!fw4: Implicitly enabled"
counter comment "!fw4: Explicitly enabled"
}
Expand Down
6 changes: 2 additions & 4 deletions tests/03_rules/03_constraints
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ table inet fw4 {
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"
iif "lo" accept comment "!fw4: Accept traffic from loopback"
}

chain forward {
Expand All @@ -119,9 +118,8 @@ table inet fw4 {
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"
oif "lo" accept comment "!fw4: Accept traffic towards loopback"
meta nfproto ipv4 ip dscp 0x0 counter comment "!fw4: DSCP match rule #1"
meta nfproto ipv6 ip6 dscp 0x0 counter comment "!fw4: DSCP match rule #1"
}
Expand Down
6 changes: 2 additions & 4 deletions tests/03_rules/04_icmp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ table inet fw4 {
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"
iif "lo" accept comment "!fw4: Accept traffic from loopback"
}

chain forward {
Expand All @@ -89,9 +88,8 @@ table inet fw4 {
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"
oif "lo" accept comment "!fw4: Accept traffic towards loopback"
meta l4proto { "icmp", "ipv6-icmp" } counter comment "!fw4: ICMP rule #1"
meta nfproto ipv6 meta l4proto ipv6-icmp counter comment "!fw4: ICMP rule #2"
meta nfproto ipv6 meta l4proto ipv6-icmp counter comment "!fw4: ICMP rule #3"
Expand Down
6 changes: 2 additions & 4 deletions tests/03_rules/05_mangle
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,8 @@ table inet fw4 {
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"
iif "lo" accept comment "!fw4: Accept traffic from loopback"
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"
}
Expand All @@ -194,9 +193,8 @@ table inet fw4 {
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"
oif "lo" accept comment "!fw4: Accept traffic towards loopback"
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"
}
Expand Down
Loading