From a43b37e9f61c3f2d5fb946bbe1250d127c9cb907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Bl=C3=A4se?= Date: Wed, 5 Jan 2022 13:45:58 +0100 Subject: [PATCH] fff-babel: Make implementation runtime switchable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some users might want to prefer one babel implementation over another for various reasons. Having to compile the firmware from scratch can be quite tedious in that case. Instead, make the babel implementation switchable at runtime. The implementation can be switched manually using the uci option `babelimpl.impl.impl`, which currently is not upgrade-safe. Signed-off-by: Fabian Bläse Acked-by: Christian Dresel --- src/packages/fff/fff-babel-bird2/Makefile | 1 - .../fff/{babeldaemon => babeldaemon/bird2} | 8 +++- .../fff-babel/files/lib/functions/fff/babel | 43 ++++++++++++++++++- .../files/etc/uci-defaults/30-disable-babeld | 3 ++ .../fff/{babeldaemon => babeldaemon/babeld} | 8 +++- src/packages/fff/fff-layer3/Makefile | 1 + .../usr/lib/nodewatcher.d/10-systemdata.sh | 10 +++-- 7 files changed, 64 insertions(+), 10 deletions(-) rename src/packages/fff/fff-babel-bird2/files/lib/functions/fff/{babeldaemon => babeldaemon/bird2} (89%) create mode 100644 src/packages/fff/fff-babeld/files/etc/uci-defaults/30-disable-babeld rename src/packages/fff/fff-babeld/files/lib/functions/fff/{babeldaemon => babeldaemon/babeld} (94%) diff --git a/src/packages/fff/fff-babel-bird2/Makefile b/src/packages/fff/fff-babel-bird2/Makefile index eecddf76..b0591ccc 100644 --- a/src/packages/fff/fff-babel-bird2/Makefile +++ b/src/packages/fff/fff-babel-bird2/Makefile @@ -12,7 +12,6 @@ define Package/fff-babel-bird2 URL:=https://www.freifunk-franken.de DEPENDS:=+bird2 +bird2c +owipcalc PROVIDES:=fff-babel-implementation - CONFLICTS:=fff-babeld endef define Package/fff-babel-bird2/description diff --git a/src/packages/fff/fff-babel-bird2/files/lib/functions/fff/babeldaemon b/src/packages/fff/fff-babel-bird2/files/lib/functions/fff/babeldaemon/bird2 similarity index 89% rename from src/packages/fff/fff-babel-bird2/files/lib/functions/fff/babeldaemon rename to src/packages/fff/fff-babel-bird2/files/lib/functions/fff/babeldaemon/bird2 index 5820aa6b..866478bd 100644 --- a/src/packages/fff/fff-babel-bird2/files/lib/functions/fff/babeldaemon +++ b/src/packages/fff/fff-babel-bird2/files/lib/functions/fff/babeldaemon/bird2 @@ -1,5 +1,9 @@ # SPDX-License-Identifier: GPL-3.0-only +babel_get_version() { + /usr/sbin/bird --version 2>&1 | sed "s/BIRD version /bird-/" +} + babel_add_interface() { [ "$#" -ne "4" ] && return 1 @@ -49,7 +53,7 @@ babel_remove_custom_redistribute_filters() { return 0 } -babel_apply() { +babel_apply_implementation() { # error output hidden because apply might be executed without a preceding configure step. if [ -d /tmp/bird/fff ]; then rm -rf /etc/bird/fff @@ -59,7 +63,7 @@ babel_apply() { return 0 } -babel_reload() { +babel_reload_implementation() { /etc/init.d/fff-bird reload } diff --git a/src/packages/fff/fff-babel/files/lib/functions/fff/babel b/src/packages/fff/fff-babel/files/lib/functions/fff/babel index 041c23da..a6fdf3b0 100644 --- a/src/packages/fff/fff-babel/files/lib/functions/fff/babel +++ b/src/packages/fff/fff-babel/files/lib/functions/fff/babel @@ -1,4 +1,8 @@ -. /lib/functions/fff/babeldaemon + +implementation=$(uci -q get babelimpl.impl.impl) +[ -z "$implementation" ] && implementation=babeld + +. /lib/functions/fff/babeldaemon/$implementation babel_add_iifrules() { [ "$#" -ne "1" ] && return 1 @@ -73,3 +77,40 @@ babel_add_peer6addr() { return 0 } + +babel_reload() { + # switch implementation temporarily + case $implementation in + bird2) + /etc/init.d/babeld stop 2>/dev/null + /etc/init.d/fff-bird start + ;; + babeld) + /etc/init.d/fff-bird stop 2>/dev/null + /etc/init.d/babeld start + ;; + esac + + # call implementation-specific reload commands + babel_reload_implementation + + return 0 +} + +babel_apply() { + # switch implementation persistently + case $implementation in + bird2) + /etc/init.d/babeld disable + /etc/init.d/fff-bird enable + ;; + babeld) + /etc/init.d/fff-bird disable + /etc/init.d/babeld enable + ;; + esac + + babel_apply_implementation + + return 0 +} diff --git a/src/packages/fff/fff-babeld/files/etc/uci-defaults/30-disable-babeld b/src/packages/fff/fff-babeld/files/etc/uci-defaults/30-disable-babeld new file mode 100644 index 00000000..e14dd4b9 --- /dev/null +++ b/src/packages/fff/fff-babeld/files/etc/uci-defaults/30-disable-babeld @@ -0,0 +1,3 @@ +/etc/init.d/babeld disable + +exit 0 diff --git a/src/packages/fff/fff-babeld/files/lib/functions/fff/babeldaemon b/src/packages/fff/fff-babeld/files/lib/functions/fff/babeldaemon/babeld similarity index 94% rename from src/packages/fff/fff-babeld/files/lib/functions/fff/babeldaemon rename to src/packages/fff/fff-babeld/files/lib/functions/fff/babeldaemon/babeld index c2c44768..e5427dae 100644 --- a/src/packages/fff/fff-babeld/files/lib/functions/fff/babeldaemon +++ b/src/packages/fff/fff-babeld/files/lib/functions/fff/babeldaemon/babeld @@ -1,5 +1,9 @@ # SPDX-License-Identifier: GPL-3.0-only +babel_get_version() { + /usr/sbin/babeld -V 2>&1 +} + babel_add_interface() { [ "$#" -ne "4" ] && return 1 @@ -86,11 +90,11 @@ babel_remove_custom_redistribute_filters() { return 0 } -babel_apply() { +babel_apply_implementation() { uci commit babeld } -babel_reload() { +babel_reload_implementation() { return 0 } diff --git a/src/packages/fff/fff-layer3/Makefile b/src/packages/fff/fff-layer3/Makefile index c5a174cb..16abaf41 100644 --- a/src/packages/fff/fff-layer3/Makefile +++ b/src/packages/fff/fff-layer3/Makefile @@ -13,6 +13,7 @@ define Package/fff-layer3 DEPENDS:=+fff-alfred-monitoring-proxy \ +fff-babel \ +fff-babeld \ + +fff-babel-bird2 \ +fff-boardname \ +fff-dhcp \ +fff-layer3-config \ diff --git a/src/packages/fff/fff-nodewatcher/files/usr/lib/nodewatcher.d/10-systemdata.sh b/src/packages/fff/fff-nodewatcher/files/usr/lib/nodewatcher.d/10-systemdata.sh index 34ba16c8..b0bb74a0 100755 --- a/src/packages/fff/fff-nodewatcher/files/usr/lib/nodewatcher.d/10-systemdata.sh +++ b/src/packages/fff/fff-nodewatcher/files/usr/lib/nodewatcher.d/10-systemdata.sh @@ -74,10 +74,12 @@ if [ -x /usr/bin/fastd ]; then SYSTEM_DATA="$SYSTEM_DATA$(/usr/bin/fastd -v | awk '{ print $2 }')" fi -if [ -x /usr/sbin/babeld ]; then - SYSTEM_DATA="$SYSTEM_DATA$(/usr/sbin/babeld -V 2>&1)" -elif [ -x /usr/sbin/bird ]; then - SYSTEM_DATA="$SYSTEM_DATA$(/usr/sbin/bird --version 2>&1 | sed "s/BIRD version /bird-/")" +if [ -e /lib/functions/fff/babel ]; then + . /lib/functions/fff/babel + babel_version=$(babel_get_version) + if [ $? -eq 0 ]; then + SYSTEM_DATA="$SYSTEM_DATA$babel_version" + fi fi # example for /etc/openwrt_release: