Home | History | Annotate | Download | only in SUNWcnetr
      1 #
      2 # CDDL HEADER START
      3 #
      4 # The contents of this file are subject to the terms of the
      5 # Common Development and Distribution License (the "License").
      6 # You may not use this file except in compliance with the License.
      7 #
      8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9 # or http://www.opensolaris.org/os/licensing.
     10 # See the License for the specific language governing permissions
     11 # and limitations under the License.
     12 #
     13 # When distributing Covered Code, include this CDDL HEADER in each
     14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15 # If applicable, add the following below this CDDL HEADER, with the
     16 # fields enclosed by brackets "[]" replaced with your own identifying
     17 # information: Portions Copyright [yyyy] [name of copyright owner]
     18 #
     19 # CDDL HEADER END
     20 #
     21 # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
     22 # Use is subject to license terms.
     23 #
     24 
     25 #
     26 # Convert datalink configuration into a series of dladm(1M) commands and
     27 # keep them in an upgrade script. This script will then be run in the
     28 # network-physical service.
     29 #
     30 # Note that we cannot use the /var/svc/profile/upgrade script because
     31 # that script is run during manifest-import which is too late for
     32 # datalink configuration.
     33 #
     34 UPGRADE_SCRIPT=/var/svc/profile/upgrade_datalink
     35 
     36 AGGR_CONF=/etc/aggregation.conf
     37 ORIG=$BASEDIR/$AGGR_CONF
     38 if [ ! -f "${ORIG}" ]; then
     39 	# Try the alternate location.
     40 	AGGR_CONF=/etc/dladm/aggregation.conf
     41 	ORIG=$BASEDIR/$AGGR_CONF
     42 fi
     43 
     44 # Now upgrade aggregation.conf to the new format.
     45 if [ -f "${ORIG}" ]; then
     46 	# Strip off comments, then each remaining line defines an
     47 	# aggregation the admnistrator configured on the old system.
     48 	# Each line corresponds to one dladm command that is appended
     49 	# to the upgrade script.
     50 	cat $ORIG | grep '^[^#]' | while read line; do
     51 		echo $line | while read aggr_index rest
     52 		do
     53 			policy=`echo $rest | /usr/bin/awk '{print $1}'`
     54 			nports=`echo $rest | /usr/bin/awk '{print $2}'`
     55 			ports=`echo $rest | /usr/bin/awk '{print $3}'`
     56 			mac=`echo $rest | /usr/bin/awk '{print $4}'`
     57 			lacp_mode=`echo $rest | /usr/bin/awk '{print $5}'`
     58 			lacp_timer=`echo $rest | /usr/bin/awk '{print $6}'`
     59 			dladm_string="dladm create-aggr -P $policy -l \
     60 			    $lacp_mode -T $lacp_timer"
     61 			# A fixed MAC address
     62 			if [ "${mac}" != "auto" ]; then
     63 				dladm_string="$dladm_string -u $mac"
     64 			fi
     65 			i=1
     66 			while [ $i -le "${nports}" ]; do
     67 				device=`echo $ports | cut -d, -f$i`
     68 				# Older aggregation.conf files have the format
     69 				# of device_name/port_number.  We don't need
     70 				# the port number, so get rid of it if it is
     71 				# there.
     72 				device=`echo $device | cut -d/ -f1`
     73 				i=`expr $i + 1`
     74 				dladm_string="$dladm_string -d $device"
     75 			done
     76 			dladm_string="$dladm_string $aggr_index"
     77 			echo $dladm_string >> \
     78 			    ${PKG_INSTALL_ROOT}/$UPGRADE_SCRIPT
     79 		done
     80 	done
     81 	# no longer needed, get rid of it.
     82 	rm -f $ORIG
     83 	removef $PKGINST $AGGR_CONF > /dev/null
     84 	removef -f $PKGINST > /dev/null 2>&1
     85 fi
     86 
     87 # Upgrade linkprop.conf
     88 ORIG=$BASEDIR/etc/dladm/linkprop.conf
     89 
     90 if [ -f "${ORIG}" ]; then
     91 	# Strip off comments, then each remaining line lists properties
     92 	# the administrator configured for a particular interface.
     93 	# Each line includes several properties, but we can only set
     94 	# one property per dladm invocation.
     95 	cat $ORIG | grep '^[^#]' | while read line; do
     96 		echo $line | while read link rest
     97 		do
     98 			while [ -n "${rest}" ]; do
     99 				linkprop=`echo $rest | cut -d";" -f1`
    100 				rest=`echo $rest | cut -d";" -f2-`
    101 				echo dladm set-linkprop -p $linkprop $link >> \
    102 				    ${PKG_INSTALL_ROOT}/$UPGRADE_SCRIPT
    103 			done
    104 		done
    105 	done
    106 	# no longer needed, get rid of it
    107 	rm -f $ORIG
    108 	removef $PKGINST /etc/dladm/linkprop.conf > /dev/null
    109 	removef -f $PKGINST > /dev/null 2>&1
    110 fi
    111 
    112 # Convert (hostname|hostname6|dhcp).xxx and zonecfg vlan entries
    113 
    114 for iftype in hostname hostname6 dhcp
    115 do
    116 	interface_names="`echo $rootprefix/etc/$iftype.*[0-9] 2>/dev/null`"
    117 	if [ "$interface_names" != "$rootprefix/etc/$iftype.*[0-9]" ]; then
    118 		ORIGIFS="$IFS"
    119 		IFS="$IFS."
    120 		set -- $interface_names
    121 		IFS="$ORIGIFS"
    122 		while [ $# -ge 2 ]; do
    123 			shift
    124 			if [ $# -gt 1 -a \
    125 			    "$2" != "$rootprefix/etc/$iftype" ]; then
    126 				while [ $# -gt 1 -a \
    127 				    "$1" != "$rootprefix/etc/$iftype" ]; do
    128 					shift
    129 				done
    130 			else
    131 				host_ifs="$host_ifs $1"
    132 				shift
    133 			fi
    134 		done
    135 	fi
    136 done
    137 
    138 zones=`zoneadm list -c | grep -v global`
    139 for zone in $zones
    140 do
    141 	zonecfg -z $zone info ip-type | grep exclusive >/dev/null
    142 	if [ $? -eq 0 ]; then
    143 		zif=`zonecfg -z $zone info net | grep physical | \
    144 		    nawk '{print $2}'`
    145 		zone_ifs="$zone_ifs $zif"
    146 	fi
    147 done
    148 
    149 ORIG=$BASEDIR/etc/dladm/datalink.conf
    150 for ifname in $host_ifs $zone_ifs
    151 do
    152 	grep $ifname $ORIG >/dev/null
    153 	if [ $? != 0 ]; then
    154 		phys=`echo $ifname | sed "s/[0-9]*$//"`
    155 		devnum=`echo $ifname | sed "s/$phys//g"`
    156 		if [ "$phys$devnum" != $ifname -o \
    157 		    -n "`echo $devnum | tr -d '[0-9]'`" ]; then
    158 			echo "skipping invalid interface $ifname"
    159 			continue
    160 		fi
    161 
    162 		vid=`expr $devnum / 1000`
    163 		inst=`expr $devnum % 1000`
    164 
    165 		if [ "$vid" != "0" ]; then
    166 			echo dladm create-vlan -l $phys$inst -v $vid \
    167 			    $ifname >> ${PKG_INSTALL_ROOT}/$UPGRADE_SCRIPT
    168 			if [ "$vid" != "1" ]; then
    169 				continue
    170 			fi
    171 			# If default PVID VLAN 1 is in use then warn
    172 			# the user and force PVID to zero.
    173 			echo "Warning: default VLAN tag set to 0 on $ifname"
    174 			echo dladm set-linkprop -p default_tag=0 \
    175 			    $ifname >> ${PKG_INSTALL_ROOT}/$UPGRADE_SCRIPT
    176 		fi
    177 	fi
    178 done
    179 
    180 #
    181 # Change permissions of public IKE certificates and CRLs
    182 # that may have been incorrectly created as private
    183 # PKCS#11 hints files must be left root-only readable.
    184 # Make sure this files starts with "30 82"
    185 #
    186 for file in `ls ${PKG_INSTALL_ROOT}/etc/inet/ike/crls/* \
    187     ${PKG_INSTALL_ROOT}/etc/inet/ike/publickeys/* 2>/dev/null`; do
    188 	if dd if=$file count=2 bs=1 2>/dev/null | cat -v | \
    189 	    grep "0M-^B" >/dev/null 2>&1
    190 	then
    191 	    chmod 644 $file
    192 	fi
    193 done
    194 exit 0
    195