Skip to content

Commit 7106f94

Browse files
Julian Anastasovgregkh
Julian Anastasov
authored andcommitted
ipvs: allow connection reuse for unconfirmed conntrack
[ Upstream commit f0a5e4d ] YangYuxi is reporting that connection reuse is causing one-second delay when SYN hits existing connection in TIME_WAIT state. Such delay was added to give time to expire both the IPVS connection and the corresponding conntrack. This was considered a rare case at that time but it is causing problem for some environments such as Kubernetes. As nf_conntrack_tcp_packet() can decide to release the conntrack in TIME_WAIT state and to replace it with a fresh NEW conntrack, we can use this to allow rescheduling just by tuning our check: if the conntrack is confirmed we can not schedule it to different real server and the one-second delay still applies but if new conntrack was created, we are free to select new real server without any delays. YangYuxi lists some of the problem reports: - One second connection delay in masquerading mode: https://marc.info/?t=151683118100004&r=1&w=2 - IPVS low throughput #70747 kubernetes/kubernetes#70747 - Apache Bench can fill up ipvs service proxy in seconds raspberrypi#544 cloudnativelabs/kube-router#544 - Additional 1s latency in `host -> service IP -> pod` kubernetes/kubernetes#90854 Fixes: f719e37 ("ipvs: drop first packet to redirect conntrack") Co-developed-by: YangYuxi <[email protected]> Signed-off-by: YangYuxi <[email protected]> Signed-off-by: Julian Anastasov <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent fdac853 commit 7106f94

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

include/net/ip_vs.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,18 +1614,16 @@ static inline void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp)
16141614
}
16151615
#endif /* CONFIG_IP_VS_NFCT */
16161616

1617-
/* Really using conntrack? */
1618-
static inline bool ip_vs_conn_uses_conntrack(struct ip_vs_conn *cp,
1619-
struct sk_buff *skb)
1617+
/* Using old conntrack that can not be redirected to another real server? */
1618+
static inline bool ip_vs_conn_uses_old_conntrack(struct ip_vs_conn *cp,
1619+
struct sk_buff *skb)
16201620
{
16211621
#ifdef CONFIG_IP_VS_NFCT
16221622
enum ip_conntrack_info ctinfo;
16231623
struct nf_conn *ct;
16241624

1625-
if (!(cp->flags & IP_VS_CONN_F_NFCT))
1626-
return false;
16271625
ct = nf_ct_get(skb, &ctinfo);
1628-
if (ct)
1626+
if (ct && nf_ct_is_confirmed(ct))
16291627
return true;
16301628
#endif
16311629
return false;

net/netfilter/ipvs/ip_vs_core.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,30 +1928,32 @@ ip_vs_in(struct netns_ipvs *ipvs, unsigned int hooknum, struct sk_buff *skb, int
19281928

19291929
conn_reuse_mode = sysctl_conn_reuse_mode(ipvs);
19301930
if (conn_reuse_mode && !iph.fragoffs && is_new_conn(skb, &iph) && cp) {
1931-
bool uses_ct = false, resched = false;
1931+
bool old_ct = false, resched = false;
19321932

19331933
if (unlikely(sysctl_expire_nodest_conn(ipvs)) && cp->dest &&
19341934
unlikely(!atomic_read(&cp->dest->weight))) {
19351935
resched = true;
1936-
uses_ct = ip_vs_conn_uses_conntrack(cp, skb);
1936+
old_ct = ip_vs_conn_uses_old_conntrack(cp, skb);
19371937
} else if (is_new_conn_expected(cp, conn_reuse_mode)) {
1938-
uses_ct = ip_vs_conn_uses_conntrack(cp, skb);
1938+
old_ct = ip_vs_conn_uses_old_conntrack(cp, skb);
19391939
if (!atomic_read(&cp->n_control)) {
19401940
resched = true;
19411941
} else {
19421942
/* Do not reschedule controlling connection
19431943
* that uses conntrack while it is still
19441944
* referenced by controlled connection(s).
19451945
*/
1946-
resched = !uses_ct;
1946+
resched = !old_ct;
19471947
}
19481948
}
19491949

19501950
if (resched) {
1951+
if (!old_ct)
1952+
cp->flags &= ~IP_VS_CONN_F_NFCT;
19511953
if (!atomic_read(&cp->n_control))
19521954
ip_vs_conn_expire_now(cp);
19531955
__ip_vs_conn_put(cp);
1954-
if (uses_ct)
1956+
if (old_ct)
19551957
return NF_DROP;
19561958
cp = NULL;
19571959
}

0 commit comments

Comments
 (0)