Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Nov 2002 23:23:33 -0800
From:      Rich Morin <rdm@cfcl.com>
To:        hackers@FreeBSD.ORG
Subject:   Re: auto-definition of a single network interface
Message-ID:  <p05200f11b9fba0655ad1@[192.168.254.205]>
In-Reply-To: <p05200f10b9fb4d3ddd44@[192.168.254.205]>
References:  <p05200f10b9fb4d3ddd44@[192.168.254.205]>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?p05200f11b9fba0655ad1>