From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Florian Westphal <fw@strlen.de>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [nft PATCH 3/7] evaluate: add support to set IPv6 non-byte header fields
Date: Mon, 1 Aug 2016 12:29:10 +0200 [thread overview]
Message-ID: <20160801102910.GA3206@salvia> (raw)
In-Reply-To: <1469580196-2100-4-git-send-email-fw@strlen.de>
On Wed, Jul 27, 2016 at 02:43:12AM +0200, Florian Westphal wrote:
> 'ip6 ecn set 1' will generate a zero-sized write operation.
> Just like when matching on bit-sized header fields we need to
> round up to a byte-sized quantity and add a mask to retain those
> bits outside of the header bits that we want to change.
>
> Example:
>
> ip6 ecn set ce
> [ payload load 1b @ network header + 1 => reg 1 ]
> [ bitwise reg 1 = (reg=1 & 0x000000cf ) ^ 0x00000030 ]
> [ payload write reg 1 => 1b @ network header + 1 csum_type 0 csum_off 0 ]
>
> 1. Load the full byte containing the ecn bits
> 2 .Mask out everything *BUT* the ecn bits
> 3 .Set the CE mark
>
> This patch only works if the protcol doesn't need a checksum fixup.
> Will address this in a followup patch.
>
> This also doesn't yet include the needed reverse translation.
>
> Signed-off-by: Florian Westphal <fw@strlen.de>
> ---
> src/evaluate.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
> 1 file changed, 77 insertions(+), 4 deletions(-)
>
> diff --git a/src/evaluate.c b/src/evaluate.c
> index 8116735..e6d4642 100644
> --- a/src/evaluate.c
> +++ b/src/evaluate.c
> @@ -1608,13 +1608,86 @@ static int stmt_evaluate_verdict(struct eval_ctx *ctx, struct stmt *stmt)
>
> static int stmt_evaluate_payload(struct eval_ctx *ctx, struct stmt *stmt)
> {
> + struct expr *binop, *mask, *and, *payload_bytes;
> + unsigned int masklen, extra_len = 0;
> + unsigned int payload_byte_size;
> + uint8_t shift_imm, data[16];
Instead of hardcoding to our current maximum word size, I think you
can extract this information from the ctx.
> + struct expr *payload;
> + mpz_t bitmask, ff;
> +
> if (__expr_evaluate_payload(ctx, stmt->payload.expr) < 0)
> return -1;
>
> - return stmt_evaluate_arg(ctx, stmt,
> - stmt->payload.expr->dtype,
> - stmt->payload.expr->len,
> - &stmt->payload.val);
> + payload = stmt->payload.expr;
> + if (stmt_evaluate_arg(ctx, stmt, payload->dtype, payload->len,
> + &stmt->payload.val) < 0)
> + return -1;
> +
> + /* Normal case: byte sized and byte aligned */
> + if (payload->payload.offset % BITS_PER_BYTE == 0 &&
> + payload->len % BITS_PER_BYTE == 0)
> + return 0;
This idiom is already used in expr_evaluate_payload(), so you can
probably wrap this code in a function, eg. payload_needs_adjustment()
in a follow up patch and we skip this comment on top of this function.
> +
> + shift_imm = expr_offset_shift(payload, payload->payload.offset, &extra_len);
> + if (shift_imm) {
> + struct expr *off;
> +
> + off = constant_expr_alloc(&payload->location,
> + expr_basetype(payload),
> + BYTEORDER_HOST_ENDIAN,
> + sizeof(shift_imm), &shift_imm);
> +
> + binop = binop_expr_alloc(&payload->location, OP_LSHIFT,
> + stmt->payload.val, off);
> + binop->dtype = payload->dtype;
> + binop->byteorder = payload->byteorder;
This indent doesn't look correct.
I'd suggest you amend this before pushing this out.
next prev parent reply other threads:[~2016-08-01 10:29 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-27 0:43 [nft PATCH 0/7] add payload set support for sub-byte sizes Florian Westphal
2016-07-27 0:43 ` [nft PATCH 1/7] netlink: add __binop_adjust helper Florian Westphal
2016-07-27 0:43 ` [nft PATCH 2/7] payload: print base and raw values for unknown payloads Florian Westphal
2016-07-27 0:43 ` [nft PATCH 3/7] evaluate: add support to set IPv6 non-byte header fields Florian Westphal
2016-08-01 10:29 ` Pablo Neira Ayuso [this message]
2016-08-01 14:23 ` Florian Westphal
2016-07-27 0:43 ` [nft PATCH 4/7] netlink: decode payload statment Florian Westphal
2016-08-01 10:34 ` Pablo Neira Ayuso
2016-07-27 0:43 ` [nft PATCH 5/7] tests: ip6 dscp, flowlabel and ecn test cases Florian Westphal
2016-07-27 0:43 ` [nft PATCH 6/7] netlink: make checksum fixup work with odd-sized header fields Florian Westphal
2016-07-27 0:43 ` [nft PATCH 7/7] tests: ip payload set support for ecn and dscp Florian Westphal
2016-08-01 10:35 ` [nft PATCH 0/7] add payload set support for sub-byte sizes Pablo Neira Ayuso
2016-08-01 15:12 ` Florian Westphal
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=20160801102910.GA3206@salvia \
--to=pablo@netfilter.org \
--cc=fw@strlen.de \
--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 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.