From 8d0a7118c7b2bd22d574c9ecfad64d1945d4c6e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Bl=C3=A4se?= Date: Sun, 14 Feb 2021 23:49:58 +0100 Subject: [PATCH] Add bird babel implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabian Bläse --- buildscript | 2 +- src/packages/fff/fff-babel-bird2/Makefile | 30 +++++ .../files/etc/bird-babel-include.conf | 1 + .../fff-babel-bird2/files/etc/bird-fff.conf | 108 ++++++++++++++++++ .../files/etc/uci-defaults/60-fff-bird-config | 3 + .../files/lib/functions/fff/babeldaemon | 47 ++++++++ .../files/usr/lib/nodewatcher.d/80-bird2.sh | 13 +++ src/packages/fff/fff-layer3/Makefile | 1 + .../usr/lib/nodewatcher.d/10-systemdata.sh | 2 + 9 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 src/packages/fff/fff-babel-bird2/Makefile create mode 100644 src/packages/fff/fff-babel-bird2/files/etc/bird-babel-include.conf create mode 100644 src/packages/fff/fff-babel-bird2/files/etc/bird-fff.conf create mode 100644 src/packages/fff/fff-babel-bird2/files/etc/uci-defaults/60-fff-bird-config create mode 100644 src/packages/fff/fff-babel-bird2/files/lib/functions/fff/babeldaemon create mode 100755 src/packages/fff/fff-babel-bird2/files/usr/lib/nodewatcher.d/80-bird2.sh diff --git a/buildscript b/buildscript index 5fe57d91..56d85499 100755 --- a/buildscript +++ b/buildscript @@ -22,7 +22,7 @@ ROUTINGREV="02b4dbfcb7b8f8b566940847d22d5a6f229d2e66" 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" diff --git a/src/packages/fff/fff-babel-bird2/Makefile b/src/packages/fff/fff-babel-bird2/Makefile new file mode 100644 index 00000000..9c26462b --- /dev/null +++ b/src/packages/fff/fff-babel-bird2/Makefile @@ -0,0 +1,30 @@ +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 + CONFLICTS:=fff-babeld +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)) diff --git a/src/packages/fff/fff-babel-bird2/files/etc/bird-babel-include.conf b/src/packages/fff/fff-babel-bird2/files/etc/bird-babel-include.conf new file mode 100644 index 00000000..8f7f5bb4 --- /dev/null +++ b/src/packages/fff/fff-babel-bird2/files/etc/bird-babel-include.conf @@ -0,0 +1 @@ +include "/etc/bird-babel/*.conf"; diff --git a/src/packages/fff/fff-babel-bird2/files/etc/bird-fff.conf b/src/packages/fff/fff-babel-bird2/files/etc/bird-fff.conf new file mode 100644 index 00000000..56fc2f1f --- /dev/null +++ b/src/packages/fff/fff-babel-bird2/files/etc/bird-fff.conf @@ -0,0 +1,108 @@ +ipv4 table fff4; +ipv6 sadr table fff6; + +ipv4 table local4; +ipv6 sadr table local6; + +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 ~ 2000::/3 from ::/0 then { + accept; + } + reject; + }; + 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 { + accept; + } + reject; + }; + export all; + }; + 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; + }; + kernel table 10; + scan time 15; + learn yes; +} + +protocol babel { + randomize router id yes; + + ipv4 { + table fff4; + import filter { + accept; + }; + export all; + }; + + ipv6 sadr { + table fff6; + import filter { + accept; + }; + export filter { + accept; + }; + }; + + include "/etc/bird-babel-include.conf"; +}; diff --git a/src/packages/fff/fff-babel-bird2/files/etc/uci-defaults/60-fff-bird-config b/src/packages/fff/fff-babel-bird2/files/etc/uci-defaults/60-fff-bird-config new file mode 100644 index 00000000..ff58a7f5 --- /dev/null +++ b/src/packages/fff/fff-babel-bird2/files/etc/uci-defaults/60-fff-bird-config @@ -0,0 +1,3 @@ +mv /etc/bird-fff.conf /etc/bird.conf + +exit 0 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 new file mode 100644 index 00000000..095b9206 --- /dev/null +++ b/src/packages/fff/fff-babel-bird2/files/lib/functions/fff/babeldaemon @@ -0,0 +1,47 @@ +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() { + return 0 +} + +babel_add_redistribute_filter() { + return 0 +} + +babel_remove_custom_redistribute_filters() { + return 0 +} + +babel_apply() { + mv /tmp/bird-babel /etc/bird-babel +} + +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 +} + +babel_revert() { + rm -r /tmp/bird-babel +} diff --git a/src/packages/fff/fff-babel-bird2/files/usr/lib/nodewatcher.d/80-bird2.sh b/src/packages/fff/fff-babel-bird2/files/usr/lib/nodewatcher.d/80-bird2.sh new file mode 100755 index 00000000..e911c898 --- /dev/null +++ b/src/packages/fff/fff-babel-bird2/files/usr/lib/nodewatcher.d/80-bird2.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +set -e +set -o pipefail + +neighbours="$(birdc -r show babel neighbors | + tail -n +5 | + awk '{ printf "%s%s%s", $1, $2, $3 }' + )" + +echo -n "$neighbours" + +exit 0 diff --git a/src/packages/fff/fff-layer3/Makefile b/src/packages/fff/fff-layer3/Makefile index f4938a81..4b8b31c4 100644 --- a/src/packages/fff/fff-layer3/Makefile +++ b/src/packages/fff/fff-layer3/Makefile @@ -12,6 +12,7 @@ define Package/fff-layer3 URL:=https://www.freifunk-franken.de DEPENDS:=+fff-alfred-monitoring-proxy \ +fff-babel \ + +fff-babel-bird2 \ +fff-boardname \ +fff-dhcp \ +fff-layer3-config \ diff --git a/src/packages/fff/fff-nodewatcher/files/usr/lib/nodewatcher.d/10-systemdata.sh b/src/packages/fff/fff-nodewatcher/files/usr/lib/nodewatcher.d/10-systemdata.sh index c5e07e1d..f5647d0c 100755 --- a/src/packages/fff/fff-nodewatcher/files/usr/lib/nodewatcher.d/10-systemdata.sh +++ b/src/packages/fff/fff-nodewatcher/files/usr/lib/nodewatcher.d/10-systemdata.sh @@ -74,6 +74,8 @@ fi if [ -x /usr/sbin/babeld ]; then SYSTEM_DATA="$SYSTEM_DATA$(/usr/sbin/babeld -V 2>&1)" +elif [ -x /usr/sbin/bird ]; then + SYSTEM_DATA="$SYSTEM_DATA$(/usr/sbin/bird --version 2>&1 | sed "s/BIRD version /bird-/")" fi # example for /etc/openwrt_release: