]> git.ipfire.org Git - people/ms/network.git/commitdiff
Add hotplugging for ethernet devices.
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 3 Aug 2011 17:17:24 +0000 (17:17 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 3 Aug 2011 17:17:45 +0000 (17:17 +0000)
functions.colors
functions.ports
functions.util
functions.zone
udev/network-hotplug [new file with mode: 0755]
udev/rules.d/60-net.rules

index f0da0b4c8d64328f5d47356a1b926c0edbaa7eab..d3a6e2c152e9c3d330ca0783148edfb1ed894951 100644 (file)
@@ -45,10 +45,18 @@ COLOUR_STP_DISCARDING=${COLOUR_RED}
 COLOUR_STP_LEARNING=${COLOUR_YELLOW}
 COLOUR_STP_BLOCKING=${COLOUR_YELLOW}
 
+COLOUR_VARIABLES="COLOUR_GREEN COLOUR_RED COLOUR_NORMAL COLOUR_YELLOW"
+COLOUR_VARIABLES="${COLOUR_VARIABLES} COLOUR_BOLD COLOUR_DOWN COLOUR_ERROR"
+COLOUR_VARIABLES="${COLOUR_VARIABLES} COLOUR_ERROR COLOUR_OK COLOUR_UP"
+COLOUR_VARIABLES="${COLOUR_VARIABLES} COLOUR_WARM COLOUR_ENABLED COLOUR_DISABLED"
+COLOUR_VARIABLES="${COLOUR_VARIABLES} COLOUR_LOG COLOUR_STP_FORWARDING"
+COLOUR_VARIABLES="${COLOUR_VARIABLES} COLOUR_STP_DISCARDING COLOUR_STP_LEARNING"
+COLOUR_VARIABLES="${COLOUR_VARIABLES} COLOUR_STP_BLOCKING"
+
 function colours_disable() {
        local line
-       for line in $(set | grep "^COLOUR_"); do
-               unset ${line%%=*}
+       for line in ${COLOUR_VARIABLES}; do
+               unset ${line}
        done
 }
 
index 6460ab19fbda865cec4b46382345c2eecb45b6b5..cb247a165ae64adcd547419bb6168d4d15129f35 100644 (file)
@@ -260,3 +260,21 @@ function port_get_children() {
 
        port_get_info ${port} PORT_CHILDREN
 }
+
+function port_zone() {
+       # Get name of the zones, this port is configured in.
+       local port=${1}
+       shift
+
+       assert isset port
+
+       local zone
+       for zone in $(zones_get_all); do
+               if zone_has_port ${zone} ${port}; then
+                       echo "${zone}"
+                       return ${EXIT_OK}
+               fi
+       done
+
+       return ${EXIT_OK}
+}
index fa9005f6ba57d5fea1b4b7d30bdfcecd92f2a116..7da58f7acbe97d67e2988498d92c6daffa5b3267 100644 (file)
@@ -444,3 +444,8 @@ function dec() {
 
        printf "%d\n" "${hex}"
 }
+
+function network_is_running() {
+       # Check, if the network service is running.
+       service_is_active network
+}
index 31c66fb15dd86486f6531ed794a32518ca9eece0..79c6e0c060804b2fd16ac30b44dbbfb1bab6ca31 100644 (file)
@@ -321,6 +321,20 @@ function zone_get_ports() {
        done
 }
 
+function zone_has_port() {
+       # Check, if the given port is configured
+       # in this zone.
+
+       local zone=${1}
+       local port=${2}
+       shift 2
+
+       assert isset zone
+       assert isset port
+
+       [ -e "$(zone_dir ${zone})/ports/${port}" ]
+}
+
 # XXX overwritten some lines below
 function zone_config() {
        local zone=${1}
@@ -374,6 +388,24 @@ function zone_config() {
        esac
 }
 
+function zone_config_option() {
+       local zone=${1}
+       local option=${2}
+       local default=${3}
+       shift 2
+
+       assert isset zone
+       assert isset option
+
+       (
+               VALUE="${default}"
+               zone_config_read ${zone}
+
+               VALUE="${!option}"
+               echo "${VALUE}"
+       )
+}
+
 function zone_config_create() {
        local zone=${1}
        shift
diff --git a/udev/network-hotplug b/udev/network-hotplug
new file mode 100755 (executable)
index 0000000..d4a76cb
--- /dev/null
@@ -0,0 +1,70 @@
+#!/bin/bash
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2011  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/>.       #
+#                                                                             #
+###############################################################################
+
+. /lib/network/functions
+
+# Do nothing, if the network isn't running.
+# That happens for example on boot time.
+if ! network_is_running; then
+       exit 0
+fi
+
+# Check if the udev environment variables are properly set.
+assert isset ACTION
+assert isset INTERFACE
+
+# Check, if the device is a physical network interface and
+# if we can handle it.
+if ! device_is_real ${INTERFACE}; then
+       exit ${EXIT_OK}
+fi
+
+# Check, if there is a configuration for that device.
+if port_exists ${INTERFACE}; then
+       port=${INTERFACE}
+
+else
+       # If the given device was not configured,
+       # we create an initial configuration.
+       port_create ethernet ${INTERFACE}
+       exit ${EXIT_OK}
+fi
+
+case "${ACTION}" in
+       add|register)
+               zone=$(port_zone ${port})
+
+               # Check, if the device is configured in a zone.
+               # If not, there is nothing to do.
+               isset zone || exit ${EXIT_OK}
+
+               boot=$(zone_config_option ${zone} BOOT)
+               if enabled boot; then
+                       zone_up ${zone}
+               fi
+               ;;
+
+       remove|unregister)
+               port_down ${port}
+               ;;
+esac
+
+exit ${EXIT_OK}
index 7c89ccf1cd3908ad839081fee2631792162d00ce..6d7bc0b3290327b2ecb288c5e4fc4da34c25d968 100644 (file)
@@ -5,4 +5,4 @@
 ACTION=="add", SUBSYSTEM=="net", PROGRAM="/lib/udev/network-hotplug-rename", RESULT=="?*", ENV{INTERFACE_NAME}="$result"
 
 # Handle all plugged-in devices.
-#SUBSYSTEM=="net", RUN+="/lib/udev/network-hotlug"
+SUBSYSTEM=="net", RUN+="/lib/udev/network-hotplug"