forked from freifunk-franken/firmware
117 lines
2.5 KiB
Plaintext
117 lines
2.5 KiB
Plaintext
|
|
implementation=$(uci -q get babelimpl.impl.impl)
|
|
[ -z "$implementation" ] && implementation=bird2
|
|
|
|
. /lib/functions/fff/babeldaemon/$implementation
|
|
|
|
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
|
|
}
|
|
|
|
babel_reload() {
|
|
# switch implementation temporarily
|
|
case $implementation in
|
|
bird2)
|
|
[ -f /etc/init.d/babeld ] && /etc/init.d/babeld stop 2>/dev/null
|
|
[ -f /etc/init.d/fff-bird ] && /etc/init.d/fff-bird start
|
|
;;
|
|
babeld)
|
|
[ -f /etc/init.d/fff-bird ] && /etc/init.d/fff-bird stop 2>/dev/null
|
|
[ -f /etc/init.d/babeld ] && /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)
|
|
[ -f /etc/init.d/babeld ] && /etc/init.d/babeld disable
|
|
[ -f /etc/init.d/fff-bird ] && /etc/init.d/fff-bird enable
|
|
;;
|
|
babeld)
|
|
[ -f /etc/init.d/fff-bird ] && /etc/init.d/fff-bird disable
|
|
[ -f /etc/init.d/babeld ] && /etc/init.d/babeld enable
|
|
;;
|
|
esac
|
|
|
|
babel_apply_implementation
|
|
|
|
return 0
|
|
}
|