]>
Commit | Line | Data |
---|---|---|
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 | ||
24 | HOOK_SETTINGS="HOOK ADDRESS SLAVES" | |
25 | ||
26 | PORT_CHILDREN_VAR="SLAVES" | |
27 | ||
28 | ADDRESS=$(mac_generate) | |
29 | SLAVES= | |
30 | ||
31 | function hook_check() { | |
32 | assert isset ADDRESS | |
33 | assert ismac ADDRESS | |
34 | } | |
35 | ||
36 | function hook_create() { | |
37 | while [ $# -gt 0 ]; do | |
38 | case "${1}" in | |
39 | --address=*) | |
40 | ADDRESS="$(cli_get_val ${1})" | |
41 | ;; | |
42 | --slaves=*) | |
43 | SLAVES="$(cli_get_val ${1})" | |
44 | ;; | |
45 | *) | |
46 | warning "Ignoring unknown argument '${1}'" | |
47 | ;; | |
48 | esac | |
49 | shift | |
50 | done | |
51 | ||
52 | local port=$(port_find_free ${PORT_PATTERN_BATMAN_ADV}) | |
53 | assert isset port | |
54 | ||
55 | config_write $(port_file ${port}) ${HOOK_SETTINGS} | |
56 | ||
57 | exit ${EXIT_OK} | |
58 | } | |
59 | ||
60 | function hook_edit() { | |
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 | |
69 | --address=*) | |
70 | ADDRESS="$(cli_get_val ${1})" | |
71 | ;; | |
72 | --add-slave=*) | |
73 | SLAVES="${SLAVES} $(cli_get_val ${1})" | |
74 | ;; | |
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}" | |
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 | ||
97 | function hook_up() { | |
98 | local port=${1} | |
99 | assert isset port | |
100 | ||
101 | config_read $(port_file ${port}) | |
102 | ||
103 | # This cannot be started manually, but is created automatically | |
104 | # when a slave device is brought up and set up by _hotplug. | |
105 | ||
106 | local slave | |
107 | for slave in ${SLAVES}; do | |
108 | port_up "${slave}" | |
109 | done | |
110 | ||
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}" | |
116 | ||
117 | device_set_up "${port}" | |
118 | fi | |
119 | ||
120 | exit ${EXIT_OK} | |
121 | } | |
122 | ||
123 | function hook_down() { | |
124 | local port=${1} | |
125 | assert isset port | |
126 | ||
127 | config_read $(port_file ${port}) | |
128 | ||
129 | local slave | |
130 | for slave in ${SLAVES}; do | |
131 | port_down "${slave}" | |
132 | done | |
133 | ||
134 | exit ${EXIT_OK} | |
135 | } | |
136 | ||
137 | function hook_hotplug() { | |
138 | local port=${1} | |
139 | assert isset port | |
140 | ||
141 | local phy=${2} | |
142 | assert isset phy | |
143 | ||
144 | # Bring up the device. | |
145 | port_up "${port}" | |
146 | ||
147 | exit ${EXIT_OK} | |
148 | } | |
149 | ||
150 | function hook_status() { | |
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 $?)" | |
172 | ||
173 | # AP isolation | |
174 | batman_adv_get_ap_isolation "${port}" | |
175 | cli_print_fmt1 2 "Access Point Isolation" "$(cli_print_bool $?)" | |
176 | ||
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}")" | |
212 | fi | |
213 | ||
214 | cli_space | |
215 | ||
216 | exit ${EXIT_OK} | |
217 | } |