From c5e6dcef5d67386996f00280c14f63142c78f452 Mon Sep 17 00:00:00 2001 From: ywc689 Date: Tue, 21 Jun 2022 17:53:37 +0800 Subject: [PATCH] ipvs: expire quiescent connections after realserver was removed This is an optimization of pr#574, in which quiescent connections are expired immediately when realserver weight is 0. Unfortunately, it didn't deal with the case where the realserver was removed. The patch fixes the problem by also expiring the connections that are in unavailable status(dp_vs_dest_is_avail returns false). Signed-off-by: ywc689 --- src/ipvs/ip_vs_core.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/ipvs/ip_vs_core.c b/src/ipvs/ip_vs_core.c index 3bd72eeae..fbc53efa8 100644 --- a/src/ipvs/ip_vs_core.c +++ b/src/ipvs/ip_vs_core.c @@ -86,6 +86,8 @@ static struct dp_vs_conn *dp_vs_sched_persist(struct dp_vs_service *svc, assert(svc && iph && mbuf); conn_flags = (is_synproxy_on ? DPVS_CONN_F_SYNPROXY : 0); + conn_flags |= (svc->flags & DPVS_CONN_F_EXPIRE_QUIESCENT); + if (svc->af == AF_INET6) { /* FIXME: Is OK to use svc->netmask as IPv6 prefix length ? */ ipv6_addr_prefix_copy(&snet.in6, &iph->saddr.in6, svc->netmask); @@ -339,12 +341,12 @@ struct dp_vs_conn *dp_vs_schedule(struct dp_vs_service *svc, ports[0], ports[1], 0, ¶m); } - if (is_synproxy_on) { + if (is_synproxy_on) flags |= DPVS_CONN_F_SYNPROXY; - } - if (svc->flags & DP_VS_SVC_F_ONEPACKET && iph->proto == IPPROTO_UDP) { + if (svc->flags & DP_VS_SVC_F_ONEPACKET && iph->proto == IPPROTO_UDP) flags |= DPVS_CONN_F_ONE_PACKET; - } + flags |= (svc->flags & DPVS_CONN_F_EXPIRE_QUIESCENT); + conn = dp_vs_conn_new(mbuf, iph, ¶m, dest, flags); if (!conn) return NULL; @@ -1013,17 +1015,15 @@ static int __dp_vs_in(void *priv, struct rte_mbuf *mbuf, else dir = DPVS_CONN_DIR_INBOUND; } else { - /* assert(conn->dest->svc != NULL); */ - if (conn->dest && conn->dest->svc && - prot->conn_expire_quiescent && - (conn->dest->svc->flags & DPVS_CONN_F_EXPIRE_QUIESCENT)) { - if (rte_atomic16_read(&conn->dest->weight) == 0) { - RTE_LOG(INFO, IPVS, "%s: the conn is quiescent, expire it right now," - " and drop the packet!\n", __func__); - prot->conn_expire_quiescent(conn); - dp_vs_conn_put(conn); - return INET_DROP; - } + /* assert(conn->dest != NULL); */ + if (prot->conn_expire_quiescent && (conn->flags & DPVS_CONN_F_EXPIRE_QUIESCENT) && + conn->dest && (!dp_vs_dest_is_avail(conn->dest) || + rte_atomic16_read(&conn->dest->weight) == 0)) { + RTE_LOG(INFO, IPVS, "%s: the conn is quiescent, expire it right now," + " and drop the packet!\n", __func__); + prot->conn_expire_quiescent(conn); + dp_vs_conn_put(conn); + return INET_DROP; } }