2 * PF_INET6 socket protocol family
3 * Linux INET6 implementation
6 * Pedro Roque <roque@di.fc.ul.pt>
8 * Adapted from linux/net/ipv4/af_inet.c
11 * piggy, Karl Knutson : Socket protocol table
12 * Hideaki YOSHIFUJI : sin6_scope_id support
13 * Arnaldo Melo : check proc_net_create return, cleanups
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version
18 * 2 of the License, or (at your option) any later version.
21 #define pr_fmt(fmt) "IPv6: " fmt
23 #include <linux/module.h>
24 #include <linux/capability.h>
25 #include <linux/errno.h>
26 #include <linux/types.h>
27 #include <linux/socket.h>
29 #include <linux/kernel.h>
30 #include <linux/timer.h>
31 #include <linux/string.h>
32 #include <linux/sockios.h>
33 #include <linux/net.h>
34 #include <linux/fcntl.h>
36 #include <linux/interrupt.h>
37 #include <linux/proc_fs.h>
38 #include <linux/stat.h>
39 #include <linux/init.h>
40 #include <linux/slab.h>
42 #include <linux/inet.h>
43 #include <linux/netdevice.h>
44 #include <linux/icmpv6.h>
45 #include <linux/netfilter_ipv6.h>
50 #include <net/udplite.h>
52 #include <net/protocol.h>
53 #include <net/inet_common.h>
54 #include <net/route.h>
55 #include <net/transp_v6.h>
56 #include <net/ip6_route.h>
57 #include <net/addrconf.h>
58 #ifdef CONFIG_IPV6_TUNNEL
59 #include <net/ip6_tunnel.h>
62 #include <asm/uaccess.h>
63 #include <linux/mroute6.h>
65 #ifdef CONFIG_ANDROID_PARANOID_NETWORK
66 #include <linux/android_aid.h>
68 static inline int current_has_network(void)
70 return in_egroup_p(AID_INET) || capable(CAP_NET_RAW);
73 static inline int current_has_network(void)
79 MODULE_AUTHOR("Cast of dozens");
80 MODULE_DESCRIPTION("IPv6 protocol stack for Linux");
81 MODULE_LICENSE("GPL");
83 /* The inetsw6 table contains everything that inet6_create needs to
86 static struct list_head inetsw6[SOCK_MAX];
87 static DEFINE_SPINLOCK(inetsw6_lock);
89 struct ipv6_params ipv6_defaults = {
94 static int disable_ipv6_mod;
96 module_param_named(disable, disable_ipv6_mod, int, 0444);
97 MODULE_PARM_DESC(disable, "Disable IPv6 module such that it is non-functional");
99 module_param_named(disable_ipv6, ipv6_defaults.disable_ipv6, int, 0444);
100 MODULE_PARM_DESC(disable_ipv6, "Disable IPv6 on all interfaces");
102 module_param_named(autoconf, ipv6_defaults.autoconf, int, 0444);
103 MODULE_PARM_DESC(autoconf, "Enable IPv6 address autoconfiguration on all interfaces");
105 static __inline__ struct ipv6_pinfo *inet6_sk_generic(struct sock *sk)
107 const int offset = sk->sk_prot->obj_size - sizeof(struct ipv6_pinfo);
109 return (struct ipv6_pinfo *)(((u8 *)sk) + offset);
112 static int inet6_create(struct net *net, struct socket *sock, int protocol,
115 struct inet_sock *inet;
116 struct ipv6_pinfo *np;
118 struct inet_protosw *answer;
119 struct proto *answer_prot;
120 unsigned char answer_flags;
121 char answer_no_check;
122 int try_loading_module = 0;
125 if (!current_has_network())
128 if (sock->type != SOCK_RAW &&
129 sock->type != SOCK_DGRAM &&
131 build_ehash_secret();
133 /* Look for the requested type/protocol pair. */
135 err = -ESOCKTNOSUPPORT;
137 list_for_each_entry_rcu(answer, &inetsw6[sock->type], list) {
140 /* Check the non-wild match. */
141 if (protocol == answer->protocol) {
142 if (protocol != IPPROTO_IP)
145 /* Check for the two wild cases. */
146 if (IPPROTO_IP == protocol) {
147 protocol = answer->protocol;
150 if (IPPROTO_IP == answer->protocol)
153 err = -EPROTONOSUPPORT;
157 if (try_loading_module < 2) {
160 * Be more specific, e.g. net-pf-10-proto-132-type-1
161 * (net-pf-PF_INET6-proto-IPPROTO_SCTP-type-SOCK_STREAM)
163 if (++try_loading_module == 1)
164 request_module("net-pf-%d-proto-%d-type-%d",
165 PF_INET6, protocol, sock->type);
167 * Fall back to generic, e.g. net-pf-10-proto-132
168 * (net-pf-PF_INET6-proto-IPPROTO_SCTP)
171 request_module("net-pf-%d-proto-%d",
173 goto lookup_protocol;
179 if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
182 sock->ops = answer->ops;
183 answer_prot = answer->prot;
184 answer_no_check = answer->no_check;
185 answer_flags = answer->flags;
188 WARN_ON(answer_prot->slab == NULL);
191 sk = sk_alloc(net, PF_INET6, GFP_KERNEL, answer_prot);
195 sock_init_data(sock, sk);
198 sk->sk_no_check = answer_no_check;
199 if (INET_PROTOSW_REUSE & answer_flags)
200 sk->sk_reuse = SK_CAN_REUSE;
203 inet->is_icsk = (INET_PROTOSW_ICSK & answer_flags) != 0;
205 if (SOCK_RAW == sock->type) {
206 inet->inet_num = protocol;
207 if (IPPROTO_RAW == protocol)
211 sk->sk_destruct = inet_sock_destruct;
212 sk->sk_family = PF_INET6;
213 sk->sk_protocol = protocol;
215 sk->sk_backlog_rcv = answer->prot->backlog_rcv;
217 inet_sk(sk)->pinet6 = np = inet6_sk_generic(sk);
219 np->mcast_hops = IPV6_DEFAULT_MCASTHOPS;
221 np->pmtudisc = IPV6_PMTUDISC_WANT;
222 np->ipv6only = net->ipv6.sysctl.bindv6only;
224 /* Init the ipv4 part of the socket since we can have sockets
225 * using v6 API for ipv4.
232 inet->mc_list = NULL;
235 if (ipv4_config.no_pmtu_disc)
236 inet->pmtudisc = IP_PMTUDISC_DONT;
238 inet->pmtudisc = IP_PMTUDISC_WANT;
240 * Increment only the relevant sk_prot->socks debug field, this changes
241 * the previous behaviour of incrementing both the equivalent to
242 * answer->prot->socks (inet6_sock_nr) and inet_sock_nr.
244 * This allows better debug granularity as we'll know exactly how many
245 * UDPv6, TCPv6, etc socks were allocated, not the sum of all IPv6
246 * transport protocol socks. -acme
248 sk_refcnt_debug_inc(sk);
250 if (inet->inet_num) {
251 /* It assumes that any protocol which allows
252 * the user to assign a number at socket
253 * creation time automatically shares.
255 inet->inet_sport = htons(inet->inet_num);
256 sk->sk_prot->hash(sk);
258 if (sk->sk_prot->init) {
259 err = sk->sk_prot->init(sk);
261 sk_common_release(sk);
273 /* bind for INET6 API */
274 int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
276 struct sockaddr_in6 *addr = (struct sockaddr_in6 *)uaddr;
277 struct sock *sk = sock->sk;
278 struct inet_sock *inet = inet_sk(sk);
279 struct ipv6_pinfo *np = inet6_sk(sk);
280 struct net *net = sock_net(sk);
286 /* If the socket has its own bind function then use it. */
287 if (sk->sk_prot->bind)
288 return sk->sk_prot->bind(sk, uaddr, addr_len);
290 if (addr_len < SIN6_LEN_RFC2133)
293 if (addr->sin6_family != AF_INET6)
294 return -EAFNOSUPPORT;
296 addr_type = ipv6_addr_type(&addr->sin6_addr);
297 if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
300 snum = ntohs(addr->sin6_port);
301 if (snum && snum < PROT_SOCK && !ns_capable(net->user_ns, CAP_NET_BIND_SERVICE))
306 /* Check these errors (active socket, double bind). */
307 if (sk->sk_state != TCP_CLOSE || inet->inet_num) {
312 /* Check if the address belongs to the host. */
313 if (addr_type == IPV6_ADDR_MAPPED) {
316 /* Binding to v4-mapped address on a v6-only socket
324 /* Reproduce AF_INET checks to make the bindings consistent */
325 v4addr = addr->sin6_addr.s6_addr32[3];
326 chk_addr_ret = inet_addr_type(net, v4addr);
327 if (!sysctl_ip_nonlocal_bind &&
328 !(inet->freebind || inet->transparent) &&
329 v4addr != htonl(INADDR_ANY) &&
330 chk_addr_ret != RTN_LOCAL &&
331 chk_addr_ret != RTN_MULTICAST &&
332 chk_addr_ret != RTN_BROADCAST) {
333 err = -EADDRNOTAVAIL;
337 if (addr_type != IPV6_ADDR_ANY) {
338 struct net_device *dev = NULL;
341 if (__ipv6_addr_needs_scope_id(addr_type)) {
342 if (addr_len >= sizeof(struct sockaddr_in6) &&
343 addr->sin6_scope_id) {
344 /* Override any existing binding, if another one
345 * is supplied by user.
347 sk->sk_bound_dev_if = addr->sin6_scope_id;
350 /* Binding to link-local address requires an interface */
351 if (!sk->sk_bound_dev_if) {
355 dev = dev_get_by_index_rcu(net, sk->sk_bound_dev_if);
362 /* ipv4 addr of the socket is invalid. Only the
363 * unspecified and mapped address have a v4 equivalent.
365 v4addr = LOOPBACK4_IPV6;
366 if (!(addr_type & IPV6_ADDR_MULTICAST)) {
367 if (!(inet->freebind || inet->transparent) &&
368 !ipv6_chk_addr(net, &addr->sin6_addr,
370 err = -EADDRNOTAVAIL;
378 inet->inet_rcv_saddr = v4addr;
379 inet->inet_saddr = v4addr;
381 np->rcv_saddr = addr->sin6_addr;
383 if (!(addr_type & IPV6_ADDR_MULTICAST))
384 np->saddr = addr->sin6_addr;
386 /* Make sure we are allowed to bind here. */
387 if (sk->sk_prot->get_port(sk, snum)) {
388 inet_reset_saddr(sk);
393 if (addr_type != IPV6_ADDR_ANY) {
394 sk->sk_userlocks |= SOCK_BINDADDR_LOCK;
395 if (addr_type != IPV6_ADDR_MAPPED)
399 sk->sk_userlocks |= SOCK_BINDPORT_LOCK;
400 inet->inet_sport = htons(inet->inet_num);
401 inet->inet_dport = 0;
402 inet->inet_daddr = 0;
410 EXPORT_SYMBOL(inet6_bind);
412 int inet6_release(struct socket *sock)
414 struct sock *sk = sock->sk;
420 ipv6_sock_mc_close(sk);
423 ipv6_sock_ac_close(sk);
425 return inet_release(sock);
427 EXPORT_SYMBOL(inet6_release);
429 void inet6_destroy_sock(struct sock *sk)
431 struct ipv6_pinfo *np = inet6_sk(sk);
433 struct ipv6_txoptions *opt;
435 /* Release rx options */
437 skb = xchg(&np->pktoptions, NULL);
441 skb = xchg(&np->rxpmtu, NULL);
445 /* Free flowlabels */
446 fl6_free_socklist(sk);
448 /* Free tx options */
450 opt = xchg(&np->opt, NULL);
452 sock_kfree_s(sk, opt, opt->tot_len);
454 EXPORT_SYMBOL_GPL(inet6_destroy_sock);
457 * This does both peername and sockname.
460 int inet6_getname(struct socket *sock, struct sockaddr *uaddr,
461 int *uaddr_len, int peer)
463 struct sockaddr_in6 *sin = (struct sockaddr_in6 *)uaddr;
464 struct sock *sk = sock->sk;
465 struct inet_sock *inet = inet_sk(sk);
466 struct ipv6_pinfo *np = inet6_sk(sk);
468 sin->sin6_family = AF_INET6;
469 sin->sin6_flowinfo = 0;
470 sin->sin6_scope_id = 0;
472 if (!inet->inet_dport)
474 if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_SYN_SENT)) &&
477 sin->sin6_port = inet->inet_dport;
478 sin->sin6_addr = np->daddr;
480 sin->sin6_flowinfo = np->flow_label;
482 if (ipv6_addr_any(&np->rcv_saddr))
483 sin->sin6_addr = np->saddr;
485 sin->sin6_addr = np->rcv_saddr;
487 sin->sin6_port = inet->inet_sport;
489 sin->sin6_scope_id = ipv6_iface_scope_id(&sin->sin6_addr,
490 sk->sk_bound_dev_if);
491 *uaddr_len = sizeof(*sin);
494 EXPORT_SYMBOL(inet6_getname);
496 int inet6_killaddr_ioctl(struct net *net, void __user *arg) {
497 struct in6_ifreq ireq;
498 struct sockaddr_in6 sin6;
500 if (!capable(CAP_NET_ADMIN))
503 if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq)))
506 sin6.sin6_family = AF_INET6;
507 sin6.sin6_addr = ireq.ifr6_addr;
508 return tcp_nuke_addr(net, (struct sockaddr *) &sin6);
511 int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
513 struct sock *sk = sock->sk;
514 struct net *net = sock_net(sk);
518 return sock_get_timestamp(sk, (struct timeval __user *)arg);
521 return sock_get_timestampns(sk, (struct timespec __user *)arg);
526 return ipv6_route_ioctl(net, cmd, (void __user *)arg);
529 return addrconf_add_ifaddr(net, (void __user *) arg);
531 return addrconf_del_ifaddr(net, (void __user *) arg);
533 return addrconf_set_dstaddr(net, (void __user *) arg);
535 return inet6_killaddr_ioctl(net, (void __user *) arg);
537 if (!sk->sk_prot->ioctl)
539 return sk->sk_prot->ioctl(sk, cmd, arg);
544 EXPORT_SYMBOL(inet6_ioctl);
546 const struct proto_ops inet6_stream_ops = {
548 .owner = THIS_MODULE,
549 .release = inet6_release,
551 .connect = inet_stream_connect, /* ok */
552 .socketpair = sock_no_socketpair, /* a do nothing */
553 .accept = inet_accept, /* ok */
554 .getname = inet6_getname,
555 .poll = tcp_poll, /* ok */
556 .ioctl = inet6_ioctl, /* must change */
557 .listen = inet_listen, /* ok */
558 .shutdown = inet_shutdown, /* ok */
559 .setsockopt = sock_common_setsockopt, /* ok */
560 .getsockopt = sock_common_getsockopt, /* ok */
561 .sendmsg = inet_sendmsg, /* ok */
562 .recvmsg = inet_recvmsg, /* ok */
563 .mmap = sock_no_mmap,
564 .sendpage = inet_sendpage,
565 .splice_read = tcp_splice_read,
567 .compat_setsockopt = compat_sock_common_setsockopt,
568 .compat_getsockopt = compat_sock_common_getsockopt,
572 const struct proto_ops inet6_dgram_ops = {
574 .owner = THIS_MODULE,
575 .release = inet6_release,
577 .connect = inet_dgram_connect, /* ok */
578 .socketpair = sock_no_socketpair, /* a do nothing */
579 .accept = sock_no_accept, /* a do nothing */
580 .getname = inet6_getname,
581 .poll = udp_poll, /* ok */
582 .ioctl = inet6_ioctl, /* must change */
583 .listen = sock_no_listen, /* ok */
584 .shutdown = inet_shutdown, /* ok */
585 .setsockopt = sock_common_setsockopt, /* ok */
586 .getsockopt = sock_common_getsockopt, /* ok */
587 .sendmsg = inet_sendmsg, /* ok */
588 .recvmsg = inet_recvmsg, /* ok */
589 .mmap = sock_no_mmap,
590 .sendpage = sock_no_sendpage,
592 .compat_setsockopt = compat_sock_common_setsockopt,
593 .compat_getsockopt = compat_sock_common_getsockopt,
597 static const struct net_proto_family inet6_family_ops = {
599 .create = inet6_create,
600 .owner = THIS_MODULE,
603 int inet6_register_protosw(struct inet_protosw *p)
605 struct list_head *lh;
606 struct inet_protosw *answer;
607 struct list_head *last_perm;
608 int protocol = p->protocol;
611 spin_lock_bh(&inetsw6_lock);
614 if (p->type >= SOCK_MAX)
617 /* If we are trying to override a permanent protocol, bail. */
620 last_perm = &inetsw6[p->type];
621 list_for_each(lh, &inetsw6[p->type]) {
622 answer = list_entry(lh, struct inet_protosw, list);
624 /* Check only the non-wild match. */
625 if (INET_PROTOSW_PERMANENT & answer->flags) {
626 if (protocol == answer->protocol)
636 /* Add the new entry after the last permanent entry if any, so that
637 * the new entry does not override a permanent entry when matched with
638 * a wild-card protocol. But it is allowed to override any existing
639 * non-permanent entry. This means that when we remove this entry, the
640 * system automatically returns to the old behavior.
642 list_add_rcu(&p->list, last_perm);
645 spin_unlock_bh(&inetsw6_lock);
649 pr_err("Attempt to override permanent protocol %d\n", protocol);
653 pr_err("Ignoring attempt to register invalid socket type %d\n",
657 EXPORT_SYMBOL(inet6_register_protosw);
660 inet6_unregister_protosw(struct inet_protosw *p)
662 if (INET_PROTOSW_PERMANENT & p->flags) {
663 pr_err("Attempt to unregister permanent protocol %d\n",
666 spin_lock_bh(&inetsw6_lock);
667 list_del_rcu(&p->list);
668 spin_unlock_bh(&inetsw6_lock);
673 EXPORT_SYMBOL(inet6_unregister_protosw);
675 int inet6_sk_rebuild_header(struct sock *sk)
677 struct ipv6_pinfo *np = inet6_sk(sk);
678 struct dst_entry *dst;
680 dst = __sk_dst_check(sk, np->dst_cookie);
683 struct inet_sock *inet = inet_sk(sk);
684 struct in6_addr *final_p, final;
687 memset(&fl6, 0, sizeof(fl6));
688 fl6.flowi6_proto = sk->sk_protocol;
689 fl6.daddr = np->daddr;
690 fl6.saddr = np->saddr;
691 fl6.flowlabel = np->flow_label;
692 fl6.flowi6_oif = sk->sk_bound_dev_if;
693 fl6.flowi6_mark = sk->sk_mark;
694 fl6.fl6_dport = inet->inet_dport;
695 fl6.fl6_sport = inet->inet_sport;
696 security_sk_classify_flow(sk, flowi6_to_flowi(&fl6));
698 final_p = fl6_update_dst(&fl6, np->opt, &final);
700 dst = ip6_dst_lookup_flow(sk, &fl6, final_p, false);
702 sk->sk_route_caps = 0;
703 sk->sk_err_soft = -PTR_ERR(dst);
707 __ip6_dst_store(sk, dst, NULL, NULL);
712 EXPORT_SYMBOL_GPL(inet6_sk_rebuild_header);
714 bool ipv6_opt_accepted(const struct sock *sk, const struct sk_buff *skb)
716 const struct ipv6_pinfo *np = inet6_sk(sk);
717 const struct inet6_skb_parm *opt = IP6CB(skb);
720 if ((opt->hop && (np->rxopt.bits.hopopts ||
721 np->rxopt.bits.ohopopts)) ||
722 ((IPV6_FLOWINFO_MASK &
723 *(__be32 *)skb_network_header(skb)) &&
724 np->rxopt.bits.rxflow) ||
725 (opt->srcrt && (np->rxopt.bits.srcrt ||
726 np->rxopt.bits.osrcrt)) ||
727 ((opt->dst1 || opt->dst0) &&
728 (np->rxopt.bits.dstopts || np->rxopt.bits.odstopts)))
733 EXPORT_SYMBOL_GPL(ipv6_opt_accepted);
735 static struct packet_type ipv6_packet_type __read_mostly = {
736 .type = cpu_to_be16(ETH_P_IPV6),
740 static int __init ipv6_packet_init(void)
742 dev_add_pack(&ipv6_packet_type);
746 static void ipv6_packet_cleanup(void)
748 dev_remove_pack(&ipv6_packet_type);
751 static int __net_init ipv6_init_mibs(struct net *net)
753 if (snmp_mib_init((void __percpu **)net->mib.udp_stats_in6,
754 sizeof(struct udp_mib),
755 __alignof__(struct udp_mib)) < 0)
757 if (snmp_mib_init((void __percpu **)net->mib.udplite_stats_in6,
758 sizeof(struct udp_mib),
759 __alignof__(struct udp_mib)) < 0)
760 goto err_udplite_mib;
761 if (snmp_mib_init((void __percpu **)net->mib.ipv6_statistics,
762 sizeof(struct ipstats_mib),
763 __alignof__(struct ipstats_mib)) < 0)
765 if (snmp_mib_init((void __percpu **)net->mib.icmpv6_statistics,
766 sizeof(struct icmpv6_mib),
767 __alignof__(struct icmpv6_mib)) < 0)
769 net->mib.icmpv6msg_statistics = kzalloc(sizeof(struct icmpv6msg_mib),
771 if (!net->mib.icmpv6msg_statistics)
772 goto err_icmpmsg_mib;
776 snmp_mib_free((void __percpu **)net->mib.icmpv6_statistics);
778 snmp_mib_free((void __percpu **)net->mib.ipv6_statistics);
780 snmp_mib_free((void __percpu **)net->mib.udplite_stats_in6);
782 snmp_mib_free((void __percpu **)net->mib.udp_stats_in6);
786 static void ipv6_cleanup_mibs(struct net *net)
788 snmp_mib_free((void __percpu **)net->mib.udp_stats_in6);
789 snmp_mib_free((void __percpu **)net->mib.udplite_stats_in6);
790 snmp_mib_free((void __percpu **)net->mib.ipv6_statistics);
791 snmp_mib_free((void __percpu **)net->mib.icmpv6_statistics);
792 kfree(net->mib.icmpv6msg_statistics);
795 static int __net_init inet6_net_init(struct net *net)
799 net->ipv6.sysctl.bindv6only = 0;
800 net->ipv6.sysctl.icmpv6_time = 1*HZ;
802 err = ipv6_init_mibs(net);
805 #ifdef CONFIG_PROC_FS
806 err = udp6_proc_init(net);
809 err = tcp6_proc_init(net);
812 err = ac6_proc_init(net);
818 #ifdef CONFIG_PROC_FS
824 ipv6_cleanup_mibs(net);
829 static void __net_exit inet6_net_exit(struct net *net)
831 #ifdef CONFIG_PROC_FS
836 ipv6_cleanup_mibs(net);
839 static struct pernet_operations inet6_net_ops = {
840 .init = inet6_net_init,
841 .exit = inet6_net_exit,
844 static int __init inet6_init(void)
849 BUILD_BUG_ON(sizeof(struct inet6_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
851 /* Register the socket-side information for inet6_create. */
852 for (r = &inetsw6[0]; r < &inetsw6[SOCK_MAX]; ++r)
855 if (disable_ipv6_mod) {
856 pr_info("Loaded, but administratively disabled, reboot required to enable\n");
860 err = proto_register(&tcpv6_prot, 1);
864 err = proto_register(&udpv6_prot, 1);
866 goto out_unregister_tcp_proto;
868 err = proto_register(&udplitev6_prot, 1);
870 goto out_unregister_udp_proto;
872 err = proto_register(&rawv6_prot, 1);
874 goto out_unregister_udplite_proto;
877 /* We MUST register RAW sockets before we create the ICMP6,
878 * IGMP6, or NDISC control sockets.
882 goto out_unregister_raw_proto;
884 /* Register the family here so that the init calls below will
885 * be able to create sockets. (?? is this dangerous ??)
887 err = sock_register(&inet6_family_ops);
889 goto out_sock_register_fail;
891 tcpv6_prot.sysctl_mem = init_net.ipv4.sysctl_tcp_mem;
894 * ipngwg API draft makes clear that the correct semantics
895 * for TCP and UDP is to consider one TCP and UDP instance
896 * in a host available by both INET and INET6 APIs and
897 * able to communicate via both network protocols.
900 err = register_pernet_subsys(&inet6_net_ops);
902 goto register_pernet_fail;
915 err = ipv6_netfilter_init();
918 /* Create /proc/foo6 entries. */
919 #ifdef CONFIG_PROC_FS
921 if (raw6_proc_init())
923 if (udplite6_proc_init())
924 goto proc_udplite6_fail;
925 if (ipv6_misc_proc_init())
926 goto proc_misc6_fail;
930 err = ip6_route_init();
933 err = ip6_flowlabel_init();
935 goto ip6_flowlabel_fail;
936 err = addrconf_init();
940 /* Init v6 extension headers. */
941 err = ipv6_exthdrs_init();
943 goto ipv6_exthdrs_fail;
945 err = ipv6_frag_init();
949 /* Init v6 transport protocols. */
954 err = udplitev6_init();
962 err = ipv6_packet_init();
964 goto ipv6_packet_fail;
967 err = ipv6_sysctl_register();
976 ipv6_packet_cleanup();
991 ip6_flowlabel_cleanup();
995 #ifdef CONFIG_PROC_FS
998 ipv6_misc_proc_exit();
1000 udplite6_proc_exit();
1005 ipv6_netfilter_fini();
1015 unregister_pernet_subsys(&inet6_net_ops);
1016 register_pernet_fail:
1017 sock_unregister(PF_INET6);
1018 rtnl_unregister_all(PF_INET6);
1019 out_sock_register_fail:
1021 out_unregister_raw_proto:
1022 proto_unregister(&rawv6_prot);
1023 out_unregister_udplite_proto:
1024 proto_unregister(&udplitev6_prot);
1025 out_unregister_udp_proto:
1026 proto_unregister(&udpv6_prot);
1027 out_unregister_tcp_proto:
1028 proto_unregister(&tcpv6_prot);
1031 module_init(inet6_init);
1033 static void __exit inet6_exit(void)
1035 if (disable_ipv6_mod)
1038 /* First of all disallow new sockets creation. */
1039 sock_unregister(PF_INET6);
1040 /* Disallow any further netlink messages */
1041 rtnl_unregister_all(PF_INET6);
1047 /* Cleanup code parts. */
1048 ipv6_packet_cleanup();
1050 ipv6_exthdrs_exit();
1052 ip6_flowlabel_cleanup();
1053 ip6_route_cleanup();
1054 #ifdef CONFIG_PROC_FS
1056 /* Cleanup code parts. */
1058 ipv6_misc_proc_exit();
1059 udplite6_proc_exit();
1062 ipv6_netfilter_fini();
1069 unregister_pernet_subsys(&inet6_net_ops);
1070 proto_unregister(&rawv6_prot);
1071 proto_unregister(&udplitev6_prot);
1072 proto_unregister(&udpv6_prot);
1073 proto_unregister(&tcpv6_prot);
1075 rcu_barrier(); /* Wait for completion of call_rcu()'s */
1077 module_exit(inet6_exit);
1079 MODULE_ALIAS_NETPROTO(PF_INET6);