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

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