Skip to content

Commit ecb2421

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: add and use nf_ct_netns_get/put
currently aliased to try_module_get/_put. Will be changed in next patch when we add functions to make use of ->net argument to store usercount per l3proto tracker. This is needed to avoid registering the conntrack hooks in all netns and later only enable connection tracking in those that need conntrack. Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent a379854 commit ecb2421

15 files changed

Lines changed: 58 additions & 42 deletions

File tree

‎include/net/netfilter/nf_conntrack.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ static inline void nf_ct_put(struct nf_conn *ct)
181181
int nf_ct_l3proto_try_module_get(unsigned short l3proto);
182182
void nf_ct_l3proto_module_put(unsigned short l3proto);
183183

184+
/* load module; enable/disable conntrack in this namespace */
185+
int nf_ct_netns_get(struct net *net, u8 nfproto);
186+
void nf_ct_netns_put(struct net *net, u8 nfproto);
187+
184188
/*
185189
* Allocate a hashtable of hlist_head (if nulls == 0),
186190
* or hlist_nulls_head (if nulls == 1)

‎net/ipv4/netfilter/ipt_CLUSTERIP.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ static int clusterip_tg_check(const struct xt_tgchk_param *par)
419419
}
420420
cipinfo->config = config;
421421

422-
ret = nf_ct_l3proto_try_module_get(par->family);
422+
ret = nf_ct_netns_get(par->net, par->family);
423423
if (ret < 0)
424424
pr_info("cannot load conntrack support for proto=%u\n",
425425
par->family);
@@ -444,7 +444,7 @@ static void clusterip_tg_destroy(const struct xt_tgdtor_param *par)
444444

445445
clusterip_config_put(cipinfo->config);
446446

447-
nf_ct_l3proto_module_put(par->family);
447+
nf_ct_netns_get(par->net, par->family);
448448
}
449449

450450
#ifdef CONFIG_COMPAT

‎net/ipv4/netfilter/ipt_SYNPROXY.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,12 +418,12 @@ static int synproxy_tg4_check(const struct xt_tgchk_param *par)
418418
e->ip.invflags & XT_INV_PROTO)
419419
return -EINVAL;
420420

421-
return nf_ct_l3proto_try_module_get(par->family);
421+
return nf_ct_netns_get(par->net, par->family);
422422
}
423423

424424
static void synproxy_tg4_destroy(const struct xt_tgdtor_param *par)
425425
{
426-
nf_ct_l3proto_module_put(par->family);
426+
nf_ct_netns_put(par->net, par->family);
427427
}
428428

429429
static struct xt_target synproxy_tg4_reg __read_mostly = {

‎net/ipv6/netfilter/ip6t_SYNPROXY.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,12 +440,12 @@ static int synproxy_tg6_check(const struct xt_tgchk_param *par)
440440
e->ipv6.invflags & XT_INV_PROTO)
441441
return -EINVAL;
442442

443-
return nf_ct_l3proto_try_module_get(par->family);
443+
return nf_ct_netns_get(par->net, par->family);
444444
}
445445

446446
static void synproxy_tg6_destroy(const struct xt_tgdtor_param *par)
447447
{
448-
nf_ct_l3proto_module_put(par->family);
448+
nf_ct_netns_put(par->net, par->family);
449449
}
450450

451451
static struct xt_target synproxy_tg6_reg __read_mostly = {

‎net/netfilter/nf_conntrack_proto.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@ void nf_ct_l3proto_module_put(unsigned short l3proto)
125125
}
126126
EXPORT_SYMBOL_GPL(nf_ct_l3proto_module_put);
127127

128+
int nf_ct_netns_get(struct net *net, u8 nfproto)
129+
{
130+
return nf_ct_l3proto_try_module_get(nfproto);
131+
}
132+
EXPORT_SYMBOL_GPL(nf_ct_netns_get);
133+
134+
void nf_ct_netns_put(struct net *net, u8 nfproto)
135+
{
136+
nf_ct_l3proto_module_put(nfproto);
137+
}
138+
EXPORT_SYMBOL_GPL(nf_ct_netns_put);
139+
128140
struct nf_conntrack_l4proto *
129141
nf_ct_l4proto_find_get(u_int16_t l3num, u_int8_t l4num)
130142
{

‎net/netfilter/nft_ct.c‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -208,37 +208,37 @@ static const struct nla_policy nft_ct_policy[NFTA_CT_MAX + 1] = {
208208
[NFTA_CT_SREG] = { .type = NLA_U32 },
209209
};
210210

211-
static int nft_ct_l3proto_try_module_get(uint8_t family)
211+
static int nft_ct_netns_get(struct net *net, uint8_t family)
212212
{
213213
int err;
214214

215215
if (family == NFPROTO_INET) {
216-
err = nf_ct_l3proto_try_module_get(NFPROTO_IPV4);
216+
err = nf_ct_netns_get(net, NFPROTO_IPV4);
217217
if (err < 0)
218218
goto err1;
219-
err = nf_ct_l3proto_try_module_get(NFPROTO_IPV6);
219+
err = nf_ct_netns_get(net, NFPROTO_IPV6);
220220
if (err < 0)
221221
goto err2;
222222
} else {
223-
err = nf_ct_l3proto_try_module_get(family);
223+
err = nf_ct_netns_get(net, family);
224224
if (err < 0)
225225
goto err1;
226226
}
227227
return 0;
228228

229229
err2:
230-
nf_ct_l3proto_module_put(NFPROTO_IPV4);
230+
nf_ct_netns_put(net, NFPROTO_IPV4);
231231
err1:
232232
return err;
233233
}
234234

235-
static void nft_ct_l3proto_module_put(uint8_t family)
235+
static void nft_ct_netns_put(struct net *net, uint8_t family)
236236
{
237237
if (family == NFPROTO_INET) {
238-
nf_ct_l3proto_module_put(NFPROTO_IPV4);
239-
nf_ct_l3proto_module_put(NFPROTO_IPV6);
238+
nf_ct_netns_put(net, NFPROTO_IPV4);
239+
nf_ct_netns_put(net, NFPROTO_IPV6);
240240
} else
241-
nf_ct_l3proto_module_put(family);
241+
nf_ct_netns_put(net, family);
242242
}
243243

244244
static int nft_ct_get_init(const struct nft_ctx *ctx,
@@ -342,7 +342,7 @@ static int nft_ct_get_init(const struct nft_ctx *ctx,
342342
if (err < 0)
343343
return err;
344344

345-
err = nft_ct_l3proto_try_module_get(ctx->afi->family);
345+
err = nft_ct_netns_get(ctx->net, ctx->afi->family);
346346
if (err < 0)
347347
return err;
348348

@@ -390,7 +390,7 @@ static int nft_ct_set_init(const struct nft_ctx *ctx,
390390
if (err < 0)
391391
goto err1;
392392

393-
err = nft_ct_l3proto_try_module_get(ctx->afi->family);
393+
err = nft_ct_netns_get(ctx->net, ctx->afi->family);
394394
if (err < 0)
395395
goto err1;
396396

@@ -405,7 +405,7 @@ static int nft_ct_set_init(const struct nft_ctx *ctx,
405405
static void nft_ct_get_destroy(const struct nft_ctx *ctx,
406406
const struct nft_expr *expr)
407407
{
408-
nft_ct_l3proto_module_put(ctx->afi->family);
408+
nf_ct_netns_put(ctx->net, ctx->afi->family);
409409
}
410410

411411
static void nft_ct_set_destroy(const struct nft_ctx *ctx,
@@ -423,7 +423,7 @@ static void nft_ct_set_destroy(const struct nft_ctx *ctx,
423423
break;
424424
}
425425

426-
nft_ct_l3proto_module_put(ctx->afi->family);
426+
nft_ct_netns_put(ctx->net, ctx->afi->family);
427427
}
428428

429429
static int nft_ct_get_dump(struct sk_buff *skb, const struct nft_expr *expr)

‎net/netfilter/xt_CONNSECMARK.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static int connsecmark_tg_check(const struct xt_tgchk_param *par)
106106
return -EINVAL;
107107
}
108108

109-
ret = nf_ct_l3proto_try_module_get(par->family);
109+
ret = nf_ct_netns_get(par->net, par->family);
110110
if (ret < 0)
111111
pr_info("cannot load conntrack support for proto=%u\n",
112112
par->family);
@@ -115,7 +115,7 @@ static int connsecmark_tg_check(const struct xt_tgchk_param *par)
115115

116116
static void connsecmark_tg_destroy(const struct xt_tgdtor_param *par)
117117
{
118-
nf_ct_l3proto_module_put(par->family);
118+
nf_ct_netns_put(par->net, par->family);
119119
}
120120

121121
static struct xt_target connsecmark_tg_reg __read_mostly = {

‎net/netfilter/xt_CT.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static int xt_ct_tg_check(const struct xt_tgchk_param *par,
216216
goto err1;
217217
#endif
218218

219-
ret = nf_ct_l3proto_try_module_get(par->family);
219+
ret = nf_ct_netns_get(par->net, par->family);
220220
if (ret < 0)
221221
goto err1;
222222

@@ -260,7 +260,7 @@ static int xt_ct_tg_check(const struct xt_tgchk_param *par,
260260
err3:
261261
nf_ct_tmpl_free(ct);
262262
err2:
263-
nf_ct_l3proto_module_put(par->family);
263+
nf_ct_netns_put(par->net, par->family);
264264
err1:
265265
return ret;
266266
}
@@ -341,7 +341,7 @@ static void xt_ct_tg_destroy(const struct xt_tgdtor_param *par,
341341
if (help)
342342
module_put(help->helper->me);
343343

344-
nf_ct_l3proto_module_put(par->family);
344+
nf_ct_netns_put(par->net, par->family);
345345

346346
xt_ct_destroy_timeout(ct);
347347
nf_ct_put(info->ct);

‎net/netfilter/xt_connbytes.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static int connbytes_mt_check(const struct xt_mtchk_param *par)
110110
sinfo->direction != XT_CONNBYTES_DIR_BOTH)
111111
return -EINVAL;
112112

113-
ret = nf_ct_l3proto_try_module_get(par->family);
113+
ret = nf_ct_netns_get(par->net, par->family);
114114
if (ret < 0)
115115
pr_info("cannot load conntrack support for proto=%u\n",
116116
par->family);
@@ -129,7 +129,7 @@ static int connbytes_mt_check(const struct xt_mtchk_param *par)
129129

130130
static void connbytes_mt_destroy(const struct xt_mtdtor_param *par)
131131
{
132-
nf_ct_l3proto_module_put(par->family);
132+
nf_ct_netns_put(par->net, par->family);
133133
}
134134

135135
static struct xt_match connbytes_mt_reg __read_mostly = {

‎net/netfilter/xt_connlabel.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static int connlabel_mt_check(const struct xt_mtchk_param *par)
6161
return -EINVAL;
6262
}
6363

64-
ret = nf_ct_l3proto_try_module_get(par->family);
64+
ret = nf_ct_netns_get(par->net, par->family);
6565
if (ret < 0) {
6666
pr_info("cannot load conntrack support for proto=%u\n",
6767
par->family);
@@ -70,14 +70,14 @@ static int connlabel_mt_check(const struct xt_mtchk_param *par)
7070

7171
ret = nf_connlabels_get(par->net, info->bit);
7272
if (ret < 0)
73-
nf_ct_l3proto_module_put(par->family);
73+
nf_ct_netns_put(par->net, par->family);
7474
return ret;
7575
}
7676

7777
static void connlabel_mt_destroy(const struct xt_mtdtor_param *par)
7878
{
7979
nf_connlabels_put(par->net);
80-
nf_ct_l3proto_module_put(par->family);
80+
nf_ct_netns_put(par->net, par->family);
8181
}
8282

8383
static struct xt_match connlabels_mt_reg __read_mostly = {

0 commit comments

Comments
 (0)