net-physical revision 6ba597c56d749c61b4f783157f63196d7b2445f0
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye# CDDL HEADER START
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye# The contents of this file are subject to the terms of the
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye# Common Development and Distribution License (the "License").
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye# You may not use this file except in compliance with the License.
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye# See the License for the specific language governing permissions
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye# and limitations under the License.
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye# When distributing Covered Code, include this CDDL HEADER in each
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye# If applicable, add the following below this CDDL HEADER, with the
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye# fields enclosed by brackets "[]" replaced with your own identifying
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye# information: Portions Copyright [yyyy] [name of copyright owner]
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye# CDDL HEADER END
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye# Copyright 2010 Sun Microsystems, Inc. All rights reserved.
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye# Use is subject to license terms.
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T.
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye# All rights reserved.
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye# In a shared-IP zone we need this service to be up, but all of the work
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye# it tries to do is irrelevant (and will actually lead to the service
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye# failing if we try to do it), so just bail out.
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye# In the global zone and exclusive-IP zones we proceed.
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye# Make sure that the libraries essential to this stage of booting can be found.
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye # Update PVID on interfaces configured with VLAN 1
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye # Upgrade handling. The upgrade file consists of a series of dladm(1M)
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye # commands. Note that after we are done, we cannot rename the upgrade
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye # script file as the file system is still read-only at this point.
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye # Defer this to the manifest-import service.
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye upgrade_script=/var/svc/profile/upgrade_datalink
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye if [ -f "${upgrade_script}" ]; then
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye . "${upgrade_script}"
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye # Bring up simnets, link aggregations and initialize security objects.
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye # Note that link property initialization is deferred until after
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye # IP interfaces are plumbed to ensure that the links will not
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye # be unloaded (and the property settings lost). We should bring
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye # up simnets prior to VLANs/Aggrs to enable creation of VLANs/Aggrs
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye # over simnets.
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye # Bring up VNICs
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye # Create flows via flowadm.
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye# If the system was net booted by DHCP, hand DHCP management off to the
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye# DHCP agent (ifconfig communicates to the DHCP agent through the
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye# loopback interface).
0a0811923cbbd2976425db6f4c78eed811c2825bKnut Anders Hatlenif [ -n "$_INIT_NET_IF" -a "$_INIT_NET_STRATEGY" = "dhcp" ]; then
49f592091468eac515dde6139fbc8efa26056b0aJorgen Austvik# The network initialization is done early to support diskless and
945f4c3c36a15447913781dfb1894b34f2941c57Jorgen Austvik# dataless configurations. For IPv4 interfaces that were configured by
5a0c5ad4116f5a4dd0dd5a0a4e6d02973cd5eef9Lubos Kosco# the kernel (e.g. those on diskless machines) and not configured by
780cc7d1b57609ff15fb283201e93cb501ebe9e6Jorgen Austvik# DHCP, reset the netmask using the local "/etc/netmasks" file if one
780cc7d1b57609ff15fb283201e93cb501ebe9e6Jorgen Austvik# exists, and then reset the broadcast address based on the netmask.
d3d2404f9a49bf70b124053feabe666f85ef5361Knut Anders Hatlen/sbin/ifconfig -auD4 netmask + broadcast +
0466de7c67573e1ce5e0733325c1e5383270f5d5Knut Anders Hatlen /sbin/dladm show-iptun -P $intf > /dev/null 2>&1
0466de7c67573e1ce5e0733325c1e5383270f5d5Knut Anders Hatlen if [ $? -eq 0 ]; then
7ecd52b03dc1f0b03ff8f522b4891c8531896c3dJorgen Austvik if [ $# -eq 2 -a \( "$1" = "ip" -o "$1" = "ip6" \) ]; then
b34561d2c3d92fac37dbced05ba6a8738e3d20e9Lubos Kosco # It looks like one, but another type of link might be
b34561d2c3d92fac37dbced05ba6a8738e3d20e9Lubos Kosco # using a name that looks like an implicit IP tunnel.
7ecd52b03dc1f0b03ff8f522b4891c8531896c3dJorgen Austvik # If dladm show-link -P finds it, then it's not an IP
c7eb123c8b2081a261deff3c401fbf92ddba1b58Jorgen Austvik /sbin/dladm show-link -Pp $intf > /dev/null 2>&1
5a0c5ad4116f5a4dd0dd5a0a4e6d02973cd5eef9Lubos Kosco if [ $? -eq 0 ]; then
945f4c3c36a15447913781dfb1894b34f2941c57Jorgen Austvik# All the IPv4 and IPv6 interfaces are plumbed before doing any
5a0c5ad4116f5a4dd0dd5a0a4e6d02973cd5eef9Lubos Kosco# interface configuration. This prevents errors from plumb failures
945f4c3c36a15447913781dfb1894b34f2941c57Jorgen Austvik# getting mixed in with the configured interface lists that the script
1ed6b730409d4740e941142599767d5eac7e7d92Lubos Kosco# Get the list of IPv4 interfaces to configure by breaking
7ecd52b03dc1f0b03ff8f522b4891c8531896c3dJorgen Austvik# /etc/hostname.* into separate args by using "." as a shell separator
64b763950bf11e9357facbd2b5666631a895c085Trond Norbyeinterface_names="`echo /etc/hostname.*[0-9] 2>/dev/null`"
b34561d2c3d92fac37dbced05ba6a8738e3d20e9Lubos Koscoif [ "$interface_names" != "/etc/hostname.*[0-9]" ]; then
b34561d2c3d92fac37dbced05ba6a8738e3d20e9Lubos Kosco while [ $# -gt 1 -a "$2" != "/etc/hostname" ]; do
b34561d2c3d92fac37dbced05ba6a8738e3d20e9Lubos Kosco # skip IP tunnel interfaces plumbed by net-iptun.
a5cc1506d5c0704805c6733a46c7f1f8f91ae724Knut Anders Hatlen# Get the list of IPv6 interfaces to configure by breaking
a5cc1506d5c0704805c6733a46c7f1f8f91ae724Knut Anders Hatlen# /etc/hostname6.* into separate args by using "." as a shell separator
a5cc1506d5c0704805c6733a46c7f1f8f91ae724Knut Anders Hatleninterface_names="`echo /etc/hostname6.*[0-9] 2>/dev/null`"
7b046969a1b2565787df8ae3a8126359e8cd6fafTrond Norbyeif [ "$interface_names" != "/etc/hostname6.*[0-9]" ]; then
a5cc1506d5c0704805c6733a46c7f1f8f91ae724Knut Anders Hatlen while [ $# -gt 1 -a "$2" != "/etc/hostname6" ]; do
a5cc1506d5c0704805c6733a46c7f1f8f91ae724Knut Anders Hatlen # skip IP tunnel interfaces plumbed by net-iptun.
a5cc1506d5c0704805c6733a46c7f1f8f91ae724Knut Anders Hatlen read one rest < /etc/hostname6.$intf_name
a5cc1506d5c0704805c6733a46c7f1f8f91ae724Knut Anders Hatlen# Create all of the IPv4 IPMP interfaces.
a5cc1506d5c0704805c6733a46c7f1f8f91ae724Knut Anders Hatlenif [ -n "$ipmp_list" ]; then
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye [ -n "$ipmp_failed" ] && warn_failed_ifs "create IPv4 IPMP" \
d3d2404f9a49bf70b124053feabe666f85ef5361Knut Anders Hatlen# Step through the IPv4 interface list and try to plumb every interface.
64b763950bf11e9357facbd2b5666631a895c085Trond Norbye# Generate list of plumbed and failed IPv4 interfaces.
9cf297d9a579835e9336d587eaee187ca0954767Knut Anders Hatlenif [ -n "$inet_list" ]; then
2dbc1835e0ae88ad102e2b9a85e5c7b5298b14b6Knut Anders Hatlen if /sbin/ifconfig $1 inet >/dev/null 2>&1; then
2dbc1835e0ae88ad102e2b9a85e5c7b5298b14b6Knut Anders Hatlen [ -n "$inet_failed" ] && warn_failed_ifs "plumb IPv4" "$inet_failed"
2dbc1835e0ae88ad102e2b9a85e5c7b5298b14b6Knut Anders Hatlen# Run autoconf to connect to a WLAN if the interface is a wireless one
2dbc1835e0ae88ad102e2b9a85e5c7b5298b14b6Knut Anders Hatlenif [ -x /sbin/wificonfig -a -n "$inet_plumbed" ]; then
9cf297d9a579835e9336d587eaee187ca0954767Knut Anders Hatlen /sbin/wificonfig -i $1 startconf >/dev/null
2dbc1835e0ae88ad102e2b9a85e5c7b5298b14b6Knut Anders Hatlen# Step through the IPv6 interface list and plumb every interface.
2dbc1835e0ae88ad102e2b9a85e5c7b5298b14b6Knut Anders Hatlen# Generate list of plumbed and failed IPv6 interfaces. Each plumbed
f53d230f3e516218f38a7f1f2866e42bb3e0290eKnut Anders Hatlen# interface will be brought up later, after processing any contents of
752fbd3cf33aada419c8258959ff5574d2d2047dTrond Norbye# the /etc/hostname6.* file.
2dbc1835e0ae88ad102e2b9a85e5c7b5298b14b6Knut Anders Hatlenif [ -n "$inet6_list" ]; then
2dbc1835e0ae88ad102e2b9a85e5c7b5298b14b6Knut Anders Hatlen if /sbin/ifconfig $1 inet6 >/dev/null 2>&1; then
9661674ed58ba62a40e43d1a4b38d5e77c3c6545Knut Anders Hatlen [ -n "$inet6_failed" ] && warn_failed_ifs "plumb IPv6" "$inet6_failed"
9cf297d9a579835e9336d587eaee187ca0954767Knut Anders Hatlen# Create all of the IPv6 IPMP interfaces.
64b763950bf11e9357facbd2b5666631a895c085Trond Norbyeif [ -n "$ipmp6_list" ]; then
523201f786f6b12b7cf54091c6e5be167878cbeeTrond Norbye [ -n "$ipmp6_failed" ] && warn_failed_ifs "create IPv6 IPMP" \
c0550b01024b910b8c1468811c0ea663b10b1372Trond Norbye# Process the /etc/hostname[6].* files for IPMP interfaces. Processing these
0a0811923cbbd2976425db6f4c78eed811c2825bKnut Anders Hatlen# before non-IPMP interfaces avoids accidental implicit IPMP group creation.
e4d314d81209a23aae928ed62128ad9128c115bdLubos Kosco[ -n "$ipmp_created" ] && if_configure inet "IPMP" $ipmp_created
c67bbf00f725074786ac47867d2276e7b935b570Trond Norbye[ -n "$ipmp6_created" ] && if_configure inet6 "IPMP" $ipmp6_created
0a0811923cbbd2976425db6f4c78eed811c2825bKnut Anders Hatlen# Process the /etc/hostname[6].* files for non-IPMP interfaces.
0a0811923cbbd2976425db6f4c78eed811c2825bKnut Anders Hatlen[ -n "$inet_plumbed" ] && if_configure inet "" $inet_plumbed
a07b2874263e3c5f0cd2e83441719415d53059c2Knut Anders Hatlen[ -n "$inet6_plumbed" ] && if_configure inet6 "" $inet6_plumbed
a07b2874263e3c5f0cd2e83441719415d53059c2Knut Anders Hatlen# For the IPv4 and IPv6 interfaces that failed to plumb, find (or create)
5e6c91d7e77062129cd0b6ac8aaa546dff216419Lubos Kosco# IPMP meta-interfaces to host their data addresses.
a07b2874263e3c5f0cd2e83441719415d53059c2Knut Anders Hatlen[ -n "$inet_failed" ] && move_addresses inet
a07b2874263e3c5f0cd2e83441719415d53059c2Knut Anders Hatlen[ -n "$inet6_failed" ] && move_addresses inet6
b34561d2c3d92fac37dbced05ba6a8738e3d20e9Lubos Kosco# Run DHCP if requested. Skip boot-configured interface.
b34561d2c3d92fac37dbced05ba6a8738e3d20e9Lubos Koscointerface_names="`echo /etc/dhcp.*[0-9] 2>/dev/null`"
a07b2874263e3c5f0cd2e83441719415d53059c2Knut Anders Hatlenif [ "$interface_names" != '/etc/dhcp.*[0-9]' ]; then
5e6c91d7e77062129cd0b6ac8aaa546dff216419Lubos Kosco # First find the primary interface. Default to the first
5e6c91d7e77062129cd0b6ac8aaa546dff216419Lubos Kosco # interface if not specified. First primary interface found
5e6c91d7e77062129cd0b6ac8aaa546dff216419Lubos Kosco # "wins". Use care not to "reconfigure" a net-booted interface
5e6c91d7e77062129cd0b6ac8aaa546dff216419Lubos Kosco # configured using DHCP. Run through the list of interfaces
a07b2874263e3c5f0cd2e83441719415d53059c2Knut Anders Hatlen # again, this time trying DHCP.
edcb01bf549171673fd0bb4239f2edfc7a810397Knut Anders Hatlen [ -n "$primary" ] && break
7ecd52b03dc1f0b03ff8f522b4891c8531896c3dJorgen Austvik echo "starting DHCP on primary interface $primary"
7ecd52b03dc1f0b03ff8f522b4891c8531896c3dJorgen Austvik /sbin/ifconfig $primary auto-dhcp primary $cmdline
7ecd52b03dc1f0b03ff8f522b4891c8531896c3dJorgen Austvik # Exit code 4 means ifconfig timed out waiting for dhcpagent
7ecd52b03dc1f0b03ff8f522b4891c8531896c3dJorgen Austvik [ $? != 0 ] && [ $? != 4 ] && i4d_fail="$i4d_fail $primary"
7ecd52b03dc1f0b03ff8f522b4891c8531896c3dJorgen Austvik echo "starting DHCP on interface $1"
c7eb123c8b2081a261deff3c401fbf92ddba1b58Jorgen Austvik # Exit code can't be timeout when wait is 0
85e0595857351c6e22f75b8928967d14cb679ac5Jorgen Austvik [ -n "$i4d_fail" ] && warn_failed_ifs "configure IPv4 DHCP" "$i4d_fail"
85e0595857351c6e22f75b8928967d14cb679ac5Jorgen Austvik# In order to avoid bringing up the interfaces that have
85e0595857351c6e22f75b8928967d14cb679ac5Jorgen Austvik# intentionally been left down, perform RARP only if the system
85e0595857351c6e22f75b8928967d14cb679ac5Jorgen Austvik# has no configured hostname in /etc/nodename
2e3c025fdd5908a27cc82eb1d5346368a8be4e0dJorgen Austvikif [ "$_INIT_NET_STRATEGY" = "rarp" -o -z "$hostname" ]; then
52cf1d63b1f1b231ff1e86eca2058d88560579b5Lubos Kosco /sbin/ifconfig -adD4 auto-revarp netmask + broadcast + up
1f17ba9e3c026d75f488227451416bd72a222afeTrond Norbye# If the /etc/defaultrouter file exists, process it now so that the next
1f17ba9e3c026d75f488227451416bd72a222afeTrond Norbye# stage of booting will have access to NFS.
1f17ba9e3c026d75f488227451416bd72a222afeTrond Norbye *) /sbin/route -n add default -gateway $router ;;
49f592091468eac515dde6139fbc8efa26056b0aJorgen Austvik# If we get here and were not asked to plumb any IPv4 interfaces, look
49f592091468eac515dde6139fbc8efa26056b0aJorgen Austvik# for boot properties that direct us.
49f592091468eac515dde6139fbc8efa26056b0aJorgen Austvik# - The "network-interface" property is required and indicates the
49f592091468eac515dde6139fbc8efa26056b0aJorgen Austvik# interface name.
49f592091468eac515dde6139fbc8efa26056b0aJorgen Austvik# - The "xpv-hcp" property, if present, is used by the hypervisor
945f4c3c36a15447913781dfb1894b34f2941c57Jorgen Austvik# tools to indicate how the specified interface should be configured.
49f592091468eac515dde6139fbc8efa26056b0aJorgen Austvik# Permitted values are "dhcp" and "off", where "off" indicates static
49f592091468eac515dde6139fbc8efa26056b0aJorgen Austvik# IP configuration.
45cf976b01987ad147e9edb54ffab0938dd6c016Trond Norbye# In the case where "xpv-hcp" is set to "dhcp", no further properties
49f592091468eac515dde6139fbc8efa26056b0aJorgen Austvik# are required or examined.
49f592091468eac515dde6139fbc8efa26056b0aJorgen Austvik# In the case where "xpv-hcp" is not present or set to "off", the
49f592091468eac515dde6139fbc8efa26056b0aJorgen Austvik# "host-ip" and "subnet-mask" properties are used to configure
49f592091468eac515dde6139fbc8efa26056b0aJorgen Austvik# the specified interface. The "router-ip" property, if present,
945f4c3c36a15447913781dfb1894b34f2941c57Jorgen Austvik# is used to add a default route.
945f4c3c36a15447913781dfb1894b34f2941c57Jorgen Austvikif smf_is_globalzone && [ -z "$inet_list" ] && [ -n "$nic" ]; then
945f4c3c36a15447913781dfb1894b34f2941c57Jorgen Austvik [ -n "`/sbin/ifconfig $nic 2>/dev/null`" ] && (
945f4c3c36a15447913781dfb1894b34f2941c57Jorgen Austvik # Given that this is the only IPv4 interface,
945f4c3c36a15447913781dfb1894b34f2941c57Jorgen Austvik echo "starting DHCP on primary interface $primary";
945f4c3c36a15447913781dfb1894b34f2941c57Jorgen Austvik # Exit code 4 means ifconfig timed out waiting
945f4c3c36a15447913781dfb1894b34f2941c57Jorgen Austvik [ $? != 0 ] && [ $? != 4 ] && \
30637745bf5a7db2ff9684a2536cc9f8c9df2218Lubos Kosco# We tell smf this service is online if any of the following is true:
30637745bf5a7db2ff9684a2536cc9f8c9df2218Lubos Kosco# - no interfaces were configured for plumbing and no DHCP failures
30637745bf5a7db2ff9684a2536cc9f8c9df2218Lubos Kosco# - any non-loopback IPv4 interfaces are up and have a non-zero address
7ecd52b03dc1f0b03ff8f522b4891c8531896c3dJorgen Austvik# - there are any DHCP interfaces started
f09d46eefeb5e4db6dc11e02e417b448fa9362a9Jorgen Austvik# - any non-loopback IPv6 interfaces are up
7ecd52b03dc1f0b03ff8f522b4891c8531896c3dJorgen Austvik# If we weren't asked to configure any interfaces, exit
7ecd52b03dc1f0b03ff8f522b4891c8531896c3dJorgen Austvikif [ -z "$inet_list" ] && [ -z "$inet6_list" ]; then
7ecd52b03dc1f0b03ff8f522b4891c8531896c3dJorgen Austvik # Config error if DHCP was attempted without plumbed interfaces
7ecd52b03dc1f0b03ff8f522b4891c8531896c3dJorgen Austvik [ -n "$i4d_fail" ] && exit $SMF_EXIT_ERR_CONFIG
7ecd52b03dc1f0b03ff8f522b4891c8531896c3dJorgen Austvik# Any non-loopback IPv4 interfaces with usable addresses up?
7ecd52b03dc1f0b03ff8f522b4891c8531896c3dJorgen Austvik /sbin/ifconfig -a4u | while read intf addr rest; do
2e3c025fdd5908a27cc82eb1d5346368a8be4e0dJorgen Austvik [ $intf = inet ] && [ $addr != 127.0.0.1 ] &&
2e3c025fdd5908a27cc82eb1d5346368a8be4e0dJorgen Austvik# Any DHCP interfaces started?
2e3c025fdd5908a27cc82eb1d5346368a8be4e0dJorgen Austvik[ -n "`/sbin/ifconfig -a4 dhcp status 2>/dev/null`" ] && exit $SMF_EXIT_OK
2e3c025fdd5908a27cc82eb1d5346368a8be4e0dJorgen Austvik# Any non-loopback IPv6 interfaces up?
63e0f31920b0818d6f471a066c12da991fb35346Trond Norbye /sbin/ifconfig -au6 | while read intf addr rest; do
2e3c025fdd5908a27cc82eb1d5346368a8be4e0dJorgen Austvik [ $intf = inet6 ] && [ $addr != ::1/128 ] && exit $SMF_EXIT_OK
2e3c025fdd5908a27cc82eb1d5346368a8be4e0dJorgen Austvik# This service was supposed to configure something yet didn't. Exit
2e3c025fdd5908a27cc82eb1d5346368a8be4e0dJorgen Austvik# with config error.