From: Julian Anastasov <ja@ssi.bg>
To: "longguang.yue" <bigclouds@163.com>
Cc: kuba@kernel.org, yuelongguang@gmail.com,
Wensong Zhang <wensong@linux-vs.org>,
Simon Horman <horms@verge.net.au>,
Pablo Neira Ayuso <pablo@netfilter.org>,
"open list:IPVS" <lvs-devel@vger.kernel.org>,
"open list:NETFILTER" <netfilter-devel@vger.kernel.org>
Subject: Re: [PATCH v3] ipvs: Add traffic statistic up even it is VS/DR or VS/TUN mode
Date: Wed, 30 Sep 2020 21:19:43 +0300 (EEST) [thread overview]
Message-ID: <alpine.LFD.2.23.451.2009302019180.5709@ja.home.ssi.bg> (raw)
In-Reply-To: <20200930012611.54859-1-bigclouds@163.com>
Hello,
On Wed, 30 Sep 2020, longguang.yue wrote:
> It's ipvs's duty to do traffic statistic if packets get hit,
> no matter what mode it is.
>
> Signed-off-by: longguang.yue <bigclouds@163.com>
> ---
> net/netfilter/ipvs/ip_vs_conn.c | 14 ++++++++++++--
> net/netfilter/ipvs/ip_vs_core.c | 5 ++++-
> 2 files changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
> index a90b8eac16ac..c4d164ce8ca7 100644
> --- a/net/netfilter/ipvs/ip_vs_conn.c
> +++ b/net/netfilter/ipvs/ip_vs_conn.c
> @@ -401,6 +401,8 @@ struct ip_vs_conn *ip_vs_ct_in_get(const struct ip_vs_conn_param *p)
> struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p)
> {
> unsigned int hash;
> + __be16 cport;
> + const union nf_inet_addr *caddr;
> struct ip_vs_conn *cp, *ret=NULL;
May be we can do it in few rounds, here is a list
of some initial notes...
caddr/cport are misleading, can be saddr/sport (source)
or laddr/lport (local).
> /*
> @@ -411,10 +413,18 @@ struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p)
> rcu_read_lock();
>
> hlist_for_each_entry_rcu(cp, &ip_vs_conn_tab[hash], c_list) {
Lets first check here for cp->cport before touching more
cache lines while traversing the list, it eliminates the cost of
next checks:
if (p->vport != cp->cport)
continue;
then
if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ) {
...
> - if (p->vport == cp->cport && p->cport == cp->dport &&
> + cport = cp->dport;
> + caddr = &cp->daddr;
> +
> + if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ) {
> + cport = cp->vport;
> + caddr = &cp->vaddr;
> + }
Considering the issues solved by commit 3c5ab3f395d6,
such check more correctly matches the replies from DR/TUN
real server to local clients but also to remote clients
if director is used as router.
> +
> + if (p->vport == cp->cport && p->cport == cport &&
if (p->cport == sport &&
...
> cp->af == p->af &&
> ip_vs_addr_equal(p->af, p->vaddr, &cp->caddr) &&
> - ip_vs_addr_equal(p->af, p->caddr, &cp->daddr) &&
> + ip_vs_addr_equal(p->af, p->caddr, caddr) &&
> p->protocol == cp->protocol &&
> cp->ipvs == p->ipvs) {
> if (!__ip_vs_conn_get(cp))
> diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
> index e3668a6e54e4..7ba88dab297a 100644
> --- a/net/netfilter/ipvs/ip_vs_core.c
> +++ b/net/netfilter/ipvs/ip_vs_core.c
> @@ -1413,8 +1413,11 @@ ip_vs_out(struct netns_ipvs *ipvs, unsigned int hooknum, struct sk_buff *skb, in
> ipvs, af, skb, &iph);
>
> if (likely(cp)) {
> - if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ)
> + if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ) {
> + ip_vs_out_stats(cp, skb);
> + skb->ipvs_property = 1;
We will also need:
if (!(cp->flags & IP_VS_CONN_F_NFCT))
ip_vs_notrack(skb);
Similar code is needed in handle_response_icmp(),
so that we account ICMP packets, where a jump to new label
before ip_vs_out_stats() can work.
But such jump is preferred even for handle_response()
because the (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ) check
should be moved from ip_vs_out() into handle_response().
For this to work the ip_vs_set_state() call in handle_response()
should be moved before the new label and ip_vs_out_stats() call.
> goto ignore_cp;
> + }
> return handle_response(af, skb, pd, cp, &iph, hooknum);
> }
Regards
--
Julian Anastasov <ja@ssi.bg>
next prev parent reply other threads:[~2020-09-30 18:19 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-29 5:03 [PATCH] ipvs: Add traffic statistic up even it is VS/DR or VS/TUN mode longguang.yue
2020-09-29 5:17 ` yue longguang
2020-09-29 8:18 ` [PATCH v2] " longguang.yue
2020-09-29 14:41 ` Jakub Kicinski
2020-09-30 1:26 ` [PATCH v3] " longguang.yue
2020-09-30 18:19 ` Julian Anastasov [this message]
2020-10-02 17:17 ` [PATCH v4] " longguang.yue
2020-10-02 19:26 ` Julian Anastasov
2020-10-04 4:13 ` [PATCH v5] " longguang.yue
2020-10-04 12:25 ` Julian Anastasov
2020-10-04 15:07 ` [PATCH v6] ipvs: inspect reply packets from DR/TUN real servers longguang.yue
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LFD.2.23.451.2009302019180.5709@ja.home.ssi.bg \
--to=ja@ssi.bg \
--cc=bigclouds@163.com \
--cc=horms@verge.net.au \
--cc=kuba@kernel.org \
--cc=lvs-devel@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
--cc=wensong@linux-vs.org \
--cc=yuelongguang@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).