1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/types.h>
4 #include <linux/netfilter.h>
5 #include <linux/module.h>
6 #include <linux/slab.h>
7 #include <linux/mutex.h>
8 #include <linux/vmalloc.h>
9 #include <linux/stddef.h>
10 #include <linux/err.h>
11 #include <linux/percpu.h>
12 #include <linux/notifier.h>
13 #include <linux/kernel.h>
14 #include <linux/netdevice.h>
16 #include <net/netfilter/nf_conntrack.h>
17 #include <net/netfilter/nf_conntrack_l4proto.h>
18 #include <net/netfilter/nf_conntrack_core.h>
19 #include <net/netfilter/nf_log.h>
22 #include <linux/icmp.h>
23 #include <linux/sysctl.h>
24 #include <net/route.h>
27 #include <linux/netfilter_ipv4.h>
28 #include <linux/netfilter_ipv6.h>
29 #include <linux/netfilter_ipv6/ip6_tables.h>
30 #include <net/netfilter/nf_conntrack_helper.h>
31 #include <net/netfilter/nf_conntrack_zones.h>
32 #include <net/netfilter/nf_conntrack_seqadj.h>
33 #include <net/netfilter/ipv4/nf_conntrack_ipv4.h>
34 #include <net/netfilter/ipv6/nf_conntrack_ipv6.h>
35 #include <net/netfilter/nf_nat_helper.h>
36 #include <net/netfilter/ipv4/nf_defrag_ipv4.h>
37 #include <net/netfilter/ipv6/nf_defrag_ipv6.h>
39 #include <linux/ipv6.h>
40 #include <linux/in6.h>
42 #include <net/inet_frag.h>
44 extern unsigned int nf_conntrack_net_id;
46 static struct nf_conntrack_l4proto __rcu *nf_ct_protos[MAX_NF_CT_PROTO + 1] __read_mostly;
48 static DEFINE_MUTEX(nf_ct_proto_mutex);
52 nf_ct_register_sysctl(struct net *net,
53 struct ctl_table_header **header,
55 struct ctl_table *table)
57 if (*header == NULL) {
58 *header = register_net_sysctl(net, path, table);
67 nf_ct_unregister_sysctl(struct ctl_table_header **header,
68 struct ctl_table **table,
74 unregister_net_sysctl_table(*header);
81 void nf_l4proto_log_invalid(const struct sk_buff *skb,
89 if (net->ct.sysctl_log_invalid != protonum ||
90 net->ct.sysctl_log_invalid != IPPROTO_RAW)
97 nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL,
98 "nf_ct_proto_%d: %pV ", protonum, &vaf);
101 EXPORT_SYMBOL_GPL(nf_l4proto_log_invalid);
104 void nf_ct_l4proto_log_invalid(const struct sk_buff *skb,
105 const struct nf_conn *ct,
106 const char *fmt, ...)
108 struct va_format vaf;
113 if (likely(net->ct.sysctl_log_invalid == 0))
120 nf_l4proto_log_invalid(skb, net, nf_ct_l3num(ct),
121 nf_ct_protonum(ct), "%pV", &vaf);
124 EXPORT_SYMBOL_GPL(nf_ct_l4proto_log_invalid);
127 const struct nf_conntrack_l4proto *__nf_ct_l4proto_find(u8 l4proto)
129 if (unlikely(l4proto >= ARRAY_SIZE(nf_ct_protos)))
130 return &nf_conntrack_l4proto_generic;
132 return rcu_dereference(nf_ct_protos[l4proto]);
134 EXPORT_SYMBOL_GPL(__nf_ct_l4proto_find);
136 const struct nf_conntrack_l4proto *nf_ct_l4proto_find_get(u8 l4num)
138 const struct nf_conntrack_l4proto *p;
141 p = __nf_ct_l4proto_find(l4num);
142 if (!try_module_get(p->me))
143 p = &nf_conntrack_l4proto_generic;
148 EXPORT_SYMBOL_GPL(nf_ct_l4proto_find_get);
150 void nf_ct_l4proto_put(const struct nf_conntrack_l4proto *p)
154 EXPORT_SYMBOL_GPL(nf_ct_l4proto_put);
156 static int kill_l4proto(struct nf_conn *i, void *data)
158 const struct nf_conntrack_l4proto *l4proto;
160 return nf_ct_protonum(i) == l4proto->l4proto;
163 static struct nf_proto_net *nf_ct_l4proto_net(struct net *net,
164 const struct nf_conntrack_l4proto *l4proto)
166 if (l4proto->get_net_proto) {
167 /* statically built-in protocols use static per-net */
168 return l4proto->get_net_proto(net);
169 } else if (l4proto->net_id) {
170 /* ... and loadable protocols use dynamic per-net */
171 return net_generic(net, *l4proto->net_id);
177 int nf_ct_l4proto_register_sysctl(struct net *net,
178 struct nf_proto_net *pn)
183 if (pn->ctl_table != NULL) {
184 err = nf_ct_register_sysctl(net,
185 &pn->ctl_table_header,
190 kfree(pn->ctl_table);
191 pn->ctl_table = NULL;
195 #endif /* CONFIG_SYSCTL */
200 void nf_ct_l4proto_unregister_sysctl(struct nf_proto_net *pn)
203 if (pn->ctl_table_header != NULL)
204 nf_ct_unregister_sysctl(&pn->ctl_table_header,
207 #endif /* CONFIG_SYSCTL */
210 /* FIXME: Allow NULL functions and sub in pointers to generic for
212 int nf_ct_l4proto_register_one(const struct nf_conntrack_l4proto *l4proto)
216 if ((l4proto->to_nlattr && l4proto->nlattr_size == 0) ||
217 (l4proto->tuple_to_nlattr && !l4proto->nlattr_tuple_size))
220 mutex_lock(&nf_ct_proto_mutex);
221 if (rcu_dereference_protected(
222 nf_ct_protos[l4proto->l4proto],
223 lockdep_is_held(&nf_ct_proto_mutex)
224 ) != &nf_conntrack_l4proto_generic) {
229 rcu_assign_pointer(nf_ct_protos[l4proto->l4proto], l4proto);
231 mutex_unlock(&nf_ct_proto_mutex);
234 EXPORT_SYMBOL_GPL(nf_ct_l4proto_register_one);
236 int nf_ct_l4proto_pernet_register_one(struct net *net,
237 const struct nf_conntrack_l4proto *l4proto)
240 struct nf_proto_net *pn = NULL;
242 if (l4proto->init_net) {
243 ret = l4proto->init_net(net);
248 pn = nf_ct_l4proto_net(net, l4proto);
252 ret = nf_ct_l4proto_register_sysctl(net, pn);
260 EXPORT_SYMBOL_GPL(nf_ct_l4proto_pernet_register_one);
262 static void __nf_ct_l4proto_unregister_one(const struct nf_conntrack_l4proto *l4proto)
265 BUG_ON(l4proto->l4proto >= ARRAY_SIZE(nf_ct_protos));
267 BUG_ON(rcu_dereference_protected(
268 nf_ct_protos[l4proto->l4proto],
269 lockdep_is_held(&nf_ct_proto_mutex)
271 rcu_assign_pointer(nf_ct_protos[l4proto->l4proto],
272 &nf_conntrack_l4proto_generic);
275 void nf_ct_l4proto_unregister_one(const struct nf_conntrack_l4proto *l4proto)
277 mutex_lock(&nf_ct_proto_mutex);
278 __nf_ct_l4proto_unregister_one(l4proto);
279 mutex_unlock(&nf_ct_proto_mutex);
282 /* Remove all contrack entries for this protocol */
283 nf_ct_iterate_destroy(kill_l4proto, (void *)l4proto);
285 EXPORT_SYMBOL_GPL(nf_ct_l4proto_unregister_one);
287 void nf_ct_l4proto_pernet_unregister_one(struct net *net,
288 const struct nf_conntrack_l4proto *l4proto)
290 struct nf_proto_net *pn = nf_ct_l4proto_net(net, l4proto);
296 nf_ct_l4proto_unregister_sysctl(pn);
298 EXPORT_SYMBOL_GPL(nf_ct_l4proto_pernet_unregister_one);
301 nf_ct_l4proto_unregister(const struct nf_conntrack_l4proto * const l4proto[],
302 unsigned int num_proto)
306 mutex_lock(&nf_ct_proto_mutex);
307 for (i = 0; i < num_proto; i++)
308 __nf_ct_l4proto_unregister_one(l4proto[i]);
309 mutex_unlock(&nf_ct_proto_mutex);
313 for (i = 0; i < num_proto; i++)
314 nf_ct_iterate_destroy(kill_l4proto, (void *)l4proto[i]);
318 nf_ct_l4proto_register(const struct nf_conntrack_l4proto * const l4proto[],
319 unsigned int num_proto)
324 for (i = 0; i < num_proto; i++) {
325 ret = nf_ct_l4proto_register_one(l4proto[i]);
329 if (i != num_proto) {
330 pr_err("nf_conntrack: can't register l4 %d proto.\n",
331 l4proto[i]->l4proto);
332 nf_ct_l4proto_unregister(l4proto, i);
337 int nf_ct_l4proto_pernet_register(struct net *net,
338 const struct nf_conntrack_l4proto *const l4proto[],
339 unsigned int num_proto)
344 for (i = 0; i < num_proto; i++) {
345 ret = nf_ct_l4proto_pernet_register_one(net, l4proto[i]);
349 if (i != num_proto) {
350 pr_err("nf_conntrack %d: pernet registration failed\n",
351 l4proto[i]->l4proto);
352 nf_ct_l4proto_pernet_unregister(net, l4proto, i);
356 EXPORT_SYMBOL_GPL(nf_ct_l4proto_pernet_register);
358 void nf_ct_l4proto_pernet_unregister(struct net *net,
359 const struct nf_conntrack_l4proto *const l4proto[],
360 unsigned int num_proto)
362 while (num_proto-- != 0)
363 nf_ct_l4proto_pernet_unregister_one(net, l4proto[num_proto]);
365 EXPORT_SYMBOL_GPL(nf_ct_l4proto_pernet_unregister);
367 static unsigned int ipv4_helper(void *priv,
369 const struct nf_hook_state *state)
372 enum ip_conntrack_info ctinfo;
373 const struct nf_conn_help *help;
374 const struct nf_conntrack_helper *helper;
376 /* This is where we call the helper: as the packet goes out. */
377 ct = nf_ct_get(skb, &ctinfo);
378 if (!ct || ctinfo == IP_CT_RELATED_REPLY)
381 help = nfct_help(ct);
385 /* rcu_read_lock()ed by nf_hook_thresh */
386 helper = rcu_dereference(help->helper);
390 return helper->help(skb, skb_network_offset(skb) + ip_hdrlen(skb),
394 static unsigned int ipv4_confirm(void *priv,
396 const struct nf_hook_state *state)
399 enum ip_conntrack_info ctinfo;
401 ct = nf_ct_get(skb, &ctinfo);
402 if (!ct || ctinfo == IP_CT_RELATED_REPLY)
405 /* adjust seqs for loopback traffic only in outgoing direction */
406 if (test_bit(IPS_SEQ_ADJUST_BIT, &ct->status) &&
407 !nf_is_loopback_packet(skb)) {
408 if (!nf_ct_seq_adjust(skb, ct, ctinfo, ip_hdrlen(skb))) {
409 NF_CT_STAT_INC_ATOMIC(nf_ct_net(ct), drop);
414 /* We've seen it coming out the other side: confirm it */
415 return nf_conntrack_confirm(skb);
418 static unsigned int ipv4_conntrack_in(void *priv,
420 const struct nf_hook_state *state)
422 return nf_conntrack_in(skb, state);
425 static unsigned int ipv4_conntrack_local(void *priv,
427 const struct nf_hook_state *state)
429 if (ip_is_fragment(ip_hdr(skb))) { /* IP_NODEFRAG setsockopt set */
430 enum ip_conntrack_info ctinfo;
431 struct nf_conn *tmpl;
433 tmpl = nf_ct_get(skb, &ctinfo);
434 if (tmpl && nf_ct_is_template(tmpl)) {
435 /* when skipping ct, clear templates to avoid fooling
436 * later targets/matches
444 return nf_conntrack_in(skb, state);
447 /* Connection tracking may drop packets, but never alters them, so
448 * make it the first hook.
450 static const struct nf_hook_ops ipv4_conntrack_ops[] = {
452 .hook = ipv4_conntrack_in,
454 .hooknum = NF_INET_PRE_ROUTING,
455 .priority = NF_IP_PRI_CONNTRACK,
458 .hook = ipv4_conntrack_local,
460 .hooknum = NF_INET_LOCAL_OUT,
461 .priority = NF_IP_PRI_CONNTRACK,
466 .hooknum = NF_INET_POST_ROUTING,
467 .priority = NF_IP_PRI_CONNTRACK_HELPER,
470 .hook = ipv4_confirm,
472 .hooknum = NF_INET_POST_ROUTING,
473 .priority = NF_IP_PRI_CONNTRACK_CONFIRM,
478 .hooknum = NF_INET_LOCAL_IN,
479 .priority = NF_IP_PRI_CONNTRACK_HELPER,
482 .hook = ipv4_confirm,
484 .hooknum = NF_INET_LOCAL_IN,
485 .priority = NF_IP_PRI_CONNTRACK_CONFIRM,
489 /* Fast function for those who don't want to parse /proc (and I don't
491 * Reversing the socket's dst/src point of view gives us the reply
495 getorigdst(struct sock *sk, int optval, void __user *user, int *len)
497 const struct inet_sock *inet = inet_sk(sk);
498 const struct nf_conntrack_tuple_hash *h;
499 struct nf_conntrack_tuple tuple;
501 memset(&tuple, 0, sizeof(tuple));
504 tuple.src.u3.ip = inet->inet_rcv_saddr;
505 tuple.src.u.tcp.port = inet->inet_sport;
506 tuple.dst.u3.ip = inet->inet_daddr;
507 tuple.dst.u.tcp.port = inet->inet_dport;
508 tuple.src.l3num = PF_INET;
509 tuple.dst.protonum = sk->sk_protocol;
512 /* We only do TCP and SCTP at the moment: is there a better way? */
513 if (tuple.dst.protonum != IPPROTO_TCP &&
514 tuple.dst.protonum != IPPROTO_SCTP) {
515 pr_debug("SO_ORIGINAL_DST: Not a TCP/SCTP socket\n");
519 if ((unsigned int)*len < sizeof(struct sockaddr_in)) {
520 pr_debug("SO_ORIGINAL_DST: len %d not %zu\n",
521 *len, sizeof(struct sockaddr_in));
525 h = nf_conntrack_find_get(sock_net(sk), &nf_ct_zone_dflt, &tuple);
527 struct sockaddr_in sin;
528 struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(h);
530 sin.sin_family = AF_INET;
531 sin.sin_port = ct->tuplehash[IP_CT_DIR_ORIGINAL]
532 .tuple.dst.u.tcp.port;
533 sin.sin_addr.s_addr = ct->tuplehash[IP_CT_DIR_ORIGINAL]
535 memset(sin.sin_zero, 0, sizeof(sin.sin_zero));
537 pr_debug("SO_ORIGINAL_DST: %pI4 %u\n",
538 &sin.sin_addr.s_addr, ntohs(sin.sin_port));
540 if (copy_to_user(user, &sin, sizeof(sin)) != 0)
545 pr_debug("SO_ORIGINAL_DST: Can't find %pI4/%u-%pI4/%u.\n",
546 &tuple.src.u3.ip, ntohs(tuple.src.u.tcp.port),
547 &tuple.dst.u3.ip, ntohs(tuple.dst.u.tcp.port));
551 static struct nf_sockopt_ops so_getorigdst = {
553 .get_optmin = SO_ORIGINAL_DST,
554 .get_optmax = SO_ORIGINAL_DST + 1,
556 .owner = THIS_MODULE,
559 #if IS_ENABLED(CONFIG_IPV6)
561 ipv6_getorigdst(struct sock *sk, int optval, void __user *user, int *len)
563 struct nf_conntrack_tuple tuple = { .src.l3num = NFPROTO_IPV6 };
564 const struct ipv6_pinfo *inet6 = inet6_sk(sk);
565 const struct inet_sock *inet = inet_sk(sk);
566 const struct nf_conntrack_tuple_hash *h;
567 struct sockaddr_in6 sin6;
573 tuple.src.u3.in6 = sk->sk_v6_rcv_saddr;
574 tuple.src.u.tcp.port = inet->inet_sport;
575 tuple.dst.u3.in6 = sk->sk_v6_daddr;
576 tuple.dst.u.tcp.port = inet->inet_dport;
577 tuple.dst.protonum = sk->sk_protocol;
578 bound_dev_if = sk->sk_bound_dev_if;
579 flow_label = inet6->flow_label;
582 if (tuple.dst.protonum != IPPROTO_TCP &&
583 tuple.dst.protonum != IPPROTO_SCTP)
586 if (*len < 0 || (unsigned int)*len < sizeof(sin6))
589 h = nf_conntrack_find_get(sock_net(sk), &nf_ct_zone_dflt, &tuple);
591 pr_debug("IP6T_SO_ORIGINAL_DST: Can't find %pI6c/%u-%pI6c/%u.\n",
592 &tuple.src.u3.ip6, ntohs(tuple.src.u.tcp.port),
593 &tuple.dst.u3.ip6, ntohs(tuple.dst.u.tcp.port));
597 ct = nf_ct_tuplehash_to_ctrack(h);
599 sin6.sin6_family = AF_INET6;
600 sin6.sin6_port = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.u.tcp.port;
601 sin6.sin6_flowinfo = flow_label & IPV6_FLOWINFO_MASK;
602 memcpy(&sin6.sin6_addr,
603 &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.u3.in6,
604 sizeof(sin6.sin6_addr));
607 sin6.sin6_scope_id = ipv6_iface_scope_id(&sin6.sin6_addr, bound_dev_if);
608 return copy_to_user(user, &sin6, sizeof(sin6)) ? -EFAULT : 0;
611 static struct nf_sockopt_ops so_getorigdst6 = {
613 .get_optmin = IP6T_SO_ORIGINAL_DST,
614 .get_optmax = IP6T_SO_ORIGINAL_DST + 1,
615 .get = ipv6_getorigdst,
616 .owner = THIS_MODULE,
619 static unsigned int ipv6_confirm(void *priv,
621 const struct nf_hook_state *state)
624 enum ip_conntrack_info ctinfo;
625 unsigned char pnum = ipv6_hdr(skb)->nexthdr;
629 ct = nf_ct_get(skb, &ctinfo);
630 if (!ct || ctinfo == IP_CT_RELATED_REPLY)
633 protoff = ipv6_skip_exthdr(skb, sizeof(struct ipv6hdr), &pnum,
635 if (protoff < 0 || (frag_off & htons(~0x7)) != 0) {
636 pr_debug("proto header not found\n");
640 /* adjust seqs for loopback traffic only in outgoing direction */
641 if (test_bit(IPS_SEQ_ADJUST_BIT, &ct->status) &&
642 !nf_is_loopback_packet(skb)) {
643 if (!nf_ct_seq_adjust(skb, ct, ctinfo, protoff)) {
644 NF_CT_STAT_INC_ATOMIC(nf_ct_net(ct), drop);
649 /* We've seen it coming out the other side: confirm it */
650 return nf_conntrack_confirm(skb);
653 static unsigned int ipv6_conntrack_in(void *priv,
655 const struct nf_hook_state *state)
657 return nf_conntrack_in(skb, state);
660 static unsigned int ipv6_conntrack_local(void *priv,
662 const struct nf_hook_state *state)
664 return nf_conntrack_in(skb, state);
667 static unsigned int ipv6_helper(void *priv,
669 const struct nf_hook_state *state)
672 const struct nf_conn_help *help;
673 const struct nf_conntrack_helper *helper;
674 enum ip_conntrack_info ctinfo;
679 /* This is where we call the helper: as the packet goes out. */
680 ct = nf_ct_get(skb, &ctinfo);
681 if (!ct || ctinfo == IP_CT_RELATED_REPLY)
684 help = nfct_help(ct);
687 /* rcu_read_lock()ed by nf_hook_thresh */
688 helper = rcu_dereference(help->helper);
692 nexthdr = ipv6_hdr(skb)->nexthdr;
693 protoff = ipv6_skip_exthdr(skb, sizeof(struct ipv6hdr), &nexthdr,
695 if (protoff < 0 || (frag_off & htons(~0x7)) != 0) {
696 pr_debug("proto header not found\n");
700 return helper->help(skb, protoff, ct, ctinfo);
703 static const struct nf_hook_ops ipv6_conntrack_ops[] = {
705 .hook = ipv6_conntrack_in,
707 .hooknum = NF_INET_PRE_ROUTING,
708 .priority = NF_IP6_PRI_CONNTRACK,
711 .hook = ipv6_conntrack_local,
713 .hooknum = NF_INET_LOCAL_OUT,
714 .priority = NF_IP6_PRI_CONNTRACK,
719 .hooknum = NF_INET_POST_ROUTING,
720 .priority = NF_IP6_PRI_CONNTRACK_HELPER,
723 .hook = ipv6_confirm,
725 .hooknum = NF_INET_POST_ROUTING,
726 .priority = NF_IP6_PRI_LAST,
731 .hooknum = NF_INET_LOCAL_IN,
732 .priority = NF_IP6_PRI_CONNTRACK_HELPER,
735 .hook = ipv6_confirm,
737 .hooknum = NF_INET_LOCAL_IN,
738 .priority = NF_IP6_PRI_LAST - 1,
743 static int nf_ct_tcp_fixup(struct nf_conn *ct, void *_nfproto)
745 u8 nfproto = (unsigned long)_nfproto;
747 if (nf_ct_l3num(ct) != nfproto)
750 if (nf_ct_protonum(ct) == IPPROTO_TCP &&
751 ct->proto.tcp.state == TCP_CONNTRACK_ESTABLISHED) {
752 ct->proto.tcp.seen[0].td_maxwin = 0;
753 ct->proto.tcp.seen[1].td_maxwin = 0;
759 static int nf_ct_netns_do_get(struct net *net, u8 nfproto)
761 struct nf_conntrack_net *cnet = net_generic(net, nf_conntrack_net_id);
762 bool fixup_needed = false;
765 mutex_lock(&nf_ct_proto_mutex);
770 if (cnet->users4 > 1)
772 err = nf_defrag_ipv4_enable(net);
778 err = nf_register_net_hooks(net, ipv4_conntrack_ops,
779 ARRAY_SIZE(ipv4_conntrack_ops));
785 #if IS_ENABLED(CONFIG_IPV6)
788 if (cnet->users6 > 1)
790 err = nf_defrag_ipv6_enable(net);
796 err = nf_register_net_hooks(net, ipv6_conntrack_ops,
797 ARRAY_SIZE(ipv6_conntrack_ops));
809 mutex_unlock(&nf_ct_proto_mutex);
812 nf_ct_iterate_cleanup_net(net, nf_ct_tcp_fixup,
813 (void *)(unsigned long)nfproto, 0, 0);
818 static void nf_ct_netns_do_put(struct net *net, u8 nfproto)
820 struct nf_conntrack_net *cnet = net_generic(net, nf_conntrack_net_id);
822 mutex_lock(&nf_ct_proto_mutex);
825 if (cnet->users4 && (--cnet->users4 == 0))
826 nf_unregister_net_hooks(net, ipv4_conntrack_ops,
827 ARRAY_SIZE(ipv4_conntrack_ops));
829 #if IS_ENABLED(CONFIG_IPV6)
831 if (cnet->users6 && (--cnet->users6 == 0))
832 nf_unregister_net_hooks(net, ipv6_conntrack_ops,
833 ARRAY_SIZE(ipv6_conntrack_ops));
838 mutex_unlock(&nf_ct_proto_mutex);
841 int nf_ct_netns_get(struct net *net, u8 nfproto)
845 if (nfproto == NFPROTO_INET) {
846 err = nf_ct_netns_do_get(net, NFPROTO_IPV4);
849 err = nf_ct_netns_do_get(net, NFPROTO_IPV6);
853 err = nf_ct_netns_do_get(net, nfproto);
860 nf_ct_netns_put(net, NFPROTO_IPV4);
864 EXPORT_SYMBOL_GPL(nf_ct_netns_get);
866 void nf_ct_netns_put(struct net *net, uint8_t nfproto)
868 if (nfproto == NFPROTO_INET) {
869 nf_ct_netns_do_put(net, NFPROTO_IPV4);
870 nf_ct_netns_do_put(net, NFPROTO_IPV6);
872 nf_ct_netns_do_put(net, nfproto);
875 EXPORT_SYMBOL_GPL(nf_ct_netns_put);
877 static const struct nf_conntrack_l4proto * const builtin_l4proto[] = {
878 &nf_conntrack_l4proto_tcp,
879 &nf_conntrack_l4proto_udp,
880 &nf_conntrack_l4proto_icmp,
881 #ifdef CONFIG_NF_CT_PROTO_DCCP
882 &nf_conntrack_l4proto_dccp,
884 #ifdef CONFIG_NF_CT_PROTO_SCTP
885 &nf_conntrack_l4proto_sctp,
887 #ifdef CONFIG_NF_CT_PROTO_UDPLITE
888 &nf_conntrack_l4proto_udplite,
890 #if IS_ENABLED(CONFIG_IPV6)
891 &nf_conntrack_l4proto_icmpv6,
892 #endif /* CONFIG_IPV6 */
895 int nf_conntrack_proto_init(void)
899 ret = nf_register_sockopt(&so_getorigdst);
903 #if IS_ENABLED(CONFIG_IPV6)
904 ret = nf_register_sockopt(&so_getorigdst6);
906 goto cleanup_sockopt;
909 for (i = 0; i < ARRAY_SIZE(nf_ct_protos); i++)
910 RCU_INIT_POINTER(nf_ct_protos[i],
911 &nf_conntrack_l4proto_generic);
913 ret = nf_ct_l4proto_register(builtin_l4proto,
914 ARRAY_SIZE(builtin_l4proto));
916 goto cleanup_sockopt2;
920 nf_unregister_sockopt(&so_getorigdst);
921 #if IS_ENABLED(CONFIG_IPV6)
923 nf_unregister_sockopt(&so_getorigdst6);
928 void nf_conntrack_proto_fini(void)
930 nf_unregister_sockopt(&so_getorigdst);
931 #if IS_ENABLED(CONFIG_IPV6)
932 nf_unregister_sockopt(&so_getorigdst6);
936 int nf_conntrack_proto_pernet_init(struct net *net)
939 struct nf_proto_net *pn = nf_ct_l4proto_net(net,
940 &nf_conntrack_l4proto_generic);
942 err = nf_conntrack_l4proto_generic.init_net(net);
945 err = nf_ct_l4proto_register_sysctl(net,
950 err = nf_ct_l4proto_pernet_register(net, builtin_l4proto,
951 ARRAY_SIZE(builtin_l4proto));
953 nf_ct_l4proto_unregister_sysctl(pn);
961 void nf_conntrack_proto_pernet_fini(struct net *net)
963 struct nf_proto_net *pn = nf_ct_l4proto_net(net,
964 &nf_conntrack_l4proto_generic);
966 nf_ct_l4proto_pernet_unregister(net, builtin_l4proto,
967 ARRAY_SIZE(builtin_l4proto));
969 nf_ct_l4proto_unregister_sysctl(pn);
973 module_param_call(hashsize, nf_conntrack_set_hashsize, param_get_uint,
974 &nf_conntrack_htable_size, 0600);
976 MODULE_ALIAS("ip_conntrack");
977 MODULE_ALIAS("nf_conntrack-" __stringify(AF_INET));
978 MODULE_ALIAS("nf_conntrack-" __stringify(AF_INET6));
979 MODULE_LICENSE("GPL");