fff-babel: Make implementation runtime switchable

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 <fabian@blaese.de>
Acked-by: Christian Dresel <freifunk@dresel.systems>
This commit is contained in:
Fabian Bläse 2022-01-05 13:45:58 +01:00
parent 803e2746df
commit a43b37e9f6
7 changed files with 64 additions and 10 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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
}

View File

@ -0,0 +1,3 @@
/etc/init.d/babeld disable
exit 0

View File

@ -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
}

View File

@ -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 \

View File

@ -74,10 +74,12 @@ if [ -x /usr/bin/fastd ]; then
SYSTEM_DATA="$SYSTEM_DATA<fastd_version>$(/usr/bin/fastd -v | awk '{ print $2 }')</fastd_version>"
fi
if [ -x /usr/sbin/babeld ]; then
SYSTEM_DATA="$SYSTEM_DATA<babel_version>$(/usr/sbin/babeld -V 2>&1)</babel_version>"
elif [ -x /usr/sbin/bird ]; then
SYSTEM_DATA="$SYSTEM_DATA<babel_version>$(/usr/sbin/bird --version 2>&1 | sed "s/BIRD version /bird-/")</babel_version>"
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>$babel_version</babel_version>"
fi
fi
# example for /etc/openwrt_release: