All of lore.kernel.org
 help / color / mirror / Atom feed
From: kaber@trash.net
To: davem@davemloft.net
Cc: netfilter-devel@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH 31/79] IPVS: Backup, adding version 0 sending capabilities
Date: Wed, 19 Jan 2011 20:14:31 +0100	[thread overview]
Message-ID: <1295464519-21763-32-git-send-email-kaber@trash.net> (raw)
In-Reply-To: <1295464519-21763-1-git-send-email-kaber@trash.net>

From: Hans Schillstrom <hans.schillstrom@ericsson.com>

This patch adds a sysclt net.ipv4.vs.sync_version
that can be used to send sync msg in version 0 or 1 format.

sync_version value is logical,
     Value 1 (default) New version
           0 Plain old version

Signed-off-by: Hans Schillstrom <hans.schillstrom@ericsson.com>
Acked-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Simon Horman <horms@verge.net.au>
---
 include/net/ip_vs.h             |    2 +
 net/netfilter/ipvs/ip_vs_ctl.c  |   28 ++++++++-
 net/netfilter/ipvs/ip_vs_sync.c |  134 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 163 insertions(+), 1 deletions(-)

diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
index a715f3d..d858264 100644
--- a/include/net/ip_vs.h
+++ b/include/net/ip_vs.h
@@ -883,7 +883,9 @@ extern int sysctl_ip_vs_conntrack;
 extern int sysctl_ip_vs_snat_reroute;
 extern struct ip_vs_stats ip_vs_stats;
 extern const struct ctl_path net_vs_ctl_path[];
+extern int sysctl_ip_vs_sync_ver;
 
+extern void ip_vs_sync_switch_mode(int mode);
 extern struct ip_vs_service *
 ip_vs_service_get(int af, __u32 fwmark, __u16 protocol,
 		  const union nf_inet_addr *vaddr, __be16 vport);
diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
index a5bd002..d12a13c 100644
--- a/net/netfilter/ipvs/ip_vs_ctl.c
+++ b/net/netfilter/ipvs/ip_vs_ctl.c
@@ -92,7 +92,7 @@ int sysctl_ip_vs_nat_icmp_send = 0;
 int sysctl_ip_vs_conntrack;
 #endif
 int sysctl_ip_vs_snat_reroute = 1;
-
+int sysctl_ip_vs_sync_ver = 1;		/* Default version of sync proto */
 
 #ifdef CONFIG_IP_VS_DEBUG
 static int sysctl_ip_vs_debug_level = 0;
@@ -1536,6 +1536,25 @@ proc_do_sync_threshold(ctl_table *table, int write,
 	return rc;
 }
 
+static int
+proc_do_sync_mode(ctl_table *table, int write,
+		     void __user *buffer, size_t *lenp, loff_t *ppos)
+{
+	int *valp = table->data;
+	int val = *valp;
+	int rc;
+
+	rc = proc_dointvec(table, write, buffer, lenp, ppos);
+	if (write && (*valp != val)) {
+		if ((*valp < 0) || (*valp > 1)) {
+			/* Restore the correct value */
+			*valp = val;
+		} else {
+			ip_vs_sync_switch_mode(val);
+		}
+	}
+	return rc;
+}
 
 /*
  *	IPVS sysctl table (under the /proc/sys/net/ipv4/vs/)
@@ -1602,6 +1621,13 @@ static struct ctl_table vs_vars[] = {
 		.mode		= 0644,
 		.proc_handler	= &proc_dointvec,
 	},
+	{
+		.procname	= "sync_version",
+		.data		= &sysctl_ip_vs_sync_ver,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= &proc_do_sync_mode,
+	},
 #if 0
 	{
 		.procname	= "timeout_established",
diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
index df5abf0..c1c167a 100644
--- a/net/netfilter/ipvs/ip_vs_sync.c
+++ b/net/netfilter/ipvs/ip_vs_sync.c
@@ -5,6 +5,18 @@
  *              high-performance and highly available server based on a
  *              cluster of servers.
  *
+ * Version 1,   is capable of handling both version 0 and 1 messages.
+ *              Version 0 is the plain old format.
+ *              Note Version 0 receivers will just drop Ver 1 messages.
+ *              Version 1 is capable of handle IPv6, Persistence data,
+ *              time-outs, and firewall marks.
+ *              In ver.1 "ip_vs_sync_conn_options" will be sent in netw. order.
+ *              Ver. 0 can be turned on by sysctl -w net.ipv4.vs.sync_version=0
+ *
+ * Definitions  Message: is a complete datagram
+ *              Sync_conn: is a part of a Message
+ *              Param Data is an option to a Sync_conn.
+ *
  * Authors:     Wensong Zhang <wensong@linuxvirtualserver.org>
  *
  * ip_vs_sync:  sync connection info from master load balancer to backups
@@ -15,6 +27,8 @@
  *	Alexandre Cassen	:	Added SyncID support for incoming sync
  *					messages filtering.
  *	Justin Ossevoort	:	Fix endian problem on sync message size.
+ *	Hans Schillstrom	:	Added Version 1: i.e. IPv6,
+ *					Persistence support, fwmark and time-out.
  */
 
 #define KMSG_COMPONENT "IPVS"
@@ -392,6 +406,121 @@ get_curr_sync_buff(unsigned long time)
 }
 
 /*
+ * Switch mode from sending version 0 or 1
+ *  - must handle sync_buf
+ */
+void ip_vs_sync_switch_mode(int mode) {
+
+	if (!ip_vs_sync_state & IP_VS_STATE_MASTER)
+		return;
+	if (mode == sysctl_ip_vs_sync_ver || !curr_sb)
+		return;
+
+	spin_lock_bh(&curr_sb_lock);
+	/* Buffer empty ? then let buf_create do the job  */
+	if ( curr_sb->mesg->size <=  sizeof(struct ip_vs_sync_mesg)) {
+		kfree(curr_sb);
+		curr_sb = NULL;
+	} else {
+		spin_lock_bh(&ip_vs_sync_lock);
+		if (ip_vs_sync_state & IP_VS_STATE_MASTER)
+			list_add_tail(&curr_sb->list, &ip_vs_sync_queue);
+		else
+			ip_vs_sync_buff_release(curr_sb);
+		spin_unlock_bh(&ip_vs_sync_lock);
+	}
+	spin_unlock_bh(&curr_sb_lock);
+}
+
+/*
+ * Create a new sync buffer for Version 0 proto.
+ */
+static inline struct ip_vs_sync_buff * ip_vs_sync_buff_create_v0(void)
+{
+	struct ip_vs_sync_buff *sb;
+	struct ip_vs_sync_mesg_v0 *mesg;
+
+	if (!(sb=kmalloc(sizeof(struct ip_vs_sync_buff), GFP_ATOMIC)))
+		return NULL;
+
+	if (!(sb->mesg=kmalloc(sync_send_mesg_maxlen, GFP_ATOMIC))) {
+		kfree(sb);
+		return NULL;
+	}
+	mesg = (struct ip_vs_sync_mesg_v0 *)sb->mesg;
+	mesg->nr_conns = 0;
+	mesg->syncid = ip_vs_master_syncid;
+	mesg->size = 4;
+	sb->head = (unsigned char *)mesg + 4;
+	sb->end = (unsigned char *)mesg + sync_send_mesg_maxlen;
+	sb->firstuse = jiffies;
+	return sb;
+}
+
+/*
+ *      Version 0 , could be switched in by sys_ctl.
+ *      Add an ip_vs_conn information into the current sync_buff.
+ */
+void ip_vs_sync_conn_v0(struct ip_vs_conn *cp)
+{
+	struct ip_vs_sync_mesg_v0 *m;
+	struct ip_vs_sync_conn_v0 *s;
+	int len;
+
+	if (unlikely(cp->af != AF_INET))
+		return;
+	/* Do not sync ONE PACKET */
+	if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
+		return;
+
+	spin_lock(&curr_sb_lock);
+	if (!curr_sb) {
+		if (!(curr_sb=ip_vs_sync_buff_create_v0())) {
+			spin_unlock(&curr_sb_lock);
+			pr_err("ip_vs_sync_buff_create failed.\n");
+			return;
+		}
+	}
+
+	len = (cp->flags & IP_VS_CONN_F_SEQ_MASK) ? FULL_CONN_SIZE :
+		SIMPLE_CONN_SIZE;
+	m = (struct ip_vs_sync_mesg_v0 *)curr_sb->mesg;
+	s = (struct ip_vs_sync_conn_v0 *)curr_sb->head;
+
+	/* copy members */
+	s->reserved = 0;
+	s->protocol = cp->protocol;
+	s->cport = cp->cport;
+	s->vport = cp->vport;
+	s->dport = cp->dport;
+	s->caddr = cp->caddr.ip;
+	s->vaddr = cp->vaddr.ip;
+	s->daddr = cp->daddr.ip;
+	s->flags = htons(cp->flags & ~IP_VS_CONN_F_HASHED);
+	s->state = htons(cp->state);
+	if (cp->flags & IP_VS_CONN_F_SEQ_MASK) {
+		struct ip_vs_sync_conn_options *opt =
+			(struct ip_vs_sync_conn_options *)&s[1];
+		memcpy(opt, &cp->in_seq, sizeof(*opt));
+	}
+
+	m->nr_conns++;
+	m->size += len;
+	curr_sb->head += len;
+
+	/* check if there is a space for next one */
+	if (curr_sb->head + FULL_CONN_SIZE > curr_sb->end) {
+		sb_queue_tail(curr_sb);
+		curr_sb = NULL;
+	}
+	spin_unlock(&curr_sb_lock);
+
+	/* synchronize its controller if it has */
+	if (cp->control)
+		ip_vs_sync_conn(cp->control);
+}
+
+/*
  *      Add an ip_vs_conn information into the current sync_buff.
  *      Called by ip_vs_in.
  *      Sending Version 1 messages
@@ -403,6 +532,11 @@ void ip_vs_sync_conn(struct ip_vs_conn *cp)
 	__u8 *p;
 	unsigned int len, pe_name_len, pad;
 
+	/* Handle old version of the protocol */
+	if (sysctl_ip_vs_sync_ver == 0) {
+		ip_vs_sync_conn_v0(cp);
+		return;
+	}
 	/* Do not sync ONE PACKET */
 	if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
 		goto control;
-- 
1.7.2.3


  parent reply	other threads:[~2011-01-19 19:15 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-19 19:14 [PATCH 00/79] netfilter: netfilter update kaber
2011-01-19 19:14 ` [PATCH 01/79] netfilter: nf_conntrack: don't always initialize ct->proto kaber
2011-01-19 19:14 ` [PATCH 02/79] netfilter: xt_NFQUEUE: remove modulo operations kaber
2011-01-19 19:14 ` [PATCH 03/79] netfilter: xt_LOG: do print MAC header on FORWARD kaber
2011-01-19 19:14 ` [PATCH 04/79] netfilter: ct_extend: fix the wrong alloc_size kaber
2011-01-19 19:14 ` [PATCH 05/79] netfilter: nf_conntrack: define ct_*_info as needed kaber
2011-01-19 19:14 ` [PATCH 06/79] netfilter: nf_nat: don't use atomic bit operation kaber
2011-01-19 19:14 ` [PATCH 07/79] netfilter: ct_extend: define NF_CT_EXT_* as needed kaber
2011-01-19 19:14 ` [PATCH 08/79] netfilter: nf_nat: define nat_pptp_info " kaber
2011-01-19 19:14 ` [PATCH 09/79] netfilter: xt_CLASSIFY: add ARP support, allow CLASSIFY target on any table kaber
2011-01-19 19:14 ` [PATCH 10/79] netfilter: add __rcu annotations kaber
2011-01-19 19:14 ` [PATCH 11/79] netfilter: nf_ct_frag6_sysctl_table is static kaber
2011-01-19 19:14 ` [PATCH 12/79] netfilter: add __rcu annotations kaber
2011-01-19 19:14 ` [PATCH 13/79] netfilter: nf_nat_amanda: rename a variable kaber
2011-01-19 19:14 ` [PATCH 14/79] netfilter: rcu sparse cleanups kaber
2011-01-19 19:14 ` [PATCH 15/79] IPVS: Add persistence engine to connection entry kaber
2011-01-19 19:14 ` [PATCH 16/79] IPVS: Only match pe_data created by the same pe kaber
2011-01-19 19:14 ` [PATCH 17/79] IPVS: Make the cp argument to ip_vs_sync_conn() static kaber
2011-01-19 19:14 ` [PATCH 18/79] IPVS: Remove useless { } block from ip_vs_process_message() kaber
2011-01-19 19:40   ` Joe Perches
2011-01-25  2:10     ` Simon Horman
2011-01-25  5:16       ` Simon Horman
2011-01-19 19:14 ` [PATCH 19/79] IPVS: buffer argument to ip_vs_process_message() should not be const kaber
2011-01-19 19:14 ` [PATCH 20/79] ipvs: add static and read_mostly attributes kaber
2011-01-19 19:14 ` [PATCH 21/79] ipvs: remove shadow rt variable kaber
2011-01-19 19:14 ` [PATCH 22/79] ipvs: allow transmit of GRO aggregated skbs kaber
2011-01-19 19:14 ` [PATCH 23/79] netfilter: nf_conntrack: one less atomic op in nf_ct_expect_insert() kaber
2011-01-19 19:14 ` [PATCH 24/79] IPVS: Backup, Prepare for transferring firewall marks (fwmark) to the backup daemon kaber
2011-01-19 19:14 ` [PATCH 25/79] IPVS: Split ports[2] into src_port and dst_port kaber
2011-01-19 19:14 ` [PATCH 26/79] IPVS: skb defrag in L7 helpers kaber
2011-01-19 19:14 ` [PATCH 27/79] IPVS: Handle Scheduling errors kaber
2011-01-19 19:14 ` [PATCH 28/79] IPVS: Backup, Adding structs for new sync format kaber
2011-01-19 19:14 ` [PATCH 29/79] IPVS: Backup, Adding Version 1 receive capability kaber
2011-01-19 19:14 ` [PATCH 30/79] IPVS: Backup, Change sending to Version 1 format kaber
2011-01-19 19:14 ` kaber [this message]
2011-01-19 19:14 ` [PATCH 32/79] netfilter: xtables: use guarded types kaber
2011-01-19 19:14 ` [PATCH 33/79] netfilter: fix compilation when conntrack is disabled but tproxy is enabled kaber
2011-01-19 19:14 ` [PATCH 34/79] IPVS: netns, add basic init per netns kaber
2011-01-19 19:14 ` [PATCH 35/79] IPVS: netns to services part 1 kaber
2011-01-19 19:14 ` [PATCH 36/79] IPVS: netns awarness to lblcr sheduler kaber
2011-01-19 19:14 ` [PATCH 37/79] IPVS: netns awarness to lblc sheduler kaber
2011-01-19 19:14 ` [PATCH 38/79] IPVS: netns, prepare protocol kaber
2011-01-19 19:14 ` [PATCH 39/79] IPVS: netns preparation for proto_tcp kaber
2011-01-19 19:14 ` [PATCH 40/79] IPVS: netns preparation for proto_udp kaber
2011-01-19 19:14 ` [PATCH 41/79] IPVS: netns preparation for proto_sctp kaber
2011-01-19 19:14 ` [PATCH 42/79] IPVS: netns preparation for proto_ah_esp kaber
2011-01-19 19:14 ` [PATCH 43/79] IPVS: netns, use ip_vs_proto_data as param kaber
2011-01-19 19:14 ` [PATCH 44/79] IPVS: netns, common protocol changes and use of appcnt kaber
2011-01-19 19:14 ` [PATCH 45/79] IPVS: netns awareness to ip_vs_app kaber
2011-01-19 19:14 ` [PATCH 46/79] IPVS: netns awareness to ip_vs_est kaber
2011-01-19 19:14 ` [PATCH 47/79] IPVS: netns awareness to ip_vs_sync kaber
2011-01-19 19:14 ` [PATCH 48/79] IPVS: netns, ip_vs_stats and its procfs kaber
2011-01-19 19:14 ` [PATCH 49/79] IPVS: netns, connection hash got net as param kaber
2011-01-19 19:14 ` [PATCH 50/79] IPVS: netns, ip_vs_ctl local vars moved to ipvs struct kaber
2011-01-19 19:14 ` [PATCH 51/79] IPVS: netns, defense work timer kaber
2011-01-19 19:14 ` [PATCH 52/79] IPVS: netns, trash handling kaber
2011-01-19 19:14 ` [PATCH 53/79] IPVS: netns, svc counters moved in ip_vs_ctl,c kaber
2011-01-19 19:14 ` [PATCH 54/79] IPVS: netns, misc init_net removal in core kaber
2011-01-19 19:14 ` [PATCH 55/79] IPVS: netns, final patch enabling network name space kaber
2011-01-19 19:14 ` [PATCH 56/79] netfilter: xt_comment: drop unneeded unsigned qualifier kaber
2011-01-19 19:14 ` [PATCH 57/79] netfilter: xt_conntrack: support matching on port ranges kaber
2011-01-19 19:14 ` [PATCH 58/79] netfilter: x_table: speedup compat operations kaber
2011-01-19 19:14 ` [PATCH 59/79] netfilter: ebt_ip6: allow matching on ipv6-icmp types/codes kaber
2011-01-19 19:15 ` [PATCH 60/79] netfilter: fix Kconfig dependencies kaber
2011-01-19 19:15 ` [PATCH 61/79] netfilter: nf_conntrack: use is_vmalloc_addr() kaber
2011-01-19 19:15 ` [PATCH 62/79] netfilter: audit target to record accepted/dropped packets kaber
2011-01-19 19:15 ` [PATCH 63/79] netfilter: create audit records for x_tables replaces kaber
2011-01-19 19:15 ` [PATCH 64/79] netfilter: xtables: add missing aliases for autoloading via iptables kaber
2011-01-19 19:15 ` [PATCH 65/79] audit: export symbol for use with xt_AUDIT kaber
2011-01-19 19:15 ` [PATCH 66/79] netfilter: xt_connlimit: use hotdrop jump mark kaber
2011-01-19 19:15 ` [PATCH 67/79] netfilter: xtables: use __uXX guarded types for userspace exports kaber
2011-01-19 19:15 ` [PATCH 68/79] netfilter: xtables: add missing header files to export list kaber
2011-01-19 19:15 ` [PATCH 69/79] netfilter: nf_nat: fix conversion to non-atomic bit ops kaber
2011-01-19 19:15 ` [PATCH 70/79] netfilter: nf_conntrack: remove an atomic bit operation kaber
2011-01-19 19:15 ` [PATCH 71/79] netfilter: Kconfig: NFQUEUE is useless without NETFILTER_NETLINK_QUEUE kaber
2011-01-19 19:15 ` [PATCH 72/79] netfilter: nfnetlink_queue: return error number to caller kaber
2011-01-19 19:15 ` [PATCH 73/79] netfilter: nfnetlink_queue: do not free skb on error kaber
2011-01-19 19:15 ` [PATCH 74/79] netfilter: reduce NF_VERDICT_MASK to 0xff kaber
2011-01-19 19:15 ` [PATCH 75/79] netfilter: allow NFQUEUE bypass if no listener is available kaber
2011-01-19 19:15 ` [PATCH 76/79] netfilter: ipt_CLUSTERIP: remove "no conntrack!" kaber
2011-01-19 19:15 ` [PATCH 77/79] netfilter: nf_conntrack: nf_conntrack snmp helper kaber
2011-01-19 19:15 ` [PATCH 78/79] netfilter: nf_conntrack_tstamp: add flow-based timestamp extension kaber
2011-01-19 19:15 ` [PATCH 79/79] netfilter: nf_conntrack: fix lifetime display for disabled connections kaber
2011-01-19 21:55 ` [PATCH 00/79] netfilter: netfilter update David Miller
2011-01-20  0:50   ` David Miller
2011-01-20  0:59     ` Jan Engelhardt
2011-01-20  1:13     ` Patrick McHardy
2011-01-20  1:36       ` Jan Engelhardt
2011-01-20  7:49         ` Patrick McHardy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1295464519-21763-32-git-send-email-kaber@trash.net \
    --to=kaber@trash.net \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.