fff-babeld: Move common babeld procedures into functions

Various things have to be done for every interface on
which babeld shall run.

Those procedures are moved into functions to reduce duplicate code.

Signed-off-by: Fabian Bläse <fabian@blaese.de>
Reviewed-by: Robert Langhammer <rlanghammer@web.de>
This commit is contained in:
Fabian Bläse 2019-06-27 19:48:25 +02:00
parent fbc7dab6de
commit 53ff6f631b
2 changed files with 97 additions and 30 deletions

View File

@ -1,4 +1,5 @@
. /lib/functions.sh . /lib/functions.sh
. /lib/functions/fff/babel
#load board specific properties #load board specific properties
BOARD="$(uci get board.model.name)" BOARD="$(uci get board.model.name)"
@ -14,10 +15,9 @@ configure() {
# remove interface # remove interface
uci -q del network.$name uci -q del network.$name
# remove iif-rules # remove iif-rules
uci -q del network.${name}_rule babel_delete_iifrules "$name"
uci -q del network.${name}_rule6
# remove babel interface # remove babel interface
uci -q del babeld.$name babel_delete_interface "$name"
fi fi
fi fi
} }
@ -67,37 +67,16 @@ configure() {
uci set network.$name.ifname=$iface uci set network.$name.ifname=$iface
# add iif-rules # add iif-rules
uci set network.${name}_rule=rule babel_add_iifrules "$name" || { echo "Could not add iif-rules for babelpeer $name"; exit 1; }
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 # peer_ip
if peer_ip=$(uci -q get gateway.@gateway[0].peer_ip); then uci -q delete "network.$name.ipaddr"
uci set network.$name.ipaddr="$peer_ip" uci -q delete "network.$name.ip6addr"
elif ipaddr=$(uci -q get gateway.@client[0].ipaddr); then babel_add_peeraddr "network.$name.ipaddr"
# use ipaddr (without subnet) if no peer_ip set babel_add_peer6addr "network.$name.ip6addr"
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 # add babel interface
uci set babeld.$name=interface babel_add_interface "$name" "$iface" "$type" "$rxcost" || { echo "Could not add babeld interface for babelpeer $name"; exit 1; }
uci set babeld.$name.ifname=$iface
uci set babeld.$name.type=$type
uci set babeld.$name.rxcost=$rxcost
} }
config_load gateway config_load gateway

View File

@ -0,0 +1,88 @@
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 ipaddr=$(uci -q get gateway.@client[0].ipaddr); then
# use ipaddr (without subnet) if no peer_ip set
uci add_list "$option"=$(echo $ipaddr | cut -d / -f1)
else
echo "FATAL: Neither peer_ip nor ipaddr set! No peering ipv4 set!"
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
}
babel_add_interface() {
[ "$#" -ne "4" ] && return 1
local name="$1"
local interface="$2"
local type="$3"
local rxcost="$4"
uci set babeld.$name=interface
uci set babeld.$name.ifname="$interface"
uci set babeld.$name.type="$type"
uci set babeld.$name.rxcost="$rxcost"
return 0
}
babel_delete_interface() {
[ "$#" -ne "1" ] && return 1
local name="$1"
uci -q del babeld.$name
return 0
}