From 3afcab057a29075f93b7a4827f4a5e22cd91edca Mon Sep 17 00:00:00 2001
From: "Leigh B. Stoller" <stoller@flux.utah.edu>
Date: Fri, 29 Oct 2004 16:13:54 +0000
Subject: [PATCH] dhclient changes for ElabInElab. The crux of this is that
 inner nodes are treated specially. For inner boss/ops, ignore most of what
 DHCPD returns; we need to do the DHCP so that we know what interface, but for
 the moment stuff is hardwired into /etc/rc.conf when the inner boss and ops
 are created. I can probably fix this up later as needed, to be more dynamic
 for supporting swapout/swapin of an inner emulab, but swapout and restore of
 an inner elab has som many open issues, that not worrying about it now.

For inner nodes, the change is simple; If no hostname provided, ignore
the DHCPD reply completely, favoring a full reply from the inner
control network, and returning -1 from the exit hook so that dhclient
keeps trying in the foreground.

I am committing these so they get into new images.
---
 tmcd/freebsd/GNUmakefile.in       |  2 ++
 tmcd/freebsd/dhclient-enter-hooks | 47 +++++++++++++++++++++++++++++++
 tmcd/freebsd/dhclient-exit-hooks  | 31 +++++++++++++++++++-
 tmcd/linux/dhclient-enter-hooks   | 28 ++++++++++++++++++
 tmcd/linux/dhclient-exit-hooks    | 14 +++++++++
 5 files changed, 121 insertions(+), 1 deletion(-)
 create mode 100644 tmcd/freebsd/dhclient-enter-hooks

diff --git a/tmcd/freebsd/GNUmakefile.in b/tmcd/freebsd/GNUmakefile.in
index 2b6b6e75b3..4a2344967a 100644
--- a/tmcd/freebsd/GNUmakefile.in
+++ b/tmcd/freebsd/GNUmakefile.in
@@ -137,6 +137,8 @@ sysetc-install:	dir-install
 	$(INSTALL) -m 755 $(SRCDIR)/rc.conf $(SYSETCDIR)/rc.conf
 	$(INSTALL) -m 755 $(SRCDIR)/dhclient-exit-hooks \
 			$(SYSETCDIR)/dhclient-exit-hooks
+	$(INSTALL) -m 755 $(SRCDIR)/dhclient-enter-hooks \
+			$(SYSETCDIR)/dhclient-enter-hooks
 	$(INSTALL) -m 755 $(SRCDIR)/periodic.conf $(SYSETCDIR)/periodic.conf
 	$(INSTALL) -m 755 $(SRCDIR)/testbed.sh $(RCDIR)/testbed.sh
 	$(INSTALL) -m 755 $(SRCDIR)/elvind.sh $(RCDIR)/elvind.sh
diff --git a/tmcd/freebsd/dhclient-enter-hooks b/tmcd/freebsd/dhclient-enter-hooks
new file mode 100644
index 0000000000..ebcb7ed1ee
--- /dev/null
+++ b/tmcd/freebsd/dhclient-enter-hooks
@@ -0,0 +1,47 @@
+#!/bin/sh
+#
+# EMULAB-COPYRIGHT
+# Copyright (c) 2000-2004 University of Utah and the Flux Group.
+# All rights reserved.
+#
+. /etc/emulab/paths.sh
+
+if [ x$reason != xREBOOT -a x$reason != xBOUND -a x$reason != xRENEW ]
+then
+    return 0
+fi
+
+#
+# ElabinElab support.
+#
+if [ -e "$ETCDIR/outer_bossnode" ]; then
+    #
+    # On inner boss/ops, we do not accept the following from the DHCPD
+    # server on outer boss. This stuff has been setup in /etc/rc.conf
+    # when the inner boss/ops was created. 
+    #
+    unset new_host_name
+    unset new_domain_name_servers
+    unset new_domain_name
+    unset new_routers
+elif [ "$new_host_name" = "" ]; then
+    #
+    # Otherwise, if no hostname provided, it means that its an outer emulab
+    # returning DHCPD info, in which case we want to again ignore most of the
+    # info since all we want to do is configure the interface. 
+    #
+    new_static_routes="$new_dhcp_server_identifier $new_routers"
+    unset new_domain_name_servers
+    unset new_domain_name
+    unset new_routers
+    new_subnet_mask="255.255.255.0"
+
+    #
+    # Ack, changed my mind. This is a pain in the ass. For now do not
+    # configure the outer interface; worry about it later.
+    # 
+    exit_status=1
+    return
+fi
+
+return 0
diff --git a/tmcd/freebsd/dhclient-exit-hooks b/tmcd/freebsd/dhclient-exit-hooks
index 05faa0fb45..c1126e737c 100644
--- a/tmcd/freebsd/dhclient-exit-hooks
+++ b/tmcd/freebsd/dhclient-exit-hooks
@@ -11,6 +11,35 @@ then
     exit 0
 fi
 
+#
+# ElabinElab support
+#
+if [ -e "$ETCDIR/outer_bossnode" ]; then
+    #
+    # Inner boss or ops. The outer network has now been configured.
+    # Call rc.inelab to get the inner control network configured (we
+    # have to ask outer boss in the usual manner).
+    #
+    $BINDIR/rc/rc.inelab >$LOGDIR/dhclient.log 2>&1
+
+    # Then kill as we normally do.
+    killall dhclient >>$LOGDIR/dhclient.log 2>&1
+    exit 0
+    
+elif [ "$new_host_name" = "" ]; then
+    #
+    # Otherwise, if no hostname provided, it means that its an outer emulab
+    # returning DHCPD info, in which case all we want to do is configure the
+    # interface, but not allow dhclient to think it has finished its job.
+    # So, exit with non-zero status and dhclient will keep trying to configure
+    # another interface (the inner control network). This assumes this
+    # was the first interface to respond. If the inner control interface
+    # came up first, then dhclient is already in the background. See below;
+    # we are going to let dhclient keep running. 
+    #
+    exit 1
+fi
+
 #
 # Remember our server IP, real hostname, router IP, etc.
 #
@@ -35,7 +64,7 @@ fi
 
 #
 # Once we have an IP address, we can stop dhclient so that it doesn't get
-# in the way 
+# in the way.
 #
 # I'd love to use the dhclient.pid file, but it helpfully has not been
 # created at this point
diff --git a/tmcd/linux/dhclient-enter-hooks b/tmcd/linux/dhclient-enter-hooks
index 8e5c46dc59..9ee0e974e4 100644
--- a/tmcd/linux/dhclient-enter-hooks
+++ b/tmcd/linux/dhclient-enter-hooks
@@ -4,6 +4,7 @@
 # Copyright (c) 2004 University of Utah and the Flux Group.
 # All rights reserved.
 #
+. /etc/emulab/paths.sh
 
 #
 # Sweet! dhclient on linux wants to DHCP on the loopback interface
@@ -11,4 +12,31 @@
 #
 if [ xxx$interface = xxxlo ]; then
     exit_status=1
+    return
+fi
+
+if [ x$reason != xREBOOT -a x$reason != xBOUND -a x$reason != xRENEW -a x$reason != xREBIND ]
+then
+    return
+fi
+
+#
+# ElabinElab support.
+#
+if [ "$new_host_name" = "" ]; then
+    #
+    # If no hostname provided, it means that its an outer emulab returning
+    # DHCPD info, in which case we want to again ignore most of the
+    # info since all we want to do is configure the interface. 
+    #
+    new_static_routes="$new_dhcp_server_identifier $new_routers"
+    unset new_domain_name_servers
+    unset new_domain_name
+    unset new_routers
+    #
+    # Ack, changed my mind. This is a pain in the ass. For now do not
+    # configure the outer interface; worry about it later.
+    # 
+    exit_status=1
+    return
 fi
diff --git a/tmcd/linux/dhclient-exit-hooks b/tmcd/linux/dhclient-exit-hooks
index e14cec0e6d..bc7dac881a 100644
--- a/tmcd/linux/dhclient-exit-hooks
+++ b/tmcd/linux/dhclient-exit-hooks
@@ -11,6 +11,20 @@ then
     exit 0
 fi
 
+#
+# ElabinElab support
+#
+if [ "$new_host_name" = "" ]; then
+    #
+    # If no hostname provided, it means that its an outer emulab
+    # returning DHCPD info, in which case all we want to do is configure the
+    # interface, but not allow dhclient to think it has finished its job.
+    # So, exit with non-zero status and dhclient will keep trying to configure
+    # another interface (the inner control network).
+    #
+    exit 1
+fi
+
 #
 # Remember our server IP, real hostname, router IP, etc.
 #
-- 
GitLab