NetBSD/etc/netstart

190 lines
5.2 KiB
Plaintext
Raw Normal View History

1993-03-21 12:45:37 +03:00
#!/bin/sh -
#
# $NetBSD: netstart,v 1.56 1999/05/28 21:01:42 christos Exp $
1997-02-15 13:02:07 +03:00
# from: @(#)netstart 8.1 (Berkeley) 7/23/93
1993-03-21 12:45:37 +03:00
1997-08-29 14:09:38 +04:00
if [ -f /etc/rc.subr ]; then
. /etc/rc.subr
else
1997-08-29 14:09:38 +04:00
echo "Can't read /etc/rc.subr; aborting."
exit 1;
fi
if [ -f /etc/rc.conf ]; then
. /etc/rc.conf
fi
# If $hostname is set, use it for my Internet name, otherwise use /etc/myname
if [ -z "$hostname" -a -f /etc/myname ]; then
hostname=`cat /etc/myname`
fi
if [ -n "$hostname" ]; then
echo "hostname: $hostname"
hostname $hostname
fi
# Check $domainname first, then /etc/defaultdomain, for NIS/YP domain name
if [ -z "$domainname" -a -f /etc/defaultdomain ]; then
domainname=`cat /etc/defaultdomain`
fi
if [ -n "$domainname" ]; then
echo "domainname: $domainname"
domainname $domainname
fi
1993-03-21 12:45:37 +03:00
# Flush all routes just to make sure it is clean
1998-01-26 15:02:43 +03:00
if checkyesno flushroutes; then
route flush
fi
1997-05-13 03:40:50 +04:00
# Enable, flush and install packet filter rules before configuring interfaces.
if checkyesno ipfilter; then
if [ -f /etc/ipf.conf ]; then
echo 'installing packet filter rules ... '
ipf -E -Fa -f /etc/ipf.conf
else
echo
echo "WARNING: /etc/ipf.conf not readable " \
"ipfilter not started."
# abort the boot rather than risk a security problem
exit 1;
fi
fi
# Set the address for the first loopback interface, so that the auto-route
# from a newly configured interface's address to lo0 works correctly.
#
# NOTE: obscure networking problems may occur if lo0 isn't configured...
#
ifconfig lo0 inet 127.0.0.1
# Configure all of the network interfaces listed in $net_interfaces;
# if $auto_ifconfig is YES, grab all interfaces from ifconfig.
# In the following, "xxN" stands in for interface names, like "le0".
# For any interfaces that has an $ifconfig_xxN variable associated,
# we do "ifconfig xxN $ifconfig_xxN".
# If there is no such variable, we take the contents of the file
# /etc/ifconfig.xxN, and run "ifconfig xxN" repeatedly, using each
# line of the file as the arguments for a seperate "ifconfig" invocation.
#
# In order to configure an interface reasonably, you at the very least
# need to specify "[addr_family] [hostname]" (as in "inet my.domain.org"),
# and probably a netmask (as in "netmask 0xffffffe0"). You will
# frequently need to specify a media type, as in "media UTP", for
# interface cards with multiple media connections that do not autoconfigure.
# see the ifconfig manual page for details.
if [ "$net_interfaces" != NO ]; then
if checkyesno auto_ifconfig; then
tmp="`ifconfig -l`"
else
tmp="$net_interfaces"
fi
echo -n 'configuring network interfaces:'
for int in $tmp; do
eval `echo 'args=$ifconfig_'$int`
if [ -n "$args" ]; then
echo -n " $int"
ifconfig $int $args
elif [ -f /etc/ifconfig.$int ]; then
echo -n " $int"
(while read args; do
ifconfig $int $args
done) < /etc/ifconfig.$int
else
1998-01-26 15:02:43 +03:00
if ! checkyesno auto_ifconfig; then
echo
echo "WARNING: /etc/ifconfig.$int missing " \
"and ifconfig_$int not set; " \
"interface $int not configured."
fi
continue
fi
configured_interfaces="$configured_interfaces $int"
done
echo '.'
fi
# Check $defaultroute, then /etc/mygate, for the name of my gateway host.
# That name must be in /etc/hosts.
if [ -z "$defaultroute" -a -f /etc/mygate ]; then
defaultroute=`cat /etc/mygate`
fi
if [ -n "$defaultroute" ]; then
route add default $defaultroute
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.
#
if [ -n "$configured_interfaces" ]; then
echo 'adding interface aliases:';
done_aliases_message=yes
fi
for int in $configured_interfaces; do
eval `echo 'args=$ifaliases_'$int`
if [ -n "$args" ]; then
set -- $args
while [ $# -ge 2 ]; do
addr=$1 ; net=$2 ; shift 2
if [ "$net" = "-" ]; then
ifconfig $int inet alias $addr
else
ifconfig $int inet alias $addr netmask $net
fi
1997-05-13 03:40:50 +04:00
# Use loopback, not the wire
route add $addr 127.0.0.1
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
# address interface netmask
if [ -f /etc/ifaliases ]; then
(
if [ "$done_aliases_message" != yes ]; then
echo 'adding interface aliases:';
fi
while read addr int net; do
if [ -z "$net" ]; then
ifconfig $int inet alias $addr
else
ifconfig $int inet alias $addr netmask $net
fi
# use loopback, not the wire
route add $addr 127.0.0.1
done
) < /etc/ifaliases
fi
# /etc/ppp/peers and $ppp_peers contain boot configuration information
# for pppd. each value in $ppp_peers that has a file in /etc/ppp/peers
# of the same name, will be run as `pppd <peer>'.
if [ -n "$ppp_peers" ]; then
# pppd is in /usr - need to ensure it is mounted
mount /usr >/dev/null 2>&1
set -- $ppp_peers
echo -n "starting pppd:"
while [ $# -ge 1 ]; do
peer=$1; shift
if [ -f /etc/ppp/peers/$peer ]; then
pppd call $peer
echo -n " $peer"
fi
done
echo "."
fi
if checkyesno dhclient; then
echo -n "starting dhcp client...";
dhclient $dhclient_flags
fi
if [ -s /etc/netstart.local ]; then
. /etc/netstart.local
fi