summaryrefslogtreecommitdiff
path: root/src/conf_mode/firewall.py
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2023-08-27 12:33:15 +0200
committerGitHub <noreply@github.com>2023-08-27 12:33:15 +0200
commitd3edda22573fb9c9d1c469f14f5a3eec9ca512a5 (patch)
treec6118e7d1dc94b2963f69b7c504738320fb0a809 /src/conf_mode/firewall.py
parent904cbe448c578905c9af1d15059f2905c490e409 (diff)
parent6b5d3568b88fad9cda694c0cd8b82c1f16773b15 (diff)
downloadvyos-1x-d3edda22573fb9c9d1c469f14f5a3eec9ca512a5.tar.gz
vyos-1x-d3edda22573fb9c9d1c469f14f5a3eec9ca512a5.zip
Merge pull request #2176 from sarthurdev/T5080
firewall: T5080: Disable conntrack unless required by rules
Diffstat (limited to 'src/conf_mode/firewall.py')
-rwxr-xr-xsrc/conf_mode/firewall.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/conf_mode/firewall.py b/src/conf_mode/firewall.py
index c86d1b555..c3b1ee015 100755
--- a/src/conf_mode/firewall.py
+++ b/src/conf_mode/firewall.py
@@ -333,6 +333,17 @@ def generate(firewall):
if not os.path.exists(nftables_conf):
firewall['first_install'] = True
+ # Determine if conntrack is needed
+ firewall['ipv4_conntrack_action'] = 'return'
+ firewall['ipv6_conntrack_action'] = 'return'
+
+ for rules, path in dict_search_recursive(firewall, 'rule'):
+ if any(('state' in rule_conf or 'connection_status' in rule_conf) for rule_conf in rules.values()):
+ if path[0] == 'ipv4':
+ firewall['ipv4_conntrack_action'] = 'accept'
+ elif path[0] == 'ipv6':
+ firewall['ipv6_conntrack_action'] = 'accept'
+
render(nftables_conf, 'firewall/nftables.j2', firewall)
return None