Add functions to lookup in /etc/networks and set interface

addresses, invoke them from /etc/rc
This commit is contained in:
Luigi Rizzo 2001-10-04 00:46:44 +00:00
parent f03ad5f550
commit 19323fdd72
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=84432
2 changed files with 78 additions and 17 deletions

View File

@ -24,6 +24,8 @@ done
if [ -f /etc/rc.conf ]; then
. /etc/rc.conf
set_main_interface
set_all_interfaces
fi
rm -f /var/run/*
if [ "x$swapfile" != "xNO" -a -w "$swapfile" -a -b /dev/vn0b ]; then

View File

@ -26,7 +26,7 @@ defaultrouter="NO" # Set to default gateway (or NO).
static_routes="" # Set to static route list (or leave empty).
gateway_enable="NO" # Set to YES if this host will be a gateway.
arpproxy_all="" # replaces obsolete kernel option ARP_PROXYALL.
mask="0xffffff00"
default_mask="0xffffff00"
}
# the following lets the user specify a name and ip for his system
@ -41,32 +41,91 @@ read_address() {
fi
}
rc_conf_set_defaults
# set "ether" using $1 (interface name) as search key
get_ether() {
local key
key=$1
ether=""
set `ifconfig ${key}`
while [ "$1" != "" ] ; do
if [ "$1" = "ether" ] ; then
ether=$2
break
else
shift
fi
done
}
hostname=""
while read a b c ; do
# set "hostname" using $1 (ethernet address) as search key in /etc/hosts
fetch_hostname() {
local a b c key
key=$1 # search key
hostname=""
while read a b c ; do
if [ "$a" = "#ethertable" ] ; then
hostname="."
hostname="."
elif [ "X$hostname" = "X." -a "X$a" = "X#" ] ; then
case X${main_ether} in
case X${key} in
X${b} ) # so we can use wildcards
hostname=$c
break
;;
esac
fi
done < /etc/hosts
if [ "X$hostname" = "X" -o "X$hostname" = "X." ] ; then
if [ "X$main_ether" = "X" ] ; then
echo "No ethernets found, using localhost"
hostname=localhost
else
read_address
fi
fi
done < /etc/hosts
}
eval ifconfig_${main_if}=\" \$hostname netmask \$mask\"
network_interfaces=`ifconfig -l`
# sets "mask" using $1 (netmask name) as the search key in /etc/networks
fetch_mask() {
local a b c key
key=$1 # search key, typically hostname-netmask
mask=""
while read a b c; do # key mask otherstuff
case X${key} in
X${a} ) # we can use wildcards
mask=$b
break
;;
esac
done < /etc/networks
}
set_main_interface() {
fetch_hostname ${main_ether}
if [ "X$hostname" = "X" -o "X$hostname" = "X." ] ; then
if [ "X$main_ether" = "X" ] ; then
echo "No ethernets found, using localhost"
hostname=localhost
else
read_address
fi
fi
fetch_mask ${hostname}-netmask
if [ "${mask}" = "" ] ; then
mask=${default_mask}
fi
eval ifconfig_${main_if}=\" \${hostname} netmask \${mask}\"
network_interfaces=`ifconfig -l`
}
set_all_interfaces() {
local i ether hostname mask
for i in `ifconfig -l` ; do
get_ether $i
fetch_hostname ${ether}
fetch_mask ${hostname}-netmask
if [ "${ether}" != "" -a "${hostname}" != "" ] ; then
eval ifconfig_${i}=\" \${hostname} netmask \${mask}\"
fi
done
}
rc_conf_set_defaults
### Allow local configuration override at the very end here ##
### can make use of a case statement to set per-host things.