Subject: Re:
To: koen.victor@pandora.be <koen.victor@pandora.be>
From: Steven M. Bellovin <smb@research.att.com>
List: netbsd-users
Date: 08/12/2003 17:53:22
In message <20030812213340.280294BAD8@euros.telenet-ops.be>, "koen.victor@pando
ra.be" writes:
>Hi,
>
>If my laptop isn't physically connected to the network, dhclient still request
>s an ip from the dhcp server. 
>I could set the timeout to some low value, but that 's not a 'perfect' solutio
>n.
>What I'd like is that dhclient is only started when the network cable is conne
>cted to the laptop.
>
>I tried it in /etc/rc.conf with
>
>VAR=$(ifconfig vr0 | grep 'status: active')
>ARG="status: active"
>ARG=$(echo -e "\t$ARG")
>dhclient=NO
>dhclient_flags="vr0"
>if [ "$VAR" = "$ARG" ]
>then
>dhclient=YES
>dhclient_flags="vr0"
>fi
>
>but dhclient doesn't appear to get set.
>
>How can this be done?

There are two issues.  The first is that your code is probably buggy, 
since it uses grep and grep is in /usr/bin.  /usr is probably not 
mounted at that point, though you could probably manage that by playing 
with parameters to mountcriticallocal.  Even without that, you could 
rewrite your code using shell constructs.

The ability to sense 'status: active' depends on the device being up.  
At the least, you need to do 'ifconfig vr0 up' and wait a couple of 
seconds before polling the device.  Even then, I've found it unreliable.
I added similar code to /etc/apm/resume -- in which I restart dhclient 
-- but it never worked right, for reasons I never figured out.  

		--Steve Bellovin, http://www.research.att.com/~smb