aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoremellor@leeni.uk.xensource.com <emellor@leeni.uk.xensource.com>2005-12-03 12:21:27 +0000
committeremellor@leeni.uk.xensource.com <emellor@leeni.uk.xensource.com>2005-12-03 12:21:27 +0000
commit60fdf33b7324089cdb1b3011ae46985ec91bd655 (patch)
treed89a8528cf0766eb68f8f4bfecee46831704ed2b
parentffa06621c6b2b9a1c186a919154eb8d3ec3d453d (diff)
downloadxen-60fdf33b7324089cdb1b3011ae46985ec91bd655.tar.gz
xen-60fdf33b7324089cdb1b3011ae46985ec91bd655.tar.bz2
xen-60fdf33b7324089cdb1b3011ae46985ec91bd655.zip
Set hostname in DHCP config from the guest name, and if more than one interface
is specified, from guest-2, guest-3 etc. Have the DHCP server send the hostname to the guest. Added a lock around DHCP config file frobbing, to avoid racing creation vs deletion. Signed-off-by: Ewan Mellor <ewan@xensource.com>
-rw-r--r--tools/examples/vif-nat27
1 files changed, 19 insertions, 8 deletions
diff --git a/tools/examples/vif-nat b/tools/examples/vif-nat
index d667fb89da..896f5961d1 100644
--- a/tools/examples/vif-nat
+++ b/tools/examples/vif-nat
@@ -42,14 +42,15 @@ then
fi
+domid=$(echo "$XENBUS_PATH" | sed -n 's#.*/\([0-9]*\)/[0-9]*$#\1#p')
+vifid=$(echo "$XENBUS_PATH" | sed -n 's#.*/[0-9]*/\([0-9]*\)$#\1#p')
+vifid=$(( $vifid + 1 ))
+
+
ip_from_dom()
{
- local domid=$(echo "$XENBUS_PATH" | sed -n 's#.*/\([0-9]*\)/[0-9]*$#\1#p')
- local vifid=$(echo "$XENBUS_PATH" | sed -n 's#.*/[0-9]*/\([0-9]*\)$#\1#p')
-
local domid1=$(( $domid / 256 ))
local domid2=$(( $domid % 256 ))
- vifid=$(( $vifid + 1 ))
echo "10.$domid1.$domid2.$vifid/16"
}
@@ -92,10 +93,17 @@ netmask=$(dotted_quad $intmask)
network=$(dotted_quad $(( $vif_int & $intmask )) )
+hostname=$(xenstore_read "$XENBUS_PATH/domain" | tr -- '_.:/+' '-----')
+if [ "$vifid" != "1" ]
+then
+ hostname="$hostname-$vifid"
+fi
+
+
dhcp_remove_entry()
{
local tmpfile=$(mktemp)
- grep -v "host Xen-${vif/./-}" "$dhcpd_conf_file" >"$tmpfile"
+ grep -v "host $hostname" "$dhcpd_conf_file" >"$tmpfile"
if diff "$tmpfile" "$dhcpd_conf_file" >/dev/null
then
rm "$tmpfile"
@@ -107,18 +115,21 @@ dhcp_remove_entry()
dhcp_up()
{
+ claim_lock "vif-nat-dhcp"
dhcp_remove_entry
mac=$(xenstore_read "$XENBUS_PATH/mac")
echo >>"$dhcpd_conf_file" \
-"host Xen-${vif/./-} { hardware ethernet $mac; fixed-address $vif_ip; option routers $router_ip; }"
-
- "$dhcpd_init_file" restart
+"host $hostname { hardware ethernet $mac; fixed-address $vif_ip; option routers $router_ip; option host-name \"$hostname\"; }"
+ release_lock "vif-nat-dhcp"
+ "$dhcpd_init_file" restart || true
}
dhcp_down()
{
+ claim_lock "vif-nat-dhcp"
dhcp_remove_entry
+ release_lock "vif-nat-dhcp"
"$dhcpd_init_file" restart || true # We need to ignore failure because
# ISC dhcpd 3 borks if there is nothing
# for it to do, which is the case if