Home | History | Annotate | Line # | Download | only in rc.d
network revision 1.61.12.3
      1        1.1     lukem #!/bin/sh
      2        1.1     lukem #
      3  1.61.12.2       tls # $NetBSD: network,v 1.61.12.3 2014/08/19 23:45:51 tls Exp $
      4        1.1     lukem #
      5        1.1     lukem 
      6        1.1     lukem # PROVIDE: network
      7       1.19     lukem # REQUIRE: ipfilter ipsec mountcritlocal root tty sysctl
      8       1.34   thorpej # BEFORE:  NETWORKING
      9        1.1     lukem 
     10       1.45   mycroft $_rc_subr_loaded . /etc/rc.subr
     11        1.1     lukem 
     12        1.1     lukem name="network"
     13        1.1     lukem start_cmd="network_start"
     14       1.14     lukem stop_cmd="network_stop"
     15        1.1     lukem 
     16       1.54       apb nl='
     17       1.54       apb ' # a newline
     18       1.54       apb 
     19  1.61.12.3       tls intmissing()
     20  1.61.12.3       tls {
     21  1.61.12.2       tls 	local int="$1"
     22  1.61.12.2       tls 	shift
     23  1.61.12.3       tls 	for i; do
     24  1.61.12.2       tls 		if [ "$int" = "$i" ]; then
     25  1.61.12.2       tls 			return 1
     26  1.61.12.2       tls 		fi
     27  1.61.12.2       tls 	done
     28  1.61.12.2       tls 	return 0
     29  1.61.12.2       tls }
     30  1.61.12.2       tls 
     31  1.61.12.3       tls have_inet6()
     32  1.61.12.3       tls {
     33  1.61.12.3       tls 	/sbin/ifconfig lo0 inet6 >/dev/null 2>&1
     34  1.61.12.3       tls }
     35  1.61.12.3       tls 
     36        1.1     lukem network_start()
     37        1.1     lukem {
     38        1.1     lukem 	# set hostname, turn on network
     39        1.1     lukem 	#
     40        1.1     lukem 	echo "Starting network."
     41        1.1     lukem 
     42  1.61.12.3       tls 	network_start_hostname
     43  1.61.12.3       tls 	network_start_domainname
     44  1.61.12.3       tls 	network_start_loopback
     45  1.61.12.3       tls 	have_inet6 &&
     46  1.61.12.3       tls 	network_start_ipv6_route
     47  1.61.12.3       tls 	[ "$net_interfaces" != NO ] &&
     48  1.61.12.3       tls 	network_start_interfaces
     49  1.61.12.3       tls 	network_start_aliases
     50  1.61.12.3       tls 	network_start_defaultroute
     51  1.61.12.3       tls 	network_start_defaultroute6
     52  1.61.12.3       tls 	have_inet6 &&
     53  1.61.12.3       tls 	network_start_ipv6_autoconf
     54  1.61.12.3       tls 	network_start_local
     55  1.61.12.3       tls }
     56  1.61.12.3       tls 
     57  1.61.12.3       tls network_start_hostname()
     58  1.61.12.3       tls {
     59        1.1     lukem 	# If $hostname is set, use it for my Internet name,
     60        1.1     lukem 	# otherwise use /etc/myname
     61        1.1     lukem 	#
     62       1.20  nisimura 	if [ -z "$hostname" ] && [ -f /etc/myname ]; then
     63       1.46  christos 		hostname=$(cat /etc/myname)
     64        1.1     lukem 	fi
     65        1.1     lukem 	if [ -n "$hostname" ]; then
     66        1.1     lukem 		echo "Hostname: $hostname"
     67        1.1     lukem 		hostname $hostname
     68        1.1     lukem 	else
     69        1.8   thorpej 		# Don't warn about it if we're going to run
     70        1.8   thorpej 		# DHCP later, as we will probably get the
     71        1.8   thorpej 		# hostname at that time.
     72        1.8   thorpej 		#
     73       1.58       roy 		if ! checkyesno dhclient && ! checkyesno dhcpcd && \
     74       1.58       roy 			[ -z "$(hostname)" ]
     75       1.58       roy 		then
     76        1.8   thorpej 			warn "\$hostname not set."
     77        1.8   thorpej 		fi
     78        1.1     lukem 	fi
     79  1.61.12.3       tls }
     80        1.1     lukem 
     81  1.61.12.3       tls network_start_domainname()
     82  1.61.12.3       tls {
     83        1.1     lukem 	# Check $domainname first, then /etc/defaultdomain,
     84        1.1     lukem 	# for NIS/YP domain name
     85        1.1     lukem 	#
     86       1.20  nisimura 	if [ -z "$domainname" ] && [ -f /etc/defaultdomain ]; then
     87       1.46  christos 		domainname=$(cat /etc/defaultdomain)
     88        1.1     lukem 	fi
     89        1.1     lukem 	if [ -n "$domainname" ]; then
     90        1.1     lukem 		echo "NIS domainname: $domainname"
     91        1.1     lukem 		domainname $domainname
     92        1.1     lukem 	fi
     93        1.1     lukem 
     94        1.1     lukem 	# Flush all routes just to make sure it is clean
     95        1.1     lukem 	if checkyesno flushroutes; then
     96       1.53      reed 		/sbin/route -qn flush
     97        1.1     lukem 	fi
     98  1.61.12.3       tls }
     99        1.1     lukem 
    100  1.61.12.3       tls network_start_loopback()
    101  1.61.12.3       tls {
    102        1.1     lukem 	# Set the address for the first loopback interface, so that the
    103        1.1     lukem 	# auto-route from a newly configured interface's address to lo0
    104        1.1     lukem 	# works correctly.
    105        1.1     lukem 	#
    106       1.32     lukem 	# NOTE: obscure networking problems will occur if lo0 isn't configured.
    107        1.1     lukem 	#
    108       1.53      reed 	/sbin/ifconfig lo0 inet 127.0.0.1
    109       1.10    itojun 
    110       1.31    itojun 	# According to RFC1122, 127.0.0.0/8 must not leave the node.
    111       1.10    itojun 	#
    112       1.53      reed 	/sbin/route -q add -inet 127.0.0.0 -netmask 0xff000000 127.0.0.1 -reject
    113  1.61.12.3       tls }
    114        1.1     lukem 
    115  1.61.12.3       tls network_start_ipv6_route()
    116  1.61.12.3       tls {
    117       1.30    itojun 	# IPv6 routing setups, and host/router mode selection.
    118       1.30    itojun 	#
    119  1.61.12.3       tls 	# We have IPv6 support in kernel.
    120       1.30    itojun 
    121  1.61.12.3       tls 	# disallow link-local unicast dest without outgoing scope
    122  1.61.12.3       tls 	# identifiers.
    123  1.61.12.3       tls 	#
    124  1.61.12.3       tls 	/sbin/route -q add -inet6 fe80:: -prefixlen 10 ::1 -reject
    125       1.30    itojun 
    126  1.61.12.3       tls 	# disallow the use of the RFC3849 documentation address
    127  1.61.12.3       tls 	#
    128  1.61.12.3       tls 	/sbin/route -q add -inet6 2001:db8:: -prefixlen 32 ::1 -reject
    129       1.50    rpaulo 
    130  1.61.12.3       tls 	# IPv6 site-local scoped address prefix (fec0::/10)
    131  1.61.12.3       tls 	# has been deprecated by RFC3879.
    132  1.61.12.3       tls 	#
    133  1.61.12.3       tls 	if [ -n "$ip6sitelocal" ]; then
    134  1.61.12.3       tls 		warn "\$ip6sitelocal is no longer valid"
    135  1.61.12.3       tls 	fi
    136       1.30    itojun 
    137  1.61.12.3       tls 	# disallow "internal" addresses to appear on the wire.
    138  1.61.12.3       tls 	#
    139  1.61.12.3       tls 	/sbin/route -q add -inet6 ::ffff:0.0.0.0 -prefixlen 96 ::1 -reject
    140       1.30    itojun 
    141  1.61.12.3       tls 	# disallow packets to malicious IPv4 compatible prefix
    142  1.61.12.3       tls 	#
    143  1.61.12.3       tls 	/sbin/route -q add -inet6 ::224.0.0.0 -prefixlen 100 ::1 -reject
    144  1.61.12.3       tls 	/sbin/route -q add -inet6 ::127.0.0.0 -prefixlen 104 ::1 -reject
    145  1.61.12.3       tls 	/sbin/route -q add -inet6 ::0.0.0.0 -prefixlen 104 ::1 -reject
    146  1.61.12.3       tls 	/sbin/route -q add -inet6 ::255.0.0.0 -prefixlen 104 ::1 -reject
    147       1.30    itojun 
    148  1.61.12.3       tls 	# disallow packets to malicious 6to4 prefix
    149  1.61.12.3       tls 	#
    150  1.61.12.3       tls 	/sbin/route -q add -inet6 2002:e000:: -prefixlen 20 ::1 -reject
    151  1.61.12.3       tls 	/sbin/route -q add -inet6 2002:7f00:: -prefixlen 24 ::1 -reject
    152  1.61.12.3       tls 	/sbin/route -q add -inet6 2002:0000:: -prefixlen 24 ::1 -reject
    153  1.61.12.3       tls 	/sbin/route -q add -inet6 2002:ff00:: -prefixlen 24 ::1 -reject
    154       1.30    itojun 
    155  1.61.12.3       tls 	# Completely disallow packets to IPv4 compatible prefix.
    156  1.61.12.3       tls 	# This may conflict with RFC1933 under following circumstances:
    157  1.61.12.3       tls 	# (1) An IPv6-only KAME node tries to originate packets to IPv4
    158  1.61.12.3       tls 	#     compatible destination.  The KAME node has no IPv4
    159  1.61.12.3       tls 	#     compatible support.  Under RFC1933, it should transmit
    160  1.61.12.3       tls 	#     native IPv6 packets toward IPv4 compatible destination,
    161  1.61.12.3       tls 	#     hoping it would reach a router that forwards the packet
    162  1.61.12.3       tls 	#     toward auto-tunnel interface.
    163  1.61.12.3       tls 	# (2) An IPv6-only node originates a packet to IPv4 compatible
    164  1.61.12.3       tls 	#     destination.  A KAME node is acting as an IPv6 router, and
    165  1.61.12.3       tls 	#     asked to forward it.
    166  1.61.12.3       tls 	# Due to rare use of IPv4 compatible address, and security
    167  1.61.12.3       tls 	# issues with it, we disable it by default.
    168  1.61.12.3       tls 	#
    169  1.61.12.3       tls 	/sbin/route -q add -inet6 ::0.0.0.0 -prefixlen 96 ::1 -reject
    170       1.30    itojun 
    171  1.61.12.3       tls 	/sbin/sysctl -qw net.inet6.ip6.forwarding=0
    172  1.61.12.3       tls 	/sbin/sysctl -qw net.inet6.ip6.accept_rtadv=0
    173       1.30    itojun 
    174  1.61.12.3       tls 	case $ip6mode in
    175  1.61.12.3       tls 	router)
    176  1.61.12.3       tls 		echo 'IPv6 mode: router'
    177  1.61.12.3       tls 		/sbin/sysctl -qw net.inet6.ip6.forwarding=1
    178       1.30    itojun 
    179  1.61.12.3       tls 		# disallow unique-local unicast forwarding without
    180  1.61.12.3       tls 		# explicit configuration.
    181  1.61.12.3       tls 		if ! checkyesno ip6uniquelocal; then
    182  1.61.12.3       tls 			/sbin/route -q add -inet6 fc00:: -prefixlen 7 \
    183  1.61.12.3       tls 			    ::1 -reject
    184  1.61.12.3       tls 		fi
    185  1.61.12.3       tls 		;;
    186       1.30    itojun 
    187  1.61.12.3       tls 	autohost)
    188  1.61.12.3       tls 		echo 'IPv6 mode: autoconfigured host'
    189  1.61.12.3       tls 		/sbin/sysctl -qw net.inet6.ip6.accept_rtadv=1
    190  1.61.12.3       tls 		;;
    191       1.30    itojun 
    192  1.61.12.3       tls 	host)	
    193  1.61.12.3       tls 		echo 'IPv6 mode: host'
    194  1.61.12.3       tls 		;;
    195  1.61.12.3       tls 
    196  1.61.12.3       tls 	*)	warn "invalid \$ip6mode value "\"$ip6mode\"
    197  1.61.12.3       tls 		;;
    198  1.61.12.3       tls 
    199  1.61.12.3       tls 	esac
    200  1.61.12.3       tls }
    201       1.30    itojun 
    202  1.61.12.3       tls network_start_interfaces()
    203  1.61.12.3       tls {
    204        1.1     lukem 	# Configure all of the network interfaces listed in $net_interfaces;
    205        1.1     lukem 	# if $auto_ifconfig is YES, grab all interfaces from ifconfig.
    206        1.1     lukem 	# In the following, "xxN" stands in for interface names, like "le0".
    207       1.54       apb 	#
    208       1.54       apb 	# For any interfaces that has an $ifconfig_xxN variable
    209       1.54       apb 	# associated, we break it into lines using ';' as a separator,
    210       1.54       apb 	# then process it just like the contents of an /etc/ifconfig.xxN
    211       1.54       apb 	# file.
    212       1.54       apb 	#
    213       1.54       apb 	# For each line from the $ifconfig_xxN variable or the
    214       1.54       apb 	# /etc/ifconfig.xxN file, we ignore comments and blank lines,
    215       1.54       apb 	# treat lines beginning with "!" as commands to execute, treat
    216       1.54       apb 	# "dhcp" as a special case to invoke dhcpcd, and for any other
    217       1.54       apb 	# line we run "ifconfig xxN", using each line of the file as the
    218       1.54       apb 	# arguments for a separate "ifconfig" invocation.
    219        1.1     lukem 	#
    220        1.1     lukem 	# In order to configure an interface reasonably, you at the very least
    221        1.1     lukem 	# need to specify "[addr_family] [hostname]" (e.g "inet my.domain.org"),
    222        1.1     lukem 	# and probably a netmask (as in "netmask 0xffffffe0"). You will
    223        1.1     lukem 	# frequently need to specify a media type, as in "media UTP", for
    224        1.1     lukem 	# interface cards with multiple media connections that do not
    225        1.1     lukem 	# autoconfigure. See the ifconfig manual page for details.
    226        1.1     lukem 	#
    227        1.1     lukem 	# Note that /etc/ifconfig.xxN takes multiple lines.  The following
    228        1.1     lukem 	# configuration is possible:
    229        1.1     lukem 	#	inet 10.1.1.1 netmask 0xffffff00
    230        1.1     lukem 	#	inet 10.1.1.2 netmask 0xffffff00 alias
    231       1.50    rpaulo 	#	inet6 2001:db8::1 prefixlen 64 alias
    232        1.1     lukem 	#
    233       1.29    itojun 	# You can put shell script fragment into /etc/ifconfig.xxN by
    234       1.29    itojun 	# starting a line with "!".  Refer to ifconfig.if(5) for details.
    235       1.29    itojun 	#
    236  1.61.12.3       tls 	ifaces="$(/sbin/ifconfig -l)"
    237  1.61.12.3       tls 	if checkyesno auto_ifconfig; then
    238  1.61.12.3       tls 		tmp="$ifaces"
    239  1.61.12.3       tls 		for cloner in $(/sbin/ifconfig -C); do
    240  1.61.12.3       tls 			for int in /etc/ifconfig.${cloner}[0-9]*; do
    241  1.61.12.3       tls 				[ ! -f $int ] && break
    242  1.61.12.3       tls 				tmp="$tmp ${int##*.}"
    243       1.15   thorpej 			done
    244  1.61.12.3       tls 		done
    245  1.61.12.3       tls 	else
    246  1.61.12.3       tls 		tmp="$net_interfaces"
    247  1.61.12.3       tls 	fi
    248  1.61.12.3       tls 	echo -n 'Configuring network interfaces:'
    249  1.61.12.3       tls 	for int in $tmp; do
    250  1.61.12.3       tls 		eval argslist=\$ifconfig_$int
    251  1.61.12.3       tls 
    252  1.61.12.3       tls 		# Skip interfaces that do not have explicit
    253  1.61.12.3       tls 		# configuration information.  If auto_ifconfig is
    254  1.61.12.3       tls 		# false then also warn about such interfaces.
    255  1.61.12.3       tls 		#
    256  1.61.12.3       tls 		if [ -z "$argslist" ] && ! [ -f /etc/ifconfig.$int ]
    257  1.61.12.3       tls 		then
    258  1.61.12.3       tls 			if ! checkyesno auto_ifconfig; then
    259  1.61.12.3       tls 				echo
    260  1.61.12.3       tls 				warn \
    261  1.61.12.3       tls 		"/etc/ifconfig.$int missing and ifconfig_$int not set;"
    262  1.61.12.3       tls 				warn "interface $int not configured."
    263        1.1     lukem 			fi
    264  1.61.12.3       tls 			continue
    265  1.61.12.3       tls 		fi
    266       1.54       apb 
    267  1.61.12.3       tls 		echo -n " $int"
    268       1.54       apb 
    269  1.61.12.3       tls 		# Create the interface if necessary.
    270  1.61.12.3       tls 		# If the interface did not exist before,
    271  1.61.12.3       tls 		# then also resync ipf(4).
    272  1.61.12.3       tls 		#
    273  1.61.12.3       tls 		if intmissing $int $ifaces; then
    274  1.61.12.3       tls 			if /sbin/ifconfig $int create && \
    275  1.61.12.3       tls 			   checkyesno ipfilter; then
    276  1.61.12.3       tls 				/sbin/ipf -y >/dev/null
    277       1.54       apb 			fi
    278  1.61.12.3       tls 		fi
    279       1.54       apb 
    280  1.61.12.3       tls 		# If $ifconfig_xxN is empty, then use
    281  1.61.12.3       tls 		# /etc/ifconfig.xxN, which we know exists due to
    282  1.61.12.3       tls 		# an earlier test.
    283  1.61.12.3       tls 		#
    284  1.61.12.3       tls 		# If $ifconfig_xxN is non-empty and contains a
    285  1.61.12.3       tls 		# newline, then just use it as is.  (This allows
    286  1.61.12.3       tls 		# semicolons through unmolested.)
    287  1.61.12.3       tls 		#
    288  1.61.12.3       tls 		# If $ifconfig_xxN is non-empty and does not
    289  1.61.12.3       tls 		# contain a newline, then convert all semicolons
    290  1.61.12.3       tls 		# to newlines.
    291  1.61.12.3       tls 		#
    292  1.61.12.3       tls 		case "$argslist" in
    293  1.61.12.3       tls 		'')
    294  1.61.12.3       tls 			cat /etc/ifconfig.$int
    295  1.61.12.3       tls 			;;
    296  1.61.12.3       tls 		*"${nl}"*)
    297  1.61.12.3       tls 			echo "$argslist"
    298  1.61.12.3       tls 			;;
    299  1.61.12.3       tls 		*)
    300  1.61.12.3       tls 			(
    301  1.61.12.3       tls 				set -o noglob
    302  1.61.12.3       tls 				IFS=';'; set -- $argslist
    303  1.61.12.3       tls 				#echo >&2 "[$#] [$1] [$2] [$3] [$4]"
    304  1.61.12.3       tls 				IFS="$nl"; echo "$*"
    305  1.61.12.3       tls 			)
    306  1.61.12.3       tls 			;;
    307  1.61.12.3       tls 		esac |
    308  1.61.12.3       tls 		collapse_backslash_newline |
    309  1.61.12.3       tls 		while read -r args; do
    310  1.61.12.3       tls 			case "$args" in
    311  1.61.12.3       tls 			''|"#"*|create)
    312  1.61.12.3       tls 				;;
    313  1.61.12.3       tls 			"!"*)
    314  1.61.12.3       tls 				# Run arbitrary command in a subshell.
    315  1.61.12.3       tls 				( eval "${args#*!}" )
    316       1.54       apb 				;;
    317  1.61.12.3       tls 			dhcp)
    318  1.61.12.3       tls 				if ! checkyesno dhcpcd; then
    319  1.61.12.3       tls 					/sbin/dhcpcd -n \
    320  1.61.12.3       tls 						${dhcpcd_flags} $int
    321  1.61.12.3       tls 				fi
    322       1.54       apb 				;;
    323       1.54       apb 			*)
    324  1.61.12.3       tls 				# Pass args to ifconfig.  Note
    325  1.61.12.3       tls 				# that args may contain embedded
    326  1.61.12.3       tls 				# shell metacharacters, such as
    327  1.61.12.3       tls 				# "ssid 'foo;*>bar'". We eval
    328  1.61.12.3       tls 				# one more time so that things
    329  1.61.12.3       tls 				# like ssid "Columbia University" work.
    330       1.54       apb 				(
    331       1.54       apb 					set -o noglob
    332  1.61.12.3       tls 					eval set -- $args
    333  1.61.12.3       tls 					#echo >&2 "[$#] [$1] [$2] [$3]"
    334  1.61.12.3       tls 					/sbin/ifconfig $int "$@"
    335       1.54       apb 				)
    336       1.54       apb 				;;
    337  1.61.12.3       tls 			esac
    338        1.1     lukem 		done
    339  1.61.12.3       tls 		configured_interfaces="$configured_interfaces $int"
    340  1.61.12.3       tls 	done
    341  1.61.12.3       tls 	echo "."
    342  1.61.12.3       tls }
    343        1.1     lukem 
    344  1.61.12.3       tls network_start_aliases()
    345  1.61.12.3       tls {
    346       1.48       cjs 	echo -n "Adding interface aliases:"
    347       1.48       cjs 
    348        1.1     lukem 	# Check if each configured interface xxN has an $ifaliases_xxN variable
    349        1.1     lukem 	# associated, then configure additional IP addresses for that interface.
    350        1.1     lukem 	# The variable contains a list of "address netmask" pairs, with
    351        1.1     lukem 	# "netmask" set to "-" if the interface default netmask is to be used.
    352        1.1     lukem 	#
    353       1.54       apb 	# Note that $ifaliases_xxN works only in certain cases and its
    354       1.54       apb 	# use is not recommended.  Use /etc/ifconfig.xxN or multiple
    355       1.54       apb 	# commands in $ifconfig_xxN instead.
    356        1.1     lukem 	#
    357       1.48       cjs 	for int in lo0 $configured_interfaces; do
    358       1.20  nisimura 		eval args=\$ifaliases_$int
    359        1.1     lukem 		if [ -n "$args" ]; then
    360        1.1     lukem 			set -- $args
    361        1.1     lukem 			while [ $# -ge 2 ]; do
    362        1.1     lukem 				addr=$1 ; net=$2 ; shift 2
    363        1.1     lukem 				if [ "$net" = "-" ]; then
    364       1.16  jdolecek 					# for compatibility only, obsolete
    365       1.53      reed 					/sbin/ifconfig $int inet alias $addr
    366        1.1     lukem 				else
    367       1.53      reed 					/sbin/ifconfig $int inet alias $addr \
    368        1.1     lukem 					    netmask $net
    369        1.1     lukem 				fi
    370       1.48       cjs 				echo -n " $int:$addr"
    371        1.1     lukem 			done
    372        1.1     lukem 		fi
    373        1.1     lukem 	done
    374        1.1     lukem 
    375        1.1     lukem 	# /etc/ifaliases, if it exists, contains the names of additional IP
    376        1.1     lukem 	# addresses for each interface. It is formatted as a series of lines
    377        1.1     lukem 	# that contain
    378        1.1     lukem 	#	address interface netmask
    379        1.1     lukem 	#
    380       1.54       apb 	# Note that /etc/ifaliases works only in certain cases and its
    381       1.54       apb 	# use is not recommended.  Use /etc/ifconfig.xxN or multiple
    382       1.54       apb 	# commands in $ifconfig_xxN instead.
    383        1.1     lukem 	#
    384        1.1     lukem 	if [ -f /etc/ifaliases ]; then
    385        1.1     lukem 		while read addr int net; do
    386        1.1     lukem 			if [ -z "$net" ]; then
    387       1.16  jdolecek 				# for compatibility only, obsolete
    388       1.53      reed 				/sbin/ifconfig $int inet alias $addr
    389        1.1     lukem 			else
    390       1.53      reed 				/sbin/ifconfig $int inet alias $addr netmask $net
    391        1.1     lukem 			fi
    392       1.20  nisimura 		done < /etc/ifaliases
    393        1.1     lukem 	fi
    394        1.1     lukem 
    395       1.56       apb 	echo "." # for "Adding interface aliases:"
    396  1.61.12.3       tls }
    397       1.56       apb 
    398  1.61.12.3       tls network_start_defaultroute()
    399  1.61.12.3       tls {
    400       1.56       apb 	# Check $defaultroute, then /etc/mygate, for the name or address
    401       1.56       apb 	# of my IPv4 gateway host. If using a name, that name must be in
    402       1.56       apb 	# /etc/hosts.
    403       1.56       apb 	#
    404       1.56       apb 	if [ -z "$defaultroute" ] && [ -f /etc/mygate ]; then
    405       1.56       apb 		defaultroute=$(cat /etc/mygate)
    406       1.56       apb 	fi
    407       1.56       apb 	if [ -n "$defaultroute" ]; then
    408       1.56       apb 		/sbin/route add default $defaultroute
    409       1.56       apb 	fi
    410  1.61.12.3       tls }
    411       1.56       apb 
    412  1.61.12.3       tls network_start_defaultroute6()
    413  1.61.12.3       tls {
    414       1.56       apb 	# Check $defaultroute6, then /etc/mygate6, for the name or address
    415       1.56       apb 	# of my IPv6 gateway host. If using a name, that name must be in
    416       1.56       apb 	# /etc/hosts.  Note that the gateway host address must be a link-local
    417       1.56       apb 	# address if it is not using an stf* interface.
    418       1.56       apb 	#
    419       1.56       apb 	if [ -z "$defaultroute6" ] && [ -f /etc/mygate6 ]; then
    420       1.56       apb 		defaultroute6=$(cat /etc/mygate6)
    421       1.56       apb 	fi
    422       1.56       apb 	if [ -n "$defaultroute6" ]; then
    423       1.56       apb 		if [ "$ip6mode" = "autohost" ]; then
    424       1.56       apb 			echo
    425       1.56       apb 			warn \
    426       1.56       apb 	    "ip6mode is set to 'autohost' and a v6 default route is also set."
    427       1.56       apb 		fi
    428       1.56       apb 		/sbin/route add -inet6 default $defaultroute6
    429       1.56       apb 	fi
    430  1.61.12.3       tls }
    431       1.48       cjs 
    432  1.61.12.3       tls network_start_ipv6_autoconf()
    433  1.61.12.3       tls {
    434       1.30    itojun 	# IPv6 interface autoconfiguration.
    435        1.1     lukem 	#
    436  1.61.12.3       tls 	# wait till DAD is completed. always invoke it in case
    437  1.61.12.3       tls 	# if are configured manually by ifconfig
    438  1.61.12.3       tls 	#
    439  1.61.12.3       tls 	echo 'Waiting for DAD completion for' \
    440  1.61.12.3       tls 	    'statically configured addresses...'
    441  1.61.12.3       tls 	dadcount=$(/sbin/sysctl -n net.inet6.ip6.dad_count 2>/dev/null)
    442  1.61.12.3       tls 	sleep $dadcount
    443  1.61.12.3       tls 	sleep 1
    444  1.61.12.3       tls 
    445  1.61.12.3       tls 	if checkyesno rtsol; then
    446  1.61.12.3       tls 		if [ "$ip6mode" = "autohost" ]; then
    447  1.61.12.3       tls 			echo 'Sending router solicitation...'
    448  1.61.12.3       tls 			/sbin/rtsol $rtsol_flags
    449  1.61.12.3       tls 		else
    450  1.61.12.3       tls 			echo
    451  1.61.12.3       tls 			warn \
    452  1.61.12.3       tls 		    "ip6mode must be set to 'autohost' to use rtsol."
    453  1.61.12.3       tls 		fi
    454  1.61.12.3       tls 
    455  1.61.12.3       tls 		# wait till DAD is completed, for global addresses
    456  1.61.12.3       tls 		# configured by router advert message.
    457       1.17    itojun 		#
    458  1.61.12.1       tls 		echo 'Waiting for DAD completion for' \
    459  1.61.12.3       tls 		    'addresses configured by router advert message...'
    460       1.17    itojun 		sleep $dadcount
    461       1.17    itojun 		sleep 1
    462       1.42  christos 	fi
    463  1.61.12.3       tls }
    464       1.42  christos 
    465  1.61.12.3       tls network_start_local()
    466  1.61.12.3       tls {
    467        1.1     lukem 	# XXX this must die
    468        1.1     lukem 	if [ -s /etc/netstart.local ]; then
    469        1.1     lukem 		sh /etc/netstart.local start
    470        1.1     lukem 	fi
    471        1.1     lukem }
    472        1.1     lukem 
    473        1.1     lukem network_stop()
    474        1.1     lukem {
    475        1.1     lukem 	echo "Stopping network."
    476        1.1     lukem 
    477  1.61.12.3       tls 	network_stop_local
    478  1.61.12.3       tls 	network_stop_aliases
    479  1.61.12.3       tls 	[ "$net_interfaces" != NO ] &&
    480  1.61.12.3       tls 	network_stop_interfaces
    481  1.61.12.3       tls 	network_stop_route
    482  1.61.12.3       tls }
    483  1.61.12.3       tls 
    484  1.61.12.3       tls network_stop_local()
    485  1.61.12.3       tls {
    486        1.1     lukem 	# XXX this must die
    487        1.1     lukem 	if [ -s /etc/netstart.local ]; then
    488        1.1     lukem 		sh /etc/netstart.local stop
    489        1.1     lukem 	fi
    490  1.61.12.3       tls }
    491        1.1     lukem 
    492  1.61.12.3       tls network_stop_aliases()
    493  1.61.12.3       tls {
    494        1.1     lukem 	echo "Deleting aliases."
    495        1.1     lukem 	if [ -f /etc/ifaliases ]; then
    496        1.1     lukem 		while read addr int net; do
    497       1.53      reed 			/sbin/ifconfig $int inet delete $addr
    498       1.20  nisimura 		done < /etc/ifaliases
    499        1.1     lukem 	fi
    500        1.1     lukem 
    501       1.53      reed 	for int in $(/sbin/ifconfig -lu); do
    502       1.20  nisimura 		eval args=\$ifaliases_$int
    503        1.1     lukem 		if [ -n "$args" ]; then
    504        1.1     lukem 			set -- $args
    505        1.1     lukem 			while [ $# -ge 2 ]; do
    506        1.1     lukem 				addr=$1 ; net=$2 ; shift 2
    507       1.53      reed 				/sbin/ifconfig $int inet delete $addr
    508        1.1     lukem 			done
    509        1.1     lukem 		fi
    510        1.1     lukem 	done
    511  1.61.12.3       tls }
    512        1.1     lukem 
    513  1.61.12.3       tls network_stop_interfaces()
    514  1.61.12.3       tls {
    515        1.1     lukem 	# down interfaces
    516        1.1     lukem 	#
    517        1.1     lukem 	echo -n 'Downing network interfaces:'
    518  1.61.12.3       tls 	if checkyesno auto_ifconfig; then
    519  1.61.12.3       tls 		tmp=$(/sbin/ifconfig -l)
    520  1.61.12.3       tls 	else
    521  1.61.12.3       tls 		tmp="$net_interfaces"
    522        1.1     lukem 	fi
    523  1.61.12.3       tls 	for int in $tmp; do
    524  1.61.12.3       tls 		eval args=\$ifconfig_$int
    525  1.61.12.3       tls 		if [ -n "$args" ] || [ -f /etc/ifconfig.$int ]; then
    526  1.61.12.3       tls 			echo -n " $int"
    527  1.61.12.3       tls 			if [ -f /var/run/dhcpcd-$int.pid ]; then
    528  1.61.12.3       tls 				/sbin/dhcpcd -k $int 2> /dev/null
    529  1.61.12.3       tls 			fi
    530  1.61.12.3       tls 			/sbin/ifconfig $int down
    531  1.61.12.3       tls 			if /sbin/ifconfig $int destroy 2>/dev/null && \
    532  1.61.12.3       tls 			   checkyesno ipfilter; then
    533  1.61.12.3       tls 				# resync ipf(4)
    534  1.61.12.3       tls 				/sbin/ipf -y >/dev/null
    535  1.61.12.3       tls 			fi
    536  1.61.12.3       tls 		fi
    537  1.61.12.3       tls 	done
    538  1.61.12.3       tls 	echo "."
    539  1.61.12.3       tls }
    540        1.1     lukem 
    541  1.61.12.3       tls network_stop_route()
    542  1.61.12.3       tls {
    543        1.1     lukem 	# flush routes
    544        1.1     lukem 	#
    545       1.53      reed 	/sbin/route -qn flush
    546       1.38      tron 
    547        1.1     lukem }
    548        1.1     lukem 
    549       1.47     lukem load_rc_config $name
    550       1.47     lukem load_rc_config_var dhclient dhclient
    551       1.58       roy load_rc_config_var dhcpcd dhcpcd
    552       1.47     lukem load_rc_config_var ipfilter ipfilter
    553        1.1     lukem run_rc_command "$1"
    554