Skip to content

Commit 62472bc

Browse files
kaberummakynes
authored andcommitted
netfilter: nf_tables: restore context for expression destructors
In order to fix set destruction notifications and get rid of unnecessary members in private data structures, pass the context to expressions' destructor functions again. In order to do so, replace various members in the nft_rule_trans structure by the full context. Signed-off-by: Patrick McHardy <kaber@trash.net> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent a36e901 commit 62472bc

7 files changed

Lines changed: 31 additions & 32 deletions

File tree

‎include/net/netfilter/nf_tables.h‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ struct nft_expr_ops {
289289
int (*init)(const struct nft_ctx *ctx,
290290
const struct nft_expr *expr,
291291
const struct nlattr * const tb[]);
292-
void (*destroy)(const struct nft_expr *expr);
292+
void (*destroy)(const struct nft_ctx *ctx,
293+
const struct nft_expr *expr);
293294
int (*dump)(struct sk_buff *skb,
294295
const struct nft_expr *expr);
295296
int (*validate)(const struct nft_ctx *ctx,
@@ -343,19 +344,13 @@ struct nft_rule {
343344
* struct nft_rule_trans - nf_tables rule update in transaction
344345
*
345346
* @list: used internally
347+
* @ctx: rule context
346348
* @rule: rule that needs to be updated
347-
* @chain: chain that this rule belongs to
348-
* @table: table for which this chain applies
349-
* @nlh: netlink header of the message that contain this update
350-
* @family: family expressesed as AF_*
351349
*/
352350
struct nft_rule_trans {
353351
struct list_head list;
352+
struct nft_ctx ctx;
354353
struct nft_rule *rule;
355-
const struct nft_chain *chain;
356-
const struct nft_table *table;
357-
const struct nlmsghdr *nlh;
358-
u8 family;
359354
};
360355

361356
static inline struct nft_expr *nft_expr_first(const struct nft_rule *rule)

‎net/netfilter/nf_tables_api.c‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,10 +1253,11 @@ static int nf_tables_newexpr(const struct nft_ctx *ctx,
12531253
return err;
12541254
}
12551255

1256-
static void nf_tables_expr_destroy(struct nft_expr *expr)
1256+
static void nf_tables_expr_destroy(const struct nft_ctx *ctx,
1257+
struct nft_expr *expr)
12571258
{
12581259
if (expr->ops->destroy)
1259-
expr->ops->destroy(expr);
1260+
expr->ops->destroy(ctx, expr);
12601261
module_put(expr->ops->type->owner);
12611262
}
12621263

@@ -1536,7 +1537,8 @@ static int nf_tables_getrule(struct sock *nlsk, struct sk_buff *skb,
15361537
return err;
15371538
}
15381539

1539-
static void nf_tables_rule_destroy(struct nft_rule *rule)
1540+
static void nf_tables_rule_destroy(const struct nft_ctx *ctx,
1541+
struct nft_rule *rule)
15401542
{
15411543
struct nft_expr *expr;
15421544

@@ -1546,7 +1548,7 @@ static void nf_tables_rule_destroy(struct nft_rule *rule)
15461548
*/
15471549
expr = nft_expr_first(rule);
15481550
while (expr->ops && expr != nft_expr_last(rule)) {
1549-
nf_tables_expr_destroy(expr);
1551+
nf_tables_expr_destroy(ctx, expr);
15501552
expr = nft_expr_next(expr);
15511553
}
15521554
kfree(rule);
@@ -1565,11 +1567,8 @@ nf_tables_trans_add(struct nft_ctx *ctx, struct nft_rule *rule)
15651567
if (rupd == NULL)
15661568
return NULL;
15671569

1568-
rupd->chain = ctx->chain;
1569-
rupd->table = ctx->table;
1570+
rupd->ctx = *ctx;
15701571
rupd->rule = rule;
1571-
rupd->family = ctx->afi->family;
1572-
rupd->nlh = ctx->nlh;
15731572
list_add_tail(&rupd->list, &ctx->net->nft.commit_list);
15741573

15751574
return rupd;
@@ -1721,7 +1720,7 @@ static int nf_tables_newrule(struct sock *nlsk, struct sk_buff *skb,
17211720
kfree(repl);
17221721
}
17231722
err2:
1724-
nf_tables_rule_destroy(rule);
1723+
nf_tables_rule_destroy(&ctx, rule);
17251724
err1:
17261725
for (i = 0; i < n; i++) {
17271726
if (info[i].ops != NULL)
@@ -1831,28 +1830,29 @@ static int nf_tables_commit(struct sk_buff *skb)
18311830
*/
18321831
if (nft_rule_is_active(net, rupd->rule)) {
18331832
nft_rule_clear(net, rupd->rule);
1834-
nf_tables_rule_notify(skb, rupd->nlh, rupd->table,
1835-
rupd->chain, rupd->rule,
1836-
NFT_MSG_NEWRULE, 0,
1837-
rupd->family);
1833+
nf_tables_rule_notify(skb, rupd->ctx.nlh,
1834+
rupd->ctx.table, rupd->ctx.chain,
1835+
rupd->rule, NFT_MSG_NEWRULE, 0,
1836+
rupd->ctx.afi->family);
18381837
list_del(&rupd->list);
18391838
kfree(rupd);
18401839
continue;
18411840
}
18421841

18431842
/* This rule is in the past, get rid of it */
18441843
list_del_rcu(&rupd->rule->list);
1845-
nf_tables_rule_notify(skb, rupd->nlh, rupd->table, rupd->chain,
1844+
nf_tables_rule_notify(skb, rupd->ctx.nlh,
1845+
rupd->ctx.table, rupd->ctx.chain,
18461846
rupd->rule, NFT_MSG_DELRULE, 0,
1847-
rupd->family);
1847+
rupd->ctx.afi->family);
18481848
}
18491849

18501850
/* Make sure we don't see any packet traversing old rules */
18511851
synchronize_rcu();
18521852

18531853
/* Now we can safely release unused old rules */
18541854
list_for_each_entry_safe(rupd, tmp, &net->nft.commit_list, list) {
1855-
nf_tables_rule_destroy(rupd->rule);
1855+
nf_tables_rule_destroy(&rupd->ctx, rupd->rule);
18561856
list_del(&rupd->list);
18571857
kfree(rupd);
18581858
}
@@ -1881,7 +1881,7 @@ static int nf_tables_abort(struct sk_buff *skb)
18811881
synchronize_rcu();
18821882

18831883
list_for_each_entry_safe(rupd, tmp, &net->nft.commit_list, list) {
1884-
nf_tables_rule_destroy(rupd->rule);
1884+
nf_tables_rule_destroy(&rupd->ctx, rupd->rule);
18851885
list_del(&rupd->list);
18861886
kfree(rupd);
18871887
}

‎net/netfilter/nft_compat.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ nft_target_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
192192
}
193193

194194
static void
195-
nft_target_destroy(const struct nft_expr *expr)
195+
nft_target_destroy(const struct nft_ctx *ctx, const struct nft_expr *expr)
196196
{
197197
struct xt_target *target = expr->ops->data;
198198

@@ -379,7 +379,7 @@ nft_match_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
379379
}
380380

381381
static void
382-
nft_match_destroy(const struct nft_expr *expr)
382+
nft_match_destroy(const struct nft_ctx *ctx, const struct nft_expr *expr)
383383
{
384384
struct xt_match *match = expr->ops->data;
385385

‎net/netfilter/nft_ct.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ static int nft_ct_init(const struct nft_ctx *ctx,
321321
return 0;
322322
}
323323

324-
static void nft_ct_destroy(const struct nft_expr *expr)
324+
static void nft_ct_destroy(const struct nft_ctx *ctx,
325+
const struct nft_expr *expr)
325326
{
326327
struct nft_ct *priv = nft_expr_priv(expr);
327328

‎net/netfilter/nft_immediate.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ static int nft_immediate_init(const struct nft_ctx *ctx,
7070
return err;
7171
}
7272

73-
static void nft_immediate_destroy(const struct nft_expr *expr)
73+
static void nft_immediate_destroy(const struct nft_ctx *ctx,
74+
const struct nft_expr *expr)
7475
{
7576
const struct nft_immediate_expr *priv = nft_expr_priv(expr);
7677
return nft_data_uninit(&priv->data, nft_dreg_to_type(priv->dreg));

‎net/netfilter/nft_log.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ static int nft_log_init(const struct nft_ctx *ctx,
7474
return 0;
7575
}
7676

77-
static void nft_log_destroy(const struct nft_expr *expr)
77+
static void nft_log_destroy(const struct nft_ctx *ctx,
78+
const struct nft_expr *expr)
7879
{
7980
struct nft_log *priv = nft_expr_priv(expr);
8081

‎net/netfilter/nft_lookup.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ static int nft_lookup_init(const struct nft_ctx *ctx,
8989
return 0;
9090
}
9191

92-
static void nft_lookup_destroy(const struct nft_expr *expr)
92+
static void nft_lookup_destroy(const struct nft_ctx *ctx,
93+
const struct nft_expr *expr)
9394
{
9495
struct nft_lookup *priv = nft_expr_priv(expr);
9596

0 commit comments

Comments
 (0)