Blame SOURCES/bz1744224-IPsrcaddr-1-add-destination-and-table-parameters.patch

9cf66a
--- ClusterLabs-resource-agents-e711383f/heartbeat/IPsrcaddr	2019-08-15 16:02:10.055827624 +0200
9cf66a
+++ /home/oalbrigt/src/resource-agents/heartbeat/IPsrcaddr	2019-08-15 15:45:50.690757838 +0200
9cf66a
@@ -1,6 +1,6 @@
9cf66a
 #!/bin/sh
9cf66a
 #
9cf66a
-#	Description:	IPsrcaddr - Preferred source address modification
9cf66a
+#	Description:	IPsrcaddr - Preferred source(/dest) address modification
9cf66a
 #
9cf66a
 #	Author:			John Sutton <john@scl.co.uk>
9cf66a
 #	Support:		users@clusterlabs.org
9cf66a
@@ -11,7 +11,7 @@
9cf66a
 #
9cf66a
 #	This script manages the preferred source address associated with
9cf66a
 #	packets which originate on the localhost and are routed through the
9cf66a
-#	default route.  By default, i.e. without the use of this script or
9cf66a
+#	matching route.  By default, i.e. without the use of this script or
9cf66a
 #	similar, these packets will carry the IP of the primary i.e. the
9cf66a
 #	non-aliased interface.  This can be a nuisance if you need to ensure
9cf66a
 #	that such packets carry the same IP irrespective of which host in
9cf66a
@@ -27,7 +27,7 @@
9cf66a
 #
9cf66a
 #	NOTES:
9cf66a
 #
9cf66a
-#	1) There must be one and not more than 1 default route!  Mainly because
9cf66a
+#	1) There must be one and not more than 1 matching route!  Mainly because
9cf66a
 #	I can't see why you should have more than one.  And if there is more
9cf66a
 #	than one, we would have to box clever to find out which one is to be
9cf66a
 #	modified, or we would have to pass its identity as an argument.
9cf66a
@@ -54,16 +54,25 @@
9cf66a
 . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
9cf66a
 
9cf66a
 # Defaults
9cf66a
+OCF_RESKEY_ipaddress_default=""
9cf66a
+OCF_RESKEY_cidr_netmask_default=""
9cf66a
+OCF_RESKEY_destination_default="0.0.0.0/0"
9cf66a
 OCF_RESKEY_proto_default=""
9cf66a
+OCF_RESKEY_table_default=""
9cf66a
 
9cf66a
+: ${OCF_RESKEY_ipaddress=${OCF_RESKEY_ipaddress_default}}
9cf66a
+: ${OCF_RESKEY_cidr_netmask=${OCF_RESKEY_cidr_netmask_default}}
9cf66a
+: ${OCF_RESKEY_destination=${OCF_RESKEY_destination_default}}
9cf66a
 : ${OCF_RESKEY_proto=${OCF_RESKEY_proto_default}}
9cf66a
+: ${OCF_RESKEY_table=${OCF_RESKEY_table_default}}
9cf66a
 #######################################################################
9cf66a
 
9cf66a
 [ -z "$OCF_RESKEY_proto" ] && PROTO="" || PROTO="proto $OCF_RESKEY_proto"
9cf66a
+[ -z "$OCF_RESKEY_table" ] && TABLE="" || TABLE="table $OCF_RESKEY_table"
9cf66a
 
9cf66a
 USAGE="usage: $0 {start|stop|status|monitor|validate-all|meta-data}";
9cf66a
 
9cf66a
-  CMDSHOW="$IP2UTIL route show   to exact 0.0.0.0/0"
9cf66a
+  CMDSHOW="$IP2UTIL route show   $TABLE to exact $OCF_RESKEY_destination"
9cf66a
 CMDCHANGE="$IP2UTIL route change to "
9cf66a
 
9cf66a
 SYSTYPE="`uname -s`"
9cf66a
@@ -91,7 +100,7 @@
9cf66a
 The IP address. 
9cf66a
 </longdesc>
9cf66a
 <shortdesc lang="en">IP address</shortdesc>
9cf66a
-<content type="string" default="" />
9cf66a
+<content type="string" default="${OCF_RESKEY_ipaddress_default}" />
9cf66a
 </parameter>
9cf66a
 
9cf66a
 <parameter name="cidr_netmask">
9cf66a
@@ -100,7 +109,15 @@
9cf66a
 dotted quad notation  255.255.255.0).
9cf66a
 </longdesc>
9cf66a
 <shortdesc lang="en">Netmask</shortdesc>
9cf66a
-<content type="string" default=""/>
9cf66a
+<content type="string" default="${OCF_RESKEY_cidr_netmask_default}"/>
9cf66a
+</parameter>
9cf66a
+
9cf66a
+<parameter name="destination">
9cf66a
+<longdesc lang="en">
9cf66a
+The destination IP/subnet for the route (default: $OCF_RESKEY_destination_default)
9cf66a
+</longdesc>
9cf66a
+<shortdesc lang="en">Destination IP/subnet</shortdesc>
9cf66a
+<content type="string" default="${OCF_RESKEY_destination_default}" />
9cf66a
 </parameter>
9cf66a
 
9cf66a
 <parameter name="proto">
9cf66a
@@ -108,7 +125,17 @@
9cf66a
 Proto to match when finding network. E.g. "kernel".
9cf66a
 </longdesc>
9cf66a
 <shortdesc lang="en">Proto</shortdesc>
9cf66a
-<content type="string" default="" />
9cf66a
+<content type="string" default="${OCF_RESKEY_proto_default}" />
9cf66a
+</parameter>
9cf66a
+
9cf66a
+<parameter name="table">
9cf66a
+<longdesc lang="en">
9cf66a
+Table to modify. E.g. "local".
9cf66a
+
9cf66a
+The table has to have a route matching the "destination" parameter.
9cf66a
+</longdesc>
9cf66a
+<shortdesc lang="en">Table</shortdesc>
9cf66a
+<content type="string" default="${OCF_RESKEY_table_default}" />
9cf66a
 </parameter>
9cf66a
 </parameters>
9cf66a
 
9cf66a
@@ -151,21 +178,22 @@
9cf66a
 export OCF_RESKEY_ip=$OCF_RESKEY_ipaddress
9cf66a
 
9cf66a
 srca_read() {
9cf66a
-	# Capture the default route - doublequotes prevent word splitting...
9cf66a
-	DEFROUTE="`$CMDSHOW`" || errorexit "command '$CMDSHOW' failed"
9cf66a
-
9cf66a
-	# ... so we can make sure there is only 1 default route
9cf66a
-	[ 1 -eq `echo "$DEFROUTE" | wc -l` ] || \
9cf66a
-		errorexit "more than 1 default route exists"
9cf66a
+	# Capture matching route - doublequotes prevent word splitting...
9cf66a
+	ROUTE="`$CMDSHOW`" || errorexit "command '$CMDSHOW' failed"
9cf66a
 
9cf66a
-	# But there might still be no default route
9cf66a
-	[ -z "$DEFROUTE" ] && errorexit "no default route exists"
9cf66a
+	# ... so we can make sure there is only 1 matching route
9cf66a
+	[ 1 -eq `echo "$ROUTE" | wc -l` ] || \
9cf66a
+		errorexit "more than 1 matching route exists"
9cf66a
+
9cf66a
+	# But there might still be no matching route
9cf66a
+	[ "$OCF_RESKEY_destination" = "0.0.0.0/0" ] && [ -z "$ROUTE" ] && \
9cf66a
+		 ! ocf_is_probe && errorexit "no matching route exists"
9cf66a
 
9cf66a
 	# Sed out the source ip address if it exists
9cf66a
-	SRCIP=`echo $DEFROUTE | sed -n "s/$MATCHROUTE/\3/p"`
9cf66a
+	SRCIP=`echo $ROUTE | sed -n "s/$MATCHROUTE/\3/p"`
9cf66a
 
9cf66a
 	# and what remains after stripping out the source ip address clause
9cf66a
-	ROUTE_WO_SRC=`echo $DEFROUTE | sed "s/$MATCHROUTE/\1\5/"`
9cf66a
+	ROUTE_WO_SRC=`echo $ROUTE | sed "s/$MATCHROUTE/\1\5/"`
9cf66a
 
9cf66a
 	[ -z "$SRCIP" ] && return 1
9cf66a
 	[ $SRCIP = $1 ] && return 0
9cf66a
@@ -185,11 +213,13 @@
9cf66a
 		rc=$OCF_SUCCESS
9cf66a
 		ocf_log info "The ip route has been already set.($NETWORK, $INTERFACE, $ROUTE_WO_SRC)"
9cf66a
 	else
9cf66a
-		$IP2UTIL route replace $NETWORK dev $INTERFACE src $1 || \
9cf66a
-			errorexit "command 'ip route replace $NETWORK dev $INTERFACE src $1' failed"
9cf66a
+		$IP2UTIL route replace $TABLE $NETWORK dev $INTERFACE src $1 || \
9cf66a
+			errorexit "command 'ip route replace $TABLE $NETWORK dev $INTERFACE src $1' failed"
9cf66a
 
9cf66a
-		$CMDCHANGE $ROUTE_WO_SRC src $1 || \
9cf66a
-			errorexit "command '$CMDCHANGE $ROUTE_WO_SRC src $1' failed"
9cf66a
+		if [ "$OCF_RESKEY_destination" = "0.0.0.0/0" ] ;then
9cf66a
+			$CMDCHANGE $ROUTE_WO_SRC src $1 || \
9cf66a
+				errorexit "command '$CMDCHANGE $ROUTE_WO_SRC src $1' failed"
9cf66a
+		fi
9cf66a
 		rc=$?
9cf66a
 	fi
9cf66a
 
9cf66a
@@ -201,7 +231,7 @@
9cf66a
 #	If one exists but it's not the same as the one specified, that's
9cf66a
 #	an error.  Maybe that's the wrong behaviour because if this fails
9cf66a
 #	then when IPaddr releases the associated interface (if there is one)
9cf66a
-#	your default route will also get dropped ;-(
9cf66a
+#	your matching route will also get dropped ;-(
9cf66a
 #	The exit code should conform to LSB exit codes.
9cf66a
 #
9cf66a
 
9cf66a
@@ -217,11 +247,13 @@
9cf66a
 	  
9cf66a
 	[ $rc = 2 ] && errorexit "The address you specified to stop does not match the preferred source address"
9cf66a
 
9cf66a
-	$IP2UTIL route replace $NETWORK dev $INTERFACE || \
9cf66a
-		errorexit "command 'ip route replace $NETWORK dev $INTERFACE' failed"
9cf66a
+	$IP2UTIL route replace $TABLE $NETWORK dev $INTERFACE || \
9cf66a
+		errorexit "command 'ip route replace $TABLE $NETWORK dev $INTERFACE' failed"
9cf66a
 
9cf66a
-	$CMDCHANGE $ROUTE_WO_SRC || \
9cf66a
-		errorexit "command '$CMDCHANGE $ROUTE_WO_SRC' failed"
9cf66a
+	if [ "$OCF_RESKEY_destination" = "0.0.0.0/0" ] ;then
9cf66a
+		$CMDCHANGE $ROUTE_WO_SRC || \
9cf66a
+			errorexit "command '$CMDCHANGE $ROUTE_WO_SRC' failed"
9cf66a
+	fi
9cf66a
 
9cf66a
 	return $?
9cf66a
 }
9cf66a
@@ -406,6 +438,10 @@
9cf66a
 		return $OCF_ERR_CONFIGURED
9cf66a
 	fi
9cf66a
 
9cf66a
+	if ! echo "$OCF_RESKEY_destination" | grep -q "/"; then
9cf66a
+		return $OCF_ERR_CONFIGURED
9cf66a
+	fi
9cf66a
+
9cf66a
 
9cf66a
 	if ! [ "x$SYSTYPE" = "xLinux" ]; then
9cf66a
 		# checks after this point are only relevant for linux.
9cf66a
@@ -486,7 +522,11 @@
9cf66a
 }
9cf66a
 
9cf66a
 INTERFACE=`echo $findif_out | awk '{print $1}'`
9cf66a
-NETWORK=`$IP2UTIL route list dev $INTERFACE scope link $PROTO match $ipaddress|grep -m 1 -o '^[^ ]*'`
9cf66a
+if [ "$OCF_RESKEY_destination" = "0.0.0.0/0" ] ;then
9cf66a
+	NETWORK=`$IP2UTIL route list dev $INTERFACE scope link $PROTO match $ipaddress|grep -m 1 -o '^[^ ]*'`
9cf66a
+else
9cf66a
+	NETWORK="$OCF_RESKEY_destination"
9cf66a
+fi
9cf66a
 
9cf66a
 case $1 in
9cf66a
 	start)		srca_start $ipaddress