network revision 1.69
11.1Slukem#!/bin/sh
21.1Slukem#
31.69Schristos# $NetBSD: network,v 1.69 2014/10/14 20:49:47 christos Exp $
41.1Slukem#
51.1Slukem
61.1Slukem# PROVIDE: network
71.19Slukem# REQUIRE: ipfilter ipsec mountcritlocal root tty sysctl
81.34Sthorpej# BEFORE:  NETWORKING
91.1Slukem
101.45Smycroft$_rc_subr_loaded . /etc/rc.subr
111.1Slukem
121.1Slukemname="network"
131.1Slukemstart_cmd="network_start"
141.14Slukemstop_cmd="network_stop"
151.1Slukem
161.54Sapbnl='
171.54Sapb' # a newline
181.54Sapb
191.65Suebayasiintmissing()
201.65Suebayasi{
211.63Schristos	local int="$1"
221.63Schristos	shift
231.65Suebayasi	for i; do
241.63Schristos		if [ "$int" = "$i" ]; then
251.63Schristos			return 1
261.63Schristos		fi
271.63Schristos	done
281.63Schristos	return 0
291.63Schristos}
301.63Schristos
311.65Suebayasihave_inet6()
321.65Suebayasi{
331.65Suebayasi	/sbin/ifconfig lo0 inet6 >/dev/null 2>&1
341.65Suebayasi}
351.65Suebayasi
361.1Slukemnetwork_start()
371.1Slukem{
381.1Slukem	# set hostname, turn on network
391.1Slukem	#
401.1Slukem	echo "Starting network."
411.1Slukem
421.64Suebayasi	network_start_hostname
431.64Suebayasi	network_start_domainname
441.64Suebayasi	network_start_loopback
451.65Suebayasi	have_inet6 &&
461.64Suebayasi	network_start_ipv6_route
471.65Suebayasi	[ "$net_interfaces" != NO ] &&
481.64Suebayasi	network_start_interfaces
491.64Suebayasi	network_start_aliases
501.64Suebayasi	network_start_defaultroute
511.64Suebayasi	network_start_defaultroute6
521.65Suebayasi	have_inet6 &&
531.64Suebayasi	network_start_ipv6_autoconf
541.64Suebayasi	network_start_local
551.64Suebayasi}
561.64Suebayasi
571.64Suebayasinetwork_start_hostname()
581.64Suebayasi{
591.1Slukem	# If $hostname is set, use it for my Internet name,
601.1Slukem	# otherwise use /etc/myname
611.1Slukem	#
621.20Snisimura	if [ -z "$hostname" ] && [ -f /etc/myname ]; then
631.46Schristos		hostname=$(cat /etc/myname)
641.1Slukem	fi
651.1Slukem	if [ -n "$hostname" ]; then
661.1Slukem		echo "Hostname: $hostname"
671.1Slukem		hostname $hostname
681.1Slukem	else
691.8Sthorpej		# Don't warn about it if we're going to run
701.8Sthorpej		# DHCP later, as we will probably get the
711.8Sthorpej		# hostname at that time.
721.8Sthorpej		#
731.58Sroy		if ! checkyesno dhclient && ! checkyesno dhcpcd && \
741.58Sroy			[ -z "$(hostname)" ]
751.58Sroy		then
761.8Sthorpej			warn "\$hostname not set."
771.8Sthorpej		fi
781.1Slukem	fi
791.64Suebayasi}
801.1Slukem
811.64Suebayasinetwork_start_domainname()
821.64Suebayasi{
831.1Slukem	# Check $domainname first, then /etc/defaultdomain,
841.1Slukem	# for NIS/YP domain name
851.1Slukem	#
861.20Snisimura	if [ -z "$domainname" ] && [ -f /etc/defaultdomain ]; then
871.46Schristos		domainname=$(cat /etc/defaultdomain)
881.1Slukem	fi
891.1Slukem	if [ -n "$domainname" ]; then
901.1Slukem		echo "NIS domainname: $domainname"
911.1Slukem		domainname $domainname
921.1Slukem	fi
931.1Slukem
941.1Slukem	# Flush all routes just to make sure it is clean
951.1Slukem	if checkyesno flushroutes; then
961.53Sreed		/sbin/route -qn flush
971.1Slukem	fi
981.64Suebayasi}
991.1Slukem
1001.64Suebayasinetwork_start_loopback()
1011.64Suebayasi{
1021.1Slukem	# Set the address for the first loopback interface, so that the
1031.1Slukem	# auto-route from a newly configured interface's address to lo0
1041.1Slukem	# works correctly.
1051.1Slukem	#
1061.32Slukem	# NOTE: obscure networking problems will occur if lo0 isn't configured.
1071.1Slukem	#
1081.53Sreed	/sbin/ifconfig lo0 inet 127.0.0.1
1091.10Sitojun
1101.31Sitojun	# According to RFC1122, 127.0.0.0/8 must not leave the node.
1111.10Sitojun	#
1121.53Sreed	/sbin/route -q add -inet 127.0.0.0 -netmask 0xff000000 127.0.0.1 -reject
1131.64Suebayasi}
1141.1Slukem
1151.64Suebayasinetwork_start_ipv6_route()
1161.64Suebayasi{
1171.30Sitojun	# IPv6 routing setups, and host/router mode selection.
1181.30Sitojun	#
1191.66Suebayasi	# We have IPv6 support in kernel.
1201.30Sitojun
1211.66Suebayasi	# disallow link-local unicast dest without outgoing scope
1221.66Suebayasi	# identifiers.
1231.66Suebayasi	#
1241.66Suebayasi	/sbin/route -q add -inet6 fe80:: -prefixlen 10 ::1 -reject
1251.30Sitojun
1261.66Suebayasi	# disallow the use of the RFC3849 documentation address
1271.66Suebayasi	#
1281.66Suebayasi	/sbin/route -q add -inet6 2001:db8:: -prefixlen 32 ::1 -reject
1291.50Srpaulo
1301.66Suebayasi	# IPv6 site-local scoped address prefix (fec0::/10)
1311.66Suebayasi	# has been deprecated by RFC3879.
1321.66Suebayasi	#
1331.66Suebayasi	if [ -n "$ip6sitelocal" ]; then
1341.66Suebayasi		warn "\$ip6sitelocal is no longer valid"
1351.66Suebayasi	fi
1361.30Sitojun
1371.66Suebayasi	# disallow "internal" addresses to appear on the wire.
1381.66Suebayasi	#
1391.66Suebayasi	/sbin/route -q add -inet6 ::ffff:0.0.0.0 -prefixlen 96 ::1 -reject
1401.30Sitojun
1411.66Suebayasi	# disallow packets to malicious IPv4 compatible prefix
1421.66Suebayasi	#
1431.66Suebayasi	/sbin/route -q add -inet6 ::224.0.0.0 -prefixlen 100 ::1 -reject
1441.66Suebayasi	/sbin/route -q add -inet6 ::127.0.0.0 -prefixlen 104 ::1 -reject
1451.66Suebayasi	/sbin/route -q add -inet6 ::0.0.0.0 -prefixlen 104 ::1 -reject
1461.66Suebayasi	/sbin/route -q add -inet6 ::255.0.0.0 -prefixlen 104 ::1 -reject
1471.66Suebayasi
1481.66Suebayasi	# disallow packets to malicious 6to4 prefix
1491.66Suebayasi	#
1501.66Suebayasi	/sbin/route -q add -inet6 2002:e000:: -prefixlen 20 ::1 -reject
1511.66Suebayasi	/sbin/route -q add -inet6 2002:7f00:: -prefixlen 24 ::1 -reject
1521.66Suebayasi	/sbin/route -q add -inet6 2002:0000:: -prefixlen 24 ::1 -reject
1531.66Suebayasi	/sbin/route -q add -inet6 2002:ff00:: -prefixlen 24 ::1 -reject
1541.66Suebayasi
1551.66Suebayasi	# Completely disallow packets to IPv4 compatible prefix.
1561.66Suebayasi	# This may conflict with RFC1933 under following circumstances:
1571.66Suebayasi	# (1) An IPv6-only KAME node tries to originate packets to IPv4
1581.66Suebayasi	#     compatible destination.  The KAME node has no IPv4
1591.66Suebayasi	#     compatible support.  Under RFC1933, it should transmit
1601.66Suebayasi	#     native IPv6 packets toward IPv4 compatible destination,
1611.66Suebayasi	#     hoping it would reach a router that forwards the packet
1621.66Suebayasi	#     toward auto-tunnel interface.
1631.66Suebayasi	# (2) An IPv6-only node originates a packet to IPv4 compatible
1641.66Suebayasi	#     destination.  A KAME node is acting as an IPv6 router, and
1651.66Suebayasi	#     asked to forward it.
1661.66Suebayasi	# Due to rare use of IPv4 compatible address, and security
1671.66Suebayasi	# issues with it, we disable it by default.
1681.66Suebayasi	#
1691.66Suebayasi	/sbin/route -q add -inet6 ::0.0.0.0 -prefixlen 96 ::1 -reject
1701.66Suebayasi
1711.66Suebayasi	/sbin/sysctl -qw net.inet6.ip6.forwarding=0
1721.66Suebayasi	/sbin/sysctl -qw net.inet6.ip6.accept_rtadv=0
1731.66Suebayasi
1741.66Suebayasi	case $ip6mode in
1751.66Suebayasi	router)
1761.66Suebayasi		echo 'IPv6 mode: router'
1771.66Suebayasi		/sbin/sysctl -qw net.inet6.ip6.forwarding=1
1781.66Suebayasi
1791.66Suebayasi		# disallow unique-local unicast forwarding without
1801.66Suebayasi		# explicit configuration.
1811.66Suebayasi		if ! checkyesno ip6uniquelocal; then
1821.66Suebayasi			/sbin/route -q add -inet6 fc00:: -prefixlen 7 \
1831.66Suebayasi			    ::1 -reject
1841.66Suebayasi		fi
1851.66Suebayasi		;;
1861.30Sitojun
1871.66Suebayasi	autohost)
1881.66Suebayasi		echo 'IPv6 mode: autoconfigured host'
1891.66Suebayasi		/sbin/sysctl -qw net.inet6.ip6.accept_rtadv=1
1901.66Suebayasi		;;
1911.30Sitojun
1921.66Suebayasi	host)	
1931.66Suebayasi		echo 'IPv6 mode: host'
1941.66Suebayasi		;;
1951.30Sitojun
1961.66Suebayasi	*)	warn "invalid \$ip6mode value "\"$ip6mode\"
1971.66Suebayasi		;;
1981.30Sitojun
1991.66Suebayasi	esac
2001.64Suebayasi}
2011.30Sitojun
2021.64Suebayasinetwork_start_interfaces()
2031.64Suebayasi{
2041.1Slukem	# Configure all of the network interfaces listed in $net_interfaces;
2051.1Slukem	# if $auto_ifconfig is YES, grab all interfaces from ifconfig.
2061.1Slukem	# In the following, "xxN" stands in for interface names, like "le0".
2071.54Sapb	#
2081.54Sapb	# For any interfaces that has an $ifconfig_xxN variable
2091.54Sapb	# associated, we break it into lines using ';' as a separator,
2101.54Sapb	# then process it just like the contents of an /etc/ifconfig.xxN
2111.54Sapb	# file.
2121.54Sapb	#
2131.54Sapb	# For each line from the $ifconfig_xxN variable or the
2141.54Sapb	# /etc/ifconfig.xxN file, we ignore comments and blank lines,
2151.54Sapb	# treat lines beginning with "!" as commands to execute, treat
2161.54Sapb	# "dhcp" as a special case to invoke dhcpcd, and for any other
2171.54Sapb	# line we run "ifconfig xxN", using each line of the file as the
2181.54Sapb	# arguments for a separate "ifconfig" invocation.
2191.1Slukem	#
2201.1Slukem	# In order to configure an interface reasonably, you at the very least
2211.1Slukem	# need to specify "[addr_family] [hostname]" (e.g "inet my.domain.org"),
2221.1Slukem	# and probably a netmask (as in "netmask 0xffffffe0"). You will
2231.1Slukem	# frequently need to specify a media type, as in "media UTP", for
2241.1Slukem	# interface cards with multiple media connections that do not
2251.1Slukem	# autoconfigure. See the ifconfig manual page for details.
2261.1Slukem	#
2271.1Slukem	# Note that /etc/ifconfig.xxN takes multiple lines.  The following
2281.1Slukem	# configuration is possible:
2291.1Slukem	#	inet 10.1.1.1 netmask 0xffffff00
2301.1Slukem	#	inet 10.1.1.2 netmask 0xffffff00 alias
2311.50Srpaulo	#	inet6 2001:db8::1 prefixlen 64 alias
2321.1Slukem	#
2331.29Sitojun	# You can put shell script fragment into /etc/ifconfig.xxN by
2341.29Sitojun	# starting a line with "!".  Refer to ifconfig.if(5) for details.
2351.29Sitojun	#
2361.66Suebayasi	ifaces="$(/sbin/ifconfig -l)"
2371.66Suebayasi	if checkyesno auto_ifconfig; then
2381.66Suebayasi		tmp="$ifaces"
2391.66Suebayasi		for cloner in $(/sbin/ifconfig -C); do
2401.66Suebayasi			for int in /etc/ifconfig.${cloner}[0-9]*; do
2411.66Suebayasi				[ ! -f $int ] && break
2421.66Suebayasi				tmp="$tmp ${int##*.}"
2431.15Sthorpej			done
2441.66Suebayasi		done
2451.66Suebayasi	else
2461.66Suebayasi		tmp="$net_interfaces"
2471.66Suebayasi	fi
2481.66Suebayasi	echo -n 'Configuring network interfaces:'
2491.66Suebayasi	for int in $tmp; do
2501.66Suebayasi		eval argslist=\$ifconfig_$int
2511.66Suebayasi
2521.66Suebayasi		# Skip interfaces that do not have explicit
2531.66Suebayasi		# configuration information.  If auto_ifconfig is
2541.66Suebayasi		# false then also warn about such interfaces.
2551.66Suebayasi		#
2561.66Suebayasi		if [ -z "$argslist" ] && ! [ -f /etc/ifconfig.$int ]
2571.66Suebayasi		then
2581.66Suebayasi			if ! checkyesno auto_ifconfig; then
2591.66Suebayasi				echo
2601.66Suebayasi				warn \
2611.66Suebayasi		"/etc/ifconfig.$int missing and ifconfig_$int not set;"
2621.66Suebayasi				warn "interface $int not configured."
2631.66Suebayasi			fi
2641.66Suebayasi			continue
2651.1Slukem		fi
2661.54Sapb
2671.66Suebayasi		echo -n " $int"
2681.54Sapb
2691.66Suebayasi		# Create the interface if necessary.
2701.66Suebayasi		# If the interface did not exist before,
2711.66Suebayasi		# then also resync ipf(4).
2721.66Suebayasi		#
2731.66Suebayasi		if intmissing $int $ifaces; then
2741.66Suebayasi			if /sbin/ifconfig $int create && \
2751.66Suebayasi			   checkyesno ipfilter; then
2761.66Suebayasi				/sbin/ipf -y >/dev/null
2771.54Sapb			fi
2781.66Suebayasi		fi
2791.54Sapb
2801.66Suebayasi		# If $ifconfig_xxN is empty, then use
2811.66Suebayasi		# /etc/ifconfig.xxN, which we know exists due to
2821.66Suebayasi		# an earlier test.
2831.66Suebayasi		#
2841.66Suebayasi		# If $ifconfig_xxN is non-empty and contains a
2851.66Suebayasi		# newline, then just use it as is.  (This allows
2861.66Suebayasi		# semicolons through unmolested.)
2871.66Suebayasi		#
2881.66Suebayasi		# If $ifconfig_xxN is non-empty and does not
2891.66Suebayasi		# contain a newline, then convert all semicolons
2901.66Suebayasi		# to newlines.
2911.66Suebayasi		#
2921.66Suebayasi		case "$argslist" in
2931.66Suebayasi		'')
2941.66Suebayasi			cat /etc/ifconfig.$int
2951.66Suebayasi			;;
2961.66Suebayasi		*"${nl}"*)
2971.66Suebayasi			echo "$argslist"
2981.66Suebayasi			;;
2991.66Suebayasi		*)
3001.66Suebayasi			(
3011.66Suebayasi				set -o noglob
3021.66Suebayasi				IFS=';'; set -- $argslist
3031.66Suebayasi				#echo >&2 "[$#] [$1] [$2] [$3] [$4]"
3041.66Suebayasi				IFS="$nl"; echo "$*"
3051.66Suebayasi			)
3061.66Suebayasi			;;
3071.66Suebayasi		esac |
3081.66Suebayasi		collapse_backslash_newline |
3091.66Suebayasi		while read -r args; do
3101.66Suebayasi			case "$args" in
3111.66Suebayasi			''|"#"*|create)
3121.66Suebayasi				;;
3131.66Suebayasi			"!"*)
3141.66Suebayasi				# Run arbitrary command in a subshell.
3151.66Suebayasi				( eval "${args#*!}" )
3161.54Sapb				;;
3171.66Suebayasi			dhcp)
3181.66Suebayasi				if ! checkyesno dhcpcd; then
3191.66Suebayasi					/sbin/dhcpcd -n \
3201.66Suebayasi						${dhcpcd_flags} $int
3211.66Suebayasi				fi
3221.54Sapb				;;
3231.54Sapb			*)
3241.66Suebayasi				# Pass args to ifconfig.  Note
3251.66Suebayasi				# that args may contain embedded
3261.66Suebayasi				# shell metacharacters, such as
3271.66Suebayasi				# "ssid 'foo;*>bar'". We eval
3281.66Suebayasi				# one more time so that things
3291.66Suebayasi				# like ssid "Columbia University" work.
3301.54Sapb				(
3311.54Sapb					set -o noglob
3321.66Suebayasi					eval set -- $args
3331.66Suebayasi					#echo >&2 "[$#] [$1] [$2] [$3]"
3341.66Suebayasi					/sbin/ifconfig $int "$@"
3351.54Sapb				)
3361.54Sapb				;;
3371.66Suebayasi			esac
3381.1Slukem		done
3391.66Suebayasi		configured_interfaces="$configured_interfaces $int"
3401.66Suebayasi	done
3411.66Suebayasi	echo "."
3421.64Suebayasi}
3431.1Slukem
3441.64Suebayasinetwork_start_aliases()
3451.64Suebayasi{
3461.48Scjs	echo -n "Adding interface aliases:"
3471.48Scjs
3481.1Slukem	# Check if each configured interface xxN has an $ifaliases_xxN variable
3491.1Slukem	# associated, then configure additional IP addresses for that interface.
3501.1Slukem	# The variable contains a list of "address netmask" pairs, with
3511.1Slukem	# "netmask" set to "-" if the interface default netmask is to be used.
3521.1Slukem	#
3531.54Sapb	# Note that $ifaliases_xxN works only in certain cases and its
3541.54Sapb	# use is not recommended.  Use /etc/ifconfig.xxN or multiple
3551.54Sapb	# commands in $ifconfig_xxN instead.
3561.1Slukem	#
3571.48Scjs	for int in lo0 $configured_interfaces; do
3581.20Snisimura		eval args=\$ifaliases_$int
3591.1Slukem		if [ -n "$args" ]; then
3601.1Slukem			set -- $args
3611.1Slukem			while [ $# -ge 2 ]; do
3621.1Slukem				addr=$1 ; net=$2 ; shift 2
3631.1Slukem				if [ "$net" = "-" ]; then
3641.16Sjdolecek					# for compatibility only, obsolete
3651.53Sreed					/sbin/ifconfig $int inet alias $addr
3661.1Slukem				else
3671.53Sreed					/sbin/ifconfig $int inet alias $addr \
3681.1Slukem					    netmask $net
3691.1Slukem				fi
3701.48Scjs				echo -n " $int:$addr"
3711.1Slukem			done
3721.1Slukem		fi
3731.1Slukem	done
3741.1Slukem
3751.1Slukem	# /etc/ifaliases, if it exists, contains the names of additional IP
3761.1Slukem	# addresses for each interface. It is formatted as a series of lines
3771.1Slukem	# that contain
3781.1Slukem	#	address interface netmask
3791.1Slukem	#
3801.54Sapb	# Note that /etc/ifaliases works only in certain cases and its
3811.54Sapb	# use is not recommended.  Use /etc/ifconfig.xxN or multiple
3821.54Sapb	# commands in $ifconfig_xxN instead.
3831.1Slukem	#
3841.1Slukem	if [ -f /etc/ifaliases ]; then
3851.1Slukem		while read addr int net; do
3861.1Slukem			if [ -z "$net" ]; then
3871.16Sjdolecek				# for compatibility only, obsolete
3881.53Sreed				/sbin/ifconfig $int inet alias $addr
3891.1Slukem			else
3901.53Sreed				/sbin/ifconfig $int inet alias $addr netmask $net
3911.1Slukem			fi
3921.20Snisimura		done < /etc/ifaliases
3931.1Slukem	fi
3941.1Slukem
3951.56Sapb	echo "." # for "Adding interface aliases:"
3961.64Suebayasi}
3971.56Sapb
3981.64Suebayasinetwork_start_defaultroute()
3991.64Suebayasi{
4001.56Sapb	# Check $defaultroute, then /etc/mygate, for the name or address
4011.56Sapb	# of my IPv4 gateway host. If using a name, that name must be in
4021.56Sapb	# /etc/hosts.
4031.56Sapb	#
4041.56Sapb	if [ -z "$defaultroute" ] && [ -f /etc/mygate ]; then
4051.56Sapb		defaultroute=$(cat /etc/mygate)
4061.56Sapb	fi
4071.56Sapb	if [ -n "$defaultroute" ]; then
4081.56Sapb		/sbin/route add default $defaultroute
4091.56Sapb	fi
4101.64Suebayasi}
4111.56Sapb
4121.64Suebayasinetwork_start_defaultroute6()
4131.64Suebayasi{
4141.56Sapb	# Check $defaultroute6, then /etc/mygate6, for the name or address
4151.56Sapb	# of my IPv6 gateway host. If using a name, that name must be in
4161.56Sapb	# /etc/hosts.  Note that the gateway host address must be a link-local
4171.56Sapb	# address if it is not using an stf* interface.
4181.56Sapb	#
4191.56Sapb	if [ -z "$defaultroute6" ] && [ -f /etc/mygate6 ]; then
4201.56Sapb		defaultroute6=$(cat /etc/mygate6)
4211.56Sapb	fi
4221.56Sapb	if [ -n "$defaultroute6" ]; then
4231.56Sapb		if [ "$ip6mode" = "autohost" ]; then
4241.56Sapb			echo
4251.56Sapb			warn \
4261.56Sapb	    "ip6mode is set to 'autohost' and a v6 default route is also set."
4271.56Sapb		fi
4281.56Sapb		/sbin/route add -inet6 default $defaultroute6
4291.56Sapb	fi
4301.64Suebayasi}
4311.48Scjs
4321.64Suebayasinetwork_start_ipv6_autoconf()
4331.64Suebayasi{
4341.30Sitojun	# IPv6 interface autoconfiguration.
4351.67Sroy
4361.66Suebayasi	dadcount=$(/sbin/sysctl -n net.inet6.ip6.dad_count 2>/dev/null)
4371.67Sroy	if [ -n "$dadcount" -a "$dadcount" != 0 ]; then
4381.67Sroy		# wait till DAD is completed
4391.67Sroy		echo 'Waiting for DAD to complete for' \
4401.67Sroy		    'statically configured addresses...'
4411.67Sroy		# Add 1 for MAX_RTR_SOLICITATION_DELAY and another
4421.67Sroy		# to give time for the last DAD packet to respond and
4431.67Sroy		# a few more for luck.
4441.67Sroy		waitsecs=$((dadcount + 4))
4451.67Sroy		/sbin/ifconfig -w $waitsecs
4461.67Sroy	fi
4471.66Suebayasi
4481.67Sroy	# dhcpcd will ensure DAD completes before forking
4491.69Schristos	if checkyesnox rtsol && ! checkyesno dhcpcd; then
4501.66Suebayasi		if [ "$ip6mode" = "autohost" ]; then
4511.66Suebayasi			echo
4521.67Sroy			warn "rtsol has been removed, " \
4531.67Sroy			    "please configure dhcpcd in its place."
4541.66Suebayasi		fi
4551.66Suebayasi	fi
4561.64Suebayasi}
4571.42Schristos
4581.64Suebayasinetwork_start_local()
4591.64Suebayasi{
4601.1Slukem	# XXX this must die
4611.1Slukem	if [ -s /etc/netstart.local ]; then
4621.1Slukem		sh /etc/netstart.local start
4631.1Slukem	fi
4641.1Slukem}
4651.1Slukem
4661.1Slukemnetwork_stop()
4671.1Slukem{
4681.1Slukem	echo "Stopping network."
4691.1Slukem
4701.64Suebayasi	network_stop_local
4711.64Suebayasi	network_stop_aliases
4721.65Suebayasi	[ "$net_interfaces" != NO ] &&
4731.64Suebayasi	network_stop_interfaces
4741.64Suebayasi	network_stop_route
4751.64Suebayasi}
4761.64Suebayasi
4771.64Suebayasinetwork_stop_local()
4781.64Suebayasi{
4791.1Slukem	# XXX this must die
4801.1Slukem	if [ -s /etc/netstart.local ]; then
4811.1Slukem		sh /etc/netstart.local stop
4821.1Slukem	fi
4831.64Suebayasi}
4841.1Slukem
4851.64Suebayasinetwork_stop_aliases()
4861.64Suebayasi{
4871.1Slukem	echo "Deleting aliases."
4881.1Slukem	if [ -f /etc/ifaliases ]; then
4891.1Slukem		while read addr int net; do
4901.53Sreed			/sbin/ifconfig $int inet delete $addr
4911.20Snisimura		done < /etc/ifaliases
4921.1Slukem	fi
4931.1Slukem
4941.53Sreed	for int in $(/sbin/ifconfig -lu); do
4951.20Snisimura		eval args=\$ifaliases_$int
4961.1Slukem		if [ -n "$args" ]; then
4971.1Slukem			set -- $args
4981.1Slukem			while [ $# -ge 2 ]; do
4991.1Slukem				addr=$1 ; net=$2 ; shift 2
5001.53Sreed				/sbin/ifconfig $int inet delete $addr
5011.1Slukem			done
5021.1Slukem		fi
5031.1Slukem	done
5041.64Suebayasi}
5051.1Slukem
5061.64Suebayasinetwork_stop_interfaces()
5071.64Suebayasi{
5081.1Slukem	# down interfaces
5091.1Slukem	#
5101.1Slukem	echo -n 'Downing network interfaces:'
5111.66Suebayasi	if checkyesno auto_ifconfig; then
5121.66Suebayasi		tmp=$(/sbin/ifconfig -l)
5131.66Suebayasi	else
5141.66Suebayasi		tmp="$net_interfaces"
5151.66Suebayasi	fi
5161.66Suebayasi	for int in $tmp; do
5171.66Suebayasi		eval args=\$ifconfig_$int
5181.66Suebayasi		if [ -n "$args" ] || [ -f /etc/ifconfig.$int ]; then
5191.66Suebayasi			echo -n " $int"
5201.66Suebayasi			if [ -f /var/run/dhcpcd-$int.pid ]; then
5211.66Suebayasi				/sbin/dhcpcd -k $int 2> /dev/null
5221.66Suebayasi			fi
5231.66Suebayasi			/sbin/ifconfig $int down
5241.66Suebayasi			if /sbin/ifconfig $int destroy 2>/dev/null && \
5251.66Suebayasi			   checkyesno ipfilter; then
5261.66Suebayasi				# resync ipf(4)
5271.66Suebayasi				/sbin/ipf -y >/dev/null
5281.66Suebayasi			fi
5291.1Slukem		fi
5301.66Suebayasi	done
5311.66Suebayasi	echo "."
5321.64Suebayasi}
5331.1Slukem
5341.64Suebayasinetwork_stop_route()
5351.64Suebayasi{
5361.1Slukem	# flush routes
5371.1Slukem	#
5381.53Sreed	/sbin/route -qn flush
5391.38Stron
5401.1Slukem}
5411.1Slukem
5421.47Slukemload_rc_config $name
5431.47Slukemload_rc_config_var dhclient dhclient
5441.58Sroyload_rc_config_var dhcpcd dhcpcd
5451.47Slukemload_rc_config_var ipfilter ipfilter
5461.1Slukemrun_rc_command "$1"
547