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