Skip to content

Commit

Permalink
Linux Foundation bug 1505: Findif parsing is all screwed up unless al…
Browse files Browse the repository at this point in the history
…l the parameters are passed, not defaulted.

I changed findif to use the OCF parameters that are passed to
both IPaddr and IPaddr2, which got rid of a bunch of ugly code
at the same time as fixing this bug.  Sounds like a win to me.

In the process I had to make IPaddr and IPaddr2 somewhat more consistent
than they had been - but not in an incompatible way, and this is also
a good thing.

--HG--
extra : convert_revision : 187c17c0769e7c659d519944b0821ea4939cd515
  • Loading branch information
Alan-R committed Mar 7, 2007
1 parent 9d7a01d commit fe39b61
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 55 deletions.
70 changes: 26 additions & 44 deletions heartbeat/IPaddr.in
Expand Up @@ -107,10 +107,10 @@ rather, specify the base interface only.
<content type="string" default="eth0"/>
</parameter>
<parameter name="netmask">
<parameter name="cidr_netmask">
<longdesc lang="en">
The netmask for the interface dot-quad notation or CIDR format. (ie,
either 255.255.255.0 or 24)
The netmask for the interface in CIDR format. (ie, 24), or in
dotted quad notation 255.255.255.0).
If unspecified, the script will also try to determine this from the
routing table.
Expand Down Expand Up @@ -249,12 +249,14 @@ lvs_restore_loopback() {
ifname=`cat "$VLDIR/$ipaddr"`
ocf_log info "Restoring loopback IP Address $ipaddr on $ifname."

NICINFO=`$FINDIF $ipaddr/32/$ifname`
if [ $? -eq 0 ]; then
CMD="OCF_RESKEY_cidr_netmask=32 OCF_RESKEY_ip=$1 OCF_RESKEY_nic=$ifname $FINDIF"
if
NICINFO=`eval $CMD`
then
netmask_text=`echo "$NICINFO" | cut -f2`
broadcast=`echo "$NICINFO" | cut -f3`
else
echo "ERROR: $IFCMD failed (rc=$rc)"
echo "ERROR: $CMD failed (rc=$rc)"
exit $OCF_ERR_GENERIC
fi

Expand Down Expand Up @@ -591,7 +593,7 @@ ip_start() {
fi

add_interface "$OCF_RESKEY_ip" "$OCF_RESKEY_nic" "$NIC_unique" \
"$OCF_RESKEY_netmask" "$OCF_RESKEY_broadcast"
"$OCF_RESKEY_cidr_netmask" "$OCF_RESKEY_broadcast"
rc=$?
if [ $rc != 0 ]; then
ocf_log err "Could not add $OCF_RESKEY_ip to $OCF_RESKEY_nic: $rc"
Expand Down Expand Up @@ -757,43 +759,11 @@ ip_validate_all() {
;;
esac

#
# $FINDIF can NOT deal with the condition of empty intermediate parameters.
#
IFCMD="$FINDIF $OCF_RESKEY_ip"
# Note: We had a version out there for a while which renamed the
# parameter to cidr_netmask. So, don't remove this aliasing code!
if [ -n "$OCF_RESKEY_cidr_netmask" -o -n "$OCF_RESKEY_netmask" ]; then
if [ -n "$OCF_RESKEY_netmask" ]; then
IFCMD="$IFCMD/$OCF_RESKEY_netmask"
else
IFCMD="$IFCMD/$OCF_RESKEY_cidr_netmask"
fi
if [ -n "$OCF_RESKEY_nic" ]; then
IFCMD="$IFCMD/$OCF_RESKEY_nic"
if [ -n "$OCF_RESKEY_broadcast" ]; then
IFCMD="$IFCMD/$OCF_RESKEY_broadcast"
fi
elif [ x$OCF_RESKEY_broadcast != x ]; then
ocf_log err "Configured broadcast value is ignored when no value for nic is specified"
OCF_RESKEY_broadcast=""
fi
else
if [ x$OCF_RESKEY_broadcast != x ]; then
ocf_log err "Configured broadcast value is ignored when no value for netmask is specified"
OCF_RESKEY_broadcast=""
fi
if [ x$OCF_RESKEY_nic != x ]; then
ocf_log err "Configured nic value is ignored when no value for netmask is specified"
OCF_RESKEY_nic=""
fi
fi

NICINFO=`$IFCMD`
NICINFO=`$FINDIF`
rc=$?

if [ $rc != 0 ]; then
ocf_log err "$IFCMD failed [rc=$rc]."
ocf_log err "$FINDIF failed [rc=$rc]."
return $OCF_ERR_GENERIC
fi

Expand All @@ -808,12 +778,15 @@ ip_validate_all() {
fi

tmp=`echo "$NICINFO" | cut -f2 | cut -d ' ' -f2`
if [ "x$OCF_RESKEY_netmask" = "x" -a "x$OCF_RESKEY_cidr_netmask" = "x" ]; then
ocf_log debug "Using calculated netmask for ${OCF_RESKEY_ip}: $tmp"

if
[ -z "$OCF_RESKEY_cidr_netmask" ]
then
ocf_log debug "Using calculated netmask for ${OCF_RESKEY_ip}: $tmp"
OCF_RESKEY_cidr_netmask=$tmp; export OCF_RESKEY_cidr_netmask
elif [ "x$OCF_RESKEY_netmask" != "x$tmp" ]; then
ocf_log info "Using calculated netmask for ${OCF_RESKEY_ip}: $tmp"
fi

# Always use the calculated version becuase it might have been specified
# using CIDR notation which not every system accepts
OCF_RESKEY_netmask=$tmp
Expand Down Expand Up @@ -849,6 +822,15 @@ else
OCF_RESKEY_lvs_support=0
fi

# Note: We had a version out there for a while which used
# netmask instead of cidr_netmask. So, don't remove this aliasing code!
if
[ ! -z "$OCF_RESKEY_netmask" -a -z "$OCF_RESKEY_cidr_netmask" ]
then
OCF_RESKEY_cidr_netmask=$OCF_RESKEY_netmask
export OCF_RESKEY_cidr_netmask
fi

case $1 in
meta-data) meta_data;;
start) ip_validate_all && ip_start;;
Expand Down
28 changes: 17 additions & 11 deletions heartbeat/IPaddr2.in
@@ -1,5 +1,6 @@
#!/bin/sh
#
# $Id: IPaddr2.in,v 1.24 2006/08/09 13:01:54 lars Exp $
#
# OCF Resource Agent compliant IPaddr2 script.
#
Expand Down Expand Up @@ -81,10 +82,13 @@ meta_data() {
<version>1.0</version>
<longdesc lang="en">
OCF Resource Agent compliant IPaddr2 script.
Implements Cluster Alias IP functionality.
This Linux-specific resource manages IP alias IP addresses.
It can add an IP alias, or remove one.
In addition, it can implement Cluster Alias IP functionality
if invoked as a clone resource.
</longdesc>
<shortdesc lang="en">OCF Resource Agent compliant IPaddr2 script.</shortdesc>
<shortdesc lang="en">Manages virtual IPv4 addresses</shortdesc>
<parameters>
<parameter name="ip" unique="1" required="1">
Expand Down Expand Up @@ -268,10 +272,13 @@ ip_init() {
BASEIP="$OCF_RESKEY_ip"
BRDCAST="$OCF_RESKEY_broadcast"
NIC="$OCF_RESKEY_nic"
# Note: We had a version out there for a while which used
# netmask instead of cidr_netmask. Don't remove this aliasing code!
if
[ ! -z "$OCF_RESKEY_netmask" -a -z "$OCF_RESKEY_cidr_netmask" ]
then
OCF_RESKEY_cidr_netmask=$OCF_RESKEY_netmask
OCF_RESKEY_cidr_netmask=$OCF_RESKEY_netmask
export OCF_RESKEY_cidr_netmask
fi
NETMASK="$OCF_RESKEY_cidr_netmask"
IFLABEL="$OCF_RESKEY_iflabel"
Expand Down Expand Up @@ -303,20 +310,19 @@ ip_init() {


# Validation is performed in ip_validate()...

#
# $FINDIF can deal with the condition of empty intermediate parameters.
# $FINDIF now takes its parameters from the environment
#
NICINFO=`$FINDIF -C "$BASEIP/$NETMASK/$NIC/$BRDCAST"`

if [ $? -eq 0 ]; then
if
NICINFO=`$FINDIF -C`
then
NICINFO=`echo $NICINFO | sed -e 's/netmask\ //;s/broadcast\ //'`
NIC=`echo "$NICINFO" | cut -d" " -f1`
NETMASK=`echo "$NICINFO" | cut -d" " -f2`
BRDCAST=`echo "$NICINFO" | cut -d" " -f3`
else
ocf_log err "Failed: $FINDIF $BASEIP/$NETMASK/$NIC/$BRDCAST . Parameter error."
exit $OCF_ERR_GENERIC
ocf_log err "[$FINDIF -C] failed"
exit $OCF_ERR_ARGS
fi

SENDARPPIDFILE="$SENDARPPIDDIR/send_arp-$BASEIP"
Expand Down

0 comments on commit fe39b61

Please sign in to comment.