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

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