Blame SOURCES/0046-src-Support-odd-sized-payload-matches.patch

1374ad
From 64f34f34acedad6cce70f2dd91c82a814d4ffe34 Mon Sep 17 00:00:00 2001
1374ad
From: Phil Sutter <psutter@redhat.com>
1374ad
Date: Wed, 19 May 2021 18:03:43 +0200
1374ad
Subject: [PATCH] src: Support odd-sized payload matches
1374ad
1374ad
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1934926
1374ad
Upstream Status: nftables commit 8a927c56d83ed
1374ad
1374ad
commit 8a927c56d83ed0f78785011bd92a53edc25a0ca0
1374ad
Author: Phil Sutter <phil@nwl.cc>
1374ad
Date:   Tue Oct 27 17:05:25 2020 +0100
1374ad
1374ad
    src: Support odd-sized payload matches
1374ad
1374ad
    When expanding a payload match, don't disregard oversized templates at
1374ad
    the right offset. A more flexible user may extract less bytes from the
1374ad
    packet if only parts of a field are interesting, e.g. only the prefix of
1374ad
    source/destination address. Support that by using the template, but fix
1374ad
    the length. Later when creating a relational expression for it, detect
1374ad
    the unusually small payload expression length and turn the RHS value
1374ad
    into a prefix expression.
1374ad
1374ad
    Signed-off-by: Phil Sutter <phil@nwl.cc>
1374ad
---
1374ad
 src/netlink_delinearize.c | 6 ++++++
1374ad
 src/payload.c             | 5 +++++
1374ad
 2 files changed, 11 insertions(+)
1374ad
1374ad
diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c
1374ad
index 88dbd5a..8bdee12 100644
1374ad
--- a/src/netlink_delinearize.c
1374ad
+++ b/src/netlink_delinearize.c
1374ad
@@ -1577,6 +1577,12 @@ static void payload_match_expand(struct rule_pp_ctx *ctx,
1374ad
 		tmp = constant_expr_splice(right, left->len);
1374ad
 		expr_set_type(tmp, left->dtype, left->byteorder);
1374ad
 
1374ad
+		if (left->payload.tmpl && (left->len < left->payload.tmpl->len)) {
1374ad
+			mpz_lshift_ui(tmp->value, left->payload.tmpl->len - left->len);
1374ad
+			tmp->len = left->payload.tmpl->len;
1374ad
+			tmp = prefix_expr_alloc(&tmp->location, tmp, left->len);
1374ad
+		}
1374ad
+
1374ad
 		nexpr = relational_expr_alloc(&expr->location, expr->op,
1374ad
 					      left, tmp);
1374ad
 		if (expr->op == OP_EQ)
1374ad
diff --git a/src/payload.c b/src/payload.c
1374ad
index 3576400..45280ef 100644
1374ad
--- a/src/payload.c
1374ad
+++ b/src/payload.c
1374ad
@@ -746,6 +746,11 @@ void payload_expr_expand(struct list_head *list, struct expr *expr,
1374ad
 			expr->payload.offset += tmpl->len;
1374ad
 			if (expr->len == 0)
1374ad
 				return;
1374ad
+		} else if (expr->len > 0) {
1374ad
+			new = payload_expr_alloc(&expr->location, desc, i);
1374ad
+			new->len = expr->len;
1374ad
+			list_add_tail(&new->list, list);
1374ad
+			return;
1374ad
 		} else
1374ad
 			break;
1374ad
 	}
1374ad
-- 
1374ad
1.8.3.1
1374ad