summaryrefslogtreecommitdiff
path: root/data/templates/firewall/nftables-policy.j2
blob: 9e28899b066f46d9a0f49bf6098a64c69a6b3d15 (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
62
63
64
65
66
67
68
69
70
71
#!/usr/sbin/nft -f

{% import 'firewall/nftables-defines.j2' as group_tmpl %}

{% if first_install is not vyos_defined %}
delete table ip vyos_mangle
delete table ip6 vyos_mangle
{% endif %}
table ip vyos_mangle {
    chain VYOS_PBR_PREROUTING {
        type filter hook prerouting priority -150; policy accept;
{% if route is vyos_defined %}
{%     for route_text, conf in route.items() if conf.interface is vyos_defined %}
        iifname { {{ conf.interface | join(",") }} } counter jump VYOS_PBR_UD_{{ route_text }}
{%     endfor %}
{% endif %}
    }

    chain VYOS_PBR_POSTROUTING {
        type filter hook postrouting priority -150; policy accept;
    }

{% if route is vyos_defined %}
{%     for route_text, conf in route.items() %}
    chain VYOS_PBR_UD_{{ route_text }} {
{%         if conf.rule is vyos_defined %}
{%             for rule_id, rule_conf in conf.rule.items() if rule_conf.disable is not vyos_defined %}
        {{ rule_conf | nft_rule('route', route_text, rule_id, 'ip') }}
{%             endfor %}
{%         endif %}
{%         if conf.default_log is vyos_defined %}
        counter log prefix "[ipv4-{{ (route_text)[:19] }}-default]"
{%         endif %}
    }
{%     endfor %}
{% endif %}

{{ group_tmpl.groups(firewall_group, False, True) }}
}

table ip6 vyos_mangle {
    chain VYOS_PBR6_PREROUTING {
        type filter hook prerouting priority -150; policy accept;
{% if route6 is vyos_defined %}
{%     for route_text, conf in route6.items() if conf.interface is vyos_defined %}
        iifname { {{ ",".join(conf.interface) }} } counter jump VYOS_PBR6_UD_{{ route_text }}
{%     endfor %}
{% endif %}
    }

    chain VYOS_PBR6_POSTROUTING {
        type filter hook postrouting priority -150; policy accept;
    }

{% if route6 is vyos_defined %}
{%     for route_text, conf in route6.items() %}
    chain VYOS_PBR6_UD_{{ route_text }} {
{%         if conf.rule is vyos_defined %}
{%             for rule_id, rule_conf in conf.rule.items() if rule_conf.disable is not vyos_defined %}
        {{ rule_conf | nft_rule('route6', route_text, rule_id, 'ip6') }}
{%             endfor %}
{%         endif %}
{%         if conf.default_log is vyos_defined %}
        counter log prefix "[ipv6-{{ (route_text)[:19] }}-default]"
{%         endif %}
    }
{%     endfor %}
{% endif %}

{{ group_tmpl.groups(firewall_group, True, True) }}
}