Blame SOURCES/bz2055016-4-IPsrcaddr-fixes.patch

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