Subject: bin/21110: dhclient-script sometimes runs a useless ifconfig
To: None <>
From: None <kre@munnari.OZ.AU>
List: netbsd-bugs
Date: 04/12/2003 21:10:03
>Number:         21110
>Category:       bin
>Synopsis:       dhclient-script sometimes runs a useless ifconfig
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Apr 12 07:15:00 PDT 2003
>Originator:     Robert Elz
>Release:        NetBSD 1.6Q
	Prince of Songkla University
System: NetBSD 1.6L NetBSD 1.6L (DELTA) #29: Fri Jan 10 11:40:50 ICT 2003 i386
	This is just the system I'm running send-pr from and is irrelevant.

Architecture: i386
Machine: i386

	dhclient(8) reads a configuration file dhclient.conf(5), which
	allows various configuration options to be set.  One of those
	is what dhclient calls the "media" for the interface, and while
	it is normally used to allow dhclient to choose between things
	like 10base2 and 10baseT for interfaces where automatic selection
	doesn't work, it can be used to give any desired ifconfig command
	where any of several possibilities might be needed.
	I used it to configiure WEP keys for an 802.11 interface.

	One possibility that might arise (does arise...) is that the
	user might want to try dhclient with no specified media (allow
	automatic selection) and then if that fails, try configuring
	various possibilities.

	dhclient.conf allows this with a syntax like

		interface "xxN" {
			media "", "media 100baseTX full-duplex",
				"media 100baseTX", ... ;

	when dhclient is running on interface xxN, it uses the media
	specifications, one by one, as long as it fails to get a response
	from the DHCP server.

	"Uses the media specifications" means running dhclient-script
	with $reason == "MEDIUM" and the desired ifconfig args in "$medium".

	dhclient-script just does "ifconfig $interface $medium"
	which is exactly what is needed.

	That is, in all cases except where $medium is "".
	In that case, what dhclient-script ends up doing is

		ifconfig $interface

	which is harmless (changes nothing, which was the intent of
	the empty media spec in dhclient.conf) but with this usage,
	ifconfig spews the interface status on stdout (which in normal
	usage is the console).   That's unnecessary, and potentially

	Create /etc/dhclient.conf with a media specification for an
	interface (say wi0) as above, with an empty media specification
	(there is no need to also have others).

	Run "dhclient wi0"

	Observe the results of "ifconfig wi0" produced on stdout, and
	wonder why, since that doesn't happen without the media clause
	in dhclient.conf (nor with a media clause that actually does

	Apply the following patch.   This patch can be applied with, or
	without, the patch I sent in my previous PR, (bin/21109) - though
	it will apply with an offset of 1 line (-1 lines really) if that
	patch has not previously been applied (similarly the patch in
	bin/21109 can be applied after this one if you really need to,
	that one is a more important fix though).

	This just causes dhclient-script to do nothing at all if called
	with $reason==MEDIUM and $medium=="" which is what it always should
	have been doing.

--- dhclient-script.OLD	Sat Apr 12 20:24:36 2003
+++ dhclient-script.NEW	Sat Apr 12 20:27:14 2003
@@ -129,6 +129,8 @@
 case "$reason" in
+	test -z "$medium" && exit_with_hooks 0
 	eval "ifconfig $interface $medium"
 	eval "ifconfig $interface inet -alias $medium" >/dev/null 2>&1