net-physical revision 6927f468b0af7710df000f6b16f6ee413e1e3007
0N/A#!/sbin/sh
2362N/A#
0N/A# CDDL HEADER START
0N/A#
0N/A# The contents of this file are subject to the terms of the
0N/A# Common Development and Distribution License (the "License").
2362N/A# You may not use this file except in compliance with the License.
0N/A#
2362N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
0N/A# or http://www.opensolaris.org/os/licensing.
0N/A# See the License for the specific language governing permissions
0N/A# and limitations under the License.
0N/A#
0N/A# When distributing Covered Code, include this CDDL HEADER in each
0N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
0N/A# If applicable, add the following below this CDDL HEADER, with the
0N/A# fields enclosed by brackets "[]" replaced with your own identifying
0N/A# information: Portions Copyright [yyyy] [name of copyright owner]
0N/A#
0N/A# CDDL HEADER END
2362N/A#
2362N/A#
2362N/A# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
0N/A# Use is subject to license terms.
0N/A#
0N/A# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T.
0N/A# All rights reserved.
0N/A#
0N/A#
0N/A# ident "%Z%%M% %I% %E% SMI"
0N/A
0N/A. /lib/svc/share/smf_include.sh
0N/A. /lib/svc/share/net_include.sh
0N/A
0N/A#
0N/A# In a zone we need this service to be up, but all of the work
0N/A# it tries to do is irrelevant (and will actually lead to the service
0N/A# failing if we try to do it), so just bail out.
0N/A#
0N/Asmf_is_globalzone || exit $SMF_EXIT_OK
0N/A
0N/A# Print warnings to console
0N/Awarn_failed_ifs() {
0N/A echo "Failed to $1 interface(s): $2" >/dev/msglog
0N/A}
0N/A
0N/A# Make sure that the libraries essential to this stage of booting can be found.
0N/ALD_LIBRARY_PATH=/lib; export LD_LIBRARY_PATH
0N/A
0N/A#
0N/A# Cause ifconfig to not automatically start in.mpathd when IPMP groups are
0N/A# configured. This is not strictly necessary but makes it so that in.mpathd
0N/A# will always be started explicitly from /etc/init.d/inetinit, when we're
0N/A# sure that /usr is mounted.
0N/A#
0N/ASUNW_NO_MPATHD=; export SUNW_NO_MPATHD
0N/A
0N/Asmf_netstrategy
0N/A
0N/A#
0N/A# Bring up link aggregations
0N/A#
0N/A/sbin/dladm up-aggr
0N/A
0N/A#
0N/A# If the system was net booted by DHCP, hand DHCP management off to the
0N/A# DHCP agent (ifconfig communicates to the DHCP agent through the
0N/A# loopback interface).
4138N/A#
0N/Aif [ -n "$_INIT_NET_IF" -a "$_INIT_NET_STRATEGY" = "dhcp" ]; then
0N/A /sbin/dhcpagent -a
0N/Afi
0N/A
4138N/A#
4138N/A# The network initialization is done early to support diskless and
4138N/A# dataless configurations. For IPv4 interfaces that were configured by
4138N/A# the kernel (e.g. those on diskless machines) and not configured by
4138N/A# DHCP, reset the netmask using the local "/etc/netmasks" file if one
4138N/A# exists, and then reset the broadcast address based on the netmask.
4138N/A#
4138N/A/sbin/ifconfig -auD4 netmask + broadcast +
4138N/A
4138N/A#
4138N/A# All the IPv4 and IPv6 interfaces are plumbed before doing any
4138N/A# interface configuration. This prevents errors from plumb failures
4138N/A# getting mixed in with the configured interface lists that the script
4138N/A# outputs.
4138N/A#
4138N/A
4138N/A#
4138N/A# Get the list of IPv4 interfaces to configure by breaking
4138N/A# /etc/hostname.* into separate args by using "." as a shell separator
4138N/A# character.
4138N/A#
4138N/Ainterface_names="`echo /etc/hostname.*[0-9] 2>/dev/null`"
4138N/Aif [ "$interface_names" != "/etc/hostname.*[0-9]" ]; then
4138N/A ORIGIFS="$IFS"
4138N/A IFS="$IFS."
4138N/A set -- $interface_names
0N/A IFS="$ORIGIFS"
0N/A while [ $# -ge 2 ]; do
0N/A shift
0N/A if [ "$1" = "xx0" ]; then
0N/A #
0N/A # For some unknown historical reason the xx0
0N/A # ifname is ignored.
0N/A #
0N/A shift
0N/A continue
0N/A fi
0N/A if [ $# -gt 1 -a "$2" != "/etc/hostname" ]; then
0N/A while [ $# -gt 1 -a "$1" != "/etc/hostname" ]; do
0N/A shift
0N/A done
0N/A else
0N/A inet_list="$inet_list $1"
0N/A shift
0N/A fi
0N/A done
0N/Afi
0N/A
0N/A#
0N/A# Get the list of IPv6 interfaces to configure by breaking
0N/A# /etc/hostname6.* into separate args by using "." as a shell separator
0N/A# character.
0N/A#
0N/Ainterface_names="`echo /etc/hostname6.*[0-9] 2>/dev/null`"
0N/Aif [ "$interface_names" != "/etc/hostname6.*[0-9]" ]; then
0N/A ORIGIFS="$IFS"
0N/A IFS="$IFS."
0N/A set -- $interface_names
0N/A IFS="$ORIGIFS"
0N/A while [ $# -ge 2 ]; do
0N/A shift
0N/A if [ $# -gt 1 -a "$2" != "/etc/hostname6" ]; then
0N/A while [ $# -gt 1 -a "$1" != "/etc/hostname6" ]; do
0N/A shift
0N/A done
0N/A else
0N/A inet6_list="$inet6_list $1"
0N/A shift
0N/A fi
0N/A done
0N/Afi
0N/A
0N/A
0N/A#
0N/A# Step through the IPv4 interface list and try to plumb every interface.
0N/A# Generate list of plumbed and failed IPv4 interfaces.
0N/A#
0N/Aif [ -n "$inet_list" ]; then
0N/A set -- $inet_list
0N/A while [ $# -gt 0 ]; do
0N/A /sbin/ifconfig $1 plumb
0N/A if /sbin/ifconfig $1 inet >/dev/null 2>&1; then
0N/A inet_plumbed="$inet_plumbed $1"
0N/A else
0N/A inet_failed="$inet_failed $1"
0N/A fi
0N/A shift
0N/A done
0N/A [ -n "$inet_failed" ] && warn_failed_ifs "plumb IPv4" $inet_failed
0N/Afi
0N/A
0N/A# Run autoconf to connect to a WLAN if the interface is a wireless one
0N/Aif [ -x /sbin/wificonfig -a -n "$inet_plumbed" ]; then
0N/A set -- $inet_plumbed
0N/A while [ $# -gt 0 ]; do
0N/A if [ -r /dev/wifi/$1 ]; then
0N/A /sbin/wificonfig -i $1 startconf >/dev/null
0N/A fi
0N/A shift
0N/A done
0N/Afi
0N/A
0N/A#
0N/A# Step through the IPv6 interface list and plumb every interface.
0N/A# Generate list of plumbed and failed IPv6 interfaces. Each plumbed
0N/A# interface will be brought up later, after processing any contents of
0N/A# the /etc/hostname6.* file.
0N/A#
0N/Aif [ -n "$inet6_list" ]; then
0N/A set -- $inet6_list
0N/A while [ $# -gt 0 ]; do
0N/A /sbin/ifconfig $1 inet6 plumb
0N/A if /sbin/ifconfig $1 inet6 >/dev/null 2>&1; then
0N/A inet6_plumbed="$inet6_plumbed $1"
0N/A else
0N/A inet6_failed="$inet6_failed $1"
0N/A fi
0N/A shift
0N/A done
0N/A [ -n "$inet6_failed" ] && warn_failed_ifs "plumb IPv6" $inet6_failed
0N/Afi
0N/A
0N/A#
0N/A# Process the /etc/hostname.* files of plumbed IPv4 interfaces. If an
0N/A# /etc/hostname file is not present or is empty, the ifconfig auto-dhcp
0N/A# / auto-revarp command will attempt to set the address, later.
0N/A#
0N/A# If /etc/hostname.lo0 exists the loop below will do additional
0N/A# configuration of lo0.
0N/A#
0N/Aif [ -n "$inet_plumbed" ]; then
0N/A i4s_fail=
0N/A echo "configuring IPv4 interfaces:\c"
0N/A set -- $inet_plumbed
0N/A while [ $# -gt 0 ]; do
0N/A inet_process_hostname /sbin/ifconfig $1 inet \
0N/A </etc/hostname.$1 >/dev/null
0N/A [ $? != 0 ] && i4s_fail="$i4s_fail $1"
0N/A echo " $1\c"
0N/A shift
0N/A done
0N/A echo "."
0N/A [ -n "$i4s_fail" ] && warn_failed_ifs "configure IPv4" $i4s_fail
0N/Afi
0N/A
0N/A#
0N/A# Process the /etc/hostname6.* files of plumbed IPv6 interfaces. After
0N/A# processing the hostname6 file, bring the interface up. If
0N/A# /etc/hostname6.lo0 exists the loop below will do additional
0N/A# configuration of lo0.
0N/A#
0N/Aif [ -n "$inet6_plumbed" ]; then
0N/A i6_fail=
0N/A echo "configuring IPv6 interfaces:\c"
0N/A set -- $inet6_plumbed
0N/A while [ $# -gt 0 ]; do
0N/A inet6_process_hostname /sbin/ifconfig $1 inet6 \
0N/A </etc/hostname6.$1 >/dev/null &&
0N/A /sbin/ifconfig $1 inet6 up
0N/A [ $? != 0 ] && i6_fail="$i6_fail $1"
0N/A echo " $1\c"
0N/A shift
0N/A done
0N/A echo "."
0N/A [ -n "$i6_fail" ] && warn_failed_ifs "configure IPv6" $i6_fail
0N/Afi
0N/A
0N/A# Run DHCP if requested. Skip boot-configured interface.
0N/Ainterface_names="`echo /etc/dhcp.*[0-9] 2>/dev/null`"
0N/Aif [ "$interface_names" != '/etc/dhcp.*[0-9]' ]; then
0N/A #
0N/A # First find the primary interface. Default to the first
# interface if not specified. First primary interface found
# "wins". Use care not to "reconfigure" a net-booted interface
# configured using DHCP. Run through the list of interfaces
# again, this time trying DHCP.
#
i4d_fail=
firstif=
primary=
ORIGIFS="$IFS"
IFS="${IFS}."
set -- $interface_names
while [ $# -ge 2 ]; do
shift
[ -z "$firstif" ] && firstif=$1
for i in `shcat /etc/dhcp\.$1`; do
if [ "$i" = primary ]; then
primary=$1
break
fi
done
[ -n "$primary" ] && break
shift
done
[ -z "$primary" ] && primary="$firstif"
cmdline=`shcat /etc/dhcp\.${primary}`
if [ "$_INIT_NET_IF" != "$primary" ]; then
echo "starting DHCP on primary interface $primary"
/sbin/ifconfig $primary auto-dhcp primary $cmdline
# Exit code 4 means ifconfig timed out waiting for dhcpagent
[ $? != 0 ] && [ $? != 4 ] && i4d_fail="$i4d_fail $primary"
fi
set -- $interface_names
while [ $# -ge 2 ]; do
shift
cmdline=`shcat /etc/dhcp\.$1`
if [ "$1" != "$primary" -a \
"$1" != "$_INIT_NET_IF" ]; then
echo "starting DHCP on interface $1"
/sbin/ifconfig $1 dhcp start wait 0 $cmdline
# Exit code can't be timeout when wait is 0
[ $? != 0 ] && i4d_fail="$i4d_fail $1"
fi
shift
done
IFS="$ORIGIFS"
unset ORIGIFS
[ -n "$i4d_fail" ] && warn_failed_ifs "configure IPv4 DHCP" $i4d_fail
fi
# In order to avoid bringing up the interfaces that have
# intentionally been left down, perform RARP only if the system
# has no configured hostname in /etc/nodename
hostname="`shcat /etc/nodename 2>/dev/null`"
if [ "$_INIT_NET_STRATEGY" = "rarp" -o -z "$hostname" ]; then
/sbin/ifconfig -adD4 auto-revarp netmask + broadcast + up
fi
#
# Process IPv4 and IPv6 interfaces that failed to plumb. Find an
# alternative interface to host the addresses.
#
[ -n "$inet_failed" ] && move_addresses inet
[ -n "$inet6_failed" ] && move_addresses inet6
#
# If the /etc/defaultrouter file exists, process it now so that the next
# stage of booting will have access to NFS.
#
if [ -f /etc/defaultrouter ]; then
while read router rubbish; do
case "$router" in
'#'* | '') ;; # Ignore comments, empty lines
*) /sbin/route -n add default -gateway $router ;;
esac
done </etc/defaultrouter
fi
#
# We tell smf this service is online if any of the following is true:
# - no interfaces were configured for plumbing and no DHCP failures
# - any non-loopback IPv4 interfaces are up and have a non-zero address
# - there are any DHCP interfaces started
# - any non-loopback IPv6 interfaces are up
#
# If we weren't asked to configure any interfaces, exit
if [ -z "$inet_list" ] && [ -z "$inet6_list" ]; then
# Config error if DHCP was attempted without plumbed interfaces
[ -n "$i4d_fail" ] && exit $SMF_EXIT_ERR_CONFIG
exit $SMF_EXIT_OK
fi
# Any non-loopback IPv4 interfaces with usable addresses up?
if [ -n "`/sbin/ifconfig -a4u`" ]; then
/sbin/ifconfig -a4u | while read intf addr rest; do
[ $intf = inet ] && [ $addr != 127.0.0.1 ] &&
[ $addr != 0.0.0.0 ] && exit 0
done && exit $SMF_EXIT_OK
fi
# Any DHCP interfaces started?
[ -n "`/sbin/ifconfig -a4 dhcp status 2>/dev/null`" ] && exit $SMF_EXIT_OK
# Any non-loopback IPv6 interfaces up?
if [ -n "`/sbin/ifconfig -au6`" ]; then
/sbin/ifconfig -au6 | while read intf addr rest; do
[ $intf = inet6 ] && [ $addr != ::1/128 ] && exit 0
done && exit $SMF_EXIT_OK
fi
# This service was supposed to configure something yet didn't. Exit
# with config error.
exit $SMF_EXIT_ERR_CONFIG