1 #!/bin/sh /etc/rc.common
3 .
$IPKG_INSTROOT/lib
/functions
/network.sh
7 pidfile
='/var/run/babeld.pid'
8 CONFIGFILE
='/var/etc/babeld.conf'
9 OTHERCONFIGFILE
="/etc/babeld.conf"
10 OTHERCONFIGDIR
="/tmp/babeld.d/"
11 EXTRA_COMMANDS
="status"
12 EXTRA_HELP
=" status Dump Babel's table to the log file."
14 # Options to ignore for the global section (old options that are translated
15 # for backward compatibility with old configuration files)
16 ignored_options
="carrier_sense assume_wireless no_split_horizon random_router_id multicast_address port hello_interval wired_hello_interval smoothing_half_time duplication_priority local_server conf_file"
18 # Append a line to the configuration file
21 echo "$value" >> $CONFIGFILE
28 config_get value
"$section" "$option"
29 # babeld convention for options is '-', not '_'
30 [ -n "$value" ] && cfg_append
"${option//_/-} $value"
33 # Append to the "$buffer" variable
39 config_get _name
"$section" "$option"
40 [ -z "$_name" ] && return 0
41 local ifname
=$
(uci_get_state network
"$_name" ifname
"$_name")
42 append buffer
"$switch $ifname"
50 config_get_bool _loctmp
"$section" "$option" 0
51 [ "$_loctmp" -gt 0 ] && append buffer
"$value"
59 config_get _loctmp
"$section" "$option"
60 [ -z "$_loctmp" ] && return 0
61 append buffer
"$switch $_loctmp"
65 # Provides backward compatibility for old option names in the global section.
71 config_get _value
"$section" "$old_option"
72 [ -z "$_value" ] && return
73 cfg_append
"${new_option//_/-} $_value"
82 config_get_bool _bool
"$section" "$old_option" 0
83 [ "$_bool" -eq 0 ] && return
84 cfg_append
"${new_option//_/-} true"
87 # Adds a new interface section for setting default interface options.
88 add_default_option
() {
91 cfg_append
"default ${option//_/-} $value"
94 # Global 'hello_interval' and 'wired_hello_interval' options are ignored,
95 # because they have no direct equivalent: you should use
96 # interface-specific settings.
97 parse_old_global_options
() {
99 translate_bool
"$section" 'carrier_sense' 'link_detect'
100 translate_bool
"$section" 'random_router_id' 'random_id'
101 translate_option
"$section" 'multicast_address' 'protocol_group'
102 translate_option
"$section" 'port' 'protocol_port'
103 translate_option
"$section" 'local_server' 'local_port'
104 translate_option
"$section" 'smoothing_half_time' 'smoothing_half_life'
105 translate_option
"$section" 'duplication_priority' 'allow_duplicates'
106 # These two global options are turned into default interface options.
108 config_get_bool _bool
"$section" 'assume_wireless' 0
109 [ "$_bool" -eq 1 ] && add_default_option
"wired" "false"
110 config_get_bool _bool
"$section" 'no_split_horizon' 0
111 [ "$_bool" -eq 1 ] && add_default_option
"split_horizon" "false"
119 config_get_bool _ignored
"$cfg" 'ignore' 0
120 [ "$_ignored" -eq 1 ] && return 0
123 append_parm
"$cfg" 'type' ''
125 append_bool
"$cfg" 'local' 'local'
127 append_parm
"$cfg" 'ip' 'ip'
128 append_parm
"$cfg" 'eq' 'eq'
129 append_parm
"$cfg" 'le' 'le'
130 append_parm
"$cfg" 'ge' 'ge'
131 append_parm
"$cfg" 'src_ip' 'src-ip'
132 append_parm
"$cfg" 'src_eq' 'src-eq'
133 append_parm
"$cfg" 'src_le' 'src-le'
134 append_parm
"$cfg" 'src_ge' 'src-ge'
135 append_parm
"$cfg" 'neigh' 'neigh'
136 append_parm
"$cfg" 'id' 'id'
137 append_parm
"$cfg" 'proto' 'proto'
139 append_ifname
"$cfg" 'if' 'if'
141 append_parm
"$cfg" 'action' ''
146 # Only one of babeld's options is allowed multiple times, "import-table".
147 # We just append it multiple times.
161 list_contains ignored_options
"$option" && return
162 cfg_append
"${option//_/-} $value"
167 config_get _ifname
"$section" 'ifname'
168 # Backward compatibility: try to use the section name
169 # if no "option ifname" was used.
170 [ -z "$_ifname" -a "${section:0:3}" != "cfg" ] && _ifname
="$section"
171 # Try to resolve the logical interface name
173 network_get_device interface
"$_ifname" || interface
="$_ifname"
178 # "option ifname" is a special option, don't actually
179 # generate configuration for it.
180 [ "$option" = "ifname" ] && return
181 [ -n "$interface" ] && _interface
="interface $interface" || _interface
="default"
182 cfg_append
"$_interface ${option//_/-} $value"
184 # Handle ignore options.
186 # This works because we loaded the whole configuration
187 # beforehand (see config_load below).
188 config_get_bool _ignored
"$section" 'ignore' 0
189 if [ "$_ignored" -eq 1 ]
191 option_cb
() { return; }
193 # Also include an empty "interface $interface" statement,
194 # so that babeld operates on this interface.
195 [ -n "$interface" ] && cfg_append
"interface $interface"
199 # Don't use reset_cb, this would also reset config_cb
200 option_cb
() { return; }
208 mkdir
-p $OTHERCONFIGDIR
210 # Start by emptying the generated config file
212 # Import dynamic config files
213 for f
in $OTHERCONFIGDIR/*.conf
; do
214 [ -f "$f" ] && cat $f >> $CONFIGFILE
216 # First load the whole config file, without callbacks, so that we are
217 # aware of all "ignore" options in the second pass.
219 # Parse general and interface sections thanks to the "config_cb()"
220 # callback. This allows to loop over all options without having to
221 # know their name in advance.
222 config_cb
() { babel_config_cb
"$@"; }
224 # Backward compatibility
225 config_foreach parse_old_global_options general
226 # Parse filters separately, since we know which options we expect
227 config_foreach babel_filter filter
228 # Using multiple config files is supported since babeld 1.5.1
229 /usr
/sbin
/babeld
-D -I "$pidfile" -c "$OTHERCONFIGFILE" -c "$CONFIGFILE"
230 # Wait for the pidfile to appear
233 [ -f "$pidfile" ] ||
sleep 1
235 [ -f "$pidfile" ] ||
(echo "Failed to start babeld"; exit 42)
239 [ -f "$pidfile" ] && kill $
(cat $pidfile)
240 # avoid race-condition on restart: wait for
241 # babeld to die for real.
242 [ -f "$pidfile" ] && sleep 1
243 [ -f "$pidfile" ] && sleep 1
244 [ -f "$pidfile" ] && sleep 1
245 [ -f "$pidfile" ] && exit 42
249 [ -f "$pidfile" ] && kill -USR1 $
(cat $pidfile)