|
|
92e3c0 |
From 50a596bfb977b18902dc62b99145bbd1a087690a Mon Sep 17 00:00:00 2001
|
|
|
92e3c0 |
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
|
|
|
92e3c0 |
Date: Tue, 1 Mar 2022 11:06:07 +0100
|
|
|
92e3c0 |
Subject: [PATCH] IPsrcaddr: fixes
|
|
|
92e3c0 |
|
|
|
92e3c0 |
- use findif.sh to detect secondary interfaces
|
|
|
92e3c0 |
- get metric and proto to update the correct route/update it correctly
|
|
|
92e3c0 |
- match route using interface to fail when trying to update secondary
|
|
|
92e3c0 |
interfaces without specifying destination (would update default route
|
|
|
92e3c0 |
before)
|
|
|
92e3c0 |
- also use PRIMARY_IP/OPTS during stop-action for default routes (to get
|
|
|
92e3c0 |
back to the exact routes we started with)
|
|
|
92e3c0 |
- dont fail during stop-action if route doesnt exist
|
|
|
92e3c0 |
- use [[:blank:]] for WS to follow POSIX standard (suggested by nrwahl)
|
|
|
92e3c0 |
---
|
|
|
92e3c0 |
heartbeat/IPsrcaddr | 35 +++++++++++++++++++----------------
|
|
|
92e3c0 |
1 file changed, 19 insertions(+), 16 deletions(-)
|
|
|
92e3c0 |
|
|
|
92e3c0 |
diff --git a/heartbeat/IPsrcaddr b/heartbeat/IPsrcaddr
|
|
|
92e3c0 |
index c82adc0e9..7dbf65ff5 100755
|
|
|
92e3c0 |
--- a/heartbeat/IPsrcaddr
|
|
|
92e3c0 |
+++ b/heartbeat/IPsrcaddr
|
|
|
92e3c0 |
@@ -52,6 +52,7 @@
|
|
|
92e3c0 |
# Initialization:
|
|
|
92e3c0 |
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
|
|
|
92e3c0 |
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
|
|
|
92e3c0 |
+. ${OCF_FUNCTIONS_DIR}/findif.sh
|
|
|
92e3c0 |
|
|
|
92e3c0 |
# Defaults
|
|
|
92e3c0 |
OCF_RESKEY_ipaddress_default=""
|
|
|
92e3c0 |
@@ -181,19 +182,21 @@ errorexit() {
|
|
|
92e3c0 |
#
|
|
|
92e3c0 |
# where the src clause "src Y.Y.Y.Y" may or may not be present
|
|
|
92e3c0 |
|
|
|
92e3c0 |
-WS="[`echo -en ' \t'`]"
|
|
|
92e3c0 |
+WS="[[:blank:]]"
|
|
|
92e3c0 |
OCTET="[0-9]\{1,3\}"
|
|
|
92e3c0 |
IPADDR="\($OCTET\.\)\{3\}$OCTET"
|
|
|
92e3c0 |
SRCCLAUSE="src$WS$WS*\($IPADDR\)"
|
|
|
92e3c0 |
MATCHROUTE="\(.*${WS}\)\($SRCCLAUSE\)\($WS.*\|$\)"
|
|
|
92e3c0 |
-FINDIF=$HA_BIN/findif
|
|
|
92e3c0 |
+METRICCLAUSE=".*\(metric$WS[^ ]\+\)"
|
|
|
92e3c0 |
+PROTOCLAUSE=".*\(proto$WS[^ ]\+\)"
|
|
|
92e3c0 |
+FINDIF=findif
|
|
|
92e3c0 |
|
|
|
92e3c0 |
# findif needs that to be set
|
|
|
92e3c0 |
export OCF_RESKEY_ip=$OCF_RESKEY_ipaddress
|
|
|
92e3c0 |
|
|
|
92e3c0 |
srca_read() {
|
|
|
92e3c0 |
# Capture matching route - doublequotes prevent word splitting...
|
|
|
92e3c0 |
- ROUTE="`$CMDSHOW 2> /dev/null`" || errorexit "command '$CMDSHOW' failed"
|
|
|
92e3c0 |
+ ROUTE="`$CMDSHOW dev $INTERFACE 2> /dev/null`" || errorexit "command '$CMDSHOW' failed"
|
|
|
92e3c0 |
|
|
|
92e3c0 |
# ... so we can make sure there is only 1 matching route
|
|
|
92e3c0 |
[ 1 -eq `echo "$ROUTE" | wc -l` ] || \
|
|
|
92e3c0 |
@@ -201,7 +204,7 @@ srca_read() {
|
|
|
92e3c0 |
|
|
|
92e3c0 |
# But there might still be no matching route
|
|
|
92e3c0 |
[ "$OCF_RESKEY_destination" = "0.0.0.0/0" ] && [ -z "$ROUTE" ] && \
|
|
|
92e3c0 |
- ! ocf_is_probe && errorexit "no matching route exists"
|
|
|
92e3c0 |
+ ! ocf_is_probe && [ "$__OCF_ACTION" != stop ] && errorexit "no matching route exists"
|
|
|
92e3c0 |
|
|
|
92e3c0 |
# Sed out the source ip address if it exists
|
|
|
92e3c0 |
SRCIP=`echo $ROUTE | sed -n "s/$MATCHROUTE/\3/p"`
|
|
|
92e3c0 |
@@ -232,8 +235,8 @@ srca_start() {
|
|
|
92e3c0 |
rc=$OCF_SUCCESS
|
|
|
92e3c0 |
ocf_log info "The ip route has been already set.($NETWORK, $INTERFACE, $ROUTE_WO_SRC)"
|
|
|
92e3c0 |
else
|
|
|
92e3c0 |
- $IP2UTIL route replace $TABLE $NETWORK dev $INTERFACE src $1 || \
|
|
|
92e3c0 |
- errorexit "command 'ip route replace $TABLE $NETWORK dev $INTERFACE src $1' failed"
|
|
|
92e3c0 |
+ $IP2UTIL route replace $TABLE $NETWORK dev $INTERFACE $PROTO src $1 $METRIC || \
|
|
|
92e3c0 |
+ errorexit "command 'ip route replace $TABLE $NETWORK dev $INTERFACE $PROTO src $1 $METRIC' failed"
|
|
|
92e3c0 |
|
|
|
92e3c0 |
if [ "$OCF_RESKEY_destination" = "0.0.0.0/0" ] ;then
|
|
|
92e3c0 |
$CMDCHANGE $ROUTE_WO_SRC src $1 || \
|
|
|
92e3c0 |
@@ -266,14 +269,11 @@ srca_stop() {
|
|
|
92e3c0 |
|
|
|
92e3c0 |
[ $rc = 2 ] && errorexit "The address you specified to stop does not match the preferred source address"
|
|
|
92e3c0 |
|
|
|
92e3c0 |
- OPTS=""
|
|
|
92e3c0 |
- if [ "$OCF_RESKEY_destination" != "0.0.0.0/0" ] ;then
|
|
|
92e3c0 |
- PRIMARY_IP="$($IP2UTIL -4 -o addr show dev $INTERFACE primary | awk '{split($4,a,"/");print a[1]}')"
|
|
|
92e3c0 |
- OPTS="proto kernel scope host src $PRIMARY_IP"
|
|
|
92e3c0 |
- fi
|
|
|
92e3c0 |
+ PRIMARY_IP="$($IP2UTIL -4 -o addr show dev $INTERFACE primary | awk '{split($4,a,"/");print a[1]}')"
|
|
|
92e3c0 |
+ OPTS="proto kernel scope link src $PRIMARY_IP"
|
|
|
92e3c0 |
|
|
|
92e3c0 |
- $IP2UTIL route replace $TABLE $NETWORK dev $INTERFACE $OPTS || \
|
|
|
92e3c0 |
- errorexit "command 'ip route replace $TABLE $NETWORK dev $INTERFACE $OPTS' failed"
|
|
|
92e3c0 |
+ $IP2UTIL route replace $TABLE $NETWORK dev $INTERFACE $OPTS $METRIC || \
|
|
|
92e3c0 |
+ errorexit "command 'ip route replace $TABLE $NETWORK dev $INTERFACE $OPTS $METRIC' failed"
|
|
|
92e3c0 |
|
|
|
92e3c0 |
if [ "$OCF_RESKEY_destination" = "0.0.0.0/0" ] ;then
|
|
|
92e3c0 |
$CMDCHANGE $ROUTE_WO_SRC || \
|
|
|
92e3c0 |
@@ -539,16 +539,19 @@ if [ $rc -ne $OCF_SUCCESS ]; then
|
|
|
92e3c0 |
esac
|
|
|
92e3c0 |
fi
|
|
|
92e3c0 |
|
|
|
92e3c0 |
-findif_out=`$FINDIF -C`
|
|
|
92e3c0 |
+findif_out=`$FINDIF`
|
|
|
92e3c0 |
rc=$?
|
|
|
92e3c0 |
[ $rc -ne 0 ] && {
|
|
|
92e3c0 |
- ocf_exit_reason "[$FINDIF -C] failed"
|
|
|
92e3c0 |
+ ocf_exit_reason "[$FINDIF] failed"
|
|
|
92e3c0 |
exit $rc
|
|
|
92e3c0 |
}
|
|
|
92e3c0 |
|
|
|
92e3c0 |
INTERFACE=`echo $findif_out | awk '{print $1}'`
|
|
|
92e3c0 |
+LISTROUTE=`$IP2UTIL route list dev $INTERFACE scope link $PROTO match $ipaddress`
|
|
|
92e3c0 |
+METRIC=`echo $LISTROUTE | sed -n "s/$METRICCLAUSE/\1/p"`
|
|
|
92e3c0 |
+[ -z "$PROTO" ] && PROTO=`echo $LISTROUTE | sed -n "s/$PROTOCLAUSE/\1/p"`
|
|
|
92e3c0 |
if [ "$OCF_RESKEY_destination" = "0.0.0.0/0" ] ;then
|
|
|
92e3c0 |
- NETWORK=`$IP2UTIL route list dev $INTERFACE scope link $PROTO match $ipaddress|grep -m 1 -o '^[^ ]*'`
|
|
|
92e3c0 |
+ NETWORK=`echo $LISTROUTE | grep -m 1 -o '^[^ ]*'`
|
|
|
92e3c0 |
|
|
|
92e3c0 |
if [ -z "$NETWORK" ]; then
|
|
|
92e3c0 |
err_str="command '$IP2UTIL route list dev $INTERFACE scope link $PROTO"
|