Files
xen/tools/examples/vif-nat
T
emellor@leeni.uk.xensource.com dad18c78cb Change uses of \s within sed regexps -- some versions of sed do not support this
escape.

Allow the vif-nat and vif-route scripts to have netdev specified, rather than
hard-coding eth0.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
2005-11-28 11:05:07 +00:00

63 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=$(dom0_ip)
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
log debug "Successful vif-nat $command for $vif."
if [ "$command" == "online" ]
then
success
fi