]> git.ipfire.org Git - people/ms/network.git/commitdiff
hotplug: Remove multiple copies of the same function
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 30 Mar 2019 13:58:12 +0000 (14:58 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 30 Mar 2019 13:58:12 +0000 (14:58 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/header-port
src/hooks/ports/dummy
src/hooks/ports/ethernet
src/hooks/ports/ip-tunnel

index 2d8a8200a5e4b84f8eaf15b0b00f62c512555587..d75fdd86240b7bc344202c1ab794288951c56cf9 100644 (file)
@@ -42,6 +42,32 @@ hook_hotplug_rename() {
        exit ${EXIT_FALSE}
 }
 
+hook_hotplug_rename_by_address() {
+       local port="${1}"
+       assert isset port
+
+       local device="${2}"
+       assert isset device
+
+       # Read in the conifguration file.
+       if ! port_settings_read "${port}"; then
+               return ${EXIT_ERROR}
+       fi
+
+       # Get the current MAC address of the device.
+       local address="$(device_get_address "${device}")"
+       assert isset address
+
+       # Check if the address matches with the configuration.
+       if list_match "${address}" "${ADDRESS}" "${DEVICE}"; then
+               log DEBUG "Device '${device}' is port '${port}'"
+               return ${EXIT_OK}
+       fi
+
+       log DEBUG "Device '${device}' is not port '${port}'"
+       return ${EXIT_ERROR}
+}
+
 hook_default_new() {
        local ${HOOK_SETTINGS[*]}
 
index 387c88b560b3459f412ac9efbd3d1390fc3420e9..36888319439cb8cb504c866f099c8b8fad21f084 100644 (file)
@@ -90,40 +90,6 @@ hook_remove() {
        dummy_remove "${port}"
 }
 
-hook_up() {
-       local port="${1}"
-       assert isset port
-
-       # Bring up the port.
-       device_set_up ${port}
-
-       exit ${EXIT_OK}
-}
-
-hook_down() {
-       local port="${1}"
-       assert isset port
-
-       # Tear down the port.
-       device_set_down ${port}
-
-       exit ${EXIT_OK}
-}
-
 hook_hotplug_rename() {
-       local port=${1}
-       assert isset port
-
-       local device=${2}
-       assert isset device
-
-       port_settings_read "${port}"
-
-       if [ "${ADDRESS}" = "$(device_get_address ${device})" ]; then
-               log DEBUG "Device '${device}' equals port '${port}'."
-               exit ${EXIT_OK}
-       fi
-
-       log DEBUG "Device '${device}' does not equal port '${port}'."
-       exit ${EXIT_ERROR}
+       hook_hotplug_rename_by_address "$@"
 }
index 5f76e1588baf1ed80a6dae1e8bed8ff4bd87dd43..82664fa15376198d712e1fed7267d0025a2d21be 100644 (file)
@@ -173,25 +173,5 @@ hook_remove() {
 }
 
 hook_hotplug_rename() {
-       local port=${1}
-       assert isset port
-
-       local device=${2}
-       assert isset device
-
-       # Read in the conifguration file.
-       port_settings_read "${port}"
-
-       # Get the current MAC address of the device.
-       local address=$(device_get_address ${device})
-       assert isset address
-
-       # Check if the address matches with the configuration.
-       if list_match "${address}" ${DEVICE} ${ADDRESS}; then
-               log DEBUG "Device '${device}' equals port '${port}'."
-               exit ${EXIT_OK}
-       fi
-
-       log DEBUG "Device '${device}' does not equal port '${port}'."
-       exit ${EXIT_ERROR}
+       hook_hotplug_rename_by_address "$@"
 }
index fa7193ca1566b92513032e6d05e94d5a5e05dfe0..482511ea2c1147196a67ea3e8c0478f336ca4719 100644 (file)
@@ -146,26 +146,5 @@ hook_remove() {
 }
 
 hook_hotplug_rename() {
-       local port="${1}"
-       assert isset port
-
-       local device="${2}"
-       assert isset device
-
-       local ${HOOK_SETTINGS[*]}
-       if ! port_settings_read "${port}"; then
-               log ERROR "Could not read settings for port ${port}"
-               return ${EXIT_ERROR}
-       fi
-
-       # Get the current MAC address of the device.
-       local address="$(device_get_address ${device})"
-       assert isset address
-
-       # Return OK on match
-       if [ "${ADDRESS}" = "${address}" ]; then
-               return ${EXIT_OK}
-       fi
-
-       return ${EXIT_ERROR}
+       hook_hotplug_rename_by_address "$@"
 }