From abba34c15cdc12eb99b29b70b3c0f4800f318145 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 12 Apr 2015 18:22:46 +0000 Subject: [PATCH] zone: Fix immediate attachment of ethernet ports to a bridge --- src/functions/functions.ports | 4 ++++ src/functions/functions.zone | 45 ++++++++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/functions/functions.ports b/src/functions/functions.ports index cfe9b50e..1edd1c30 100644 --- a/src/functions/functions.ports +++ b/src/functions/functions.ports @@ -151,6 +151,10 @@ function port_is_attached() { return ${EXIT_ERROR} } +function port_is_up() { + device_is_up $@ +} + function port_new() { #local port=${1} #shift diff --git a/src/functions/functions.zone b/src/functions/functions.zone index e39248c6..6373ec7c 100644 --- a/src/functions/functions.zone +++ b/src/functions/functions.zone @@ -651,9 +651,7 @@ function zone_port_attach() { log INFO "${port} has been attached to ${zone}" # Automatically connect the port - if zone_is_active "${zone}"; then - zone_port_create "${zone}" "${port}" - fi + zone_port_start "${zone}" "${port}" ;; *) log CRITICAL "${port} could not be attached to ${zone}" @@ -716,9 +714,7 @@ function zone_port_detach() { log INFO "${port} has been detached from ${zone}" # Bring down the port if needed - if zone_is_active "${zone}"; then - zone_port_remove "${zone}" "${port}" - fi + zone_port_stop "${zone}" "${port}" ;; *) log CRITICAL "${port} could not be detached from ${zone}" @@ -763,6 +759,43 @@ function zone_port_down() { zone_port_cmd "port_down" $@ } +# The next two functions automagically bring up and down +# port that are attached to a bridge or similar. +# The problem that is tried to overcome here is that there +# are ports which exist all the time (like ethernet ports) +# and therefore do not dispatch a hotplug event when +# port_create is called. + +function zone_port_start() { + local zone="${1}" + local port="${2}" + + if zone_is_active "${zone}"; then + if device_exists "${port}"; then + zone_port_up "${zone}" "${port}" + return ${?} + else + zone_port_create "${zone}" "${port}" + return ${?} + fi + fi + + return ${EXIT_OK} +} + +function zone_port_stop() { + local zone="${1}" + local port="${2}" + + # Shut down the port if necessary + if zone_is_active "${zone}" && port_is_up "${port}"; then + zone_port_down "${zone}" "${port}" + fi + + # Remove the port + zone_port_remove "${zone}" "${port}" +} + function zone_port_status() { zone_port_cmd "port_status" $@ } -- 2.47.3