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 conf_dir"
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"
112 # Configure alternative configuration file and directory
114 config_get conf_file
"$section" "conf_file"
115 [ -n "$conf_file" ] && OTHERCONFIGFILE
="$conf_file"
117 config_get conf_dir
"$section" "conf_dir"
118 [ -n "$conf_dir" ] && OTHERCONFIGDIR
="$conf_dir"
126 config_get_bool _ignored
"$cfg" 'ignore' 0
127 [ "$_ignored" -eq 1 ] && return 0
130 append_parm
"$cfg" 'type' ''
132 append_bool
"$cfg" 'local' 'local'
134 append_parm
"$cfg" 'ip' 'ip'
135 append_parm
"$cfg" 'eq' 'eq'
136 append_parm
"$cfg" 'le' 'le'
137 append_parm
"$cfg" 'ge' 'ge'
138 append_parm
"$cfg" 'src_ip' 'src-ip'
139 append_parm
"$cfg" 'src_eq' 'src-eq'
140 append_parm
"$cfg" 'src_le' 'src-le'
141 append_parm
"$cfg" 'src_ge' 'src-ge'
142 append_parm
"$cfg" 'neigh' 'neigh'
143 append_parm
"$cfg" 'id' 'id'
144 append_parm
"$cfg" 'proto' 'proto'
146 append_ifname
"$cfg" 'if' 'if'
148 append_parm
"$cfg" 'action' ''
153 # Only one of babeld's options is allowed multiple times, "import-table".
154 # We just append it multiple times.
168 list_contains ignored_options
"$option" && return
169 cfg_append
"${option//_/-} $value"
174 config_get _ifname
"$section" 'ifname'
175 # Backward compatibility: try to use the section name
176 # if no "option ifname" was used.
177 [ -z "$_ifname" -a "${section:0:3}" != "cfg" ] && _ifname
="$section"
178 # Try to resolve the logical interface name
180 network_get_device interface
"$_ifname" || interface
="$_ifname"
185 # "option ifname" is a special option, don't actually
186 # generate configuration for it.
187 [ "$option" = "ifname" ] && return
188 [ -n "$interface" ] && _interface
="interface $interface" || _interface
="default"
189 cfg_append
"$_interface ${option//_/-} $value"
191 # Handle ignore options.
193 # This works because we loaded the whole configuration
194 # beforehand (see config_load below).
195 config_get_bool _ignored
"$section" 'ignore' 0
196 if [ "$_ignored" -eq 1 ]
198 option_cb
() { return; }
200 # Also include an empty "interface $interface" statement,
201 # so that babeld operates on this interface.
202 [ -n "$interface" ] && cfg_append
"interface $interface"
206 # Don't use reset_cb, this would also reset config_cb
207 option_cb
() { return; }
215 mkdir
-p $OTHERCONFIGDIR
217 # Start by emptying the generated config file
219 # Import dynamic config files
220 for f
in $OTHERCONFIGDIR/*.conf
; do
221 [ -f "$f" ] && cat $f >> $CONFIGFILE
223 # First load the whole config file, without callbacks, so that we are
224 # aware of all "ignore" options in the second pass.
226 # Parse general and interface sections thanks to the "config_cb()"
227 # callback. This allows to loop over all options without having to
228 # know their name in advance.
229 config_cb
() { babel_config_cb
"$@"; }
231 # Backward compatibility
232 config_foreach parse_old_global_options general
233 # Parse filters separately, since we know which options we expect
234 config_foreach babel_filter filter
235 # Using multiple config files is supported since babeld 1.5.1
236 /usr
/sbin
/babeld
-D -I "$pidfile" -c "$OTHERCONFIGFILE" -c "$CONFIGFILE"
237 # Wait for the pidfile to appear
240 [ -f "$pidfile" ] ||
sleep 1
242 [ -f "$pidfile" ] ||
(echo "Failed to start babeld"; exit 42)
246 [ -f "$pidfile" ] && kill $
(cat $pidfile)
247 # avoid race-condition on restart: wait for
248 # babeld to die for real.
249 [ -f "$pidfile" ] && sleep 1
250 [ -f "$pidfile" ] && sleep 1
251 [ -f "$pidfile" ] && sleep 1
252 [ -f "$pidfile" ] && exit 42
256 [ -f "$pidfile" ] && kill -USR1 $
(cat $pidfile)