From: "Gao Feng" <gfree.wind@foxmail.com>
To: "'Liping Zhang'" <zlpnobody@gmail.com>
Cc: "'Liping Zhang'" <zlpnobody@163.com>,
"'Pablo Neira Ayuso'" <pablo@netfilter.org>,
"'Netfilter Developer Mailing List'"
<netfilter-devel@vger.kernel.org>, <cernekee@chromium.org>
Subject: RE: [PATCH nf] netfilter: ctnetlink: make it safer when updating ct->status
Date: Thu, 13 Apr 2017 11:22:51 +0800 [thread overview]
Message-ID: <000201d2b405$3c071920$b4154b60$@foxmail.com> (raw)
In-Reply-To: <CAML_gOeLBvnCYrYH7JzaJKg+UJ-hm+ctKGvJRnJkfsN8EEswhg@mail.gmail.com>
Hi Liping,
> -----Original Message-----
> From: Liping Zhang [mailto:zlpnobody@gmail.com]
> Sent: Thursday, April 13, 2017 11:15 AM
> To: Gao Feng <gfree.wind@foxmail.com>
> Cc: Liping Zhang <zlpnobody@163.com>; Pablo Neira Ayuso
> <pablo@netfilter.org>; Netfilter Developer Mailing List
> <netfilter-devel@vger.kernel.org>; cernekee@chromium.org
> Subject: Re: [PATCH nf] netfilter: ctnetlink: make it safer when updating
> ct->status
>
> Hi Feng,
>
> 2017-04-13 10:42 GMT+08:00 Gao Feng <gfree.wind@foxmail.com>:
> [...]
> >> +static void
> >> +__ctnetlink_change_status(struct nf_conn *ct, unsigned long on,
> >> + unsigned long off) {
> >> + unsigned long mask;
> >> + unsigned int bit;
> >> +
> >> + for (bit = 0; bit < __IPS_MAX_BIT; bit++) {
> >> + mask = 1 << bit;
> >> + /* Ignore these unchangable bits */
> >> + if (mask & IPS_UNCHANGEABLE_MASK)
> >> + continue;
> >
> > How about clear the bits of on and off with IPS_UNCHANGEABLE_MASK
> > before loop.
> > Like "on &= ~ IPS_UNCHANGEABLE_MASK";
> > Then the "if (mask & IPS_UNCHANGEABLE_MASK)" could be removed.
>
> No, it's better to do this together, there are two invocations, it's not good to
> copy these codes twice.
You mean " on &= ~ IPS_UNCHANGEABLE_MASK " and " off &= ~ IPS_UNCHANGEABLE_MASK " seems duplicated?
>
> >
> > BTW, when some bits are set both of on and off, the "on" would be
> > effective, but "off" not.
>
> This won't happen, see the invocation:
> 1. __ctnetlink_change_status(ct, status, 0); 2. __ctnetlink_change_status(ct,
> status, ~status);
>
> > So I think we could use BUILD_BUG_ON to avoid it during building.
> > BUILD_BUG_ON(on&mask);
>
> Btw, this won't help, BUILD_BUG_ON is only effective on compile time, but
> "on" and "off" will be modified at the running time.
You are right.
This new function would be used frequently at running time.
Regards
Feng
next prev parent reply other threads:[~2017-04-13 3:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-12 15:56 [PATCH nf] netfilter: ctnetlink: make it safer when updating ct->status Liping Zhang
2017-04-13 2:42 ` Gao Feng
2017-04-13 3:15 ` Liping Zhang
2017-04-13 3:22 ` Gao Feng [this message]
2017-04-13 3:55 ` Liping Zhang
2017-04-13 2:43 ` Gao Feng
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='000201d2b405$3c071920$b4154b60$@foxmail.com' \
--to=gfree.wind@foxmail.com \
--cc=cernekee@chromium.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
--cc=zlpnobody@163.com \
--cc=zlpnobody@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).