diff options
author | Christian Breunig <christian@breunig.cc> | 2023-08-26 14:59:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-26 14:59:10 +0200 |
commit | 75aa90cf2b234a34565d165697196ac9a304bb66 (patch) | |
tree | 8a1c07e17cec0333b71ed32c12f403953a762afe /data | |
parent | 3144b67f1b04e88f5ba928db2eee6f198be04a3a (diff) | |
parent | 2509a1ab84cdb6d9389b547f93b0904cf329e78a (diff) | |
download | vyos-1x-75aa90cf2b234a34565d165697196ac9a304bb66.tar.gz vyos-1x-75aa90cf2b234a34565d165697196ac9a304bb66.zip |
Merge pull request #2163 from sarthurdev/firewall_rpfilter
firewall: T3509: Add support for IPv6 reverse path filtering
Diffstat (limited to 'data')
-rw-r--r-- | data/templates/firewall/nftables-zone.j2 | 78 | ||||
-rw-r--r-- | data/templates/firewall/nftables.j2 | 14 | ||||
-rw-r--r-- | data/vyos-firewall-init.conf | 4 |
3 files changed, 18 insertions, 78 deletions
diff --git a/data/templates/firewall/nftables-zone.j2 b/data/templates/firewall/nftables-zone.j2 deleted file mode 100644 index 17ef5101d..000000000 --- a/data/templates/firewall/nftables-zone.j2 +++ /dev/null @@ -1,78 +0,0 @@ - -{% macro zone_chains(zone, state_policy=False, ipv6=False) %} -{% set fw_name = 'ipv6_name' if ipv6 else 'name' %} -{% set suffix = '6' if ipv6 else '' %} - chain VYOS_ZONE_FORWARD { - type filter hook forward priority 1; policy accept; -{% if state_policy %} - jump VYOS_STATE_POLICY{{ suffix }} -{% endif %} -{% for zone_name, zone_conf in zone.items() %} -{% if 'local_zone' not in zone_conf %} - oifname { {{ zone_conf.interface | join(',') }} } counter jump VZONE_{{ zone_name }} -{% endif %} -{% endfor %} - } - chain VYOS_ZONE_LOCAL { - type filter hook input priority 1; policy accept; -{% if state_policy %} - jump VYOS_STATE_POLICY{{ suffix }} -{% endif %} -{% for zone_name, zone_conf in zone.items() %} -{% if 'local_zone' in zone_conf %} - counter jump VZONE_{{ zone_name }}_IN -{% endif %} -{% endfor %} - } - chain VYOS_ZONE_OUTPUT { - type filter hook output priority 1; policy accept; -{% if state_policy %} - jump VYOS_STATE_POLICY{{ suffix }} -{% endif %} -{% for zone_name, zone_conf in zone.items() %} -{% if 'local_zone' in zone_conf %} - counter jump VZONE_{{ zone_name }}_OUT -{% endif %} -{% endfor %} - } -{% for zone_name, zone_conf in zone.items() %} -{% if zone_conf.local_zone is vyos_defined %} - chain VZONE_{{ zone_name }}_IN { - iifname lo counter return -{% if zone_conf.from is vyos_defined %} -{% for from_zone, from_conf in zone_conf.from.items() if from_conf.firewall[fw_name] is vyos_defined %} - iifname { {{ zone[from_zone].interface | join(",") }} } counter jump NAME{{ suffix }}_{{ from_conf.firewall[fw_name] }} - iifname { {{ zone[from_zone].interface | join(",") }} } counter return -{% endfor %} -{% endif %} - {{ zone_conf | nft_default_rule('zone_' + zone_name) }} - } - chain VZONE_{{ zone_name }}_OUT { - oifname lo counter return -{% if zone_conf.from_local is vyos_defined %} -{% for from_zone, from_conf in zone_conf.from_local.items() if from_conf.firewall[fw_name] is vyos_defined %} - oifname { {{ zone[from_zone].interface | join(",") }} } counter jump NAME{{ suffix }}_{{ from_conf.firewall[fw_name] }} - oifname { {{ zone[from_zone].interface | join(",") }} } counter return -{% endfor %} -{% endif %} - {{ zone_conf | nft_default_rule('zone_' + zone_name) }} - } -{% else %} - chain VZONE_{{ zone_name }} { - iifname { {{ zone_conf.interface | join(",") }} } counter {{ zone_conf | nft_intra_zone_action(ipv6) }} -{% if zone_conf.intra_zone_filtering is vyos_defined %} - iifname { {{ zone_conf.interface | join(",") }} } counter return -{% endif %} -{% if zone_conf.from is vyos_defined %} -{% for from_zone, from_conf in zone_conf.from.items() if from_conf.firewall[fw_name] is vyos_defined %} -{% if zone[from_zone].local_zone is not defined %} - iifname { {{ zone[from_zone].interface | join(",") }} } counter jump NAME{{ suffix }}_{{ from_conf.firewall[fw_name] }} - iifname { {{ zone[from_zone].interface | join(",") }} } counter return -{% endif %} -{% endfor %} -{% endif %} - {{ zone_conf | nft_default_rule('zone_' + zone_name) }} - } -{% endif %} -{% endfor %} -{% endmacro %} diff --git a/data/templates/firewall/nftables.j2 b/data/templates/firewall/nftables.j2 index 10cbc68cb..84af0449a 100644 --- a/data/templates/firewall/nftables.j2 +++ b/data/templates/firewall/nftables.j2 @@ -3,6 +3,20 @@ {% import 'firewall/nftables-defines.j2' as group_tmpl %} {% if first_install is not vyos_defined %} +delete table inet vyos_global_rpfilter +{% endif %} +table inet vyos_global_rpfilter { + chain PREROUTING { + type filter hook prerouting priority -300; policy accept; +{% if global_options.source_validation is vyos_defined('loose') %} + fib saddr oif 0 counter drop +{% elif global_options.source_validation is vyos_defined('strict') %} + fib saddr . iif oif 0 counter drop +{% endif %} + } +} + +{% if first_install is not vyos_defined %} delete table ip vyos_filter {% endif %} table ip vyos_filter { diff --git a/data/vyos-firewall-init.conf b/data/vyos-firewall-init.conf index 36d92fe93..ab25ab4bd 100644 --- a/data/vyos-firewall-init.conf +++ b/data/vyos-firewall-init.conf @@ -82,6 +82,10 @@ table ip6 raw { type filter hook forward priority -300; policy accept; } + chain vyos_rpfilter { + type filter hook prerouting priority -300; policy accept; + } + chain PREROUTING { type filter hook prerouting priority -300; policy accept; counter jump VYOS_CT_PREROUTING_HOOK |