Skip to contentSkip to conversation

ipvs: Fix reuse connection if real server is dead

PATCH In review Grzegorz Lyczba 5 participants 12 messages May 7, 2013 – May 14, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipvs: Fix reuse connection if real server is dead

Expire cached connection for new TCP connection if real server is down

---
 net/netfilter/ipvs/ip_vs_core.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +20 -0
index 47edf5a..7c5f083 100644
@@ -1002,6 +1002,17 @@ static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len)
 	return th->rst;
 }
 
+static inline int is_tcp_syn(const struct sk_buff *skb, int nh_len)
+{
+    struct tcphdr _tcph, *th;
+
+    th = skb_header_pointer(skb, nh_len, sizeof(_tcph), &_tcph);
+    if (th == NULL)
+        return 0;
+    return th->syn;
+}
+
+
 /* Handle response packets: rewrite addresses and send away...
  */
 static unsigned int
@@ -1627,6 +1638,15 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
 	 * Check if the packet belongs to an existing connection entry
 	 */
 	cp = pp->conn_in_get(af, skb, &iph, 0);
+
+	if (likely(cp) && likely(cp->dest) &&
+	    unlikely(!atomic_read(&cp->dest->weight)) &&
+	    iph.protocol == IPPROTO_TCP && is_tcp_syn(skb, iph.len)) {
+		ip_vs_conn_expire_now(cp);
+		__ip_vs_conn_put(cp);
+		cp = NULL;
+	}
+
 	if (unlikely(!cp) && !iph.fragoffs) {
 		/* No (second) fragments need to enter here, as nf_defrag_ipv6
 		 * replayed fragment zero will already have created the cp
Signature · 1 line
1.7.5.4
#1 lore raw

Hello

Quoted 1 line · Grzegorz Lyczba

Expire cached connection for new TCP connection if real server is down

This patch will break some "common" use cases,
on the other hand it also solves some issues...

I would prefer to have a sysctl to turn it on.

Should we have something similar for sctp?

Regards
Hans

Quoted 43 lines
---
 net/netfilter/ipvs/ip_vs_core.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +20 -0
index 47edf5a..7c5f083 100644
@@ -1002,6 +1002,17 @@ static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len)
 	return th->rst;
 }
 
+static inline int is_tcp_syn(const struct sk_buff *skb, int nh_len)
+{
+    struct tcphdr _tcph, *th;
+
+    th = skb_header_pointer(skb, nh_len, sizeof(_tcph), &_tcph);
+    if (th == NULL)
+        return 0;
+    return th->syn;
+}
+
+
 /* Handle response packets: rewrite addresses and send away...
  */
 static unsigned int
@@ -1627,6 +1638,15 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
 	 * Check if the packet belongs to an existing connection entry
 	 */
 	cp = pp->conn_in_get(af, skb, &iph, 0);
+
+	if (likely(cp) && likely(cp->dest) &&
+	    unlikely(!atomic_read(&cp->dest->weight)) &&
+	    iph.protocol == IPPROTO_TCP && is_tcp_syn(skb, iph.len)) {
+		ip_vs_conn_expire_now(cp);
+		__ip_vs_conn_put(cp);
+		cp = NULL;
+	}
+
 	if (unlikely(!cp) && !iph.fragoffs) {
 		/* No (second) fragments need to enter here, as nf_defrag_ipv6
 		 * replayed fragment zero will already have created the cp
maintainer
#2 lore raw
In reply to Grzegorz Lyczba

Hello,

Quoted 12 lines · Grzegorz Lyczba

Expire cached connection for new TCP connection if real server is down

---
 net/netfilter/ipvs/ip_vs_core.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +0 -0
index 47edf5a..7c5f083 100644

net/netfilter/ipvs/ip_vs_core.c static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len) · line 1009

Quoted 8 lines
net/netfilter/ipvs/ip_vs_core.c +5 -0
@@ -1002,6 +1002,17 @@ static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len)
 	return th->rst;
 }
 
+static inline int is_tcp_syn(const struct sk_buff *skb, int nh_len)
+{
+    struct tcphdr _tcph, *th;
+
+    th = skb_header_pointer(skb, nh_len, sizeof(_tcph), &_tcph);

As Hans notes, it is a good idea to support SCTP by
using the iph address as second argument. May be the func can be named is_new_conn:

static inline bool is_new_conn(const struct sk_buff *skb,
struct ip_vs_iphdr *iph)
...

Quoted 10 lines
net/netfilter/ipvs/ip_vs_core.c +6 -0
+    if (th == NULL)
+        return 0;
+    return th->syn;
+}
+
+
 /* Handle response packets: rewrite addresses and send away...
  */
 static unsigned int

net/netfilter/ipvs/ip_vs_core.c ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af) · line 1642

Quoted 5 lines
net/netfilter/ipvs/ip_vs_core.c +2 -0
@@ -1627,6 +1638,15 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
 	 * Check if the packet belongs to an existing connection entry
 	 */
 	cp = pp->conn_in_get(af, skb, &iph, 0);
+
+	if (likely(cp) && likely(cp->dest) &&
	I hope it is appropriate to use the expire_nodest_conn flag:

	if (unlikely(sysctl_expire_nodest_conn(ipvs) && cp && cp->dest &&

...

net/netfilter/ipvs/ip_vs_core.c ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af) · line 1643

Quoted 1 line
net/netfilter/ipvs/ip_vs_core.c +1 -0
+	    unlikely(!atomic_read(&cp->dest->weight)) &&
	We should add '!iph.fragoffs &&' here.

net/netfilter/ipvs/ip_vs_core.c ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af) · line 1652

Quoted 9 lines
net/netfilter/ipvs/ip_vs_core.c +6 -0
+	    iph.protocol == IPPROTO_TCP && is_tcp_syn(skb, iph.len)) {
+		ip_vs_conn_expire_now(cp);
+		__ip_vs_conn_put(cp);
+		cp = NULL;
+	}
+
 	if (unlikely(!cp) && !iph.fragoffs) {
 		/* No (second) fragments need to enter here, as nf_defrag_ipv6
 		 * replayed fragment zero will already have created the cp

Regards

--
Julian Anastasov <[email protected]>

#3 lore raw
Quoted 52 lines · Julian Anastasov

Hello,

Quoted 12 lines · Grzegorz Lyczba

Expire cached connection for new TCP connection if real server is down

---
 net/netfilter/ipvs/ip_vs_core.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +0 -0
index 47edf5a..7c5f083 100644

net/netfilter/ipvs/ip_vs_core.c static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len) · line 1009

Quoted 8 lines
net/netfilter/ipvs/ip_vs_core.c +5 -0
@@ -1002,6 +1002,17 @@ static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len)
 	return th->rst;
 }
 
+static inline int is_tcp_syn(const struct sk_buff *skb, int nh_len)
+{
+    struct tcphdr _tcph, *th;
+
+    th = skb_header_pointer(skb, nh_len, sizeof(_tcph), &_tcph);

As Hans notes, it is a good idea to support SCTP by
using the iph address as second argument. May be the func can be named is_new_conn:

static inline bool is_new_conn(const struct sk_buff *skb,
struct ip_vs_iphdr *iph)
...

Quoted 10 lines
net/netfilter/ipvs/ip_vs_core.c +6 -0
+    if (th == NULL)
+        return 0;
+    return th->syn;
+}
+
+
 /* Handle response packets: rewrite addresses and send away...
  */
 static unsigned int

net/netfilter/ipvs/ip_vs_core.c ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af) · line 1642

Quoted 5 lines
net/netfilter/ipvs/ip_vs_core.c +2 -0
@@ -1627,6 +1638,15 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
 	 * Check if the packet belongs to an existing connection entry
 	 */
 	cp = pp->conn_in_get(af, skb, &iph, 0);
+
+	if (likely(cp) && likely(cp->dest) &&
	I hope it is appropriate to use the expire_nodest_conn flag:

	if (unlikely(sysctl_expire_nodest_conn(ipvs) && cp && cp->dest &&
Quoted 5 lines

...

net/netfilter/ipvs/ip_vs_core.c ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af) · line 1643

Quoted 1 line
net/netfilter/ipvs/ip_vs_core.c +1 -0
+	    unlikely(!atomic_read(&cp->dest->weight)) &&
	We should add '!iph.fragoffs &&' here.

Do we really need that?
I don't think a SYN can be fragmented.

Regards
Hans

Quoted 19 lines

net/netfilter/ipvs/ip_vs_core.c ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af) · line 1652

Quoted 10 lines
net/netfilter/ipvs/ip_vs_core.c +6 -0
+	    iph.protocol == IPPROTO_TCP && is_tcp_syn(skb, iph.len)) {
+		ip_vs_conn_expire_now(cp);
+		__ip_vs_conn_put(cp);
+		cp = NULL;
+	}
+
 	if (unlikely(!cp) && !iph.fragoffs) {
 		/* No (second) fragments need to enter here, as nf_defrag_ipv6
 		 * replayed fragment zero will already have created the cp

Regards

--
Julian Anastasov <[email protected]>
--
To unsubscribe from this list: send the line "unsubscribe lvs-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#4 lore raw

Hello,

Quoted 6 lines · Hans Schillstrom
Quoted 3 lines

net/netfilter/ipvs/ip_vs_core.c ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af) · line 1643

Quoted 1 line
net/netfilter/ipvs/ip_vs_core.c +1 -0
+	    unlikely(!atomic_read(&cp->dest->weight)) &&
	We should add '!iph.fragoffs &&' here.

Do we really need that?
I don't think a SYN can be fragmented.

SYNs are usually not fragmented. But we don't have the
right to search for SYN in a packet without TCP header. It can be data fragment that contains 1 at this bit position, when weight=0 such packets should be forwarded as part of existing connection.

Regards

--
Julian Anastasov <[email protected]>

#5 lore raw
Quoted 8 lines · Julian Anastasov

Hello,

Quoted 4 lines · Hans Schillstrom
Quoted 3 lines

net/netfilter/ipvs/ip_vs_core.c ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af) · line 1643

Quoted 1 line
net/netfilter/ipvs/ip_vs_core.c +1 -0
+	    unlikely(!atomic_read(&cp->dest->weight)) &&
	We should add '!iph.fragoffs &&' here.
Quoted 9 lines
Quoted 2 lines

Do we really need that?
I don't think a SYN can be fragmented.

SYNs are usually not fragmented. But we don't have the
right to search for SYN in a packet without TCP header. It can be data fragment that contains 1 at this bit position, when weight=0 such packets should be forwarded as part of existing connection.

Shame on me, I should really have thought about that... I think I know who invented the iph.fragoffs :-)

Regards
Hans

Quoted 4 lines

Regards

--
Julian Anastasov <[email protected]>

#6 lore raw

PATCH 1/1 ipvs: Fix reuse connection if real server is dead

In reply to Julian Anastasov

From: Grzegorz Lyczba <[email protected]>

Expire cached connection for new TCP/SCTP connection if real server is down

---
 net/netfilter/ipvs/ip_vs_core.c |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +36 -0
index 47edf5a..9ee8b70 100644
@@ -1002,6 +1002,33 @@ static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len)
 	return th->rst;
 }
 
+static inline bool is_new_conn(const struct sk_buff *skb,
+	    struct ip_vs_iphdr *iph)
+{
+	switch (iph->protocol) {
+	case IPPROTO_TCP: {
+		struct tcphdr _tcph, *th;
+		th = skb_header_pointer(skb, iph->len, sizeof(_tcph), &_tcph);
+		if (th == NULL) {
+			return false;
+		}
+		return th->syn;
+	}
+	case IPPROTO_SCTP: {
+		sctp_chunkhdr_t *sch, schunk;
+		sch = skb_header_pointer(skb, iph->len + sizeof(sctp_sctphdr_t),
+				sizeof(schunk), &schunk);
+		if (sch == NULL) {
+			return false;
+		}
+		return (sch->type == SCTP_CID_INIT);
+	}
+	default:
+		return false;
+	}
+}
+
+
 /* Handle response packets: rewrite addresses and send away...
  */
 static unsigned int
@@ -1627,6 +1654,15 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
 	 * Check if the packet belongs to an existing connection entry
 	 */
 	cp = pp->conn_in_get(af, skb, &iph, 0);
+
+	if (unlikely(sysctl_expire_nodest_conn(ipvs)) && cp && cp->dest &&
+	    !iph.fragoffs && unlikely(!atomic_read(&cp->dest->weight)) &&
+	    is_new_conn(skb, &iph)) {
+		ip_vs_conn_expire_now(cp);
+		__ip_vs_conn_put(cp);
+		cp = NULL;
+	}
+
 	if (unlikely(!cp) && !iph.fragoffs) {
 		/* No (second) fragments need to enter here, as nf_defrag_ipv6
 		 * replayed fragment zero will already have created the cp
Signature · 1 line
1.7.5.4
maintainer
#7 lore raw

Hello,

Quoted 5 lines · Grzegorz Łyczba

From: Grzegorz Lyczba <[email protected]>

Expire cached connection for new TCP/SCTP connection if real server is down

The change looks correct but you have to fix some
coding style issues. Otherwise, patch will be rejected. You can also check Documentation/CodingStyle

# scripts/checkpatch.pl /tmp/patch.diff
WARNING: braces {} are not necessary for single statement blocks
#25: FILE: net/netfilter/ipvs/ip_vs_core.c:1012:
+               if (th == NULL) {
+                       return false;
+               }

WARNING: braces {} are not necessary for single statement blocks #34: FILE: net/netfilter/ipvs/ip_vs_core.c:1021:
+ if (sch == NULL) {
+ return false;
+ }

total: 0 errors, 2 warnings, 48 lines checked

Quoted 9 lines
---
 net/netfilter/ipvs/ip_vs_core.c |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +0 -0
index 47edf5a..9ee8b70 100644

net/netfilter/ipvs/ip_vs_core.c static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len) · line 1006

Quoted 5 lines
net/netfilter/ipvs/ip_vs_core.c +2 -0
@@ -1002,6 +1002,33 @@ static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len)
 	return th->rst;
 }
 
+static inline bool is_new_conn(const struct sk_buff *skb,
+	    struct ip_vs_iphdr *iph)

Above "struct" should be at the same column as "const"
in first argument, like this:

static inline bool is_new_conn(const struct sk_buff *skb,
struct ip_vs_iphdr *iph)

net/netfilter/ipvs/ip_vs_core.c static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len) · line 1008

Quoted 2 lines
net/netfilter/ipvs/ip_vs_core.c +2 -0
+{
+	switch (iph->protocol) {
	I'm still not sure if this construct is allowed:

	case ...: {
	}

	May be it should be:

	case ...:
		{
		}
	case ...

	but CodingStyle does not include rules about it.

If in doubt, you can use 'if' instead of 'switch' without adding new indentation.

net/netfilter/ipvs/ip_vs_core.c static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len) · line 1010

Quoted 2 lines
net/netfilter/ipvs/ip_vs_core.c +2 -0
+	case IPPROTO_TCP: {
+		struct tcphdr _tcph, *th;

empty line is needed here

net/netfilter/ipvs/ip_vs_core.c static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len) · line 1013

Quoted 3 lines
net/netfilter/ipvs/ip_vs_core.c +3 -0
+		th = skb_header_pointer(skb, iph->len, sizeof(_tcph), &_tcph);
+		if (th == NULL) {
+			return false;

extra braces

net/netfilter/ipvs/ip_vs_core.c static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len) · line 1018

Quoted 5 lines
net/netfilter/ipvs/ip_vs_core.c +5 -0
+		}
+		return th->syn;
+	}
+	case IPPROTO_SCTP: {
+		sctp_chunkhdr_t *sch, schunk;

empty line is needed here

net/netfilter/ipvs/ip_vs_core.c static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len) · line 1022

Quoted 4 lines
net/netfilter/ipvs/ip_vs_core.c +4 -0
+		sch = skb_header_pointer(skb, iph->len + sizeof(sctp_sctphdr_t),
+				sizeof(schunk), &schunk);
+		if (sch == NULL) {
+			return false;

extra braces

Quoted 13 lines
net/netfilter/ipvs/ip_vs_core.c +9 -0
+		}
+		return (sch->type == SCTP_CID_INIT);
+	}
+	default:
+		return false;
+	}
+}
+
+
 /* Handle response packets: rewrite addresses and send away...
  */
 static unsigned int

net/netfilter/ipvs/ip_vs_core.c ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af) · line 1659

Quoted 6 lines
net/netfilter/ipvs/ip_vs_core.c +3 -0
@@ -1627,6 +1654,15 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
 	 * Check if the packet belongs to an existing connection entry
 	 */
 	cp = pp->conn_in_get(af, skb, &iph, 0);
+
+	if (unlikely(sysctl_expire_nodest_conn(ipvs)) && cp && cp->dest &&
+	    !iph.fragoffs && unlikely(!atomic_read(&cp->dest->weight)) &&

Lets move '!iph.fragoffs' after the
'unlikely(!atomic_read(&cp->dest->weight))' because fragoffs is usually 0. Only IPv6 can see fragments at that point.

Quoted 11 lines
net/netfilter/ipvs/ip_vs_core.c +6 -0
+	    is_new_conn(skb, &iph)) {
+		ip_vs_conn_expire_now(cp);
+		__ip_vs_conn_put(cp);
+		cp = NULL;
+	}
+
 	if (unlikely(!cp) && !iph.fragoffs) {
 		/* No (second) fragments need to enter here, as nf_defrag_ipv6
 		 * replayed fragment zero will already have created the cp
Signature · 1 line
1.7.5.4

Regards

--
Julian Anastasov <[email protected]>

maintainer
#8 lore raw
Quoted 51 lines · Julian Anastasov

Hello,

Quoted 5 lines · Grzegorz Å�yczba

From: Grzegorz Lyczba <[email protected]>

Expire cached connection for new TCP/SCTP connection if real server is down

The change looks correct but you have to fix some
coding style issues. Otherwise, patch will be rejected. You can also check Documentation/CodingStyle

# scripts/checkpatch.pl /tmp/patch.diff
WARNING: braces {} are not necessary for single statement blocks
#25: FILE: net/netfilter/ipvs/ip_vs_core.c:1012:
net/netfilter/ipvs/ip_vs_core.c +3 -0
+               if (th == NULL) {
+                       return false;
+               }

WARNING: braces {} are not necessary for single statement blocks #34: FILE: net/netfilter/ipvs/ip_vs_core.c:1021:

net/netfilter/ipvs/ip_vs_core.c +3 -0
+               if (sch == NULL) {
+                       return false;
+               }

total: 0 errors, 2 warnings, 48 lines checked

Quoted 9 lines
---
 net/netfilter/ipvs/ip_vs_core.c |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +0 -0
index 47edf5a..9ee8b70 100644

net/netfilter/ipvs/ip_vs_core.c static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len) · line 1006

Quoted 5 lines
net/netfilter/ipvs/ip_vs_core.c +2 -0
@@ -1002,6 +1002,33 @@ static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len)
 	return th->rst;
 }
 
+static inline bool is_new_conn(const struct sk_buff *skb,
+	    struct ip_vs_iphdr *iph)

Above "struct" should be at the same column as "const"
in first argument, like this:

static inline bool is_new_conn(const struct sk_buff *skb,
struct ip_vs_iphdr *iph)

Quoted 7 lines

net/netfilter/ipvs/ip_vs_core.c static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len) · line 1008

Quoted 2 lines
net/netfilter/ipvs/ip_vs_core.c +2 -0
+{
+	switch (iph->protocol) {
	I'm still not sure if this construct is allowed:

	case ...: {
	}

I see some evidence of the above style in net/core/ so personally I am fine with it.

Quoted 78 lines
	May be it should be:

	case ...:
		{
		}
	case ...

	but CodingStyle does not include rules about it.

If in doubt, you can use 'if' instead of 'switch' without adding new indentation.

net/netfilter/ipvs/ip_vs_core.c static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len) · line 1010

Quoted 2 lines
net/netfilter/ipvs/ip_vs_core.c +2 -0
+	case IPPROTO_TCP: {
+		struct tcphdr _tcph, *th;

empty line is needed here

net/netfilter/ipvs/ip_vs_core.c static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len) · line 1013

Quoted 3 lines
net/netfilter/ipvs/ip_vs_core.c +3 -0
+		th = skb_header_pointer(skb, iph->len, sizeof(_tcph), &_tcph);
+		if (th == NULL) {
+			return false;

extra braces

net/netfilter/ipvs/ip_vs_core.c static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len) · line 1018

Quoted 5 lines
net/netfilter/ipvs/ip_vs_core.c +5 -0
+		}
+		return th->syn;
+	}
+	case IPPROTO_SCTP: {
+		sctp_chunkhdr_t *sch, schunk;

empty line is needed here

net/netfilter/ipvs/ip_vs_core.c static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len) · line 1022

Quoted 4 lines
net/netfilter/ipvs/ip_vs_core.c +4 -0
+		sch = skb_header_pointer(skb, iph->len + sizeof(sctp_sctphdr_t),
+				sizeof(schunk), &schunk);
+		if (sch == NULL) {
+			return false;

extra braces

Quoted 13 lines
net/netfilter/ipvs/ip_vs_core.c +9 -0
+		}
+		return (sch->type == SCTP_CID_INIT);
+	}
+	default:
+		return false;
+	}
+}
+
+
 /* Handle response packets: rewrite addresses and send away...
  */
 static unsigned int

net/netfilter/ipvs/ip_vs_core.c ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af) · line 1659

Quoted 6 lines
net/netfilter/ipvs/ip_vs_core.c +3 -0
@@ -1627,6 +1654,15 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
 	 * Check if the packet belongs to an existing connection entry
 	 */
 	cp = pp->conn_in_get(af, skb, &iph, 0);
+
+	if (unlikely(sysctl_expire_nodest_conn(ipvs)) && cp && cp->dest &&
+	    !iph.fragoffs && unlikely(!atomic_read(&cp->dest->weight)) &&

Lets move '!iph.fragoffs' after the
'unlikely(!atomic_read(&cp->dest->weight))' because fragoffs is usually 0. Only IPv6 can see fragments at that point.

Quoted 11 lines
net/netfilter/ipvs/ip_vs_core.c +6 -0
+	    is_new_conn(skb, &iph)) {
+		ip_vs_conn_expire_now(cp);
+		__ip_vs_conn_put(cp);
+		cp = NULL;
+	}
+
 	if (unlikely(!cp) && !iph.fragoffs) {
 		/* No (second) fragments need to enter here, as nf_defrag_ipv6
 		 * replayed fragment zero will already have created the cp
Signature · 1 line
1.7.5.4

Regards

--
Julian Anastasov <[email protected]>

#9 lore raw
In reply to Julian Anastasov
Quoted 3 lines · On Sat, 11 May 2013 16:23:33 +0300 (EEST) Julian Anastasov <[email protected]> wrote:

The change looks correct but you have to fix some
coding style issues. Otherwise, patch will be rejected. You can also check Documentation/CodingStyle

Also remember to add a "version" tag to the subject, when you resubmit.

Subject like:
[PATCH v3] ipvs: Fix reuse connection if real server is dead

Signature · 5 lines
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Sr. Network Kernel Developer at Red Hat
  Author of http://www.iptv-analyzer.org
  LinkedIn: http://www.linkedin.com/in/brouer
#10 lore raw

PATCH v3 1/1 ipvs: Fix reuse connection if real server is dead

In reply to Julian Anastasov

From: Grzegorz Lyczba <[email protected]>

Expire cached connection for new TCP/SCTP connection if real server is down

---
 net/netfilter/ipvs/ip_vs_core.c |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +36 -0
index 47edf5a..2e349ca 100644
@@ -1002,6 +1002,33 @@ static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len)
 	return th->rst;
 }
 
+static inline bool is_new_conn(const struct sk_buff *skb,
+			       struct ip_vs_iphdr *iph)
+{
+	switch (iph->protocol) {
+	case IPPROTO_TCP: {
+		struct tcphdr _tcph, *th;
+
+		th = skb_header_pointer(skb, iph->len, sizeof(_tcph), &_tcph);
+		if (th == NULL)
+			return false;
+		return th->syn;
+	}
+	case IPPROTO_SCTP: {
+		sctp_chunkhdr_t *sch, schunk;
+
+		sch = skb_header_pointer(skb, iph->len + sizeof(sctp_sctphdr_t),
+				sizeof(schunk), &schunk);
+		if (sch == NULL)
+			return false;
+		return (sch->type == SCTP_CID_INIT);
+	}
+	default:
+		return false;
+	}
+}
+
+
 /* Handle response packets: rewrite addresses and send away...
  */
 static unsigned int
@@ -1627,6 +1654,15 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
 	 * Check if the packet belongs to an existing connection entry
 	 */
 	cp = pp->conn_in_get(af, skb, &iph, 0);
+
+	if (unlikely(sysctl_expire_nodest_conn(ipvs)) && cp && cp->dest &&
+	    unlikely(!atomic_read(&cp->dest->weight)) && !iph.fragoffs &&
+	    is_new_conn(skb, &iph)) {
+		ip_vs_conn_expire_now(cp);
+		__ip_vs_conn_put(cp);
+		cp = NULL;
+	}
+
 	if (unlikely(!cp) && !iph.fragoffs) {
 		/* No (second) fragments need to enter here, as nf_defrag_ipv6
 		 * replayed fragment zero will already have created the cp
Signature · 1 line
1.7.5.4
maintainer Acked-by on v3 1/1
#11 lore raw

Hello,

Quoted 5 lines · Grzegorz Łyczba

From: Grzegorz Lyczba <[email protected]>

Expire cached connection for new TCP/SCTP connection if real server is down

Looks good to me, thanks!

Quoted 60 lines
---
 net/netfilter/ipvs/ip_vs_core.c |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +36 -0
index 47edf5a..2e349ca 100644
@@ -1002,6 +1002,33 @@ static inline int is_tcp_reset(const struct sk_buff *skb, int nh_len)
 	return th->rst;
 }
 
+static inline bool is_new_conn(const struct sk_buff *skb,
+			       struct ip_vs_iphdr *iph)
+{
+	switch (iph->protocol) {
+	case IPPROTO_TCP: {
+		struct tcphdr _tcph, *th;
+
+		th = skb_header_pointer(skb, iph->len, sizeof(_tcph), &_tcph);
+		if (th == NULL)
+			return false;
+		return th->syn;
+	}
+	case IPPROTO_SCTP: {
+		sctp_chunkhdr_t *sch, schunk;
+
+		sch = skb_header_pointer(skb, iph->len + sizeof(sctp_sctphdr_t),
+				sizeof(schunk), &schunk);
+		if (sch == NULL)
+			return false;
+		return (sch->type == SCTP_CID_INIT);
+	}
+	default:
+		return false;
+	}
+}
+
+
 /* Handle response packets: rewrite addresses and send away...
  */
 static unsigned int
@@ -1627,6 +1654,15 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
 	 * Check if the packet belongs to an existing connection entry
 	 */
 	cp = pp->conn_in_get(af, skb, &iph, 0);
+
+	if (unlikely(sysctl_expire_nodest_conn(ipvs)) && cp && cp->dest &&
+	    unlikely(!atomic_read(&cp->dest->weight)) && !iph.fragoffs &&
+	    is_new_conn(skb, &iph)) {
+		ip_vs_conn_expire_now(cp);
+		__ip_vs_conn_put(cp);
+		cp = NULL;
+	}
+
 	if (unlikely(!cp) && !iph.fragoffs) {
 		/* No (second) fragments need to enter here, as nf_defrag_ipv6
 		 * replayed fragment zero will already have created the cp
Signature · 1 line
1.7.5.4

Regards

--
Julian Anastasov <[email protected]>