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 # 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" 'neigh' 'neigh'
131 append_parm
"$cfg" 'id' 'id'
132 append_parm
"$cfg" 'proto' 'proto'
134 append_ifname
"$cfg" 'if' 'if'
136 append_parm
"$cfg" 'action' ''
141 # Only one of babeld's options is allowed multiple times, "import-table".
142 # We just append it multiple times.
156 list_contains ignored_options
"$option" && return
157 cfg_append
"${option//_/-} $value"
162 config_get _ifname
"$section" 'ifname'
163 # Backward compatibility: try to use the section name
164 # if no "option ifname" was used.
165 [ -z "$_ifname" -a "${section:0:3}" != "cfg" ] && _ifname
="$section"
166 # Try to resolve the logical interface name
168 network_get_device interface
"$_ifname" || interface
="$_ifname"
173 # "option ifname" is a special option, don't actually
174 # generate configuration for it.
175 [ "$option" = "ifname" ] && return
176 [ -n "$interface" ] && _interface
="interface $interface" || _interface
="default"
177 cfg_append
"$_interface ${option//_/-} $value"
179 # Handle ignore options.
181 # This works because we loaded the whole configuration
182 # beforehand (see config_load below).
183 config_get_bool _ignored
"$section" 'ignore' 0
184 if [ "$_ignored" -eq 1 ]
186 option_cb
() { return; }
188 # Also include an empty "interface $interface" statement,
189 # so that babeld operates on this interface.
190 [ -n "$interface" ] && cfg_append
"interface $interface"
194 # Don't use reset_cb, this would also reset config_cb
195 option_cb
() { return; }
202 # Start by emptying the generated config file
204 # First load the whole config file, without callbacks, so that we are
205 # aware of all "ignore" options in the second pass.
207 # Parse general and interface sections thanks to the "config_cb()"
208 # callback. This allows to loop over all options without having to
209 # know their name in advance.
210 config_cb
() { babel_config_cb
"$@"; }
212 # Backward compatibility
213 config_foreach parse_old_global_options general
214 # Parse filters separately, since we know which options we expect
215 config_foreach babel_filter filter
216 # Using multiple config files is supported since babeld 1.5.1
217 /usr
/sbin
/babeld
-D -I "$pidfile" -c "$OTHERCONFIGFILE" -c "$CONFIGFILE"
218 # Wait for the pidfile to appear
221 [ -f "$pidfile" ] ||
sleep 1
223 [ -f "$pidfile" ] ||
(echo "Failed to start babeld"; exit 42)
227 [ -f "$pidfile" ] && kill $
(cat $pidfile)
228 # avoid race-condition on restart: wait for
229 # babeld to die for real.
230 [ -f "$pidfile" ] && sleep 1
231 [ -f "$pidfile" ] && sleep 1
232 [ -f "$pidfile" ] && sleep 1
233 [ -f "$pidfile" ] && exit 42
237 [ -f "$pidfile" ] && kill -USR1 $
(cat $pidfile)