ia64/xen-unstable

changeset 8090:a20a9ec0e510

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>
author emellor@leeni.uk.xensource.com
date Mon Nov 28 11:05:07 2005 +0000 (2005-11-28)
parents c5ee3b6f25b3
children 2eb868d02f0f d5368f7fda5d
files tools/examples/README.incompatibilities tools/examples/vif-common.sh tools/examples/vif-nat tools/examples/vif-route
line diff
     1.1 --- a/tools/examples/README.incompatibilities	Mon Nov 28 01:47:28 2005 +0000
     1.2 +++ b/tools/examples/README.incompatibilities	Mon Nov 28 11:05:07 2005 +0000
     1.3 @@ -23,3 +23,9 @@ appropriately.  See xen-network-common.s
     1.4  Gentoo doesn't have ifup/ifdown; appropriate alternatives are defined in
     1.5  xen-network-common.sh.
     1.6  
     1.7 +
     1.8 +sed
     1.9 +---
    1.10 +
    1.11 +\s is not supported in regexps on Debian etch (sed 4.1.2), Ubuntu 4.10.  We
    1.12 +hand-craft character classes instead.
     2.1 --- a/tools/examples/vif-common.sh	Mon Nov 28 01:47:28 2005 +0000
     2.2 +++ b/tools/examples/vif-common.sh	Mon Nov 28 11:05:07 2005 +0000
     2.3 @@ -103,3 +103,37 @@ function handle_iptable()
     2.4        frob_iptable
     2.5    fi
     2.6  }
     2.7 +
     2.8 +
     2.9 +##
    2.10 +# ip_of interface
    2.11 +#
    2.12 +# Print the IP address currently in use at the given interface, or nothing if
    2.13 +# the interface is not up.
    2.14 +#
    2.15 +function ip_of()
    2.16 +{
    2.17 +  ip addr show "$1" | sed -n 's/^.*inet \([0-9.]*\).*$/\1/p'
    2.18 +}
    2.19 +
    2.20 +
    2.21 +##
    2.22 +# dom0_ip
    2.23 +#
    2.24 +# Print the IP address of the interface in dom0 through which we are routing.
    2.25 +# This is the IP address on the interface specified as "netdev" as a parameter
    2.26 +# to these scripts, or eth0 by default.  This function will call fatal if no
    2.27 +# such interface could be found.
    2.28 +#
    2.29 +function dom0_ip()
    2.30 +{
    2.31 +  local nd=${netdev:-eth0}
    2.32 +  local result=$(ip_of "$nd")
    2.33 +  if [ -z "$result" ]
    2.34 +  then
    2.35 +      fatal
    2.36 +"$netdev is not up.  Bring it up or specify another interface with " \
    2.37 +"netdev=<if> as a parameter to $0."
    2.38 +  fi
    2.39 +  echo "$result"
    2.40 +}
     3.1 --- a/tools/examples/vif-nat	Mon Nov 28 01:47:28 2005 +0000
     3.2 +++ b/tools/examples/vif-nat	Mon Nov 28 11:05:07 2005 +0000
     3.3 @@ -37,7 +37,7 @@ netmask=$netmask.$(( (($intmask & 0x00FF
     3.4  netmask=$netmask.$(( (($intmask & 0x0000FF00)) >> 8 ))
     3.5  netmask=$netmask.$(( $intmask & 0x000000FF ))
     3.6  
     3.7 -main_ip=$(ip addr show eth0 | sed -e '/inet /!d;s/^.*inet \([^\s*]\)\s.*$/\1/')
     3.8 +main_ip=$(dom0_ip)
     3.9  
    3.10  case "$command" in
    3.11      online)
     4.1 --- a/tools/examples/vif-route	Mon Nov 28 01:47:28 2005 +0000
     4.2 +++ b/tools/examples/vif-route	Mon Nov 28 11:05:07 2005 +0000
     4.3 @@ -23,7 +23,7 @@
     4.4  dir=$(dirname "$0")
     4.5  . "$dir/vif-common.sh"
     4.6  
     4.7 -main_ip=$(ip addr show eth0 | sed -e '/inet /!d;s/^.*inet \([^\s*]\)\s.*$/\1/')
     4.8 +main_ip=$(dom0_ip)
     4.9  
    4.10  case "$command" in
    4.11      online)