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 network_get_device interface
"$section" || interface
="$section"
110 cfg_append
"interface $interface ${option//_/-} $value"
112 # Also include an empty "interface $interface" statement, so
113 # that babeld operates on this interface.
114 cfg_append
"interface $interface"
117 # Don't use reset_cb, this would also reset config_cb
118 option_cb
() { return; }
125 # Start by emptying the generated config file
127 # Parse general and interface sections thanks to the "config_cb()"
128 # callback. This allows to loop over all options without having to
129 # know their name in advance.
131 # Parse filters separately, since we know which options we expect
132 config_foreach babel_filter filter
133 # Using multiple config files is supported since babeld 1.5.1
134 /usr
/sbin
/babeld
-D -I "$pidfile" -c "$OTHERCONFIGFILE" -c "$CONFIGFILE"
135 # Wait for the pidfile to appear
138 [ -f "$pidfile" ] ||
sleep 1
140 [ -f "$pidfile" ] ||
(echo "Failed to start babeld"; exit 42)
144 [ -f "$pidfile" ] && kill $
(cat $pidfile)
145 # avoid race-condition on restart: wait for
146 # babeld to die for real.
147 [ -f "$pidfile" ] && sleep 1
148 [ -f "$pidfile" ] && sleep 1
149 [ -f "$pidfile" ] && sleep 1
150 [ -f "$pidfile" ] && exit 42
154 [ -f "$pidfile" ] && kill -USR1 $
(cat $pidfile)