]> git.ipfire.org Git - people/stevee/network.git/commitdiff
Add automatic renaming of hotplugged devices.
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 3 Aug 2011 14:52:58 +0000 (14:52 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 3 Aug 2011 14:52:58 +0000 (14:52 +0000)
Fixes #183.

Makefile
functions.constants
functions.device
functions.ports
udev/network-hotplug-rename [new file with mode: 0755]
udev/rules.d/60-net.rules [new file with mode: 0644]

index 6f11b79c58c3f1b7c11852150fb648ec59c1bb24..0d86ce6d8e2a8d57038840c7b1091dbff8784b3f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -12,7 +12,7 @@ all:
 
 install:
        -mkdir -pv $(DESTDIR)/etc/{network,ppp}
-       -mkdir -pv $(DESTDIR)/lib/network
+       -mkdir -pv $(DESTDIR)/lib/{network,udev}
        -mkdir -pv $(DESTDIR)/sbin
        -mkdir -pv $(DESTDIR)/usr/lib/sysctl.d
        -mkdir -pv $(DESTDIR)/var/log/network
@@ -21,6 +21,7 @@ install:
 
        cp -rfv {hooks,header*,functions*} $(DESTDIR)/lib/network/
        cp -fv  sysctl.d/* $(DESTDIR)/usr/lib/sysctl.d/
+       cp -rfv udev/* $(DESTDIR)/lib/udev
 
        install -m 755 -v ppp/ip-updown $(DESTDIR)/etc/ppp
        ln -svf ip-updown $(DESTDIR)/etc/ppp/ip-pre-up
index bd2a41e8489c1a0a23d2e5a189ffacd18d9f907c..4f47c54a2dcd346a5c8953961b05370a1775780c 100644 (file)
@@ -72,3 +72,5 @@ SYS_CLASS_NET="/sys/class/net"
 TIMEOUT_RESTART=2
 
 DEVICE_PRINT_LINE1="    %-24s %s\n"
+
+PORT_PATTERN=portN
index 7367f642b7de3dbcafcc9ce8ec6b711fa660da6f..bb47baed3aa56709b3f55d0654bdb2495dc094f0 100644 (file)
@@ -558,18 +558,18 @@ function device_hotplug() {
        #assert device_exists ${device}
 
        if ! device_is_free ${device}; then
-               log ERROR "The device '${device}' does not look to be unused."
-               log ERROR "Don't proceed."
-       #       return ${EXIT_ERROR}
+               log ERROR "The device '${device}' is in use."
+               return ${EXIT_ERROR}
        fi
 
        for port in $(ports_get_all); do
                port_cmd hotplug ${port} ${device}
                if [ $? -eq ${EXIT_OK} ]; then
                        echo "${port}"
-                       exit ${EXIT_OK}
+                       return ${EXIT_OK}
                fi
        done
 
-       exit ${EXIT_ERROR}
+       port_find_free ${PORT_PATTERN}
+       return $?
 }
index 8aa4cac19eb6f27af17707035bf865e85b4ddb03..6460ab19fbda865cec4b46382345c2eecb45b6b5 100644 (file)
@@ -227,10 +227,12 @@ function port_find_free() {
                port=${pattern//N/${i}}
                if ! port_exists ${port} && ! device_exists ${port}; then
                        echo "${port}"
-                       break
+                       return ${EXIT_OK}
                fi
                i=$(( ${i} + 1 ))
        done
+
+       return ${EXIT_ERROR}
 }
 
 function port_get_info() {
diff --git a/udev/network-hotplug-rename b/udev/network-hotplug-rename
new file mode 100755 (executable)
index 0000000..3879d02
--- /dev/null
@@ -0,0 +1,31 @@
+#!/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
+
+# Check if the INTERFACE variable is properly set.
+assert isset INTERFACE
+
+# Get the name of that device from the configuration
+# or return a new one if it is unknown.
+device_hotplug ${INTERFACE}
+
+exit $?
diff --git a/udev/rules.d/60-net.rules b/udev/rules.d/60-net.rules
new file mode 100644 (file)
index 0000000..7c89ccf
--- /dev/null
@@ -0,0 +1,8 @@
+
+# Call a script that checks for the right name of the new device.
+# It is either renamed to match an existing configuration or gets
+# a new name.
+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"