+ # Execute the default action
+ hook_default_down "${port}"
+}
+
+function hook_hotplug() {
+ local port="${1}"
+ assert isset port
+
+ case "$(hotplug_action)" in
+ add)
+ # Handle events of the same interface
+ if hotplug_event_port_is_interface "${port}"; then
+ # Read configuration
+ port_settings_read "${port}" ${HOOK_SETTINGS}
+
+ # Bring up all slaves
+ # Attach those which already exist and try to create
+ # those which don't exist yet. They will be attached
+ # in their own hotplug event.
+ local slave
+ for slave in $(unquote ${SLAVES}); do
+ if device_exists "${slave}"; then
+ bonding_enslave_device "${port}" "${slave}"
+ else
+ port_create "${slave}"
+ fi
+ done
+
+ exit ${EXIT_OK}
+
+ # Handle slave devices that have just been created and
+ # attach them.
+ elif hotplug_event_interface_is_slave_of_port "${port}"; then
+ bonding_enslave_device "${port}" "${INTERFACE}"
+
+ # If the parent device has been set up, we will
+ # bring up the slave device as well.
+ if device_is_up "${port}"; then
+ port_up "${INTERFACE}"
+ fi
+ fi
+
+ exit ${EXIT_OK}
+ ;;
+
+ remove)
+ if hotplug_event_port_is_interface "${port}"; then
+ # Bring down all slaves after the parent device went away
+ local slave
+ for slave in $(port_get_slaves "${port}"); do
+ port_remove "${slave}"
+ done
+
+ exit ${EXIT_OK}
+ fi
+ ;;
+ esac
+
+ exit ${EXIT_NOT_HANDLED}