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}"
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}"
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