1 #!/usr/bin/ksh 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, Version 1.0 only 7 # (the "License"). You may not use this file except in compliance 8 # with the License. 9 # 10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 11 # or http://www.opensolaris.org/os/licensing. 12 # See the License for the specific language governing permissions 13 # and limitations under the License. 14 # 15 # When distributing Covered Code, include this CDDL HEADER in each 16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE. 17 # If applicable, add the following below this CDDL HEADER, with the 18 # fields enclosed by brackets "[]" replaced with your own identifying 19 # information: Portions Copyright [yyyy] [name of copyright owner] 20 # 21 # CDDL HEADER END 22 # 23 # 24 #ident "%Z%%M% %I% %E% SMI" 25 # 26 # Copyright (c) 2001 by Sun Microsystems, Inc. 27 # All rights reserved. 28 # 29 30 # 31 # Source the utilities. 32 # 33 DIRNAME=`dirname $0` 34 . ${DIRNAME}/utilities.san 35 36 # 37 # Process the input arguments. 38 # 39 VALIDOPTS=dr:p: 40 process_args $@ 41 42 # 43 # In case the tester wants to see script output, allow them 44 # to run in debug mode. 45 # 46 TESTNAME=`basename $0` 47 if [ ! -z "${DEBUG}" ] 48 then 49 OUTFILE=/tmp/${TESTNAME}.debug.$$ 50 echo "Output from test: ${TESTNAME}" >${OUTFILE} 51 echo >>${OUTFILE} 52 echo "debug output can be found at ${OUTFILE}" 53 else 54 OUTFILE=/dev/null 55 fi 56 57 # 58 # Set variables. 59 # 60 SRVNAME=`uname -n` 61 SRVADDR=`get_server_ip` 62 63 # 64 # Determine subnet, netmask, and broadcast address. 65 # 66 get_default_class ${SRVADDR} | read DEFNET DEFMASK 67 SUBNET=`get_netmask ${SRVADDR}` 68 if [ -z "${SUBNET}" ] 69 then 70 if [ "${DEFNET}" != "${SRVADDR}" ] 71 then 72 # likely subnetted/supernetted. 73 print - "\n\n###\tWarning\t###\n" 74 print - "Network ${SRVADDR} is netmasked, but no entry was found in the 'netmasks'\ntable; please update the 'netmasks' table in the appropriate\nnameservice before continuing (see /etc/nsswitch.conf).\n" >&2 75 return 1 76 else 77 # use the default. 78 SUBNET="${DEFMASK}" 79 fi 80 fi 81 82 SUBNETADDR=`get_subnet_addr ${SRVADDR} ${SUBNET}` 83 84 # 85 # Verify that the network table exists. 86 # 87 NETTABS=`/usr/sbin/pntadm -r ${DHCPRSRC} -p ${DHCPPATH} -L 2>>${OUTFILE}` 88 NETTAB=`echo ${NETTABS} | fgrep ${SUBNETADDR}` 89 if [ -z ${NETTAB} ] 90 then 91 echo "Network table for ${SUBNETADDR} does not exist." 92 echo "${TESTNAME} - Test failed!" 93 exit 1 94 fi 95 96 # 97 # Create the client entry. 98 # 99 CLIENTID="01AABBCCDDEEFF" 100 FLAGS="00" 101 CADDR=${SRVADDR} 102 SADDR=${SRVADDR} 103 EXPIRE="03/15/2000" 104 MACRO="UNKNOWN" 105 HOST="TESTCLIENT" 106 107 /usr/sbin/pntadm -r ${DHCPRSRC} -p ${DHCPPATH} -A ${SRVADDR} -e ${EXPIRE} -i ${CLIENTID} -s ${SRVADDR} ${SUBNETADDR} >>${OUTFILE} 2>&1 108 RET=$? 109 if [ "${RET}" != "0" ] 110 then 111 echo "Error adding entry ${SRVADDR} to table ${SUBNETADDR} = ${RET}" 112 echo "${TESTNAME} - Test failed!" 113 exit 1 114 fi 115 116 # 117 # Verify that entry was added. 118 # 119 DATAFILE=/tmp/${TESTNAME}.data.$$ 120 /usr/sbin/pntadm -r ${DHCPRSRC} -p ${DHCPPATH} -P ${SUBNETADDR} >${DATAFILE} 2>>${OUTFILE} 121 122 ENTRY=`grep "^${CLIENTID}" ${DATAFILE}` 123 if [ -z "${ENTRY}" ] 124 then 125 rm ${DATAFILE} 126 echo "Client entry not added to ${SUBNETADDR}" 127 echo "${TESTNAME} - Test failed!" 128 exit 1 129 fi 130 rm ${DATAFILE} 131 132 # 133 # Verify that the entry fields are correct. 134 # 135 FIELD=`echo $ENTRY | cut -d " " -f1,1` 136 if [ "${FIELD}" != "${CLIENTID}" ] 137 then 138 echo "ClientID of entry was not added correctly to ${SUBNETADDR}" 139 echo "${FIELD} != ${CLIENTID}" 140 echo "${TESTNAME} - Test failed!" 141 exit 1 142 fi 143 144 FIELD=`echo $ENTRY | cut -d " " -f2,2` 145 if [ "${FIELD}" != "${FLAGS}" ] 146 then 147 echo "Flags of entry was not added correctly to ${SUBNETADDR}" 148 echo "${FIELD} != ${FLAGS}" 149 echo "${TESTNAME} - Test failed!" 150 exit 1 151 fi 152 153 FIELD=`echo $ENTRY | cut -d " " -f3,3` 154 if [ "${FIELD}" != "${CADDR}" ] 155 then 156 echo "Client address of entry was not added correctly to ${SUBNETADDR}" 157 echo "${FIELD} != ${CADDR}" 158 echo "${TESTNAME} - Test failed!" 159 exit 1 160 fi 161 162 FIELD=`echo $ENTRY | cut -d " " -f4,4` 163 if [ "${FIELD}" != "${SADDR}" ] 164 then 165 echo "Server address of entry was not added correctly to ${SUBNETADDR}" 166 echo "${FIELD} != ${SADDR}" 167 echo "${TESTNAME} - Test failed!" 168 exit 1 169 fi 170 171 FIELD=`echo $ENTRY | cut -d " " -f5,5` 172 if [ "${FIELD}" != "${EXPIRE}" ] 173 then 174 echo "Lease expiration of entry was not added correctly to ${SUBNETADDR}" 175 echo "${FIELD} != ${EXPIRE}" 176 echo "${TESTNAME} - Test failed!" 177 exit 1 178 fi 179 180 FIELD=`echo $ENTRY | cut -d " " -f6,6` 181 if [ "${FIELD}" != "${MACRO}" ] 182 then 183 echo "Macro of entry was not added correctly to ${SUBNETADDR}" 184 echo "${FIELD} != ${MACRO}" 185 echo "${TESTNAME} - Test failed!" 186 exit 1 187 fi 188 189 FIELD=`echo $ENTRY | cut -d " " -f7,7` 190 if [ ! -z "${FIELD}" ] 191 then 192 echo "Comment field of entry was not added correctly to ${SUBNETADDR}" 193 echo "Should have no comment" 194 echo "${TESTNAME} - Test failed!" 195 exit 1 196 fi 197 198 echo "${TESTNAME} - Test passed." 199 exit 0