Skip to content

Commit 20afd42

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: nf_tables: add conntrack dependencies for nat/masq/redir expressions
so that conntrack core will add the needed hooks in this namespace. Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent a357b3f commit 20afd42

7 files changed

Lines changed: 40 additions & 3 deletions

File tree

‎net/ipv4/netfilter/nft_masq_ipv4.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,19 @@ static void nft_masq_ipv4_eval(const struct nft_expr *expr,
3535
&range, nft_out(pkt));
3636
}
3737

38+
static void
39+
nft_masq_ipv4_destroy(const struct nft_ctx *ctx, const struct nft_expr *expr)
40+
{
41+
nf_ct_netns_put(ctx->net, NFPROTO_IPV4);
42+
}
43+
3844
static struct nft_expr_type nft_masq_ipv4_type;
3945
static const struct nft_expr_ops nft_masq_ipv4_ops = {
4046
.type = &nft_masq_ipv4_type,
4147
.size = NFT_EXPR_SIZE(sizeof(struct nft_masq)),
4248
.eval = nft_masq_ipv4_eval,
4349
.init = nft_masq_init,
50+
.destroy = nft_masq_ipv4_destroy,
4451
.dump = nft_masq_dump,
4552
.validate = nft_masq_validate,
4653
};

‎net/ipv4/netfilter/nft_redir_ipv4.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,19 @@ static void nft_redir_ipv4_eval(const struct nft_expr *expr,
3838
regs->verdict.code = nf_nat_redirect_ipv4(pkt->skb, &mr, nft_hook(pkt));
3939
}
4040

41+
static void
42+
nft_redir_ipv4_destroy(const struct nft_ctx *ctx, const struct nft_expr *expr)
43+
{
44+
nf_ct_netns_put(ctx->net, NFPROTO_IPV4);
45+
}
46+
4147
static struct nft_expr_type nft_redir_ipv4_type;
4248
static const struct nft_expr_ops nft_redir_ipv4_ops = {
4349
.type = &nft_redir_ipv4_type,
4450
.size = NFT_EXPR_SIZE(sizeof(struct nft_redir)),
4551
.eval = nft_redir_ipv4_eval,
4652
.init = nft_redir_init,
53+
.destroy = nft_redir_ipv4_destroy,
4754
.dump = nft_redir_dump,
4855
.validate = nft_redir_validate,
4956
};

‎net/ipv6/netfilter/nft_masq_ipv6.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,19 @@ static void nft_masq_ipv6_eval(const struct nft_expr *expr,
3636
nft_out(pkt));
3737
}
3838

39+
static void
40+
nft_masq_ipv6_destroy(const struct nft_ctx *ctx, const struct nft_expr *expr)
41+
{
42+
nf_ct_netns_put(ctx->net, NFPROTO_IPV6);
43+
}
44+
3945
static struct nft_expr_type nft_masq_ipv6_type;
4046
static const struct nft_expr_ops nft_masq_ipv6_ops = {
4147
.type = &nft_masq_ipv6_type,
4248
.size = NFT_EXPR_SIZE(sizeof(struct nft_masq)),
4349
.eval = nft_masq_ipv6_eval,
4450
.init = nft_masq_init,
51+
.destroy = nft_masq_ipv6_destroy,
4552
.dump = nft_masq_dump,
4653
.validate = nft_masq_validate,
4754
};

‎net/ipv6/netfilter/nft_redir_ipv6.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,19 @@ static void nft_redir_ipv6_eval(const struct nft_expr *expr,
3939
nf_nat_redirect_ipv6(pkt->skb, &range, nft_hook(pkt));
4040
}
4141

42+
static void
43+
nft_redir_ipv6_destroy(const struct nft_ctx *ctx, const struct nft_expr *expr)
44+
{
45+
nf_ct_netns_put(ctx->net, NFPROTO_IPV6);
46+
}
47+
4248
static struct nft_expr_type nft_redir_ipv6_type;
4349
static const struct nft_expr_ops nft_redir_ipv6_ops = {
4450
.type = &nft_redir_ipv6_type,
4551
.size = NFT_EXPR_SIZE(sizeof(struct nft_redir)),
4652
.eval = nft_redir_ipv6_eval,
4753
.init = nft_redir_init,
54+
.destroy = nft_redir_ipv6_destroy,
4855
.dump = nft_redir_dump,
4956
.validate = nft_redir_validate,
5057
};

‎net/netfilter/nft_masq.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ int nft_masq_init(const struct nft_ctx *ctx,
7777
}
7878
}
7979

80-
return 0;
80+
return nf_ct_netns_get(ctx->net, ctx->afi->family);
8181
}
8282
EXPORT_SYMBOL_GPL(nft_masq_init);
8383

‎net/netfilter/nft_nat.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ static int nft_nat_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
209209
return -EINVAL;
210210
}
211211

212-
return 0;
212+
return nf_ct_netns_get(ctx->net, family);
213213
}
214214

215215
static int nft_nat_dump(struct sk_buff *skb, const struct nft_expr *expr)
@@ -257,12 +257,21 @@ static int nft_nat_dump(struct sk_buff *skb, const struct nft_expr *expr)
257257
return -1;
258258
}
259259

260+
static void
261+
nft_nat_destroy(const struct nft_ctx *ctx, const struct nft_expr *expr)
262+
{
263+
const struct nft_nat *priv = nft_expr_priv(expr);
264+
265+
nf_ct_netns_put(ctx->net, priv->family);
266+
}
267+
260268
static struct nft_expr_type nft_nat_type;
261269
static const struct nft_expr_ops nft_nat_ops = {
262270
.type = &nft_nat_type,
263271
.size = NFT_EXPR_SIZE(sizeof(struct nft_nat)),
264272
.eval = nft_nat_eval,
265273
.init = nft_nat_init,
274+
.destroy = nft_nat_destroy,
266275
.dump = nft_nat_dump,
267276
.validate = nft_nat_validate,
268277
};

‎net/netfilter/nft_redir.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ int nft_redir_init(const struct nft_ctx *ctx,
7979
return -EINVAL;
8080
}
8181

82-
return 0;
82+
return nf_ct_netns_get(ctx->net, ctx->afi->family);
8383
}
8484
EXPORT_SYMBOL_GPL(nft_redir_init);
8585

0 commit comments

Comments
 (0)