Subject: Ideas for more enhancements to /etc/netstart
To: None <tech-userlevel@NetBSD.ORG>
From: Luke Mewburn <lukem@connect.com.au>
List: tech-userlevel
Date: 04/13/1997 16:07:42
[ I've put the discussion in tech-userlevel because I thought that
  was the most appropriate mailing list. ]

Recently changes were made to /etc/netstart to support
/etc/ifconfig.XYZ files, and a variant for those who prefer
one centralised config file (/etc/rc.conf): $interface_XYZ

There's still a couple of files in /etc related to network
configuration that could have rc.conf equivalents added.

I also believe that we could add alternatives for /etc/ifaliases.
For each interface XYZ that is configured, if $ifaliases_XYZ is
defined, with pairs of "addr netmask" (or `-' for netmask if you
want to leave it as per the main interface netmask), add aliases.

These are (with suggested variable names):
	file			variable
	----			--------
	/etc/myname		$hostname
	/etc/defaultdomain	$domainname
	/etc/mygate		$defaultroute
	/etc/ifaliases		$ifaliases_XYZ

Patches to /etc/netstart to support this are as follows. If there
aren't any objections (that can't be fixed), I'll commit this stuff:


*** netstart.presnafu	Wed Apr  2 22:10:31 1997
--- netstart	Sun Apr 13 16:05:29 1997
***************
*** 3,13 ****
  #	$NetBSD: netstart,v 1.32 1997/04/01 19:36:19 perry Exp $
  #	from: @(#)netstart	8.1 (Berkeley) 7/23/93
  
! # /etc/myname contains my symbolic name
! #
! hostname=`cat /etc/myname`
  hostname $hostname
! if [ -f /etc/defaultdomain ]; then
  	domainname `cat /etc/defaultdomain`
  fi
  
--- 3,20 ----
  #	$NetBSD: netstart,v 1.32 1997/04/01 19:36:19 perry Exp $
  #	from: @(#)netstart	8.1 (Berkeley) 7/23/93
  
! # If $hostname contains "DEFAULT", look in /etc/myname for my symbolic name
! # otherwise use $hostname.
! 
! if [ "$hostname" = DEFAULT ]; then
! 	hostname=`cat /etc/myname`
! fi
  hostname $hostname
! 
! # Check $domainname first, then /etc/defaultdomain, for domain name
! if [ -n "$domainname" ];then
! 	domainname $domainname
! elif [ -f /etc/defaultdomain ]; then
  	domainname `cat /etc/defaultdomain`
  fi
  
***************
*** 42,48 ****
  	echo -n "configuring network interfaces:"
  	for i in $tmp; do
  		eval `echo 'args=$ifconfig_'$i`
! 		if [ ! -z "$args" ]; then
  			echo -n " $i"
  			ifconfig $i $args
  		elif [ -f /etc/ifconfig.$i ]; then
--- 49,55 ----
  	echo -n "configuring network interfaces:"
  	for i in $tmp; do
  		eval `echo 'args=$ifconfig_'$i`
! 		if [ -n "$args" ]; then
  			echo -n " $i"
  			ifconfig $i $args
  		elif [ -f /etc/ifconfig.$i ]; then
***************
*** 55,61 ****
--- 62,70 ----
  			echo -n "/etc/ifconfig.$i missing"
   			echo -n "& ifconfig_$i not set"
  			echo "; interface $i can't be configured"
+ 			continue
  		fi
+ 		configured_interfaces="$configured_interfaces $i"
  	done
  	echo "."
  fi
***************
*** 67,78 ****
  # use loopback, not the wire
  route add $hostname localhost
  
! # /etc/mygate, if it exists, contains the name of my gateway host
! # that name must be in /etc/hosts.
! if [ -f /etc/mygate ]; then
  	route add default `cat /etc/mygate`
  fi
  
  # /etc/ifaliases, if it exists, contains the names of additional IP
  # addresses for each interface. It is formatted as a series of lines
  # that contain
--- 76,110 ----
  # use loopback, not the wire
  route add $hostname localhost
  
! # Check $defaultroute, then /etc/mygate, for the name of my gateway host.
! # That name must be in /etc/hosts.
! if [ -n "$defaultroute" ];then
! 	route add default $defaultroute
! elif [ -f /etc/mygate ]; then
  	route add default `cat /etc/mygate`
  fi
  
+ # Check if each configured interface xxN has an $ifaliases_xxN variable
+ # associated, then configure additional IP addresses for that interface.
+ # The variable contains a list of "address netmask" pairs, with "netmask"
+ # set to "-" if the interface default netmask is to be used.
+ # 
+ for i in $configured_interfaces; do
+ 	eval `echo 'args=$ifaliases_'$i`
+ 	if [ -n "$args" ]; then
+ 		set -- $args
+ 		while [ $# -ge 2 ]; do
+ 			if [ "$2" = "-" ]; then
+ 				ifconfig $i inet alias $1
+ 			else
+ 				ifconfig $i inet alias $1 netmask $2
+ 			fi
+ 			route add $1 localhost
+ 			shift 2
+ 		done
+ 	fi
+ done
+ 
  # /etc/ifaliases, if it exists, contains the names of additional IP
  # addresses for each interface. It is formatted as a series of lines
  # that contain
***************
*** 80,86 ****
  if [ -f /etc/ifaliases ]; then
  (
  	while read addr int net; do
! 		if [ ! -n "$net" ]; then
  			ifconfig $int inet alias $addr
  		else
  			ifconfig $int inet alias $addr netmask $net
--- 112,118 ----
  if [ -f /etc/ifaliases ]; then
  (
  	while read addr int net; do
! 		if [ -z "$net" ]; then
  			ifconfig $int inet alias $addr
  		else
  			ifconfig $int inet alias $addr netmask $net