Add bird2 as an alternative babel implementation #121
|
@ -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
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
include "/etc/bird-babel/*.conf";
|
|
@ -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";
|
||||
};
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
/etc/init.d/bird disable
|
||||
rm -f /etc/init.d/bird
|
||||
|
||||
exit 0
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 }'
|
||||
|
|
Loading…
Reference in New Issue