Commit 2a389de86e4a5d0bd3abed9e6fee27050652d339

Authored by Florian Westphal
Committed by Pablo Neira Ayuso
1 parent 70aed4647c

netfilter: conntrack: remove l4proto init and get_net callbacks

Those were needed we still had modular trackers.
As we don't have those anymore, prefer direct calls and remove all
the (un)register infrastructure associated with this.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

Showing 11 changed files with 65 additions and 234 deletions Side-by-side Diff

include/net/netfilter/nf_conntrack_l4proto.h
... ... @@ -61,12 +61,6 @@
61 61 /* Print out the private part of the conntrack. */
62 62 void (*print_conntrack)(struct seq_file *s, struct nf_conn *);
63 63 #endif
64   -
65   - /* Init l4proto pernet data */
66   - int (*init_net)(struct net *net);
67   -
68   - /* Return the per-net protocol part. */
69   - struct nf_proto_net *(*get_net_proto)(struct net *net);
70 64 };
71 65  
72 66 bool icmp_pkt_to_tuple(const struct sk_buff *skb,
... ... @@ -134,6 +128,15 @@
134 128 unsigned int dataoff,
135 129 enum ip_conntrack_info ctinfo,
136 130 const struct nf_hook_state *state);
  131 +
  132 +void nf_conntrack_generic_init_net(struct net *net);
  133 +void nf_conntrack_tcp_init_net(struct net *net);
  134 +void nf_conntrack_udp_init_net(struct net *net);
  135 +void nf_conntrack_gre_init_net(struct net *net);
  136 +void nf_conntrack_dccp_init_net(struct net *net);
  137 +void nf_conntrack_sctp_init_net(struct net *net);
  138 +void nf_conntrack_icmp_init_net(struct net *net);
  139 +void nf_conntrack_icmpv6_init_net(struct net *net);
137 140  
138 141 /* Existing built-in generic protocol */
139 142 extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_generic;
include/net/netns/conntrack.h
... ... @@ -18,17 +18,11 @@
18 18 struct ctl_table_header;
19 19 struct nf_conntrack_ecache;
20 20  
21   -struct nf_proto_net {
22   - unsigned int users;
23   -};
24   -
25 21 struct nf_generic_net {
26   - struct nf_proto_net pn;
27 22 unsigned int timeout;
28 23 };
29 24  
30 25 struct nf_tcp_net {
31   - struct nf_proto_net pn;
32 26 unsigned int timeouts[TCP_CONNTRACK_TIMEOUT_MAX];
33 27 unsigned int tcp_loose;
34 28 unsigned int tcp_be_liberal;
35 29  
36 30  
... ... @@ -42,18 +36,15 @@
42 36 };
43 37  
44 38 struct nf_udp_net {
45   - struct nf_proto_net pn;
46 39 unsigned int timeouts[UDP_CT_MAX];
47 40 };
48 41  
49 42 struct nf_icmp_net {
50   - struct nf_proto_net pn;
51 43 unsigned int timeout;
52 44 };
53 45  
54 46 #ifdef CONFIG_NF_CT_PROTO_DCCP
55 47 struct nf_dccp_net {
56   - struct nf_proto_net pn;
57 48 int dccp_loose;
58 49 unsigned int dccp_timeout[CT_DCCP_MAX + 1];
59 50 };
... ... @@ -61,7 +52,6 @@
61 52  
62 53 #ifdef CONFIG_NF_CT_PROTO_SCTP
63 54 struct nf_sctp_net {
64   - struct nf_proto_net pn;
65 55 unsigned int timeouts[SCTP_CONNTRACK_MAX];
66 56 };
67 57 #endif
... ... @@ -74,7 +64,6 @@
74 64 };
75 65  
76 66 struct nf_gre_net {
77   - struct nf_proto_net nf;
78 67 struct list_head keymap_list;
79 68 unsigned int timeouts[GRE_CT_MAX];
80 69 };
net/netfilter/nf_conntrack_proto.c
... ... @@ -123,15 +123,6 @@
123 123 return nf_ct_protonum(i) == l4proto->l4proto;
124 124 }
125 125  
126   -static struct nf_proto_net *nf_ct_l4proto_net(struct net *net,
127   - const struct nf_conntrack_l4proto *l4proto)
128   -{
129   - if (l4proto->get_net_proto)
130   - return l4proto->get_net_proto(net);
131   -
132   - return NULL;
133   -}
134   -
135 126 /* FIXME: Allow NULL functions and sub in pointers to generic for
136 127 them. --RR */
137 128 int nf_ct_l4proto_register_one(const struct nf_conntrack_l4proto *l4proto)
... ... @@ -158,27 +149,6 @@
158 149 }
159 150 EXPORT_SYMBOL_GPL(nf_ct_l4proto_register_one);
160 151  
161   -static int nf_ct_l4proto_pernet_register_one(struct net *net,
162   - const struct nf_conntrack_l4proto *l4proto)
163   -{
164   - int ret = 0;
165   - struct nf_proto_net *pn = NULL;
166   -
167   - if (l4proto->init_net) {
168   - ret = l4proto->init_net(net);
169   - if (ret < 0)
170   - goto out;
171   - }
172   -
173   - pn = nf_ct_l4proto_net(net, l4proto);
174   - if (pn == NULL)
175   - goto out;
176   -
177   - pn->users++;
178   -out:
179   - return ret;
180   -}
181   -
182 152 static void __nf_ct_l4proto_unregister_one(const struct nf_conntrack_l4proto *l4proto)
183 153  
184 154 {
... ... @@ -204,17 +174,6 @@
204 174 }
205 175 EXPORT_SYMBOL_GPL(nf_ct_l4proto_unregister_one);
206 176  
207   -static void nf_ct_l4proto_pernet_unregister_one(struct net *net,
208   - const struct nf_conntrack_l4proto *l4proto)
209   -{
210   - struct nf_proto_net *pn = nf_ct_l4proto_net(net, l4proto);
211   -
212   - if (pn == NULL)
213   - return;
214   -
215   - pn->users--;
216   -}
217   -
218 177 static void
219 178 nf_ct_l4proto_unregister(const struct nf_conntrack_l4proto * const l4proto[],
220 179 unsigned int num_proto)
... ... @@ -252,34 +211,6 @@
252 211 return ret;
253 212 }
254 213  
255   -static void nf_ct_l4proto_pernet_unregister(struct net *net,
256   - const struct nf_conntrack_l4proto *const l4proto[],
257   - unsigned int num_proto)
258   -{
259   - while (num_proto-- != 0)
260   - nf_ct_l4proto_pernet_unregister_one(net, l4proto[num_proto]);
261   -}
262   -
263   -static int nf_ct_l4proto_pernet_register(struct net *net,
264   - const struct nf_conntrack_l4proto *const l4proto[],
265   - unsigned int num_proto)
266   -{
267   - int ret = -EINVAL;
268   - unsigned int i;
269   -
270   - for (i = 0; i < num_proto; i++) {
271   - ret = nf_ct_l4proto_pernet_register_one(net, l4proto[i]);
272   - if (ret < 0)
273   - break;
274   - }
275   - if (i != num_proto) {
276   - pr_err("nf_conntrack %d: pernet registration failed\n",
277   - l4proto[i]->l4proto);
278   - nf_ct_l4proto_pernet_unregister(net, l4proto, i);
279   - }
280   - return ret;
281   -}
282   -
283 214 static unsigned int nf_confirm(struct sk_buff *skb,
284 215 unsigned int protoff,
285 216 struct nf_conn *ct,
286 217  
... ... @@ -784,31 +715,25 @@
784 715  
785 716 int nf_conntrack_proto_pernet_init(struct net *net)
786 717 {
787   - int err;
788   - struct nf_proto_net *pn = nf_ct_l4proto_net(net,
789   - &nf_conntrack_l4proto_generic);
790   -
791   - err = nf_conntrack_l4proto_generic.init_net(net);
792   - if (err < 0)
793   - return err;
794   -
795   - err = nf_ct_l4proto_pernet_register(net, builtin_l4proto,
796   - ARRAY_SIZE(builtin_l4proto));
797   - if (err < 0)
798   - return err;
799   -
800   - pn->users++;
  718 + nf_conntrack_generic_init_net(net);
  719 + nf_conntrack_udp_init_net(net);
  720 + nf_conntrack_tcp_init_net(net);
  721 + nf_conntrack_icmp_init_net(net);
  722 + nf_conntrack_icmpv6_init_net(net);
  723 +#ifdef CONFIG_NF_CT_PROTO_DCCP
  724 + nf_conntrack_dccp_init_net(net);
  725 +#endif
  726 +#ifdef CONFIG_NF_CT_PROTO_SCTP
  727 + nf_conntrack_sctp_init_net(net);
  728 +#endif
  729 +#ifdef CONFIG_NF_CT_PROTO_GRE
  730 + nf_conntrack_gre_init_net(net);
  731 +#endif
801 732 return 0;
802 733 }
803 734  
804 735 void nf_conntrack_proto_pernet_fini(struct net *net)
805 736 {
806   - struct nf_proto_net *pn = nf_ct_l4proto_net(net,
807   - &nf_conntrack_l4proto_generic);
808   -
809   - nf_ct_l4proto_pernet_unregister(net, builtin_l4proto,
810   - ARRAY_SIZE(builtin_l4proto));
811   - pn->users--;
812 737 #ifdef CONFIG_NF_CT_PROTO_GRE
813 738 nf_ct_gre_keymap_flush(net);
814 739 #endif
net/netfilter/nf_conntrack_proto_dccp.c
... ... @@ -724,36 +724,26 @@
724 724 };
725 725 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
726 726  
727   -static int dccp_init_net(struct net *net)
  727 +void nf_conntrack_dccp_init_net(struct net *net)
728 728 {
729 729 struct nf_dccp_net *dn = nf_dccp_pernet(net);
730   - struct nf_proto_net *pn = &dn->pn;
731 730  
732   - if (!pn->users) {
733   - /* default values */
734   - dn->dccp_loose = 1;
735   - dn->dccp_timeout[CT_DCCP_REQUEST] = 2 * DCCP_MSL;
736   - dn->dccp_timeout[CT_DCCP_RESPOND] = 4 * DCCP_MSL;
737   - dn->dccp_timeout[CT_DCCP_PARTOPEN] = 4 * DCCP_MSL;
738   - dn->dccp_timeout[CT_DCCP_OPEN] = 12 * 3600 * HZ;
739   - dn->dccp_timeout[CT_DCCP_CLOSEREQ] = 64 * HZ;
740   - dn->dccp_timeout[CT_DCCP_CLOSING] = 64 * HZ;
741   - dn->dccp_timeout[CT_DCCP_TIMEWAIT] = 2 * DCCP_MSL;
  731 + /* default values */
  732 + dn->dccp_loose = 1;
  733 + dn->dccp_timeout[CT_DCCP_REQUEST] = 2 * DCCP_MSL;
  734 + dn->dccp_timeout[CT_DCCP_RESPOND] = 4 * DCCP_MSL;
  735 + dn->dccp_timeout[CT_DCCP_PARTOPEN] = 4 * DCCP_MSL;
  736 + dn->dccp_timeout[CT_DCCP_OPEN] = 12 * 3600 * HZ;
  737 + dn->dccp_timeout[CT_DCCP_CLOSEREQ] = 64 * HZ;
  738 + dn->dccp_timeout[CT_DCCP_CLOSING] = 64 * HZ;
  739 + dn->dccp_timeout[CT_DCCP_TIMEWAIT] = 2 * DCCP_MSL;
742 740  
743   - /* timeouts[0] is unused, make it same as SYN_SENT so
744   - * ->timeouts[0] contains 'new' timeout, like udp or icmp.
745   - */
746   - dn->dccp_timeout[CT_DCCP_NONE] = dn->dccp_timeout[CT_DCCP_REQUEST];
747   - }
748   -
749   - return 0;
  741 + /* timeouts[0] is unused, make it same as SYN_SENT so
  742 + * ->timeouts[0] contains 'new' timeout, like udp or icmp.
  743 + */
  744 + dn->dccp_timeout[CT_DCCP_NONE] = dn->dccp_timeout[CT_DCCP_REQUEST];
750 745 }
751 746  
752   -static struct nf_proto_net *dccp_get_net_proto(struct net *net)
753   -{
754   - return &net->ct.nf_ct_proto.dccp.pn;
755   -}
756   -
757 747 const struct nf_conntrack_l4proto nf_conntrack_l4proto_dccp = {
758 748 .l4proto = IPPROTO_DCCP,
759 749 .can_early_drop = dccp_can_early_drop,
... ... @@ -778,7 +768,5 @@
778 768 .nla_policy = dccp_timeout_nla_policy,
779 769 },
780 770 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
781   - .init_net = dccp_init_net,
782   - .get_net_proto = dccp_get_net_proto,
783 771 };
net/netfilter/nf_conntrack_proto_generic.c
... ... @@ -60,20 +60,13 @@
60 60 };
61 61 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
62 62  
63   -static int generic_init_net(struct net *net)
  63 +void nf_conntrack_generic_init_net(struct net *net)
64 64 {
65 65 struct nf_generic_net *gn = nf_generic_pernet(net);
66 66  
67 67 gn->timeout = nf_ct_generic_timeout;
68   -
69   - return 0;
70 68 }
71 69  
72   -static struct nf_proto_net *generic_get_net_proto(struct net *net)
73   -{
74   - return &net->ct.nf_ct_proto.generic.pn;
75   -}
76   -
77 70 const struct nf_conntrack_l4proto nf_conntrack_l4proto_generic =
78 71 {
79 72 .l4proto = 255,
... ... @@ -86,7 +79,5 @@
86 79 .nla_policy = generic_timeout_nla_policy,
87 80 },
88 81 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
89   - .init_net = generic_init_net,
90   - .get_net_proto = generic_get_net_proto,
91 82 };
net/netfilter/nf_conntrack_proto_gre.c
... ... @@ -313,7 +313,7 @@
313 313 };
314 314 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
315 315  
316   -static int gre_init_net(struct net *net)
  316 +void nf_conntrack_gre_init_net(struct net *net)
317 317 {
318 318 struct nf_gre_net *net_gre = gre_pernet(net);
319 319 int i;
... ... @@ -321,8 +321,6 @@
321 321 INIT_LIST_HEAD(&net_gre->keymap_list);
322 322 for (i = 0; i < GRE_CT_MAX; i++)
323 323 net_gre->timeouts[i] = gre_timeouts[i];
324   -
325   - return 0;
326 324 }
327 325  
328 326 /* protocol helper struct */
... ... @@ -347,6 +345,5 @@
347 345 .nla_policy = gre_timeout_nla_policy,
348 346 },
349 347 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
350   - .init_net = gre_init_net,
351 348 };
net/netfilter/nf_conntrack_proto_icmp.c
... ... @@ -298,21 +298,13 @@
298 298 };
299 299 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
300 300  
301   -
302   -static int icmp_init_net(struct net *net)
  301 +void nf_conntrack_icmp_init_net(struct net *net)
303 302 {
304 303 struct nf_icmp_net *in = nf_icmp_pernet(net);
305 304  
306 305 in->timeout = nf_ct_icmp_timeout;
307   -
308   - return 0;
309 306 }
310 307  
311   -static struct nf_proto_net *icmp_get_net_proto(struct net *net)
312   -{
313   - return &net->ct.nf_ct_proto.icmp.pn;
314   -}
315   -
316 308 const struct nf_conntrack_l4proto nf_conntrack_l4proto_icmp =
317 309 {
318 310 .l4proto = IPPROTO_ICMP,
... ... @@ -331,7 +323,5 @@
331 323 .nla_policy = icmp_timeout_nla_policy,
332 324 },
333 325 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
334   - .init_net = icmp_init_net,
335   - .get_net_proto = icmp_get_net_proto,
336 326 };
net/netfilter/nf_conntrack_proto_icmpv6.c
... ... @@ -309,21 +309,13 @@
309 309 };
310 310 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
311 311  
312   -
313   -static int icmpv6_init_net(struct net *net)
  312 +void nf_conntrack_icmpv6_init_net(struct net *net)
314 313 {
315 314 struct nf_icmp_net *in = nf_icmpv6_pernet(net);
316 315  
317 316 in->timeout = nf_ct_icmpv6_timeout;
318   -
319   - return 0;
320 317 }
321 318  
322   -static struct nf_proto_net *icmpv6_get_net_proto(struct net *net)
323   -{
324   - return &net->ct.nf_ct_proto.icmpv6.pn;
325   -}
326   -
327 319 const struct nf_conntrack_l4proto nf_conntrack_l4proto_icmpv6 =
328 320 {
329 321 .l4proto = IPPROTO_ICMPV6,
... ... @@ -342,7 +334,5 @@
342 334 .nla_policy = icmpv6_timeout_nla_policy,
343 335 },
344 336 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
345   - .init_net = icmpv6_init_net,
346   - .get_net_proto = icmpv6_get_net_proto,
347 337 };
net/netfilter/nf_conntrack_proto_sctp.c
... ... @@ -642,31 +642,20 @@
642 642 };
643 643 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
644 644  
645   -static int sctp_init_net(struct net *net)
  645 +void nf_conntrack_sctp_init_net(struct net *net)
646 646 {
647 647 struct nf_sctp_net *sn = nf_sctp_pernet(net);
648   - struct nf_proto_net *pn = &sn->pn;
  648 + int i;
649 649  
650   - if (!pn->users) {
651   - int i;
  650 + for (i = 0; i < SCTP_CONNTRACK_MAX; i++)
  651 + sn->timeouts[i] = sctp_timeouts[i];
652 652  
653   - for (i = 0; i < SCTP_CONNTRACK_MAX; i++)
654   - sn->timeouts[i] = sctp_timeouts[i];
655   -
656   - /* timeouts[0] is unused, init it so ->timeouts[0] contains
657   - * 'new' timeout, like udp or icmp.
658   - */
659   - sn->timeouts[0] = sctp_timeouts[SCTP_CONNTRACK_CLOSED];
660   - }
661   -
662   - return 0;
  653 + /* timeouts[0] is unused, init it so ->timeouts[0] contains
  654 + * 'new' timeout, like udp or icmp.
  655 + */
  656 + sn->timeouts[0] = sctp_timeouts[SCTP_CONNTRACK_CLOSED];
663 657 }
664 658  
665   -static struct nf_proto_net *sctp_get_net_proto(struct net *net)
666   -{
667   - return &net->ct.nf_ct_proto.sctp.pn;
668   -}
669   -
670 659 const struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp = {
671 660 .l4proto = IPPROTO_SCTP,
672 661 #ifdef CONFIG_NF_CONNTRACK_PROCFS
... ... @@ -691,7 +680,5 @@
691 680 .nla_policy = sctp_timeout_nla_policy,
692 681 },
693 682 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
694   - .init_net = sctp_init_net,
695   - .get_net_proto = sctp_get_net_proto,
696 683 };
net/netfilter/nf_conntrack_proto_tcp.c
... ... @@ -1387,34 +1387,23 @@
1387 1387 };
1388 1388 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
1389 1389  
1390   -static int tcp_init_net(struct net *net)
  1390 +void nf_conntrack_tcp_init_net(struct net *net)
1391 1391 {
1392 1392 struct nf_tcp_net *tn = nf_tcp_pernet(net);
1393   - struct nf_proto_net *pn = &tn->pn;
  1393 + int i;
1394 1394  
1395   - if (!pn->users) {
1396   - int i;
  1395 + for (i = 0; i < TCP_CONNTRACK_TIMEOUT_MAX; i++)
  1396 + tn->timeouts[i] = tcp_timeouts[i];
1397 1397  
1398   - for (i = 0; i < TCP_CONNTRACK_TIMEOUT_MAX; i++)
1399   - tn->timeouts[i] = tcp_timeouts[i];
1400   -
1401   - /* timeouts[0] is unused, make it same as SYN_SENT so
1402   - * ->timeouts[0] contains 'new' timeout, like udp or icmp.
1403   - */
1404   - tn->timeouts[0] = tcp_timeouts[TCP_CONNTRACK_SYN_SENT];
1405   - tn->tcp_loose = nf_ct_tcp_loose;
1406   - tn->tcp_be_liberal = nf_ct_tcp_be_liberal;
1407   - tn->tcp_max_retrans = nf_ct_tcp_max_retrans;
1408   - }
1409   -
1410   - return 0;
  1398 + /* timeouts[0] is unused, make it same as SYN_SENT so
  1399 + * ->timeouts[0] contains 'new' timeout, like udp or icmp.
  1400 + */
  1401 + tn->timeouts[0] = tcp_timeouts[TCP_CONNTRACK_SYN_SENT];
  1402 + tn->tcp_loose = nf_ct_tcp_loose;
  1403 + tn->tcp_be_liberal = nf_ct_tcp_be_liberal;
  1404 + tn->tcp_max_retrans = nf_ct_tcp_max_retrans;
1411 1405 }
1412 1406  
1413   -static struct nf_proto_net *tcp_get_net_proto(struct net *net)
1414   -{
1415   - return &net->ct.nf_ct_proto.tcp.pn;
1416   -}
1417   -
1418 1407 const struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp =
1419 1408 {
1420 1409 .l4proto = IPPROTO_TCP,
... ... @@ -1441,7 +1430,5 @@
1441 1430 .nla_policy = tcp_timeout_nla_policy,
1442 1431 },
1443 1432 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
1444   - .init_net = tcp_init_net,
1445   - .get_net_proto = tcp_get_net_proto,
1446 1433 };
net/netfilter/nf_conntrack_proto_udp.c
... ... @@ -260,27 +260,15 @@
260 260 };
261 261 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
262 262  
263   -
264   -static int udp_init_net(struct net *net)
  263 +void nf_conntrack_udp_init_net(struct net *net)
265 264 {
266 265 struct nf_udp_net *un = nf_udp_pernet(net);
267   - struct nf_proto_net *pn = &un->pn;
  266 + int i;
268 267  
269   - if (!pn->users) {
270   - int i;
271   -
272   - for (i = 0; i < UDP_CT_MAX; i++)
273   - un->timeouts[i] = udp_timeouts[i];
274   - }
275   -
276   - return 0;
  268 + for (i = 0; i < UDP_CT_MAX; i++)
  269 + un->timeouts[i] = udp_timeouts[i];
277 270 }
278 271  
279   -static struct nf_proto_net *udp_get_net_proto(struct net *net)
280   -{
281   - return &net->ct.nf_ct_proto.udp.pn;
282   -}
283   -
284 272 const struct nf_conntrack_l4proto nf_conntrack_l4proto_udp =
285 273 {
286 274 .l4proto = IPPROTO_UDP,
... ... @@ -300,8 +288,6 @@
300 288 .nla_policy = udp_timeout_nla_policy,
301 289 },
302 290 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
303   - .init_net = udp_init_net,
304   - .get_net_proto = udp_get_net_proto,
305 291 };
306 292  
307 293 #ifdef CONFIG_NF_CT_PROTO_UDPLITE
... ... @@ -324,8 +310,6 @@
324 310 .nla_policy = udp_timeout_nla_policy,
325 311 },
326 312 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
327   - .init_net = udp_init_net,
328   - .get_net_proto = udp_get_net_proto,
329 313 };
330 314 #endif