network revision 1.77
11.1Slukem#!/bin/sh 21.1Slukem# 31.77Sroy# $NetBSD: network,v 1.77 2020/02/22 11:52:45 roy Exp $ 41.1Slukem# 51.1Slukem 61.1Slukem# PROVIDE: network 71.19Slukem# REQUIRE: ipfilter ipsec mountcritlocal root tty sysctl 81.34Sthorpej# BEFORE: NETWORKING 91.1Slukem 101.45Smycroft$_rc_subr_loaded . /etc/rc.subr 111.1Slukem 121.1Slukemname="network" 131.1Slukemstart_cmd="network_start" 141.14Slukemstop_cmd="network_stop" 151.1Slukem 161.54Sapbnl=' 171.54Sapb' # a newline 181.54Sapb 191.65Suebayasiintmissing() 201.65Suebayasi{ 211.63Schristos local int="$1" 221.63Schristos shift 231.65Suebayasi for i; do 241.63Schristos if [ "$int" = "$i" ]; then 251.63Schristos return 1 261.63Schristos fi 271.63Schristos done 281.63Schristos return 0 291.63Schristos} 301.63Schristos 311.65Suebayasihave_inet6() 321.65Suebayasi{ 331.65Suebayasi /sbin/ifconfig lo0 inet6 >/dev/null 2>&1 341.65Suebayasi} 351.65Suebayasi 361.1Slukemnetwork_start() 371.1Slukem{ 381.1Slukem # set hostname, turn on network 391.1Slukem # 401.1Slukem echo "Starting network." 411.1Slukem 421.64Suebayasi network_start_hostname 431.64Suebayasi network_start_domainname 441.64Suebayasi network_start_loopback 451.65Suebayasi have_inet6 && 461.64Suebayasi network_start_ipv6_route 471.65Suebayasi [ "$net_interfaces" != NO ] && 481.64Suebayasi network_start_interfaces 491.64Suebayasi network_start_aliases 501.64Suebayasi network_start_defaultroute 511.64Suebayasi network_start_defaultroute6 521.65Suebayasi have_inet6 && 531.64Suebayasi network_start_ipv6_autoconf 541.70Sroy network_wait_dad 551.75Sroy network_start_resolv 561.64Suebayasi network_start_local 571.64Suebayasi} 581.64Suebayasi 591.64Suebayasinetwork_start_hostname() 601.64Suebayasi{ 611.1Slukem # If $hostname is set, use it for my Internet name, 621.1Slukem # otherwise use /etc/myname 631.1Slukem # 641.20Snisimura if [ -z "$hostname" ] && [ -f /etc/myname ]; then 651.71Schristos hostname=$(kat /etc/myname) 661.1Slukem fi 671.1Slukem if [ -n "$hostname" ]; then 681.1Slukem echo "Hostname: $hostname" 691.1Slukem hostname $hostname 701.1Slukem else 711.8Sthorpej # Don't warn about it if we're going to run 721.8Sthorpej # DHCP later, as we will probably get the 731.8Sthorpej # hostname at that time. 741.8Sthorpej # 751.74Sroy if ! checkyesno dhcpcd && \ 761.58Sroy [ -z "$(hostname)" ] 771.58Sroy then 781.8Sthorpej warn "\$hostname not set." 791.8Sthorpej fi 801.1Slukem fi 811.64Suebayasi} 821.1Slukem 831.64Suebayasinetwork_start_domainname() 841.64Suebayasi{ 851.1Slukem # Check $domainname first, then /etc/defaultdomain, 861.1Slukem # for NIS/YP domain name 871.1Slukem # 881.20Snisimura if [ -z "$domainname" ] && [ -f /etc/defaultdomain ]; then 891.71Schristos domainname=$(kat /etc/defaultdomain) 901.1Slukem fi 911.1Slukem if [ -n "$domainname" ]; then 921.1Slukem echo "NIS domainname: $domainname" 931.1Slukem domainname $domainname 941.1Slukem fi 951.1Slukem 961.1Slukem # Flush all routes just to make sure it is clean 971.1Slukem if checkyesno flushroutes; then 981.53Sreed /sbin/route -qn flush 991.1Slukem fi 1001.64Suebayasi} 1011.1Slukem 1021.64Suebayasinetwork_start_loopback() 1031.64Suebayasi{ 1041.1Slukem # Set the address for the first loopback interface, so that the 1051.1Slukem # auto-route from a newly configured interface's address to lo0 1061.1Slukem # works correctly. 1071.1Slukem # 1081.32Slukem # NOTE: obscure networking problems will occur if lo0 isn't configured. 1091.1Slukem # 1101.53Sreed /sbin/ifconfig lo0 inet 127.0.0.1 1111.10Sitojun 1121.31Sitojun # According to RFC1122, 127.0.0.0/8 must not leave the node. 1131.10Sitojun # 1141.53Sreed /sbin/route -q add -inet 127.0.0.0 -netmask 0xff000000 127.0.0.1 -reject 1151.64Suebayasi} 1161.1Slukem 1171.64Suebayasinetwork_start_ipv6_route() 1181.64Suebayasi{ 1191.30Sitojun # IPv6 routing setups, and host/router mode selection. 1201.30Sitojun # 1211.66Suebayasi # We have IPv6 support in kernel. 1221.30Sitojun 1231.66Suebayasi # disallow link-local unicast dest without outgoing scope 1241.66Suebayasi # identifiers. 1251.66Suebayasi # 1261.66Suebayasi /sbin/route -q add -inet6 fe80:: -prefixlen 10 ::1 -reject 1271.30Sitojun 1281.66Suebayasi # disallow the use of the RFC3849 documentation address 1291.66Suebayasi # 1301.66Suebayasi /sbin/route -q add -inet6 2001:db8:: -prefixlen 32 ::1 -reject 1311.50Srpaulo 1321.66Suebayasi # IPv6 site-local scoped address prefix (fec0::/10) 1331.66Suebayasi # has been deprecated by RFC3879. 1341.66Suebayasi # 1351.66Suebayasi if [ -n "$ip6sitelocal" ]; then 1361.66Suebayasi warn "\$ip6sitelocal is no longer valid" 1371.66Suebayasi fi 1381.30Sitojun 1391.66Suebayasi # disallow "internal" addresses to appear on the wire. 1401.66Suebayasi # 1411.66Suebayasi /sbin/route -q add -inet6 ::ffff:0.0.0.0 -prefixlen 96 ::1 -reject 1421.30Sitojun 1431.66Suebayasi # disallow packets to malicious IPv4 compatible prefix 1441.66Suebayasi # 1451.66Suebayasi /sbin/route -q add -inet6 ::224.0.0.0 -prefixlen 100 ::1 -reject 1461.66Suebayasi /sbin/route -q add -inet6 ::127.0.0.0 -prefixlen 104 ::1 -reject 1471.66Suebayasi /sbin/route -q add -inet6 ::0.0.0.0 -prefixlen 104 ::1 -reject 1481.66Suebayasi /sbin/route -q add -inet6 ::255.0.0.0 -prefixlen 104 ::1 -reject 1491.66Suebayasi 1501.66Suebayasi # disallow packets to malicious 6to4 prefix 1511.66Suebayasi # 1521.66Suebayasi /sbin/route -q add -inet6 2002:e000:: -prefixlen 20 ::1 -reject 1531.66Suebayasi /sbin/route -q add -inet6 2002:7f00:: -prefixlen 24 ::1 -reject 1541.66Suebayasi /sbin/route -q add -inet6 2002:0000:: -prefixlen 24 ::1 -reject 1551.66Suebayasi /sbin/route -q add -inet6 2002:ff00:: -prefixlen 24 ::1 -reject 1561.66Suebayasi 1571.66Suebayasi # Completely disallow packets to IPv4 compatible prefix. 1581.66Suebayasi # This may conflict with RFC1933 under following circumstances: 1591.66Suebayasi # (1) An IPv6-only KAME node tries to originate packets to IPv4 1601.66Suebayasi # compatible destination. The KAME node has no IPv4 1611.66Suebayasi # compatible support. Under RFC1933, it should transmit 1621.66Suebayasi # native IPv6 packets toward IPv4 compatible destination, 1631.66Suebayasi # hoping it would reach a router that forwards the packet 1641.66Suebayasi # toward auto-tunnel interface. 1651.66Suebayasi # (2) An IPv6-only node originates a packet to IPv4 compatible 1661.66Suebayasi # destination. A KAME node is acting as an IPv6 router, and 1671.66Suebayasi # asked to forward it. 1681.66Suebayasi # Due to rare use of IPv4 compatible address, and security 1691.66Suebayasi # issues with it, we disable it by default. 1701.66Suebayasi # 1711.66Suebayasi /sbin/route -q add -inet6 ::0.0.0.0 -prefixlen 96 ::1 -reject 1721.66Suebayasi 1731.66Suebayasi /sbin/sysctl -qw net.inet6.ip6.forwarding=0 1741.66Suebayasi /sbin/sysctl -qw net.inet6.ip6.accept_rtadv=0 1751.66Suebayasi 1761.66Suebayasi case $ip6mode in 1771.66Suebayasi router) 1781.66Suebayasi echo 'IPv6 mode: router' 1791.66Suebayasi /sbin/sysctl -qw net.inet6.ip6.forwarding=1 1801.66Suebayasi 1811.66Suebayasi # disallow unique-local unicast forwarding without 1821.66Suebayasi # explicit configuration. 1831.66Suebayasi if ! checkyesno ip6uniquelocal; then 1841.66Suebayasi /sbin/route -q add -inet6 fc00:: -prefixlen 7 \ 1851.66Suebayasi ::1 -reject 1861.66Suebayasi fi 1871.66Suebayasi ;; 1881.30Sitojun 1891.66Suebayasi autohost) 1901.66Suebayasi echo 'IPv6 mode: autoconfigured host' 1911.66Suebayasi /sbin/sysctl -qw net.inet6.ip6.accept_rtadv=1 1921.66Suebayasi ;; 1931.30Sitojun 1941.66Suebayasi host) 1951.66Suebayasi echo 'IPv6 mode: host' 1961.66Suebayasi ;; 1971.30Sitojun 1981.66Suebayasi *) warn "invalid \$ip6mode value "\"$ip6mode\" 1991.66Suebayasi ;; 2001.30Sitojun 2011.66Suebayasi esac 2021.64Suebayasi} 2031.30Sitojun 2041.64Suebayasinetwork_start_interfaces() 2051.64Suebayasi{ 2061.1Slukem # Configure all of the network interfaces listed in $net_interfaces; 2071.1Slukem # if $auto_ifconfig is YES, grab all interfaces from ifconfig. 2081.1Slukem # In the following, "xxN" stands in for interface names, like "le0". 2091.54Sapb # 2101.54Sapb # For any interfaces that has an $ifconfig_xxN variable 2111.54Sapb # associated, we break it into lines using ';' as a separator, 2121.54Sapb # then process it just like the contents of an /etc/ifconfig.xxN 2131.54Sapb # file. 2141.54Sapb # 2151.54Sapb # For each line from the $ifconfig_xxN variable or the 2161.54Sapb # /etc/ifconfig.xxN file, we ignore comments and blank lines, 2171.54Sapb # treat lines beginning with "!" as commands to execute, treat 2181.54Sapb # "dhcp" as a special case to invoke dhcpcd, and for any other 2191.54Sapb # line we run "ifconfig xxN", using each line of the file as the 2201.54Sapb # arguments for a separate "ifconfig" invocation. 2211.1Slukem # 2221.1Slukem # In order to configure an interface reasonably, you at the very least 2231.1Slukem # need to specify "[addr_family] [hostname]" (e.g "inet my.domain.org"), 2241.1Slukem # and probably a netmask (as in "netmask 0xffffffe0"). You will 2251.1Slukem # frequently need to specify a media type, as in "media UTP", for 2261.1Slukem # interface cards with multiple media connections that do not 2271.1Slukem # autoconfigure. See the ifconfig manual page for details. 2281.1Slukem # 2291.1Slukem # Note that /etc/ifconfig.xxN takes multiple lines. The following 2301.1Slukem # configuration is possible: 2311.1Slukem # inet 10.1.1.1 netmask 0xffffff00 2321.1Slukem # inet 10.1.1.2 netmask 0xffffff00 alias 2331.50Srpaulo # inet6 2001:db8::1 prefixlen 64 alias 2341.1Slukem # 2351.29Sitojun # You can put shell script fragment into /etc/ifconfig.xxN by 2361.29Sitojun # starting a line with "!". Refer to ifconfig.if(5) for details. 2371.29Sitojun # 2381.66Suebayasi ifaces="$(/sbin/ifconfig -l)" 2391.66Suebayasi if checkyesno auto_ifconfig; then 2401.66Suebayasi tmp="$ifaces" 2411.66Suebayasi for cloner in $(/sbin/ifconfig -C); do 2421.66Suebayasi for int in /etc/ifconfig.${cloner}[0-9]*; do 2431.66Suebayasi [ ! -f $int ] && break 2441.66Suebayasi tmp="$tmp ${int##*.}" 2451.15Sthorpej done 2461.66Suebayasi done 2471.66Suebayasi else 2481.66Suebayasi tmp="$net_interfaces" 2491.66Suebayasi fi 2501.66Suebayasi echo -n 'Configuring network interfaces:' 2511.66Suebayasi for int in $tmp; do 2521.66Suebayasi eval argslist=\$ifconfig_$int 2531.66Suebayasi 2541.66Suebayasi # Skip interfaces that do not have explicit 2551.66Suebayasi # configuration information. If auto_ifconfig is 2561.66Suebayasi # false then also warn about such interfaces. 2571.66Suebayasi # 2581.66Suebayasi if [ -z "$argslist" ] && ! [ -f /etc/ifconfig.$int ] 2591.66Suebayasi then 2601.66Suebayasi if ! checkyesno auto_ifconfig; then 2611.66Suebayasi echo 2621.66Suebayasi warn \ 2631.66Suebayasi "/etc/ifconfig.$int missing and ifconfig_$int not set;" 2641.66Suebayasi warn "interface $int not configured." 2651.66Suebayasi fi 2661.66Suebayasi continue 2671.1Slukem fi 2681.54Sapb 2691.66Suebayasi echo -n " $int" 2701.54Sapb 2711.66Suebayasi # Create the interface if necessary. 2721.66Suebayasi # If the interface did not exist before, 2731.66Suebayasi # then also resync ipf(4). 2741.66Suebayasi # 2751.66Suebayasi if intmissing $int $ifaces; then 2761.66Suebayasi if /sbin/ifconfig $int create && \ 2771.66Suebayasi checkyesno ipfilter; then 2781.66Suebayasi /sbin/ipf -y >/dev/null 2791.54Sapb fi 2801.66Suebayasi fi 2811.54Sapb 2821.66Suebayasi # If $ifconfig_xxN is empty, then use 2831.66Suebayasi # /etc/ifconfig.xxN, which we know exists due to 2841.66Suebayasi # an earlier test. 2851.66Suebayasi # 2861.66Suebayasi # If $ifconfig_xxN is non-empty and contains a 2871.66Suebayasi # newline, then just use it as is. (This allows 2881.66Suebayasi # semicolons through unmolested.) 2891.66Suebayasi # 2901.66Suebayasi # If $ifconfig_xxN is non-empty and does not 2911.66Suebayasi # contain a newline, then convert all semicolons 2921.66Suebayasi # to newlines. 2931.66Suebayasi # 2941.66Suebayasi case "$argslist" in 2951.66Suebayasi '') 2961.66Suebayasi cat /etc/ifconfig.$int 2971.66Suebayasi ;; 2981.66Suebayasi *"${nl}"*) 2991.66Suebayasi echo "$argslist" 3001.66Suebayasi ;; 3011.66Suebayasi *) 3021.66Suebayasi ( 3031.66Suebayasi set -o noglob 3041.66Suebayasi IFS=';'; set -- $argslist 3051.66Suebayasi #echo >&2 "[$#] [$1] [$2] [$3] [$4]" 3061.66Suebayasi IFS="$nl"; echo "$*" 3071.66Suebayasi ) 3081.66Suebayasi ;; 3091.66Suebayasi esac | 3101.66Suebayasi collapse_backslash_newline | 3111.66Suebayasi while read -r args; do 3121.66Suebayasi case "$args" in 3131.66Suebayasi ''|"#"*|create) 3141.66Suebayasi ;; 3151.66Suebayasi "!"*) 3161.66Suebayasi # Run arbitrary command in a subshell. 3171.66Suebayasi ( eval "${args#*!}" ) 3181.54Sapb ;; 3191.66Suebayasi dhcp) 3201.66Suebayasi if ! checkyesno dhcpcd; then 3211.66Suebayasi /sbin/dhcpcd -n \ 3221.66Suebayasi ${dhcpcd_flags} $int 3231.66Suebayasi fi 3241.54Sapb ;; 3251.54Sapb *) 3261.66Suebayasi # Pass args to ifconfig. Note 3271.66Suebayasi # that args may contain embedded 3281.66Suebayasi # shell metacharacters, such as 3291.66Suebayasi # "ssid 'foo;*>bar'". We eval 3301.66Suebayasi # one more time so that things 3311.66Suebayasi # like ssid "Columbia University" work. 3321.54Sapb ( 3331.54Sapb set -o noglob 3341.66Suebayasi eval set -- $args 3351.66Suebayasi #echo >&2 "[$#] [$1] [$2] [$3]" 3361.66Suebayasi /sbin/ifconfig $int "$@" 3371.54Sapb ) 3381.54Sapb ;; 3391.66Suebayasi esac 3401.1Slukem done 3411.66Suebayasi configured_interfaces="$configured_interfaces $int" 3421.66Suebayasi done 3431.66Suebayasi echo "." 3441.64Suebayasi} 3451.1Slukem 3461.64Suebayasinetwork_start_aliases() 3471.64Suebayasi{ 3481.48Scjs echo -n "Adding interface aliases:" 3491.48Scjs 3501.1Slukem # Check if each configured interface xxN has an $ifaliases_xxN variable 3511.1Slukem # associated, then configure additional IP addresses for that interface. 3521.1Slukem # The variable contains a list of "address netmask" pairs, with 3531.1Slukem # "netmask" set to "-" if the interface default netmask is to be used. 3541.1Slukem # 3551.54Sapb # Note that $ifaliases_xxN works only in certain cases and its 3561.54Sapb # use is not recommended. Use /etc/ifconfig.xxN or multiple 3571.54Sapb # commands in $ifconfig_xxN instead. 3581.1Slukem # 3591.48Scjs for int in lo0 $configured_interfaces; do 3601.20Snisimura eval args=\$ifaliases_$int 3611.1Slukem if [ -n "$args" ]; then 3621.1Slukem set -- $args 3631.1Slukem while [ $# -ge 2 ]; do 3641.1Slukem addr=$1 ; net=$2 ; shift 2 3651.1Slukem if [ "$net" = "-" ]; then 3661.16Sjdolecek # for compatibility only, obsolete 3671.53Sreed /sbin/ifconfig $int inet alias $addr 3681.1Slukem else 3691.53Sreed /sbin/ifconfig $int inet alias $addr \ 3701.1Slukem netmask $net 3711.1Slukem fi 3721.48Scjs echo -n " $int:$addr" 3731.1Slukem done 3741.1Slukem fi 3751.1Slukem done 3761.1Slukem 3771.1Slukem # /etc/ifaliases, if it exists, contains the names of additional IP 3781.1Slukem # addresses for each interface. It is formatted as a series of lines 3791.1Slukem # that contain 3801.1Slukem # address interface netmask 3811.1Slukem # 3821.54Sapb # Note that /etc/ifaliases works only in certain cases and its 3831.54Sapb # use is not recommended. Use /etc/ifconfig.xxN or multiple 3841.54Sapb # commands in $ifconfig_xxN instead. 3851.1Slukem # 3861.1Slukem if [ -f /etc/ifaliases ]; then 3871.1Slukem while read addr int net; do 3881.1Slukem if [ -z "$net" ]; then 3891.16Sjdolecek # for compatibility only, obsolete 3901.53Sreed /sbin/ifconfig $int inet alias $addr 3911.1Slukem else 3921.53Sreed /sbin/ifconfig $int inet alias $addr netmask $net 3931.1Slukem fi 3941.20Snisimura done < /etc/ifaliases 3951.1Slukem fi 3961.1Slukem 3971.56Sapb echo "." # for "Adding interface aliases:" 3981.64Suebayasi} 3991.56Sapb 4001.64Suebayasinetwork_start_defaultroute() 4011.64Suebayasi{ 4021.56Sapb # Check $defaultroute, then /etc/mygate, for the name or address 4031.56Sapb # of my IPv4 gateway host. If using a name, that name must be in 4041.56Sapb # /etc/hosts. 4051.56Sapb # 4061.56Sapb if [ -z "$defaultroute" ] && [ -f /etc/mygate ]; then 4071.71Schristos defaultroute=$(kat /etc/mygate) 4081.56Sapb fi 4091.56Sapb if [ -n "$defaultroute" ]; then 4101.56Sapb /sbin/route add default $defaultroute 4111.56Sapb fi 4121.64Suebayasi} 4131.56Sapb 4141.64Suebayasinetwork_start_defaultroute6() 4151.64Suebayasi{ 4161.56Sapb # Check $defaultroute6, then /etc/mygate6, for the name or address 4171.56Sapb # of my IPv6 gateway host. If using a name, that name must be in 4181.56Sapb # /etc/hosts. Note that the gateway host address must be a link-local 4191.56Sapb # address if it is not using an stf* interface. 4201.56Sapb # 4211.56Sapb if [ -z "$defaultroute6" ] && [ -f /etc/mygate6 ]; then 4221.71Schristos defaultroute6=$(kat /etc/mygate6) 4231.56Sapb fi 4241.56Sapb if [ -n "$defaultroute6" ]; then 4251.56Sapb if [ "$ip6mode" = "autohost" ]; then 4261.56Sapb echo 4271.56Sapb warn \ 4281.56Sapb "ip6mode is set to 'autohost' and a v6 default route is also set." 4291.56Sapb fi 4301.56Sapb /sbin/route add -inet6 default $defaultroute6 4311.56Sapb fi 4321.64Suebayasi} 4331.48Scjs 4341.64Suebayasinetwork_start_ipv6_autoconf() 4351.64Suebayasi{ 4361.30Sitojun # IPv6 interface autoconfiguration. 4371.67Sroy 4381.67Sroy # dhcpcd will ensure DAD completes before forking 4391.73Skre if checkyesnox rtsol && ! checkyesno dhcpcd; then 4401.66Suebayasi if [ "$ip6mode" = "autohost" ]; then 4411.66Suebayasi echo 4421.67Sroy warn "rtsol has been removed, " \ 4431.67Sroy "please configure dhcpcd in its place." 4441.66Suebayasi fi 4451.66Suebayasi fi 4461.64Suebayasi} 4471.42Schristos 4481.70Sroynetwork_wait_dad() 4491.70Sroy{ 4501.77Sroy # Wait for the DAD flags to clear from all addresses. 4511.70Sroy if [ -n "$ifconfig_wait_dad_flags" ]; then 4521.77Sroy echo "Waiting for duplicate address detection to finish..." 4531.70Sroy ifconfig $ifconfig_wait_dad_flags 4541.70Sroy fi 4551.70Sroy} 4561.70Sroy 4571.75Sroynetwork_start_resolv() 4581.75Sroy{ 4591.75Sroy resconf= 4601.75Sroy 4611.75Sroy if [ -n "$dns_domain" ]; then 4621.75Sroy resconf="${resconf}domain $dns_domain$nl" 4631.75Sroy fi 4641.75Sroy if [ -n "$dns_search" ]; then 4651.75Sroy resconf="${resconf}search $dns_search$nl" 4661.75Sroy fi 4671.75Sroy for n in $dns_nameservers; do 4681.75Sroy resconf="${resconf}nameserver $n$nl" 4691.75Sroy done 4701.75Sroy if [ -n "$dns_sortlist" ]; then 4711.75Sroy resconf="${resconf}sortlist $dns_sortlist$nl" 4721.75Sroy fi 4731.75Sroy if [ -n "$dns_options" ]; then 4741.75Sroy resconf="${resconf}options $dns_options$nl" 4751.75Sroy fi 4761.75Sroy if [ -n "$resconf" ]; then 4771.75Sroy resconf="# Generated by /etc/rc.d/network$nl$resconf" 4781.75Sroy echo 'Configuring resolv.conf' 4791.75Sroy printf %s "$resconf" | resolvconf -m "${dns_metric:-0}" -a network 4801.75Sroy fi 4811.75Sroy} 4821.75Sroy 4831.64Suebayasinetwork_start_local() 4841.64Suebayasi{ 4851.1Slukem # XXX this must die 4861.1Slukem if [ -s /etc/netstart.local ]; then 4871.1Slukem sh /etc/netstart.local start 4881.1Slukem fi 4891.1Slukem} 4901.1Slukem 4911.1Slukemnetwork_stop() 4921.1Slukem{ 4931.1Slukem echo "Stopping network." 4941.1Slukem 4951.64Suebayasi network_stop_local 4961.75Sroy network_stop_resolv 4971.64Suebayasi network_stop_aliases 4981.65Suebayasi [ "$net_interfaces" != NO ] && 4991.64Suebayasi network_stop_interfaces 5001.64Suebayasi network_stop_route 5011.64Suebayasi} 5021.64Suebayasi 5031.64Suebayasinetwork_stop_local() 5041.64Suebayasi{ 5051.1Slukem # XXX this must die 5061.1Slukem if [ -s /etc/netstart.local ]; then 5071.1Slukem sh /etc/netstart.local stop 5081.1Slukem fi 5091.64Suebayasi} 5101.1Slukem 5111.75Sroynetwork_stop_resolv() 5121.75Sroy{ 5131.75Sroy resolvconf -f -d network 5141.75Sroy} 5151.75Sroy 5161.64Suebayasinetwork_stop_aliases() 5171.64Suebayasi{ 5181.1Slukem echo "Deleting aliases." 5191.1Slukem if [ -f /etc/ifaliases ]; then 5201.1Slukem while read addr int net; do 5211.53Sreed /sbin/ifconfig $int inet delete $addr 5221.20Snisimura done < /etc/ifaliases 5231.1Slukem fi 5241.1Slukem 5251.53Sreed for int in $(/sbin/ifconfig -lu); do 5261.20Snisimura eval args=\$ifaliases_$int 5271.1Slukem if [ -n "$args" ]; then 5281.1Slukem set -- $args 5291.1Slukem while [ $# -ge 2 ]; do 5301.1Slukem addr=$1 ; net=$2 ; shift 2 5311.53Sreed /sbin/ifconfig $int inet delete $addr 5321.1Slukem done 5331.1Slukem fi 5341.1Slukem done 5351.64Suebayasi} 5361.1Slukem 5371.64Suebayasinetwork_stop_interfaces() 5381.64Suebayasi{ 5391.1Slukem # down interfaces 5401.1Slukem # 5411.1Slukem echo -n 'Downing network interfaces:' 5421.66Suebayasi if checkyesno auto_ifconfig; then 5431.66Suebayasi tmp=$(/sbin/ifconfig -l) 5441.66Suebayasi else 5451.66Suebayasi tmp="$net_interfaces" 5461.66Suebayasi fi 5471.66Suebayasi for int in $tmp; do 5481.66Suebayasi eval args=\$ifconfig_$int 5491.66Suebayasi if [ -n "$args" ] || [ -f /etc/ifconfig.$int ]; then 5501.66Suebayasi echo -n " $int" 5511.66Suebayasi if [ -f /var/run/dhcpcd-$int.pid ]; then 5521.66Suebayasi /sbin/dhcpcd -k $int 2> /dev/null 5531.66Suebayasi fi 5541.66Suebayasi /sbin/ifconfig $int down 5551.66Suebayasi if /sbin/ifconfig $int destroy 2>/dev/null && \ 5561.66Suebayasi checkyesno ipfilter; then 5571.66Suebayasi # resync ipf(4) 5581.66Suebayasi /sbin/ipf -y >/dev/null 5591.66Suebayasi fi 5601.1Slukem fi 5611.66Suebayasi done 5621.66Suebayasi echo "." 5631.64Suebayasi} 5641.1Slukem 5651.64Suebayasinetwork_stop_route() 5661.64Suebayasi{ 5671.1Slukem # flush routes 5681.1Slukem # 5691.76Smrg if checkyesno flushroutes; then 5701.76Smrg /sbin/route -qn flush 5711.76Smrg fi 5721.1Slukem} 5731.1Slukem 5741.47Slukemload_rc_config $name 5751.58Sroyload_rc_config_var dhcpcd dhcpcd 5761.47Slukemload_rc_config_var ipfilter ipfilter 5771.1Slukemrun_rc_command "$1" 578