#!/bin/sh
#
# 	License:      GNU General Public License (GPL)
#
#	This script is called to "give up" an IP address when requested
#
#	It could be that we don't have it, in which case we ignore the request.
#
#
#	Note: this script is called by the heartbeat code, so it gets
#	most of its arguments through the environment.
#

. $HA_FUNCS

IFCONFIG=/sbin/ifconfig
ROUTE=/sbin/route
RSCMGR=$HA_NOARCHBIN/ResourceManager

#
#

# Really a resource group name...
case "$HA_ipaddr" in
    ?*)		false;;
    *)
  	cat <<-!EOF
	$0 will give up the specified IP address if we have it assigned to us.
	Otherwise it will do nothing.
	
	$0 was invoked with these arguments:
	$*
	And this is the HA_ environment:
	!EOF
	env | grep '^HA_'
	exit 1;;
esac

#
#	HA_t, HA_src, and HA_ipaddr are fields the sender put in the message
#
CMD=$HA_t
ORIGNODE=$HA_src
IPADDR=$HA_ipaddr

if
  [ "X$ORIGNODE" = "X$HA_CURHOST" ]
then
  exit 0; # request is from us!
fi

#	
#	Ignore this request if we don't own this resource
#
if
  $RSCMGR status $IPADDR
then
  weown=yes
  if
    [ -x $HA_RCDIR/local_giveip ]
  then
    $HA_RCDIR/local_giveip $*
  fi

  $RSCMGR givegroup $IPADDR
else
  weown=no
fi



#
#	Now give our ip-request-response message...
#

ha_clustermsg <<!MSG
t=$CMD-resp
dest=$ORIGNODE
ipaddr=$IPADDR
weown=$weown
ok=OK
!MSG
