netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Phil Sutter <phil@nwl.cc>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [conntrack-tools PATCH] conntrack: Fix CIDR to mask conversion on Big Endian
Date: Tue, 3 Sep 2019 22:34:47 +0200	[thread overview]
Message-ID: <20190903203447.saqplkgbbxlajkqr@salvia> (raw)
In-Reply-To: <20190902164431.18398-1-phil@nwl.cc>

On Mon, Sep 02, 2019 at 06:44:31PM +0200, Phil Sutter wrote:
> Code assumed host architecture to be Little Endian. Instead produce a
> proper mask by pushing the set bits into most significant position and
> apply htonl() on the result.
> 
> Fixes: 3f6a2e90936bb ("conntrack: add support for CIDR notation")
> Signed-off-by: Phil Sutter <phil@nwl.cc>
> ---
>  src/conntrack.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/conntrack.c b/src/conntrack.c
> index c980a13f33d2c..baafcbd869c12 100644
> --- a/src/conntrack.c
> +++ b/src/conntrack.c
> @@ -2210,7 +2210,7 @@ nfct_build_netmask(uint32_t *dst, int b, int n)
>  			dst[i] = 0xffffffff;
>  			b -= 32;
>  		} else if (b > 0) {
> -			dst[i] = (1 << b) - 1;
> +			dst[i] = htonl(((1 << b) - 1) << (32 - b));

Simply this instead?

                        dst[i] = htonl(((1 << b) - 1);

>  			b = 0;
>  		} else {
>  			dst[i] = 0;
> -- 
> 2.22.0
> 

  reply	other threads:[~2019-09-03 20:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-02 16:44 [conntrack-tools PATCH] conntrack: Fix CIDR to mask conversion on Big Endian Phil Sutter
2019-09-03 20:34 ` Pablo Neira Ayuso [this message]
2019-09-04  6:53   ` Phil Sutter
2019-09-04  8:21     ` Florian Westphal
2019-09-04  9:31       ` Phil Sutter

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=20190903203447.saqplkgbbxlajkqr@salvia \
    --to=pablo@netfilter.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=phil@nwl.cc \
    /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).