Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * PF_INET6 socket protocol family |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 3 | * Linux INET6 implementation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * Authors: |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 6 | * Pedro Roque <roque@di.fc.ul.pt> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * Adapted from linux/net/ipv4/af_inet.c |
| 9 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * Fixes: |
| 11 | * piggy, Karl Knutson : Socket protocol table |
| 12 | * Hideaki YOSHIFUJI : sin6_scope_id support |
| 13 | * Arnaldo Melo : check proc_net_create return, cleanups |
| 14 | * |
| 15 | * This program is free software; you can redistribute it and/or |
| 16 | * modify it under the terms of the GNU General Public License |
| 17 | * as published by the Free Software Foundation; either version |
| 18 | * 2 of the License, or (at your option) any later version. |
| 19 | */ |
| 20 | |
| 21 | |
| 22 | #include <linux/module.h> |
Randy Dunlap | 4fc268d | 2006-01-11 12:17:47 -0800 | [diff] [blame] | 23 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/errno.h> |
| 25 | #include <linux/types.h> |
| 26 | #include <linux/socket.h> |
| 27 | #include <linux/in.h> |
| 28 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/timer.h> |
| 30 | #include <linux/string.h> |
| 31 | #include <linux/sockios.h> |
| 32 | #include <linux/net.h> |
| 33 | #include <linux/fcntl.h> |
| 34 | #include <linux/mm.h> |
| 35 | #include <linux/interrupt.h> |
| 36 | #include <linux/proc_fs.h> |
| 37 | #include <linux/stat.h> |
| 38 | #include <linux/init.h> |
| 39 | |
| 40 | #include <linux/inet.h> |
| 41 | #include <linux/netdevice.h> |
| 42 | #include <linux/icmpv6.h> |
Harald Welte | 2cc7d57 | 2005-08-09 19:42:34 -0700 | [diff] [blame] | 43 | #include <linux/netfilter_ipv6.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
| 45 | #include <net/ip.h> |
| 46 | #include <net/ipv6.h> |
| 47 | #include <net/udp.h> |
Gerrit Renker | ba4e58e | 2006-11-27 11:10:57 -0800 | [diff] [blame] | 48 | #include <net/udplite.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #include <net/tcp.h> |
| 50 | #include <net/ipip.h> |
| 51 | #include <net/protocol.h> |
| 52 | #include <net/inet_common.h> |
| 53 | #include <net/transp_v6.h> |
| 54 | #include <net/ip6_route.h> |
| 55 | #include <net/addrconf.h> |
| 56 | #ifdef CONFIG_IPV6_TUNNEL |
| 57 | #include <net/ip6_tunnel.h> |
| 58 | #endif |
| 59 | |
| 60 | #include <asm/uaccess.h> |
| 61 | #include <asm/system.h> |
YOSHIFUJI Hideaki | 7bc570c | 2008-04-03 09:22:53 +0900 | [diff] [blame] | 62 | #include <linux/mroute6.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | MODULE_AUTHOR("Cast of dozens"); |
| 65 | MODULE_DESCRIPTION("IPv6 protocol stack for Linux"); |
| 66 | MODULE_LICENSE("GPL"); |
| 67 | |
Pavel Emelyanov | f126734 | 2007-11-23 21:28:44 +0800 | [diff] [blame] | 68 | /* The inetsw6 table contains everything that inet6_create needs to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | * build a new socket. |
| 70 | */ |
| 71 | static struct list_head inetsw6[SOCK_MAX]; |
| 72 | static DEFINE_SPINLOCK(inetsw6_lock); |
| 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | static __inline__ struct ipv6_pinfo *inet6_sk_generic(struct sock *sk) |
| 75 | { |
| 76 | const int offset = sk->sk_prot->obj_size - sizeof(struct ipv6_pinfo); |
| 77 | |
| 78 | return (struct ipv6_pinfo *)(((u8 *)sk) + offset); |
| 79 | } |
| 80 | |
Eric W. Biederman | 1b8d7ae | 2007-10-08 23:24:22 -0700 | [diff] [blame] | 81 | static int inet6_create(struct net *net, struct socket *sock, int protocol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | { |
| 83 | struct inet_sock *inet; |
| 84 | struct ipv6_pinfo *np; |
| 85 | struct sock *sk; |
| 86 | struct list_head *p; |
| 87 | struct inet_protosw *answer; |
| 88 | struct proto *answer_prot; |
| 89 | unsigned char answer_flags; |
| 90 | char answer_no_check; |
YOSHIFUJI Hideaki | af1afe8 | 2005-12-02 20:56:57 -0800 | [diff] [blame] | 91 | int try_loading_module = 0; |
| 92 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
David S. Miller | b3da2cf | 2007-03-23 11:40:27 -0700 | [diff] [blame] | 94 | if (sock->type != SOCK_RAW && |
| 95 | sock->type != SOCK_DGRAM && |
| 96 | !inet_ehash_secret) |
| 97 | build_ehash_secret(); |
| 98 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | /* Look for the requested type/protocol pair. */ |
| 100 | answer = NULL; |
YOSHIFUJI Hideaki | af1afe8 | 2005-12-02 20:56:57 -0800 | [diff] [blame] | 101 | lookup_protocol: |
| 102 | err = -ESOCKTNOSUPPORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | rcu_read_lock(); |
| 104 | list_for_each_rcu(p, &inetsw6[sock->type]) { |
| 105 | answer = list_entry(p, struct inet_protosw, list); |
| 106 | |
| 107 | /* Check the non-wild match. */ |
| 108 | if (protocol == answer->protocol) { |
| 109 | if (protocol != IPPROTO_IP) |
| 110 | break; |
| 111 | } else { |
| 112 | /* Check for the two wild cases. */ |
| 113 | if (IPPROTO_IP == protocol) { |
| 114 | protocol = answer->protocol; |
| 115 | break; |
| 116 | } |
| 117 | if (IPPROTO_IP == answer->protocol) |
| 118 | break; |
| 119 | } |
YOSHIFUJI Hideaki | af1afe8 | 2005-12-02 20:56:57 -0800 | [diff] [blame] | 120 | err = -EPROTONOSUPPORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | answer = NULL; |
| 122 | } |
| 123 | |
YOSHIFUJI Hideaki | af1afe8 | 2005-12-02 20:56:57 -0800 | [diff] [blame] | 124 | if (!answer) { |
| 125 | if (try_loading_module < 2) { |
| 126 | rcu_read_unlock(); |
| 127 | /* |
| 128 | * Be more specific, e.g. net-pf-10-proto-132-type-1 |
| 129 | * (net-pf-PF_INET6-proto-IPPROTO_SCTP-type-SOCK_STREAM) |
| 130 | */ |
| 131 | if (++try_loading_module == 1) |
| 132 | request_module("net-pf-%d-proto-%d-type-%d", |
| 133 | PF_INET6, protocol, sock->type); |
| 134 | /* |
| 135 | * Fall back to generic, e.g. net-pf-10-proto-132 |
| 136 | * (net-pf-PF_INET6-proto-IPPROTO_SCTP) |
| 137 | */ |
| 138 | else |
| 139 | request_module("net-pf-%d-proto-%d", |
| 140 | PF_INET6, protocol); |
| 141 | goto lookup_protocol; |
| 142 | } else |
| 143 | goto out_rcu_unlock; |
| 144 | } |
| 145 | |
| 146 | err = -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | if (answer->capability > 0 && !capable(answer->capability)) |
| 148 | goto out_rcu_unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
| 150 | sock->ops = answer->ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | answer_prot = answer->prot; |
| 152 | answer_no_check = answer->no_check; |
| 153 | answer_flags = answer->flags; |
| 154 | rcu_read_unlock(); |
| 155 | |
| 156 | BUG_TRAP(answer_prot->slab != NULL); |
| 157 | |
YOSHIFUJI Hideaki | af1afe8 | 2005-12-02 20:56:57 -0800 | [diff] [blame] | 158 | err = -ENOBUFS; |
Pavel Emelyanov | 6257ff2 | 2007-11-01 00:39:31 -0700 | [diff] [blame] | 159 | sk = sk_alloc(net, PF_INET6, GFP_KERNEL, answer_prot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | if (sk == NULL) |
| 161 | goto out; |
| 162 | |
| 163 | sock_init_data(sock, sk); |
| 164 | |
YOSHIFUJI Hideaki | af1afe8 | 2005-12-02 20:56:57 -0800 | [diff] [blame] | 165 | err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | sk->sk_no_check = answer_no_check; |
| 167 | if (INET_PROTOSW_REUSE & answer_flags) |
| 168 | sk->sk_reuse = 1; |
| 169 | |
| 170 | inet = inet_sk(sk); |
Paul Moore | 469de9b | 2007-01-09 14:37:06 -0800 | [diff] [blame] | 171 | inet->is_icsk = (INET_PROTOSW_ICSK & answer_flags) != 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
| 173 | if (SOCK_RAW == sock->type) { |
| 174 | inet->num = protocol; |
| 175 | if (IPPROTO_RAW == protocol) |
| 176 | inet->hdrincl = 1; |
| 177 | } |
| 178 | |
Arnaldo Carvalho de Melo | e684897 | 2005-08-09 19:45:38 -0700 | [diff] [blame] | 179 | sk->sk_destruct = inet_sock_destruct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | sk->sk_family = PF_INET6; |
| 181 | sk->sk_protocol = protocol; |
| 182 | |
| 183 | sk->sk_backlog_rcv = answer->prot->backlog_rcv; |
| 184 | |
| 185 | inet_sk(sk)->pinet6 = np = inet6_sk_generic(sk); |
| 186 | np->hop_limit = -1; |
| 187 | np->mcast_hops = -1; |
| 188 | np->mc_loop = 1; |
| 189 | np->pmtudisc = IPV6_PMTUDISC_WANT; |
Pavel Emelyanov | 2e761e0 | 2008-06-09 15:53:30 -0700 | [diff] [blame] | 190 | np->ipv6only = net->ipv6.sysctl.bindv6only; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | /* Init the ipv4 part of the socket since we can have sockets |
| 193 | * using v6 API for ipv4. |
| 194 | */ |
| 195 | inet->uc_ttl = -1; |
| 196 | |
| 197 | inet->mc_loop = 1; |
| 198 | inet->mc_ttl = 1; |
| 199 | inet->mc_index = 0; |
| 200 | inet->mc_list = NULL; |
| 201 | |
| 202 | if (ipv4_config.no_pmtu_disc) |
| 203 | inet->pmtudisc = IP_PMTUDISC_DONT; |
| 204 | else |
| 205 | inet->pmtudisc = IP_PMTUDISC_WANT; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 206 | /* |
Arnaldo Carvalho de Melo | e684897 | 2005-08-09 19:45:38 -0700 | [diff] [blame] | 207 | * Increment only the relevant sk_prot->socks debug field, this changes |
| 208 | * the previous behaviour of incrementing both the equivalent to |
| 209 | * answer->prot->socks (inet6_sock_nr) and inet_sock_nr. |
| 210 | * |
| 211 | * This allows better debug granularity as we'll know exactly how many |
| 212 | * UDPv6, TCPv6, etc socks were allocated, not the sum of all IPv6 |
| 213 | * transport protocol socks. -acme |
| 214 | */ |
| 215 | sk_refcnt_debug_inc(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | if (inet->num) { |
| 218 | /* It assumes that any protocol which allows |
| 219 | * the user to assign a number at socket |
| 220 | * creation time automatically shares. |
| 221 | */ |
Al Viro | e69a4ad | 2006-11-14 20:56:00 -0800 | [diff] [blame] | 222 | inet->sport = htons(inet->num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | sk->sk_prot->hash(sk); |
| 224 | } |
| 225 | if (sk->sk_prot->init) { |
YOSHIFUJI Hideaki | af1afe8 | 2005-12-02 20:56:57 -0800 | [diff] [blame] | 226 | err = sk->sk_prot->init(sk); |
| 227 | if (err) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | sk_common_release(sk); |
| 229 | goto out; |
| 230 | } |
| 231 | } |
| 232 | out: |
YOSHIFUJI Hideaki | af1afe8 | 2005-12-02 20:56:57 -0800 | [diff] [blame] | 233 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | out_rcu_unlock: |
| 235 | rcu_read_unlock(); |
| 236 | goto out; |
| 237 | } |
| 238 | |
| 239 | |
| 240 | /* bind for INET6 API */ |
| 241 | int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) |
| 242 | { |
| 243 | struct sockaddr_in6 *addr=(struct sockaddr_in6 *)uaddr; |
| 244 | struct sock *sk = sock->sk; |
| 245 | struct inet_sock *inet = inet_sk(sk); |
| 246 | struct ipv6_pinfo *np = inet6_sk(sk); |
YOSHIFUJI Hideaki | 3b1e0a6 | 2008-03-26 02:26:21 +0900 | [diff] [blame] | 247 | struct net *net = sock_net(sk); |
Al Viro | fd68322 | 2006-09-26 22:17:51 -0700 | [diff] [blame] | 248 | __be32 v4addr = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | unsigned short snum; |
| 250 | int addr_type = 0; |
| 251 | int err = 0; |
| 252 | |
| 253 | /* If the socket has its own bind function then use it. */ |
| 254 | if (sk->sk_prot->bind) |
| 255 | return sk->sk_prot->bind(sk, uaddr, addr_len); |
| 256 | |
| 257 | if (addr_len < SIN6_LEN_RFC2133) |
| 258 | return -EINVAL; |
| 259 | addr_type = ipv6_addr_type(&addr->sin6_addr); |
| 260 | if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM) |
| 261 | return -EINVAL; |
| 262 | |
| 263 | snum = ntohs(addr->sin6_port); |
| 264 | if (snum && snum < PROT_SOCK && !capable(CAP_NET_BIND_SERVICE)) |
| 265 | return -EACCES; |
| 266 | |
| 267 | lock_sock(sk); |
| 268 | |
| 269 | /* Check these errors (active socket, double bind). */ |
| 270 | if (sk->sk_state != TCP_CLOSE || inet->num) { |
| 271 | err = -EINVAL; |
| 272 | goto out; |
| 273 | } |
| 274 | |
| 275 | /* Check if the address belongs to the host. */ |
| 276 | if (addr_type == IPV6_ADDR_MAPPED) { |
| 277 | v4addr = addr->sin6_addr.s6_addr32[3]; |
Benjamin Thery | 075de93 | 2008-03-05 10:45:59 -0800 | [diff] [blame] | 278 | if (inet_addr_type(net, v4addr) != RTN_LOCAL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | err = -EADDRNOTAVAIL; |
| 280 | goto out; |
| 281 | } |
| 282 | } else { |
| 283 | if (addr_type != IPV6_ADDR_ANY) { |
| 284 | struct net_device *dev = NULL; |
| 285 | |
| 286 | if (addr_type & IPV6_ADDR_LINKLOCAL) { |
| 287 | if (addr_len >= sizeof(struct sockaddr_in6) && |
| 288 | addr->sin6_scope_id) { |
| 289 | /* Override any existing binding, if another one |
| 290 | * is supplied by user. |
| 291 | */ |
| 292 | sk->sk_bound_dev_if = addr->sin6_scope_id; |
| 293 | } |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 294 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | /* Binding to link-local address requires an interface */ |
| 296 | if (!sk->sk_bound_dev_if) { |
| 297 | err = -EINVAL; |
| 298 | goto out; |
| 299 | } |
Benjamin Thery | 075de93 | 2008-03-05 10:45:59 -0800 | [diff] [blame] | 300 | dev = dev_get_by_index(net, sk->sk_bound_dev_if); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | if (!dev) { |
| 302 | err = -ENODEV; |
| 303 | goto out; |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | /* ipv4 addr of the socket is invalid. Only the |
| 308 | * unspecified and mapped address have a v4 equivalent. |
| 309 | */ |
| 310 | v4addr = LOOPBACK4_IPV6; |
| 311 | if (!(addr_type & IPV6_ADDR_MULTICAST)) { |
Benjamin Thery | 075de93 | 2008-03-05 10:45:59 -0800 | [diff] [blame] | 312 | if (!ipv6_chk_addr(net, &addr->sin6_addr, |
Daniel Lezcano | bfeade0 | 2008-01-10 22:43:18 -0800 | [diff] [blame] | 313 | dev, 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | if (dev) |
| 315 | dev_put(dev); |
| 316 | err = -EADDRNOTAVAIL; |
| 317 | goto out; |
| 318 | } |
| 319 | } |
| 320 | if (dev) |
| 321 | dev_put(dev); |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | inet->rcv_saddr = v4addr; |
| 326 | inet->saddr = v4addr; |
| 327 | |
| 328 | ipv6_addr_copy(&np->rcv_saddr, &addr->sin6_addr); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | if (!(addr_type & IPV6_ADDR_MULTICAST)) |
| 331 | ipv6_addr_copy(&np->saddr, &addr->sin6_addr); |
| 332 | |
| 333 | /* Make sure we are allowed to bind here. */ |
| 334 | if (sk->sk_prot->get_port(sk, snum)) { |
| 335 | inet_reset_saddr(sk); |
| 336 | err = -EADDRINUSE; |
| 337 | goto out; |
| 338 | } |
| 339 | |
| 340 | if (addr_type != IPV6_ADDR_ANY) |
| 341 | sk->sk_userlocks |= SOCK_BINDADDR_LOCK; |
| 342 | if (snum) |
| 343 | sk->sk_userlocks |= SOCK_BINDPORT_LOCK; |
Al Viro | e69a4ad | 2006-11-14 20:56:00 -0800 | [diff] [blame] | 344 | inet->sport = htons(inet->num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | inet->dport = 0; |
| 346 | inet->daddr = 0; |
| 347 | out: |
| 348 | release_sock(sk); |
| 349 | return err; |
| 350 | } |
| 351 | |
YOSHIFUJI Hideaki | 7159039 | 2007-02-22 22:05:40 +0900 | [diff] [blame] | 352 | EXPORT_SYMBOL(inet6_bind); |
| 353 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | int inet6_release(struct socket *sock) |
| 355 | { |
| 356 | struct sock *sk = sock->sk; |
| 357 | |
| 358 | if (sk == NULL) |
| 359 | return -EINVAL; |
| 360 | |
| 361 | /* Free mc lists */ |
| 362 | ipv6_sock_mc_close(sk); |
| 363 | |
| 364 | /* Free ac lists */ |
| 365 | ipv6_sock_ac_close(sk); |
| 366 | |
| 367 | return inet_release(sock); |
| 368 | } |
| 369 | |
YOSHIFUJI Hideaki | 7159039 | 2007-02-22 22:05:40 +0900 | [diff] [blame] | 370 | EXPORT_SYMBOL(inet6_release); |
| 371 | |
Brian Haley | 7d06b2e | 2008-06-14 17:04:49 -0700 | [diff] [blame] | 372 | void inet6_destroy_sock(struct sock *sk) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | { |
| 374 | struct ipv6_pinfo *np = inet6_sk(sk); |
| 375 | struct sk_buff *skb; |
| 376 | struct ipv6_txoptions *opt; |
| 377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | /* Release rx options */ |
| 379 | |
| 380 | if ((skb = xchg(&np->pktoptions, NULL)) != NULL) |
| 381 | kfree_skb(skb); |
| 382 | |
| 383 | /* Free flowlabels */ |
| 384 | fl6_free_socklist(sk); |
| 385 | |
| 386 | /* Free tx options */ |
| 387 | |
| 388 | if ((opt = xchg(&np->opt, NULL)) != NULL) |
| 389 | sock_kfree_s(sk, opt, opt->tot_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Arnaldo Carvalho de Melo | 3cf3dc6 | 2005-12-13 23:23:20 -0800 | [diff] [blame] | 392 | EXPORT_SYMBOL_GPL(inet6_destroy_sock); |
| 393 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | /* |
| 395 | * This does both peername and sockname. |
| 396 | */ |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | int inet6_getname(struct socket *sock, struct sockaddr *uaddr, |
| 399 | int *uaddr_len, int peer) |
| 400 | { |
| 401 | struct sockaddr_in6 *sin=(struct sockaddr_in6 *)uaddr; |
| 402 | struct sock *sk = sock->sk; |
| 403 | struct inet_sock *inet = inet_sk(sk); |
| 404 | struct ipv6_pinfo *np = inet6_sk(sk); |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | sin->sin6_family = AF_INET6; |
| 407 | sin->sin6_flowinfo = 0; |
| 408 | sin->sin6_scope_id = 0; |
| 409 | if (peer) { |
| 410 | if (!inet->dport) |
| 411 | return -ENOTCONN; |
| 412 | if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_SYN_SENT)) && |
| 413 | peer == 1) |
| 414 | return -ENOTCONN; |
| 415 | sin->sin6_port = inet->dport; |
| 416 | ipv6_addr_copy(&sin->sin6_addr, &np->daddr); |
| 417 | if (np->sndflow) |
| 418 | sin->sin6_flowinfo = np->flow_label; |
| 419 | } else { |
| 420 | if (ipv6_addr_any(&np->rcv_saddr)) |
| 421 | ipv6_addr_copy(&sin->sin6_addr, &np->saddr); |
| 422 | else |
| 423 | ipv6_addr_copy(&sin->sin6_addr, &np->rcv_saddr); |
| 424 | |
| 425 | sin->sin6_port = inet->sport; |
| 426 | } |
| 427 | if (ipv6_addr_type(&sin->sin6_addr) & IPV6_ADDR_LINKLOCAL) |
| 428 | sin->sin6_scope_id = sk->sk_bound_dev_if; |
| 429 | *uaddr_len = sizeof(*sin); |
| 430 | return(0); |
| 431 | } |
| 432 | |
YOSHIFUJI Hideaki | 7159039 | 2007-02-22 22:05:40 +0900 | [diff] [blame] | 433 | EXPORT_SYMBOL(inet6_getname); |
| 434 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) |
| 436 | { |
| 437 | struct sock *sk = sock->sk; |
YOSHIFUJI Hideaki | 3b1e0a6 | 2008-03-26 02:26:21 +0900 | [diff] [blame] | 438 | struct net *net = sock_net(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 440 | switch(cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | { |
| 442 | case SIOCGSTAMP: |
| 443 | return sock_get_timestamp(sk, (struct timeval __user *)arg); |
| 444 | |
Eric Dumazet | ae40eb1 | 2007-03-18 17:33:16 -0700 | [diff] [blame] | 445 | case SIOCGSTAMPNS: |
| 446 | return sock_get_timestampns(sk, (struct timespec __user *)arg); |
| 447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | case SIOCADDRT: |
| 449 | case SIOCDELRT: |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 450 | |
Daniel Lezcano | 5578689 | 2008-03-04 13:47:47 -0800 | [diff] [blame] | 451 | return(ipv6_route_ioctl(net, cmd, (void __user *)arg)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | |
| 453 | case SIOCSIFADDR: |
Daniel Lezcano | af28493 | 2008-03-05 10:46:57 -0800 | [diff] [blame] | 454 | return addrconf_add_ifaddr(net, (void __user *) arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | case SIOCDIFADDR: |
Daniel Lezcano | af28493 | 2008-03-05 10:46:57 -0800 | [diff] [blame] | 456 | return addrconf_del_ifaddr(net, (void __user *) arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | case SIOCSIFDSTADDR: |
Daniel Lezcano | af28493 | 2008-03-05 10:46:57 -0800 | [diff] [blame] | 458 | return addrconf_set_dstaddr(net, (void __user *) arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | default: |
Christoph Hellwig | b5e5fa5 | 2006-01-03 14:18:33 -0800 | [diff] [blame] | 460 | if (!sk->sk_prot->ioctl) |
| 461 | return -ENOIOCTLCMD; |
| 462 | return sk->sk_prot->ioctl(sk, cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | } |
| 464 | /*NOTREACHED*/ |
| 465 | return(0); |
| 466 | } |
| 467 | |
YOSHIFUJI Hideaki | 7159039 | 2007-02-22 22:05:40 +0900 | [diff] [blame] | 468 | EXPORT_SYMBOL(inet6_ioctl); |
| 469 | |
Eric Dumazet | 90ddc4f | 2005-12-22 12:49:22 -0800 | [diff] [blame] | 470 | const struct proto_ops inet6_stream_ops = { |
Arnaldo Carvalho de Melo | 543d9cf | 2006-03-20 22:48:35 -0800 | [diff] [blame] | 471 | .family = PF_INET6, |
| 472 | .owner = THIS_MODULE, |
| 473 | .release = inet6_release, |
| 474 | .bind = inet6_bind, |
| 475 | .connect = inet_stream_connect, /* ok */ |
| 476 | .socketpair = sock_no_socketpair, /* a do nothing */ |
| 477 | .accept = inet_accept, /* ok */ |
| 478 | .getname = inet6_getname, |
| 479 | .poll = tcp_poll, /* ok */ |
| 480 | .ioctl = inet6_ioctl, /* must change */ |
| 481 | .listen = inet_listen, /* ok */ |
| 482 | .shutdown = inet_shutdown, /* ok */ |
| 483 | .setsockopt = sock_common_setsockopt, /* ok */ |
| 484 | .getsockopt = sock_common_getsockopt, /* ok */ |
David S. Miller | 3516ffb | 2007-08-02 19:23:56 -0700 | [diff] [blame] | 485 | .sendmsg = tcp_sendmsg, /* ok */ |
Arnaldo Carvalho de Melo | 543d9cf | 2006-03-20 22:48:35 -0800 | [diff] [blame] | 486 | .recvmsg = sock_common_recvmsg, /* ok */ |
| 487 | .mmap = sock_no_mmap, |
| 488 | .sendpage = tcp_sendpage, |
Jens Axboe | a0974dd | 2007-11-06 23:31:58 -0800 | [diff] [blame] | 489 | .splice_read = tcp_splice_read, |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 490 | #ifdef CONFIG_COMPAT |
Arnaldo Carvalho de Melo | 543d9cf | 2006-03-20 22:48:35 -0800 | [diff] [blame] | 491 | .compat_setsockopt = compat_sock_common_setsockopt, |
| 492 | .compat_getsockopt = compat_sock_common_getsockopt, |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 493 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | }; |
| 495 | |
Eric Dumazet | 90ddc4f | 2005-12-22 12:49:22 -0800 | [diff] [blame] | 496 | const struct proto_ops inet6_dgram_ops = { |
Arnaldo Carvalho de Melo | 543d9cf | 2006-03-20 22:48:35 -0800 | [diff] [blame] | 497 | .family = PF_INET6, |
| 498 | .owner = THIS_MODULE, |
| 499 | .release = inet6_release, |
| 500 | .bind = inet6_bind, |
| 501 | .connect = inet_dgram_connect, /* ok */ |
| 502 | .socketpair = sock_no_socketpair, /* a do nothing */ |
| 503 | .accept = sock_no_accept, /* a do nothing */ |
| 504 | .getname = inet6_getname, |
| 505 | .poll = udp_poll, /* ok */ |
| 506 | .ioctl = inet6_ioctl, /* must change */ |
| 507 | .listen = sock_no_listen, /* ok */ |
| 508 | .shutdown = inet_shutdown, /* ok */ |
| 509 | .setsockopt = sock_common_setsockopt, /* ok */ |
| 510 | .getsockopt = sock_common_getsockopt, /* ok */ |
| 511 | .sendmsg = inet_sendmsg, /* ok */ |
| 512 | .recvmsg = sock_common_recvmsg, /* ok */ |
| 513 | .mmap = sock_no_mmap, |
| 514 | .sendpage = sock_no_sendpage, |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 515 | #ifdef CONFIG_COMPAT |
Arnaldo Carvalho de Melo | 543d9cf | 2006-03-20 22:48:35 -0800 | [diff] [blame] | 516 | .compat_setsockopt = compat_sock_common_setsockopt, |
| 517 | .compat_getsockopt = compat_sock_common_getsockopt, |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 518 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | }; |
| 520 | |
| 521 | static struct net_proto_family inet6_family_ops = { |
| 522 | .family = PF_INET6, |
| 523 | .create = inet6_create, |
| 524 | .owner = THIS_MODULE, |
| 525 | }; |
| 526 | |
Daniel Lezcano | 87c3efb | 2007-12-11 02:25:01 -0800 | [diff] [blame] | 527 | int inet6_register_protosw(struct inet_protosw *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | { |
| 529 | struct list_head *lh; |
| 530 | struct inet_protosw *answer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | struct list_head *last_perm; |
Daniel Lezcano | 87c3efb | 2007-12-11 02:25:01 -0800 | [diff] [blame] | 532 | int protocol = p->protocol; |
| 533 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | |
| 535 | spin_lock_bh(&inetsw6_lock); |
| 536 | |
Daniel Lezcano | 87c3efb | 2007-12-11 02:25:01 -0800 | [diff] [blame] | 537 | ret = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | if (p->type >= SOCK_MAX) |
| 539 | goto out_illegal; |
| 540 | |
| 541 | /* If we are trying to override a permanent protocol, bail. */ |
| 542 | answer = NULL; |
Daniel Lezcano | 87c3efb | 2007-12-11 02:25:01 -0800 | [diff] [blame] | 543 | ret = -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | last_perm = &inetsw6[p->type]; |
| 545 | list_for_each(lh, &inetsw6[p->type]) { |
| 546 | answer = list_entry(lh, struct inet_protosw, list); |
| 547 | |
| 548 | /* Check only the non-wild match. */ |
| 549 | if (INET_PROTOSW_PERMANENT & answer->flags) { |
| 550 | if (protocol == answer->protocol) |
| 551 | break; |
| 552 | last_perm = lh; |
| 553 | } |
| 554 | |
| 555 | answer = NULL; |
| 556 | } |
| 557 | if (answer) |
| 558 | goto out_permanent; |
| 559 | |
| 560 | /* Add the new entry after the last permanent entry if any, so that |
| 561 | * the new entry does not override a permanent entry when matched with |
| 562 | * a wild-card protocol. But it is allowed to override any existing |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 563 | * non-permanent entry. This means that when we remove this entry, the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | * system automatically returns to the old behavior. |
| 565 | */ |
| 566 | list_add_rcu(&p->list, last_perm); |
Daniel Lezcano | 87c3efb | 2007-12-11 02:25:01 -0800 | [diff] [blame] | 567 | ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | out: |
| 569 | spin_unlock_bh(&inetsw6_lock); |
Daniel Lezcano | 87c3efb | 2007-12-11 02:25:01 -0800 | [diff] [blame] | 570 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
| 572 | out_permanent: |
| 573 | printk(KERN_ERR "Attempt to override permanent protocol %d.\n", |
| 574 | protocol); |
| 575 | goto out; |
| 576 | |
| 577 | out_illegal: |
| 578 | printk(KERN_ERR |
| 579 | "Ignoring attempt to register invalid socket type %d.\n", |
| 580 | p->type); |
| 581 | goto out; |
| 582 | } |
| 583 | |
YOSHIFUJI Hideaki | 7159039 | 2007-02-22 22:05:40 +0900 | [diff] [blame] | 584 | EXPORT_SYMBOL(inet6_register_protosw); |
| 585 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | void |
| 587 | inet6_unregister_protosw(struct inet_protosw *p) |
| 588 | { |
| 589 | if (INET_PROTOSW_PERMANENT & p->flags) { |
| 590 | printk(KERN_ERR |
| 591 | "Attempt to unregister permanent protocol %d.\n", |
| 592 | p->protocol); |
| 593 | } else { |
| 594 | spin_lock_bh(&inetsw6_lock); |
| 595 | list_del_rcu(&p->list); |
| 596 | spin_unlock_bh(&inetsw6_lock); |
| 597 | |
| 598 | synchronize_net(); |
| 599 | } |
| 600 | } |
| 601 | |
YOSHIFUJI Hideaki | 7159039 | 2007-02-22 22:05:40 +0900 | [diff] [blame] | 602 | EXPORT_SYMBOL(inet6_unregister_protosw); |
| 603 | |
Arnaldo Carvalho de Melo | b9750ce | 2005-12-13 23:22:54 -0800 | [diff] [blame] | 604 | int inet6_sk_rebuild_header(struct sock *sk) |
| 605 | { |
| 606 | int err; |
| 607 | struct dst_entry *dst; |
| 608 | struct ipv6_pinfo *np = inet6_sk(sk); |
| 609 | |
| 610 | dst = __sk_dst_check(sk, np->dst_cookie); |
| 611 | |
| 612 | if (dst == NULL) { |
| 613 | struct inet_sock *inet = inet_sk(sk); |
| 614 | struct in6_addr *final_p = NULL, final; |
| 615 | struct flowi fl; |
| 616 | |
| 617 | memset(&fl, 0, sizeof(fl)); |
| 618 | fl.proto = sk->sk_protocol; |
| 619 | ipv6_addr_copy(&fl.fl6_dst, &np->daddr); |
| 620 | ipv6_addr_copy(&fl.fl6_src, &np->saddr); |
| 621 | fl.fl6_flowlabel = np->flow_label; |
| 622 | fl.oif = sk->sk_bound_dev_if; |
| 623 | fl.fl_ip_dport = inet->dport; |
| 624 | fl.fl_ip_sport = inet->sport; |
Venkat Yekkirala | beb8d13 | 2006-08-04 23:12:42 -0700 | [diff] [blame] | 625 | security_sk_classify_flow(sk, &fl); |
Arnaldo Carvalho de Melo | b9750ce | 2005-12-13 23:22:54 -0800 | [diff] [blame] | 626 | |
| 627 | if (np->opt && np->opt->srcrt) { |
| 628 | struct rt0_hdr *rt0 = (struct rt0_hdr *) np->opt->srcrt; |
| 629 | ipv6_addr_copy(&final, &fl.fl6_dst); |
| 630 | ipv6_addr_copy(&fl.fl6_dst, rt0->addr); |
| 631 | final_p = &final; |
| 632 | } |
| 633 | |
| 634 | err = ip6_dst_lookup(sk, &dst, &fl); |
| 635 | if (err) { |
| 636 | sk->sk_route_caps = 0; |
| 637 | return err; |
| 638 | } |
| 639 | if (final_p) |
| 640 | ipv6_addr_copy(&fl.fl6_dst, final_p); |
| 641 | |
| 642 | if ((err = xfrm_lookup(&dst, &fl, sk, 0)) < 0) { |
| 643 | sk->sk_err_soft = -err; |
| 644 | return err; |
| 645 | } |
| 646 | |
YOSHIFUJI Hideaki | 8e1ef0a | 2006-08-29 17:15:09 -0700 | [diff] [blame] | 647 | __ip6_dst_store(sk, dst, NULL, NULL); |
Arnaldo Carvalho de Melo | b9750ce | 2005-12-13 23:22:54 -0800 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | return 0; |
| 651 | } |
| 652 | |
| 653 | EXPORT_SYMBOL_GPL(inet6_sk_rebuild_header); |
| 654 | |
Arnaldo Carvalho de Melo | 399c07d | 2005-12-13 23:24:28 -0800 | [diff] [blame] | 655 | int ipv6_opt_accepted(struct sock *sk, struct sk_buff *skb) |
| 656 | { |
| 657 | struct ipv6_pinfo *np = inet6_sk(sk); |
| 658 | struct inet6_skb_parm *opt = IP6CB(skb); |
| 659 | |
| 660 | if (np->rxopt.all) { |
| 661 | if ((opt->hop && (np->rxopt.bits.hopopts || |
| 662 | np->rxopt.bits.ohopopts)) || |
Arnaldo Carvalho de Melo | d56f90a | 2007-04-10 20:50:43 -0700 | [diff] [blame] | 663 | ((IPV6_FLOWINFO_MASK & |
| 664 | *(__be32 *)skb_network_header(skb)) && |
Arnaldo Carvalho de Melo | 399c07d | 2005-12-13 23:24:28 -0800 | [diff] [blame] | 665 | np->rxopt.bits.rxflow) || |
| 666 | (opt->srcrt && (np->rxopt.bits.srcrt || |
| 667 | np->rxopt.bits.osrcrt)) || |
| 668 | ((opt->dst1 || opt->dst0) && |
| 669 | (np->rxopt.bits.dstopts || np->rxopt.bits.odstopts))) |
| 670 | return 1; |
| 671 | } |
| 672 | return 0; |
| 673 | } |
| 674 | |
| 675 | EXPORT_SYMBOL_GPL(ipv6_opt_accepted); |
| 676 | |
YOSHIFUJI Hideaki | 662397f | 2008-02-27 23:14:03 +0900 | [diff] [blame] | 677 | static struct inet6_protocol *ipv6_gso_pull_exthdrs(struct sk_buff *skb, |
| 678 | int proto) |
| 679 | { |
| 680 | struct inet6_protocol *ops = NULL; |
| 681 | |
| 682 | for (;;) { |
| 683 | struct ipv6_opt_hdr *opth; |
| 684 | int len; |
| 685 | |
| 686 | if (proto != NEXTHDR_HOP) { |
| 687 | ops = rcu_dereference(inet6_protos[proto]); |
| 688 | |
| 689 | if (unlikely(!ops)) |
| 690 | break; |
| 691 | |
| 692 | if (!(ops->flags & INET6_PROTO_GSO_EXTHDR)) |
| 693 | break; |
| 694 | } |
| 695 | |
| 696 | if (unlikely(!pskb_may_pull(skb, 8))) |
| 697 | break; |
| 698 | |
| 699 | opth = (void *)skb->data; |
| 700 | len = ipv6_optlen(opth); |
| 701 | |
| 702 | if (unlikely(!pskb_may_pull(skb, len))) |
| 703 | break; |
| 704 | |
| 705 | proto = opth->nexthdr; |
| 706 | __skb_pull(skb, len); |
| 707 | } |
| 708 | |
| 709 | return ops; |
| 710 | } |
| 711 | |
| 712 | static int ipv6_gso_send_check(struct sk_buff *skb) |
| 713 | { |
| 714 | struct ipv6hdr *ipv6h; |
| 715 | struct inet6_protocol *ops; |
| 716 | int err = -EINVAL; |
| 717 | |
| 718 | if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h)))) |
| 719 | goto out; |
| 720 | |
| 721 | ipv6h = ipv6_hdr(skb); |
| 722 | __skb_pull(skb, sizeof(*ipv6h)); |
| 723 | err = -EPROTONOSUPPORT; |
| 724 | |
| 725 | rcu_read_lock(); |
| 726 | ops = ipv6_gso_pull_exthdrs(skb, ipv6h->nexthdr); |
| 727 | if (likely(ops && ops->gso_send_check)) { |
| 728 | skb_reset_transport_header(skb); |
| 729 | err = ops->gso_send_check(skb); |
| 730 | } |
| 731 | rcu_read_unlock(); |
| 732 | |
| 733 | out: |
| 734 | return err; |
| 735 | } |
| 736 | |
| 737 | static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb, int features) |
| 738 | { |
| 739 | struct sk_buff *segs = ERR_PTR(-EINVAL); |
| 740 | struct ipv6hdr *ipv6h; |
| 741 | struct inet6_protocol *ops; |
| 742 | |
| 743 | if (!(features & NETIF_F_V6_CSUM)) |
| 744 | features &= ~NETIF_F_SG; |
| 745 | |
| 746 | if (unlikely(skb_shinfo(skb)->gso_type & |
| 747 | ~(SKB_GSO_UDP | |
| 748 | SKB_GSO_DODGY | |
| 749 | SKB_GSO_TCP_ECN | |
| 750 | SKB_GSO_TCPV6 | |
| 751 | 0))) |
| 752 | goto out; |
| 753 | |
| 754 | if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h)))) |
| 755 | goto out; |
| 756 | |
| 757 | ipv6h = ipv6_hdr(skb); |
| 758 | __skb_pull(skb, sizeof(*ipv6h)); |
| 759 | segs = ERR_PTR(-EPROTONOSUPPORT); |
| 760 | |
| 761 | rcu_read_lock(); |
| 762 | ops = ipv6_gso_pull_exthdrs(skb, ipv6h->nexthdr); |
| 763 | if (likely(ops && ops->gso_segment)) { |
| 764 | skb_reset_transport_header(skb); |
| 765 | segs = ops->gso_segment(skb, features); |
| 766 | } |
| 767 | rcu_read_unlock(); |
| 768 | |
| 769 | if (unlikely(IS_ERR(segs))) |
| 770 | goto out; |
| 771 | |
| 772 | for (skb = segs; skb; skb = skb->next) { |
| 773 | ipv6h = ipv6_hdr(skb); |
| 774 | ipv6h->payload_len = htons(skb->len - skb->mac_len - |
| 775 | sizeof(*ipv6h)); |
| 776 | } |
| 777 | |
| 778 | out: |
| 779 | return segs; |
| 780 | } |
| 781 | |
| 782 | static struct packet_type ipv6_packet_type = { |
| 783 | .type = __constant_htons(ETH_P_IPV6), |
| 784 | .func = ipv6_rcv, |
| 785 | .gso_send_check = ipv6_gso_send_check, |
| 786 | .gso_segment = ipv6_gso_segment, |
| 787 | }; |
| 788 | |
| 789 | static int __init ipv6_packet_init(void) |
| 790 | { |
| 791 | dev_add_pack(&ipv6_packet_type); |
| 792 | return 0; |
| 793 | } |
| 794 | |
| 795 | static void ipv6_packet_cleanup(void) |
| 796 | { |
| 797 | dev_remove_pack(&ipv6_packet_type); |
| 798 | } |
| 799 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | static int __init init_ipv6_mibs(void) |
| 801 | { |
YOSHIFUJI Hideaki | c69bce2 | 2008-01-23 22:31:45 -0800 | [diff] [blame] | 802 | if (snmp_mib_init((void **)ipv6_statistics, |
| 803 | sizeof(struct ipstats_mib)) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | goto err_ip_mib; |
YOSHIFUJI Hideaki | c69bce2 | 2008-01-23 22:31:45 -0800 | [diff] [blame] | 805 | if (snmp_mib_init((void **)icmpv6_statistics, |
| 806 | sizeof(struct icmpv6_mib)) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | goto err_icmp_mib; |
David L Stevens | 14878f7 | 2007-09-16 16:52:35 -0700 | [diff] [blame] | 808 | if (snmp_mib_init((void **)icmpv6msg_statistics, |
YOSHIFUJI Hideaki | c69bce2 | 2008-01-23 22:31:45 -0800 | [diff] [blame] | 809 | sizeof(struct icmpv6msg_mib)) < 0) |
David L Stevens | 14878f7 | 2007-09-16 16:52:35 -0700 | [diff] [blame] | 810 | goto err_icmpmsg_mib; |
YOSHIFUJI Hideaki | c69bce2 | 2008-01-23 22:31:45 -0800 | [diff] [blame] | 811 | if (snmp_mib_init((void **)udp_stats_in6, sizeof (struct udp_mib)) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | goto err_udp_mib; |
YOSHIFUJI Hideaki | c69bce2 | 2008-01-23 22:31:45 -0800 | [diff] [blame] | 813 | if (snmp_mib_init((void **)udplite_stats_in6, |
| 814 | sizeof (struct udp_mib)) < 0) |
Gerrit Renker | ba4e58e | 2006-11-27 11:10:57 -0800 | [diff] [blame] | 815 | goto err_udplite_mib; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | return 0; |
| 817 | |
Gerrit Renker | ba4e58e | 2006-11-27 11:10:57 -0800 | [diff] [blame] | 818 | err_udplite_mib: |
Herbert Xu | 7f7d9a6 | 2007-04-24 21:54:09 -0700 | [diff] [blame] | 819 | snmp_mib_free((void **)udp_stats_in6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | err_udp_mib: |
David L Stevens | 14878f7 | 2007-09-16 16:52:35 -0700 | [diff] [blame] | 821 | snmp_mib_free((void **)icmpv6msg_statistics); |
| 822 | err_icmpmsg_mib: |
Herbert Xu | 7f7d9a6 | 2007-04-24 21:54:09 -0700 | [diff] [blame] | 823 | snmp_mib_free((void **)icmpv6_statistics); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | err_icmp_mib: |
Herbert Xu | 7f7d9a6 | 2007-04-24 21:54:09 -0700 | [diff] [blame] | 825 | snmp_mib_free((void **)ipv6_statistics); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | err_ip_mib: |
| 827 | return -ENOMEM; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 828 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | static void cleanup_ipv6_mibs(void) |
| 832 | { |
Herbert Xu | 7f7d9a6 | 2007-04-24 21:54:09 -0700 | [diff] [blame] | 833 | snmp_mib_free((void **)ipv6_statistics); |
| 834 | snmp_mib_free((void **)icmpv6_statistics); |
Pavel Emelyanov | dc8a82a | 2007-10-17 19:30:40 -0700 | [diff] [blame] | 835 | snmp_mib_free((void **)icmpv6msg_statistics); |
Herbert Xu | 7f7d9a6 | 2007-04-24 21:54:09 -0700 | [diff] [blame] | 836 | snmp_mib_free((void **)udp_stats_in6); |
| 837 | snmp_mib_free((void **)udplite_stats_in6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | } |
| 839 | |
Daniel Lezcano | 81c1c17 | 2008-01-10 02:48:33 -0800 | [diff] [blame] | 840 | static int inet6_net_init(struct net *net) |
| 841 | { |
Daniel Lezcano | 0c96d8c | 2008-03-21 04:14:17 -0700 | [diff] [blame] | 842 | int err = 0; |
| 843 | |
Daniel Lezcano | 99bc9c4 | 2008-01-10 02:54:53 -0800 | [diff] [blame] | 844 | net->ipv6.sysctl.bindv6only = 0; |
Daniel Lezcano | 4990509 | 2008-01-10 03:01:01 -0800 | [diff] [blame] | 845 | net->ipv6.sysctl.flush_delay = 0; |
| 846 | net->ipv6.sysctl.ip6_rt_max_size = 4096; |
| 847 | net->ipv6.sysctl.ip6_rt_gc_min_interval = HZ / 2; |
| 848 | net->ipv6.sysctl.ip6_rt_gc_timeout = 60*HZ; |
| 849 | net->ipv6.sysctl.ip6_rt_gc_interval = 30*HZ; |
| 850 | net->ipv6.sysctl.ip6_rt_gc_elasticity = 9; |
| 851 | net->ipv6.sysctl.ip6_rt_mtu_expires = 10*60*HZ; |
| 852 | net->ipv6.sysctl.ip6_rt_min_advmss = IPV6_MIN_MTU - 20 - 40; |
Daniel Lezcano | 41a7690 | 2008-01-10 03:02:40 -0800 | [diff] [blame] | 853 | net->ipv6.sysctl.icmpv6_time = 1*HZ; |
Daniel Lezcano | e71e034 | 2008-01-10 02:56:03 -0800 | [diff] [blame] | 854 | |
Daniel Lezcano | 0c96d8c | 2008-03-21 04:14:17 -0700 | [diff] [blame] | 855 | #ifdef CONFIG_PROC_FS |
| 856 | err = udp6_proc_init(net); |
| 857 | if (err) |
| 858 | goto out; |
Daniel Lezcano | 6f8b13b | 2008-03-21 04:14:45 -0700 | [diff] [blame] | 859 | err = tcp6_proc_init(net); |
| 860 | if (err) |
| 861 | goto proc_tcp6_fail; |
Daniel Lezcano | 6ab57e7 | 2008-03-26 16:52:32 -0700 | [diff] [blame] | 862 | err = ac6_proc_init(net); |
| 863 | if (err) |
| 864 | goto proc_ac6_fail; |
Daniel Lezcano | 0c96d8c | 2008-03-21 04:14:17 -0700 | [diff] [blame] | 865 | out: |
| 866 | #endif |
| 867 | return err; |
Daniel Lezcano | 6f8b13b | 2008-03-21 04:14:45 -0700 | [diff] [blame] | 868 | |
| 869 | #ifdef CONFIG_PROC_FS |
Daniel Lezcano | 6ab57e7 | 2008-03-26 16:52:32 -0700 | [diff] [blame] | 870 | proc_ac6_fail: |
| 871 | tcp6_proc_exit(net); |
Daniel Lezcano | 6f8b13b | 2008-03-21 04:14:45 -0700 | [diff] [blame] | 872 | proc_tcp6_fail: |
| 873 | udp6_proc_exit(net); |
| 874 | goto out; |
| 875 | #endif |
Daniel Lezcano | 81c1c17 | 2008-01-10 02:48:33 -0800 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | static void inet6_net_exit(struct net *net) |
| 879 | { |
Daniel Lezcano | 0c96d8c | 2008-03-21 04:14:17 -0700 | [diff] [blame] | 880 | #ifdef CONFIG_PROC_FS |
| 881 | udp6_proc_exit(net); |
Daniel Lezcano | 6f8b13b | 2008-03-21 04:14:45 -0700 | [diff] [blame] | 882 | tcp6_proc_exit(net); |
Daniel Lezcano | 6ab57e7 | 2008-03-26 16:52:32 -0700 | [diff] [blame] | 883 | ac6_proc_exit(net); |
Daniel Lezcano | 0c96d8c | 2008-03-21 04:14:17 -0700 | [diff] [blame] | 884 | #endif |
Daniel Lezcano | 81c1c17 | 2008-01-10 02:48:33 -0800 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | static struct pernet_operations inet6_net_ops = { |
| 888 | .init = inet6_net_init, |
| 889 | .exit = inet6_net_exit, |
| 890 | }; |
| 891 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | static int __init inet6_init(void) |
| 893 | { |
| 894 | struct sk_buff *dummy_skb; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 895 | struct list_head *r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | int err; |
| 897 | |
YOSHIFUJI Hideaki | ef047f5 | 2006-09-01 00:29:06 -0700 | [diff] [blame] | 898 | BUILD_BUG_ON(sizeof(struct inet6_skb_parm) > sizeof(dummy_skb->cb)); |
| 899 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | err = proto_register(&tcpv6_prot, 1); |
| 901 | if (err) |
| 902 | goto out; |
| 903 | |
| 904 | err = proto_register(&udpv6_prot, 1); |
| 905 | if (err) |
| 906 | goto out_unregister_tcp_proto; |
| 907 | |
Gerrit Renker | ba4e58e | 2006-11-27 11:10:57 -0800 | [diff] [blame] | 908 | err = proto_register(&udplitev6_prot, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | if (err) |
| 910 | goto out_unregister_udp_proto; |
| 911 | |
Gerrit Renker | ba4e58e | 2006-11-27 11:10:57 -0800 | [diff] [blame] | 912 | err = proto_register(&rawv6_prot, 1); |
| 913 | if (err) |
| 914 | goto out_unregister_udplite_proto; |
| 915 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | |
| 917 | /* Register the socket-side information for inet6_create. */ |
| 918 | for(r = &inetsw6[0]; r < &inetsw6[SOCK_MAX]; ++r) |
| 919 | INIT_LIST_HEAD(r); |
| 920 | |
| 921 | /* We MUST register RAW sockets before we create the ICMP6, |
| 922 | * IGMP6, or NDISC control sockets. |
| 923 | */ |
Daniel Lezcano | 7f4e486 | 2007-12-11 02:25:35 -0800 | [diff] [blame] | 924 | err = rawv6_init(); |
| 925 | if (err) |
| 926 | goto out_unregister_raw_proto; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | |
| 928 | /* Register the family here so that the init calls below will |
| 929 | * be able to create sockets. (?? is this dangerous ??) |
| 930 | */ |
David S. Miller | 8eb5591 | 2005-11-11 15:05:47 -0800 | [diff] [blame] | 931 | err = sock_register(&inet6_family_ops); |
| 932 | if (err) |
Daniel Lezcano | 7f4e486 | 2007-12-11 02:25:35 -0800 | [diff] [blame] | 933 | goto out_sock_register_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | |
| 935 | /* Initialise ipv6 mibs */ |
| 936 | err = init_ipv6_mibs(); |
| 937 | if (err) |
David S. Miller | 8eb5591 | 2005-11-11 15:05:47 -0800 | [diff] [blame] | 938 | goto out_unregister_sock; |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 939 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | /* |
| 941 | * ipngwg API draft makes clear that the correct semantics |
| 942 | * for TCP and UDP is to consider one TCP and UDP instance |
| 943 | * in a host availiable by both INET and INET6 APIs and |
| 944 | * able to communicate via both network protocols. |
| 945 | */ |
| 946 | |
Daniel Lezcano | 81c1c17 | 2008-01-10 02:48:33 -0800 | [diff] [blame] | 947 | err = register_pernet_subsys(&inet6_net_ops); |
| 948 | if (err) |
| 949 | goto register_pernet_fail; |
Denis V. Lunev | 9b0f976 | 2008-02-29 11:13:15 -0800 | [diff] [blame] | 950 | err = icmpv6_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | if (err) |
| 952 | goto icmp_fail; |
Wang Chen | 623d1a1 | 2008-07-03 12:13:30 +0800 | [diff] [blame] | 953 | err = ip6_mr_init(); |
| 954 | if (err) |
| 955 | goto ipmr_fail; |
Denis V. Lunev | 9b0f976 | 2008-02-29 11:13:15 -0800 | [diff] [blame] | 956 | err = ndisc_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | if (err) |
| 958 | goto ndisc_fail; |
Denis V. Lunev | 9b0f976 | 2008-02-29 11:13:15 -0800 | [diff] [blame] | 959 | err = igmp6_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | if (err) |
| 961 | goto igmp_fail; |
Harald Welte | 2cc7d57 | 2005-08-09 19:42:34 -0700 | [diff] [blame] | 962 | err = ipv6_netfilter_init(); |
| 963 | if (err) |
| 964 | goto netfilter_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | /* Create /proc/foo6 entries. */ |
| 966 | #ifdef CONFIG_PROC_FS |
| 967 | err = -ENOMEM; |
| 968 | if (raw6_proc_init()) |
| 969 | goto proc_raw6_fail; |
Gerrit Renker | ba4e58e | 2006-11-27 11:10:57 -0800 | [diff] [blame] | 970 | if (udplite6_proc_init()) |
| 971 | goto proc_udplite6_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | if (ipv6_misc_proc_init()) |
| 973 | goto proc_misc6_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | if (if6_proc_init()) |
| 975 | goto proc_if6_fail; |
| 976 | #endif |
Daniel Lezcano | e2fddf5 | 2007-12-07 00:44:29 -0800 | [diff] [blame] | 977 | err = ip6_route_init(); |
| 978 | if (err) |
| 979 | goto ip6_route_fail; |
Daniel Lezcano | 0a3e78a | 2007-12-11 02:23:18 -0800 | [diff] [blame] | 980 | err = ip6_flowlabel_init(); |
| 981 | if (err) |
| 982 | goto ip6_flowlabel_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | err = addrconf_init(); |
| 984 | if (err) |
| 985 | goto addrconf_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | |
| 987 | /* Init v6 extension headers. */ |
Daniel Lezcano | 248b238 | 2007-12-11 02:23:54 -0800 | [diff] [blame] | 988 | err = ipv6_exthdrs_init(); |
| 989 | if (err) |
| 990 | goto ipv6_exthdrs_fail; |
| 991 | |
Daniel Lezcano | 853cbba | 2007-12-11 02:24:29 -0800 | [diff] [blame] | 992 | err = ipv6_frag_init(); |
| 993 | if (err) |
| 994 | goto ipv6_frag_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | |
| 996 | /* Init v6 transport protocols. */ |
Daniel Lezcano | 7f4e486 | 2007-12-11 02:25:35 -0800 | [diff] [blame] | 997 | err = udpv6_init(); |
| 998 | if (err) |
| 999 | goto udpv6_fail; |
Herbert Xu | e2ed405 | 2005-07-05 14:41:20 -0700 | [diff] [blame] | 1000 | |
Daniel Lezcano | 7f4e486 | 2007-12-11 02:25:35 -0800 | [diff] [blame] | 1001 | err = udplitev6_init(); |
| 1002 | if (err) |
| 1003 | goto udplitev6_fail; |
| 1004 | |
| 1005 | err = tcpv6_init(); |
| 1006 | if (err) |
| 1007 | goto tcpv6_fail; |
| 1008 | |
| 1009 | err = ipv6_packet_init(); |
| 1010 | if (err) |
| 1011 | goto ipv6_packet_fail; |
Benjamin Thery | 94911fe | 2008-03-05 10:45:36 -0800 | [diff] [blame] | 1012 | |
| 1013 | #ifdef CONFIG_SYSCTL |
| 1014 | err = ipv6_sysctl_register(); |
| 1015 | if (err) |
| 1016 | goto sysctl_fail; |
| 1017 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | out: |
| 1019 | return err; |
| 1020 | |
Benjamin Thery | 94911fe | 2008-03-05 10:45:36 -0800 | [diff] [blame] | 1021 | #ifdef CONFIG_SYSCTL |
| 1022 | sysctl_fail: |
| 1023 | ipv6_packet_cleanup(); |
| 1024 | #endif |
Daniel Lezcano | 7f4e486 | 2007-12-11 02:25:35 -0800 | [diff] [blame] | 1025 | ipv6_packet_fail: |
| 1026 | tcpv6_exit(); |
| 1027 | tcpv6_fail: |
| 1028 | udplitev6_exit(); |
| 1029 | udplitev6_fail: |
| 1030 | udpv6_exit(); |
| 1031 | udpv6_fail: |
| 1032 | ipv6_frag_exit(); |
Daniel Lezcano | 853cbba | 2007-12-11 02:24:29 -0800 | [diff] [blame] | 1033 | ipv6_frag_fail: |
| 1034 | ipv6_exthdrs_exit(); |
Daniel Lezcano | 248b238 | 2007-12-11 02:23:54 -0800 | [diff] [blame] | 1035 | ipv6_exthdrs_fail: |
| 1036 | addrconf_cleanup(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | addrconf_fail: |
| 1038 | ip6_flowlabel_cleanup(); |
Daniel Lezcano | 0a3e78a | 2007-12-11 02:23:18 -0800 | [diff] [blame] | 1039 | ip6_flowlabel_fail: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | ip6_route_cleanup(); |
Daniel Lezcano | e2fddf5 | 2007-12-07 00:44:29 -0800 | [diff] [blame] | 1041 | ip6_route_fail: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | #ifdef CONFIG_PROC_FS |
| 1043 | if6_proc_exit(); |
| 1044 | proc_if6_fail: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | ipv6_misc_proc_exit(); |
| 1046 | proc_misc6_fail: |
Gerrit Renker | ba4e58e | 2006-11-27 11:10:57 -0800 | [diff] [blame] | 1047 | udplite6_proc_exit(); |
| 1048 | proc_udplite6_fail: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | raw6_proc_exit(); |
| 1050 | proc_raw6_fail: |
| 1051 | #endif |
Harald Welte | 2cc7d57 | 2005-08-09 19:42:34 -0700 | [diff] [blame] | 1052 | ipv6_netfilter_fini(); |
| 1053 | netfilter_fail: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | igmp6_cleanup(); |
| 1055 | igmp_fail: |
| 1056 | ndisc_cleanup(); |
| 1057 | ndisc_fail: |
Wang Chen | 623d1a1 | 2008-07-03 12:13:30 +0800 | [diff] [blame] | 1058 | ip6_mr_cleanup(); |
| 1059 | ipmr_fail: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | icmpv6_cleanup(); |
| 1061 | icmp_fail: |
Daniel Lezcano | 81c1c17 | 2008-01-10 02:48:33 -0800 | [diff] [blame] | 1062 | unregister_pernet_subsys(&inet6_net_ops); |
| 1063 | register_pernet_fail: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | cleanup_ipv6_mibs(); |
David S. Miller | 8eb5591 | 2005-11-11 15:05:47 -0800 | [diff] [blame] | 1065 | out_unregister_sock: |
| 1066 | sock_unregister(PF_INET6); |
Daniel Lezcano | e2fddf5 | 2007-12-07 00:44:29 -0800 | [diff] [blame] | 1067 | rtnl_unregister_all(PF_INET6); |
Daniel Lezcano | 7f4e486 | 2007-12-11 02:25:35 -0800 | [diff] [blame] | 1068 | out_sock_register_fail: |
| 1069 | rawv6_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | out_unregister_raw_proto: |
| 1071 | proto_unregister(&rawv6_prot); |
Gerrit Renker | ba4e58e | 2006-11-27 11:10:57 -0800 | [diff] [blame] | 1072 | out_unregister_udplite_proto: |
| 1073 | proto_unregister(&udplitev6_prot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | out_unregister_udp_proto: |
| 1075 | proto_unregister(&udpv6_prot); |
| 1076 | out_unregister_tcp_proto: |
| 1077 | proto_unregister(&tcpv6_prot); |
| 1078 | goto out; |
| 1079 | } |
| 1080 | module_init(inet6_init); |
| 1081 | |
| 1082 | static void __exit inet6_exit(void) |
| 1083 | { |
| 1084 | /* First of all disallow new sockets creation. */ |
| 1085 | sock_unregister(PF_INET6); |
Thomas Graf | c127ea2 | 2007-03-22 11:58:32 -0700 | [diff] [blame] | 1086 | /* Disallow any further netlink messages */ |
| 1087 | rtnl_unregister_all(PF_INET6); |
Joe Jin | ca17c23 | 2007-02-20 01:30:15 -0800 | [diff] [blame] | 1088 | |
Benjamin Thery | 94911fe | 2008-03-05 10:45:36 -0800 | [diff] [blame] | 1089 | #ifdef CONFIG_SYSCTL |
| 1090 | ipv6_sysctl_unregister(); |
| 1091 | #endif |
Daniel Lezcano | 7f4e486 | 2007-12-11 02:25:35 -0800 | [diff] [blame] | 1092 | udpv6_exit(); |
| 1093 | udplitev6_exit(); |
| 1094 | tcpv6_exit(); |
| 1095 | |
Joe Jin | ca17c23 | 2007-02-20 01:30:15 -0800 | [diff] [blame] | 1096 | /* Cleanup code parts. */ |
| 1097 | ipv6_packet_cleanup(); |
Daniel Lezcano | 853cbba | 2007-12-11 02:24:29 -0800 | [diff] [blame] | 1098 | ipv6_frag_exit(); |
Daniel Lezcano | 248b238 | 2007-12-11 02:23:54 -0800 | [diff] [blame] | 1099 | ipv6_exthdrs_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | addrconf_cleanup(); |
Joe Jin | ca17c23 | 2007-02-20 01:30:15 -0800 | [diff] [blame] | 1101 | ip6_flowlabel_cleanup(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | ip6_route_cleanup(); |
Joe Jin | ca17c23 | 2007-02-20 01:30:15 -0800 | [diff] [blame] | 1103 | #ifdef CONFIG_PROC_FS |
| 1104 | |
| 1105 | /* Cleanup code parts. */ |
| 1106 | if6_proc_exit(); |
Joe Jin | ca17c23 | 2007-02-20 01:30:15 -0800 | [diff] [blame] | 1107 | ipv6_misc_proc_exit(); |
| 1108 | udplite6_proc_exit(); |
Joe Jin | ca17c23 | 2007-02-20 01:30:15 -0800 | [diff] [blame] | 1109 | raw6_proc_exit(); |
| 1110 | #endif |
Harald Welte | 2cc7d57 | 2005-08-09 19:42:34 -0700 | [diff] [blame] | 1111 | ipv6_netfilter_fini(); |
Joe Jin | ca17c23 | 2007-02-20 01:30:15 -0800 | [diff] [blame] | 1112 | igmp6_cleanup(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | ndisc_cleanup(); |
Wang Chen | 623d1a1 | 2008-07-03 12:13:30 +0800 | [diff] [blame] | 1114 | ip6_mr_cleanup(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | icmpv6_cleanup(); |
Daniel Lezcano | 7f4e486 | 2007-12-11 02:25:35 -0800 | [diff] [blame] | 1116 | rawv6_exit(); |
Benjamin Thery | 94911fe | 2008-03-05 10:45:36 -0800 | [diff] [blame] | 1117 | |
Daniel Lezcano | 81c1c17 | 2008-01-10 02:48:33 -0800 | [diff] [blame] | 1118 | unregister_pernet_subsys(&inet6_net_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | cleanup_ipv6_mibs(); |
| 1120 | proto_unregister(&rawv6_prot); |
Joe Jin | ca17c23 | 2007-02-20 01:30:15 -0800 | [diff] [blame] | 1121 | proto_unregister(&udplitev6_prot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | proto_unregister(&udpv6_prot); |
| 1123 | proto_unregister(&tcpv6_prot); |
| 1124 | } |
| 1125 | module_exit(inet6_exit); |
| 1126 | |
| 1127 | MODULE_ALIAS_NETPROTO(PF_INET6); |