xref: /illumos-gate/usr/src/cmd/svc/milestone/net-physical (revision bbf215553c7233fbab8a0afdf1fac74c44781867)
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#
307c478bd9Sstevel@tonic-gate
316927f468Sdp. /lib/svc/share/smf_include.sh
326927f468Sdp. /lib/svc/share/net_include.sh
336927f468Sdp
347c478bd9Sstevel@tonic-gate#
35f4b3ec61Sdh155122# In a shared-IP zone we need this service to be up, but all of the work
367c478bd9Sstevel@tonic-gate# it tries to do is irrelevant (and will actually lead to the service
377c478bd9Sstevel@tonic-gate# failing if we try to do it), so just bail out.
38f4b3ec61Sdh155122# In the global zone and exclusive-IP zones we proceed.
397c478bd9Sstevel@tonic-gate#
40f4b3ec61Sdh155122smf_configure_ip || exit $SMF_EXIT_OK
417c478bd9Sstevel@tonic-gate
426e91bba0SGirish Moodalbail
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
48f4b3ec61Sdh155122if smf_is_globalzone; then
49d62bc4baSyz147064	net_reconfigure || exit $SMF_EXIT_ERR_CONFIG
50d62bc4baSyz147064
514eaa4710SRishi Srivatsavai	# Update PVID on interfaces configured with VLAN 1
524eaa4710SRishi Srivatsavai	update_pvid
534eaa4710SRishi Srivatsavai
54d62bc4baSyz147064	#
55*bbf21555SRichard Lowe	# Upgrade handling. The upgrade file consists of a series of dladm(8)
56d62bc4baSyz147064	# commands. Note that after we are done, we cannot rename the upgrade
57d62bc4baSyz147064	# script file as the file system is still read-only at this point.
58d62bc4baSyz147064	# Defer this to the manifest-import service.
59d62bc4baSyz147064	#
60d62bc4baSyz147064	upgrade_script=/var/svc/profile/upgrade_datalink
61d62bc4baSyz147064	if [ -f "${upgrade_script}" ]; then
62d62bc4baSyz147064		. "${upgrade_script}"
63d62bc4baSyz147064	fi
64d62bc4baSyz147064
657c478bd9Sstevel@tonic-gate	#
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
731cfa752fSRamaswamy Tummala		ibd_upgraded=`/bin/svcprop -c -p ibd/ibd_upgraded \
741cfa752fSRamaswamy Tummala		    $SMF_FMRI 2> /dev/null`
751cfa752fSRamaswamy Tummala		if [ "$ibd_upgraded" != "true" ]; then
761cfa752fSRamaswamy Tummala			/sbin/ibd_upgrade -v
771cfa752fSRamaswamy Tummala		fi
7812c67a59SMilan Jurik	fi
791cfa752fSRamaswamy Tummala
801cfa752fSRamaswamy Tummala	#
81b509e89bSRishi Srivatsavai	# Bring up simnets, link aggregations and initialize security objects.
820ba2cbe9Sxc151355	# Note that link property initialization is deferred until after
830ba2cbe9Sxc151355	# 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.
87210db224Sericheng	#
88b509e89bSRishi Srivatsavai	/sbin/dladm up-simnet
89210db224Sericheng	/sbin/dladm up-aggr
90d62bc4baSyz147064	/sbin/dladm up-vlan
911cfa752fSRamaswamy Tummala	/sbin/dladm up-part
920ba2cbe9Sxc151355	/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
101f4b3ec61Sdh155122fi
102210db224Sericheng
103210db224Sericheng#
1047c478bd9Sstevel@tonic-gate# If the system was net booted by DHCP, hand DHCP management off to the
1057c478bd9Sstevel@tonic-gate# DHCP agent (ifconfig communicates to the DHCP agent through the
1067c478bd9Sstevel@tonic-gate# loopback interface).
1077c478bd9Sstevel@tonic-gate#
1087c478bd9Sstevel@tonic-gateif [ -n "$_INIT_NET_IF" -a "$_INIT_NET_STRATEGY" = "dhcp" ]; then
1097c478bd9Sstevel@tonic-gate	/sbin/dhcpagent -a
1107c478bd9Sstevel@tonic-gatefi
1117c478bd9Sstevel@tonic-gate
1127c478bd9Sstevel@tonic-gate#
1137c478bd9Sstevel@tonic-gate# The network initialization is done early to support diskless and
1147c478bd9Sstevel@tonic-gate# dataless configurations.  For IPv4 interfaces that were configured by
1157c478bd9Sstevel@tonic-gate# the kernel (e.g.  those on diskless machines) and not configured by
1167c478bd9Sstevel@tonic-gate# DHCP, reset the netmask using the local "/etc/netmasks" file if one
1177c478bd9Sstevel@tonic-gate# exists, and then reset the broadcast address based on the netmask.
1187c478bd9Sstevel@tonic-gate#
1197c478bd9Sstevel@tonic-gate/sbin/ifconfig -auD4 netmask + broadcast +
1207c478bd9Sstevel@tonic-gate
1212b24ab6bSSebastien Royis_iptun ()
1222b24ab6bSSebastien Roy{
1232b24ab6bSSebastien Roy	intf=$1
1242b24ab6bSSebastien Roy	# Is this a persistent IP tunnel link?
1252b24ab6bSSebastien Roy	/sbin/dladm show-iptun -P $intf > /dev/null 2>&1
1262b24ab6bSSebastien Roy	if [ $? -eq 0 ]; then
1272b24ab6bSSebastien Roy		return 0
1282b24ab6bSSebastien Roy	fi
1292b24ab6bSSebastien Roy	# Is this an implicit IP tunnel (i.e., ip.tun0)
1302b24ab6bSSebastien Roy	ORIGIFS="$IFS"
1312b24ab6bSSebastien Roy	IFS="$IFS."
1322b24ab6bSSebastien Roy	set -- $intf
1332b24ab6bSSebastien Roy	IFS="$ORIGIFS"
1342b24ab6bSSebastien Roy	if [ $# -eq 2 -a \( "$1" = "ip" -o "$1" = "ip6" \) ]; then
1352b24ab6bSSebastien Roy		#
1362b24ab6bSSebastien Roy		# It looks like one, but another type of link might be
1372b24ab6bSSebastien Roy		# using a name that looks like an implicit IP tunnel.
1382b24ab6bSSebastien Roy		# If dladm show-link -P finds it, then it's not an IP
1392b24ab6bSSebastien Roy		# tunnel.
1402b24ab6bSSebastien Roy		#
1412b24ab6bSSebastien Roy		/sbin/dladm show-link -Pp $intf > /dev/null 2>&1
1422b24ab6bSSebastien Roy		if [ $? -eq 0 ]; then
1432b24ab6bSSebastien Roy			return 1
1442b24ab6bSSebastien Roy		else
1452b24ab6bSSebastien Roy			return 0
1462b24ab6bSSebastien Roy		fi
1472b24ab6bSSebastien Roy	fi
1482b24ab6bSSebastien Roy	return 1
1492b24ab6bSSebastien Roy}
1502b24ab6bSSebastien Roy
1517c478bd9Sstevel@tonic-gate#
1527c478bd9Sstevel@tonic-gate# All the IPv4 and IPv6 interfaces are plumbed before doing any
1537c478bd9Sstevel@tonic-gate# interface configuration.  This prevents errors from plumb failures
1547c478bd9Sstevel@tonic-gate# getting mixed in with the configured interface lists that the script
1557c478bd9Sstevel@tonic-gate# outputs.
1567c478bd9Sstevel@tonic-gate#
1577c478bd9Sstevel@tonic-gate
1587c478bd9Sstevel@tonic-gate#
1596e91bba0SGirish Moodalbail# First deal with /etc/hostname
1606e91bba0SGirish Moodalbail#
1617c478bd9Sstevel@tonic-gate# Get the list of IPv4 interfaces to configure by breaking
1627c478bd9Sstevel@tonic-gate# /etc/hostname.* into separate args by using "." as a shell separator
1637c478bd9Sstevel@tonic-gate# character.
1647c478bd9Sstevel@tonic-gate#
1657c478bd9Sstevel@tonic-gateinterface_names="`echo /etc/hostname.*[0-9] 2>/dev/null`"
1667c478bd9Sstevel@tonic-gateif [ "$interface_names" != "/etc/hostname.*[0-9]" ]; then
1677c478bd9Sstevel@tonic-gate	ORIGIFS="$IFS"
1687c478bd9Sstevel@tonic-gate	IFS="$IFS."
1697c478bd9Sstevel@tonic-gate	set -- $interface_names
1707c478bd9Sstevel@tonic-gate	IFS="$ORIGIFS"
1717c478bd9Sstevel@tonic-gate	while [ $# -ge 2 ]; do
1727c478bd9Sstevel@tonic-gate		shift
173e11c3f44Smeem		intf_name=$1
174e11c3f44Smeem		while [ $# -gt 1 -a "$2" != "/etc/hostname" ]; do
175e11c3f44Smeem			intf_name="$intf_name.$2"
1767c478bd9Sstevel@tonic-gate			shift
1777c478bd9Sstevel@tonic-gate		done
1787c478bd9Sstevel@tonic-gate		shift
179e11c3f44Smeem
1802b24ab6bSSebastien Roy		# skip IP tunnel interfaces plumbed by net-iptun.
1812b24ab6bSSebastien Roy		if is_iptun $intf_name; then
1822b24ab6bSSebastien Roy			continue
1832b24ab6bSSebastien Roy		fi
1842b24ab6bSSebastien Roy
185e11c3f44Smeem	        read one rest < /etc/hostname.$intf_name
186e11c3f44Smeem		if [ "$one" = ipmp ]; then
187e11c3f44Smeem			ipmp_list="$ipmp_list $intf_name"
188e11c3f44Smeem		else
189e11c3f44Smeem			inet_list="$inet_list $intf_name"
1907c478bd9Sstevel@tonic-gate		fi
1917c478bd9Sstevel@tonic-gate	done
1927c478bd9Sstevel@tonic-gatefi
1937c478bd9Sstevel@tonic-gate
1947c478bd9Sstevel@tonic-gate#
1957c478bd9Sstevel@tonic-gate# Get the list of IPv6 interfaces to configure by breaking
1967c478bd9Sstevel@tonic-gate# /etc/hostname6.* into separate args by using "." as a shell separator
1977c478bd9Sstevel@tonic-gate# character.
1987c478bd9Sstevel@tonic-gate#
1997c478bd9Sstevel@tonic-gateinterface_names="`echo /etc/hostname6.*[0-9] 2>/dev/null`"
2007c478bd9Sstevel@tonic-gateif [ "$interface_names" != "/etc/hostname6.*[0-9]" ]; then
2017c478bd9Sstevel@tonic-gate	ORIGIFS="$IFS"
2027c478bd9Sstevel@tonic-gate	IFS="$IFS."
2037c478bd9Sstevel@tonic-gate	set -- $interface_names
2047c478bd9Sstevel@tonic-gate	IFS="$ORIGIFS"
2057c478bd9Sstevel@tonic-gate	while [ $# -ge 2 ]; do
2067c478bd9Sstevel@tonic-gate		shift
207e11c3f44Smeem		intf_name=$1
208e11c3f44Smeem		while [ $# -gt 1 -a "$2" != "/etc/hostname6" ]; do
209e11c3f44Smeem			intf_name="$intf_name.$2"
2107c478bd9Sstevel@tonic-gate			shift
2117c478bd9Sstevel@tonic-gate		done
2127c478bd9Sstevel@tonic-gate		shift
213e11c3f44Smeem
2142b24ab6bSSebastien Roy		# skip IP tunnel interfaces plumbed by net-iptun.
2152b24ab6bSSebastien Roy		if is_iptun $intf_name; then
2162b24ab6bSSebastien Roy			continue
2172b24ab6bSSebastien Roy		fi
2182b24ab6bSSebastien Roy
219e11c3f44Smeem	        read one rest < /etc/hostname6.$intf_name
220e11c3f44Smeem		if [ "$one" = ipmp ]; then
221e11c3f44Smeem			ipmp6_list="$ipmp6_list $intf_name"
222e11c3f44Smeem		else
223e11c3f44Smeem			inet6_list="$inet6_list $intf_name"
2247c478bd9Sstevel@tonic-gate		fi
2257c478bd9Sstevel@tonic-gate	done
2267c478bd9Sstevel@tonic-gatefi
2277c478bd9Sstevel@tonic-gate
228e11c3f44Smeem#
229e11c3f44Smeem# Create all of the IPv4 IPMP interfaces.
230e11c3f44Smeem#
231e11c3f44Smeemif [ -n "$ipmp_list" ]; then
232e11c3f44Smeem	set -- $ipmp_list
233e11c3f44Smeem	while [ $# -gt 0 ]; do
234e11c3f44Smeem		if /sbin/ifconfig $1 ipmp; then
235e11c3f44Smeem			ipmp_created="$ipmp_created $1"
236e11c3f44Smeem		else
237e11c3f44Smeem			ipmp_failed="$ipmp_failed $1"
238e11c3f44Smeem		fi
239e11c3f44Smeem		shift
240e11c3f44Smeem	done
241e11c3f44Smeem	[ -n "$ipmp_failed" ] && warn_failed_ifs "create IPv4 IPMP" \
242e11c3f44Smeem	    "$ipmp_failed"
243e11c3f44Smeemfi
2447c478bd9Sstevel@tonic-gate
2457c478bd9Sstevel@tonic-gate#
2467c478bd9Sstevel@tonic-gate# Step through the IPv4 interface list and try to plumb every interface.
2477c478bd9Sstevel@tonic-gate# Generate list of plumbed and failed IPv4 interfaces.
2487c478bd9Sstevel@tonic-gate#
2497c478bd9Sstevel@tonic-gateif [ -n "$inet_list" ]; then
2507c478bd9Sstevel@tonic-gate	set -- $inet_list
2517c478bd9Sstevel@tonic-gate	while [ $# -gt 0 ]; do
2527c478bd9Sstevel@tonic-gate		/sbin/ifconfig $1 plumb
2537c478bd9Sstevel@tonic-gate		if /sbin/ifconfig $1 inet >/dev/null 2>&1; then
2547c478bd9Sstevel@tonic-gate			inet_plumbed="$inet_plumbed $1"
2557c478bd9Sstevel@tonic-gate		else
2567c478bd9Sstevel@tonic-gate			inet_failed="$inet_failed $1"
2577c478bd9Sstevel@tonic-gate		fi
2587c478bd9Sstevel@tonic-gate		shift
2597c478bd9Sstevel@tonic-gate	done
260e11c3f44Smeem	[ -n "$inet_failed" ] && warn_failed_ifs "plumb IPv4" "$inet_failed"
2617c478bd9Sstevel@tonic-gatefi
2627c478bd9Sstevel@tonic-gate
263516fc7f3Shx147065# Run autoconf to connect to a WLAN if the interface is a wireless one
264516fc7f3Shx147065if [ -x /sbin/wificonfig -a -n "$inet_plumbed" ]; then
265516fc7f3Shx147065	set -- $inet_plumbed
266516fc7f3Shx147065	while [ $# -gt 0 ]; do
267516fc7f3Shx147065			if [ -r /dev/wifi/$1 ]; then
268516fc7f3Shx147065				/sbin/wificonfig -i $1 startconf >/dev/null
269516fc7f3Shx147065			fi
270516fc7f3Shx147065		shift
271516fc7f3Shx147065	done
272516fc7f3Shx147065fi
273516fc7f3Shx147065
2747c478bd9Sstevel@tonic-gate#
2757c478bd9Sstevel@tonic-gate# Step through the IPv6 interface list and plumb every interface.
2767c478bd9Sstevel@tonic-gate# Generate list of plumbed and failed IPv6 interfaces.  Each plumbed
2777c478bd9Sstevel@tonic-gate# interface will be brought up later, after processing any contents of
2787c478bd9Sstevel@tonic-gate# the /etc/hostname6.* file.
2797c478bd9Sstevel@tonic-gate#
2807c478bd9Sstevel@tonic-gateif [ -n "$inet6_list" ]; then
2817c478bd9Sstevel@tonic-gate	set -- $inet6_list
2827c478bd9Sstevel@tonic-gate	while [ $# -gt 0 ]; do
2837c478bd9Sstevel@tonic-gate		/sbin/ifconfig $1 inet6 plumb
2847c478bd9Sstevel@tonic-gate		if /sbin/ifconfig $1 inet6 >/dev/null 2>&1; then
2857c478bd9Sstevel@tonic-gate			inet6_plumbed="$inet6_plumbed $1"
2867c478bd9Sstevel@tonic-gate		else
2877c478bd9Sstevel@tonic-gate			inet6_failed="$inet6_failed $1"
2887c478bd9Sstevel@tonic-gate		fi
2897c478bd9Sstevel@tonic-gate		shift
2907c478bd9Sstevel@tonic-gate	done
291e11c3f44Smeem	[ -n "$inet6_failed" ] && warn_failed_ifs "plumb IPv6" "$inet6_failed"
292e11c3f44Smeemfi
293e11c3f44Smeem
294e11c3f44Smeem#
295e11c3f44Smeem# Create all of the IPv6 IPMP interfaces.
296e11c3f44Smeem#
297e11c3f44Smeemif [ -n "$ipmp6_list" ]; then
298e11c3f44Smeem	set -- $ipmp6_list
299e11c3f44Smeem	while [ $# -gt 0 ]; do
300e11c3f44Smeem		if /sbin/ifconfig $1 inet6 ipmp; then
301e11c3f44Smeem			ipmp6_created="$ipmp6_created $1"
302e11c3f44Smeem		else
303e11c3f44Smeem			ipmp6_failed="$ipmp6_failed $1"
304e11c3f44Smeem		fi
305e11c3f44Smeem		shift
306e11c3f44Smeem	done
307e11c3f44Smeem	[ -n "$ipmp6_failed" ] && warn_failed_ifs "create IPv6 IPMP" \
308e11c3f44Smeem	    "$ipmp6_failed"
3097c478bd9Sstevel@tonic-gatefi
3107c478bd9Sstevel@tonic-gate
3110ba2cbe9Sxc151355#
312a73be61aSHans Rosenfeld# Upgrade ipadm.conf.
313a73be61aSHans Rosenfeld#
314a73be61aSHans Rosenfeldif /usr/bin/grep -q _family /etc/ipadm/ipadm.conf; then
315a73be61aSHans Rosenfeld	oldifs=$(/usr/bin/sed -En \
316a73be61aSHans Rosenfeld	    's/^_ifname=([a-z0-9]+);_family=[0-9]+;$/\1/p' \
317a73be61aSHans Rosenfeld	    /etc/ipadm/ipadm.conf | /usr/bin/sort -u)
318a73be61aSHans Rosenfeld	/usr/bin/sed -i '/_family/d' /etc/ipadm/ipadm.conf
319a73be61aSHans Rosenfeld	for oldif in $oldifs; do
320a73be61aSHans Rosenfeld		/usr/bin/printf \
321a73be61aSHans Rosenfeld		    "_ifname=%s;_ifclass=0;_families=2,26;\n" \
322a73be61aSHans Rosenfeld		    $oldif >> /etc/ipadm/ipadm.conf
323a73be61aSHans Rosenfeld	done
324a73be61aSHans Rosenfeldfi
325a73be61aSHans Rosenfeld
326a73be61aSHans Rosenfeld#
327550b6e40SSowmini Varadhan# Finally configure interfaces set up with ipadm. Any /etc/hostname*.intf
328550b6e40SSowmini Varadhan# files take precedence over ipadm defined configurations except when
329550b6e40SSowmini Varadhan# we are in a non-global zone and Layer-3 protection of IP addresses is
330550b6e40SSowmini Varadhan# enforced on the interface by the global zone.
3316e91bba0SGirish Moodalbail#
332550b6e40SSowmini Varadhanfor showif_output in `/sbin/ipadm show-if -p -o ifname,state,current`; do
3336e91bba0SGirish Moodalbail	intf=`echo $showif_output | /usr/bin/cut -f1 -d:`
3346e91bba0SGirish Moodalbail	state=`echo $showif_output | /usr/bin/cut -f2 -d:`
335550b6e40SSowmini Varadhan	current=`echo $showif_output | /usr/bin/cut -f3 -d:`
336550b6e40SSowmini Varadhan	if  [[ "$state" != "disabled" && $current != *Z* ]]; then
337550b6e40SSowmini Varadhan		#
338550b6e40SSowmini Varadhan		# skip if not a persistent interface, or if it should get IP
339550b6e40SSowmini Varadhan		# configuration from the global zone ('Z' flag is set)
340550b6e40SSowmini Varadhan		#
3416e91bba0SGirish Moodalbail		continue;
3426e91bba0SGirish Moodalbail	elif is_iptun $intf; then
3436e91bba0SGirish Moodalbail		# skip IP tunnel interfaces plumbed by net-iptun
3446e91bba0SGirish Moodalbail		continue;
3456e91bba0SGirish Moodalbail	elif [ -f /etc/hostname.$intf ] || [ -f /etc/hostname6.$intf ]; then
346550b6e40SSowmini Varadhan		if [[ $current != *Z* ]]; then
347550b6e40SSowmini Varadhan			echo "found /etc/hostname.$intf "\
348550b6e40SSowmini Varadhan			    "or /etc/hostname6.$intf, "\
3496e91bba0SGirish Moodalbail			    "ignoring ipadm configuration" > /dev/msglog
3506e91bba0SGirish Moodalbail			continue;
351550b6e40SSowmini Varadhan		else
352550b6e40SSowmini Varadhan			echo "Ignoring /etc/hostname*.$intf" > /dev/msglog
353550b6e40SSowmini Varadhan			/sbin/ifconfig $intf unplumb > /dev/null 2>&1
354550b6e40SSowmini Varadhan			/sbin/ifconfig $intf inet6 unplumb > /dev/null 2>&1
355550b6e40SSowmini Varadhan		fi
3566e91bba0SGirish Moodalbail	fi
3576e91bba0SGirish Moodalbail
3586e91bba0SGirish Moodalbail	# Enable the interface managed by ipadm
3596e91bba0SGirish Moodalbail	/sbin/ipadm enable-if -t $intf
3606e91bba0SGirish Moodalbaildone
3616e91bba0SGirish Moodalbail
3626e91bba0SGirish Moodalbail#
363e11c3f44Smeem# Process the /etc/hostname[6].* files for IPMP interfaces.  Processing these
364e11c3f44Smeem# before non-IPMP interfaces avoids accidental implicit IPMP group creation.
3657c478bd9Sstevel@tonic-gate#
366e11c3f44Smeem[ -n "$ipmp_created" ] && if_configure inet "IPMP" $ipmp_created
367e11c3f44Smeem[ -n "$ipmp6_created" ] && if_configure inet6 "IPMP" $ipmp6_created
3687c478bd9Sstevel@tonic-gate
3697c478bd9Sstevel@tonic-gate#
370e11c3f44Smeem# Process the /etc/hostname[6].* files for non-IPMP interfaces.
3717c478bd9Sstevel@tonic-gate#
372e11c3f44Smeem[ -n "$inet_plumbed" ] && if_configure inet "" $inet_plumbed
373e11c3f44Smeem[ -n "$inet6_plumbed" ] && if_configure inet6 "" $inet6_plumbed
374e11c3f44Smeem
375e11c3f44Smeem#
376e11c3f44Smeem# For the IPv4 and IPv6 interfaces that failed to plumb, find (or create)
377e11c3f44Smeem# IPMP meta-interfaces to host their data addresses.
378e11c3f44Smeem#
379e11c3f44Smeem[ -n "$inet_failed" ] && move_addresses inet
380e11c3f44Smeem[ -n "$inet6_failed" ] && move_addresses inet6
3817c478bd9Sstevel@tonic-gate
3827c478bd9Sstevel@tonic-gate# Run DHCP if requested. Skip boot-configured interface.
3837c478bd9Sstevel@tonic-gateinterface_names="`echo /etc/dhcp.*[0-9] 2>/dev/null`"
3847c478bd9Sstevel@tonic-gateif [ "$interface_names" != '/etc/dhcp.*[0-9]' ]; then
3857c478bd9Sstevel@tonic-gate	#
3867c478bd9Sstevel@tonic-gate	# First find the primary interface. Default to the first
3877c478bd9Sstevel@tonic-gate	# interface if not specified. First primary interface found
3887c478bd9Sstevel@tonic-gate	# "wins". Use care not to "reconfigure" a net-booted interface
3897c478bd9Sstevel@tonic-gate	# configured using DHCP. Run through the list of interfaces
3907c478bd9Sstevel@tonic-gate	# again, this time trying DHCP.
3917c478bd9Sstevel@tonic-gate	#
3927c478bd9Sstevel@tonic-gate	i4d_fail=
3937c478bd9Sstevel@tonic-gate	firstif=
3947c478bd9Sstevel@tonic-gate	primary=
3957c478bd9Sstevel@tonic-gate	ORIGIFS="$IFS"
3967c478bd9Sstevel@tonic-gate	IFS="${IFS}."
3977c478bd9Sstevel@tonic-gate	set -- $interface_names
3987c478bd9Sstevel@tonic-gate
3997c478bd9Sstevel@tonic-gate	while [ $# -ge 2 ]; do
4007c478bd9Sstevel@tonic-gate		shift
4017c478bd9Sstevel@tonic-gate		[ -z "$firstif" ] && firstif=$1
4027c478bd9Sstevel@tonic-gate
4037c478bd9Sstevel@tonic-gate		for i in `shcat /etc/dhcp\.$1`; do
4047c478bd9Sstevel@tonic-gate			if [ "$i" = primary ]; then
4057c478bd9Sstevel@tonic-gate				primary=$1
4067c478bd9Sstevel@tonic-gate				break
4077c478bd9Sstevel@tonic-gate			fi
4087c478bd9Sstevel@tonic-gate		done
4097c478bd9Sstevel@tonic-gate
4107c478bd9Sstevel@tonic-gate		[ -n "$primary" ] && break
4117c478bd9Sstevel@tonic-gate		shift
4127c478bd9Sstevel@tonic-gate	done
4137c478bd9Sstevel@tonic-gate
4147c478bd9Sstevel@tonic-gate	[ -z "$primary" ] && primary="$firstif"
4157c478bd9Sstevel@tonic-gate	cmdline=`shcat /etc/dhcp\.${primary}`
4167c478bd9Sstevel@tonic-gate
4177c478bd9Sstevel@tonic-gate	if [ "$_INIT_NET_IF" != "$primary" ]; then
4187c478bd9Sstevel@tonic-gate		echo "starting DHCP on primary interface $primary"
4197c478bd9Sstevel@tonic-gate		/sbin/ifconfig $primary auto-dhcp primary $cmdline
4207c478bd9Sstevel@tonic-gate		# Exit code 4 means ifconfig timed out waiting for dhcpagent
4217c478bd9Sstevel@tonic-gate		[ $? != 0 ] && [ $? != 4 ] && i4d_fail="$i4d_fail $primary"
4227c478bd9Sstevel@tonic-gate	fi
4237c478bd9Sstevel@tonic-gate
4247c478bd9Sstevel@tonic-gate	set -- $interface_names
4257c478bd9Sstevel@tonic-gate
4267c478bd9Sstevel@tonic-gate	while [ $# -ge 2 ]; do
4277c478bd9Sstevel@tonic-gate		shift
4287c478bd9Sstevel@tonic-gate		cmdline=`shcat /etc/dhcp\.$1`
4297c478bd9Sstevel@tonic-gate		if [ "$1" != "$primary" -a \
4307c478bd9Sstevel@tonic-gate			"$1" != "$_INIT_NET_IF"  ]; then
4317c478bd9Sstevel@tonic-gate			echo "starting DHCP on interface $1"
4327c478bd9Sstevel@tonic-gate			/sbin/ifconfig $1 dhcp start wait 0 $cmdline
4337c478bd9Sstevel@tonic-gate			# Exit code can't be timeout when wait is 0
4347c478bd9Sstevel@tonic-gate			[ $? != 0 ] && i4d_fail="$i4d_fail $1"
4357c478bd9Sstevel@tonic-gate		fi
4367c478bd9Sstevel@tonic-gate		shift
4377c478bd9Sstevel@tonic-gate	done
4387c478bd9Sstevel@tonic-gate	IFS="$ORIGIFS"
4397c478bd9Sstevel@tonic-gate	unset ORIGIFS
440e11c3f44Smeem	[ -n "$i4d_fail" ] && warn_failed_ifs "configure IPv4 DHCP" "$i4d_fail"
4417c478bd9Sstevel@tonic-gatefi
4427c478bd9Sstevel@tonic-gate
4430659b2b8Sse146197# In order to avoid bringing up the interfaces that have
4440659b2b8Sse146197# intentionally been left down, perform RARP only if the system
4450659b2b8Sse146197# has no configured hostname in /etc/nodename
4460659b2b8Sse146197hostname="`shcat /etc/nodename 2>/dev/null`"
4470659b2b8Sse146197if [ "$_INIT_NET_STRATEGY" = "rarp" -o -z "$hostname" ]; then
4487c478bd9Sstevel@tonic-gate	/sbin/ifconfig -adD4 auto-revarp netmask + broadcast + up
4490659b2b8Sse146197fi
4507c478bd9Sstevel@tonic-gate
4517c478bd9Sstevel@tonic-gate#
4527c478bd9Sstevel@tonic-gate# If the /etc/defaultrouter file exists, process it now so that the next
4537c478bd9Sstevel@tonic-gate# stage of booting will have access to NFS.
4547c478bd9Sstevel@tonic-gate#
4557c478bd9Sstevel@tonic-gateif [ -f /etc/defaultrouter ]; then
4567c478bd9Sstevel@tonic-gate	while read router rubbish; do
4577c478bd9Sstevel@tonic-gate		case "$router" in
4587c478bd9Sstevel@tonic-gate			'#'* | '') ;;	#  Ignore comments, empty lines
4597c478bd9Sstevel@tonic-gate			*)	/sbin/route -n add default -gateway $router ;;
4607c478bd9Sstevel@tonic-gate		esac
4617c478bd9Sstevel@tonic-gate	done </etc/defaultrouter
4627c478bd9Sstevel@tonic-gatefi
4637c478bd9Sstevel@tonic-gate
4647c478bd9Sstevel@tonic-gate#
465843e1988Sjohnlev# If we get here and were not asked to plumb any IPv4 interfaces, look
466843e1988Sjohnlev# for boot properties that direct us.
467843e1988Sjohnlev#
468843e1988Sjohnlev# - The "network-interface" property is required and indicates the
469843e1988Sjohnlev#   interface name.
470843e1988Sjohnlev# - The "xpv-hcp" property, if present, is used by the hypervisor
471843e1988Sjohnlev#   tools to indicate how the specified interface should be configured.
472843e1988Sjohnlev#   Permitted values are "dhcp" and "off", where "off" indicates static
473843e1988Sjohnlev#   IP configuration.
474843e1988Sjohnlev#
475843e1988Sjohnlev# In the case where "xpv-hcp" is set to "dhcp", no further properties
476843e1988Sjohnlev# are required or examined.
477843e1988Sjohnlev#
478843e1988Sjohnlev# In the case where "xpv-hcp" is not present or set to "off", the
479843e1988Sjohnlev# "host-ip" and "subnet-mask" properties are used to configure
480843e1988Sjohnlev# the specified interface.  The "router-ip" property, if present,
481843e1988Sjohnlev# is used to add a default route.
482843e1988Sjohnlev#
483843e1988Sjohnlevnic="`/sbin/devprop network-interface`"
484843e1988Sjohnlevif smf_is_globalzone && [ -z "$inet_list" ] && [ -n "$nic" ]; then
485843e1988Sjohnlev	hcp="`/sbin/devprop xpv-hcp`"
486843e1988Sjohnlev	case "$hcp" in
487843e1988Sjohnlev	"dhcp")
488843e1988Sjohnlev		/sbin/ifconfig $nic plumb 2>/dev/null
489843e1988Sjohnlev		[ -n "`/sbin/ifconfig $nic 2>/dev/null`" ] && (
490843e1988Sjohnlev			# The interface is successfully plumbed, so
491843e1988Sjohnlev			# modify "inet_list" to force the exit code
492843e1988Sjohnlev			# checks to work.
493843e1988Sjohnlev			inet_list=$nic;
494843e1988Sjohnlev			# Given that this is the only IPv4 interface,
495843e1988Sjohnlev			# we assert that it is primary.
496843e1988Sjohnlev			echo "starting DHCP on primary interface $primary";
497843e1988Sjohnlev			/sbin/ifconfig $nic auto-dhcp primary;
498843e1988Sjohnlev			# Exit code 4 means ifconfig timed out waiting
499843e1988Sjohnlev			# for dhcpagent
500843e1988Sjohnlev			[ $? != 0 ] && [ $? != 4 ] && \
501843e1988Sjohnlev			    i4d_fail="$i4d_fail $nic";
502843e1988Sjohnlev		)
503843e1988Sjohnlev		;;
504843e1988Sjohnlev
505843e1988Sjohnlev	"off"|"")
506843e1988Sjohnlev		/sbin/devprop host-ip subnet-mask router-ip | (
507843e1988Sjohnlev			read ip;
508843e1988Sjohnlev			read mask;
509843e1988Sjohnlev			read router;
510843e1988Sjohnlev			[ -n "$ip" ] && [ -n "$mask" ] && \
511843e1988Sjohnlev				/sbin/ifconfig $nic plumb 2>/dev/null
512843e1988Sjohnlev			[ -n "`/sbin/ifconfig $nic 2>/dev/null`" ] && (
513843e1988Sjohnlev				# The interface is successfully
514843e1988Sjohnlev				# plumbed, so modify "inet_list" to
515843e1988Sjohnlev				# force the exit code checks to work.
516843e1988Sjohnlev				inet_list=$nic;
517843e1988Sjohnlev				/sbin/ifconfig $nic  inet $ip \
518843e1988Sjohnlev				    netmask $mask broadcast + up 2>/dev/null;
519843e1988Sjohnlev				[ -n "$router" ] && route add \
520843e1988Sjohnlev				    default $router 2>/dev/null;
521843e1988Sjohnlev			)
522843e1988Sjohnlev		)
523843e1988Sjohnlev		;;
524843e1988Sjohnlev	esac
525843e1988Sjohnlevfi
526843e1988Sjohnlev
527843e1988Sjohnlev#
5287c478bd9Sstevel@tonic-gate# We tell smf this service is online if any of the following is true:
5297c478bd9Sstevel@tonic-gate# - no interfaces were configured for plumbing and no DHCP failures
5307c478bd9Sstevel@tonic-gate# - any non-loopback IPv4 interfaces are up and have a non-zero address
5317c478bd9Sstevel@tonic-gate# - there are any DHCP interfaces started
5327c478bd9Sstevel@tonic-gate# - any non-loopback IPv6 interfaces are up
5337c478bd9Sstevel@tonic-gate#
5347c478bd9Sstevel@tonic-gate# If we weren't asked to configure any interfaces, exit
5357c478bd9Sstevel@tonic-gateif [ -z "$inet_list" ] && [ -z "$inet6_list" ]; then
5367c478bd9Sstevel@tonic-gate	# Config error if DHCP was attempted without plumbed interfaces
5377c478bd9Sstevel@tonic-gate	[ -n "$i4d_fail" ] && exit $SMF_EXIT_ERR_CONFIG
5387c478bd9Sstevel@tonic-gate	exit $SMF_EXIT_OK
5397c478bd9Sstevel@tonic-gatefi
5407c478bd9Sstevel@tonic-gate
5417c478bd9Sstevel@tonic-gate# Any non-loopback IPv4 interfaces with usable addresses up?
5427c478bd9Sstevel@tonic-gateif [ -n "`/sbin/ifconfig -a4u`" ]; then
5437c478bd9Sstevel@tonic-gate	/sbin/ifconfig -a4u | while read intf addr rest; do
5447c478bd9Sstevel@tonic-gate		[ $intf = inet ] && [ $addr != 127.0.0.1 ] &&
545843e1988Sjohnlev		[ $addr != 0.0.0.0 ] && exit $SMF_EXIT_OK
5467c478bd9Sstevel@tonic-gate	done && exit $SMF_EXIT_OK
5477c478bd9Sstevel@tonic-gatefi
5487c478bd9Sstevel@tonic-gate
5497c478bd9Sstevel@tonic-gate# Any DHCP interfaces started?
5507c478bd9Sstevel@tonic-gate[ -n "`/sbin/ifconfig -a4 dhcp status 2>/dev/null`" ] && exit $SMF_EXIT_OK
5517c478bd9Sstevel@tonic-gate
5527c478bd9Sstevel@tonic-gate# Any non-loopback IPv6 interfaces up?
5537c478bd9Sstevel@tonic-gateif [ -n "`/sbin/ifconfig -au6`" ]; then
5547c478bd9Sstevel@tonic-gate	/sbin/ifconfig -au6 | while read intf addr rest; do
555843e1988Sjohnlev		[ $intf = inet6 ] && [ $addr != ::1/128 ] && exit $SMF_EXIT_OK
5567c478bd9Sstevel@tonic-gate	done && exit $SMF_EXIT_OK
5577c478bd9Sstevel@tonic-gatefi
5587c478bd9Sstevel@tonic-gate
5597c478bd9Sstevel@tonic-gate# This service was supposed to configure something yet didn't.  Exit
5607c478bd9Sstevel@tonic-gate# with config error.
5617c478bd9Sstevel@tonic-gateexit $SMF_EXIT_ERR_CONFIG
562