Bug 18583

Summary: [PATCH] DHCP should be able to override hostname.
Product: Base System Reporter: brooks <brooks>
Component: confAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 5.0-CURRENT   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description brooks 2000-05-16 06:40:00 UTC
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.

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.
How-To-Repeat: 
Try using DHCP for configuration at multiple sites and using your laptop
disconnected as well.
Comment 1 Sheldon Hearn 2000-05-16 14:57:23 UTC
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.
Comment 2 brooks 2000-05-16 17:14:21 UTC
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.
Comment 3 Garrett A. Wollman 2000-05-16 17:31:22 UTC
<<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
Comment 4 brooks 2000-05-16 18:02:52 UTC
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.
Comment 5 brooks 2000-05-16 19:23:12 UTC
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.
Comment 6 Sheldon Hearn 2000-05-16 20:28:19 UTC
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.
Comment 7 brooks 2000-05-16 20:42:37 UTC
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.
Comment 8 David E. O'Brien freebsd_committer freebsd_triage 2000-05-16 21:20:48 UTC
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.....
Comment 9 David E. O'Brien freebsd_committer freebsd_triage 2000-05-16 21:22:20 UTC
> 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.
Comment 10 brooks 2000-05-16 22:06:44 UTC
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.
Comment 11 David E. O'Brien freebsd_committer freebsd_triage 2000-05-16 22:19:03 UTC
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.
Comment 12 brooks 2000-05-18 21:31:41 UTC
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
Comment 13 patrick 2000-07-11 08:53:54 UTC
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.
Comment 14 Sheldon Hearn freebsd_committer freebsd_triage 2000-07-11 09:31:45 UTC
Responsible Changed
From-To: freebsd-bugs->obrien

Over to the DHCP maintainer.
Comment 15 brooks 2000-07-11 18:42:17 UTC
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.
Comment 16 David E. O'Brien freebsd_committer freebsd_triage 2000-07-11 19:11:16 UTC
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)
Comment 17 brooks 2000-08-24 00:21:58 UTC
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
Comment 18 David E. O'Brien freebsd_committer freebsd_triage 2000-11-10 19:24:33 UTC
Responsible Changed
From-To: obrien->freebsd-bugs

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.
Comment 19 brooks 2001-05-28 06:46:31 UTC
Please close this PR, the problem needs to be fixed via ISC.

-- Brooks

-- 
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
Comment 20 Peter Pentchev freebsd_committer freebsd_triage 2001-05-28 07:20:25 UTC
State Changed
From-To: open->closed

Submitter agrees the problem needs to be taken up with ISC.