1 #!/bin/sh /etc/rc.common
3 .
$IPKG_INSTROOT/lib
/functions
/network.sh
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 # Append a line to the configuration file
17 echo "$value" >> "$CONFIGFILE"
24 config_get value
"$section" "$option"
25 # babeld convention for options is '-', not '_'
26 [ -n "$value" ] && cfg_append
"${option//_/-} $value"
29 # Append to the "$buffer" variable
35 config_get _name
"$section" "$option"
36 [ -z "$_name" ] && return 0
37 local ifname
=$
(uci_get_state network
"$_name" ifname
"$_name")
38 append buffer
"$switch $ifname"
46 config_get_bool _loctmp
"$section" "$option" 0
47 [ "$_loctmp" -gt 0 ] && append buffer
"$value"
55 config_get _loctmp
"$section" "$option"
56 [ -z "$_loctmp" ] && return 0
57 append buffer
"$switch $_loctmp"
65 config_get_bool _ignored
"$cfg" 'ignore' 0
66 [ "$_ignored" -eq 1 ] && return 0
69 append_parm
"$cfg" 'type' ''
71 append_bool
"$cfg" 'local' 'local'
73 append_parm
"$cfg" 'ip' 'ip'
74 append_parm
"$cfg" 'eq' 'eq'
75 append_parm
"$cfg" 'le' 'le'
76 append_parm
"$cfg" 'ge' 'ge'
77 append_parm
"$cfg" 'src_ip' 'src-ip'
78 append_parm
"$cfg" 'src_eq' 'src-eq'
79 append_parm
"$cfg" 'src_le' 'src-le'
80 append_parm
"$cfg" 'src_ge' 'src-ge'
81 append_parm
"$cfg" 'neigh' 'neigh'
82 append_parm
"$cfg" 'id' 'id'
83 append_parm
"$cfg" 'proto' 'proto'
85 append_ifname
"$cfg" 'if' 'if'
87 append_parm
"$cfg" 'action' ''
92 # Only one of babeld's options is allowed multiple times, "import-table".
93 # We just append it multiple times.
106 # Ignore options that are not supposed to be given to babeld
107 [ "$option" = "conf_file" ] && return
108 [ "$option" = "conf_dir" ] && return
109 # Skip lists. They will be taken care of by list_cb
110 test "${option#*_ITEM}" != "$option" && return
111 test "${option#*_LENGTH}" != "$option" && return
112 cfg_append
"${option//_/-} $value"
117 config_get _ifname
"$section" 'ifname'
118 # Try to resolve the logical interface name
120 network_get_device interface
"$_ifname" || interface
="$_ifname"
125 # "option ifname" is a special option, don't actually
126 # generate configuration for it.
127 [ "$option" = "ifname" ] && return
128 [ -n "$interface" ] && _interface
="interface $interface" || _interface
="default"
129 cfg_append
"$_interface ${option//_/-} $value"
131 # Handle ignore options.
133 # This works because we loaded the whole configuration
134 # beforehand (see config_load below).
135 config_get_bool _ignored
"$section" 'ignore' 0
136 if [ "$_ignored" -eq 1 ]
138 option_cb
() { return; }
140 # Also include an empty "interface $interface" statement,
141 # so that babeld operates on this interface.
142 [ -n "$interface" ] && cfg_append
"interface $interface"
146 # Don't use reset_cb, this would also reset config_cb
147 option_cb
() { return; }
152 # Support for conf_file and conf_dir
153 babel_configpaths
() {
156 config_get conf_file
"$cfg" "conf_file"
157 [ -n "$conf_file" ] && OTHERCONFIGFILE
="$conf_file"
159 config_get conf_dir
"$cfg" "conf_dir"
160 [ -n "$conf_dir" ] && OTHERCONFIGDIR
="$conf_dir"
167 # First load the whole config file, without callbacks, so that we are
168 # aware of all "ignore" options in the second pass. This also allows
169 # to load the configuration paths (conf_file and conf_dir).
172 # Configure alternative configuration file and directory
173 config_foreach babel_configpaths
"general"
175 # Start by emptying the generated config file
177 # Import dynamic config files
178 mkdir
-p "$OTHERCONFIGDIR"
179 for f
in "$OTHERCONFIGDIR"/*.conf
; do
180 [ -f "$f" ] && cat "$f" >> "$CONFIGFILE"
183 # Parse general and interface sections thanks to the "config_cb()"
184 # callback. This allows to loop over all options without having to
185 # know their name in advance.
186 config_cb
() { babel_config_cb
"$@"; }
188 # Parse filters separately, since we know which options we expect
189 config_foreach babel_filter filter
191 # Using multiple config files is supported since babeld 1.5.1
192 procd_set_param
command /usr
/sbin
/babeld
-I "" -c "$OTHERCONFIGFILE" -c "$CONFIGFILE"
193 procd_set_param stdout
1
194 procd_set_param stderr
1
195 procd_set_param
file "$OTHERCONFIGFILE" "$OTHERCONFIGDIR"/*.conf
"$CONFIGFILE"
196 procd_set_param respawn
201 procd_add_reload_trigger babeld
205 kill -USR1 $
(pgrep
-P 1 babeld
)