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
) {
281 /* Binding to v4-mapped address on a v6-only socket
289 /* Reproduce AF_INET checks to make the bindings consitant */
290 v4addr
= addr
->sin6_addr
.s6_addr32
[3];
291 chk_addr_ret
= inet_addr_type(net
, v4addr
);
292 if (!sysctl_ip_nonlocal_bind
&&
293 !(inet
->freebind
|| inet
->transparent
) &&
294 v4addr
!= htonl(INADDR_ANY
) &&
295 chk_addr_ret
!= RTN_LOCAL
&&
296 chk_addr_ret
!= RTN_MULTICAST
&&
297 chk_addr_ret
!= RTN_BROADCAST
)
300 if (addr_type
!= IPV6_ADDR_ANY
) {
301 struct net_device
*dev
= NULL
;
303 if (addr_type
& IPV6_ADDR_LINKLOCAL
) {
304 if (addr_len
>= sizeof(struct sockaddr_in6
) &&
305 addr
->sin6_scope_id
) {
306 /* Override any existing binding, if another one
307 * is supplied by user.
309 sk
->sk_bound_dev_if
= addr
->sin6_scope_id
;
312 /* Binding to link-local address requires an interface */
313 if (!sk
->sk_bound_dev_if
) {
317 dev
= dev_get_by_index(net
, sk
->sk_bound_dev_if
);
324 /* ipv4 addr of the socket is invalid. Only the
325 * unspecified and mapped address have a v4 equivalent.
327 v4addr
= LOOPBACK4_IPV6
;
328 if (!(addr_type
& IPV6_ADDR_MULTICAST
)) {
329 if (!ipv6_chk_addr(net
, &addr
->sin6_addr
,
333 err
= -EADDRNOTAVAIL
;
342 inet
->rcv_saddr
= v4addr
;
343 inet
->saddr
= v4addr
;
345 ipv6_addr_copy(&np
->rcv_saddr
, &addr
->sin6_addr
);
347 if (!(addr_type
& IPV6_ADDR_MULTICAST
))
348 ipv6_addr_copy(&np
->saddr
, &addr
->sin6_addr
);
350 /* Make sure we are allowed to bind here. */
351 if (sk
->sk_prot
->get_port(sk
, snum
)) {
352 inet_reset_saddr(sk
);
357 if (addr_type
!= IPV6_ADDR_ANY
) {
358 sk
->sk_userlocks
|= SOCK_BINDADDR_LOCK
;
359 if (addr_type
!= IPV6_ADDR_MAPPED
)
363 sk
->sk_userlocks
|= SOCK_BINDPORT_LOCK
;
364 inet
->sport
= htons(inet
->num
);
372 EXPORT_SYMBOL(inet6_bind
);
374 int inet6_release(struct socket
*sock
)
376 struct sock
*sk
= sock
->sk
;
382 ipv6_sock_mc_close(sk
);
385 ipv6_sock_ac_close(sk
);
387 return inet_release(sock
);
390 EXPORT_SYMBOL(inet6_release
);
392 void inet6_destroy_sock(struct sock
*sk
)
394 struct ipv6_pinfo
*np
= inet6_sk(sk
);
396 struct ipv6_txoptions
*opt
;
398 /* Release rx options */
400 if ((skb
= xchg(&np
->pktoptions
, NULL
)) != NULL
)
403 /* Free flowlabels */
404 fl6_free_socklist(sk
);
406 /* Free tx options */
408 if ((opt
= xchg(&np
->opt
, NULL
)) != NULL
)
409 sock_kfree_s(sk
, opt
, opt
->tot_len
);
412 EXPORT_SYMBOL_GPL(inet6_destroy_sock
);
415 * This does both peername and sockname.
418 int inet6_getname(struct socket
*sock
, struct sockaddr
*uaddr
,
419 int *uaddr_len
, int peer
)
421 struct sockaddr_in6
*sin
=(struct sockaddr_in6
*)uaddr
;
422 struct sock
*sk
= sock
->sk
;
423 struct inet_sock
*inet
= inet_sk(sk
);
424 struct ipv6_pinfo
*np
= inet6_sk(sk
);
426 sin
->sin6_family
= AF_INET6
;
427 sin
->sin6_flowinfo
= 0;
428 sin
->sin6_scope_id
= 0;
432 if (((1 << sk
->sk_state
) & (TCPF_CLOSE
| TCPF_SYN_SENT
)) &&
435 sin
->sin6_port
= inet
->dport
;
436 ipv6_addr_copy(&sin
->sin6_addr
, &np
->daddr
);
438 sin
->sin6_flowinfo
= np
->flow_label
;
440 if (ipv6_addr_any(&np
->rcv_saddr
))
441 ipv6_addr_copy(&sin
->sin6_addr
, &np
->saddr
);
443 ipv6_addr_copy(&sin
->sin6_addr
, &np
->rcv_saddr
);
445 sin
->sin6_port
= inet
->sport
;
447 if (ipv6_addr_type(&sin
->sin6_addr
) & IPV6_ADDR_LINKLOCAL
)
448 sin
->sin6_scope_id
= sk
->sk_bound_dev_if
;
449 *uaddr_len
= sizeof(*sin
);
453 EXPORT_SYMBOL(inet6_getname
);
455 int inet6_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
)
457 struct sock
*sk
= sock
->sk
;
458 struct net
*net
= sock_net(sk
);
463 return sock_get_timestamp(sk
, (struct timeval __user
*)arg
);
466 return sock_get_timestampns(sk
, (struct timespec __user
*)arg
);
471 return(ipv6_route_ioctl(net
, cmd
, (void __user
*)arg
));
474 return addrconf_add_ifaddr(net
, (void __user
*) arg
);
476 return addrconf_del_ifaddr(net
, (void __user
*) arg
);
478 return addrconf_set_dstaddr(net
, (void __user
*) arg
);
480 if (!sk
->sk_prot
->ioctl
)
482 return sk
->sk_prot
->ioctl(sk
, cmd
, arg
);
488 EXPORT_SYMBOL(inet6_ioctl
);
490 const struct proto_ops inet6_stream_ops
= {
492 .owner
= THIS_MODULE
,
493 .release
= inet6_release
,
495 .connect
= inet_stream_connect
, /* ok */
496 .socketpair
= sock_no_socketpair
, /* a do nothing */
497 .accept
= inet_accept
, /* ok */
498 .getname
= inet6_getname
,
499 .poll
= tcp_poll
, /* ok */
500 .ioctl
= inet6_ioctl
, /* must change */
501 .listen
= inet_listen
, /* ok */
502 .shutdown
= inet_shutdown
, /* ok */
503 .setsockopt
= sock_common_setsockopt
, /* ok */
504 .getsockopt
= sock_common_getsockopt
, /* ok */
505 .sendmsg
= tcp_sendmsg
, /* ok */
506 .recvmsg
= sock_common_recvmsg
, /* ok */
507 .mmap
= sock_no_mmap
,
508 .sendpage
= tcp_sendpage
,
509 .splice_read
= tcp_splice_read
,
511 .compat_setsockopt
= compat_sock_common_setsockopt
,
512 .compat_getsockopt
= compat_sock_common_getsockopt
,
516 const struct proto_ops inet6_dgram_ops
= {
518 .owner
= THIS_MODULE
,
519 .release
= inet6_release
,
521 .connect
= inet_dgram_connect
, /* ok */
522 .socketpair
= sock_no_socketpair
, /* a do nothing */
523 .accept
= sock_no_accept
, /* a do nothing */
524 .getname
= inet6_getname
,
525 .poll
= udp_poll
, /* ok */
526 .ioctl
= inet6_ioctl
, /* must change */
527 .listen
= sock_no_listen
, /* ok */
528 .shutdown
= inet_shutdown
, /* ok */
529 .setsockopt
= sock_common_setsockopt
, /* ok */
530 .getsockopt
= sock_common_getsockopt
, /* ok */
531 .sendmsg
= inet_sendmsg
, /* ok */
532 .recvmsg
= sock_common_recvmsg
, /* ok */
533 .mmap
= sock_no_mmap
,
534 .sendpage
= sock_no_sendpage
,
536 .compat_setsockopt
= compat_sock_common_setsockopt
,
537 .compat_getsockopt
= compat_sock_common_getsockopt
,
541 static struct net_proto_family inet6_family_ops
= {
543 .create
= inet6_create
,
544 .owner
= THIS_MODULE
,
547 int inet6_register_protosw(struct inet_protosw
*p
)
549 struct list_head
*lh
;
550 struct inet_protosw
*answer
;
551 struct list_head
*last_perm
;
552 int protocol
= p
->protocol
;
555 spin_lock_bh(&inetsw6_lock
);
558 if (p
->type
>= SOCK_MAX
)
561 /* If we are trying to override a permanent protocol, bail. */
564 last_perm
= &inetsw6
[p
->type
];
565 list_for_each(lh
, &inetsw6
[p
->type
]) {
566 answer
= list_entry(lh
, struct inet_protosw
, list
);
568 /* Check only the non-wild match. */
569 if (INET_PROTOSW_PERMANENT
& answer
->flags
) {
570 if (protocol
== answer
->protocol
)
580 /* Add the new entry after the last permanent entry if any, so that
581 * the new entry does not override a permanent entry when matched with
582 * a wild-card protocol. But it is allowed to override any existing
583 * non-permanent entry. This means that when we remove this entry, the
584 * system automatically returns to the old behavior.
586 list_add_rcu(&p
->list
, last_perm
);
589 spin_unlock_bh(&inetsw6_lock
);
593 printk(KERN_ERR
"Attempt to override permanent protocol %d.\n",
599 "Ignoring attempt to register invalid socket type %d.\n",
604 EXPORT_SYMBOL(inet6_register_protosw
);
607 inet6_unregister_protosw(struct inet_protosw
*p
)
609 if (INET_PROTOSW_PERMANENT
& p
->flags
) {
611 "Attempt to unregister permanent protocol %d.\n",
614 spin_lock_bh(&inetsw6_lock
);
615 list_del_rcu(&p
->list
);
616 spin_unlock_bh(&inetsw6_lock
);
622 EXPORT_SYMBOL(inet6_unregister_protosw
);
624 int inet6_sk_rebuild_header(struct sock
*sk
)
627 struct dst_entry
*dst
;
628 struct ipv6_pinfo
*np
= inet6_sk(sk
);
630 dst
= __sk_dst_check(sk
, np
->dst_cookie
);
633 struct inet_sock
*inet
= inet_sk(sk
);
634 struct in6_addr
*final_p
= NULL
, final
;
637 memset(&fl
, 0, sizeof(fl
));
638 fl
.proto
= sk
->sk_protocol
;
639 ipv6_addr_copy(&fl
.fl6_dst
, &np
->daddr
);
640 ipv6_addr_copy(&fl
.fl6_src
, &np
->saddr
);
641 fl
.fl6_flowlabel
= np
->flow_label
;
642 fl
.oif
= sk
->sk_bound_dev_if
;
643 fl
.fl_ip_dport
= inet
->dport
;
644 fl
.fl_ip_sport
= inet
->sport
;
645 security_sk_classify_flow(sk
, &fl
);
647 if (np
->opt
&& np
->opt
->srcrt
) {
648 struct rt0_hdr
*rt0
= (struct rt0_hdr
*) np
->opt
->srcrt
;
649 ipv6_addr_copy(&final
, &fl
.fl6_dst
);
650 ipv6_addr_copy(&fl
.fl6_dst
, rt0
->addr
);
654 err
= ip6_dst_lookup(sk
, &dst
, &fl
);
656 sk
->sk_route_caps
= 0;
660 ipv6_addr_copy(&fl
.fl6_dst
, final_p
);
662 if ((err
= xfrm_lookup(sock_net(sk
), &dst
, &fl
, sk
, 0)) < 0) {
663 sk
->sk_err_soft
= -err
;
667 __ip6_dst_store(sk
, dst
, NULL
, NULL
);
673 EXPORT_SYMBOL_GPL(inet6_sk_rebuild_header
);
675 int ipv6_opt_accepted(struct sock
*sk
, struct sk_buff
*skb
)
677 struct ipv6_pinfo
*np
= inet6_sk(sk
);
678 struct inet6_skb_parm
*opt
= IP6CB(skb
);
681 if ((opt
->hop
&& (np
->rxopt
.bits
.hopopts
||
682 np
->rxopt
.bits
.ohopopts
)) ||
683 ((IPV6_FLOWINFO_MASK
&
684 *(__be32
*)skb_network_header(skb
)) &&
685 np
->rxopt
.bits
.rxflow
) ||
686 (opt
->srcrt
&& (np
->rxopt
.bits
.srcrt
||
687 np
->rxopt
.bits
.osrcrt
)) ||
688 ((opt
->dst1
|| opt
->dst0
) &&
689 (np
->rxopt
.bits
.dstopts
|| np
->rxopt
.bits
.odstopts
)))
695 EXPORT_SYMBOL_GPL(ipv6_opt_accepted
);
697 static int ipv6_gso_pull_exthdrs(struct sk_buff
*skb
, int proto
)
699 struct inet6_protocol
*ops
= NULL
;
702 struct ipv6_opt_hdr
*opth
;
705 if (proto
!= NEXTHDR_HOP
) {
706 ops
= rcu_dereference(inet6_protos
[proto
]);
711 if (!(ops
->flags
& INET6_PROTO_GSO_EXTHDR
))
715 if (unlikely(!pskb_may_pull(skb
, 8)))
718 opth
= (void *)skb
->data
;
719 len
= ipv6_optlen(opth
);
721 if (unlikely(!pskb_may_pull(skb
, len
)))
724 proto
= opth
->nexthdr
;
725 __skb_pull(skb
, len
);
731 static int ipv6_gso_send_check(struct sk_buff
*skb
)
733 struct ipv6hdr
*ipv6h
;
734 struct inet6_protocol
*ops
;
737 if (unlikely(!pskb_may_pull(skb
, sizeof(*ipv6h
))))
740 ipv6h
= ipv6_hdr(skb
);
741 __skb_pull(skb
, sizeof(*ipv6h
));
742 err
= -EPROTONOSUPPORT
;
745 ops
= rcu_dereference(inet6_protos
[
746 ipv6_gso_pull_exthdrs(skb
, ipv6h
->nexthdr
)]);
748 if (likely(ops
&& ops
->gso_send_check
)) {
749 skb_reset_transport_header(skb
);
750 err
= ops
->gso_send_check(skb
);
758 static struct sk_buff
*ipv6_gso_segment(struct sk_buff
*skb
, int features
)
760 struct sk_buff
*segs
= ERR_PTR(-EINVAL
);
761 struct ipv6hdr
*ipv6h
;
762 struct inet6_protocol
*ops
;
764 if (!(features
& NETIF_F_V6_CSUM
))
765 features
&= ~NETIF_F_SG
;
767 if (unlikely(skb_shinfo(skb
)->gso_type
&
775 if (unlikely(!pskb_may_pull(skb
, sizeof(*ipv6h
))))
778 ipv6h
= ipv6_hdr(skb
);
779 __skb_pull(skb
, sizeof(*ipv6h
));
780 segs
= ERR_PTR(-EPROTONOSUPPORT
);
783 ops
= rcu_dereference(inet6_protos
[
784 ipv6_gso_pull_exthdrs(skb
, ipv6h
->nexthdr
)]);
786 if (likely(ops
&& ops
->gso_segment
)) {
787 skb_reset_transport_header(skb
);
788 segs
= ops
->gso_segment(skb
, features
);
792 if (unlikely(IS_ERR(segs
)))
795 for (skb
= segs
; skb
; skb
= skb
->next
) {
796 ipv6h
= ipv6_hdr(skb
);
797 ipv6h
->payload_len
= htons(skb
->len
- skb
->mac_len
-
806 struct napi_gro_cb napi
;
810 #define IPV6_GRO_CB(skb) ((struct ipv6_gro_cb *)(skb)->cb)
812 static struct sk_buff
**ipv6_gro_receive(struct sk_buff
**head
,
815 struct inet6_protocol
*ops
;
816 struct sk_buff
**pp
= NULL
;
824 iph
= skb_gro_header(skb
, sizeof(*iph
));
828 skb_gro_pull(skb
, sizeof(*iph
));
829 skb_set_transport_header(skb
, skb_gro_offset(skb
));
831 flush
+= ntohs(iph
->payload_len
) != skb_gro_len(skb
);
834 proto
= iph
->nexthdr
;
835 ops
= rcu_dereference(inet6_protos
[proto
]);
836 if (!ops
|| !ops
->gro_receive
) {
837 __pskb_pull(skb
, skb_gro_offset(skb
));
838 proto
= ipv6_gso_pull_exthdrs(skb
, proto
);
839 skb_gro_pull(skb
, -skb_transport_offset(skb
));
840 skb_reset_transport_header(skb
);
841 __skb_push(skb
, skb_gro_offset(skb
));
843 if (!ops
|| !ops
->gro_receive
)
849 IPV6_GRO_CB(skb
)->proto
= proto
;
852 nlen
= skb_network_header_len(skb
);
854 for (p
= *head
; p
; p
= p
->next
) {
855 struct ipv6hdr
*iph2
;
857 if (!NAPI_GRO_CB(p
)->same_flow
)
862 /* All fields must match except length. */
863 if (nlen
!= skb_network_header_len(p
) ||
864 memcmp(iph
, iph2
, offsetof(struct ipv6hdr
, payload_len
)) ||
865 memcmp(&iph
->nexthdr
, &iph2
->nexthdr
,
866 nlen
- offsetof(struct ipv6hdr
, nexthdr
))) {
867 NAPI_GRO_CB(p
)->same_flow
= 0;
871 NAPI_GRO_CB(p
)->flush
|= flush
;
874 NAPI_GRO_CB(skb
)->flush
|= flush
;
877 skb_postpull_rcsum(skb
, iph
, skb_network_header_len(skb
));
879 pp
= ops
->gro_receive(head
, skb
);
887 NAPI_GRO_CB(skb
)->flush
|= flush
;
892 static int ipv6_gro_complete(struct sk_buff
*skb
)
894 struct inet6_protocol
*ops
;
895 struct ipv6hdr
*iph
= ipv6_hdr(skb
);
898 iph
->payload_len
= htons(skb
->len
- skb_network_offset(skb
) -
902 ops
= rcu_dereference(inet6_protos
[IPV6_GRO_CB(skb
)->proto
]);
903 if (WARN_ON(!ops
|| !ops
->gro_complete
))
906 err
= ops
->gro_complete(skb
);
914 static struct packet_type ipv6_packet_type __read_mostly
= {
915 .type
= cpu_to_be16(ETH_P_IPV6
),
917 .gso_send_check
= ipv6_gso_send_check
,
918 .gso_segment
= ipv6_gso_segment
,
919 .gro_receive
= ipv6_gro_receive
,
920 .gro_complete
= ipv6_gro_complete
,
923 static int __init
ipv6_packet_init(void)
925 dev_add_pack(&ipv6_packet_type
);
929 static void ipv6_packet_cleanup(void)
931 dev_remove_pack(&ipv6_packet_type
);
934 static int __net_init
ipv6_init_mibs(struct net
*net
)
936 if (snmp_mib_init((void **)net
->mib
.udp_stats_in6
,
937 sizeof (struct udp_mib
)) < 0)
939 if (snmp_mib_init((void **)net
->mib
.udplite_stats_in6
,
940 sizeof (struct udp_mib
)) < 0)
941 goto err_udplite_mib
;
942 if (snmp_mib_init((void **)net
->mib
.ipv6_statistics
,
943 sizeof(struct ipstats_mib
)) < 0)
945 if (snmp_mib_init((void **)net
->mib
.icmpv6_statistics
,
946 sizeof(struct icmpv6_mib
)) < 0)
948 if (snmp_mib_init((void **)net
->mib
.icmpv6msg_statistics
,
949 sizeof(struct icmpv6msg_mib
)) < 0)
950 goto err_icmpmsg_mib
;
954 snmp_mib_free((void **)net
->mib
.icmpv6_statistics
);
956 snmp_mib_free((void **)net
->mib
.ipv6_statistics
);
958 snmp_mib_free((void **)net
->mib
.udplite_stats_in6
);
960 snmp_mib_free((void **)net
->mib
.udp_stats_in6
);
964 static void __net_exit
ipv6_cleanup_mibs(struct net
*net
)
966 snmp_mib_free((void **)net
->mib
.udp_stats_in6
);
967 snmp_mib_free((void **)net
->mib
.udplite_stats_in6
);
968 snmp_mib_free((void **)net
->mib
.ipv6_statistics
);
969 snmp_mib_free((void **)net
->mib
.icmpv6_statistics
);
970 snmp_mib_free((void **)net
->mib
.icmpv6msg_statistics
);
973 static int __net_init
inet6_net_init(struct net
*net
)
977 net
->ipv6
.sysctl
.bindv6only
= 0;
978 net
->ipv6
.sysctl
.icmpv6_time
= 1*HZ
;
980 err
= ipv6_init_mibs(net
);
983 #ifdef CONFIG_PROC_FS
984 err
= udp6_proc_init(net
);
987 err
= tcp6_proc_init(net
);
990 err
= ac6_proc_init(net
);
996 #ifdef CONFIG_PROC_FS
1000 udp6_proc_exit(net
);
1002 ipv6_cleanup_mibs(net
);
1007 static void inet6_net_exit(struct net
*net
)
1009 #ifdef CONFIG_PROC_FS
1010 udp6_proc_exit(net
);
1011 tcp6_proc_exit(net
);
1014 ipv6_cleanup_mibs(net
);
1017 static struct pernet_operations inet6_net_ops
= {
1018 .init
= inet6_net_init
,
1019 .exit
= inet6_net_exit
,
1022 static int __init
inet6_init(void)
1024 struct sk_buff
*dummy_skb
;
1025 struct list_head
*r
;
1028 BUILD_BUG_ON(sizeof(struct inet6_skb_parm
) > sizeof(dummy_skb
->cb
));
1030 /* Register the socket-side information for inet6_create. */
1031 for(r
= &inetsw6
[0]; r
< &inetsw6
[SOCK_MAX
]; ++r
)
1036 "IPv6: Loaded, but administratively disabled, "
1037 "reboot required to enable\n");
1041 err
= proto_register(&tcpv6_prot
, 1);
1045 err
= proto_register(&udpv6_prot
, 1);
1047 goto out_unregister_tcp_proto
;
1049 err
= proto_register(&udplitev6_prot
, 1);
1051 goto out_unregister_udp_proto
;
1053 err
= proto_register(&rawv6_prot
, 1);
1055 goto out_unregister_udplite_proto
;
1058 /* We MUST register RAW sockets before we create the ICMP6,
1059 * IGMP6, or NDISC control sockets.
1063 goto out_unregister_raw_proto
;
1065 /* Register the family here so that the init calls below will
1066 * be able to create sockets. (?? is this dangerous ??)
1068 err
= sock_register(&inet6_family_ops
);
1070 goto out_sock_register_fail
;
1072 #ifdef CONFIG_SYSCTL
1073 err
= ipv6_static_sysctl_register();
1075 goto static_sysctl_fail
;
1078 * ipngwg API draft makes clear that the correct semantics
1079 * for TCP and UDP is to consider one TCP and UDP instance
1080 * in a host availiable by both INET and INET6 APIs and
1081 * able to communicate via both network protocols.
1084 err
= register_pernet_subsys(&inet6_net_ops
);
1086 goto register_pernet_fail
;
1087 err
= icmpv6_init();
1090 err
= ip6_mr_init();
1099 err
= ipv6_netfilter_init();
1101 goto netfilter_fail
;
1102 /* Create /proc/foo6 entries. */
1103 #ifdef CONFIG_PROC_FS
1105 if (raw6_proc_init())
1106 goto proc_raw6_fail
;
1107 if (udplite6_proc_init())
1108 goto proc_udplite6_fail
;
1109 if (ipv6_misc_proc_init())
1110 goto proc_misc6_fail
;
1111 if (if6_proc_init())
1114 err
= ip6_route_init();
1116 goto ip6_route_fail
;
1117 err
= ip6_flowlabel_init();
1119 goto ip6_flowlabel_fail
;
1120 err
= addrconf_init();
1124 /* Init v6 extension headers. */
1125 err
= ipv6_exthdrs_init();
1127 goto ipv6_exthdrs_fail
;
1129 err
= ipv6_frag_init();
1131 goto ipv6_frag_fail
;
1133 /* Init v6 transport protocols. */
1138 err
= udplitev6_init();
1140 goto udplitev6_fail
;
1146 err
= ipv6_packet_init();
1148 goto ipv6_packet_fail
;
1150 #ifdef CONFIG_SYSCTL
1151 err
= ipv6_sysctl_register();
1158 #ifdef CONFIG_SYSCTL
1160 ipv6_packet_cleanup();
1171 ipv6_exthdrs_exit();
1175 ip6_flowlabel_cleanup();
1177 ip6_route_cleanup();
1179 #ifdef CONFIG_PROC_FS
1182 ipv6_misc_proc_exit();
1184 udplite6_proc_exit();
1189 ipv6_netfilter_fini();
1199 unregister_pernet_subsys(&inet6_net_ops
);
1200 register_pernet_fail
:
1201 #ifdef CONFIG_SYSCTL
1202 ipv6_static_sysctl_unregister();
1205 sock_unregister(PF_INET6
);
1206 rtnl_unregister_all(PF_INET6
);
1207 out_sock_register_fail
:
1209 out_unregister_raw_proto
:
1210 proto_unregister(&rawv6_prot
);
1211 out_unregister_udplite_proto
:
1212 proto_unregister(&udplitev6_prot
);
1213 out_unregister_udp_proto
:
1214 proto_unregister(&udpv6_prot
);
1215 out_unregister_tcp_proto
:
1216 proto_unregister(&tcpv6_prot
);
1219 module_init(inet6_init
);
1221 static void __exit
inet6_exit(void)
1226 /* First of all disallow new sockets creation. */
1227 sock_unregister(PF_INET6
);
1228 /* Disallow any further netlink messages */
1229 rtnl_unregister_all(PF_INET6
);
1231 #ifdef CONFIG_SYSCTL
1232 ipv6_sysctl_unregister();
1238 /* Cleanup code parts. */
1239 ipv6_packet_cleanup();
1241 ipv6_exthdrs_exit();
1243 ip6_flowlabel_cleanup();
1244 ip6_route_cleanup();
1245 #ifdef CONFIG_PROC_FS
1247 /* Cleanup code parts. */
1249 ipv6_misc_proc_exit();
1250 udplite6_proc_exit();
1253 ipv6_netfilter_fini();
1260 unregister_pernet_subsys(&inet6_net_ops
);
1261 #ifdef CONFIG_SYSCTL
1262 ipv6_static_sysctl_unregister();
1264 proto_unregister(&rawv6_prot
);
1265 proto_unregister(&udplitev6_prot
);
1266 proto_unregister(&udpv6_prot
);
1267 proto_unregister(&tcpv6_prot
);
1269 module_exit(inet6_exit
);
1271 MODULE_ALIAS_NETPROTO(PF_INET6
);