network/roles/firewall/templates/mgmt.intf.j2
Timotej Lazar 2f662373e5 firewall: get mgmt gateway from custom field on prefix
Mainly so we can add IPv6 mgmt addresses and drop the gateway custom
field from NetBox interfaces.
2025-03-26 19:20:03 +01:00

32 lines
1 KiB
Django/Jinja

auto mgmt
iface mgmt
pre-up ip link add $IFACE type vrf table 100
up ip link set dev $IFACE up
post-down ip link del $IFACE
{% for iface in interfaces | selectattr('name', 'match', '^mgmt') %}
auto {{ iface.name }}
iface {{ iface.name }}
{% if iface.vrf %}
requires {{ iface.vrf.name }}
pre-up ip link set $IFACE master {{ iface.vrf.name }}
{% endif %}
pre-up sysctl -w net.ipv4.conf.$IFACE.forwarding=0
pre-up sysctl -w net.ipv6.conf.$IFACE.forwarding=0
{% if iface.mtu %}
mtu {{ iface.mtu }}
{% endif %}
{% for addr in iface.ip_addresses %}
address {{ addr.address }}
{% set subnet = addr.address | ipaddr('subnet') %}
{% set prefix_match = prefixes | selectattr('prefix', '==', subnet) %}
{% if prefix_match %}
{% set prefix = prefix_match | first %}
{% if prefix.custom_fields.gateway %}
up ip route add default via {{ prefix.custom_fields.gateway.address | ipaddr('address') }}{% if iface.vrf %} vrf {{ iface.vrf.name }}{% endif %}
{% endif %}
{% endif +%}
{% endfor %}
{% endfor %}