]> git.ipfire.org Git - people/ms/network.git/commitdiff
Move all of the device renaming code to network-hotplug-rename.
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 27 May 2012 12:07:06 +0000 (12:07 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 27 May 2012 12:07:06 +0000 (12:07 +0000)
The port hooks get an additional method called _hotplug() which
handles the actual hotplugging stuff.
To rename devices, there is now the _hotplug_rename() function
which returns either EXIT_TRUE or EXIT_FALSE.

functions.constants
functions.device
header-port
hooks/ports/ethernet
udev/network-hotplug-rename

index 52f35649df0b17857d92047cf21ee50b56582df3..56baa6e398dbb3258f9d00bc69f2ea5ec198e4c5 100644 (file)
@@ -50,6 +50,9 @@ EXIT_ERROR=1
 EXIT_CONF_ERROR=2
 EXIT_ERROR_ASSERT=3
 
+EXIT_TRUE=0
+EXIT_FALSE=1
+
 STATUS_UP=0
 STATUS_DOWN=1
 STATUS_NOCARRIER=2
index f0dd1330fffaa2fb5fd9eda6a5ed094d4db06edb..3c1005dbee1fa3077e33ccbaa2c3898a0a97b476 100644 (file)
@@ -568,41 +568,3 @@ function device_get_tx_errors() {
 
        __device_get_file ${device} statistics/tx_errors
 }
-
-function device_hotplug() {
-       local device=${1}
-       shift
-
-       assert isset device
-
-       # Just check if the device has already vanished.
-       device_exists ${device} || return ${EXIT_ERROR}
-
-       if ! device_is_free ${device}; then
-               log ERROR "The device '${device}' is in use."
-               return ${EXIT_ERROR}
-       fi
-
-       if ! device_is_real ${device}; then
-               log DEBUG "Don't rename any virtual devices."
-               return ${EXIT_OK}
-       fi
-
-       for port in $(ports_get_all); do
-               port_cmd hotplug ${port} ${device}
-               if [ $? -eq ${EXIT_OK} ]; then
-                       echo "${port}"
-                       return ${EXIT_OK}
-               fi
-       done
-
-       # If no port configuration could be found, we search for the next
-       # unused name and return that.
-       local port=$(port_find_free ${PORT_PATTERN})
-
-       log DEBUG "Could not find an existing port configuration for '${device}'."
-       log DEBUG "${device} --> ${port}"
-
-       echo "${port}"
-       return ${EXIT_OK}
-}
index bb319a4fec4f13141ba94cb038c8f25781d8fe2a..bb169174c6efcf829436bea74877999b78c32def 100644 (file)
@@ -19,7 +19,7 @@
 #                                                                             #
 ###############################################################################
 
-. /lib/network/functions
+. /usr/lib/network/functions
 
 HOOK=$(basename ${0})
 INFO_SETTINGS="HOOK PORT_PARENTS PORT_CHILDREN"
@@ -40,7 +40,7 @@ done
 
 function run() {
        case "${action}" in
-               edit|add|create|rem|up|down|status|info|hotplug)
+               edit|add|create|rem|up|down|status|info|hotplug|hotplug_rename)
                        _${action} $@
                        ;;
        esac
@@ -49,8 +49,21 @@ function run() {
        exit ${EXIT_ERROR}
 }
 
+# This function is called after a device has been plugged
+# into the system and got its correct name.
+# The function is intended to create child ports and things
+# like that.
 function _hotplug() {
-       exit ${EXIT_ERROR}
+       exit ${EXIT_OK}
+}
+
+# This function gets called when a device is plugged in
+# to determine the right name.
+# The first argument is the port which should be tested
+# against the second argument which is the device that
+# has been plugged in.
+function _hotplug_rename() {
+       exit ${EXIT_FALSE}
 }
 
 function _info() {
index 499889adc84e66f3646f7965dfe0962e68f27352..5d93fc81caae86e251f26ab96d176ea96c18edbd 100755 (executable)
@@ -60,7 +60,7 @@ function _down() {
        exit ${EXIT_OK}
 }
 
-function _hotplug() {
+function _hotplug_rename() {
        local port=${1}
        local device=${2}
 
index 1678deb61dfb8e7cc7e38e66807e555f1e55c863..0d3767d997ee2bef562bcbcf817f0ea564d6c1d7 100755 (executable)
@@ -38,11 +38,44 @@ assert isset INTERFACE
 # Log what we are doing here.
 log DEBUG "Called for interface '${INTERFACE}'."
 
+# Just check if the device has already vanished.
+device_exists ${INTERFACE} || exit ${EXIT_ERROR}
+
 # Acquiring lock for this operation.
 lock_acquire ${LOCKFILE}
 
-# Get the name of that device from the configuration
-# or return a new one if it is unknown.
-device_hotplug ${INTERFACE}
+# Check if the device is already in use and
+# prevent the script to touch it in any way.
+if ! device_is_free ${INTERFACE}; then
+       log ERROR "The device '${INTERFACE}' is in use."
+       exit ${EXIT_ERROR}
+fi
+
+# Determine the type of the device and then see what
+# we need to do with it.
+type=$(device_get_type ${INTERFACE})
+log DEBUG "Interface '${INTERFACE}' is of type '${type}'."
+
+case "${type}" in
+       ethernet|real)
+               # Search within all the port configurations
+               # if this port has already been configured.
+               for port in $(ports_get_all); do
+                       port_cmd hotplug_rename ${port} ${INTERFACE} &>/dev/null
+                       if [ $? -eq ${EXIT_TRUE} ]; then
+                               echo "${port}"
+                               exit ${EXIT_OK}
+                       fi
+               done
+
+               # If no port configuration could be found,
+               # we search for the next unused name and return that.
+               port=$(port_find_free ${PORT_PATTERN})
+               echo "${port}"
+
+               log DEBUG "Could not find an existing port configuration for '${INTERFACE}'."
+               log DEBUG "${INTERFACE} --> ${port}"
+               ;;
+esac
 
-exit $?
+exit ${EXIT_OK}