Hi list, occasionally I'm in the situation where having multiple configurations for a single network interface are handy to have.
Admittedly, this doesn't affect servers as much as notebooks, where using severals wifi nets/logins is the average case. Most seamlessly, this could be handled by using an arbitrary extension to the hostname.if files, separated by and additional dot (e.g. hostname.athn0.home, hostname.em0.bak20120223). Below a diff to /etc/netstart is attached, that strips the suffix including the dot from hostname.if.suffix (if it is present) and otherwise allows such files to be used. I tried to change the code of netstart as minimally as possible. An interesting side-effect is the ease with which wifi cell changes can now be handled by ifstated. I'd suppose that this must scratch the itch of other users, too. However as this is only a rough guess, I'm curious to hear some opinions on it. All the best, /Markus --- /etc/netstart Tue Dec 20 18:54:07 2011 +++ netstart Thu Feb 16 11:15:14 2012 @@ -18,7 +18,7 @@ _n=$1 while [ ${#_n} != 0 ]; do case $_n in - [A-Za-z0-9]*) ;; + [A-Za-z0-9.]*) ;; *) return 1;; esac _n=${_n#?} @@ -26,6 +26,14 @@ return 0 } +# Strips everything from the first dot, if applicable +raw() { + local_r + _r=$1 + _r=${_r%%.*} + echo $_r +} + # Start the $1 interface ifstart() { if=$1 @@ -47,9 +55,9 @@ chmod -LR o-rwx $file chown -LR root.wheel $file fi - if ! ifconfig $if > /dev/null 2>&1; then + if ! ifconfig `raw $if` > /dev/null 2>&1; then # Try to create interface if it does not exist - if ! ifconfig $if create > /dev/null 2>&1; then + if ! ifconfig `raw $if` create > /dev/null 2>&1; then return fi fi @@ -83,13 +91,13 @@ [ "$name" = "NONE" ] && name= [ "$mask" = "NONE" ] && mask= [ "$bcaddr" = "NONE" ] && bcaddr= - cmd="ifconfig $if $name $mask $bcaddr $ext1 $ext2 down" - cmd="$cmd;dhclient $if" - dhcpif="$dhcpif $if" + cmd="ifconfig `raw $if` $name $mask $bcaddr $ext1 $ext2 down" + cmd="$cmd;dhclient `raw $if`" + dhcpif="$dhcpif `raw $if`" ;; "rtsol") - rtsolif="$rtsolif $if" - cmd="ifconfig $if $name $mask $bcaddr $ext1 $ext2 up" + rtsolif="$rtsolif `raw $if`" + cmd="ifconfig `raw $if` $name $mask $bcaddr $ext1 $ext2 up" ;; *) read dt dtaddr @@ -104,7 +112,7 @@ else alias= fi - cmd="ifconfig $if $af $alias $name" + cmd="ifconfig 4raw $if4 $af $alias $name" case "$dt" in dest) cmd="$cmd $dtaddr" @@ -149,7 +157,8 @@ # don't start "$2" interfaces ifmstart() { for sif in ${1:-ALL}; do - for hn in /etc/hostname.*; do + # Only loop over real interfaces + for hn in /etc/hostname.*([A-Za-z0-9]); do # Strip off /etc/hostname. prefix if=${hn#/etc/hostname.} test "$if" = "*" && continue