From owner-freebsd-hackers Fri Nov 15 23:32:11 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 639E337B401 for ; Fri, 15 Nov 2002 23:32:08 -0800 (PST) Received: from cfcl.com (cpe-24-221-172-174.ca.sprintbbd.net [24.221.172.174]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5F62D43E42 for ; Fri, 15 Nov 2002 23:32:07 -0800 (PST) (envelope-from rdm@cfcl.com) Received: from [192.168.254.205] ([192.168.254.205]) by cfcl.com (8.12.6/8.11.1) with ESMTP id gAG7WVoU000631 for ; Fri, 15 Nov 2002 23:32:32 -0800 (PST) (envelope-from rdm@cfcl.com) Mime-Version: 1.0 Message-Id: In-Reply-To: References: X-Mailer: Eudora for Macintosh! Date: Fri, 15 Nov 2002 23:23:33 -0800 To: hackers@FreeBSD.ORG From: Rich Morin Subject: Re: auto-definition of a single network interface Content-Type: text/plain; charset="us-ascii" ; format="flowed" Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Hearing no objections (:-), I decided to go ahead with this effort. I have created a script named /etc/rc.ifsgl, which is invoked by (the FreeBSD 4.7 RELEASE version of) /etc/rc.network, as follows: 183a184,185 > . /etc/rc.ifsgl # handle sgl_ifconfig variable (etc). > That is, just before the lines: dhcp_interfaces="" for ifn in ${network_interfaces}; do ... The relevant lines in rc.conf look like: === sgl_ifconfig=" inet 192.168.254.193 netmask 255.255.255.0" sgl_ifconfig_alias0="inet 192.168.254.199 netmask 255.255.255.255" === The script itself looks like this: === : # rc.ifsgl - handle sgl_ifconfig and sgl_ifconfig_aliasN variables # # Sourced by rc.network; sets ifconfig_XX0 variable if sgl_ifconfig is set # and exactly one "link" interface has been detected. Also adds aliases, # as defined by sgl_ifconfig_aliasN variables. # # Written by Rich Morin, CFCL, 2002.11 # set -x # DEBUG # sgl_ifconfig=" inet 192.168.254.193 netmask 255.255.255.0" # DEBUG # sgl_ifconfig_alias0="inet 192.168.254.199 netmask 255.255.255.255" # DEBUG # LOG=/tmp/rc.ifsgl.log # DEBUG for once in aboot; do if [ "$sgl_ifconfig" ]; then ifns=`ifconfig -l link` if [ ! "$ifns" ]; then echo "rc.ifsgl: no 'link' interfaces found." break fi # echo "ifns=|$ifns|" > /tmp/rc.ifsgl.log # DEBUG cnt= for ifn in $ifns; do eval test=\$ifconfig_${ifn} if [ "$test" ]; then echo "rc.ifsgl: interface ($ifn) already defined." break fi cnt=".$cnt" done if [ "$test" ]; then break fi if [ "$cnt" != '.' ]; then echo "rc.ifsgl: more than one interface found." break fi eval ifconfig_${ifn}=\$sgl_ifconfig # echo "VAR: ifconfig_${ifn}" >> $LOG # DEBUG # eval echo "VAL: \$ifconfig_${ifn}" >> $LOG # DEBUG alias=0 while : ; do eval test=\$sgl_ifconfig_alias${alias} if [ ! "$test" ]; then break fi eval ifconfig_${ifn}_alias${alias}=\$test # echo "VAR: ifconfig_${ifn}_alias${alias}" >> $LOG # DEBUG # eval echo "VAL: \$ifconfig_${ifn}_alias${alias}" >> $LOG # DEBUG alias=$((${alias} + 1)) done fi done # set +x === I am currently using this setup on my production machine, so I guess I'm pretty confident that it's doing what _I_ need correctly. I'm not at all sure, however, that I'm taking every other possible system configuration into account. So, again, comments are solicited... -r -- email: rdm@cfcl.com; phone: +1 650-873-7841 http://www.cfcl.com/rdm - my home page, resume, etc. http://www.cfcl.com/Meta - The FreeBSD Browser, Meta Project, etc. http://www.ptf.com/dossier - Prime Time Freeware's DOSSIER series http://www.ptf.com/tdc - Prime Time Freeware's Darwin Collection To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message