network revision 1.70
11.1Slukem#!/bin/sh
21.1Slukem#
31.70Sroy# $NetBSD: network,v 1.70 2016/01/07 11:51:07 roy 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.70Sroy	network_wait_dad
551.64Suebayasi	network_start_local
561.64Suebayasi}
571.64Suebayasi
581.64Suebayasinetwork_start_hostname()
591.64Suebayasi{
601.1Slukem	# If $hostname is set, use it for my Internet name,
611.1Slukem	# otherwise use /etc/myname
621.1Slukem	#
631.20Snisimura	if [ -z "$hostname" ] && [ -f /etc/myname ]; then
641.46Schristos		hostname=$(cat /etc/myname)
651.1Slukem	fi
661.1Slukem	if [ -n "$hostname" ]; then
671.1Slukem		echo "Hostname: $hostname"
681.1Slukem		hostname $hostname
691.1Slukem	else
701.8Sthorpej		# Don't warn about it if we're going to run
711.8Sthorpej		# DHCP later, as we will probably get the
721.8Sthorpej		# hostname at that time.
731.8Sthorpej		#
741.58Sroy		if ! checkyesno dhclient && ! checkyesno dhcpcd && \
751.58Sroy			[ -z "$(hostname)" ]
761.58Sroy		then
771.8Sthorpej			warn "\$hostname not set."
781.8Sthorpej		fi
791.1Slukem	fi
801.64Suebayasi}
811.1Slukem
821.64Suebayasinetwork_start_domainname()
831.64Suebayasi{
841.1Slukem	# Check $domainname first, then /etc/defaultdomain,
851.1Slukem	# for NIS/YP domain name
861.1Slukem	#
871.20Snisimura	if [ -z "$domainname" ] && [ -f /etc/defaultdomain ]; then
881.46Schristos		domainname=$(cat /etc/defaultdomain)
891.1Slukem	fi
901.1Slukem	if [ -n "$domainname" ]; then
911.1Slukem		echo "NIS domainname: $domainname"
921.1Slukem		domainname $domainname
931.1Slukem	fi
941.1Slukem
951.1Slukem	# Flush all routes just to make sure it is clean
961.1Slukem	if checkyesno flushroutes; then
971.53Sreed		/sbin/route -qn flush
981.1Slukem	fi
991.64Suebayasi}
1001.1Slukem
1011.64Suebayasinetwork_start_loopback()
1021.64Suebayasi{
1031.1Slukem	# Set the address for the first loopback interface, so that the
1041.1Slukem	# auto-route from a newly configured interface's address to lo0
1051.1Slukem	# works correctly.
1061.1Slukem	#
1071.32Slukem	# NOTE: obscure networking problems will occur if lo0 isn't configured.
1081.1Slukem	#
1091.53Sreed	/sbin/ifconfig lo0 inet 127.0.0.1
1101.10Sitojun
1111.31Sitojun	# According to RFC1122, 127.0.0.0/8 must not leave the node.
1121.10Sitojun	#
1131.53Sreed	/sbin/route -q add -inet 127.0.0.0 -netmask 0xff000000 127.0.0.1 -reject
1141.64Suebayasi}
1151.1Slukem
1161.64Suebayasinetwork_start_ipv6_route()
1171.64Suebayasi{
1181.30Sitojun	# IPv6 routing setups, and host/router mode selection.
1191.30Sitojun	#
1201.66Suebayasi	# We have IPv6 support in kernel.
1211.30Sitojun
1221.66Suebayasi	# disallow link-local unicast dest without outgoing scope
1231.66Suebayasi	# identifiers.
1241.66Suebayasi	#
1251.66Suebayasi	/sbin/route -q add -inet6 fe80:: -prefixlen 10 ::1 -reject
1261.30Sitojun
1271.66Suebayasi	# disallow the use of the RFC3849 documentation address
1281.66Suebayasi	#
1291.66Suebayasi	/sbin/route -q add -inet6 2001:db8:: -prefixlen 32 ::1 -reject
1301.50Srpaulo
1311.66Suebayasi	# IPv6 site-local scoped address prefix (fec0::/10)
1321.66Suebayasi	# has been deprecated by RFC3879.
1331.66Suebayasi	#
1341.66Suebayasi	if [ -n "$ip6sitelocal" ]; then
1351.66Suebayasi		warn "\$ip6sitelocal is no longer valid"
1361.66Suebayasi	fi
1371.30Sitojun
1381.66Suebayasi	# disallow "internal" addresses to appear on the wire.
1391.66Suebayasi	#
1401.66Suebayasi	/sbin/route -q add -inet6 ::ffff:0.0.0.0 -prefixlen 96 ::1 -reject
1411.30Sitojun
1421.66Suebayasi	# disallow packets to malicious IPv4 compatible prefix
1431.66Suebayasi	#
1441.66Suebayasi	/sbin/route -q add -inet6 ::224.0.0.0 -prefixlen 100 ::1 -reject
1451.66Suebayasi	/sbin/route -q add -inet6 ::127.0.0.0 -prefixlen 104 ::1 -reject
1461.66Suebayasi	/sbin/route -q add -inet6 ::0.0.0.0 -prefixlen 104 ::1 -reject
1471.66Suebayasi	/sbin/route -q add -inet6 ::255.0.0.0 -prefixlen 104 ::1 -reject
1481.66Suebayasi
1491.66Suebayasi	# disallow packets to malicious 6to4 prefix
1501.66Suebayasi	#
1511.66Suebayasi	/sbin/route -q add -inet6 2002:e000:: -prefixlen 20 ::1 -reject
1521.66Suebayasi	/sbin/route -q add -inet6 2002:7f00:: -prefixlen 24 ::1 -reject
1531.66Suebayasi	/sbin/route -q add -inet6 2002:0000:: -prefixlen 24 ::1 -reject
1541.66Suebayasi	/sbin/route -q add -inet6 2002:ff00:: -prefixlen 24 ::1 -reject
1551.66Suebayasi
1561.66Suebayasi	# Completely disallow packets to IPv4 compatible prefix.
1571.66Suebayasi	# This may conflict with RFC1933 under following circumstances:
1581.66Suebayasi	# (1) An IPv6-only KAME node tries to originate packets to IPv4
1591.66Suebayasi	#     compatible destination.  The KAME node has no IPv4
1601.66Suebayasi	#     compatible support.  Under RFC1933, it should transmit
1611.66Suebayasi	#     native IPv6 packets toward IPv4 compatible destination,
1621.66Suebayasi	#     hoping it would reach a router that forwards the packet
1631.66Suebayasi	#     toward auto-tunnel interface.
1641.66Suebayasi	# (2) An IPv6-only node originates a packet to IPv4 compatible
1651.66Suebayasi	#     destination.  A KAME node is acting as an IPv6 router, and
1661.66Suebayasi	#     asked to forward it.
1671.66Suebayasi	# Due to rare use of IPv4 compatible address, and security
1681.66Suebayasi	# issues with it, we disable it by default.
1691.66Suebayasi	#
1701.66Suebayasi	/sbin/route -q add -inet6 ::0.0.0.0 -prefixlen 96 ::1 -reject
1711.66Suebayasi
1721.66Suebayasi	/sbin/sysctl -qw net.inet6.ip6.forwarding=0
1731.66Suebayasi	/sbin/sysctl -qw net.inet6.ip6.accept_rtadv=0
1741.66Suebayasi
1751.66Suebayasi	case $ip6mode in
1761.66Suebayasi	router)
1771.66Suebayasi		echo 'IPv6 mode: router'
1781.66Suebayasi		/sbin/sysctl -qw net.inet6.ip6.forwarding=1
1791.66Suebayasi
1801.66Suebayasi		# disallow unique-local unicast forwarding without
1811.66Suebayasi		# explicit configuration.
1821.66Suebayasi		if ! checkyesno ip6uniquelocal; then
1831.66Suebayasi			/sbin/route -q add -inet6 fc00:: -prefixlen 7 \
1841.66Suebayasi			    ::1 -reject
1851.66Suebayasi		fi
1861.66Suebayasi		;;
1871.30Sitojun
1881.66Suebayasi	autohost)
1891.66Suebayasi		echo 'IPv6 mode: autoconfigured host'
1901.66Suebayasi		/sbin/sysctl -qw net.inet6.ip6.accept_rtadv=1
1911.66Suebayasi		;;
1921.30Sitojun
1931.66Suebayasi	host)	
1941.66Suebayasi		echo 'IPv6 mode: host'
1951.66Suebayasi		;;
1961.30Sitojun
1971.66Suebayasi	*)	warn "invalid \$ip6mode value "\"$ip6mode\"
1981.66Suebayasi		;;
1991.30Sitojun
2001.66Suebayasi	esac
2011.64Suebayasi}
2021.30Sitojun
2031.64Suebayasinetwork_start_interfaces()
2041.64Suebayasi{
2051.1Slukem	# Configure all of the network interfaces listed in $net_interfaces;
2061.1Slukem	# if $auto_ifconfig is YES, grab all interfaces from ifconfig.
2071.1Slukem	# In the following, "xxN" stands in for interface names, like "le0".
2081.54Sapb	#
2091.54Sapb	# For any interfaces that has an $ifconfig_xxN variable
2101.54Sapb	# associated, we break it into lines using ';' as a separator,
2111.54Sapb	# then process it just like the contents of an /etc/ifconfig.xxN
2121.54Sapb	# file.
2131.54Sapb	#
2141.54Sapb	# For each line from the $ifconfig_xxN variable or the
2151.54Sapb	# /etc/ifconfig.xxN file, we ignore comments and blank lines,
2161.54Sapb	# treat lines beginning with "!" as commands to execute, treat
2171.54Sapb	# "dhcp" as a special case to invoke dhcpcd, and for any other
2181.54Sapb	# line we run "ifconfig xxN", using each line of the file as the
2191.54Sapb	# arguments for a separate "ifconfig" invocation.
2201.1Slukem	#
2211.1Slukem	# In order to configure an interface reasonably, you at the very least
2221.1Slukem	# need to specify "[addr_family] [hostname]" (e.g "inet my.domain.org"),
2231.1Slukem	# and probably a netmask (as in "netmask 0xffffffe0"). You will
2241.1Slukem	# frequently need to specify a media type, as in "media UTP", for
2251.1Slukem	# interface cards with multiple media connections that do not
2261.1Slukem	# autoconfigure. See the ifconfig manual page for details.
2271.1Slukem	#
2281.1Slukem	# Note that /etc/ifconfig.xxN takes multiple lines.  The following
2291.1Slukem	# configuration is possible:
2301.1Slukem	#	inet 10.1.1.1 netmask 0xffffff00
2311.1Slukem	#	inet 10.1.1.2 netmask 0xffffff00 alias
2321.50Srpaulo	#	inet6 2001:db8::1 prefixlen 64 alias
2331.1Slukem	#
2341.29Sitojun	# You can put shell script fragment into /etc/ifconfig.xxN by
2351.29Sitojun	# starting a line with "!".  Refer to ifconfig.if(5) for details.
2361.29Sitojun	#
2371.66Suebayasi	ifaces="$(/sbin/ifconfig -l)"
2381.66Suebayasi	if checkyesno auto_ifconfig; then
2391.66Suebayasi		tmp="$ifaces"
2401.66Suebayasi		for cloner in $(/sbin/ifconfig -C); do
2411.66Suebayasi			for int in /etc/ifconfig.${cloner}[0-9]*; do
2421.66Suebayasi				[ ! -f $int ] && break
2431.66Suebayasi				tmp="$tmp ${int##*.}"
2441.15Sthorpej			done
2451.66Suebayasi		done
2461.66Suebayasi	else
2471.66Suebayasi		tmp="$net_interfaces"
2481.66Suebayasi	fi
2491.66Suebayasi	echo -n 'Configuring network interfaces:'
2501.66Suebayasi	for int in $tmp; do
2511.66Suebayasi		eval argslist=\$ifconfig_$int
2521.66Suebayasi
2531.66Suebayasi		# Skip interfaces that do not have explicit
2541.66Suebayasi		# configuration information.  If auto_ifconfig is
2551.66Suebayasi		# false then also warn about such interfaces.
2561.66Suebayasi		#
2571.66Suebayasi		if [ -z "$argslist" ] && ! [ -f /etc/ifconfig.$int ]
2581.66Suebayasi		then
2591.66Suebayasi			if ! checkyesno auto_ifconfig; then
2601.66Suebayasi				echo
2611.66Suebayasi				warn \
2621.66Suebayasi		"/etc/ifconfig.$int missing and ifconfig_$int not set;"
2631.66Suebayasi				warn "interface $int not configured."
2641.66Suebayasi			fi
2651.66Suebayasi			continue
2661.1Slukem		fi
2671.54Sapb
2681.66Suebayasi		echo -n " $int"
2691.54Sapb
2701.66Suebayasi		# Create the interface if necessary.
2711.66Suebayasi		# If the interface did not exist before,
2721.66Suebayasi		# then also resync ipf(4).
2731.66Suebayasi		#
2741.66Suebayasi		if intmissing $int $ifaces; then
2751.66Suebayasi			if /sbin/ifconfig $int create && \
2761.66Suebayasi			   checkyesno ipfilter; then
2771.66Suebayasi				/sbin/ipf -y >/dev/null
2781.54Sapb			fi
2791.66Suebayasi		fi
2801.54Sapb
2811.66Suebayasi		# If $ifconfig_xxN is empty, then use
2821.66Suebayasi		# /etc/ifconfig.xxN, which we know exists due to
2831.66Suebayasi		# an earlier test.
2841.66Suebayasi		#
2851.66Suebayasi		# If $ifconfig_xxN is non-empty and contains a
2861.66Suebayasi		# newline, then just use it as is.  (This allows
2871.66Suebayasi		# semicolons through unmolested.)
2881.66Suebayasi		#
2891.66Suebayasi		# If $ifconfig_xxN is non-empty and does not
2901.66Suebayasi		# contain a newline, then convert all semicolons
2911.66Suebayasi		# to newlines.
2921.66Suebayasi		#
2931.66Suebayasi		case "$argslist" in
2941.66Suebayasi		'')
2951.66Suebayasi			cat /etc/ifconfig.$int
2961.66Suebayasi			;;
2971.66Suebayasi		*"${nl}"*)
2981.66Suebayasi			echo "$argslist"
2991.66Suebayasi			;;
3001.66Suebayasi		*)
3011.66Suebayasi			(
3021.66Suebayasi				set -o noglob
3031.66Suebayasi				IFS=';'; set -- $argslist
3041.66Suebayasi				#echo >&2 "[$#] [$1] [$2] [$3] [$4]"
3051.66Suebayasi				IFS="$nl"; echo "$*"
3061.66Suebayasi			)
3071.66Suebayasi			;;
3081.66Suebayasi		esac |
3091.66Suebayasi		collapse_backslash_newline |
3101.66Suebayasi		while read -r args; do
3111.66Suebayasi			case "$args" in
3121.66Suebayasi			''|"#"*|create)
3131.66Suebayasi				;;
3141.66Suebayasi			"!"*)
3151.66Suebayasi				# Run arbitrary command in a subshell.
3161.66Suebayasi				( eval "${args#*!}" )
3171.54Sapb				;;
3181.66Suebayasi			dhcp)
3191.66Suebayasi				if ! checkyesno dhcpcd; then
3201.66Suebayasi					/sbin/dhcpcd -n \
3211.66Suebayasi						${dhcpcd_flags} $int
3221.66Suebayasi				fi
3231.54Sapb				;;
3241.54Sapb			*)
3251.66Suebayasi				# Pass args to ifconfig.  Note
3261.66Suebayasi				# that args may contain embedded
3271.66Suebayasi				# shell metacharacters, such as
3281.66Suebayasi				# "ssid 'foo;*>bar'". We eval
3291.66Suebayasi				# one more time so that things
3301.66Suebayasi				# like ssid "Columbia University" work.
3311.54Sapb				(
3321.54Sapb					set -o noglob
3331.66Suebayasi					eval set -- $args
3341.66Suebayasi					#echo >&2 "[$#] [$1] [$2] [$3]"
3351.66Suebayasi					/sbin/ifconfig $int "$@"
3361.54Sapb				)
3371.54Sapb				;;
3381.66Suebayasi			esac
3391.1Slukem		done
3401.66Suebayasi		configured_interfaces="$configured_interfaces $int"
3411.66Suebayasi	done
3421.66Suebayasi	echo "."
3431.64Suebayasi}
3441.1Slukem
3451.64Suebayasinetwork_start_aliases()
3461.64Suebayasi{
3471.48Scjs	echo -n "Adding interface aliases:"
3481.48Scjs
3491.1Slukem	# Check if each configured interface xxN has an $ifaliases_xxN variable
3501.1Slukem	# associated, then configure additional IP addresses for that interface.
3511.1Slukem	# The variable contains a list of "address netmask" pairs, with
3521.1Slukem	# "netmask" set to "-" if the interface default netmask is to be used.
3531.1Slukem	#
3541.54Sapb	# Note that $ifaliases_xxN works only in certain cases and its
3551.54Sapb	# use is not recommended.  Use /etc/ifconfig.xxN or multiple
3561.54Sapb	# commands in $ifconfig_xxN instead.
3571.1Slukem	#
3581.48Scjs	for int in lo0 $configured_interfaces; do
3591.20Snisimura		eval args=\$ifaliases_$int
3601.1Slukem		if [ -n "$args" ]; then
3611.1Slukem			set -- $args
3621.1Slukem			while [ $# -ge 2 ]; do
3631.1Slukem				addr=$1 ; net=$2 ; shift 2
3641.1Slukem				if [ "$net" = "-" ]; then
3651.16Sjdolecek					# for compatibility only, obsolete
3661.53Sreed					/sbin/ifconfig $int inet alias $addr
3671.1Slukem				else
3681.53Sreed					/sbin/ifconfig $int inet alias $addr \
3691.1Slukem					    netmask $net
3701.1Slukem				fi
3711.48Scjs				echo -n " $int:$addr"
3721.1Slukem			done
3731.1Slukem		fi
3741.1Slukem	done
3751.1Slukem
3761.1Slukem	# /etc/ifaliases, if it exists, contains the names of additional IP
3771.1Slukem	# addresses for each interface. It is formatted as a series of lines
3781.1Slukem	# that contain
3791.1Slukem	#	address interface netmask
3801.1Slukem	#
3811.54Sapb	# Note that /etc/ifaliases works only in certain cases and its
3821.54Sapb	# use is not recommended.  Use /etc/ifconfig.xxN or multiple
3831.54Sapb	# commands in $ifconfig_xxN instead.
3841.1Slukem	#
3851.1Slukem	if [ -f /etc/ifaliases ]; then
3861.1Slukem		while read addr int net; do
3871.1Slukem			if [ -z "$net" ]; then
3881.16Sjdolecek				# for compatibility only, obsolete
3891.53Sreed				/sbin/ifconfig $int inet alias $addr
3901.1Slukem			else
3911.53Sreed				/sbin/ifconfig $int inet alias $addr netmask $net
3921.1Slukem			fi
3931.20Snisimura		done < /etc/ifaliases
3941.1Slukem	fi
3951.1Slukem
3961.56Sapb	echo "." # for "Adding interface aliases:"
3971.64Suebayasi}
3981.56Sapb
3991.64Suebayasinetwork_start_defaultroute()
4001.64Suebayasi{
4011.56Sapb	# Check $defaultroute, then /etc/mygate, for the name or address
4021.56Sapb	# of my IPv4 gateway host. If using a name, that name must be in
4031.56Sapb	# /etc/hosts.
4041.56Sapb	#
4051.56Sapb	if [ -z "$defaultroute" ] && [ -f /etc/mygate ]; then
4061.56Sapb		defaultroute=$(cat /etc/mygate)
4071.56Sapb	fi
4081.56Sapb	if [ -n "$defaultroute" ]; then
4091.56Sapb		/sbin/route add default $defaultroute
4101.56Sapb	fi
4111.64Suebayasi}
4121.56Sapb
4131.64Suebayasinetwork_start_defaultroute6()
4141.64Suebayasi{
4151.56Sapb	# Check $defaultroute6, then /etc/mygate6, for the name or address
4161.56Sapb	# of my IPv6 gateway host. If using a name, that name must be in
4171.56Sapb	# /etc/hosts.  Note that the gateway host address must be a link-local
4181.56Sapb	# address if it is not using an stf* interface.
4191.56Sapb	#
4201.56Sapb	if [ -z "$defaultroute6" ] && [ -f /etc/mygate6 ]; then
4211.56Sapb		defaultroute6=$(cat /etc/mygate6)
4221.56Sapb	fi
4231.56Sapb	if [ -n "$defaultroute6" ]; then
4241.56Sapb		if [ "$ip6mode" = "autohost" ]; then
4251.56Sapb			echo
4261.56Sapb			warn \
4271.56Sapb	    "ip6mode is set to 'autohost' and a v6 default route is also set."
4281.56Sapb		fi
4291.56Sapb		/sbin/route add -inet6 default $defaultroute6
4301.56Sapb	fi
4311.64Suebayasi}
4321.48Scjs
4331.64Suebayasinetwork_start_ipv6_autoconf()
4341.64Suebayasi{
4351.30Sitojun	# IPv6 interface autoconfiguration.
4361.67Sroy
4371.67Sroy	# dhcpcd will ensure DAD completes before forking
4381.69Schristos	if checkyesnox rtsol && ! checkyesno dhcpcd; then
4391.66Suebayasi		if [ "$ip6mode" = "autohost" ]; then
4401.66Suebayasi			echo
4411.67Sroy			warn "rtsol has been removed, " \
4421.67Sroy			    "please configure dhcpcd in its place."
4431.66Suebayasi		fi
4441.66Suebayasi	fi
4451.64Suebayasi}
4461.42Schristos
4471.70Sroynetwork_wait_dad()
4481.70Sroy{
4491.70Sroy	# Wait for the DAD flags to clear form all addresses.
4501.70Sroy	if [ -n "$ifconfig_wait_dad_flags" ]; then
4511.70Sroy		echo 'Waiting for DAD to complete for' \
4521.70Sroy		    'statically configured addresses...'
4531.70Sroy		ifconfig $ifconfig_wait_dad_flags
4541.70Sroy	fi
4551.70Sroy}
4561.70Sroy
4571.64Suebayasinetwork_start_local()
4581.64Suebayasi{
4591.1Slukem	# XXX this must die
4601.1Slukem	if [ -s /etc/netstart.local ]; then
4611.1Slukem		sh /etc/netstart.local start
4621.1Slukem	fi
4631.1Slukem}
4641.1Slukem
4651.1Slukemnetwork_stop()
4661.1Slukem{
4671.1Slukem	echo "Stopping network."
4681.1Slukem
4691.64Suebayasi	network_stop_local
4701.64Suebayasi	network_stop_aliases
4711.65Suebayasi	[ "$net_interfaces" != NO ] &&
4721.64Suebayasi	network_stop_interfaces
4731.64Suebayasi	network_stop_route
4741.64Suebayasi}
4751.64Suebayasi
4761.64Suebayasinetwork_stop_local()
4771.64Suebayasi{
4781.1Slukem	# XXX this must die
4791.1Slukem	if [ -s /etc/netstart.local ]; then
4801.1Slukem		sh /etc/netstart.local stop
4811.1Slukem	fi
4821.64Suebayasi}
4831.1Slukem
4841.64Suebayasinetwork_stop_aliases()
4851.64Suebayasi{
4861.1Slukem	echo "Deleting aliases."
4871.1Slukem	if [ -f /etc/ifaliases ]; then
4881.1Slukem		while read addr int net; do
4891.53Sreed			/sbin/ifconfig $int inet delete $addr
4901.20Snisimura		done < /etc/ifaliases
4911.1Slukem	fi
4921.1Slukem
4931.53Sreed	for int in $(/sbin/ifconfig -lu); do
4941.20Snisimura		eval args=\$ifaliases_$int
4951.1Slukem		if [ -n "$args" ]; then
4961.1Slukem			set -- $args
4971.1Slukem			while [ $# -ge 2 ]; do
4981.1Slukem				addr=$1 ; net=$2 ; shift 2
4991.53Sreed				/sbin/ifconfig $int inet delete $addr
5001.1Slukem			done
5011.1Slukem		fi
5021.1Slukem	done
5031.64Suebayasi}
5041.1Slukem
5051.64Suebayasinetwork_stop_interfaces()
5061.64Suebayasi{
5071.1Slukem	# down interfaces
5081.1Slukem	#
5091.1Slukem	echo -n 'Downing network interfaces:'
5101.66Suebayasi	if checkyesno auto_ifconfig; then
5111.66Suebayasi		tmp=$(/sbin/ifconfig -l)
5121.66Suebayasi	else
5131.66Suebayasi		tmp="$net_interfaces"
5141.66Suebayasi	fi
5151.66Suebayasi	for int in $tmp; do
5161.66Suebayasi		eval args=\$ifconfig_$int
5171.66Suebayasi		if [ -n "$args" ] || [ -f /etc/ifconfig.$int ]; then
5181.66Suebayasi			echo -n " $int"
5191.66Suebayasi			if [ -f /var/run/dhcpcd-$int.pid ]; then
5201.66Suebayasi				/sbin/dhcpcd -k $int 2> /dev/null
5211.66Suebayasi			fi
5221.66Suebayasi			/sbin/ifconfig $int down
5231.66Suebayasi			if /sbin/ifconfig $int destroy 2>/dev/null && \
5241.66Suebayasi			   checkyesno ipfilter; then
5251.66Suebayasi				# resync ipf(4)
5261.66Suebayasi				/sbin/ipf -y >/dev/null
5271.66Suebayasi			fi
5281.1Slukem		fi
5291.66Suebayasi	done
5301.66Suebayasi	echo "."
5311.64Suebayasi}
5321.1Slukem
5331.64Suebayasinetwork_stop_route()
5341.64Suebayasi{
5351.1Slukem	# flush routes
5361.1Slukem	#
5371.53Sreed	/sbin/route -qn flush
5381.38Stron
5391.1Slukem}
5401.1Slukem
5411.47Slukemload_rc_config $name
5421.47Slukemload_rc_config_var dhclient dhclient
5431.58Sroyload_rc_config_var dhcpcd dhcpcd
5441.47Slukemload_rc_config_var ipfilter ipfilter
5451.1Slukemrun_rc_command "$1"
546