]> git.ipfire.org Git - people/ms/network.git/blame - src/hooks/ports/batman-adv
dhcp: Add support for DHCPv6 over Ethernet
[people/ms/network.git] / src / hooks / ports / batman-adv
CommitLineData
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 24HOOK_SETTINGS="HOOK ADDRESS SLAVES"
91987cc5 25
e6993835 26PORT_CHILDREN_VAR="SLAVES"
91987cc5 27
e6993835
MT
28ADDRESS=$(mac_generate)
29SLAVES=
91987cc5 30
1e6f187e 31function hook_check_settings() {
91987cc5
MT
32 assert isset ADDRESS
33 assert ismac ADDRESS
91987cc5
MT
34}
35
1ba6a2bb 36function hook_new() {
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 60function 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
1ba6a2bb
MT
97function hook_create() {
98 local port="${1}"
91987cc5
MT
99 assert isset port
100
e9df08ad 101 port_settings_read "${port}" ${HOOK_SETTINGS}
91987cc5 102
1ba6a2bb
MT
103 # Create a new batman-adv device
104 batman_adv_add "${port}" || exit ${?}
91987cc5 105
b8026986
MT
106 # Set the address.
107 device_set_address "${port}" "${ADDRESS}"
91987cc5 108
91987cc5
MT
109 exit ${EXIT_OK}
110}
111
1ba6a2bb
MT
112function hook_remove() {
113 local port="${1}"
91987cc5
MT
114 assert isset port
115
1ba6a2bb 116 port_settings_read "${port}" ${HOOK_SETTINGS}
91987cc5 117
1ba6a2bb
MT
118 # Remove the batman-adv device
119 batman_adv_delete "${port}"
b8026986 120
91987cc5
MT
121 exit ${EXIT_OK}
122}
123
b8026986
MT
124function hook_hotplug() {
125 local port="${1}"
126 assert isset port
127
128 case "$(hotplug_action)" in
129 add)
b8026986
MT
130 # Handle events of the same interface
131 if hotplug_event_port_is_interface "${port}"; then
b8026986
MT
132 # Bring up all slaves
133 # They will be attached by their own hotplug event
134 local slave
1ba6a2bb
MT
135 for slave in $(port_get_slaves "${port}"); do
136 port_create "${slave}"
b8026986
MT
137 done
138
139 exit ${EXIT_OK}
140
141 # Handle slave devices that have just been created and
142 # attach them.
2a969c27 143 elif hotplug_event_interface_is_slave_of_port "${port}"; then
b8026986 144 batman_adv_attach "${port}" "${INTERFACE}"
1ba6a2bb
MT
145
146 # If the batman-adv is already up, we will bring
147 # up the slave we just added as well.
148 if port_is_up "${port}"; then
149 port_up "${INTERFACE}"
150 fi
b8026986
MT
151 fi
152
153 exit ${EXIT_OK}
154 ;;
155
156 remove)
1ba6a2bb
MT
157 if hotplug_event_port_is_interface "${port}"; then
158 # Bring down all slaves when the batman device went down
159 local slave
160 for slave in $(port_get_slaves "${port}"); do
161 port_remove "${slave}"
162 done
b8026986 163
1ba6a2bb
MT
164 exit ${EXIT_OK}
165 fi
b8026986
MT
166 ;;
167 esac
1ba6a2bb 168 exit ${EXIT_NOT_HANDLED}
b8026986 169}
e6993835 170
2181765d 171function hook_status() {
e6993835
MT
172 local port=${1}
173 assert isset port
174
175 cli_device_headline "${port}" --long
176
177 cli_headline 2 "B.A.T.M.A.N."
178
179 # Routing algorithm
180 cli_print_fmt1 2 "Routing Algorithm" \
181 "$(batman_adv_get_routing_algorithm "${port}")"
182
183 # Space
184 cli_space
185
186 # Originator interval
187 cli_print_fmt1 2 "Originator Interval" \
188 "$(batman_adv_get_originator_interval "${port}") ms"
189
190 # Aggregated originator messages
191 batman_adv_get_aggregated_ogms "${port}"
192 cli_print_fmt1 2 "Aggregated Originator Messages" "$(cli_print_bool $?)"
91987cc5 193
e6993835
MT
194 # AP isolation
195 batman_adv_get_ap_isolation "${port}"
196 cli_print_fmt1 2 "Access Point Isolation" "$(cli_print_bool $?)"
91987cc5 197
e6993835
MT
198 # Bonding mode
199 batman_adv_get_bonding_mode "${port}"
200 cli_print_fmt1 2 "Bonding Mode" "$(cli_print_bool $?)"
201
202 # Bridge loop avoidance
203 batman_adv_get_bridge_loop_avoidance "${port}"
204 cli_print_fmt1 2 "Bridge Loop Avoidance" "$(cli_print_bool $?)"
205
206 # Distributed ARP table
207 batman_adv_get_distributed_arp_table "${port}"
208 cli_print_fmt1 2 "Distributed ARP Table" "$(cli_print_bool $?)"
209
210 # Fragmentation
211 batman_adv_get_fragmentation "${port}"
212 cli_print_fmt1 2 "Fragmentation" "$(cli_print_bool $?)"
213
214 # Hop penalty
215 cli_print_fmt1 2 "Hop Penalty" \
216 "$(batman_adv_get_hop_penalty "${port}")"
217 cli_space
218
219 # Gateway
220 cli_headline 3 "Gateway"
221
222 # Gateway mode
223 batman_adv_get_gateway_mode "${port}"
224 local gw_enabled=$?
225
226 cli_print_fmt1 3 "Enabled" "$(cli_print_bool ${gw_enabled})"
227
228 if [ ${gw_enabled} -eq ${EXIT_TRUE} ]; then
229 cli_print_fmt1 3 "Bandwidth" \
230 "$(batman_adv_get_gateway_bandwidth "${port}")"
231 cli_print_fmt1 3 "Selection Class" \
232 "$(batman_adv_get_gateway_selection_class "${port}")"
91987cc5
MT
233 fi
234
e6993835
MT
235 cli_space
236
91987cc5
MT
237 exit ${EXIT_OK}
238}