[curl]: enable compile against axTLS and CyaSSL
[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_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
97 append args ' ' "'"
98 }
99
100 babel_config() {
101 local cfg="$1"
102
103 append_bool "$cfg" 'carrier_sense' '-l'
104 append_bool "$cfg" 'assume_wireless' '-w'
105 append_bool "$cfg" 'no_split_horizon' '-s'
106 append_bool "$cfg" 'keep_unfeasible' '-u'
107 append_bool "$cfg" 'random_router_id' '-r'
108
109 append_parm "$cfg" 'multicast_address' '-m'
110 append_parm "$cfg" 'port' '-p'
111 append_parm "$cfg" 'state_file' '-S'
112 append_parm "$cfg" 'hello_interval' '-h'
113 append_parm "$cfg" 'wired_hello_interval' '-H'
114 append_parm "$cfg" 'diversity' '-z'
115 append_parm "$cfg" 'smoothing_half_time' '-M'
116 append_parm "$cfg" 'kernel_priority' '-k'
117 append_parm "$cfg" 'duplication_priority' '-A'
118 append_parm "$cfg" 'debug' '-d'
119 append_parm "$cfg" 'local_server' '-g'
120 append_parm "$cfg" 'export_table' '-t'
121 config_list_foreach "$cfg" 'import_table' append_switch '-T'
122 append_parm "$cfg" 'conf_file' '-c'
123 append_parm "$cfg" 'log_file' '-L'
124 }
125
126 start() {
127 mkdir -p /var/lib
128 config_load babeld
129 unset args
130 unset interfaces
131 config_foreach babel_config general
132 config_foreach babel_addif interface
133 config_foreach babel_filter filter
134 [ -z "$interfaces" ] && return 0
135 eval "/usr/sbin/babeld -D -I $PID_F $args $interfaces"
136 }
137
138 stop() {
139 [ -f $PID_F ] && kill $(cat $PID_F)
140 }
141
142 status() {
143 [ -f $PID_F ] && kill -USR1 $(cat $PID_F)
144 }