From brooks@minya.sea.one-eyed-alien.net  Mon May 15 22:33:19 2000
Return-Path: <brooks@minya.sea.one-eyed-alien.net>
Received: from minya.sea.one-eyed-alien.net (sense-sea-mas-52.oz.net [216.39.130.52])
	by hub.freebsd.org (Postfix) with ESMTP id 952CF37BA26
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 15 May 2000 22:33:17 -0700 (PDT)
	(envelope-from brooks@minya.sea.one-eyed-alien.net)
Received: (from brooks@localhost)
	by minya.sea.one-eyed-alien.net (8.9.3/8.9.3) id WAA00568;
	Mon, 15 May 2000 22:33:46 -0700 (PDT)
	(envelope-from brooks)
Message-Id: <200005160533.WAA00568@minya.sea.one-eyed-alien.net>
Date: Mon, 15 May 2000 22:33:46 -0700 (PDT)
From: brooks@one-eyed-alien.net
Sender: brooks@minya.sea.one-eyed-alien.net
Reply-To: brooks@one-eyed-alien.net
To: FreeBSD-gnats-submit@freebsd.org
Subject: [PATCH] DHCP should be able to override hostname.
X-Send-Pr-Version: 3.2

>Number:         18583
>Category:       conf
>Synopsis:       [PATCH] DHCP should be able to override hostname.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon May 15 22:40:00 PDT 2000
>Closed-Date:    Sun May 27 23:20:25 PDT 2001
>Last-Modified:  Sun May 27 23:24:49 PDT 2001
>Originator:     Brooks Davis
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
The Aerospace Corporation
>Environment:

FreeBSD minya 5.0-CURRENT FreeBSD 5.0-CURRENT #21: Tue May  9 18:49:06 PDT 2000     root@minya:/usr/src/sys/compile/MINYA  i386

>Description:

There's a long standing issue where you can either have a hardwired
hostname and have it all the time or you can get your hostname from DHCP
and not have one unless you set it manualy while not networked.  I have
hacked up a solution which I think avoids POLA violations.  My only
concern with it is the new program to get variables out of
/etc/defaults/rc.conf and the like called rc_conf_var.  It's a new
addition to /sbin which it bound to be touchy.  OTOH, this is exactly
the direction we need to move in if we ever want to make rc.conf not be
a shell script.

>How-To-Repeat:

Try using DHCP for configuration at multiple sites and using your laptop
disconnected as well.

>Fix:

The following patch should work, but I've never made a patch
that added files before, so I'm not sure.  I've seen complaints about
this since DHCP was added to the base, so I'd like to get it comitted.
If nothing else, it's a lot of diffs (by file count) to keep in my own
tree.

--- /usr/src/etc/rc.network	Tue May  9 15:00:17 2000
+++ /etc/rc.network	Wed May 10 09:51:03 2000
@@ -16,8 +16,13 @@
 	# Set the host name if it is not already set
 	#
 	if [ -z "`hostname -s`" ]; then
-		hostname ${hostname}
-		echo -n ' hostname'
+		if [ -n "${hostname}" ]; then
+			hostname ${hostname}
+			echo -n ' hostname'
+		elif [ -n "${default_hostname}" ]; then
+			hostname ${default_hostname}
+			echo -n ' default_hostname'
+		fi
 	fi
 
 	# Set the domainname if we're using NIS
--- /usr/src/etc/defaults/rc.conf	Tue May  9 15:00:17 2000
+++ /etc/defaults/rc.conf	Tue May  9 21:22:16 2000
@@ -39,6 +39,7 @@
 
 ### Basic network options: ###
 hostname=""			# Set this!
+default_hostname=""		# Set this if you get your hostname elseware.
 nisdomainname="NO"		# Set to NIS domain if using NIS (or NO).
 dhcp_program="/sbin/dhclient"	# Path to dhcp client program.
 dhcp_flags=""			# Additional flags to pass to dhcp client.
--- /usr/src/contrib/isc-dhcp/client/scripts/freebsd	Sat Jan 15 14:46:40 2000
+++ /sbin/dhclient-script	Tue May  9 21:44:59 2000
@@ -76,7 +76,7 @@
 if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
    [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
   current_hostname=`/bin/hostname`
-  if [ x$current_hostname = x ] || \
+  if [ x$current_hostname = x`rc_conf_var default_hostname` ] || \
      [ x$current_hostname = x$old_host_name ]; then
     if [ x$new_host_name != x$old_host_name ]; then
       $LOGGER "New Hostname: $new_host_name"
--- /sbin/rc_conf_var.orig	Wed May 10 11:19:16 2000
+++ /sbin/rc_conf_var	Tue May  9 21:40:06 2000
@@ -0,0 +1,13 @@
+#!/bin/sh
+# $FreeBSD$
+
+# If there is a global system configuration file, suck it in.
+#
+if [ -r /etc/defaults/rc.conf ]; then
+	. /etc/defaults/rc.conf
+	source_rc_confs
+elif [ -r /etc/rc.conf ]; then
+	. /etc/rc.conf
+fi
+
+eval echo \$${1}


>Release-Note:
>Audit-Trail:

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: brooks@one-eyed-alien.net
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: conf/18583: [PATCH] DHCP should be able to override hostname. 
Date: Tue, 16 May 2000 15:57:23 +0200

 On Mon, 15 May 2000 22:33:46 MST, brooks@one-eyed-alien.net wrote:
 
 > My only concern with it is the new program to get variables out of
 > /etc/defaults/rc.conf and the like called rc_conf_var.  It's a new
 > addition to /sbin which it bound to be touchy.
 
 Which is exactly why you should have avoided it.  If you'd come up with
 a solution that didn't trample all over holy ground, chances would be
 much better that it would gain acceptance.
 
 Just source /etc/defaults/rc.conf and call the source_rc_confs shell
 function.  That way, folks don't have to resolve a holy war to address
 your problem.
 
 Ciao,
 Sheldon.
 

From: Brooks Davis <brooks@one-eyed-alien.net>
To: Sheldon Hearn <sheldonh@uunet.co.za>
Cc: obrien@FreeBSD.org, FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: conf/18583: [PATCH] DHCP should be able to override hostname.
Date: Tue, 16 May 2000 09:14:21 -0700

 On Tue, May 16, 2000 at 03:57:23PM +0200, Sheldon Hearn wrote:
 > 
 > 
 > On Mon, 15 May 2000 22:33:46 MST, brooks@one-eyed-alien.net wrote:
 > 
 > > My only concern with it is the new program to get variables out of
 > > /etc/defaults/rc.conf and the like called rc_conf_var.  It's a new
 > > addition to /sbin which it bound to be touchy.
 > 
 > Which is exactly why you should have avoided it.  If you'd come up with
 > a solution that didn't trample all over holy ground, chances would be
 > much better that it would gain acceptance.
 > 
 > Just source /etc/defaults/rc.conf and call the source_rc_confs shell
 > function.  That way, folks don't have to resolve a holy war to address
 > your problem.
 
 If that has been a real option, I would have done it.  However, dhclient
 communicates with it's script through the environment and rc.conf et al
 work by spamming the environment.  There is at least one namespace
 collision between them.  The only remotly viable solution I can think of
 is internaly renaming all the environmental variables used to pass
 things to the dhclient-script which is one heck of a disgusting hack.
 It's also likely to be quite annoying to maintain if ISC adds variables.
 However, if the dhclient maintainer agrees that this is the right way to
 do this I'll work up a patch.
 
 -- Brooks
 
 -- 
 Any statement of the form "X is the one, true Y" is FALSE.
 

From: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
To: Brooks Davis <brooks@one-eyed-alien.net>
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: conf/18583: [PATCH] DHCP should be able to override hostname.
Date: Tue, 16 May 2000 12:31:22 -0400 (EDT)

 <<On Tue, 16 May 2000 09:20:02 -0700 (PDT), Brooks Davis <brooks@one-eyed-alien.net> said:
 
 >  If that has been a real option, I would have done it.  However, dhclient
 >  communicates with it's script through the environment and rc.conf et al
 >  work by spamming the environment.
 
 Use a subshell.
 
 -GAWollman
 
 

From: Brooks Davis <brooks@one-eyed-alien.net>
To: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: conf/18583: [PATCH] DHCP should be able to override hostname.
Date: Tue, 16 May 2000 10:02:52 -0700

 On Tue, May 16, 2000 at 12:31:22PM -0400, Garrett Wollman wrote:
 > <<On Tue, 16 May 2000 09:20:02 -0700 (PDT), Brooks Davis <brooks@one-eyed-alien.net> said:
 > 
 > >  If that has been a real option, I would have done it.  However, dhclient
 > >  communicates with it's script through the environment and rc.conf et al
 > >  work by spamming the environment.
 > 
 > Use a subshell.
 
 Thank's for the tip, I'm working up a new patch.
 
 -- Brooks
 
 -- 
 Any statement of the form "X is the one, true Y" is FALSE.
 

From: Brooks Davis <brooks@one-eyed-alien.net>
To: brooks@one-eyed-alien.net
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: conf/18583: [PATCH] DHCP should be able to override hostname.
Date: Tue, 16 May 2000 11:23:12 -0700

 The following is an improved patch which does not supper from the
 problem of adding a new script to /sbin.  Thanks to Garrett Wollman for
 pointing me in the right direction (using a subshell.)
 
 -- Brooks
 
 Index: contrib/isc-dhcp/client/scripts/freebsd
 ===================================================================
 RCS file: /home/ncvs/src/contrib/isc-dhcp/client/scripts/freebsd,v
 retrieving revision 1.9
 diff -u -r1.9 freebsd
 --- contrib/isc-dhcp/client/scripts/freebsd	2000/01/15 22:46:40	1.9
 +++ contrib/isc-dhcp/client/scripts/freebsd	2000/05/16 18:19:45
 @@ -8,6 +8,17 @@
  	LOGGER=echo
  fi
  
 +get_rc_conf_var() {
 +  (if [ -r /etc/defaults/rc.conf ]; then
 +     . /etc/defaults/rc.conf
 +     source_rc_confs
 +   elif [ -r /etc/rc.conf ]; then
 +     . /etc/rc.conf
 +   fi
 +
 +   eval echo \$${1})
 +}
 +
  make_resolv_conf() {
    echo search $new_domain_name >/etc/resolv.conf
    for nameserver in $new_domain_name_servers; do
 @@ -76,7 +87,7 @@
  if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
     [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
    current_hostname=`/bin/hostname`
 -  if [ x$current_hostname = x ] || \
 +  if [ x$current_hostname = x`get_rc_conf_var default_hostname` ] || \
       [ x$current_hostname = x$old_host_name ]; then
      if [ x$new_host_name != x$old_host_name ]; then
        $LOGGER "New Hostname: $new_host_name"
 Index: etc//rc.network
 ===================================================================
 RCS file: /home/ncvs/src/etc/rc.network,v
 retrieving revision 1.79
 diff -u -r1.79 rc.network
 --- etc//rc.network	2000/05/16 06:52:11	1.79
 +++ etc//rc.network	2000/05/16 18:12:19
 @@ -16,8 +16,13 @@
  	# Set the host name if it is not already set
  	#
  	if [ -z "`hostname -s`" ]; then
 -		hostname ${hostname}
 -		echo -n ' hostname'
 +		if [ -n "${hostname}" ]; then
 +			hostname ${hostname}
 +			echo -n ' hostname'
 +		elif [ -n "${default_hostname}" ]; then
 +			hostname ${default_hostname}
 +			echo -n ' default_hostname'
 +		fi
  	fi
  
  	# Set the domainname if we're using NIS
 Index: etc//defaults/rc.conf
 ===================================================================
 RCS file: /home/ncvs/src/etc/defaults/rc.conf,v
 retrieving revision 1.61
 diff -u -r1.61 rc.conf
 --- etc//defaults/rc.conf	2000/05/16 06:52:11	1.61
 +++ etc//defaults/rc.conf	2000/05/16 18:15:46
 @@ -39,6 +39,8 @@
  
  ### Basic network options: ###
  hostname=""			# Set this!
 +default_hostname=""		# ...or this to get a hostname from DHCP.
 +				# NOTE: Only set one of these.
  nisdomainname="NO"		# Set to NIS domain if using NIS (or NO).
  dhcp_program="/sbin/dhclient"	# Path to dhcp client program.
  dhcp_flags=""			# Additional flags to pass to dhcp client.
 -- 
 Any statement of the form "X is the one, true Y" is FALSE.
 

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: Brooks Davis <brooks@one-eyed-alien.net>
Cc: obrien@FreeBSD.org, FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: conf/18583: [PATCH] DHCP should be able to override hostname. 
Date: Tue, 16 May 2000 21:28:19 +0200

 On Tue, 16 May 2000 09:14:21 MST, Brooks Davis wrote:
 
 > If that has been a real option, I would have done it.  However, dhclient
 > communicates with it's script through the environment and rc.conf et al
 > work by spamming the environment.  There is at least one namespace
 > collision between them.
 
 Hmm, not something I thought of, nor something I have a simple solution
 for. :-)
 
 I _do_ think that dhclient-script needs to be taught a way to prevent
 the spamming of /etc/resolv.conf, but I'm pretty sure that's not going
 to solve _this_ problem. :-)
 
 Ciao,
 Sheldon.
 

From: Brooks Davis <brooks@one-eyed-alien.net>
To: Sheldon Hearn <sheldonh@uunet.co.za>
Cc: obrien@FreeBSD.org, FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: conf/18583: [PATCH] DHCP should be able to override hostname.
Date: Tue, 16 May 2000 12:42:37 -0700

 On Tue, May 16, 2000 at 09:28:19PM +0200, Sheldon Hearn wrote:
 > Hmm, not something I thought of, nor something I have a simple solution
 > for. :-)
 
 Garrett Wollman pointed me in the right direction.  My latest hack
 should avoid offending people that way, though I suppose it might offend
 ISC. ;-)
 
 > I _do_ think that dhclient-script needs to be taught a way to prevent
 > the spamming of /etc/resolv.conf, but I'm pretty sure that's not going
 > to solve _this_ problem. :-)
 
 With my rc.conf variable lookup function this should be pretty simple.  I
 just looked at the script again and noticed that what's in there now is
 quite bogus.  The function for creating resolv.conf files is never used
 and resolv.conf files are created two slightly different ways.  If the
 function were used all the time the simple solution would be to check
 for something like "dhcp_update_resolv" not being set to no before
 spamming the file.
 
 -- Brooks
 
 -- 
 Any statement of the form "X is the one, true Y" is FALSE.
 

From: "David O'Brien" <obrien@FreeBSD.org>
To: Sheldon Hearn <sheldonh@uunet.co.za>
Cc: Brooks Davis <brooks@one-eyed-alien.net>,
	FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: conf/18583: [PATCH] DHCP should be able to override hostname.
Date: Tue, 16 May 2000 13:20:48 -0700

 On Tue, May 16, 2000 at 09:28:19PM +0200, Sheldon Hearn wrote:
 > I _do_ think that dhclient-script needs to be taught a way to prevent
 > the spamming of /etc/resolv.conf, but I'm pretty sure that's not going
 > to solve _this_ problem. :-)
 
     supersede domain-name "nuxi.com freebsd.org cdrom.com cs.ucdavis.edu";
     supersede etc.....
 

From: "David O'Brien" <obrien@FreeBSD.org>
To: Brooks Davis <brooks@one-eyed-alien.net>
Cc: Sheldon Hearn <sheldonh@uunet.co.za>,
	FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: conf/18583: [PATCH] DHCP should be able to override hostname.
Date: Tue, 16 May 2000 13:22:20 -0700

 > If that has been a real option, I would have done it.  However, dhclient
 > communicates with it's script through the environment and rc.conf et al
 
 /sbin/dhclient-script should be rewriten.  There is a nice script in a PR
 on dhclient.  However it is the 4-clause BSDL, and the author has not
 replied to my requests to make it a 2 or 3-clause BSDL.
 
 -- 
 -- David  (obrien@FreeBSD.org)
           Disclaimer: Not speaking for FreeBSD, just expressing my own opinion.
 

From: Brooks Davis <brooks@one-eyed-alien.net>
To: "David O'Brien" <obrien@FreeBSD.org>
Cc: Brooks Davis <brooks@one-eyed-alien.net>,
	Sheldon Hearn <sheldonh@uunet.co.za>,
	FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: conf/18583: [PATCH] DHCP should be able to override hostname.
Date: Tue, 16 May 2000 14:06:44 -0700

 On Tue, May 16, 2000 at 01:22:20PM -0700, David O'Brien wrote:
 > > If that has been a real option, I would have done it.  However, dhclient
 > > communicates with it's script through the environment and rc.conf et al
 > 
 > /sbin/dhclient-script should be rewriten.  There is a nice script in a PR
 > on dhclient.  However it is the 4-clause BSDL, and the author has not
 > replied to my requests to make it a 2 or 3-clause BSDL.
 
 Ok, that script does look nice.  Should I consider that to be the
 minimum standard for changes to the dhclient-script?  If so, I guess
 I'll try a re-write of the dhclient-script with an eye towards that
 degree of flexability under a more friendly license.
 
 -- Brooks
 
 -- 
 Any statement of the form "X is the one, true Y" is FALSE.
 

From: "David O'Brien" <obrien@FreeBSD.org>
To: Brooks Davis <brooks@one-eyed-alien.net>
Cc: Sheldon Hearn <sheldonh@uunet.co.za>,
	FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: conf/18583: [PATCH] DHCP should be able to override hostname.
Date: Tue, 16 May 2000 14:19:03 -0700

 On Tue, May 16, 2000 at 02:06:44PM -0700, Brooks Davis wrote:
 > Ok, that script does look nice.  Should I consider that to be the
 > minimum standard for changes to the dhclient-script?
 
 Not sure it matters.  Easy of reading is key for any new script.
 
 
 > I'll try a re-write of the dhclient-script with an eye towards that
 > degree of flexability under a more friendly license.
 
 Cool.
 
 -- 
 -- David  (obrien@FreeBSD.org)
           Disclaimer: Not speaking for FreeBSD, just expressing my own opinion.
 

From: Brooks Davis <brooks@one-eyed-alien.net>
To: "David O'Brien" <obrien@FreeBSD.org>
Cc: Brooks Davis <brooks@one-eyed-alien.net>,
	Sheldon Hearn <sheldonh@uunet.co.za>,
	FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: conf/18583: [PATCH] DHCP should be able to override hostname.
Date: Thu, 18 May 2000 13:31:41 -0700

 On Tue, May 16, 2000 at 02:19:03PM -0700, David O'Brien wrote:
 > On Tue, May 16, 2000 at 02:06:44PM -0700, Brooks Davis wrote:
 > > I'll try a re-write of the dhclient-script with an eye towards that
 > > degree of flexability under a more friendly license.
 > 
 > Cool.
 
 Here is is.  It looks similar to the on in the other PR because I took
 some ideas from it, but it's a new rewrite.  It seems to work in general
 and it has been running on my laptop since last night.  It does want to
 /etc/defaults/rc.conf and /etc/rc.network portions of my previous patch
 with it, but I believe it will work without them.
 
 -- Brooks
 
 -- 
 Any statement of the form "X is the one, true Y" is FALSE.
 
 #!/bin/sh
 
 #############################################################################
 # Copyright (c) 2000 Brooks Davis <brooks@one-eyed-alien.net>
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
 # are met:
 # 1. Redistributions of source code must retain the above copyright
 #    notice, this list of conditions and the following disclaimer.
 # 2. Redistributions in binary form must reproduce the above copyright
 #    notice, this list of conditions and the following disclaimer in the
 #    documentation and/or other materials provided with the distribution.
 #
 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 # SUCH DAMAGE.
 #
 #############################################################################
 # Many of the ideas behind this file are based on a version submitted as
 # pr bin/15342 by Patrick Bihan-Faou, patrick@mindstep.com.  The actual
 # file is a # complete rewrite derived from FreeBSD's v1.9.  This should
 # be almost identical in function to v1.9 except for the support for
 # the default_hostname variable to allow proper disconnected operation.
 #############################################################################
 
 # Use logger(1) if it's available
 #
 if [ -x /usr/bin/logger ]; then
 	LOGGER="/usr/bin/logger -s -p user.notice -t dhclient"
 else
 	LOGGER=echo
 fi
 
 # These functions are to be overridden as necessicary in the optional
 # /etc/dhclient-enter-hooks file.  The pre_state_*_hook functions are
 # called before the (non-overable) if_state_* functions which are
 # followed by calls to the post_state_*_functions.
 #
 pre_state_ARPCHECK_hook() { }
 pre_state_APRSEND_hook() { }
 pre_state_BOUND_hook() { }
 pre_state_EXPIRE_hook() { }
 pre_state_FAIL_hook() { }
 pre_state_MEDIUM_hook() { }
 pre_state_PREINIT_hook() { }
 pre_state_REBIND_hook() { }
 pre_state_REBOOT_hook() { }
 pre_state_RENEW_hook() { }
 pre_state_TIMEOUT_hook() { }
 
 post_state_ARPCHECK_hook() { }
 post_state_APRSEND_hook() { }
 post_state_BOUND_hook() { }
 post_state_EXPIRE_hook() { }
 post_state_FAIL_hook() { }
 post_state_MEDIUM_hook() { }
 post_state_PREINIT_hook() { }
 post_state_REBIND_hook() { }
 post_state_REBOOT_hook() { }
 post_state_RENEW_hook() { }
 post_state_TIMEOUT_hook() { }
 
 # The make_resolv_conf() function may be overridden as well.
 #
 make_resolv_conf() {
 	echo search $new_domain_name >/etc/resolv.conf
 	for nameserver in $new_domain_name_servers; do
 		echo nameserver $nameserver >>/etc/resolv.conf
 	done
 }
 
 # This must be used on exit to allow any exit hooks to be called.
 #
 exit_with_hooks() {
 	exit_status=$1
 	if [ -x /etc/dhclient-exit-hooks ]; then
 		. /etc/dhclient-exit-hooks
 	fi
 	exit $exit_status
 }
 
 # This function does the overriding of functions.  If the local script
 # wishes to, it may abort processing of this state.  The local script
 # must set exit_status to a nonzero value to do so.
 #
 enter_with_hooks() {
 	if [ -x /etc/dhclient-enter-hooks ]; then
 		exit_status=0
 		. /etc/dhclient-enter-hooks
 		# allow the local script to abort processing of this state
 		# local script must set exit_status variable to nonzero.
 		if [ $exit_status -ne 0 ]; then
 			exit_with_hooks $exit_status
 		fi
 	fi
 }
 
 # This function prints any important changes in network config.
 #
 print_net_changes() {
 	if [ -n "$new_host_name" ]; then
 		$LOGGER "New Hostname: $new_host_name"
 	fi
 	if [ -n "$new_ip_address" ]; then
 		$LOGGER "New IP Address ($interface): $new_ip_address"
 	fi
 	if [ -n "$new_subnet_mask" ]; then
 		$LOGGER "New Subnet Mask ($interface): $new_subnet_mask"
 	fi
 	if [ -n "$new_broadcast_address" ]; then
 		$LOGGER "New Broadcast Address ($interface): $new_broadcast_address"
 	fi
 	if [ -n "$new_routers" ]; then
 		$LOGGER "New Routers: $new_routers"
 	fi
 	if [ -n "$new_static_routes" ]; then
 		$LOGGER "New Static Routes: $new_static_routes"
 	fi
 }
 
 # Utility functions.
 #
 add_route() {
 	route add $1 $2 > /dev/null 2>&1
 }
 
 delete_route() {
 	route delete $1 $2 > /dev/null 2>&1
 }
 
 add_routers() {
 	eval routers="\$${1}_routers"
 	for router in $routers; do
 		add_route default $router
 	done
 }
 
 delete_routers() {
 	eval routers="\$${1}_routers"
 	for router in $routers; do
 		delete_route default $router
 	done
 }
 
 add_static_routes() {
 	eval static_routes="\$${1}_static_routes"
 	set "$static_routes"
 	while [ $# -gt 1 ]; do
 		add_route $1 $2
 		shift; shift
 	done
 }
 
 delete_static_routes() {
 	eval static_routes="\$${1}_static_routes"
 	set "$static_routes"
 	while [ $# -gt 1 ]; do
 		delete_route $1 $2
 		shift; shift
 	done
 }
 
 config_ip_address() {
 	eval address="\$${1}_ip_address"
 	eval netmask="\$${1}_subnet_mask"
 	eval broadcast="\$${1}_broadcast_address"
 
 	if [ -n "$address" ]; then
 		ifconfig $interface inet $address netmask $netmask \
 			broadcast $broadcast $medium
 	fi
 }
 
 delete_ip_address() {
 	eval address="\$${1}_ip_address"
 
 	if [ -n "$address" ]; then
 		ifconfig inet delete $address $medium
 	fi
 }
 
 clear_arp_table() {
 	arp -d -a
 }
 
 get_rc_conf_var() {
 	(
 		if [ -r /etc/defaults/rc.conf ]; then
 			. /etc/defaults/rc.conf
 			source_rc_confs
 		elif [ -r /etc/rc.conf ]; then
 			. /etc/rc.conf
 		fi
 
 		eval echo \$${1}
 	)
 }
 
 set_hostname() {
 	current_hostname=`hostname`
 	if [ "$current_hostname" = "`get_rc_conf_var default_hostname`" ] || \
 		[ "$current_hostname" = "$old_host_name" ]; then
 		if [ "$new_host_name" != "$old_host_name" ] && \
 			[ -n "$new_host_name" ]; then
 			hostname $new_host_name
 		fi
 	fi
 }
 
 config_alias() {
 	if [ -n "$alias_ip_address" ]; then
 		ifconfig $interface inet $alias_ip_address \
 			netmask $alias_subnet_mask
 	fi
 }
 
 delete_alias() {
 	if [ -n "$alias_ip_address" ]; then
 		delete_ip_address alias
 		delete_route $alias_ip_address 127.0.0.1
 	fi
 }
 
 test_lease() {
 	if [ -n "$new_routers" ]; then
 		config_ip_address new
 		set $new_routers
 		if ping -q -c $1; then
 			rval=0
 		else
 			rval=1
 		fi
 		delete_ip_address new
 	else
 		rval=1
 	fi
 
 	return $rval
 }
 
 config_new() {
 	config_ip_address new
 	if [ "$alias_ip_address" != "$new_ip_address" ]; then
 		config_alias
 	fi
 	add_routers new
 	add_static_routes new
 	make_resolv_conf
 }
 
 delete_old() {
 	delete_ip_address old
 	delete_routers old
 	delete_static_routes old
 	clear_arp_table
 }
 
 # in_state_* functions.  These should not be overridden in the hooks files.
 #
 in_state_ARPCHECK() {
 	exit_status=0
 }
 
 in_state_APRSEND() {
 	exit_status=0;
 }
 
 in_state_BOUND() {
 	set_hostname
 	if [ "$alias_ip_address" != "$old_ip_address" ]; then
 		delete_alias
 	fi
 	if [ -n "$old_ip_address" ] && \
 		[ "$old_ip_address" != "$new_ip_address" ]; then
 		delete_old
 	fi
 	config_new
 	exit_status=0
 }
 
 in_state_EXPIRE() {
 	if_state_FAIL
 }
 
 in_state_FAIL() {
 	delete_alias
 	delete_old
 	config_alias
 	exit_status=0
 }
 
 in_state_MEDIUM() {
 	ifconfig $interface $medium
 	ifconfig $interface inet delete 0.0.0.0 $medium >/dev/null 2>&1
 	sleep 1
 	exit_status=0
 }
 
 in_state_PREINIT() {
 	delete_alias
 	ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \
 		broadcast 255.255.255.255 up
 	exit_status=0
 }
 
 in_state_REBIND() {
 	set_hostname
 	if [ "$alias_ip_address" != "$old_ip_address" ]; then
 		delete_alias
 	fi
 	if [ "$old_ip_address" != "$new_ip_address" ]; then
 		delete_old
 		config_new
 	fi
 	exit_status=0
 }
 
 in_state_REBOOT() {
 	in_state_BOUND
 }
 
 in_state_RENEW() {
 	in_state_REBIND
 }
 
 in_state_TIMEOUT() {
 	delete_alias
 	if test_lease; then
 		config_new
 		exit_status=0
 	else
 		delete_old
 		config_alias
 		exit_status=1
 	fi
 }
 
 # Actually do something
 #
 enter_with_hooks
 print_net_changes
 pre_state_${reason}_hook
 in_state_${reason}
 post_state_${reason}_hook
 exit_with_hooks $exit_status
 

From: "Patrick Bihan-Faou" <patrick@mindstep.com>
To: <freebsd-gnats-submit@FreeBSD.org>, <brooks@one-eyed-alien.net>
Cc:  
Subject: Re: conf/18583: [PATCH] DHCP should be able to override hostname.
Date: Tue, 11 Jul 2000 03:53:54 -0400

 Hi,
 
 Although I appreciate the fact that you give credit in your version of the
 script I submitted for the DHCP client stuff, I would not go as far as
 calling it a full rewrite.
 
 Anyway, I have fixed the licence on the original version of that script, and
 it is now a 2 clause BSD (which was my intent to begin with). My silence on
 this issue was due to a wrong email address...
 
 Please update the script as you think is necessary, but don't call it a full
 rewrite if it is not one :).
 
 Also I think that not catching unexpected values for $reason is potentially
 dangerous in your script, as well as not keeping the "local" qualifiers for
 variables that are used only in the script functions.
 
 
 Sincerely,
 
 
 Patrick.
 
 
 
Responsible-Changed-From-To: freebsd-bugs->obrien 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Tue Jul 11 01:31:45 PDT 2000 
Responsible-Changed-Why:  
Over to the DHCP maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=18583 

From: Brooks Davis <brooks@one-eyed-alien.net>
To: Patrick Bihan-Faou <patrick@mindstep.com>
Cc: freebsd-gnats-submit@FreeBSD.org, brooks@one-eyed-alien.net,
	obrien@FreeBSD.org
Subject: Re: conf/18583: [PATCH] DHCP should be able to override hostname.
Date: Tue, 11 Jul 2000 10:42:17 -0700

 On Tue, Jul 11, 2000 at 03:53:54AM -0400, Patrick Bihan-Faou wrote:
 > Although I appreciate the fact that you give credit in your version of the
 > script I submitted for the DHCP client stuff, I would not go as far as
 > calling it a full rewrite.
 
 I'd rather your script was comitted as the ideas where yours.  Since these
 things need to be submitted to ISC I will attempt to create patches
 to your script to add the support I want so the patched version can be
 submitted to ISC in one go (assuming David hasn't done so already).
 
 -- Brooks
 
 -- 
 Any statement of the form "X is the one, true Y" is FALSE.
 

From: "David O'Brien" <obrien@FreeBSD.org>
To: Brooks Davis <brooks@one-eyed-alien.net>
Cc: Patrick Bihan-Faou <patrick@mindstep.com>,
	freebsd-gnats-submit@FreeBSD.org
Subject: Re: conf/18583: [PATCH] DHCP should be able to override hostname.
Date: Tue, 11 Jul 2000 11:11:16 -0700

 On Tue, Jul 11, 2000 at 10:50:01AM -0700, Brooks Davis wrote:
 >  Since these things need to be submitted to ISC I will attempt to
 >  create patches to your script to add the support I want so the patched
 >  version can be submitted to ISC in one go (assuming David hasn't done
 >  so already).
 
 I doubt I will submit this script to ISC.  (1) I'm not the author of it,
 and (2) its structure is so much different from the ISC's* I doubt they
 will accept it [but I could of course be wrong].
 
 *and thus the reason it is so preferable to the ISC one.
   
 -- 
 -- David  (obrien@FreeBSD.org)
 

From: Brooks Davis <brooks@one-eyed-alien.net>
To: brooks@one-eyed-alien.net
Cc: FreeBSD-gnats-submit@FreeBSD.ORG,
	"David O'Brien" <obrien@FreeBSD.ORG>
Subject: Re: conf/18583: [PATCH] DHCP should be able to override hostname.
Date: Wed, 23 Aug 2000 16:21:58 -0700

 Here's the latest iteration of this patch.  Since it appears the
 currently ISC derived script is here to say and that it has been taken
 off the vendor branch, I can't see any reason not to commit this.
 
 Thanks,
 Brooks
 
 Index: contrib/isc-dhcp/client/scripts/freebsd
 ===================================================================
 RCS file: /home/ncvs/src/contrib/isc-dhcp/client/scripts/freebsd,v
 retrieving revision 1.17
 diff -u -u -r1.17 freebsd
 --- contrib/isc-dhcp/client/scripts/freebsd	2000/07/28 09:20:39	1.17
 +++ contrib/isc-dhcp/client/scripts/freebsd	2000/08/01 18:11:52
 @@ -8,6 +8,17 @@
  	LOGGER=echo
  fi
  
 +get_rc_conf_var() {
 +  (if [ -r /etc/defaults/rc.conf ]; then
 +     . /etc/defaults/rc.conf
 +     source_rc_confs
 +   elif [ -r /etc/rc.conf ]; then
 +     . /etc/rc.conf
 +   fi
 +
 +   eval echo \$${1})
 +}
 +
  make_resolv_conf() {
    echo search $new_domain_name >/etc/resolv.conf
    for nameserver in $new_domain_name_servers; do
 @@ -76,7 +87,7 @@
  if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
     [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
    current_hostname=`/bin/hostname`
 -  if [ x$current_hostname = x ] || \
 +  if [ x$current_hostname = x`get_rc_conf_var default_hostname` ] || \
       [ x$current_hostname = x$old_host_name ]; then
      if [ x$new_host_name != x$old_host_name ]; then
        $LOGGER "New Hostname: $new_host_name"
 Index: etc/rc.network
 ===================================================================
 RCS file: /home/ncvs/src/etc/rc.network,v
 retrieving revision 1.83
 diff -u -u -r1.83 rc.network
 --- etc/rc.network	2000/08/16 23:08:28	1.83
 +++ etc/rc.network	2000/08/21 16:28:53
 @@ -16,8 +16,13 @@
  	# Set the host name if it is not already set
  	#
  	if [ -z "`hostname -s`" ]; then
 -		hostname ${hostname}
 -		echo -n ' hostname'
 +		if [ -n "${hostname}" ]; then
 +			hostname ${hostname}
 +			echo -n ' hostname'
 +		elif [ -n "${default_hostname}" ]; then
 +			hostname ${default_hostname}
 +			echo -n ' default_hostname'
 +		fi
  	fi
  
  	# Set the domainname if we're using NIS
 Index: etc/defaults/rc.conf
 ===================================================================
 RCS file: /home/ncvs/src/etc/defaults/rc.conf,v
 retrieving revision 1.77
 diff -u -u -r1.77 rc.conf
 --- etc/defaults/rc.conf	2000/08/18 09:37:50	1.77
 +++ etc/defaults/rc.conf	2000/08/21 16:28:55
 @@ -38,6 +38,8 @@
  
  ### Basic network and firewall/security options: ###
  hostname=""			# Set this!
 +default_hostname=""		# ...or this to get a hostname from DHCP.
 +				# NOTE: Only set one of these.
  nisdomainname="NO"		# Set to NIS domain if using NIS (or NO).
  dhcp_program="/sbin/dhclient"	# Path to dhcp client program.
  dhcp_flags=""			# Additional flags to pass to dhcp client.
 Index: share/man/man5/rc.conf.5
 ===================================================================
 RCS file: /home/ncvs/src/share/man/man5/rc.conf.5,v
 retrieving revision 1.80
 diff -u -u -r1.80 rc.conf.5
 --- share/man/man5/rc.conf.5	2000/08/18 09:37:48	1.80
 +++ share/man/man5/rc.conf.5	2000/08/21 16:33:50
 @@ -130,6 +130,14 @@
  you are not connected to a network.  If you are using
  .Xr dhclient 8
  to set your hostname via DHCP, this variable should be set to an empty string.
 +.It Ar default_hostname
 +If you are using
 +.Xr dhclient 8
 +to set your hostname via DHCP and will be operating without a network
 +sometimes, set this to something meaningful to be used in those cases.
 +You should set
 +.Ar hostname
 +to an empty string if this is set.
  .It Ar nisdomainname
  (str) The NIS domainname of your host, or
  .Ar NO
 
Responsible-Changed-From-To: obrien->freebsd-bugs 
Responsible-Changed-By: obrien 
Responsible-Changed-When: Fri Nov 10 11:24:33 PST 2000 
Responsible-Changed-Why:  
This is not a dhclient issue, but an /etc/rc one. 
I have synced the FreeBSD dhclient 2.0 script with the ISC version 3 one. 
If you still have a problem, needed changes should be addressed to the 
ISC DHCP developers.  I will not maintain a greatly rouge version of the 
dhclient script.  It makes taking bug fixes from ISC just too hard. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=18583 

From: Brooks Davis <brooks@one-eyed-alien.net>
To: FreeBSD-gnats-submit@FreeBSD.ORG
Cc:  
Subject: Re: conf/18583: [PATCH] DHCP should be able to override hostname.
Date: Sun, 27 May 2001 22:46:31 -0700

 --sm4nu43k4a2Rpi4c
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 Please close this PR, the problem needs to be fixed via ISC.
 
 -- Brooks
 
 --=20
 Any statement of the form "X is the one, true Y" is FALSE.
 PGP fingerprint 655D 519C 26A7 82E7 2529  9BF0 5D8E 8BE9 F238 1AD4
 
 --sm4nu43k4a2Rpi4c
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.0.4 (GNU/Linux)
 Comment: For info see http://www.gnupg.org
 
 iD8DBQE7EeY3XY6L6fI4GtQRAtlQAJ9JrVhDDHzAvIFzthaD4KatsCtEAwCfQwO4
 IAb1UpVG1p9FJzFDc15bb6w=
 =tDJE
 -----END PGP SIGNATURE-----
 
 --sm4nu43k4a2Rpi4c--
State-Changed-From-To: open->closed 
State-Changed-By: roam 
State-Changed-When: Sun May 27 23:20:25 PDT 2001 
State-Changed-Why:  
Submitter agrees the problem needs to be taken up with ISC. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=18583 
>Unformatted:
