Files
xen/tools/examples/vif-nat
T
emellor@leeni.uk.xensource.com 8d43373af6 Have the vif scripts expect the offline event, not the remove event. With
the remove event, the script environment variable has disappeared, so we must
hook on the offline event instead.  This fix was put into xen-backend.rules,
but not the vif scripts, so they were out of sync, and the interfaces were not
being properly closed down.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
2005-11-15 15:56:47 +01:00

59 lines
1.7 KiB
Bash

#!/bin/sh
#============================================================================
# /etc/xen/vif-nat
#
# Script for configuring a vif in routed-nat 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 vif-bridge is the default.
#
# Usage:
# vif-nat (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:
# ip list of IP networks for the vif, space-separated (default given in
# this script).
#============================================================================
dir=$(dirname "$0")
. "$dir/vif-common.sh"
if [ "$ip" == "" ]
then
ip='169.254.1.1/24'
fi
#determine ip address and netmask
vif_ip=`echo ${ip} | awk -F/ '{print $1}'`
bits=`echo ${ip} | awk -F/ '{print $2}'`
intmask=$(( ((0xFFFFFFFF << ((32 - $bits)))) & 0xFFFFFFFF ))
netmask=$(( (($intmask & 0xFF000000)) >> 24 ))
netmask=$netmask.$(( (($intmask & 0x00FF0000)) >> 16 ))
netmask=$netmask.$(( (($intmask & 0x0000FF00)) >> 8 ))
netmask=$netmask.$(( $intmask & 0x000000FF ))
main_ip=$(ip addr show eth0 | sed -e '/inet /!d;s/^.*inet \([^\s*]\)\s.*$/\1/')
case "$command" in
online)
ifconfig ${vif} ${vif_ip} netmask ${netmask} up
echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp
ipcmd='a'
;;
offline)
ifconfig ${vif} down
ipcmd='d'
;;
esac
ip r ${ipcmd} ${ip} dev ${vif} src ${main_ip}
handle_iptable
success