ia64/xen-unstable

changeset 16873:86c32269ba60

network-nat: Fix NAT scripts.
Signed-off-by: Dan Magenheimer <dan.magenheimer@oracle.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jan 24 14:37:53 2008 +0000 (2008-01-24)
parents 1190d50ce18c
children bfea0518d630
files tools/examples/network-nat tools/examples/vif-nat tools/examples/xen-network-common.sh
line diff
     1.1 --- a/tools/examples/network-nat	Thu Jan 24 14:35:52 2008 +0000
     1.2 +++ b/tools/examples/network-nat	Thu Jan 24 14:37:53 2008 +0000
     1.3 @@ -1,4 +1,4 @@
     1.4 -#!/bin/bash
     1.5 +#!/bin/bash -x
     1.6  #============================================================================
     1.7  # Default Xen network start/stop script when using NAT.
     1.8  # Xend calls a network script when it starts.
     1.9 @@ -27,7 +27,15 @@ evalVariables "$@"
    1.10  netdev=${netdev:-eth0}
    1.11  # antispoofing not yet implemented
    1.12  antispoof=${antispoof:-no}
    1.13 -dhcp=${dhcp:-no}
    1.14 +
    1.15 +# turn on dhcp feature by default if dhcpd is installed
    1.16 +if [ -f /etc/dhcpd.conf ]
    1.17 +then
    1.18 +	dhcp=${dhcp:-yes}
    1.19 +else
    1.20 +	dhcp=${dhcp:-no}
    1.21 +fi
    1.22 +
    1.23  
    1.24  if [ "$dhcp" != 'no' ]
    1.25  then
     2.1 --- a/tools/examples/vif-nat	Thu Jan 24 14:35:52 2008 +0000
     2.2 +++ b/tools/examples/vif-nat	Thu Jan 24 14:37:53 2008 +0000
     2.3 @@ -28,15 +28,22 @@
     2.4  dir=$(dirname "$0")
     2.5  . "$dir/vif-common.sh"
     2.6  
     2.7 -dhcp=${dhcp:-no}
     2.8 +# turn on dhcp feature by default if dhcpd is installed
     2.9 +if [ -f /etc/dhcpd.conf ]
    2.10 +then
    2.11 +	dhcp=${dhcp:-yes}
    2.12 +else
    2.13 +	dhcp=${dhcp:-no}
    2.14 +fi
    2.15  
    2.16  if [ "$dhcp" != 'no' ]
    2.17  then
    2.18    dhcpd_conf_file=$(find_dhcpd_conf_file)
    2.19    dhcpd_init_file=$(find_dhcpd_init_file)
    2.20 -  if [ -z "$dhcpd_conf_file" ] || [ -z "$dhcpd_init_file" ]
    2.21 +  dhcpd_arg_file=$(find_dhcpd_arg_file)
    2.22 +  if [ -z "$dhcpd_conf_file" ] || [ -z "$dhcpd_init_file" ] || [ -z "$dhcpd_arg_file" ]
    2.23    then
    2.24 -    echo 'Failed to find dhcpd configuration or init file.' >&2
    2.25 +    echo 'Failed to find dhcpd configuration or init or args file.' >&2
    2.26      exit 1
    2.27    fi
    2.28  fi
    2.29 @@ -88,6 +95,31 @@ then
    2.30    hostname="$hostname-$vifid"
    2.31  fi
    2.32  
    2.33 +dhcparg_remove_entry()
    2.34 +{
    2.35 +  local tmpfile=$(mktemp)
    2.36 +  sed -e "s/$vif //" "$dhcpd_arg_file" >"$tmpfile"
    2.37 +  if diff "$tmpfile" "$dhcpd_arg_file" >/dev/null
    2.38 +  then
    2.39 +    rm "$tmpfile"
    2.40 +  else
    2.41 +    mv "$tmpfile" "$dhcpd_arg_file"
    2.42 +  fi
    2.43 +}
    2.44 +
    2.45 +dhcparg_add_entry()
    2.46 +{
    2.47 +  dhcparg_remove_entry
    2.48 +  local tmpfile=$(mktemp)
    2.49 +  # handle Red Hat, SUSE, and Debian styles, with or without quotes
    2.50 +  sed -e 's/^DHCPDARGS="*\([^"]*\)"*/DHCPDARGS="\1'"$vif "'"/' \
    2.51 +     "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file"
    2.52 +  sed -e 's/^DHCPD_INTERFACE="*\([^"]*\)"*/DHCPD_INTERFACE="\1'"$vif "'"/' \
    2.53 +     "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file"
    2.54 +  sed -e 's/^INTERFACES="*\([^"]*\)"*/INTERFACES="\1'"$vif "'"/' \
    2.55 +     "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file"
    2.56 +  rm -f "$tmpfile"
    2.57 +}
    2.58  
    2.59  dhcp_remove_entry()
    2.60  {
    2.61 @@ -99,6 +131,7 @@ dhcp_remove_entry()
    2.62    else
    2.63      mv "$tmpfile" "$dhcpd_conf_file"
    2.64    fi
    2.65 +  dhcparg_remove_entry
    2.66  }
    2.67  
    2.68  
    2.69 @@ -109,6 +142,7 @@ dhcp_up()
    2.70    mac=$(xenstore_read "$XENBUS_PATH/mac")
    2.71    echo >>"$dhcpd_conf_file" \
    2.72  "host $hostname { hardware ethernet $mac; fixed-address $vif_ip; option routers $router_ip; option host-name \"$hostname\"; }"
    2.73 +  dhcparg_add_entry
    2.74    release_lock "vif-nat-dhcp"
    2.75    "$dhcpd_init_file" restart || true
    2.76  }
     3.1 --- a/tools/examples/xen-network-common.sh	Thu Jan 24 14:35:52 2008 +0000
     3.2 +++ b/tools/examples/xen-network-common.sh	Thu Jan 24 14:37:53 2008 +0000
     3.3 @@ -74,6 +74,11 @@ find_dhcpd_init_file()
     3.4    first_file -x /etc/init.d/{dhcp3-server,dhcp,dhcpd}
     3.5  }
     3.6  
     3.7 +find_dhcpd_arg_file()
     3.8 +{
     3.9 +  first_file -f /etc/sysconfig/dhcpd /etc/defaults/dhcp
    3.10 +}
    3.11 +
    3.12  # configure interfaces which act as pure bridge ports:
    3.13  setup_bridge_port() {
    3.14      local dev="$1"