netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Changli Gao <xiaosuo@gmail.com>
Cc: netfilter-devel@vger.kernel.org, kaber@trash.net,
	jengelh@medozas.de, kadlec@blackhole.kfki.hu,
	eric.dumazet@gmail.com
Subject: Re: [PATCH 1/2] netfilter: add extended accounting infrastructure over nfnetlink
Date: Sat, 24 Dec 2011 01:55:47 +0100	[thread overview]
Message-ID: <20111224005547.GC12560@1984> (raw)
In-Reply-To: <CABa6K_EX=L_4Fp=Cxt1-m521meoVLtEa5Enp5dO2zap+YU5goA@mail.gmail.com>

On Fri, Dec 23, 2011 at 10:54:47PM +0800, Changli Gao wrote:
> On Fri, Dec 23, 2011 at 9:42 PM,  <pablo@netfilter.org> wrote:
> > +
> > +static LIST_HEAD(nfnl_acct_list);
> 
> You suppose that there won't be many accounting instants. It isn't
> scalable, as we have to iterate the list to find a special item. How
> about a hash table?

The lookup only happens if the rule is loaded.

There's no real gain from using hashing here.

> > +static int
> > +nfnl_acct_dump(struct sk_buff *skb, struct netlink_callback *cb)
> > +{
> > +       struct nf_acct *cur, *last;
> > +
> > +       if (cb->args[2])
> > +               return 0;
> > +
> > +       last = (struct nf_acct *)cb->args[1];
> > +       if (cb->args[1])
> > +               cb->args[1] = 0;
> > +
> > +       rcu_read_lock();
> > +       list_for_each_entry(cur, &nfnl_acct_list, head) {
> 
> You should use the RCU variant here.

I'll fix this, thanks.

> > +               if (last && cur != last)
> > +                       continue;
> > +
> > +               if (nfnl_acct_fill_info(skb, NETLINK_CB(cb->skb).pid,
> > +                                      cb->nlh->nlmsg_seq,
> > +                                      NFNL_MSG_ACCT_NEW, cur) < 0) {
> > +                       cb->args[1] = (unsigned long)cur;
> > +                       break;
> > +               }
> > +
> > +               if (NFNL_MSG_TYPE(cb->nlh->nlmsg_type) ==
> > +                                               NFNL_MSG_ACCT_GET_CTRZERO) {
> > +                       atomic64_set(&cur->pkts, 0);
> > +                       atomic64_set(&cur->bytes, 0);
> 
> The get and zero operations should be done in an atomic context,
> otherwise counters added between them will be lost.

Good catch.

I think we can fix this with xchg.

Similar patch should go to nf_conntrack_netlink.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2011-12-24  0:55 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-23 13:42 [PATCH 0/2] nfacct infrastructure (version 2) pablo
2011-12-23 13:42 ` [PATCH 1/2] netfilter: add extended accounting infrastructure over nfnetlink pablo
2011-12-23 14:10   ` Eric Dumazet
2011-12-23 14:12     ` Eric Dumazet
2011-12-24  0:24       ` Pablo Neira Ayuso
2011-12-24  0:23     ` Pablo Neira Ayuso
2011-12-23 14:54   ` Changli Gao
2011-12-24  0:55     ` Pablo Neira Ayuso [this message]
2011-12-23 13:42 ` [PATCH 2/2] netfilter: xtables: add nfacct match to support extended accounting pablo
  -- strict thread matches above, loose matches on Subject: below --
2011-12-14 11:00 [PATCH 0/2] [RFC] Extended accounting infrastructure for iptables pablo
2011-12-14 11:00 ` [PATCH 1/2] netfilter: add extended accounting infrastructure over nfnetlink pablo
2011-12-14 11:16   ` Eric Dumazet
2011-12-14 12:41     ` Pablo Neira Ayuso
2011-12-14 13:18       ` Eric Dumazet
2011-12-14 13:45         ` Eric Dumazet
2011-12-18  0:21           ` Pablo Neira Ayuso
2011-12-14 11:23   ` Patrick McHardy
2011-12-14 13:18     ` Pablo Neira Ayuso
2011-12-14 16:31       ` Patrick McHardy
2011-12-15 12:20         ` Pablo Neira Ayuso
2011-12-14 13:23   ` Changli Gao
2011-12-14 13:43   ` Jan Engelhardt
2011-12-14 16:50     ` Pablo Neira Ayuso
2011-12-14 18:30       ` Jozsef Kadlecsik
2011-12-14 23:06         ` Maciej Żenczykowski
2011-12-15 12:26         ` Pablo Neira Ayuso
2011-12-15 12:32           ` Jan Engelhardt
2011-12-14 13:49   ` Anand Raj Manickam
2011-12-14 13:54     ` Eric Dumazet

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=20111224005547.GC12560@1984 \
    --to=pablo@netfilter.org \
    --cc=eric.dumazet@gmail.com \
    --cc=jengelh@medozas.de \
    --cc=kaber@trash.net \
    --cc=kadlec@blackhole.kfki.hu \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=xiaosuo@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).