summaryrefslogtreecommitdiff
path: root/data/templates/firewall/nftables-policy.tmpl
blob: 484b6f2032809c7ad44b53c8ffebcd65c8bcfa24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/sbin/nft -f

{% if cleanup_commands is defined %}
{%   for command in cleanup_commands %}
{{ command }}
{%   endfor %}
{% endif %}

include "/run/nftables_defines.conf"

table ip mangle {
{% if first_install is defined %}
    chain VYOS_PBR_PREROUTING {
        type filter hook prerouting priority -150; policy accept;
    }
    chain VYOS_PBR_POSTROUTING {
        type filter hook postrouting priority -150; policy accept;
    }
{% endif %}
{% if route is defined and route is not none -%}
{%   for route_text, conf in route.items() %}
    chain VYOS_PBR_{{ route_text }} {
{%     if conf.rule is defined %}
{%       for rule_id, rule_conf in conf.rule.items() if rule_conf.disable is not defined %}
        {{ rule_conf | nft_rule(route_text, rule_id, 'ip') }}
{%       endfor %}
{%     endif %}
{%     if conf.default_action is defined %}
        counter {{ conf.default_action | nft_action }} comment "{{ name_text }} default-action {{ conf.default_action }}"
{%     else %}
        counter return
{%     endif %}
    }
{%   endfor %}
{%- endif %}
}

table ip6 mangle {
{% if first_install is defined %}
    chain VYOS_PBR6_PREROUTING {
        type filter hook prerouting priority -150; policy accept;
    }
    chain VYOS_PBR6_POSTROUTING {
        type filter hook postrouting priority -150; policy accept;
    }
{% endif %}
{% if route6 is defined and route6 is not none %}
{%   for route_text, conf in route6.items() %}
    chain VYOS_PBR6_{{ route_text }} {
{%     if conf.rule is defined %}
{%       for rule_id, rule_conf in conf.rule.items() if rule_conf.disable is not defined %}
        {{ rule_conf | nft_rule(route_text, rule_id, 'ip6') }}
{%       endfor %}
{%     endif %}
{%     if conf.default_action is defined %}
        counter {{ conf.default_action | nft_action }} comment "{{ name_text }} default-action {{ conf.default_action }}"
{%     endif %}
    }
{%   endfor %}
{% endif %}
}