Skip to content

Commit 2cc4eec

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 #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 3c3e890 commit 2cc4eec

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
@@ -1624,18 +1624,16 @@ static inline void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp)
16241624
}
16251625
#endif /* CONFIG_IP_VS_NFCT */
16261626

1627-
/* Really using conntrack? */
1628-
static inline bool ip_vs_conn_uses_conntrack(struct ip_vs_conn *cp,
1629-
struct sk_buff *skb)
1627+
/* Using old conntrack that can not be redirected to another real server? */
1628+
static inline bool ip_vs_conn_uses_old_conntrack(struct ip_vs_conn *cp,
1629+
struct sk_buff *skb)
16301630
{
16311631
#ifdef CONFIG_IP_VS_NFCT
16321632
enum ip_conntrack_info ctinfo;
16331633
struct nf_conn *ct;
16341634

1635-
if (!(cp->flags & IP_VS_CONN_F_NFCT))
1636-
return false;
16371635
ct = nf_ct_get(skb, &ctinfo);
1638-
if (ct)
1636+
if (ct && nf_ct_is_confirmed(ct))
16391637
return true;
16401638
#endif
16411639
return false;

net/netfilter/ipvs/ip_vs_core.c

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

20672067
conn_reuse_mode = sysctl_conn_reuse_mode(ipvs);
20682068
if (conn_reuse_mode && !iph.fragoffs && is_new_conn(skb, &iph) && cp) {
2069-
bool uses_ct = false, resched = false;
2069+
bool old_ct = false, resched = false;
20702070

20712071
if (unlikely(sysctl_expire_nodest_conn(ipvs)) && cp->dest &&
20722072
unlikely(!atomic_read(&cp->dest->weight))) {
20732073
resched = true;
2074-
uses_ct = ip_vs_conn_uses_conntrack(cp, skb);
2074+
old_ct = ip_vs_conn_uses_old_conntrack(cp, skb);
20752075
} else if (is_new_conn_expected(cp, conn_reuse_mode)) {
2076-
uses_ct = ip_vs_conn_uses_conntrack(cp, skb);
2076+
old_ct = ip_vs_conn_uses_old_conntrack(cp, skb);
20772077
if (!atomic_read(&cp->n_control)) {
20782078
resched = true;
20792079
} else {
20802080
/* Do not reschedule controlling connection
20812081
* that uses conntrack while it is still
20822082
* referenced by controlled connection(s).
20832083
*/
2084-
resched = !uses_ct;
2084+
resched = !old_ct;
20852085
}
20862086
}
20872087

20882088
if (resched) {
2089+
if (!old_ct)
2090+
cp->flags &= ~IP_VS_CONN_F_NFCT;
20892091
if (!atomic_read(&cp->n_control))
20902092
ip_vs_conn_expire_now(cp);
20912093
__ip_vs_conn_put(cp);
2092-
if (uses_ct)
2094+
if (old_ct)
20932095
return NF_DROP;
20942096
cp = NULL;
20952097
}

0 commit comments

Comments
 (0)