WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] tools: Add default IP address and netmask logic to v

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] tools: Add default IP address and netmask logic to vif-nat
From: Jon Mason <jdmason@xxxxxxxxxx>
Date: Tue, 11 Oct 2005 18:16:10 -0500
Delivery-date: Tue, 11 Oct 2005 23:14:44 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Mail-followup-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.8i
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@xxxxxxxxxx>

# HG changeset patch
# User root@pentium4
# Node ID b7a71e4db06d0235d67fef66db1e78cd2238c240
# Parent  4e335372ace84b605cebc36a42610caadb09a4d8

Add default IP address and netmask logic

diff -r 4e335372ace8 -r b7a71e4db06d tools/examples/vif-nat
--- a/tools/examples/vif-nat    Tue Oct 11 14:23:19 2005
+++ b/tools/examples/vif-nat    Tue Oct 11 21:44:55 2005
@@ -23,7 +23,6 @@
 # Exit if anything goes wrong
 set -e 
 export PATH=/sbin:/bin:/usr/bin:/usr/sbin:$PATH
-echo "*vif-nat $*" >&2
 
 # Operation name.
 OP=$1
@@ -35,17 +34,25 @@
 # Required parameters. Fail if not set.
 domain=${domain:?}
 vif=${vif:?}
-ip=${ip:?} 
+ip=${ip:-'169.254.1.1/24'}   #if not defined, give a default address 
 
-# strip /netmask
+echo "*vif-nat $OP domain=$domain vif=$vif ip=$ip" >&2
+
+#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=`ifconfig eth0 | grep "inet addr:" | sed -e 's/.*inet 
addr:\(\w\w*\.\w\w*\.\w\w*\.\w\w*\).*/\1/'`
 
 # Are we going up or down?
 case $OP in
     up)
-        ifconfig ${vif} ${vif_ip} netmask 255.255.255.0 up
+        ifconfig ${vif} ${vif_ip} netmask ${netmask} up
         echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp
         iptcmd='-A'
         ipcmd='a'

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] tools: Add default IP address and netmask logic to vif-nat, Jon Mason <=