babeld: Generate a configuration file instead of passing cmdline arguments
This is the first step toward fixing issue #33. This still lacks some features: - no support for "ignore" options - no backward compatibility for option names - no support for default interface options
This commit is contained in:
parent
25f7667e0e
commit
f81d53fad2
1 changed files with 63 additions and 69 deletions
|
@ -1,18 +1,31 @@
|
||||||
#!/bin/sh /etc/rc.common
|
#!/bin/sh /etc/rc.common
|
||||||
|
|
||||||
|
. /lib/functions/network.sh
|
||||||
|
|
||||||
START=70
|
START=70
|
||||||
|
|
||||||
pidfile='/var/run/babeld.pid'
|
pidfile='/var/run/babeld.pid'
|
||||||
|
CONFIGFILE='/var/etc/babeld.conf'
|
||||||
|
OTHERCONFIGFILE="/etc/babeld.conf"
|
||||||
EXTRA_COMMANDS="status"
|
EXTRA_COMMANDS="status"
|
||||||
EXTRA_HELP=" status Dump Babel's table to the log file."
|
EXTRA_HELP=" status Dump Babel's table to the log file."
|
||||||
|
|
||||||
listen_ifname() {
|
# Append a line to the configuration file
|
||||||
local ifname=$(uci_get_state network "$1" ifname "$1")
|
cfg_append() {
|
||||||
local switch="$2"
|
local value="$1"
|
||||||
append args "$switch $ifname"
|
echo "$value" >> $CONFIGFILE
|
||||||
append interfaces "$ifname"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg_append_option() {
|
||||||
|
local section="$1"
|
||||||
|
local option="$2"
|
||||||
|
local value
|
||||||
|
config_get value "$section" "$option"
|
||||||
|
# babeld convention for options is '-', not '_'
|
||||||
|
[ -n "$value" ] && cfg_append "${option//_/-} $value"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Append to the "$buffer" variable
|
||||||
append_ifname() {
|
append_ifname() {
|
||||||
local section="$1"
|
local section="$1"
|
||||||
local option="$2"
|
local option="$2"
|
||||||
|
@ -21,7 +34,7 @@ append_ifname() {
|
||||||
config_get _name "$section" "$option"
|
config_get _name "$section" "$option"
|
||||||
[ -z "$_name" ] && return 0
|
[ -z "$_name" ] && return 0
|
||||||
local ifname=$(uci_get_state network "$_name" ifname "$_name")
|
local ifname=$(uci_get_state network "$_name" ifname "$_name")
|
||||||
append args "$switch $ifname"
|
append buffer "$switch $ifname"
|
||||||
}
|
}
|
||||||
|
|
||||||
append_bool() {
|
append_bool() {
|
||||||
|
@ -30,13 +43,7 @@ append_bool() {
|
||||||
local value="$3"
|
local value="$3"
|
||||||
local _loctmp
|
local _loctmp
|
||||||
config_get_bool _loctmp "$section" "$option" 0
|
config_get_bool _loctmp "$section" "$option" 0
|
||||||
[ "$_loctmp" -gt 0 ] && append args "$value"
|
[ "$_loctmp" -gt 0 ] && append buffer "$value"
|
||||||
}
|
|
||||||
|
|
||||||
append_switch() {
|
|
||||||
local value="$1"
|
|
||||||
local switch="$2"
|
|
||||||
append args "$switch $value"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
append_parm() {
|
append_parm() {
|
||||||
|
@ -46,7 +53,7 @@ append_parm() {
|
||||||
local _loctmp
|
local _loctmp
|
||||||
config_get _loctmp "$section" "$option"
|
config_get _loctmp "$section" "$option"
|
||||||
[ -z "$_loctmp" ] && return 0
|
[ -z "$_loctmp" ] && return 0
|
||||||
append args "$switch $_loctmp"
|
append buffer "$switch $_loctmp"
|
||||||
}
|
}
|
||||||
|
|
||||||
babel_filter() {
|
babel_filter() {
|
||||||
|
@ -56,9 +63,8 @@ babel_filter() {
|
||||||
local _ignored
|
local _ignored
|
||||||
config_get_bool _ignored "$cfg" 'ignore' 0
|
config_get_bool _ignored "$cfg" 'ignore' 0
|
||||||
[ "$_ignored" -eq 1 ] && return 0
|
[ "$_ignored" -eq 1 ] && return 0
|
||||||
|
|
||||||
append args "-C '"
|
|
||||||
|
|
||||||
|
unset buffer
|
||||||
append_parm "$cfg" 'type' ''
|
append_parm "$cfg" 'type' ''
|
||||||
|
|
||||||
append_bool "$cfg" 'local' 'local'
|
append_bool "$cfg" 'local' 'local'
|
||||||
|
@ -75,69 +81,57 @@ babel_filter() {
|
||||||
|
|
||||||
append_parm "$cfg" 'action' ''
|
append_parm "$cfg" 'action' ''
|
||||||
|
|
||||||
append args ' ' "'"
|
cfg_append "$buffer"
|
||||||
}
|
}
|
||||||
|
|
||||||
babel_addif() {
|
# Only one of babeld's options is allowed multiple times, "import-table".
|
||||||
local cfg="$1"
|
# We just append it multiple times.
|
||||||
|
list_cb() {
|
||||||
local _ignored
|
option_cb "$@"
|
||||||
config_get_bool _ignored "$cfg" 'ignore' 0
|
|
||||||
[ "$_ignored" -eq 1 ] && return 0
|
|
||||||
|
|
||||||
listen_ifname "$cfg" "-C 'interface"
|
|
||||||
|
|
||||||
append_parm "$cfg" 'wired' 'wired'
|
|
||||||
append_parm "$cfg" 'link_quality' 'link-quality'
|
|
||||||
append_parm "$cfg" 'split_horizon' 'split-horizon'
|
|
||||||
append_parm "$cfg" 'rxcost' 'rxcost'
|
|
||||||
append_parm "$cfg" 'hello_interval' 'hello-interval'
|
|
||||||
append_parm "$cfg" 'update_interval' 'update-interval'
|
|
||||||
append_parm "$cfg" 'enable_timestamps' 'enable-timestamps'
|
|
||||||
append_parm "$cfg" 'max_rtt_penalty' 'max-rtt-penalty'
|
|
||||||
append_parm "$cfg" 'rtt_decay' 'rtt-decay'
|
|
||||||
append_parm "$cfg" 'rtt_min' 'rtt-min'
|
|
||||||
append_parm "$cfg" 'rtt_max' 'rtt-max'
|
|
||||||
|
|
||||||
append args ' ' "'"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
babel_config() {
|
config_cb() {
|
||||||
local cfg="$1"
|
local type="$1"
|
||||||
|
local section="$2"
|
||||||
append_bool "$cfg" 'carrier_sense' '-l'
|
case "$type" in
|
||||||
append_bool "$cfg" 'assume_wireless' '-w'
|
"general")
|
||||||
append_bool "$cfg" 'no_split_horizon' '-s'
|
option_cb() {
|
||||||
append_bool "$cfg" 'keep_unfeasible' '-u'
|
local option="$1"
|
||||||
append_bool "$cfg" 'random_router_id' '-r'
|
local value="$2"
|
||||||
|
cfg_append "${option//_/-} $value"
|
||||||
append_parm "$cfg" 'multicast_address' '-m'
|
}
|
||||||
append_parm "$cfg" 'port' '-p'
|
;;
|
||||||
append_parm "$cfg" 'state_file' '-S'
|
"interface")
|
||||||
append_parm "$cfg" 'hello_interval' '-h'
|
unset interface
|
||||||
append_parm "$cfg" 'wired_hello_interval' '-H'
|
network_get_device interface "$section" || interface="$section"
|
||||||
append_parm "$cfg" 'diversity' '-z'
|
option_cb() {
|
||||||
append_parm "$cfg" 'smoothing_half_time' '-M'
|
local option="$1"
|
||||||
append_parm "$cfg" 'kernel_priority' '-k'
|
local value="$2"
|
||||||
append_parm "$cfg" 'duplication_priority' '-A'
|
cfg_append "interface $interface ${option//_/-} $value"
|
||||||
append_parm "$cfg" 'debug' '-d'
|
}
|
||||||
append_parm "$cfg" 'local_server' '-g'
|
# Also include an empty "interface $interface" statement, so
|
||||||
append_parm "$cfg" 'export_table' '-t'
|
# that babeld operates on this interface.
|
||||||
config_list_foreach "$cfg" 'import_table' append_switch '-T'
|
cfg_append "interface $interface"
|
||||||
append_parm "$cfg" 'conf_file' '-c'
|
;;
|
||||||
append_parm "$cfg" 'log_file' '-L'
|
*)
|
||||||
|
# Don't use reset_cb, this would also reset config_cb
|
||||||
|
option_cb() { return; }
|
||||||
|
;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
mkdir -p /var/lib
|
mkdir -p /var/lib
|
||||||
|
# Start by emptying the generated config file
|
||||||
|
>"$CONFIGFILE"
|
||||||
|
# Parse general and interface sections thanks to the "config_cb()"
|
||||||
|
# callback. This allows to loop over all options without having to
|
||||||
|
# know their name in advance.
|
||||||
config_load babeld
|
config_load babeld
|
||||||
unset args
|
# Parse filters separately, since we know which options we expect
|
||||||
unset interfaces
|
|
||||||
config_foreach babel_config general
|
|
||||||
config_foreach babel_addif interface
|
|
||||||
config_foreach babel_filter filter
|
config_foreach babel_filter filter
|
||||||
[ -z "$interfaces" ] && return 0
|
# Using multiple config files is supported since babeld 1.5.1
|
||||||
eval "/usr/sbin/babeld -D -I $pidfile $args $interfaces"
|
/usr/sbin/babeld -D -I "$pidfile" -c "$OTHERCONFIGFILE" -c "$CONFIGFILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
|
|
Loading…
Reference in a new issue