Files
xen/tools/examples/vif-bridge
T
emellor@leeni.uk.xensource.com af374bc7d2 Added xen-script-common.sh, for functions common to all scripts, not just the
hotplug ones.  Added evalVariables and findCommand functions to that, which we
use to clarify the handling of variables being passed in as command line
variables.

Make vif-bridge able to find the bridge for itself if only one bridge is in
use.  This means that it is not necessary to specify a bridge in many
configurations.  Allow the bridge to be specified on the command line, meaning
that a default may be provided in the xend-config.sxp if desired.

Added xenstore_read_default to xen-hotplug-common.sh, which reads from the
store but uses a given default if the path in the store is not present.  This
is used by vif-bridge to allow the store details (i.e. those given to xm create)
to override the default value given in the xend-config.sxp.

Remove vif-bridge setting -- the value can be specified on the vif-script
command line if necessary.

Added examples for network-nat/vif-nat.

Added lots of big comments.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
2005-10-30 13:33:17 +01:00

71 lines
1.9 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 (up|down)
#
# 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
up)
if brctl show "$bridge" | grep "$vif" >&/dev/null
then
log debug "$vif already attached to $bridge"
exit 0
fi
brctl addif "$bridge" "$vif" ||
fatal "brctl addif $bridge $vif failed"
ifconfig "$vif" up || fatal "ifconfig $vif up failed"
;;
down)
# vifs are auto-removed from bridge.
ifconfig "$vif" down || fatal "ifconfig $vif down failed"
;;
esac
handle_iptable
log debug "Successful vif-bridge operation for $vif, bridge $bridge."