GNU Linux-libre 4.19.264-gnu1
[releases.git] / net / netfilter / nf_conntrack_standalone.c
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/types.h>
3 #include <linux/netfilter.h>
4 #include <linux/slab.h>
5 #include <linux/module.h>
6 #include <linux/skbuff.h>
7 #include <linux/proc_fs.h>
8 #include <linux/seq_file.h>
9 #include <linux/percpu.h>
10 #include <linux/netdevice.h>
11 #include <linux/security.h>
12 #include <net/net_namespace.h>
13 #ifdef CONFIG_SYSCTL
14 #include <linux/sysctl.h>
15 #endif
16
17 #include <net/netfilter/nf_conntrack.h>
18 #include <net/netfilter/nf_conntrack_core.h>
19 #include <net/netfilter/nf_conntrack_l4proto.h>
20 #include <net/netfilter/nf_conntrack_expect.h>
21 #include <net/netfilter/nf_conntrack_helper.h>
22 #include <net/netfilter/nf_conntrack_acct.h>
23 #include <net/netfilter/nf_conntrack_zones.h>
24 #include <net/netfilter/nf_conntrack_timestamp.h>
25 #include <linux/rculist_nulls.h>
26
27 unsigned int nf_conntrack_net_id __read_mostly;
28
29 #ifdef CONFIG_NF_CONNTRACK_PROCFS
30 void
31 print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple,
32             const struct nf_conntrack_l4proto *l4proto)
33 {
34         switch (tuple->src.l3num) {
35         case NFPROTO_IPV4:
36                 seq_printf(s, "src=%pI4 dst=%pI4 ",
37                            &tuple->src.u3.ip, &tuple->dst.u3.ip);
38                 break;
39         case NFPROTO_IPV6:
40                 seq_printf(s, "src=%pI6 dst=%pI6 ",
41                            tuple->src.u3.ip6, tuple->dst.u3.ip6);
42                 break;
43         default:
44                 break;
45         }
46
47         switch (l4proto->l4proto) {
48         case IPPROTO_ICMP:
49                 seq_printf(s, "type=%u code=%u id=%u ",
50                            tuple->dst.u.icmp.type,
51                            tuple->dst.u.icmp.code,
52                            ntohs(tuple->src.u.icmp.id));
53                 break;
54         case IPPROTO_TCP:
55                 seq_printf(s, "sport=%hu dport=%hu ",
56                            ntohs(tuple->src.u.tcp.port),
57                            ntohs(tuple->dst.u.tcp.port));
58                 break;
59         case IPPROTO_UDPLITE: /* fallthrough */
60         case IPPROTO_UDP:
61                 seq_printf(s, "sport=%hu dport=%hu ",
62                            ntohs(tuple->src.u.udp.port),
63                            ntohs(tuple->dst.u.udp.port));
64
65                 break;
66         case IPPROTO_DCCP:
67                 seq_printf(s, "sport=%hu dport=%hu ",
68                            ntohs(tuple->src.u.dccp.port),
69                            ntohs(tuple->dst.u.dccp.port));
70                 break;
71         case IPPROTO_SCTP:
72                 seq_printf(s, "sport=%hu dport=%hu ",
73                            ntohs(tuple->src.u.sctp.port),
74                            ntohs(tuple->dst.u.sctp.port));
75                 break;
76         case IPPROTO_ICMPV6:
77                 seq_printf(s, "type=%u code=%u id=%u ",
78                            tuple->dst.u.icmp.type,
79                            tuple->dst.u.icmp.code,
80                            ntohs(tuple->src.u.icmp.id));
81                 break;
82         case IPPROTO_GRE:
83                 seq_printf(s, "srckey=0x%x dstkey=0x%x ",
84                            ntohs(tuple->src.u.gre.key),
85                            ntohs(tuple->dst.u.gre.key));
86                 break;
87         default:
88                 break;
89         }
90 }
91 EXPORT_SYMBOL_GPL(print_tuple);
92
93 struct ct_iter_state {
94         struct seq_net_private p;
95         struct hlist_nulls_head *hash;
96         unsigned int htable_size;
97         unsigned int bucket;
98         u_int64_t time_now;
99 };
100
101 static struct hlist_nulls_node *ct_get_first(struct seq_file *seq)
102 {
103         struct ct_iter_state *st = seq->private;
104         struct hlist_nulls_node *n;
105
106         for (st->bucket = 0;
107              st->bucket < st->htable_size;
108              st->bucket++) {
109                 n = rcu_dereference(
110                         hlist_nulls_first_rcu(&st->hash[st->bucket]));
111                 if (!is_a_nulls(n))
112                         return n;
113         }
114         return NULL;
115 }
116
117 static struct hlist_nulls_node *ct_get_next(struct seq_file *seq,
118                                       struct hlist_nulls_node *head)
119 {
120         struct ct_iter_state *st = seq->private;
121
122         head = rcu_dereference(hlist_nulls_next_rcu(head));
123         while (is_a_nulls(head)) {
124                 if (likely(get_nulls_value(head) == st->bucket)) {
125                         if (++st->bucket >= st->htable_size)
126                                 return NULL;
127                 }
128                 head = rcu_dereference(
129                         hlist_nulls_first_rcu(&st->hash[st->bucket]));
130         }
131         return head;
132 }
133
134 static struct hlist_nulls_node *ct_get_idx(struct seq_file *seq, loff_t pos)
135 {
136         struct hlist_nulls_node *head = ct_get_first(seq);
137
138         if (head)
139                 while (pos && (head = ct_get_next(seq, head)))
140                         pos--;
141         return pos ? NULL : head;
142 }
143
144 static void *ct_seq_start(struct seq_file *seq, loff_t *pos)
145         __acquires(RCU)
146 {
147         struct ct_iter_state *st = seq->private;
148
149         st->time_now = ktime_get_real_ns();
150         rcu_read_lock();
151
152         nf_conntrack_get_ht(&st->hash, &st->htable_size);
153         return ct_get_idx(seq, *pos);
154 }
155
156 static void *ct_seq_next(struct seq_file *s, void *v, loff_t *pos)
157 {
158         (*pos)++;
159         return ct_get_next(s, v);
160 }
161
162 static void ct_seq_stop(struct seq_file *s, void *v)
163         __releases(RCU)
164 {
165         rcu_read_unlock();
166 }
167
168 #ifdef CONFIG_NF_CONNTRACK_SECMARK
169 static void ct_show_secctx(struct seq_file *s, const struct nf_conn *ct)
170 {
171         int ret;
172         u32 len;
173         char *secctx;
174
175         ret = security_secid_to_secctx(ct->secmark, &secctx, &len);
176         if (ret)
177                 return;
178
179         seq_printf(s, "secctx=%s ", secctx);
180
181         security_release_secctx(secctx, len);
182 }
183 #else
184 static inline void ct_show_secctx(struct seq_file *s, const struct nf_conn *ct)
185 {
186 }
187 #endif
188
189 #ifdef CONFIG_NF_CONNTRACK_ZONES
190 static void ct_show_zone(struct seq_file *s, const struct nf_conn *ct,
191                          int dir)
192 {
193         const struct nf_conntrack_zone *zone = nf_ct_zone(ct);
194
195         if (zone->dir != dir)
196                 return;
197         switch (zone->dir) {
198         case NF_CT_DEFAULT_ZONE_DIR:
199                 seq_printf(s, "zone=%u ", zone->id);
200                 break;
201         case NF_CT_ZONE_DIR_ORIG:
202                 seq_printf(s, "zone-orig=%u ", zone->id);
203                 break;
204         case NF_CT_ZONE_DIR_REPL:
205                 seq_printf(s, "zone-reply=%u ", zone->id);
206                 break;
207         default:
208                 break;
209         }
210 }
211 #else
212 static inline void ct_show_zone(struct seq_file *s, const struct nf_conn *ct,
213                                 int dir)
214 {
215 }
216 #endif
217
218 #ifdef CONFIG_NF_CONNTRACK_TIMESTAMP
219 static void ct_show_delta_time(struct seq_file *s, const struct nf_conn *ct)
220 {
221         struct ct_iter_state *st = s->private;
222         struct nf_conn_tstamp *tstamp;
223         s64 delta_time;
224
225         tstamp = nf_conn_tstamp_find(ct);
226         if (tstamp) {
227                 delta_time = st->time_now - tstamp->start;
228                 if (delta_time > 0)
229                         delta_time = div_s64(delta_time, NSEC_PER_SEC);
230                 else
231                         delta_time = 0;
232
233                 seq_printf(s, "delta-time=%llu ",
234                            (unsigned long long)delta_time);
235         }
236         return;
237 }
238 #else
239 static inline void
240 ct_show_delta_time(struct seq_file *s, const struct nf_conn *ct)
241 {
242 }
243 #endif
244
245 static const char* l3proto_name(u16 proto)
246 {
247         switch (proto) {
248         case AF_INET: return "ipv4";
249         case AF_INET6: return "ipv6";
250         }
251
252         return "unknown";
253 }
254
255 static const char* l4proto_name(u16 proto)
256 {
257         switch (proto) {
258         case IPPROTO_ICMP: return "icmp";
259         case IPPROTO_TCP: return "tcp";
260         case IPPROTO_UDP: return "udp";
261         case IPPROTO_DCCP: return "dccp";
262         case IPPROTO_GRE: return "gre";
263         case IPPROTO_SCTP: return "sctp";
264         case IPPROTO_UDPLITE: return "udplite";
265         case IPPROTO_ICMPV6: return "icmpv6";
266         }
267
268         return "unknown";
269 }
270
271 /* return 0 on success, 1 in case of error */
272 static int ct_seq_show(struct seq_file *s, void *v)
273 {
274         struct nf_conntrack_tuple_hash *hash = v;
275         struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(hash);
276         const struct nf_conntrack_l4proto *l4proto;
277         struct net *net = seq_file_net(s);
278         int ret = 0;
279
280         WARN_ON(!ct);
281         if (unlikely(!atomic_inc_not_zero(&ct->ct_general.use)))
282                 return 0;
283
284         if (nf_ct_should_gc(ct)) {
285                 nf_ct_kill(ct);
286                 goto release;
287         }
288
289         /* we only want to print DIR_ORIGINAL */
290         if (NF_CT_DIRECTION(hash))
291                 goto release;
292
293         if (!net_eq(nf_ct_net(ct), net))
294                 goto release;
295
296         l4proto = __nf_ct_l4proto_find(nf_ct_l3num(ct), nf_ct_protonum(ct));
297         WARN_ON(!l4proto);
298
299         ret = -ENOSPC;
300         seq_printf(s, "%-8s %u %-8s %u ",
301                    l3proto_name(nf_ct_l3num(ct)), nf_ct_l3num(ct),
302                    l4proto_name(l4proto->l4proto), nf_ct_protonum(ct));
303
304         if (!test_bit(IPS_OFFLOAD_BIT, &ct->status))
305                 seq_printf(s, "%ld ", nf_ct_expires(ct)  / HZ);
306
307         if (l4proto->print_conntrack)
308                 l4proto->print_conntrack(s, ct);
309
310         print_tuple(s, &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
311                     l4proto);
312
313         ct_show_zone(s, ct, NF_CT_ZONE_DIR_ORIG);
314
315         if (seq_has_overflowed(s))
316                 goto release;
317
318         if (seq_print_acct(s, ct, IP_CT_DIR_ORIGINAL))
319                 goto release;
320
321         if (!(test_bit(IPS_SEEN_REPLY_BIT, &ct->status)))
322                 seq_puts(s, "[UNREPLIED] ");
323
324         print_tuple(s, &ct->tuplehash[IP_CT_DIR_REPLY].tuple, l4proto);
325
326         ct_show_zone(s, ct, NF_CT_ZONE_DIR_REPL);
327
328         if (seq_print_acct(s, ct, IP_CT_DIR_REPLY))
329                 goto release;
330
331         if (test_bit(IPS_OFFLOAD_BIT, &ct->status))
332                 seq_puts(s, "[OFFLOAD] ");
333         else if (test_bit(IPS_ASSURED_BIT, &ct->status))
334                 seq_puts(s, "[ASSURED] ");
335
336         if (seq_has_overflowed(s))
337                 goto release;
338
339 #if defined(CONFIG_NF_CONNTRACK_MARK)
340         seq_printf(s, "mark=%u ", ct->mark);
341 #endif
342
343         ct_show_secctx(s, ct);
344         ct_show_zone(s, ct, NF_CT_DEFAULT_ZONE_DIR);
345         ct_show_delta_time(s, ct);
346
347         seq_printf(s, "use=%u\n", atomic_read(&ct->ct_general.use));
348
349         if (seq_has_overflowed(s))
350                 goto release;
351
352         ret = 0;
353 release:
354         nf_ct_put(ct);
355         return ret;
356 }
357
358 static const struct seq_operations ct_seq_ops = {
359         .start = ct_seq_start,
360         .next  = ct_seq_next,
361         .stop  = ct_seq_stop,
362         .show  = ct_seq_show
363 };
364
365 static void *ct_cpu_seq_start(struct seq_file *seq, loff_t *pos)
366 {
367         struct net *net = seq_file_net(seq);
368         int cpu;
369
370         if (*pos == 0)
371                 return SEQ_START_TOKEN;
372
373         for (cpu = *pos-1; cpu < nr_cpu_ids; ++cpu) {
374                 if (!cpu_possible(cpu))
375                         continue;
376                 *pos = cpu + 1;
377                 return per_cpu_ptr(net->ct.stat, cpu);
378         }
379
380         return NULL;
381 }
382
383 static void *ct_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos)
384 {
385         struct net *net = seq_file_net(seq);
386         int cpu;
387
388         for (cpu = *pos; cpu < nr_cpu_ids; ++cpu) {
389                 if (!cpu_possible(cpu))
390                         continue;
391                 *pos = cpu + 1;
392                 return per_cpu_ptr(net->ct.stat, cpu);
393         }
394         (*pos)++;
395         return NULL;
396 }
397
398 static void ct_cpu_seq_stop(struct seq_file *seq, void *v)
399 {
400 }
401
402 static int ct_cpu_seq_show(struct seq_file *seq, void *v)
403 {
404         struct net *net = seq_file_net(seq);
405         unsigned int nr_conntracks = atomic_read(&net->ct.count);
406         const struct ip_conntrack_stat *st = v;
407
408         if (v == SEQ_START_TOKEN) {
409                 seq_puts(seq, "entries  searched found new invalid ignore delete delete_list insert insert_failed drop early_drop icmp_error  expect_new expect_create expect_delete search_restart\n");
410                 return 0;
411         }
412
413         seq_printf(seq, "%08x  %08x %08x %08x %08x %08x %08x %08x "
414                         "%08x %08x %08x %08x %08x  %08x %08x %08x %08x\n",
415                    nr_conntracks,
416                    0,
417                    st->found,
418                    0,
419                    st->invalid,
420                    st->ignore,
421                    0,
422                    0,
423                    st->insert,
424                    st->insert_failed,
425                    st->drop,
426                    st->early_drop,
427                    st->error,
428
429                    st->expect_new,
430                    st->expect_create,
431                    st->expect_delete,
432                    st->search_restart
433                 );
434         return 0;
435 }
436
437 static const struct seq_operations ct_cpu_seq_ops = {
438         .start  = ct_cpu_seq_start,
439         .next   = ct_cpu_seq_next,
440         .stop   = ct_cpu_seq_stop,
441         .show   = ct_cpu_seq_show,
442 };
443
444 static int nf_conntrack_standalone_init_proc(struct net *net)
445 {
446         struct proc_dir_entry *pde;
447         kuid_t root_uid;
448         kgid_t root_gid;
449
450         pde = proc_create_net("nf_conntrack", 0440, net->proc_net, &ct_seq_ops,
451                         sizeof(struct ct_iter_state));
452         if (!pde)
453                 goto out_nf_conntrack;
454
455         root_uid = make_kuid(net->user_ns, 0);
456         root_gid = make_kgid(net->user_ns, 0);
457         if (uid_valid(root_uid) && gid_valid(root_gid))
458                 proc_set_user(pde, root_uid, root_gid);
459
460         pde = proc_create_net("nf_conntrack", 0444, net->proc_net_stat,
461                         &ct_cpu_seq_ops, sizeof(struct seq_net_private));
462         if (!pde)
463                 goto out_stat_nf_conntrack;
464         return 0;
465
466 out_stat_nf_conntrack:
467         remove_proc_entry("nf_conntrack", net->proc_net);
468 out_nf_conntrack:
469         return -ENOMEM;
470 }
471
472 static void nf_conntrack_standalone_fini_proc(struct net *net)
473 {
474         remove_proc_entry("nf_conntrack", net->proc_net_stat);
475         remove_proc_entry("nf_conntrack", net->proc_net);
476 }
477 #else
478 static int nf_conntrack_standalone_init_proc(struct net *net)
479 {
480         return 0;
481 }
482
483 static void nf_conntrack_standalone_fini_proc(struct net *net)
484 {
485 }
486 #endif /* CONFIG_NF_CONNTRACK_PROCFS */
487
488 /* Sysctl support */
489
490 #ifdef CONFIG_SYSCTL
491 /* Log invalid packets of a given protocol */
492 static int log_invalid_proto_min __read_mostly;
493 static int log_invalid_proto_max __read_mostly = 255;
494
495 /* size the user *wants to set */
496 static unsigned int nf_conntrack_htable_size_user __read_mostly;
497
498 static int
499 nf_conntrack_hash_sysctl(struct ctl_table *table, int write,
500                          void __user *buffer, size_t *lenp, loff_t *ppos)
501 {
502         int ret;
503
504         /* module_param hashsize could have changed value */
505         nf_conntrack_htable_size_user = nf_conntrack_htable_size;
506
507         ret = proc_dointvec(table, write, buffer, lenp, ppos);
508         if (ret < 0 || !write)
509                 return ret;
510
511         /* update ret, we might not be able to satisfy request */
512         ret = nf_conntrack_hash_resize(nf_conntrack_htable_size_user);
513
514         /* update it to the actual value used by conntrack */
515         nf_conntrack_htable_size_user = nf_conntrack_htable_size;
516         return ret;
517 }
518
519 static struct ctl_table_header *nf_ct_netfilter_header;
520
521 static struct ctl_table nf_ct_sysctl_table[] = {
522         {
523                 .procname       = "nf_conntrack_max",
524                 .data           = &nf_conntrack_max,
525                 .maxlen         = sizeof(int),
526                 .mode           = 0644,
527                 .proc_handler   = proc_dointvec,
528         },
529         {
530                 .procname       = "nf_conntrack_count",
531                 .data           = &init_net.ct.count,
532                 .maxlen         = sizeof(int),
533                 .mode           = 0444,
534                 .proc_handler   = proc_dointvec,
535         },
536         {
537                 .procname       = "nf_conntrack_buckets",
538                 .data           = &nf_conntrack_htable_size_user,
539                 .maxlen         = sizeof(unsigned int),
540                 .mode           = 0644,
541                 .proc_handler   = nf_conntrack_hash_sysctl,
542         },
543         {
544                 .procname       = "nf_conntrack_checksum",
545                 .data           = &init_net.ct.sysctl_checksum,
546                 .maxlen         = sizeof(unsigned int),
547                 .mode           = 0644,
548                 .proc_handler   = proc_dointvec,
549         },
550         {
551                 .procname       = "nf_conntrack_log_invalid",
552                 .data           = &init_net.ct.sysctl_log_invalid,
553                 .maxlen         = sizeof(unsigned int),
554                 .mode           = 0644,
555                 .proc_handler   = proc_dointvec_minmax,
556                 .extra1         = &log_invalid_proto_min,
557                 .extra2         = &log_invalid_proto_max,
558         },
559         {
560                 .procname       = "nf_conntrack_expect_max",
561                 .data           = &nf_ct_expect_max,
562                 .maxlen         = sizeof(int),
563                 .mode           = 0644,
564                 .proc_handler   = proc_dointvec,
565         },
566         { }
567 };
568
569 static struct ctl_table nf_ct_netfilter_table[] = {
570         {
571                 .procname       = "nf_conntrack_max",
572                 .data           = &nf_conntrack_max,
573                 .maxlen         = sizeof(int),
574                 .mode           = 0644,
575                 .proc_handler   = proc_dointvec,
576         },
577         { }
578 };
579
580 static int nf_conntrack_standalone_init_sysctl(struct net *net)
581 {
582         struct ctl_table *table;
583
584         table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
585                         GFP_KERNEL);
586         if (!table)
587                 goto out_kmemdup;
588
589         table[1].data = &net->ct.count;
590         table[3].data = &net->ct.sysctl_checksum;
591         table[4].data = &net->ct.sysctl_log_invalid;
592
593         /* Don't export sysctls to unprivileged users */
594         if (net->user_ns != &init_user_ns)
595                 table[0].procname = NULL;
596
597         if (!net_eq(&init_net, net)) {
598                 table[0].mode = 0444;
599                 table[2].mode = 0444;
600                 table[5].mode = 0444;
601         }
602
603         net->ct.sysctl_header = register_net_sysctl(net, "net/netfilter", table);
604         if (!net->ct.sysctl_header)
605                 goto out_unregister_netfilter;
606
607         return 0;
608
609 out_unregister_netfilter:
610         kfree(table);
611 out_kmemdup:
612         return -ENOMEM;
613 }
614
615 static void nf_conntrack_standalone_fini_sysctl(struct net *net)
616 {
617         struct ctl_table *table;
618
619         table = net->ct.sysctl_header->ctl_table_arg;
620         unregister_net_sysctl_table(net->ct.sysctl_header);
621         kfree(table);
622 }
623 #else
624 static int nf_conntrack_standalone_init_sysctl(struct net *net)
625 {
626         return 0;
627 }
628
629 static void nf_conntrack_standalone_fini_sysctl(struct net *net)
630 {
631 }
632 #endif /* CONFIG_SYSCTL */
633
634 static int nf_conntrack_pernet_init(struct net *net)
635 {
636         int ret;
637
638         ret = nf_conntrack_init_net(net);
639         if (ret < 0)
640                 goto out_init;
641
642         ret = nf_conntrack_standalone_init_proc(net);
643         if (ret < 0)
644                 goto out_proc;
645
646         net->ct.sysctl_checksum = 1;
647         net->ct.sysctl_log_invalid = 0;
648         ret = nf_conntrack_standalone_init_sysctl(net);
649         if (ret < 0)
650                 goto out_sysctl;
651
652         return 0;
653
654 out_sysctl:
655         nf_conntrack_standalone_fini_proc(net);
656 out_proc:
657         nf_conntrack_cleanup_net(net);
658 out_init:
659         return ret;
660 }
661
662 static void nf_conntrack_pernet_exit(struct list_head *net_exit_list)
663 {
664         struct net *net;
665
666         list_for_each_entry(net, net_exit_list, exit_list) {
667                 nf_conntrack_standalone_fini_sysctl(net);
668                 nf_conntrack_standalone_fini_proc(net);
669         }
670         nf_conntrack_cleanup_net_list(net_exit_list);
671 }
672
673 static struct pernet_operations nf_conntrack_net_ops = {
674         .init           = nf_conntrack_pernet_init,
675         .exit_batch     = nf_conntrack_pernet_exit,
676         .id             = &nf_conntrack_net_id,
677         .size = sizeof(struct nf_conntrack_net),
678 };
679
680 static int __init nf_conntrack_standalone_init(void)
681 {
682         int ret = nf_conntrack_init_start();
683         if (ret < 0)
684                 goto out_start;
685
686         BUILD_BUG_ON(SKB_NFCT_PTRMASK != NFCT_PTRMASK);
687         BUILD_BUG_ON(NFCT_INFOMASK <= IP_CT_NUMBER);
688
689 #ifdef CONFIG_SYSCTL
690         nf_ct_netfilter_header =
691                 register_net_sysctl(&init_net, "net", nf_ct_netfilter_table);
692         if (!nf_ct_netfilter_header) {
693                 pr_err("nf_conntrack: can't register to sysctl.\n");
694                 ret = -ENOMEM;
695                 goto out_sysctl;
696         }
697
698         nf_conntrack_htable_size_user = nf_conntrack_htable_size;
699 #endif
700
701         ret = register_pernet_subsys(&nf_conntrack_net_ops);
702         if (ret < 0)
703                 goto out_pernet;
704
705         nf_conntrack_init_end();
706         return 0;
707
708 out_pernet:
709 #ifdef CONFIG_SYSCTL
710         unregister_net_sysctl_table(nf_ct_netfilter_header);
711 out_sysctl:
712 #endif
713         nf_conntrack_cleanup_end();
714 out_start:
715         return ret;
716 }
717
718 static void __exit nf_conntrack_standalone_fini(void)
719 {
720         nf_conntrack_cleanup_start();
721         unregister_pernet_subsys(&nf_conntrack_net_ops);
722 #ifdef CONFIG_SYSCTL
723         unregister_net_sysctl_table(nf_ct_netfilter_header);
724 #endif
725         nf_conntrack_cleanup_end();
726 }
727
728 module_init(nf_conntrack_standalone_init);
729 module_exit(nf_conntrack_standalone_fini);
730
731 /* Some modules need us, but don't depend directly on any symbol.
732    They should call this. */
733 void need_conntrack(void)
734 {
735 }
736 EXPORT_SYMBOL_GPL(need_conntrack);