diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2022-05-06 22:43:44 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2022-05-06 22:44:15 +0200 |
commit | 484ad4421a2ed07a94159b0fe92d5135f362c3bf (patch) | |
tree | fdc2349fe74eb05b20b6e888903ad4f879d61960 | |
parent | b9e00458b9f357f6c9b301f95b276fd019da0692 (diff) |
regs: do not assume 16 registers
nftnl_regs_alloc() allows for more than 16 registers for future use,
replaced hardcoded number of registers.
Fixes: b9e00458b9f3 ("src: add dynamic register allocation infrastructure")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r-- | src/regs.c | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -84,9 +84,9 @@ static void nft_expr_reg_update(struct nftnl_regs *regs, return expr->ops->reg.update(®s->reg[i], expr); } -static int reg_space(int i) +static int reg_space(const struct nftnl_regs *regs, int i) { - return sizeof(uint32_t) * 16 - sizeof(uint32_t) * i; + return sizeof(uint32_t) * regs->num_regs - sizeof(uint32_t) * i; } struct nftnl_reg_ctx { @@ -98,7 +98,7 @@ struct nftnl_reg_ctx { static void register_track(struct nftnl_reg_ctx *ctx, const struct nftnl_regs *regs, int i, int len) { - if (ctx->reg >= 0 || regs->reg[i].word || reg_space(i) < len) + if (ctx->reg >= 0 || regs->reg[i].word || reg_space(regs, i) < len) return; if (regs->reg[i].type == NFT_EXPR_UNSPEC) { @@ -183,7 +183,7 @@ uint32_t nftnl_reg_get(struct nftnl_regs *regs, const struct nftnl_expr *expr) type = nftnl_expr_type(expr); len = nftnl_expr_reg_len(expr); - for (i = 0; i < 16; i++) { + for (i = 0; i < regs->num_regs; i++) { register_track(&ctx, regs, i, len); if (!nftnl_expr_reg_cmp(regs, expr, i)) @@ -215,7 +215,7 @@ uint32_t nftnl_reg_get_scratch(struct nftnl_regs *regs, uint32_t len) }; int i; - for (i = 0; i < 16; i++) + for (i = 0; i < regs->num_regs; i++) register_track(&ctx, regs, i, len); register_evict(&ctx); |