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

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