]> git.ipfire.org Git - people/stevee/network.git/blobdiff - src/hooks/zones/bridge.ports/ethernet
Use autotools.
[people/stevee/network.git] / src / hooks / zones / bridge.ports / ethernet
diff --git a/src/hooks/zones/bridge.ports/ethernet b/src/hooks/zones/bridge.ports/ethernet
new file mode 100755 (executable)
index 0000000..1b7d92b
--- /dev/null
@@ -0,0 +1,165 @@
+#!/bin/bash
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2010  Michael Tremer & Christian Schmidt                      #
+#                                                                             #
+# 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_SETTINGS="COST PRIORITY"
+
+function hook_check() {
+       local i
+       for i in COST PRIORITY; do
+               if isset ${i}; then
+                       assert isinteger ${i}
+               fi
+       done
+}
+
+function hook_add() {
+       local zone=${1}
+       local port=${2}
+       shift 2
+
+       assert isset zone
+       assert isset port
+
+       if ! port_exists ${port}; then
+               error "Port '${port}' does not exist."
+               exit ${EXIT_ERROR}
+       fi
+
+       config_read $(zone_dir ${zone})/ports/${port}
+
+       while [ $# -gt 0 ]; do
+               case "${1}" in
+                       --priority=*)
+                               PRIORITY=${1#--priority=}
+                               ;;
+                       --cost=*)
+                               COST=${1#--cost=}
+                               ;;
+               esac
+               shift
+       done
+
+       config_write $(zone_dir ${zone})/ports/${port} ${HOOK_SETTINGS}
+
+       exit ${EXIT_OK}
+}
+
+function hook_edit() {
+       hook_add $@
+}
+
+function hook_remove() {
+       local zone=${1}
+       local port=${2}
+
+       assert isset zone
+       assert isset port
+
+       assert zone_exists ${zone}
+
+       if ! listmatch ${port} $(zone_get_ports ${zone}); then
+               error "Port '${port}' does not belong to '${zone}'."
+               error "Won't remove anything."
+               exit ${EXIT_ERROR}
+       fi
+
+       if port_exists ${port}; then
+               ( _down ${zone} ${port} )
+       fi
+
+       rm -f $(zone_dir ${zone})/ports/${port}
+
+       exit ${EXIT_OK}
+}
+
+function hook_up() {
+       local zone=${1}
+       local port=${2}
+
+       assert isset zone
+       assert isset port
+
+       assert zone_exists ${zone}
+       assert port_exists ${port}
+
+       port_up ${port}
+
+       # Set same MTU to device that the bridge has got
+       device_set_mtu ${port} $(device_get_mtu ${zone})
+
+       bridge_attach_device ${zone} ${port}
+
+       # XXX must set cost and prio here
+
+       exit ${EXIT_OK}
+}
+
+function hook_down() {
+       local zone=${1}
+       local port=${2}
+
+       assert isset zone
+       assert isset port
+
+       assert zone_exists ${zone}
+       assert port_exists ${port}
+
+       bridge_detach_device ${zone} ${port}
+
+       port_down ${port}
+
+       exit ${EXIT_OK}
+}
+
+function hook_status() {
+       local zone=${1}
+       local port=${2}
+
+       # Do nothing for devices which are not up and running.
+       device_exists ${port} || exit ${EXIT_OK}
+
+       local status
+
+       # Check if the device is down.
+       if ! device_is_up ${port}; then
+               status=${MSG_DEVICE_STATUS_DOWN}
+
+       # Check if the device has no carrier.
+       elif ! device_has_carrier ${port}; then
+               status=${MSG_DEVICE_STATUS_NOCARRIER}
+
+       # Check for STP information.
+       elif stp_is_enabled ${zone}; then
+               local state=$(stp_port_get_state ${zone} ${port})
+               state="MSG_STP_${state}"
+               status="${!state}"
+
+               status="${status} - DSR: $(stp_port_get_designated_root ${zone} ${port})"
+               status="${status} - Cost: $(stp_port_get_cost ${zone} ${port})"
+       else
+               status=${MSG_DEVICE_STATUS_UP}
+       fi
+       cli_statusline 3 "${port}" "${status}"
+
+       exit ${EXIT_OK}
+}