xref: /illumos-gate/usr/src/cmd/svc/milestone/net-nwam (revision cb04b8739c50e3e6d12e89b790fa7b8d0d899865)
1#!/sbin/sh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22#
23# Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24#
25
26. /lib/svc/share/smf_include.sh
27. /lib/svc/share/net_include.sh
28
29# FMRI constants
30IPSEC_IKE_FMRI="svc:/network/ipsec/ike"
31IPSEC_POLICY_FMRI="svc:/network/ipsec/policy"
32IPFILTER_FMRI="svc:/network/ipfilter:default"
33NIS_CLIENT_FMRI="svc:/network/nis/client:default"
34NET_PHYS_FMRI="svc:/network/physical:default"
35NET_NWAM_FMRI="svc:/network/physical:nwam"
36NET_LOC_FMRI="svc:/network/location:default"
37
38#
39# Default *.conf files
40# Set appropriate config SMF property to these files when NWAM is stopped
41# and corresponding config properties in the Legacy location are emtpy
42#
43IPF6_DEFAULT_CONFIG_FILE=/etc/ipf/ipf6.conf
44IPNAT_DEFAULT_CONFIG_FILE=/etc/ipf/ipnat.conf
45IPPOOL_DEFAULT_CONFIG_FILE=/etc/ipf/ippool.conf
46IPSEC_IKE_DEFAULT_CONFIG_FILE=/etc/inet/ike/config
47IPSEC_POLICY_DEFAULT_CONFIG_FILE=/etc/inet/ipsecinit.conf
48
49# commands
50BASENAME=/usr/bin/basename
51CAT=/usr/bin/cat
52CP=/usr/bin/cp
53DOMAINNAME=/usr/bin/domainname
54GREP=/usr/bin/grep
55LDAPCLIENT=/usr/sbin/ldapclient
56MKDIR=/usr/bin/mkdir
57MKFIFO=/usr/bin/mkfifo
58NAWK=/usr/bin/nawk
59NWAMCFG=/usr/sbin/nwamcfg
60RM=/usr/bin/rm
61SVCADM=/usr/sbin/svcadm
62SVCCFG=/usr/sbin/svccfg
63SVCPROP=/usr/bin/svcprop
64
65# Path to directories
66# We don't have a writable file system so we write to /etc/svc/volatile and
67# then later copy anything interesting to /etc/nwam.
68VOL_NWAM_PATH=/etc/svc/volatile/nwam
69VOL_LEGACY_PATH=$VOL_NWAM_PATH/Legacy
70PERM_LEGACY_PATH=/etc/nwam/loc/Legacy
71NIS_BIND_PATH=/var/yp/binding
72
73#
74# copy_to_legacy_loc <file>
75#
76# Copies the file to the Legacy location directory
77# (in /etc/svc/volatile/nwam/Legacy)
78#
79copy_to_legacy_loc() {
80	$MKDIR -p $VOL_LEGACY_PATH
81	if [ -f "$1" ]; then
82		$CP -p $1 $VOL_LEGACY_PATH
83	fi
84}
85
86#
87# copy_from_legacy_loc <destination file>
88#
89# Copies file with the same name from Legacy location
90# (in /etc/nwam/loc/Legacy) to the given destination file
91#
92copy_from_legacy_loc () {
93	DEST_DIR=`/usr/bin/dirname $1`
94	SRC_FILE="$PERM_LEGACY_PATH/`$BASENAME $1`"
95
96	# Make destination directory if needed
97	if [ ! -d "$DEST_DIR" ]; then
98		$MKDIR -p $DEST_DIR
99	fi
100
101	if [ -f "$SRC_FILE" ]; then
102		$CP -p $SRC_FILE $DEST_DIR
103	fi
104}
105
106#
107# write_loc_prop <property> <value> <file>
108#
109# Appends to <file> a nwamcfg command to set <property> to <value> if non-empty
110#
111write_loc_prop () {
112	prop=$1
113	val=$2
114	file=$3
115
116	if [ -n "$val" -a -n "$file" ]; then
117		echo "set $prop=$val" >> $file
118	fi
119}
120
121#
122# set_smf_prop <fmri> <property name> <property value>
123#
124set_smf_prop () {
125	$SVCCFG -s $1 setprop $2 = astring: "$3" && return
126}
127
128#
129# get_smf_prop <fmri> <property name>
130#
131get_smf_prop () {
132	$SVCPROP -p $2 $1
133}
134
135#
136# Creates Legacy location from the current configuration
137#
138create_legacy_loc () {
139	CREATE_LOC_LEGACY_FILE=$VOL_NWAM_PATH/create_loc_legacy
140
141	#
142	# Write nwamcfg commands to create Legacy location to
143	# $CREATE_LOC_LEGACY_FILE as values for properties are determined
144	# Note that some of the *_CONFIG_FILE variables point at copies of
145	# files we've made and others indicate where those copies should be
146	# if we are enabling the location.
147	#
148	echo "create loc Legacy" > $CREATE_LOC_LEGACY_FILE
149	write_loc_prop "activation-mode" "system" $CREATE_LOC_LEGACY_FILE
150
151	NAMESERVICES=""
152	NAMESERVICES_CONFIG_FILE=""
153	DNS_NAMESERVICE_CONFIGSRC=""
154	DNS_NAMESERVICE_DOMAIN=""
155	DNS_NAMESERVICE_SERVERS=""
156	DNS_NAMESERVICE_SEARCH=""
157	NIS_NAMESERVICE_CONFIGSRC=""
158	NIS_NAMESERVICE_SERVERS=""
159	LDAP_NAMESERVICE_CONFIGSRC=""
160	LDAP_NAMESERVICE_SERVERS=""
161	DEFAULT_DOMAIN=""
162
163	# Copy /etc/nsswitch.conf file
164	copy_to_legacy_loc /etc/nsswitch.conf
165	NAMESERVICES_CONFIG_FILE="$VOL_LEGACY_PATH/nsswitch.conf"
166
167	# Gather DNS info from resolv.conf if present.
168	if [ -f /etc/resolv.conf ]; then
169		NAMESERVICES="dns,"
170		$GREP -i "added by dhcp" /etc/nsswitch.conf >/dev/null
171		if [ $? -eq 0 ]; then
172			DNS_NAMESERVICE_CONFIGSRC="dhcp"
173		else
174			DNS_NAMESERVICE_CONFIGSRC="manual"
175			DNS_NAMESERVICE_DOMAIN=`$NAWK '$1 == "domain" {\
176			    print $2 }' < /etc/resolv.conf`
177			DNS_NAMESERVICE_SERVERS=`$NAWK '$1 == "nameserver" \
178			    { printf "%s,", $2 }' < /etc/resolv.conf`
179			DNS_NAMESERVICE_SEARCH=`$NAWK '$1 == "search" \
180			    { printf "%s,", $2 }' < /etc/resolv.conf`
181			copy_to_legacy_loc /etc/resolv.conf
182		fi
183	fi
184
185	# Gather NIS info from appropriate file if present.
186	if service_is_enabled $NIS_CLIENT_FMRI; then
187		NAMESERVICES="${NAMESERVICES}nis,"
188		NIS_NAMESERVICE_CONFIGSRC="manual"
189		DEFAULT_DOMAIN=`$CAT /etc/defaultdomain`
190
191		yp_servers=`$NAWK '{ printf "%s ", $1 }' \
192		    < $NIS_BIND_PATH/$DEFAULT_DOMAIN/ypservers`
193		for serv in $yp_servers; do
194			if is_valid_addr $serv; then
195				addr="$serv,"
196			else
197				addr=`$GREP -iw $serv /etc/inet/hosts | \
198				    $NAWK '{ printf "%s,", $1 }'`
199			fi
200			NIS_NAMESERVICE_SERVERS="${NIS_NAMESERVICE_SERVERS}$addr"
201		done
202	fi
203
204	# Gather LDAP info via ldapclient(1M).
205	if [ -f /var/ldap/ldap_client_file ]; then
206		copy_to_legacy /var/ldap/ldap_client_file
207		NAMESERVICES="${NAMESERVICES}ldap,"
208		LDAP_NAMESERVICE_CONFIGSRC="manual"
209		LDAP_NAMESERVICE_SERVERS=`$LDAPCLIENT list 2>/dev/null | \
210		    $NAWK '$1 == "preferredServerList:" { print $2 }'`
211		DEFAULT_DOMAIN=`$CAT /etc/defaultdomain`
212	fi
213
214	# Now, write nwamcfg commands for nameservices
215	write_loc_prop "nameservices" $NAMESERVICES $CREATE_LOC_LEGACY_FILE
216 	write_loc_prop "nameservices-config-file" $NAMESERVICES_CONFIG_FILE \
217 	    $CREATE_LOC_LEGACY_FILE
218	write_loc_prop "dns-nameservice-configsrc" $DNS_NAMESERVICE_CONFIGSRC \
219	    $CREATE_LOC_LEGACY_FILE
220	write_loc_prop "dns-nameservice-domain" $DNS_NAMESERVICE_DOMAIN \
221 	    $CREATE_LOC_LEGACY_FILE
222	write_loc_prop "dns-nameservice-servers" $DNS_NAMESERVICE_SERVERS \
223	    $CREATE_LOC_LEGACY_FILE
224	write_loc_prop "dns-nameservice-search" $DNS_NAMESERVICE_SEARCH \
225	    $CREATE_LOC_LEGACY_FILE
226	write_loc_prop "nis-nameservice-configsrc" $NIS_NAMESERVICE_CONFIGSRC \
227	    $CREATE_LOC_LEGACY_FILE
228	write_loc_prop "nis-nameservice-servers" $NIS_NAMESERVICE_SERVERS \
229	    $CREATE_LOC_LEGACY_FILE
230	write_loc_prop "ldap-nameservice-configsrc" $LDAP_NAMESERVICE_CONFIGSRC\
231	    $CREATE_LOC_LEGACY_FILE
232	write_loc_prop "ldap-nameservice-servers" $LDAP_NAMESERVICE_SERVERS \
233	    $CREATE_LOC_LEGACY_FILE
234	write_loc_prop "default-domain" $DEFAULT_DOMAIN $CREATE_LOC_LEGACY_FILE
235
236	# Retrieve NFSv4 domain.
237	if [ -f /etc/default/nfs ]; then
238		copy_to_legacy_loc /etc/default/nfs
239		NFS_DOMAIN=`$NAWK '/^NFSMAPID_DOMAIN.*/ { FS="=" ; print $2 }' \
240		    < /etc/default/nfs`
241		write_loc_prop "nfsv4-domain" \
242		    $NFS_DOMAIN $CREATE_LOC_LEGACY_FILE
243	fi
244
245	IPF_CONFIG_FILE=""
246	IPF6_CONFIG_FILE=""
247	IPNAT_CONFIG_FILE=""
248	IPPOOL_CONFIG_FILE=""
249	IKE_CONFIG_FILE=""
250	IPSEC_POLICY_CONFIG_FILE=""
251
252	#
253	# IPFilter
254	#
255	# If the firewall policy is "custom", simply copy the
256	# custom_policy_file.  If the firewall policy is "none", "allow" or
257	# "deny", save the value as "/<value>".  When reverting back to the
258	# Legacy location, these values will have to be treated as special.
259	#
260	# For all configuration files, copy them to the Legacy directory.
261	# Use the respective properties to remember the original locations
262	# of the files so that they can be copied back there when NWAM is
263	# stopped.
264	#
265	if service_is_enabled $IPFILTER_FMRI; then
266		FIREWALL_POLICY=`get_smf_prop $IPFILTER_FMRI \
267		    firewall_config_default/policy`
268		if [ "$FIREWALL_POLICY" = "custom" ]; then
269			IPF_CONFIG_FILE=`get_smf_prop $IPFILTER_FMRI \
270			    firewall_config_default/custom_policy_file`
271			copy_to_legacy_loc $IPF_CONFIG_FILE
272		else
273			# save value as /none, /allow, or /deny
274			IPF_CONFIG_FILE="/$FIREWALL_POLICY"
275		fi
276		IPF6_CONFIG_FILE=`get_smf_prop $IPFILTER_FMRI \
277		    config/ipf6_config_file`
278		copy_to_legacy_loc $IPF6_CONFIG_FILE
279
280		IPNAT_CONFIG_FILE=`get_smf_prop $IPFILTER_FMRI \
281		    config/ipnat_config_file`
282		copy_to_legacy_loc $IPNAT_CONFIG_FILE
283
284		IPPOOL_CONFIG_FILE=`get_smf_prop $IPFILTER_FMRI \
285		    config/ippool_config_file`
286		copy_to_legacy_loc $IPPOOL_CONFIG_FILE
287	fi
288
289	# IKE
290	if service_is_enabled $IPSEC_IKE_FMRI:default; then
291		IKE_CONFIG_FILE=`get_smf_prop $IPSEC_IKE_FMRI config/config_file`
292		copy_to_legacy_loc $IKE_CONFIG_FILE
293	fi
294
295	# IPsec
296	if service_is_enabled $IPSEC_POLICY_FMRI:default; then
297		IPSEC_POLICY_CONFIG_FILE=`get_smf_prop $IPSEC_POLICY_FMRI \
298		    config/config_file`
299		copy_to_legacy_loc $IPSEC_POLICY_CONFIG_FILE
300	fi
301
302	if [ -n "$IPF_CONFIG_FILE" -a \( "$IPF_CONFIG_FILE" = "/allow" \
303	    -o "$IPF_CONFIG_FILE" = "/deny" -o "$IPF_CONFIG_FILE" = "/none" \
304	    -o -f "$IPF_CONFIG_FILE" \) ]; then
305		write_loc_prop "ipfilter-config-file" $IPF_CONFIG_FILE \
306		    $CREATE_LOC_LEGACY_FILE
307	fi
308	if [ -n "$IPF6_CONFIG_FILE" -a -f "$IPF6_CONFIG_FILE" ]; then
309		write_loc_prop "ipfilter-v6-config-file" $IPF6_CONFIG_FILE \
310		    $CREATE_LOC_LEGACY_FILE
311	fi
312	if [ -n "$IPNAT_CONFIG_FILE" -a -f "$IPNAT_CONFIG_FILE" ]; then
313		write_loc_prop "ipnat-config-file" $IPNAT_CONFIG_FILE \
314		    $CREATE_LOC_LEGACY_FILE
315	fi
316	if [ -n "$IPPOOL_CONFIG_FILE" -a -f "$IPPOOL_CONFIG_FILE" ]; then
317		write_loc_prop "ippool-config-file" $IPPOOL_CONFIG_FILE \
318		    $CREATE_LOC_LEGACY_FILE
319	fi
320	if [ -n "$IKE_CONFIG_FILE" -a -f "$IKE_CONFIG_FILE" ]; then
321		write_loc_prop "ike-config-file" $IKE_CONFIG_FILE \
322		    $CREATE_LOC_LEGACY_FILE
323	fi
324	if [ -n "$IPSEC_POLICY_CONFIG_FILE" -a -f "$IPSEC_POLICY_CONFIG_FILE" ]
325	then
326		write_loc_prop "ipsecpolicy-config-file" \
327		    $IPSEC_POLICY_CONFIG_FILE $CREATE_LOC_LEGACY_FILE
328	fi
329
330	# End
331	echo "end" >> $CREATE_LOC_LEGACY_FILE
332	# network/location will create the Legacy location with these commands.
333}
334
335#
336# Undoes the effects of the Legacy location creation
337#
338revert_to_legacy_loc () {
339	$SVCADM disable dns/client
340	$SVCADM disable nis/client
341	$SVCADM disable ldap/client
342
343	# copy nsswitch.conf to /etc/nsswitch.conf
344	copy_from_legacy_loc /etc/nsswitch.conf
345
346	# DNS - copy resolv.conf to /etc/resolv.conf
347	if [ -f "$PERM_LEGACY_PATH/resolv.conf" ]; then
348		copy_from_legacy_loc /etc/resolv.conf
349	        $SVCADM enable dns/client
350	fi
351
352	# set /etc/defaultdomain and domainname(1M)
353	DEFAULT_DOMAIN=`nwam_get_loc_prop Legacy default-domain`
354	if [ -n "$DEFAULT_DOMAIN" ]; then
355		$DOMAINNAME $DEFAULT_DOMAIN
356		$DOMAINNAME > /etc/defaultdomain
357	fi
358
359	# NIS - directory and ypserver in /var/yp/binding/
360	NIS_CONFIGSRC=`nwam_get_loc_prop Legacy nis-nameservice-configsrc`
361	NIS_SERVERS=`nwam_get_loc_prop Legacy nis-nameservice-servers`
362	if [ -n "$NIS_CONFIGSRC" ]; then
363		if [ ! -d "$NIS_BIND_PATH/$DEFAULT_DOMAIN" ]; then
364			$MKDIR -p $NIS_BIND_PATH/$DEFAULT_DOMAIN
365		fi
366		if [ -n "$NIS_SERVERS" ]; then
367			echo "$NIS_SERVERS" | $NAWK \
368			    'FS="," { for (i = 1; i <= NF; i++) print $i }' \
369			    > $NIS_BIND_PATH/$DEFAULT_DOMAIN/ypservers
370		fi
371		$SVCADM enable nis/client
372	fi
373
374	# LDAP - copy ldap_client_file to /var/ldap/ldap_client_file
375	if [ -f "$PERM_LEGACY_PATH/ldap_client_file" ]; then
376		copy_from_legacy_loc /var/ldap/ldap_client_file
377		$SVCADM enable ldap/client
378	fi
379
380	# Copy back nfs file
381        copy_from_legacy_loc /etc/default/nfs
382
383	# IPFilter, IPsec, and IKE
384	ipf_file=`nwam_get_loc_prop Legacy ipfilter-config-file`
385	ipf6_file=`nwam_get_loc_prop Legacy ipfilter-v6-config-file`
386	ipnat_file=`nwam_get_loc_prop Legacy ipnat-config-file`
387	ippool_file=`nwam_get_loc_prop Legacy ippool-config-file`
388	ike_file=`nwam_get_loc_prop Legacy ike-config-file`
389	pol_file=`nwam_get_loc_prop Legacy ipsecpolicy-config-file`
390
391	if [ -n "$ike_file" ]; then
392		copy_from_legacy_loc $ike_file
393		set_smf_prop $IPSEC_IKE_FMRI config/config_file $ike_file
394		$SVCADM refresh $IPSEC_IKE_FMRI
395		$SVCADM enable $IPSEC_IKE_FMRI
396	else
397		set_smf_prop $IPSEC_IKE_FMRI config/config_file \
398		    $IPSEC_IKE_DEFAULT_CONFIG_FILE
399		$SVCADM disable $IPSEC_IKE_FMRI
400	fi
401	if [ -n "$pol_file" ]; then
402		copy_from_legacy_loc $pol_file
403		set_smf_prop $IPSEC_POLICY_FMRI config/config_file $pol_file
404		$SVCADM refresh $IPSEC_POLICY_FMRI
405		$SVCADM enable $IPSEC_POLICY_FMRI
406	else
407		set_smf_prop $IPSEC_POLICY_FMRI config/config_file \
408		    $IPSEC_POLICY_DEFAULT_CONFIG_FILE
409		$SVCADM disable $IPSEC_POLICY_FMRI
410	fi
411
412	refresh_ipf=false
413	if [ -n "$ipf_file" ]; then
414		# change /none, /allow, and /deny to firewall policy
415		if [ "$ipf_file" = "/none" -o "$ipf_file" = "/allow" \
416		    -o "$ipf_file" = "/deny" ]; then
417			policy=`echo "$ipf_file" | $NAWK 'FS="/" { print $2 }'`
418			set_smf_prop $IPFILTER_FMRI \
419			    firewall_config_default/policy $policy
420			# no need to clear custom_policy_file as it isn't "custom"
421		else
422			copy_from_legacy_loc $ipf_file
423			set_smf_prop $IPFILTER_FMRI \
424			    firewall_config_default/policy "custom"
425			set_smf_prop $IPFILTER_FMRI \
426			    firewall_config_default/custom_policy_file $ipf_file
427		fi
428		refresh_ipf=true
429	fi
430	if [ -n "$ipf6_file" ]; then
431		copy_from_legacy_loc $ipf6_file
432		set_smf_prop $IPFILTER_FMRI config/ipf6_config_file $ipf6_file
433		refresh_ipf=true
434	else
435		set_smf_prop $IPFILTER_FMRI config/ipf6_config_file \
436		    $IPF6_DEFAULT_CONFIG_FILE
437	fi
438	if [ -n "$ipnat_file" ]; then
439		copy_from_legacy_loc $ipnat_file
440		set_smf_prop $IPFILTER_FMRI config/ipnat_config_file $ipnat_file
441		refresh_ipf=true
442	else
443		set_smf_prop $IPFILTER_FMRI config/ipnat_config_file \
444		    $IPNAT_DEFAULT_CONFIG_FILE
445	fi
446	if [ -n "$ippool_file" ]; then
447		copy_from_legacy_loc $ippool_file
448		set_smf_prop $IPFILTER_FMRI config/ippool_config_file \
449		    $ippool_file
450		refresh_ipf=true
451	else
452		set_smf_prop $IPFILTER_FMRI config/ippool_config_file \
453		    $IPPOOL_DEFAULT_CONFIG_FILE
454	fi
455
456	$SVCADM refresh $IPFILTER_FMRI
457	if [ "$refresh_ipf" = "true" ]; then
458		$SVCADM enable $IPFILTER_FMRI
459	else
460		$SVCADM disable $IPFILTER_FMRI
461	fi
462
463	# Remove the Legacy directories, script and location
464	$RM -rf $VOL_LEGACY_PATH
465	$RM -rf $PERM_LEGACY_PATH
466	$RM -f $VOL_NWAM_PATH/create_loc_legacy
467	$NWAMCFG destroy loc Legacy
468}
469
470#
471# Script entry point
472#
473# Arguments to net-nwam are
474#       method ( start | refresh | stop | -u | -c )
475#
476
477#
478# Create nwam directory in /etc/svc/volatile
479#
480if [ ! -d $VOL_NWAM_PATH ]; then
481	$MKDIR -m 0755 $VOL_NWAM_PATH
482fi
483
484case "$1" in
485'refresh')
486	/usr/bin/pkill -HUP -z `smf_zonename` nwamd
487	#
488	# Enable network/location.  Needed on first boot post-install as
489	# network/location will not exist until after manifest-import runs.
490	#
491	if service_exists $NET_LOC_FMRI ; then
492		$SVCADM enable -t $NET_LOC_FMRI
493	fi
494	;;
495
496'start')
497	# The real daemon is not started in a shared stack zone. But we need to
498	# create a dummy background process to preserve contract lifetime.
499	smf_configure_ip
500	if [ $? = "1" ] ; then
501		$RM -f $VOL_NWAM_PATH/nwam_blocked
502		$MKFIFO $VOL_NWAM_PATH/nwam_blocked
503		($CAT <$VOL_NWAM_PATH/nwam_blocked >/dev/null) &
504		exit $SMF_EXIT_OK
505	fi
506
507	#
508	# Enable network/location.
509	#
510	if service_exists $NET_LOC_FMRI ; then
511		$SVCADM enable -t $NET_LOC_FMRI
512	fi
513
514	if smf_is_globalzone; then
515		net_reconfigure || exit $SMF_EXIT_ERR_CONFIG
516
517		# Update PVID on interfaces configured with VLAN 1
518		update_pvid
519
520		#
521		# Upgrade handling. The upgrade file consists of a series
522		# of dladm(1M) commands. Note that after we are done, we
523		# cannot rename the upgrade script file as the file system
524		# is still read-only at this point. Defer this to the
525		# manifest-import service.
526		#
527		upgrade_script=/var/svc/profile/upgrade_datalink
528		if [ -f "${upgrade_script}" ]; then
529			. "${upgrade_script}"
530		fi
531
532		#
533		# Upgrade handling for ibd:
534		# After we are done with the upgrade handling, we can not set the
535		# ibd/ibd_upgraded property to "true" as the file system is
536		# read-only at this point. It will be done later by ibd-post-upgrade
537		# service.
538		#
539		ibd_upgraded=`/bin/svcprop -c -p ibd/ibd_upgraded \
540		    svc:/network/physical:default 2> /dev/null`
541		if [ "$ibd_upgraded" != "true" ]; then
542			/sbin/ibd_upgrade -v
543		fi
544
545		# Bring up simnet instances
546		/sbin/dladm up-simnet
547		# Initialize security objects.
548		/sbin/dladm init-secobj
549
550		#
551		# Initialize VNICs, VLANs and flows.  Though they are brought
552		# up here, NWAM will not automatically manage VNICs and VLANs.
553		#
554		/sbin/dladm up-vnic
555		/sbin/dladm up-vlan
556		/sbin/dladm up-part
557		/sbin/dladm up-aggr
558		/sbin/flowadm init-flow
559	fi
560
561	#
562	# We also need to create the Legacy location, which is used
563	# to restore non-NWAM settings that are overwritten when
564	# NWAM is enabled (e.g. resolv.conf, nsswitch.conf, etc.).
565	#
566	$NWAMCFG list loc Legacy >/dev/null 2>&1
567	if [ $? -eq 1 ]; then
568		create_legacy_loc
569	fi
570
571	# start nwamd in foreground; it will daemonize itself
572	if /lib/inet/nwamd ; then
573		exit $SMF_EXIT_OK
574	else
575		exit $SMF_EXIT_ERR_FATAL
576	fi
577	;;
578
579'stop')
580	# We need to make the dummy process we created above stop.
581	smf_configure_ip
582	if [ $? = "1" ] ; then
583		echo "stop" > $VOL_NWAM_PATH/nwam_blocked
584		exit $SMF_EXIT_OK
585	fi
586
587	/usr/bin/pkill -z `smf_zonename` nwamd
588
589	#
590	# Restore the non-NWAM settings.
591	#
592	$NWAMCFG list loc Legacy >/dev/null 2>&1
593	if [ $? -eq 1 ]; then
594		echo "No Legacy location to revert to!"
595		exit $SMF_EXIT_OK
596	fi
597	revert_to_legacy_loc
598	# remove the location property group
599	$SVCCFG -s $NET_LOC_FMRI delpg location
600	;;
601
602'-u')
603	# After we run this part of the script upon the next reboot
604	# network/physical:default will be enabled and
605	# network/physical:nwam will be disabled.
606	# There are various other parts of the system (nscd, nfs) that
607	# depend on continuing to have a working network.  For this
608	# reason we don't change the network configuration immediately.
609	#
610	# Disable network/physical temporarily and make sure that will
611	# be enabled on reboot.
612	$SVCADM disable -st $NET_PHYS_FMRI
613	$SVCCFG -s $NET_PHYS_FMRI setprop general/enabled=true
614
615	# If nwam is online then make sure that it's temporarily enabled.
616	nwam_online=`$SVCPROP -t -p restarter/state $NET_NWAM_FMRI`
617	if [ $? -eq 0 ]; then
618		set -- $nwam_online
619		[ $3 = "online" ] && $SVCADM enable -st $NET_NWAM_FMRI
620	fi
621
622	# Set nwam so that it won't be enabled upon reboot.
623	$SVCCFG -s $NET_NWAM_FMRI setprop general/enabled=false
624	exit 0
625	;;
626
627'-c')
628	# Nothing to do for sysidtool
629	exit 0
630	;;
631
632*)
633	echo "Usage: $0 { start | stop | refresh }"
634	exit $SMF_EXIT_ERR_FATAL
635	;;
636esac
637exit $SMF_EXIT_OK
638