olsrd: Merge branch 'olsrd_6and4' by Alessio Caiazza.
[feed/routing.git] / babeld / files / babeld.init
1 #!/bin/sh /etc/rc.common
2
3 START=70
4
5 pidfile='/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_switch() {
37 local value="$1"
38 local switch="$2"
39 append args "$switch $value"
40 }
41
42 append_parm() {
43 local section="$1"
44 local option="$2"
45 local switch="$3"
46 local _loctmp
47 config_get _loctmp "$section" "$option"
48 [ -z "$_loctmp" ] && return 0
49 append args "$switch $_loctmp"
50 }
51
52 babel_filter() {
53 local cfg="$1"
54 local _loctmp
55
56 local _ignored
57 config_get_bool _ignored "$cfg" 'ignore' 0
58 [ "$_ignored" -eq 1 ] && return 0
59
60 append args "-C '"
61
62 append_parm "$cfg" 'type' ''
63
64 append_bool "$cfg" 'local' 'local'
65
66 append_parm "$cfg" 'ip' 'ip'
67 append_parm "$cfg" 'eq' 'eq'
68 append_parm "$cfg" 'le' 'le'
69 append_parm "$cfg" 'ge' 'ge'
70 append_parm "$cfg" 'neigh' 'neigh'
71 append_parm "$cfg" 'id' 'id'
72 append_parm "$cfg" 'proto' 'proto'
73
74 append_ifname "$cfg" 'if' 'if'
75
76 append_parm "$cfg" 'action' ''
77
78 append args ' ' "'"
79 }
80
81 babel_addif() {
82 local cfg="$1"
83
84 local _ignored
85 config_get_bool _ignored "$cfg" 'ignore' 0
86 [ "$_ignored" -eq 1 ] && return 0
87
88 listen_ifname "$cfg" "-C 'interface"
89
90 append_parm "$cfg" 'wired' 'wired'
91 append_parm "$cfg" 'link_quality' 'link-quality'
92 append_parm "$cfg" 'split_horizon' 'split-horizon'
93 append_parm "$cfg" 'rxcost' 'rxcost'
94 append_parm "$cfg" 'hello_interval' 'hello-interval'
95 append_parm "$cfg" 'update_interval' 'update-interval'
96 append_bool "$cfg" 'enable_timestamps' 'enable-timestamps'
97 append_parm "$cfg" 'max_rtt_penalty' 'max-rtt-penalty'
98 append_parm "$cfg" 'rtt_decay' 'rtt-decay'
99 append_parm "$cfg" 'rtt_min' 'rtt-min'
100 append_parm "$cfg" 'rtt_max' 'rtt-max'
101
102 append args ' ' "'"
103 }
104
105 babel_config() {
106 local cfg="$1"
107
108 append_bool "$cfg" 'carrier_sense' '-l'
109 append_bool "$cfg" 'assume_wireless' '-w'
110 append_bool "$cfg" 'no_split_horizon' '-s'
111 append_bool "$cfg" 'keep_unfeasible' '-u'
112 append_bool "$cfg" 'random_router_id' '-r'
113
114 append_parm "$cfg" 'multicast_address' '-m'
115 append_parm "$cfg" 'port' '-p'
116 append_parm "$cfg" 'state_file' '-S'
117 append_parm "$cfg" 'hello_interval' '-h'
118 append_parm "$cfg" 'wired_hello_interval' '-H'
119 append_parm "$cfg" 'diversity' '-z'
120 append_parm "$cfg" 'smoothing_half_time' '-M'
121 append_parm "$cfg" 'kernel_priority' '-k'
122 append_parm "$cfg" 'duplication_priority' '-A'
123 append_parm "$cfg" 'debug' '-d'
124 append_parm "$cfg" 'local_server' '-g'
125 append_parm "$cfg" 'export_table' '-t'
126 config_list_foreach "$cfg" 'import_table' append_switch '-T'
127 append_parm "$cfg" 'conf_file' '-c'
128 append_parm "$cfg" 'log_file' '-L'
129 }
130
131 start() {
132 mkdir -p /var/lib
133 config_load babeld
134 unset args
135 unset interfaces
136 config_foreach babel_config general
137 config_foreach babel_addif interface
138 config_foreach babel_filter filter
139 [ -z "$interfaces" ] && return 0
140 eval "/usr/sbin/babeld -D -I $pidfile $args $interfaces"
141 }
142
143 stop() {
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
151 }
152
153 status() {
154 [ -f "$pidfile" ] && kill -USR1 $(cat $pidfile)
155 }