1 #!/bin/sh /etc/rc.common
3 .
/lib
/functions
/network.sh
7 pidfile
='/var/run/babeld.pid'
8 CONFIGFILE
='/var/etc/babeld.conf'
9 OTHERCONFIGFILE
="/etc/babeld.conf"
10 EXTRA_COMMANDS
="status"
11 EXTRA_HELP
=" status Dump Babel's table to the log file."
13 # Append a line to the configuration file
16 echo "$value" >> $CONFIGFILE
23 config_get value
"$section" "$option"
24 # babeld convention for options is '-', not '_'
25 [ -n "$value" ] && cfg_append
"${option//_/-} $value"
28 # Append to the "$buffer" variable
34 config_get _name
"$section" "$option"
35 [ -z "$_name" ] && return 0
36 local ifname
=$
(uci_get_state network
"$_name" ifname
"$_name")
37 append buffer
"$switch $ifname"
45 config_get_bool _loctmp
"$section" "$option" 0
46 [ "$_loctmp" -gt 0 ] && append buffer
"$value"
54 config_get _loctmp
"$section" "$option"
55 [ -z "$_loctmp" ] && return 0
56 append buffer
"$switch $_loctmp"
64 config_get_bool _ignored
"$cfg" 'ignore' 0
65 [ "$_ignored" -eq 1 ] && return 0
68 append_parm
"$cfg" 'type' ''
70 append_bool
"$cfg" 'local' 'local'
72 append_parm
"$cfg" 'ip' 'ip'
73 append_parm
"$cfg" 'eq' 'eq'
74 append_parm
"$cfg" 'le' 'le'
75 append_parm
"$cfg" 'ge' 'ge'
76 append_parm
"$cfg" 'neigh' 'neigh'
77 append_parm
"$cfg" 'id' 'id'
78 append_parm
"$cfg" 'proto' 'proto'
80 append_ifname
"$cfg" 'if' 'if'
82 append_parm
"$cfg" 'action' ''
87 # Only one of babeld's options is allowed multiple times, "import-table".
88 # We just append it multiple times.
101 cfg_append
"${option//_/-} $value"
106 config_get _ifname
"$section" 'ifname'
107 # Try to resolve the logical interface name
109 network_get_device interface
"$_ifname" || interface
="$_ifname"
114 # "option ifname" is a special option, don't actually
115 # generate configuration for it.
116 [ "$option" = "ifname" ] && return
117 [ -n "$interface" ] && _interface
="interface $interface" || _interface
="default"
118 cfg_append
"$_interface ${option//_/-} $value"
120 # Handle ignore options.
122 # This works because we loaded the whole configuration
123 # beforehand (see config_load below).
124 config_get_bool _ignored
"$section" 'ignore' 0
125 if [ "$_ignored" -eq 1 ]
127 option_cb
() { return; }
129 # Also include an empty "interface $interface" statement,
130 # so that babeld operates on this interface.
131 [ -n "$interface" ] && cfg_append
"interface $interface"
135 # Don't use reset_cb, this would also reset config_cb
136 option_cb
() { return; }
143 # Start by emptying the generated config file
145 # First load the whole config file, without callbacks, so that we are
146 # aware of all "ignore" options in the second pass.
148 # Parse general and interface sections thanks to the "config_cb()"
149 # callback. This allows to loop over all options without having to
150 # know their name in advance.
151 config_cb
() { babel_config_cb
"$@"; }
153 # Parse filters separately, since we know which options we expect
154 config_foreach babel_filter filter
155 # Using multiple config files is supported since babeld 1.5.1
156 /usr
/sbin
/babeld
-D -I "$pidfile" -c "$OTHERCONFIGFILE" -c "$CONFIGFILE"
157 # Wait for the pidfile to appear
160 [ -f "$pidfile" ] ||
sleep 1
162 [ -f "$pidfile" ] ||
(echo "Failed to start babeld"; exit 42)
166 [ -f "$pidfile" ] && kill $
(cat $pidfile)
167 # avoid race-condition on restart: wait for
168 # babeld to die for real.
169 [ -f "$pidfile" ] && sleep 1
170 [ -f "$pidfile" ] && sleep 1
171 [ -f "$pidfile" ] && sleep 1
172 [ -f "$pidfile" ] && exit 42
176 [ -f "$pidfile" ] && kill -USR1 $
(cat $pidfile)