dfcf700985647641cd798754b1e8e526305d3a93
[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_bool "$cfg" 'local' 'local'
60
61 append_parm "$cfg" 'ip' 'ip'
62 append_parm "$cfg" 'eq' 'eq'
63 append_parm "$cfg" 'le' 'le'
64 append_parm "$cfg" 'ge' 'ge'
65 append_parm "$cfg" 'neigh' 'neigh'
66 append_parm "$cfg" 'id' 'id'
67 append_parm "$cfg" 'proto' 'proto'
68
69 append_ifname "$cfg" 'if' 'if'
70
71 append_parm "$cfg" 'action' ''
72
73 append args ' ' "'"
74 }
75
76 babel_addif() {
77 local cfg="$1"
78
79 local _ignored
80 config_get_bool _ignored "$cfg" 'ignore' 0
81 [ "$_ignored" -eq 1 ] && return 0
82
83 listen_ifname "$cfg" "-C 'interface"
84
85 append_parm "$cfg" 'wired' 'wired'
86 append_parm "$cfg" 'link_quality' 'link-quality'
87 append_parm "$cfg" 'split_horizon' 'split-horizon'
88 append_parm "$cfg" 'rxcost' 'rxcost'
89 append_parm "$cfg" 'hello_interval' 'hello-interval'
90 append_parm "$cfg" 'update_interval' 'update-interval'
91
92 append args ' ' "'"
93 }
94
95 babel_config() {
96 local cfg="$1"
97
98 append_bool "$cfg" 'carrier_sense' '-l'
99 append_bool "$cfg" 'assume_wireless' '-w'
100 append_bool "$cfg" 'no_split_horizon' '-s'
101 append_bool "$cfg" 'parasitic' '-P'
102
103 append_parm "$cfg" 'multicast_address' '-m'
104 append_parm "$cfg" 'port' '-p'
105 append_parm "$cfg" 'state_file' '-S'
106 append_parm "$cfg" 'hello_interval' '-h'
107 append_parm "$cfg" 'wired_hello_interval' '-H'
108 append_parm "$cfg" 'idle_hello_interval' '-i'
109 append_parm "$cfg" 'kernel_priority' '-k'
110 append_parm "$cfg" 'duplication_priority' '-A'
111 append_parm "$cfg" 'debug' '-d'
112 append_parm "$cfg" 'local_server' '-g'
113 append_parm "$cfg" 'export_table' '-t'
114 append_parm "$cfg" 'import_table' '-T'
115 append_parm "$cfg" 'conf_file' '-c'
116 append_parm "$cfg" 'log_file' '-L'
117 }
118
119 start() {
120 mkdir -p /var/lib
121 config_load babeld
122 unset args
123 unset interfaces
124 config_foreach babel_config general
125 config_foreach babel_addif interface
126 config_foreach babel_filter filter
127 [ -z "$interfaces" ] && return 0
128 eval "/usr/sbin/babeld -D -I $PID_F $args $interfaces"
129 }
130
131 stop() {
132 [ -f $PID_F ] && kill $(cat $PID_F)
133 }
134
135 status() {
136 [ -f $PID_F ] && kill -USR1 $(cat $PID_F)
137 }