Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *  PF_INET6 socket protocol family
0004  *  Linux INET6 implementation
0005  *
0006  *  Authors:
0007  *  Pedro Roque     <roque@di.fc.ul.pt>
0008  *
0009  *  Adapted from linux/net/ipv4/af_inet.c
0010  *
0011  *  Fixes:
0012  *  piggy, Karl Knutson :   Socket protocol table
0013  *  Hideaki YOSHIFUJI   :   sin6_scope_id support
0014  *  Arnaldo Melo        :   check proc_net_create return, cleanups
0015  */
0016 
0017 #define pr_fmt(fmt) "IPv6: " fmt
0018 
0019 #include <linux/module.h>
0020 #include <linux/capability.h>
0021 #include <linux/errno.h>
0022 #include <linux/types.h>
0023 #include <linux/socket.h>
0024 #include <linux/in.h>
0025 #include <linux/kernel.h>
0026 #include <linux/timer.h>
0027 #include <linux/string.h>
0028 #include <linux/sockios.h>
0029 #include <linux/net.h>
0030 #include <linux/fcntl.h>
0031 #include <linux/mm.h>
0032 #include <linux/interrupt.h>
0033 #include <linux/proc_fs.h>
0034 #include <linux/stat.h>
0035 #include <linux/init.h>
0036 #include <linux/slab.h>
0037 
0038 #include <linux/inet.h>
0039 #include <linux/netdevice.h>
0040 #include <linux/icmpv6.h>
0041 #include <linux/netfilter_ipv6.h>
0042 
0043 #include <net/ip.h>
0044 #include <net/ipv6.h>
0045 #include <net/udp.h>
0046 #include <net/udplite.h>
0047 #include <net/tcp.h>
0048 #include <net/ping.h>
0049 #include <net/protocol.h>
0050 #include <net/inet_common.h>
0051 #include <net/route.h>
0052 #include <net/transp_v6.h>
0053 #include <net/ip6_route.h>
0054 #include <net/addrconf.h>
0055 #include <net/ipv6_stubs.h>
0056 #include <net/ndisc.h>
0057 #ifdef CONFIG_IPV6_TUNNEL
0058 #include <net/ip6_tunnel.h>
0059 #endif
0060 #include <net/calipso.h>
0061 #include <net/seg6.h>
0062 #include <net/rpl.h>
0063 #include <net/compat.h>
0064 #include <net/xfrm.h>
0065 #include <net/ioam6.h>
0066 #include <net/rawv6.h>
0067 
0068 #include <linux/uaccess.h>
0069 #include <linux/mroute6.h>
0070 
0071 #include "ip6_offload.h"
0072 
0073 MODULE_AUTHOR("Cast of dozens");
0074 MODULE_DESCRIPTION("IPv6 protocol stack for Linux");
0075 MODULE_LICENSE("GPL");
0076 
0077 /* The inetsw6 table contains everything that inet6_create needs to
0078  * build a new socket.
0079  */
0080 static struct list_head inetsw6[SOCK_MAX];
0081 static DEFINE_SPINLOCK(inetsw6_lock);
0082 
0083 struct ipv6_params ipv6_defaults = {
0084     .disable_ipv6 = 0,
0085     .autoconf = 1,
0086 };
0087 
0088 static int disable_ipv6_mod;
0089 
0090 module_param_named(disable, disable_ipv6_mod, int, 0444);
0091 MODULE_PARM_DESC(disable, "Disable IPv6 module such that it is non-functional");
0092 
0093 module_param_named(disable_ipv6, ipv6_defaults.disable_ipv6, int, 0444);
0094 MODULE_PARM_DESC(disable_ipv6, "Disable IPv6 on all interfaces");
0095 
0096 module_param_named(autoconf, ipv6_defaults.autoconf, int, 0444);
0097 MODULE_PARM_DESC(autoconf, "Enable IPv6 address autoconfiguration on all interfaces");
0098 
0099 bool ipv6_mod_enabled(void)
0100 {
0101     return disable_ipv6_mod == 0;
0102 }
0103 EXPORT_SYMBOL_GPL(ipv6_mod_enabled);
0104 
0105 static __inline__ struct ipv6_pinfo *inet6_sk_generic(struct sock *sk)
0106 {
0107     const int offset = sk->sk_prot->obj_size - sizeof(struct ipv6_pinfo);
0108 
0109     return (struct ipv6_pinfo *)(((u8 *)sk) + offset);
0110 }
0111 
0112 static int inet6_create(struct net *net, struct socket *sock, int protocol,
0113             int kern)
0114 {
0115     struct inet_sock *inet;
0116     struct ipv6_pinfo *np;
0117     struct sock *sk;
0118     struct inet_protosw *answer;
0119     struct proto *answer_prot;
0120     unsigned char answer_flags;
0121     int try_loading_module = 0;
0122     int err;
0123 
0124     if (protocol < 0 || protocol >= IPPROTO_MAX)
0125         return -EINVAL;
0126 
0127     /* Look for the requested type/protocol pair. */
0128 lookup_protocol:
0129     err = -ESOCKTNOSUPPORT;
0130     rcu_read_lock();
0131     list_for_each_entry_rcu(answer, &inetsw6[sock->type], list) {
0132 
0133         err = 0;
0134         /* Check the non-wild match. */
0135         if (protocol == answer->protocol) {
0136             if (protocol != IPPROTO_IP)
0137                 break;
0138         } else {
0139             /* Check for the two wild cases. */
0140             if (IPPROTO_IP == protocol) {
0141                 protocol = answer->protocol;
0142                 break;
0143             }
0144             if (IPPROTO_IP == answer->protocol)
0145                 break;
0146         }
0147         err = -EPROTONOSUPPORT;
0148     }
0149 
0150     if (err) {
0151         if (try_loading_module < 2) {
0152             rcu_read_unlock();
0153             /*
0154              * Be more specific, e.g. net-pf-10-proto-132-type-1
0155              * (net-pf-PF_INET6-proto-IPPROTO_SCTP-type-SOCK_STREAM)
0156              */
0157             if (++try_loading_module == 1)
0158                 request_module("net-pf-%d-proto-%d-type-%d",
0159                         PF_INET6, protocol, sock->type);
0160             /*
0161              * Fall back to generic, e.g. net-pf-10-proto-132
0162              * (net-pf-PF_INET6-proto-IPPROTO_SCTP)
0163              */
0164             else
0165                 request_module("net-pf-%d-proto-%d",
0166                         PF_INET6, protocol);
0167             goto lookup_protocol;
0168         } else
0169             goto out_rcu_unlock;
0170     }
0171 
0172     err = -EPERM;
0173     if (sock->type == SOCK_RAW && !kern &&
0174         !ns_capable(net->user_ns, CAP_NET_RAW))
0175         goto out_rcu_unlock;
0176 
0177     sock->ops = answer->ops;
0178     answer_prot = answer->prot;
0179     answer_flags = answer->flags;
0180     rcu_read_unlock();
0181 
0182     WARN_ON(!answer_prot->slab);
0183 
0184     err = -ENOBUFS;
0185     sk = sk_alloc(net, PF_INET6, GFP_KERNEL, answer_prot, kern);
0186     if (!sk)
0187         goto out;
0188 
0189     sock_init_data(sock, sk);
0190 
0191     err = 0;
0192     if (INET_PROTOSW_REUSE & answer_flags)
0193         sk->sk_reuse = SK_CAN_REUSE;
0194 
0195     inet = inet_sk(sk);
0196     inet->is_icsk = (INET_PROTOSW_ICSK & answer_flags) != 0;
0197 
0198     if (SOCK_RAW == sock->type) {
0199         inet->inet_num = protocol;
0200         if (IPPROTO_RAW == protocol)
0201             inet->hdrincl = 1;
0202     }
0203 
0204     sk->sk_destruct     = inet_sock_destruct;
0205     sk->sk_family       = PF_INET6;
0206     sk->sk_protocol     = protocol;
0207 
0208     sk->sk_backlog_rcv  = answer->prot->backlog_rcv;
0209 
0210     inet_sk(sk)->pinet6 = np = inet6_sk_generic(sk);
0211     np->hop_limit   = -1;
0212     np->mcast_hops  = IPV6_DEFAULT_MCASTHOPS;
0213     np->mc_loop = 1;
0214     np->mc_all  = 1;
0215     np->pmtudisc    = IPV6_PMTUDISC_WANT;
0216     np->repflow = net->ipv6.sysctl.flowlabel_reflect & FLOWLABEL_REFLECT_ESTABLISHED;
0217     sk->sk_ipv6only = net->ipv6.sysctl.bindv6only;
0218 
0219     /* Init the ipv4 part of the socket since we can have sockets
0220      * using v6 API for ipv4.
0221      */
0222     inet->uc_ttl    = -1;
0223 
0224     inet->mc_loop   = 1;
0225     inet->mc_ttl    = 1;
0226     inet->mc_index  = 0;
0227     RCU_INIT_POINTER(inet->mc_list, NULL);
0228     inet->rcv_tos   = 0;
0229 
0230     if (READ_ONCE(net->ipv4.sysctl_ip_no_pmtu_disc))
0231         inet->pmtudisc = IP_PMTUDISC_DONT;
0232     else
0233         inet->pmtudisc = IP_PMTUDISC_WANT;
0234     /*
0235      * Increment only the relevant sk_prot->socks debug field, this changes
0236      * the previous behaviour of incrementing both the equivalent to
0237      * answer->prot->socks (inet6_sock_nr) and inet_sock_nr.
0238      *
0239      * This allows better debug granularity as we'll know exactly how many
0240      * UDPv6, TCPv6, etc socks were allocated, not the sum of all IPv6
0241      * transport protocol socks. -acme
0242      */
0243     sk_refcnt_debug_inc(sk);
0244 
0245     if (inet->inet_num) {
0246         /* It assumes that any protocol which allows
0247          * the user to assign a number at socket
0248          * creation time automatically shares.
0249          */
0250         inet->inet_sport = htons(inet->inet_num);
0251         err = sk->sk_prot->hash(sk);
0252         if (err) {
0253             sk_common_release(sk);
0254             goto out;
0255         }
0256     }
0257     if (sk->sk_prot->init) {
0258         err = sk->sk_prot->init(sk);
0259         if (err) {
0260             sk_common_release(sk);
0261             goto out;
0262         }
0263     }
0264 
0265     if (!kern) {
0266         err = BPF_CGROUP_RUN_PROG_INET_SOCK(sk);
0267         if (err) {
0268             sk_common_release(sk);
0269             goto out;
0270         }
0271     }
0272 out:
0273     return err;
0274 out_rcu_unlock:
0275     rcu_read_unlock();
0276     goto out;
0277 }
0278 
0279 static int __inet6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,
0280             u32 flags)
0281 {
0282     struct sockaddr_in6 *addr = (struct sockaddr_in6 *)uaddr;
0283     struct inet_sock *inet = inet_sk(sk);
0284     struct ipv6_pinfo *np = inet6_sk(sk);
0285     struct net *net = sock_net(sk);
0286     __be32 v4addr = 0;
0287     unsigned short snum;
0288     bool saved_ipv6only;
0289     int addr_type = 0;
0290     int err = 0;
0291 
0292     if (addr->sin6_family != AF_INET6)
0293         return -EAFNOSUPPORT;
0294 
0295     addr_type = ipv6_addr_type(&addr->sin6_addr);
0296     if ((addr_type & IPV6_ADDR_MULTICAST) && sk->sk_type == SOCK_STREAM)
0297         return -EINVAL;
0298 
0299     snum = ntohs(addr->sin6_port);
0300     if (!(flags & BIND_NO_CAP_NET_BIND_SERVICE) &&
0301         snum && inet_port_requires_bind_service(net, snum) &&
0302         !ns_capable(net->user_ns, CAP_NET_BIND_SERVICE))
0303         return -EACCES;
0304 
0305     if (flags & BIND_WITH_LOCK)
0306         lock_sock(sk);
0307 
0308     /* Check these errors (active socket, double bind). */
0309     if (sk->sk_state != TCP_CLOSE || inet->inet_num) {
0310         err = -EINVAL;
0311         goto out;
0312     }
0313 
0314     /* Check if the address belongs to the host. */
0315     if (addr_type == IPV6_ADDR_MAPPED) {
0316         struct net_device *dev = NULL;
0317         int chk_addr_ret;
0318 
0319         /* Binding to v4-mapped address on a v6-only socket
0320          * makes no sense
0321          */
0322         if (ipv6_only_sock(sk)) {
0323             err = -EINVAL;
0324             goto out;
0325         }
0326 
0327         rcu_read_lock();
0328         if (sk->sk_bound_dev_if) {
0329             dev = dev_get_by_index_rcu(net, sk->sk_bound_dev_if);
0330             if (!dev) {
0331                 err = -ENODEV;
0332                 goto out_unlock;
0333             }
0334         }
0335 
0336         /* Reproduce AF_INET checks to make the bindings consistent */
0337         v4addr = addr->sin6_addr.s6_addr32[3];
0338         chk_addr_ret = inet_addr_type_dev_table(net, dev, v4addr);
0339         rcu_read_unlock();
0340 
0341         if (!inet_addr_valid_or_nonlocal(net, inet, v4addr,
0342                          chk_addr_ret)) {
0343             err = -EADDRNOTAVAIL;
0344             goto out;
0345         }
0346     } else {
0347         if (addr_type != IPV6_ADDR_ANY) {
0348             struct net_device *dev = NULL;
0349 
0350             rcu_read_lock();
0351             if (__ipv6_addr_needs_scope_id(addr_type)) {
0352                 if (addr_len >= sizeof(struct sockaddr_in6) &&
0353                     addr->sin6_scope_id) {
0354                     /* Override any existing binding, if another one
0355                      * is supplied by user.
0356                      */
0357                     sk->sk_bound_dev_if = addr->sin6_scope_id;
0358                 }
0359 
0360                 /* Binding to link-local address requires an interface */
0361                 if (!sk->sk_bound_dev_if) {
0362                     err = -EINVAL;
0363                     goto out_unlock;
0364                 }
0365             }
0366 
0367             if (sk->sk_bound_dev_if) {
0368                 dev = dev_get_by_index_rcu(net, sk->sk_bound_dev_if);
0369                 if (!dev) {
0370                     err = -ENODEV;
0371                     goto out_unlock;
0372                 }
0373             }
0374 
0375             /* ipv4 addr of the socket is invalid.  Only the
0376              * unspecified and mapped address have a v4 equivalent.
0377              */
0378             v4addr = LOOPBACK4_IPV6;
0379             if (!(addr_type & IPV6_ADDR_MULTICAST)) {
0380                 if (!ipv6_can_nonlocal_bind(net, inet) &&
0381                     !ipv6_chk_addr(net, &addr->sin6_addr,
0382                            dev, 0)) {
0383                     err = -EADDRNOTAVAIL;
0384                     goto out_unlock;
0385                 }
0386             }
0387             rcu_read_unlock();
0388         }
0389     }
0390 
0391     inet->inet_rcv_saddr = v4addr;
0392     inet->inet_saddr = v4addr;
0393 
0394     sk->sk_v6_rcv_saddr = addr->sin6_addr;
0395 
0396     if (!(addr_type & IPV6_ADDR_MULTICAST))
0397         np->saddr = addr->sin6_addr;
0398 
0399     saved_ipv6only = sk->sk_ipv6only;
0400     if (addr_type != IPV6_ADDR_ANY && addr_type != IPV6_ADDR_MAPPED)
0401         sk->sk_ipv6only = 1;
0402 
0403     /* Make sure we are allowed to bind here. */
0404     if (snum || !(inet->bind_address_no_port ||
0405               (flags & BIND_FORCE_ADDRESS_NO_PORT))) {
0406         if (sk->sk_prot->get_port(sk, snum)) {
0407             sk->sk_ipv6only = saved_ipv6only;
0408             inet_reset_saddr(sk);
0409             err = -EADDRINUSE;
0410             goto out;
0411         }
0412         if (!(flags & BIND_FROM_BPF)) {
0413             err = BPF_CGROUP_RUN_PROG_INET6_POST_BIND(sk);
0414             if (err) {
0415                 sk->sk_ipv6only = saved_ipv6only;
0416                 inet_reset_saddr(sk);
0417                 if (sk->sk_prot->put_port)
0418                     sk->sk_prot->put_port(sk);
0419                 goto out;
0420             }
0421         }
0422     }
0423 
0424     if (addr_type != IPV6_ADDR_ANY)
0425         sk->sk_userlocks |= SOCK_BINDADDR_LOCK;
0426     if (snum)
0427         sk->sk_userlocks |= SOCK_BINDPORT_LOCK;
0428     inet->inet_sport = htons(inet->inet_num);
0429     inet->inet_dport = 0;
0430     inet->inet_daddr = 0;
0431 out:
0432     if (flags & BIND_WITH_LOCK)
0433         release_sock(sk);
0434     return err;
0435 out_unlock:
0436     rcu_read_unlock();
0437     goto out;
0438 }
0439 
0440 /* bind for INET6 API */
0441 int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
0442 {
0443     struct sock *sk = sock->sk;
0444     u32 flags = BIND_WITH_LOCK;
0445     const struct proto *prot;
0446     int err = 0;
0447 
0448     /* IPV6_ADDRFORM can change sk->sk_prot under us. */
0449     prot = READ_ONCE(sk->sk_prot);
0450     /* If the socket has its own bind function then use it. */
0451     if (prot->bind)
0452         return prot->bind(sk, uaddr, addr_len);
0453 
0454     if (addr_len < SIN6_LEN_RFC2133)
0455         return -EINVAL;
0456 
0457     /* BPF prog is run before any checks are done so that if the prog
0458      * changes context in a wrong way it will be caught.
0459      */
0460     err = BPF_CGROUP_RUN_PROG_INET_BIND_LOCK(sk, uaddr,
0461                          CGROUP_INET6_BIND, &flags);
0462     if (err)
0463         return err;
0464 
0465     return __inet6_bind(sk, uaddr, addr_len, flags);
0466 }
0467 EXPORT_SYMBOL(inet6_bind);
0468 
0469 int inet6_release(struct socket *sock)
0470 {
0471     struct sock *sk = sock->sk;
0472 
0473     if (!sk)
0474         return -EINVAL;
0475 
0476     /* Free mc lists */
0477     ipv6_sock_mc_close(sk);
0478 
0479     /* Free ac lists */
0480     ipv6_sock_ac_close(sk);
0481 
0482     return inet_release(sock);
0483 }
0484 EXPORT_SYMBOL(inet6_release);
0485 
0486 void inet6_destroy_sock(struct sock *sk)
0487 {
0488     struct ipv6_pinfo *np = inet6_sk(sk);
0489     struct sk_buff *skb;
0490     struct ipv6_txoptions *opt;
0491 
0492     /* Release rx options */
0493 
0494     skb = xchg(&np->pktoptions, NULL);
0495     kfree_skb(skb);
0496 
0497     skb = xchg(&np->rxpmtu, NULL);
0498     kfree_skb(skb);
0499 
0500     /* Free flowlabels */
0501     fl6_free_socklist(sk);
0502 
0503     /* Free tx options */
0504 
0505     opt = xchg((__force struct ipv6_txoptions **)&np->opt, NULL);
0506     if (opt) {
0507         atomic_sub(opt->tot_len, &sk->sk_omem_alloc);
0508         txopt_put(opt);
0509     }
0510 }
0511 EXPORT_SYMBOL_GPL(inet6_destroy_sock);
0512 
0513 /*
0514  *  This does both peername and sockname.
0515  */
0516 int inet6_getname(struct socket *sock, struct sockaddr *uaddr,
0517           int peer)
0518 {
0519     struct sockaddr_in6 *sin = (struct sockaddr_in6 *)uaddr;
0520     struct sock *sk = sock->sk;
0521     struct inet_sock *inet = inet_sk(sk);
0522     struct ipv6_pinfo *np = inet6_sk(sk);
0523 
0524     sin->sin6_family = AF_INET6;
0525     sin->sin6_flowinfo = 0;
0526     sin->sin6_scope_id = 0;
0527     lock_sock(sk);
0528     if (peer) {
0529         if (!inet->inet_dport ||
0530             (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_SYN_SENT)) &&
0531             peer == 1)) {
0532             release_sock(sk);
0533             return -ENOTCONN;
0534         }
0535         sin->sin6_port = inet->inet_dport;
0536         sin->sin6_addr = sk->sk_v6_daddr;
0537         if (np->sndflow)
0538             sin->sin6_flowinfo = np->flow_label;
0539         BPF_CGROUP_RUN_SA_PROG(sk, (struct sockaddr *)sin,
0540                        CGROUP_INET6_GETPEERNAME);
0541     } else {
0542         if (ipv6_addr_any(&sk->sk_v6_rcv_saddr))
0543             sin->sin6_addr = np->saddr;
0544         else
0545             sin->sin6_addr = sk->sk_v6_rcv_saddr;
0546         sin->sin6_port = inet->inet_sport;
0547         BPF_CGROUP_RUN_SA_PROG(sk, (struct sockaddr *)sin,
0548                        CGROUP_INET6_GETSOCKNAME);
0549     }
0550     sin->sin6_scope_id = ipv6_iface_scope_id(&sin->sin6_addr,
0551                          sk->sk_bound_dev_if);
0552     release_sock(sk);
0553     return sizeof(*sin);
0554 }
0555 EXPORT_SYMBOL(inet6_getname);
0556 
0557 int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
0558 {
0559     void __user *argp = (void __user *)arg;
0560     struct sock *sk = sock->sk;
0561     struct net *net = sock_net(sk);
0562     const struct proto *prot;
0563 
0564     switch (cmd) {
0565     case SIOCADDRT:
0566     case SIOCDELRT: {
0567         struct in6_rtmsg rtmsg;
0568 
0569         if (copy_from_user(&rtmsg, argp, sizeof(rtmsg)))
0570             return -EFAULT;
0571         return ipv6_route_ioctl(net, cmd, &rtmsg);
0572     }
0573     case SIOCSIFADDR:
0574         return addrconf_add_ifaddr(net, argp);
0575     case SIOCDIFADDR:
0576         return addrconf_del_ifaddr(net, argp);
0577     case SIOCSIFDSTADDR:
0578         return addrconf_set_dstaddr(net, argp);
0579     default:
0580         /* IPV6_ADDRFORM can change sk->sk_prot under us. */
0581         prot = READ_ONCE(sk->sk_prot);
0582         if (!prot->ioctl)
0583             return -ENOIOCTLCMD;
0584         return prot->ioctl(sk, cmd, arg);
0585     }
0586     /*NOTREACHED*/
0587     return 0;
0588 }
0589 EXPORT_SYMBOL(inet6_ioctl);
0590 
0591 #ifdef CONFIG_COMPAT
0592 struct compat_in6_rtmsg {
0593     struct in6_addr     rtmsg_dst;
0594     struct in6_addr     rtmsg_src;
0595     struct in6_addr     rtmsg_gateway;
0596     u32         rtmsg_type;
0597     u16         rtmsg_dst_len;
0598     u16         rtmsg_src_len;
0599     u32         rtmsg_metric;
0600     u32         rtmsg_info;
0601     u32         rtmsg_flags;
0602     s32         rtmsg_ifindex;
0603 };
0604 
0605 static int inet6_compat_routing_ioctl(struct sock *sk, unsigned int cmd,
0606         struct compat_in6_rtmsg __user *ur)
0607 {
0608     struct in6_rtmsg rt;
0609 
0610     if (copy_from_user(&rt.rtmsg_dst, &ur->rtmsg_dst,
0611             3 * sizeof(struct in6_addr)) ||
0612         get_user(rt.rtmsg_type, &ur->rtmsg_type) ||
0613         get_user(rt.rtmsg_dst_len, &ur->rtmsg_dst_len) ||
0614         get_user(rt.rtmsg_src_len, &ur->rtmsg_src_len) ||
0615         get_user(rt.rtmsg_metric, &ur->rtmsg_metric) ||
0616         get_user(rt.rtmsg_info, &ur->rtmsg_info) ||
0617         get_user(rt.rtmsg_flags, &ur->rtmsg_flags) ||
0618         get_user(rt.rtmsg_ifindex, &ur->rtmsg_ifindex))
0619         return -EFAULT;
0620 
0621 
0622     return ipv6_route_ioctl(sock_net(sk), cmd, &rt);
0623 }
0624 
0625 int inet6_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
0626 {
0627     void __user *argp = compat_ptr(arg);
0628     struct sock *sk = sock->sk;
0629 
0630     switch (cmd) {
0631     case SIOCADDRT:
0632     case SIOCDELRT:
0633         return inet6_compat_routing_ioctl(sk, cmd, argp);
0634     default:
0635         return -ENOIOCTLCMD;
0636     }
0637 }
0638 EXPORT_SYMBOL_GPL(inet6_compat_ioctl);
0639 #endif /* CONFIG_COMPAT */
0640 
0641 INDIRECT_CALLABLE_DECLARE(int udpv6_sendmsg(struct sock *, struct msghdr *,
0642                         size_t));
0643 int inet6_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
0644 {
0645     struct sock *sk = sock->sk;
0646     const struct proto *prot;
0647 
0648     if (unlikely(inet_send_prepare(sk)))
0649         return -EAGAIN;
0650 
0651     /* IPV6_ADDRFORM can change sk->sk_prot under us. */
0652     prot = READ_ONCE(sk->sk_prot);
0653     return INDIRECT_CALL_2(prot->sendmsg, tcp_sendmsg, udpv6_sendmsg,
0654                    sk, msg, size);
0655 }
0656 
0657 INDIRECT_CALLABLE_DECLARE(int udpv6_recvmsg(struct sock *, struct msghdr *,
0658                         size_t, int, int *));
0659 int inet6_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
0660           int flags)
0661 {
0662     struct sock *sk = sock->sk;
0663     const struct proto *prot;
0664     int addr_len = 0;
0665     int err;
0666 
0667     if (likely(!(flags & MSG_ERRQUEUE)))
0668         sock_rps_record_flow(sk);
0669 
0670     /* IPV6_ADDRFORM can change sk->sk_prot under us. */
0671     prot = READ_ONCE(sk->sk_prot);
0672     err = INDIRECT_CALL_2(prot->recvmsg, tcp_recvmsg, udpv6_recvmsg,
0673                   sk, msg, size, flags, &addr_len);
0674     if (err >= 0)
0675         msg->msg_namelen = addr_len;
0676     return err;
0677 }
0678 
0679 const struct proto_ops inet6_stream_ops = {
0680     .family        = PF_INET6,
0681     .owner         = THIS_MODULE,
0682     .release       = inet6_release,
0683     .bind          = inet6_bind,
0684     .connect       = inet_stream_connect,   /* ok       */
0685     .socketpair    = sock_no_socketpair,    /* a do nothing */
0686     .accept        = inet_accept,       /* ok       */
0687     .getname       = inet6_getname,
0688     .poll          = tcp_poll,          /* ok       */
0689     .ioctl         = inet6_ioctl,       /* must change  */
0690     .gettstamp     = sock_gettstamp,
0691     .listen        = inet_listen,       /* ok       */
0692     .shutdown      = inet_shutdown,     /* ok       */
0693     .setsockopt    = sock_common_setsockopt,    /* ok       */
0694     .getsockopt    = sock_common_getsockopt,    /* ok       */
0695     .sendmsg       = inet6_sendmsg,     /* retpoline's sake */
0696     .recvmsg       = inet6_recvmsg,     /* retpoline's sake */
0697 #ifdef CONFIG_MMU
0698     .mmap          = tcp_mmap,
0699 #endif
0700     .sendpage      = inet_sendpage,
0701     .sendmsg_locked    = tcp_sendmsg_locked,
0702     .sendpage_locked   = tcp_sendpage_locked,
0703     .splice_read       = tcp_splice_read,
0704     .read_sock     = tcp_read_sock,
0705     .read_skb      = tcp_read_skb,
0706     .peek_len      = tcp_peek_len,
0707 #ifdef CONFIG_COMPAT
0708     .compat_ioctl      = inet6_compat_ioctl,
0709 #endif
0710     .set_rcvlowat      = tcp_set_rcvlowat,
0711 };
0712 
0713 const struct proto_ops inet6_dgram_ops = {
0714     .family        = PF_INET6,
0715     .owner         = THIS_MODULE,
0716     .release       = inet6_release,
0717     .bind          = inet6_bind,
0718     .connect       = inet_dgram_connect,    /* ok       */
0719     .socketpair    = sock_no_socketpair,    /* a do nothing */
0720     .accept        = sock_no_accept,        /* a do nothing */
0721     .getname       = inet6_getname,
0722     .poll          = udp_poll,          /* ok       */
0723     .ioctl         = inet6_ioctl,       /* must change  */
0724     .gettstamp     = sock_gettstamp,
0725     .listen        = sock_no_listen,        /* ok       */
0726     .shutdown      = inet_shutdown,     /* ok       */
0727     .setsockopt    = sock_common_setsockopt,    /* ok       */
0728     .getsockopt    = sock_common_getsockopt,    /* ok       */
0729     .sendmsg       = inet6_sendmsg,     /* retpoline's sake */
0730     .recvmsg       = inet6_recvmsg,     /* retpoline's sake */
0731     .read_skb      = udp_read_skb,
0732     .mmap          = sock_no_mmap,
0733     .sendpage      = sock_no_sendpage,
0734     .set_peek_off      = sk_set_peek_off,
0735 #ifdef CONFIG_COMPAT
0736     .compat_ioctl      = inet6_compat_ioctl,
0737 #endif
0738 };
0739 
0740 static const struct net_proto_family inet6_family_ops = {
0741     .family = PF_INET6,
0742     .create = inet6_create,
0743     .owner  = THIS_MODULE,
0744 };
0745 
0746 int inet6_register_protosw(struct inet_protosw *p)
0747 {
0748     struct list_head *lh;
0749     struct inet_protosw *answer;
0750     struct list_head *last_perm;
0751     int protocol = p->protocol;
0752     int ret;
0753 
0754     spin_lock_bh(&inetsw6_lock);
0755 
0756     ret = -EINVAL;
0757     if (p->type >= SOCK_MAX)
0758         goto out_illegal;
0759 
0760     /* If we are trying to override a permanent protocol, bail. */
0761     answer = NULL;
0762     ret = -EPERM;
0763     last_perm = &inetsw6[p->type];
0764     list_for_each(lh, &inetsw6[p->type]) {
0765         answer = list_entry(lh, struct inet_protosw, list);
0766 
0767         /* Check only the non-wild match. */
0768         if (INET_PROTOSW_PERMANENT & answer->flags) {
0769             if (protocol == answer->protocol)
0770                 break;
0771             last_perm = lh;
0772         }
0773 
0774         answer = NULL;
0775     }
0776     if (answer)
0777         goto out_permanent;
0778 
0779     /* Add the new entry after the last permanent entry if any, so that
0780      * the new entry does not override a permanent entry when matched with
0781      * a wild-card protocol. But it is allowed to override any existing
0782      * non-permanent entry.  This means that when we remove this entry, the
0783      * system automatically returns to the old behavior.
0784      */
0785     list_add_rcu(&p->list, last_perm);
0786     ret = 0;
0787 out:
0788     spin_unlock_bh(&inetsw6_lock);
0789     return ret;
0790 
0791 out_permanent:
0792     pr_err("Attempt to override permanent protocol %d\n", protocol);
0793     goto out;
0794 
0795 out_illegal:
0796     pr_err("Ignoring attempt to register invalid socket type %d\n",
0797            p->type);
0798     goto out;
0799 }
0800 EXPORT_SYMBOL(inet6_register_protosw);
0801 
0802 void
0803 inet6_unregister_protosw(struct inet_protosw *p)
0804 {
0805     if (INET_PROTOSW_PERMANENT & p->flags) {
0806         pr_err("Attempt to unregister permanent protocol %d\n",
0807                p->protocol);
0808     } else {
0809         spin_lock_bh(&inetsw6_lock);
0810         list_del_rcu(&p->list);
0811         spin_unlock_bh(&inetsw6_lock);
0812 
0813         synchronize_net();
0814     }
0815 }
0816 EXPORT_SYMBOL(inet6_unregister_protosw);
0817 
0818 int inet6_sk_rebuild_header(struct sock *sk)
0819 {
0820     struct ipv6_pinfo *np = inet6_sk(sk);
0821     struct dst_entry *dst;
0822 
0823     dst = __sk_dst_check(sk, np->dst_cookie);
0824 
0825     if (!dst) {
0826         struct inet_sock *inet = inet_sk(sk);
0827         struct in6_addr *final_p, final;
0828         struct flowi6 fl6;
0829 
0830         memset(&fl6, 0, sizeof(fl6));
0831         fl6.flowi6_proto = sk->sk_protocol;
0832         fl6.daddr = sk->sk_v6_daddr;
0833         fl6.saddr = np->saddr;
0834         fl6.flowlabel = np->flow_label;
0835         fl6.flowi6_oif = sk->sk_bound_dev_if;
0836         fl6.flowi6_mark = sk->sk_mark;
0837         fl6.fl6_dport = inet->inet_dport;
0838         fl6.fl6_sport = inet->inet_sport;
0839         fl6.flowi6_uid = sk->sk_uid;
0840         security_sk_classify_flow(sk, flowi6_to_flowi_common(&fl6));
0841 
0842         rcu_read_lock();
0843         final_p = fl6_update_dst(&fl6, rcu_dereference(np->opt),
0844                      &final);
0845         rcu_read_unlock();
0846 
0847         dst = ip6_dst_lookup_flow(sock_net(sk), sk, &fl6, final_p);
0848         if (IS_ERR(dst)) {
0849             sk->sk_route_caps = 0;
0850             sk->sk_err_soft = -PTR_ERR(dst);
0851             return PTR_ERR(dst);
0852         }
0853 
0854         ip6_dst_store(sk, dst, NULL, NULL);
0855     }
0856 
0857     return 0;
0858 }
0859 EXPORT_SYMBOL_GPL(inet6_sk_rebuild_header);
0860 
0861 bool ipv6_opt_accepted(const struct sock *sk, const struct sk_buff *skb,
0862                const struct inet6_skb_parm *opt)
0863 {
0864     const struct ipv6_pinfo *np = inet6_sk(sk);
0865 
0866     if (np->rxopt.all) {
0867         if (((opt->flags & IP6SKB_HOPBYHOP) &&
0868              (np->rxopt.bits.hopopts || np->rxopt.bits.ohopopts)) ||
0869             (ip6_flowinfo((struct ipv6hdr *) skb_network_header(skb)) &&
0870              np->rxopt.bits.rxflow) ||
0871             (opt->srcrt && (np->rxopt.bits.srcrt ||
0872              np->rxopt.bits.osrcrt)) ||
0873             ((opt->dst1 || opt->dst0) &&
0874              (np->rxopt.bits.dstopts || np->rxopt.bits.odstopts)))
0875             return true;
0876     }
0877     return false;
0878 }
0879 EXPORT_SYMBOL_GPL(ipv6_opt_accepted);
0880 
0881 static struct packet_type ipv6_packet_type __read_mostly = {
0882     .type = cpu_to_be16(ETH_P_IPV6),
0883     .func = ipv6_rcv,
0884     .list_func = ipv6_list_rcv,
0885 };
0886 
0887 static int __init ipv6_packet_init(void)
0888 {
0889     dev_add_pack(&ipv6_packet_type);
0890     return 0;
0891 }
0892 
0893 static void ipv6_packet_cleanup(void)
0894 {
0895     dev_remove_pack(&ipv6_packet_type);
0896 }
0897 
0898 static int __net_init ipv6_init_mibs(struct net *net)
0899 {
0900     int i;
0901 
0902     net->mib.udp_stats_in6 = alloc_percpu(struct udp_mib);
0903     if (!net->mib.udp_stats_in6)
0904         return -ENOMEM;
0905     net->mib.udplite_stats_in6 = alloc_percpu(struct udp_mib);
0906     if (!net->mib.udplite_stats_in6)
0907         goto err_udplite_mib;
0908     net->mib.ipv6_statistics = alloc_percpu(struct ipstats_mib);
0909     if (!net->mib.ipv6_statistics)
0910         goto err_ip_mib;
0911 
0912     for_each_possible_cpu(i) {
0913         struct ipstats_mib *af_inet6_stats;
0914         af_inet6_stats = per_cpu_ptr(net->mib.ipv6_statistics, i);
0915         u64_stats_init(&af_inet6_stats->syncp);
0916     }
0917 
0918 
0919     net->mib.icmpv6_statistics = alloc_percpu(struct icmpv6_mib);
0920     if (!net->mib.icmpv6_statistics)
0921         goto err_icmp_mib;
0922     net->mib.icmpv6msg_statistics = kzalloc(sizeof(struct icmpv6msg_mib),
0923                         GFP_KERNEL);
0924     if (!net->mib.icmpv6msg_statistics)
0925         goto err_icmpmsg_mib;
0926     return 0;
0927 
0928 err_icmpmsg_mib:
0929     free_percpu(net->mib.icmpv6_statistics);
0930 err_icmp_mib:
0931     free_percpu(net->mib.ipv6_statistics);
0932 err_ip_mib:
0933     free_percpu(net->mib.udplite_stats_in6);
0934 err_udplite_mib:
0935     free_percpu(net->mib.udp_stats_in6);
0936     return -ENOMEM;
0937 }
0938 
0939 static void ipv6_cleanup_mibs(struct net *net)
0940 {
0941     free_percpu(net->mib.udp_stats_in6);
0942     free_percpu(net->mib.udplite_stats_in6);
0943     free_percpu(net->mib.ipv6_statistics);
0944     free_percpu(net->mib.icmpv6_statistics);
0945     kfree(net->mib.icmpv6msg_statistics);
0946 }
0947 
0948 static int __net_init inet6_net_init(struct net *net)
0949 {
0950     int err = 0;
0951 
0952     net->ipv6.sysctl.bindv6only = 0;
0953     net->ipv6.sysctl.icmpv6_time = 1*HZ;
0954     net->ipv6.sysctl.icmpv6_echo_ignore_all = 0;
0955     net->ipv6.sysctl.icmpv6_echo_ignore_multicast = 0;
0956     net->ipv6.sysctl.icmpv6_echo_ignore_anycast = 0;
0957 
0958     /* By default, rate limit error messages.
0959      * Except for pmtu discovery, it would break it.
0960      * proc_do_large_bitmap needs pointer to the bitmap.
0961      */
0962     bitmap_set(net->ipv6.sysctl.icmpv6_ratemask, 0, ICMPV6_ERRMSG_MAX + 1);
0963     bitmap_clear(net->ipv6.sysctl.icmpv6_ratemask, ICMPV6_PKT_TOOBIG, 1);
0964     net->ipv6.sysctl.icmpv6_ratemask_ptr = net->ipv6.sysctl.icmpv6_ratemask;
0965 
0966     net->ipv6.sysctl.flowlabel_consistency = 1;
0967     net->ipv6.sysctl.auto_flowlabels = IP6_DEFAULT_AUTO_FLOW_LABELS;
0968     net->ipv6.sysctl.idgen_retries = 3;
0969     net->ipv6.sysctl.idgen_delay = 1 * HZ;
0970     net->ipv6.sysctl.flowlabel_state_ranges = 0;
0971     net->ipv6.sysctl.max_dst_opts_cnt = IP6_DEFAULT_MAX_DST_OPTS_CNT;
0972     net->ipv6.sysctl.max_hbh_opts_cnt = IP6_DEFAULT_MAX_HBH_OPTS_CNT;
0973     net->ipv6.sysctl.max_dst_opts_len = IP6_DEFAULT_MAX_DST_OPTS_LEN;
0974     net->ipv6.sysctl.max_hbh_opts_len = IP6_DEFAULT_MAX_HBH_OPTS_LEN;
0975     net->ipv6.sysctl.fib_notify_on_flag_change = 0;
0976     atomic_set(&net->ipv6.fib6_sernum, 1);
0977 
0978     net->ipv6.sysctl.ioam6_id = IOAM6_DEFAULT_ID;
0979     net->ipv6.sysctl.ioam6_id_wide = IOAM6_DEFAULT_ID_WIDE;
0980 
0981     err = ipv6_init_mibs(net);
0982     if (err)
0983         return err;
0984 #ifdef CONFIG_PROC_FS
0985     err = udp6_proc_init(net);
0986     if (err)
0987         goto out;
0988     err = tcp6_proc_init(net);
0989     if (err)
0990         goto proc_tcp6_fail;
0991     err = ac6_proc_init(net);
0992     if (err)
0993         goto proc_ac6_fail;
0994 #endif
0995     return err;
0996 
0997 #ifdef CONFIG_PROC_FS
0998 proc_ac6_fail:
0999     tcp6_proc_exit(net);
1000 proc_tcp6_fail:
1001     udp6_proc_exit(net);
1002 out:
1003     ipv6_cleanup_mibs(net);
1004     return err;
1005 #endif
1006 }
1007 
1008 static void __net_exit inet6_net_exit(struct net *net)
1009 {
1010 #ifdef CONFIG_PROC_FS
1011     udp6_proc_exit(net);
1012     tcp6_proc_exit(net);
1013     ac6_proc_exit(net);
1014 #endif
1015     ipv6_cleanup_mibs(net);
1016 }
1017 
1018 static struct pernet_operations inet6_net_ops = {
1019     .init = inet6_net_init,
1020     .exit = inet6_net_exit,
1021 };
1022 
1023 static int ipv6_route_input(struct sk_buff *skb)
1024 {
1025     ip6_route_input(skb);
1026     return skb_dst(skb)->error;
1027 }
1028 
1029 static const struct ipv6_stub ipv6_stub_impl = {
1030     .ipv6_sock_mc_join = ipv6_sock_mc_join,
1031     .ipv6_sock_mc_drop = ipv6_sock_mc_drop,
1032     .ipv6_dst_lookup_flow = ip6_dst_lookup_flow,
1033     .ipv6_route_input  = ipv6_route_input,
1034     .fib6_get_table    = fib6_get_table,
1035     .fib6_table_lookup = fib6_table_lookup,
1036     .fib6_lookup       = fib6_lookup,
1037     .fib6_select_path  = fib6_select_path,
1038     .ip6_mtu_from_fib6 = ip6_mtu_from_fib6,
1039     .fib6_nh_init      = fib6_nh_init,
1040     .fib6_nh_release   = fib6_nh_release,
1041     .fib6_nh_release_dsts = fib6_nh_release_dsts,
1042     .fib6_update_sernum = fib6_update_sernum_stub,
1043     .fib6_rt_update    = fib6_rt_update,
1044     .ip6_del_rt    = ip6_del_rt,
1045     .udpv6_encap_enable = udpv6_encap_enable,
1046     .ndisc_send_na = ndisc_send_na,
1047 #if IS_ENABLED(CONFIG_XFRM)
1048     .xfrm6_local_rxpmtu = xfrm6_local_rxpmtu,
1049     .xfrm6_udp_encap_rcv = xfrm6_udp_encap_rcv,
1050     .xfrm6_rcv_encap = xfrm6_rcv_encap,
1051 #endif
1052     .nd_tbl = &nd_tbl,
1053     .ipv6_fragment = ip6_fragment,
1054     .ipv6_dev_find = ipv6_dev_find,
1055 };
1056 
1057 static const struct ipv6_bpf_stub ipv6_bpf_stub_impl = {
1058     .inet6_bind = __inet6_bind,
1059     .udp6_lib_lookup = __udp6_lib_lookup,
1060 };
1061 
1062 static int __init inet6_init(void)
1063 {
1064     struct list_head *r;
1065     int err = 0;
1066 
1067     sock_skb_cb_check_size(sizeof(struct inet6_skb_parm));
1068 
1069     /* Register the socket-side information for inet6_create.  */
1070     for (r = &inetsw6[0]; r < &inetsw6[SOCK_MAX]; ++r)
1071         INIT_LIST_HEAD(r);
1072 
1073     raw_hashinfo_init(&raw_v6_hashinfo);
1074 
1075     if (disable_ipv6_mod) {
1076         pr_info("Loaded, but administratively disabled, reboot required to enable\n");
1077         goto out;
1078     }
1079 
1080     err = proto_register(&tcpv6_prot, 1);
1081     if (err)
1082         goto out;
1083 
1084     err = proto_register(&udpv6_prot, 1);
1085     if (err)
1086         goto out_unregister_tcp_proto;
1087 
1088     err = proto_register(&udplitev6_prot, 1);
1089     if (err)
1090         goto out_unregister_udp_proto;
1091 
1092     err = proto_register(&rawv6_prot, 1);
1093     if (err)
1094         goto out_unregister_udplite_proto;
1095 
1096     err = proto_register(&pingv6_prot, 1);
1097     if (err)
1098         goto out_unregister_raw_proto;
1099 
1100     /* We MUST register RAW sockets before we create the ICMP6,
1101      * IGMP6, or NDISC control sockets.
1102      */
1103     err = rawv6_init();
1104     if (err)
1105         goto out_unregister_ping_proto;
1106 
1107     /* Register the family here so that the init calls below will
1108      * be able to create sockets. (?? is this dangerous ??)
1109      */
1110     err = sock_register(&inet6_family_ops);
1111     if (err)
1112         goto out_sock_register_fail;
1113 
1114     /*
1115      *  ipngwg API draft makes clear that the correct semantics
1116      *  for TCP and UDP is to consider one TCP and UDP instance
1117      *  in a host available by both INET and INET6 APIs and
1118      *  able to communicate via both network protocols.
1119      */
1120 
1121     err = register_pernet_subsys(&inet6_net_ops);
1122     if (err)
1123         goto register_pernet_fail;
1124     err = ip6_mr_init();
1125     if (err)
1126         goto ipmr_fail;
1127     err = icmpv6_init();
1128     if (err)
1129         goto icmp_fail;
1130     err = ndisc_init();
1131     if (err)
1132         goto ndisc_fail;
1133     err = igmp6_init();
1134     if (err)
1135         goto igmp_fail;
1136 
1137     err = ipv6_netfilter_init();
1138     if (err)
1139         goto netfilter_fail;
1140     /* Create /proc/foo6 entries. */
1141 #ifdef CONFIG_PROC_FS
1142     err = -ENOMEM;
1143     if (raw6_proc_init())
1144         goto proc_raw6_fail;
1145     if (udplite6_proc_init())
1146         goto proc_udplite6_fail;
1147     if (ipv6_misc_proc_init())
1148         goto proc_misc6_fail;
1149     if (if6_proc_init())
1150         goto proc_if6_fail;
1151 #endif
1152     err = ip6_route_init();
1153     if (err)
1154         goto ip6_route_fail;
1155     err = ndisc_late_init();
1156     if (err)
1157         goto ndisc_late_fail;
1158     err = ip6_flowlabel_init();
1159     if (err)
1160         goto ip6_flowlabel_fail;
1161     err = ipv6_anycast_init();
1162     if (err)
1163         goto ipv6_anycast_fail;
1164     err = addrconf_init();
1165     if (err)
1166         goto addrconf_fail;
1167 
1168     /* Init v6 extension headers. */
1169     err = ipv6_exthdrs_init();
1170     if (err)
1171         goto ipv6_exthdrs_fail;
1172 
1173     err = ipv6_frag_init();
1174     if (err)
1175         goto ipv6_frag_fail;
1176 
1177     /* Init v6 transport protocols. */
1178     err = udpv6_init();
1179     if (err)
1180         goto udpv6_fail;
1181 
1182     err = udplitev6_init();
1183     if (err)
1184         goto udplitev6_fail;
1185 
1186     err = udpv6_offload_init();
1187     if (err)
1188         goto udpv6_offload_fail;
1189 
1190     err = tcpv6_init();
1191     if (err)
1192         goto tcpv6_fail;
1193 
1194     err = ipv6_packet_init();
1195     if (err)
1196         goto ipv6_packet_fail;
1197 
1198     err = pingv6_init();
1199     if (err)
1200         goto pingv6_fail;
1201 
1202     err = calipso_init();
1203     if (err)
1204         goto calipso_fail;
1205 
1206     err = seg6_init();
1207     if (err)
1208         goto seg6_fail;
1209 
1210     err = rpl_init();
1211     if (err)
1212         goto rpl_fail;
1213 
1214     err = ioam6_init();
1215     if (err)
1216         goto ioam6_fail;
1217 
1218     err = igmp6_late_init();
1219     if (err)
1220         goto igmp6_late_err;
1221 
1222 #ifdef CONFIG_SYSCTL
1223     err = ipv6_sysctl_register();
1224     if (err)
1225         goto sysctl_fail;
1226 #endif
1227 
1228     /* ensure that ipv6 stubs are visible only after ipv6 is ready */
1229     wmb();
1230     ipv6_stub = &ipv6_stub_impl;
1231     ipv6_bpf_stub = &ipv6_bpf_stub_impl;
1232 out:
1233     return err;
1234 
1235 #ifdef CONFIG_SYSCTL
1236 sysctl_fail:
1237     igmp6_late_cleanup();
1238 #endif
1239 igmp6_late_err:
1240     ioam6_exit();
1241 ioam6_fail:
1242     rpl_exit();
1243 rpl_fail:
1244     seg6_exit();
1245 seg6_fail:
1246     calipso_exit();
1247 calipso_fail:
1248     pingv6_exit();
1249 pingv6_fail:
1250     ipv6_packet_cleanup();
1251 ipv6_packet_fail:
1252     tcpv6_exit();
1253 tcpv6_fail:
1254     udpv6_offload_exit();
1255 udpv6_offload_fail:
1256     udplitev6_exit();
1257 udplitev6_fail:
1258     udpv6_exit();
1259 udpv6_fail:
1260     ipv6_frag_exit();
1261 ipv6_frag_fail:
1262     ipv6_exthdrs_exit();
1263 ipv6_exthdrs_fail:
1264     addrconf_cleanup();
1265 addrconf_fail:
1266     ipv6_anycast_cleanup();
1267 ipv6_anycast_fail:
1268     ip6_flowlabel_cleanup();
1269 ip6_flowlabel_fail:
1270     ndisc_late_cleanup();
1271 ndisc_late_fail:
1272     ip6_route_cleanup();
1273 ip6_route_fail:
1274 #ifdef CONFIG_PROC_FS
1275     if6_proc_exit();
1276 proc_if6_fail:
1277     ipv6_misc_proc_exit();
1278 proc_misc6_fail:
1279     udplite6_proc_exit();
1280 proc_udplite6_fail:
1281     raw6_proc_exit();
1282 proc_raw6_fail:
1283 #endif
1284     ipv6_netfilter_fini();
1285 netfilter_fail:
1286     igmp6_cleanup();
1287 igmp_fail:
1288     ndisc_cleanup();
1289 ndisc_fail:
1290     icmpv6_cleanup();
1291 icmp_fail:
1292     ip6_mr_cleanup();
1293 ipmr_fail:
1294     unregister_pernet_subsys(&inet6_net_ops);
1295 register_pernet_fail:
1296     sock_unregister(PF_INET6);
1297     rtnl_unregister_all(PF_INET6);
1298 out_sock_register_fail:
1299     rawv6_exit();
1300 out_unregister_ping_proto:
1301     proto_unregister(&pingv6_prot);
1302 out_unregister_raw_proto:
1303     proto_unregister(&rawv6_prot);
1304 out_unregister_udplite_proto:
1305     proto_unregister(&udplitev6_prot);
1306 out_unregister_udp_proto:
1307     proto_unregister(&udpv6_prot);
1308 out_unregister_tcp_proto:
1309     proto_unregister(&tcpv6_prot);
1310     goto out;
1311 }
1312 module_init(inet6_init);
1313 
1314 MODULE_ALIAS_NETPROTO(PF_INET6);