Skip to content

Commit 22fc4c4

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: conntrack: gre: switch module to be built-in
This makes the last of the modular l4 trackers 'bool'. After this, all infrastructure to handle dynamic l4 protocol registration becomes obsolete and can be removed in followup patches. Old: 302824 net/netfilter/nf_conntrack.ko 21504 net/netfilter/nf_conntrack_proto_gre.ko New: 313728 net/netfilter/nf_conntrack.ko Old: text data bss dec hex filename 6281 1732 4 8017 1f51 nf_conntrack_proto_gre.ko 108356 20613 236 129205 1f8b5 nf_conntrack.ko New: 112095 21381 240 133716 20a54 nf_conntrack.ko The size increase is only temporary. Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 202e651 commit 22fc4c4

9 files changed

Lines changed: 55 additions & 98 deletions

File tree

‎include/linux/netfilter/nf_conntrack_proto_gre.h‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,11 @@ struct nf_ct_gre_keymap {
2222
struct rcu_head rcu;
2323
};
2424

25-
enum grep_conntrack {
26-
GRE_CT_UNREPLIED,
27-
GRE_CT_REPLIED,
28-
GRE_CT_MAX
29-
};
30-
31-
struct netns_proto_gre {
32-
struct nf_proto_net nf;
33-
rwlock_t keymap_lock;
34-
struct list_head keymap_list;
35-
unsigned int gre_timeouts[GRE_CT_MAX];
36-
};
37-
3825
/* add new tuple->key_reply pair to keymap */
3926
int nf_ct_gre_keymap_add(struct nf_conn *ct, enum ip_conntrack_dir dir,
4027
struct nf_conntrack_tuple *t);
4128

29+
void nf_ct_gre_keymap_flush(struct net *net);
4230
/* delete keymap entries */
4331
void nf_ct_gre_keymap_destroy(struct nf_conn *ct);
4432

‎include/net/netfilter/ipv4/nf_conntrack_ipv4.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@ extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp;
2222
#ifdef CONFIG_NF_CT_PROTO_UDPLITE
2323
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite;
2424
#endif
25+
#ifdef CONFIG_NF_CT_PROTO_GRE
26+
extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_gre;
27+
#endif
2528

2629
#endif /*_NF_CONNTRACK_IPV4_H*/

‎include/net/netfilter/nf_conntrack_l4proto.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,11 @@ static inline struct nf_sctp_net *nf_sctp_pernet(struct net *net)
239239
}
240240
#endif
241241

242+
#ifdef CONFIG_NF_CT_PROTO_GRE
243+
static inline struct nf_gre_net *nf_gre_pernet(struct net *net)
244+
{
245+
return &net->ct.nf_ct_proto.gre;
246+
}
247+
#endif
248+
242249
#endif /*_NF_CONNTRACK_PROTOCOL_H*/

‎include/net/netns/conntrack.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@ struct nf_sctp_net {
7070
};
7171
#endif
7272

73+
#ifdef CONFIG_NF_CT_PROTO_GRE
74+
enum gre_conntrack {
75+
GRE_CT_UNREPLIED,
76+
GRE_CT_REPLIED,
77+
GRE_CT_MAX
78+
};
79+
80+
struct nf_gre_net {
81+
struct nf_proto_net nf;
82+
struct list_head keymap_list;
83+
unsigned int timeouts[GRE_CT_MAX];
84+
};
85+
#endif
86+
7387
struct nf_ip_net {
7488
struct nf_generic_net generic;
7589
struct nf_tcp_net tcp;
@@ -82,6 +96,9 @@ struct nf_ip_net {
8296
#ifdef CONFIG_NF_CT_PROTO_SCTP
8397
struct nf_sctp_net sctp;
8498
#endif
99+
#ifdef CONFIG_NF_CT_PROTO_GRE
100+
struct nf_gre_net gre;
101+
#endif
85102
};
86103

87104
struct ct_pcpu {

‎net/netfilter/Kconfig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ config NF_CT_PROTO_DCCP
174174
If unsure, say Y.
175175

176176
config NF_CT_PROTO_GRE
177-
tristate
177+
bool
178178

179179
config NF_CT_PROTO_SCTP
180180
bool 'SCTP protocol connection tracking support'

‎net/netfilter/Makefile‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ nf_conntrack-$(CONFIG_NF_CONNTRACK_EVENTS) += nf_conntrack_ecache.o
1313
nf_conntrack-$(CONFIG_NF_CONNTRACK_LABELS) += nf_conntrack_labels.o
1414
nf_conntrack-$(CONFIG_NF_CT_PROTO_DCCP) += nf_conntrack_proto_dccp.o
1515
nf_conntrack-$(CONFIG_NF_CT_PROTO_SCTP) += nf_conntrack_proto_sctp.o
16+
nf_conntrack-$(CONFIG_NF_CT_PROTO_GRE) += nf_conntrack_proto_gre.o
1617

1718
obj-$(CONFIG_NETFILTER) = netfilter.o
1819

@@ -25,8 +26,6 @@ obj-$(CONFIG_NETFILTER_NETLINK_OSF) += nfnetlink_osf.o
2526
# connection tracking
2627
obj-$(CONFIG_NF_CONNTRACK) += nf_conntrack.o
2728

28-
obj-$(CONFIG_NF_CT_PROTO_GRE) += nf_conntrack_proto_gre.o
29-
3029
# netlink interface for nf_conntrack
3130
obj-$(CONFIG_NF_CT_NETLINK) += nf_conntrack_netlink.o
3231
obj-$(CONFIG_NF_CT_NETLINK_TIMEOUT) += nfnetlink_cttimeout.o

‎net/netfilter/nf_conntrack_proto.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,9 @@ static const struct nf_conntrack_l4proto * const builtin_l4proto[] = {
817817
#ifdef CONFIG_NF_CT_PROTO_UDPLITE
818818
&nf_conntrack_l4proto_udplite,
819819
#endif
820+
#ifdef CONFIG_NF_CT_PROTO_GRE
821+
&nf_conntrack_l4proto_gre,
822+
#endif
820823
#if IS_ENABLED(CONFIG_IPV6)
821824
&nf_conntrack_l4proto_icmpv6,
822825
#endif /* CONFIG_IPV6 */
@@ -897,9 +900,11 @@ void nf_conntrack_proto_pernet_fini(struct net *net)
897900
ARRAY_SIZE(builtin_l4proto));
898901
pn->users--;
899902
nf_ct_l4proto_unregister_sysctl(pn);
903+
#ifdef CONFIG_NF_CT_PROTO_GRE
904+
nf_ct_gre_keymap_flush(net);
905+
#endif
900906
}
901907

902-
903908
module_param_call(hashsize, nf_conntrack_set_hashsize, param_get_uint,
904909
&nf_conntrack_htable_size, 0600);
905910

‎net/netfilter/nf_conntrack_proto_gre.c‎

Lines changed: 18 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,17 @@ static const unsigned int gre_timeouts[GRE_CT_MAX] = {
4848
[GRE_CT_REPLIED] = 180*HZ,
4949
};
5050

51-
static unsigned int proto_gre_net_id __read_mostly;
5251
/* used when expectation is added */
5352
static DEFINE_SPINLOCK(keymap_lock);
5453

55-
static inline struct netns_proto_gre *gre_pernet(struct net *net)
54+
static inline struct nf_gre_net *gre_pernet(struct net *net)
5655
{
57-
return net_generic(net, proto_gre_net_id);
56+
return &net->ct.nf_ct_proto.gre;
5857
}
5958

60-
static void nf_ct_gre_keymap_flush(struct net *net)
59+
void nf_ct_gre_keymap_flush(struct net *net)
6160
{
62-
struct netns_proto_gre *net_gre = gre_pernet(net);
61+
struct nf_gre_net *net_gre = gre_pernet(net);
6362
struct nf_ct_gre_keymap *km, *tmp;
6463

6564
spin_lock_bh(&keymap_lock);
@@ -83,7 +82,7 @@ static inline int gre_key_cmpfn(const struct nf_ct_gre_keymap *km,
8382
/* look up the source key for a given tuple */
8483
static __be16 gre_keymap_lookup(struct net *net, struct nf_conntrack_tuple *t)
8584
{
86-
struct netns_proto_gre *net_gre = gre_pernet(net);
85+
struct nf_gre_net *net_gre = gre_pernet(net);
8786
struct nf_ct_gre_keymap *km;
8887
__be16 key = 0;
8988

@@ -105,7 +104,7 @@ int nf_ct_gre_keymap_add(struct nf_conn *ct, enum ip_conntrack_dir dir,
105104
struct nf_conntrack_tuple *t)
106105
{
107106
struct net *net = nf_ct_net(ct);
108-
struct netns_proto_gre *net_gre = gre_pernet(net);
107+
struct nf_gre_net *net_gre = gre_pernet(net);
109108
struct nf_ct_pptp_master *ct_pptp_info = nfct_help_data(ct);
110109
struct nf_ct_gre_keymap **kmp, *km;
111110

@@ -210,7 +209,7 @@ static void gre_print_conntrack(struct seq_file *s, struct nf_conn *ct)
210209

211210
static unsigned int *gre_get_timeouts(struct net *net)
212211
{
213-
return gre_pernet(net)->gre_timeouts;
212+
return gre_pernet(net)->timeouts;
214213
}
215214

216215
/* Returns verdict for packet, and may modify conntrack */
@@ -272,13 +271,13 @@ static int gre_timeout_nlattr_to_obj(struct nlattr *tb[],
272271
struct net *net, void *data)
273272
{
274273
unsigned int *timeouts = data;
275-
struct netns_proto_gre *net_gre = gre_pernet(net);
274+
struct nf_gre_net *net_gre = gre_pernet(net);
276275

277276
if (!timeouts)
278277
timeouts = gre_get_timeouts(net);
279278
/* set default timeouts for GRE. */
280-
timeouts[GRE_CT_UNREPLIED] = net_gre->gre_timeouts[GRE_CT_UNREPLIED];
281-
timeouts[GRE_CT_REPLIED] = net_gre->gre_timeouts[GRE_CT_REPLIED];
279+
timeouts[GRE_CT_UNREPLIED] = net_gre->timeouts[GRE_CT_UNREPLIED];
280+
timeouts[GRE_CT_REPLIED] = net_gre->timeouts[GRE_CT_REPLIED];
282281

283282
if (tb[CTA_TIMEOUT_GRE_UNREPLIED]) {
284283
timeouts[GRE_CT_UNREPLIED] =
@@ -332,10 +331,11 @@ static struct ctl_table gre_sysctl_table[] = {
332331
};
333332
#endif
334333

335-
static int gre_kmemdup_sysctl_table(struct net *net, struct nf_proto_net *nf,
336-
struct netns_proto_gre *net_gre)
334+
static int gre_kmemdup_sysctl_table(struct net *net)
337335
{
338336
#ifdef CONFIG_SYSCTL
337+
struct nf_gre_net *net_gre = gre_pernet(net);
338+
struct nf_proto_net *nf = &net_gre->nf;
339339
int i;
340340

341341
if (nf->ctl_table)
@@ -348,26 +348,25 @@ static int gre_kmemdup_sysctl_table(struct net *net, struct nf_proto_net *nf,
348348
return -ENOMEM;
349349

350350
for (i = 0; i < GRE_CT_MAX; i++)
351-
nf->ctl_table[i].data = &net_gre->gre_timeouts[i];
351+
nf->ctl_table[i].data = &net_gre->timeouts[i];
352352
#endif
353353
return 0;
354354
}
355355

356356
static int gre_init_net(struct net *net)
357357
{
358-
struct netns_proto_gre *net_gre = gre_pernet(net);
359-
struct nf_proto_net *nf = &net_gre->nf;
358+
struct nf_gre_net *net_gre = gre_pernet(net);
360359
int i;
361360

362361
INIT_LIST_HEAD(&net_gre->keymap_list);
363362
for (i = 0; i < GRE_CT_MAX; i++)
364-
net_gre->gre_timeouts[i] = gre_timeouts[i];
363+
net_gre->timeouts[i] = gre_timeouts[i];
365364

366-
return gre_kmemdup_sysctl_table(net, nf, net_gre);
365+
return gre_kmemdup_sysctl_table(net);
367366
}
368367

369368
/* protocol helper struct */
370-
static const struct nf_conntrack_l4proto nf_conntrack_l4proto_gre4 = {
369+
const struct nf_conntrack_l4proto nf_conntrack_l4proto_gre = {
371370
.l4proto = IPPROTO_GRE,
372371
.pkt_to_tuple = gre_pkt_to_tuple,
373372
#ifdef CONFIG_NF_CONNTRACK_PROCFS
@@ -391,61 +390,5 @@ static const struct nf_conntrack_l4proto nf_conntrack_l4proto_gre4 = {
391390
.nla_policy = gre_timeout_nla_policy,
392391
},
393392
#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
394-
.net_id = &proto_gre_net_id,
395393
.init_net = gre_init_net,
396394
};
397-
398-
static int proto_gre_net_init(struct net *net)
399-
{
400-
int ret = 0;
401-
402-
ret = nf_ct_l4proto_pernet_register_one(net,
403-
&nf_conntrack_l4proto_gre4);
404-
if (ret < 0)
405-
pr_err("nf_conntrack_gre4: pernet registration failed.\n");
406-
return ret;
407-
}
408-
409-
static void proto_gre_net_exit(struct net *net)
410-
{
411-
nf_ct_l4proto_pernet_unregister_one(net, &nf_conntrack_l4proto_gre4);
412-
nf_ct_gre_keymap_flush(net);
413-
}
414-
415-
static struct pernet_operations proto_gre_net_ops = {
416-
.init = proto_gre_net_init,
417-
.exit = proto_gre_net_exit,
418-
.id = &proto_gre_net_id,
419-
.size = sizeof(struct netns_proto_gre),
420-
};
421-
422-
static int __init nf_ct_proto_gre_init(void)
423-
{
424-
int ret;
425-
426-
BUILD_BUG_ON(offsetof(struct netns_proto_gre, nf) != 0);
427-
428-
ret = register_pernet_subsys(&proto_gre_net_ops);
429-
if (ret < 0)
430-
goto out_pernet;
431-
ret = nf_ct_l4proto_register_one(&nf_conntrack_l4proto_gre4);
432-
if (ret < 0)
433-
goto out_gre4;
434-
435-
return 0;
436-
out_gre4:
437-
unregister_pernet_subsys(&proto_gre_net_ops);
438-
out_pernet:
439-
return ret;
440-
}
441-
442-
static void __exit nf_ct_proto_gre_fini(void)
443-
{
444-
nf_ct_l4proto_unregister_one(&nf_conntrack_l4proto_gre4);
445-
unregister_pernet_subsys(&proto_gre_net_ops);
446-
}
447-
448-
module_init(nf_ct_proto_gre_init);
449-
module_exit(nf_ct_proto_gre_fini);
450-
451-
MODULE_LICENSE("GPL");

‎net/netfilter/nfnetlink_cttimeout.c‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,7 @@ static int cttimeout_default_get(struct net *net, struct sock *ctnl,
474474
break;
475475
case IPPROTO_GRE:
476476
#ifdef CONFIG_NF_CT_PROTO_GRE
477-
if (l4proto->net_id) {
478-
struct netns_proto_gre *net_gre;
479-
480-
net_gre = net_generic(net, *l4proto->net_id);
481-
timeouts = net_gre->gre_timeouts;
482-
}
477+
timeouts = nf_gre_pernet(net)->timeouts;
483478
#endif
484479
break;
485480
case 255:

0 commit comments

Comments
 (0)