]> git.ipfire.org Git - people/stevee/network.git/blob - src/functions/functions.batman-adv
Use "ip link set X master" where ever we can
[people/stevee/network.git] / src / functions / functions.batman-adv
1 #!/bin/bash
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2013 IPFire Network Development Team #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 batman_adv_start() {
23 # Load the batman kernel module.
24 module_load "batman-adv"
25 }
26
27 batman_adv_add() {
28 local device="${1}"
29 assert isset device
30
31 local cmd="ip link add name ${device} type batadv"
32 cmd_quiet "${cmd}"
33 local ret=$?
34
35 if [ ${ret} -eq ${EXIT_OK} ]; then
36 log DEBUG "batman-adv device '${device}' has been created"
37 else
38 log ERROR "batman-adv device '${device}' could not be created: ${ret}"
39 fi
40
41 return ${ret}
42 }
43
44 batman_adv_delete() {
45 local device="${1}"
46 assert isset device
47
48 device_delete "${device}"
49 }
50
51 batman_adv_attach() {
52 local device=${1}
53 assert isset device
54
55 local port=${2}
56 assert isset port
57
58 # Make sure, batman is running.
59 batman_adv_start
60
61 device_set_master "${port}" "${device}"
62 }
63
64 batman_adv_detach() {
65 local port=${1}
66 assert isset port
67
68 __device_set_file "${port}" "batman_adv/mesh_iface" "none"
69 }
70
71 batman_adv_get_aggregated_ogms() {
72 local device=${1}
73 assert isset device
74
75 local value="$(__device_get_file "${device}" "mesh/aggregated_ogms")"
76 case "${value}" in
77 enabled)
78 return ${EXIT_TRUE}
79 ;;
80 disabled)
81 return ${EXIT_FALSE}
82 ;;
83 esac
84
85 return ${EXIT_ERROR}
86 }
87
88 batman_adv_get_ap_isolation() {
89 local device=${1}
90 assert isset device
91
92 local value="$(__device_get_file "${device}" "mesh/ap_isolation")"
93 case "${value}" in
94 enabled)
95 return ${EXIT_TRUE}
96 ;;
97 disabled)
98 return ${EXIT_FALSE}
99 ;;
100 esac
101
102 return ${EXIT_ERROR}
103 }
104
105 batman_adv_get_bonding_mode() {
106 local device=${1}
107 assert isset device
108
109 local value="$(__device_get_file "${device}" "mesh/bonding")"
110 case "${value}" in
111 enabled)
112 return ${EXIT_TRUE}
113 ;;
114 disabled)
115 return ${EXIT_FALSE}
116 ;;
117 esac
118
119 return ${EXIT_ERROR}
120 }
121
122 batman_adv_get_distributed_arp_table() {
123 local device=${1}
124 assert isset device
125
126 local value="$(__device_get_file "${device}" "mesh/distributed_arp_table")"
127 case "${value}" in
128 enabled)
129 return ${EXIT_TRUE}
130 ;;
131 disabled)
132 return ${EXIT_FALSE}
133 ;;
134 esac
135
136 return ${EXIT_ERROR}
137 }
138
139 batman_adv_get_bridge_loop_avoidance() {
140 local device=${1}
141 assert isset device
142
143 local value="$(__device_get_file "${device}" "mesh/bridge_loop_avoidance")"
144 case "${value}" in
145 enabled)
146 return ${EXIT_TRUE}
147 ;;
148 disabled)
149 return ${EXIT_FALSE}
150 ;;
151 esac
152
153 return ${EXIT_ERROR}
154 }
155
156 batman_adv_get_fragmentation() {
157 local device=${1}
158 assert isset device
159
160 local value="$(__device_get_file "${device}" "mesh/fragmentation")"
161 case "${value}" in
162 enabled)
163 return ${EXIT_TRUE}
164 ;;
165 disabled)
166 return ${EXIT_FALSE}
167 ;;
168 esac
169
170 return ${EXIT_ERROR}
171 }
172
173 batman_adv_get_gateway_mode() {
174 local device=${1}
175 assert isset device
176
177 local value="$(__device_get_file "${device}" "mesh/gw_mode")"
178 case "${value}" in
179 on)
180 return ${EXIT_TRUE}
181 ;;
182 off)
183 return ${EXIT_FALSE}
184 ;;
185 esac
186
187 return ${EXIT_ERROR}
188 }
189
190 batman_adv_get_gateway_bandwidth() {
191 local device=${1}
192 assert isset device
193
194 __device_get_file "${device}" "mesh/gw_bandwidth"
195 }
196
197 batman_adv_get_gateway_selection_class() {
198 local device=${1}
199 assert isset device
200
201 __device_get_file "${device}" "mesh/gw_sel_class"
202 }
203
204 batman_adv_get_hop_penalty() {
205 local device=${1}
206 assert isset device
207
208 __device_get_file "${device}" "mesh/hop_penalty"
209 }
210
211 batman_adv_get_originator_interval() {
212 local device=${1}
213 assert isset device
214
215 __device_get_file "${device}" "mesh/orig_interval"
216 }
217
218 batman_adv_get_routing_algorithm() {
219 local device=${1}
220 assert isset device
221
222 __device_get_file "${device}" "mesh/routing_algo"
223 }