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

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