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