Files
xen/tools/examples/vif-bridge
T
emellor@leeni.uk.xensource.com 92b5e81264 Don't treat the failure of ifconfig vifX.Y down as a fatal error. This hasn't
emerged as a problem in the field, AFAIK, but it seems that distro scripts
could have brought the device down already by this point (Debian stable's
net.agent does ifdown vifX.Y, and it wouldn't surprise me if someone decided
to do ifconfig vifX.Y down if this failed, for example).

Logging but ignoring the failure seems sensible.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
2005-11-23 19:16:54 +00:00

73 lines
2.0 KiB
Bash
Executable File

#!/bin/sh
#============================================================================
# /etc/xen/vif-bridge
#
# Script for configuring a vif in bridged mode.
# The hotplugging system will call this script if it is specified either in
# the device configuration given to Xend, or the default Xend configuration
# in /etc/xen/xend-config.sxp. If the script is specified in neither of those
# places, then this script is the default.
#
# Usage:
# vif-bridge (add|remove|online|offline)
#
# Environment vars:
# vif vif interface name (required).
# XENBUS_PATH path to this device's details in the XenStore (required).
#
# Read from the store:
# bridge bridge to add the vif to (optional). Defaults to searching for the
# bridge itself.
# ip list of IP networks for the vif, space-separated (optional).
#
# up:
# Enslaves the vif interface to the bridge and adds iptables rules
# for its ip addresses (if any).
#
# down:
# Removes the vif interface from the bridge and removes the iptables
# rules for its ip addresses (if any).
#============================================================================
dir=$(dirname "$0")
. "$dir/vif-common.sh"
bridge=${bridge:-}
bridge=$(xenstore_read_default "$XENBUS_PATH/bridge" "$bridge")
if [ -z "$bridge" ]
then
bridge=$(brctl show | cut -d "
" -f 2 | cut -f 1)
if [ -z "$bridge" ]
then
fatal "Could not find bridge, and none was specified"
fi
fi
case "$command" in
online)
if brctl show | grep "$vif" >&/dev/null
then
log debug "$vif already attached to a bridge"
exit 0
fi
brctl addif "$bridge" "$vif" ||
fatal "brctl addif $bridge $vif failed"
ifconfig "$vif" up || fatal "ifconfig $vif up failed"
;;
offline)
# vifs are auto-removed from bridge.
ifconfig "$vif" down || log err "ifconfig $vif down failed"
;;
esac
handle_iptable
log debug "Successful vif-bridge operation for $vif, bridge $bridge."
success