]> git.ipfire.org Git - people/stevee/network.git/commitdiff
Add port hook for wireless mesh devices after 802.11s
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 15 Aug 2017 21:04:37 +0000 (21:04 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 15 Aug 2017 21:04:37 +0000 (21:04 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/functions/functions.constants
src/hooks/ports/wireless-mesh [new file with mode: 0644]

index ce9b9e2a018fbd8f2337697b006677bbbca23be0..edd6dc493f40bbbd38f20cfa552d772206388856 100644 (file)
@@ -213,7 +213,8 @@ dist_hooks_ports_SCRIPTS = \
        src/hooks/ports/ethernet \
        src/hooks/ports/vlan \
        src/hooks/ports/wireless-adhoc \
-       src/hooks/ports/wireless-ap
+       src/hooks/ports/wireless-ap \
+       src/hooks/ports/wireless-mesh
 
 dist_hooks_zones_SCRIPTS = \
        src/hooks/zones/6to4-tunnel \
index ab087d7a96cc26f6aca97ec5dc888ff2cfcb935a..91e5ffcf7b024c64eb76b5508336e17d02576c54 100644 (file)
@@ -104,6 +104,7 @@ DEVICE_PRINT_LINE1="    %-24s %s\n"
 PORT_PATTERN="pN"
 PORT_PATTERN_ACCESSPOINT="apN"
 PORT_PATTERN_BATMAN_ADV="batN"
+PORT_PATTERN_MESH="mN"
 PORT_PATTERN_WIRELESS="wN"
 PORT_PATTERN_WIRELESS_ADHOC="adhocN"
 PORT_PATTERN_WIRELESS_MONITOR="wmonN"
diff --git a/src/hooks/ports/wireless-mesh b/src/hooks/ports/wireless-mesh
new file mode 100644 (file)
index 0000000..813777a
--- /dev/null
@@ -0,0 +1,132 @@
+#!/bin/bash
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2017 Michael Tremer                                           #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+. /usr/lib/network/header-port
+
+HOOK_PORT_PATTERN="${PORT_PATTERN_MESH}"
+
+HOOK_SETTINGS="HOOK ADDRESS MESH_ID CHANNEL PHY"
+
+hook_check_settings() {
+       assert ismac ADDRESS
+       assert isset MESH_ID
+       assert isset CHANNEL
+       assert isset PHY
+       assert ismac PHY
+}
+
+hook_parse_cmdline() {
+       while [ $# -gt 0 ]; do
+               case "${1}" in
+                       --address=*)
+                               ADDRESS=$(cli_get_val "${1}")
+                               ;;
+                       --channel=*)
+                               CHANNEL=$(cli_get_val "${1}")
+                               ;;
+                       --mesh-id=*)
+                               MESH_ID=$(cli_get_val "${1}")
+                               ;;
+                       --phy=*)
+                               PHY=$(cli_get_val "${1}")
+                               ;;
+                       *)
+                               warning "Ignoring unknown argument '${1}'"
+                               ;;
+               esac
+               shift
+       done
+
+       if ! isset MESH_ID; then
+               error "Please pass a mesh ID"
+               return ${EXIT_ERROR}
+       fi
+
+       # Save address of phy do identify it again
+       PHY=$(phy_get ${PHY})
+       PHY=$(phy_get_address ${PHY})
+
+       # Generate a MAC address if none given
+       if ! isset ADDRESS; then
+               ADDRESS=$(mac_generate)
+       fi
+
+       # XXX check if wireless channel is valid
+}
+
+hook_create() {
+       local port="${1}"
+       assert isset port
+
+       # Read settings
+       port_settings_read "${port}" ${HOOK_SETTINGS}
+
+       # Check if the PHY is present.
+       local phy="$(phy_get "${PHY}")"
+       if ! isset phy; then
+               log DEBUG "phy '${PHY}' is not present"
+               return ${EXIT_ERROR}
+       fi
+
+       # Create the wireless device, if it does not exist, yet.
+       if ! device_exists "${port}"; then
+               wireless_create "${port}" \
+                       --address="${ADDRESS}" \
+                       --channel="${CHANNEL}" \
+                       --phy="${phy}" \
+                       --type="mesh-point" || return $?
+       fi
+
+       return ${EXIT_OK}
+}
+
+hook_remove() {
+       local port="${1}"
+       assert isset port
+
+       if device_exists "${port}"; then
+               wireless_remove "${port}"
+       fi
+
+       exit ${EXIT_OK}
+}
+
+hook_hotplug() {
+       local port="${1}"
+       assert isset port
+
+       port_settings_read "${port}" ${HOOK_SETTINGS}
+
+       case "$(hotplug_action)" in
+               add)
+                       # Bring up the port when the phy is plugged in
+                       if hotplug_event_port_uses_phy "${port}"; then
+                               hook_create "${port}" || exit $?
+                       fi
+                       ;;
+
+               *)
+                       exit ${EXIT_NOT_HANDLED}
+                       ;;
+       esac
+
+       exit ${EXIT_OK}
+}