]>
Commit | Line | Data |
---|---|---|
91987cc5 MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2013 Michael Tremer # | |
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 | . /usr/lib/network/header-port | |
23 | ||
e6993835 | 24 | HOOK_SETTINGS="HOOK ADDRESS SLAVES" |
91987cc5 | 25 | |
e6993835 | 26 | PORT_CHILDREN_VAR="SLAVES" |
91987cc5 | 27 | |
e6993835 MT |
28 | ADDRESS=$(mac_generate) |
29 | SLAVES= | |
91987cc5 | 30 | |
2181765d | 31 | function hook_check() { |
91987cc5 MT |
32 | assert isset ADDRESS |
33 | assert ismac ADDRESS | |
91987cc5 MT |
34 | } |
35 | ||
2181765d | 36 | function hook_create() { |
91987cc5 MT |
37 | while [ $# -gt 0 ]; do |
38 | case "${1}" in | |
39 | --address=*) | |
e6993835 | 40 | ADDRESS="$(cli_get_val ${1})" |
91987cc5 | 41 | ;; |
e6993835 MT |
42 | --slaves=*) |
43 | SLAVES="$(cli_get_val ${1})" | |
91987cc5 MT |
44 | ;; |
45 | *) | |
46 | warning "Ignoring unknown argument '${1}'" | |
47 | ;; | |
48 | esac | |
49 | shift | |
50 | done | |
51 | ||
e6993835 | 52 | local port=$(port_find_free ${PORT_PATTERN_BATMAN_ADV}) |
91987cc5 MT |
53 | assert isset port |
54 | ||
e9df08ad | 55 | port_settings_write "${port}" ${HOOK_SETTINGS} |
91987cc5 MT |
56 | |
57 | exit ${EXIT_OK} | |
58 | } | |
59 | ||
2181765d | 60 | function hook_edit() { |
91987cc5 MT |
61 | local port=${1} |
62 | assert isset port | |
63 | shift | |
64 | ||
e9df08ad | 65 | port_settings_read "${port}" |
91987cc5 MT |
66 | |
67 | while [ $# -gt 0 ]; do | |
68 | case "${1}" in | |
e6993835 MT |
69 | --address=*) |
70 | ADDRESS="$(cli_get_val ${1})" | |
91987cc5 | 71 | ;; |
e6993835 MT |
72 | --add-slave=*) |
73 | SLAVES="${SLAVES} $(cli_get_val ${1})" | |
91987cc5 | 74 | ;; |
e6993835 MT |
75 | --del-slave=*) |
76 | local slave="$(cli_get_val ${1})" | |
77 | ||
78 | local s slaves | |
79 | for s in ${SLAVES}; do | |
80 | [ "${slave}" = "${s}" ] && continue | |
81 | slaves="${slaves} ${s}" | |
82 | done | |
83 | SLAVES="${slaves}" | |
91987cc5 MT |
84 | ;; |
85 | *) | |
86 | warning "Unknown argument '${1}'" | |
87 | ;; | |
88 | esac | |
89 | shift | |
90 | done | |
91 | ||
e9df08ad | 92 | port_settings_write "${port}" ${HOOK_SETTINGS} |
91987cc5 MT |
93 | |
94 | exit ${EXIT_OK} | |
95 | } | |
96 | ||
2181765d | 97 | function hook_up() { |
91987cc5 MT |
98 | local port=${1} |
99 | assert isset port | |
100 | ||
e9df08ad | 101 | port_settings_read "${port}" ${HOOK_SETTINGS} |
91987cc5 | 102 | |
b8026986 MT |
103 | # Create batman device if it does not exist, yet. |
104 | if ! device_exists "${port}"; then | |
105 | batman_adv_add "${port}" | |
106 | fi | |
91987cc5 | 107 | |
b8026986 MT |
108 | # Set the address. |
109 | device_set_address "${port}" "${ADDRESS}" | |
91987cc5 | 110 | |
b8026986 MT |
111 | # Bring up the port |
112 | device_set_up "${port}" | |
91987cc5 MT |
113 | |
114 | exit ${EXIT_OK} | |
115 | } | |
116 | ||
2181765d | 117 | function hook_down() { |
91987cc5 MT |
118 | local port=${1} |
119 | assert isset port | |
120 | ||
e9df08ad | 121 | port_settings_read "${port}" |
91987cc5 | 122 | |
e6993835 MT |
123 | local slave |
124 | for slave in ${SLAVES}; do | |
125 | port_down "${slave}" | |
126 | done | |
91987cc5 | 127 | |
b8026986 MT |
128 | # Remove the batman device |
129 | device_exists "${port}" && batman_adv_delete "${port}" | |
130 | ||
91987cc5 MT |
131 | exit ${EXIT_OK} |
132 | } | |
133 | ||
b8026986 MT |
134 | function hook_hotplug() { |
135 | local port="${1}" | |
136 | assert isset port | |
137 | ||
138 | case "$(hotplug_action)" in | |
139 | add) | |
140 | # Don't handle this event if the batman | |
141 | # device has not been started, yet. | |
142 | #if ! device_exists "${port}"; then | |
143 | # exit ${EXIT_NOT_HANDLED} | |
144 | #fi | |
145 | ||
146 | # Handle events of the same interface | |
147 | if hotplug_event_port_is_interface "${port}"; then | |
148 | # Read configuration | |
149 | port_settings_read "${port}" | |
150 | ||
151 | # Bring up all slaves | |
152 | # They will be attached by their own hotplug event | |
153 | local slave | |
154 | for slave in ${SLAVES}; do | |
155 | if port_exists "${slave}"; then | |
156 | port_up "${slave}" | |
157 | fi | |
158 | done | |
159 | ||
160 | exit ${EXIT_OK} | |
161 | ||
162 | # Handle slave devices that have just been created and | |
163 | # attach them. | |
2a969c27 | 164 | elif hotplug_event_interface_is_slave_of_port "${port}"; then |
b8026986 MT |
165 | device_exists "${port}" || port_up "${port}" |
166 | ||
167 | batman_adv_attach "${port}" "${INTERFACE}" | |
168 | fi | |
169 | ||
170 | exit ${EXIT_OK} | |
171 | ;; | |
172 | ||
173 | remove) | |
174 | # Bring down all slaves when the batman device went down | |
175 | local slave | |
176 | for slave in ${SLAVES}; do | |
177 | port_down "${slave}" | |
178 | done | |
179 | ||
180 | exit ${EXIT_OK} | |
181 | ;; | |
182 | ||
183 | *) | |
184 | exit ${EXIT_NOT_HANDLED} | |
185 | ;; | |
186 | esac | |
187 | } | |
e6993835 | 188 | |
2181765d | 189 | function hook_status() { |
e6993835 MT |
190 | local port=${1} |
191 | assert isset port | |
192 | ||
193 | cli_device_headline "${port}" --long | |
194 | ||
195 | cli_headline 2 "B.A.T.M.A.N." | |
196 | ||
197 | # Routing algorithm | |
198 | cli_print_fmt1 2 "Routing Algorithm" \ | |
199 | "$(batman_adv_get_routing_algorithm "${port}")" | |
200 | ||
201 | # Space | |
202 | cli_space | |
203 | ||
204 | # Originator interval | |
205 | cli_print_fmt1 2 "Originator Interval" \ | |
206 | "$(batman_adv_get_originator_interval "${port}") ms" | |
207 | ||
208 | # Aggregated originator messages | |
209 | batman_adv_get_aggregated_ogms "${port}" | |
210 | cli_print_fmt1 2 "Aggregated Originator Messages" "$(cli_print_bool $?)" | |
91987cc5 | 211 | |
e6993835 MT |
212 | # AP isolation |
213 | batman_adv_get_ap_isolation "${port}" | |
214 | cli_print_fmt1 2 "Access Point Isolation" "$(cli_print_bool $?)" | |
91987cc5 | 215 | |
e6993835 MT |
216 | # Bonding mode |
217 | batman_adv_get_bonding_mode "${port}" | |
218 | cli_print_fmt1 2 "Bonding Mode" "$(cli_print_bool $?)" | |
219 | ||
220 | # Bridge loop avoidance | |
221 | batman_adv_get_bridge_loop_avoidance "${port}" | |
222 | cli_print_fmt1 2 "Bridge Loop Avoidance" "$(cli_print_bool $?)" | |
223 | ||
224 | # Distributed ARP table | |
225 | batman_adv_get_distributed_arp_table "${port}" | |
226 | cli_print_fmt1 2 "Distributed ARP Table" "$(cli_print_bool $?)" | |
227 | ||
228 | # Fragmentation | |
229 | batman_adv_get_fragmentation "${port}" | |
230 | cli_print_fmt1 2 "Fragmentation" "$(cli_print_bool $?)" | |
231 | ||
232 | # Hop penalty | |
233 | cli_print_fmt1 2 "Hop Penalty" \ | |
234 | "$(batman_adv_get_hop_penalty "${port}")" | |
235 | cli_space | |
236 | ||
237 | # Gateway | |
238 | cli_headline 3 "Gateway" | |
239 | ||
240 | # Gateway mode | |
241 | batman_adv_get_gateway_mode "${port}" | |
242 | local gw_enabled=$? | |
243 | ||
244 | cli_print_fmt1 3 "Enabled" "$(cli_print_bool ${gw_enabled})" | |
245 | ||
246 | if [ ${gw_enabled} -eq ${EXIT_TRUE} ]; then | |
247 | cli_print_fmt1 3 "Bandwidth" \ | |
248 | "$(batman_adv_get_gateway_bandwidth "${port}")" | |
249 | cli_print_fmt1 3 "Selection Class" \ | |
250 | "$(batman_adv_get_gateway_selection_class "${port}")" | |
91987cc5 MT |
251 | fi |
252 | ||
e6993835 MT |
253 | cli_space |
254 | ||
91987cc5 MT |
255 | exit ${EXIT_OK} |
256 | } |