Subject: preconfiguring dhclient interfaces
To: None <netbsd-users@netbsd.org>
From: Steve Bellovin <smb@research.att.com>
List: netbsd-users
Date: 11/22/2002 10:57:18
I want to ensure that dhclient only runs on certain interfaces, to 
prevent it from overwriting the static address for vmnet1.  I can't set 
dhclient_flags, because wi0 is sometimes present and sometimes not.  
Instead, I wrote the following script, which I put into
/etc/rc.conf.d/dhclient (though it could -- should? -- go into
/etc/rc.d/dhclient.



#!/bin/sh

dhclient_precmd()
{
        if [ "x$dhclient_flags" = x -a -f /etc/dhcpinterface ]
        then
                iface="/"
                for i in `ifconfig -l`
                do
                        iface="$iface$i/"
                done

                rc_flags=""
                while read x
                do
                        if expr "$x" : "#" >/dev/null
                        then
                                continue
                        fi
                        if expr "$iface" : ".*/$x/" >/dev/null
                        then
                                rc_flags="$rc_flags $x"
                        fi
                done </etc/dhcpinterface
                echo $rc_flags
        fi
}

start_precmd=dhclient_precmd
restart_precmd=dhclient_precmd


The file /etc/dhcpinterface lists the allowable dhcp interfaces; 
however, only those that actually exist are passed in.  There are some 
obvious and easy ways to accomplish the match more easily; however, I 
needed something that only used commands in /bin, because at boot time 
dhclient runs before /usr is mounted.  (Let's not dredge up *that* 
argument again....)

The script is skipped if dhclient_flags has been set explicitly by the 
user.  (Should I be checking rc_flags there?)

In my /etc/apm/resume script, I invoked '/etc/rc.d/dhclient restart'.


		--Steve Bellovin, http://www.research.att.com/~smb (me)
		http://www.wilyhacker.com ("Firewalls" book)