[package] babeld: Fix reload rule in init script
[openwrt/svn-archive/archive.git] / net / babel / files / babeld.init
1 #!/bin/sh /etc/rc.common
2
3 START=70
4
5 PID_F='/var/run/babeld.pid'
6 EXTRA_COMMANDS="status"
7 EXTRA_HELP=" status Dump Babel's table to the log file."
8
9 listen_ifname() {
10 local name="$1"
11 local switch="$2"
12 local _uciname=`uci get -q -P /var/state network.$name.ifname`
13 append args "$switch ${_uciname:-$name}"
14 append interfaces "${_uciname:-$name}"
15 }
16
17 append_ifname() {
18 local section="$1"
19 local option="$2"
20 local switch="$3"
21 local _name
22 config_get _name "$section" "$option"
23 [ -z "$name" ] && return 0
24 local _uciname=`uci get -q -P /var/state network.$_name.ifname`
25 append args "$switch ${_uciname:-$_name}"
26 }
27
28 append_bool() {
29 local section="$1"
30 local option="$2"
31 local value="$3"
32 local _loctmp
33 config_get_bool _loctmp "$section" "$option"
34 [ "$_loctmp" -gt 0 ] && append args "$value"
35 }
36
37 append_parm() {
38 local section="$1"
39 local option="$2"
40 local switch="$3"
41 local _loctmp
42 config_get _loctmp "$section" "$option"
43 [ -z "$_loctmp" ] && return 0
44 append args "$switch $_loctmp"
45 }
46
47 babel_filter() {
48 local cfg="$1"
49 local _loctmp
50
51 local _ignored
52 config_get_bool _ignored "$cfg" 'ignore' 0
53 [ "$_ignored" -eq 1 ] && return 0
54
55 append args "-C '"
56
57 append_parm "$cfg" 'type' ''
58
59 append_parm "$cfg" 'ip' 'ip'
60 append_parm "$cfg" 'le' 'le'
61 append_parm "$cfg" 'ge' 'ge'
62 append_parm "$cfg" 'neigh' 'neigh'
63 append_parm "$cfg" 'id' 'id'
64 append_parm "$cfg" 'proto' 'proto'
65
66 append_ifname "$cfg" 'if' 'if'
67
68 append_bool "$cfg" 'local' 'local'
69
70 append args ' ' "'"
71 }
72
73 babel_addif() {
74 local cfg="$1"
75
76 local _ignored
77 config_get_bool _ignored "$cfg" 'ignore' 0
78 [ "$_ignored" -eq 1 ] && return 0
79
80 listen_ifname "$cfg" "-C 'interface"
81
82 append_parm "$cfg" 'wired' 'wired'
83 append_parm "$cfg" 'link_quality' 'link-quality'
84 append_parm "$cfg" 'split_horizon' 'split-horizon'
85 append_parm "$cfg" 'rxcost' 'rxcost'
86 append_parm "$cfg" 'hello_interval' 'hello-interval'
87 append_parm "$cfg" 'update_interval' 'update-interval'
88
89 append args ' ' "'"
90 }
91
92 babel_config() {
93 local cfg="$1"
94
95 append_bool "$cfg" 'carrier_sense' '-l'
96 append_bool "$cfg" 'assume_wireless' '-w'
97 append_bool "$cfg" 'no_split_horizon' '-s'
98 append_bool "$cfg" 'parasitic' '-P'
99
100 append_parm "$cfg" 'multicast_address' '-m'
101 append_parm "$cfg" 'port' '-p'
102 append_parm "$cfg" 'state_file' '-S'
103 append_parm "$cfg" 'hello_interval' '-h'
104 append_parm "$cfg" 'wired_hello_interval' '-H'
105 append_parm "$cfg" 'idle_hello_interval' '-i'
106 append_parm "$cfg" 'kernel_priority' '-k'
107 append_parm "$cfg" 'duplication_priority' '-A'
108 append_parm "$cfg" 'debug' '-d'
109 append_parm "$cfg" 'local_server' '-g'
110 append_parm "$cfg" 'export_table' '-t'
111 append_parm "$cfg" 'import_table' '-T'
112 append_parm "$cfg" 'conf_file' '-c'
113 append_parm "$cfg" 'log_file' '-L'
114 }
115
116 start() {
117 mkdir -p /var/lib
118 config_load babeld
119 unset args
120 unset interfaces
121 config_foreach babel_config general
122 config_foreach babel_addif interface
123 config_foreach babel_filter filter
124 [ -z "$interfaces" ] && return 0
125 eval "/usr/sbin/babeld -D -I $PID_F $args $interfaces"
126 }
127
128 stop() {
129 [ -f $PID_F ] && kill $(cat $PID_F)
130 }
131
132 status() {
133 [ -f $PID_F ] && kill -USR1 $(cat $PID_F)
134 }