From owner-freebsd-hackers Fri Nov 15 18:18:49 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 E073B37B401 for ; Fri, 15 Nov 2002 18:18:46 -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 3FB1E43E88 for ; Fri, 15 Nov 2002 18:18:46 -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 gAG2JDEu021809 for ; Fri, 15 Nov 2002 18:19:14 -0800 (PST) (envelope-from rdm@cfcl.com) Mime-Version: 1.0 Message-Id: X-Mailer: Eudora for Macintosh! Date: Fri, 15 Nov 2002 18:18:37 -0800 To: hackers@freebsd.org From: Rich Morin Subject: 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 I had a recent experience in which my FreeBSD system would not configure my Ethernet card because the specification in rc.conf was for a different type of card. It seems like FreeBSD could easily handle the general case (only one network interface) automagically, letting folks with fancier systems add more specific configuration information. So, instead of: ifconfig_dc0=" inet 192.168.254.193 netmask 255.255.255.0" one could use: ifconfig_SGL=" inet 192.168.254.193 netmask 255.255.255.0" and the system would automagically configure a single networking interface. Here is a first-cut implementation of some code to do this: ================= : # iffy - automagical definition of interfaces # # Written by Rich Morin , CFCL, 2002.11 # set -x # DEBUG ifconfig_SGL="inet 192.168.254.193 netmask 255.255.255.0" # DEBUG if [ "$ifconfig_SGL" ]; then ifns=`ifconfig -l link` if [ ! "$ifns" ]; then echo "no interfaces found" # DEBUG exit fi echo "ifns=|$ifns|" # DEBUG cnt= for ifn in $ifns; do eval test=\$ifconfig_${ifn} if [ "$test" ]; then echo "interface ($ifn) defined" # DEBUG exit fi cnt=".$cnt" done if [ "$cnt" != '.' ]; then echo "too many interfaces found" # DEBUG exit fi eval ifconfig_${ifn}=\$ifconfig_SGL echo "VAR: ifconfig_${ifn}" # DEBUG eval echo "VAL: \$ifconfig_${ifn}" # DEBUG fi ================= It could be made a bit fancier, to be sure. For example, it would be nice to handle things like ifconfig_SGL_alias0="inet 192.168.254.199 netmask 255.255.255.255" First, however, I'd like to know if the general idea/approach/... is faulty. Comments, anyone? -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