From 57e9ca6d06feb02e496d90e5d3f5237e4d9727f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Bl=C3=A4se?= Date: Mon, 15 Feb 2021 00:32:53 +0100 Subject: [PATCH 1/5] Add support for different babel implementations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/packages/fff/fff-babel/Makefile | 28 ++++++ .../files/etc/layer3.d/40-babel | 14 +-- .../files/etc/uci-defaults/26-babel-iproute | 0 .../etc/uci-defaults/27-babel-network-rules | 0 .../fff-babel/files/lib/functions/fff/babel | 75 ++++++++++++++++ src/packages/fff/fff-babeld/Makefile | 1 + .../lib/functions/fff/{babel => babeldaemon} | 86 +++---------------- src/packages/fff/fff-layer3/Makefile | 1 + src/packages/fff/fff-wireguard/Makefile | 2 +- .../files/etc/layer3.d/50-wireguard | 12 ++- 10 files changed, 136 insertions(+), 83 deletions(-) create mode 100644 src/packages/fff/fff-babel/Makefile rename src/packages/fff/{fff-babeld => fff-babel}/files/etc/layer3.d/40-babel (92%) rename src/packages/fff/{fff-babeld => fff-babel}/files/etc/uci-defaults/26-babel-iproute (100%) rename src/packages/fff/{fff-babeld => fff-babel}/files/etc/uci-defaults/27-babel-network-rules (100%) create mode 100644 src/packages/fff/fff-babel/files/lib/functions/fff/babel rename src/packages/fff/fff-babeld/files/lib/functions/fff/{babel => babeldaemon} (54%) diff --git a/src/packages/fff/fff-babel/Makefile b/src/packages/fff/fff-babel/Makefile new file mode 100644 index 00000000..abae858c --- /dev/null +++ b/src/packages/fff/fff-babel/Makefile @@ -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)) diff --git a/src/packages/fff/fff-babeld/files/etc/layer3.d/40-babel b/src/packages/fff/fff-babel/files/etc/layer3.d/40-babel similarity index 92% rename from src/packages/fff/fff-babeld/files/etc/layer3.d/40-babel rename to src/packages/fff/fff-babel/files/etc/layer3.d/40-babel index 04b17c91..735d01f4 100644 --- a/src/packages/fff/fff-babeld/files/etc/layer3.d/40-babel +++ b/src/packages/fff/fff-babel/files/etc/layer3.d/40-babel @@ -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 @@ -101,10 +101,14 @@ configure() { apply() { uci commit network - uci commit babeld + babel_apply +} + +reload() { + babel_reload } revert() { uci revert network - uci revert babeld + babel_revert } diff --git a/src/packages/fff/fff-babeld/files/etc/uci-defaults/26-babel-iproute b/src/packages/fff/fff-babel/files/etc/uci-defaults/26-babel-iproute similarity index 100% rename from src/packages/fff/fff-babeld/files/etc/uci-defaults/26-babel-iproute rename to src/packages/fff/fff-babel/files/etc/uci-defaults/26-babel-iproute diff --git a/src/packages/fff/fff-babeld/files/etc/uci-defaults/27-babel-network-rules b/src/packages/fff/fff-babel/files/etc/uci-defaults/27-babel-network-rules similarity index 100% rename from src/packages/fff/fff-babeld/files/etc/uci-defaults/27-babel-network-rules rename to src/packages/fff/fff-babel/files/etc/uci-defaults/27-babel-network-rules diff --git a/src/packages/fff/fff-babel/files/lib/functions/fff/babel b/src/packages/fff/fff-babel/files/lib/functions/fff/babel new file mode 100644 index 00000000..041c23da --- /dev/null +++ b/src/packages/fff/fff-babel/files/lib/functions/fff/babel @@ -0,0 +1,75 @@ +. /lib/functions/fff/babeldaemon + +babel_add_iifrules() { + [ "$#" -ne "1" ] && return 1 + + local name="$1" + local table='10' + local prio='31' + + uci set network.${name}_rule=rule + uci set network.${name}_rule.in="$name" + uci set network.${name}_rule.lookup="$table" + uci set network.${name}_rule.priority="$prio" + + uci set network.${name}_rule6=rule6 + uci set network.${name}_rule6.in="$name" + uci set network.${name}_rule6.lookup="$table" + uci set network.${name}_rule6.priority="$prio" + + return 0 +} + +babel_delete_iifrules() { + [ "$#" -ne "1" ] && return 1 + + local name="$1" + + uci -q del network.${name}_rule + uci -q del network.${name}_rule6 + + return 0 +} + +babel_add_peeraddr() { + [ "$#" -ne "1" ] && return 1 + + local option="$1" + + if peer_ip=$(uci -q get gateway.@gateway[0].peer_ip); then + uci add_list "$option"="$peer_ip" + elif router_ip=$(uci -q get gateway.meta.router_ip); then + # use router_ip if no peer_ip is set + ip=$router_ip + + # use only first ip + ip=${ip%% *} + + # remove CIDR mask + ip=${ip%%/*} + + uci add_list "$option"="$ip" + elif ipaddr=$(uci -q get gateway.@client[0].ipaddr); then + # use client interface address (without subnet) if no router_ip is set + uci add_list "$option"=${ipaddr%%/*} + else + echo "WARNING: No peer_ip, router_ip or client interface ipaddr set! IPv4 routing is not possible." + return 1 + fi + + return 0 +} + +babel_add_peer6addr() { + [ "$#" -ne "1" ] && return 1 + + local option="$1" + + if peer_ip6=$(uci -q get gateway.@gateway[0].peer_ip6); then + uci add_list "$option"="$peer_ip6" + else + return 1 + fi + + return 0 +} diff --git a/src/packages/fff/fff-babeld/Makefile b/src/packages/fff/fff-babeld/Makefile index 2231e205..e21f03e6 100644 --- a/src/packages/fff/fff-babeld/Makefile +++ b/src/packages/fff/fff-babeld/Makefile @@ -11,6 +11,7 @@ define Package/fff-babeld TITLE:=Freifunk-Franken babeld configuration example URL:=https://www.freifunk-franken.de DEPENDS:=+babeld + PROVIDES:=fff-babel-implementation endef define Package/fff-babeld/description diff --git a/src/packages/fff/fff-babeld/files/lib/functions/fff/babel b/src/packages/fff/fff-babeld/files/lib/functions/fff/babeldaemon similarity index 54% rename from src/packages/fff/fff-babeld/files/lib/functions/fff/babel rename to src/packages/fff/fff-babeld/files/lib/functions/fff/babeldaemon index fa4e7e9c..c2c44768 100644 --- a/src/packages/fff/fff-babeld/files/lib/functions/fff/babel +++ b/src/packages/fff/fff-babeld/files/lib/functions/fff/babeldaemon @@ -1,76 +1,4 @@ -babel_add_iifrules() { - [ "$#" -ne "1" ] && return 1 - - local name="$1" - local table='10' - local prio='31' - - uci set network.${name}_rule=rule - uci set network.${name}_rule.in="$name" - uci set network.${name}_rule.lookup="$table" - uci set network.${name}_rule.priority="$prio" - - uci set network.${name}_rule6=rule6 - uci set network.${name}_rule6.in="$name" - uci set network.${name}_rule6.lookup="$table" - uci set network.${name}_rule6.priority="$prio" - - return 0 -} - -babel_delete_iifrules() { - [ "$#" -ne "1" ] && return 1 - - local name="$1" - - uci -q del network.${name}_rule - uci -q del network.${name}_rule6 - - return 0 -} - -babel_add_peeraddr() { - [ "$#" -ne "1" ] && return 1 - - local option="$1" - - if peer_ip=$(uci -q get gateway.@gateway[0].peer_ip); then - uci add_list "$option"="$peer_ip" - elif router_ip=$(uci -q get gateway.meta.router_ip); then - # use router_ip if no peer_ip is set - ip=$router_ip - - # use only first ip - ip=${ip%% *} - - # remove CIDR mask - ip=${ip%%/*} - - uci add_list "$option"="$ip" - elif ipaddr=$(uci -q get gateway.@client[0].ipaddr); then - # use client interface address (without subnet) if no router_ip is set - uci add_list "$option"=${ipaddr%%/*} - else - echo "WARNING: No peer_ip, router_ip or client interface ipaddr set! IPv4 routing is not possible." - return 1 - fi - - return 0 -} - -babel_add_peer6addr() { - [ "$#" -ne "1" ] && return 1 - - local option="$1" - - if peer_ip6=$(uci -q get gateway.@gateway[0].peer_ip6); then - uci add_list "$option"="$peer_ip6" - else - return 1 - fi - - return 0 -} +# SPDX-License-Identifier: GPL-3.0-only babel_add_interface() { [ "$#" -ne "4" ] && return 1 @@ -157,3 +85,15 @@ babel_remove_custom_redistribute_filters() { return 0 } + +babel_apply() { + uci commit babeld +} + +babel_reload() { + return 0 +} + +babel_revert() { + uci revert babeld +} diff --git a/src/packages/fff/fff-layer3/Makefile b/src/packages/fff/fff-layer3/Makefile index 4d2e0b1d..c5a174cb 100644 --- a/src/packages/fff/fff-layer3/Makefile +++ b/src/packages/fff/fff-layer3/Makefile @@ -11,6 +11,7 @@ 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-boardname \ +fff-dhcp \ diff --git a/src/packages/fff/fff-wireguard/Makefile b/src/packages/fff/fff-wireguard/Makefile index 64ec4f50..f2b33f1c 100644 --- a/src/packages/fff/fff-wireguard/Makefile +++ b/src/packages/fff/fff-wireguard/Makefile @@ -14,7 +14,7 @@ define Package/fff-wireguard +kmod-wireguard \ +owipcalc \ +wireguard-tools \ - +fff-babeld \ + +fff-babel \ +fff-network endef diff --git a/src/packages/fff/fff-wireguard/files/etc/layer3.d/50-wireguard b/src/packages/fff/fff-wireguard/files/etc/layer3.d/50-wireguard index 910755b3..04f20692 100644 --- a/src/packages/fff/fff-wireguard/files/etc/layer3.d/50-wireguard +++ b/src/packages/fff/fff-wireguard/files/etc/layer3.d/50-wireguard @@ -31,7 +31,7 @@ configure() { fi } - config_load babeld + config_load network config_foreach remove_wgpeer interface @@ -128,7 +128,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 @@ -137,12 +137,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 } -- 2.39.2 From e9784dffff89bbc5ec20657ca9e1bcc758eba71d 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 2/5] Add bird2 as selectable babel implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- 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 | 117 ++++++++++++++++++ .../files/etc/uci-defaults/60-fff-bird-config | 5 + .../files/lib/functions/fff/babeldaemon | 63 ++++++++++ .../files/usr/lib/nodewatcher.d/80-bird2.sh | 14 +++ .../usr/lib/nodewatcher.d/10-systemdata.sh | 2 + 8 files changed, 233 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 bd496baa..6ad4b112 100755 --- a/buildscript +++ b/buildscript @@ -15,7 +15,7 @@ ROUTINGREV="10d3ffd8b30186b49538167bac1fa1bf9c88f860" 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..54ccda6f --- /dev/null +++ b/src/packages/fff/fff-babel-bird2/files/etc/bird-fff.conf @@ -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"; +}; 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..7689bea0 --- /dev/null +++ b/src/packages/fff/fff-babel-bird2/files/etc/uci-defaults/60-fff-bird-config @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-3.0-only + +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..a1740bfa --- /dev/null +++ b/src/packages/fff/fff-babel-bird2/files/lib/functions/fff/babeldaemon @@ -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() { + # 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..6fb79e8b --- /dev/null +++ b/src/packages/fff/fff-babel-bird2/files/usr/lib/nodewatcher.d/80-bird2.sh @@ -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 "%s%s%s", $1, $2, $3 }' + )" + +echo -n "$neighbours" + +exit 0 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 9b8a7d44..34ba16c8 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 @@ -76,6 +76,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: -- 2.39.2 From 4e7f394ba32a8891ae6d9cbe460420c2e9712b40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Bl=C3=A4se?= Date: Sun, 6 Mar 2022 11:14:37 +0100 Subject: [PATCH 3/5] 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 --- src/packages/fff/fff-babel-bird2/Makefile | 2 +- .../files/etc/bird-babel-include.conf | 1 - .../fff-babel-bird2/files/etc/bird-fff.conf | 8 +++- .../files/etc/bird/fff/nat-filter.conf | 0 .../fff-babel-bird2/files/etc/init.d/fff-bird | 45 +++++++++++++++++++ .../files/etc/uci-defaults/30-disable-bird2 | 4 ++ .../files/lib/functions/fff/babeldaemon | 41 +++++++++-------- .../files/usr/lib/nodewatcher.d/80-bird2.sh | 6 +++ 8 files changed, 86 insertions(+), 21 deletions(-) delete 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/nat-filter.conf create mode 100755 src/packages/fff/fff-babel-bird2/files/etc/init.d/fff-bird create mode 100644 src/packages/fff/fff-babel-bird2/files/etc/uci-defaults/30-disable-bird2 diff --git a/src/packages/fff/fff-babel-bird2/Makefile b/src/packages/fff/fff-babel-bird2/Makefile index 9c26462b..eecddf76 100644 --- a/src/packages/fff/fff-babel-bird2/Makefile +++ b/src/packages/fff/fff-babel-bird2/Makefile @@ -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 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 deleted file mode 100644 index 8f7f5bb4..00000000 --- a/src/packages/fff/fff-babel-bird2/files/etc/bird-babel-include.conf +++ /dev/null @@ -1 +0,0 @@ -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 index 54ccda6f..271dc3b2 100644 --- a/src/packages/fff/fff-babel-bird2/files/etc/bird-fff.conf +++ b/src/packages/fff/fff-babel-bird2/files/etc/bird-fff.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"; }; diff --git a/src/packages/fff/fff-babel-bird2/files/etc/bird/fff/nat-filter.conf b/src/packages/fff/fff-babel-bird2/files/etc/bird/fff/nat-filter.conf new file mode 100644 index 00000000..e69de29b diff --git a/src/packages/fff/fff-babel-bird2/files/etc/init.d/fff-bird b/src/packages/fff/fff-babel-bird2/files/etc/init.d/fff-bird new file mode 100755 index 00000000..a23f4a37 --- /dev/null +++ b/src/packages/fff/fff-babel-bird2/files/etc/init.d/fff-bird @@ -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 +} diff --git a/src/packages/fff/fff-babel-bird2/files/etc/uci-defaults/30-disable-bird2 b/src/packages/fff/fff-babel-bird2/files/etc/uci-defaults/30-disable-bird2 new file mode 100644 index 00000000..726c5f79 --- /dev/null +++ b/src/packages/fff/fff-babel-bird2/files/etc/uci-defaults/30-disable-bird2 @@ -0,0 +1,4 @@ +/etc/init.d/bird disable +rm -f /etc/init.d/bird + +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 index a1740bfa..5820aa6b 100644 --- a/src/packages/fff/fff-babel-bird2/files/lib/functions/fff/babeldaemon +++ b/src/packages/fff/fff-babel-bird2/files/lib/functions/fff/babeldaemon @@ -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 } 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 index 6fb79e8b..a7708eb9 100755 --- 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 @@ -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 "%s%s%s", $1, $2, $3 }' -- 2.39.2 From 9444aaa959481c05d478dacf3eed8bdbc36f34d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Bl=C3=A4se?= Date: Wed, 5 Jan 2022 13:45:58 +0100 Subject: [PATCH 4/5] fff-babel: Make implementation runtime switchable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/packages/fff/fff-babel-bird2/Makefile | 1 - .../fff/{babeldaemon => babeldaemon/bird2} | 4 +- .../fff-babel/files/lib/functions/fff/babel | 43 ++++++++++++++++++- .../files/etc/uci-defaults/30-disable-babeld | 3 ++ .../fff/{babeldaemon => babeldaemon/babeld} | 4 +- src/packages/fff/fff-layer3/Makefile | 1 + 6 files changed, 50 insertions(+), 6 deletions(-) rename src/packages/fff/fff-babel-bird2/files/lib/functions/fff/{babeldaemon => babeldaemon/bird2} (95%) create mode 100644 src/packages/fff/fff-babeld/files/etc/uci-defaults/30-disable-babeld rename src/packages/fff/fff-babeld/files/lib/functions/fff/{babeldaemon => babeldaemon/babeld} (96%) diff --git a/src/packages/fff/fff-babel-bird2/Makefile b/src/packages/fff/fff-babel-bird2/Makefile index eecddf76..b0591ccc 100644 --- a/src/packages/fff/fff-babel-bird2/Makefile +++ b/src/packages/fff/fff-babel-bird2/Makefile @@ -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 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/bird2 similarity index 95% rename from src/packages/fff/fff-babel-bird2/files/lib/functions/fff/babeldaemon rename to src/packages/fff/fff-babel-bird2/files/lib/functions/fff/babeldaemon/bird2 index 5820aa6b..83ac2726 100644 --- a/src/packages/fff/fff-babel-bird2/files/lib/functions/fff/babeldaemon +++ b/src/packages/fff/fff-babel-bird2/files/lib/functions/fff/babeldaemon/bird2 @@ -49,7 +49,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 +59,7 @@ babel_apply() { return 0 } -babel_reload() { +babel_reload_implementation() { /etc/init.d/fff-bird reload } diff --git a/src/packages/fff/fff-babel/files/lib/functions/fff/babel b/src/packages/fff/fff-babel/files/lib/functions/fff/babel index 041c23da..a6fdf3b0 100644 --- a/src/packages/fff/fff-babel/files/lib/functions/fff/babel +++ b/src/packages/fff/fff-babel/files/lib/functions/fff/babel @@ -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 +} diff --git a/src/packages/fff/fff-babeld/files/etc/uci-defaults/30-disable-babeld b/src/packages/fff/fff-babeld/files/etc/uci-defaults/30-disable-babeld new file mode 100644 index 00000000..e14dd4b9 --- /dev/null +++ b/src/packages/fff/fff-babeld/files/etc/uci-defaults/30-disable-babeld @@ -0,0 +1,3 @@ +/etc/init.d/babeld disable + +exit 0 diff --git a/src/packages/fff/fff-babeld/files/lib/functions/fff/babeldaemon b/src/packages/fff/fff-babeld/files/lib/functions/fff/babeldaemon/babeld similarity index 96% rename from src/packages/fff/fff-babeld/files/lib/functions/fff/babeldaemon rename to src/packages/fff/fff-babeld/files/lib/functions/fff/babeldaemon/babeld index c2c44768..75bc47b6 100644 --- a/src/packages/fff/fff-babeld/files/lib/functions/fff/babeldaemon +++ b/src/packages/fff/fff-babeld/files/lib/functions/fff/babeldaemon/babeld @@ -86,11 +86,11 @@ babel_remove_custom_redistribute_filters() { return 0 } -babel_apply() { +babel_apply_implementation() { uci commit babeld } -babel_reload() { +babel_reload_implementation() { return 0 } diff --git a/src/packages/fff/fff-layer3/Makefile b/src/packages/fff/fff-layer3/Makefile index c5a174cb..16abaf41 100644 --- a/src/packages/fff/fff-layer3/Makefile +++ b/src/packages/fff/fff-layer3/Makefile @@ -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 \ -- 2.39.2 From c2a6fc08e44e4a513bb4f7d93b25fa60d6caab4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Bl=C3=A4se?= Date: Sat, 19 Mar 2022 14:53:46 +0100 Subject: [PATCH 5/5] fixup: make babel version dependent on selected implementation --- .../files/lib/functions/fff/babeldaemon/bird2 | 4 ++++ .../files/lib/functions/fff/babeldaemon/babeld | 4 ++++ .../files/usr/lib/nodewatcher.d/10-systemdata.sh | 10 ++++++---- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/packages/fff/fff-babel-bird2/files/lib/functions/fff/babeldaemon/bird2 b/src/packages/fff/fff-babel-bird2/files/lib/functions/fff/babeldaemon/bird2 index 83ac2726..866478bd 100644 --- a/src/packages/fff/fff-babel-bird2/files/lib/functions/fff/babeldaemon/bird2 +++ b/src/packages/fff/fff-babel-bird2/files/lib/functions/fff/babeldaemon/bird2 @@ -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 diff --git a/src/packages/fff/fff-babeld/files/lib/functions/fff/babeldaemon/babeld b/src/packages/fff/fff-babeld/files/lib/functions/fff/babeldaemon/babeld index 75bc47b6..e5427dae 100644 --- a/src/packages/fff/fff-babeld/files/lib/functions/fff/babeldaemon/babeld +++ b/src/packages/fff/fff-babeld/files/lib/functions/fff/babeldaemon/babeld @@ -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 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 34ba16c8..b0bb74a0 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,10 +74,12 @@ if [ -x /usr/bin/fastd ]; then SYSTEM_DATA="$SYSTEM_DATA$(/usr/bin/fastd -v | awk '{ print $2 }')" 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-/")" +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" + fi fi # example for /etc/openwrt_release: -- 2.39.2