ia64/xen-unstable

changeset 7341:456b91c81427

The NAT scripts currently work, but the changes below decrease user
error and allow the netmask to be passed in.

Signed-off-by: Jon Mason <jdmason@us.ibm.com>
author kaf24@firebug.cl.cam.ac.uk
date Wed Oct 12 09:28:12 2005 +0100 (2005-10-12)
parents c05d5e85ded2
children 0fd84f168103
files tools/examples/vif-nat
line diff
     1.1 --- a/tools/examples/vif-nat	Wed Oct 12 09:27:28 2005 +0100
     1.2 +++ b/tools/examples/vif-nat	Wed Oct 12 09:28:12 2005 +0100
     1.3 @@ -23,7 +23,6 @@
     1.4  # Exit if anything goes wrong
     1.5  set -e 
     1.6  export PATH=/sbin:/bin:/usr/bin:/usr/sbin:$PATH
     1.7 -echo "*vif-nat $*" >&2
     1.8  
     1.9  # Operation name.
    1.10  OP=$1
    1.11 @@ -35,17 +34,25 @@ for arg ; do export "${arg}" ; done
    1.12  # Required parameters. Fail if not set.
    1.13  domain=${domain:?}
    1.14  vif=${vif:?}
    1.15 -ip=${ip:?} 
    1.16 +ip=${ip:-'169.254.1.1/24'}   #if not defined, give a default address 
    1.17 +
    1.18 +echo "*vif-nat $OP domain=$domain vif=$vif ip=$ip" >&2
    1.19  
    1.20 -# strip /netmask
    1.21 +#determine ip address and netmask 
    1.22  vif_ip=`echo ${ip} | awk -F/ '{print $1}'`
    1.23 +bits=`echo ${ip} | awk -F/ '{print $2}'`
    1.24 +intmask=$(( ((0xFFFFFFFF << ((32 - $bits)))) & 0xFFFFFFFF ))
    1.25 +netmask=$(( (($intmask & 0xFF000000)) >> 24 ))
    1.26 +netmask=$netmask.$(( (($intmask & 0x00FF0000)) >> 16 ))
    1.27 +netmask=$netmask.$(( (($intmask & 0x0000FF00)) >> 8 ))
    1.28 +netmask=$netmask.$(( $intmask & 0x000000FF ))
    1.29  
    1.30  main_ip=`ifconfig eth0 | grep "inet addr:" | sed -e 's/.*inet addr:\(\w\w*\.\w\w*\.\w\w*\.\w\w*\).*/\1/'`
    1.31  
    1.32  # Are we going up or down?
    1.33  case $OP in
    1.34      up)
    1.35 -        ifconfig ${vif} ${vif_ip} netmask 255.255.255.0 up
    1.36 +        ifconfig ${vif} ${vif_ip} netmask ${netmask} up
    1.37          echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp
    1.38          iptcmd='-A'
    1.39          ipcmd='a'