All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xiao Liang <shaw.leon@gmail.com>
To: netfilter-devel <netfilter-devel@vger.kernel.org>
Cc: Xiao Liang <shaw.leon@gmail.com>
Subject: [PATCH nftables] src: Optimize prefix match only if is big-endian
Date: Sat, 21 Aug 2021 00:12:37 +0800	[thread overview]
Message-ID: <20210820161237.18821-1-shaw.leon@gmail.com> (raw)

A prefix of integer type is big-endian in nature. Prefix match can be
optimized to truncated 'cmp' only if it is big-endian.

Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
---
 src/netlink_linearize.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/netlink_linearize.c b/src/netlink_linearize.c
index eb53ccec..454b9ba3 100644
--- a/src/netlink_linearize.c
+++ b/src/netlink_linearize.c
@@ -548,7 +548,8 @@ static void netlink_gen_relational(struct netlink_linearize_ctx *ctx,
 	case EXPR_PREFIX:
 		sreg = get_register(ctx, expr->left);
 		if (expr_basetype(expr->left)->type != TYPE_STRING &&
-		    (!expr->right->prefix_len ||
+		    (expr->right->byteorder != BYTEORDER_BIG_ENDIAN ||
+		     !expr->right->prefix_len ||
 		     expr->right->prefix_len % BITS_PER_BYTE)) {
 			len = div_round_up(expr->right->len, BITS_PER_BYTE);
 			netlink_gen_expr(ctx, expr->left, sreg);
-- 
2.33.0


             reply	other threads:[~2021-08-20 16:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-20 16:12 Xiao Liang [this message]
2021-08-23 14:36 ` [PATCH nftables] src: Optimize prefix match only if is big-endian 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=20210820161237.18821-1-shaw.leon@gmail.com \
    --to=shaw.leon@gmail.com \
    --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.