From e07f6121cca2fde1689a61cb4150be0c47f88595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Bl=C3=A4se?= Date: Wed, 3 Mar 2021 19:01:50 +0100 Subject: [PATCH] fff-layer3-config: add router_ip option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For some purposes (e.g. SNAT, vxlan) it might be necessary to have an additional address just for the router which is not attached to any interfaces. Addresses like this are typically added to the loopback interface. The new options "router_ip" and "router_ip6" are added to the gateway config to allow the user to configure such addresses. It is possible to both specify the address with or without a subnet size. The default configuration contains the IPv4 loopback address (127.0.0.1/8) explicitly, but this is not necessary. These addresses are configured automatically, even if they are not present in the configuration, so they can safely be removed, if present. The filters of our routing daemon babeld are adjusted accordingly, so the newly added addresses are announced correctly. Signed-off-by: Fabian Bläse Reviewed-by: Christian Dresel Reviewed-by: Johannes Kimmel --- .../fff/fff-babeld/files/etc/config/babeld | 5 +++ .../fff-babeld/files/lib/functions/fff/babel | 7 +++-- .../files/etc/layer3.d/30-network-routerip | 31 +++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 src/packages/fff/fff-layer3-config/files/etc/layer3.d/30-network-routerip diff --git a/src/packages/fff/fff-babeld/files/etc/config/babeld b/src/packages/fff/fff-babeld/files/etc/config/babeld index 889602c6..a38744f1 100644 --- a/src/packages/fff/fff-babeld/files/etc/config/babeld +++ b/src/packages/fff/fff-babeld/files/etc/config/babeld @@ -21,6 +21,11 @@ config filter option local 'true' option ip 'fd43:5602:29bd::/48' +config filter + option type 'redistribute' + option local 'true' + option if 'lo' + config filter option type 'redistribute' option local 'true' diff --git a/src/packages/fff/fff-babeld/files/lib/functions/fff/babel b/src/packages/fff/fff-babeld/files/lib/functions/fff/babel index 3b2c7dac..09eda2b3 100644 --- a/src/packages/fff/fff-babeld/files/lib/functions/fff/babel +++ b/src/packages/fff/fff-babeld/files/lib/functions/fff/babel @@ -36,11 +36,14 @@ babel_add_peeraddr() { if peer_ip=$(uci -q get gateway.@gateway[0].peer_ip); then uci add_list "$option"="$peer_ip" + elif router_ip=$(uci -q get gateway.meta.router_ip); then + # use router_ip if no peer_ip is set + uci add_list "$option"="$router_ip" elif ipaddr=$(uci -q get gateway.@client[0].ipaddr); then - # use ipaddr (without subnet) if no peer_ip set + # use client interface address (without subnet) if no router_ip is set uci add_list "$option"=$(echo $ipaddr | cut -d / -f1) else - echo "WARNING: Neither peer_ip nor ipaddr set! IPv4 routing is not possible." + echo "WARNING: No peer_ip, router_ip or client interface ipaddr set! IPv4 routing is not possible." return 1 fi diff --git a/src/packages/fff/fff-layer3-config/files/etc/layer3.d/30-network-routerip b/src/packages/fff/fff-layer3-config/files/etc/layer3.d/30-network-routerip new file mode 100644 index 00000000..32412bf8 --- /dev/null +++ b/src/packages/fff/fff-layer3-config/files/etc/layer3.d/30-network-routerip @@ -0,0 +1,31 @@ +configure() { + local router_ip + local router_ip6 + + # clean old addresses + uci -q del network.loopback.ipaddr + uci -q del network.loopback.ip6addr + + # remove netmask entry that ships by default + uci -q del network.loopback.netmask + + # add router_ip + router_ip=$(uci -q get gateway.meta.router_ip) + for ip in $router_ip; do + uci -q add_list network.loopback.ipaddr="$ip" + done + + # add router_ip6 + router_ip6=$(uci -q get gateway.meta.router_ip6) + for ip in $router_ip6; do + uci -q add_list network.loopback.ip6addr="$ip" + done +} + +apply() { + uci commit network +} + +revert() { + uci revert network +}