Skip to content

Commit 43dd16e

Browse files
committed
netfilter: nf_tables: store data in offload context registers
Store immediate data into offload context register. This allows follow up instructions to take it from the corresponding source register. This patch is required to support for payload mangling, although other instructions that take data from source register will benefit from this too. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent bd8699e commit 43dd16e

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

‎include/net/netfilter/nf_tables_offload.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ struct nft_offload_reg {
99
u32 len;
1010
u32 base_offset;
1111
u32 offset;
12+
struct nft_data data;
1213
struct nft_data mask;
1314
};
1415

‎net/netfilter/nft_immediate.c‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,13 @@ static int nft_immediate_validate(const struct nft_ctx *ctx,
125125
return 0;
126126
}
127127

128-
static int nft_immediate_offload(struct nft_offload_ctx *ctx,
129-
struct nft_flow_rule *flow,
130-
const struct nft_expr *expr)
128+
static int nft_immediate_offload_verdict(struct nft_offload_ctx *ctx,
129+
struct nft_flow_rule *flow,
130+
const struct nft_immediate_expr *priv)
131131
{
132-
const struct nft_immediate_expr *priv = nft_expr_priv(expr);
133132
struct flow_action_entry *entry;
134133
const struct nft_data *data;
135134

136-
if (priv->dreg != NFT_REG_VERDICT)
137-
return -EOPNOTSUPP;
138-
139135
entry = &flow->rule->action.entries[ctx->num_actions++];
140136

141137
data = &priv->data;
@@ -153,6 +149,20 @@ static int nft_immediate_offload(struct nft_offload_ctx *ctx,
153149
return 0;
154150
}
155151

152+
static int nft_immediate_offload(struct nft_offload_ctx *ctx,
153+
struct nft_flow_rule *flow,
154+
const struct nft_expr *expr)
155+
{
156+
const struct nft_immediate_expr *priv = nft_expr_priv(expr);
157+
158+
if (priv->dreg == NFT_REG_VERDICT)
159+
return nft_immediate_offload_verdict(ctx, flow, priv);
160+
161+
memcpy(&ctx->regs[priv->dreg].data, &priv->data, sizeof(priv->data));
162+
163+
return 0;
164+
}
165+
156166
static const struct nft_expr_ops nft_imm_ops = {
157167
.type = &nft_imm_type,
158168
.size = NFT_EXPR_SIZE(sizeof(struct nft_immediate_expr)),

0 commit comments

Comments
 (0)