Home | History | Annotate | Download | only in dhc
      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/CDDL.txt
      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/CDDL.txt.
     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 
     22 #
     23 # Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
     24 # Use is subject to license terms.
     25 #
     26 # ident	"@(#)functions.ksh	1.9	07/06/06 SMI"
     27 #
     28 
     29 # DHCP VARIABLES
     30 
     31 
     32 CLINFO="/usr/sbin/clinfo -n"
     33 LOCALNODENAME=`scha_cluster_get -O NODENAME_LOCAL`
     34 IPMPSTATUS="/usr/cluster/bin/scstat -i -h ${LOCALNODENAME}"
     35 INDHCPD="/usr/lib/inet/in.dhcpd -i"
     36 PNTADM="/usr/sbin/pntadm"
     37 PNMPTOR="/usr/cluster/bin/pnmptor"
     38 S34DHCP=/etc/rc3.d/S34dhcp
     39 DSVCLOCKD="/usr/lib/inet/dsvclockd"
     40 TOUPPER="/usr/bin/tr -s '[:lower:]' '[:upper:]'"
     41 DHCPCLIENT=/opt/SUNWscdhc/bin/dhcpclient
     42 DHCPCFG=/etc/inet/dhcpsvc.conf
     43 NETWORKS_ALL="`echo $NETWORKS | tr '/' ' '`"
     44 NETWORKTYPE=nafo
     45 TMPFILE=/tmp/dhcp_${RESOURCE}.tmp
     46 IPNR=`/bin/getent hosts ${LOCALNODENAME} | /bin/awk '{print $1}'`
     47 
     48 # TFTP VARIABLES
     49 
     50 TFTP=/bin/tftp
     51 INETDCFG=/etc/inet/inetd.conf
     52 TFTPDACTIVE=`/bin/cat ${INETDCFG} | /bin/grep -v '#' | /bin/grep tftp`
     53 TFTPHOST=localhost
     54 TFTPTIMEOUT=10
     55 
     56 # DHCPCLIENT VARIABLES
     57 
     58 DHCPCLIENT=/opt/SUNWscdhc/bin/dhcpclient
     59 DHCPCLIENTTIMEOUT=15
     60 
     61 
     62 # OTHER VARIABLES
     63 
     64 SCLOGGER=/usr/cluster/lib/sc/scds_syslog
     65 PKG=SUNWscdhc
     66 METHOD=`basename $0`
     67 HATIMERUN=/usr/cluster/bin/hatimerun
     68 
     69 syslog_tag()
     70 {
     71         #
     72         # Data Service message format
     73         #
     74 
     75         $SET_DEBUG
     76 
     77         print "SC[${PKG:-??}.${METHOD:-??}]:${RESOURCEGROUP:-??}:${RESOURCE:-??}"
     78 }
     79 
     80 scds_syslog()
     81 {
     82 
     83         #
     84         # Log a message
     85         #
     86 
     87         $SET_DEBUG
     88 
     89         $SCLOGGER "$@" &
     90 }
     91 
     92 debug_message()
     93 {
     94         #
     95         # Output a debug message to syslog if required
     96         #
     97 
     98         if [ "$DEBUG" = "$RESOURCE" -o "$DEBUG" = "ALL" ]
     99         then
    100                 SET_DEBUG="set -x"
    101 
    102                 DEBUG_TEXT=$1
    103 
    104                 scds_syslog -p daemon.debug -t $(syslog_tag) -m \
    105                         "%s" "$DEBUG_TEXT"
    106         else
    107                 SET_DEBUG=
    108         fi
    109 }
    110 
    111 validate_options()
    112 {
    113         #
    114         # Ensure all options are set
    115         #
    116 
    117         for i in RESOURCE RESOURCEGROUP NETWORKS
    118         do
    119                 case $i in
    120                         RESOURCE)
    121                         if [ -z $RESOURCE ]; then
    122                                 # SCMSGS
    123                                 # @explanation
    124                                 # The specified option is not set within
    125                                 # either the Start, Stop, Probe or Validate
    126                                 # command
    127                                 # @user_action
    128                                 # The syslog tag identifies the agent script
    129                                 # that produced this message. Fix the relevant
    130                                 # Start, Stop, Probe or Validate command with
    131                                 # the appropriate option. The easiest way to
    132                                 # accomplish this is to reregister the
    133                                 # resource.
    134                                 scds_syslog -p daemon.error -t $(syslog_tag) -m \
    135                                 "ERROR: Option -%s not set" "R"
    136                                 exit 1
    137                         fi;;
    138 
    139                         RESOURCEGROUP)
    140                         if [ -z $RESOURCEGROUP ]; then
    141                                 scds_syslog -p daemon.error -t $(syslog_tag) -m \
    142                                 "ERROR: Option -%s not set" "G"
    143                                 exit 1
    144                         fi;;
    145 
    146                         NETWORKS)
    147                         if [ -z ${STATICDHCP} -a -z $NETWORKS ]; then
    148                                 scds_syslog -p daemon.error -t $(syslog_tag) -m \
    149                                 "ERROR: Option -%s not set" "N"
    150                                 exit 1
    151                         fi;;
    152 
    153                 esac
    154         done
    155 }
    156 
    157 validate()
    158 {
    159 
    160 	#
    161 	# Validate DHCP
    162 	#
    163 	
    164         debug_message "Function: validate - Begin"
    165 	$SET_DEBUG
    166 
    167 	rc_validate=0
    168 
    169 	#
    170 	# Validate that dhcpsvc.conf exists
    171 	#
    172 
    173 	if [ ! -f "${DHCPCFG}" ]
    174 	then
    175    		# SCMSGS
    176    		# @explanation
    177    		# The DHCP resource could not validate that
    178    		# /etc/inet/dhcpsvc.conf exists.
    179    		# @user_action
    180    		# Ensure that /etc/inet/dhcpsvc.conf exists.
    181    		scds_syslog -p daemon.error -t $(syslog_tag) -m \
    182 			"Validate - DHCP config file %s does not exist" \
    183 			"${DHCPCFG}"
    184 		rc_validate=1
    185 		return 
    186 	else
    187 		debug_message "Validate - DHCP config file ${DHCPCFG} exists"
    188 	fi
    189 
    190 	#
    191 	# Save the old Path and source the config file
    192 	#
    193 
    194 	# /etc/inet/dhcpsvc.conf has a PATH variable which gets overwritten
    195 	# when we source /etc/inet/dhcpsvc.conf. PATH gets reinstated at the
    196 	# end of validate or if rc_validate=1 
    197 
    198 	OLDPATH=${PATH}
    199 
    200 	. ${DHCPCFG}
    201 
    202 	#
    203 	# Validate Daemon_enabled is true
    204 	#
    205 
    206 	if [ "`/usr/bin/echo ${DAEMON_ENABLED} | ${TOUPPER}`" != "TRUE" ]
    207 	then
    208    		# SCMSGS
    209    		# @explanation
    210    		# The DHCP resource requires that that the
    211    		# /etc/inet/dhcpsvc.conf file has DAEMON_ENABLED=TRUE.
    212    		# @user_action
    213    		# Ensure that /etc/inet/dhcpsvc.conf has DAEMON_ENABLED=TRUE
    214    		# by configuring DHCP appropriately, i.e. as defined within
    215    		# the Sun Cluster Data Service for DHCP.
    216    		scds_syslog -p daemon.error -t $(syslog_tag) -m \
    217 			"Validate - DHCP is not enabled (DAEMON_ENABLED)"
    218 		rc_validate=1
    219 		return 
    220 	else
    221 		debug_message "Validate - DHCP is enabled (DAEMON_ENABLED)"
    222 	fi
    223 
    224 	#
    225 	# Validate SUNWfiles or SUNWbinfiles
    226 	#
    227 
    228 	if [ "`/usr/bin/echo ${RESOURCE} | ${TOUPPER}`" != "SUNWFILES" -a "`/usr/bin/echo ${RESOURCE} | ${TOUPPER}`" != "SUNWBINFILES" ]
    229 	then
    230    		# SCMSGS
    231    		# @explanation
    232    		# The DHCP resource requires that that the
    233    		# /etc/inet/dhcpsvc.conf file has RESOURCE=SUNWfiles or
    234    		# SUNWbinfiles.
    235    		# @user_action
    236    		# Ensure that /etc/inet/dhcpsvc.conf has RESOURCE=SUNWfiles or
    237    		# SUNWbinfiles by configuring DHCP appropriately, i.e. as
    238    		# defined within the Sun Cluster Data Service for DHCP.
    239    		scds_syslog -p daemon.error -t $(syslog_tag) -m \
    240 			"Validate - Only SUNWfiles or SUNWbinfiles are supported"
    241 		rc_validate=1
    242 		return 
    243 	else
    244 		debug_message "Validate - SUNWfiles or SUNWbinfiles are defined"
    245 	fi
    246 
    247 	#
    248 	# Validate that Run_mode is server
    249 	#
    250 
    251 	if [ "`/usr/bin/echo ${RUN_MODE} | ${TOUPPER}`" != "SERVER" ]
    252 	then
    253    		# SCMSGS
    254    		# @explanation
    255    		# The DHCP resource requires that that the
    256    		# /etc/inet/dhcpsvc.conf file has RUN_MODE=SERVER.
    257    		# @user_action
    258    		# Ensure that /etc/inet/dhcpsvc.conf has RUN_MODE=SERVER by
    259    		# configuring DHCP appropriately, i.e. as defined within the
    260    		# Sun Cluster Data Service for DHCP.
    261    		scds_syslog -p daemon.error -t $(syslog_tag) -m \
    262 			"Validate - RUN_MODE has to be server"
    263 		rc_validate=1
    264 		return 
    265 	else
    266 		debug_message "Validate - RUN_MODE is server"
    267 	fi
    268 
    269 	#
    270 	# Validate the path is a directory
    271 	#
    272 
    273 	if [ ! -d "${PATH}" ]
    274 	then
    275    		# SCMSGS
    276    		# @explanation
    277    		# The DHCP resource could not validate that the DHCP directory
    278    		# defined in the /etc/inet/dhcpsvc.conf file for the PATH
    279    		# variable exists.
    280    		# @user_action
    281    		# Ensure that /etc/inet/dhcpsvc.conf has the correct entry for
    282    		# the PATH variable by configuring DHCP appropriately, i.e. as
    283    		# defined within the Sun Cluster Data Service for DHCP.
    284    		scds_syslog -p daemon.error -t $(syslog_tag) -m \
    285 			"Validate - DHCP directory %s does not exist" \
    286 			"${PATH}"
    287 		rc_validate=1
    288 		return 
    289 	else
    290 		debug_message "Validate - DHCP directory ${PATH} exists"
    291 	fi
    292 	
    293 	#
    294 	# Validate that S34dhcp is not active
    295 	#
    296 
    297 	if [ -f "${S34DHCP}" ]
    298 	then
    299    		# SCMSGS
    300    		# @explanation
    301    		# The DHCP resource validates that /etc/rc3.d/S34dhcp is not
    302    		# active and achieves this by deleting/etc/rc3.d/S34dhcp.
    303    		# @user_action
    304    		# No user action is needed. /etc/rc3.d/S34dhcp will be
    305    		# deleted.
    306    		scds_syslog -p daemon.notice -t $(syslog_tag) -m \
    307 			"Validate - De-activating %s, by removing it" \
    308 			"${S34DHCP}"
    309 	
    310    		/bin/rm -f ${S34DHCP}
    311 	else
    312 		debug_message "Validate - ${S34DHCP} does not exist which is ok"
    313 	fi
    314 
    315 	# USE OLDPATH
    316 	PATH=${OLDPATH}
    317 
    318         #
    319 	# Validate that if CGTPUSED is SET the variable INTERFACES has to be set
    320         #
    321 
    322         if [ ! -z "${CGTPUSED}" -a -z "${INTERFACES}" ]; then
    323 
    324                         # SCMSGS
    325                         # @explanation
    326                         # If USE_CGTP=TRUE was set within
    327                         # /opt/SUNWscdhc/util/dhcp_config then the INTERFACES
    328                         # within /etc/inet/dhcpsvc.conf needs to be set.
    329                         # @user_action
    330                         # If USE_CGTP=TRUE is required, then ensure that the
    331                         # INTERFACES variable is set within
    332                         # /etc/inet/dhcpsvc.conf. If USE_CGTP=TRUE is
    333                         # required, then ensure that the INTERFACES variable
    334                         # is set within /etc/inet/dhcpsvc.conf. Refer to
    335                         # dhcpsvc.conf(4) man page for further information on
    336                         # INTERFACES.
    337                         scds_syslog -p daemon.notice -t $(syslog_tag) -m \
    338                         "Validate - The keyword INTERFACES have to be set in %s when -T is being used" \
    339                         "${DHCPCFG}"
    340 
    341 			rc_validate=1
    342 			return 
    343 
    344         else
    345                 debug_message "Validate - The keyword INTERFACES is set when -T is being used"
    346         fi
    347 
    348         #
    349 	# Validate tftp
    350 	#
    351 
    352 	if [ ! -z "${TFTPFILE}" ]; then
    353 
    354 		if [ -z "${TFTPDACTIVE}" ]; then
    355                         # SCMSGS
    356                         # @explanation
    357                         # If TFTPTESTFILE= was set within
    358                         # /opt/SUNWscdhc/util/dhcp_config then the tftp daemon
    359                         # needs to be activated witihin /etc/inet/inetd.conf.
    360                         # @user_action
    361                         # If TFTPTESTFILE= is required, then ensure that tftp
    362                         # is activated within /etc/inet/inetd.conf.
    363                         scds_syslog -p daemon.notice -t $(syslog_tag) -m \
    364                         "Validate - tftpd daemon has to be activated in %s when -F is being used" \
    365                         "${INETDCFG}"
    366 
    367 			rc_validate=1
    368 			return
    369 
    370         	else
    371                		debug_message "Validate - tftpd is active"
    372         	fi
    373 
    374 
    375 		if [ ! -s "${TFTPFILE}" ]; then
    376                         # SCMSGS
    377                         # @explanation
    378                         # The file specified in TFTPTESTFILE= within
    379                         # /opt/SUNWscdhc/util/dhcp_config doesn't exist or has
    380                         # a zero length witihin /etc/inet/inetd.conf.
    381                         # @user_action
    382                         # If TFTPTESTFILE= is required, then ensure file
    383                         # specified is correct.
    384                         scds_syslog -p daemon.notice -t $(syslog_tag) -m \
    385                         "Validate - The tftp testfile (%s) don't exist in directory (%s) or has filesize of zero bytes" \
    386                         "`basename ${TFTPFILE}`" "`dirname ${TFTPFILE}`"
    387 
    388 			rc_validate=1
    389 			return
    390 
    391         	else
    392                		debug_message "Validate - tftp testfile (${TFTPFILE}) exists"
    393         	fi
    394         fi
    395 
    396 
    397 
    398 	debug_message "Function: validate - End"
    399 }
    400 
    401 get_adapter_type()
    402 {
    403 	#
    404 	# Test if CGTP is being used
    405 	#
    406 
    407 	debug_message "Function: get_adapter_type - Begin"
    408 	$SET_DEBUG
    409 
    410         if [ ! -z "${CGTPUSED}" ]; then
    411            NETWORKTYPE=cgtp
    412 
    413 	else
    414 		NETWORKTYPE=ipmp
    415 	fi
    416 
    417 	debug_message "Function: get_adapter_type - ${NETWORKTYPE} is being used"
    418 	debug_message "Function: get_adapter_type - End"
    419 }
    420 		
    421 get_nafo_adapter()
    422 {
    423 	#
    424 	# Get active adapter and interface ip number
    425 	#
    426 
    427 	debug_message "Function: get_nafo_adapter - Begin"
    428 	$SET_DEBUG
    429 
    430      	ADAPTER=`${PNMPTOR} ${NAFO_NODE}`
    431 
    432 	debug_message "get_nafo_adapter - Interface=${ADAPTER}"
    433 
    434 	debug_message "Function: get_nafo_adapter - End"
    435 }
    436 
    437 get_ipmp_adapter()
    438 {
    439 	#
    440 	# Get all interfaces belonging to defined IPMP GROUP
    441 	#
    442 	
    443 	debug_message "Function: get_ipmp_adapter - Begin"
    444 	$SET_DEBUG
    445 
    446         ADAPTER=""
    447 
    448         for s1 in `${IPMPSTATUS} | /bin/grep "IPMP Group:" | /bin/awk '{print $4,$6,$7}' | /bin/grep ${NAFO_NODE} | /bin/grep Online | /bin/awk '{print $2}'`
    449         do
    450           
    451            if [ -z "${ADAPTER}" ]; then 
    452              ADAPTER=${s1}
    453            else
    454              ADAPTER=${ADAPTER}","${s1}
    455            fi
    456 
    457   	done
    458 
    459 	debug_message "get_ipmp_adapter - Interface=${ADAPTER}"
    460 
    461 	debug_message "Function: get_ipmp_adapter - End"
    462 }
    463 
    464 get_cgtp_adapter()
    465 {
    466 	#
    467 	# Get all ip-adresses belonging to defined INTERFACES
    468 	#
    469 	
    470 	debug_message "Function: get_cgtp_adapter - Begin"
    471 	$SET_DEBUG
    472 
    473         ADAPTER=${INTERFACES}
    474 
    475 	debug_message "get_cgtp_adapter - Interface=${ADAPTER}"
    476 
    477 	debug_message "Function: get_cgtp_adapter - End"
    478 }
    479 
    480 get_server_ip()
    481 {
    482 	#
    483 	# get the server ip number
    484 	#
    485 	
    486 	debug_message "Function: get_server_ip - Begin"
    487 	$SET_DEBUG
    488 
    489 	SRVIPNR=`${PNTADM} -P ${NW} | /usr/bin/awk '{print $4}' | /bin/tail -1`
    490 
    491 	rc_pntadm=$?
    492 
    493 	if [ "${rc_pntadm}" -ne 0 ]
    494 	then
    495 		scds_syslog -p daemon.error -t $(syslog_tag) -m \ 
    496 			"get_server_ip - pntadm failed rc<%s>" \
    497 			"${rc_pntadm}"
    498 	else
    499 		debug_message "get-server_ip - Server IP=${SRVIPNR}"
    500 	fi
    501 
    502 	debug_message "Function: get_server_ip - End"
    503 }
    504 
    505 start_dhcp()
    506 {
    507 	#
    508 	# Start DHCP
    509 	#
    510 
    511         debug_message "Function: start_dhcp - Begin"
    512 	$SET_DEBUG
    513 	
    514 	NODEID=`${CLINFO}`
    515 	USED_ADAPTER=""
    516 
    517 	if [ -f ${TMPFILE} ]
    518 	then
    519    		rm -f ${TMPFILE}
    520 	fi
    521 
    522 	# IF CGTPUSED AND STATICDHCP IS BEING USED
    523 	# SET USED_ADAPTER=${INTERFACES}
    524 
    525         if [ ! -z "${CGTPUSED}" -a ! -z "${STATICDHCP}" ]; then
    526           USED_ADAPTER=${INTERFACES}
    527 	fi
    528 
    529 	# GET ADEPTER TYPE
    530 
    531 	get_adapter_type	
    532 
    533 	# PARSE ${NETWORKS_ALL} OPTIONS TO RETRIVE IP-NUMBERS FOR
    534 	# ACTIVE ADAPTERS
    535 
    536 	NW_ALL=
    537 
    538 	for tab in ${NETWORKS_ALL}
    539 	do
    540    		NW=`/usr/bin/echo ${tab} | cut -d'@' -f1`
    541    		NAFO_NODE=`/usr/bin/echo ${tab} | cut -d'@' -f2`
    542    		ID=`/usr/bin/echo ${tab} | cut -d'@' -f3`
    543 
    544    		if [ "${ID}" = "${NODEID}" ]
    545 		then
    546 
    547 			if [ "${NETWORKTYPE}" = "ipmp" ]; then
    548 				get_ipmp_adapter
    549 			elif [ "${NETWORKTYPE}" = "nafo" ]; then
    550 				get_nafo_adapter
    551                         else
    552                                 get_cgtp_adapter
    553 			fi
    554 
    555 			# USED_ADAPTER allows for multiple interfaces so long as we match "${ID}" = "${NODEID}"
    556 
    557 			if [ -z "${USED_ADAPTER}" ]
    558 			then
    559        				USED_ADAPTER=${ADAPTER}
    560      			else
    561        				USED_ADAPTER=${USED_ADAPTER}","${ADAPTER}
    562 			fi
    563 
    564 			NW_ALL="$NW_ALL $NW"
    565 		fi
    566 	done
    567 
    568 	# CHECK IF CHANGE OF OWNER SHIP IS NEEDED
    569 
    570 	if [ -z "${STATICDHCP}" ]; then
    571 
    572 		for NW in $NW_ALL
    573 		do
    574 			# GET OWNER OF DHCP-TABLES
    575 
    576 			get_server_ip
    577 
    578 			if [ ! -z "${SRVIPNR}" ]
    579 			then
    580 				# Check which node owns the DHCP table
    581 
    582                 		echo ${IPNR} | grep ${SRVIPNR} > /dev/null
    583 
    584 				if [ $? -ne 0 ]
    585 				then
    586 
    587 					debug_message "start_dhcp - Changing Server IP for network ${NW} from ${SRVIPNR} to ${IPNR}"
    588 
    589 					# Dump each client and create a PNTADM batchfile to change the server ip number
    590 
    591 					for client in `${PNTADM} -P ${NW} | /usr/bin/awk '{print $3}' | /usr/bin/grep '\.'`
    592        					do
    593           					/usr/bin/echo "pntadm -M ${client} -s ${IPNR} ${NW}" >> ${TMPFILE}
    594        					done
    595 				else
    596 					debug_message "start_dhcp - This node owns the DHCP table entries"
    597      				fi
    598 			fi
    599 		done
    600 	fi
    601 
    602 	# Run the ${TMPFILE} in batch mode to PNTADM
    603 
    604 	if [ -f "${TMPFILE}" ]
    605 	then
    606 		debug_message "start_dhcp - Start DHCP batch job to change Server IP address"
    607 
    608   		${PNTADM} -B ${TMPFILE}
    609 
    610 		rc_pntadm=$?
    611 
    612 		if [ "${rc_pntadm}" -ne 0 ]
    613 		then
    614 			scds_syslog -p daemon.error -t $(syslog_tag) -m \ 
    615 			"start_dhcp - DHCP batch job failed rc<%s>" \
    616 			"${rc_pntadm}"
    617 		else
    618 			debug_message "start_dhcp - DHCP batchjob is finished"
    619 		fi
    620 	fi
    621 
    622 	# Start Dhcp daemon
    623 
    624 	${INDHCPD} ${USED_ADAPTER}
    625 	St=$?
    626 
    627 	if [ ${St} -ne 0 ]
    628 	then
    629    		# SCMSGS
    630    		# @explanation
    631    		# The DHCP resource has tried to start the DHCP server using
    632    		# in.dhcpd, however this has failed.
    633    		# @user_action
    634    		# The DHCP server will be restarted. Examine the other syslog
    635    		# messages occurring at the same time on the same node, to see
    636    		# if the cause of the problem can be identified.
    637    		scds_syslog -p daemon.error -t $(syslog_tag) -m \
    638 			"start_dhcp - %s %s failed" \
    639 			"${INDHCPD}" "${USED_ADAPTER}"
    640 	else
    641 		debug_message "start_dhcp - DHCP started"
    642 	fi
    643 
    644 	debug_message "Function: start_dhcp - End"
    645 }
    646 
    647 stop_dhcp()
    648 {
    649 	#
    650 	# Stop DHCP
    651 	#
    652 
    653         debug_message "Function: stop_dhcp - Begin"
    654 	$SET_DEBUG
    655 
    656 	/bin/pkill -TERM `basename ${DSVCLOCKD}`
    657 
    658 	debug_message "Function: stop_dhcp - End"
    659 }
    660 
    661 check_dhcp()
    662 {
    663 	# 
    664 	# Probe DHCP
    665 	#
    666 
    667         debug_message "Function: check_dhcp - Begin"
    668 	$SET_DEBUG
    669 
    670 	rc_check_dhcp=0
    671 	#
    672 	# Check if the agent is starting
    673 	#
    674 
    675 	if [ ! -z "`pgrep start_dhcp`" ]
    676 	then
    677 		debug_message "check_dhcp - DHCP is starting, exiting"
    678 		rc_check_dhcp=100
    679 		return
    680 	fi
    681 
    682         # IF CGTPUSED IS BEING USED DISABLE NETWORKS
    683 
    684         if [ ! -z "${CGTPUSED}" ]; then
    685           NETWORKS_ALL=""
    686         fi
    687 
    688 	# GET ADAPTER TYPE
    689 
    690 	get_adapter_type
    691 
    692 	#
    693 	# Check if active adapter/interface in nafo has changed
    694 	#
    695 
    696 	NODEID=`${CLINFO}`
    697 
    698 	for tab in ${NETWORKS_ALL}
    699 	do
    700    		NW=`/usr/bin/echo ${tab} | cut -d'@' -f1`
    701    		NAFO_NODE=`/usr/bin/echo ${tab} | cut -d'@' -f2`
    702    		ID=`/usr/bin/echo ${tab} | cut -d'@' -f3`
    703 
    704 		# Test the ${NETWORKS_ALL} ${ID} with the cluster node number
    705 
    706    		if [ "${ID}" = "${NODEID}" ]
    707 		then
    708 
    709 			if [ "${NETWORKTYPE}" = "nafo" ]
    710 			then
    711 				get_nafo_adapter
    712 
    713 	     			NAFO_NODE_FILE=/var/tmp/`basename $0`.${NAFO_NODE}
    714 
    715 				# The first time through we create ${NAFO_NODE_FILE} with the active interface
    716 				# Subsequent restarts or failovers will then test to see if the interface has changed
    717 	
    718      				if [ ! -f "${NAFO_NODE_FILE}" ]
    719 				then
    720 					debug_message "check_dhcp - Creating ${NAFO_NODE_FILE} with active interface ${ADAPTER}"
    721 
    722        		 			/bin/echo ${ADAPTER} > ${NAFO_NODE_FILE}
    723      				else
    724        		 			OLDADAPTER=`/bin/cat ${NAFO_NODE_FILE}`
    725 
    726 					debug_message "check_dhcp - Check if active interface has changed"
    727 
    728        		 			if [ "${ADAPTER}" != "${OLDADAPTER}" ]
    729 					then
    730        		    				# SCMSGS
    731        		    				# @explanation
    732        		    				# The DHCP resource's fault
    733        		    				# monitor has detected that
    734        		    				# the active interface has
    735        		    				# changed.
    736        		    				# @user_action
    737        		    				# No user action is needed.
    738        		    				# The fault monitor will
    739        		    				# restart the DHCP server.
    740        		    				scds_syslog -p daemon.notice -t $(syslog_tag) -m \
    741 						"check_dhcp - Active interface has changed from %s to %s" \
    742 						"${OLDADAPTER}" "${ADAPTER}"
    743 
    744 						debug_message "check_dhcp - Updating ${NAFO_NODE_FILE} with new active interface ${ADAPTER}"
    745 
    746        		    				/bin/echo ${ADAPTER} > ${NAFO_NODE_FILE}
    747 
    748 						rc_check_dhcp=100
    749 						return
    750 					else
    751 						debug_message "check_dhcp - Active interface has not changed"
    752 					fi
    753        		 		fi
    754 			elif [ "${NETWORKTYPE}" = "ipmp" ]; then
    755 				debug_message "check_dhcp - Don't check for adapter changes when ipmp is being used"
    756 			else
    757 				debug_message "check_dhcp - Don't check for adapter changes when cgtp is being used"
    758 			fi
    759    		fi
    760 	done
    761 
    762 	#
    763 	# Check Dhcp with dhcpclient if ClientID is supplied
    764 	#
    765 
    766 	if [ ! -z "${CLIENTID}" ]; then
    767 
    768 		debug_message "Function: check_dhcp - Check if in.dhcpd can answer dhcp requests"
    769 
    770 		DHCPCLIENTLOGFILE=/tmp/${RESOURCE}.tmp
    771 
    772 		# Remove DHCPCLIENTLOGFILE
    773 
    774 		rm -f ${DHCPCLIENTLOGFILE}
    775 
    776 		# Run dhcpclient under timeout
    777 
    778 		${HATIMERUN} -t ${DHCPCLIENTTIMEOUT} ${DHCPCLIENT} -q ${CLIENTID} >${DHCPCLIENTLOGFILE} 2>&1
    779 
    780 		St=$?
    781 
    782 		#
    783 		# CHECK RESULTS
    784 		#
    785 
    786 		# Check for timeouts
    787 
    788 		if [ $St -eq 99 ]; then
    789 			# SCMSGS
    790 			# @explanation
    791 			# The dhcpclient has exceeded it's timeout allowance.
    792 			# @user_action
    793 			# None required. Informational message, an immediate
    794 			# failover is being requested.
    795 			scds_syslog -p daemon.error -t $(syslog_tag) -m \
    796 			"check_dhcp - Dhcpclient test timed out exeeded %s seconds" \
    797 			"${DHCPCLIENTTIMEOUT}"
    798 
    799 			rc_check_dhcp=201
    800 			return
    801 		else
    802 			debug_message "check_dhcp - Dhcpclient test didn't time out"
    803 		fi
    804 
    805 		# Check if Dhcpclient exited non-zero
    806 		
    807 		if [ $St -ne 0 ]; then
    808 			# SCMSGS
    809 			# @explanation
    810 			# The dhcpclient test exited with a non-zero return
    811 			# code.
    812 			# @user_action
    813 			# None required. Informational message, an immediate
    814 			# failover is being requested.
    815 			scds_syslog -p daemon.error -t $(syslog_tag) -m \
    816 			"check_dhcp - Dhcpclient test exited with %s" \
    817 			"${St}"
    818 
    819 			rc_check_dhcp=201
    820 			return
    821 		else
    822 			debug_message "check_dhcp - Dhcpclient test exited with ${St}"
    823 		fi
    824 
    825 		# Check if Dhcpclient retrieved an IP-address
    826 		
    827 		if [ -z `/bin/grep SERVER ${DHCPCLIENTLOGFILE}` ]; then
    828 			# SCMSGS
    829 			# @explanation
    830 			# The dhcpclient could not retrieve any IP number.
    831 			# @user_action
    832 			# None required. Informational message, an immediate
    833 			# failover is being requested.
    834 			scds_syslog -p daemon.error -t $(syslog_tag) -m \
    835 			"check_dhcp - Dhcpclient didn't retrieve any IP-number" 
    836 
    837 			rc_check_dhcp=201
    838 			return
    839 		else
    840 			debug_message "check_dhcp - Dhcpclient did retrieve an IP-number"
    841 		fi
    842 	 fi
    843 
    844 	#
    845 	# Check tftp
    846 	#
    847 
    848 	if [ ! -z "${TFTPFILE}" ]; then
    849 
    850 		debug_message "Function: check_dhcp - Check tftpd"
    851 
    852 		# Retrieve filename from TFTPFILE
    853 
    854 		TFTPDFILE=`basename ${TFTPFILE}`
    855 
    856 		RETRIEVEDFILE=/tmp/${TFTPDFILE}
    857 
    858 		TFTPLOGFILE=/tmp/${RESOURCE}.tmp
    859 
    860 		# REMOVE RETRIEVEDFILE TFTPLOGFILE
    861 
    862 		rm -f ${TFTPLOGFILE} ${RETRIEVEDFILE}
    863 
    864 		# Connect to tftp on localhost and retrieve the testfile
    865 
    866 	        debug_message "Function: check_dhcp - Connect to ${TFTPHOST} and try to retrieve ${TFTPDFILE}"
    867 
    868 		${HATIMERUN} -t ${TFTPTIMEOUT} ${TFTP} > ${TFTPLOGFILE} << EOF
    869 		verbose
    870 		connect ${TFTPHOST}
    871 		mode binary
    872 		get ${TFTPDFILE} ${RETRIEVEDFILE}
    873 		quit
    874 EOF
    875 
    876 		#
    877 		# CHECK RESULTS
    878 		#
    879 
    880 		# Check for timeouts
    881 
    882 		if [ $? -eq 99 ]; then
    883 			# SCMSGS
    884 			# @explanation
    885 			# The tftp transfer has exceeded it's timeout
    886 			# allowance.
    887 			# @user_action
    888 			# None required. Informational message, an immediate
    889 			# failover is being requested.
    890 			scds_syslog -p daemon.error -t $(syslog_tag) -m \
    891 			"check_dhcp - tftp transfer test timed out exeeded %s seconds" \
    892 			"${TFTPTIMEOUT}"
    893 
    894 			rc_check_dhcp=201
    895 			return
    896 		else
    897 			debug_message "check_dhcp - tftp transfer test didn't time out"
    898 		fi
    899 
    900 		# Check error codes in the logfile
    901 
    902 		Msg=`/bin/grep Error ${TFTPLOGFILE}`
    903 
    904 		if [ ! -z "${Msg}" ]; then
    905 			# SCMSGS
    906 			# @explanation
    907 			# The tftp transfer exited with a non-zero return
    908 			# code.
    909 			# @user_action
    910 			# None required. Informational message, an immediate
    911 			# failover is being requested.
    912 			scds_syslog -p daemon.error -t $(syslog_tag) -m \
    913 			"check_dhcp - tftp transfer test generated an error code of (%s)" \
    914 			"${Msg}"
    915 
    916 			rc_check_dhcp=201
    917 			return
    918 		else
    919 			debug_message "check_dhcp - tftp transfer test didn't generate any error codes"
    920 		fi
    921 
    922 		# Check if the retrieved file exist and is non-zero bytes
    923 
    924 		if [ ! -s "${RETRIEVEDFILE}" ]; then
    925 			# SCMSGS
    926 			# @explanation
    927 			# The (tftp) retrieved file either does not exist or
    928 			# has filesize of zero bytes
    929 			# @user_action
    930 			# None required. Informational message, an immediate
    931 			# failover is being requested.
    932 			scds_syslog -p daemon.error -t $(syslog_tag) -m \
    933 			"check_dhcp - The retrieved file (%s) don't exist or is zero-bytes long." \
    934 			"${RETRIEVEDFILE}"
    935 
    936 			rc_check_dhcp=201
    937 			return
    938 		else
    939 			debug_message "check_dhcp - The retrieved file (${RETRIEVEDFILE}) exist and is not non-zero bytes long"
    940 		fi
    941 
    942 	fi
    943 
    944 
    945 
    946 	debug_message "Function: check_dhcp - End"
    947 }
    948