From: Florian Westphal <fw@strlen.de>
To: mathieu.poirier@linaro.org
Cc: pablo@netfilter.org, kaber@trash.net, kadlec@blackhole.kfki.hu,
netfilter-devel@vger.kernel.org, netfilter@vger.kernel.org,
fw@strlen.de
Subject: Re: [PATCH RESEND v3] netfilter: xtables: add quota support to nfacct
Date: Sat, 1 Feb 2014 23:57:26 +0100 [thread overview]
Message-ID: <20140201225726.GF776@breakpoint.cc> (raw)
In-Reply-To: <1391292671-26466-1-git-send-email-mathieu.poirier@linaro.org>
mathieu.poirier@linaro.org <mathieu.poirier@linaro.org> wrote:
> +struct xt_nfacct_match_info_v1 {
> + char name[NFACCT_NAME_MAX];
> + struct nf_acct *nfacct;
> +
> + __u32 flags;
> + __aligned_u64 quota;
> + /* used internally by kernel */
> + struct nf_acct_quota *priv __attribute__((aligned(8)));
> +};
I think *nfacct pointer is also kernel internal, so it should also get
aligned (might also be possible to stash it in *private struct).
> + if (info->flags & XT_NFACCT_QUOTA) {
> + spin_lock_bh(&info->priv->lock);
> + val = (info->flags & XT_NFACCT_QUOTA_PKTS) ?
> + atomic64_read(&info->nfacct->pkts) :
> + atomic64_read(&info->nfacct->bytes);
> + if (val <= info->quota) {
> + ret = !ret;
> + info->priv->quota_reached = false;
Why quota_reached = false
assignment?
[ How is this toggled (other than transition to 'true' below)? ]
> + if (val >= info->quota && !info->priv->quota_reached) {
> + info->priv->quota_reached = true;
> + nfnl_quota_event(info->nfacct);
> + }
> +
> + spin_unlock_bh(&info->priv->lock);
> + }
Hm. Not sure why the lock has to be hold during all tests. What about:
if (info->flags & XT_NFACCT_QUOTA) {
val = (info->flags & XT_NFACCT_QUOTA_PKTS) ?
atomic64_read(&info->nfacct->pkts) :
atomic64_read(&info->nfacct->bytes);
/* normal case: quota not reached */
if (val <= info->quota)
return !ret;
/* other case: quota reached AND event sent */
if (info->priv->quota_reached)
return ret;
spin_lock_bh(&info->priv->lock);
if (!info->priv->quota_reached) {
info->priv->quota_reached = true;
nfnl_quota_event(info->nfacct);
}
spin_unlock_bh(&info->priv->lock);
[ could also cmpxchg instead of spinlock ]
Other than that this looks good to me.
next prev parent reply other threads:[~2014-02-01 22:57 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-01 22:11 [PATCH RESEND v3] netfilter: xtables: add quota support to nfacct mathieu.poirier
2014-02-01 22:57 ` Florian Westphal [this message]
2014-02-02 17:58 ` Mathieu Poirier
2014-02-02 20:40 ` Florian Westphal
2014-02-03 23:40 ` Mathieu Poirier
2014-02-12 10:33 ` Pablo Neira Ayuso
2014-02-12 16:58 ` Mathieu Poirier
2014-02-12 22:16 ` Pablo Neira Ayuso
2014-02-12 22:20 ` Pablo Neira Ayuso
2014-02-14 15:20 ` Mathieu Poirier
2014-02-16 2:38 ` Mathieu Poirier
2014-02-16 10:01 ` Pablo Neira Ayuso
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=20140201225726.GF776@breakpoint.cc \
--to=fw@strlen.de \
--cc=kaber@trash.net \
--cc=kadlec@blackhole.kfki.hu \
--cc=mathieu.poirier@linaro.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=netfilter@vger.kernel.org \
--cc=pablo@netfilter.org \
/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).