Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

firewall: T7148: Bridge state-policy uses drop in place of reject #4357

Merged
merged 1 commit into from
Feb 22, 2025
Merged
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: 3 additions & 3 deletions data/templates/firewall/nftables.j2
Original file line number Diff line number Diff line change
Expand Up @@ -435,13 +435,13 @@ table bridge vyos_filter {
{% if global_options.state_policy is vyos_defined %}
chain VYOS_STATE_POLICY {
{% if global_options.state_policy.established is vyos_defined %}
{{ global_options.state_policy.established | nft_state_policy('established') }}
{{ global_options.state_policy.established | nft_state_policy('established', bridge=True) }}
{% endif %}
{% if global_options.state_policy.invalid is vyos_defined %}
{{ global_options.state_policy.invalid | nft_state_policy('invalid') }}
{{ global_options.state_policy.invalid | nft_state_policy('invalid', bridge=True) }}
{% endif %}
{% if global_options.state_policy.related is vyos_defined %}
{{ global_options.state_policy.related | nft_state_policy('related') }}
{{ global_options.state_policy.related | nft_state_policy('related', bridge=True) }}
{% endif %}
return
}
Expand Down
13 changes: 9 additions & 4 deletions python/vyos/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,12 +612,17 @@ def nft_default_rule(fw_conf, fw_name, family):
return " ".join(output)

@register_filter('nft_state_policy')
def nft_state_policy(conf, state):
def nft_state_policy(conf, state, bridge=False):
out = [f'ct state {state}']

action = conf['action'] if 'action' in conf else None

if bridge and action == 'reject':
action = 'drop' # T7148 - Bridge cannot use reject

if 'log' in conf:
log_state = state[:3].upper()
log_action = (conf['action'] if 'action' in conf else 'accept')[:1].upper()
log_action = (action if action else 'accept')[:1].upper()
out.append(f'log prefix "[STATE-POLICY-{log_state}-{log_action}]"')

if 'log_level' in conf:
Expand All @@ -626,8 +631,8 @@ def nft_state_policy(conf, state):

out.append('counter')

if 'action' in conf:
out.append(conf['action'])
if action:
out.append(action)

return " ".join(out)

Expand Down
7 changes: 7 additions & 0 deletions smoketest/scripts/cli/test_firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,13 @@ def test_ipv4_global_state(self):

self.verify_nftables(nftables_search, 'ip vyos_filter')

# T7148 - Ensure bridge rule reject -> drop
self.cli_set(['firewall', 'global-options', 'state-policy', 'invalid', 'action', 'reject'])
self.cli_commit()

self.verify_nftables([['ct state invalid', 'reject']], 'ip vyos_filter')
self.verify_nftables([['ct state invalid', 'drop']], 'bridge vyos_filter')

# Check conntrack is enabled from state-policy
self.verify_nftables_chain([['accept']], 'ip vyos_conntrack', 'FW_CONNTRACK')
self.verify_nftables_chain([['accept']], 'ip6 vyos_conntrack', 'FW_CONNTRACK')
Expand Down
Loading