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 MODULE_AUTHOR("Cast of dozens");
66 MODULE_DESCRIPTION("IPv6 protocol stack for Linux");
67 MODULE_LICENSE("GPL");
69 /* The inetsw6 table contains everything that inet6_create needs to
72 static struct list_head inetsw6[SOCK_MAX];
73 static DEFINE_SPINLOCK(inetsw6_lock);
75 struct ipv6_params ipv6_defaults = {
80 static int disable_ipv6_mod;
82 module_param_named(disable, disable_ipv6_mod, int, 0444);
83 MODULE_PARM_DESC(disable, "Disable IPv6 module such that it is non-functional");
85 module_param_named(disable_ipv6, ipv6_defaults.disable_ipv6, int, 0444);
86 MODULE_PARM_DESC(disable_ipv6, "Disable IPv6 on all interfaces");
88 module_param_named(autoconf, ipv6_defaults.autoconf, int, 0444);
89 MODULE_PARM_DESC(autoconf, "Enable IPv6 address autoconfiguration on all interfaces");
91 static __inline__ struct ipv6_pinfo *inet6_sk_generic(struct sock *sk)
93 const int offset = sk->sk_prot->obj_size - sizeof(struct ipv6_pinfo);
95 return (struct ipv6_pinfo *)(((u8 *)sk) + offset);
98 static int inet6_create(struct net *net, struct socket *sock, int protocol,
101 struct inet_sock *inet;
102 struct ipv6_pinfo *np;
104 struct inet_protosw *answer;
105 struct proto *answer_prot;
106 unsigned char answer_flags;
107 char answer_no_check;
108 int try_loading_module = 0;
111 if (sock->type != SOCK_RAW &&
112 sock->type != SOCK_DGRAM &&
114 build_ehash_secret();
116 if (protocol < 0 || protocol >= IPPROTO_MAX)
119 /* Look for the requested type/protocol pair. */
121 err = -ESOCKTNOSUPPORT;
123 list_for_each_entry_rcu(answer, &inetsw6[sock->type], list) {
126 /* Check the non-wild match. */
127 if (protocol == answer->protocol) {
128 if (protocol != IPPROTO_IP)
131 /* Check for the two wild cases. */
132 if (IPPROTO_IP == protocol) {
133 protocol = answer->protocol;
136 if (IPPROTO_IP == answer->protocol)
139 err = -EPROTONOSUPPORT;
143 if (try_loading_module < 2) {
146 * Be more specific, e.g. net-pf-10-proto-132-type-1
147 * (net-pf-PF_INET6-proto-IPPROTO_SCTP-type-SOCK_STREAM)
149 if (++try_loading_module == 1)
150 request_module("net-pf-%d-proto-%d-type-%d",
151 PF_INET6, protocol, sock->type);
153 * Fall back to generic, e.g. net-pf-10-proto-132
154 * (net-pf-PF_INET6-proto-IPPROTO_SCTP)
157 request_module("net-pf-%d-proto-%d",
159 goto lookup_protocol;
165 if (sock->type == SOCK_RAW && !kern &&
166 !ns_capable(net->user_ns, CAP_NET_RAW))
169 sock->ops = answer->ops;
170 answer_prot = answer->prot;
171 answer_no_check = answer->no_check;
172 answer_flags = answer->flags;
175 WARN_ON(answer_prot->slab == NULL);
178 sk = sk_alloc(net, PF_INET6, GFP_KERNEL, answer_prot);
182 sock_init_data(sock, sk);
185 sk->sk_no_check = answer_no_check;
186 if (INET_PROTOSW_REUSE & answer_flags)
187 sk->sk_reuse = SK_CAN_REUSE;
190 inet->is_icsk = (INET_PROTOSW_ICSK & answer_flags) != 0;
192 if (SOCK_RAW == sock->type) {
193 inet->inet_num = protocol;
194 if (IPPROTO_RAW == protocol)
198 sk->sk_destruct = inet_sock_destruct;
199 sk->sk_family = PF_INET6;
200 sk->sk_protocol = protocol;
202 sk->sk_backlog_rcv = answer->prot->backlog_rcv;
204 inet_sk(sk)->pinet6 = np = inet6_sk_generic(sk);
206 np->mcast_hops = IPV6_DEFAULT_MCASTHOPS;
208 np->pmtudisc = IPV6_PMTUDISC_WANT;
209 np->ipv6only = net->ipv6.sysctl.bindv6only;
211 /* Init the ipv4 part of the socket since we can have sockets
212 * using v6 API for ipv4.
219 inet->mc_list = NULL;
222 if (ipv4_config.no_pmtu_disc)
223 inet->pmtudisc = IP_PMTUDISC_DONT;
225 inet->pmtudisc = IP_PMTUDISC_WANT;
227 * Increment only the relevant sk_prot->socks debug field, this changes
228 * the previous behaviour of incrementing both the equivalent to
229 * answer->prot->socks (inet6_sock_nr) and inet_sock_nr.
231 * This allows better debug granularity as we'll know exactly how many
232 * UDPv6, TCPv6, etc socks were allocated, not the sum of all IPv6
233 * transport protocol socks. -acme
235 sk_refcnt_debug_inc(sk);
237 if (inet->inet_num) {
238 /* It assumes that any protocol which allows
239 * the user to assign a number at socket
240 * creation time automatically shares.
242 inet->inet_sport = htons(inet->inet_num);
243 sk->sk_prot->hash(sk);
245 if (sk->sk_prot->init) {
246 err = sk->sk_prot->init(sk);
248 sk_common_release(sk);
260 /* bind for INET6 API */
261 int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
263 struct sockaddr_in6 *addr = (struct sockaddr_in6 *)uaddr;
264 struct sock *sk = sock->sk;
265 struct inet_sock *inet = inet_sk(sk);
266 struct ipv6_pinfo *np = inet6_sk(sk);
267 struct net *net = sock_net(sk);
273 /* If the socket has its own bind function then use it. */
274 if (sk->sk_prot->bind)
275 return sk->sk_prot->bind(sk, uaddr, addr_len);
277 if (addr_len < SIN6_LEN_RFC2133)
280 if (addr->sin6_family != AF_INET6)
281 return -EAFNOSUPPORT;
283 addr_type = ipv6_addr_type(&addr->sin6_addr);
284 if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
287 snum = ntohs(addr->sin6_port);
288 if (snum && snum < PROT_SOCK && !ns_capable(net->user_ns, CAP_NET_BIND_SERVICE))
293 /* Check these errors (active socket, double bind). */
294 if (sk->sk_state != TCP_CLOSE || inet->inet_num) {
299 /* Check if the address belongs to the host. */
300 if (addr_type == IPV6_ADDR_MAPPED) {
303 /* Binding to v4-mapped address on a v6-only socket
311 /* Reproduce AF_INET checks to make the bindings consistent */
312 v4addr = addr->sin6_addr.s6_addr32[3];
313 chk_addr_ret = inet_addr_type(net, v4addr);
314 if (!sysctl_ip_nonlocal_bind &&
315 !(inet->freebind || inet->transparent) &&
316 v4addr != htonl(INADDR_ANY) &&
317 chk_addr_ret != RTN_LOCAL &&
318 chk_addr_ret != RTN_MULTICAST &&
319 chk_addr_ret != RTN_BROADCAST) {
320 err = -EADDRNOTAVAIL;
324 if (addr_type != IPV6_ADDR_ANY) {
325 struct net_device *dev = NULL;
328 if (__ipv6_addr_needs_scope_id(addr_type)) {
329 if (addr_len >= sizeof(struct sockaddr_in6) &&
330 addr->sin6_scope_id) {
331 /* Override any existing binding, if another one
332 * is supplied by user.
334 sk->sk_bound_dev_if = addr->sin6_scope_id;
337 /* Binding to link-local address requires an interface */
338 if (!sk->sk_bound_dev_if) {
342 dev = dev_get_by_index_rcu(net, sk->sk_bound_dev_if);
349 /* ipv4 addr of the socket is invalid. Only the
350 * unspecified and mapped address have a v4 equivalent.
352 v4addr = LOOPBACK4_IPV6;
353 if (!(addr_type & IPV6_ADDR_MULTICAST)) {
354 if (!(inet->freebind || inet->transparent) &&
355 !ipv6_chk_addr(net, &addr->sin6_addr,
357 err = -EADDRNOTAVAIL;
365 inet->inet_rcv_saddr = v4addr;
366 inet->inet_saddr = v4addr;
368 np->rcv_saddr = addr->sin6_addr;
370 if (!(addr_type & IPV6_ADDR_MULTICAST))
371 np->saddr = addr->sin6_addr;
373 /* Make sure we are allowed to bind here. */
374 if (sk->sk_prot->get_port(sk, snum)) {
375 inet_reset_saddr(sk);
380 if (addr_type != IPV6_ADDR_ANY) {
381 sk->sk_userlocks |= SOCK_BINDADDR_LOCK;
382 if (addr_type != IPV6_ADDR_MAPPED)
386 sk->sk_userlocks |= SOCK_BINDPORT_LOCK;
387 inet->inet_sport = htons(inet->inet_num);
388 inet->inet_dport = 0;
389 inet->inet_daddr = 0;
397 EXPORT_SYMBOL(inet6_bind);
399 int inet6_release(struct socket *sock)
401 struct sock *sk = sock->sk;
407 ipv6_sock_mc_close(sk);
410 ipv6_sock_ac_close(sk);
412 return inet_release(sock);
414 EXPORT_SYMBOL(inet6_release);
416 void inet6_destroy_sock(struct sock *sk)
418 struct ipv6_pinfo *np = inet6_sk(sk);
420 struct ipv6_txoptions *opt;
422 /* Release rx options */
424 skb = xchg(&np->pktoptions, NULL);
428 skb = xchg(&np->rxpmtu, NULL);
432 /* Free flowlabels */
433 fl6_free_socklist(sk);
435 /* Free tx options */
437 opt = xchg(&np->opt, NULL);
439 sock_kfree_s(sk, opt, opt->tot_len);
441 EXPORT_SYMBOL_GPL(inet6_destroy_sock);
444 * This does both peername and sockname.
447 int inet6_getname(struct socket *sock, struct sockaddr *uaddr,
448 int *uaddr_len, int peer)
450 struct sockaddr_in6 *sin = (struct sockaddr_in6 *)uaddr;
451 struct sock *sk = sock->sk;
452 struct inet_sock *inet = inet_sk(sk);
453 struct ipv6_pinfo *np = inet6_sk(sk);
455 sin->sin6_family = AF_INET6;
456 sin->sin6_flowinfo = 0;
457 sin->sin6_scope_id = 0;
459 if (!inet->inet_dport)
461 if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_SYN_SENT)) &&
464 sin->sin6_port = inet->inet_dport;
465 sin->sin6_addr = np->daddr;
467 sin->sin6_flowinfo = np->flow_label;
469 if (ipv6_addr_any(&np->rcv_saddr))
470 sin->sin6_addr = np->saddr;
472 sin->sin6_addr = np->rcv_saddr;
474 sin->sin6_port = inet->inet_sport;
476 sin->sin6_scope_id = ipv6_iface_scope_id(&sin->sin6_addr,
477 sk->sk_bound_dev_if);
478 *uaddr_len = sizeof(*sin);
481 EXPORT_SYMBOL(inet6_getname);
483 int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
485 struct sock *sk = sock->sk;
486 struct net *net = sock_net(sk);
490 return sock_get_timestamp(sk, (struct timeval __user *)arg);
493 return sock_get_timestampns(sk, (struct timespec __user *)arg);
498 return ipv6_route_ioctl(net, cmd, (void __user *)arg);
501 return addrconf_add_ifaddr(net, (void __user *) arg);
503 return addrconf_del_ifaddr(net, (void __user *) arg);
505 return addrconf_set_dstaddr(net, (void __user *) arg);
507 if (!sk->sk_prot->ioctl)
509 return sk->sk_prot->ioctl(sk, cmd, arg);
514 EXPORT_SYMBOL(inet6_ioctl);
516 const struct proto_ops inet6_stream_ops = {
518 .owner = THIS_MODULE,
519 .release = inet6_release,
521 .connect = inet_stream_connect, /* ok */
522 .socketpair = sock_no_socketpair, /* a do nothing */
523 .accept = inet_accept, /* ok */
524 .getname = inet6_getname,
525 .poll = tcp_poll, /* ok */
526 .ioctl = inet6_ioctl, /* must change */
527 .listen = inet_listen, /* ok */
528 .shutdown = inet_shutdown, /* ok */
529 .setsockopt = sock_common_setsockopt, /* ok */
530 .getsockopt = sock_common_getsockopt, /* ok */
531 .sendmsg = inet_sendmsg, /* ok */
532 .recvmsg = inet_recvmsg, /* ok */
533 .mmap = sock_no_mmap,
534 .sendpage = inet_sendpage,
535 .splice_read = tcp_splice_read,
537 .compat_setsockopt = compat_sock_common_setsockopt,
538 .compat_getsockopt = compat_sock_common_getsockopt,
542 const struct proto_ops inet6_dgram_ops = {
544 .owner = THIS_MODULE,
545 .release = inet6_release,
547 .connect = inet_dgram_connect, /* ok */
548 .socketpair = sock_no_socketpair, /* a do nothing */
549 .accept = sock_no_accept, /* a do nothing */
550 .getname = inet6_getname,
551 .poll = udp_poll, /* ok */
552 .ioctl = inet6_ioctl, /* must change */
553 .listen = sock_no_listen, /* ok */
554 .shutdown = inet_shutdown, /* ok */
555 .setsockopt = sock_common_setsockopt, /* ok */
556 .getsockopt = sock_common_getsockopt, /* ok */
557 .sendmsg = inet_sendmsg, /* ok */
558 .recvmsg = inet_recvmsg, /* ok */
559 .mmap = sock_no_mmap,
560 .sendpage = sock_no_sendpage,
562 .compat_setsockopt = compat_sock_common_setsockopt,
563 .compat_getsockopt = compat_sock_common_getsockopt,
567 static const struct net_proto_family inet6_family_ops = {
569 .create = inet6_create,
570 .owner = THIS_MODULE,
573 int inet6_register_protosw(struct inet_protosw *p)
575 struct list_head *lh;
576 struct inet_protosw *answer;
577 struct list_head *last_perm;
578 int protocol = p->protocol;
581 spin_lock_bh(&inetsw6_lock);
584 if (p->type >= SOCK_MAX)
587 /* If we are trying to override a permanent protocol, bail. */
590 last_perm = &inetsw6[p->type];
591 list_for_each(lh, &inetsw6[p->type]) {
592 answer = list_entry(lh, struct inet_protosw, list);
594 /* Check only the non-wild match. */
595 if (INET_PROTOSW_PERMANENT & answer->flags) {
596 if (protocol == answer->protocol)
606 /* Add the new entry after the last permanent entry if any, so that
607 * the new entry does not override a permanent entry when matched with
608 * a wild-card protocol. But it is allowed to override any existing
609 * non-permanent entry. This means that when we remove this entry, the
610 * system automatically returns to the old behavior.
612 list_add_rcu(&p->list, last_perm);
615 spin_unlock_bh(&inetsw6_lock);
619 pr_err("Attempt to override permanent protocol %d\n", protocol);
623 pr_err("Ignoring attempt to register invalid socket type %d\n",
627 EXPORT_SYMBOL(inet6_register_protosw);
630 inet6_unregister_protosw(struct inet_protosw *p)
632 if (INET_PROTOSW_PERMANENT & p->flags) {
633 pr_err("Attempt to unregister permanent protocol %d\n",
636 spin_lock_bh(&inetsw6_lock);
637 list_del_rcu(&p->list);
638 spin_unlock_bh(&inetsw6_lock);
643 EXPORT_SYMBOL(inet6_unregister_protosw);
645 int inet6_sk_rebuild_header(struct sock *sk)
647 struct ipv6_pinfo *np = inet6_sk(sk);
648 struct dst_entry *dst;
650 dst = __sk_dst_check(sk, np->dst_cookie);
653 struct inet_sock *inet = inet_sk(sk);
654 struct in6_addr *final_p, final;
657 memset(&fl6, 0, sizeof(fl6));
658 fl6.flowi6_proto = sk->sk_protocol;
659 fl6.daddr = np->daddr;
660 fl6.saddr = np->saddr;
661 fl6.flowlabel = np->flow_label;
662 fl6.flowi6_oif = sk->sk_bound_dev_if;
663 fl6.flowi6_mark = sk->sk_mark;
664 fl6.fl6_dport = inet->inet_dport;
665 fl6.fl6_sport = inet->inet_sport;
666 security_sk_classify_flow(sk, flowi6_to_flowi(&fl6));
668 final_p = fl6_update_dst(&fl6, np->opt, &final);
670 dst = ip6_dst_lookup_flow(sk, &fl6, final_p, false);
672 sk->sk_route_caps = 0;
673 sk->sk_err_soft = -PTR_ERR(dst);
677 __ip6_dst_store(sk, dst, NULL, NULL);
682 EXPORT_SYMBOL_GPL(inet6_sk_rebuild_header);
684 bool ipv6_opt_accepted(const struct sock *sk, const struct sk_buff *skb)
686 const struct ipv6_pinfo *np = inet6_sk(sk);
687 const struct inet6_skb_parm *opt = IP6CB(skb);
690 if ((opt->hop && (np->rxopt.bits.hopopts ||
691 np->rxopt.bits.ohopopts)) ||
692 ((IPV6_FLOWINFO_MASK &
693 *(__be32 *)skb_network_header(skb)) &&
694 np->rxopt.bits.rxflow) ||
695 (opt->srcrt && (np->rxopt.bits.srcrt ||
696 np->rxopt.bits.osrcrt)) ||
697 ((opt->dst1 || opt->dst0) &&
698 (np->rxopt.bits.dstopts || np->rxopt.bits.odstopts)))
703 EXPORT_SYMBOL_GPL(ipv6_opt_accepted);
705 static struct packet_type ipv6_packet_type __read_mostly = {
706 .type = cpu_to_be16(ETH_P_IPV6),
710 static int __init ipv6_packet_init(void)
712 dev_add_pack(&ipv6_packet_type);
716 static void ipv6_packet_cleanup(void)
718 dev_remove_pack(&ipv6_packet_type);
721 static int __net_init ipv6_init_mibs(struct net *net)
723 if (snmp_mib_init((void __percpu **)net->mib.udp_stats_in6,
724 sizeof(struct udp_mib),
725 __alignof__(struct udp_mib)) < 0)
727 if (snmp_mib_init((void __percpu **)net->mib.udplite_stats_in6,
728 sizeof(struct udp_mib),
729 __alignof__(struct udp_mib)) < 0)
730 goto err_udplite_mib;
731 if (snmp_mib_init((void __percpu **)net->mib.ipv6_statistics,
732 sizeof(struct ipstats_mib),
733 __alignof__(struct ipstats_mib)) < 0)
735 if (snmp_mib_init((void __percpu **)net->mib.icmpv6_statistics,
736 sizeof(struct icmpv6_mib),
737 __alignof__(struct icmpv6_mib)) < 0)
739 net->mib.icmpv6msg_statistics = kzalloc(sizeof(struct icmpv6msg_mib),
741 if (!net->mib.icmpv6msg_statistics)
742 goto err_icmpmsg_mib;
746 snmp_mib_free((void __percpu **)net->mib.icmpv6_statistics);
748 snmp_mib_free((void __percpu **)net->mib.ipv6_statistics);
750 snmp_mib_free((void __percpu **)net->mib.udplite_stats_in6);
752 snmp_mib_free((void __percpu **)net->mib.udp_stats_in6);
756 static void ipv6_cleanup_mibs(struct net *net)
758 snmp_mib_free((void __percpu **)net->mib.udp_stats_in6);
759 snmp_mib_free((void __percpu **)net->mib.udplite_stats_in6);
760 snmp_mib_free((void __percpu **)net->mib.ipv6_statistics);
761 snmp_mib_free((void __percpu **)net->mib.icmpv6_statistics);
762 kfree(net->mib.icmpv6msg_statistics);
765 static int __net_init inet6_net_init(struct net *net)
769 net->ipv6.sysctl.bindv6only = 0;
770 net->ipv6.sysctl.icmpv6_time = 1*HZ;
772 err = ipv6_init_mibs(net);
775 #ifdef CONFIG_PROC_FS
776 err = udp6_proc_init(net);
779 err = tcp6_proc_init(net);
782 err = ac6_proc_init(net);
788 #ifdef CONFIG_PROC_FS
794 ipv6_cleanup_mibs(net);
799 static void __net_exit inet6_net_exit(struct net *net)
801 #ifdef CONFIG_PROC_FS
806 ipv6_cleanup_mibs(net);
809 static struct pernet_operations inet6_net_ops = {
810 .init = inet6_net_init,
811 .exit = inet6_net_exit,
814 static int __init inet6_init(void)
819 BUILD_BUG_ON(sizeof(struct inet6_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
821 /* Register the socket-side information for inet6_create. */
822 for (r = &inetsw6[0]; r < &inetsw6[SOCK_MAX]; ++r)
825 if (disable_ipv6_mod) {
826 pr_info("Loaded, but administratively disabled, reboot required to enable\n");
830 err = proto_register(&tcpv6_prot, 1);
834 err = proto_register(&udpv6_prot, 1);
836 goto out_unregister_tcp_proto;
838 err = proto_register(&udplitev6_prot, 1);
840 goto out_unregister_udp_proto;
842 err = proto_register(&rawv6_prot, 1);
844 goto out_unregister_udplite_proto;
847 /* We MUST register RAW sockets before we create the ICMP6,
848 * IGMP6, or NDISC control sockets.
852 goto out_unregister_raw_proto;
854 /* Register the family here so that the init calls below will
855 * be able to create sockets. (?? is this dangerous ??)
857 err = sock_register(&inet6_family_ops);
859 goto out_sock_register_fail;
861 tcpv6_prot.sysctl_mem = init_net.ipv4.sysctl_tcp_mem;
864 * ipngwg API draft makes clear that the correct semantics
865 * for TCP and UDP is to consider one TCP and UDP instance
866 * in a host available by both INET and INET6 APIs and
867 * able to communicate via both network protocols.
870 err = register_pernet_subsys(&inet6_net_ops);
872 goto register_pernet_fail;
885 err = ipv6_netfilter_init();
888 /* Create /proc/foo6 entries. */
889 #ifdef CONFIG_PROC_FS
891 if (raw6_proc_init())
893 if (udplite6_proc_init())
894 goto proc_udplite6_fail;
895 if (ipv6_misc_proc_init())
896 goto proc_misc6_fail;
900 err = ip6_route_init();
903 err = ip6_flowlabel_init();
905 goto ip6_flowlabel_fail;
906 err = addrconf_init();
910 /* Init v6 extension headers. */
911 err = ipv6_exthdrs_init();
913 goto ipv6_exthdrs_fail;
915 err = ipv6_frag_init();
919 /* Init v6 transport protocols. */
924 err = udplitev6_init();
932 err = ipv6_packet_init();
934 goto ipv6_packet_fail;
937 err = ipv6_sysctl_register();
946 ipv6_packet_cleanup();
961 ip6_flowlabel_cleanup();
965 #ifdef CONFIG_PROC_FS
968 ipv6_misc_proc_exit();
970 udplite6_proc_exit();
975 ipv6_netfilter_fini();
985 unregister_pernet_subsys(&inet6_net_ops);
986 register_pernet_fail:
987 sock_unregister(PF_INET6);
988 rtnl_unregister_all(PF_INET6);
989 out_sock_register_fail:
991 out_unregister_raw_proto:
992 proto_unregister(&rawv6_prot);
993 out_unregister_udplite_proto:
994 proto_unregister(&udplitev6_prot);
995 out_unregister_udp_proto:
996 proto_unregister(&udpv6_prot);
997 out_unregister_tcp_proto:
998 proto_unregister(&tcpv6_prot);
1001 module_init(inet6_init);
1003 static void __exit inet6_exit(void)
1005 if (disable_ipv6_mod)
1008 /* First of all disallow new sockets creation. */
1009 sock_unregister(PF_INET6);
1010 /* Disallow any further netlink messages */
1011 rtnl_unregister_all(PF_INET6);
1017 /* Cleanup code parts. */
1018 ipv6_packet_cleanup();
1020 ipv6_exthdrs_exit();
1022 ip6_flowlabel_cleanup();
1023 ip6_route_cleanup();
1024 #ifdef CONFIG_PROC_FS
1026 /* Cleanup code parts. */
1028 ipv6_misc_proc_exit();
1029 udplite6_proc_exit();
1032 ipv6_netfilter_fini();
1039 unregister_pernet_subsys(&inet6_net_ops);
1040 proto_unregister(&rawv6_prot);
1041 proto_unregister(&udplitev6_prot);
1042 proto_unregister(&udpv6_prot);
1043 proto_unregister(&tcpv6_prot);
1045 rcu_barrier(); /* Wait for completion of call_rcu()'s */
1047 module_exit(inet6_exit);
1049 MODULE_ALIAS_NETPROTO(PF_INET6);