fff-babel: add configuration scripts

This adds a configuration script to allow configuration
of babel with configuregateway.

Signed-off-by: Fabian Bläse <fabian@blaese.de>
This commit is contained in:
Fabian Bläse 2019-05-12 15:48:48 +02:00
parent 95bfe752f0
commit 2f359a3e00
1 changed files with 115 additions and 0 deletions

View File

@ -0,0 +1,115 @@
. /lib/functions.sh
#load board specific properties
BOARD="$(uci get board.model.name)"
. /etc/network.$BOARD
configure() {
## babelpeer
# remove peers missing in gateway config
remove_babelpeer() {
local name="$1"
if ! echo $name | grep cfg > /dev/null; then # do not delete default interface
if ! uci -q get gateway.$name > /dev/null; then
# remove interface
uci -q del network.$name
# remove iif-rules
uci -q del network.${name}_rule
uci -q del network.${name}_rule6
# remove babel interface
uci -q del babeld.$name
fi
fi
}
config_load babeld
config_foreach remove_babelpeer interface
#add new peers
add_babelpeer() {
local name="$1"
local vlan
local type
# prohibit cfg* as name
if echo $name | grep cfg > /dev/null; then
echo "ERROR: name $name is invalid for babelpeer!"
exit 1
fi
# get iface
if vlan=$(uci -q get gateway.$name.vlan); then
iface="${SWITCHDEV}.$vlan"
elif iface=$(uci -q get gateway.$name.iface); then
iface="$iface"
else
echo "ERROR: No iface set for babelpeer $name!"
exit 1
fi
# get type
if type=$(uci -q get gateway.$name.type); then
type="$type"
else
type=wired
fi
# get rxcost
if rxcost=$(uci -q get gateway.$name.rxcost); then
rxcost="$rxcost"
else
rxcost=96
fi
# add interface
uci set network.$name=interface
uci set network.$name.proto=static
uci set network.$name.ifname=$iface
# add iif-rules
uci set network.${name}_rule=rule
uci set network.${name}_rule.in="$name"
uci set network.${name}_rule.lookup='10'
uci set network.${name}_rule.priority='31'
uci set network.${name}_rule6=rule6
uci set network.${name}_rule6.in="$name"
uci set network.${name}_rule6.lookup='10'
uci set network.${name}_rule6.priority='31'
# peer_ip
if peer_ip=$(uci -q get gateway.@gateway[0].peer_ip); then
uci set network.$name.ipaddr="$peer_ip"
elif ipaddr=$(uci -q get gateway.@client[0].ipaddr); then
# use ipaddr (without subnet) if no peer_ip set
uci set network.$name.ipaddr=$(echo $ipaddr | cut -d / -f1)
else
echo "FATAL: Neither peer_ip nor ipaddr set! No peering ipv4 set!"
exit 1
fi
# peer_ip6
if peer_ip6=$(uci -q get gateway.@gateway[0].peer_ip6); then
uci set network.$name.ip6addr="$peer_ip6"
fi
# add babel interface
uci set babeld.$name=interface
uci set babeld.$name.ifname=$iface
uci set babeld.$name.type=$type
uci set babeld.$name.rxcost=$rxcost
}
config_load gateway
config_foreach add_babelpeer babelpeer
}
apply() {
uci commit network
uci commit babeld
}
revert() {
uci revert network
uci revert babeld
}