Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next
[linux-2.6-microblaze.git] / net / netfilter / nfnetlink_cttimeout.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * (C) 2012 by Pablo Neira Ayuso <pablo@netfilter.org>
4  * (C) 2012 by Vyatta Inc. <http://www.vyatta.com>
5  */
6 #include <linux/init.h>
7 #include <linux/module.h>
8 #include <linux/kernel.h>
9 #include <linux/rculist.h>
10 #include <linux/rculist_nulls.h>
11 #include <linux/types.h>
12 #include <linux/timer.h>
13 #include <linux/security.h>
14 #include <linux/skbuff.h>
15 #include <linux/errno.h>
16 #include <linux/netlink.h>
17 #include <linux/spinlock.h>
18 #include <linux/interrupt.h>
19 #include <linux/slab.h>
20
21 #include <linux/netfilter.h>
22 #include <net/netlink.h>
23 #include <net/netns/generic.h>
24 #include <net/sock.h>
25 #include <net/netfilter/nf_conntrack.h>
26 #include <net/netfilter/nf_conntrack_core.h>
27 #include <net/netfilter/nf_conntrack_l4proto.h>
28 #include <net/netfilter/nf_conntrack_tuple.h>
29 #include <net/netfilter/nf_conntrack_timeout.h>
30
31 #include <linux/netfilter/nfnetlink.h>
32 #include <linux/netfilter/nfnetlink_cttimeout.h>
33
34 static unsigned int nfct_timeout_id __read_mostly;
35
36 struct nfct_timeout_pernet {
37         struct list_head        nfct_timeout_list;
38 };
39
40 MODULE_LICENSE("GPL");
41 MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>");
42 MODULE_DESCRIPTION("cttimeout: Extended Netfilter Connection Tracking timeout tuning");
43
44 static const struct nla_policy cttimeout_nla_policy[CTA_TIMEOUT_MAX+1] = {
45         [CTA_TIMEOUT_NAME]      = { .type = NLA_NUL_STRING,
46                                     .len  = CTNL_TIMEOUT_NAME_MAX - 1},
47         [CTA_TIMEOUT_L3PROTO]   = { .type = NLA_U16 },
48         [CTA_TIMEOUT_L4PROTO]   = { .type = NLA_U8 },
49         [CTA_TIMEOUT_DATA]      = { .type = NLA_NESTED },
50 };
51
52 static struct nfct_timeout_pernet *nfct_timeout_pernet(struct net *net)
53 {
54         return net_generic(net, nfct_timeout_id);
55 }
56
57 static int
58 ctnl_timeout_parse_policy(void *timeout,
59                           const struct nf_conntrack_l4proto *l4proto,
60                           struct net *net, const struct nlattr *attr)
61 {
62         struct nlattr **tb;
63         int ret = 0;
64
65         tb = kcalloc(l4proto->ctnl_timeout.nlattr_max + 1, sizeof(*tb),
66                      GFP_KERNEL);
67
68         if (!tb)
69                 return -ENOMEM;
70
71         ret = nla_parse_nested_deprecated(tb,
72                                           l4proto->ctnl_timeout.nlattr_max,
73                                           attr,
74                                           l4proto->ctnl_timeout.nla_policy,
75                                           NULL);
76         if (ret < 0)
77                 goto err;
78
79         ret = l4proto->ctnl_timeout.nlattr_to_obj(tb, net, timeout);
80
81 err:
82         kfree(tb);
83         return ret;
84 }
85
86 static int cttimeout_new_timeout(struct net *net, struct sock *ctnl,
87                                  struct sk_buff *skb,
88                                  const struct nlmsghdr *nlh,
89                                  const struct nlattr * const cda[],
90                                  struct netlink_ext_ack *extack)
91 {
92         struct nfct_timeout_pernet *pernet = nfct_timeout_pernet(net);
93         __u16 l3num;
94         __u8 l4num;
95         const struct nf_conntrack_l4proto *l4proto;
96         struct ctnl_timeout *timeout, *matching = NULL;
97         char *name;
98         int ret;
99
100         if (!cda[CTA_TIMEOUT_NAME] ||
101             !cda[CTA_TIMEOUT_L3PROTO] ||
102             !cda[CTA_TIMEOUT_L4PROTO] ||
103             !cda[CTA_TIMEOUT_DATA])
104                 return -EINVAL;
105
106         name = nla_data(cda[CTA_TIMEOUT_NAME]);
107         l3num = ntohs(nla_get_be16(cda[CTA_TIMEOUT_L3PROTO]));
108         l4num = nla_get_u8(cda[CTA_TIMEOUT_L4PROTO]);
109
110         list_for_each_entry(timeout, &pernet->nfct_timeout_list, head) {
111                 if (strncmp(timeout->name, name, CTNL_TIMEOUT_NAME_MAX) != 0)
112                         continue;
113
114                 if (nlh->nlmsg_flags & NLM_F_EXCL)
115                         return -EEXIST;
116
117                 matching = timeout;
118                 break;
119         }
120
121         if (matching) {
122                 if (nlh->nlmsg_flags & NLM_F_REPLACE) {
123                         /* You cannot replace one timeout policy by another of
124                          * different kind, sorry.
125                          */
126                         if (matching->timeout.l3num != l3num ||
127                             matching->timeout.l4proto->l4proto != l4num)
128                                 return -EINVAL;
129
130                         return ctnl_timeout_parse_policy(&matching->timeout.data,
131                                                          matching->timeout.l4proto,
132                                                          net, cda[CTA_TIMEOUT_DATA]);
133                 }
134
135                 return -EBUSY;
136         }
137
138         l4proto = nf_ct_l4proto_find(l4num);
139
140         /* This protocol is not supportted, skip. */
141         if (l4proto->l4proto != l4num) {
142                 ret = -EOPNOTSUPP;
143                 goto err_proto_put;
144         }
145
146         timeout = kzalloc(sizeof(struct ctnl_timeout) +
147                           l4proto->ctnl_timeout.obj_size, GFP_KERNEL);
148         if (timeout == NULL) {
149                 ret = -ENOMEM;
150                 goto err_proto_put;
151         }
152
153         ret = ctnl_timeout_parse_policy(&timeout->timeout.data, l4proto, net,
154                                         cda[CTA_TIMEOUT_DATA]);
155         if (ret < 0)
156                 goto err;
157
158         strcpy(timeout->name, nla_data(cda[CTA_TIMEOUT_NAME]));
159         timeout->timeout.l3num = l3num;
160         timeout->timeout.l4proto = l4proto;
161         refcount_set(&timeout->refcnt, 1);
162         list_add_tail_rcu(&timeout->head, &pernet->nfct_timeout_list);
163
164         return 0;
165 err:
166         kfree(timeout);
167 err_proto_put:
168         return ret;
169 }
170
171 static int
172 ctnl_timeout_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type,
173                        int event, struct ctnl_timeout *timeout)
174 {
175         struct nlmsghdr *nlh;
176         unsigned int flags = portid ? NLM_F_MULTI : 0;
177         const struct nf_conntrack_l4proto *l4proto = timeout->timeout.l4proto;
178         struct nlattr *nest_parms;
179         int ret;
180
181         event = nfnl_msg_type(NFNL_SUBSYS_CTNETLINK_TIMEOUT, event);
182         nlh = nfnl_msg_put(skb, portid, seq, event, flags, AF_UNSPEC,
183                            NFNETLINK_V0, 0);
184         if (!nlh)
185                 goto nlmsg_failure;
186
187         if (nla_put_string(skb, CTA_TIMEOUT_NAME, timeout->name) ||
188             nla_put_be16(skb, CTA_TIMEOUT_L3PROTO,
189                          htons(timeout->timeout.l3num)) ||
190             nla_put_u8(skb, CTA_TIMEOUT_L4PROTO, l4proto->l4proto) ||
191             nla_put_be32(skb, CTA_TIMEOUT_USE,
192                          htonl(refcount_read(&timeout->refcnt))))
193                 goto nla_put_failure;
194
195         nest_parms = nla_nest_start(skb, CTA_TIMEOUT_DATA);
196         if (!nest_parms)
197                 goto nla_put_failure;
198
199         ret = l4proto->ctnl_timeout.obj_to_nlattr(skb, &timeout->timeout.data);
200         if (ret < 0)
201                 goto nla_put_failure;
202
203         nla_nest_end(skb, nest_parms);
204
205         nlmsg_end(skb, nlh);
206         return skb->len;
207
208 nlmsg_failure:
209 nla_put_failure:
210         nlmsg_cancel(skb, nlh);
211         return -1;
212 }
213
214 static int
215 ctnl_timeout_dump(struct sk_buff *skb, struct netlink_callback *cb)
216 {
217         struct nfct_timeout_pernet *pernet;
218         struct net *net = sock_net(skb->sk);
219         struct ctnl_timeout *cur, *last;
220
221         if (cb->args[2])
222                 return 0;
223
224         last = (struct ctnl_timeout *)cb->args[1];
225         if (cb->args[1])
226                 cb->args[1] = 0;
227
228         rcu_read_lock();
229         pernet = nfct_timeout_pernet(net);
230         list_for_each_entry_rcu(cur, &pernet->nfct_timeout_list, head) {
231                 if (last) {
232                         if (cur != last)
233                                 continue;
234
235                         last = NULL;
236                 }
237                 if (ctnl_timeout_fill_info(skb, NETLINK_CB(cb->skb).portid,
238                                            cb->nlh->nlmsg_seq,
239                                            NFNL_MSG_TYPE(cb->nlh->nlmsg_type),
240                                            IPCTNL_MSG_TIMEOUT_NEW, cur) < 0) {
241                         cb->args[1] = (unsigned long)cur;
242                         break;
243                 }
244         }
245         if (!cb->args[1])
246                 cb->args[2] = 1;
247         rcu_read_unlock();
248         return skb->len;
249 }
250
251 static int cttimeout_get_timeout(struct net *net, struct sock *ctnl,
252                                  struct sk_buff *skb,
253                                  const struct nlmsghdr *nlh,
254                                  const struct nlattr * const cda[],
255                                  struct netlink_ext_ack *extack)
256 {
257         struct nfct_timeout_pernet *pernet = nfct_timeout_pernet(net);
258         int ret = -ENOENT;
259         char *name;
260         struct ctnl_timeout *cur;
261
262         if (nlh->nlmsg_flags & NLM_F_DUMP) {
263                 struct netlink_dump_control c = {
264                         .dump = ctnl_timeout_dump,
265                 };
266                 return netlink_dump_start(ctnl, skb, nlh, &c);
267         }
268
269         if (!cda[CTA_TIMEOUT_NAME])
270                 return -EINVAL;
271         name = nla_data(cda[CTA_TIMEOUT_NAME]);
272
273         list_for_each_entry(cur, &pernet->nfct_timeout_list, head) {
274                 struct sk_buff *skb2;
275
276                 if (strncmp(cur->name, name, CTNL_TIMEOUT_NAME_MAX) != 0)
277                         continue;
278
279                 skb2 = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
280                 if (skb2 == NULL) {
281                         ret = -ENOMEM;
282                         break;
283                 }
284
285                 ret = ctnl_timeout_fill_info(skb2, NETLINK_CB(skb).portid,
286                                              nlh->nlmsg_seq,
287                                              NFNL_MSG_TYPE(nlh->nlmsg_type),
288                                              IPCTNL_MSG_TIMEOUT_NEW, cur);
289                 if (ret <= 0) {
290                         kfree_skb(skb2);
291                         break;
292                 }
293                 ret = netlink_unicast(ctnl, skb2, NETLINK_CB(skb).portid,
294                                         MSG_DONTWAIT);
295                 if (ret > 0)
296                         ret = 0;
297
298                 /* this avoids a loop in nfnetlink. */
299                 return ret == -EAGAIN ? -ENOBUFS : ret;
300         }
301         return ret;
302 }
303
304 /* try to delete object, fail if it is still in use. */
305 static int ctnl_timeout_try_del(struct net *net, struct ctnl_timeout *timeout)
306 {
307         int ret = 0;
308
309         /* We want to avoid races with ctnl_timeout_put. So only when the
310          * current refcnt is 1, we decrease it to 0.
311          */
312         if (refcount_dec_if_one(&timeout->refcnt)) {
313                 /* We are protected by nfnl mutex. */
314                 list_del_rcu(&timeout->head);
315                 nf_ct_untimeout(net, &timeout->timeout);
316                 kfree_rcu(timeout, rcu_head);
317         } else {
318                 ret = -EBUSY;
319         }
320         return ret;
321 }
322
323 static int cttimeout_del_timeout(struct net *net, struct sock *ctnl,
324                                  struct sk_buff *skb,
325                                  const struct nlmsghdr *nlh,
326                                  const struct nlattr * const cda[],
327                                  struct netlink_ext_ack *extack)
328 {
329         struct nfct_timeout_pernet *pernet = nfct_timeout_pernet(net);
330         struct ctnl_timeout *cur, *tmp;
331         int ret = -ENOENT;
332         char *name;
333
334         if (!cda[CTA_TIMEOUT_NAME]) {
335                 list_for_each_entry_safe(cur, tmp, &pernet->nfct_timeout_list,
336                                          head)
337                         ctnl_timeout_try_del(net, cur);
338
339                 return 0;
340         }
341         name = nla_data(cda[CTA_TIMEOUT_NAME]);
342
343         list_for_each_entry(cur, &pernet->nfct_timeout_list, head) {
344                 if (strncmp(cur->name, name, CTNL_TIMEOUT_NAME_MAX) != 0)
345                         continue;
346
347                 ret = ctnl_timeout_try_del(net, cur);
348                 if (ret < 0)
349                         return ret;
350
351                 break;
352         }
353         return ret;
354 }
355
356 static int cttimeout_default_set(struct net *net, struct sock *ctnl,
357                                  struct sk_buff *skb,
358                                  const struct nlmsghdr *nlh,
359                                  const struct nlattr * const cda[],
360                                  struct netlink_ext_ack *extack)
361 {
362         const struct nf_conntrack_l4proto *l4proto;
363         __u8 l4num;
364         int ret;
365
366         if (!cda[CTA_TIMEOUT_L3PROTO] ||
367             !cda[CTA_TIMEOUT_L4PROTO] ||
368             !cda[CTA_TIMEOUT_DATA])
369                 return -EINVAL;
370
371         l4num = nla_get_u8(cda[CTA_TIMEOUT_L4PROTO]);
372         l4proto = nf_ct_l4proto_find(l4num);
373
374         /* This protocol is not supported, skip. */
375         if (l4proto->l4proto != l4num) {
376                 ret = -EOPNOTSUPP;
377                 goto err;
378         }
379
380         ret = ctnl_timeout_parse_policy(NULL, l4proto, net,
381                                         cda[CTA_TIMEOUT_DATA]);
382         if (ret < 0)
383                 goto err;
384
385         return 0;
386 err:
387         return ret;
388 }
389
390 static int
391 cttimeout_default_fill_info(struct net *net, struct sk_buff *skb, u32 portid,
392                             u32 seq, u32 type, int event, u16 l3num,
393                             const struct nf_conntrack_l4proto *l4proto,
394                             const unsigned int *timeouts)
395 {
396         struct nlmsghdr *nlh;
397         unsigned int flags = portid ? NLM_F_MULTI : 0;
398         struct nlattr *nest_parms;
399         int ret;
400
401         event = nfnl_msg_type(NFNL_SUBSYS_CTNETLINK_TIMEOUT, event);
402         nlh = nfnl_msg_put(skb, portid, seq, event, flags, AF_UNSPEC,
403                            NFNETLINK_V0, 0);
404         if (!nlh)
405                 goto nlmsg_failure;
406
407         if (nla_put_be16(skb, CTA_TIMEOUT_L3PROTO, htons(l3num)) ||
408             nla_put_u8(skb, CTA_TIMEOUT_L4PROTO, l4proto->l4proto))
409                 goto nla_put_failure;
410
411         nest_parms = nla_nest_start(skb, CTA_TIMEOUT_DATA);
412         if (!nest_parms)
413                 goto nla_put_failure;
414
415         ret = l4proto->ctnl_timeout.obj_to_nlattr(skb, timeouts);
416         if (ret < 0)
417                 goto nla_put_failure;
418
419         nla_nest_end(skb, nest_parms);
420
421         nlmsg_end(skb, nlh);
422         return skb->len;
423
424 nlmsg_failure:
425 nla_put_failure:
426         nlmsg_cancel(skb, nlh);
427         return -1;
428 }
429
430 static int cttimeout_default_get(struct net *net, struct sock *ctnl,
431                                  struct sk_buff *skb,
432                                  const struct nlmsghdr *nlh,
433                                  const struct nlattr * const cda[],
434                                  struct netlink_ext_ack *extack)
435 {
436         const struct nf_conntrack_l4proto *l4proto;
437         unsigned int *timeouts = NULL;
438         struct sk_buff *skb2;
439         int ret, err;
440         __u16 l3num;
441         __u8 l4num;
442
443         if (!cda[CTA_TIMEOUT_L3PROTO] || !cda[CTA_TIMEOUT_L4PROTO])
444                 return -EINVAL;
445
446         l3num = ntohs(nla_get_be16(cda[CTA_TIMEOUT_L3PROTO]));
447         l4num = nla_get_u8(cda[CTA_TIMEOUT_L4PROTO]);
448         l4proto = nf_ct_l4proto_find(l4num);
449
450         err = -EOPNOTSUPP;
451         if (l4proto->l4proto != l4num)
452                 goto err;
453
454         switch (l4proto->l4proto) {
455         case IPPROTO_ICMP:
456                 timeouts = &nf_icmp_pernet(net)->timeout;
457                 break;
458         case IPPROTO_TCP:
459                 timeouts = nf_tcp_pernet(net)->timeouts;
460                 break;
461         case IPPROTO_UDP:
462         case IPPROTO_UDPLITE:
463                 timeouts = nf_udp_pernet(net)->timeouts;
464                 break;
465         case IPPROTO_DCCP:
466 #ifdef CONFIG_NF_CT_PROTO_DCCP
467                 timeouts = nf_dccp_pernet(net)->dccp_timeout;
468 #endif
469                 break;
470         case IPPROTO_ICMPV6:
471                 timeouts = &nf_icmpv6_pernet(net)->timeout;
472                 break;
473         case IPPROTO_SCTP:
474 #ifdef CONFIG_NF_CT_PROTO_SCTP
475                 timeouts = nf_sctp_pernet(net)->timeouts;
476 #endif
477                 break;
478         case IPPROTO_GRE:
479 #ifdef CONFIG_NF_CT_PROTO_GRE
480                 timeouts = nf_gre_pernet(net)->timeouts;
481 #endif
482                 break;
483         case 255:
484                 timeouts = &nf_generic_pernet(net)->timeout;
485                 break;
486         default:
487                 WARN_ONCE(1, "Missing timeouts for proto %d", l4proto->l4proto);
488                 break;
489         }
490
491         if (!timeouts)
492                 goto err;
493
494         skb2 = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
495         if (skb2 == NULL) {
496                 err = -ENOMEM;
497                 goto err;
498         }
499
500         ret = cttimeout_default_fill_info(net, skb2, NETLINK_CB(skb).portid,
501                                           nlh->nlmsg_seq,
502                                           NFNL_MSG_TYPE(nlh->nlmsg_type),
503                                           IPCTNL_MSG_TIMEOUT_DEFAULT_SET,
504                                           l3num, l4proto, timeouts);
505         if (ret <= 0) {
506                 kfree_skb(skb2);
507                 err = -ENOMEM;
508                 goto err;
509         }
510         ret = netlink_unicast(ctnl, skb2, NETLINK_CB(skb).portid, MSG_DONTWAIT);
511         if (ret > 0)
512                 ret = 0;
513
514         /* this avoids a loop in nfnetlink. */
515         return ret == -EAGAIN ? -ENOBUFS : ret;
516 err:
517         return err;
518 }
519
520 static struct nf_ct_timeout *ctnl_timeout_find_get(struct net *net,
521                                                    const char *name)
522 {
523         struct nfct_timeout_pernet *pernet = nfct_timeout_pernet(net);
524         struct ctnl_timeout *timeout, *matching = NULL;
525
526         list_for_each_entry_rcu(timeout, &pernet->nfct_timeout_list, head) {
527                 if (strncmp(timeout->name, name, CTNL_TIMEOUT_NAME_MAX) != 0)
528                         continue;
529
530                 if (!try_module_get(THIS_MODULE))
531                         goto err;
532
533                 if (!refcount_inc_not_zero(&timeout->refcnt)) {
534                         module_put(THIS_MODULE);
535                         goto err;
536                 }
537                 matching = timeout;
538                 break;
539         }
540 err:
541         return matching ? &matching->timeout : NULL;
542 }
543
544 static void ctnl_timeout_put(struct nf_ct_timeout *t)
545 {
546         struct ctnl_timeout *timeout =
547                 container_of(t, struct ctnl_timeout, timeout);
548
549         if (refcount_dec_and_test(&timeout->refcnt))
550                 kfree_rcu(timeout, rcu_head);
551
552         module_put(THIS_MODULE);
553 }
554
555 static const struct nfnl_callback cttimeout_cb[IPCTNL_MSG_TIMEOUT_MAX] = {
556         [IPCTNL_MSG_TIMEOUT_NEW]        = { .call = cttimeout_new_timeout,
557                                             .attr_count = CTA_TIMEOUT_MAX,
558                                             .policy = cttimeout_nla_policy },
559         [IPCTNL_MSG_TIMEOUT_GET]        = { .call = cttimeout_get_timeout,
560                                             .attr_count = CTA_TIMEOUT_MAX,
561                                             .policy = cttimeout_nla_policy },
562         [IPCTNL_MSG_TIMEOUT_DELETE]     = { .call = cttimeout_del_timeout,
563                                             .attr_count = CTA_TIMEOUT_MAX,
564                                             .policy = cttimeout_nla_policy },
565         [IPCTNL_MSG_TIMEOUT_DEFAULT_SET]= { .call = cttimeout_default_set,
566                                             .attr_count = CTA_TIMEOUT_MAX,
567                                             .policy = cttimeout_nla_policy },
568         [IPCTNL_MSG_TIMEOUT_DEFAULT_GET]= { .call = cttimeout_default_get,
569                                             .attr_count = CTA_TIMEOUT_MAX,
570                                             .policy = cttimeout_nla_policy },
571 };
572
573 static const struct nfnetlink_subsystem cttimeout_subsys = {
574         .name                           = "conntrack_timeout",
575         .subsys_id                      = NFNL_SUBSYS_CTNETLINK_TIMEOUT,
576         .cb_count                       = IPCTNL_MSG_TIMEOUT_MAX,
577         .cb                             = cttimeout_cb,
578 };
579
580 MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_CTNETLINK_TIMEOUT);
581
582 static int __net_init cttimeout_net_init(struct net *net)
583 {
584         struct nfct_timeout_pernet *pernet = nfct_timeout_pernet(net);
585
586         INIT_LIST_HEAD(&pernet->nfct_timeout_list);
587
588         return 0;
589 }
590
591 static void __net_exit cttimeout_net_exit(struct net *net)
592 {
593         struct nfct_timeout_pernet *pernet = nfct_timeout_pernet(net);
594         struct ctnl_timeout *cur, *tmp;
595
596         nf_ct_unconfirmed_destroy(net);
597         nf_ct_untimeout(net, NULL);
598
599         list_for_each_entry_safe(cur, tmp, &pernet->nfct_timeout_list, head) {
600                 list_del_rcu(&cur->head);
601
602                 if (refcount_dec_and_test(&cur->refcnt))
603                         kfree_rcu(cur, rcu_head);
604         }
605 }
606
607 static struct pernet_operations cttimeout_ops = {
608         .init   = cttimeout_net_init,
609         .exit   = cttimeout_net_exit,
610         .id     = &nfct_timeout_id,
611         .size   = sizeof(struct nfct_timeout_pernet),
612 };
613
614 static int __init cttimeout_init(void)
615 {
616         int ret;
617
618         ret = register_pernet_subsys(&cttimeout_ops);
619         if (ret < 0)
620                 return ret;
621
622         ret = nfnetlink_subsys_register(&cttimeout_subsys);
623         if (ret < 0) {
624                 pr_err("cttimeout_init: cannot register cttimeout with "
625                         "nfnetlink.\n");
626                 goto err_out;
627         }
628         RCU_INIT_POINTER(nf_ct_timeout_find_get_hook, ctnl_timeout_find_get);
629         RCU_INIT_POINTER(nf_ct_timeout_put_hook, ctnl_timeout_put);
630         return 0;
631
632 err_out:
633         unregister_pernet_subsys(&cttimeout_ops);
634         return ret;
635 }
636
637 static void __exit cttimeout_exit(void)
638 {
639         nfnetlink_subsys_unregister(&cttimeout_subsys);
640
641         unregister_pernet_subsys(&cttimeout_ops);
642         RCU_INIT_POINTER(nf_ct_timeout_find_get_hook, NULL);
643         RCU_INIT_POINTER(nf_ct_timeout_put_hook, NULL);
644         synchronize_rcu();
645 }
646
647 module_init(cttimeout_init);
648 module_exit(cttimeout_exit);