From 9b47451e7cdd6f3c25ec46d83a919398aaf695eb Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 22 Sep 2018 13:47:44 +0100 Subject: [PATCH] hotplug: Let bridges create their ports in hotplug event This patch changes that all ports are being created in the hotplug event and allows us to start bridges at any time with ports existing or being added later. Fixes: #11360 Signed-off-by: Arne Fitzenreiter Signed-off-by: Michael Tremer --- src/functions/functions.hotplug | 11 +++++++++++ src/hooks/zones/bridge | 33 ++++++++++++++++++++++++--------- src/udev/network-hotplug | 8 ++------ 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/functions/functions.hotplug b/src/functions/functions.hotplug index 8fccae4e..f7a02ae4 100644 --- a/src/functions/functions.hotplug +++ b/src/functions/functions.hotplug @@ -70,6 +70,17 @@ hotplug_propagate_all_zones() { done } +hotplug_event_interface_is_zone() { + hotplug_assert_in_hotplug_event + + local zone="${1}" + assert isset zone + + log DEBUG "${zone}= ${INTERFACE}?" + + [ "${zone}" = "${INTERFACE}" ] +} + hotplug_event_port_is_interface() { hotplug_assert_in_hotplug_event diff --git a/src/hooks/zones/bridge b/src/hooks/zones/bridge index 33d5378d..92263741 100644 --- a/src/hooks/zones/bridge +++ b/src/hooks/zones/bridge @@ -120,10 +120,6 @@ hook_up() { # set our bridges to promisc mode. device_set_promisc "${zone}" on - # Bring up all ports - zone_ports_create "${zone}" - zone_ports_up "${zone}" - # Bring up all configurations zone_configs_up "${zone}" @@ -136,8 +132,18 @@ hook_hotplug() { case "$(hotplug_action)" in add) + # Attach all ports when zone is coming up + if hotplug_event_interface_is_zone "${zone}"; then + # Bring up all ports + local port + for port in $(zone_get_ports "${zone}"); do + log DEBUG "Trying to attach port ${port} to ${zone}" + + hook_port_up "${zone}" "${port}" + done + # Handle ports of this zone that have just been added - if hotplug_event_interface_is_port_of_zone "${zone}"; then + elif hotplug_event_interface_is_port_of_zone "${zone}"; then # Attach the device if the parent bridge is up if zone_is_active "${zone}"; then hook_port_up "${zone}" "${INTERFACE}" @@ -145,8 +151,17 @@ hook_hotplug() { fi ;; remove) + if hotplug_event_interface_is_zone "${zone}"; then + # Bring down/destroy all ports + local port + for port in $(zone_get_ports "${zone}"); do + log DEBUG "Trying to detach port ${port} from ${zone}" + + hook_port_down "${zone}" "${port}" + done + # Handle ports of this zone that have just been removed - if hotplug_event_interface_is_port_of_zone "${zone}"; then + elif hotplug_event_interface_is_port_of_zone "${zone}"; then hook_port_down "${zone}" "${INTERFACE}" fi ;; @@ -308,7 +323,7 @@ hook_port_up() { if ! device_exists "${port}"; then port_create "${port}" - exit ${EXIT_OK} + return ${EXIT_OK} fi # Read configuration values @@ -329,7 +344,7 @@ hook_port_up() { # Make sure that the port is up port_up "${port}" - exit ${EXIT_OK} + return ${EXIT_OK} } hook_port_down() { @@ -344,7 +359,7 @@ hook_port_down() { port_down "${port}" fi - exit ${EXIT_OK} + return ${EXIT_OK} } hook_port_status() { diff --git a/src/udev/network-hotplug b/src/udev/network-hotplug index af6c0df9..2a2d3e1f 100644 --- a/src/udev/network-hotplug +++ b/src/udev/network-hotplug @@ -63,12 +63,8 @@ case "${SUBSYSTEM}" in net) assert isset INTERFACE - # Don't do anything for zones - if zone_exists "${INTERFACE}"; then - exit ${EXIT_OK} - # Stop processing rules for the loopback device - elif device_is_loopback ${INTERFACE}; then + if device_is_loopback ${INTERFACE}; then exit ${EXIT_OK} # Stop processing rules for wireless monitoring devices @@ -77,7 +73,7 @@ case "${SUBSYSTEM}" in fi # Did we get called for a non-existing interface? - if ! port_exists "${INTERFACE}"; then + if ! zone_exists "${INTERFACE}" && ! port_exists "${INTERFACE}"; then case "${ACTION}" in add) log WARNING "Got to hotplug event for a port which does not exist: ${INTERFACE}" -- 2.39.2