aboutsummaryrefslogtreecommitdiffstats
path: root/tools/examples
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2008-01-24 14:37:53 +0000
committerKeir Fraser <keir.fraser@citrix.com>2008-01-24 14:37:53 +0000
commit9577157dc4bbda42bc121e677ae9540c8a70d241 (patch)
treefa8459c36e30238ba45eba0fc5b4ad418e776c5b /tools/examples
parent26bf63427f77d844326bf2d3ba21466df12363cf (diff)
downloadxen-9577157dc4bbda42bc121e677ae9540c8a70d241.tar.gz
xen-9577157dc4bbda42bc121e677ae9540c8a70d241.tar.bz2
xen-9577157dc4bbda42bc121e677ae9540c8a70d241.zip
network-nat: Fix NAT scripts.
Signed-off-by: Dan Magenheimer <dan.magenheimer@oracle.com>
Diffstat (limited to 'tools/examples')
-rw-r--r--tools/examples/network-nat12
-rw-r--r--tools/examples/vif-nat40
-rw-r--r--tools/examples/xen-network-common.sh5
3 files changed, 52 insertions, 5 deletions
diff --git a/tools/examples/network-nat b/tools/examples/network-nat
index 62d2b0c259..d9c62c6160 100644
--- a/tools/examples/network-nat
+++ b/tools/examples/network-nat
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/bash -x
#============================================================================
# Default Xen network start/stop script when using NAT.
# Xend calls a network script when it starts.
@@ -27,7 +27,15 @@ evalVariables "$@"
netdev=${netdev:-eth0}
# antispoofing not yet implemented
antispoof=${antispoof:-no}
-dhcp=${dhcp:-no}
+
+# turn on dhcp feature by default if dhcpd is installed
+if [ -f /etc/dhcpd.conf ]
+then
+ dhcp=${dhcp:-yes}
+else
+ dhcp=${dhcp:-no}
+fi
+
if [ "$dhcp" != 'no' ]
then
diff --git a/tools/examples/vif-nat b/tools/examples/vif-nat
index 579d7eba35..75bdf5c444 100644
--- a/tools/examples/vif-nat
+++ b/tools/examples/vif-nat
@@ -28,15 +28,22 @@
dir=$(dirname "$0")
. "$dir/vif-common.sh"
-dhcp=${dhcp:-no}
+# turn on dhcp feature by default if dhcpd is installed
+if [ -f /etc/dhcpd.conf ]
+then
+ dhcp=${dhcp:-yes}
+else
+ dhcp=${dhcp:-no}
+fi
if [ "$dhcp" != 'no' ]
then
dhcpd_conf_file=$(find_dhcpd_conf_file)
dhcpd_init_file=$(find_dhcpd_init_file)
- if [ -z "$dhcpd_conf_file" ] || [ -z "$dhcpd_init_file" ]
+ dhcpd_arg_file=$(find_dhcpd_arg_file)
+ if [ -z "$dhcpd_conf_file" ] || [ -z "$dhcpd_init_file" ] || [ -z "$dhcpd_arg_file" ]
then
- echo 'Failed to find dhcpd configuration or init file.' >&2
+ echo 'Failed to find dhcpd configuration or init or args file.' >&2
exit 1
fi
fi
@@ -88,6 +95,31 @@ then
hostname="$hostname-$vifid"
fi
+dhcparg_remove_entry()
+{
+ local tmpfile=$(mktemp)
+ sed -e "s/$vif //" "$dhcpd_arg_file" >"$tmpfile"
+ if diff "$tmpfile" "$dhcpd_arg_file" >/dev/null
+ then
+ rm "$tmpfile"
+ else
+ mv "$tmpfile" "$dhcpd_arg_file"
+ fi
+}
+
+dhcparg_add_entry()
+{
+ dhcparg_remove_entry
+ local tmpfile=$(mktemp)
+ # handle Red Hat, SUSE, and Debian styles, with or without quotes
+ sed -e 's/^DHCPDARGS="*\([^"]*\)"*/DHCPDARGS="\1'"$vif "'"/' \
+ "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file"
+ sed -e 's/^DHCPD_INTERFACE="*\([^"]*\)"*/DHCPD_INTERFACE="\1'"$vif "'"/' \
+ "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file"
+ sed -e 's/^INTERFACES="*\([^"]*\)"*/INTERFACES="\1'"$vif "'"/' \
+ "$dhcpd_arg_file" >"$tmpfile" && mv "$tmpfile" "$dhcpd_arg_file"
+ rm -f "$tmpfile"
+}
dhcp_remove_entry()
{
@@ -99,6 +131,7 @@ dhcp_remove_entry()
else
mv "$tmpfile" "$dhcpd_conf_file"
fi
+ dhcparg_remove_entry
}
@@ -109,6 +142,7 @@ dhcp_up()
mac=$(xenstore_read "$XENBUS_PATH/mac")
echo >>"$dhcpd_conf_file" \
"host $hostname { hardware ethernet $mac; fixed-address $vif_ip; option routers $router_ip; option host-name \"$hostname\"; }"
+ dhcparg_add_entry
release_lock "vif-nat-dhcp"
"$dhcpd_init_file" restart || true
}
diff --git a/tools/examples/xen-network-common.sh b/tools/examples/xen-network-common.sh
index 95d2ef8f62..8fe9500440 100644
--- a/tools/examples/xen-network-common.sh
+++ b/tools/examples/xen-network-common.sh
@@ -74,6 +74,11 @@ find_dhcpd_init_file()
first_file -x /etc/init.d/{dhcp3-server,dhcp,dhcpd}
}
+find_dhcpd_arg_file()
+{
+ first_file -f /etc/sysconfig/dhcpd /etc/defaults/dhcp
+}
+
# configure interfaces which act as pure bridge ports:
setup_bridge_port() {
local dev="$1"