[packages] babeld: cope with empty flag options
[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 ifname=$(uci_get_state network "$1" ifname "$1")
11 local switch="$2"
12 append args "$switch $ifname"
13 append interfaces "$ifname"
14 }
15
16 append_ifname() {
17 local section="$1"
18 local option="$2"
19 local switch="$3"
20 local _name
21 config_get _name "$section" "$option"
22 [ -z "$_name" ] && return 0
23 local ifname=$(uci_get_state network "$_name" ifname "$_name")
24 append args "$switch $ifname"
25 }
26
27 append_bool() {
28 local section="$1"
29 local option="$2"
30 local value="$3"
31 local _loctmp
32 config_get_bool _loctmp "$section" "$option" 0
33 [ "$_loctmp" -gt 0 ] && append args "$value"
34 }
35
36 append_parm() {
37 local section="$1"
38 local option="$2"
39 local switch="$3"
40 local _loctmp
41 config_get _loctmp "$section" "$option"
42 [ -z "$_loctmp" ] && return 0
43 append args "$switch $_loctmp"
44 }
45
46 babel_filter() {
47 local cfg="$1"
48 local _loctmp
49
50 local _ignored
51 config_get_bool _ignored "$cfg" 'ignore' 0
52 [ "$_ignored" -eq 1 ] && return 0
53
54 append args "-C '"
55
56 append_parm "$cfg" 'type' ''
57
58 append_bool "$cfg" 'local' 'local'
59
60 append_parm "$cfg" 'ip' 'ip'
61 append_parm "$cfg" 'eq' 'eq'
62 append_parm "$cfg" 'le' 'le'
63 append_parm "$cfg" 'ge' 'ge'
64 append_parm "$cfg" 'neigh' 'neigh'
65 append_parm "$cfg" 'id' 'id'
66 append_parm "$cfg" 'proto' 'proto'
67
68 append_ifname "$cfg" 'if' 'if'
69
70 append_parm "$cfg" 'action' ''
71
72 append args ' ' "'"
73 }
74
75 babel_addif() {
76 local cfg="$1"
77
78 local _ignored
79 config_get_bool _ignored "$cfg" 'ignore' 0
80 [ "$_ignored" -eq 1 ] && return 0
81
82 listen_ifname "$cfg" "-C 'interface"
83
84 append_parm "$cfg" 'wired' 'wired'
85 append_parm "$cfg" 'link_quality' 'link-quality'
86 append_parm "$cfg" 'split_horizon' 'split-horizon'
87 append_parm "$cfg" 'rxcost' 'rxcost'
88 append_parm "$cfg" 'hello_interval' 'hello-interval'
89 append_parm "$cfg" 'update_interval' 'update-interval'
90
91 append args ' ' "'"
92 }
93
94 babel_config() {
95 local cfg="$1"
96
97 append_bool "$cfg" 'carrier_sense' '-l'
98 append_bool "$cfg" 'assume_wireless' '-w'
99 append_bool "$cfg" 'no_split_horizon' '-s'
100 append_bool "$cfg" 'parasitic' '-P'
101
102 append_parm "$cfg" 'multicast_address' '-m'
103 append_parm "$cfg" 'port' '-p'
104 append_parm "$cfg" 'state_file' '-S'
105 append_parm "$cfg" 'hello_interval' '-h'
106 append_parm "$cfg" 'wired_hello_interval' '-H'
107 append_parm "$cfg" 'idle_hello_interval' '-i'
108 append_parm "$cfg" 'kernel_priority' '-k'
109 append_parm "$cfg" 'duplication_priority' '-A'
110 append_parm "$cfg" 'debug' '-d'
111 append_parm "$cfg" 'local_server' '-g'
112 append_parm "$cfg" 'export_table' '-t'
113 append_parm "$cfg" 'import_table' '-T'
114 append_parm "$cfg" 'conf_file' '-c'
115 append_parm "$cfg" 'log_file' '-L'
116 }
117
118 start() {
119 mkdir -p /var/lib
120 config_load babeld
121 unset args
122 unset interfaces
123 config_foreach babel_config general
124 config_foreach babel_addif interface
125 config_foreach babel_filter filter
126 [ -z "$interfaces" ] && return 0
127 eval "/usr/sbin/babeld -D -I $PID_F $args $interfaces"
128 }
129
130 stop() {
131 [ -f $PID_F ] && kill $(cat $PID_F)
132 }
133
134 status() {
135 [ -f $PID_F ] && kill -USR1 $(cat $PID_F)
136 }