bird2-fixup

- refine configure/test/apply mechanics
	- move dynamic includes to /tmp -> not preserved during reboot
	- add custom bird procd init.d script to generate dynamic includes
		-> use /tmp/bird/fff if existent (test-mode), /etc/bird/fff otherwise
- move dynamic bird2 configs to /{tmp,etc}/bird/fff
- Fix nodewatcher failing when bird is not running
This commit is contained in:
Fabian Bläse 2022-03-06 11:14:37 +01:00
parent e9784dffff
commit 4e7f394ba3
8 changed files with 86 additions and 21 deletions

View File

@ -10,7 +10,7 @@ define Package/fff-babel-bird2
CATEGORY:=Freifunk
TITLE:=Freifunk-Franken babel-bird2
URL:=https://www.freifunk-franken.de
DEPENDS:=+bird2 +bird2c
DEPENDS:=+bird2 +bird2c +owipcalc
PROVIDES:=fff-babel-implementation
CONFLICTS:=fff-babeld
endef

View File

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

View File

@ -13,6 +13,8 @@ protocol direct {
ipv4 {
table fff4;
import filter {
include "/tmp/bird/include/nat-filter.conf";
if (net ~ 10.50.0.0/16 || net ~ 10.83.0.0/16) && net.len = 32 then {
accept;
}
@ -26,6 +28,8 @@ protocol direct {
ipv4 {
table fff4;
import filter {
include "/tmp/bird/include/nat-filter.conf";
if net ~ 10.50.0.0/16 || net ~ 10.83.0.0/16 then {
accept;
}
@ -82,6 +86,8 @@ protocol kernel {
ipv4 {
table fff4;
import filter {
include "/tmp/bird/include/nat-filter.conf";
# only import routes from kernel with proto static
if krt_source = 4 then {
accept;
@ -113,5 +119,5 @@ protocol babel {
export all;
};
include "/etc/bird-babel-include.conf";
include "/tmp/bird/include/babelpeers.conf";
};

View File

@ -0,0 +1,45 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2010-2017 OpenWrt.org
USE_PROCD=1
START=70
BIRD_BIN="/usr/sbin/bird"
BIRD_CONF="/etc/bird.conf"
BIRD_PID_FILE="/var/run/bird.pid"
start_service() {
mkdir -p /var/run
set_include_path
procd_open_instance
procd_set_param command $BIRD_BIN -f -c $BIRD_CONF -P $BIRD_PID_FILE
procd_set_param file "$BIRD_CONF"
procd_set_param stdout 1
procd_set_param stderr 1
procd_set_param respawn
procd_close_instance
}
reload_service() {
set_include_path
procd_send_signal fff-bird
}
set_include_path() {
# Change include file path, so bird uses the correct configuration, depending on the configuration state:
# - If test mode is active (and /tmp/bird/fff exists), switch to the temporary configuration to be tested.
# - If new settings are applied or the old settings are restored after an unsuccessful test (and /tmp/bird/fff does not exist),
# switch back to the permanent configuration (/etc/bird/fff).
mkdir -p /tmp/bird/include
if [ -d /tmp/bird/fff ]; then
echo 'include "/tmp/bird/fff/babelpeers/*.conf";' > /tmp/bird/include/babelpeers.conf
echo 'include "/tmp/bird/fff/nat-filter.conf";' > /tmp/bird/include/nat-filter.conf
else
echo 'include "/etc/bird/fff/babelpeers/*.conf";' > /tmp/bird/include/babelpeers.conf
echo 'include "/etc/bird/fff/nat-filter.conf";' > /tmp/bird/include/nat-filter.conf
fi
}

View File

@ -0,0 +1,4 @@
/etc/init.d/bird disable
rm -f /etc/init.d/bird
exit 0

View File

@ -8,8 +8,8 @@ babel_add_interface() {
local type="$3"
local rxcost="$4"
mkdir -p /tmp/bird-babel
echo "interface \"$interface\" { type $type; rxcost $rxcost; };" > /tmp/bird-babel/$name.conf
mkdir -p /tmp/bird/fff/babelpeers
echo "interface \"$interface\" { type $type; rxcost $rxcost; };" > /tmp/bird/fff/babelpeers/$name.conf
return 0
}
@ -21,7 +21,7 @@ babel_delete_interface() {
# 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
rm -f /tmp/bird/fff/babelpeers/$name.conf
return 0
}
@ -30,34 +30,39 @@ babel_add_redistribute_filter() {
return 0
}
babel_add_private_prefix_filter() {
[ "$#" -ne "1" ] && return 1
local prefix="$1"
prefix=$(owipcalc "$prefix" network prefix "$prefix")
mkdir -p /tmp/bird/fff
echo "if net ~ $prefix then reject;" > /tmp/bird/fff/nat-filter.conf
return 0
}
babel_remove_custom_redistribute_filters() {
mkdir -p /tmp/bird/fff
> /tmp/bird/fff/nat-filter.conf
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
if [ -d /tmp/bird/fff ]; then
rm -rf /etc/bird/fff
mv /tmp/bird/fff /etc/bird/fff
fi
return 0
}
babel_reload() {
# 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
/etc/init.d/fff-bird reload
}
babel_revert() {
rm -r /tmp/bird-babel
rm -r /tmp/bird/fff
}

View File

@ -4,6 +4,12 @@
set -e
set -o pipefail
if ! birdc show status >/dev/null 2>&1; then
# bird daemon not running or unavailable. exit.
exit 0
fi
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 }'