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