netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Florian Westphal <fw@strlen.de>
Cc: Patrick McHardy <kaber@trash.net>, netfilter-devel@vger.kernel.org
Subject: Re: [PATCH nft] proto: fix VLAN header definition
Date: Mon, 30 Nov 2015 13:31:43 +0100	[thread overview]
Message-ID: <20151130123143.GA4233@salvia> (raw)
In-Reply-To: <20151129223743.GA29878@breakpoint.cc>

[-- Attachment #1: Type: text/plain, Size: 987 bytes --]

On Sun, Nov 29, 2015 at 11:37:43PM +0100, Florian Westphal wrote:
> Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> > On Sun, Nov 29, 2015 at 01:09:29AM +0100, Florian Westphal wrote:
> > > Thanks for looking at this.  I'll take a closer look tomorrow,
> > > your patch works fine for ip version/hdrlength but seems it messes
> > > with endianess somewhere.
> > 
> > I forgot to update payload_shift_value() too, to skip the shift when
> > not needed, sorry, new patch attached.
> 
> Almost there. Again, with Patricks patch to fix VLAN header:
> 
> # src/nft --debug=netlink add rule bridge raw prerouting ether type vlan vlan type ip vlan id 4094 ip version 4 counter 
> bridge raw prerouting

OK, new try, the idea behind is to calculate this shift through:

        x = offset % BITS_PER_BYTE
        y = len % BITS_PER_BYTE

to get both offset and length at byte level.

Then calculate the shift based on this:

        shift = BITS_PER_BYTE - (x + y)

Does this look good to you?

[-- Attachment #2: x.patch --]
[-- Type: text/x-diff, Size: 1230 bytes --]

diff --git a/src/netlink_linearize.c b/src/netlink_linearize.c
index 9840cd4..96f4dda 100644
--- a/src/netlink_linearize.c
+++ b/src/netlink_linearize.c
@@ -113,7 +113,8 @@ static void netlink_gen_payload_mask(struct netlink_linearize_ctx *ctx,
 	mpz_t mask;
 
 	offset = expr->payload.offset % BITS_PER_BYTE;
-	shift = (expr->len % BITS_PER_BYTE) - offset;
+	len = expr->len % BITS_PER_BYTE;
+	shift = BITS_PER_BYTE - (offset + len);
 	masklen = expr->len + shift;
 
 	if (masklen > 128)
@@ -291,7 +292,7 @@ static void netlink_gen_range(struct netlink_linearize_ctx *ctx,
 
 static void payload_shift_value(const struct expr *left, struct expr *right)
 {
-	unsigned int shift, offset;
+	unsigned int shift, offset, len;
 
 	if (right->ops->type != EXPR_VALUE ||
 	    left->ops->type != EXPR_PAYLOAD)
@@ -300,7 +301,8 @@ static void payload_shift_value(const struct expr *left, struct expr *right)
 	if (left->payload.offset % BITS_PER_BYTE ||
 	    (left->payload.offset + left->len) % BITS_PER_BYTE) {
 		offset = left->payload.offset % BITS_PER_BYTE;
-		shift = (left->len % BITS_PER_BYTE) - offset;
+		len = left->len % BITS_PER_BYTE;
+		shift = BITS_PER_BYTE - (offset + len);
 		mpz_lshift_ui(right->value, shift);
 	}
 }

  reply	other threads:[~2015-11-30 12:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-27  9:13 [PATCH nft] proto: fix VLAN header definition Patrick McHardy
2015-11-27  9:49 ` Florian Westphal
2015-11-27  9:54   ` Patrick McHardy
2015-11-27 10:34     ` Florian Westphal
2015-11-27 10:42       ` Florian Westphal
2015-11-27 10:49         ` Patrick McHardy
2015-11-27 10:54           ` Florian Westphal
2015-11-27 11:00             ` Patrick McHardy
2015-11-28 23:32             ` Pablo Neira Ayuso
2015-11-29  0:09               ` Florian Westphal
2015-11-29 22:00                 ` Pablo Neira Ayuso
2015-11-29 22:37                   ` Florian Westphal
2015-11-30 12:31                     ` Pablo Neira Ayuso [this message]
2015-11-30 13:53                       ` Florian Westphal
2015-11-30 13:57                         ` 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=20151130123143.GA4233@salvia \
    --to=pablo@netfilter.org \
    --cc=fw@strlen.de \
    --cc=kaber@trash.net \
    --cc=netfilter-devel@vger.kernel.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).