summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXiao Liang <shaw.leon@gmail.com>2021-08-21 00:12:37 +0800
committerPablo Neira Ayuso <pablo@netfilter.org>2021-08-23 16:34:52 +0200
commitbd6ba14bebd27181ee18cfc3aebb21a78d96d672 (patch)
tree5e88ef776bfc3e6f6b418239d51b218689f76417
parentffde58ab86507755ba7049a00dde5c4df6f26fbe (diff)
src: Optimize prefix match only if is big-endian
A prefix of integer type is big-endian in nature. Prefix match can be optimized to truncated 'cmp' only if it is big-endian. [ Add one tests/py for this use-case --pablo ] Fixes: 25338cdb6c77 ("src: Optimize prefix matches on byte-boundaries") Signed-off-by: Xiao Liang <shaw.leon@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--src/netlink_linearize.c3
-rw-r--r--tests/py/any/meta.t1
-rw-r--r--tests/py/any/meta.t.json20
-rw-r--r--tests/py/any/meta.t.payload6
4 files changed, 29 insertions, 1 deletions
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);
diff --git a/tests/py/any/meta.t b/tests/py/any/meta.t
index 125b0a3f..6ec4853e 100644
--- a/tests/py/any/meta.t
+++ b/tests/py/any/meta.t
@@ -55,6 +55,7 @@ meta mark and 0x03 == 0x01;ok;meta mark & 0x00000003 == 0x00000001
meta mark and 0x03 != 0x01;ok;meta mark & 0x00000003 != 0x00000001
meta mark 0x10;ok;meta mark 0x00000010
meta mark != 0x10;ok;meta mark != 0x00000010
+meta mark 0xffffff00/24;ok
meta mark or 0x03 == 0x01;ok;meta mark | 0x00000003 == 0x00000001
meta mark or 0x03 != 0x01;ok;meta mark | 0x00000003 != 0x00000001
diff --git a/tests/py/any/meta.t.json b/tests/py/any/meta.t.json
index fd4d1c2a..b140aaaa 100644
--- a/tests/py/any/meta.t.json
+++ b/tests/py/any/meta.t.json
@@ -662,6 +662,26 @@
}
]
+# meta mark 0xffffff00/24
+[
+ {
+ "match": {
+ "left": {
+ "meta": {
+ "key": "mark"
+ }
+ },
+ "op": "==",
+ "right": {
+ "prefix": {
+ "addr": 4294967040,
+ "len": 24
+ }
+ }
+ }
+ }
+]
+
# meta mark or 0x03 == 0x01
[
{
diff --git a/tests/py/any/meta.t.payload b/tests/py/any/meta.t.payload
index b79a0255..d8351c27 100644
--- a/tests/py/any/meta.t.payload
+++ b/tests/py/any/meta.t.payload
@@ -155,6 +155,12 @@ ip test-ip4 input
[ meta load mark => reg 1 ]
[ cmp neq reg 1 0x00000010 ]
+# meta mark 0xffffff00/24
+ip test-ip4 input
+ [ meta load mark => reg 1 ]
+ [ bitwise reg 1 = ( reg 1 & 0xffffff00 ) ^ 0x00000000 ]
+ [ cmp eq reg 1 0xffffff00 ]
+
# meta mark or 0x03 == 0x01
ip test-ip4 input
[ meta load mark => reg 1 ]