From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH nft 4/6] netlink_linearize: use u64 conversion for 64bit quantities
Date: Fri, 8 Jan 2016 10:42:49 +0100 [thread overview]
Message-ID: <1452246171-13943-5-git-send-email-fw@strlen.de> (raw)
In-Reply-To: <1452246171-13943-1-git-send-email-fw@strlen.de>
nft generated two 4-byte swaps for conntrack byte/packet counters,
which are 64bit host-endian values:
byteorder reg 1 = hton(reg 1, 4, 8) ]
This makes the kernel perform two htonl() calls, but we need
a cpu_to_be64 conversion instead (reg 1, 8, 8).
Without this a rule like 'ct original packets > 10'
matched when counter was between 1 and 10.
Signed-off-by: Florian Westphal <fw@strlen.de>
---
src/netlink_linearize.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/netlink_linearize.c b/src/netlink_linearize.c
index 48f5f02..c77c462 100644
--- a/src/netlink_linearize.c
+++ b/src/netlink_linearize.c
@@ -592,6 +592,14 @@ static void netlink_gen_unary(struct netlink_linearize_ctx *ctx,
enum nft_registers dreg)
{
struct nftnl_expr *nle;
+ int byte_size;
+
+ if ((expr->arg->len % 64) == 0)
+ byte_size = 8;
+ else if ((expr->arg->len % 32) == 0)
+ byte_size = 4;
+ else
+ byte_size = 2;
netlink_gen_expr(ctx, expr->arg, dreg);
@@ -601,7 +609,7 @@ static void netlink_gen_unary(struct netlink_linearize_ctx *ctx,
nftnl_expr_set_u32(nle, NFTNL_EXPR_BYTEORDER_LEN,
expr->len / BITS_PER_BYTE);
nftnl_expr_set_u32(nle, NFTNL_EXPR_BYTEORDER_SIZE,
- expr->arg->len % 32 ? 2 : 4);
+ byte_size);
nftnl_expr_set_u32(nle, NFTNL_EXPR_BYTEORDER_OP,
netlink_gen_unary_op(expr->op));
nftnl_rule_add_expr(ctx->nlr, nle);
--
2.4.10
next prev parent reply other threads:[~2016-01-08 9:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-08 9:42 [PATCH nft 0/6] add support for conntrack counters Florian Westphal
2016-01-08 9:42 ` [PATCH libnftnl 1/6] src: ct: add packet and byte counter support Florian Westphal
2016-01-08 9:42 ` [PATCH nft 2/6] nft: swap key and direction in ct_dir syntax Florian Westphal
2016-01-08 9:42 ` [PATCH nft 3/6] ct: add packet/byte counter support Florian Westphal
2016-01-08 9:42 ` Florian Westphal [this message]
2016-01-08 9:42 ` [PATCH nft 5/6] ct regression tests for bytes, packets Florian Westphal
2016-01-08 9:42 ` [PATCH nft 6/6] tests: ct: remove BUG cases that work with current master Florian Westphal
2016-01-13 12:50 ` [PATCH nft 0/6] add support for conntrack counters 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=1452246171-13943-5-git-send-email-fw@strlen.de \
--to=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 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).