net-physical revision e11c3f44f531fdff80941ce57c065d2ae861cefc
08d6658a4e2ec8104cd1307f6baa75fdb07a24f8Mark Washenberger# CDDL HEADER START
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen# The contents of this file are subject to the terms of the
29d4c6eac14a0b3d79656eb6b206a102fd09d24aTimo Sirainen# Common Development and Distribution License (the "License").
73bfdbe28c2ce6d143eadf0bab8ccfbe4cab0faeTimo Sirainen# You may not use this file except in compliance with the License.
5cda7e699876c1de203c30777924c899d2a20221Timo Sirainen# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
419baa2c17c63ae516b2df6cc5695f15aaccbff8Timo Sirainen# See the License for the specific language governing permissions
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen# and limitations under the License.
73bfdbe28c2ce6d143eadf0bab8ccfbe4cab0faeTimo Sirainen# When distributing Covered Code, include this CDDL HEADER in each
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
8eefc42b2559db19d06d7ad7b8ad9d1cd2a09178Timo Sirainen# If applicable, add the following below this CDDL HEADER, with the
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen# fields enclosed by brackets "[]" replaced with your own identifying
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen# information: Portions Copyright [yyyy] [name of copyright owner]
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen# CDDL HEADER END
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen# Use is subject to license terms.
76213404317a7ed17bec0beadb5137c82785d816Timo Sirainen# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T.
76213404317a7ed17bec0beadb5137c82785d816Timo Sirainen# All rights reserved.
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen# In a shared-IP zone we need this service to be up, but all of the work
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen# it tries to do is irrelevant (and will actually lead to the service
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen# failing if we try to do it), so just bail out.
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen# In the global zone and exclusive-IP zones we proceed.
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen# Make sure that the libraries essential to this stage of booting can be found.
c96a1bff0db10e7f7e1d50bc434c95bf1f071805Timo Sirainen # Upgrade handling. The upgrade file consists of a series of dladm(1M)
c96a1bff0db10e7f7e1d50bc434c95bf1f071805Timo Sirainen # commands. Note that after we are done, we cannot rename the upgrade
c96a1bff0db10e7f7e1d50bc434c95bf1f071805Timo Sirainen # script file as the file system is still read-only at this point.
c96a1bff0db10e7f7e1d50bc434c95bf1f071805Timo Sirainen # Defer this to the manifest-import service.
c96a1bff0db10e7f7e1d50bc434c95bf1f071805Timo Sirainen upgrade_script=/var/svc/profile/upgrade_datalink
c96a1bff0db10e7f7e1d50bc434c95bf1f071805Timo Sirainen if [ -f "${upgrade_script}" ]; then
c96a1bff0db10e7f7e1d50bc434c95bf1f071805Timo Sirainen . "${upgrade_script}"
c96a1bff0db10e7f7e1d50bc434c95bf1f071805Timo Sirainen # Bring up link aggregations and initialize security objects.
c96a1bff0db10e7f7e1d50bc434c95bf1f071805Timo Sirainen # Note that link property initialization is deferred until after
c96a1bff0db10e7f7e1d50bc434c95bf1f071805Timo Sirainen # IP interfaces are plumbed to ensure that the links will not
c96a1bff0db10e7f7e1d50bc434c95bf1f071805Timo Sirainen # be unloaded (and the property settings lost).
c96a1bff0db10e7f7e1d50bc434c95bf1f071805Timo Sirainen # Bring up VNICs
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen # Create flows via flowadm.
eb7b8855cc45292334056f425645215e348ec493Timo Sirainen# If the system was net booted by DHCP, hand DHCP management off to the
eb7b8855cc45292334056f425645215e348ec493Timo Sirainen# DHCP agent (ifconfig communicates to the DHCP agent through the
657afb33796f8216c568ad813627da89970760beTimo Sirainen# loopback interface).
a7bee3930831a9261fa6180d02af29c484d862e9Timo Sirainenif [ -n "$_INIT_NET_IF" -a "$_INIT_NET_STRATEGY" = "dhcp" ]; then
73bfdbe28c2ce6d143eadf0bab8ccfbe4cab0faeTimo Sirainen# The network initialization is done early to support diskless and
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen# dataless configurations. For IPv4 interfaces that were configured by
2a90d8a14b0e7cc1508814bc87d3dfa598ef46a8Timo Sirainen# the kernel (e.g. those on diskless machines) and not configured by
ab90f702ceedb7ba445a9a592be0b213b27cbafaStephan Bosch# DHCP, reset the netmask using the local "/etc/netmasks" file if one
73bfdbe28c2ce6d143eadf0bab8ccfbe4cab0faeTimo Sirainen# exists, and then reset the broadcast address based on the netmask.
7a60e1dc9e93ef3f7c7fe1af6385a0bfa1e31bc3Timo Sirainen# All the IPv4 and IPv6 interfaces are plumbed before doing any
9261dbf0675204898c6557591c7aa376e23a52b2Timo Sirainen# interface configuration. This prevents errors from plumb failures
9261dbf0675204898c6557591c7aa376e23a52b2Timo Sirainen# getting mixed in with the configured interface lists that the script
73bfdbe28c2ce6d143eadf0bab8ccfbe4cab0faeTimo Sirainen# Get the list of IPv4 interfaces to configure by breaking
73bfdbe28c2ce6d143eadf0bab8ccfbe4cab0faeTimo Sirainen# /etc/hostname.* into separate args by using "." as a shell separator
419baa2c17c63ae516b2df6cc5695f15aaccbff8Timo Siraineninterface_names="`echo /etc/hostname.*[0-9] 2>/dev/null`"
419baa2c17c63ae516b2df6cc5695f15aaccbff8Timo Sirainenif [ "$interface_names" != "/etc/hostname.*[0-9]" ]; then
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainen while [ $# -gt 1 -a "$2" != "/etc/hostname" ]; do
73bfdbe28c2ce6d143eadf0bab8ccfbe4cab0faeTimo Sirainen# Get the list of IPv6 interfaces to configure by breaking
d9a7e950a9cd21f2b4a90ec7759fca9e8fcc7995Timo Sirainen# /etc/hostname6.* into separate args by using "." as a shell separator
39dcbe101c4538ee25d8b196eab30e5f0faa22eeTimo Siraineninterface_names="`echo /etc/hostname6.*[0-9] 2>/dev/null`"
39dcbe101c4538ee25d8b196eab30e5f0faa22eeTimo Sirainenif [ "$interface_names" != "/etc/hostname6.*[0-9]" ]; then
39dcbe101c4538ee25d8b196eab30e5f0faa22eeTimo Sirainen while [ $# -gt 1 -a "$2" != "/etc/hostname6" ]; do
1862352e2ef8ed1ef824368d9c0c2c0fce89962eTimo Sirainen# Create all of the IPv4 IPMP interfaces.
1862352e2ef8ed1ef824368d9c0c2c0fce89962eTimo Sirainenif [ -n "$ipmp_list" ]; then
1862352e2ef8ed1ef824368d9c0c2c0fce89962eTimo Sirainen [ -n "$ipmp_failed" ] && warn_failed_ifs "create IPv4 IPMP" \
9261dbf0675204898c6557591c7aa376e23a52b2Timo Sirainen# Step through the IPv4 interface list and try to plumb every interface.
0602c7dee8ceda2d7c7e5723f18c56698ac5a76dTimo Sirainen# Generate list of plumbed and failed IPv4 interfaces.
b8a6abfd2bc86118f54f59ee71005f634f45cdfcTimo Sirainenif [ -n "$inet_list" ]; then
1862352e2ef8ed1ef824368d9c0c2c0fce89962eTimo Sirainen if /sbin/ifconfig $1 inet >/dev/null 2>&1; then
1862352e2ef8ed1ef824368d9c0c2c0fce89962eTimo Sirainen [ -n "$inet_failed" ] && warn_failed_ifs "plumb IPv4" "$inet_failed"
1862352e2ef8ed1ef824368d9c0c2c0fce89962eTimo Sirainen# Run autoconf to connect to a WLAN if the interface is a wireless one
1862352e2ef8ed1ef824368d9c0c2c0fce89962eTimo Sirainenif [ -x /sbin/wificonfig -a -n "$inet_plumbed" ]; then
b8a6abfd2bc86118f54f59ee71005f634f45cdfcTimo Sirainen# Step through the IPv6 interface list and plumb every interface.
b8a6abfd2bc86118f54f59ee71005f634f45cdfcTimo Sirainen# Generate list of plumbed and failed IPv6 interfaces. Each plumbed
1862352e2ef8ed1ef824368d9c0c2c0fce89962eTimo Sirainen# interface will be brought up later, after processing any contents of
1862352e2ef8ed1ef824368d9c0c2c0fce89962eTimo Sirainenif [ -n "$inet6_list" ]; then
c95b7ce6c3ebf84a9ef20320b9f11ef2129e1f1aTimo Sirainen if /sbin/ifconfig $1 inet6 >/dev/null 2>&1; then
c95b7ce6c3ebf84a9ef20320b9f11ef2129e1f1aTimo Sirainen [ -n "$inet6_failed" ] && warn_failed_ifs "plumb IPv6" "$inet6_failed"
c95b7ce6c3ebf84a9ef20320b9f11ef2129e1f1aTimo Sirainen# Create all of the IPv6 IPMP interfaces.
c95b7ce6c3ebf84a9ef20320b9f11ef2129e1f1aTimo Sirainenif [ -n "$ipmp6_list" ]; then
4240acc84d065472e5b21becd6481553fc38fe38Timo Sirainen [ -n "$ipmp6_failed" ] && warn_failed_ifs "create IPv6 IPMP" \
0f39a57760d93cddbce3ca43096d78e0fe2f42fdTimo Sirainen # Wifi drivers use special property interfaces that are not supported
137ea7ca34005345aa2304a940149b7f3774d727Timo Sirainen # by the existing property persistence mechanism, so if a wifi driver
9398c0935613ba038cf2275ff66c43b25092cfd0Timo Sirainen # unloads and then is subsequently reloaded, associated links' properties
0602c7dee8ceda2d7c7e5723f18c56698ac5a76dTimo Sirainen # will not be restored. For now, wait until after interfaces have been
9398c0935613ba038cf2275ff66c43b25092cfd0Timo Sirainen # plumbed (above) to initialize link properties.
c95b7ce6c3ebf84a9ef20320b9f11ef2129e1f1aTimo Sirainen# Process the /etc/hostname[6].* files for IPMP interfaces. Processing these
c95b7ce6c3ebf84a9ef20320b9f11ef2129e1f1aTimo Sirainen# before non-IPMP interfaces avoids accidental implicit IPMP group creation.
c95b7ce6c3ebf84a9ef20320b9f11ef2129e1f1aTimo Sirainen[ -n "$ipmp_created" ] && if_configure inet "IPMP" $ipmp_created
c95b7ce6c3ebf84a9ef20320b9f11ef2129e1f1aTimo Sirainen[ -n "$ipmp6_created" ] && if_configure inet6 "IPMP" $ipmp6_created
0f39a57760d93cddbce3ca43096d78e0fe2f42fdTimo Sirainen# Process the /etc/hostname[6].* files for non-IPMP interfaces.
cd75c360f244c96b9ee10e01ee3a66fad13183c8Timo Sirainen[ -n "$inet_plumbed" ] && if_configure inet "" $inet_plumbed
ee6df9526e9716b3f1734d85b566e00fc41208bcTimo Sirainen[ -n "$inet6_plumbed" ] && if_configure inet6 "" $inet6_plumbed
3313a51ef9b245248d672c20f930c52a577a42f7Timo Sirainen# For the IPv4 and IPv6 interfaces that failed to plumb, find (or create)
3313a51ef9b245248d672c20f930c52a577a42f7Timo Sirainen# IPMP meta-interfaces to host their data addresses.
0f39a57760d93cddbce3ca43096d78e0fe2f42fdTimo Sirainen# Run DHCP if requested. Skip boot-configured interface.
9398c0935613ba038cf2275ff66c43b25092cfd0Timo Siraineninterface_names="`echo /etc/dhcp.*[0-9] 2>/dev/null`"
548193b7d6c19a14eff810202cd334f364b75e36Timo Sirainenif [ "$interface_names" != '/etc/dhcp.*[0-9]' ]; then
559f278a4c54d9fa7e0f2e96ebceda30562f9009Timo Sirainen # First find the primary interface. Default to the first
559f278a4c54d9fa7e0f2e96ebceda30562f9009Timo Sirainen # interface if not specified. First primary interface found
0f39a57760d93cddbce3ca43096d78e0fe2f42fdTimo Sirainen # "wins". Use care not to "reconfigure" a net-booted interface
9398c0935613ba038cf2275ff66c43b25092cfd0Timo Sirainen # configured using DHCP. Run through the list of interfaces
397165dbd694272487e29c8d48d619822da52abcTimo Sirainen # again, this time trying DHCP.
1862352e2ef8ed1ef824368d9c0c2c0fce89962eTimo Sirainen [ -n "$primary" ] && break
401b0787fff2dc986a5321ddb32acb1947ff66b0Timo Sirainen echo "starting DHCP on primary interface $primary"
1862352e2ef8ed1ef824368d9c0c2c0fce89962eTimo Sirainen /sbin/ifconfig $primary auto-dhcp primary $cmdline
9398c0935613ba038cf2275ff66c43b25092cfd0Timo Sirainen # Exit code 4 means ifconfig timed out waiting for dhcpagent
1862352e2ef8ed1ef824368d9c0c2c0fce89962eTimo Sirainen [ $? != 0 ] && [ $? != 4 ] && i4d_fail="$i4d_fail $primary"
1862352e2ef8ed1ef824368d9c0c2c0fce89962eTimo Sirainen echo "starting DHCP on interface $1"
bbdd683dd23641dca779bffdf22c089b57fe5066Timo Sirainen # Exit code can't be timeout when wait is 0
76830cda2eddcb36736bbb349dcbc2e9ca032483Timo Sirainen [ -n "$i4d_fail" ] && warn_failed_ifs "configure IPv4 DHCP" "$i4d_fail"
76830cda2eddcb36736bbb349dcbc2e9ca032483Timo Sirainen# In order to avoid bringing up the interfaces that have
1862352e2ef8ed1ef824368d9c0c2c0fce89962eTimo Sirainen# intentionally been left down, perform RARP only if the system
1862352e2ef8ed1ef824368d9c0c2c0fce89962eTimo Sirainen# has no configured hostname in /etc/nodename
1862352e2ef8ed1ef824368d9c0c2c0fce89962eTimo Sirainenif [ "$_INIT_NET_STRATEGY" = "rarp" -o -z "$hostname" ]; then
1862352e2ef8ed1ef824368d9c0c2c0fce89962eTimo Sirainen /sbin/ifconfig -adD4 auto-revarp netmask + broadcast + up
1862352e2ef8ed1ef824368d9c0c2c0fce89962eTimo Sirainen# If the /etc/defaultrouter file exists, process it now so that the next
1862352e2ef8ed1ef824368d9c0c2c0fce89962eTimo Sirainen# stage of booting will have access to NFS.
4f17af486518a4a7526dc6c4eed702178dc0bee9Timo Sirainen *) /sbin/route -n add default -gateway $router ;;
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainen# If we get here and were not asked to plumb any IPv4 interfaces, look
0602c7dee8ceda2d7c7e5723f18c56698ac5a76dTimo Sirainen# for boot properties that direct us.
1862352e2ef8ed1ef824368d9c0c2c0fce89962eTimo Sirainen# - The "network-interface" property is required and indicates the
1862352e2ef8ed1ef824368d9c0c2c0fce89962eTimo Sirainen# interface name.
70c181da837ed85fc5b0426c010b65609bda5329Timo Sirainen# - The "xpv-hcp" property, if present, is used by the hypervisor
91233a89f0060f95542ed661683e5d99a50f1778Timo Sirainen# tools to indicate how the specified interface should be configured.
91233a89f0060f95542ed661683e5d99a50f1778Timo Sirainen# Permitted values are "dhcp" and "off", where "off" indicates static
91233a89f0060f95542ed661683e5d99a50f1778Timo Sirainen# IP configuration.
91233a89f0060f95542ed661683e5d99a50f1778Timo Sirainen# In the case where "xpv-hcp" is set to "dhcp", no further properties
91233a89f0060f95542ed661683e5d99a50f1778Timo Sirainen# are required or examined.
91233a89f0060f95542ed661683e5d99a50f1778Timo Sirainen# In the case where "xpv-hcp" is not present or set to "off", the
91233a89f0060f95542ed661683e5d99a50f1778Timo Sirainen# "host-ip" and "subnet-mask" properties are used to configure
91233a89f0060f95542ed661683e5d99a50f1778Timo Sirainen# the specified interface. The "router-ip" property, if present,
91233a89f0060f95542ed661683e5d99a50f1778Timo Sirainen# is used to add a default route.
91233a89f0060f95542ed661683e5d99a50f1778Timo Sirainenif smf_is_globalzone && [ -z "$inet_list" ] && [ -n "$nic" ]; then
91233a89f0060f95542ed661683e5d99a50f1778Timo Sirainen [ -n "`/sbin/ifconfig $nic 2>/dev/null`" ] && (
91233a89f0060f95542ed661683e5d99a50f1778Timo Sirainen echo "starting DHCP on primary interface $primary";
91233a89f0060f95542ed661683e5d99a50f1778Timo Sirainen # Exit code 4 means ifconfig timed out waiting
86a58337862c546aa489f07e8e6d242f0180e4a0Timo Sirainen [ $? != 0 ] && [ $? != 4 ] && \
8eefc42b2559db19d06d7ad7b8ad9d1cd2a09178Timo Sirainen /sbin/devprop host-ip subnet-mask router-ip | (
86a58337862c546aa489f07e8e6d242f0180e4a0Timo Sirainen [ -n "`/sbin/ifconfig $nic 2>/dev/null`" ] && (
5965eaa2d972e6264cecaf54091cd43019bc7d1fTimo Sirainen# We tell smf this service is online if any of the following is true:
c95b7ce6c3ebf84a9ef20320b9f11ef2129e1f1aTimo Sirainen# - no interfaces were configured for plumbing and no DHCP failures
c95b7ce6c3ebf84a9ef20320b9f11ef2129e1f1aTimo Sirainen# - any non-loopback IPv4 interfaces are up and have a non-zero address
c95b7ce6c3ebf84a9ef20320b9f11ef2129e1f1aTimo Sirainen# - there are any DHCP interfaces started
86a58337862c546aa489f07e8e6d242f0180e4a0Timo Sirainen# - any non-loopback IPv6 interfaces are up
c95b7ce6c3ebf84a9ef20320b9f11ef2129e1f1aTimo Sirainen# If we weren't asked to configure any interfaces, exit
5965eaa2d972e6264cecaf54091cd43019bc7d1fTimo Sirainenif [ -z "$inet_list" ] && [ -z "$inet6_list" ]; then
1862352e2ef8ed1ef824368d9c0c2c0fce89962eTimo Sirainen # Config error if DHCP was attempted without plumbed interfaces
401b0787fff2dc986a5321ddb32acb1947ff66b0Timo Sirainen [ -n "$i4d_fail" ] && exit $SMF_EXIT_ERR_CONFIG
1862352e2ef8ed1ef824368d9c0c2c0fce89962eTimo Sirainen# Any non-loopback IPv4 interfaces with usable addresses up?
9398c0935613ba038cf2275ff66c43b25092cfd0Timo Sirainen /sbin/ifconfig -a4u | while read intf addr rest; do
47b5ef748f34ca194419befab4f7450002f4e85dTimo Sirainen# Any DHCP interfaces started?
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen[ -n "`/sbin/ifconfig -a4 dhcp status 2>/dev/null`" ] && exit $SMF_EXIT_OK
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen# Any non-loopback IPv6 interfaces up?
1ce47e48d7231da6f18f02eab6bab6451b4ef12aTimo Sirainen /sbin/ifconfig -au6 | while read intf addr rest; do
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen [ $intf = inet6 ] && [ $addr != ::1/128 ] && exit $SMF_EXIT_OK
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen# This service was supposed to configure something yet didn't. Exit
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen# with config error.