From 9444aaa959481c05d478dacf3eed8bdbc36f34d7 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 --- src/packages/fff/fff-babel-bird2/Makefile | 1 - .../fff/{babeldaemon => babeldaemon/bird2} | 4 +- .../fff-babel/files/lib/functions/fff/babel | 43 ++++++++++++++++++- .../files/etc/uci-defaults/30-disable-babeld | 3 ++ .../fff/{babeldaemon => babeldaemon/babeld} | 4 +- src/packages/fff/fff-layer3/Makefile | 1 + 6 files changed, 50 insertions(+), 6 deletions(-) rename src/packages/fff/fff-babel-bird2/files/lib/functions/fff/{babeldaemon => babeldaemon/bird2} (95%) 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} (96%) 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 95% 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..83ac2726 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 @@ -49,7 +49,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 +59,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 96% 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..75bc47b6 100644 --- a/src/packages/fff/fff-babeld/files/lib/functions/fff/babeldaemon +++ b/src/packages/fff/fff-babeld/files/lib/functions/fff/babeldaemon/babeld @@ -86,11 +86,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 \