OPS patch for Keepalived

Erik de Groot <[email protected]>
Newsgroups gmane.linux.keepalived.devel
Message-ID <[email protected]>
Hi,

I've created an patch to include support for One Packet Scheduling 
(--ops in ipvsadm) in Keepalived.

The reason for doing this that I want to use Keepalived for RADIUS 
loadbalancing. The tricky point with RADIUS is that it comes from a very 
limited pool of source IP/soure port combinations. This alone could 
cause load not being correctly balanced over the real servers. An 
additional problem occurs when a previously failed real-server is 
recovered. Since LVS creates virtual connections for RADIUS traffic 
which, with RADIUS, will never actually expire, the just recovered 
real-server will not get any RADIUS traffic assigned until some other 
real-server in the pool fails. This is unacceptable for most situations.

The patch was developed and tested on Keepalived 1.2.7.

I hope the patch is OK, but obviously I am open to suggestions to 
improve it.

Best Regards,
Erik

------------------------------------------------------------------------------
Introducing Performance Central, a new site from SourceForge and 
AppDynamics. Performance Central is your source for news, insights, 
analysis and resources for efficient Application Performance Management. 
Visit us today!
http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk

_______________________________________________
Keepalived-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/keepalived-devel
keepalived-1.2.7-ops.patch (text/plain, 6.3 KB)
diff --recursive -u keepalived-1.2.7/doc/KEEPALIVED-MIB keepalived-1.2.7.new/doc/KEEPALIVED-MIB
--- keepalived-1.2.7/doc/KEEPALIVED-MIB	2012-08-29 00:05:12.000000000 +0200
+++ keepalived-1.2.7.new/doc/KEEPALIVED-MIB	2013-06-10 18:24:40.011861837 +0200
@@ -1271,6 +1271,7 @@
 	virtualServerProtocol INTEGER,
 	virtualServerLoadBalancingAlgo INTEGER,
 	virtualServerLoadBalancingKind INTEGER,
+    virtualServerOPS TruthValue,
 	virtualServerStatus INTEGER,
 	virtualServerVirtualHost DisplayString,
 	virtualServerPersist INTEGER,
@@ -1623,6 +1624,14 @@
 	"Current outgoing rate for this virtual server."
     ::= { virtualServerEntry 36 }
 
+virtualServerOPS OBJECT-TYPE
+    SYNTAX TruthValue
+    MAX-ACCESS read-only
+    STATUS current
+    DESCRIPTION
+        "If set to true(1), One-Packet-Scheduling will be applied."
+    ::= { virtualServerEntry 37 }
+
 
 -- real servers
 
diff --recursive -u keepalived-1.2.7/doc/keepalived.conf.SYNOPSIS keepalived-1.2.7.new/doc/keepalived.conf.SYNOPSIS
--- keepalived-1.2.7/doc/keepalived.conf.SYNOPSIS	2012-07-18 21:59:40.000000000 +0200
+++ keepalived-1.2.7.new/doc/keepalived.conf.SYNOPSIS	2013-06-10 18:30:47.599872228 +0200
@@ -273,6 +273,7 @@
 virtual_server group <STRING>      {	# VS group declaration
     delay_loop <INTEGER>		# delay timer for service polling
     lvs_sched rr|wrr|lc|wlc|lblc|sh|dh	# LVS scheduler used
+    ops                                 # Apply One-Packet-Scheduling (only for UDP)
     lvs_method NAT|DR|TUN		# LVS method used
     persistence_timeout <INTEGER>	# LVS persistence timeout
     persistence_granularity <NETMASK>	# LVS granularity mask
diff --recursive -u keepalived-1.2.7/doc/man/man5/keepalived.conf.5 keepalived-1.2.7.new/doc/man/man5/keepalived.conf.5
--- keepalived-1.2.7/doc/man/man5/keepalived.conf.5	2012-08-13 20:50:25.000000000 +0200
+++ keepalived-1.2.7.new/doc/man/man5/keepalived.conf.5	2013-06-10 18:31:32.630883047 +0200
@@ -294,6 +294,8 @@
 
     # LVS scheduler 
     lb_algo rr|wrr|lc|wlc|lblc|sh|dh 
+    # Enable One-Packet-Scheduling for UDP (-O in ipvsadm)
+    ops
     # LVS forwarding method
     lb_kind NAT|DR|TUN 
     # LVS persistence timeout, sec
diff --recursive -u keepalived-1.2.7/keepalived/check/check_parser.c keepalived-1.2.7.new/keepalived/check/check_parser.c
--- keepalived-1.2.7/keepalived/check/check_parser.c	2012-08-29 00:05:12.000000000 +0200
+++ keepalived-1.2.7.new/keepalived/check/check_parser.c	2013-06-10 11:06:25.051900688 +0200
@@ -151,6 +151,12 @@
 	vs->ha_suspend = 1;
 }
 static void
+ops_handler(vector_t *strvec)
+{
+	virtual_server *vs = LIST_TAIL_DATA(check_data->vs);
+	vs->ops = 1;
+}
+static void
 virtualhost_handler(vector_t *strvec)
 {
 	virtual_server *vs = LIST_TAIL_DATA(check_data->vs);
@@ -294,6 +300,7 @@
 	install_keyword("persistence_granularity", &pgr_handler);
 	install_keyword("protocol", &proto_handler);
 	install_keyword("ha_suspend", &hasuspend_handler);
+	install_keyword("ops", &ops_handler);
 	install_keyword("virtualhost", &virtualhost_handler);
 
 	/* Pool regression detection and handling. */
diff --recursive -u keepalived-1.2.7/keepalived/check/check_snmp.c keepalived-1.2.7.new/keepalived/check/check_snmp.c
--- keepalived-1.2.7/keepalived/check/check_snmp.c	2012-08-29 00:05:12.000000000 +0200
+++ keepalived-1.2.7.new/keepalived/check/check_snmp.c	2013-06-10 17:56:47.125863702 +0200
@@ -333,6 +333,9 @@
 	case CHECK_SNMP_VSHASUSPEND:
 		long_ret = v->ha_suspend?1:2;
 		return (u_char*)&long_ret;
+	case CHECK_SNMP_VSOPS:
+		long_ret = v->ops?1:2;
+		return (u_char*)&long_ret;
 	case CHECK_SNMP_VSALPHA:
 		long_ret = v->alpha?1:2;
 		return (u_char*)&long_ret;
@@ -787,6 +790,8 @@
 	 check_snmp_virtualserver, 3, {3, 1, 25}},
 	{CHECK_SNMP_VSHYSTERESIS, ASN_UNSIGNED, RONLY,
 	 check_snmp_virtualserver, 3, {3, 1, 26}},
+	{CHECK_SNMP_VSOPS, ASN_INTEGER, RONLY,
+	 check_snmp_virtualserver, 3, {3, 1, 37}},
 #if defined(_KRNL_2_6_) && defined(_WITH_LVS_)
 	{CHECK_SNMP_VSSTATSCONNS, ASN_GAUGE, RONLY,
 	 check_snmp_virtualserver, 3, {3, 1, 27}},
diff --recursive -u keepalived-1.2.7/keepalived/check/ipvswrapper.c keepalived-1.2.7.new/keepalived/check/ipvswrapper.c
--- keepalived-1.2.7/keepalived/check/ipvswrapper.c	2012-08-13 20:50:25.000000000 +0200
+++ keepalived-1.2.7.new/keepalived/check/ipvswrapper.c	2013-06-10 12:24:27.281867019 +0200
@@ -543,7 +543,11 @@
 				    , ntohs(inet_sockaddrport(&vs->addr)));
 
 	if (srule->timeout != 0 || vs->granularity_persistence)
-		srule->flags = IP_VS_SVC_F_PERSISTENT;
+		srule->flags |= IP_VS_SVC_F_PERSISTENT;
+
+    /* Only for UDP services */
+    if (vs->ops == 1 && srule->protocol == IPPROTO_UDP)
+		srule->flags |= IP_VS_SVC_F_ONEPACKET;
 
 	if (cmd == IP_VS_SO_SET_ADD || cmd == IP_VS_SO_SET_DEL)
 		if (vs->granularity_persistence)
diff --recursive -u keepalived-1.2.7/keepalived/include/check_data.h keepalived-1.2.7.new/keepalived/include/check_data.h
--- keepalived-1.2.7/keepalived/include/check_data.h	2012-08-29 00:05:12.000000000 +0200
+++ keepalived-1.2.7.new/keepalived/include/check_data.h	2013-06-10 11:04:46.731866636 +0200
@@ -116,6 +116,7 @@
 	uint16_t service_type;
 	long delay_loop;
 	int ha_suspend;
+    int ops;
 	char sched[SCHED_MAX_LENGTH];
 	char timeout_persistence[MAX_TIMEOUT_LENGTH];
 	unsigned loadbalancing_kind;
diff --recursive -u keepalived-1.2.7/keepalived/include/check_snmp.h keepalived-1.2.7.new/keepalived/include/check_snmp.h
--- keepalived-1.2.7/keepalived/include/check_snmp.h	2012-08-13 20:50:25.000000000 +0200
+++ keepalived-1.2.7.new/keepalived/include/check_snmp.h	2013-06-10 18:00:05.148903082 +0200
@@ -97,6 +97,7 @@
 #define CHECK_SNMP_RSRATEOUTPPS 58
 #define CHECK_SNMP_RSRATEINBPS 59
 #define CHECK_SNMP_RSRATEOUTBPS 60
+#define CHECK_SNMP_VSOPS 71
 
 #define STATE_VSGM_FWMARK 1
 #define STATE_VSGM_ADDRESS 2
diff --recursive -u keepalived-1.2.7/keepalived/libipvs-2.6/ip_vs.h keepalived-1.2.7.new/keepalived/libipvs-2.6/ip_vs.h
--- keepalived-1.2.7/keepalived/libipvs-2.6/ip_vs.h	2012-07-18 21:47:24.000000000 +0200
+++ keepalived-1.2.7.new/keepalived/libipvs-2.6/ip_vs.h	2013-06-10 10:16:36.990865018 +0200
@@ -34,7 +34,8 @@
  *      Virtual Service Flags
  */
 #define IP_VS_SVC_F_PERSISTENT	0x0001		/* persistent port */
-#define IP_VS_SVC_F_HASHED	0x0002		/* hashed entry */
+#define IP_VS_SVC_F_HASHED	0x0002		    /* hashed entry */
+#define IP_VS_SVC_F_ONEPACKET  0x0004       /* one-packet scheduling */
 
 /*
  *      Destination Server Flags
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.