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>
40 #include <linux/inet.h>
41 #include <linux/netdevice.h>
42 #include <linux/icmpv6.h>
43 #include <linux/netfilter_ipv6.h>
48 #include <net/udplite.h>
51 #include <net/protocol.h>
52 #include <net/inet_common.h>
53 #include <net/route.h>
54 #include <net/transp_v6.h>
55 #include <net/ip6_route.h>
56 #include <net/addrconf.h>
57 #ifdef CONFIG_IPV6_TUNNEL
58 #include <net/ip6_tunnel.h>
61 #include <asm/uaccess.h>
62 #include <asm/system.h>
63 #include <linux/mroute6.h>
65 MODULE_AUTHOR("Cast of dozens");
66 MODULE_DESCRIPTION("IPv6 protocol stack for Linux");
67 MODULE_LICENSE("GPL");
69 /* The inetsw6 table contains everything that inet6_create needs to
72 static struct list_head inetsw6
[SOCK_MAX
];
73 static DEFINE_SPINLOCK(inetsw6_lock
);
75 static int disable_ipv6
= 0;
76 module_param_named(disable
, disable_ipv6
, int, 0);
77 MODULE_PARM_DESC(disable
, "Disable IPv6 such that it is non-functional");
79 static __inline__
struct ipv6_pinfo
*inet6_sk_generic(struct sock
*sk
)
81 const int offset
= sk
->sk_prot
->obj_size
- sizeof(struct ipv6_pinfo
);
83 return (struct ipv6_pinfo
*)(((u8
*)sk
) + offset
);
86 static int inet6_create(struct net
*net
, struct socket
*sock
, int protocol
)
88 struct inet_sock
*inet
;
89 struct ipv6_pinfo
*np
;
91 struct inet_protosw
*answer
;
92 struct proto
*answer_prot
;
93 unsigned char answer_flags
;
95 int try_loading_module
= 0;
98 if (sock
->type
!= SOCK_RAW
&&
99 sock
->type
!= SOCK_DGRAM
&&
101 build_ehash_secret();
103 /* Look for the requested type/protocol pair. */
105 err
= -ESOCKTNOSUPPORT
;
107 list_for_each_entry_rcu(answer
, &inetsw6
[sock
->type
], list
) {
110 /* Check the non-wild match. */
111 if (protocol
== answer
->protocol
) {
112 if (protocol
!= IPPROTO_IP
)
115 /* Check for the two wild cases. */
116 if (IPPROTO_IP
== protocol
) {
117 protocol
= answer
->protocol
;
120 if (IPPROTO_IP
== answer
->protocol
)
123 err
= -EPROTONOSUPPORT
;
127 if (try_loading_module
< 2) {
130 * Be more specific, e.g. net-pf-10-proto-132-type-1
131 * (net-pf-PF_INET6-proto-IPPROTO_SCTP-type-SOCK_STREAM)
133 if (++try_loading_module
== 1)
134 request_module("net-pf-%d-proto-%d-type-%d",
135 PF_INET6
, protocol
, sock
->type
);
137 * Fall back to generic, e.g. net-pf-10-proto-132
138 * (net-pf-PF_INET6-proto-IPPROTO_SCTP)
141 request_module("net-pf-%d-proto-%d",
143 goto lookup_protocol
;
149 if (answer
->capability
> 0 && !capable(answer
->capability
))
152 sock
->ops
= answer
->ops
;
153 answer_prot
= answer
->prot
;
154 answer_no_check
= answer
->no_check
;
155 answer_flags
= answer
->flags
;
158 WARN_ON(answer_prot
->slab
== NULL
);
161 sk
= sk_alloc(net
, PF_INET6
, GFP_KERNEL
, answer_prot
);
165 sock_init_data(sock
, sk
);
168 sk
->sk_no_check
= answer_no_check
;
169 if (INET_PROTOSW_REUSE
& answer_flags
)
173 inet
->is_icsk
= (INET_PROTOSW_ICSK
& answer_flags
) != 0;
175 if (SOCK_RAW
== sock
->type
) {
176 inet
->num
= protocol
;
177 if (IPPROTO_RAW
== protocol
)
181 sk
->sk_destruct
= inet_sock_destruct
;
182 sk
->sk_family
= PF_INET6
;
183 sk
->sk_protocol
= protocol
;
185 sk
->sk_backlog_rcv
= answer
->prot
->backlog_rcv
;
187 inet_sk(sk
)->pinet6
= np
= inet6_sk_generic(sk
);
191 np
->pmtudisc
= IPV6_PMTUDISC_WANT
;
192 np
->ipv6only
= net
->ipv6
.sysctl
.bindv6only
;
194 /* Init the ipv4 part of the socket since we can have sockets
195 * using v6 API for ipv4.
202 inet
->mc_list
= NULL
;
204 if (ipv4_config
.no_pmtu_disc
)
205 inet
->pmtudisc
= IP_PMTUDISC_DONT
;
207 inet
->pmtudisc
= IP_PMTUDISC_WANT
;
209 * Increment only the relevant sk_prot->socks debug field, this changes
210 * the previous behaviour of incrementing both the equivalent to
211 * answer->prot->socks (inet6_sock_nr) and inet_sock_nr.
213 * This allows better debug granularity as we'll know exactly how many
214 * UDPv6, TCPv6, etc socks were allocated, not the sum of all IPv6
215 * transport protocol socks. -acme
217 sk_refcnt_debug_inc(sk
);
220 /* It assumes that any protocol which allows
221 * the user to assign a number at socket
222 * creation time automatically shares.
224 inet
->sport
= htons(inet
->num
);
225 sk
->sk_prot
->hash(sk
);
227 if (sk
->sk_prot
->init
) {
228 err
= sk
->sk_prot
->init(sk
);
230 sk_common_release(sk
);
242 /* bind for INET6 API */
243 int inet6_bind(struct socket
*sock
, struct sockaddr
*uaddr
, int addr_len
)
245 struct sockaddr_in6
*addr
=(struct sockaddr_in6
*)uaddr
;
246 struct sock
*sk
= sock
->sk
;
247 struct inet_sock
*inet
= inet_sk(sk
);
248 struct ipv6_pinfo
*np
= inet6_sk(sk
);
249 struct net
*net
= sock_net(sk
);
255 /* If the socket has its own bind function then use it. */
256 if (sk
->sk_prot
->bind
)
257 return sk
->sk_prot
->bind(sk
, uaddr
, addr_len
);
259 if (addr_len
< SIN6_LEN_RFC2133
)
261 addr_type
= ipv6_addr_type(&addr
->sin6_addr
);
262 if ((addr_type
& IPV6_ADDR_MULTICAST
) && sock
->type
== SOCK_STREAM
)
265 snum
= ntohs(addr
->sin6_port
);
266 if (snum
&& snum
< PROT_SOCK
&& !capable(CAP_NET_BIND_SERVICE
))
271 /* Check these errors (active socket, double bind). */
272 if (sk
->sk_state
!= TCP_CLOSE
|| inet
->num
) {
277 /* Check if the address belongs to the host. */
278 if (addr_type
== IPV6_ADDR_MAPPED
) {
279 /* Binding to v4-mapped address on a v6-only socket
286 v4addr
= addr
->sin6_addr
.s6_addr32
[3];
287 if (inet_addr_type(net
, v4addr
) != RTN_LOCAL
) {
288 err
= -EADDRNOTAVAIL
;
292 if (addr_type
!= IPV6_ADDR_ANY
) {
293 struct net_device
*dev
= NULL
;
295 if (addr_type
& IPV6_ADDR_LINKLOCAL
) {
296 if (addr_len
>= sizeof(struct sockaddr_in6
) &&
297 addr
->sin6_scope_id
) {
298 /* Override any existing binding, if another one
299 * is supplied by user.
301 sk
->sk_bound_dev_if
= addr
->sin6_scope_id
;
304 /* Binding to link-local address requires an interface */
305 if (!sk
->sk_bound_dev_if
) {
309 dev
= dev_get_by_index(net
, sk
->sk_bound_dev_if
);
316 /* ipv4 addr of the socket is invalid. Only the
317 * unspecified and mapped address have a v4 equivalent.
319 v4addr
= LOOPBACK4_IPV6
;
320 if (!(addr_type
& IPV6_ADDR_MULTICAST
)) {
321 if (!ipv6_chk_addr(net
, &addr
->sin6_addr
,
325 err
= -EADDRNOTAVAIL
;
334 inet
->rcv_saddr
= v4addr
;
335 inet
->saddr
= v4addr
;
337 ipv6_addr_copy(&np
->rcv_saddr
, &addr
->sin6_addr
);
339 if (!(addr_type
& IPV6_ADDR_MULTICAST
))
340 ipv6_addr_copy(&np
->saddr
, &addr
->sin6_addr
);
342 /* Make sure we are allowed to bind here. */
343 if (sk
->sk_prot
->get_port(sk
, snum
)) {
344 inet_reset_saddr(sk
);
349 if (addr_type
!= IPV6_ADDR_ANY
) {
350 sk
->sk_userlocks
|= SOCK_BINDADDR_LOCK
;
351 if (addr_type
!= IPV6_ADDR_MAPPED
)
355 sk
->sk_userlocks
|= SOCK_BINDPORT_LOCK
;
356 inet
->sport
= htons(inet
->num
);
364 EXPORT_SYMBOL(inet6_bind
);
366 int inet6_release(struct socket
*sock
)
368 struct sock
*sk
= sock
->sk
;
374 ipv6_sock_mc_close(sk
);
377 ipv6_sock_ac_close(sk
);
379 return inet_release(sock
);
382 EXPORT_SYMBOL(inet6_release
);
384 void inet6_destroy_sock(struct sock
*sk
)
386 struct ipv6_pinfo
*np
= inet6_sk(sk
);
388 struct ipv6_txoptions
*opt
;
390 /* Release rx options */
392 if ((skb
= xchg(&np
->pktoptions
, NULL
)) != NULL
)
395 /* Free flowlabels */
396 fl6_free_socklist(sk
);
398 /* Free tx options */
400 if ((opt
= xchg(&np
->opt
, NULL
)) != NULL
)
401 sock_kfree_s(sk
, opt
, opt
->tot_len
);
404 EXPORT_SYMBOL_GPL(inet6_destroy_sock
);
407 * This does both peername and sockname.
410 int inet6_getname(struct socket
*sock
, struct sockaddr
*uaddr
,
411 int *uaddr_len
, int peer
)
413 struct sockaddr_in6
*sin
=(struct sockaddr_in6
*)uaddr
;
414 struct sock
*sk
= sock
->sk
;
415 struct inet_sock
*inet
= inet_sk(sk
);
416 struct ipv6_pinfo
*np
= inet6_sk(sk
);
418 sin
->sin6_family
= AF_INET6
;
419 sin
->sin6_flowinfo
= 0;
420 sin
->sin6_scope_id
= 0;
424 if (((1 << sk
->sk_state
) & (TCPF_CLOSE
| TCPF_SYN_SENT
)) &&
427 sin
->sin6_port
= inet
->dport
;
428 ipv6_addr_copy(&sin
->sin6_addr
, &np
->daddr
);
430 sin
->sin6_flowinfo
= np
->flow_label
;
432 if (ipv6_addr_any(&np
->rcv_saddr
))
433 ipv6_addr_copy(&sin
->sin6_addr
, &np
->saddr
);
435 ipv6_addr_copy(&sin
->sin6_addr
, &np
->rcv_saddr
);
437 sin
->sin6_port
= inet
->sport
;
439 if (ipv6_addr_type(&sin
->sin6_addr
) & IPV6_ADDR_LINKLOCAL
)
440 sin
->sin6_scope_id
= sk
->sk_bound_dev_if
;
441 *uaddr_len
= sizeof(*sin
);
445 EXPORT_SYMBOL(inet6_getname
);
447 int inet6_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
)
449 struct sock
*sk
= sock
->sk
;
450 struct net
*net
= sock_net(sk
);
455 return sock_get_timestamp(sk
, (struct timeval __user
*)arg
);
458 return sock_get_timestampns(sk
, (struct timespec __user
*)arg
);
463 return(ipv6_route_ioctl(net
, cmd
, (void __user
*)arg
));
466 return addrconf_add_ifaddr(net
, (void __user
*) arg
);
468 return addrconf_del_ifaddr(net
, (void __user
*) arg
);
470 return addrconf_set_dstaddr(net
, (void __user
*) arg
);
472 if (!sk
->sk_prot
->ioctl
)
474 return sk
->sk_prot
->ioctl(sk
, cmd
, arg
);
480 EXPORT_SYMBOL(inet6_ioctl
);
482 const struct proto_ops inet6_stream_ops
= {
484 .owner
= THIS_MODULE
,
485 .release
= inet6_release
,
487 .connect
= inet_stream_connect
, /* ok */
488 .socketpair
= sock_no_socketpair
, /* a do nothing */
489 .accept
= inet_accept
, /* ok */
490 .getname
= inet6_getname
,
491 .poll
= tcp_poll
, /* ok */
492 .ioctl
= inet6_ioctl
, /* must change */
493 .listen
= inet_listen
, /* ok */
494 .shutdown
= inet_shutdown
, /* ok */
495 .setsockopt
= sock_common_setsockopt
, /* ok */
496 .getsockopt
= sock_common_getsockopt
, /* ok */
497 .sendmsg
= tcp_sendmsg
, /* ok */
498 .recvmsg
= sock_common_recvmsg
, /* ok */
499 .mmap
= sock_no_mmap
,
500 .sendpage
= tcp_sendpage
,
501 .splice_read
= tcp_splice_read
,
503 .compat_setsockopt
= compat_sock_common_setsockopt
,
504 .compat_getsockopt
= compat_sock_common_getsockopt
,
508 const struct proto_ops inet6_dgram_ops
= {
510 .owner
= THIS_MODULE
,
511 .release
= inet6_release
,
513 .connect
= inet_dgram_connect
, /* ok */
514 .socketpair
= sock_no_socketpair
, /* a do nothing */
515 .accept
= sock_no_accept
, /* a do nothing */
516 .getname
= inet6_getname
,
517 .poll
= udp_poll
, /* ok */
518 .ioctl
= inet6_ioctl
, /* must change */
519 .listen
= sock_no_listen
, /* ok */
520 .shutdown
= inet_shutdown
, /* ok */
521 .setsockopt
= sock_common_setsockopt
, /* ok */
522 .getsockopt
= sock_common_getsockopt
, /* ok */
523 .sendmsg
= inet_sendmsg
, /* ok */
524 .recvmsg
= sock_common_recvmsg
, /* ok */
525 .mmap
= sock_no_mmap
,
526 .sendpage
= sock_no_sendpage
,
528 .compat_setsockopt
= compat_sock_common_setsockopt
,
529 .compat_getsockopt
= compat_sock_common_getsockopt
,
533 static struct net_proto_family inet6_family_ops
= {
535 .create
= inet6_create
,
536 .owner
= THIS_MODULE
,
539 int inet6_register_protosw(struct inet_protosw
*p
)
541 struct list_head
*lh
;
542 struct inet_protosw
*answer
;
543 struct list_head
*last_perm
;
544 int protocol
= p
->protocol
;
547 spin_lock_bh(&inetsw6_lock
);
550 if (p
->type
>= SOCK_MAX
)
553 /* If we are trying to override a permanent protocol, bail. */
556 last_perm
= &inetsw6
[p
->type
];
557 list_for_each(lh
, &inetsw6
[p
->type
]) {
558 answer
= list_entry(lh
, struct inet_protosw
, list
);
560 /* Check only the non-wild match. */
561 if (INET_PROTOSW_PERMANENT
& answer
->flags
) {
562 if (protocol
== answer
->protocol
)
572 /* Add the new entry after the last permanent entry if any, so that
573 * the new entry does not override a permanent entry when matched with
574 * a wild-card protocol. But it is allowed to override any existing
575 * non-permanent entry. This means that when we remove this entry, the
576 * system automatically returns to the old behavior.
578 list_add_rcu(&p
->list
, last_perm
);
581 spin_unlock_bh(&inetsw6_lock
);
585 printk(KERN_ERR
"Attempt to override permanent protocol %d.\n",
591 "Ignoring attempt to register invalid socket type %d.\n",
596 EXPORT_SYMBOL(inet6_register_protosw
);
599 inet6_unregister_protosw(struct inet_protosw
*p
)
601 if (INET_PROTOSW_PERMANENT
& p
->flags
) {
603 "Attempt to unregister permanent protocol %d.\n",
606 spin_lock_bh(&inetsw6_lock
);
607 list_del_rcu(&p
->list
);
608 spin_unlock_bh(&inetsw6_lock
);
614 EXPORT_SYMBOL(inet6_unregister_protosw
);
616 int inet6_sk_rebuild_header(struct sock
*sk
)
619 struct dst_entry
*dst
;
620 struct ipv6_pinfo
*np
= inet6_sk(sk
);
622 dst
= __sk_dst_check(sk
, np
->dst_cookie
);
625 struct inet_sock
*inet
= inet_sk(sk
);
626 struct in6_addr
*final_p
= NULL
, final
;
629 memset(&fl
, 0, sizeof(fl
));
630 fl
.proto
= sk
->sk_protocol
;
631 ipv6_addr_copy(&fl
.fl6_dst
, &np
->daddr
);
632 ipv6_addr_copy(&fl
.fl6_src
, &np
->saddr
);
633 fl
.fl6_flowlabel
= np
->flow_label
;
634 fl
.oif
= sk
->sk_bound_dev_if
;
635 fl
.fl_ip_dport
= inet
->dport
;
636 fl
.fl_ip_sport
= inet
->sport
;
637 security_sk_classify_flow(sk
, &fl
);
639 if (np
->opt
&& np
->opt
->srcrt
) {
640 struct rt0_hdr
*rt0
= (struct rt0_hdr
*) np
->opt
->srcrt
;
641 ipv6_addr_copy(&final
, &fl
.fl6_dst
);
642 ipv6_addr_copy(&fl
.fl6_dst
, rt0
->addr
);
646 err
= ip6_dst_lookup(sk
, &dst
, &fl
);
648 sk
->sk_route_caps
= 0;
652 ipv6_addr_copy(&fl
.fl6_dst
, final_p
);
654 if ((err
= xfrm_lookup(sock_net(sk
), &dst
, &fl
, sk
, 0)) < 0) {
655 sk
->sk_err_soft
= -err
;
659 __ip6_dst_store(sk
, dst
, NULL
, NULL
);
665 EXPORT_SYMBOL_GPL(inet6_sk_rebuild_header
);
667 int ipv6_opt_accepted(struct sock
*sk
, struct sk_buff
*skb
)
669 struct ipv6_pinfo
*np
= inet6_sk(sk
);
670 struct inet6_skb_parm
*opt
= IP6CB(skb
);
673 if ((opt
->hop
&& (np
->rxopt
.bits
.hopopts
||
674 np
->rxopt
.bits
.ohopopts
)) ||
675 ((IPV6_FLOWINFO_MASK
&
676 *(__be32
*)skb_network_header(skb
)) &&
677 np
->rxopt
.bits
.rxflow
) ||
678 (opt
->srcrt
&& (np
->rxopt
.bits
.srcrt
||
679 np
->rxopt
.bits
.osrcrt
)) ||
680 ((opt
->dst1
|| opt
->dst0
) &&
681 (np
->rxopt
.bits
.dstopts
|| np
->rxopt
.bits
.odstopts
)))
687 EXPORT_SYMBOL_GPL(ipv6_opt_accepted
);
689 static int ipv6_gso_pull_exthdrs(struct sk_buff
*skb
, int proto
)
691 struct inet6_protocol
*ops
= NULL
;
694 struct ipv6_opt_hdr
*opth
;
697 if (proto
!= NEXTHDR_HOP
) {
698 ops
= rcu_dereference(inet6_protos
[proto
]);
703 if (!(ops
->flags
& INET6_PROTO_GSO_EXTHDR
))
707 if (unlikely(!pskb_may_pull(skb
, 8)))
710 opth
= (void *)skb
->data
;
711 len
= ipv6_optlen(opth
);
713 if (unlikely(!pskb_may_pull(skb
, len
)))
716 proto
= opth
->nexthdr
;
717 __skb_pull(skb
, len
);
723 static int ipv6_gso_send_check(struct sk_buff
*skb
)
725 struct ipv6hdr
*ipv6h
;
726 struct inet6_protocol
*ops
;
729 if (unlikely(!pskb_may_pull(skb
, sizeof(*ipv6h
))))
732 ipv6h
= ipv6_hdr(skb
);
733 __skb_pull(skb
, sizeof(*ipv6h
));
734 err
= -EPROTONOSUPPORT
;
737 ops
= rcu_dereference(inet6_protos
[
738 ipv6_gso_pull_exthdrs(skb
, ipv6h
->nexthdr
)]);
740 if (likely(ops
&& ops
->gso_send_check
)) {
741 skb_reset_transport_header(skb
);
742 err
= ops
->gso_send_check(skb
);
750 static struct sk_buff
*ipv6_gso_segment(struct sk_buff
*skb
, int features
)
752 struct sk_buff
*segs
= ERR_PTR(-EINVAL
);
753 struct ipv6hdr
*ipv6h
;
754 struct inet6_protocol
*ops
;
756 if (!(features
& NETIF_F_V6_CSUM
))
757 features
&= ~NETIF_F_SG
;
759 if (unlikely(skb_shinfo(skb
)->gso_type
&
767 if (unlikely(!pskb_may_pull(skb
, sizeof(*ipv6h
))))
770 ipv6h
= ipv6_hdr(skb
);
771 __skb_pull(skb
, sizeof(*ipv6h
));
772 segs
= ERR_PTR(-EPROTONOSUPPORT
);
775 ops
= rcu_dereference(inet6_protos
[
776 ipv6_gso_pull_exthdrs(skb
, ipv6h
->nexthdr
)]);
778 if (likely(ops
&& ops
->gso_segment
)) {
779 skb_reset_transport_header(skb
);
780 segs
= ops
->gso_segment(skb
, features
);
784 if (unlikely(IS_ERR(segs
)))
787 for (skb
= segs
; skb
; skb
= skb
->next
) {
788 ipv6h
= ipv6_hdr(skb
);
789 ipv6h
->payload_len
= htons(skb
->len
- skb
->mac_len
-
798 struct napi_gro_cb napi
;
802 #define IPV6_GRO_CB(skb) ((struct ipv6_gro_cb *)(skb)->cb)
804 static struct sk_buff
**ipv6_gro_receive(struct sk_buff
**head
,
807 struct inet6_protocol
*ops
;
808 struct sk_buff
**pp
= NULL
;
816 iph
= skb_gro_header(skb
, sizeof(*iph
));
820 skb_gro_pull(skb
, sizeof(*iph
));
821 skb_set_transport_header(skb
, skb_gro_offset(skb
));
823 flush
+= ntohs(iph
->payload_len
) != skb_gro_len(skb
);
826 proto
= iph
->nexthdr
;
827 ops
= rcu_dereference(inet6_protos
[proto
]);
828 if (!ops
|| !ops
->gro_receive
) {
829 __pskb_pull(skb
, skb_gro_offset(skb
));
830 proto
= ipv6_gso_pull_exthdrs(skb
, proto
);
831 skb_gro_pull(skb
, -skb_transport_offset(skb
));
832 skb_reset_transport_header(skb
);
833 __skb_push(skb
, skb_gro_offset(skb
));
835 if (!ops
|| !ops
->gro_receive
)
841 IPV6_GRO_CB(skb
)->proto
= proto
;
844 nlen
= skb_network_header_len(skb
);
846 for (p
= *head
; p
; p
= p
->next
) {
847 struct ipv6hdr
*iph2
;
849 if (!NAPI_GRO_CB(p
)->same_flow
)
854 /* All fields must match except length. */
855 if (nlen
!= skb_network_header_len(p
) ||
856 memcmp(iph
, iph2
, offsetof(struct ipv6hdr
, payload_len
)) ||
857 memcmp(&iph
->nexthdr
, &iph2
->nexthdr
,
858 nlen
- offsetof(struct ipv6hdr
, nexthdr
))) {
859 NAPI_GRO_CB(p
)->same_flow
= 0;
863 NAPI_GRO_CB(p
)->flush
|= flush
;
866 NAPI_GRO_CB(skb
)->flush
|= flush
;
869 skb_postpull_rcsum(skb
, iph
, skb_network_header_len(skb
));
871 pp
= ops
->gro_receive(head
, skb
);
879 NAPI_GRO_CB(skb
)->flush
|= flush
;
884 static int ipv6_gro_complete(struct sk_buff
*skb
)
886 struct inet6_protocol
*ops
;
887 struct ipv6hdr
*iph
= ipv6_hdr(skb
);
890 iph
->payload_len
= htons(skb
->len
- skb_network_offset(skb
) -
894 ops
= rcu_dereference(inet6_protos
[IPV6_GRO_CB(skb
)->proto
]);
895 if (WARN_ON(!ops
|| !ops
->gro_complete
))
898 err
= ops
->gro_complete(skb
);
906 static struct packet_type ipv6_packet_type __read_mostly
= {
907 .type
= cpu_to_be16(ETH_P_IPV6
),
909 .gso_send_check
= ipv6_gso_send_check
,
910 .gso_segment
= ipv6_gso_segment
,
911 .gro_receive
= ipv6_gro_receive
,
912 .gro_complete
= ipv6_gro_complete
,
915 static int __init
ipv6_packet_init(void)
917 dev_add_pack(&ipv6_packet_type
);
921 static void ipv6_packet_cleanup(void)
923 dev_remove_pack(&ipv6_packet_type
);
926 static int __net_init
ipv6_init_mibs(struct net
*net
)
928 if (snmp_mib_init((void **)net
->mib
.udp_stats_in6
,
929 sizeof (struct udp_mib
)) < 0)
931 if (snmp_mib_init((void **)net
->mib
.udplite_stats_in6
,
932 sizeof (struct udp_mib
)) < 0)
933 goto err_udplite_mib
;
934 if (snmp_mib_init((void **)net
->mib
.ipv6_statistics
,
935 sizeof(struct ipstats_mib
)) < 0)
937 if (snmp_mib_init((void **)net
->mib
.icmpv6_statistics
,
938 sizeof(struct icmpv6_mib
)) < 0)
940 if (snmp_mib_init((void **)net
->mib
.icmpv6msg_statistics
,
941 sizeof(struct icmpv6msg_mib
)) < 0)
942 goto err_icmpmsg_mib
;
946 snmp_mib_free((void **)net
->mib
.icmpv6_statistics
);
948 snmp_mib_free((void **)net
->mib
.ipv6_statistics
);
950 snmp_mib_free((void **)net
->mib
.udplite_stats_in6
);
952 snmp_mib_free((void **)net
->mib
.udp_stats_in6
);
956 static void __net_exit
ipv6_cleanup_mibs(struct net
*net
)
958 snmp_mib_free((void **)net
->mib
.udp_stats_in6
);
959 snmp_mib_free((void **)net
->mib
.udplite_stats_in6
);
960 snmp_mib_free((void **)net
->mib
.ipv6_statistics
);
961 snmp_mib_free((void **)net
->mib
.icmpv6_statistics
);
962 snmp_mib_free((void **)net
->mib
.icmpv6msg_statistics
);
965 static int __net_init
inet6_net_init(struct net
*net
)
969 net
->ipv6
.sysctl
.bindv6only
= 0;
970 net
->ipv6
.sysctl
.icmpv6_time
= 1*HZ
;
972 err
= ipv6_init_mibs(net
);
975 #ifdef CONFIG_PROC_FS
976 err
= udp6_proc_init(net
);
979 err
= tcp6_proc_init(net
);
982 err
= ac6_proc_init(net
);
988 #ifdef CONFIG_PROC_FS
994 ipv6_cleanup_mibs(net
);
999 static void inet6_net_exit(struct net
*net
)
1001 #ifdef CONFIG_PROC_FS
1002 udp6_proc_exit(net
);
1003 tcp6_proc_exit(net
);
1006 ipv6_cleanup_mibs(net
);
1009 static struct pernet_operations inet6_net_ops
= {
1010 .init
= inet6_net_init
,
1011 .exit
= inet6_net_exit
,
1014 static int __init
inet6_init(void)
1016 struct sk_buff
*dummy_skb
;
1017 struct list_head
*r
;
1020 BUILD_BUG_ON(sizeof(struct inet6_skb_parm
) > sizeof(dummy_skb
->cb
));
1022 /* Register the socket-side information for inet6_create. */
1023 for(r
= &inetsw6
[0]; r
< &inetsw6
[SOCK_MAX
]; ++r
)
1028 "IPv6: Loaded, but administratively disabled, "
1029 "reboot required to enable\n");
1033 err
= proto_register(&tcpv6_prot
, 1);
1037 err
= proto_register(&udpv6_prot
, 1);
1039 goto out_unregister_tcp_proto
;
1041 err
= proto_register(&udplitev6_prot
, 1);
1043 goto out_unregister_udp_proto
;
1045 err
= proto_register(&rawv6_prot
, 1);
1047 goto out_unregister_udplite_proto
;
1050 /* We MUST register RAW sockets before we create the ICMP6,
1051 * IGMP6, or NDISC control sockets.
1055 goto out_unregister_raw_proto
;
1057 /* Register the family here so that the init calls below will
1058 * be able to create sockets. (?? is this dangerous ??)
1060 err
= sock_register(&inet6_family_ops
);
1062 goto out_sock_register_fail
;
1064 #ifdef CONFIG_SYSCTL
1065 err
= ipv6_static_sysctl_register();
1067 goto static_sysctl_fail
;
1070 * ipngwg API draft makes clear that the correct semantics
1071 * for TCP and UDP is to consider one TCP and UDP instance
1072 * in a host availiable by both INET and INET6 APIs and
1073 * able to communicate via both network protocols.
1076 err
= register_pernet_subsys(&inet6_net_ops
);
1078 goto register_pernet_fail
;
1079 err
= icmpv6_init();
1082 err
= ip6_mr_init();
1091 err
= ipv6_netfilter_init();
1093 goto netfilter_fail
;
1094 /* Create /proc/foo6 entries. */
1095 #ifdef CONFIG_PROC_FS
1097 if (raw6_proc_init())
1098 goto proc_raw6_fail
;
1099 if (udplite6_proc_init())
1100 goto proc_udplite6_fail
;
1101 if (ipv6_misc_proc_init())
1102 goto proc_misc6_fail
;
1103 if (if6_proc_init())
1106 err
= ip6_route_init();
1108 goto ip6_route_fail
;
1109 err
= ip6_flowlabel_init();
1111 goto ip6_flowlabel_fail
;
1112 err
= addrconf_init();
1116 /* Init v6 extension headers. */
1117 err
= ipv6_exthdrs_init();
1119 goto ipv6_exthdrs_fail
;
1121 err
= ipv6_frag_init();
1123 goto ipv6_frag_fail
;
1125 /* Init v6 transport protocols. */
1130 err
= udplitev6_init();
1132 goto udplitev6_fail
;
1138 err
= ipv6_packet_init();
1140 goto ipv6_packet_fail
;
1142 #ifdef CONFIG_SYSCTL
1143 err
= ipv6_sysctl_register();
1150 #ifdef CONFIG_SYSCTL
1152 ipv6_packet_cleanup();
1163 ipv6_exthdrs_exit();
1167 ip6_flowlabel_cleanup();
1169 ip6_route_cleanup();
1171 #ifdef CONFIG_PROC_FS
1174 ipv6_misc_proc_exit();
1176 udplite6_proc_exit();
1181 ipv6_netfilter_fini();
1191 unregister_pernet_subsys(&inet6_net_ops
);
1192 register_pernet_fail
:
1193 #ifdef CONFIG_SYSCTL
1194 ipv6_static_sysctl_unregister();
1197 sock_unregister(PF_INET6
);
1198 rtnl_unregister_all(PF_INET6
);
1199 out_sock_register_fail
:
1201 out_unregister_raw_proto
:
1202 proto_unregister(&rawv6_prot
);
1203 out_unregister_udplite_proto
:
1204 proto_unregister(&udplitev6_prot
);
1205 out_unregister_udp_proto
:
1206 proto_unregister(&udpv6_prot
);
1207 out_unregister_tcp_proto
:
1208 proto_unregister(&tcpv6_prot
);
1211 module_init(inet6_init
);
1213 static void __exit
inet6_exit(void)
1218 /* First of all disallow new sockets creation. */
1219 sock_unregister(PF_INET6
);
1220 /* Disallow any further netlink messages */
1221 rtnl_unregister_all(PF_INET6
);
1223 #ifdef CONFIG_SYSCTL
1224 ipv6_sysctl_unregister();
1230 /* Cleanup code parts. */
1231 ipv6_packet_cleanup();
1233 ipv6_exthdrs_exit();
1235 ip6_flowlabel_cleanup();
1236 ip6_route_cleanup();
1237 #ifdef CONFIG_PROC_FS
1239 /* Cleanup code parts. */
1241 ipv6_misc_proc_exit();
1242 udplite6_proc_exit();
1245 ipv6_netfilter_fini();
1252 unregister_pernet_subsys(&inet6_net_ops
);
1253 #ifdef CONFIG_SYSCTL
1254 ipv6_static_sysctl_unregister();
1256 proto_unregister(&rawv6_prot
);
1257 proto_unregister(&udplitev6_prot
);
1258 proto_unregister(&udpv6_prot
);
1259 proto_unregister(&tcpv6_prot
);
1261 module_exit(inet6_exit
);
1263 MODULE_ALIAS_NETPROTO(PF_INET6
);