All of lore.kernel.org
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: Florian Westphal <fw@strlen.de>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>, netfilter-devel@vger.kernel.org
Subject: Re: [conntrack-tools PATCH] conntrack: Fix CIDR to mask conversion on Big Endian
Date: Wed, 4 Sep 2019 11:31:14 +0200	[thread overview]
Message-ID: <20190904093114.GI25650@orbyte.nwl.cc> (raw)
In-Reply-To: <20190904082128.GG13660@breakpoint.cc>

Hi,

On Wed, Sep 04, 2019 at 10:21:28AM +0200, Florian Westphal wrote:
> Phil Sutter <phil@nwl.cc> wrote:
> > What we need in b is 'ff ff ff 00' for a prefix length of 24. Your
> > suggested alternative does not compile, so I tried both options for the
> > closing brace:
> > 
> > | htonl((1 << 24) - 1)
> > 
> > This turns into '00 ff ff ff' for both LE and BE, the opposite of what
> > we need.
> > 
> > | htonl((1 << 24)) - 1
> > 
> > This turns into '00 00 00 00' on LE and '00 ff ff ff' on BE.
> > 
> > My code leads to correct result on either architecture and I don't see a
> > simpler way of doing it.
> 
> htonl(~0u << (32 - i)) would work, assuming i > 0 and <= 32.

Ah, indeed! Left-shifting all-ones didn't come to mind. I'll send a v2.

Thanks, Phil

      reply	other threads:[~2019-09-04  9:31 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
2019-09-04  6:53   ` Phil Sutter
2019-09-04  8:21     ` Florian Westphal
2019-09-04  9:31       ` Phil Sutter [this message]

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=20190904093114.GI25650@orbyte.nwl.cc \
    --to=phil@nwl.cc \
    --cc=fw@strlen.de \
    --cc=netfilter-devel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.