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

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