Skip to content

Commit

Permalink
Low: findif.sh: move parameter checks to a function
Browse files Browse the repository at this point in the history
  • Loading branch information
Keisuke MORI committed Oct 19, 2012
1 parent e9ba65c commit 3348918
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions heartbeat/findif.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,15 @@ getnetworkinfo()
echo $LINE)
}

findif()
findif_check_params()
{
local family="$1"
local match="$OCF_RESKEY_ip"
local family="inet"
local scope
local NIC="$OCF_RESKEY_nic"
local NETMASK="$OCF_RESKEY_cidr_netmask"
local BRDCAST="$OCF_RESKEY_broadcast"
echo $match | grep -qs ":"
if [ $? = 0 ] ; then

if [ "$family" = "inet6" ] ; then
ipcheck_ipv6 $match
if [ $? = 1 ] ; then
ocf_log err "IP address [$match] not valid."
Expand All @@ -112,10 +111,9 @@ findif()
ocf_log err "Invalid netmask specification [$NETMASK]."
return $OCF_ERR_CONFIGURED
fi
match=$match/$NETMASK
fi
family="inet6"
else
# family = inet
ipcheck_ipv4 $match
if [ $? = 1 ] ; then
ocf_log err "IP address [$match] not valid."
Expand All @@ -134,7 +132,6 @@ findif()
ocf_log err "Invalid netmask specification [$NETMASK]."
return $OCF_ERR_CONFIGURED
fi
match=$match/$NETMASK
fi
if [ -n "$BRDCAST" ] ; then
ipcheck_ipv4 $BRDCAST
Expand All @@ -143,8 +140,31 @@ findif()
return $OCF_ERR_CONFIGURED
fi
fi
fi
return $OCF_SUCCESS
}

findif()
{
local match="$OCF_RESKEY_ip"
local family
local scope
local NIC="$OCF_RESKEY_nic"
local NETMASK="$OCF_RESKEY_cidr_netmask"
local BRDCAST="$OCF_RESKEY_broadcast"

This comment has been minimized.

Copy link
@dmuhamedagic

dmuhamedagic Oct 22, 2012

Local variables are typically lowercase. Obviously, this is just a style observation, but it may be good to consider later.

This comment has been minimized.

Copy link
@dmuhamedagic

dmuhamedagic Oct 22, 2012

In order to avoid potential confusion, that is :)

This comment has been minimized.

Copy link
@kskmori

kskmori Oct 23, 2012

Owner

Right. I've added a commit d2a7772 for fixing it.


echo $match | grep -qs ":"
if [ $? = 0 ] ; then
family="inet6"
else
family="inet"
scope="scope link"
fi
findif_check_params $family || return $?

if [ -n "$NETMASK" ] ; then
match=$match/$NETMASK
fi
if [ -n "$NIC" ] ; then
# NIC supports more than two.
set -- `ip -o -f $family route list match $match $scope | grep "dev $NIC"`
Expand Down

0 comments on commit 3348918

Please sign in to comment.