forked from freifunk-franken/firmware
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> Acked-by: Christian Dresel <freifunk@dresel.systems>
This commit is contained in:
parent
128a748626
commit
71d137d4f1
28
src/packages/fff/fff-babel/Makefile
Normal file
28
src/packages/fff/fff-babel/Makefile
Normal 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))
|
|
@ -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
|
||||
}
|
75
src/packages/fff/fff-babel/files/lib/functions/fff/babel
Normal file
75
src/packages/fff/fff-babel/files/lib/functions/fff/babel
Normal file
|
@ -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
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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 \
|
||||
|
|
|
@ -14,7 +14,7 @@ define Package/fff-wireguard
|
|||
+kmod-wireguard \
|
||||
+owipcalc \
|
||||
+wireguard-tools \
|
||||
+fff-babeld \
|
||||
+fff-babel \
|
||||
+fff-network
|
||||
endef
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user