xref: /titanic_50/usr/src/cmd/svc/milestone/net-physical (revision e11c3f44f531fdff80941ce57c065d2ae861cefc)
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#
227c478bd9Sstevel@tonic-gate#
23*e11c3f44Smeem# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate# Use is subject to license terms.
257c478bd9Sstevel@tonic-gate#
267c478bd9Sstevel@tonic-gate# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T.
277c478bd9Sstevel@tonic-gate# All rights reserved.
287c478bd9Sstevel@tonic-gate#
297c478bd9Sstevel@tonic-gate
306927f468Sdp. /lib/svc/share/smf_include.sh
316927f468Sdp. /lib/svc/share/net_include.sh
326927f468Sdp
337c478bd9Sstevel@tonic-gate#
34f4b3ec61Sdh155122# In a shared-IP zone we need this service to be up, but all of the work
357c478bd9Sstevel@tonic-gate# it tries to do is irrelevant (and will actually lead to the service
367c478bd9Sstevel@tonic-gate# failing if we try to do it), so just bail out.
37f4b3ec61Sdh155122# In the global zone and exclusive-IP zones we proceed.
387c478bd9Sstevel@tonic-gate#
39f4b3ec61Sdh155122smf_configure_ip || exit $SMF_EXIT_OK
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate# Make sure that the libraries essential to this stage of booting can be found.
427c478bd9Sstevel@tonic-gateLD_LIBRARY_PATH=/lib; export LD_LIBRARY_PATH
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gatesmf_netstrategy
457c478bd9Sstevel@tonic-gate
46f4b3ec61Sdh155122if smf_is_globalzone; then
47d62bc4baSyz147064	net_reconfigure || exit $SMF_EXIT_ERR_CONFIG
48d62bc4baSyz147064
49d62bc4baSyz147064	#
50d62bc4baSyz147064	# Upgrade handling. The upgrade file consists of a series of dladm(1M)
51d62bc4baSyz147064	# commands. Note that after we are done, we cannot rename the upgrade
52d62bc4baSyz147064	# script file as the file system is still read-only at this point.
53d62bc4baSyz147064	# Defer this to the manifest-import service.
54d62bc4baSyz147064	#
55d62bc4baSyz147064	upgrade_script=/var/svc/profile/upgrade_datalink
56d62bc4baSyz147064	if [ -f "${upgrade_script}" ]; then
57d62bc4baSyz147064		. "${upgrade_script}"
58d62bc4baSyz147064	fi
59d62bc4baSyz147064
607c478bd9Sstevel@tonic-gate	#
610ba2cbe9Sxc151355	# Bring up link aggregations and initialize security objects.
620ba2cbe9Sxc151355	# Note that link property initialization is deferred until after
630ba2cbe9Sxc151355	# IP interfaces are plumbed to ensure that the links will not
640ba2cbe9Sxc151355	# be unloaded (and the property settings lost).
65210db224Sericheng	#
66210db224Sericheng	/sbin/dladm up-aggr
67d62bc4baSyz147064	/sbin/dladm up-vlan
680ba2cbe9Sxc151355	/sbin/dladm init-secobj
69da14cebeSEric Cheng	#
70da14cebeSEric Cheng	# Bring up VNICs
71da14cebeSEric Cheng	#
72da14cebeSEric Cheng	/sbin/dladm up-vnic
73da14cebeSEric Cheng	#
74da14cebeSEric Cheng	# Create flows via flowadm.
75da14cebeSEric Cheng	#
76da14cebeSEric Cheng	/sbin/flowadm init-flow
77f4b3ec61Sdh155122fi
78210db224Sericheng
79210db224Sericheng#
807c478bd9Sstevel@tonic-gate# If the system was net booted by DHCP, hand DHCP management off to the
817c478bd9Sstevel@tonic-gate# DHCP agent (ifconfig communicates to the DHCP agent through the
827c478bd9Sstevel@tonic-gate# loopback interface).
837c478bd9Sstevel@tonic-gate#
847c478bd9Sstevel@tonic-gateif [ -n "$_INIT_NET_IF" -a "$_INIT_NET_STRATEGY" = "dhcp" ]; then
857c478bd9Sstevel@tonic-gate	/sbin/dhcpagent -a
867c478bd9Sstevel@tonic-gatefi
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate#
897c478bd9Sstevel@tonic-gate# The network initialization is done early to support diskless and
907c478bd9Sstevel@tonic-gate# dataless configurations.  For IPv4 interfaces that were configured by
917c478bd9Sstevel@tonic-gate# the kernel (e.g.  those on diskless machines) and not configured by
927c478bd9Sstevel@tonic-gate# DHCP, reset the netmask using the local "/etc/netmasks" file if one
937c478bd9Sstevel@tonic-gate# exists, and then reset the broadcast address based on the netmask.
947c478bd9Sstevel@tonic-gate#
957c478bd9Sstevel@tonic-gate/sbin/ifconfig -auD4 netmask + broadcast +
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate#
987c478bd9Sstevel@tonic-gate# All the IPv4 and IPv6 interfaces are plumbed before doing any
997c478bd9Sstevel@tonic-gate# interface configuration.  This prevents errors from plumb failures
1007c478bd9Sstevel@tonic-gate# getting mixed in with the configured interface lists that the script
1017c478bd9Sstevel@tonic-gate# outputs.
1027c478bd9Sstevel@tonic-gate#
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate#
1057c478bd9Sstevel@tonic-gate# Get the list of IPv4 interfaces to configure by breaking
1067c478bd9Sstevel@tonic-gate# /etc/hostname.* into separate args by using "." as a shell separator
1077c478bd9Sstevel@tonic-gate# character.
1087c478bd9Sstevel@tonic-gate#
1097c478bd9Sstevel@tonic-gateinterface_names="`echo /etc/hostname.*[0-9] 2>/dev/null`"
1107c478bd9Sstevel@tonic-gateif [ "$interface_names" != "/etc/hostname.*[0-9]" ]; then
1117c478bd9Sstevel@tonic-gate	ORIGIFS="$IFS"
1127c478bd9Sstevel@tonic-gate	IFS="$IFS."
1137c478bd9Sstevel@tonic-gate	set -- $interface_names
1147c478bd9Sstevel@tonic-gate	IFS="$ORIGIFS"
1157c478bd9Sstevel@tonic-gate	while [ $# -ge 2 ]; do
1167c478bd9Sstevel@tonic-gate		shift
117*e11c3f44Smeem		intf_name=$1
118*e11c3f44Smeem		while [ $# -gt 1 -a "$2" != "/etc/hostname" ]; do
119*e11c3f44Smeem			intf_name="$intf_name.$2"
1207c478bd9Sstevel@tonic-gate			shift
1217c478bd9Sstevel@tonic-gate		done
1227c478bd9Sstevel@tonic-gate		shift
123*e11c3f44Smeem
124*e11c3f44Smeem	        read one rest < /etc/hostname.$intf_name
125*e11c3f44Smeem		if [ "$one" = ipmp ]; then
126*e11c3f44Smeem			ipmp_list="$ipmp_list $intf_name"
127*e11c3f44Smeem		else
128*e11c3f44Smeem			inet_list="$inet_list $intf_name"
1297c478bd9Sstevel@tonic-gate		fi
1307c478bd9Sstevel@tonic-gate	done
1317c478bd9Sstevel@tonic-gatefi
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate#
1347c478bd9Sstevel@tonic-gate# Get the list of IPv6 interfaces to configure by breaking
1357c478bd9Sstevel@tonic-gate# /etc/hostname6.* into separate args by using "." as a shell separator
1367c478bd9Sstevel@tonic-gate# character.
1377c478bd9Sstevel@tonic-gate#
1387c478bd9Sstevel@tonic-gateinterface_names="`echo /etc/hostname6.*[0-9] 2>/dev/null`"
1397c478bd9Sstevel@tonic-gateif [ "$interface_names" != "/etc/hostname6.*[0-9]" ]; then
1407c478bd9Sstevel@tonic-gate	ORIGIFS="$IFS"
1417c478bd9Sstevel@tonic-gate	IFS="$IFS."
1427c478bd9Sstevel@tonic-gate	set -- $interface_names
1437c478bd9Sstevel@tonic-gate	IFS="$ORIGIFS"
1447c478bd9Sstevel@tonic-gate	while [ $# -ge 2 ]; do
1457c478bd9Sstevel@tonic-gate		shift
146*e11c3f44Smeem		intf_name=$1
147*e11c3f44Smeem		while [ $# -gt 1 -a "$2" != "/etc/hostname6" ]; do
148*e11c3f44Smeem			intf_name="$intf_name.$2"
1497c478bd9Sstevel@tonic-gate			shift
1507c478bd9Sstevel@tonic-gate		done
1517c478bd9Sstevel@tonic-gate		shift
152*e11c3f44Smeem
153*e11c3f44Smeem	        read one rest < /etc/hostname6.$intf_name
154*e11c3f44Smeem		if [ "$one" = ipmp ]; then
155*e11c3f44Smeem			ipmp6_list="$ipmp6_list $intf_name"
156*e11c3f44Smeem		else
157*e11c3f44Smeem			inet6_list="$inet6_list $intf_name"
1587c478bd9Sstevel@tonic-gate		fi
1597c478bd9Sstevel@tonic-gate	done
1607c478bd9Sstevel@tonic-gatefi
1617c478bd9Sstevel@tonic-gate
162*e11c3f44Smeem#
163*e11c3f44Smeem# Create all of the IPv4 IPMP interfaces.
164*e11c3f44Smeem#
165*e11c3f44Smeemif [ -n "$ipmp_list" ]; then
166*e11c3f44Smeem	set -- $ipmp_list
167*e11c3f44Smeem	while [ $# -gt 0 ]; do
168*e11c3f44Smeem	    	if /sbin/ifconfig $1 ipmp; then
169*e11c3f44Smeem			ipmp_created="$ipmp_created $1"
170*e11c3f44Smeem		else
171*e11c3f44Smeem			ipmp_failed="$ipmp_failed $1"
172*e11c3f44Smeem		fi
173*e11c3f44Smeem		shift
174*e11c3f44Smeem	done
175*e11c3f44Smeem	[ -n "$ipmp_failed" ] && warn_failed_ifs "create IPv4 IPMP" \
176*e11c3f44Smeem	    "$ipmp_failed"
177*e11c3f44Smeemfi
1787c478bd9Sstevel@tonic-gate
1797c478bd9Sstevel@tonic-gate#
1807c478bd9Sstevel@tonic-gate# Step through the IPv4 interface list and try to plumb every interface.
1817c478bd9Sstevel@tonic-gate# Generate list of plumbed and failed IPv4 interfaces.
1827c478bd9Sstevel@tonic-gate#
1837c478bd9Sstevel@tonic-gateif [ -n "$inet_list" ]; then
1847c478bd9Sstevel@tonic-gate	set -- $inet_list
1857c478bd9Sstevel@tonic-gate	while [ $# -gt 0 ]; do
1867c478bd9Sstevel@tonic-gate		/sbin/ifconfig $1 plumb
1877c478bd9Sstevel@tonic-gate		if /sbin/ifconfig $1 inet >/dev/null 2>&1; then
1887c478bd9Sstevel@tonic-gate			inet_plumbed="$inet_plumbed $1"
1897c478bd9Sstevel@tonic-gate		else
1907c478bd9Sstevel@tonic-gate			inet_failed="$inet_failed $1"
1917c478bd9Sstevel@tonic-gate		fi
1927c478bd9Sstevel@tonic-gate		shift
1937c478bd9Sstevel@tonic-gate	done
194*e11c3f44Smeem	[ -n "$inet_failed" ] && warn_failed_ifs "plumb IPv4" "$inet_failed"
1957c478bd9Sstevel@tonic-gatefi
1967c478bd9Sstevel@tonic-gate
197516fc7f3Shx147065# Run autoconf to connect to a WLAN if the interface is a wireless one
198516fc7f3Shx147065if [ -x /sbin/wificonfig -a -n "$inet_plumbed" ]; then
199516fc7f3Shx147065	set -- $inet_plumbed
200516fc7f3Shx147065	while [ $# -gt 0 ]; do
201516fc7f3Shx147065			if [ -r /dev/wifi/$1 ]; then
202516fc7f3Shx147065				/sbin/wificonfig -i $1 startconf >/dev/null
203516fc7f3Shx147065			fi
204516fc7f3Shx147065		shift
205516fc7f3Shx147065	done
206516fc7f3Shx147065fi
207516fc7f3Shx147065
2087c478bd9Sstevel@tonic-gate#
2097c478bd9Sstevel@tonic-gate# Step through the IPv6 interface list and plumb every interface.
2107c478bd9Sstevel@tonic-gate# Generate list of plumbed and failed IPv6 interfaces.  Each plumbed
2117c478bd9Sstevel@tonic-gate# interface will be brought up later, after processing any contents of
2127c478bd9Sstevel@tonic-gate# the /etc/hostname6.* file.
2137c478bd9Sstevel@tonic-gate#
2147c478bd9Sstevel@tonic-gateif [ -n "$inet6_list" ]; then
2157c478bd9Sstevel@tonic-gate	set -- $inet6_list
2167c478bd9Sstevel@tonic-gate	while [ $# -gt 0 ]; do
2177c478bd9Sstevel@tonic-gate		/sbin/ifconfig $1 inet6 plumb
2187c478bd9Sstevel@tonic-gate		if /sbin/ifconfig $1 inet6 >/dev/null 2>&1; then
2197c478bd9Sstevel@tonic-gate			inet6_plumbed="$inet6_plumbed $1"
2207c478bd9Sstevel@tonic-gate		else
2217c478bd9Sstevel@tonic-gate			inet6_failed="$inet6_failed $1"
2227c478bd9Sstevel@tonic-gate		fi
2237c478bd9Sstevel@tonic-gate		shift
2247c478bd9Sstevel@tonic-gate	done
225*e11c3f44Smeem	[ -n "$inet6_failed" ] && warn_failed_ifs "plumb IPv6" "$inet6_failed"
226*e11c3f44Smeemfi
227*e11c3f44Smeem
228*e11c3f44Smeem#
229*e11c3f44Smeem# Create all of the IPv6 IPMP interfaces.
230*e11c3f44Smeem#
231*e11c3f44Smeemif [ -n "$ipmp6_list" ]; then
232*e11c3f44Smeem	set -- $ipmp6_list
233*e11c3f44Smeem	while [ $# -gt 0 ]; do
234*e11c3f44Smeem	    	if /sbin/ifconfig $1 inet6 ipmp; then
235*e11c3f44Smeem			ipmp6_created="$ipmp6_created $1"
236*e11c3f44Smeem		else
237*e11c3f44Smeem			ipmp6_failed="$ipmp6_failed $1"
238*e11c3f44Smeem 		fi
239*e11c3f44Smeem		shift
240*e11c3f44Smeem	done
241*e11c3f44Smeem	[ -n "$ipmp6_failed" ] && warn_failed_ifs "create IPv6 IPMP" \
242*e11c3f44Smeem	    "$ipmp6_failed"
2437c478bd9Sstevel@tonic-gatefi
2447c478bd9Sstevel@tonic-gate
245f4b3ec61Sdh155122if smf_is_globalzone; then
2467c478bd9Sstevel@tonic-gate	#
24730890389Sartem	# Wifi drivers use special property interfaces that are not supported
24830890389Sartem	# by the existing property persistence mechanism, so if a wifi driver
24930890389Sartem	# unloads and then is subsequently reloaded, associated links' properties
25030890389Sartem	# will not be restored.  For now, wait until after interfaces have been
251f4b3ec61Sdh155122	# plumbed (above) to initialize link properties.
2520ba2cbe9Sxc151355	#
25330890389Sartem	/sbin/dladm init-linkprop -w
254f4b3ec61Sdh155122fi
2550ba2cbe9Sxc151355
2560ba2cbe9Sxc151355#
257*e11c3f44Smeem# Process the /etc/hostname[6].* files for IPMP interfaces.  Processing these
258*e11c3f44Smeem# before non-IPMP interfaces avoids accidental implicit IPMP group creation.
2597c478bd9Sstevel@tonic-gate#
260*e11c3f44Smeem[ -n "$ipmp_created" ] && if_configure inet "IPMP" $ipmp_created
261*e11c3f44Smeem[ -n "$ipmp6_created" ] && if_configure inet6 "IPMP" $ipmp6_created
2627c478bd9Sstevel@tonic-gate
2637c478bd9Sstevel@tonic-gate#
264*e11c3f44Smeem# Process the /etc/hostname[6].* files for non-IPMP interfaces.
2657c478bd9Sstevel@tonic-gate#
266*e11c3f44Smeem[ -n "$inet_plumbed" ] && if_configure inet "" $inet_plumbed
267*e11c3f44Smeem[ -n "$inet6_plumbed" ] && if_configure inet6 "" $inet6_plumbed
268*e11c3f44Smeem
269*e11c3f44Smeem#
270*e11c3f44Smeem# For the IPv4 and IPv6 interfaces that failed to plumb, find (or create)
271*e11c3f44Smeem# IPMP meta-interfaces to host their data addresses.
272*e11c3f44Smeem#
273*e11c3f44Smeem[ -n "$inet_failed" ] && move_addresses inet
274*e11c3f44Smeem[ -n "$inet6_failed" ] && move_addresses inet6
2757c478bd9Sstevel@tonic-gate
2767c478bd9Sstevel@tonic-gate# Run DHCP if requested. Skip boot-configured interface.
2777c478bd9Sstevel@tonic-gateinterface_names="`echo /etc/dhcp.*[0-9] 2>/dev/null`"
2787c478bd9Sstevel@tonic-gateif [ "$interface_names" != '/etc/dhcp.*[0-9]' ]; then
2797c478bd9Sstevel@tonic-gate	#
2807c478bd9Sstevel@tonic-gate	# First find the primary interface. Default to the first
2817c478bd9Sstevel@tonic-gate	# interface if not specified. First primary interface found
2827c478bd9Sstevel@tonic-gate	# "wins". Use care not to "reconfigure" a net-booted interface
2837c478bd9Sstevel@tonic-gate	# configured using DHCP. Run through the list of interfaces
2847c478bd9Sstevel@tonic-gate	# again, this time trying DHCP.
2857c478bd9Sstevel@tonic-gate	#
2867c478bd9Sstevel@tonic-gate	i4d_fail=
2877c478bd9Sstevel@tonic-gate	firstif=
2887c478bd9Sstevel@tonic-gate	primary=
2897c478bd9Sstevel@tonic-gate	ORIGIFS="$IFS"
2907c478bd9Sstevel@tonic-gate	IFS="${IFS}."
2917c478bd9Sstevel@tonic-gate	set -- $interface_names
2927c478bd9Sstevel@tonic-gate
2937c478bd9Sstevel@tonic-gate	while [ $# -ge 2 ]; do
2947c478bd9Sstevel@tonic-gate		shift
2957c478bd9Sstevel@tonic-gate		[ -z "$firstif" ] && firstif=$1
2967c478bd9Sstevel@tonic-gate
2977c478bd9Sstevel@tonic-gate		for i in `shcat /etc/dhcp\.$1`; do
2987c478bd9Sstevel@tonic-gate			if [ "$i" = primary ]; then
2997c478bd9Sstevel@tonic-gate				primary=$1
3007c478bd9Sstevel@tonic-gate				break
3017c478bd9Sstevel@tonic-gate			fi
3027c478bd9Sstevel@tonic-gate		done
3037c478bd9Sstevel@tonic-gate
3047c478bd9Sstevel@tonic-gate		[ -n "$primary" ] && break
3057c478bd9Sstevel@tonic-gate		shift
3067c478bd9Sstevel@tonic-gate	done
3077c478bd9Sstevel@tonic-gate
3087c478bd9Sstevel@tonic-gate	[ -z "$primary" ] && primary="$firstif"
3097c478bd9Sstevel@tonic-gate	cmdline=`shcat /etc/dhcp\.${primary}`
3107c478bd9Sstevel@tonic-gate
3117c478bd9Sstevel@tonic-gate	if [ "$_INIT_NET_IF" != "$primary" ]; then
3127c478bd9Sstevel@tonic-gate		echo "starting DHCP on primary interface $primary"
3137c478bd9Sstevel@tonic-gate		/sbin/ifconfig $primary auto-dhcp primary $cmdline
3147c478bd9Sstevel@tonic-gate		# Exit code 4 means ifconfig timed out waiting for dhcpagent
3157c478bd9Sstevel@tonic-gate		[ $? != 0 ] && [ $? != 4 ] && i4d_fail="$i4d_fail $primary"
3167c478bd9Sstevel@tonic-gate	fi
3177c478bd9Sstevel@tonic-gate
3187c478bd9Sstevel@tonic-gate	set -- $interface_names
3197c478bd9Sstevel@tonic-gate
3207c478bd9Sstevel@tonic-gate	while [ $# -ge 2 ]; do
3217c478bd9Sstevel@tonic-gate		shift
3227c478bd9Sstevel@tonic-gate		cmdline=`shcat /etc/dhcp\.$1`
3237c478bd9Sstevel@tonic-gate		if [ "$1" != "$primary" -a \
3247c478bd9Sstevel@tonic-gate			"$1" != "$_INIT_NET_IF"  ]; then
3257c478bd9Sstevel@tonic-gate			echo "starting DHCP on interface $1"
3267c478bd9Sstevel@tonic-gate			/sbin/ifconfig $1 dhcp start wait 0 $cmdline
3277c478bd9Sstevel@tonic-gate			# Exit code can't be timeout when wait is 0
3287c478bd9Sstevel@tonic-gate			[ $? != 0 ] && i4d_fail="$i4d_fail $1"
3297c478bd9Sstevel@tonic-gate		fi
3307c478bd9Sstevel@tonic-gate		shift
3317c478bd9Sstevel@tonic-gate	done
3327c478bd9Sstevel@tonic-gate	IFS="$ORIGIFS"
3337c478bd9Sstevel@tonic-gate	unset ORIGIFS
334*e11c3f44Smeem	[ -n "$i4d_fail" ] && warn_failed_ifs "configure IPv4 DHCP" "$i4d_fail"
3357c478bd9Sstevel@tonic-gatefi
3367c478bd9Sstevel@tonic-gate
3370659b2b8Sse146197# In order to avoid bringing up the interfaces that have
3380659b2b8Sse146197# intentionally been left down, perform RARP only if the system
3390659b2b8Sse146197# has no configured hostname in /etc/nodename
3400659b2b8Sse146197hostname="`shcat /etc/nodename 2>/dev/null`"
3410659b2b8Sse146197if [ "$_INIT_NET_STRATEGY" = "rarp" -o -z "$hostname" ]; then
3427c478bd9Sstevel@tonic-gate	/sbin/ifconfig -adD4 auto-revarp netmask + broadcast + up
3430659b2b8Sse146197fi
3447c478bd9Sstevel@tonic-gate
3457c478bd9Sstevel@tonic-gate#
3467c478bd9Sstevel@tonic-gate# If the /etc/defaultrouter file exists, process it now so that the next
3477c478bd9Sstevel@tonic-gate# stage of booting will have access to NFS.
3487c478bd9Sstevel@tonic-gate#
3497c478bd9Sstevel@tonic-gateif [ -f /etc/defaultrouter ]; then
3507c478bd9Sstevel@tonic-gate	while read router rubbish; do
3517c478bd9Sstevel@tonic-gate		case "$router" in
3527c478bd9Sstevel@tonic-gate			'#'* | '') ;;	#  Ignore comments, empty lines
3537c478bd9Sstevel@tonic-gate			*)	/sbin/route -n add default -gateway $router ;;
3547c478bd9Sstevel@tonic-gate		esac
3557c478bd9Sstevel@tonic-gate	done </etc/defaultrouter
3567c478bd9Sstevel@tonic-gatefi
3577c478bd9Sstevel@tonic-gate
3587c478bd9Sstevel@tonic-gate#
359843e1988Sjohnlev# If we get here and were not asked to plumb any IPv4 interfaces, look
360843e1988Sjohnlev# for boot properties that direct us.
361843e1988Sjohnlev#
362843e1988Sjohnlev# - The "network-interface" property is required and indicates the
363843e1988Sjohnlev#   interface name.
364843e1988Sjohnlev# - The "xpv-hcp" property, if present, is used by the hypervisor
365843e1988Sjohnlev#   tools to indicate how the specified interface should be configured.
366843e1988Sjohnlev#   Permitted values are "dhcp" and "off", where "off" indicates static
367843e1988Sjohnlev#   IP configuration.
368843e1988Sjohnlev#
369843e1988Sjohnlev# In the case where "xpv-hcp" is set to "dhcp", no further properties
370843e1988Sjohnlev# are required or examined.
371843e1988Sjohnlev#
372843e1988Sjohnlev# In the case where "xpv-hcp" is not present or set to "off", the
373843e1988Sjohnlev# "host-ip" and "subnet-mask" properties are used to configure
374843e1988Sjohnlev# the specified interface.  The "router-ip" property, if present,
375843e1988Sjohnlev# is used to add a default route.
376843e1988Sjohnlev#
377843e1988Sjohnlevnic="`/sbin/devprop network-interface`"
378843e1988Sjohnlevif smf_is_globalzone && [ -z "$inet_list" ] && [ -n "$nic" ]; then
379843e1988Sjohnlev	hcp="`/sbin/devprop xpv-hcp`"
380843e1988Sjohnlev	case "$hcp" in
381843e1988Sjohnlev	"dhcp")
382843e1988Sjohnlev		/sbin/ifconfig $nic plumb 2>/dev/null
383843e1988Sjohnlev		[ -n "`/sbin/ifconfig $nic 2>/dev/null`" ] && (
384843e1988Sjohnlev			# The interface is successfully plumbed, so
385843e1988Sjohnlev			# modify "inet_list" to force the exit code
386843e1988Sjohnlev			# checks to work.
387843e1988Sjohnlev			inet_list=$nic;
388843e1988Sjohnlev			# Given that this is the only IPv4 interface,
389843e1988Sjohnlev			# we assert that it is primary.
390843e1988Sjohnlev			echo "starting DHCP on primary interface $primary";
391843e1988Sjohnlev			/sbin/ifconfig $nic auto-dhcp primary;
392843e1988Sjohnlev			# Exit code 4 means ifconfig timed out waiting
393843e1988Sjohnlev			# for dhcpagent
394843e1988Sjohnlev			[ $? != 0 ] && [ $? != 4 ] && \
395843e1988Sjohnlev			    i4d_fail="$i4d_fail $nic";
396843e1988Sjohnlev		)
397843e1988Sjohnlev		;;
398843e1988Sjohnlev
399843e1988Sjohnlev	"off"|"")
400843e1988Sjohnlev		/sbin/devprop host-ip subnet-mask router-ip | (
401843e1988Sjohnlev			read ip;
402843e1988Sjohnlev			read mask;
403843e1988Sjohnlev			read router;
404843e1988Sjohnlev			[ -n "$ip" ] && [ -n "$mask" ] && \
405843e1988Sjohnlev				/sbin/ifconfig $nic plumb 2>/dev/null
406843e1988Sjohnlev			[ -n "`/sbin/ifconfig $nic 2>/dev/null`" ] && (
407843e1988Sjohnlev				# The interface is successfully
408843e1988Sjohnlev				# plumbed, so modify "inet_list" to
409843e1988Sjohnlev				# force the exit code checks to work.
410843e1988Sjohnlev				inet_list=$nic;
411843e1988Sjohnlev				/sbin/ifconfig $nic  inet $ip \
412843e1988Sjohnlev				    netmask $mask broadcast + up 2>/dev/null;
413843e1988Sjohnlev				[ -n "$router" ] && route add \
414843e1988Sjohnlev				    default $router 2>/dev/null;
415843e1988Sjohnlev			)
416843e1988Sjohnlev		)
417843e1988Sjohnlev		;;
418843e1988Sjohnlev	esac
419843e1988Sjohnlevfi
420843e1988Sjohnlev
421843e1988Sjohnlev#
4227c478bd9Sstevel@tonic-gate# We tell smf this service is online if any of the following is true:
4237c478bd9Sstevel@tonic-gate# - no interfaces were configured for plumbing and no DHCP failures
4247c478bd9Sstevel@tonic-gate# - any non-loopback IPv4 interfaces are up and have a non-zero address
4257c478bd9Sstevel@tonic-gate# - there are any DHCP interfaces started
4267c478bd9Sstevel@tonic-gate# - any non-loopback IPv6 interfaces are up
4277c478bd9Sstevel@tonic-gate#
4287c478bd9Sstevel@tonic-gate# If we weren't asked to configure any interfaces, exit
4297c478bd9Sstevel@tonic-gateif [ -z "$inet_list" ] && [ -z "$inet6_list" ]; then
4307c478bd9Sstevel@tonic-gate	# Config error if DHCP was attempted without plumbed interfaces
4317c478bd9Sstevel@tonic-gate	[ -n "$i4d_fail" ] && exit $SMF_EXIT_ERR_CONFIG
4327c478bd9Sstevel@tonic-gate	exit $SMF_EXIT_OK
4337c478bd9Sstevel@tonic-gatefi
4347c478bd9Sstevel@tonic-gate
4357c478bd9Sstevel@tonic-gate# Any non-loopback IPv4 interfaces with usable addresses up?
4367c478bd9Sstevel@tonic-gateif [ -n "`/sbin/ifconfig -a4u`" ]; then
4377c478bd9Sstevel@tonic-gate    	/sbin/ifconfig -a4u | while read intf addr rest; do
4387c478bd9Sstevel@tonic-gate		[ $intf = inet ] && [ $addr != 127.0.0.1 ] &&
439843e1988Sjohnlev		[ $addr != 0.0.0.0 ] && exit $SMF_EXIT_OK
4407c478bd9Sstevel@tonic-gate	done && exit $SMF_EXIT_OK
4417c478bd9Sstevel@tonic-gatefi
4427c478bd9Sstevel@tonic-gate
4437c478bd9Sstevel@tonic-gate# Any DHCP interfaces started?
4447c478bd9Sstevel@tonic-gate[ -n "`/sbin/ifconfig -a4 dhcp status 2>/dev/null`" ] && exit $SMF_EXIT_OK
4457c478bd9Sstevel@tonic-gate
4467c478bd9Sstevel@tonic-gate# Any non-loopback IPv6 interfaces up?
4477c478bd9Sstevel@tonic-gateif [ -n "`/sbin/ifconfig -au6`" ]; then
4487c478bd9Sstevel@tonic-gate	/sbin/ifconfig -au6 | while read intf addr rest; do
449843e1988Sjohnlev		[ $intf = inet6 ] && [ $addr != ::1/128 ] && exit $SMF_EXIT_OK
4507c478bd9Sstevel@tonic-gate	done && exit $SMF_EXIT_OK
4517c478bd9Sstevel@tonic-gatefi
4527c478bd9Sstevel@tonic-gate
4537c478bd9Sstevel@tonic-gate# This service was supposed to configure something yet didn't.  Exit
4547c478bd9Sstevel@tonic-gate# with config error.
4557c478bd9Sstevel@tonic-gateexit $SMF_EXIT_ERR_CONFIG
456