From: Paul Durrant Date: Tue, 11 Aug 2020 08:01:57 +0000 (+0100) Subject: tools/hotplug/Linux: add remove_from_bridge() X-Git-Tag: archive/raspbian/4.16.0+51-g0941d6cb-1+rpi1~2^2~42^2~1733 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=bb13d936d2500f303c8fbf9420da9ed340818294;p=xen.git tools/hotplug/Linux: add remove_from_bridge() This patch adds a remove_from_bridge() function into xen-network-common.sh to partner with the existing add_to_bridge() function. The vif-bridge script is then modified to use it. Signed-off-by: Paul Durrant Acked-by: Wei Liu --- diff --git a/tools/hotplug/Linux/vif-bridge b/tools/hotplug/Linux/vif-bridge index e722090ca8..c3e409926d 100644 --- a/tools/hotplug/Linux/vif-bridge +++ b/tools/hotplug/Linux/vif-bridge @@ -84,12 +84,7 @@ case "$command" in ;; offline) - if which brctl >&/dev/null; then - do_without_error brctl delif "$bridge" "$dev" - else - do_without_error ip link set "$dev" nomaster - fi - do_without_error ifconfig "$dev" down + remove_from_bridge "$bridge" "$dev" ;; add) diff --git a/tools/hotplug/Linux/xen-network-common.sh b/tools/hotplug/Linux/xen-network-common.sh index ec3bd4ec4a..6a0904361f 100644 --- a/tools/hotplug/Linux/xen-network-common.sh +++ b/tools/hotplug/Linux/xen-network-common.sh @@ -141,6 +141,25 @@ add_to_bridge () { ip link set dev ${dev} up } +remove_from_bridge () { + local bridge=$1 + local dev=$2 + + do_without_error ip link set dev ${dev} down + + # Don't remove $dev from $bridge if it's not on the bridge. + if [ -e "/sys/class/net/${bridge}/brif/${dev}" ]; then + log debug "removing $dev from bridge $bridge" + if which brctl >&/dev/null; then + do_without_error brctl delif ${bridge} ${dev} + else + do_without_error ip link set ${dev} nomaster + fi + else + log debug "$dev not on bridge $bridge" + fi +} + # Usage: set_mtu bridge dev set_mtu () { local bridge=$1