11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * PF_INET6 socket protocol family 31da177e4SLinus Torvalds * Linux INET6 implementation 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Authors: 61da177e4SLinus Torvalds * Pedro Roque <roque@di.fc.ul.pt> 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * Adapted from linux/net/ipv4/af_inet.c 91da177e4SLinus Torvalds * 101da177e4SLinus Torvalds * Fixes: 111da177e4SLinus Torvalds * piggy, Karl Knutson : Socket protocol table 121da177e4SLinus Torvalds * Hideaki YOSHIFUJI : sin6_scope_id support 131da177e4SLinus Torvalds * Arnaldo Melo : check proc_net_create return, cleanups 141da177e4SLinus Torvalds * 151da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or 161da177e4SLinus Torvalds * modify it under the terms of the GNU General Public License 171da177e4SLinus Torvalds * as published by the Free Software Foundation; either version 181da177e4SLinus Torvalds * 2 of the License, or (at your option) any later version. 191da177e4SLinus Torvalds */ 201da177e4SLinus Torvalds 211da177e4SLinus Torvalds 221da177e4SLinus Torvalds #include <linux/module.h> 234fc268d2SRandy Dunlap #include <linux/capability.h> 241da177e4SLinus Torvalds #include <linux/errno.h> 251da177e4SLinus Torvalds #include <linux/types.h> 261da177e4SLinus Torvalds #include <linux/socket.h> 271da177e4SLinus Torvalds #include <linux/in.h> 281da177e4SLinus Torvalds #include <linux/kernel.h> 291da177e4SLinus Torvalds #include <linux/timer.h> 301da177e4SLinus Torvalds #include <linux/string.h> 311da177e4SLinus Torvalds #include <linux/sockios.h> 321da177e4SLinus Torvalds #include <linux/net.h> 331da177e4SLinus Torvalds #include <linux/fcntl.h> 341da177e4SLinus Torvalds #include <linux/mm.h> 351da177e4SLinus Torvalds #include <linux/interrupt.h> 361da177e4SLinus Torvalds #include <linux/proc_fs.h> 371da177e4SLinus Torvalds #include <linux/stat.h> 381da177e4SLinus Torvalds #include <linux/init.h> 391da177e4SLinus Torvalds 401da177e4SLinus Torvalds #include <linux/inet.h> 411da177e4SLinus Torvalds #include <linux/netdevice.h> 421da177e4SLinus Torvalds #include <linux/icmpv6.h> 432cc7d573SHarald Welte #include <linux/netfilter_ipv6.h> 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds #include <net/ip.h> 461da177e4SLinus Torvalds #include <net/ipv6.h> 471da177e4SLinus Torvalds #include <net/udp.h> 48ba4e58ecSGerrit Renker #include <net/udplite.h> 491da177e4SLinus Torvalds #include <net/tcp.h> 501da177e4SLinus Torvalds #include <net/ipip.h> 511da177e4SLinus Torvalds #include <net/protocol.h> 521da177e4SLinus Torvalds #include <net/inet_common.h> 531668e010SKOVACS Krisztian #include <net/route.h> 541da177e4SLinus Torvalds #include <net/transp_v6.h> 551da177e4SLinus Torvalds #include <net/ip6_route.h> 561da177e4SLinus Torvalds #include <net/addrconf.h> 571da177e4SLinus Torvalds #ifdef CONFIG_IPV6_TUNNEL 581da177e4SLinus Torvalds #include <net/ip6_tunnel.h> 591da177e4SLinus Torvalds #endif 601da177e4SLinus Torvalds 611da177e4SLinus Torvalds #include <asm/uaccess.h> 621da177e4SLinus Torvalds #include <asm/system.h> 637bc570c8SYOSHIFUJI Hideaki #include <linux/mroute6.h> 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds MODULE_AUTHOR("Cast of dozens"); 661da177e4SLinus Torvalds MODULE_DESCRIPTION("IPv6 protocol stack for Linux"); 671da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 681da177e4SLinus Torvalds 69f1267347SPavel Emelyanov /* The inetsw6 table contains everything that inet6_create needs to 701da177e4SLinus Torvalds * build a new socket. 711da177e4SLinus Torvalds */ 721da177e4SLinus Torvalds static struct list_head inetsw6[SOCK_MAX]; 731da177e4SLinus Torvalds static DEFINE_SPINLOCK(inetsw6_lock); 741da177e4SLinus Torvalds 751da177e4SLinus Torvalds static __inline__ struct ipv6_pinfo *inet6_sk_generic(struct sock *sk) 761da177e4SLinus Torvalds { 771da177e4SLinus Torvalds const int offset = sk->sk_prot->obj_size - sizeof(struct ipv6_pinfo); 781da177e4SLinus Torvalds 791da177e4SLinus Torvalds return (struct ipv6_pinfo *)(((u8 *)sk) + offset); 801da177e4SLinus Torvalds } 811da177e4SLinus Torvalds 821b8d7ae4SEric W. Biederman static int inet6_create(struct net *net, struct socket *sock, int protocol) 831da177e4SLinus Torvalds { 841da177e4SLinus Torvalds struct inet_sock *inet; 851da177e4SLinus Torvalds struct ipv6_pinfo *np; 861da177e4SLinus Torvalds struct sock *sk; 871da177e4SLinus Torvalds struct inet_protosw *answer; 881da177e4SLinus Torvalds struct proto *answer_prot; 891da177e4SLinus Torvalds unsigned char answer_flags; 901da177e4SLinus Torvalds char answer_no_check; 91af1afe86SYOSHIFUJI Hideaki int try_loading_module = 0; 92af1afe86SYOSHIFUJI Hideaki int err; 931da177e4SLinus Torvalds 94b3da2cf3SDavid S. Miller if (sock->type != SOCK_RAW && 95b3da2cf3SDavid S. Miller sock->type != SOCK_DGRAM && 96b3da2cf3SDavid S. Miller !inet_ehash_secret) 97b3da2cf3SDavid S. Miller build_ehash_secret(); 98b3da2cf3SDavid S. Miller 991da177e4SLinus Torvalds /* Look for the requested type/protocol pair. */ 100af1afe86SYOSHIFUJI Hideaki lookup_protocol: 101af1afe86SYOSHIFUJI Hideaki err = -ESOCKTNOSUPPORT; 1021da177e4SLinus Torvalds rcu_read_lock(); 103696adfe8SPaul E. McKenney list_for_each_entry_rcu(answer, &inetsw6[sock->type], list) { 1041da177e4SLinus Torvalds 105696adfe8SPaul E. McKenney err = 0; 1061da177e4SLinus Torvalds /* Check the non-wild match. */ 1071da177e4SLinus Torvalds if (protocol == answer->protocol) { 1081da177e4SLinus Torvalds if (protocol != IPPROTO_IP) 1091da177e4SLinus Torvalds break; 1101da177e4SLinus Torvalds } else { 1111da177e4SLinus Torvalds /* Check for the two wild cases. */ 1121da177e4SLinus Torvalds if (IPPROTO_IP == protocol) { 1131da177e4SLinus Torvalds protocol = answer->protocol; 1141da177e4SLinus Torvalds break; 1151da177e4SLinus Torvalds } 1161da177e4SLinus Torvalds if (IPPROTO_IP == answer->protocol) 1171da177e4SLinus Torvalds break; 1181da177e4SLinus Torvalds } 119af1afe86SYOSHIFUJI Hideaki err = -EPROTONOSUPPORT; 1201da177e4SLinus Torvalds } 1211da177e4SLinus Torvalds 122696adfe8SPaul E. McKenney if (err) { 123af1afe86SYOSHIFUJI Hideaki if (try_loading_module < 2) { 124af1afe86SYOSHIFUJI Hideaki rcu_read_unlock(); 125af1afe86SYOSHIFUJI Hideaki /* 126af1afe86SYOSHIFUJI Hideaki * Be more specific, e.g. net-pf-10-proto-132-type-1 127af1afe86SYOSHIFUJI Hideaki * (net-pf-PF_INET6-proto-IPPROTO_SCTP-type-SOCK_STREAM) 128af1afe86SYOSHIFUJI Hideaki */ 129af1afe86SYOSHIFUJI Hideaki if (++try_loading_module == 1) 130af1afe86SYOSHIFUJI Hideaki request_module("net-pf-%d-proto-%d-type-%d", 131af1afe86SYOSHIFUJI Hideaki PF_INET6, protocol, sock->type); 132af1afe86SYOSHIFUJI Hideaki /* 133af1afe86SYOSHIFUJI Hideaki * Fall back to generic, e.g. net-pf-10-proto-132 134af1afe86SYOSHIFUJI Hideaki * (net-pf-PF_INET6-proto-IPPROTO_SCTP) 135af1afe86SYOSHIFUJI Hideaki */ 136af1afe86SYOSHIFUJI Hideaki else 137af1afe86SYOSHIFUJI Hideaki request_module("net-pf-%d-proto-%d", 138af1afe86SYOSHIFUJI Hideaki PF_INET6, protocol); 139af1afe86SYOSHIFUJI Hideaki goto lookup_protocol; 140af1afe86SYOSHIFUJI Hideaki } else 1411da177e4SLinus Torvalds goto out_rcu_unlock; 142af1afe86SYOSHIFUJI Hideaki } 143af1afe86SYOSHIFUJI Hideaki 144af1afe86SYOSHIFUJI Hideaki err = -EPERM; 1451da177e4SLinus Torvalds if (answer->capability > 0 && !capable(answer->capability)) 1461da177e4SLinus Torvalds goto out_rcu_unlock; 1471da177e4SLinus Torvalds 1481da177e4SLinus Torvalds sock->ops = answer->ops; 1491da177e4SLinus Torvalds answer_prot = answer->prot; 1501da177e4SLinus Torvalds answer_no_check = answer->no_check; 1511da177e4SLinus Torvalds answer_flags = answer->flags; 1521da177e4SLinus Torvalds rcu_read_unlock(); 1531da177e4SLinus Torvalds 154547b792cSIlpo Järvinen WARN_ON(answer_prot->slab == NULL); 1551da177e4SLinus Torvalds 156af1afe86SYOSHIFUJI Hideaki err = -ENOBUFS; 1576257ff21SPavel Emelyanov sk = sk_alloc(net, PF_INET6, GFP_KERNEL, answer_prot); 1581da177e4SLinus Torvalds if (sk == NULL) 1591da177e4SLinus Torvalds goto out; 1601da177e4SLinus Torvalds 1611da177e4SLinus Torvalds sock_init_data(sock, sk); 1621da177e4SLinus Torvalds 163af1afe86SYOSHIFUJI Hideaki err = 0; 1641da177e4SLinus Torvalds sk->sk_no_check = answer_no_check; 1651da177e4SLinus Torvalds if (INET_PROTOSW_REUSE & answer_flags) 1661da177e4SLinus Torvalds sk->sk_reuse = 1; 1671da177e4SLinus Torvalds 1681da177e4SLinus Torvalds inet = inet_sk(sk); 169469de9b9SPaul Moore inet->is_icsk = (INET_PROTOSW_ICSK & answer_flags) != 0; 1701da177e4SLinus Torvalds 1711da177e4SLinus Torvalds if (SOCK_RAW == sock->type) { 1721da177e4SLinus Torvalds inet->num = protocol; 1731da177e4SLinus Torvalds if (IPPROTO_RAW == protocol) 1741da177e4SLinus Torvalds inet->hdrincl = 1; 1751da177e4SLinus Torvalds } 1761da177e4SLinus Torvalds 177e6848976SArnaldo Carvalho de Melo sk->sk_destruct = inet_sock_destruct; 1781da177e4SLinus Torvalds sk->sk_family = PF_INET6; 1791da177e4SLinus Torvalds sk->sk_protocol = protocol; 1801da177e4SLinus Torvalds 1811da177e4SLinus Torvalds sk->sk_backlog_rcv = answer->prot->backlog_rcv; 1821da177e4SLinus Torvalds 1831da177e4SLinus Torvalds inet_sk(sk)->pinet6 = np = inet6_sk_generic(sk); 1841da177e4SLinus Torvalds np->hop_limit = -1; 1851da177e4SLinus Torvalds np->mcast_hops = -1; 1861da177e4SLinus Torvalds np->mc_loop = 1; 1871da177e4SLinus Torvalds np->pmtudisc = IPV6_PMTUDISC_WANT; 1882e761e05SPavel Emelyanov np->ipv6only = net->ipv6.sysctl.bindv6only; 1891da177e4SLinus Torvalds 1901da177e4SLinus Torvalds /* Init the ipv4 part of the socket since we can have sockets 1911da177e4SLinus Torvalds * using v6 API for ipv4. 1921da177e4SLinus Torvalds */ 1931da177e4SLinus Torvalds inet->uc_ttl = -1; 1941da177e4SLinus Torvalds 1951da177e4SLinus Torvalds inet->mc_loop = 1; 1961da177e4SLinus Torvalds inet->mc_ttl = 1; 1971da177e4SLinus Torvalds inet->mc_index = 0; 1981da177e4SLinus Torvalds inet->mc_list = NULL; 1991da177e4SLinus Torvalds 2001da177e4SLinus Torvalds if (ipv4_config.no_pmtu_disc) 2011da177e4SLinus Torvalds inet->pmtudisc = IP_PMTUDISC_DONT; 2021da177e4SLinus Torvalds else 2031da177e4SLinus Torvalds inet->pmtudisc = IP_PMTUDISC_WANT; 204e6848976SArnaldo Carvalho de Melo /* 205e6848976SArnaldo Carvalho de Melo * Increment only the relevant sk_prot->socks debug field, this changes 206e6848976SArnaldo Carvalho de Melo * the previous behaviour of incrementing both the equivalent to 207e6848976SArnaldo Carvalho de Melo * answer->prot->socks (inet6_sock_nr) and inet_sock_nr. 208e6848976SArnaldo Carvalho de Melo * 209e6848976SArnaldo Carvalho de Melo * This allows better debug granularity as we'll know exactly how many 210e6848976SArnaldo Carvalho de Melo * UDPv6, TCPv6, etc socks were allocated, not the sum of all IPv6 211e6848976SArnaldo Carvalho de Melo * transport protocol socks. -acme 212e6848976SArnaldo Carvalho de Melo */ 213e6848976SArnaldo Carvalho de Melo sk_refcnt_debug_inc(sk); 2141da177e4SLinus Torvalds 2151da177e4SLinus Torvalds if (inet->num) { 2161da177e4SLinus Torvalds /* It assumes that any protocol which allows 2171da177e4SLinus Torvalds * the user to assign a number at socket 2181da177e4SLinus Torvalds * creation time automatically shares. 2191da177e4SLinus Torvalds */ 220e69a4adcSAl Viro inet->sport = htons(inet->num); 2211da177e4SLinus Torvalds sk->sk_prot->hash(sk); 2221da177e4SLinus Torvalds } 2231da177e4SLinus Torvalds if (sk->sk_prot->init) { 224af1afe86SYOSHIFUJI Hideaki err = sk->sk_prot->init(sk); 225af1afe86SYOSHIFUJI Hideaki if (err) { 2261da177e4SLinus Torvalds sk_common_release(sk); 2271da177e4SLinus Torvalds goto out; 2281da177e4SLinus Torvalds } 2291da177e4SLinus Torvalds } 2301da177e4SLinus Torvalds out: 231af1afe86SYOSHIFUJI Hideaki return err; 2321da177e4SLinus Torvalds out_rcu_unlock: 2331da177e4SLinus Torvalds rcu_read_unlock(); 2341da177e4SLinus Torvalds goto out; 2351da177e4SLinus Torvalds } 2361da177e4SLinus Torvalds 2371da177e4SLinus Torvalds 2381da177e4SLinus Torvalds /* bind for INET6 API */ 2391da177e4SLinus Torvalds int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) 2401da177e4SLinus Torvalds { 2411da177e4SLinus Torvalds struct sockaddr_in6 *addr=(struct sockaddr_in6 *)uaddr; 2421da177e4SLinus Torvalds struct sock *sk = sock->sk; 2431da177e4SLinus Torvalds struct inet_sock *inet = inet_sk(sk); 2441da177e4SLinus Torvalds struct ipv6_pinfo *np = inet6_sk(sk); 2453b1e0a65SYOSHIFUJI Hideaki struct net *net = sock_net(sk); 246fd683222SAl Viro __be32 v4addr = 0; 2471da177e4SLinus Torvalds unsigned short snum; 2481da177e4SLinus Torvalds int addr_type = 0; 2491da177e4SLinus Torvalds int err = 0; 2501da177e4SLinus Torvalds 2511da177e4SLinus Torvalds /* If the socket has its own bind function then use it. */ 2521da177e4SLinus Torvalds if (sk->sk_prot->bind) 2531da177e4SLinus Torvalds return sk->sk_prot->bind(sk, uaddr, addr_len); 2541da177e4SLinus Torvalds 2551da177e4SLinus Torvalds if (addr_len < SIN6_LEN_RFC2133) 2561da177e4SLinus Torvalds return -EINVAL; 2571da177e4SLinus Torvalds addr_type = ipv6_addr_type(&addr->sin6_addr); 2581da177e4SLinus Torvalds if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM) 2591da177e4SLinus Torvalds return -EINVAL; 2601da177e4SLinus Torvalds 2611da177e4SLinus Torvalds snum = ntohs(addr->sin6_port); 2621da177e4SLinus Torvalds if (snum && snum < PROT_SOCK && !capable(CAP_NET_BIND_SERVICE)) 2631da177e4SLinus Torvalds return -EACCES; 2641da177e4SLinus Torvalds 2651da177e4SLinus Torvalds lock_sock(sk); 2661da177e4SLinus Torvalds 2671da177e4SLinus Torvalds /* Check these errors (active socket, double bind). */ 2681da177e4SLinus Torvalds if (sk->sk_state != TCP_CLOSE || inet->num) { 2691da177e4SLinus Torvalds err = -EINVAL; 2701da177e4SLinus Torvalds goto out; 2711da177e4SLinus Torvalds } 2721da177e4SLinus Torvalds 2731da177e4SLinus Torvalds /* Check if the address belongs to the host. */ 2741da177e4SLinus Torvalds if (addr_type == IPV6_ADDR_MAPPED) { 2751da177e4SLinus Torvalds v4addr = addr->sin6_addr.s6_addr32[3]; 276075de939SBenjamin Thery if (inet_addr_type(net, v4addr) != RTN_LOCAL) { 2771da177e4SLinus Torvalds err = -EADDRNOTAVAIL; 2781da177e4SLinus Torvalds goto out; 2791da177e4SLinus Torvalds } 2801da177e4SLinus Torvalds } else { 2811da177e4SLinus Torvalds if (addr_type != IPV6_ADDR_ANY) { 2821da177e4SLinus Torvalds struct net_device *dev = NULL; 2831da177e4SLinus Torvalds 2841da177e4SLinus Torvalds if (addr_type & IPV6_ADDR_LINKLOCAL) { 2851da177e4SLinus Torvalds if (addr_len >= sizeof(struct sockaddr_in6) && 2861da177e4SLinus Torvalds addr->sin6_scope_id) { 2871da177e4SLinus Torvalds /* Override any existing binding, if another one 2881da177e4SLinus Torvalds * is supplied by user. 2891da177e4SLinus Torvalds */ 2901da177e4SLinus Torvalds sk->sk_bound_dev_if = addr->sin6_scope_id; 2911da177e4SLinus Torvalds } 2921da177e4SLinus Torvalds 2931da177e4SLinus Torvalds /* Binding to link-local address requires an interface */ 2941da177e4SLinus Torvalds if (!sk->sk_bound_dev_if) { 2951da177e4SLinus Torvalds err = -EINVAL; 2961da177e4SLinus Torvalds goto out; 2971da177e4SLinus Torvalds } 298075de939SBenjamin Thery dev = dev_get_by_index(net, sk->sk_bound_dev_if); 2991da177e4SLinus Torvalds if (!dev) { 3001da177e4SLinus Torvalds err = -ENODEV; 3011da177e4SLinus Torvalds goto out; 3021da177e4SLinus Torvalds } 3031da177e4SLinus Torvalds } 3041da177e4SLinus Torvalds 3051da177e4SLinus Torvalds /* ipv4 addr of the socket is invalid. Only the 3061da177e4SLinus Torvalds * unspecified and mapped address have a v4 equivalent. 3071da177e4SLinus Torvalds */ 3081da177e4SLinus Torvalds v4addr = LOOPBACK4_IPV6; 3091da177e4SLinus Torvalds if (!(addr_type & IPV6_ADDR_MULTICAST)) { 310075de939SBenjamin Thery if (!ipv6_chk_addr(net, &addr->sin6_addr, 311bfeade08SDaniel Lezcano dev, 0)) { 3121da177e4SLinus Torvalds if (dev) 3131da177e4SLinus Torvalds dev_put(dev); 3141da177e4SLinus Torvalds err = -EADDRNOTAVAIL; 3151da177e4SLinus Torvalds goto out; 3161da177e4SLinus Torvalds } 3171da177e4SLinus Torvalds } 3181da177e4SLinus Torvalds if (dev) 3191da177e4SLinus Torvalds dev_put(dev); 3201da177e4SLinus Torvalds } 3211da177e4SLinus Torvalds } 3221da177e4SLinus Torvalds 3231da177e4SLinus Torvalds inet->rcv_saddr = v4addr; 3241da177e4SLinus Torvalds inet->saddr = v4addr; 3251da177e4SLinus Torvalds 3261da177e4SLinus Torvalds ipv6_addr_copy(&np->rcv_saddr, &addr->sin6_addr); 3271da177e4SLinus Torvalds 3281da177e4SLinus Torvalds if (!(addr_type & IPV6_ADDR_MULTICAST)) 3291da177e4SLinus Torvalds ipv6_addr_copy(&np->saddr, &addr->sin6_addr); 3301da177e4SLinus Torvalds 3311da177e4SLinus Torvalds /* Make sure we are allowed to bind here. */ 3321da177e4SLinus Torvalds if (sk->sk_prot->get_port(sk, snum)) { 3331da177e4SLinus Torvalds inet_reset_saddr(sk); 3341da177e4SLinus Torvalds err = -EADDRINUSE; 3351da177e4SLinus Torvalds goto out; 3361da177e4SLinus Torvalds } 3371da177e4SLinus Torvalds 3381da177e4SLinus Torvalds if (addr_type != IPV6_ADDR_ANY) 3391da177e4SLinus Torvalds sk->sk_userlocks |= SOCK_BINDADDR_LOCK; 3401da177e4SLinus Torvalds if (snum) 3411da177e4SLinus Torvalds sk->sk_userlocks |= SOCK_BINDPORT_LOCK; 342e69a4adcSAl Viro inet->sport = htons(inet->num); 3431da177e4SLinus Torvalds inet->dport = 0; 3441da177e4SLinus Torvalds inet->daddr = 0; 3451da177e4SLinus Torvalds out: 3461da177e4SLinus Torvalds release_sock(sk); 3471da177e4SLinus Torvalds return err; 3481da177e4SLinus Torvalds } 3491da177e4SLinus Torvalds 3507159039aSYOSHIFUJI Hideaki EXPORT_SYMBOL(inet6_bind); 3517159039aSYOSHIFUJI Hideaki 3521da177e4SLinus Torvalds int inet6_release(struct socket *sock) 3531da177e4SLinus Torvalds { 3541da177e4SLinus Torvalds struct sock *sk = sock->sk; 3551da177e4SLinus Torvalds 3561da177e4SLinus Torvalds if (sk == NULL) 3571da177e4SLinus Torvalds return -EINVAL; 3581da177e4SLinus Torvalds 3591da177e4SLinus Torvalds /* Free mc lists */ 3601da177e4SLinus Torvalds ipv6_sock_mc_close(sk); 3611da177e4SLinus Torvalds 3621da177e4SLinus Torvalds /* Free ac lists */ 3631da177e4SLinus Torvalds ipv6_sock_ac_close(sk); 3641da177e4SLinus Torvalds 3651da177e4SLinus Torvalds return inet_release(sock); 3661da177e4SLinus Torvalds } 3671da177e4SLinus Torvalds 3687159039aSYOSHIFUJI Hideaki EXPORT_SYMBOL(inet6_release); 3697159039aSYOSHIFUJI Hideaki 3707d06b2e0SBrian Haley void inet6_destroy_sock(struct sock *sk) 3711da177e4SLinus Torvalds { 3721da177e4SLinus Torvalds struct ipv6_pinfo *np = inet6_sk(sk); 3731da177e4SLinus Torvalds struct sk_buff *skb; 3741da177e4SLinus Torvalds struct ipv6_txoptions *opt; 3751da177e4SLinus Torvalds 3761da177e4SLinus Torvalds /* Release rx options */ 3771da177e4SLinus Torvalds 3781da177e4SLinus Torvalds if ((skb = xchg(&np->pktoptions, NULL)) != NULL) 3791da177e4SLinus Torvalds kfree_skb(skb); 3801da177e4SLinus Torvalds 3811da177e4SLinus Torvalds /* Free flowlabels */ 3821da177e4SLinus Torvalds fl6_free_socklist(sk); 3831da177e4SLinus Torvalds 3841da177e4SLinus Torvalds /* Free tx options */ 3851da177e4SLinus Torvalds 3861da177e4SLinus Torvalds if ((opt = xchg(&np->opt, NULL)) != NULL) 3871da177e4SLinus Torvalds sock_kfree_s(sk, opt, opt->tot_len); 3881da177e4SLinus Torvalds } 3891da177e4SLinus Torvalds 3903cf3dc6cSArnaldo Carvalho de Melo EXPORT_SYMBOL_GPL(inet6_destroy_sock); 3913cf3dc6cSArnaldo Carvalho de Melo 3921da177e4SLinus Torvalds /* 3931da177e4SLinus Torvalds * This does both peername and sockname. 3941da177e4SLinus Torvalds */ 3951da177e4SLinus Torvalds 3961da177e4SLinus Torvalds int inet6_getname(struct socket *sock, struct sockaddr *uaddr, 3971da177e4SLinus Torvalds int *uaddr_len, int peer) 3981da177e4SLinus Torvalds { 3991da177e4SLinus Torvalds struct sockaddr_in6 *sin=(struct sockaddr_in6 *)uaddr; 4001da177e4SLinus Torvalds struct sock *sk = sock->sk; 4011da177e4SLinus Torvalds struct inet_sock *inet = inet_sk(sk); 4021da177e4SLinus Torvalds struct ipv6_pinfo *np = inet6_sk(sk); 4031da177e4SLinus Torvalds 4041da177e4SLinus Torvalds sin->sin6_family = AF_INET6; 4051da177e4SLinus Torvalds sin->sin6_flowinfo = 0; 4061da177e4SLinus Torvalds sin->sin6_scope_id = 0; 4071da177e4SLinus Torvalds if (peer) { 4081da177e4SLinus Torvalds if (!inet->dport) 4091da177e4SLinus Torvalds return -ENOTCONN; 4101da177e4SLinus Torvalds if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_SYN_SENT)) && 4111da177e4SLinus Torvalds peer == 1) 4121da177e4SLinus Torvalds return -ENOTCONN; 4131da177e4SLinus Torvalds sin->sin6_port = inet->dport; 4141da177e4SLinus Torvalds ipv6_addr_copy(&sin->sin6_addr, &np->daddr); 4151da177e4SLinus Torvalds if (np->sndflow) 4161da177e4SLinus Torvalds sin->sin6_flowinfo = np->flow_label; 4171da177e4SLinus Torvalds } else { 4181da177e4SLinus Torvalds if (ipv6_addr_any(&np->rcv_saddr)) 4191da177e4SLinus Torvalds ipv6_addr_copy(&sin->sin6_addr, &np->saddr); 4201da177e4SLinus Torvalds else 4211da177e4SLinus Torvalds ipv6_addr_copy(&sin->sin6_addr, &np->rcv_saddr); 4221da177e4SLinus Torvalds 4231da177e4SLinus Torvalds sin->sin6_port = inet->sport; 4241da177e4SLinus Torvalds } 4251da177e4SLinus Torvalds if (ipv6_addr_type(&sin->sin6_addr) & IPV6_ADDR_LINKLOCAL) 4261da177e4SLinus Torvalds sin->sin6_scope_id = sk->sk_bound_dev_if; 4271da177e4SLinus Torvalds *uaddr_len = sizeof(*sin); 4281da177e4SLinus Torvalds return(0); 4291da177e4SLinus Torvalds } 4301da177e4SLinus Torvalds 4317159039aSYOSHIFUJI Hideaki EXPORT_SYMBOL(inet6_getname); 4327159039aSYOSHIFUJI Hideaki 4331da177e4SLinus Torvalds int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) 4341da177e4SLinus Torvalds { 4351da177e4SLinus Torvalds struct sock *sk = sock->sk; 4363b1e0a65SYOSHIFUJI Hideaki struct net *net = sock_net(sk); 4371da177e4SLinus Torvalds 4381da177e4SLinus Torvalds switch(cmd) 4391da177e4SLinus Torvalds { 4401da177e4SLinus Torvalds case SIOCGSTAMP: 4411da177e4SLinus Torvalds return sock_get_timestamp(sk, (struct timeval __user *)arg); 4421da177e4SLinus Torvalds 443ae40eb1eSEric Dumazet case SIOCGSTAMPNS: 444ae40eb1eSEric Dumazet return sock_get_timestampns(sk, (struct timespec __user *)arg); 445ae40eb1eSEric Dumazet 4461da177e4SLinus Torvalds case SIOCADDRT: 4471da177e4SLinus Torvalds case SIOCDELRT: 4481da177e4SLinus Torvalds 4495578689aSDaniel Lezcano return(ipv6_route_ioctl(net, cmd, (void __user *)arg)); 4501da177e4SLinus Torvalds 4511da177e4SLinus Torvalds case SIOCSIFADDR: 452af284937SDaniel Lezcano return addrconf_add_ifaddr(net, (void __user *) arg); 4531da177e4SLinus Torvalds case SIOCDIFADDR: 454af284937SDaniel Lezcano return addrconf_del_ifaddr(net, (void __user *) arg); 4551da177e4SLinus Torvalds case SIOCSIFDSTADDR: 456af284937SDaniel Lezcano return addrconf_set_dstaddr(net, (void __user *) arg); 4571da177e4SLinus Torvalds default: 458b5e5fa5eSChristoph Hellwig if (!sk->sk_prot->ioctl) 459b5e5fa5eSChristoph Hellwig return -ENOIOCTLCMD; 460b5e5fa5eSChristoph Hellwig return sk->sk_prot->ioctl(sk, cmd, arg); 4611da177e4SLinus Torvalds } 4621da177e4SLinus Torvalds /*NOTREACHED*/ 4631da177e4SLinus Torvalds return(0); 4641da177e4SLinus Torvalds } 4651da177e4SLinus Torvalds 4667159039aSYOSHIFUJI Hideaki EXPORT_SYMBOL(inet6_ioctl); 4677159039aSYOSHIFUJI Hideaki 46890ddc4f0SEric Dumazet const struct proto_ops inet6_stream_ops = { 4691da177e4SLinus Torvalds .family = PF_INET6, 4701da177e4SLinus Torvalds .owner = THIS_MODULE, 4711da177e4SLinus Torvalds .release = inet6_release, 4721da177e4SLinus Torvalds .bind = inet6_bind, 4731da177e4SLinus Torvalds .connect = inet_stream_connect, /* ok */ 4741da177e4SLinus Torvalds .socketpair = sock_no_socketpair, /* a do nothing */ 4751da177e4SLinus Torvalds .accept = inet_accept, /* ok */ 4761da177e4SLinus Torvalds .getname = inet6_getname, 4771da177e4SLinus Torvalds .poll = tcp_poll, /* ok */ 4781da177e4SLinus Torvalds .ioctl = inet6_ioctl, /* must change */ 4791da177e4SLinus Torvalds .listen = inet_listen, /* ok */ 4801da177e4SLinus Torvalds .shutdown = inet_shutdown, /* ok */ 4811da177e4SLinus Torvalds .setsockopt = sock_common_setsockopt, /* ok */ 4821da177e4SLinus Torvalds .getsockopt = sock_common_getsockopt, /* ok */ 4833516ffb0SDavid S. Miller .sendmsg = tcp_sendmsg, /* ok */ 484543d9cfeSArnaldo Carvalho de Melo .recvmsg = sock_common_recvmsg, /* ok */ 485543d9cfeSArnaldo Carvalho de Melo .mmap = sock_no_mmap, 486543d9cfeSArnaldo Carvalho de Melo .sendpage = tcp_sendpage, 487a0974dd3SJens Axboe .splice_read = tcp_splice_read, 4883fdadf7dSDmitry Mishin #ifdef CONFIG_COMPAT 4893fdadf7dSDmitry Mishin .compat_setsockopt = compat_sock_common_setsockopt, 4903fdadf7dSDmitry Mishin .compat_getsockopt = compat_sock_common_getsockopt, 4913fdadf7dSDmitry Mishin #endif 4921da177e4SLinus Torvalds }; 4931da177e4SLinus Torvalds 49490ddc4f0SEric Dumazet const struct proto_ops inet6_dgram_ops = { 4951da177e4SLinus Torvalds .family = PF_INET6, 4961da177e4SLinus Torvalds .owner = THIS_MODULE, 4971da177e4SLinus Torvalds .release = inet6_release, 4981da177e4SLinus Torvalds .bind = inet6_bind, 4991da177e4SLinus Torvalds .connect = inet_dgram_connect, /* ok */ 5001da177e4SLinus Torvalds .socketpair = sock_no_socketpair, /* a do nothing */ 5011da177e4SLinus Torvalds .accept = sock_no_accept, /* a do nothing */ 5021da177e4SLinus Torvalds .getname = inet6_getname, 5031da177e4SLinus Torvalds .poll = udp_poll, /* ok */ 5041da177e4SLinus Torvalds .ioctl = inet6_ioctl, /* must change */ 5051da177e4SLinus Torvalds .listen = sock_no_listen, /* ok */ 5061da177e4SLinus Torvalds .shutdown = inet_shutdown, /* ok */ 5071da177e4SLinus Torvalds .setsockopt = sock_common_setsockopt, /* ok */ 5081da177e4SLinus Torvalds .getsockopt = sock_common_getsockopt, /* ok */ 5091da177e4SLinus Torvalds .sendmsg = inet_sendmsg, /* ok */ 5101da177e4SLinus Torvalds .recvmsg = sock_common_recvmsg, /* ok */ 5111da177e4SLinus Torvalds .mmap = sock_no_mmap, 5121da177e4SLinus Torvalds .sendpage = sock_no_sendpage, 513543d9cfeSArnaldo Carvalho de Melo #ifdef CONFIG_COMPAT 514543d9cfeSArnaldo Carvalho de Melo .compat_setsockopt = compat_sock_common_setsockopt, 515543d9cfeSArnaldo Carvalho de Melo .compat_getsockopt = compat_sock_common_getsockopt, 516543d9cfeSArnaldo Carvalho de Melo #endif 5171da177e4SLinus Torvalds }; 5181da177e4SLinus Torvalds 5191da177e4SLinus Torvalds static struct net_proto_family inet6_family_ops = { 5201da177e4SLinus Torvalds .family = PF_INET6, 5211da177e4SLinus Torvalds .create = inet6_create, 5221da177e4SLinus Torvalds .owner = THIS_MODULE, 5231da177e4SLinus Torvalds }; 5241da177e4SLinus Torvalds 52587c3efbfSDaniel Lezcano int inet6_register_protosw(struct inet_protosw *p) 5261da177e4SLinus Torvalds { 5271da177e4SLinus Torvalds struct list_head *lh; 5281da177e4SLinus Torvalds struct inet_protosw *answer; 5291da177e4SLinus Torvalds struct list_head *last_perm; 53087c3efbfSDaniel Lezcano int protocol = p->protocol; 53187c3efbfSDaniel Lezcano int ret; 5321da177e4SLinus Torvalds 5331da177e4SLinus Torvalds spin_lock_bh(&inetsw6_lock); 5341da177e4SLinus Torvalds 53587c3efbfSDaniel Lezcano ret = -EINVAL; 5361da177e4SLinus Torvalds if (p->type >= SOCK_MAX) 5371da177e4SLinus Torvalds goto out_illegal; 5381da177e4SLinus Torvalds 5391da177e4SLinus Torvalds /* If we are trying to override a permanent protocol, bail. */ 5401da177e4SLinus Torvalds answer = NULL; 54187c3efbfSDaniel Lezcano ret = -EPERM; 5421da177e4SLinus Torvalds last_perm = &inetsw6[p->type]; 5431da177e4SLinus Torvalds list_for_each(lh, &inetsw6[p->type]) { 5441da177e4SLinus Torvalds answer = list_entry(lh, struct inet_protosw, list); 5451da177e4SLinus Torvalds 5461da177e4SLinus Torvalds /* Check only the non-wild match. */ 5471da177e4SLinus Torvalds if (INET_PROTOSW_PERMANENT & answer->flags) { 5481da177e4SLinus Torvalds if (protocol == answer->protocol) 5491da177e4SLinus Torvalds break; 5501da177e4SLinus Torvalds last_perm = lh; 5511da177e4SLinus Torvalds } 5521da177e4SLinus Torvalds 5531da177e4SLinus Torvalds answer = NULL; 5541da177e4SLinus Torvalds } 5551da177e4SLinus Torvalds if (answer) 5561da177e4SLinus Torvalds goto out_permanent; 5571da177e4SLinus Torvalds 5581da177e4SLinus Torvalds /* Add the new entry after the last permanent entry if any, so that 5591da177e4SLinus Torvalds * the new entry does not override a permanent entry when matched with 5601da177e4SLinus Torvalds * a wild-card protocol. But it is allowed to override any existing 5611da177e4SLinus Torvalds * non-permanent entry. This means that when we remove this entry, the 5621da177e4SLinus Torvalds * system automatically returns to the old behavior. 5631da177e4SLinus Torvalds */ 5641da177e4SLinus Torvalds list_add_rcu(&p->list, last_perm); 56587c3efbfSDaniel Lezcano ret = 0; 5661da177e4SLinus Torvalds out: 5671da177e4SLinus Torvalds spin_unlock_bh(&inetsw6_lock); 56887c3efbfSDaniel Lezcano return ret; 5691da177e4SLinus Torvalds 5701da177e4SLinus Torvalds out_permanent: 5711da177e4SLinus Torvalds printk(KERN_ERR "Attempt to override permanent protocol %d.\n", 5721da177e4SLinus Torvalds protocol); 5731da177e4SLinus Torvalds goto out; 5741da177e4SLinus Torvalds 5751da177e4SLinus Torvalds out_illegal: 5761da177e4SLinus Torvalds printk(KERN_ERR 5771da177e4SLinus Torvalds "Ignoring attempt to register invalid socket type %d.\n", 5781da177e4SLinus Torvalds p->type); 5791da177e4SLinus Torvalds goto out; 5801da177e4SLinus Torvalds } 5811da177e4SLinus Torvalds 5827159039aSYOSHIFUJI Hideaki EXPORT_SYMBOL(inet6_register_protosw); 5837159039aSYOSHIFUJI Hideaki 5841da177e4SLinus Torvalds void 5851da177e4SLinus Torvalds inet6_unregister_protosw(struct inet_protosw *p) 5861da177e4SLinus Torvalds { 5871da177e4SLinus Torvalds if (INET_PROTOSW_PERMANENT & p->flags) { 5881da177e4SLinus Torvalds printk(KERN_ERR 5891da177e4SLinus Torvalds "Attempt to unregister permanent protocol %d.\n", 5901da177e4SLinus Torvalds p->protocol); 5911da177e4SLinus Torvalds } else { 5921da177e4SLinus Torvalds spin_lock_bh(&inetsw6_lock); 5931da177e4SLinus Torvalds list_del_rcu(&p->list); 5941da177e4SLinus Torvalds spin_unlock_bh(&inetsw6_lock); 5951da177e4SLinus Torvalds 5961da177e4SLinus Torvalds synchronize_net(); 5971da177e4SLinus Torvalds } 5981da177e4SLinus Torvalds } 5991da177e4SLinus Torvalds 6007159039aSYOSHIFUJI Hideaki EXPORT_SYMBOL(inet6_unregister_protosw); 6017159039aSYOSHIFUJI Hideaki 602b9750ce1SArnaldo Carvalho de Melo int inet6_sk_rebuild_header(struct sock *sk) 603b9750ce1SArnaldo Carvalho de Melo { 604b9750ce1SArnaldo Carvalho de Melo int err; 605b9750ce1SArnaldo Carvalho de Melo struct dst_entry *dst; 606b9750ce1SArnaldo Carvalho de Melo struct ipv6_pinfo *np = inet6_sk(sk); 607b9750ce1SArnaldo Carvalho de Melo 608b9750ce1SArnaldo Carvalho de Melo dst = __sk_dst_check(sk, np->dst_cookie); 609b9750ce1SArnaldo Carvalho de Melo 610b9750ce1SArnaldo Carvalho de Melo if (dst == NULL) { 611b9750ce1SArnaldo Carvalho de Melo struct inet_sock *inet = inet_sk(sk); 612b9750ce1SArnaldo Carvalho de Melo struct in6_addr *final_p = NULL, final; 613b9750ce1SArnaldo Carvalho de Melo struct flowi fl; 614b9750ce1SArnaldo Carvalho de Melo 615b9750ce1SArnaldo Carvalho de Melo memset(&fl, 0, sizeof(fl)); 616b9750ce1SArnaldo Carvalho de Melo fl.proto = sk->sk_protocol; 617b9750ce1SArnaldo Carvalho de Melo ipv6_addr_copy(&fl.fl6_dst, &np->daddr); 618b9750ce1SArnaldo Carvalho de Melo ipv6_addr_copy(&fl.fl6_src, &np->saddr); 619b9750ce1SArnaldo Carvalho de Melo fl.fl6_flowlabel = np->flow_label; 620b9750ce1SArnaldo Carvalho de Melo fl.oif = sk->sk_bound_dev_if; 621b9750ce1SArnaldo Carvalho de Melo fl.fl_ip_dport = inet->dport; 622b9750ce1SArnaldo Carvalho de Melo fl.fl_ip_sport = inet->sport; 623beb8d13bSVenkat Yekkirala security_sk_classify_flow(sk, &fl); 624b9750ce1SArnaldo Carvalho de Melo 625b9750ce1SArnaldo Carvalho de Melo if (np->opt && np->opt->srcrt) { 626b9750ce1SArnaldo Carvalho de Melo struct rt0_hdr *rt0 = (struct rt0_hdr *) np->opt->srcrt; 627b9750ce1SArnaldo Carvalho de Melo ipv6_addr_copy(&final, &fl.fl6_dst); 628b9750ce1SArnaldo Carvalho de Melo ipv6_addr_copy(&fl.fl6_dst, rt0->addr); 629b9750ce1SArnaldo Carvalho de Melo final_p = &final; 630b9750ce1SArnaldo Carvalho de Melo } 631b9750ce1SArnaldo Carvalho de Melo 632b9750ce1SArnaldo Carvalho de Melo err = ip6_dst_lookup(sk, &dst, &fl); 633b9750ce1SArnaldo Carvalho de Melo if (err) { 634b9750ce1SArnaldo Carvalho de Melo sk->sk_route_caps = 0; 635b9750ce1SArnaldo Carvalho de Melo return err; 636b9750ce1SArnaldo Carvalho de Melo } 637b9750ce1SArnaldo Carvalho de Melo if (final_p) 638b9750ce1SArnaldo Carvalho de Melo ipv6_addr_copy(&fl.fl6_dst, final_p); 639b9750ce1SArnaldo Carvalho de Melo 640b9750ce1SArnaldo Carvalho de Melo if ((err = xfrm_lookup(&dst, &fl, sk, 0)) < 0) { 641b9750ce1SArnaldo Carvalho de Melo sk->sk_err_soft = -err; 642b9750ce1SArnaldo Carvalho de Melo return err; 643b9750ce1SArnaldo Carvalho de Melo } 644b9750ce1SArnaldo Carvalho de Melo 6458e1ef0a9SYOSHIFUJI Hideaki __ip6_dst_store(sk, dst, NULL, NULL); 646b9750ce1SArnaldo Carvalho de Melo } 647b9750ce1SArnaldo Carvalho de Melo 648b9750ce1SArnaldo Carvalho de Melo return 0; 649b9750ce1SArnaldo Carvalho de Melo } 650b9750ce1SArnaldo Carvalho de Melo 651b9750ce1SArnaldo Carvalho de Melo EXPORT_SYMBOL_GPL(inet6_sk_rebuild_header); 652b9750ce1SArnaldo Carvalho de Melo 653399c07deSArnaldo Carvalho de Melo int ipv6_opt_accepted(struct sock *sk, struct sk_buff *skb) 654399c07deSArnaldo Carvalho de Melo { 655399c07deSArnaldo Carvalho de Melo struct ipv6_pinfo *np = inet6_sk(sk); 656399c07deSArnaldo Carvalho de Melo struct inet6_skb_parm *opt = IP6CB(skb); 657399c07deSArnaldo Carvalho de Melo 658399c07deSArnaldo Carvalho de Melo if (np->rxopt.all) { 659399c07deSArnaldo Carvalho de Melo if ((opt->hop && (np->rxopt.bits.hopopts || 660399c07deSArnaldo Carvalho de Melo np->rxopt.bits.ohopopts)) || 661d56f90a7SArnaldo Carvalho de Melo ((IPV6_FLOWINFO_MASK & 662d56f90a7SArnaldo Carvalho de Melo *(__be32 *)skb_network_header(skb)) && 663399c07deSArnaldo Carvalho de Melo np->rxopt.bits.rxflow) || 664399c07deSArnaldo Carvalho de Melo (opt->srcrt && (np->rxopt.bits.srcrt || 665399c07deSArnaldo Carvalho de Melo np->rxopt.bits.osrcrt)) || 666399c07deSArnaldo Carvalho de Melo ((opt->dst1 || opt->dst0) && 667399c07deSArnaldo Carvalho de Melo (np->rxopt.bits.dstopts || np->rxopt.bits.odstopts))) 668399c07deSArnaldo Carvalho de Melo return 1; 669399c07deSArnaldo Carvalho de Melo } 670399c07deSArnaldo Carvalho de Melo return 0; 671399c07deSArnaldo Carvalho de Melo } 672399c07deSArnaldo Carvalho de Melo 673399c07deSArnaldo Carvalho de Melo EXPORT_SYMBOL_GPL(ipv6_opt_accepted); 674399c07deSArnaldo Carvalho de Melo 675662397fdSYOSHIFUJI Hideaki static struct inet6_protocol *ipv6_gso_pull_exthdrs(struct sk_buff *skb, 676662397fdSYOSHIFUJI Hideaki int proto) 677662397fdSYOSHIFUJI Hideaki { 678662397fdSYOSHIFUJI Hideaki struct inet6_protocol *ops = NULL; 679662397fdSYOSHIFUJI Hideaki 680662397fdSYOSHIFUJI Hideaki for (;;) { 681662397fdSYOSHIFUJI Hideaki struct ipv6_opt_hdr *opth; 682662397fdSYOSHIFUJI Hideaki int len; 683662397fdSYOSHIFUJI Hideaki 684662397fdSYOSHIFUJI Hideaki if (proto != NEXTHDR_HOP) { 685662397fdSYOSHIFUJI Hideaki ops = rcu_dereference(inet6_protos[proto]); 686662397fdSYOSHIFUJI Hideaki 687662397fdSYOSHIFUJI Hideaki if (unlikely(!ops)) 688662397fdSYOSHIFUJI Hideaki break; 689662397fdSYOSHIFUJI Hideaki 690662397fdSYOSHIFUJI Hideaki if (!(ops->flags & INET6_PROTO_GSO_EXTHDR)) 691662397fdSYOSHIFUJI Hideaki break; 692662397fdSYOSHIFUJI Hideaki } 693662397fdSYOSHIFUJI Hideaki 694662397fdSYOSHIFUJI Hideaki if (unlikely(!pskb_may_pull(skb, 8))) 695662397fdSYOSHIFUJI Hideaki break; 696662397fdSYOSHIFUJI Hideaki 697662397fdSYOSHIFUJI Hideaki opth = (void *)skb->data; 698662397fdSYOSHIFUJI Hideaki len = ipv6_optlen(opth); 699662397fdSYOSHIFUJI Hideaki 700662397fdSYOSHIFUJI Hideaki if (unlikely(!pskb_may_pull(skb, len))) 701662397fdSYOSHIFUJI Hideaki break; 702662397fdSYOSHIFUJI Hideaki 703662397fdSYOSHIFUJI Hideaki proto = opth->nexthdr; 704662397fdSYOSHIFUJI Hideaki __skb_pull(skb, len); 705662397fdSYOSHIFUJI Hideaki } 706662397fdSYOSHIFUJI Hideaki 707662397fdSYOSHIFUJI Hideaki return ops; 708662397fdSYOSHIFUJI Hideaki } 709662397fdSYOSHIFUJI Hideaki 710662397fdSYOSHIFUJI Hideaki static int ipv6_gso_send_check(struct sk_buff *skb) 711662397fdSYOSHIFUJI Hideaki { 712662397fdSYOSHIFUJI Hideaki struct ipv6hdr *ipv6h; 713662397fdSYOSHIFUJI Hideaki struct inet6_protocol *ops; 714662397fdSYOSHIFUJI Hideaki int err = -EINVAL; 715662397fdSYOSHIFUJI Hideaki 716662397fdSYOSHIFUJI Hideaki if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h)))) 717662397fdSYOSHIFUJI Hideaki goto out; 718662397fdSYOSHIFUJI Hideaki 719662397fdSYOSHIFUJI Hideaki ipv6h = ipv6_hdr(skb); 720662397fdSYOSHIFUJI Hideaki __skb_pull(skb, sizeof(*ipv6h)); 721662397fdSYOSHIFUJI Hideaki err = -EPROTONOSUPPORT; 722662397fdSYOSHIFUJI Hideaki 723662397fdSYOSHIFUJI Hideaki rcu_read_lock(); 724662397fdSYOSHIFUJI Hideaki ops = ipv6_gso_pull_exthdrs(skb, ipv6h->nexthdr); 725662397fdSYOSHIFUJI Hideaki if (likely(ops && ops->gso_send_check)) { 726662397fdSYOSHIFUJI Hideaki skb_reset_transport_header(skb); 727662397fdSYOSHIFUJI Hideaki err = ops->gso_send_check(skb); 728662397fdSYOSHIFUJI Hideaki } 729662397fdSYOSHIFUJI Hideaki rcu_read_unlock(); 730662397fdSYOSHIFUJI Hideaki 731662397fdSYOSHIFUJI Hideaki out: 732662397fdSYOSHIFUJI Hideaki return err; 733662397fdSYOSHIFUJI Hideaki } 734662397fdSYOSHIFUJI Hideaki 735662397fdSYOSHIFUJI Hideaki static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb, int features) 736662397fdSYOSHIFUJI Hideaki { 737662397fdSYOSHIFUJI Hideaki struct sk_buff *segs = ERR_PTR(-EINVAL); 738662397fdSYOSHIFUJI Hideaki struct ipv6hdr *ipv6h; 739662397fdSYOSHIFUJI Hideaki struct inet6_protocol *ops; 740662397fdSYOSHIFUJI Hideaki 741662397fdSYOSHIFUJI Hideaki if (!(features & NETIF_F_V6_CSUM)) 742662397fdSYOSHIFUJI Hideaki features &= ~NETIF_F_SG; 743662397fdSYOSHIFUJI Hideaki 744662397fdSYOSHIFUJI Hideaki if (unlikely(skb_shinfo(skb)->gso_type & 745662397fdSYOSHIFUJI Hideaki ~(SKB_GSO_UDP | 746662397fdSYOSHIFUJI Hideaki SKB_GSO_DODGY | 747662397fdSYOSHIFUJI Hideaki SKB_GSO_TCP_ECN | 748662397fdSYOSHIFUJI Hideaki SKB_GSO_TCPV6 | 749662397fdSYOSHIFUJI Hideaki 0))) 750662397fdSYOSHIFUJI Hideaki goto out; 751662397fdSYOSHIFUJI Hideaki 752662397fdSYOSHIFUJI Hideaki if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h)))) 753662397fdSYOSHIFUJI Hideaki goto out; 754662397fdSYOSHIFUJI Hideaki 755662397fdSYOSHIFUJI Hideaki ipv6h = ipv6_hdr(skb); 756662397fdSYOSHIFUJI Hideaki __skb_pull(skb, sizeof(*ipv6h)); 757662397fdSYOSHIFUJI Hideaki segs = ERR_PTR(-EPROTONOSUPPORT); 758662397fdSYOSHIFUJI Hideaki 759662397fdSYOSHIFUJI Hideaki rcu_read_lock(); 760662397fdSYOSHIFUJI Hideaki ops = ipv6_gso_pull_exthdrs(skb, ipv6h->nexthdr); 761662397fdSYOSHIFUJI Hideaki if (likely(ops && ops->gso_segment)) { 762662397fdSYOSHIFUJI Hideaki skb_reset_transport_header(skb); 763662397fdSYOSHIFUJI Hideaki segs = ops->gso_segment(skb, features); 764662397fdSYOSHIFUJI Hideaki } 765662397fdSYOSHIFUJI Hideaki rcu_read_unlock(); 766662397fdSYOSHIFUJI Hideaki 767662397fdSYOSHIFUJI Hideaki if (unlikely(IS_ERR(segs))) 768662397fdSYOSHIFUJI Hideaki goto out; 769662397fdSYOSHIFUJI Hideaki 770662397fdSYOSHIFUJI Hideaki for (skb = segs; skb; skb = skb->next) { 771662397fdSYOSHIFUJI Hideaki ipv6h = ipv6_hdr(skb); 772662397fdSYOSHIFUJI Hideaki ipv6h->payload_len = htons(skb->len - skb->mac_len - 773662397fdSYOSHIFUJI Hideaki sizeof(*ipv6h)); 774662397fdSYOSHIFUJI Hideaki } 775662397fdSYOSHIFUJI Hideaki 776662397fdSYOSHIFUJI Hideaki out: 777662397fdSYOSHIFUJI Hideaki return segs; 778662397fdSYOSHIFUJI Hideaki } 779662397fdSYOSHIFUJI Hideaki 780662397fdSYOSHIFUJI Hideaki static struct packet_type ipv6_packet_type = { 781662397fdSYOSHIFUJI Hideaki .type = __constant_htons(ETH_P_IPV6), 782662397fdSYOSHIFUJI Hideaki .func = ipv6_rcv, 783662397fdSYOSHIFUJI Hideaki .gso_send_check = ipv6_gso_send_check, 784662397fdSYOSHIFUJI Hideaki .gso_segment = ipv6_gso_segment, 785662397fdSYOSHIFUJI Hideaki }; 786662397fdSYOSHIFUJI Hideaki 787662397fdSYOSHIFUJI Hideaki static int __init ipv6_packet_init(void) 788662397fdSYOSHIFUJI Hideaki { 789662397fdSYOSHIFUJI Hideaki dev_add_pack(&ipv6_packet_type); 790662397fdSYOSHIFUJI Hideaki return 0; 791662397fdSYOSHIFUJI Hideaki } 792662397fdSYOSHIFUJI Hideaki 793662397fdSYOSHIFUJI Hideaki static void ipv6_packet_cleanup(void) 794662397fdSYOSHIFUJI Hideaki { 795662397fdSYOSHIFUJI Hideaki dev_remove_pack(&ipv6_packet_type); 796662397fdSYOSHIFUJI Hideaki } 797662397fdSYOSHIFUJI Hideaki 7981da177e4SLinus Torvalds static int __init init_ipv6_mibs(void) 7991da177e4SLinus Torvalds { 8001da177e4SLinus Torvalds return 0; 8011da177e4SLinus Torvalds } 8021da177e4SLinus Torvalds 8031da177e4SLinus Torvalds static void cleanup_ipv6_mibs(void) 8041da177e4SLinus Torvalds { 8051da177e4SLinus Torvalds } 8061da177e4SLinus Torvalds 807e43291cbSDenis V. Lunev static int __net_init ipv6_init_mibs(struct net *net) 808e43291cbSDenis V. Lunev { 8090c7ed677SDenis V. Lunev if (snmp_mib_init((void **)net->mib.udp_stats_in6, 8100c7ed677SDenis V. Lunev sizeof (struct udp_mib)) < 0) 8110c7ed677SDenis V. Lunev return -ENOMEM; 812be713a44SDenis V. Lunev if (snmp_mib_init((void **)net->mib.udplite_stats_in6, 813be713a44SDenis V. Lunev sizeof (struct udp_mib)) < 0) 814be713a44SDenis V. Lunev goto err_udplite_mib; 8159261e537SDenis V. Lunev if (snmp_mib_init((void **)net->mib.ipv6_statistics, 8169261e537SDenis V. Lunev sizeof(struct ipstats_mib)) < 0) 8179261e537SDenis V. Lunev goto err_ip_mib; 8189261e537SDenis V. Lunev if (snmp_mib_init((void **)net->mib.icmpv6_statistics, 8199261e537SDenis V. Lunev sizeof(struct icmpv6_mib)) < 0) 8209261e537SDenis V. Lunev goto err_icmp_mib; 8219261e537SDenis V. Lunev if (snmp_mib_init((void **)net->mib.icmpv6msg_statistics, 8229261e537SDenis V. Lunev sizeof(struct icmpv6msg_mib)) < 0) 8239261e537SDenis V. Lunev goto err_icmpmsg_mib; 824e43291cbSDenis V. Lunev return 0; 825be713a44SDenis V. Lunev 8269261e537SDenis V. Lunev err_icmpmsg_mib: 8279261e537SDenis V. Lunev snmp_mib_free((void **)net->mib.icmpv6_statistics); 8289261e537SDenis V. Lunev err_icmp_mib: 8299261e537SDenis V. Lunev snmp_mib_free((void **)net->mib.ipv6_statistics); 8309261e537SDenis V. Lunev err_ip_mib: 8319261e537SDenis V. Lunev snmp_mib_free((void **)net->mib.udplite_stats_in6); 832be713a44SDenis V. Lunev err_udplite_mib: 833be713a44SDenis V. Lunev snmp_mib_free((void **)net->mib.udp_stats_in6); 834be713a44SDenis V. Lunev return -ENOMEM; 835e43291cbSDenis V. Lunev } 836e43291cbSDenis V. Lunev 837e43291cbSDenis V. Lunev static void __net_exit ipv6_cleanup_mibs(struct net *net) 838e43291cbSDenis V. Lunev { 8390c7ed677SDenis V. Lunev snmp_mib_free((void **)net->mib.udp_stats_in6); 840be713a44SDenis V. Lunev snmp_mib_free((void **)net->mib.udplite_stats_in6); 8419261e537SDenis V. Lunev snmp_mib_free((void **)net->mib.ipv6_statistics); 8429261e537SDenis V. Lunev snmp_mib_free((void **)net->mib.icmpv6_statistics); 8439261e537SDenis V. Lunev snmp_mib_free((void **)net->mib.icmpv6msg_statistics); 844e43291cbSDenis V. Lunev } 845e43291cbSDenis V. Lunev 84681c1c178SDaniel Lezcano static int inet6_net_init(struct net *net) 84781c1c178SDaniel Lezcano { 8480c96d8c5SDaniel Lezcano int err = 0; 8490c96d8c5SDaniel Lezcano 85099bc9c4eSDaniel Lezcano net->ipv6.sysctl.bindv6only = 0; 85141a76906SDaniel Lezcano net->ipv6.sysctl.icmpv6_time = 1*HZ; 852e71e0349SDaniel Lezcano 853e43291cbSDenis V. Lunev err = ipv6_init_mibs(net); 854e43291cbSDenis V. Lunev if (err) 855e43291cbSDenis V. Lunev return err; 8560c96d8c5SDaniel Lezcano #ifdef CONFIG_PROC_FS 8570c96d8c5SDaniel Lezcano err = udp6_proc_init(net); 8580c96d8c5SDaniel Lezcano if (err) 8590c96d8c5SDaniel Lezcano goto out; 8606f8b13bcSDaniel Lezcano err = tcp6_proc_init(net); 8616f8b13bcSDaniel Lezcano if (err) 8626f8b13bcSDaniel Lezcano goto proc_tcp6_fail; 8636ab57e7eSDaniel Lezcano err = ac6_proc_init(net); 8646ab57e7eSDaniel Lezcano if (err) 8656ab57e7eSDaniel Lezcano goto proc_ac6_fail; 8660c96d8c5SDaniel Lezcano #endif 8670c96d8c5SDaniel Lezcano return err; 8686f8b13bcSDaniel Lezcano 8696f8b13bcSDaniel Lezcano #ifdef CONFIG_PROC_FS 8706ab57e7eSDaniel Lezcano proc_ac6_fail: 8716ab57e7eSDaniel Lezcano tcp6_proc_exit(net); 8726f8b13bcSDaniel Lezcano proc_tcp6_fail: 8736f8b13bcSDaniel Lezcano udp6_proc_exit(net); 874e43291cbSDenis V. Lunev out: 875e43291cbSDenis V. Lunev ipv6_cleanup_mibs(net); 876e43291cbSDenis V. Lunev return err; 8776f8b13bcSDaniel Lezcano #endif 87881c1c178SDaniel Lezcano } 87981c1c178SDaniel Lezcano 88081c1c178SDaniel Lezcano static void inet6_net_exit(struct net *net) 88181c1c178SDaniel Lezcano { 8820c96d8c5SDaniel Lezcano #ifdef CONFIG_PROC_FS 8830c96d8c5SDaniel Lezcano udp6_proc_exit(net); 8846f8b13bcSDaniel Lezcano tcp6_proc_exit(net); 8856ab57e7eSDaniel Lezcano ac6_proc_exit(net); 8860c96d8c5SDaniel Lezcano #endif 887e43291cbSDenis V. Lunev ipv6_cleanup_mibs(net); 88881c1c178SDaniel Lezcano } 88981c1c178SDaniel Lezcano 89081c1c178SDaniel Lezcano static struct pernet_operations inet6_net_ops = { 89181c1c178SDaniel Lezcano .init = inet6_net_init, 89281c1c178SDaniel Lezcano .exit = inet6_net_exit, 89381c1c178SDaniel Lezcano }; 89481c1c178SDaniel Lezcano 8951da177e4SLinus Torvalds static int __init inet6_init(void) 8961da177e4SLinus Torvalds { 8971da177e4SLinus Torvalds struct sk_buff *dummy_skb; 8981da177e4SLinus Torvalds struct list_head *r; 8991da177e4SLinus Torvalds int err; 9001da177e4SLinus Torvalds 901ef047f5eSYOSHIFUJI Hideaki BUILD_BUG_ON(sizeof(struct inet6_skb_parm) > sizeof(dummy_skb->cb)); 902ef047f5eSYOSHIFUJI Hideaki 9031da177e4SLinus Torvalds err = proto_register(&tcpv6_prot, 1); 9041da177e4SLinus Torvalds if (err) 9051da177e4SLinus Torvalds goto out; 9061da177e4SLinus Torvalds 9071da177e4SLinus Torvalds err = proto_register(&udpv6_prot, 1); 9081da177e4SLinus Torvalds if (err) 9091da177e4SLinus Torvalds goto out_unregister_tcp_proto; 9101da177e4SLinus Torvalds 911ba4e58ecSGerrit Renker err = proto_register(&udplitev6_prot, 1); 9121da177e4SLinus Torvalds if (err) 9131da177e4SLinus Torvalds goto out_unregister_udp_proto; 9141da177e4SLinus Torvalds 915ba4e58ecSGerrit Renker err = proto_register(&rawv6_prot, 1); 916ba4e58ecSGerrit Renker if (err) 917ba4e58ecSGerrit Renker goto out_unregister_udplite_proto; 918ba4e58ecSGerrit Renker 9191da177e4SLinus Torvalds 9201da177e4SLinus Torvalds /* Register the socket-side information for inet6_create. */ 9211da177e4SLinus Torvalds for(r = &inetsw6[0]; r < &inetsw6[SOCK_MAX]; ++r) 9221da177e4SLinus Torvalds INIT_LIST_HEAD(r); 9231da177e4SLinus Torvalds 9241da177e4SLinus Torvalds /* We MUST register RAW sockets before we create the ICMP6, 9251da177e4SLinus Torvalds * IGMP6, or NDISC control sockets. 9261da177e4SLinus Torvalds */ 9277f4e4868SDaniel Lezcano err = rawv6_init(); 9287f4e4868SDaniel Lezcano if (err) 9297f4e4868SDaniel Lezcano goto out_unregister_raw_proto; 9301da177e4SLinus Torvalds 9311da177e4SLinus Torvalds /* Register the family here so that the init calls below will 9321da177e4SLinus Torvalds * be able to create sockets. (?? is this dangerous ??) 9331da177e4SLinus Torvalds */ 9348eb55910SDavid S. Miller err = sock_register(&inet6_family_ops); 9358eb55910SDavid S. Miller if (err) 9367f4e4868SDaniel Lezcano goto out_sock_register_fail; 9371da177e4SLinus Torvalds 9381da177e4SLinus Torvalds /* Initialise ipv6 mibs */ 9391da177e4SLinus Torvalds err = init_ipv6_mibs(); 9401da177e4SLinus Torvalds if (err) 9418eb55910SDavid S. Miller goto out_unregister_sock; 9421da177e4SLinus Torvalds 943eeb61f71SAl Viro #ifdef CONFIG_SYSCTL 944eeb61f71SAl Viro err = ipv6_static_sysctl_register(); 945eeb61f71SAl Viro if (err) 946eeb61f71SAl Viro goto static_sysctl_fail; 947eeb61f71SAl Viro #endif 9481da177e4SLinus Torvalds /* 9491da177e4SLinus Torvalds * ipngwg API draft makes clear that the correct semantics 9501da177e4SLinus Torvalds * for TCP and UDP is to consider one TCP and UDP instance 9511da177e4SLinus Torvalds * in a host availiable by both INET and INET6 APIs and 9521da177e4SLinus Torvalds * able to communicate via both network protocols. 9531da177e4SLinus Torvalds */ 9541da177e4SLinus Torvalds 95581c1c178SDaniel Lezcano err = register_pernet_subsys(&inet6_net_ops); 95681c1c178SDaniel Lezcano if (err) 95781c1c178SDaniel Lezcano goto register_pernet_fail; 9589b0f976fSDenis V. Lunev err = icmpv6_init(); 9591da177e4SLinus Torvalds if (err) 9601da177e4SLinus Torvalds goto icmp_fail; 961623d1a1aSWang Chen err = ip6_mr_init(); 962623d1a1aSWang Chen if (err) 963623d1a1aSWang Chen goto ipmr_fail; 9649b0f976fSDenis V. Lunev err = ndisc_init(); 9651da177e4SLinus Torvalds if (err) 9661da177e4SLinus Torvalds goto ndisc_fail; 9679b0f976fSDenis V. Lunev err = igmp6_init(); 9681da177e4SLinus Torvalds if (err) 9691da177e4SLinus Torvalds goto igmp_fail; 9702cc7d573SHarald Welte err = ipv6_netfilter_init(); 9712cc7d573SHarald Welte if (err) 9722cc7d573SHarald Welte goto netfilter_fail; 9731da177e4SLinus Torvalds /* Create /proc/foo6 entries. */ 9741da177e4SLinus Torvalds #ifdef CONFIG_PROC_FS 9751da177e4SLinus Torvalds err = -ENOMEM; 9761da177e4SLinus Torvalds if (raw6_proc_init()) 9771da177e4SLinus Torvalds goto proc_raw6_fail; 978ba4e58ecSGerrit Renker if (udplite6_proc_init()) 979ba4e58ecSGerrit Renker goto proc_udplite6_fail; 9801da177e4SLinus Torvalds if (ipv6_misc_proc_init()) 9811da177e4SLinus Torvalds goto proc_misc6_fail; 9821da177e4SLinus Torvalds if (if6_proc_init()) 9831da177e4SLinus Torvalds goto proc_if6_fail; 9841da177e4SLinus Torvalds #endif 985e2fddf5eSDaniel Lezcano err = ip6_route_init(); 986e2fddf5eSDaniel Lezcano if (err) 987e2fddf5eSDaniel Lezcano goto ip6_route_fail; 9880a3e78acSDaniel Lezcano err = ip6_flowlabel_init(); 9890a3e78acSDaniel Lezcano if (err) 9900a3e78acSDaniel Lezcano goto ip6_flowlabel_fail; 9911da177e4SLinus Torvalds err = addrconf_init(); 9921da177e4SLinus Torvalds if (err) 9931da177e4SLinus Torvalds goto addrconf_fail; 9941da177e4SLinus Torvalds 9951da177e4SLinus Torvalds /* Init v6 extension headers. */ 996248b238dSDaniel Lezcano err = ipv6_exthdrs_init(); 997248b238dSDaniel Lezcano if (err) 998248b238dSDaniel Lezcano goto ipv6_exthdrs_fail; 999248b238dSDaniel Lezcano 1000853cbbaaSDaniel Lezcano err = ipv6_frag_init(); 1001853cbbaaSDaniel Lezcano if (err) 1002853cbbaaSDaniel Lezcano goto ipv6_frag_fail; 10031da177e4SLinus Torvalds 10041da177e4SLinus Torvalds /* Init v6 transport protocols. */ 10057f4e4868SDaniel Lezcano err = udpv6_init(); 10067f4e4868SDaniel Lezcano if (err) 10077f4e4868SDaniel Lezcano goto udpv6_fail; 1008e2ed4052SHerbert Xu 10097f4e4868SDaniel Lezcano err = udplitev6_init(); 10107f4e4868SDaniel Lezcano if (err) 10117f4e4868SDaniel Lezcano goto udplitev6_fail; 10127f4e4868SDaniel Lezcano 10137f4e4868SDaniel Lezcano err = tcpv6_init(); 10147f4e4868SDaniel Lezcano if (err) 10157f4e4868SDaniel Lezcano goto tcpv6_fail; 10167f4e4868SDaniel Lezcano 10177f4e4868SDaniel Lezcano err = ipv6_packet_init(); 10187f4e4868SDaniel Lezcano if (err) 10197f4e4868SDaniel Lezcano goto ipv6_packet_fail; 102094911fe3SBenjamin Thery 102194911fe3SBenjamin Thery #ifdef CONFIG_SYSCTL 102294911fe3SBenjamin Thery err = ipv6_sysctl_register(); 102394911fe3SBenjamin Thery if (err) 102494911fe3SBenjamin Thery goto sysctl_fail; 102594911fe3SBenjamin Thery #endif 10261da177e4SLinus Torvalds out: 10271da177e4SLinus Torvalds return err; 10281da177e4SLinus Torvalds 102994911fe3SBenjamin Thery #ifdef CONFIG_SYSCTL 103094911fe3SBenjamin Thery sysctl_fail: 103194911fe3SBenjamin Thery ipv6_packet_cleanup(); 103294911fe3SBenjamin Thery #endif 10337f4e4868SDaniel Lezcano ipv6_packet_fail: 10347f4e4868SDaniel Lezcano tcpv6_exit(); 10357f4e4868SDaniel Lezcano tcpv6_fail: 10367f4e4868SDaniel Lezcano udplitev6_exit(); 10377f4e4868SDaniel Lezcano udplitev6_fail: 10387f4e4868SDaniel Lezcano udpv6_exit(); 10397f4e4868SDaniel Lezcano udpv6_fail: 10407f4e4868SDaniel Lezcano ipv6_frag_exit(); 1041853cbbaaSDaniel Lezcano ipv6_frag_fail: 1042853cbbaaSDaniel Lezcano ipv6_exthdrs_exit(); 1043248b238dSDaniel Lezcano ipv6_exthdrs_fail: 1044248b238dSDaniel Lezcano addrconf_cleanup(); 10451da177e4SLinus Torvalds addrconf_fail: 10461da177e4SLinus Torvalds ip6_flowlabel_cleanup(); 10470a3e78acSDaniel Lezcano ip6_flowlabel_fail: 10481da177e4SLinus Torvalds ip6_route_cleanup(); 1049e2fddf5eSDaniel Lezcano ip6_route_fail: 10501da177e4SLinus Torvalds #ifdef CONFIG_PROC_FS 10511da177e4SLinus Torvalds if6_proc_exit(); 10521da177e4SLinus Torvalds proc_if6_fail: 10531da177e4SLinus Torvalds ipv6_misc_proc_exit(); 10541da177e4SLinus Torvalds proc_misc6_fail: 1055ba4e58ecSGerrit Renker udplite6_proc_exit(); 1056ba4e58ecSGerrit Renker proc_udplite6_fail: 10571da177e4SLinus Torvalds raw6_proc_exit(); 10581da177e4SLinus Torvalds proc_raw6_fail: 10591da177e4SLinus Torvalds #endif 10602cc7d573SHarald Welte ipv6_netfilter_fini(); 10612cc7d573SHarald Welte netfilter_fail: 10621da177e4SLinus Torvalds igmp6_cleanup(); 10631da177e4SLinus Torvalds igmp_fail: 10641da177e4SLinus Torvalds ndisc_cleanup(); 10651da177e4SLinus Torvalds ndisc_fail: 1066623d1a1aSWang Chen ip6_mr_cleanup(); 1067623d1a1aSWang Chen ipmr_fail: 10681da177e4SLinus Torvalds icmpv6_cleanup(); 10691da177e4SLinus Torvalds icmp_fail: 107081c1c178SDaniel Lezcano unregister_pernet_subsys(&inet6_net_ops); 107181c1c178SDaniel Lezcano register_pernet_fail: 1072eeb61f71SAl Viro #ifdef CONFIG_SYSCTL 1073eeb61f71SAl Viro ipv6_static_sysctl_unregister(); 1074eeb61f71SAl Viro static_sysctl_fail: 1075eeb61f71SAl Viro #endif 10761da177e4SLinus Torvalds cleanup_ipv6_mibs(); 10778eb55910SDavid S. Miller out_unregister_sock: 10788eb55910SDavid S. Miller sock_unregister(PF_INET6); 1079e2fddf5eSDaniel Lezcano rtnl_unregister_all(PF_INET6); 10807f4e4868SDaniel Lezcano out_sock_register_fail: 10817f4e4868SDaniel Lezcano rawv6_exit(); 10821da177e4SLinus Torvalds out_unregister_raw_proto: 10831da177e4SLinus Torvalds proto_unregister(&rawv6_prot); 1084ba4e58ecSGerrit Renker out_unregister_udplite_proto: 1085ba4e58ecSGerrit Renker proto_unregister(&udplitev6_prot); 10861da177e4SLinus Torvalds out_unregister_udp_proto: 10871da177e4SLinus Torvalds proto_unregister(&udpv6_prot); 10881da177e4SLinus Torvalds out_unregister_tcp_proto: 10891da177e4SLinus Torvalds proto_unregister(&tcpv6_prot); 10901da177e4SLinus Torvalds goto out; 10911da177e4SLinus Torvalds } 10921da177e4SLinus Torvalds module_init(inet6_init); 10931da177e4SLinus Torvalds 10941da177e4SLinus Torvalds static void __exit inet6_exit(void) 10951da177e4SLinus Torvalds { 10961da177e4SLinus Torvalds /* First of all disallow new sockets creation. */ 10971da177e4SLinus Torvalds sock_unregister(PF_INET6); 1098c127ea2cSThomas Graf /* Disallow any further netlink messages */ 1099c127ea2cSThomas Graf rtnl_unregister_all(PF_INET6); 1100ca17c233SJoe Jin 110194911fe3SBenjamin Thery #ifdef CONFIG_SYSCTL 110294911fe3SBenjamin Thery ipv6_sysctl_unregister(); 110394911fe3SBenjamin Thery #endif 11047f4e4868SDaniel Lezcano udpv6_exit(); 11057f4e4868SDaniel Lezcano udplitev6_exit(); 11067f4e4868SDaniel Lezcano tcpv6_exit(); 11077f4e4868SDaniel Lezcano 1108ca17c233SJoe Jin /* Cleanup code parts. */ 1109ca17c233SJoe Jin ipv6_packet_cleanup(); 1110853cbbaaSDaniel Lezcano ipv6_frag_exit(); 1111248b238dSDaniel Lezcano ipv6_exthdrs_exit(); 11121da177e4SLinus Torvalds addrconf_cleanup(); 1113ca17c233SJoe Jin ip6_flowlabel_cleanup(); 11141da177e4SLinus Torvalds ip6_route_cleanup(); 1115ca17c233SJoe Jin #ifdef CONFIG_PROC_FS 1116ca17c233SJoe Jin 1117ca17c233SJoe Jin /* Cleanup code parts. */ 1118ca17c233SJoe Jin if6_proc_exit(); 1119ca17c233SJoe Jin ipv6_misc_proc_exit(); 1120ca17c233SJoe Jin udplite6_proc_exit(); 1121ca17c233SJoe Jin raw6_proc_exit(); 1122ca17c233SJoe Jin #endif 11232cc7d573SHarald Welte ipv6_netfilter_fini(); 1124ca17c233SJoe Jin igmp6_cleanup(); 11251da177e4SLinus Torvalds ndisc_cleanup(); 1126623d1a1aSWang Chen ip6_mr_cleanup(); 11271da177e4SLinus Torvalds icmpv6_cleanup(); 11287f4e4868SDaniel Lezcano rawv6_exit(); 112994911fe3SBenjamin Thery 113081c1c178SDaniel Lezcano unregister_pernet_subsys(&inet6_net_ops); 1131eeb61f71SAl Viro #ifdef CONFIG_SYSCTL 1132eeb61f71SAl Viro ipv6_static_sysctl_unregister(); 1133eeb61f71SAl Viro #endif 11341da177e4SLinus Torvalds cleanup_ipv6_mibs(); 11351da177e4SLinus Torvalds proto_unregister(&rawv6_prot); 1136ca17c233SJoe Jin proto_unregister(&udplitev6_prot); 11371da177e4SLinus Torvalds proto_unregister(&udpv6_prot); 11381da177e4SLinus Torvalds proto_unregister(&tcpv6_prot); 11391da177e4SLinus Torvalds } 11401da177e4SLinus Torvalds module_exit(inet6_exit); 11411da177e4SLinus Torvalds 11421da177e4SLinus Torvalds MODULE_ALIAS_NETPROTO(PF_INET6); 1143