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