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