changeset 12873:451918cc0343

6963737 NWAM refreshes continuously, causing toggling of network on osol_142
author Renee Danson Sommerfeld <Renee.Sommerfeld@Oracle.COM>
date Mon, 19 Jul 2010 13:20:31 -0700
parents 6be3b83e2860
children b8f151378367
files usr/src/cmd/svc/milestone/net-loc usr/src/cmd/svc/shell/net_include.sh
diffstat 2 files changed, 107 insertions(+), 82 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/svc/milestone/net-loc	Mon Jul 19 14:15:00 2010 -0600
+++ b/usr/src/cmd/svc/milestone/net-loc	Mon Jul 19 13:20:31 2010 -0700
@@ -83,7 +83,9 @@
 #
 # get_dhcpinfo <code/identifier>
 #
-# echoes the value received through each interface controlled by DHCP
+# echoes the value received through each interface controlled by DHCP;
+# multiple values are echoed as a space-separated list
+#
 # returns:
 #	0 => property is set
 #	1 => property is not set
@@ -101,7 +103,7 @@
 			if [ "$info" = "" ]; then
 				info="$val"
 			else
-				info="$info,$val"
+				info="$info $val"
 			fi
 		fi
  	done
@@ -166,25 +168,12 @@
 }
 
 #
-# enable_nonet
-#
-# Enables the NoNet location.  This function is called whenever an error is
-# detected in the location currently being activated (missing property or the
-# location itself).
-#
-enable_nonet () {
-	echo "reverting to NoNet location"
-	set_smf_prop $SMF_FMRI location/selected NoNet
-	refresh_svc $SMF_FMRI
-	# Refresh nwam so that it re-does the condition checking
-	refresh_svc $NWAM_FMRI
-}
-
-#
 # do_dns <location>
 #
 # Installs DNS information on /etc/resolv.conf for location
 #
+# Returns 0 on success, 1 on failure
+#
 do_dns () {
 	loc=$1
 	file=/etc/resolv.conf
@@ -192,23 +181,24 @@
 	# Write out to temporary file first
 	$TOUCH $file.$$
 
-	DNS_CONFIGSRC=`nwam_get_loc_prop $loc dns-nameservice-configsrc`
+	DNS_CONFIGSRC=`nwam_get_loc_list_prop $loc dns-nameservice-configsrc`
 	if [ -z "$DNS_CONFIGSRC" ]; then
 		echo "missing 'dns-nameservice-configsrc' property for '$loc'"
-		enable_nonet
-		return
+		return 1
 	fi
 
-	(IFS=" ";
-	dns_server_set=false
 	for configsrc in $DNS_CONFIGSRC; do
 		case "$configsrc" in
 		'manual')
+			DNS_SERVERS=`nwam_get_loc_list_prop $loc \
+			    dns-nameservice-servers`
+			if [ -z "$DNS_SERVERS" ]; then
+				echo "DNS nameserver not set for '$loc'"
+				return 1
+			fi
 			DNS_DOMAIN=`nwam_get_loc_prop $loc \
 			    dns-nameservice-domain`
-			DNS_SERVERS=`nwam_get_loc_prop $loc \
-			    dns-nameservice-servers`
-			DNS_SEARCH=`nwam_get_loc_prop $loc \
+			DNS_SEARCH=`nwam_get_loc_list_prop $loc \
 			    dns-nameservice-search`
 			;;
 		'dhcp')
@@ -224,32 +214,27 @@
 		# Write DNS settings
 		if [ -n "$DNS_DOMAIN" ]; then
 			echo "$DNS_DOMAIN" | $NAWK \
-			    'FS="," { for (i = 1; i <= NF; i++) \
+			    '{ for (i = 1; i <= NF; i++) \
 			    print "domain ", $i }' >> $file.$$
 		fi
 		if [ -n "$DNS_SEARCH" ]; then
 			echo "$DNS_SEARCH" | $NAWK \
-                            'FS="," { printf("search"); \
+                            '{ printf("search"); \
 			    for (i = 1; i <= NF; i++) printf(" %s", $i); \
 			    printf("\n") }' >> $file.$$
 		fi
 		if [ -n "$DNS_SERVERS" ]; then
-			dns_server_set=true
 			echo "$DNS_SERVERS" | $NAWK \
-			    'FS="," { for (i = 1; i <= NF; i++) \
+			    '{ for (i = 1; i <= NF; i++) \
 			    print "nameserver ", $i }' >> $file.$$
 		fi
 	done	
-	if [ "$dns_server_set" = "false" ]; then
-		echo "DNS nameserver not set for '$loc'"
-		enable_nonet
-		return
-	fi
-	)
 
 	# Finally, copy our working version to the real thing
 	$MV -f $file.$$ $file
 	start_svc $DNS_CLIENT_FMRI
+
+	return 0
 }
 
 #
@@ -257,40 +242,40 @@
 #
 # Installs NIS information on /var/yp/binding/ for location
 #
+# Returns 0 on success, 1 on failure
+#
 do_nis () {
 	loc=$1
 
-	NIS_CONFIGSRC=`nwam_get_loc_prop $loc nis-nameservice-configsrc`
+	NIS_CONFIGSRC=`nwam_get_loc_list_prop $loc nis-nameservice-configsrc`
 	if [ -z "$NIS_CONFIGSRC" ]; then
 		echo "missing 'nis-nameservice-configsrc' property for '$loc'"
-		enable_nonet
-		return
+		return 1
 	fi
 
-	(IFS=" ";
-	domainname_set=false
 	for configsrc in $NIS_CONFIGSRC; do
 		case "$configsrc" in
 		'manual')
-			NIS_SERVERS=`nwam_get_loc_prop $loc \
+			NIS_SERVERS=`nwam_get_loc_list_prop $loc \
 			    nis-nameservice-servers`
 			DEFAULT_DOMAIN=`nwam_get_loc_prop $loc default-domain`
 			# user-specified default-domain always wins
 			if [ -n "$DEFAULT_DOMAIN" ]; then
 				$DOMAINNAME $DEFAULT_DOMAIN
 				$DOMAINNAME > $ETC_DEFAULT_DOMAIN
-				domainname_set=true
+			else
+				echo "'domainname' not set for '$loc'"
+				return 1
 			fi
 			;;
 		'dhcp')
 			# Use only the first name
 			DEFAULT_DOMAIN=`get_dhcpinfo NISdmain | \
-			    $NAWK 'FS="," { print $1 }'`
+			    $NAWK '{ print $1 }'`
 			NIS_SERVERS=`get_dhcpinfo NISservs`
 			if [ "$domainname_set" = "false" ]; then
 				$DOMAINNAME $DEFAULT_DOMAIN
 				$DOMAINNAME > $ETC_DEFAULT_DOMAIN
-				domainname_set=true
 			fi
 			;;
 		'*')
@@ -304,17 +289,14 @@
 		fi
 		if [ -n "$NIS_SERVERS" ]; then
 			echo "$NIS_SERVERS" | $NAWK \
-			    'FS="," { for (i = 1; i <= NF; i++) print $i }' \
+			    '{ for (i = 1; i <= NF; i++) print $i }' \
 			    > $NIS_BIND_PATH/$DEFAULT_DOMAIN/ypservers
 		fi
 	done
-	if [ "$domainname_set" = "false" ]; then
-		echo "'domainname' not set for '$loc'"
-		enable_nonet
-		return
-	fi
-	)
+
 	start_svc $NIS_CLIENT_FMRI
+
+	return 0
 }
 
 #
@@ -322,47 +304,46 @@
 #
 # Installs LDAP information using ldapclient(1M) for location
 #
+# Returns 0 on success, 1 on failure
+#
 do_ldap () {
 	loc=$1
 
-	LDAP_CONFIGSRC=`nwam_get_loc_prop $loc ldap-nameservice-configsrc`
+	LDAP_CONFIGSRC=`nwam_get_loc_list_prop $loc ldap-nameservice-configsrc`
 	if [ -z "$LDAP_CONFIGSRC" ]; then
 		echo "missing 'ldap-nameservice-configsrc' property for '$loc'"
-		enable_nonet
-		return
+		return 1
 	fi
 
-	(IFS=" ";
-	ldap_config_set=false
 	for configsrc in $LDAP_CONFIGSRC; do
 		case "$configsrc" in
 		'manual')
-			LDAP_SERVERS=`nwam_get_loc_prop $loc \
+			LDAP_SERVERS=`nwam_get_loc_list_prop $loc \
 			    ldap-nameservice-servers`
 			DEFAULT_DOMAIN=`nwam_get_loc_prop $loc default-domain`
+			if [ -z $LDAP_SERVERS -o -z $DEFAULT_DOMAIN ]; then
+				echo "LDAP configuration could not be set "\
+				    "for '$loc'"
+				return 1
+			fi
 			$DOMAINNAME $DEFAULT_DOMAIN
 			$DOMAINNAME > $ETC_DEFAULT_DOMAIN
 			;;
 		'*')
-			echo "Unrecognized LDAP configsrc ${configsrc}; ignoring"
+			echo "Invalid LDAP configsrc ${configsrc}; ignoring"
 			;;
 		esac
 
 		# Use ldapclient(1M) to initialize LDAP client settings.
 		if [ -n "$DEFAULT_DOMAIN" -o -n "$LDAP_SERVERS" ]; then
-			ldap_config_set=true
-			# XXX need to check how to specify multiple LDAP servers.
 			$LDAPCLIENT init -a domainName=$DEFAULT_DOMAIN \
 			    $LDAP_SERVERS
 		fi
 	done
-	if [ "$ldap_config_set" = "false" ]; then
-		echo "LDAP configuration could not be set for '$loc'"
-		enable_nonet
-		return
-	fi
-	)
+
 	start_svc $LDAP_CLIENT_FMRI
+
+	return 0
 }
 
 #
@@ -370,6 +351,8 @@
 #
 # Installs different nameservices for location 
 #
+# Returns 0 on success, 1 on failure
+#
 do_ns () {
 	loc=$1
 
@@ -391,43 +374,39 @@
 	$RM -f $ETC_DEFAULT_DOMAIN
 	$DOMAINNAME " "
 
-	NAMESERVICES=`nwam_get_loc_prop $loc nameservices`
+	NAMESERVICES=`nwam_get_loc_list_prop $loc nameservices`
 	if [ -z "$NAMESERVICES" ]; then
 		echo "missing 'nameservices' property for location '$loc'"
-		enable_nonet
-		return
+		return 1
 	fi
 
 	NAMESERVICES_CONFIG_FILE=`nwam_get_loc_prop \
 	    $loc nameservices-config-file`
 	if [ -z "$NAMESERVICES_CONFIG_FILE" ]; then
 		echo "missing 'nameservices-config-file' property for '$loc'"
-		enable_nonet
-		return
+		return 1
 	fi
 	$CP -p $NAMESERVICES_CONFIG_FILE /etc/nsswitch.conf
 
-	(IFS=,;
 	for ns in $NAMESERVICES; do
 		case "$ns" in
 		'files')
 			# no additional setup needed for files nameservice
 			;;
 		'dns')
-			do_dns $loc
+			do_dns $loc || return 1
 			;;
 		'nis')
-			do_nis $loc
+			do_nis $loc || return 1
 			;;
 		'ldap')
-			do_ldap $loc
+			do_ldap $loc || return 1
 			;;
 		'*')
 			echo "Unrecognized nameservices value ${ns}; ignoring"
 			;;
 		esac
 	done
-	)
 
 	#
 	# Restart other related services
@@ -437,6 +416,8 @@
 	# to enable the service if it's currently disabled.
 	#
 	restart_svc $AUTOFS_FMRI
+
+	return 0
 }
 
 #
@@ -446,6 +427,8 @@
 # service.  If config properties are not set, delete the SMF property and
 # stop the service.
 #
+# Returns 0 on success, 1 on failure
+#
 do_sec () {
 	loc=$1
 
@@ -523,6 +506,8 @@
 		stop_svc $IPFILTER_FMRI
 		refresh_svc $IPFILTER_FMRI
 	fi
+
+	return 0
 }
 
 #
@@ -566,6 +551,8 @@
 #
 # Updates NFSv4 domain for location
 #
+# Returns 0 on success, 1 on failure
+#
 do_nfsv4 () {
 	loc=$1
 
@@ -576,6 +563,8 @@
 	else
 		stop_svc $MAPID_FMRI
 	fi
+
+	return 0
 }
 
 #
@@ -583,14 +572,19 @@
 #
 # Activates the given location
 #
+# Returns 0 on success, 1 on failure
+#
 activate_loc () {
 	loc=$1
 
 	echo activating $loc location
 
-	do_sec $loc
-	do_ns $loc
-	do_nfsv4 $loc
+	#
+	# if we fail to complete any part of the config,
+	# stop activation work and report failure.
+	#
+	do_sec $loc && do_ns $loc && do_nfsv4 $loc && return 0
+	return 1
 }
 
 #
@@ -747,14 +741,24 @@
 		# location hasn't been selected; default to NoNet
 		activate_loc NoNet
 	else
-		# check if the selected location exists
+		#
+		# If the selected location does not exist, or if we fail
+		# to activate it completely, we fall back to the NoNet
+		# location.  Also poke nwamd, so it will check conditions
+		# for a better choice.
+		#
 		$NWAMCFG list loc $sel_loc >/dev/null 2>&1
 		if [ $? -eq 1 ]; then
 			echo "location '$sel_loc' doesn't exist"
-			enable_nonet
+			activate_loc NoNet
+			refresh_svc $NWAM_FMRI
 		else
 			# activate selected location
-			activate_loc $sel_loc
+			if ! activate_loc $sel_loc; then
+				echo "failed to activate '$sel_loc'"
+				activate_loc NoNet
+				refresh_svc $NWAM_FMRI
+			fi
 		fi
 	fi
 fi
--- a/usr/src/cmd/svc/shell/net_include.sh	Mon Jul 19 14:15:00 2010 -0600
+++ b/usr/src/cmd/svc/shell/net_include.sh	Mon Jul 19 13:20:31 2010 -0700
@@ -854,3 +854,24 @@
 	echo $value
 	return $rtn
 }
+
+#
+# nwam_get_loc_list_prop location property
+#
+# echoes a space-separated list of the property values for the given location
+# return:
+#	0 => property is set
+#	1 => property is not set
+#
+nwam_get_loc_list_prop()
+{
+	clist=`/usr/sbin/nwamcfg "select loc $1; get -V $2" 2>/dev/null`
+	rtn=$?
+	#
+	# nwamcfg gives us a comma-separated list;
+	# need to convert commas to spaces.
+	#
+	slist=`echo $clist | sed -e s/","/" "/g`
+	echo $slist
+	return $rtn
+}