]> git.ipfire.org Git - people/stevee/network.git/blame - src/hooks/ports/batman-adv
Remove executable permissions from source files.
[people/stevee/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
2181765d 31function hook_check() {
91987cc5
MT
32 assert isset ADDRESS
33 assert ismac ADDRESS
91987cc5
MT
34}
35
2181765d 36function 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
55 config_write $(port_file ${port}) ${HOOK_SETTINGS}
56
57 exit ${EXIT_OK}
58}
59
2181765d 60function hook_edit() {
91987cc5
MT
61 local port=${1}
62 assert isset port
63 shift
64
65 config_read $(port_file ${port})
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
92 config_write $(port_file ${port}) ${HOOK_SETTINGS}
93
94 exit ${EXIT_OK}
95}
96
2181765d 97function hook_up() {
91987cc5
MT
98 local port=${1}
99 assert isset port
100
101 config_read $(port_file ${port})
102
e6993835
MT
103 # This cannot be started manually, but is created automatically
104 # when a slave device is brought up and set up by _hotplug.
91987cc5 105
e6993835
MT
106 local slave
107 for slave in ${SLAVES}; do
108 port_up "${slave}"
109 done
91987cc5 110
e6993835
MT
111 # If the port has been created (does not happen, when there are
112 # no slaves), we bring it up.
113 if device_exists "${port}"; then
114 # Set the address.
115 device_set_address "${port}" "${ADDRESS}"
91987cc5 116
e6993835
MT
117 device_set_up "${port}"
118 fi
91987cc5
MT
119
120 exit ${EXIT_OK}
121}
122
2181765d 123function hook_down() {
91987cc5
MT
124 local port=${1}
125 assert isset port
126
e6993835 127 config_read $(port_file ${port})
91987cc5 128
e6993835
MT
129 local slave
130 for slave in ${SLAVES}; do
131 port_down "${slave}"
132 done
91987cc5
MT
133
134 exit ${EXIT_OK}
135}
136
2181765d 137function hook_hotplug() {
91987cc5
MT
138 local port=${1}
139 assert isset port
140
141 local phy=${2}
142 assert isset phy
143
e6993835
MT
144 # Bring up the device.
145 port_up "${port}"
91987cc5 146
e6993835
MT
147 exit ${EXIT_OK}
148}
149
2181765d 150function hook_status() {
e6993835
MT
151 local port=${1}
152 assert isset port
153
154 cli_device_headline "${port}" --long
155
156 cli_headline 2 "B.A.T.M.A.N."
157
158 # Routing algorithm
159 cli_print_fmt1 2 "Routing Algorithm" \
160 "$(batman_adv_get_routing_algorithm "${port}")"
161
162 # Space
163 cli_space
164
165 # Originator interval
166 cli_print_fmt1 2 "Originator Interval" \
167 "$(batman_adv_get_originator_interval "${port}") ms"
168
169 # Aggregated originator messages
170 batman_adv_get_aggregated_ogms "${port}"
171 cli_print_fmt1 2 "Aggregated Originator Messages" "$(cli_print_bool $?)"
91987cc5 172
e6993835
MT
173 # AP isolation
174 batman_adv_get_ap_isolation "${port}"
175 cli_print_fmt1 2 "Access Point Isolation" "$(cli_print_bool $?)"
91987cc5 176
e6993835
MT
177 # Bonding mode
178 batman_adv_get_bonding_mode "${port}"
179 cli_print_fmt1 2 "Bonding Mode" "$(cli_print_bool $?)"
180
181 # Bridge loop avoidance
182 batman_adv_get_bridge_loop_avoidance "${port}"
183 cli_print_fmt1 2 "Bridge Loop Avoidance" "$(cli_print_bool $?)"
184
185 # Distributed ARP table
186 batman_adv_get_distributed_arp_table "${port}"
187 cli_print_fmt1 2 "Distributed ARP Table" "$(cli_print_bool $?)"
188
189 # Fragmentation
190 batman_adv_get_fragmentation "${port}"
191 cli_print_fmt1 2 "Fragmentation" "$(cli_print_bool $?)"
192
193 # Hop penalty
194 cli_print_fmt1 2 "Hop Penalty" \
195 "$(batman_adv_get_hop_penalty "${port}")"
196 cli_space
197
198 # Gateway
199 cli_headline 3 "Gateway"
200
201 # Gateway mode
202 batman_adv_get_gateway_mode "${port}"
203 local gw_enabled=$?
204
205 cli_print_fmt1 3 "Enabled" "$(cli_print_bool ${gw_enabled})"
206
207 if [ ${gw_enabled} -eq ${EXIT_TRUE} ]; then
208 cli_print_fmt1 3 "Bandwidth" \
209 "$(batman_adv_get_gateway_bandwidth "${port}")"
210 cli_print_fmt1 3 "Selection Class" \
211 "$(batman_adv_get_gateway_selection_class "${port}")"
91987cc5
MT
212 fi
213
e6993835
MT
214 cli_space
215
91987cc5
MT
216 exit ${EXIT_OK}
217}