Skip to contentSkip to conversation

IPVS: Backup, Change sending to Version 1 format

PATCH Superseded Hans Schillstrom 3 participants 4 messages Oct 29, 2010 – Oct 31, 2010

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 4/4 IPVS: Backup, Change sending to Version 1 format

Enable sending and removal of version 0 sending
Affected functions,

ip_vs_sync_buff_create()
ip_vs_sync_conn()

ip_vs_core.c removal of IPv4 check.

---
 net/netfilter/ipvs/ip_vs_core.c |    5 +-
 net/netfilter/ipvs/ip_vs_sync.c |  139 +++++++++++++++++++++++++++++----------
 2 files changed, 107 insertions(+), 37 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +2 -3
index e2bb3cd..9c68045 100644
@@ -1537,7 +1537,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
 	 * encorage the standby servers to update the connections timeout
 	 */
 	pkts = atomic_add_return(1, &cp->in_pkts);
-	if (af == AF_INET && (ip_vs_sync_state & IP_VS_STATE_MASTER) &&
+	if ((ip_vs_sync_state & IP_VS_STATE_MASTER) &&
 	    cp->protocol == IPPROTO_SCTP) {
 		if ((cp->state == IP_VS_SCTP_S_ESTABLISHED &&
 			(pkts % sysctl_ip_vs_sync_threshold[1]
@@ -1552,8 +1552,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
 	}
 
 	/* Keep this block last: TCP and others with pp->num_states <= 1 */
-	else if (af == AF_INET &&
-	    (ip_vs_sync_state & IP_VS_STATE_MASTER) &&
+	else if ((ip_vs_sync_state & IP_VS_STATE_MASTER) &&
 	    (((cp->protocol != IPPROTO_TCP ||
 	       cp->state == IP_VS_TCP_S_ESTABLISHED) &&
 	      (pkts % sysctl_ip_vs_sync_threshold[1]
net/netfilter/ipvs/ip_vs_sync.c +105 -34

188 lines not on this page · raw message

Signature · 1 line
1.7.0.1
maintainer
#1 lore raw
Quoted 9 lines · Hans Schillstrom

Enable sending and removal of version 0 sending
Affected functions,

ip_vs_sync_buff_create()
ip_vs_sync_conn()

ip_vs_core.c removal of IPv4 check.

[ snip ]

Quoted 4 lines
net/netfilter/ipvs/ip_vs_sync.c +0 -0
index 5aa8e04..00f0fd3 100644

[ snip ]

Quoted 60 lines
net/netfilter/ipvs/ip_vs_sync.c +27 -24
@@ -376,36 +420,63 @@ void ip_vs_sync_conn(struct ip_vs_conn *cp)
 		}
 	}
 
-	len = (cp->flags & IP_VS_CONN_F_SEQ_MASK) ? FULL_CONN_SIZE :
-		SIMPLE_CONN_SIZE;
+
 	m = curr_sb->mesg;
-	s = (struct ip_vs_sync_conn_v0 *)curr_sb->head;
+	s = (union ip_vs_sync_conn *)curr_sb->head;
+	p = (char *)s;
 
+	/* Set message type */
+	s->v4.type = (cp->af == AF_INET6 ? STYPE_INET6 : 0 );
 	/* copy members */
-	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));
-	}
-
+	s->v4.ver_size = htons(len & SVER_MASK);	/* Version=0 */
+	s->v4.flags = htonl(cp->flags & ~IP_VS_CONN_F_HASHED);
+	s->v4.state = htons(cp->state);
+	s->v4.protocol = cp->protocol;
+	s->v4.cport = cp->cport;
+	s->v4.vport = cp->vport;
+	s->v4.dport = cp->dport;
+	s->v4.fwmark = htonl(cp->fwmark);
+	s->v4.timeout = htonl(cp->timeout / HZ);
 	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;
+#ifdef CONFIG_IP_VS_IPV6
+	if (cp->af == AF_INET6 ) {
+		p += sizeof(struct ip_vs_sync_v6);
+		ipv6_addr_copy(&s->v6.caddr, &cp->caddr.in6);
+		ipv6_addr_copy(&s->v6.vaddr, &cp->vaddr.in6);
+		ipv6_addr_copy(&s->v6.daddr, &cp->daddr.in6);
+	} else
+#endif
+	{
+		p += sizeof(struct ip_vs_sync_v4);	/* options ptr */
+		s->v4.caddr = cp->caddr.ip;
+		s->v4.vaddr = cp->vaddr.ip;
+		s->v4.daddr = cp->daddr.ip;

net/netfilter/ipvs/ip_vs_sync.c void ip_vs_sync_conn(struct ip_vs_conn *cp) · line 464

Quoted 10 lines
net/netfilter/ipvs/ip_vs_sync.c +9 -0
+	}
+	if (cp->flags & IP_VS_CONN_F_SEQ_MASK) {
+		*(p++) = IPVS_OPT_SEQ_DATA;
+		*(p++) = sizeof(struct ip_vs_sync_conn_options);
+		memcpy(p, &cp->in_seq,
+			       sizeof(struct ip_vs_sync_conn_options));
+			p += sizeof(struct ip_vs_sync_conn_options);
 	}
+	/* Handle pe data */
+	if (cp->pe_data_len && cp->pe_data) {

I don't think that its possible for pe_data_len to be non-zero and pe_data be NULL and vice-versa.

Quoted 18 lines
net/netfilter/ipvs/ip_vs_sync.c +15 -0
+		*(p++) = IPVS_OPT_PE_DATA;
+		*(p++) = cp->pe_data_len;
+		memcpy(p, cp->pe_data,cp->pe_data_len);
+		p += cp->pe_data_len;
+		if (pe_name_len) {
+			/* Add PE_NAME */
+			*(p++) = IPVS_OPT_PE_NAME;
+			*(p++) = pe_name_len;
+			memcpy(p, cp->dest->svc->pe->name, pe_name_len);
+			p[pe_name_len-1] = 0; /* Make sure \0 is there */
+		}
+	}
+        m->size += len;
+        curr_sb->head += len;
+
 	spin_unlock(&curr_sb_lock);
 
 	/* synchronize its controller if it has */

[ snip ]

#2 lore raw
Quoted 85 lines · On Saturday, October 30, 2010 08:50:31 Simon Horman wrote:
Quoted 9 lines · Hans Schillstrom

Enable sending and removal of version 0 sending
Affected functions,

ip_vs_sync_buff_create()
ip_vs_sync_conn()

ip_vs_core.c removal of IPv4 check.

[ snip ]

Quoted 4 lines
net/netfilter/ipvs/ip_vs_sync.c +0 -0
index 5aa8e04..00f0fd3 100644

[ snip ]

Quoted 65 lines
net/netfilter/ipvs/ip_vs_sync.c +32 -24
@@ -376,36 +420,63 @@ void ip_vs_sync_conn(struct ip_vs_conn *cp)
 		}
 	}
 
-	len = (cp->flags & IP_VS_CONN_F_SEQ_MASK) ? FULL_CONN_SIZE :
-		SIMPLE_CONN_SIZE;
+
 	m = curr_sb->mesg;
-	s = (struct ip_vs_sync_conn_v0 *)curr_sb->head;
+	s = (union ip_vs_sync_conn *)curr_sb->head;
+	p = (char *)s;
 
+	/* Set message type */
+	s->v4.type = (cp->af == AF_INET6 ? STYPE_INET6 : 0 );
 	/* copy members */
-	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));
-	}
-
+	s->v4.ver_size = htons(len & SVER_MASK);	/* Version=0 */
+	s->v4.flags = htonl(cp->flags & ~IP_VS_CONN_F_HASHED);
+	s->v4.state = htons(cp->state);
+	s->v4.protocol = cp->protocol;
+	s->v4.cport = cp->cport;
+	s->v4.vport = cp->vport;
+	s->v4.dport = cp->dport;
+	s->v4.fwmark = htonl(cp->fwmark);
+	s->v4.timeout = htonl(cp->timeout / HZ);
 	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;
+#ifdef CONFIG_IP_VS_IPV6
+	if (cp->af == AF_INET6 ) {
+		p += sizeof(struct ip_vs_sync_v6);
+		ipv6_addr_copy(&s->v6.caddr, &cp->caddr.in6);
+		ipv6_addr_copy(&s->v6.vaddr, &cp->vaddr.in6);
+		ipv6_addr_copy(&s->v6.daddr, &cp->daddr.in6);
+	} else
+#endif
+	{
+		p += sizeof(struct ip_vs_sync_v4);	/* options ptr */
+		s->v4.caddr = cp->caddr.ip;
+		s->v4.vaddr = cp->vaddr.ip;
+		s->v4.daddr = cp->daddr.ip;
+	}
+	if (cp->flags & IP_VS_CONN_F_SEQ_MASK) {
+		*(p++) = IPVS_OPT_SEQ_DATA;
+		*(p++) = sizeof(struct ip_vs_sync_conn_options);
+		memcpy(p, &cp->in_seq,
Quoted 8 lines

net/netfilter/ipvs/ip_vs_sync.c void ip_vs_sync_conn(struct ip_vs_conn *cp) · line 464

Quoted 5 lines
net/netfilter/ipvs/ip_vs_sync.c +4 -0
+			       sizeof(struct ip_vs_sync_conn_options));
+			p += sizeof(struct ip_vs_sync_conn_options);
 	}
+	/* Handle pe data */
+	if (cp->pe_data_len && cp->pe_data) {

I don't think that its possible for pe_data_len to be non-zero and pe_data be NULL and vice-versa.

I prefer to avoid a NULL pointer exception :-)
but if you are 100% sure that that I can remove the "&& cp->pe_data", I do that

Quoted 21 lines
Quoted 19 lines
net/netfilter/ipvs/ip_vs_sync.c +15 -0
+		*(p++) = IPVS_OPT_PE_DATA;
+		*(p++) = cp->pe_data_len;
+		memcpy(p, cp->pe_data,cp->pe_data_len);
+		p += cp->pe_data_len;
+		if (pe_name_len) {
+			/* Add PE_NAME */
+			*(p++) = IPVS_OPT_PE_NAME;
+			*(p++) = pe_name_len;
+			memcpy(p, cp->dest->svc->pe->name, pe_name_len);
+			p[pe_name_len-1] = 0; /* Make sure \0 is there */
+		}
+	}
+        m->size += len;
+        curr_sb->head += len;
+
 	spin_unlock(&curr_sb_lock);
 
 	/* synchronize its controller if it has */

[ snip ]

maintainer
#3 lore raw
Quoted 96 lines · Hans Schillstrom
Quoted 85 lines · On Saturday, October 30, 2010 08:50:31 Simon Horman wrote:
Quoted 9 lines · Hans Schillstrom

Enable sending and removal of version 0 sending
Affected functions,

ip_vs_sync_buff_create()
ip_vs_sync_conn()

ip_vs_core.c removal of IPv4 check.

[ snip ]

Quoted 4 lines
net/netfilter/ipvs/ip_vs_sync.c +0 -0
index 5aa8e04..00f0fd3 100644

[ snip ]

Quoted 65 lines
net/netfilter/ipvs/ip_vs_sync.c +32 -24
@@ -376,36 +420,63 @@ void ip_vs_sync_conn(struct ip_vs_conn *cp)
 		}
 	}
 
-	len = (cp->flags & IP_VS_CONN_F_SEQ_MASK) ? FULL_CONN_SIZE :
-		SIMPLE_CONN_SIZE;
+
 	m = curr_sb->mesg;
-	s = (struct ip_vs_sync_conn_v0 *)curr_sb->head;
+	s = (union ip_vs_sync_conn *)curr_sb->head;
+	p = (char *)s;
 
+	/* Set message type */
+	s->v4.type = (cp->af == AF_INET6 ? STYPE_INET6 : 0 );
 	/* copy members */
-	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));
-	}
-
+	s->v4.ver_size = htons(len & SVER_MASK);	/* Version=0 */
+	s->v4.flags = htonl(cp->flags & ~IP_VS_CONN_F_HASHED);
+	s->v4.state = htons(cp->state);
+	s->v4.protocol = cp->protocol;
+	s->v4.cport = cp->cport;
+	s->v4.vport = cp->vport;
+	s->v4.dport = cp->dport;
+	s->v4.fwmark = htonl(cp->fwmark);
+	s->v4.timeout = htonl(cp->timeout / HZ);
 	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;
+#ifdef CONFIG_IP_VS_IPV6
+	if (cp->af == AF_INET6 ) {
+		p += sizeof(struct ip_vs_sync_v6);
+		ipv6_addr_copy(&s->v6.caddr, &cp->caddr.in6);
+		ipv6_addr_copy(&s->v6.vaddr, &cp->vaddr.in6);
+		ipv6_addr_copy(&s->v6.daddr, &cp->daddr.in6);
+	} else
+#endif
+	{
+		p += sizeof(struct ip_vs_sync_v4);	/* options ptr */
+		s->v4.caddr = cp->caddr.ip;
+		s->v4.vaddr = cp->vaddr.ip;
+		s->v4.daddr = cp->daddr.ip;
+	}
+	if (cp->flags & IP_VS_CONN_F_SEQ_MASK) {
+		*(p++) = IPVS_OPT_SEQ_DATA;
+		*(p++) = sizeof(struct ip_vs_sync_conn_options);
+		memcpy(p, &cp->in_seq,
Quoted 8 lines

net/netfilter/ipvs/ip_vs_sync.c void ip_vs_sync_conn(struct ip_vs_conn *cp) · line 464

Quoted 5 lines
net/netfilter/ipvs/ip_vs_sync.c +4 -0
+			       sizeof(struct ip_vs_sync_conn_options));
+			p += sizeof(struct ip_vs_sync_conn_options);
 	}
+	/* Handle pe data */
+	if (cp->pe_data_len && cp->pe_data) {

I don't think that its possible for pe_data_len to be non-zero and pe_data be NULL and vice-versa.

Quoted 2 lines

I prefer to avoid a NULL pointer exception :-)
but if you are 100% sure that that I can remove the "&& cp->pe_data", I do that

I am 99.9% sure. You call :-)