From 640bd524ebbb38000c3ebcd41b940f6a6b81d80c Mon Sep 17 00:00:00 2001 From: Simon Polack Date: Mon, 2 Dec 2024 23:00:47 +0100 Subject: [PATCH] Core/Gateway: Babel: add metrics for IPv4 --- .../templates/corerouter/bird.conf.j2 | 16 +++++++++++++++- roles/cfg_openwrt/templates/gateway/bird.conf.j2 | 15 ++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/roles/cfg_openwrt/templates/corerouter/bird.conf.j2 b/roles/cfg_openwrt/templates/corerouter/bird.conf.j2 index 664029de0..c34cf3832 100644 --- a/roles/cfg_openwrt/templates/corerouter/bird.conf.j2 +++ b/roles/cfg_openwrt/templates/corerouter/bird.conf.j2 @@ -51,7 +51,21 @@ protocol babel { }; }; ipv4 { - import all; + import filter { +{% for nw in networks | selectattr('role', 'equalto', 'mesh') %} + {# metrics for 2 GHz adhoc get a penalty over 5 GHz adhoc so 5 GHz is preferred #} + {% set default_mesh_metric = hostvars[inventory_hostname].get('mesh_metric_adhoc_' ~ nw.get('mesh_radio'), mesh_metric_default_in) %} + if ifname = "{{ libnetwork.getIfname(nw) }}" then { + babel_metric = babel_metric + {{ nw.get('mesh_metric', default_mesh_metric) }}; + } +{% endfor %} +{% for nw in networks | selectattr('role', 'equalto', 'tunnel') %} + if ifname = "{{ nw.get('ifname') }}" then { + babel_metric = babel_metric + {{ nw.get('mesh_metric', mesh_metric_tunnel_in) }}; + } +{% endfor %} + accept; + }; export where source = RTS_BABEL; # For now only advertise routes learned from babel }; diff --git a/roles/cfg_openwrt/templates/gateway/bird.conf.j2 b/roles/cfg_openwrt/templates/gateway/bird.conf.j2 index ddcce1038..2b352eef7 100644 --- a/roles/cfg_openwrt/templates/gateway/bird.conf.j2 +++ b/roles/cfg_openwrt/templates/gateway/bird.conf.j2 @@ -97,7 +97,20 @@ protocol babel babel_mesh { }; ipv4 { table v4_main; - import where ifname !~ "gre4-*"; # Drop IPv4 routes learned via GRE, which remains a rather dirty hack for IPv6 + import filter { + if ifname ~ "gre4-*" then reject; +{% for interface in mesh_links %} + if ifname = "{{ interface['ifname'] }}" then { + babel_metric = babel_metric + {{ interface.get('mesh_metric', mesh_metric_default_in) }}; + accept; + } +{% endfor %} + if ifname ~ "wg_*" then { + babel_metric = babel_metric + {{ mesh_metric_tunnel_in }}; + accept; + } + accept; + }; export where source = RTS_BABEL || net = 0.0.0.0/0; # Readvertise Babel routes and advertise default route };