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