Compare commits

...

3 Commits

Author SHA1 Message Date
Fabian Bläse bdcaa1c285 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.

Currently, the implementation has to be switched manually in
/lib/functions/fff/babel, which is not upgrade-safe. Also, the previous
implementation is currently not restored after test-mode, so switching
implementations should not be done with test-mode.

Signed-off-by: Fabian Bläse <fabian@blaese.de>
2022-01-05 14:35:19 +01:00
Fabian Bläse b7829d789a Add bird2 as selectable babel implementation
Bird 2 has a few advantages over babeld. Especially the possiblity to
dynamically reload the configuration without restarting the daemon and
birds significant performance advantage make it an interesting
alternative to babeld for our firmware.

This adds the necessary implementation-specific fff-babel-bird2 package,
which allows to integrate bird2 into the fff firmware.

Signed-off-by: Fabian Bläse <fabian@blaese.de>
2022-01-05 14:33:31 +01:00
Fabian Bläse ccc4bf823c Add support for different babel implementations
To be able to swap out babeld for a different babel implementation in
the future, this splits all fff-specific configuration into a seperate
fff-babel package.

Implementation specific configuration is done in
/lib/functions/fff/babeldaemon, which is included with every selectable
babel implementation. It contains functions, which are called by the
fff-specific code, and therefore allows to configure the implementation
specific parts.

The babel implementation is provided by implementation-specific
fff-packages, which provide 'fff-babel-implementation'. At the moment,
only fff-babeld is supported for use as babel implementation.

Signed-off-by: Fabian Bläse <fabian@blaese.de>
2022-01-05 14:33:31 +01:00
20 changed files with 381 additions and 65 deletions

View File

@ -15,7 +15,7 @@ ROUTINGREV="2baff33918c089fd3744c7192f8ae7a29c47a8d7"
GLUONREV="12e41d0ff07ec54bbd67a31ab50d12ca04f2238c"
OPENWRT_PKGS="gpioctl-sysfs libugpio fastd haserl micrond mtr bmon"
ROUTING_PKGS="kmod-batman-adv batctl alfred babeld"
ROUTING_PKGS="kmod-batman-adv batctl alfred babeld bird2"
GLUON_PKGS="simple-tc uradvd"
FFF_VARIANTS="node layer3"

View File

@ -0,0 +1,29 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=fff-babel-bird2
PKG_RELEASE:=1
include $(INCLUDE_DIR)/package.mk
define Package/fff-babel-bird2
SECTION:=base
CATEGORY:=Freifunk
TITLE:=Freifunk-Franken babel-bird2
URL:=https://www.freifunk-franken.de
DEPENDS:=+bird2 +bird2c
PROVIDES:=fff-babel-implementation
endef
define Package/fff-babel-bird2/description
This is the Freifunk Franken Firmware babel-bird2 package.
endef
define Build/Compile
# nothing
endef
define Package/fff-babel-bird2/install
$(CP) ./files/* $(1)/
endef
$(eval $(call BuildPackage,fff-babel-bird2))

View File

@ -0,0 +1 @@
include "/etc/bird-babel/*.conf";

View File

@ -0,0 +1,117 @@
# router id is not required for babeld, but necessary for bird startup
router id 192.0.2.0;
ipv4 table fff4;
ipv6 sadr table fff6;
protocol device {
scan time 15;
}
# device routes for ipv4 peering address
protocol direct {
ipv4 {
table fff4;
import filter {
if (net ~ 10.50.0.0/16 || net ~ 10.83.0.0/16) && net.len = 32 then {
accept;
}
reject;
};
};
}
# device routes on loopback interface
protocol direct {
ipv4 {
table fff4;
import filter {
if net ~ 10.50.0.0/16 || net ~ 10.83.0.0/16 then {
accept;
}
reject;
};
};
ipv6 sadr {
table fff6;
import filter {
if net ~ fdff::/64 from ::/0 then {
reject;
}
# only import GUA + ULA addresses
if net !~ 2000::/3 from ::/0 || net !~ fc00::/7 from ::/0 then {
reject;
}
accept;
};
import keep filtered;
};
interface "lo";
}
# ipv6 kernel route interface
protocol kernel {
ipv6 sadr {
table fff6;
import filter {
# only import routes from kernel with proto static
if krt_source != 4 then {
reject;
}
if net ~ fdff::/64 from ::/0 then {
reject;
}
accept;
};
export all;
preference 200;
};
kernel table 10;
scan time 15;
learn yes;
}
# ipv4 kernel route interface
protocol kernel {
ipv4 {
table fff4;
import filter {
# only import routes from kernel with proto static
if krt_source = 4 then {
accept;
}
reject;
};
export all;
preference 200;
};
kernel table 10;
scan time 15;
learn yes;
}
protocol babel {
# required due to static configuration of global router id.
# also improves reconnect speed after restart.
randomize router id yes;
ipv4 {
table fff4;
import all;
export all;
};
ipv6 sadr {
table fff6;
import all;
export all;
};
include "/etc/bird-babel-include.conf";
};

View File

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

View File

@ -0,0 +1,5 @@
# SPDX-License-Identifier: GPL-3.0-only
mv /etc/bird-fff.conf /etc/bird.conf
exit 0

View File

@ -0,0 +1,63 @@
# SPDX-License-Identifier: GPL-3.0-only
babel_add_interface() {
[ "$#" -ne "4" ] && return 1
local name="$1"
local interface="$2"
local type="$3"
local rxcost="$4"
mkdir -p /tmp/bird-babel
echo "interface \"$interface\" { type $type; rxcost $rxcost; };" > /tmp/bird-babel/$name.conf
return 0
}
babel_delete_interface() {
[ "$#" -ne "1" ] && return 1
local name="$1"
# Removing peers from /etc is not necessary, as all peers are generated into /tmp on every configuration run,
# which completely overwrites existing peers in /etc in the apply step.
rm -f /tmp/bird-babel/$name.conf
return 0
}
babel_add_redistribute_filter() {
return 0
}
babel_remove_custom_redistribute_filters() {
return 0
}
babel_apply() {
# error output hidden because apply might be executed without a preceding configure step.
if [ -d /tmp/bird-babel ]; then
rm -rf /etc/bird-babel
mv /tmp/bird-babel /etc/bird-babel
fi
return 0
}
babel_reload_implementation() {
# Change include file path, so bird uses the correct configuration, depending on the configuration state:
# - If test mode is active (and /tmp/bird-babel exists), switch to the temporary (/tmp) configuration to be tested.
# - If new settings are applied or the old settings are restored after an unsuccessful test (and /tmp/bird-babel does not exist),
# switch back to the permanent configuration (/etc).
if [ -d /tmp/bird-babel ]; then
echo 'include "/tmp/bird-babel/*.conf";' > /etc/bird-babel-include.conf
else
echo 'include "/etc/bird-babel/*.conf";' > /etc/bird-babel-include.conf
fi
/etc/init.d/bird reload
}
babel_revert() {
rm -r /tmp/bird-babel
}

View File

@ -0,0 +1,14 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-3.0-only
set -e
set -o pipefail
neighbours="$(birdc -r show babel neighbors |
tail -n +5 |
awk '{ printf "<neighbour><ip>%s</ip><outgoing_interface>%s</outgoing_interface><link_cost>%s</link_cost></neighbour>", $1, $2, $3 }'
)"
echo -n "<babel_neighbours>$neighbours</babel_neighbours>"
exit 0

View File

@ -0,0 +1,28 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=fff-babel
PKG_RELEASE:=1
include $(INCLUDE_DIR)/package.mk
define Package/fff-babel
SECTION:=base
CATEGORY:=Freifunk
TITLE:=Freifunk-Franken babel
URL:=https://www.freifunk-franken.de
DEPENDS:=+fff-babel-implementation
endef
define Package/fff-babel/description
This is the Freifunk Franken Firmware babel package.
endef
define Build/Compile
# nothing
endef
define Package/fff-babel/install
$(CP) ./files/* $(1)/
endef
$(eval $(call BuildPackage,fff-babel))

View File

@ -26,7 +26,7 @@ configure() {
fi
}
config_load babeld
config_load network
config_foreach remove_babelpeer interface
#add new peers
@ -75,14 +75,14 @@ configure() {
babel_add_peer6addr "network.$prefixname.ip6addr"
# add babel interface
babel_add_interface "$prefixname" "$iface" "$type" "$rxcost" || { echo "Could not add babeld interface for babelpeer $name"; exit 1; }
babel_add_interface "$prefixname" "$iface" "$type" "$rxcost" || { echo "Could not add babel interface for babelpeer $name"; exit 1; }
}
config_load gateway
config_foreach add_babelpeer babelpeer
# configure babeld filters for custom ipv6 addresses
# configure babel filters for custom ipv6 addresses
## remove old filters
babel_remove_custom_redistribute_filters
@ -94,10 +94,14 @@ configure() {
apply() {
uci commit network
uci commit babeld
babel_apply
}
reload() {
babel_reload
}
revert() {
uci revert network
uci revert babeld
babel_revert
}

View File

@ -1,3 +1,7 @@
implementation=babeld
. /lib/functions/fff/babeldaemon/$implementation
babel_add_iifrules() {
[ "$#" -ne "1" ] && return 1
@ -61,61 +65,25 @@ babel_add_peer6addr() {
return 0
}
babel_add_interface() {
[ "$#" -ne "4" ] && return 1
babel_reload() {
# switch implementation
case $implementation in
bird2)
/etc/init.d/babeld stop 2>/dev/null
/etc/init.d/babeld disable
/etc/init.d/bird enable
/etc/init.d/bird start
;;
babeld)
/etc/init.d/bird stop 2>/dev/null
/etc/init.d/bird disable
/etc/init.d/babeld enable
/etc/init.d/babeld start
;;
esac
local name="$1"
local interface="$2"
local type="$3"
local rxcost="$4"
uci set babeld.$name=interface
uci set babeld.$name.ifname="$interface"
uci set babeld.$name.type="$type"
uci set babeld.$name.rxcost="$rxcost"
return 0
}
babel_delete_interface() {
[ "$#" -ne "1" ] && return 1
local name="$1"
uci -q del babeld.$name
return 0
}
babel_add_redistribute_filter() {
[ "$#" -ne "1" ] && return 1
local prefix="$1"
config=$(uci add babeld filter)
uci set babeld.$config.type='redistribute'
uci set babeld.$config.ip="$prefix"
uci set babeld.$config.addedbyautoconfig='true'
return 0
}
babel_remove_custom_redistribute_filters() {
[ "$#" -ne "0" ] && return 1
remove_filters() {
local name="$1"
# check if filter was added by configuregateway
if ! [ "$(uci -q get babeld.$name.addedbyautoconfig)" = 'true' ]; then
return
fi
uci -q del babeld.$name
}
config_load babeld
config_foreach remove_filters filter
# call implementation-specific reload commands
babel_reload_implementation
return 0
}

View File

@ -11,6 +11,7 @@ define Package/fff-babeld
TITLE:=Freifunk-Franken babeld configuration example
URL:=http://www.freifunk-franken.de
DEPENDS:=+babeld
PROVIDES:=fff-babel-implementation
endef
define Package/fff-babeld/description

View File

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

View File

@ -0,0 +1,72 @@
# SPDX-License-Identifier: GPL-3.0-only
babel_add_interface() {
[ "$#" -ne "4" ] && return 1
local name="$1"
local interface="$2"
local type="$3"
local rxcost="$4"
uci set babeld.$name=interface
uci set babeld.$name.ifname="$interface"
uci set babeld.$name.type="$type"
uci set babeld.$name.rxcost="$rxcost"
return 0
}
babel_delete_interface() {
[ "$#" -ne "1" ] && return 1
local name="$1"
uci -q del babeld.$name
return 0
}
babel_add_redistribute_filter() {
[ "$#" -ne "1" ] && return 1
local prefix="$1"
config=$(uci add babeld filter)
uci set babeld.$config.type='redistribute'
uci set babeld.$config.ip="$prefix"
uci set babeld.$config.addedbyautoconfig='true'
return 0
}
babel_remove_custom_redistribute_filters() {
[ "$#" -ne "0" ] && return 1
remove_filters() {
local name="$1"
# check if filter was added by configuregateway
if ! [ "$(uci -q get babeld.$name.addedbyautoconfig)" = 'true' ]; then
return
fi
uci -q del babeld.$name
}
config_load babeld
config_foreach remove_filters filter
return 0
}
babel_apply() {
uci commit babeld
}
babel_reload_implementation() {
return 0
}
babel_revert() {
uci revert babeld
}

View File

@ -11,7 +11,9 @@ define Package/fff-layer3
TITLE:=Freifunk-Franken gateway configuration
URL:=https://www.freifunk-franken.de
DEPENDS:=+fff-alfred-monitoring-proxy \
+fff-babel \
+fff-babeld \
+fff-babel-bird2 \
+fff-boardname \
+fff-dhcp \
+fff-layer3-config \

View File

@ -76,6 +76,8 @@ 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>"
fi
# example for /etc/openwrt_release:

View File

@ -14,7 +14,7 @@ define Package/fff-wireguard
+kmod-wireguard \
+owipcalc \
+wireguard-tools \
+fff-babeld \
+fff-babel \
+fff-network
endef

View File

@ -30,7 +30,7 @@ configure() {
fi
}
config_load babeld
config_load network
config_foreach remove_wgpeer interface
@ -127,7 +127,7 @@ configure() {
babel_add_iifrules "$prefixname" || { echo "ERROR: Could not add iif-rules for wgpeer $name"; exit 1; }
# add babel interface
babel_add_interface "$prefixname" "$prefixname" 'wired' "$rxcost" || { echo "ERROR: Could not add babeld interface for wgpeer $name"; exit 1; }
babel_add_interface "$prefixname" "$prefixname" 'wired' "$rxcost" || { echo "ERROR: Could not add babel interface for wgpeer $name"; exit 1; }
}
config_load gateway
@ -136,12 +136,16 @@ configure() {
apply() {
uci commit network
uci commit babeld
uci commit gateway
babel_apply
}
reload() {
babel_reload
}
revert() {
uci revert network
uci revert babeld
uci revert gateway
babel_revert
}