From 09eb030e3278346d68972371b9cf7b12fd167c66 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Thu, 27 Mar 2025 11:31:40 +0100 Subject: [PATCH] exit: determine uplink gateway address from interface address So we can actually drop the gateway custom field from NetBox interfaces. --- roles/exit/templates/frr.conf.j2 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/roles/exit/templates/frr.conf.j2 b/roles/exit/templates/frr.conf.j2 index 059a5ff..39c35e1 100644 --- a/roles/exit/templates/frr.conf.j2 +++ b/roles/exit/templates/frr.conf.j2 @@ -11,8 +11,16 @@ service integrated-vtysh-config # Route to the outside world. vrf outside - ip route 0.0.0.0/0 {{ (interfaces | selectattr('name', '==', iface_uplink) | first).custom_fields.gateway.address | ipaddr('address') }} {{ iface_uplink }} - ipv6 route ::/0 fe80::2 {{ iface_uplink }} +{# Add default routes for IPv4 and IPv6. Both are over link-local addresses. #} +{% set uplink = interfaces | selectattr('name', '==', iface_uplink) | first %} +{% for address in uplink.ip_addresses %} +{% set gateway = address.address | ipmath(1) %} +{% if address.family.value == 4 %} + ip route 0.0.0.0/0 {{ gateway }} {{ iface_uplink }} +{% else %} + ipv6 route ::/0 {{ gateway }} {{ iface_uplink }} +{% endif %} +{% endfor %} # Route installation into kernel fails (rarely) without this option. # It is not documented anywhere and appears to be a Cumulus extension.