5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
23 # Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
24 # Copyright 2012 Milan Jurik. All rights reserved.
26 # Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T.
27 # All rights reserved.
30 .
/lib
/svc
/share
/smf_include.sh
31 .
/lib
/svc
/share
/net_include.sh
34 # In a shared-IP zone we need this service to be up, but all of the work
35 # it tries to do is irrelevant (and will actually lead to the service
36 # failing if we try to do it), so just bail out.
37 # In the global zone and exclusive-IP zones we proceed.
39 smf_configure_ip ||
exit $SMF_EXIT_OK
42 # Make sure that the libraries essential to this stage of booting can be found.
43 LD_LIBRARY_PATH
=/lib
; export LD_LIBRARY_PATH
47 if smf_is_globalzone
; then
48 net_reconfigure ||
exit $SMF_EXIT_ERR_CONFIG
50 # Update PVID on interfaces configured with VLAN 1
54 # Upgrade handling. The upgrade file consists of a series of dladm(1M)
55 # commands. Note that after we are done, we cannot rename the upgrade
56 # script file as the file system is still read-only at this point.
57 # Defer this to the manifest-import service.
59 upgrade_script
=/var
/svc
/profile
/upgrade_datalink
60 if [ -f "${upgrade_script}" ]; then
65 # Upgrade handling for ibd:
66 # After we are done with the upgrade handling, we can not set the
67 # ibd/ibd_upgraded property to "true" as the file system is
68 # read-only at this point. It will be done later by ibd-post-upgrade
71 if [ -x /sbin
/ibd_upgrade
]; then
72 ibd_upgraded
=`/bin/svcprop -c -p ibd/ibd_upgraded \
73 $SMF_FMRI 2> /dev/null`
74 if [ "$ibd_upgraded" != "true" ]; then
80 # Bring up simnets, link aggregations and initialize security objects.
81 # Note that link property initialization is deferred until after
82 # IP interfaces are plumbed to ensure that the links will not
83 # be unloaded (and the property settings lost). We should bring
84 # up simnets prior to VLANs/Aggrs to enable creation of VLANs/Aggrs
91 /sbin
/dladm init-secobj
97 # Create flows via flowadm.
99 /sbin
/flowadm init-flow
103 # If the system was net booted by DHCP, hand DHCP management off to the
104 # DHCP agent (ifconfig communicates to the DHCP agent through the
105 # loopback interface).
107 if [ -n "$_INIT_NET_IF" -a "$_INIT_NET_STRATEGY" = "dhcp" ]; then
112 # The network initialization is done early to support diskless and
113 # dataless configurations. For IPv4 interfaces that were configured by
114 # the kernel (e.g. those on diskless machines) and not configured by
115 # DHCP, reset the netmask using the local "/etc/netmasks" file if one
116 # exists, and then reset the broadcast address based on the netmask.
118 /sbin
/ifconfig
-auD4 netmask
+ broadcast
+
123 # Is this a persistent IP tunnel link?
124 /sbin
/dladm show-iptun
-P $intf > /dev
/null
2>&1
125 if [ $?
-eq 0 ]; then
128 # Is this an implicit IP tunnel (i.e., ip.tun0)
133 if [ $# -eq 2 -a \
( "$1" = "ip" -o "$1" = "ip6" \
) ]; then
135 # It looks like one, but another type of link might be
136 # using a name that looks like an implicit IP tunnel.
137 # If dladm show-link -P finds it, then it's not an IP
140 /sbin
/dladm show-link
-Pp $intf > /dev
/null
2>&1
141 if [ $?
-eq 0 ]; then
151 # All the IPv4 and IPv6 interfaces are plumbed before doing any
152 # interface configuration. This prevents errors from plumb failures
153 # getting mixed in with the configured interface lists that the script
158 # First deal with /etc/hostname
160 # Get the list of IPv4 interfaces to configure by breaking
161 # /etc/hostname.* into separate args by using "." as a shell separator
164 interface_names
="`echo /etc/hostname.*[0-9] 2>/dev/null`"
165 if [ "$interface_names" != "/etc/hostname.*[0-9]" ]; then
168 set -- $interface_names
170 while [ $# -ge 2 ]; do
173 while [ $# -gt 1 -a "$2" != "/etc/hostname" ]; do
174 intf_name
="$intf_name.$2"
179 # skip IP tunnel interfaces plumbed by net-iptun.
180 if is_iptun
$intf_name; then
184 read one rest
< /etc
/hostname.
$intf_name
185 if [ "$one" = ipmp
]; then
186 ipmp_list
="$ipmp_list $intf_name"
188 inet_list
="$inet_list $intf_name"
194 # Get the list of IPv6 interfaces to configure by breaking
195 # /etc/hostname6.* into separate args by using "." as a shell separator
198 interface_names
="`echo /etc/hostname6.*[0-9] 2>/dev/null`"
199 if [ "$interface_names" != "/etc/hostname6.*[0-9]" ]; then
202 set -- $interface_names
204 while [ $# -ge 2 ]; do
207 while [ $# -gt 1 -a "$2" != "/etc/hostname6" ]; do
208 intf_name
="$intf_name.$2"
213 # skip IP tunnel interfaces plumbed by net-iptun.
214 if is_iptun
$intf_name; then
218 read one rest
< /etc
/hostname6.
$intf_name
219 if [ "$one" = ipmp
]; then
220 ipmp6_list
="$ipmp6_list $intf_name"
222 inet6_list
="$inet6_list $intf_name"
228 # Create all of the IPv4 IPMP interfaces.
230 if [ -n "$ipmp_list" ]; then
232 while [ $# -gt 0 ]; do
233 if /sbin
/ifconfig
$1 ipmp
; then
234 ipmp_created
="$ipmp_created $1"
236 ipmp_failed
="$ipmp_failed $1"
240 [ -n "$ipmp_failed" ] && warn_failed_ifs
"create IPv4 IPMP" \
245 # Step through the IPv4 interface list and try to plumb every interface.
246 # Generate list of plumbed and failed IPv4 interfaces.
248 if [ -n "$inet_list" ]; then
250 while [ $# -gt 0 ]; do
251 /sbin
/ifconfig
$1 plumb
252 if /sbin
/ifconfig
$1 inet
>/dev
/null
2>&1; then
253 inet_plumbed
="$inet_plumbed $1"
255 inet_failed
="$inet_failed $1"
259 [ -n "$inet_failed" ] && warn_failed_ifs
"plumb IPv4" "$inet_failed"
262 # Run autoconf to connect to a WLAN if the interface is a wireless one
263 if [ -x /sbin
/wificonfig
-a -n "$inet_plumbed" ]; then
265 while [ $# -gt 0 ]; do
266 if [ -r /dev
/wifi
/$1 ]; then
267 /sbin
/wificonfig
-i $1 startconf
>/dev
/null
274 # Step through the IPv6 interface list and plumb every interface.
275 # Generate list of plumbed and failed IPv6 interfaces. Each plumbed
276 # interface will be brought up later, after processing any contents of
277 # the /etc/hostname6.* file.
279 if [ -n "$inet6_list" ]; then
281 while [ $# -gt 0 ]; do
282 /sbin
/ifconfig
$1 inet6 plumb
283 if /sbin
/ifconfig
$1 inet6
>/dev
/null
2>&1; then
284 inet6_plumbed
="$inet6_plumbed $1"
286 inet6_failed
="$inet6_failed $1"
290 [ -n "$inet6_failed" ] && warn_failed_ifs
"plumb IPv6" "$inet6_failed"
294 # Create all of the IPv6 IPMP interfaces.
296 if [ -n "$ipmp6_list" ]; then
298 while [ $# -gt 0 ]; do
299 if /sbin
/ifconfig
$1 inet6 ipmp
; then
300 ipmp6_created
="$ipmp6_created $1"
302 ipmp6_failed
="$ipmp6_failed $1"
306 [ -n "$ipmp6_failed" ] && warn_failed_ifs
"create IPv6 IPMP" \
311 # Finally configure interfaces set up with ipadm. Any /etc/hostname*.intf
312 # files take precedence over ipadm defined configurations except when
313 # we are in a non-global zone and Layer-3 protection of IP addresses is
314 # enforced on the interface by the global zone.
316 for showif_output
in `/sbin/ipadm show-if -p -o ifname,state,current`; do
317 intf
=`echo $showif_output | /usr/bin/cut -f1 -d:`
318 state
=`echo $showif_output | /usr/bin/cut -f2 -d:`
319 current
=`echo $showif_output | /usr/bin/cut -f3 -d:`
320 if [[ "$state" != "disabled" && $current != *Z
* ]]; then
322 # skip if not a persistent interface, or if it should get IP
323 # configuration from the global zone ('Z' flag is set)
326 elif is_iptun
$intf; then
327 # skip IP tunnel interfaces plumbed by net-iptun
329 elif [ -f /etc
/hostname.
$intf ] ||
[ -f /etc
/hostname6.
$intf ]; then
330 if [[ $current != *Z
* ]]; then
331 echo "found /etc/hostname.$intf "\
332 "or /etc/hostname6.$intf, "\
333 "ignoring ipadm configuration" > /dev
/msglog
336 echo "Ignoring /etc/hostname*.$intf" > /dev
/msglog
337 /sbin
/ifconfig
$intf unplumb
> /dev
/null
2>&1
338 /sbin
/ifconfig
$intf inet6 unplumb
> /dev
/null
2>&1
342 # Enable the interface managed by ipadm
343 /sbin
/ipadm enable-if
-t $intf
347 # Process the /etc/hostname[6].* files for IPMP interfaces. Processing these
348 # before non-IPMP interfaces avoids accidental implicit IPMP group creation.
350 [ -n "$ipmp_created" ] && if_configure inet
"IPMP" $ipmp_created
351 [ -n "$ipmp6_created" ] && if_configure inet6
"IPMP" $ipmp6_created
354 # Process the /etc/hostname[6].* files for non-IPMP interfaces.
356 [ -n "$inet_plumbed" ] && if_configure inet
"" $inet_plumbed
357 [ -n "$inet6_plumbed" ] && if_configure inet6
"" $inet6_plumbed
360 # For the IPv4 and IPv6 interfaces that failed to plumb, find (or create)
361 # IPMP meta-interfaces to host their data addresses.
363 [ -n "$inet_failed" ] && move_addresses inet
364 [ -n "$inet6_failed" ] && move_addresses inet6
366 # Run DHCP if requested. Skip boot-configured interface.
367 interface_names
="`echo /etc/dhcp.*[0-9] 2>/dev/null`"
368 if [ "$interface_names" != '/etc/dhcp.*[0-9]' ]; then
370 # First find the primary interface. Default to the first
371 # interface if not specified. First primary interface found
372 # "wins". Use care not to "reconfigure" a net-booted interface
373 # configured using DHCP. Run through the list of interfaces
374 # again, this time trying DHCP.
381 set -- $interface_names
383 while [ $# -ge 2 ]; do
385 [ -z "$firstif" ] && firstif
=$1
387 for i
in `shcat /etc/dhcp\.$1`; do
388 if [ "$i" = primary
]; then
394 [ -n "$primary" ] && break
398 [ -z "$primary" ] && primary
="$firstif"
399 cmdline
=`shcat /etc/dhcp\.${primary}`
401 if [ "$_INIT_NET_IF" != "$primary" ]; then
402 echo "starting DHCP on primary interface $primary"
403 /sbin
/ifconfig
$primary auto-dhcp primary
$cmdline
404 # Exit code 4 means ifconfig timed out waiting for dhcpagent
405 [ $?
!= 0 ] && [ $?
!= 4 ] && i4d_fail
="$i4d_fail $primary"
408 set -- $interface_names
410 while [ $# -ge 2 ]; do
412 cmdline
=`shcat /etc/dhcp\.$1`
413 if [ "$1" != "$primary" -a \
414 "$1" != "$_INIT_NET_IF" ]; then
415 echo "starting DHCP on interface $1"
416 /sbin
/ifconfig
$1 dhcp start
wait 0 $cmdline
417 # Exit code can't be timeout when wait is 0
418 [ $?
!= 0 ] && i4d_fail
="$i4d_fail $1"
424 [ -n "$i4d_fail" ] && warn_failed_ifs
"configure IPv4 DHCP" "$i4d_fail"
427 # In order to avoid bringing up the interfaces that have
428 # intentionally been left down, perform RARP only if the system
429 # has no configured hostname in /etc/nodename
430 hostname
="`shcat /etc/nodename 2>/dev/null`"
431 if [ "$_INIT_NET_STRATEGY" = "rarp" -o -z "$hostname" ]; then
432 /sbin
/ifconfig
-adD4 auto-revarp netmask
+ broadcast
+ up
436 # If the /etc/defaultrouter file exists, process it now so that the next
437 # stage of booting will have access to NFS.
439 if [ -f /etc
/defaultrouter
]; then
440 while read router rubbish
; do
442 '#'* |
'') ;; # Ignore comments, empty lines
443 *) /sbin
/route
-n add default
-gateway $router ;;
445 done </etc
/defaultrouter
449 # If we get here and were not asked to plumb any IPv4 interfaces, look
450 # for boot properties that direct us.
452 # - The "network-interface" property is required and indicates the
454 # - The "xpv-hcp" property, if present, is used by the hypervisor
455 # tools to indicate how the specified interface should be configured.
456 # Permitted values are "dhcp" and "off", where "off" indicates static
459 # In the case where "xpv-hcp" is set to "dhcp", no further properties
460 # are required or examined.
462 # In the case where "xpv-hcp" is not present or set to "off", the
463 # "host-ip" and "subnet-mask" properties are used to configure
464 # the specified interface. The "router-ip" property, if present,
465 # is used to add a default route.
467 nic
="`/sbin/devprop network-interface`"
468 if smf_is_globalzone
&& [ -z "$inet_list" ] && [ -n "$nic" ]; then
469 hcp
="`/sbin/devprop xpv-hcp`"
472 /sbin
/ifconfig
$nic plumb
2>/dev
/null
473 [ -n "`/sbin/ifconfig $nic 2>/dev/null`" ] && (
474 # The interface is successfully plumbed, so
475 # modify "inet_list" to force the exit code
478 # Given that this is the only IPv4 interface,
479 # we assert that it is primary.
480 echo "starting DHCP on primary interface $primary";
481 /sbin
/ifconfig
$nic auto-dhcp primary
;
482 # Exit code 4 means ifconfig timed out waiting
484 [ $?
!= 0 ] && [ $?
!= 4 ] && \
485 i4d_fail
="$i4d_fail $nic";
490 /sbin
/devprop host-ip subnet-mask router-ip |
(
494 [ -n "$ip" ] && [ -n "$mask" ] && \
495 /sbin
/ifconfig
$nic plumb
2>/dev
/null
496 [ -n "`/sbin/ifconfig $nic 2>/dev/null`" ] && (
497 # The interface is successfully
498 # plumbed, so modify "inet_list" to
499 # force the exit code checks to work.
501 /sbin
/ifconfig
$nic inet
$ip \
502 netmask
$mask broadcast
+ up
2>/dev
/null
;
503 [ -n "$router" ] && route add \
504 default
$router 2>/dev
/null
;
512 # We tell smf this service is online if any of the following is true:
513 # - no interfaces were configured for plumbing and no DHCP failures
514 # - any non-loopback IPv4 interfaces are up and have a non-zero address
515 # - there are any DHCP interfaces started
516 # - any non-loopback IPv6 interfaces are up
518 # If we weren't asked to configure any interfaces, exit
519 if [ -z "$inet_list" ] && [ -z "$inet6_list" ]; then
520 # Config error if DHCP was attempted without plumbed interfaces
521 [ -n "$i4d_fail" ] && exit $SMF_EXIT_ERR_CONFIG
525 # Any non-loopback IPv4 interfaces with usable addresses up?
526 if [ -n "`/sbin/ifconfig -a4u`" ]; then
527 /sbin
/ifconfig
-a4u |
while read intf addr rest
; do
528 [ $intf = inet
] && [ $addr != 127.0.0.1 ] &&
529 [ $addr != 0.0.0.0 ] && exit $SMF_EXIT_OK
530 done && exit $SMF_EXIT_OK
533 # Any DHCP interfaces started?
534 [ -n "`/sbin/ifconfig -a4 dhcp status 2>/dev/null`" ] && exit $SMF_EXIT_OK
536 # Any non-loopback IPv6 interfaces up?
537 if [ -n "`/sbin/ifconfig -au6`" ]; then
538 /sbin
/ifconfig
-au6 |
while read intf addr rest
; do
539 [ $intf = inet6
] && [ $addr != ::1/128 ] && exit $SMF_EXIT_OK
540 done && exit $SMF_EXIT_OK
543 # This service was supposed to configure something yet didn't. Exit
545 exit $SMF_EXIT_ERR_CONFIG