11.1Slukem#!/bin/sh
21.1Slukem#
31.85Skim# $NetBSD: network,v 1.85 2020/10/16 15:31:04 kim Exp $
41.1Slukem#
51.1Slukem
61.1Slukem# PROVIDE: network
71.82Smartin# REQUIRE: ipfilter ipsec CRITLOCALMOUNTED 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.70Sroy	network_wait_dad
541.75Sroy	network_start_resolv
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.71Schristos		hostname=$(kat /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.74Sroy		if ! 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.71Schristos		domainname=$(kat /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
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.79Sroy		if ! checkyesno dhcpcd; then
1891.79Sroy			warn "rtsol and kernel ra handling have been removed"
1901.79Sroy			warn "please configure dhcpcd in its place."
1911.79Sroy		fi
1921.66Suebayasi		;;
1931.30Sitojun
1941.80Sskrll	host)
1951.66Suebayasi		echo 'IPv6 mode: host'
1961.66Suebayasi		;;
1971.30Sitojun
1981.66Suebayasi	*)	warn "invalid \$ip6mode value "\"$ip6mode\"
1991.66Suebayasi		;;
2001.30Sitojun
2011.66Suebayasi	esac
2021.64Suebayasi}
2031.30Sitojun
2041.64Suebayasinetwork_start_interfaces()
2051.64Suebayasi{
2061.1Slukem	# Configure all of the network interfaces listed in $net_interfaces;
2071.1Slukem	# if $auto_ifconfig is YES, grab all interfaces from ifconfig.
2081.1Slukem	# In the following, "xxN" stands in for interface names, like "le0".
2091.54Sapb	#
2101.54Sapb	# For any interfaces that has an $ifconfig_xxN variable
2111.54Sapb	# associated, we break it into lines using ';' as a separator,
2121.54Sapb	# then process it just like the contents of an /etc/ifconfig.xxN
2131.54Sapb	# file.
2141.54Sapb	#
2151.54Sapb	# For each line from the $ifconfig_xxN variable or the
2161.54Sapb	# /etc/ifconfig.xxN file, we ignore comments and blank lines,
2171.54Sapb	# treat lines beginning with "!" as commands to execute, treat
2181.78Skim	# "dhcp" as a special case to invoke dhcpcd, treat "rtsol" as
2191.78Skim	# a special case to send a router solicitation, and for any other
2201.54Sapb	# line we run "ifconfig xxN", using each line of the file as the
2211.54Sapb	# arguments for a separate "ifconfig" invocation.
2221.1Slukem	#
2231.1Slukem	# In order to configure an interface reasonably, you at the very least
2241.1Slukem	# need to specify "[addr_family] [hostname]" (e.g "inet my.domain.org"),
2251.1Slukem	# and probably a netmask (as in "netmask 0xffffffe0"). You will
2261.1Slukem	# frequently need to specify a media type, as in "media UTP", for
2271.1Slukem	# interface cards with multiple media connections that do not
2281.1Slukem	# autoconfigure. See the ifconfig manual page for details.
2291.1Slukem	#
2301.1Slukem	# Note that /etc/ifconfig.xxN takes multiple lines.  The following
2311.1Slukem	# configuration is possible:
2321.1Slukem	#	inet 10.1.1.1 netmask 0xffffff00
2331.1Slukem	#	inet 10.1.1.2 netmask 0xffffff00 alias
2341.50Srpaulo	#	inet6 2001:db8::1 prefixlen 64 alias
2351.1Slukem	#
2361.29Sitojun	# You can put shell script fragment into /etc/ifconfig.xxN by
2371.29Sitojun	# starting a line with "!".  Refer to ifconfig.if(5) for details.
2381.29Sitojun	#
2391.66Suebayasi	ifaces="$(/sbin/ifconfig -l)"
2401.66Suebayasi	if checkyesno auto_ifconfig; then
2411.66Suebayasi		tmp="$ifaces"
2421.66Suebayasi		for cloner in $(/sbin/ifconfig -C); do
2431.66Suebayasi			for int in /etc/ifconfig.${cloner}[0-9]*; do
2441.66Suebayasi				[ ! -f $int ] && break
2451.66Suebayasi				tmp="$tmp ${int##*.}"
2461.15Sthorpej			done
2471.66Suebayasi		done
2481.66Suebayasi	else
2491.66Suebayasi		tmp="$net_interfaces"
2501.66Suebayasi	fi
2511.66Suebayasi	echo -n 'Configuring network interfaces:'
2521.66Suebayasi	for int in $tmp; do
2531.66Suebayasi		eval argslist=\$ifconfig_$int
2541.66Suebayasi
2551.66Suebayasi		# Skip interfaces that do not have explicit
2561.66Suebayasi		# configuration information.  If auto_ifconfig is
2571.66Suebayasi		# false then also warn about such interfaces.
2581.66Suebayasi		#
2591.66Suebayasi		if [ -z "$argslist" ] && ! [ -f /etc/ifconfig.$int ]
2601.66Suebayasi		then
2611.66Suebayasi			if ! checkyesno auto_ifconfig; then
2621.66Suebayasi				echo
2631.66Suebayasi				warn \
2641.66Suebayasi		"/etc/ifconfig.$int missing and ifconfig_$int not set;"
2651.66Suebayasi				warn "interface $int not configured."
2661.66Suebayasi			fi
2671.66Suebayasi			continue
2681.1Slukem		fi
2691.54Sapb
2701.66Suebayasi		echo -n " $int"
2711.54Sapb
2721.66Suebayasi		# Create the interface if necessary.
2731.66Suebayasi		# If the interface did not exist before,
2741.66Suebayasi		# then also resync ipf(4).
2751.66Suebayasi		#
2761.66Suebayasi		if intmissing $int $ifaces; then
2771.66Suebayasi			if /sbin/ifconfig $int create && \
2781.66Suebayasi			   checkyesno ipfilter; then
2791.66Suebayasi				/sbin/ipf -y >/dev/null
2801.54Sapb			fi
2811.66Suebayasi		fi
2821.54Sapb
2831.66Suebayasi		# If $ifconfig_xxN is empty, then use
2841.66Suebayasi		# /etc/ifconfig.xxN, which we know exists due to
2851.66Suebayasi		# an earlier test.
2861.66Suebayasi		#
2871.66Suebayasi		# If $ifconfig_xxN is non-empty and contains a
2881.66Suebayasi		# newline, then just use it as is.  (This allows
2891.66Suebayasi		# semicolons through unmolested.)
2901.66Suebayasi		#
2911.66Suebayasi		# If $ifconfig_xxN is non-empty and does not
2921.66Suebayasi		# contain a newline, then convert all semicolons
2931.66Suebayasi		# to newlines.
2941.66Suebayasi		#
2951.66Suebayasi		case "$argslist" in
2961.66Suebayasi		'')
2971.66Suebayasi			cat /etc/ifconfig.$int
2981.66Suebayasi			;;
2991.66Suebayasi		*"${nl}"*)
3001.66Suebayasi			echo "$argslist"
3011.66Suebayasi			;;
3021.66Suebayasi		*)
3031.66Suebayasi			(
3041.66Suebayasi				set -o noglob
3051.66Suebayasi				IFS=';'; set -- $argslist
3061.66Suebayasi				#echo >&2 "[$#] [$1] [$2] [$3] [$4]"
3071.66Suebayasi				IFS="$nl"; echo "$*"
3081.66Suebayasi			)
3091.66Suebayasi			;;
3101.66Suebayasi		esac |
3111.66Suebayasi		collapse_backslash_newline |
3121.66Suebayasi		while read -r args; do
3131.66Suebayasi			case "$args" in
3141.66Suebayasi			''|"#"*|create)
3151.66Suebayasi				;;
3161.66Suebayasi			"!"*)
3171.66Suebayasi				# Run arbitrary command in a subshell.
3181.66Suebayasi				( eval "${args#*!}" )
3191.54Sapb				;;
3201.66Suebayasi			dhcp)
3211.66Suebayasi				if ! checkyesno dhcpcd; then
3221.79Sroy					/sbin/dhcpcd -n --dhcp \
3231.66Suebayasi						${dhcpcd_flags} $int
3241.66Suebayasi				fi
3251.54Sapb				;;
3261.78Skim			rtsol)
3271.78Skim				if ! checkyesno dhcpcd; then
3281.85Skim					/sbin/dhcpcd -n6b \
3291.79Sroy						${dhcpcd_flags} $int
3301.78Skim				fi
3311.78Skim				;;
3321.54Sapb			*)
3331.66Suebayasi				# Pass args to ifconfig.  Note
3341.66Suebayasi				# that args may contain embedded
3351.66Suebayasi				# shell metacharacters, such as
3361.66Suebayasi				# "ssid 'foo;*>bar'". We eval
3371.66Suebayasi				# one more time so that things
3381.66Suebayasi				# like ssid "Columbia University" work.
3391.54Sapb				(
3401.54Sapb					set -o noglob
3411.66Suebayasi					eval set -- $args
3421.66Suebayasi					#echo >&2 "[$#] [$1] [$2] [$3]"
3431.66Suebayasi					/sbin/ifconfig $int "$@"
3441.54Sapb				)
3451.54Sapb				;;
3461.66Suebayasi			esac
3471.1Slukem		done
3481.66Suebayasi		configured_interfaces="$configured_interfaces $int"
3491.66Suebayasi	done
3501.66Suebayasi	echo "."
3511.64Suebayasi}
3521.1Slukem
3531.64Suebayasinetwork_start_aliases()
3541.64Suebayasi{
3551.48Scjs	echo -n "Adding interface aliases:"
3561.48Scjs
3571.1Slukem	# Check if each configured interface xxN has an $ifaliases_xxN variable
3581.1Slukem	# associated, then configure additional IP addresses for that interface.
3591.1Slukem	# The variable contains a list of "address netmask" pairs, with
3601.1Slukem	# "netmask" set to "-" if the interface default netmask is to be used.
3611.1Slukem	#
3621.54Sapb	# Note that $ifaliases_xxN works only in certain cases and its
3631.54Sapb	# use is not recommended.  Use /etc/ifconfig.xxN or multiple
3641.54Sapb	# commands in $ifconfig_xxN instead.
3651.1Slukem	#
3661.48Scjs	for int in lo0 $configured_interfaces; do
3671.20Snisimura		eval args=\$ifaliases_$int
3681.1Slukem		if [ -n "$args" ]; then
3691.1Slukem			set -- $args
3701.1Slukem			while [ $# -ge 2 ]; do
3711.1Slukem				addr=$1 ; net=$2 ; shift 2
3721.1Slukem				if [ "$net" = "-" ]; then
3731.16Sjdolecek					# for compatibility only, obsolete
3741.53Sreed					/sbin/ifconfig $int inet alias $addr
3751.1Slukem				else
3761.53Sreed					/sbin/ifconfig $int inet alias $addr \
3771.1Slukem					    netmask $net
3781.1Slukem				fi
3791.48Scjs				echo -n " $int:$addr"
3801.1Slukem			done
3811.1Slukem		fi
3821.1Slukem	done
3831.1Slukem
3841.1Slukem	# /etc/ifaliases, if it exists, contains the names of additional IP
3851.1Slukem	# addresses for each interface. It is formatted as a series of lines
3861.1Slukem	# that contain
3871.1Slukem	#	address interface netmask
3881.1Slukem	#
3891.54Sapb	# Note that /etc/ifaliases works only in certain cases and its
3901.54Sapb	# use is not recommended.  Use /etc/ifconfig.xxN or multiple
3911.54Sapb	# commands in $ifconfig_xxN instead.
3921.1Slukem	#
3931.1Slukem	if [ -f /etc/ifaliases ]; then
3941.1Slukem		while read addr int net; do
3951.1Slukem			if [ -z "$net" ]; then
3961.16Sjdolecek				# for compatibility only, obsolete
3971.53Sreed				/sbin/ifconfig $int inet alias $addr
3981.1Slukem			else
3991.53Sreed				/sbin/ifconfig $int inet alias $addr netmask $net
4001.1Slukem			fi
4011.20Snisimura		done < /etc/ifaliases
4021.1Slukem	fi
4031.1Slukem
4041.56Sapb	echo "." # for "Adding interface aliases:"
4051.64Suebayasi}
4061.56Sapb
4071.64Suebayasinetwork_start_defaultroute()
4081.64Suebayasi{
4091.56Sapb	# Check $defaultroute, then /etc/mygate, for the name or address
4101.56Sapb	# of my IPv4 gateway host. If using a name, that name must be in
4111.56Sapb	# /etc/hosts.
4121.56Sapb	#
4131.56Sapb	if [ -z "$defaultroute" ] && [ -f /etc/mygate ]; then
4141.71Schristos		defaultroute=$(kat /etc/mygate)
4151.56Sapb	fi
4161.56Sapb	if [ -n "$defaultroute" ]; then
4171.56Sapb		/sbin/route add default $defaultroute
4181.56Sapb	fi
4191.64Suebayasi}
4201.56Sapb
4211.64Suebayasinetwork_start_defaultroute6()
4221.64Suebayasi{
4231.56Sapb	# Check $defaultroute6, then /etc/mygate6, for the name or address
4241.56Sapb	# of my IPv6 gateway host. If using a name, that name must be in
4251.56Sapb	# /etc/hosts.  Note that the gateway host address must be a link-local
4261.56Sapb	# address if it is not using an stf* interface.
4271.56Sapb	#
4281.56Sapb	if [ -z "$defaultroute6" ] && [ -f /etc/mygate6 ]; then
4291.71Schristos		defaultroute6=$(kat /etc/mygate6)
4301.56Sapb	fi
4311.56Sapb	if [ -n "$defaultroute6" ]; then
4321.56Sapb		if [ "$ip6mode" = "autohost" ]; then
4331.56Sapb			echo
4341.56Sapb			warn \
4351.56Sapb	    "ip6mode is set to 'autohost' and a v6 default route is also set."
4361.56Sapb		fi
4371.56Sapb		/sbin/route add -inet6 default $defaultroute6
4381.56Sapb	fi
4391.64Suebayasi}
4401.48Scjs
4411.70Sroynetwork_wait_dad()
4421.70Sroy{
4431.77Sroy	# Wait for the DAD flags to clear from all addresses.
4441.70Sroy	if [ -n "$ifconfig_wait_dad_flags" ]; then
4451.77Sroy		echo "Waiting for duplicate address detection to finish..."
4461.70Sroy		ifconfig $ifconfig_wait_dad_flags
4471.70Sroy	fi
4481.70Sroy}
4491.70Sroy
4501.75Sroynetwork_start_resolv()
4511.75Sroy{
4521.75Sroy	resconf=
4531.75Sroy
4541.75Sroy	if [ -n "$dns_domain" ]; then
4551.75Sroy		resconf="${resconf}domain $dns_domain$nl"
4561.75Sroy	fi
4571.75Sroy	if [ -n "$dns_search" ]; then
4581.75Sroy		resconf="${resconf}search $dns_search$nl"
4591.75Sroy	fi
4601.75Sroy	for n in $dns_nameservers; do
4611.75Sroy		resconf="${resconf}nameserver $n$nl"
4621.75Sroy	done
4631.75Sroy	if [ -n "$dns_sortlist" ]; then
4641.75Sroy		resconf="${resconf}sortlist $dns_sortlist$nl"
4651.75Sroy	fi
4661.75Sroy	if [ -n "$dns_options" ]; then
4671.75Sroy		resconf="${resconf}options $dns_options$nl"
4681.75Sroy	fi
4691.75Sroy	if [ -n "$resconf" ]; then
4701.75Sroy		resconf="# Generated by /etc/rc.d/network$nl$resconf"
4711.75Sroy		echo 'Configuring resolv.conf'
4721.75Sroy		printf %s "$resconf" | resolvconf -m "${dns_metric:-0}" -a network
4731.75Sroy	fi
4741.75Sroy}
4751.75Sroy
4761.64Suebayasinetwork_start_local()
4771.64Suebayasi{
4781.1Slukem	# XXX this must die
4791.1Slukem	if [ -s /etc/netstart.local ]; then
4801.1Slukem		sh /etc/netstart.local start
4811.1Slukem	fi
4821.1Slukem}
4831.1Slukem
4841.1Slukemnetwork_stop()
4851.1Slukem{
4861.1Slukem	echo "Stopping network."
4871.1Slukem
4881.64Suebayasi	network_stop_local
4891.75Sroy	network_stop_resolv
4901.64Suebayasi	network_stop_aliases
4911.65Suebayasi	[ "$net_interfaces" != NO ] &&
4921.64Suebayasi	network_stop_interfaces
4931.64Suebayasi	network_stop_route
4941.64Suebayasi}
4951.64Suebayasi
4961.64Suebayasinetwork_stop_local()
4971.64Suebayasi{
4981.1Slukem	# XXX this must die
4991.1Slukem	if [ -s /etc/netstart.local ]; then
5001.1Slukem		sh /etc/netstart.local stop
5011.1Slukem	fi
5021.64Suebayasi}
5031.1Slukem
5041.75Sroynetwork_stop_resolv()
5051.75Sroy{
5061.75Sroy	resolvconf -f -d network
5071.75Sroy}
5081.75Sroy
5091.64Suebayasinetwork_stop_aliases()
5101.64Suebayasi{
5111.1Slukem	echo "Deleting aliases."
5121.1Slukem	if [ -f /etc/ifaliases ]; then
5131.1Slukem		while read addr int net; do
5141.53Sreed			/sbin/ifconfig $int inet delete $addr
5151.20Snisimura		done < /etc/ifaliases
5161.1Slukem	fi
5171.1Slukem
5181.53Sreed	for int in $(/sbin/ifconfig -lu); do
5191.20Snisimura		eval args=\$ifaliases_$int
5201.1Slukem		if [ -n "$args" ]; then
5211.1Slukem			set -- $args
5221.1Slukem			while [ $# -ge 2 ]; do
5231.1Slukem				addr=$1 ; net=$2 ; shift 2
5241.53Sreed				/sbin/ifconfig $int inet delete $addr
5251.1Slukem			done
5261.1Slukem		fi
5271.1Slukem	done
5281.64Suebayasi}
5291.1Slukem
5301.64Suebayasinetwork_stop_interfaces()
5311.64Suebayasi{
5321.1Slukem	# down interfaces
5331.1Slukem	#
5341.1Slukem	echo -n 'Downing network interfaces:'
5351.66Suebayasi	if checkyesno auto_ifconfig; then
5361.66Suebayasi		tmp=$(/sbin/ifconfig -l)
5371.66Suebayasi	else
5381.66Suebayasi		tmp="$net_interfaces"
5391.66Suebayasi	fi
5401.66Suebayasi	for int in $tmp; do
5411.66Suebayasi		eval args=\$ifconfig_$int
5421.66Suebayasi		if [ -n "$args" ] || [ -f /etc/ifconfig.$int ]; then
5431.66Suebayasi			echo -n " $int"
5441.66Suebayasi			if [ -f /var/run/dhcpcd-$int.pid ]; then
5451.66Suebayasi				/sbin/dhcpcd -k $int 2> /dev/null
5461.66Suebayasi			fi
5471.66Suebayasi			/sbin/ifconfig $int down
5481.66Suebayasi			if /sbin/ifconfig $int destroy 2>/dev/null && \
5491.66Suebayasi			   checkyesno ipfilter; then
5501.66Suebayasi				# resync ipf(4)
5511.66Suebayasi				/sbin/ipf -y >/dev/null
5521.66Suebayasi			fi
5531.1Slukem		fi
5541.66Suebayasi	done
5551.66Suebayasi	echo "."
5561.64Suebayasi}
5571.1Slukem
5581.64Suebayasinetwork_stop_route()
5591.64Suebayasi{
5601.1Slukem	# flush routes
5611.1Slukem	#
5621.76Smrg	if checkyesno flushroutes; then
5631.76Smrg		/sbin/route -qn flush
5641.76Smrg	fi
5651.1Slukem}
5661.1Slukem
5671.47Slukemload_rc_config $name
5681.58Sroyload_rc_config_var dhcpcd dhcpcd
5691.47Slukemload_rc_config_var ipfilter ipfilter
5701.1Slukemrun_rc_command "$1"
571