forked from freifunk-franken/firmware
Fabian Bläse
a43b37e9f6
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 <fabian@blaese.de> Acked-by: Christian Dresel <freifunk@dresel.systems>
104 lines
1.9 KiB
Plaintext
104 lines
1.9 KiB
Plaintext
# SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
babel_get_version() {
|
|
/usr/sbin/babeld -V 2>&1
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
babel_add_redistribute_filter() {
|
|
[ "$#" -ne "1" ] && return 1
|
|
|
|
local prefix="$1"
|
|
|
|
config=$(uci add babeld filter)
|
|
uci set babeld.$config.type='redistribute'
|
|
uci set babeld.$config.ip="$prefix"
|
|
uci set babeld.$config.addedbyautoconfig='true'
|
|
|
|
return 0
|
|
}
|
|
|
|
babel_add_private_prefix_filter() {
|
|
[ "$#" -ne "1" ] && return 1
|
|
|
|
local prefix="$1"
|
|
|
|
config=$(uci add babeld filter)
|
|
uci set babeld.$config.type='redistribute'
|
|
uci set babeld.$config.ip="$prefix"
|
|
uci set babeld.$config.addedbyautoconfig='true'
|
|
uci set babeld.$config.action='deny'
|
|
|
|
# move to top, so filter rule has precedence over all other rules
|
|
uci reorder babeld.$config=0
|
|
|
|
config=$(uci add babeld filter)
|
|
uci set babeld.$config.type='redistribute'
|
|
uci set babeld.$config.ip="$prefix"
|
|
uci set babeld.$config.addedbyautoconfig='true'
|
|
uci set babeld.$config.local='true'
|
|
uci set babeld.$config.action='deny'
|
|
|
|
# move to top, so filter rule has precedence over all other rules
|
|
uci reorder babeld.$config=0
|
|
|
|
return 0
|
|
}
|
|
|
|
babel_remove_custom_redistribute_filters() {
|
|
[ "$#" -ne "0" ] && return 1
|
|
|
|
remove_filters() {
|
|
local name="$1"
|
|
|
|
# check if filter was added by configuregateway
|
|
if ! [ "$(uci -q get babeld.$name.addedbyautoconfig)" = 'true' ]; then
|
|
return
|
|
fi
|
|
|
|
uci -q del babeld.$name
|
|
}
|
|
|
|
config_load babeld
|
|
config_foreach remove_filters filter
|
|
|
|
return 0
|
|
}
|
|
|
|
babel_apply_implementation() {
|
|
uci commit babeld
|
|
}
|
|
|
|
babel_reload_implementation() {
|
|
return 0
|
|
}
|
|
|
|
babel_revert() {
|
|
uci revert babeld
|
|
}
|