17c478bd9Sstevel@tonic-gate#!/sbin/sh
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
66927f468Sdp# Common Development and Distribution License (the "License").
76927f468Sdp# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
22a73be61aSHans Rosenfeld
237c478bd9Sstevel@tonic-gate#
247c478bd9Sstevel@tonic-gate# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T.
257c478bd9Sstevel@tonic-gate# All rights reserved.
26a73be61aSHans Rosenfeld# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
27a73be61aSHans Rosenfeld# Copyright 2012 Milan Jurik. All rights reserved.
28a73be61aSHans Rosenfeld# Copyright 2021 Tintri by DDN, Inc. All rights reserved.
297c478bd9Sstevel@tonic-gate#
30*faa2068dSAndy Fiddaman# Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
317c478bd9Sstevel@tonic-gate
326927f468Sdp. /lib/svc/share/smf_include.sh
336927f468Sdp. /lib/svc/share/net_include.sh
346927f468Sdp
357c478bd9Sstevel@tonic-gate#
36f4b3ec61Sdh# In a shared-IP zone we need this service to be up, but all of the work
37a73be61aSHans Rosenfeld# it tries to do is irrelevant (and will actually lead to the service
38a73be61aSHans Rosenfeld# failing if we try to do it), so just bail out.
39f4b3ec61Sdh# In the global zone and exclusive-IP zones we proceed.
407c478bd9Sstevel@tonic-gate#
41f4b3ec61Sdhsmf_configure_ip || exit $SMF_EXIT_OK
427c478bd9Sstevel@tonic-gate
437c478bd9Sstevel@tonic-gate# Make sure that the libraries essential to this stage of booting can be found.
447c478bd9Sstevel@tonic-gateLD_LIBRARY_PATH=/lib; export LD_LIBRARY_PATH
457c478bd9Sstevel@tonic-gate
467c478bd9Sstevel@tonic-gatesmf_netstrategy
477c478bd9Sstevel@tonic-gate
48f4b3ec61Sdhif smf_is_globalzone; then
49d62bc4baSyz	net_reconfigure || exit $SMF_EXIT_ERR_CONFIG
50d62bc4baSyz
514eaa4710SRishi Srivatsavai	# Update PVID on interfaces configured with VLAN 1
524eaa4710SRishi Srivatsavai	update_pvid
534eaa4710SRishi Srivatsavai
54a73be61aSHans Rosenfeld	#
55bbf21555SRichard Lowe	# Upgrade handling. The upgrade file consists of a series of dladm(8)
56d62bc4baSyz	# commands. Note that after we are done, we cannot rename the upgrade
57d62bc4baSyz	# script file as the file system is still read-only at this point.
58d62bc4baSyz	# Defer this to the manifest-import service.
59d62bc4baSyz	#
60d62bc4baSyz	upgrade_script=/var/svc/profile/upgrade_datalink
61a73be61aSHans Rosenfeld	if [ -f "${upgrade_script}" ]; then
62d62bc4baSyz		. "${upgrade_script}"
63d62bc4baSyz	fi
64d62bc4baSyz
651cfa752fSRamaswamy Tummala	#
661cfa752fSRamaswamy Tummala	# Upgrade handling for ibd:
671cfa752fSRamaswamy Tummala	# After we are done with the upgrade handling, we can not set the
681cfa752fSRamaswamy Tummala	# ibd/ibd_upgraded property to "true" as the file system is
691cfa752fSRamaswamy Tummala	# read-only at this point. It will be done later by ibd-post-upgrade
701cfa752fSRamaswamy Tummala	# service.
711cfa752fSRamaswamy Tummala	#
7212c67a59SMilan Jurik	if [ -x /sbin/ibd_upgrade ]; then
7312c67a59SMilan Jurik		ibd_upgraded=`/bin/svcprop -c -p ibd/ibd_upgraded \
7412c67a59SMilan Jurik		    $SMF_FMRI 2> /dev/null`
7512c67a59SMilan Jurik		if [ "$ibd_upgraded" != "true" ]; then
7612c67a59SMilan Jurik			/sbin/ibd_upgrade -v
7712c67a59SMilan Jurik		fi
781cfa752fSRamaswamy Tummala	fi
791cfa752fSRamaswamy Tummala
80f4b3ec61Sdh	#
81b509e89bSRishi Srivatsavai	# Bring up simnets, link aggregations and initialize security objects.
82f4b3ec61Sdh	# Note that link property initialization is deferred until after
83f4b3ec61Sdh	# IP interfaces are plumbed to ensure that the links will not
84b509e89bSRishi Srivatsavai	# be unloaded (and the property settings lost). We should bring
85b509e89bSRishi Srivatsavai	# up simnets prior to VLANs/Aggrs to enable creation of VLANs/Aggrs
86b509e89bSRishi Srivatsavai	# over simnets.
87f4b3ec61Sdh	#
88b509e89bSRishi Srivatsavai	/sbin/dladm up-simnet
89f4b3ec61Sdh	/sbin/dladm up-aggr
90d62bc4baSyz	/sbin/dladm up-vlan
911cfa752fSRamaswamy Tummala	/sbin/dladm up-part
92f4b3ec61Sdh	/sbin/dladm init-secobj
93da14cebeSEric Cheng	#
94da14cebeSEric Cheng	# Bring up VNICs
95da14cebeSEric Cheng	#
96da14cebeSEric Cheng	/sbin/dladm up-vnic
97da14cebeSEric Cheng	#
98da14cebeSEric Cheng	# Create flows via flowadm.
99da14cebeSEric Cheng	#
100da14cebeSEric Cheng	/sbin/flowadm init-flow
101*faa2068dSAndy Fiddaman	#
102*faa2068dSAndy Fiddaman	# Bring up overlays
103*faa2068dSAndy Fiddaman	# Note that there may be VNICs configured over these overlays but
104*faa2068dSAndy Fiddaman	# these cannot be brought up until the network interface on which
105*faa2068dSAndy Fiddaman	# varpd will listen is enabled, and that doesn't happen until
106*faa2068dSAndy Fiddaman	# near the end of this script. Therefore VNIC initialisation is
107*faa2068dSAndy Fiddaman	# repeated below if overlays are present.
108*faa2068dSAndy Fiddaman	#
109*faa2068dSAndy Fiddaman	/sbin/dladm up-overlay
110f4b3ec61Sdhfi
111210db224Sericheng
1127c478bd9Sstevel@tonic-gate#
1137c478bd9Sstevel@tonic-gate# If the system was net booted by DHCP, hand DHCP management off to the
1147c478bd9Sstevel@tonic-gate# DHCP agent (ifconfig communicates to the DHCP agent through the
1157c478bd9Sstevel@tonic-gate# loopback interface).
1167c478bd9Sstevel@tonic-gate#
1177c478bd9Sstevel@tonic-gateif [ -n "$_INIT_NET_IF" -a "$_INIT_NET_STRATEGY" = "dhcp" ]; then
1187c478bd9Sstevel@tonic-gate	/sbin/dhcpagent -a
1197c478bd9Sstevel@tonic-gatefi
1207c478bd9Sstevel@tonic-gate
1217c478bd9Sstevel@tonic-gate#
1227c478bd9Sstevel@tonic-gate# The network initialization is done early to support diskless and
1237c478bd9Sstevel@tonic-gate# dataless configurations.  For IPv4 interfaces that were configured by
1247c478bd9Sstevel@tonic-gate# the kernel (e.g.  those on diskless machines) and not configured by
1257c478bd9Sstevel@tonic-gate# DHCP, reset the netmask using the local "/etc/netmasks" file if one
1267c478bd9Sstevel@tonic-gate# exists, and then reset the broadcast address based on the netmask.
1277c478bd9Sstevel@tonic-gate#
1287c478bd9Sstevel@tonic-gate/sbin/ifconfig -auD4 netmask + broadcast +
1297c478bd9Sstevel@tonic-gate
1302b24ab6bSSebastien Royis_iptun ()
1312b24ab6bSSebastien Roy{
1322b24ab6bSSebastien Roy	intf=$1
1332b24ab6bSSebastien Roy	# Is this a persistent IP tunnel link?
1342b24ab6bSSebastien Roy	/sbin/dladm show-iptun -P $intf > /dev/null 2>&1
1352b24ab6bSSebastien Roy	if [ $? -eq 0 ]; then
1362b24ab6bSSebastien Roy		return 0
1372b24ab6bSSebastien Roy	fi
1382b24ab6bSSebastien Roy	# Is this an implicit IP tunnel (i.e., ip.tun0)
1392b24ab6bSSebastien Roy	ORIGIFS="$IFS"
1402b24ab6bSSebastien Roy	IFS="$IFS."
1412b24ab6bSSebastien Roy	set -- $intf
1422b24ab6bSSebastien Roy	IFS="$ORIGIFS"
1432b24ab6bSSebastien Roy	if [ $# -eq 2 -a \( "$1" = "ip" -o "$1" = "ip6" \) ]; then
1442b24ab6bSSebastien Roy		#
1452b24ab6bSSebastien Roy		# It looks like one, but another type of link might be
1462b24ab6bSSebastien Roy		# using a name that looks like an implicit IP tunnel.
1472b24ab6bSSebastien Roy		# If dladm show-link -P finds it, then it's not an IP
1482b24ab6bSSebastien Roy		# tunnel.
1492b24ab6bSSebastien Roy		#
1502b24ab6bSSebastien Roy		/sbin/dladm show-link -Pp $intf > /dev/null 2>&1
1512b24ab6bSSebastien Roy		if [ $? -eq 0 ]; then
1522b24ab6bSSebastien Roy			return 1
1532b24ab6bSSebastien Roy		else
1542b24ab6bSSebastien Roy			return 0
1552b24ab6bSSebastien Roy		fi
1562b24ab6bSSebastien Roy	fi
1572b24ab6bSSebastien Roy	return 1
1582b24ab6bSSebastien Roy}
1592b24ab6bSSebastien Roy
160*faa2068dSAndy Fiddamanbringup_ipif()
161*faa2068dSAndy Fiddaman{
162*faa2068dSAndy Fiddaman	for showif_output in `\
163*faa2068dSAndy Fiddaman	    /sbin/ipadm show-if -p -o ifname,state,current`; do
164*faa2068dSAndy Fiddaman		intf=`echo $showif_output | /usr/bin/cut -f1 -d:`
165*faa2068dSAndy Fiddaman		state=`echo $showif_output | /usr/bin/cut -f2 -d:`
166*faa2068dSAndy Fiddaman		current=`echo $showif_output | /usr/bin/cut -f3 -d:`
167*faa2068dSAndy Fiddaman		if  [[ "$state" != "disabled" && $current != *Z* ]]; then
168*faa2068dSAndy Fiddaman			#
169*faa2068dSAndy Fiddaman			# skip if not a persistent interface, or if it should
170*faa2068dSAndy Fiddaman			# get IP configuration from the global zone ('Z' flag
171*faa2068dSAndy Fiddaman			# is set)
172*faa2068dSAndy Fiddaman			#
173*faa2068dSAndy Fiddaman			continue;
174*faa2068dSAndy Fiddaman		elif is_iptun $intf; then
175*faa2068dSAndy Fiddaman			# skip IP tunnel interfaces plumbed by net-iptun
176*faa2068dSAndy Fiddaman			continue;
177*faa2068dSAndy Fiddaman		elif [ -f /etc/hostname.$intf ] || \
178*faa2068dSAndy Fiddaman		    [ -f /etc/hostname6.$intf ]; then
179*faa2068dSAndy Fiddaman			if [[ $current != *Z* ]]; then
180*faa2068dSAndy Fiddaman				echo "found /etc/hostname.$intf "\
181*faa2068dSAndy Fiddaman				    "or /etc/hostname6.$intf, "\
182*faa2068dSAndy Fiddaman				    "ignoring ipadm configuration" > /dev/msglog
183*faa2068dSAndy Fiddaman				continue;
184*faa2068dSAndy Fiddaman			else
185*faa2068dSAndy Fiddaman				echo "Ignoring /etc/hostname*.$intf" \
186*faa2068dSAndy Fiddaman				    > /dev/msglog
187*faa2068dSAndy Fiddaman				{
188*faa2068dSAndy Fiddaman					/sbin/ifconfig $intf unplumb
189*faa2068dSAndy Fiddaman					/sbin/ifconfig $intf inet6 unplumb
190*faa2068dSAndy Fiddaman				} > /dev/null 2>&1
191*faa2068dSAndy Fiddaman			fi
192*faa2068dSAndy Fiddaman		fi
193*faa2068dSAndy Fiddaman
194*faa2068dSAndy Fiddaman		# Enable the interface managed by ipadm
195*faa2068dSAndy Fiddaman		/sbin/ipadm enable-if -t $intf
196*faa2068dSAndy Fiddaman	done
197*faa2068dSAndy Fiddaman}
198*faa2068dSAndy Fiddaman
1997c478bd9Sstevel@tonic-gate#
2007c478bd9Sstevel@tonic-gate# All the IPv4 and IPv6 interfaces are plumbed before doing any
2017c478bd9Sstevel@tonic-gate# interface configuration.  This prevents errors from plumb failures
2027c478bd9Sstevel@tonic-gate# getting mixed in with the configured interface lists that the script
2037c478bd9Sstevel@tonic-gate# outputs.
2047c478bd9Sstevel@tonic-gate#
2057c478bd9Sstevel@tonic-gate
2066e91bba0SGirish Moodalbail#
2076e91bba0SGirish Moodalbail# First deal with /etc/hostname
2087c478bd9Sstevel@tonic-gate#
2097c478bd9Sstevel@tonic-gate# Get the list of IPv4 interfaces to configure by breaking
2107c478bd9Sstevel@tonic-gate# /etc/hostname.* into separate args by using "." as a shell separator
2117c478bd9Sstevel@tonic-gate# character.
2127c478bd9Sstevel@tonic-gate#
2137c478bd9Sstevel@tonic-gateinterface_names="`echo /etc/hostname.*[0-9] 2>/dev/null`"
2147c478bd9Sstevel@tonic-gateif [ "$interface_names" != "/etc/hostname.*[0-9]" ]; then
2157c478bd9Sstevel@tonic-gate	ORIGIFS="$IFS"
2167c478bd9Sstevel@tonic-gate	IFS="$IFS."
2177c478bd9Sstevel@tonic-gate	set -- $interface_names
2187c478bd9Sstevel@tonic-gate	IFS="$ORIGIFS"
2197c478bd9Sstevel@tonic-gate	while [ $# -ge 2 ]; do
2207c478bd9Sstevel@tonic-gate		shift
221e11c3f44Smeem		intf_name=$1
222e11c3f44Smeem		while [ $# -gt 1 -a "$2" != "/etc/hostname" ]; do
223e11c3f44Smeem			intf_name="$intf_name.$2"
2247c478bd9Sstevel@tonic-gate			shift
225e11c3f44Smeem		done
226e11c3f44Smeem		shift
227e11c3f44Smeem
2282b24ab6bSSebastien Roy		# skip IP tunnel interfaces plumbed by net-iptun.
2292b24ab6bSSebastien Roy		if is_iptun $intf_name; then
2302b24ab6bSSebastien Roy			continue
2312b24ab6bSSebastien Roy		fi
2322b24ab6bSSebastien Roy
233e11c3f44Smeem	        read one rest < /etc/hostname.$intf_name
234e11c3f44Smeem		if [ "$one" = ipmp ]; then
235e11c3f44Smeem			ipmp_list="$ipmp_list $intf_name"
236e11c3f44Smeem		else
237e11c3f44Smeem			inet_list="$inet_list $intf_name"
2387c478bd9Sstevel@tonic-gate		fi
2397c478bd9Sstevel@tonic-gate	done
2407c478bd9Sstevel@tonic-gatefi
2417c478bd9Sstevel@tonic-gate
2427c478bd9Sstevel@tonic-gate#
2437c478bd9Sstevel@tonic-gate# Get the list of IPv6 interfaces to configure by breaking
2447c478bd9Sstevel@tonic-gate# /etc/hostname6.* into separate args by using "." as a shell separator
2457c478bd9Sstevel@tonic-gate# character.
2467c478bd9Sstevel@tonic-gate#
2477c478bd9Sstevel@tonic-gateinterface_names="`echo /etc/hostname6.*[0-9] 2>/dev/null`"
2487c478bd9Sstevel@tonic-gateif [ "$interface_names" != "/etc/hostname6.*[0-9]" ]; then
2497c478bd9Sstevel@tonic-gate	ORIGIFS="$IFS"
2507c478bd9Sstevel@tonic-gate	IFS="$IFS."
2517c478bd9Sstevel@tonic-gate	set -- $interface_names
2527c478bd9Sstevel@tonic-gate	IFS="$ORIGIFS"
2537c478bd9Sstevel@tonic-gate	while [ $# -ge 2 ]; do
2547c478bd9Sstevel@tonic-gate		shift
255e11c3f44Smeem		intf_name=$1
256e11c3f44Smeem		while [ $# -gt 1 -a "$2" != "/etc/hostname6" ]; do
257e11c3f44Smeem			intf_name="$intf_name.$2"
2587c478bd9Sstevel@tonic-gate			shift
259e11c3f44Smeem		done
260e11c3f44Smeem		shift
261e11c3f44Smeem
2622b24ab6bSSebastien Roy		# skip IP tunnel interfaces plumbed by net-iptun.
2632b24ab6bSSebastien Roy		if is_iptun $intf_name; then
2642b24ab6bSSebastien Roy			continue
2652b24ab6bSSebastien Roy		fi
2662b24ab6bSSebastien Roy
267e11c3f44Smeem	        read one rest < /etc/hostname6.$intf_name
268e11c3f44Smeem		if [ "$one" = ipmp ]; then
269e11c3f44Smeem			ipmp6_list="$ipmp6_list $intf_name"
270e11c3f44Smeem		else
271e11c3f44Smeem			inet6_list="$inet6_list $intf_name"
2727c478bd9Sstevel@tonic-gate		fi
2737c478bd9Sstevel@tonic-gate	done
2747c478bd9Sstevel@tonic-gatefi
2757c478bd9Sstevel@tonic-gate
276e11c3f44Smeem#
277e11c3f44Smeem# Create all of the IPv4 IPMP interfaces.
278e11c3f44Smeem#
279e11c3f44Smeemif [ -n "$ipmp_list" ]; then
280e11c3f44Smeem	set -- $ipmp_list
281e11c3f44Smeem	while [ $# -gt 0 ]; do
282a73be61aSHans Rosenfeld		if /sbin/ifconfig $1 ipmp; then
283e11c3f44Smeem			ipmp_created="$ipmp_created $1"
284e11c3f44Smeem		else
285e11c3f44Smeem			ipmp_failed="$ipmp_failed $1"
286a73be61aSHans Rosenfeld		fi
287e11c3f44Smeem		shift
288e11c3f44Smeem	done
289e11c3f44Smeem	[ -n "$ipmp_failed" ] && warn_failed_ifs "create IPv4 IPMP" \
290e11c3f44Smeem	    "$ipmp_failed"
291e11c3f44Smeemfi
2927c478bd9Sstevel@tonic-gate
2937c478bd9Sstevel@tonic-gate#
2947c478bd9Sstevel@tonic-gate# Step through the IPv4 interface list and try to plumb every interface.
2957c478bd9Sstevel@tonic-gate# Generate list of plumbed and failed IPv4 interfaces.
2967c478bd9Sstevel@tonic-gate#
2977c478bd9Sstevel@tonic-gateif [ -n "$inet_list" ]; then
2987c478bd9Sstevel@tonic-gate	set -- $inet_list
2997c478bd9Sstevel@tonic-gate	while [ $# -gt 0 ]; do
3007c478bd9Sstevel@tonic-gate		/sbin/ifconfig $1 plumb
3017c478bd9Sstevel@tonic-gate		if /sbin/ifconfig $1 inet >/dev/null 2>&1; then
3027c478bd9Sstevel@tonic-gate			inet_plumbed="$inet_plumbed $1"
3037c478bd9Sstevel@tonic-gate		else
3047c478bd9Sstevel@tonic-gate			inet_failed="$inet_failed $1"
3057c478bd9Sstevel@tonic-gate		fi
3067c478bd9Sstevel@tonic-gate		shift
3077c478bd9Sstevel@tonic-gate	done
308e11c3f44Smeem	[ -n "$inet_failed" ] && warn_failed_ifs "plumb IPv4" "$inet_failed"
3097c478bd9Sstevel@tonic-gatefi
3107c478bd9Sstevel@tonic-gate
311516fc7f3Shx# Run autoconf to connect to a WLAN if the interface is a wireless one
312516fc7f3Shxif [ -x /sbin/wificonfig -a -n "$inet_plumbed" ]; then
313516fc7f3Shx	set -- $inet_plumbed
314516fc7f3Shx	while [ $# -gt 0 ]; do
315516fc7f3Shx			if [ -r /dev/wifi/$1 ]; then
316516fc7f3Shx				/sbin/wificonfig -i $1 startconf >/dev/null
317516fc7f3Shx			fi
318516fc7f3Shx		shift
319516fc7f3Shx	done
320516fc7f3Shxfi
321516fc7f3Shx
3227c478bd9Sstevel@tonic-gate#
3237c478bd9Sstevel@tonic-gate# Step through the IPv6 interface list and plumb every interface.
3247c478bd9Sstevel@tonic-gate# Generate list of plumbed and failed IPv6 interfaces.  Each plumbed
3257c478bd9Sstevel@tonic-gate# interface will be brought up later, after processing any contents of
3267c478bd9Sstevel@tonic-gate# the /etc/hostname6.* file.
3277c478bd9Sstevel@tonic-gate#
3287c478bd9Sstevel@tonic-gateif [ -n "$inet6_list" ]; then
3297c478bd9Sstevel@tonic-gate	set -- $inet6_list
3307c478bd9Sstevel@tonic-gate	while [ $# -gt 0 ]; do
3317c478bd9Sstevel@tonic-gate		/sbin/ifconfig $1 inet6 plumb
3327c478bd9Sstevel@tonic-gate		if /sbin/ifconfig $1 inet6 >/dev/null 2>&1; then
3337c478bd9Sstevel@tonic-gate			inet6_plumbed="$inet6_plumbed $1"
3347c478bd9Sstevel@tonic-gate		else
3357c478bd9Sstevel@tonic-gate			inet6_failed="$inet6_failed $1"
3367c478bd9Sstevel@tonic-gate		fi
3377c478bd9Sstevel@tonic-gate		shift
3387c478bd9Sstevel@tonic-gate	done
339e11c3f44Smeem	[ -n "$inet6_failed" ] && warn_failed_ifs "plumb IPv6" "$inet6_failed"
340e11c3f44Smeemfi
341e11c3f44Smeem
342e11c3f44Smeem#
343e11c3f44Smeem# Create all of the IPv6 IPMP interfaces.
344e11c3f44Smeem#
345e11c3f44Smeemif [ -n "$ipmp6_list" ]; then
346e11c3f44Smeem	set -- $ipmp6_list
347e11c3f44Smeem	while [ $# -gt 0 ]; do
348a73be61aSHans Rosenfeld		if /sbin/ifconfig $1 inet6 ipmp; then
349e11c3f44Smeem			ipmp6_created="$ipmp6_created $1"
350e11c3f44Smeem		else
351e11c3f44Smeem			ipmp6_failed="$ipmp6_failed $1"
352a73be61aSHans Rosenfeld		fi
353e11c3f44Smeem		shift
354e11c3f44Smeem	done
355e11c3f44Smeem	[ -n "$ipmp6_failed" ] && warn_failed_ifs "create IPv6 IPMP" \
356e11c3f44Smeem	    "$ipmp6_failed"
3577c478bd9Sstevel@tonic-gatefi
3587c478bd9Sstevel@tonic-gate
359a73be61aSHans Rosenfeld#
360a73be61aSHans Rosenfeld# Upgrade ipadm.conf.
361a73be61aSHans Rosenfeld#
362a73be61aSHans Rosenfeldif /usr/bin/grep -q _family /etc/ipadm/ipadm.conf; then
363a73be61aSHans Rosenfeld	oldifs=$(/usr/bin/sed -En \
364*faa2068dSAndy Fiddaman	    's/^_ifname=([a-z0-9_]+);_family=[0-9]+;$/\1/p' \
365a73be61aSHans Rosenfeld	    /etc/ipadm/ipadm.conf | /usr/bin/sort -u)
366a73be61aSHans Rosenfeld	/usr/bin/sed -i '/_family/d' /etc/ipadm/ipadm.conf
367a73be61aSHans Rosenfeld	for oldif in $oldifs; do
368a73be61aSHans Rosenfeld		/usr/bin/printf \
369a73be61aSHans Rosenfeld		    "_ifname=%s;_ifclass=0;_families=2,26;\n" \
370a73be61aSHans Rosenfeld		    $oldif >> /etc/ipadm/ipadm.conf
371a73be61aSHans Rosenfeld	done
372a73be61aSHans Rosenfeldfi
373a73be61aSHans Rosenfeld
3746e91bba0SGirish Moodalbail#
375550b6e40SSowmini Varadhan# Finally configure interfaces set up with ipadm. Any /etc/hostname*.intf
376550b6e40SSowmini Varadhan# files take precedence over ipadm defined configurations except when
377550b6e40SSowmini Varadhan# we are in a non-global zone and Layer-3 protection of IP addresses is
378550b6e40SSowmini Varadhan# enforced on the interface by the global zone.
3796e91bba0SGirish Moodalbail#
380*faa2068dSAndy Fiddamanbringup_ipif
3816e91bba0SGirish Moodalbail
3827c478bd9Sstevel@tonic-gate#
383e11c3f44Smeem# Process the /etc/hostname[6].* files for IPMP interfaces.  Processing these
384e11c3f44Smeem# before non-IPMP interfaces avoids accidental implicit IPMP group creation.
385e11c3f44Smeem#
386e11c3f44Smeem[ -n "$ipmp_created" ] && if_configure inet "IPMP" $ipmp_created
387e11c3f44Smeem[ -n "$ipmp6_created" ] && if_configure inet6 "IPMP" $ipmp6_created
388e11c3f44Smeem
3897c478bd9Sstevel@tonic-gate#
390e11c3f44Smeem# Process the /etc/hostname[6].* files for non-IPMP interfaces.
3917c478bd9Sstevel@tonic-gate#
392e11c3f44Smeem[ -n "$inet_plumbed" ] && if_configure inet "" $inet_plumbed
393e11c3f44Smeem[ -n "$inet6_plumbed" ] && if_configure inet6 "" $inet6_plumbed
3947c478bd9Sstevel@tonic-gate
3957c478bd9Sstevel@tonic-gate#
396e11c3f44Smeem# For the IPv4 and IPv6 interfaces that failed to plumb, find (or create)
397e11c3f44Smeem# IPMP meta-interfaces to host their data addresses.
3987c478bd9Sstevel@tonic-gate#
399e11c3f44Smeem[ -n "$inet_failed" ] && move_addresses inet
400e11c3f44Smeem[ -n "$inet6_failed" ] && move_addresses inet6
4017c478bd9Sstevel@tonic-gate
4027c478bd9Sstevel@tonic-gate# Run DHCP if requested. Skip boot-configured interface.
4037c478bd9Sstevel@tonic-gateinterface_names="`echo /etc/dhcp.*[0-9] 2>/dev/null`"
4047c478bd9Sstevel@tonic-gateif [ "$interface_names" != '/etc/dhcp.*[0-9]' ]; then
4057c478bd9Sstevel@tonic-gate	#
4067c478bd9Sstevel@tonic-gate	# First find the primary interface. Default to the first
4077c478bd9Sstevel@tonic-gate	# interface if not specified. First primary interface found
4087c478bd9Sstevel@tonic-gate	# "wins". Use care not to "reconfigure" a net-booted interface
4097c478bd9Sstevel@tonic-gate	# configured using DHCP. Run through the list of interfaces
4107c478bd9Sstevel@tonic-gate	# again, this time trying DHCP.
4117c478bd9Sstevel@tonic-gate	#
4127c478bd9Sstevel@tonic-gate	i4d_fail=
4137c478bd9Sstevel@tonic-gate	firstif=
4147c478bd9Sstevel@tonic-gate	primary=
4157c478bd9Sstevel@tonic-gate	ORIGIFS="$IFS"
4167c478bd9Sstevel@tonic-gate	IFS="${IFS}."
4177c478bd9Sstevel@tonic-gate	set -- $interface_names
4187c478bd9Sstevel@tonic-gate
4197c478bd9Sstevel@tonic-gate	while [ $# -ge 2 ]; do
4207c478bd9Sstevel@tonic-gate		shift
4217c478bd9Sstevel@tonic-gate		[ -z "$firstif" ] && firstif=$1
4227c478bd9Sstevel@tonic-gate
4237c478bd9Sstevel@tonic-gate		for i in `shcat /etc/dhcp\.$1`; do
4247c478bd9Sstevel@tonic-gate			if [ "$i" = primary ]; then
4257c478bd9Sstevel@tonic-gate				primary=$1
4267c478bd9Sstevel@tonic-gate				break
4277c478bd9Sstevel@tonic-gate			fi
4287c478bd9Sstevel@tonic-gate		done
4297c478bd9Sstevel@tonic-gate
4307c478bd9Sstevel@tonic-gate		[ -n "$primary" ] && break
4317c478bd9Sstevel@tonic-gate		shift
4327c478bd9Sstevel@tonic-gate	done
4337c478bd9Sstevel@tonic-gate
4347c478bd9Sstevel@tonic-gate	[ -z "$primary" ] && primary="$firstif"
4357c478bd9Sstevel@tonic-gate	cmdline=`shcat /etc/dhcp\.${primary}`
4367c478bd9Sstevel@tonic-gate
4377c478bd9Sstevel@tonic-gate	if [ "$_INIT_NET_IF" != "$primary" ]; then
4387c478bd9Sstevel@tonic-gate		echo "starting DHCP on primary interface $primary"
4397c478bd9Sstevel@tonic-gate		/sbin/ifconfig $primary auto-dhcp primary $cmdline
4407c478bd9Sstevel@tonic-gate		# Exit code 4 means ifconfig timed out waiting for dhcpagent
441843e1988Sjohnlev		[ $? != 0 ] && [ $? != 4 ] && i4d_fail="$i4d_fail $primary"
4427c478bd9Sstevel@tonic-gate	fi
4437c478bd9Sstevel@tonic-gate
4447c478bd9Sstevel@tonic-gate	set -- $interface_names
4457c478bd9Sstevel@tonic-gate
4467c478bd9Sstevel@tonic-gate	while [ $# -ge 2 ]; do
4477c478bd9Sstevel@tonic-gate		shift
4487c478bd9Sstevel@tonic-gate		cmdline=`shcat /etc/dhcp\.$1`
4497c478bd9Sstevel@tonic-gate		if [ "$1" != "$primary" -a \
4507c478bd9Sstevel@tonic-gate			"$1" != "$_INIT_NET_IF"  ]; then
4517c478bd9Sstevel@tonic-gate			echo "starting DHCP on interface $1"
4527c478bd9Sstevel@tonic-gate			/sbin/ifconfig $1 dhcp start wait 0 $cmdline
4537c478bd9Sstevel@tonic-gate			# Exit code can't be timeout when wait is 0
4547c478bd9Sstevel@tonic-gate			[ $? != 0 ] && i4d_fail="$i4d_fail $1"
4557c478bd9Sstevel@tonic-gate		fi
4567c478bd9Sstevel@tonic-gate		shift
4577c478bd9Sstevel@tonic-gate	done
4587c478bd9Sstevel@tonic-gate	IFS="$ORIGIFS"
4597c478bd9Sstevel@tonic-gate	unset ORIGIFS
460e11c3f44Smeem	[ -n "$i4d_fail" ] && warn_failed_ifs "configure IPv4 DHCP" "$i4d_fail"
4617c478bd9Sstevel@tonic-gatefi
4627c478bd9Sstevel@tonic-gate
463*faa2068dSAndy Fiddaman# There is a chicken-and-egg problem with bringing up overlay VNICs at boot
464*faa2068dSAndy Fiddaman# time. When the first VNIC is added to an overlay, it creates a kernel socket
465*faa2068dSAndy Fiddaman# to listen for incoming encapsulated frames. Therefore, VNICs cannot be added
466*faa2068dSAndy Fiddaman# until after IP interfaces have been brought up. Overlay VNICs may themselves
467*faa2068dSAndy Fiddaman# have IP interfaces over them and so it is necessary to attempt to bring up
468*faa2068dSAndy Fiddaman# any remaining IP interfaces once the overlay VNICs are in place.
469*faa2068dSAndy Fiddamanif smf_is_globalzone && dladm show-link -p -o class | egrep -s 'overlay'; then
470*faa2068dSAndy Fiddaman	echo "Bringing up any remaining VNICs on overlays"
471*faa2068dSAndy Fiddaman	/sbin/dladm up-vnic
472*faa2068dSAndy Fiddaman	echo "Bringing up any remaining IP interfaces on overlay VNICs"
473*faa2068dSAndy Fiddaman	bringup_ipif
474*faa2068dSAndy Fiddamanfi
475*faa2068dSAndy Fiddaman
4760659b2b8Sse# In order to avoid bringing up the interfaces that have
4770659b2b8Sse# intentionally been left down, perform RARP only if the system
4780659b2b8Sse# has no configured hostname in /etc/nodename
4790659b2b8Ssehostname="`shcat /etc/nodename 2>/dev/null`"
4800659b2b8Sseif [ "$_INIT_NET_STRATEGY" = "rarp" -o -z "$hostname" ]; then
4810659b2b8Sse	/sbin/ifconfig -adD4 auto-revarp netmask + broadcast + up
4820659b2b8Ssefi
4837c478bd9Sstevel@tonic-gate
4847c478bd9Sstevel@tonic-gate#
4857c478bd9Sstevel@tonic-gate# If the /etc/defaultrouter file exists, process it now so that the next
4867c478bd9Sstevel@tonic-gate# stage of booting will have access to NFS.
4877c478bd9Sstevel@tonic-gate#
4887c478bd9Sstevel@tonic-gateif [ -f /etc/defaultrouter ]; then
4897c478bd9Sstevel@tonic-gate	while read router rubbish; do
4907c478bd9Sstevel@tonic-gate		case "$router" in
4917c478bd9Sstevel@tonic-gate			'#'* | '') ;;	#  Ignore comments, empty lines
4927c478bd9Sstevel@tonic-gate			*)	/sbin/route -n add default -gateway $router ;;
4937c478bd9Sstevel@tonic-gate		esac
4947c478bd9Sstevel@tonic-gate	done </etc/defaultrouter
4957c478bd9Sstevel@tonic-gatefi
4967c478bd9Sstevel@tonic-gate
497843e1988Sjohnlev#
498843e1988Sjohnlev# If we get here and were not asked to plumb any IPv4 interfaces, look
499843e1988Sjohnlev# for boot properties that direct us.
500843e1988Sjohnlev#
501843e1988Sjohnlev# - The "network-interface" property is required and indicates the
502843e1988Sjohnlev#   interface name.
503843e1988Sjohnlev# - The "xpv-hcp" property, if present, is used by the hypervisor
504843e1988Sjohnlev#   tools to indicate how the specified interface should be configured.
505843e1988Sjohnlev#   Permitted values are "dhcp" and "off", where "off" indicates static
506843e1988Sjohnlev#   IP configuration.
507843e1988Sjohnlev#
508843e1988Sjohnlev# In the case where "xpv-hcp" is set to "dhcp", no further properties
509843e1988Sjohnlev# are required or examined.
510843e1988Sjohnlev#
511843e1988Sjohnlev# In the case where "xpv-hcp" is not present or set to "off", the
512843e1988Sjohnlev# "host-ip" and "subnet-mask" properties are used to configure
513843e1988Sjohnlev# the specified interface.  The "router-ip" property, if present,
514843e1988Sjohnlev# is used to add a default route.
515843e1988Sjohnlev#
516843e1988Sjohnlevnic="`/sbin/devprop network-interface`"
517843e1988Sjohnlevif smf_is_globalzone && [ -z "$inet_list" ] && [ -n "$nic" ]; then
518843e1988Sjohnlev	hcp="`/sbin/devprop xpv-hcp`"
519843e1988Sjohnlev	case "$hcp" in
520843e1988Sjohnlev	"dhcp")
521843e1988Sjohnlev		/sbin/ifconfig $nic plumb 2>/dev/null
522843e1988Sjohnlev		[ -n "`/sbin/ifconfig $nic 2>/dev/null`" ] && (
523843e1988Sjohnlev			# The interface is successfully plumbed, so
524843e1988Sjohnlev			# modify "inet_list" to force the exit code
525843e1988Sjohnlev			# checks to work.
526843e1988Sjohnlev			inet_list=$nic;
527843e1988Sjohnlev			# Given that this is the only IPv4 interface,
528843e1988Sjohnlev			# we assert that it is primary.
529843e1988Sjohnlev			echo "starting DHCP on primary interface $primary";
530843e1988Sjohnlev			/sbin/ifconfig $nic auto-dhcp primary;
531843e1988Sjohnlev			# Exit code 4 means ifconfig timed out waiting
532843e1988Sjohnlev			# for dhcpagent
533843e1988Sjohnlev			[ $? != 0 ] && [ $? != 4 ] && \
534843e1988Sjohnlev			    i4d_fail="$i4d_fail $nic";
535843e1988Sjohnlev		)
536843e1988Sjohnlev		;;
537843e1988Sjohnlev
538843e1988Sjohnlev	"off"|"")
539843e1988Sjohnlev		/sbin/devprop host-ip subnet-mask router-ip | (
540843e1988Sjohnlev			read ip;
541843e1988Sjohnlev			read mask;
542843e1988Sjohnlev			read router;
543843e1988Sjohnlev			[ -n "$ip" ] && [ -n "$mask" ] && \
544843e1988Sjohnlev				/sbin/ifconfig $nic plumb 2>/dev/null
545843e1988Sjohnlev			[ -n "`/sbin/ifconfig $nic 2>/dev/null`" ] && (
546843e1988Sjohnlev				# The interface is successfully
547843e1988Sjohnlev				# plumbed, so modify "inet_list" to
548843e1988Sjohnlev				# force the exit code checks to work.
549843e1988Sjohnlev				inet_list=$nic;
550843e1988Sjohnlev				/sbin/ifconfig $nic  inet $ip \
551843e1988Sjohnlev				    netmask $mask broadcast + up 2>/dev/null;
552843e1988Sjohnlev				[ -n "$router" ] && route add \
553843e1988Sjohnlev				    default $router 2>/dev/null;
554843e1988Sjohnlev			)
555843e1988Sjohnlev		)
556843e1988Sjohnlev		;;
557843e1988Sjohnlev	esac
558843e1988Sjohnlevfi
559843e1988Sjohnlev
5607c478bd9Sstevel@tonic-gate#
5617c478bd9Sstevel@tonic-gate# We tell smf this service is online if any of the following is true:
5627c478bd9Sstevel@tonic-gate# - no interfaces were configured for plumbing and no DHCP failures
5637c478bd9Sstevel@tonic-gate# - any non-loopback IPv4 interfaces are up and have a non-zero address
5647c478bd9Sstevel@tonic-gate# - there are any DHCP interfaces started
5657c478bd9Sstevel@tonic-gate# - any non-loopback IPv6 interfaces are up
5667c478bd9Sstevel@tonic-gate#
5677c478bd9Sstevel@tonic-gate# If we weren't asked to configure any interfaces, exit
5687c478bd9Sstevel@tonic-gateif [ -z "$inet_list" ] && [ -z "$inet6_list" ]; then
5697c478bd9Sstevel@tonic-gate	# Config error if DHCP was attempted without plumbed interfaces
5707c478bd9Sstevel@tonic-gate	[ -n "$i4d_fail" ] && exit $SMF_EXIT_ERR_CONFIG
5717c478bd9Sstevel@tonic-gate	exit $SMF_EXIT_OK
5727c478bd9Sstevel@tonic-gatefi
5737c478bd9Sstevel@tonic-gate
5747c478bd9Sstevel@tonic-gate# Any non-loopback IPv4 interfaces with usable addresses up?
5757c478bd9Sstevel@tonic-gateif [ -n "`/sbin/ifconfig -a4u`" ]; then
576a73be61aSHans Rosenfeld	/sbin/ifconfig -a4u | while read intf addr rest; do
5777c478bd9Sstevel@tonic-gate		[ $intf = inet ] && [ $addr != 127.0.0.1 ] &&
578843e1988Sjohnlev		[ $addr != 0.0.0.0 ] && exit $SMF_EXIT_OK
5797c478bd9Sstevel@tonic-gate	done && exit $SMF_EXIT_OK
5807c478bd9Sstevel@tonic-gatefi
5817c478bd9Sstevel@tonic-gate
5827c478bd9Sstevel@tonic-gate# Any DHCP interfaces started?
5837c478bd9Sstevel@tonic-gate[ -n "`/sbin/ifconfig -a4 dhcp status 2>/dev/null`" ] && exit $SMF_EXIT_OK
5847c478bd9Sstevel@tonic-gate
5857c478bd9Sstevel@tonic-gate# Any non-loopback IPv6 interfaces up?
5867c478bd9Sstevel@tonic-gateif [ -n "`/sbin/ifconfig -au6`" ]; then
5877c478bd9Sstevel@tonic-gate	/sbin/ifconfig -au6 | while read intf addr rest; do
588843e1988Sjohnlev		[ $intf = inet6 ] && [ $addr != ::1/128 ] && exit $SMF_EXIT_OK
5897c478bd9Sstevel@tonic-gate	done && exit $SMF_EXIT_OK
5907c478bd9Sstevel@tonic-gatefi
5917c478bd9Sstevel@tonic-gate
5927c478bd9Sstevel@tonic-gate# This service was supposed to configure something yet didn't.  Exit
5937c478bd9Sstevel@tonic-gate# with config error.
5947c478bd9Sstevel@tonic-gateexit $SMF_EXIT_ERR_CONFIG
595