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