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 EXTRA_COMMANDS
="status"
11 EXTRA_HELP
=" status Dump Babel's table to the log file."
13 # Options to ignore for the global section (old options that are translated
14 # for backward compatibility with old configuration files)
15 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"
17 # Append a line to the configuration file
20 echo "$value" >> $CONFIGFILE
27 config_get value
"$section" "$option"
28 # babeld convention for options is '-', not '_'
29 [ -n "$value" ] && cfg_append
"${option//_/-} $value"
32 # Append to the "$buffer" variable
38 config_get _name
"$section" "$option"
39 [ -z "$_name" ] && return 0
40 local ifname
=$
(uci_get_state network
"$_name" ifname
"$_name")
41 append buffer
"$switch $ifname"
49 config_get_bool _loctmp
"$section" "$option" 0
50 [ "$_loctmp" -gt 0 ] && append buffer
"$value"
58 config_get _loctmp
"$section" "$option"
59 [ -z "$_loctmp" ] && return 0
60 append buffer
"$switch $_loctmp"
64 # Provides backward compatibility for old option names in the global section.
70 config_get _value
"$section" "$old_option"
71 [ -z "$_value" ] && return
72 cfg_append
"${new_option//_/-} $_value"
81 config_get_bool _bool
"$section" "$old_option" 0
82 [ "$_bool" -eq 0 ] && return
83 cfg_append
"${new_option//_/-} true"
86 # Adds a new interface section for setting default interface options.
87 add_default_option
() {
90 cfg_append
"default ${option//_/-} $value"
93 # Global 'hello_interval' and 'wired_hello_interval' options are ignored,
94 # because they have no direct equivalent: you should use
95 # interface-specific settings.
96 parse_old_global_options
() {
98 translate_bool
"$section" 'carrier_sense' 'link_detect'
99 translate_bool
"$section" 'random_router_id' 'random_id'
100 translate_option
"$section" 'multicast_address' 'protocol_group'
101 translate_option
"$section" 'port' 'protocol_port'
102 translate_option
"$section" 'local_server' 'local_port'
103 translate_option
"$section" 'smoothing_half_time' 'smoothing_half_life'
104 translate_option
"$section" 'duplication_priority' 'allow_duplicates'
105 # These two global options are turned into default interface options.
107 config_get_bool _bool
"$section" 'assume_wireless' 0
108 [ "$_bool" -eq 1 ] && add_default_option
"wired" "false"
109 config_get_bool _bool
"$section" 'no_split_horizon' 0
110 [ "$_bool" -eq 1 ] && add_default_option
"split_horizon" "false"
118 config_get_bool _ignored
"$cfg" 'ignore' 0
119 [ "$_ignored" -eq 1 ] && return 0
122 append_parm
"$cfg" 'type' ''
124 append_bool
"$cfg" 'local' 'local'
126 append_parm
"$cfg" 'ip' 'ip'
127 append_parm
"$cfg" 'eq' 'eq'
128 append_parm
"$cfg" 'le' 'le'
129 append_parm
"$cfg" 'ge' 'ge'
130 append_parm
"$cfg" 'src_ip' 'src-ip'
131 append_parm
"$cfg" 'src_eq' 'src-eq'
132 append_parm
"$cfg" 'src_le' 'src-le'
133 append_parm
"$cfg" 'src_ge' 'src-ge'
134 append_parm
"$cfg" 'neigh' 'neigh'
135 append_parm
"$cfg" 'id' 'id'
136 append_parm
"$cfg" 'proto' 'proto'
138 append_ifname
"$cfg" 'if' 'if'
140 append_parm
"$cfg" 'action' ''
145 # Only one of babeld's options is allowed multiple times, "import-table".
146 # We just append it multiple times.
160 list_contains ignored_options
"$option" && return
161 cfg_append
"${option//_/-} $value"
166 config_get _ifname
"$section" 'ifname'
167 # Backward compatibility: try to use the section name
168 # if no "option ifname" was used.
169 [ -z "$_ifname" -a "${section:0:3}" != "cfg" ] && _ifname
="$section"
170 # Try to resolve the logical interface name
172 network_get_device interface
"$_ifname" || interface
="$_ifname"
177 # "option ifname" is a special option, don't actually
178 # generate configuration for it.
179 [ "$option" = "ifname" ] && return
180 [ -n "$interface" ] && _interface
="interface $interface" || _interface
="default"
181 cfg_append
"$_interface ${option//_/-} $value"
183 # Handle ignore options.
185 # This works because we loaded the whole configuration
186 # beforehand (see config_load below).
187 config_get_bool _ignored
"$section" 'ignore' 0
188 if [ "$_ignored" -eq 1 ]
190 option_cb
() { return; }
192 # Also include an empty "interface $interface" statement,
193 # so that babeld operates on this interface.
194 [ -n "$interface" ] && cfg_append
"interface $interface"
198 # Don't use reset_cb, this would also reset config_cb
199 option_cb
() { return; }
207 # Start by emptying the generated config file
209 # First load the whole config file, without callbacks, so that we are
210 # aware of all "ignore" options in the second pass.
212 # Parse general and interface sections thanks to the "config_cb()"
213 # callback. This allows to loop over all options without having to
214 # know their name in advance.
215 config_cb
() { babel_config_cb
"$@"; }
217 # Backward compatibility
218 config_foreach parse_old_global_options general
219 # Parse filters separately, since we know which options we expect
220 config_foreach babel_filter filter
221 # Using multiple config files is supported since babeld 1.5.1
222 /usr
/sbin
/babeld
-D -I "$pidfile" -c "$OTHERCONFIGFILE" -c "$CONFIGFILE"
223 # Wait for the pidfile to appear
226 [ -f "$pidfile" ] ||
sleep 1
228 [ -f "$pidfile" ] ||
(echo "Failed to start babeld"; exit 42)
232 [ -f "$pidfile" ] && kill $
(cat $pidfile)
233 # avoid race-condition on restart: wait for
234 # babeld to die for real.
235 [ -f "$pidfile" ] && sleep 1
236 [ -f "$pidfile" ] && sleep 1
237 [ -f "$pidfile" ] && sleep 1
238 [ -f "$pidfile" ] && exit 42
242 [ -f "$pidfile" ] && kill -USR1 $
(cat $pidfile)