Date: Fri, 15 Nov 2002 18:18:37 -0800 From: Rich Morin <rdm@cfcl.com> To: hackers@freebsd.org Subject: auto-definition of a single network interface Message-ID: <p05200f10b9fb4d3ddd44@[192.168.254.205]>
next in thread | raw e-mail | index | archive | help
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 <rdm@cfcl.com>, 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?p05200f10b9fb4d3ddd44>
