]>
git.ipfire.org Git - people/ms/network.git/blob - src/hooks/ports/batman-adv-port
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2013 Michael Tremer #
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. #
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. #
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/>. #
20 ###############################################################################
22 .
/usr
/lib
/network
/header-port
24 HOOK_SETTINGS
="HOOK ADDRESS MESH_ID SSID CHANNEL PHY"
26 ADDRESS
=$
(mac_generate
)
32 # batman-adv inserts an additional header of 28 bytes, so we set the MTU
33 # to 1560, that normal ethernet packets with 1500 bytes can pass the network.
36 function hook_check
() {
47 function hook_create
() {
48 while [ $# -gt 0 ]; do
51 ADDRESS
=$
(cli_get_val
${1})
54 CHANNEL
=$
(cli_get_val
${1})
57 PHY
=$
(cli_get_val
${1})
60 SSID
=$
(cli_get_val
${1})
63 MESH_ID
=$
(cli_get_val
${1})
66 warning
"Ignoring unknown argument '${1}'"
72 # Save address of phy do identify it again
74 PHY
=$
(phy_get_address
${PHY})
76 local port
=$
(port_find_free
${PORT_PATTERN_BATMAN_ADV_PORT})
79 port_settings_write
"${port}" ${HOOK_SETTINGS}
84 function hook_edit
() {
89 port_settings_read
"${port}" ${HOOK_SETTINGS}
91 while [ $# -gt 0 ]; do
94 CHANNEL
=$
(cli_get_val
${1})
97 MESH_ID
=$
(cli_get_val
${1})
100 SSID
=$
(cli_get_val
${1})
103 warning
"Unknown argument '${1}'"
109 port_settings_write
"${port}" ${HOOK_SETTINGS}
118 port_settings_read
"${port}" ${HOOK_SETTINGS}
120 # Check if the PHY is present.
121 local phy
=$
(phy_get
${PHY})
123 log DEBUG
"phy '${PHY}' is not present"
127 # Create the wireless device, if it does not exist, yet.
128 if ! device_exists
${port}; then
129 wireless_create
${port} \
130 --address="${ADDRESS}" \
136 device_set_mtu
"${port}" "${MTU}"
138 # Join the ad-hoc network.
139 wireless_ibss_join
"${port}" --channel="${CHANNEL}" \
140 --bssid="${MESH_ID}" --essid="${SSID}"
142 # Add the device as a batman-adv device.
143 local parent
="$(hook_find_parent ${port})"
144 if isset parent
; then
145 batman_adv_interface_add
"${parent}" "${port}"
151 function hook_down
() {
155 # Remove the batman-adv device.
156 batman_adv_interface_del
"${port}"
158 # Leave the ad-hoc network.
159 wireless_ibss_leave
"${port}"
161 # Remove the device if it is still present.
162 if device_exists
${port}; then
163 wireless_remove
${port}
169 function hook_hotplug
() {
176 assert port_exists
${port}
178 # Read configuration of port.
179 port_settings_read
"${port}" ${HOOK_SETTINGS}
181 # Get the address of the phy.
182 local phy_address
=$
(phy_get_address
"${phy}")
184 # Check if the phy is the same we have
185 # read from the configuration file.
186 if [ "${PHY}" = "${phy_address}" ]; then
187 # Bring up the device.
193 exit ${EXIT_NOT_HANDLED}
196 function hook_find_parent
() {
201 for p
in $
(ports_get
); do
202 hook
=$
(port_get_hook
"${p}")
204 if [ "${hook}" = "batman-adv" ]; then
205 for child
in $
(port_get_children
"${p}"); do
206 [ "${child}" = "${port}" ] ||
continue