2000-03-10 14:53:23 +03:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2002-05-04 17:53:02 +04:00
|
|
|
# $NetBSD: network,v 1.38 2002/05/04 13:53:02 tron Exp $
|
2000-03-10 14:53:23 +03:00
|
|
|
#
|
|
|
|
|
|
|
|
# PROVIDE: network
|
2000-08-22 03:35:20 +04:00
|
|
|
# REQUIRE: ipfilter ipsec mountcritlocal root tty sysctl
|
2002-03-22 07:33:57 +03:00
|
|
|
# BEFORE: NETWORKING
|
2000-03-10 14:53:23 +03:00
|
|
|
|
|
|
|
. /etc/rc.subr
|
|
|
|
|
|
|
|
name="network"
|
|
|
|
start_cmd="network_start"
|
2000-07-17 19:25:42 +04:00
|
|
|
stop_cmd="network_stop"
|
2000-03-10 14:53:23 +03:00
|
|
|
|
|
|
|
network_start()
|
|
|
|
{
|
|
|
|
# set hostname, turn on network
|
|
|
|
#
|
|
|
|
echo "Starting network."
|
|
|
|
|
|
|
|
# If $hostname is set, use it for my Internet name,
|
|
|
|
# otherwise use /etc/myname
|
|
|
|
#
|
2000-10-09 09:02:14 +04:00
|
|
|
if [ -z "$hostname" ] && [ -f /etc/myname ]; then
|
2000-03-10 14:53:23 +03:00
|
|
|
hostname=`cat /etc/myname`
|
|
|
|
fi
|
|
|
|
if [ -n "$hostname" ]; then
|
|
|
|
echo "Hostname: $hostname"
|
|
|
|
hostname $hostname
|
|
|
|
else
|
2000-04-28 04:13:39 +04:00
|
|
|
# Don't warn about it if we're going to run
|
|
|
|
# DHCP later, as we will probably get the
|
|
|
|
# hostname at that time.
|
|
|
|
#
|
2000-11-26 09:46:42 +03:00
|
|
|
if ! checkyesno dhclient && [ -z "`hostname`" ]; then
|
2000-04-28 04:13:39 +04:00
|
|
|
warn "\$hostname not set."
|
|
|
|
fi
|
2000-03-10 14:53:23 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Check $domainname first, then /etc/defaultdomain,
|
|
|
|
# for NIS/YP domain name
|
|
|
|
#
|
2000-10-09 09:02:14 +04:00
|
|
|
if [ -z "$domainname" ] && [ -f /etc/defaultdomain ]; then
|
2000-03-10 14:53:23 +03:00
|
|
|
domainname=`cat /etc/defaultdomain`
|
|
|
|
fi
|
|
|
|
if [ -n "$domainname" ]; then
|
|
|
|
echo "NIS domainname: $domainname"
|
|
|
|
domainname $domainname
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Flush all routes just to make sure it is clean
|
|
|
|
if checkyesno flushroutes; then
|
|
|
|
route -n flush
|
|
|
|
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.
|
|
|
|
#
|
2001-07-08 11:16:00 +04:00
|
|
|
# NOTE: obscure networking problems will occur if lo0 isn't configured.
|
2000-03-10 14:53:23 +03:00
|
|
|
#
|
|
|
|
ifconfig lo0 inet 127.0.0.1
|
|
|
|
|
2001-03-02 06:07:29 +03:00
|
|
|
# According to RFC1122, 127.0.0.0/8 must not leave the node.
|
2000-05-09 14:49:26 +04:00
|
|
|
#
|
2002-03-24 20:58:21 +03:00
|
|
|
route -q add -inet 127.0.0.0 -netmask 0xff000000 127.0.0.1 -reject
|
2000-05-09 14:49:26 +04:00
|
|
|
|
2001-01-13 16:26:36 +03:00
|
|
|
# IPv6 routing setups, and host/router mode selection.
|
|
|
|
#
|
|
|
|
if ifconfig lo0 inet6 >/dev/null 2>&1; then
|
|
|
|
# We have IPv6 support in kernel.
|
|
|
|
|
|
|
|
# disallow link-local unicast dest without outgoing scope
|
|
|
|
# identifiers.
|
|
|
|
#
|
2002-03-24 20:58:21 +03:00
|
|
|
route -q add -inet6 fe80:: -prefixlen 10 ::1 -reject
|
2001-01-13 16:26:36 +03:00
|
|
|
|
|
|
|
# disallow site-local unicast dest without outgoing scope
|
|
|
|
# identifiers.
|
|
|
|
# If you configure site-locals without scope id (it is
|
|
|
|
# permissible config for routers that are not on scope
|
|
|
|
# boundary), you may want to comment the following one out.
|
|
|
|
#
|
|
|
|
if ! checkyesno ip6sitelocal; then
|
2002-03-24 20:58:21 +03:00
|
|
|
route -q add -inet6 fec0:: -prefixlen 10 ::1 -reject
|
2001-01-13 16:26:36 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
# disallow "internal" addresses to appear on the wire.
|
|
|
|
#
|
2002-03-24 20:58:21 +03:00
|
|
|
route -q add -inet6 ::ffff:0.0.0.0 -prefixlen 96 ::1 -reject
|
2001-01-13 16:26:36 +03:00
|
|
|
|
|
|
|
# disallow packets to malicious IPv4 compatible prefix
|
|
|
|
#
|
2002-03-24 20:58:21 +03:00
|
|
|
route -q add -inet6 ::224.0.0.0 -prefixlen 100 ::1 -reject
|
|
|
|
route -q add -inet6 ::127.0.0.0 -prefixlen 104 ::1 -reject
|
|
|
|
route -q add -inet6 ::0.0.0.0 -prefixlen 104 ::1 -reject
|
|
|
|
route -q add -inet6 ::255.0.0.0 -prefixlen 104 ::1 -reject
|
2001-01-13 16:26:36 +03:00
|
|
|
|
|
|
|
# disallow packets to malicious 6to4 prefix
|
|
|
|
#
|
2002-03-24 20:58:21 +03:00
|
|
|
route -q add -inet6 2002:e000:: -prefixlen 20 ::1 -reject
|
|
|
|
route -q add -inet6 2002:7f00:: -prefixlen 24 ::1 -reject
|
|
|
|
route -q add -inet6 2002:0000:: -prefixlen 24 ::1 -reject
|
|
|
|
route -q add -inet6 2002:ff00:: -prefixlen 24 ::1 -reject
|
2001-01-13 16:26:36 +03:00
|
|
|
|
|
|
|
# Completely disallow packets to IPv4 compatible prefix.
|
|
|
|
# This may conflict with RFC1933 under following circumstances:
|
|
|
|
# (1) An IPv6-only KAME node tries to originate packets to IPv4
|
|
|
|
# comatible destination. The KAME node has no IPv4
|
|
|
|
# compatible support. Under RFC1933, it should transmit
|
|
|
|
# native IPv6 packets toward IPv4 compatible destination,
|
|
|
|
# hoping it would reach a router that forwards the packet
|
|
|
|
# toward auto-tunnel interface.
|
|
|
|
# (2) An IPv6-only node originates a packet to IPv4 compatible
|
|
|
|
# destination. A KAME node is acting as an IPv6 router, and
|
|
|
|
# asked to forward it.
|
|
|
|
# Due to rare use of IPv4 compatible address, and security
|
|
|
|
# issues with it, we disable it by default.
|
|
|
|
#
|
2002-03-24 20:58:21 +03:00
|
|
|
route -q add -inet6 ::0.0.0.0 -prefixlen 96 ::1 -reject
|
2001-01-13 16:26:36 +03:00
|
|
|
|
2002-03-24 20:58:21 +03:00
|
|
|
sysctl -qw net.inet6.ip6.forwarding=0
|
|
|
|
sysctl -qw net.inet6.ip6.accept_rtadv=0
|
2001-01-13 16:26:36 +03:00
|
|
|
|
|
|
|
case $ip6mode in
|
|
|
|
router)
|
|
|
|
echo 'IPv6 mode: router'
|
2002-03-24 20:58:21 +03:00
|
|
|
sysctl -qw net.inet6.ip6.forwarding=1
|
2001-01-13 16:26:36 +03:00
|
|
|
;;
|
|
|
|
|
|
|
|
autohost)
|
|
|
|
echo 'IPv6 mode: autoconfigured host'
|
2002-03-24 20:58:21 +03:00
|
|
|
sysctl -qw net.inet6.ip6.accept_rtadv=1
|
2001-01-13 16:26:36 +03:00
|
|
|
;;
|
|
|
|
|
|
|
|
host)
|
|
|
|
echo 'IPv6 mode: host'
|
|
|
|
;;
|
|
|
|
|
2002-03-27 10:37:56 +03:00
|
|
|
*) warn "invalid \$ip6mode value "\"$ip6mode\"
|
2001-01-13 16:26:36 +03:00
|
|
|
;;
|
|
|
|
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2000-03-10 14:53:23 +03:00
|
|
|
# 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
|
2001-07-22 17:33:58 +04:00
|
|
|
# line of the file as the arguments for a separate "ifconfig"
|
2000-03-10 14:53:23 +03:00
|
|
|
# invocation.
|
|
|
|
#
|
|
|
|
# In order to configure an interface reasonably, you at the very least
|
|
|
|
# need to specify "[addr_family] [hostname]" (e.g "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.
|
|
|
|
#
|
|
|
|
# Note that /etc/ifconfig.xxN takes multiple lines. The following
|
|
|
|
# configuration is possible:
|
|
|
|
# inet 10.1.1.1 netmask 0xffffff00
|
|
|
|
# inet 10.1.1.2 netmask 0xffffff00 alias
|
|
|
|
# inet6 fec0::1 prefixlen 64 alias
|
|
|
|
#
|
2001-01-11 20:56:16 +03:00
|
|
|
# You can put shell script fragment into /etc/ifconfig.xxN by
|
|
|
|
# starting a line with "!". Refer to ifconfig.if(5) for details.
|
|
|
|
#
|
2000-03-10 14:53:23 +03:00
|
|
|
if [ "$net_interfaces" != NO ]; then
|
|
|
|
if checkyesno auto_ifconfig; then
|
2000-11-21 11:39:50 +03:00
|
|
|
tmp=`ifconfig -l`
|
2000-07-20 23:43:10 +04:00
|
|
|
for cloner in `ifconfig -C 2>/dev/null`; do
|
2000-11-21 19:12:48 +03:00
|
|
|
for int in /etc/ifconfig.${cloner}[0-9]*; do
|
2000-11-21 12:38:06 +03:00
|
|
|
[ ! -f $int ] && break
|
2000-11-17 07:19:06 +03:00
|
|
|
tmp="$tmp ${int##*.}"
|
2000-07-20 23:43:10 +04:00
|
|
|
done
|
|
|
|
done
|
2000-03-10 14:53:23 +03:00
|
|
|
else
|
|
|
|
tmp="$net_interfaces"
|
|
|
|
fi
|
|
|
|
echo -n 'Configuring network interfaces:'
|
|
|
|
for int in $tmp; do
|
2000-10-09 09:02:14 +04:00
|
|
|
eval args=\$ifconfig_$int
|
2000-11-21 12:59:02 +03:00
|
|
|
if [ -n "$args" ]; then
|
2000-03-10 14:53:23 +03:00
|
|
|
echo -n " $int"
|
|
|
|
ifconfig $int $args
|
|
|
|
elif [ -f /etc/ifconfig.$int ]; then
|
|
|
|
echo -n " $int"
|
2000-10-09 09:02:14 +04:00
|
|
|
while read args; do
|
2000-11-22 07:20:04 +03:00
|
|
|
[ -z "$args" ] && continue
|
2001-01-11 20:56:16 +03:00
|
|
|
case "$args" in
|
|
|
|
"#"*)
|
|
|
|
;;
|
|
|
|
"!"*)
|
|
|
|
eval ${args#*!}
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
ifconfig $int $args
|
|
|
|
;;
|
|
|
|
esac
|
2000-10-09 09:02:14 +04:00
|
|
|
done < /etc/ifconfig.$int
|
2000-03-10 14:53:23 +03:00
|
|
|
else
|
|
|
|
if ! checkyesno auto_ifconfig; then
|
|
|
|
echo
|
|
|
|
warn \
|
|
|
|
"/etc/ifconfig.$int missing and ifconfig_$int not set;"
|
|
|
|
warn "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.
|
|
|
|
#
|
2000-10-09 09:02:14 +04:00
|
|
|
if [ -z "$defaultroute" ] && [ -f /etc/mygate ]; then
|
2000-03-10 14:53:23 +03:00
|
|
|
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.
|
|
|
|
#
|
|
|
|
# Note that $ifaliases_xxN works only with certain configurations and
|
|
|
|
# considered not recommended. Use /etc/ifconfig.xxN if possible.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
if [ -n "$configured_interfaces" ]; then
|
|
|
|
echo "Adding interface aliases:"
|
|
|
|
done_aliases_message=yes
|
|
|
|
fi
|
|
|
|
for int in $configured_interfaces; do
|
2000-10-09 09:02:14 +04:00
|
|
|
eval args=\$ifaliases_$int
|
2000-03-10 14:53:23 +03:00
|
|
|
if [ -n "$args" ]; then
|
|
|
|
set -- $args
|
|
|
|
while [ $# -ge 2 ]; do
|
|
|
|
addr=$1 ; net=$2 ; shift 2
|
|
|
|
if [ "$net" = "-" ]; then
|
2000-07-25 22:47:28 +04:00
|
|
|
# for compatibility only, obsolete
|
2000-03-10 14:53:23 +03:00
|
|
|
ifconfig $int inet alias $addr
|
|
|
|
else
|
|
|
|
ifconfig $int inet alias $addr \
|
|
|
|
netmask $net
|
|
|
|
fi
|
|
|
|
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
|
|
|
|
#
|
|
|
|
# Note that /etc/ifaliases works only with certain cases only and its
|
|
|
|
# use is not recommended. Use /etc/ifconfig.xxN instead.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
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
|
2000-07-25 22:47:28 +04:00
|
|
|
# for compatibility only, obsolete
|
2000-03-10 14:53:23 +03:00
|
|
|
ifconfig $int inet alias $addr
|
|
|
|
else
|
|
|
|
ifconfig $int inet alias $addr netmask $net
|
|
|
|
fi
|
2000-10-09 09:02:14 +04:00
|
|
|
done < /etc/ifaliases
|
2000-03-10 14:53:23 +03:00
|
|
|
fi
|
|
|
|
|
2001-01-13 16:26:36 +03:00
|
|
|
# IPv6 interface autoconfiguration.
|
2000-03-10 14:53:23 +03:00
|
|
|
#
|
|
|
|
if ifconfig lo0 inet6 >/dev/null 2>&1; then
|
2000-08-02 00:49:11 +04:00
|
|
|
# wait till DAD is completed. always invoke it in case
|
|
|
|
# if are configured manually by ifconfig
|
|
|
|
#
|
|
|
|
dadcount=`sysctl -n net.inet6.ip6.dad_count 2>/dev/null`
|
|
|
|
sleep $dadcount
|
|
|
|
sleep 1
|
|
|
|
|
2000-03-10 14:53:23 +03:00
|
|
|
if checkyesno rtsol; then
|
|
|
|
if [ "$ip6mode" = "autohost" ]; then
|
|
|
|
echo 'Sending router solicitation...'
|
|
|
|
rtsol $rtsol_flags
|
|
|
|
else
|
|
|
|
echo
|
|
|
|
warn \
|
|
|
|
"ip6mode must be set to 'autohost' to use rtsol."
|
|
|
|
fi
|
|
|
|
|
2000-08-02 17:59:11 +04:00
|
|
|
# wait till DAD is completed, for global addresses
|
|
|
|
# configured by router advert message.
|
2000-08-02 00:49:11 +04:00
|
|
|
#
|
|
|
|
sleep $dadcount
|
|
|
|
sleep 1
|
|
|
|
fi
|
2000-03-10 14:53:23 +03:00
|
|
|
fi
|
|
|
|
|
2002-05-04 17:53:02 +04:00
|
|
|
# resync ipf(4)
|
|
|
|
if checkyesno ipfilter; then
|
|
|
|
/sbin/ipf -y
|
|
|
|
fi
|
|
|
|
|
2000-03-10 14:53:23 +03:00
|
|
|
# XXX this must die
|
|
|
|
if [ -s /etc/netstart.local ]; then
|
|
|
|
sh /etc/netstart.local start
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
network_stop()
|
|
|
|
{
|
|
|
|
echo "Stopping network."
|
|
|
|
|
|
|
|
# XXX this must die
|
|
|
|
if [ -s /etc/netstart.local ]; then
|
|
|
|
sh /etc/netstart.local stop
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Deleting aliases."
|
|
|
|
if [ -f /etc/ifaliases ]; then
|
|
|
|
while read addr int net; do
|
|
|
|
ifconfig $int inet delete $addr
|
2000-10-09 09:02:14 +04:00
|
|
|
done < /etc/ifaliases
|
2000-03-10 14:53:23 +03:00
|
|
|
fi
|
|
|
|
|
2000-11-17 07:19:06 +03:00
|
|
|
for int in `ifconfig -lu`; do
|
2000-10-09 09:02:14 +04:00
|
|
|
eval args=\$ifaliases_$int
|
2000-03-10 14:53:23 +03:00
|
|
|
if [ -n "$args" ]; then
|
|
|
|
set -- $args
|
|
|
|
while [ $# -ge 2 ]; do
|
|
|
|
addr=$1 ; net=$2 ; shift 2
|
|
|
|
ifconfig $int inet delete $addr
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# down interfaces
|
|
|
|
#
|
|
|
|
echo -n 'Downing network interfaces:'
|
|
|
|
if [ "$net_interfaces" != NO ]; then
|
|
|
|
if checkyesno auto_ifconfig; then
|
2000-11-21 11:39:50 +03:00
|
|
|
tmp=`ifconfig -l`
|
2000-03-10 14:53:23 +03:00
|
|
|
else
|
|
|
|
tmp="$net_interfaces"
|
|
|
|
fi
|
|
|
|
for int in $tmp; do
|
2000-10-09 09:02:14 +04:00
|
|
|
eval args=\$ifconfig_$int
|
2000-03-11 23:13:42 +03:00
|
|
|
if [ -n "$args" ] || [ -f /etc/ifconfig.$int ]; then
|
2000-03-10 14:53:23 +03:00
|
|
|
echo -n " $int"
|
|
|
|
ifconfig $int down
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo "."
|
|
|
|
fi
|
|
|
|
|
|
|
|
# flush routes
|
|
|
|
#
|
|
|
|
route -n flush
|
|
|
|
|
2002-05-04 17:53:02 +04:00
|
|
|
# resync ipf(4)
|
|
|
|
if checkyesno ipfilter; then
|
|
|
|
/sbin/ipf -y
|
|
|
|
fi
|
|
|
|
|
2000-03-10 14:53:23 +03:00
|
|
|
}
|
|
|
|
|
2000-05-13 12:45:06 +04:00
|
|
|
load_rc_config $name
|
2000-03-10 14:53:23 +03:00
|
|
|
run_rc_command "$1"
|