Skip to content

Commit 483e5ea

Browse files
author
Florian Westphal
committed
src: avoid errouneous assert with map+concat
Phil reported following assert: add rule ip6 f o mark set ip6 saddr . ip6 daddr . tcp dport \ map { dead::beef . f00::. 22 : 1 } nft: netlink_linearize.c:655: netlink_gen_expr: Assertion `dreg < ctx->reg_low' failed. This happens because "mark set" will allocate one register (the dreg), but netlink_gen_concat_expr will populate a lot more register space if the concat expression strings a lot of expressions together. As the assert is useful pseudo-reserve the register space as per concat->len and undo after generating the expressions. Reported-by: Phil Sutter <[email protected]> Signed-off-by: Florian Westphal <[email protected]>
1 parent 65a9d63 commit 483e5ea

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Diff for: src/netlink_linearize.c

+8
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ static void netlink_gen_map(struct netlink_linearize_ctx *ctx,
243243
{
244244
struct nftnl_expr *nle;
245245
enum nft_registers sreg;
246+
int regspace = 0;
246247

247248
assert(expr->mappings->ops->type == EXPR_SET_REF);
248249

@@ -251,7 +252,14 @@ static void netlink_gen_map(struct netlink_linearize_ctx *ctx,
251252
else
252253
sreg = dreg;
253254

255+
/* suppress assert in netlink_gen_expr */
256+
if (expr->map->ops->type == EXPR_CONCAT) {
257+
regspace = netlink_register_space(expr->map->len);
258+
ctx->reg_low += regspace;
259+
}
260+
254261
netlink_gen_expr(ctx, expr->map, sreg);
262+
ctx->reg_low -= regspace;
255263

256264
nle = alloc_nft_expr("lookup");
257265
netlink_put_register(nle, NFTNL_EXPR_LOOKUP_SREG, sreg);

0 commit comments

Comments
 (0)