network revision 1.79 1 1.1 lukem #!/bin/sh
2 1.1 lukem #
3 1.79 roy # $NetBSD: network,v 1.79 2020/06/12 11:04:45 roy 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.70 roy network_wait_dad
54 1.75 roy network_start_resolv
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.74 roy if ! 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
174 1.66 uebayasi case $ip6mode in
175 1.66 uebayasi router)
176 1.66 uebayasi echo 'IPv6 mode: router'
177 1.66 uebayasi /sbin/sysctl -qw net.inet6.ip6.forwarding=1
178 1.66 uebayasi
179 1.66 uebayasi # disallow unique-local unicast forwarding without
180 1.66 uebayasi # explicit configuration.
181 1.66 uebayasi if ! checkyesno ip6uniquelocal; then
182 1.66 uebayasi /sbin/route -q add -inet6 fc00:: -prefixlen 7 \
183 1.66 uebayasi ::1 -reject
184 1.66 uebayasi fi
185 1.66 uebayasi ;;
186 1.30 itojun
187 1.66 uebayasi autohost)
188 1.79 roy if ! checkyesno dhcpcd; then
189 1.79 roy warn "rtsol and kernel ra handling have been removed"
190 1.79 roy warn "please configure dhcpcd in its place."
191 1.79 roy fi
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.78 kim # "dhcp" as a special case to invoke dhcpcd, treat "rtsol" as
219 1.78 kim # 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.79 roy /sbin/dhcpcd -n --dhcp \
323 1.66 uebayasi ${dhcpcd_flags} $int
324 1.66 uebayasi fi
325 1.54 apb ;;
326 1.78 kim rtsol)
327 1.78 kim if ! checkyesno dhcpcd; then
328 1.79 roy /sbin/dhcpcd -n --ipv6rs \
329 1.79 roy ${dhcpcd_flags} $int
330 1.78 kim fi
331 1.78 kim ;;
332 1.54 apb *)
333 1.66 uebayasi # Pass args to ifconfig. Note
334 1.66 uebayasi # that args may contain embedded
335 1.66 uebayasi # shell metacharacters, such as
336 1.66 uebayasi # "ssid 'foo;*>bar'". We eval
337 1.66 uebayasi # one more time so that things
338 1.66 uebayasi # like ssid "Columbia University" work.
339 1.54 apb (
340 1.54 apb set -o noglob
341 1.66 uebayasi eval set -- $args
342 1.66 uebayasi #echo >&2 "[$#] [$1] [$2] [$3]"
343 1.66 uebayasi /sbin/ifconfig $int "$@"
344 1.54 apb )
345 1.54 apb ;;
346 1.66 uebayasi esac
347 1.1 lukem done
348 1.66 uebayasi configured_interfaces="$configured_interfaces $int"
349 1.66 uebayasi done
350 1.66 uebayasi echo "."
351 1.64 uebayasi }
352 1.1 lukem
353 1.64 uebayasi network_start_aliases()
354 1.64 uebayasi {
355 1.48 cjs echo -n "Adding interface aliases:"
356 1.48 cjs
357 1.1 lukem # Check if each configured interface xxN has an $ifaliases_xxN variable
358 1.1 lukem # associated, then configure additional IP addresses for that interface.
359 1.1 lukem # The variable contains a list of "address netmask" pairs, with
360 1.1 lukem # "netmask" set to "-" if the interface default netmask is to be used.
361 1.1 lukem #
362 1.54 apb # Note that $ifaliases_xxN works only in certain cases and its
363 1.54 apb # use is not recommended. Use /etc/ifconfig.xxN or multiple
364 1.54 apb # commands in $ifconfig_xxN instead.
365 1.1 lukem #
366 1.48 cjs for int in lo0 $configured_interfaces; do
367 1.20 nisimura eval args=\$ifaliases_$int
368 1.1 lukem if [ -n "$args" ]; then
369 1.1 lukem set -- $args
370 1.1 lukem while [ $# -ge 2 ]; do
371 1.1 lukem addr=$1 ; net=$2 ; shift 2
372 1.1 lukem if [ "$net" = "-" ]; then
373 1.16 jdolecek # for compatibility only, obsolete
374 1.53 reed /sbin/ifconfig $int inet alias $addr
375 1.1 lukem else
376 1.53 reed /sbin/ifconfig $int inet alias $addr \
377 1.1 lukem netmask $net
378 1.1 lukem fi
379 1.48 cjs echo -n " $int:$addr"
380 1.1 lukem done
381 1.1 lukem fi
382 1.1 lukem done
383 1.1 lukem
384 1.1 lukem # /etc/ifaliases, if it exists, contains the names of additional IP
385 1.1 lukem # addresses for each interface. It is formatted as a series of lines
386 1.1 lukem # that contain
387 1.1 lukem # address interface netmask
388 1.1 lukem #
389 1.54 apb # Note that /etc/ifaliases works only in certain cases and its
390 1.54 apb # use is not recommended. Use /etc/ifconfig.xxN or multiple
391 1.54 apb # commands in $ifconfig_xxN instead.
392 1.1 lukem #
393 1.1 lukem if [ -f /etc/ifaliases ]; then
394 1.1 lukem while read addr int net; do
395 1.1 lukem if [ -z "$net" ]; then
396 1.16 jdolecek # for compatibility only, obsolete
397 1.53 reed /sbin/ifconfig $int inet alias $addr
398 1.1 lukem else
399 1.53 reed /sbin/ifconfig $int inet alias $addr netmask $net
400 1.1 lukem fi
401 1.20 nisimura done < /etc/ifaliases
402 1.1 lukem fi
403 1.1 lukem
404 1.56 apb echo "." # for "Adding interface aliases:"
405 1.64 uebayasi }
406 1.56 apb
407 1.64 uebayasi network_start_defaultroute()
408 1.64 uebayasi {
409 1.56 apb # Check $defaultroute, then /etc/mygate, for the name or address
410 1.56 apb # of my IPv4 gateway host. If using a name, that name must be in
411 1.56 apb # /etc/hosts.
412 1.56 apb #
413 1.56 apb if [ -z "$defaultroute" ] && [ -f /etc/mygate ]; then
414 1.71 christos defaultroute=$(kat /etc/mygate)
415 1.56 apb fi
416 1.56 apb if [ -n "$defaultroute" ]; then
417 1.56 apb /sbin/route add default $defaultroute
418 1.56 apb fi
419 1.64 uebayasi }
420 1.56 apb
421 1.64 uebayasi network_start_defaultroute6()
422 1.64 uebayasi {
423 1.56 apb # Check $defaultroute6, then /etc/mygate6, for the name or address
424 1.56 apb # of my IPv6 gateway host. If using a name, that name must be in
425 1.56 apb # /etc/hosts. Note that the gateway host address must be a link-local
426 1.56 apb # address if it is not using an stf* interface.
427 1.56 apb #
428 1.56 apb if [ -z "$defaultroute6" ] && [ -f /etc/mygate6 ]; then
429 1.71 christos defaultroute6=$(kat /etc/mygate6)
430 1.56 apb fi
431 1.56 apb if [ -n "$defaultroute6" ]; then
432 1.56 apb if [ "$ip6mode" = "autohost" ]; then
433 1.56 apb echo
434 1.56 apb warn \
435 1.56 apb "ip6mode is set to 'autohost' and a v6 default route is also set."
436 1.56 apb fi
437 1.56 apb /sbin/route add -inet6 default $defaultroute6
438 1.56 apb fi
439 1.64 uebayasi }
440 1.48 cjs
441 1.70 roy network_wait_dad()
442 1.70 roy {
443 1.77 roy # Wait for the DAD flags to clear from all addresses.
444 1.70 roy if [ -n "$ifconfig_wait_dad_flags" ]; then
445 1.77 roy echo "Waiting for duplicate address detection to finish..."
446 1.70 roy ifconfig $ifconfig_wait_dad_flags
447 1.70 roy fi
448 1.70 roy }
449 1.70 roy
450 1.75 roy network_start_resolv()
451 1.75 roy {
452 1.75 roy resconf=
453 1.75 roy
454 1.75 roy if [ -n "$dns_domain" ]; then
455 1.75 roy resconf="${resconf}domain $dns_domain$nl"
456 1.75 roy fi
457 1.75 roy if [ -n "$dns_search" ]; then
458 1.75 roy resconf="${resconf}search $dns_search$nl"
459 1.75 roy fi
460 1.75 roy for n in $dns_nameservers; do
461 1.75 roy resconf="${resconf}nameserver $n$nl"
462 1.75 roy done
463 1.75 roy if [ -n "$dns_sortlist" ]; then
464 1.75 roy resconf="${resconf}sortlist $dns_sortlist$nl"
465 1.75 roy fi
466 1.75 roy if [ -n "$dns_options" ]; then
467 1.75 roy resconf="${resconf}options $dns_options$nl"
468 1.75 roy fi
469 1.75 roy if [ -n "$resconf" ]; then
470 1.75 roy resconf="# Generated by /etc/rc.d/network$nl$resconf"
471 1.75 roy echo 'Configuring resolv.conf'
472 1.75 roy printf %s "$resconf" | resolvconf -m "${dns_metric:-0}" -a network
473 1.75 roy fi
474 1.75 roy }
475 1.75 roy
476 1.64 uebayasi network_start_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 start
481 1.1 lukem fi
482 1.1 lukem }
483 1.1 lukem
484 1.1 lukem network_stop()
485 1.1 lukem {
486 1.1 lukem echo "Stopping network."
487 1.1 lukem
488 1.64 uebayasi network_stop_local
489 1.75 roy network_stop_resolv
490 1.64 uebayasi network_stop_aliases
491 1.65 uebayasi [ "$net_interfaces" != NO ] &&
492 1.64 uebayasi network_stop_interfaces
493 1.64 uebayasi network_stop_route
494 1.64 uebayasi }
495 1.64 uebayasi
496 1.64 uebayasi network_stop_local()
497 1.64 uebayasi {
498 1.1 lukem # XXX this must die
499 1.1 lukem if [ -s /etc/netstart.local ]; then
500 1.1 lukem sh /etc/netstart.local stop
501 1.1 lukem fi
502 1.64 uebayasi }
503 1.1 lukem
504 1.75 roy network_stop_resolv()
505 1.75 roy {
506 1.75 roy resolvconf -f -d network
507 1.75 roy }
508 1.75 roy
509 1.64 uebayasi network_stop_aliases()
510 1.64 uebayasi {
511 1.1 lukem echo "Deleting aliases."
512 1.1 lukem if [ -f /etc/ifaliases ]; then
513 1.1 lukem while read addr int net; do
514 1.53 reed /sbin/ifconfig $int inet delete $addr
515 1.20 nisimura done < /etc/ifaliases
516 1.1 lukem fi
517 1.1 lukem
518 1.53 reed for int in $(/sbin/ifconfig -lu); do
519 1.20 nisimura eval args=\$ifaliases_$int
520 1.1 lukem if [ -n "$args" ]; then
521 1.1 lukem set -- $args
522 1.1 lukem while [ $# -ge 2 ]; do
523 1.1 lukem addr=$1 ; net=$2 ; shift 2
524 1.53 reed /sbin/ifconfig $int inet delete $addr
525 1.1 lukem done
526 1.1 lukem fi
527 1.1 lukem done
528 1.64 uebayasi }
529 1.1 lukem
530 1.64 uebayasi network_stop_interfaces()
531 1.64 uebayasi {
532 1.1 lukem # down interfaces
533 1.1 lukem #
534 1.1 lukem echo -n 'Downing network interfaces:'
535 1.66 uebayasi if checkyesno auto_ifconfig; then
536 1.66 uebayasi tmp=$(/sbin/ifconfig -l)
537 1.66 uebayasi else
538 1.66 uebayasi tmp="$net_interfaces"
539 1.66 uebayasi fi
540 1.66 uebayasi for int in $tmp; do
541 1.66 uebayasi eval args=\$ifconfig_$int
542 1.66 uebayasi if [ -n "$args" ] || [ -f /etc/ifconfig.$int ]; then
543 1.66 uebayasi echo -n " $int"
544 1.66 uebayasi if [ -f /var/run/dhcpcd-$int.pid ]; then
545 1.66 uebayasi /sbin/dhcpcd -k $int 2> /dev/null
546 1.66 uebayasi fi
547 1.66 uebayasi /sbin/ifconfig $int down
548 1.66 uebayasi if /sbin/ifconfig $int destroy 2>/dev/null && \
549 1.66 uebayasi checkyesno ipfilter; then
550 1.66 uebayasi # resync ipf(4)
551 1.66 uebayasi /sbin/ipf -y >/dev/null
552 1.66 uebayasi fi
553 1.1 lukem fi
554 1.66 uebayasi done
555 1.66 uebayasi echo "."
556 1.64 uebayasi }
557 1.1 lukem
558 1.64 uebayasi network_stop_route()
559 1.64 uebayasi {
560 1.1 lukem # flush routes
561 1.1 lukem #
562 1.76 mrg if checkyesno flushroutes; then
563 1.76 mrg /sbin/route -qn flush
564 1.76 mrg fi
565 1.1 lukem }
566 1.1 lukem
567 1.47 lukem load_rc_config $name
568 1.58 roy load_rc_config_var dhcpcd dhcpcd
569 1.47 lukem load_rc_config_var ipfilter ipfilter
570 1.1 lukem run_rc_command "$1"
571