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> 531da177e4SLinus Torvalds #include <net/transp_v6.h> 541da177e4SLinus Torvalds #include <net/ip6_route.h> 551da177e4SLinus Torvalds #include <net/addrconf.h> 561da177e4SLinus Torvalds #ifdef CONFIG_IPV6_TUNNEL 571da177e4SLinus Torvalds #include <net/ip6_tunnel.h> 581da177e4SLinus Torvalds #endif 591da177e4SLinus Torvalds 601da177e4SLinus Torvalds #include <asm/uaccess.h> 611da177e4SLinus Torvalds #include <asm/system.h> 627bc570c8SYOSHIFUJI Hideaki #include <linux/mroute6.h> 631da177e4SLinus Torvalds 641da177e4SLinus Torvalds MODULE_AUTHOR("Cast of dozens"); 651da177e4SLinus Torvalds MODULE_DESCRIPTION("IPv6 protocol stack for Linux"); 661da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 671da177e4SLinus Torvalds 68f1267347SPavel Emelyanov /* The inetsw6 table contains everything that inet6_create needs to 691da177e4SLinus Torvalds * build a new socket. 701da177e4SLinus Torvalds */ 711da177e4SLinus Torvalds static struct list_head inetsw6[SOCK_MAX]; 721da177e4SLinus Torvalds static DEFINE_SPINLOCK(inetsw6_lock); 731da177e4SLinus Torvalds 741da177e4SLinus Torvalds static __inline__ struct ipv6_pinfo *inet6_sk_generic(struct sock *sk) 751da177e4SLinus Torvalds { 761da177e4SLinus Torvalds const int offset = sk->sk_prot->obj_size - sizeof(struct ipv6_pinfo); 771da177e4SLinus Torvalds 781da177e4SLinus Torvalds return (struct ipv6_pinfo *)(((u8 *)sk) + offset); 791da177e4SLinus Torvalds } 801da177e4SLinus Torvalds 811b8d7ae4SEric W. Biederman static int inet6_create(struct net *net, struct socket *sock, int protocol) 821da177e4SLinus Torvalds { 831da177e4SLinus Torvalds struct inet_sock *inet; 841da177e4SLinus Torvalds struct ipv6_pinfo *np; 851da177e4SLinus Torvalds struct sock *sk; 861da177e4SLinus Torvalds struct inet_protosw *answer; 871da177e4SLinus Torvalds struct proto *answer_prot; 881da177e4SLinus Torvalds unsigned char answer_flags; 891da177e4SLinus Torvalds char answer_no_check; 90af1afe86SYOSHIFUJI Hideaki int try_loading_module = 0; 91af1afe86SYOSHIFUJI Hideaki int err; 921da177e4SLinus Torvalds 93b3da2cf3SDavid S. Miller if (sock->type != SOCK_RAW && 94b3da2cf3SDavid S. Miller sock->type != SOCK_DGRAM && 95b3da2cf3SDavid S. Miller !inet_ehash_secret) 96b3da2cf3SDavid S. Miller build_ehash_secret(); 97b3da2cf3SDavid S. Miller 981da177e4SLinus Torvalds /* Look for the requested type/protocol pair. */ 99af1afe86SYOSHIFUJI Hideaki lookup_protocol: 100af1afe86SYOSHIFUJI Hideaki err = -ESOCKTNOSUPPORT; 1011da177e4SLinus Torvalds rcu_read_lock(); 102696adfe8SPaul E. McKenney list_for_each_entry_rcu(answer, &inetsw6[sock->type], list) { 1031da177e4SLinus Torvalds 104696adfe8SPaul E. McKenney err = 0; 1051da177e4SLinus Torvalds /* Check the non-wild match. */ 1061da177e4SLinus Torvalds if (protocol == answer->protocol) { 1071da177e4SLinus Torvalds if (protocol != IPPROTO_IP) 1081da177e4SLinus Torvalds break; 1091da177e4SLinus Torvalds } else { 1101da177e4SLinus Torvalds /* Check for the two wild cases. */ 1111da177e4SLinus Torvalds if (IPPROTO_IP == protocol) { 1121da177e4SLinus Torvalds protocol = answer->protocol; 1131da177e4SLinus Torvalds break; 1141da177e4SLinus Torvalds } 1151da177e4SLinus Torvalds if (IPPROTO_IP == answer->protocol) 1161da177e4SLinus Torvalds break; 1171da177e4SLinus Torvalds } 118af1afe86SYOSHIFUJI Hideaki err = -EPROTONOSUPPORT; 1191da177e4SLinus Torvalds } 1201da177e4SLinus Torvalds 121696adfe8SPaul E. McKenney if (err) { 122af1afe86SYOSHIFUJI Hideaki if (try_loading_module < 2) { 123af1afe86SYOSHIFUJI Hideaki rcu_read_unlock(); 124af1afe86SYOSHIFUJI Hideaki /* 125af1afe86SYOSHIFUJI Hideaki * Be more specific, e.g. net-pf-10-proto-132-type-1 126af1afe86SYOSHIFUJI Hideaki * (net-pf-PF_INET6-proto-IPPROTO_SCTP-type-SOCK_STREAM) 127af1afe86SYOSHIFUJI Hideaki */ 128af1afe86SYOSHIFUJI Hideaki if (++try_loading_module == 1) 129af1afe86SYOSHIFUJI Hideaki request_module("net-pf-%d-proto-%d-type-%d", 130af1afe86SYOSHIFUJI Hideaki PF_INET6, protocol, sock->type); 131af1afe86SYOSHIFUJI Hideaki /* 132af1afe86SYOSHIFUJI Hideaki * Fall back to generic, e.g. net-pf-10-proto-132 133af1afe86SYOSHIFUJI Hideaki * (net-pf-PF_INET6-proto-IPPROTO_SCTP) 134af1afe86SYOSHIFUJI Hideaki */ 135af1afe86SYOSHIFUJI Hideaki else 136af1afe86SYOSHIFUJI Hideaki request_module("net-pf-%d-proto-%d", 137af1afe86SYOSHIFUJI Hideaki PF_INET6, protocol); 138af1afe86SYOSHIFUJI Hideaki goto lookup_protocol; 139af1afe86SYOSHIFUJI Hideaki } else 1401da177e4SLinus Torvalds goto out_rcu_unlock; 141af1afe86SYOSHIFUJI Hideaki } 142af1afe86SYOSHIFUJI Hideaki 143af1afe86SYOSHIFUJI Hideaki err = -EPERM; 1441da177e4SLinus Torvalds if (answer->capability > 0 && !capable(answer->capability)) 1451da177e4SLinus Torvalds goto out_rcu_unlock; 1461da177e4SLinus Torvalds 1471da177e4SLinus Torvalds sock->ops = answer->ops; 1481da177e4SLinus Torvalds answer_prot = answer->prot; 1491da177e4SLinus Torvalds answer_no_check = answer->no_check; 1501da177e4SLinus Torvalds answer_flags = answer->flags; 1511da177e4SLinus Torvalds rcu_read_unlock(); 1521da177e4SLinus Torvalds 1531da177e4SLinus Torvalds BUG_TRAP(answer_prot->slab != NULL); 1541da177e4SLinus Torvalds 155af1afe86SYOSHIFUJI Hideaki err = -ENOBUFS; 1566257ff21SPavel Emelyanov sk = sk_alloc(net, PF_INET6, GFP_KERNEL, answer_prot); 1571da177e4SLinus Torvalds if (sk == NULL) 1581da177e4SLinus Torvalds goto out; 1591da177e4SLinus Torvalds 1601da177e4SLinus Torvalds sock_init_data(sock, sk); 1611da177e4SLinus Torvalds 162af1afe86SYOSHIFUJI Hideaki err = 0; 1631da177e4SLinus Torvalds sk->sk_no_check = answer_no_check; 1641da177e4SLinus Torvalds if (INET_PROTOSW_REUSE & answer_flags) 1651da177e4SLinus Torvalds sk->sk_reuse = 1; 1661da177e4SLinus Torvalds 1671da177e4SLinus Torvalds inet = inet_sk(sk); 168469de9b9SPaul Moore inet->is_icsk = (INET_PROTOSW_ICSK & answer_flags) != 0; 1691da177e4SLinus Torvalds 1701da177e4SLinus Torvalds if (SOCK_RAW == sock->type) { 1711da177e4SLinus Torvalds inet->num = protocol; 1721da177e4SLinus Torvalds if (IPPROTO_RAW == protocol) 1731da177e4SLinus Torvalds inet->hdrincl = 1; 1741da177e4SLinus Torvalds } 1751da177e4SLinus Torvalds 176e6848976SArnaldo Carvalho de Melo sk->sk_destruct = inet_sock_destruct; 1771da177e4SLinus Torvalds sk->sk_family = PF_INET6; 1781da177e4SLinus Torvalds sk->sk_protocol = protocol; 1791da177e4SLinus Torvalds 1801da177e4SLinus Torvalds sk->sk_backlog_rcv = answer->prot->backlog_rcv; 1811da177e4SLinus Torvalds 1821da177e4SLinus Torvalds inet_sk(sk)->pinet6 = np = inet6_sk_generic(sk); 1831da177e4SLinus Torvalds np->hop_limit = -1; 1841da177e4SLinus Torvalds np->mcast_hops = -1; 1851da177e4SLinus Torvalds np->mc_loop = 1; 1861da177e4SLinus Torvalds np->pmtudisc = IPV6_PMTUDISC_WANT; 1872e761e05SPavel Emelyanov np->ipv6only = net->ipv6.sysctl.bindv6only; 1881da177e4SLinus Torvalds 1891da177e4SLinus Torvalds /* Init the ipv4 part of the socket since we can have sockets 1901da177e4SLinus Torvalds * using v6 API for ipv4. 1911da177e4SLinus Torvalds */ 1921da177e4SLinus Torvalds inet->uc_ttl = -1; 1931da177e4SLinus Torvalds 1941da177e4SLinus Torvalds inet->mc_loop = 1; 1951da177e4SLinus Torvalds inet->mc_ttl = 1; 1961da177e4SLinus Torvalds inet->mc_index = 0; 1971da177e4SLinus Torvalds inet->mc_list = NULL; 1981da177e4SLinus Torvalds 1991da177e4SLinus Torvalds if (ipv4_config.no_pmtu_disc) 2001da177e4SLinus Torvalds inet->pmtudisc = IP_PMTUDISC_DONT; 2011da177e4SLinus Torvalds else 2021da177e4SLinus Torvalds inet->pmtudisc = IP_PMTUDISC_WANT; 203e6848976SArnaldo Carvalho de Melo /* 204e6848976SArnaldo Carvalho de Melo * Increment only the relevant sk_prot->socks debug field, this changes 205e6848976SArnaldo Carvalho de Melo * the previous behaviour of incrementing both the equivalent to 206e6848976SArnaldo Carvalho de Melo * answer->prot->socks (inet6_sock_nr) and inet_sock_nr. 207e6848976SArnaldo Carvalho de Melo * 208e6848976SArnaldo Carvalho de Melo * This allows better debug granularity as we'll know exactly how many 209e6848976SArnaldo Carvalho de Melo * UDPv6, TCPv6, etc socks were allocated, not the sum of all IPv6 210e6848976SArnaldo Carvalho de Melo * transport protocol socks. -acme 211e6848976SArnaldo Carvalho de Melo */ 212e6848976SArnaldo Carvalho de Melo sk_refcnt_debug_inc(sk); 2131da177e4SLinus Torvalds 2141da177e4SLinus Torvalds if (inet->num) { 2151da177e4SLinus Torvalds /* It assumes that any protocol which allows 2161da177e4SLinus Torvalds * the user to assign a number at socket 2171da177e4SLinus Torvalds * creation time automatically shares. 2181da177e4SLinus Torvalds */ 219e69a4adcSAl Viro inet->sport = htons(inet->num); 2201da177e4SLinus Torvalds sk->sk_prot->hash(sk); 2211da177e4SLinus Torvalds } 2221da177e4SLinus Torvalds if (sk->sk_prot->init) { 223af1afe86SYOSHIFUJI Hideaki err = sk->sk_prot->init(sk); 224af1afe86SYOSHIFUJI Hideaki if (err) { 2251da177e4SLinus Torvalds sk_common_release(sk); 2261da177e4SLinus Torvalds goto out; 2271da177e4SLinus Torvalds } 2281da177e4SLinus Torvalds } 2291da177e4SLinus Torvalds out: 230af1afe86SYOSHIFUJI Hideaki return err; 2311da177e4SLinus Torvalds out_rcu_unlock: 2321da177e4SLinus Torvalds rcu_read_unlock(); 2331da177e4SLinus Torvalds goto out; 2341da177e4SLinus Torvalds } 2351da177e4SLinus Torvalds 2361da177e4SLinus Torvalds 2371da177e4SLinus Torvalds /* bind for INET6 API */ 2381da177e4SLinus Torvalds int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) 2391da177e4SLinus Torvalds { 2401da177e4SLinus Torvalds struct sockaddr_in6 *addr=(struct sockaddr_in6 *)uaddr; 2411da177e4SLinus Torvalds struct sock *sk = sock->sk; 2421da177e4SLinus Torvalds struct inet_sock *inet = inet_sk(sk); 2431da177e4SLinus Torvalds struct ipv6_pinfo *np = inet6_sk(sk); 2443b1e0a65SYOSHIFUJI Hideaki struct net *net = sock_net(sk); 245fd683222SAl Viro __be32 v4addr = 0; 2461da177e4SLinus Torvalds unsigned short snum; 2471da177e4SLinus Torvalds int addr_type = 0; 2481da177e4SLinus Torvalds int err = 0; 2491da177e4SLinus Torvalds 2501da177e4SLinus Torvalds /* If the socket has its own bind function then use it. */ 2511da177e4SLinus Torvalds if (sk->sk_prot->bind) 2521da177e4SLinus Torvalds return sk->sk_prot->bind(sk, uaddr, addr_len); 2531da177e4SLinus Torvalds 2541da177e4SLinus Torvalds if (addr_len < SIN6_LEN_RFC2133) 2551da177e4SLinus Torvalds return -EINVAL; 2561da177e4SLinus Torvalds addr_type = ipv6_addr_type(&addr->sin6_addr); 2571da177e4SLinus Torvalds if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM) 2581da177e4SLinus Torvalds return -EINVAL; 2591da177e4SLinus Torvalds 2601da177e4SLinus Torvalds snum = ntohs(addr->sin6_port); 2611da177e4SLinus Torvalds if (snum && snum < PROT_SOCK && !capable(CAP_NET_BIND_SERVICE)) 2621da177e4SLinus Torvalds return -EACCES; 2631da177e4SLinus Torvalds 2641da177e4SLinus Torvalds lock_sock(sk); 2651da177e4SLinus Torvalds 2661da177e4SLinus Torvalds /* Check these errors (active socket, double bind). */ 2671da177e4SLinus Torvalds if (sk->sk_state != TCP_CLOSE || inet->num) { 2681da177e4SLinus Torvalds err = -EINVAL; 2691da177e4SLinus Torvalds goto out; 2701da177e4SLinus Torvalds } 2711da177e4SLinus Torvalds 2721da177e4SLinus Torvalds /* Check if the address belongs to the host. */ 2731da177e4SLinus Torvalds if (addr_type == IPV6_ADDR_MAPPED) { 2741da177e4SLinus Torvalds v4addr = addr->sin6_addr.s6_addr32[3]; 275075de939SBenjamin Thery if (inet_addr_type(net, v4addr) != RTN_LOCAL) { 2761da177e4SLinus Torvalds err = -EADDRNOTAVAIL; 2771da177e4SLinus Torvalds goto out; 2781da177e4SLinus Torvalds } 2791da177e4SLinus Torvalds } else { 2801da177e4SLinus Torvalds if (addr_type != IPV6_ADDR_ANY) { 2811da177e4SLinus Torvalds struct net_device *dev = NULL; 2821da177e4SLinus Torvalds 2831da177e4SLinus Torvalds if (addr_type & IPV6_ADDR_LINKLOCAL) { 2841da177e4SLinus Torvalds if (addr_len >= sizeof(struct sockaddr_in6) && 2851da177e4SLinus Torvalds addr->sin6_scope_id) { 2861da177e4SLinus Torvalds /* Override any existing binding, if another one 2871da177e4SLinus Torvalds * is supplied by user. 2881da177e4SLinus Torvalds */ 2891da177e4SLinus Torvalds sk->sk_bound_dev_if = addr->sin6_scope_id; 2901da177e4SLinus Torvalds } 2911da177e4SLinus Torvalds 2921da177e4SLinus Torvalds /* Binding to link-local address requires an interface */ 2931da177e4SLinus Torvalds if (!sk->sk_bound_dev_if) { 2941da177e4SLinus Torvalds err = -EINVAL; 2951da177e4SLinus Torvalds goto out; 2961da177e4SLinus Torvalds } 297075de939SBenjamin Thery dev = dev_get_by_index(net, sk->sk_bound_dev_if); 2981da177e4SLinus Torvalds if (!dev) { 2991da177e4SLinus Torvalds err = -ENODEV; 3001da177e4SLinus Torvalds goto out; 3011da177e4SLinus Torvalds } 3021da177e4SLinus Torvalds } 3031da177e4SLinus Torvalds 3041da177e4SLinus Torvalds /* ipv4 addr of the socket is invalid. Only the 3051da177e4SLinus Torvalds * unspecified and mapped address have a v4 equivalent. 3061da177e4SLinus Torvalds */ 3071da177e4SLinus Torvalds v4addr = LOOPBACK4_IPV6; 3081da177e4SLinus Torvalds if (!(addr_type & IPV6_ADDR_MULTICAST)) { 309075de939SBenjamin Thery if (!ipv6_chk_addr(net, &addr->sin6_addr, 310bfeade08SDaniel Lezcano dev, 0)) { 3111da177e4SLinus Torvalds if (dev) 3121da177e4SLinus Torvalds dev_put(dev); 3131da177e4SLinus Torvalds err = -EADDRNOTAVAIL; 3141da177e4SLinus Torvalds goto out; 3151da177e4SLinus Torvalds } 3161da177e4SLinus Torvalds } 3171da177e4SLinus Torvalds if (dev) 3181da177e4SLinus Torvalds dev_put(dev); 3191da177e4SLinus Torvalds } 3201da177e4SLinus Torvalds } 3211da177e4SLinus Torvalds 3221da177e4SLinus Torvalds inet->rcv_saddr = v4addr; 3231da177e4SLinus Torvalds inet->saddr = v4addr; 3241da177e4SLinus Torvalds 3251da177e4SLinus Torvalds ipv6_addr_copy(&np->rcv_saddr, &addr->sin6_addr); 3261da177e4SLinus Torvalds 3271da177e4SLinus Torvalds if (!(addr_type & IPV6_ADDR_MULTICAST)) 3281da177e4SLinus Torvalds ipv6_addr_copy(&np->saddr, &addr->sin6_addr); 3291da177e4SLinus Torvalds 3301da177e4SLinus Torvalds /* Make sure we are allowed to bind here. */ 3311da177e4SLinus Torvalds if (sk->sk_prot->get_port(sk, snum)) { 3321da177e4SLinus Torvalds inet_reset_saddr(sk); 3331da177e4SLinus Torvalds err = -EADDRINUSE; 3341da177e4SLinus Torvalds goto out; 3351da177e4SLinus Torvalds } 3361da177e4SLinus Torvalds 3371da177e4SLinus Torvalds if (addr_type != IPV6_ADDR_ANY) 3381da177e4SLinus Torvalds sk->sk_userlocks |= SOCK_BINDADDR_LOCK; 3391da177e4SLinus Torvalds if (snum) 3401da177e4SLinus Torvalds sk->sk_userlocks |= SOCK_BINDPORT_LOCK; 341e69a4adcSAl Viro inet->sport = htons(inet->num); 3421da177e4SLinus Torvalds inet->dport = 0; 3431da177e4SLinus Torvalds inet->daddr = 0; 3441da177e4SLinus Torvalds out: 3451da177e4SLinus Torvalds release_sock(sk); 3461da177e4SLinus Torvalds return err; 3471da177e4SLinus Torvalds } 3481da177e4SLinus Torvalds 3497159039aSYOSHIFUJI Hideaki EXPORT_SYMBOL(inet6_bind); 3507159039aSYOSHIFUJI Hideaki 3511da177e4SLinus Torvalds int inet6_release(struct socket *sock) 3521da177e4SLinus Torvalds { 3531da177e4SLinus Torvalds struct sock *sk = sock->sk; 3541da177e4SLinus Torvalds 3551da177e4SLinus Torvalds if (sk == NULL) 3561da177e4SLinus Torvalds return -EINVAL; 3571da177e4SLinus Torvalds 3581da177e4SLinus Torvalds /* Free mc lists */ 3591da177e4SLinus Torvalds ipv6_sock_mc_close(sk); 3601da177e4SLinus Torvalds 3611da177e4SLinus Torvalds /* Free ac lists */ 3621da177e4SLinus Torvalds ipv6_sock_ac_close(sk); 3631da177e4SLinus Torvalds 3641da177e4SLinus Torvalds return inet_release(sock); 3651da177e4SLinus Torvalds } 3661da177e4SLinus Torvalds 3677159039aSYOSHIFUJI Hideaki EXPORT_SYMBOL(inet6_release); 3687159039aSYOSHIFUJI Hideaki 3697d06b2e0SBrian Haley void inet6_destroy_sock(struct sock *sk) 3701da177e4SLinus Torvalds { 3711da177e4SLinus Torvalds struct ipv6_pinfo *np = inet6_sk(sk); 3721da177e4SLinus Torvalds struct sk_buff *skb; 3731da177e4SLinus Torvalds struct ipv6_txoptions *opt; 3741da177e4SLinus Torvalds 3751da177e4SLinus Torvalds /* Release rx options */ 3761da177e4SLinus Torvalds 3771da177e4SLinus Torvalds if ((skb = xchg(&np->pktoptions, NULL)) != NULL) 3781da177e4SLinus Torvalds kfree_skb(skb); 3791da177e4SLinus Torvalds 3801da177e4SLinus Torvalds /* Free flowlabels */ 3811da177e4SLinus Torvalds fl6_free_socklist(sk); 3821da177e4SLinus Torvalds 3831da177e4SLinus Torvalds /* Free tx options */ 3841da177e4SLinus Torvalds 3851da177e4SLinus Torvalds if ((opt = xchg(&np->opt, NULL)) != NULL) 3861da177e4SLinus Torvalds sock_kfree_s(sk, opt, opt->tot_len); 3871da177e4SLinus Torvalds } 3881da177e4SLinus Torvalds 3893cf3dc6cSArnaldo Carvalho de Melo EXPORT_SYMBOL_GPL(inet6_destroy_sock); 3903cf3dc6cSArnaldo Carvalho de Melo 3911da177e4SLinus Torvalds /* 3921da177e4SLinus Torvalds * This does both peername and sockname. 3931da177e4SLinus Torvalds */ 3941da177e4SLinus Torvalds 3951da177e4SLinus Torvalds int inet6_getname(struct socket *sock, struct sockaddr *uaddr, 3961da177e4SLinus Torvalds int *uaddr_len, int peer) 3971da177e4SLinus Torvalds { 3981da177e4SLinus Torvalds struct sockaddr_in6 *sin=(struct sockaddr_in6 *)uaddr; 3991da177e4SLinus Torvalds struct sock *sk = sock->sk; 4001da177e4SLinus Torvalds struct inet_sock *inet = inet_sk(sk); 4011da177e4SLinus Torvalds struct ipv6_pinfo *np = inet6_sk(sk); 4021da177e4SLinus Torvalds 4031da177e4SLinus Torvalds sin->sin6_family = AF_INET6; 4041da177e4SLinus Torvalds sin->sin6_flowinfo = 0; 4051da177e4SLinus Torvalds sin->sin6_scope_id = 0; 4061da177e4SLinus Torvalds if (peer) { 4071da177e4SLinus Torvalds if (!inet->dport) 4081da177e4SLinus Torvalds return -ENOTCONN; 4091da177e4SLinus Torvalds if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_SYN_SENT)) && 4101da177e4SLinus Torvalds peer == 1) 4111da177e4SLinus Torvalds return -ENOTCONN; 4121da177e4SLinus Torvalds sin->sin6_port = inet->dport; 4131da177e4SLinus Torvalds ipv6_addr_copy(&sin->sin6_addr, &np->daddr); 4141da177e4SLinus Torvalds if (np->sndflow) 4151da177e4SLinus Torvalds sin->sin6_flowinfo = np->flow_label; 4161da177e4SLinus Torvalds } else { 4171da177e4SLinus Torvalds if (ipv6_addr_any(&np->rcv_saddr)) 4181da177e4SLinus Torvalds ipv6_addr_copy(&sin->sin6_addr, &np->saddr); 4191da177e4SLinus Torvalds else 4201da177e4SLinus Torvalds ipv6_addr_copy(&sin->sin6_addr, &np->rcv_saddr); 4211da177e4SLinus Torvalds 4221da177e4SLinus Torvalds sin->sin6_port = inet->sport; 4231da177e4SLinus Torvalds } 4241da177e4SLinus Torvalds if (ipv6_addr_type(&sin->sin6_addr) & IPV6_ADDR_LINKLOCAL) 4251da177e4SLinus Torvalds sin->sin6_scope_id = sk->sk_bound_dev_if; 4261da177e4SLinus Torvalds *uaddr_len = sizeof(*sin); 4271da177e4SLinus Torvalds return(0); 4281da177e4SLinus Torvalds } 4291da177e4SLinus Torvalds 4307159039aSYOSHIFUJI Hideaki EXPORT_SYMBOL(inet6_getname); 4317159039aSYOSHIFUJI Hideaki 4321da177e4SLinus Torvalds int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) 4331da177e4SLinus Torvalds { 4341da177e4SLinus Torvalds struct sock *sk = sock->sk; 4353b1e0a65SYOSHIFUJI Hideaki struct net *net = sock_net(sk); 4361da177e4SLinus Torvalds 4371da177e4SLinus Torvalds switch(cmd) 4381da177e4SLinus Torvalds { 4391da177e4SLinus Torvalds case SIOCGSTAMP: 4401da177e4SLinus Torvalds return sock_get_timestamp(sk, (struct timeval __user *)arg); 4411da177e4SLinus Torvalds 442ae40eb1eSEric Dumazet case SIOCGSTAMPNS: 443ae40eb1eSEric Dumazet return sock_get_timestampns(sk, (struct timespec __user *)arg); 444ae40eb1eSEric Dumazet 4451da177e4SLinus Torvalds case SIOCADDRT: 4461da177e4SLinus Torvalds case SIOCDELRT: 4471da177e4SLinus Torvalds 4485578689aSDaniel Lezcano return(ipv6_route_ioctl(net, cmd, (void __user *)arg)); 4491da177e4SLinus Torvalds 4501da177e4SLinus Torvalds case SIOCSIFADDR: 451af284937SDaniel Lezcano return addrconf_add_ifaddr(net, (void __user *) arg); 4521da177e4SLinus Torvalds case SIOCDIFADDR: 453af284937SDaniel Lezcano return addrconf_del_ifaddr(net, (void __user *) arg); 4541da177e4SLinus Torvalds case SIOCSIFDSTADDR: 455af284937SDaniel Lezcano return addrconf_set_dstaddr(net, (void __user *) arg); 4561da177e4SLinus Torvalds default: 457b5e5fa5eSChristoph Hellwig if (!sk->sk_prot->ioctl) 458b5e5fa5eSChristoph Hellwig return -ENOIOCTLCMD; 459b5e5fa5eSChristoph Hellwig return sk->sk_prot->ioctl(sk, cmd, arg); 4601da177e4SLinus Torvalds } 4611da177e4SLinus Torvalds /*NOTREACHED*/ 4621da177e4SLinus Torvalds return(0); 4631da177e4SLinus Torvalds } 4641da177e4SLinus Torvalds 4657159039aSYOSHIFUJI Hideaki EXPORT_SYMBOL(inet6_ioctl); 4667159039aSYOSHIFUJI Hideaki 46790ddc4f0SEric Dumazet const struct proto_ops inet6_stream_ops = { 4681da177e4SLinus Torvalds .family = PF_INET6, 4691da177e4SLinus Torvalds .owner = THIS_MODULE, 4701da177e4SLinus Torvalds .release = inet6_release, 4711da177e4SLinus Torvalds .bind = inet6_bind, 4721da177e4SLinus Torvalds .connect = inet_stream_connect, /* ok */ 4731da177e4SLinus Torvalds .socketpair = sock_no_socketpair, /* a do nothing */ 4741da177e4SLinus Torvalds .accept = inet_accept, /* ok */ 4751da177e4SLinus Torvalds .getname = inet6_getname, 4761da177e4SLinus Torvalds .poll = tcp_poll, /* ok */ 4771da177e4SLinus Torvalds .ioctl = inet6_ioctl, /* must change */ 4781da177e4SLinus Torvalds .listen = inet_listen, /* ok */ 4791da177e4SLinus Torvalds .shutdown = inet_shutdown, /* ok */ 4801da177e4SLinus Torvalds .setsockopt = sock_common_setsockopt, /* ok */ 4811da177e4SLinus Torvalds .getsockopt = sock_common_getsockopt, /* ok */ 4823516ffb0SDavid S. Miller .sendmsg = tcp_sendmsg, /* ok */ 483543d9cfeSArnaldo Carvalho de Melo .recvmsg = sock_common_recvmsg, /* ok */ 484543d9cfeSArnaldo Carvalho de Melo .mmap = sock_no_mmap, 485543d9cfeSArnaldo Carvalho de Melo .sendpage = tcp_sendpage, 486a0974dd3SJens Axboe .splice_read = tcp_splice_read, 4873fdadf7dSDmitry Mishin #ifdef CONFIG_COMPAT 4883fdadf7dSDmitry Mishin .compat_setsockopt = compat_sock_common_setsockopt, 4893fdadf7dSDmitry Mishin .compat_getsockopt = compat_sock_common_getsockopt, 4903fdadf7dSDmitry Mishin #endif 4911da177e4SLinus Torvalds }; 4921da177e4SLinus Torvalds 49390ddc4f0SEric Dumazet const struct proto_ops inet6_dgram_ops = { 4941da177e4SLinus Torvalds .family = PF_INET6, 4951da177e4SLinus Torvalds .owner = THIS_MODULE, 4961da177e4SLinus Torvalds .release = inet6_release, 4971da177e4SLinus Torvalds .bind = inet6_bind, 4981da177e4SLinus Torvalds .connect = inet_dgram_connect, /* ok */ 4991da177e4SLinus Torvalds .socketpair = sock_no_socketpair, /* a do nothing */ 5001da177e4SLinus Torvalds .accept = sock_no_accept, /* a do nothing */ 5011da177e4SLinus Torvalds .getname = inet6_getname, 5021da177e4SLinus Torvalds .poll = udp_poll, /* ok */ 5031da177e4SLinus Torvalds .ioctl = inet6_ioctl, /* must change */ 5041da177e4SLinus Torvalds .listen = sock_no_listen, /* ok */ 5051da177e4SLinus Torvalds .shutdown = inet_shutdown, /* ok */ 5061da177e4SLinus Torvalds .setsockopt = sock_common_setsockopt, /* ok */ 5071da177e4SLinus Torvalds .getsockopt = sock_common_getsockopt, /* ok */ 5081da177e4SLinus Torvalds .sendmsg = inet_sendmsg, /* ok */ 5091da177e4SLinus Torvalds .recvmsg = sock_common_recvmsg, /* ok */ 5101da177e4SLinus Torvalds .mmap = sock_no_mmap, 5111da177e4SLinus Torvalds .sendpage = sock_no_sendpage, 512543d9cfeSArnaldo Carvalho de Melo #ifdef CONFIG_COMPAT 513543d9cfeSArnaldo Carvalho de Melo .compat_setsockopt = compat_sock_common_setsockopt, 514543d9cfeSArnaldo Carvalho de Melo .compat_getsockopt = compat_sock_common_getsockopt, 515543d9cfeSArnaldo Carvalho de Melo #endif 5161da177e4SLinus Torvalds }; 5171da177e4SLinus Torvalds 5181da177e4SLinus Torvalds static struct net_proto_family inet6_family_ops = { 5191da177e4SLinus Torvalds .family = PF_INET6, 5201da177e4SLinus Torvalds .create = inet6_create, 5211da177e4SLinus Torvalds .owner = THIS_MODULE, 5221da177e4SLinus Torvalds }; 5231da177e4SLinus Torvalds 52487c3efbfSDaniel Lezcano int inet6_register_protosw(struct inet_protosw *p) 5251da177e4SLinus Torvalds { 5261da177e4SLinus Torvalds struct list_head *lh; 5271da177e4SLinus Torvalds struct inet_protosw *answer; 5281da177e4SLinus Torvalds struct list_head *last_perm; 52987c3efbfSDaniel Lezcano int protocol = p->protocol; 53087c3efbfSDaniel Lezcano int ret; 5311da177e4SLinus Torvalds 5321da177e4SLinus Torvalds spin_lock_bh(&inetsw6_lock); 5331da177e4SLinus Torvalds 53487c3efbfSDaniel Lezcano ret = -EINVAL; 5351da177e4SLinus Torvalds if (p->type >= SOCK_MAX) 5361da177e4SLinus Torvalds goto out_illegal; 5371da177e4SLinus Torvalds 5381da177e4SLinus Torvalds /* If we are trying to override a permanent protocol, bail. */ 5391da177e4SLinus Torvalds answer = NULL; 54087c3efbfSDaniel Lezcano ret = -EPERM; 5411da177e4SLinus Torvalds last_perm = &inetsw6[p->type]; 5421da177e4SLinus Torvalds list_for_each(lh, &inetsw6[p->type]) { 5431da177e4SLinus Torvalds answer = list_entry(lh, struct inet_protosw, list); 5441da177e4SLinus Torvalds 5451da177e4SLinus Torvalds /* Check only the non-wild match. */ 5461da177e4SLinus Torvalds if (INET_PROTOSW_PERMANENT & answer->flags) { 5471da177e4SLinus Torvalds if (protocol == answer->protocol) 5481da177e4SLinus Torvalds break; 5491da177e4SLinus Torvalds last_perm = lh; 5501da177e4SLinus Torvalds } 5511da177e4SLinus Torvalds 5521da177e4SLinus Torvalds answer = NULL; 5531da177e4SLinus Torvalds } 5541da177e4SLinus Torvalds if (answer) 5551da177e4SLinus Torvalds goto out_permanent; 5561da177e4SLinus Torvalds 5571da177e4SLinus Torvalds /* Add the new entry after the last permanent entry if any, so that 5581da177e4SLinus Torvalds * the new entry does not override a permanent entry when matched with 5591da177e4SLinus Torvalds * a wild-card protocol. But it is allowed to override any existing 5601da177e4SLinus Torvalds * non-permanent entry. This means that when we remove this entry, the 5611da177e4SLinus Torvalds * system automatically returns to the old behavior. 5621da177e4SLinus Torvalds */ 5631da177e4SLinus Torvalds list_add_rcu(&p->list, last_perm); 56487c3efbfSDaniel Lezcano ret = 0; 5651da177e4SLinus Torvalds out: 5661da177e4SLinus Torvalds spin_unlock_bh(&inetsw6_lock); 56787c3efbfSDaniel Lezcano return ret; 5681da177e4SLinus Torvalds 5691da177e4SLinus Torvalds out_permanent: 5701da177e4SLinus Torvalds printk(KERN_ERR "Attempt to override permanent protocol %d.\n", 5711da177e4SLinus Torvalds protocol); 5721da177e4SLinus Torvalds goto out; 5731da177e4SLinus Torvalds 5741da177e4SLinus Torvalds out_illegal: 5751da177e4SLinus Torvalds printk(KERN_ERR 5761da177e4SLinus Torvalds "Ignoring attempt to register invalid socket type %d.\n", 5771da177e4SLinus Torvalds p->type); 5781da177e4SLinus Torvalds goto out; 5791da177e4SLinus Torvalds } 5801da177e4SLinus Torvalds 5817159039aSYOSHIFUJI Hideaki EXPORT_SYMBOL(inet6_register_protosw); 5827159039aSYOSHIFUJI Hideaki 5831da177e4SLinus Torvalds void 5841da177e4SLinus Torvalds inet6_unregister_protosw(struct inet_protosw *p) 5851da177e4SLinus Torvalds { 5861da177e4SLinus Torvalds if (INET_PROTOSW_PERMANENT & p->flags) { 5871da177e4SLinus Torvalds printk(KERN_ERR 5881da177e4SLinus Torvalds "Attempt to unregister permanent protocol %d.\n", 5891da177e4SLinus Torvalds p->protocol); 5901da177e4SLinus Torvalds } else { 5911da177e4SLinus Torvalds spin_lock_bh(&inetsw6_lock); 5921da177e4SLinus Torvalds list_del_rcu(&p->list); 5931da177e4SLinus Torvalds spin_unlock_bh(&inetsw6_lock); 5941da177e4SLinus Torvalds 5951da177e4SLinus Torvalds synchronize_net(); 5961da177e4SLinus Torvalds } 5971da177e4SLinus Torvalds } 5981da177e4SLinus Torvalds 5997159039aSYOSHIFUJI Hideaki EXPORT_SYMBOL(inet6_unregister_protosw); 6007159039aSYOSHIFUJI Hideaki 601b9750ce1SArnaldo Carvalho de Melo int inet6_sk_rebuild_header(struct sock *sk) 602b9750ce1SArnaldo Carvalho de Melo { 603b9750ce1SArnaldo Carvalho de Melo int err; 604b9750ce1SArnaldo Carvalho de Melo struct dst_entry *dst; 605b9750ce1SArnaldo Carvalho de Melo struct ipv6_pinfo *np = inet6_sk(sk); 606b9750ce1SArnaldo Carvalho de Melo 607b9750ce1SArnaldo Carvalho de Melo dst = __sk_dst_check(sk, np->dst_cookie); 608b9750ce1SArnaldo Carvalho de Melo 609b9750ce1SArnaldo Carvalho de Melo if (dst == NULL) { 610b9750ce1SArnaldo Carvalho de Melo struct inet_sock *inet = inet_sk(sk); 611b9750ce1SArnaldo Carvalho de Melo struct in6_addr *final_p = NULL, final; 612b9750ce1SArnaldo Carvalho de Melo struct flowi fl; 613b9750ce1SArnaldo Carvalho de Melo 614b9750ce1SArnaldo Carvalho de Melo memset(&fl, 0, sizeof(fl)); 615b9750ce1SArnaldo Carvalho de Melo fl.proto = sk->sk_protocol; 616b9750ce1SArnaldo Carvalho de Melo ipv6_addr_copy(&fl.fl6_dst, &np->daddr); 617b9750ce1SArnaldo Carvalho de Melo ipv6_addr_copy(&fl.fl6_src, &np->saddr); 618b9750ce1SArnaldo Carvalho de Melo fl.fl6_flowlabel = np->flow_label; 619b9750ce1SArnaldo Carvalho de Melo fl.oif = sk->sk_bound_dev_if; 620b9750ce1SArnaldo Carvalho de Melo fl.fl_ip_dport = inet->dport; 621b9750ce1SArnaldo Carvalho de Melo fl.fl_ip_sport = inet->sport; 622beb8d13bSVenkat Yekkirala security_sk_classify_flow(sk, &fl); 623b9750ce1SArnaldo Carvalho de Melo 624b9750ce1SArnaldo Carvalho de Melo if (np->opt && np->opt->srcrt) { 625b9750ce1SArnaldo Carvalho de Melo struct rt0_hdr *rt0 = (struct rt0_hdr *) np->opt->srcrt; 626b9750ce1SArnaldo Carvalho de Melo ipv6_addr_copy(&final, &fl.fl6_dst); 627b9750ce1SArnaldo Carvalho de Melo ipv6_addr_copy(&fl.fl6_dst, rt0->addr); 628b9750ce1SArnaldo Carvalho de Melo final_p = &final; 629b9750ce1SArnaldo Carvalho de Melo } 630b9750ce1SArnaldo Carvalho de Melo 631b9750ce1SArnaldo Carvalho de Melo err = ip6_dst_lookup(sk, &dst, &fl); 632b9750ce1SArnaldo Carvalho de Melo if (err) { 633b9750ce1SArnaldo Carvalho de Melo sk->sk_route_caps = 0; 634b9750ce1SArnaldo Carvalho de Melo return err; 635b9750ce1SArnaldo Carvalho de Melo } 636b9750ce1SArnaldo Carvalho de Melo if (final_p) 637b9750ce1SArnaldo Carvalho de Melo ipv6_addr_copy(&fl.fl6_dst, final_p); 638b9750ce1SArnaldo Carvalho de Melo 639b9750ce1SArnaldo Carvalho de Melo if ((err = xfrm_lookup(&dst, &fl, sk, 0)) < 0) { 640b9750ce1SArnaldo Carvalho de Melo sk->sk_err_soft = -err; 641b9750ce1SArnaldo Carvalho de Melo return err; 642b9750ce1SArnaldo Carvalho de Melo } 643b9750ce1SArnaldo Carvalho de Melo 6448e1ef0a9SYOSHIFUJI Hideaki __ip6_dst_store(sk, dst, NULL, NULL); 645b9750ce1SArnaldo Carvalho de Melo } 646b9750ce1SArnaldo Carvalho de Melo 647b9750ce1SArnaldo Carvalho de Melo return 0; 648b9750ce1SArnaldo Carvalho de Melo } 649b9750ce1SArnaldo Carvalho de Melo 650b9750ce1SArnaldo Carvalho de Melo EXPORT_SYMBOL_GPL(inet6_sk_rebuild_header); 651b9750ce1SArnaldo Carvalho de Melo 652399c07deSArnaldo Carvalho de Melo int ipv6_opt_accepted(struct sock *sk, struct sk_buff *skb) 653399c07deSArnaldo Carvalho de Melo { 654399c07deSArnaldo Carvalho de Melo struct ipv6_pinfo *np = inet6_sk(sk); 655399c07deSArnaldo Carvalho de Melo struct inet6_skb_parm *opt = IP6CB(skb); 656399c07deSArnaldo Carvalho de Melo 657399c07deSArnaldo Carvalho de Melo if (np->rxopt.all) { 658399c07deSArnaldo Carvalho de Melo if ((opt->hop && (np->rxopt.bits.hopopts || 659399c07deSArnaldo Carvalho de Melo np->rxopt.bits.ohopopts)) || 660d56f90a7SArnaldo Carvalho de Melo ((IPV6_FLOWINFO_MASK & 661d56f90a7SArnaldo Carvalho de Melo *(__be32 *)skb_network_header(skb)) && 662399c07deSArnaldo Carvalho de Melo np->rxopt.bits.rxflow) || 663399c07deSArnaldo Carvalho de Melo (opt->srcrt && (np->rxopt.bits.srcrt || 664399c07deSArnaldo Carvalho de Melo np->rxopt.bits.osrcrt)) || 665399c07deSArnaldo Carvalho de Melo ((opt->dst1 || opt->dst0) && 666399c07deSArnaldo Carvalho de Melo (np->rxopt.bits.dstopts || np->rxopt.bits.odstopts))) 667399c07deSArnaldo Carvalho de Melo return 1; 668399c07deSArnaldo Carvalho de Melo } 669399c07deSArnaldo Carvalho de Melo return 0; 670399c07deSArnaldo Carvalho de Melo } 671399c07deSArnaldo Carvalho de Melo 672399c07deSArnaldo Carvalho de Melo EXPORT_SYMBOL_GPL(ipv6_opt_accepted); 673399c07deSArnaldo Carvalho de Melo 674662397fdSYOSHIFUJI Hideaki static struct inet6_protocol *ipv6_gso_pull_exthdrs(struct sk_buff *skb, 675662397fdSYOSHIFUJI Hideaki int proto) 676662397fdSYOSHIFUJI Hideaki { 677662397fdSYOSHIFUJI Hideaki struct inet6_protocol *ops = NULL; 678662397fdSYOSHIFUJI Hideaki 679662397fdSYOSHIFUJI Hideaki for (;;) { 680662397fdSYOSHIFUJI Hideaki struct ipv6_opt_hdr *opth; 681662397fdSYOSHIFUJI Hideaki int len; 682662397fdSYOSHIFUJI Hideaki 683662397fdSYOSHIFUJI Hideaki if (proto != NEXTHDR_HOP) { 684662397fdSYOSHIFUJI Hideaki ops = rcu_dereference(inet6_protos[proto]); 685662397fdSYOSHIFUJI Hideaki 686662397fdSYOSHIFUJI Hideaki if (unlikely(!ops)) 687662397fdSYOSHIFUJI Hideaki break; 688662397fdSYOSHIFUJI Hideaki 689662397fdSYOSHIFUJI Hideaki if (!(ops->flags & INET6_PROTO_GSO_EXTHDR)) 690662397fdSYOSHIFUJI Hideaki break; 691662397fdSYOSHIFUJI Hideaki } 692662397fdSYOSHIFUJI Hideaki 693662397fdSYOSHIFUJI Hideaki if (unlikely(!pskb_may_pull(skb, 8))) 694662397fdSYOSHIFUJI Hideaki break; 695662397fdSYOSHIFUJI Hideaki 696662397fdSYOSHIFUJI Hideaki opth = (void *)skb->data; 697662397fdSYOSHIFUJI Hideaki len = ipv6_optlen(opth); 698662397fdSYOSHIFUJI Hideaki 699662397fdSYOSHIFUJI Hideaki if (unlikely(!pskb_may_pull(skb, len))) 700662397fdSYOSHIFUJI Hideaki break; 701662397fdSYOSHIFUJI Hideaki 702662397fdSYOSHIFUJI Hideaki proto = opth->nexthdr; 703662397fdSYOSHIFUJI Hideaki __skb_pull(skb, len); 704662397fdSYOSHIFUJI Hideaki } 705662397fdSYOSHIFUJI Hideaki 706662397fdSYOSHIFUJI Hideaki return ops; 707662397fdSYOSHIFUJI Hideaki } 708662397fdSYOSHIFUJI Hideaki 709662397fdSYOSHIFUJI Hideaki static int ipv6_gso_send_check(struct sk_buff *skb) 710662397fdSYOSHIFUJI Hideaki { 711662397fdSYOSHIFUJI Hideaki struct ipv6hdr *ipv6h; 712662397fdSYOSHIFUJI Hideaki struct inet6_protocol *ops; 713662397fdSYOSHIFUJI Hideaki int err = -EINVAL; 714662397fdSYOSHIFUJI Hideaki 715662397fdSYOSHIFUJI Hideaki if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h)))) 716662397fdSYOSHIFUJI Hideaki goto out; 717662397fdSYOSHIFUJI Hideaki 718662397fdSYOSHIFUJI Hideaki ipv6h = ipv6_hdr(skb); 719662397fdSYOSHIFUJI Hideaki __skb_pull(skb, sizeof(*ipv6h)); 720662397fdSYOSHIFUJI Hideaki err = -EPROTONOSUPPORT; 721662397fdSYOSHIFUJI Hideaki 722662397fdSYOSHIFUJI Hideaki rcu_read_lock(); 723662397fdSYOSHIFUJI Hideaki ops = ipv6_gso_pull_exthdrs(skb, ipv6h->nexthdr); 724662397fdSYOSHIFUJI Hideaki if (likely(ops && ops->gso_send_check)) { 725662397fdSYOSHIFUJI Hideaki skb_reset_transport_header(skb); 726662397fdSYOSHIFUJI Hideaki err = ops->gso_send_check(skb); 727662397fdSYOSHIFUJI Hideaki } 728662397fdSYOSHIFUJI Hideaki rcu_read_unlock(); 729662397fdSYOSHIFUJI Hideaki 730662397fdSYOSHIFUJI Hideaki out: 731662397fdSYOSHIFUJI Hideaki return err; 732662397fdSYOSHIFUJI Hideaki } 733662397fdSYOSHIFUJI Hideaki 734662397fdSYOSHIFUJI Hideaki static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb, int features) 735662397fdSYOSHIFUJI Hideaki { 736662397fdSYOSHIFUJI Hideaki struct sk_buff *segs = ERR_PTR(-EINVAL); 737662397fdSYOSHIFUJI Hideaki struct ipv6hdr *ipv6h; 738662397fdSYOSHIFUJI Hideaki struct inet6_protocol *ops; 739662397fdSYOSHIFUJI Hideaki 740662397fdSYOSHIFUJI Hideaki if (!(features & NETIF_F_V6_CSUM)) 741662397fdSYOSHIFUJI Hideaki features &= ~NETIF_F_SG; 742662397fdSYOSHIFUJI Hideaki 743662397fdSYOSHIFUJI Hideaki if (unlikely(skb_shinfo(skb)->gso_type & 744662397fdSYOSHIFUJI Hideaki ~(SKB_GSO_UDP | 745662397fdSYOSHIFUJI Hideaki SKB_GSO_DODGY | 746662397fdSYOSHIFUJI Hideaki SKB_GSO_TCP_ECN | 747662397fdSYOSHIFUJI Hideaki SKB_GSO_TCPV6 | 748662397fdSYOSHIFUJI Hideaki 0))) 749662397fdSYOSHIFUJI Hideaki goto out; 750662397fdSYOSHIFUJI Hideaki 751662397fdSYOSHIFUJI Hideaki if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h)))) 752662397fdSYOSHIFUJI Hideaki goto out; 753662397fdSYOSHIFUJI Hideaki 754662397fdSYOSHIFUJI Hideaki ipv6h = ipv6_hdr(skb); 755662397fdSYOSHIFUJI Hideaki __skb_pull(skb, sizeof(*ipv6h)); 756662397fdSYOSHIFUJI Hideaki segs = ERR_PTR(-EPROTONOSUPPORT); 757662397fdSYOSHIFUJI Hideaki 758662397fdSYOSHIFUJI Hideaki rcu_read_lock(); 759662397fdSYOSHIFUJI Hideaki ops = ipv6_gso_pull_exthdrs(skb, ipv6h->nexthdr); 760662397fdSYOSHIFUJI Hideaki if (likely(ops && ops->gso_segment)) { 761662397fdSYOSHIFUJI Hideaki skb_reset_transport_header(skb); 762662397fdSYOSHIFUJI Hideaki segs = ops->gso_segment(skb, features); 763662397fdSYOSHIFUJI Hideaki } 764662397fdSYOSHIFUJI Hideaki rcu_read_unlock(); 765662397fdSYOSHIFUJI Hideaki 766662397fdSYOSHIFUJI Hideaki if (unlikely(IS_ERR(segs))) 767662397fdSYOSHIFUJI Hideaki goto out; 768662397fdSYOSHIFUJI Hideaki 769662397fdSYOSHIFUJI Hideaki for (skb = segs; skb; skb = skb->next) { 770662397fdSYOSHIFUJI Hideaki ipv6h = ipv6_hdr(skb); 771662397fdSYOSHIFUJI Hideaki ipv6h->payload_len = htons(skb->len - skb->mac_len - 772662397fdSYOSHIFUJI Hideaki sizeof(*ipv6h)); 773662397fdSYOSHIFUJI Hideaki } 774662397fdSYOSHIFUJI Hideaki 775662397fdSYOSHIFUJI Hideaki out: 776662397fdSYOSHIFUJI Hideaki return segs; 777662397fdSYOSHIFUJI Hideaki } 778662397fdSYOSHIFUJI Hideaki 779662397fdSYOSHIFUJI Hideaki static struct packet_type ipv6_packet_type = { 780662397fdSYOSHIFUJI Hideaki .type = __constant_htons(ETH_P_IPV6), 781662397fdSYOSHIFUJI Hideaki .func = ipv6_rcv, 782662397fdSYOSHIFUJI Hideaki .gso_send_check = ipv6_gso_send_check, 783662397fdSYOSHIFUJI Hideaki .gso_segment = ipv6_gso_segment, 784662397fdSYOSHIFUJI Hideaki }; 785662397fdSYOSHIFUJI Hideaki 786662397fdSYOSHIFUJI Hideaki static int __init ipv6_packet_init(void) 787662397fdSYOSHIFUJI Hideaki { 788662397fdSYOSHIFUJI Hideaki dev_add_pack(&ipv6_packet_type); 789662397fdSYOSHIFUJI Hideaki return 0; 790662397fdSYOSHIFUJI Hideaki } 791662397fdSYOSHIFUJI Hideaki 792662397fdSYOSHIFUJI Hideaki static void ipv6_packet_cleanup(void) 793662397fdSYOSHIFUJI Hideaki { 794662397fdSYOSHIFUJI Hideaki dev_remove_pack(&ipv6_packet_type); 795662397fdSYOSHIFUJI Hideaki } 796662397fdSYOSHIFUJI Hideaki 7971da177e4SLinus Torvalds static int __init init_ipv6_mibs(void) 7981da177e4SLinus Torvalds { 799c69bce20SYOSHIFUJI Hideaki if (snmp_mib_init((void **)ipv6_statistics, 800c69bce20SYOSHIFUJI Hideaki sizeof(struct ipstats_mib)) < 0) 8011da177e4SLinus Torvalds goto err_ip_mib; 802c69bce20SYOSHIFUJI Hideaki if (snmp_mib_init((void **)icmpv6_statistics, 803c69bce20SYOSHIFUJI Hideaki sizeof(struct icmpv6_mib)) < 0) 8041da177e4SLinus Torvalds goto err_icmp_mib; 80514878f75SDavid L Stevens if (snmp_mib_init((void **)icmpv6msg_statistics, 806c69bce20SYOSHIFUJI Hideaki sizeof(struct icmpv6msg_mib)) < 0) 80714878f75SDavid L Stevens goto err_icmpmsg_mib; 808c69bce20SYOSHIFUJI Hideaki if (snmp_mib_init((void **)udp_stats_in6, sizeof (struct udp_mib)) < 0) 8091da177e4SLinus Torvalds goto err_udp_mib; 810c69bce20SYOSHIFUJI Hideaki if (snmp_mib_init((void **)udplite_stats_in6, 811c69bce20SYOSHIFUJI Hideaki sizeof (struct udp_mib)) < 0) 812ba4e58ecSGerrit Renker goto err_udplite_mib; 8131da177e4SLinus Torvalds return 0; 8141da177e4SLinus Torvalds 815ba4e58ecSGerrit Renker err_udplite_mib: 8167f7d9a6bSHerbert Xu snmp_mib_free((void **)udp_stats_in6); 8171da177e4SLinus Torvalds err_udp_mib: 81814878f75SDavid L Stevens snmp_mib_free((void **)icmpv6msg_statistics); 81914878f75SDavid L Stevens err_icmpmsg_mib: 8207f7d9a6bSHerbert Xu snmp_mib_free((void **)icmpv6_statistics); 8211da177e4SLinus Torvalds err_icmp_mib: 8227f7d9a6bSHerbert Xu snmp_mib_free((void **)ipv6_statistics); 8231da177e4SLinus Torvalds err_ip_mib: 8241da177e4SLinus Torvalds return -ENOMEM; 8251da177e4SLinus Torvalds 8261da177e4SLinus Torvalds } 8271da177e4SLinus Torvalds 8281da177e4SLinus Torvalds static void cleanup_ipv6_mibs(void) 8291da177e4SLinus Torvalds { 8307f7d9a6bSHerbert Xu snmp_mib_free((void **)ipv6_statistics); 8317f7d9a6bSHerbert Xu snmp_mib_free((void **)icmpv6_statistics); 832dc8a82adSPavel Emelyanov snmp_mib_free((void **)icmpv6msg_statistics); 8337f7d9a6bSHerbert Xu snmp_mib_free((void **)udp_stats_in6); 8347f7d9a6bSHerbert Xu snmp_mib_free((void **)udplite_stats_in6); 8351da177e4SLinus Torvalds } 8361da177e4SLinus Torvalds 83781c1c178SDaniel Lezcano static int inet6_net_init(struct net *net) 83881c1c178SDaniel Lezcano { 8390c96d8c5SDaniel Lezcano int err = 0; 8400c96d8c5SDaniel Lezcano 84199bc9c4eSDaniel Lezcano net->ipv6.sysctl.bindv6only = 0; 8424990509fSDaniel Lezcano net->ipv6.sysctl.flush_delay = 0; 8434990509fSDaniel Lezcano net->ipv6.sysctl.ip6_rt_max_size = 4096; 8444990509fSDaniel Lezcano net->ipv6.sysctl.ip6_rt_gc_min_interval = HZ / 2; 8454990509fSDaniel Lezcano net->ipv6.sysctl.ip6_rt_gc_timeout = 60*HZ; 8464990509fSDaniel Lezcano net->ipv6.sysctl.ip6_rt_gc_interval = 30*HZ; 8474990509fSDaniel Lezcano net->ipv6.sysctl.ip6_rt_gc_elasticity = 9; 8484990509fSDaniel Lezcano net->ipv6.sysctl.ip6_rt_mtu_expires = 10*60*HZ; 8494990509fSDaniel Lezcano net->ipv6.sysctl.ip6_rt_min_advmss = IPV6_MIN_MTU - 20 - 40; 85041a76906SDaniel Lezcano net->ipv6.sysctl.icmpv6_time = 1*HZ; 851e71e0349SDaniel Lezcano 8520c96d8c5SDaniel Lezcano #ifdef CONFIG_PROC_FS 8530c96d8c5SDaniel Lezcano err = udp6_proc_init(net); 8540c96d8c5SDaniel Lezcano if (err) 8550c96d8c5SDaniel Lezcano goto out; 8566f8b13bcSDaniel Lezcano err = tcp6_proc_init(net); 8576f8b13bcSDaniel Lezcano if (err) 8586f8b13bcSDaniel Lezcano goto proc_tcp6_fail; 8596ab57e7eSDaniel Lezcano err = ac6_proc_init(net); 8606ab57e7eSDaniel Lezcano if (err) 8616ab57e7eSDaniel Lezcano goto proc_ac6_fail; 8620c96d8c5SDaniel Lezcano out: 8630c96d8c5SDaniel Lezcano #endif 8640c96d8c5SDaniel Lezcano return err; 8656f8b13bcSDaniel Lezcano 8666f8b13bcSDaniel Lezcano #ifdef CONFIG_PROC_FS 8676ab57e7eSDaniel Lezcano proc_ac6_fail: 8686ab57e7eSDaniel Lezcano tcp6_proc_exit(net); 8696f8b13bcSDaniel Lezcano proc_tcp6_fail: 8706f8b13bcSDaniel Lezcano udp6_proc_exit(net); 8716f8b13bcSDaniel Lezcano goto out; 8726f8b13bcSDaniel Lezcano #endif 87381c1c178SDaniel Lezcano } 87481c1c178SDaniel Lezcano 87581c1c178SDaniel Lezcano static void inet6_net_exit(struct net *net) 87681c1c178SDaniel Lezcano { 8770c96d8c5SDaniel Lezcano #ifdef CONFIG_PROC_FS 8780c96d8c5SDaniel Lezcano udp6_proc_exit(net); 8796f8b13bcSDaniel Lezcano tcp6_proc_exit(net); 8806ab57e7eSDaniel Lezcano ac6_proc_exit(net); 8810c96d8c5SDaniel Lezcano #endif 88281c1c178SDaniel Lezcano } 88381c1c178SDaniel Lezcano 88481c1c178SDaniel Lezcano static struct pernet_operations inet6_net_ops = { 88581c1c178SDaniel Lezcano .init = inet6_net_init, 88681c1c178SDaniel Lezcano .exit = inet6_net_exit, 88781c1c178SDaniel Lezcano }; 88881c1c178SDaniel Lezcano 8891da177e4SLinus Torvalds static int __init inet6_init(void) 8901da177e4SLinus Torvalds { 8911da177e4SLinus Torvalds struct sk_buff *dummy_skb; 8921da177e4SLinus Torvalds struct list_head *r; 8931da177e4SLinus Torvalds int err; 8941da177e4SLinus Torvalds 895ef047f5eSYOSHIFUJI Hideaki BUILD_BUG_ON(sizeof(struct inet6_skb_parm) > sizeof(dummy_skb->cb)); 896ef047f5eSYOSHIFUJI Hideaki 8971da177e4SLinus Torvalds err = proto_register(&tcpv6_prot, 1); 8981da177e4SLinus Torvalds if (err) 8991da177e4SLinus Torvalds goto out; 9001da177e4SLinus Torvalds 9011da177e4SLinus Torvalds err = proto_register(&udpv6_prot, 1); 9021da177e4SLinus Torvalds if (err) 9031da177e4SLinus Torvalds goto out_unregister_tcp_proto; 9041da177e4SLinus Torvalds 905ba4e58ecSGerrit Renker err = proto_register(&udplitev6_prot, 1); 9061da177e4SLinus Torvalds if (err) 9071da177e4SLinus Torvalds goto out_unregister_udp_proto; 9081da177e4SLinus Torvalds 909ba4e58ecSGerrit Renker err = proto_register(&rawv6_prot, 1); 910ba4e58ecSGerrit Renker if (err) 911ba4e58ecSGerrit Renker goto out_unregister_udplite_proto; 912ba4e58ecSGerrit Renker 9131da177e4SLinus Torvalds 9141da177e4SLinus Torvalds /* Register the socket-side information for inet6_create. */ 9151da177e4SLinus Torvalds for(r = &inetsw6[0]; r < &inetsw6[SOCK_MAX]; ++r) 9161da177e4SLinus Torvalds INIT_LIST_HEAD(r); 9171da177e4SLinus Torvalds 9181da177e4SLinus Torvalds /* We MUST register RAW sockets before we create the ICMP6, 9191da177e4SLinus Torvalds * IGMP6, or NDISC control sockets. 9201da177e4SLinus Torvalds */ 9217f4e4868SDaniel Lezcano err = rawv6_init(); 9227f4e4868SDaniel Lezcano if (err) 9237f4e4868SDaniel Lezcano goto out_unregister_raw_proto; 9241da177e4SLinus Torvalds 9251da177e4SLinus Torvalds /* Register the family here so that the init calls below will 9261da177e4SLinus Torvalds * be able to create sockets. (?? is this dangerous ??) 9271da177e4SLinus Torvalds */ 9288eb55910SDavid S. Miller err = sock_register(&inet6_family_ops); 9298eb55910SDavid S. Miller if (err) 9307f4e4868SDaniel Lezcano goto out_sock_register_fail; 9311da177e4SLinus Torvalds 9321da177e4SLinus Torvalds /* Initialise ipv6 mibs */ 9331da177e4SLinus Torvalds err = init_ipv6_mibs(); 9341da177e4SLinus Torvalds if (err) 9358eb55910SDavid S. Miller goto out_unregister_sock; 9361da177e4SLinus Torvalds 9371da177e4SLinus Torvalds /* 9381da177e4SLinus Torvalds * ipngwg API draft makes clear that the correct semantics 9391da177e4SLinus Torvalds * for TCP and UDP is to consider one TCP and UDP instance 9401da177e4SLinus Torvalds * in a host availiable by both INET and INET6 APIs and 9411da177e4SLinus Torvalds * able to communicate via both network protocols. 9421da177e4SLinus Torvalds */ 9431da177e4SLinus Torvalds 94481c1c178SDaniel Lezcano err = register_pernet_subsys(&inet6_net_ops); 94581c1c178SDaniel Lezcano if (err) 94681c1c178SDaniel Lezcano goto register_pernet_fail; 9479b0f976fSDenis V. Lunev err = icmpv6_init(); 9481da177e4SLinus Torvalds if (err) 9491da177e4SLinus Torvalds goto icmp_fail; 950623d1a1aSWang Chen err = ip6_mr_init(); 951623d1a1aSWang Chen if (err) 952623d1a1aSWang Chen goto ipmr_fail; 9539b0f976fSDenis V. Lunev err = ndisc_init(); 9541da177e4SLinus Torvalds if (err) 9551da177e4SLinus Torvalds goto ndisc_fail; 9569b0f976fSDenis V. Lunev err = igmp6_init(); 9571da177e4SLinus Torvalds if (err) 9581da177e4SLinus Torvalds goto igmp_fail; 9592cc7d573SHarald Welte err = ipv6_netfilter_init(); 9602cc7d573SHarald Welte if (err) 9612cc7d573SHarald Welte goto netfilter_fail; 9621da177e4SLinus Torvalds /* Create /proc/foo6 entries. */ 9631da177e4SLinus Torvalds #ifdef CONFIG_PROC_FS 9641da177e4SLinus Torvalds err = -ENOMEM; 9651da177e4SLinus Torvalds if (raw6_proc_init()) 9661da177e4SLinus Torvalds goto proc_raw6_fail; 967ba4e58ecSGerrit Renker if (udplite6_proc_init()) 968ba4e58ecSGerrit Renker goto proc_udplite6_fail; 9691da177e4SLinus Torvalds if (ipv6_misc_proc_init()) 9701da177e4SLinus Torvalds goto proc_misc6_fail; 9711da177e4SLinus Torvalds if (if6_proc_init()) 9721da177e4SLinus Torvalds goto proc_if6_fail; 9731da177e4SLinus Torvalds #endif 974e2fddf5eSDaniel Lezcano err = ip6_route_init(); 975e2fddf5eSDaniel Lezcano if (err) 976e2fddf5eSDaniel Lezcano goto ip6_route_fail; 9770a3e78acSDaniel Lezcano err = ip6_flowlabel_init(); 9780a3e78acSDaniel Lezcano if (err) 9790a3e78acSDaniel Lezcano goto ip6_flowlabel_fail; 9801da177e4SLinus Torvalds err = addrconf_init(); 9811da177e4SLinus Torvalds if (err) 9821da177e4SLinus Torvalds goto addrconf_fail; 9831da177e4SLinus Torvalds 9841da177e4SLinus Torvalds /* Init v6 extension headers. */ 985248b238dSDaniel Lezcano err = ipv6_exthdrs_init(); 986248b238dSDaniel Lezcano if (err) 987248b238dSDaniel Lezcano goto ipv6_exthdrs_fail; 988248b238dSDaniel Lezcano 989853cbbaaSDaniel Lezcano err = ipv6_frag_init(); 990853cbbaaSDaniel Lezcano if (err) 991853cbbaaSDaniel Lezcano goto ipv6_frag_fail; 9921da177e4SLinus Torvalds 9931da177e4SLinus Torvalds /* Init v6 transport protocols. */ 9947f4e4868SDaniel Lezcano err = udpv6_init(); 9957f4e4868SDaniel Lezcano if (err) 9967f4e4868SDaniel Lezcano goto udpv6_fail; 997e2ed4052SHerbert Xu 9987f4e4868SDaniel Lezcano err = udplitev6_init(); 9997f4e4868SDaniel Lezcano if (err) 10007f4e4868SDaniel Lezcano goto udplitev6_fail; 10017f4e4868SDaniel Lezcano 10027f4e4868SDaniel Lezcano err = tcpv6_init(); 10037f4e4868SDaniel Lezcano if (err) 10047f4e4868SDaniel Lezcano goto tcpv6_fail; 10057f4e4868SDaniel Lezcano 10067f4e4868SDaniel Lezcano err = ipv6_packet_init(); 10077f4e4868SDaniel Lezcano if (err) 10087f4e4868SDaniel Lezcano goto ipv6_packet_fail; 100994911fe3SBenjamin Thery 101094911fe3SBenjamin Thery #ifdef CONFIG_SYSCTL 101194911fe3SBenjamin Thery err = ipv6_sysctl_register(); 101294911fe3SBenjamin Thery if (err) 101394911fe3SBenjamin Thery goto sysctl_fail; 101494911fe3SBenjamin Thery #endif 10151da177e4SLinus Torvalds out: 10161da177e4SLinus Torvalds return err; 10171da177e4SLinus Torvalds 101894911fe3SBenjamin Thery #ifdef CONFIG_SYSCTL 101994911fe3SBenjamin Thery sysctl_fail: 102094911fe3SBenjamin Thery ipv6_packet_cleanup(); 102194911fe3SBenjamin Thery #endif 10227f4e4868SDaniel Lezcano ipv6_packet_fail: 10237f4e4868SDaniel Lezcano tcpv6_exit(); 10247f4e4868SDaniel Lezcano tcpv6_fail: 10257f4e4868SDaniel Lezcano udplitev6_exit(); 10267f4e4868SDaniel Lezcano udplitev6_fail: 10277f4e4868SDaniel Lezcano udpv6_exit(); 10287f4e4868SDaniel Lezcano udpv6_fail: 10297f4e4868SDaniel Lezcano ipv6_frag_exit(); 1030853cbbaaSDaniel Lezcano ipv6_frag_fail: 1031853cbbaaSDaniel Lezcano ipv6_exthdrs_exit(); 1032248b238dSDaniel Lezcano ipv6_exthdrs_fail: 1033248b238dSDaniel Lezcano addrconf_cleanup(); 10341da177e4SLinus Torvalds addrconf_fail: 10351da177e4SLinus Torvalds ip6_flowlabel_cleanup(); 10360a3e78acSDaniel Lezcano ip6_flowlabel_fail: 10371da177e4SLinus Torvalds ip6_route_cleanup(); 1038e2fddf5eSDaniel Lezcano ip6_route_fail: 10391da177e4SLinus Torvalds #ifdef CONFIG_PROC_FS 10401da177e4SLinus Torvalds if6_proc_exit(); 10411da177e4SLinus Torvalds proc_if6_fail: 10421da177e4SLinus Torvalds ipv6_misc_proc_exit(); 10431da177e4SLinus Torvalds proc_misc6_fail: 1044ba4e58ecSGerrit Renker udplite6_proc_exit(); 1045ba4e58ecSGerrit Renker proc_udplite6_fail: 10461da177e4SLinus Torvalds raw6_proc_exit(); 10471da177e4SLinus Torvalds proc_raw6_fail: 10481da177e4SLinus Torvalds #endif 10492cc7d573SHarald Welte ipv6_netfilter_fini(); 10502cc7d573SHarald Welte netfilter_fail: 10511da177e4SLinus Torvalds igmp6_cleanup(); 10521da177e4SLinus Torvalds igmp_fail: 10531da177e4SLinus Torvalds ndisc_cleanup(); 10541da177e4SLinus Torvalds ndisc_fail: 1055623d1a1aSWang Chen ip6_mr_cleanup(); 1056623d1a1aSWang Chen ipmr_fail: 10571da177e4SLinus Torvalds icmpv6_cleanup(); 10581da177e4SLinus Torvalds icmp_fail: 105981c1c178SDaniel Lezcano unregister_pernet_subsys(&inet6_net_ops); 106081c1c178SDaniel Lezcano register_pernet_fail: 10611da177e4SLinus Torvalds cleanup_ipv6_mibs(); 10628eb55910SDavid S. Miller out_unregister_sock: 10638eb55910SDavid S. Miller sock_unregister(PF_INET6); 1064e2fddf5eSDaniel Lezcano rtnl_unregister_all(PF_INET6); 10657f4e4868SDaniel Lezcano out_sock_register_fail: 10667f4e4868SDaniel Lezcano rawv6_exit(); 10671da177e4SLinus Torvalds out_unregister_raw_proto: 10681da177e4SLinus Torvalds proto_unregister(&rawv6_prot); 1069ba4e58ecSGerrit Renker out_unregister_udplite_proto: 1070ba4e58ecSGerrit Renker proto_unregister(&udplitev6_prot); 10711da177e4SLinus Torvalds out_unregister_udp_proto: 10721da177e4SLinus Torvalds proto_unregister(&udpv6_prot); 10731da177e4SLinus Torvalds out_unregister_tcp_proto: 10741da177e4SLinus Torvalds proto_unregister(&tcpv6_prot); 10751da177e4SLinus Torvalds goto out; 10761da177e4SLinus Torvalds } 10771da177e4SLinus Torvalds module_init(inet6_init); 10781da177e4SLinus Torvalds 10791da177e4SLinus Torvalds static void __exit inet6_exit(void) 10801da177e4SLinus Torvalds { 10811da177e4SLinus Torvalds /* First of all disallow new sockets creation. */ 10821da177e4SLinus Torvalds sock_unregister(PF_INET6); 1083c127ea2cSThomas Graf /* Disallow any further netlink messages */ 1084c127ea2cSThomas Graf rtnl_unregister_all(PF_INET6); 1085ca17c233SJoe Jin 108694911fe3SBenjamin Thery #ifdef CONFIG_SYSCTL 108794911fe3SBenjamin Thery ipv6_sysctl_unregister(); 108894911fe3SBenjamin Thery #endif 10897f4e4868SDaniel Lezcano udpv6_exit(); 10907f4e4868SDaniel Lezcano udplitev6_exit(); 10917f4e4868SDaniel Lezcano tcpv6_exit(); 10927f4e4868SDaniel Lezcano 1093ca17c233SJoe Jin /* Cleanup code parts. */ 1094ca17c233SJoe Jin ipv6_packet_cleanup(); 1095853cbbaaSDaniel Lezcano ipv6_frag_exit(); 1096248b238dSDaniel Lezcano ipv6_exthdrs_exit(); 10971da177e4SLinus Torvalds addrconf_cleanup(); 1098ca17c233SJoe Jin ip6_flowlabel_cleanup(); 10991da177e4SLinus Torvalds ip6_route_cleanup(); 1100ca17c233SJoe Jin #ifdef CONFIG_PROC_FS 1101ca17c233SJoe Jin 1102ca17c233SJoe Jin /* Cleanup code parts. */ 1103ca17c233SJoe Jin if6_proc_exit(); 1104ca17c233SJoe Jin ipv6_misc_proc_exit(); 1105ca17c233SJoe Jin udplite6_proc_exit(); 1106ca17c233SJoe Jin raw6_proc_exit(); 1107ca17c233SJoe Jin #endif 11082cc7d573SHarald Welte ipv6_netfilter_fini(); 1109ca17c233SJoe Jin igmp6_cleanup(); 11101da177e4SLinus Torvalds ndisc_cleanup(); 1111623d1a1aSWang Chen ip6_mr_cleanup(); 11121da177e4SLinus Torvalds icmpv6_cleanup(); 11137f4e4868SDaniel Lezcano rawv6_exit(); 111494911fe3SBenjamin Thery 111581c1c178SDaniel Lezcano unregister_pernet_subsys(&inet6_net_ops); 11161da177e4SLinus Torvalds cleanup_ipv6_mibs(); 11171da177e4SLinus Torvalds proto_unregister(&rawv6_prot); 1118ca17c233SJoe Jin proto_unregister(&udplitev6_prot); 11191da177e4SLinus Torvalds proto_unregister(&udpv6_prot); 11201da177e4SLinus Torvalds proto_unregister(&tcpv6_prot); 11211da177e4SLinus Torvalds } 11221da177e4SLinus Torvalds module_exit(inet6_exit); 11231da177e4SLinus Torvalds 11241da177e4SLinus Torvalds MODULE_ALIAS_NETPROTO(PF_INET6); 1125