]> git.ipfire.org Git - people/ms/network.git/commitdiff
Move creating port configurations into network-hotplug-rename
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 21 Sep 2018 21:58:01 +0000 (22:58 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 21 Sep 2018 21:58:01 +0000 (22:58 +0100)
This script is now actually creating a new configuration while
it is holding the lock.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/hooks/ports/ethernet
src/udev/network-hotplug
src/udev/network-hotplug-rename

index 18e9d57c35e10bfe366e875b6ad4e1892acc7c1c..cdc3dec7d2c7e98279a48604c4d5cb7d4c6b8d08 100644 (file)
@@ -106,7 +106,10 @@ hook_new() {
        local port="${1}"
        assert isset port
 
-       local DEVICE="$(device_get_address "${port}")"
+       local device="${2}"
+       assert isset device
+
+       local DEVICE="$(device_get_address "${device}")"
 
        if ! port_settings_write "${port}" ${HOOK_SETTINGS}; then
                log ERROR "Could not write settings for port ${port}"
index c94fa2a5e734e308cde87e7c41a323ea97414af6..af6c0df90e5173a6194488345f8e5a602a38a4a7 100644 (file)
@@ -80,17 +80,10 @@ case "${SUBSYSTEM}" in
                if ! port_exists "${INTERFACE}"; then
                        case "${ACTION}" in
                                add)
-                                       TYPE="$(device_get_type "${INTERFACE}")"
-
-                                       # If this is an Ethernet device, we will automatically create a new port
-                                       if [ "${TYPE}" = "ethernet" ]; then
-                                               port_new "ethernet" "${INTERFACE}"
-                                               exit $?
-                                       fi
-
                                        log WARNING "Got to hotplug event for a port which does not exist: ${INTERFACE}"
 
                                        # Try to remove the device again
+                                       TYPE="$(device_get_type "${INTERFACE}")"
                                        case "${TYPE}" in
                                                bonding)
                                                        bonding_remove "${INTERFACE}"
index ec417b663db853bd08b75cd40f12d1c12a07926d..25091649b608d5fe6c601a279b7045db1db805a6 100644 (file)
@@ -60,18 +60,22 @@ main() {
                        for port in $(ports_get_all); do
                                port_cmd hotplug_rename "${port}" "${INTERFACE}" &>/dev/null
                                if [ $? -eq ${EXIT_TRUE} ]; then
-                                       echo "${port}"
+                                       print "${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}"
+                       # Could not find a valid port configuration, creating a new one
+                       port="$(port_find_free "${PORT_PATTERN}")"
+                       assert isset port
 
-                       log DEBUG "Could not find an existing port configuration for '${INTERFACE}'"
-                       log DEBUG "Renaming interface '${INTERFACE}' to '${port}'"
+                       # Create a new port configuration with the new name
+                       if ! port_new "ethernet" "${port}" "${INTERFACE}"; then
+                               log ERROR "Could not create new port configuration for ${INTERFACE}"
+                               return ${EXIT_ERROR}
+                       fi
+
+                       print "${port}"
                        ;;
        esac