When expanding a payload match, don't disregard oversized templates at the right offset. A more flexible user may extract less bytes from the packet if only parts of a field are interesting, e.g. only the prefix of source/destination address. Support that by using the template, but fix the length. Later when creating a relational expression for it, detect the unusually small payload expression length and turn the RHS value into a prefix expression. Signed-off-by: Phil Sutter <phil@xxxxxx> --- src/netlink_delinearize.c | 6 ++++++ src/payload.c | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c index 43d7ff821504d..b7876a8da8375 100644 --- a/src/netlink_delinearize.c +++ b/src/netlink_delinearize.c @@ -1776,6 +1776,12 @@ static void payload_match_expand(struct rule_pp_ctx *ctx, tmp = constant_expr_splice(right, left->len); expr_set_type(tmp, left->dtype, left->byteorder); + if (left->payload.tmpl && (left->len < left->payload.tmpl->len)) { + mpz_lshift_ui(tmp->value, left->payload.tmpl->len - left->len); + tmp->len = left->payload.tmpl->len; + tmp = prefix_expr_alloc(&tmp->location, tmp, left->len); + } + nexpr = relational_expr_alloc(&expr->location, expr->op, left, tmp); if (expr->op == OP_EQ) diff --git a/src/payload.c b/src/payload.c index ca422d5bcd561..e51c5797c589a 100644 --- a/src/payload.c +++ b/src/payload.c @@ -822,6 +822,11 @@ void payload_expr_expand(struct list_head *list, struct expr *expr, expr->payload.offset += tmpl->len; if (expr->len == 0) return; + } else if (expr->len > 0) { + new = payload_expr_alloc(&expr->location, desc, i); + new->len = expr->len; + list_add_tail(&new->list, list); + return; } else break; } -- 2.28.0