2 * PF_INET6 socket protocol family
3 * Linux INET6 implementation
6 * Pedro Roque <roque@di.fc.ul.pt>
8 * Adapted from linux/net/ipv4/af_inet.c
11 * piggy, Karl Knutson : Socket protocol table
12 * Hideaki YOSHIFUJI : sin6_scope_id support
13 * Arnaldo Melo : check proc_net_create return, cleanups
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version
18 * 2 of the License, or (at your option) any later version.
22 #include <linux/module.h>
23 #include <linux/capability.h>
24 #include <linux/errno.h>
25 #include <linux/types.h>
26 #include <linux/socket.h>
28 #include <linux/kernel.h>
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>
35 #include <linux/interrupt.h>
36 #include <linux/proc_fs.h>
37 #include <linux/stat.h>
38 #include <linux/init.h>
39 #include <linux/slab.h>
41 #include <linux/inet.h>
42 #include <linux/netdevice.h>
43 #include <linux/icmpv6.h>
44 #include <linux/netfilter_ipv6.h>
49 #include <net/udplite.h>
52 #include <net/protocol.h>
53 #include <net/inet_common.h>
54 #include <net/route.h>
55 #include <net/transp_v6.h>
56 #include <net/ip6_route.h>
57 #include <net/addrconf.h>
58 #ifdef CONFIG_IPV6_TUNNEL
59 #include <net/ip6_tunnel.h>
62 #include <asm/uaccess.h>
63 #include <asm/system.h>
64 #include <linux/mroute6.h>
66 MODULE_AUTHOR("Cast of dozens");
67 MODULE_DESCRIPTION("IPv6 protocol stack for Linux");
68 MODULE_LICENSE("GPL");
70 /* The inetsw6 table contains everything that inet6_create needs to
73 static struct list_head inetsw6[SOCK_MAX];
74 static DEFINE_SPINLOCK(inetsw6_lock);
76 struct ipv6_params ipv6_defaults = {
81 static int disable_ipv6_mod = 0;
83 module_param_named(disable, disable_ipv6_mod, int, 0444);
84 MODULE_PARM_DESC(disable, "Disable IPv6 module such that it is non-functional");
86 module_param_named(disable_ipv6, ipv6_defaults.disable_ipv6, int, 0444);
87 MODULE_PARM_DESC(disable_ipv6, "Disable IPv6 on all interfaces");
89 module_param_named(autoconf, ipv6_defaults.autoconf, int, 0444);
90 MODULE_PARM_DESC(autoconf, "Enable IPv6 address autoconfiguration on all interfaces");
92 static __inline__ struct ipv6_pinfo *inet6_sk_generic(struct sock *sk)
94 const int offset = sk->sk_prot->obj_size - sizeof(struct ipv6_pinfo);
96 return (struct ipv6_pinfo *)(((u8 *)sk) + offset);
99 static int inet6_create(struct net *net, struct socket *sock, int protocol,
102 struct inet_sock *inet;
103 struct ipv6_pinfo *np;
105 struct inet_protosw *answer;
106 struct proto *answer_prot;
107 unsigned char answer_flags;
108 char answer_no_check;
109 int try_loading_module = 0;
112 if (protocol < 0 || protocol >= IPPROTO_MAX)
115 if (sock->type != SOCK_RAW &&
116 sock->type != SOCK_DGRAM &&
118 build_ehash_secret();
120 /* Look for the requested type/protocol pair. */
122 err = -ESOCKTNOSUPPORT;
124 list_for_each_entry_rcu(answer, &inetsw6[sock->type], list) {
127 /* Check the non-wild match. */
128 if (protocol == answer->protocol) {
129 if (protocol != IPPROTO_IP)
132 /* Check for the two wild cases. */
133 if (IPPROTO_IP == protocol) {
134 protocol = answer->protocol;
137 if (IPPROTO_IP == answer->protocol)
140 err = -EPROTONOSUPPORT;
144 if (try_loading_module < 2) {
147 * Be more specific, e.g. net-pf-10-proto-132-type-1
148 * (net-pf-PF_INET6-proto-IPPROTO_SCTP-type-SOCK_STREAM)
150 if (++try_loading_module == 1)
151 request_module("net-pf-%d-proto-%d-type-%d",
152 PF_INET6, protocol, sock->type);
154 * Fall back to generic, e.g. net-pf-10-proto-132
155 * (net-pf-PF_INET6-proto-IPPROTO_SCTP)
158 request_module("net-pf-%d-proto-%d",
160 goto lookup_protocol;
166 if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
169 sock->ops = answer->ops;
170 answer_prot = answer->prot;
171 answer_no_check = answer->no_check;
172 answer_flags = answer->flags;
175 WARN_ON(answer_prot->slab == NULL);
178 sk = sk_alloc(net, PF_INET6, GFP_KERNEL, answer_prot);
182 sock_init_data(sock, sk);
185 sk->sk_no_check = answer_no_check;
186 if (INET_PROTOSW_REUSE & answer_flags)
190 inet->is_icsk = (INET_PROTOSW_ICSK & answer_flags) != 0;
192 if (SOCK_RAW == sock->type) {
193 inet->inet_num = protocol;
194 if (IPPROTO_RAW == protocol)
198 sk->sk_destruct = inet_sock_destruct;
199 sk->sk_family = PF_INET6;
200 sk->sk_protocol = protocol;
202 sk->sk_backlog_rcv = answer->prot->backlog_rcv;
204 inet_sk(sk)->pinet6 = np = inet6_sk_generic(sk);
206 np->mcast_hops = IPV6_DEFAULT_MCASTHOPS;
208 np->pmtudisc = IPV6_PMTUDISC_WANT;
209 np->ipv6only = net->ipv6.sysctl.bindv6only;
211 /* Init the ipv4 part of the socket since we can have sockets
212 * using v6 API for ipv4.
219 inet->mc_list = NULL;
221 if (ipv4_config.no_pmtu_disc)
222 inet->pmtudisc = IP_PMTUDISC_DONT;
224 inet->pmtudisc = IP_PMTUDISC_WANT;
226 * Increment only the relevant sk_prot->socks debug field, this changes
227 * the previous behaviour of incrementing both the equivalent to
228 * answer->prot->socks (inet6_sock_nr) and inet_sock_nr.
230 * This allows better debug granularity as we'll know exactly how many
231 * UDPv6, TCPv6, etc socks were allocated, not the sum of all IPv6
232 * transport protocol socks. -acme
234 sk_refcnt_debug_inc(sk);
236 if (inet->inet_num) {
237 /* It assumes that any protocol which allows
238 * the user to assign a number at socket
239 * creation time automatically shares.
241 inet->inet_sport = htons(inet->inet_num);
242 sk->sk_prot->hash(sk);
244 if (sk->sk_prot->init) {
245 err = sk->sk_prot->init(sk);
247 sk_common_release(sk);
259 /* bind for INET6 API */
260 int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
262 struct sockaddr_in6 *addr=(struct sockaddr_in6 *)uaddr;
263 struct sock *sk = sock->sk;
264 struct inet_sock *inet = inet_sk(sk);
265 struct ipv6_pinfo *np = inet6_sk(sk);
266 struct net *net = sock_net(sk);
272 /* If the socket has its own bind function then use it. */
273 if (sk->sk_prot->bind)
274 return sk->sk_prot->bind(sk, uaddr, addr_len);
276 if (addr_len < SIN6_LEN_RFC2133)
279 if (addr->sin6_family != AF_INET6)
280 return -EAFNOSUPPORT;
282 addr_type = ipv6_addr_type(&addr->sin6_addr);
283 if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
286 snum = ntohs(addr->sin6_port);
287 if (snum && snum < PROT_SOCK && !capable(CAP_NET_BIND_SERVICE))
292 /* Check these errors (active socket, double bind). */
293 if (sk->sk_state != TCP_CLOSE || inet->inet_num) {
298 /* Check if the address belongs to the host. */
299 if (addr_type == IPV6_ADDR_MAPPED) {
302 /* Binding to v4-mapped address on a v6-only socket
310 /* Reproduce AF_INET checks to make the bindings consistent */
311 v4addr = addr->sin6_addr.s6_addr32[3];
312 chk_addr_ret = inet_addr_type(net, v4addr);
313 if (!sysctl_ip_nonlocal_bind &&
314 !(inet->freebind || inet->transparent) &&
315 v4addr != htonl(INADDR_ANY) &&
316 chk_addr_ret != RTN_LOCAL &&
317 chk_addr_ret != RTN_MULTICAST &&
318 chk_addr_ret != RTN_BROADCAST) {
319 err = -EADDRNOTAVAIL;
323 if (addr_type != IPV6_ADDR_ANY) {
324 struct net_device *dev = NULL;
327 if (addr_type & IPV6_ADDR_LINKLOCAL) {
328 if (addr_len >= sizeof(struct sockaddr_in6) &&
329 addr->sin6_scope_id) {
330 /* Override any existing binding, if another one
331 * is supplied by user.
333 sk->sk_bound_dev_if = addr->sin6_scope_id;
336 /* Binding to link-local address requires an interface */
337 if (!sk->sk_bound_dev_if) {
341 dev = dev_get_by_index_rcu(net, sk->sk_bound_dev_if);
348 /* ipv4 addr of the socket is invalid. Only the
349 * unspecified and mapped address have a v4 equivalent.
351 v4addr = LOOPBACK4_IPV6;
352 if (!(addr_type & IPV6_ADDR_MULTICAST)) {
353 if (!inet->transparent &&
354 !ipv6_chk_addr(net, &addr->sin6_addr,
356 err = -EADDRNOTAVAIL;
364 inet->inet_rcv_saddr = v4addr;
365 inet->inet_saddr = v4addr;
367 ipv6_addr_copy(&np->rcv_saddr, &addr->sin6_addr);
369 if (!(addr_type & IPV6_ADDR_MULTICAST))
370 ipv6_addr_copy(&np->saddr, &addr->sin6_addr);
372 /* Make sure we are allowed to bind here. */
373 if (sk->sk_prot->get_port(sk, snum)) {
374 inet_reset_saddr(sk);
379 if (addr_type != IPV6_ADDR_ANY) {
380 sk->sk_userlocks |= SOCK_BINDADDR_LOCK;
381 if (addr_type != IPV6_ADDR_MAPPED)
385 sk->sk_userlocks |= SOCK_BINDPORT_LOCK;
386 inet->inet_sport = htons(inet->inet_num);
387 inet->inet_dport = 0;
388 inet->inet_daddr = 0;
397 EXPORT_SYMBOL(inet6_bind);
399 int inet6_release(struct socket *sock)
401 struct sock *sk = sock->sk;
407 ipv6_sock_mc_close(sk);
410 ipv6_sock_ac_close(sk);
412 return inet_release(sock);
415 EXPORT_SYMBOL(inet6_release);
417 void inet6_destroy_sock(struct sock *sk)
419 struct ipv6_pinfo *np = inet6_sk(sk);
421 struct ipv6_txoptions *opt;
423 /* Release rx options */
425 if ((skb = xchg(&np->pktoptions, NULL)) != NULL)
428 if ((skb = xchg(&np->rxpmtu, NULL)) != NULL)
431 /* Free flowlabels */
432 fl6_free_socklist(sk);
434 /* Free tx options */
436 opt = xchg((__force struct ipv6_txoptions **)&np->opt, NULL);
438 atomic_sub(opt->tot_len, &sk->sk_omem_alloc);
443 EXPORT_SYMBOL_GPL(inet6_destroy_sock);
446 * This does both peername and sockname.
449 int inet6_getname(struct socket *sock, struct sockaddr *uaddr,
450 int *uaddr_len, int peer)
452 struct sockaddr_in6 *sin=(struct sockaddr_in6 *)uaddr;
453 struct sock *sk = sock->sk;
454 struct inet_sock *inet = inet_sk(sk);
455 struct ipv6_pinfo *np = inet6_sk(sk);
457 sin->sin6_family = AF_INET6;
458 sin->sin6_flowinfo = 0;
459 sin->sin6_scope_id = 0;
461 if (!inet->inet_dport)
463 if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_SYN_SENT)) &&
466 sin->sin6_port = inet->inet_dport;
467 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
469 sin->sin6_flowinfo = np->flow_label;
471 if (ipv6_addr_any(&np->rcv_saddr))
472 ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
474 ipv6_addr_copy(&sin->sin6_addr, &np->rcv_saddr);
476 sin->sin6_port = inet->inet_sport;
478 if (ipv6_addr_type(&sin->sin6_addr) & IPV6_ADDR_LINKLOCAL)
479 sin->sin6_scope_id = sk->sk_bound_dev_if;
480 *uaddr_len = sizeof(*sin);
484 EXPORT_SYMBOL(inet6_getname);
486 int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
488 struct sock *sk = sock->sk;
489 struct net *net = sock_net(sk);
494 return sock_get_timestamp(sk, (struct timeval __user *)arg);
497 return sock_get_timestampns(sk, (struct timespec __user *)arg);
502 return ipv6_route_ioctl(net, cmd, (void __user *)arg);
505 return addrconf_add_ifaddr(net, (void __user *) arg);
507 return addrconf_del_ifaddr(net, (void __user *) arg);
509 return addrconf_set_dstaddr(net, (void __user *) arg);
511 if (!sk->sk_prot->ioctl)
513 return sk->sk_prot->ioctl(sk, cmd, arg);
519 EXPORT_SYMBOL(inet6_ioctl);
521 const struct proto_ops inet6_stream_ops = {
523 .owner = THIS_MODULE,
524 .release = inet6_release,
526 .connect = inet_stream_connect, /* ok */
527 .socketpair = sock_no_socketpair, /* a do nothing */
528 .accept = inet_accept, /* ok */
529 .getname = inet6_getname,
530 .poll = tcp_poll, /* ok */
531 .ioctl = inet6_ioctl, /* must change */
532 .listen = inet_listen, /* ok */
533 .shutdown = inet_shutdown, /* ok */
534 .setsockopt = sock_common_setsockopt, /* ok */
535 .getsockopt = sock_common_getsockopt, /* ok */
536 .sendmsg = inet_sendmsg, /* ok */
537 .recvmsg = inet_recvmsg, /* ok */
538 .mmap = sock_no_mmap,
539 .sendpage = inet_sendpage,
540 .splice_read = tcp_splice_read,
542 .compat_setsockopt = compat_sock_common_setsockopt,
543 .compat_getsockopt = compat_sock_common_getsockopt,
547 const struct proto_ops inet6_dgram_ops = {
549 .owner = THIS_MODULE,
550 .release = inet6_release,
552 .connect = inet_dgram_connect, /* ok */
553 .socketpair = sock_no_socketpair, /* a do nothing */
554 .accept = sock_no_accept, /* a do nothing */
555 .getname = inet6_getname,
556 .poll = udp_poll, /* ok */
557 .ioctl = inet6_ioctl, /* must change */
558 .listen = sock_no_listen, /* ok */
559 .shutdown = inet_shutdown, /* ok */
560 .setsockopt = sock_common_setsockopt, /* ok */
561 .getsockopt = sock_common_getsockopt, /* ok */
562 .sendmsg = inet_sendmsg, /* ok */
563 .recvmsg = inet_recvmsg, /* ok */
564 .mmap = sock_no_mmap,
565 .sendpage = sock_no_sendpage,
567 .compat_setsockopt = compat_sock_common_setsockopt,
568 .compat_getsockopt = compat_sock_common_getsockopt,
572 static const struct net_proto_family inet6_family_ops = {
574 .create = inet6_create,
575 .owner = THIS_MODULE,
578 int inet6_register_protosw(struct inet_protosw *p)
580 struct list_head *lh;
581 struct inet_protosw *answer;
582 struct list_head *last_perm;
583 int protocol = p->protocol;
586 spin_lock_bh(&inetsw6_lock);
589 if (p->type >= SOCK_MAX)
592 /* If we are trying to override a permanent protocol, bail. */
595 last_perm = &inetsw6[p->type];
596 list_for_each(lh, &inetsw6[p->type]) {
597 answer = list_entry(lh, struct inet_protosw, list);
599 /* Check only the non-wild match. */
600 if (INET_PROTOSW_PERMANENT & answer->flags) {
601 if (protocol == answer->protocol)
611 /* Add the new entry after the last permanent entry if any, so that
612 * the new entry does not override a permanent entry when matched with
613 * a wild-card protocol. But it is allowed to override any existing
614 * non-permanent entry. This means that when we remove this entry, the
615 * system automatically returns to the old behavior.
617 list_add_rcu(&p->list, last_perm);
620 spin_unlock_bh(&inetsw6_lock);
624 printk(KERN_ERR "Attempt to override permanent protocol %d.\n",
630 "Ignoring attempt to register invalid socket type %d.\n",
635 EXPORT_SYMBOL(inet6_register_protosw);
638 inet6_unregister_protosw(struct inet_protosw *p)
640 if (INET_PROTOSW_PERMANENT & p->flags) {
642 "Attempt to unregister permanent protocol %d.\n",
645 spin_lock_bh(&inetsw6_lock);
646 list_del_rcu(&p->list);
647 spin_unlock_bh(&inetsw6_lock);
653 EXPORT_SYMBOL(inet6_unregister_protosw);
655 int inet6_sk_rebuild_header(struct sock *sk)
657 struct ipv6_pinfo *np = inet6_sk(sk);
658 struct dst_entry *dst;
660 dst = __sk_dst_check(sk, np->dst_cookie);
663 struct inet_sock *inet = inet_sk(sk);
664 struct in6_addr *final_p, final;
667 memset(&fl6, 0, sizeof(fl6));
668 fl6.flowi6_proto = sk->sk_protocol;
669 ipv6_addr_copy(&fl6.daddr, &np->daddr);
670 ipv6_addr_copy(&fl6.saddr, &np->saddr);
671 fl6.flowlabel = np->flow_label;
672 fl6.flowi6_oif = sk->sk_bound_dev_if;
673 fl6.flowi6_mark = sk->sk_mark;
674 fl6.fl6_dport = inet->inet_dport;
675 fl6.fl6_sport = inet->inet_sport;
676 security_sk_classify_flow(sk, flowi6_to_flowi(&fl6));
679 final_p = fl6_update_dst(&fl6, rcu_dereference(np->opt),
683 dst = ip6_dst_lookup_flow(sk, &fl6, final_p, false);
685 sk->sk_route_caps = 0;
686 sk->sk_err_soft = -PTR_ERR(dst);
690 __ip6_dst_store(sk, dst, NULL, NULL);
696 EXPORT_SYMBOL_GPL(inet6_sk_rebuild_header);
698 int ipv6_opt_accepted(struct sock *sk, struct sk_buff *skb)
700 struct ipv6_pinfo *np = inet6_sk(sk);
701 struct inet6_skb_parm *opt = IP6CB(skb);
704 if ((opt->hop && (np->rxopt.bits.hopopts ||
705 np->rxopt.bits.ohopopts)) ||
706 ((IPV6_FLOWINFO_MASK &
707 *(__be32 *)skb_network_header(skb)) &&
708 np->rxopt.bits.rxflow) ||
709 (opt->srcrt && (np->rxopt.bits.srcrt ||
710 np->rxopt.bits.osrcrt)) ||
711 ((opt->dst1 || opt->dst0) &&
712 (np->rxopt.bits.dstopts || np->rxopt.bits.odstopts)))
718 EXPORT_SYMBOL_GPL(ipv6_opt_accepted);
720 static int ipv6_gso_pull_exthdrs(struct sk_buff *skb, int proto)
722 const struct inet6_protocol *ops = NULL;
725 struct ipv6_opt_hdr *opth;
728 if (proto != NEXTHDR_HOP) {
729 ops = rcu_dereference(inet6_protos[proto]);
734 if (!(ops->flags & INET6_PROTO_GSO_EXTHDR))
738 if (unlikely(!pskb_may_pull(skb, 8)))
741 opth = (void *)skb->data;
742 len = ipv6_optlen(opth);
744 if (unlikely(!pskb_may_pull(skb, len)))
747 proto = opth->nexthdr;
748 __skb_pull(skb, len);
754 static int ipv6_gso_send_check(struct sk_buff *skb)
756 const struct ipv6hdr *ipv6h;
757 const struct inet6_protocol *ops;
760 if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h))))
763 ipv6h = ipv6_hdr(skb);
764 __skb_pull(skb, sizeof(*ipv6h));
765 err = -EPROTONOSUPPORT;
768 ops = rcu_dereference(inet6_protos[
769 ipv6_gso_pull_exthdrs(skb, ipv6h->nexthdr)]);
771 if (likely(ops && ops->gso_send_check)) {
772 skb_reset_transport_header(skb);
773 err = ops->gso_send_check(skb);
781 static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb, u32 features)
783 struct sk_buff *segs = ERR_PTR(-EINVAL);
784 struct ipv6hdr *ipv6h;
785 const struct inet6_protocol *ops;
787 struct frag_hdr *fptr;
788 unsigned int unfrag_ip6hlen;
792 if (!(features & NETIF_F_V6_CSUM))
793 features &= ~NETIF_F_SG;
795 if (unlikely(skb_shinfo(skb)->gso_type &
803 if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h))))
806 ipv6h = ipv6_hdr(skb);
807 __skb_pull(skb, sizeof(*ipv6h));
808 segs = ERR_PTR(-EPROTONOSUPPORT);
810 proto = ipv6_gso_pull_exthdrs(skb, ipv6h->nexthdr);
812 ops = rcu_dereference(inet6_protos[proto]);
813 if (likely(ops && ops->gso_segment)) {
814 skb_reset_transport_header(skb);
815 segs = ops->gso_segment(skb, features);
822 for (skb = segs; skb; skb = skb->next) {
823 ipv6h = ipv6_hdr(skb);
824 ipv6h->payload_len = htons(skb->len - skb->mac_len -
826 if (proto == IPPROTO_UDP) {
827 unfrag_ip6hlen = ip6_find_1stfragopt(skb, &prevhdr);
828 fptr = (struct frag_hdr *)(skb_network_header(skb) +
830 fptr->frag_off = htons(offset);
831 if (skb->next != NULL)
832 fptr->frag_off |= htons(IP6_MF);
833 offset += (ntohs(ipv6h->payload_len) -
834 sizeof(struct frag_hdr));
843 struct napi_gro_cb napi;
847 #define IPV6_GRO_CB(skb) ((struct ipv6_gro_cb *)(skb)->cb)
849 static struct sk_buff **ipv6_gro_receive(struct sk_buff **head,
852 const struct inet6_protocol *ops;
853 struct sk_buff **pp = NULL;
863 off = skb_gro_offset(skb);
864 hlen = off + sizeof(*iph);
865 iph = skb_gro_header_fast(skb, off);
866 if (skb_gro_header_hard(skb, hlen)) {
867 iph = skb_gro_header_slow(skb, hlen, off);
872 skb_gro_pull(skb, sizeof(*iph));
873 skb_set_transport_header(skb, skb_gro_offset(skb));
875 flush += ntohs(iph->payload_len) != skb_gro_len(skb);
878 proto = iph->nexthdr;
879 ops = rcu_dereference(inet6_protos[proto]);
880 if (!ops || !ops->gro_receive) {
881 __pskb_pull(skb, skb_gro_offset(skb));
882 skb_gro_frag0_invalidate(skb);
883 proto = ipv6_gso_pull_exthdrs(skb, proto);
884 skb_gro_pull(skb, -skb_transport_offset(skb));
885 skb_reset_transport_header(skb);
886 __skb_push(skb, skb_gro_offset(skb));
888 ops = rcu_dereference(inet6_protos[proto]);
889 if (!ops || !ops->gro_receive)
895 IPV6_GRO_CB(skb)->proto = proto;
898 nlen = skb_network_header_len(skb);
900 for (p = *head; p; p = p->next) {
901 struct ipv6hdr *iph2;
903 if (!NAPI_GRO_CB(p)->same_flow)
908 /* All fields must match except length. */
909 if (nlen != skb_network_header_len(p) ||
910 memcmp(iph, iph2, offsetof(struct ipv6hdr, payload_len)) ||
911 memcmp(&iph->nexthdr, &iph2->nexthdr,
912 nlen - offsetof(struct ipv6hdr, nexthdr))) {
913 NAPI_GRO_CB(p)->same_flow = 0;
917 NAPI_GRO_CB(p)->flush |= flush;
920 NAPI_GRO_CB(skb)->flush |= flush;
923 skb_postpull_rcsum(skb, iph, skb_network_header_len(skb));
925 pp = ops->gro_receive(head, skb);
933 NAPI_GRO_CB(skb)->flush |= flush;
938 static int ipv6_gro_complete(struct sk_buff *skb)
940 const struct inet6_protocol *ops;
941 struct ipv6hdr *iph = ipv6_hdr(skb);
944 iph->payload_len = htons(skb->len - skb_network_offset(skb) -
948 ops = rcu_dereference(inet6_protos[IPV6_GRO_CB(skb)->proto]);
949 if (WARN_ON(!ops || !ops->gro_complete))
952 err = ops->gro_complete(skb);
960 static struct packet_type ipv6_packet_type __read_mostly = {
961 .type = cpu_to_be16(ETH_P_IPV6),
963 .gso_send_check = ipv6_gso_send_check,
964 .gso_segment = ipv6_gso_segment,
965 .gro_receive = ipv6_gro_receive,
966 .gro_complete = ipv6_gro_complete,
969 static int __init ipv6_packet_init(void)
971 dev_add_pack(&ipv6_packet_type);
975 static void ipv6_packet_cleanup(void)
977 dev_remove_pack(&ipv6_packet_type);
980 static int __net_init ipv6_init_mibs(struct net *net)
982 if (snmp_mib_init((void __percpu **)net->mib.udp_stats_in6,
983 sizeof(struct udp_mib),
984 __alignof__(struct udp_mib)) < 0)
986 if (snmp_mib_init((void __percpu **)net->mib.udplite_stats_in6,
987 sizeof(struct udp_mib),
988 __alignof__(struct udp_mib)) < 0)
989 goto err_udplite_mib;
990 if (snmp_mib_init((void __percpu **)net->mib.ipv6_statistics,
991 sizeof(struct ipstats_mib),
992 __alignof__(struct ipstats_mib)) < 0)
994 if (snmp_mib_init((void __percpu **)net->mib.icmpv6_statistics,
995 sizeof(struct icmpv6_mib),
996 __alignof__(struct icmpv6_mib)) < 0)
998 if (snmp_mib_init((void __percpu **)net->mib.icmpv6msg_statistics,
999 sizeof(struct icmpv6msg_mib),
1000 __alignof__(struct icmpv6msg_mib)) < 0)
1001 goto err_icmpmsg_mib;
1005 snmp_mib_free((void __percpu **)net->mib.icmpv6_statistics);
1007 snmp_mib_free((void __percpu **)net->mib.ipv6_statistics);
1009 snmp_mib_free((void __percpu **)net->mib.udplite_stats_in6);
1011 snmp_mib_free((void __percpu **)net->mib.udp_stats_in6);
1015 static void ipv6_cleanup_mibs(struct net *net)
1017 snmp_mib_free((void __percpu **)net->mib.udp_stats_in6);
1018 snmp_mib_free((void __percpu **)net->mib.udplite_stats_in6);
1019 snmp_mib_free((void __percpu **)net->mib.ipv6_statistics);
1020 snmp_mib_free((void __percpu **)net->mib.icmpv6_statistics);
1021 snmp_mib_free((void __percpu **)net->mib.icmpv6msg_statistics);
1024 static int __net_init inet6_net_init(struct net *net)
1028 net->ipv6.sysctl.bindv6only = 0;
1029 net->ipv6.sysctl.icmpv6_time = 1*HZ;
1031 err = ipv6_init_mibs(net);
1034 #ifdef CONFIG_PROC_FS
1035 err = udp6_proc_init(net);
1038 err = tcp6_proc_init(net);
1040 goto proc_tcp6_fail;
1041 err = ac6_proc_init(net);
1047 #ifdef CONFIG_PROC_FS
1049 tcp6_proc_exit(net);
1051 udp6_proc_exit(net);
1053 ipv6_cleanup_mibs(net);
1058 static void __net_exit inet6_net_exit(struct net *net)
1060 #ifdef CONFIG_PROC_FS
1061 udp6_proc_exit(net);
1062 tcp6_proc_exit(net);
1065 ipv6_cleanup_mibs(net);
1068 static struct pernet_operations inet6_net_ops = {
1069 .init = inet6_net_init,
1070 .exit = inet6_net_exit,
1073 static int __init inet6_init(void)
1075 struct sk_buff *dummy_skb;
1076 struct list_head *r;
1079 BUILD_BUG_ON(sizeof(struct inet6_skb_parm) > sizeof(dummy_skb->cb));
1081 /* Register the socket-side information for inet6_create. */
1082 for(r = &inetsw6[0]; r < &inetsw6[SOCK_MAX]; ++r)
1085 if (disable_ipv6_mod) {
1087 "IPv6: Loaded, but administratively disabled, "
1088 "reboot required to enable\n");
1092 err = proto_register(&tcpv6_prot, 1);
1096 err = proto_register(&udpv6_prot, 1);
1098 goto out_unregister_tcp_proto;
1100 err = proto_register(&udplitev6_prot, 1);
1102 goto out_unregister_udp_proto;
1104 err = proto_register(&rawv6_prot, 1);
1106 goto out_unregister_udplite_proto;
1109 /* We MUST register RAW sockets before we create the ICMP6,
1110 * IGMP6, or NDISC control sockets.
1114 goto out_unregister_raw_proto;
1116 /* Register the family here so that the init calls below will
1117 * be able to create sockets. (?? is this dangerous ??)
1119 err = sock_register(&inet6_family_ops);
1121 goto out_sock_register_fail;
1123 #ifdef CONFIG_SYSCTL
1124 err = ipv6_static_sysctl_register();
1126 goto static_sysctl_fail;
1129 * ipngwg API draft makes clear that the correct semantics
1130 * for TCP and UDP is to consider one TCP and UDP instance
1131 * in a host available by both INET and INET6 APIs and
1132 * able to communicate via both network protocols.
1135 err = register_pernet_subsys(&inet6_net_ops);
1137 goto register_pernet_fail;
1138 err = icmpv6_init();
1141 err = ip6_mr_init();
1150 err = ipv6_netfilter_init();
1152 goto netfilter_fail;
1153 /* Create /proc/foo6 entries. */
1154 #ifdef CONFIG_PROC_FS
1156 if (raw6_proc_init())
1157 goto proc_raw6_fail;
1158 if (udplite6_proc_init())
1159 goto proc_udplite6_fail;
1160 if (ipv6_misc_proc_init())
1161 goto proc_misc6_fail;
1162 if (if6_proc_init())
1165 err = ip6_route_init();
1167 goto ip6_route_fail;
1168 err = ip6_flowlabel_init();
1170 goto ip6_flowlabel_fail;
1171 err = addrconf_init();
1175 /* Init v6 extension headers. */
1176 err = ipv6_exthdrs_init();
1178 goto ipv6_exthdrs_fail;
1180 err = ipv6_frag_init();
1182 goto ipv6_frag_fail;
1184 /* Init v6 transport protocols. */
1189 err = udplitev6_init();
1191 goto udplitev6_fail;
1197 err = ipv6_packet_init();
1199 goto ipv6_packet_fail;
1201 #ifdef CONFIG_SYSCTL
1202 err = ipv6_sysctl_register();
1209 #ifdef CONFIG_SYSCTL
1211 ipv6_packet_cleanup();
1222 ipv6_exthdrs_exit();
1226 ip6_flowlabel_cleanup();
1228 ip6_route_cleanup();
1230 #ifdef CONFIG_PROC_FS
1233 ipv6_misc_proc_exit();
1235 udplite6_proc_exit();
1240 ipv6_netfilter_fini();
1250 unregister_pernet_subsys(&inet6_net_ops);
1251 register_pernet_fail:
1252 #ifdef CONFIG_SYSCTL
1253 ipv6_static_sysctl_unregister();
1256 sock_unregister(PF_INET6);
1257 rtnl_unregister_all(PF_INET6);
1258 out_sock_register_fail:
1260 out_unregister_raw_proto:
1261 proto_unregister(&rawv6_prot);
1262 out_unregister_udplite_proto:
1263 proto_unregister(&udplitev6_prot);
1264 out_unregister_udp_proto:
1265 proto_unregister(&udpv6_prot);
1266 out_unregister_tcp_proto:
1267 proto_unregister(&tcpv6_prot);
1270 module_init(inet6_init);
1272 static void __exit inet6_exit(void)
1274 if (disable_ipv6_mod)
1277 /* First of all disallow new sockets creation. */
1278 sock_unregister(PF_INET6);
1279 /* Disallow any further netlink messages */
1280 rtnl_unregister_all(PF_INET6);
1282 #ifdef CONFIG_SYSCTL
1283 ipv6_sysctl_unregister();
1289 /* Cleanup code parts. */
1290 ipv6_packet_cleanup();
1292 ipv6_exthdrs_exit();
1294 ip6_flowlabel_cleanup();
1295 ip6_route_cleanup();
1296 #ifdef CONFIG_PROC_FS
1298 /* Cleanup code parts. */
1300 ipv6_misc_proc_exit();
1301 udplite6_proc_exit();
1304 ipv6_netfilter_fini();
1311 unregister_pernet_subsys(&inet6_net_ops);
1312 #ifdef CONFIG_SYSCTL
1313 ipv6_static_sysctl_unregister();
1315 proto_unregister(&rawv6_prot);
1316 proto_unregister(&udplitev6_prot);
1317 proto_unregister(&udpv6_prot);
1318 proto_unregister(&tcpv6_prot);
1320 rcu_barrier(); /* Wait for completion of call_rcu()'s */
1322 module_exit(inet6_exit);
1324 MODULE_ALIAS_NETPROTO(PF_INET6);