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/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>
60 #include <asm/uaccess.h>
61 #include <asm/system.h>
62 #include <linux/mroute6.h>
64 MODULE_AUTHOR("Cast of dozens");
65 MODULE_DESCRIPTION("IPv6 protocol stack for Linux");
66 MODULE_LICENSE("GPL");
68 /* The inetsw6 table contains everything that inet6_create needs to
71 static struct list_head inetsw6
[SOCK_MAX
];
72 static DEFINE_SPINLOCK(inetsw6_lock
);
74 static __inline__
struct ipv6_pinfo
*inet6_sk_generic(struct sock
*sk
)
76 const int offset
= sk
->sk_prot
->obj_size
- sizeof(struct ipv6_pinfo
);
78 return (struct ipv6_pinfo
*)(((u8
*)sk
) + offset
);
81 static int inet6_create(struct net
*net
, struct socket
*sock
, int protocol
)
83 struct inet_sock
*inet
;
84 struct ipv6_pinfo
*np
;
86 struct inet_protosw
*answer
;
87 struct proto
*answer_prot
;
88 unsigned char answer_flags
;
90 int try_loading_module
= 0;
93 if (sock
->type
!= SOCK_RAW
&&
94 sock
->type
!= SOCK_DGRAM
&&
98 /* Look for the requested type/protocol pair. */
100 err
= -ESOCKTNOSUPPORT
;
102 list_for_each_entry_rcu(answer
, &inetsw6
[sock
->type
], list
) {
105 /* Check the non-wild match. */
106 if (protocol
== answer
->protocol
) {
107 if (protocol
!= IPPROTO_IP
)
110 /* Check for the two wild cases. */
111 if (IPPROTO_IP
== protocol
) {
112 protocol
= answer
->protocol
;
115 if (IPPROTO_IP
== answer
->protocol
)
118 err
= -EPROTONOSUPPORT
;
122 if (try_loading_module
< 2) {
125 * Be more specific, e.g. net-pf-10-proto-132-type-1
126 * (net-pf-PF_INET6-proto-IPPROTO_SCTP-type-SOCK_STREAM)
128 if (++try_loading_module
== 1)
129 request_module("net-pf-%d-proto-%d-type-%d",
130 PF_INET6
, protocol
, sock
->type
);
132 * Fall back to generic, e.g. net-pf-10-proto-132
133 * (net-pf-PF_INET6-proto-IPPROTO_SCTP)
136 request_module("net-pf-%d-proto-%d",
138 goto lookup_protocol
;
144 if (answer
->capability
> 0 && !capable(answer
->capability
))
147 sock
->ops
= answer
->ops
;
148 answer_prot
= answer
->prot
;
149 answer_no_check
= answer
->no_check
;
150 answer_flags
= answer
->flags
;
153 WARN_ON(answer_prot
->slab
== NULL
);
156 sk
= sk_alloc(net
, PF_INET6
, GFP_KERNEL
, answer_prot
);
160 sock_init_data(sock
, sk
);
163 sk
->sk_no_check
= answer_no_check
;
164 if (INET_PROTOSW_REUSE
& answer_flags
)
168 inet
->is_icsk
= (INET_PROTOSW_ICSK
& answer_flags
) != 0;
170 if (SOCK_RAW
== sock
->type
) {
171 inet
->num
= protocol
;
172 if (IPPROTO_RAW
== protocol
)
176 sk
->sk_destruct
= inet_sock_destruct
;
177 sk
->sk_family
= PF_INET6
;
178 sk
->sk_protocol
= protocol
;
180 sk
->sk_backlog_rcv
= answer
->prot
->backlog_rcv
;
182 inet_sk(sk
)->pinet6
= np
= inet6_sk_generic(sk
);
186 np
->pmtudisc
= IPV6_PMTUDISC_WANT
;
187 np
->ipv6only
= net
->ipv6
.sysctl
.bindv6only
;
189 /* Init the ipv4 part of the socket since we can have sockets
190 * using v6 API for ipv4.
197 inet
->mc_list
= NULL
;
199 if (ipv4_config
.no_pmtu_disc
)
200 inet
->pmtudisc
= IP_PMTUDISC_DONT
;
202 inet
->pmtudisc
= IP_PMTUDISC_WANT
;
204 * Increment only the relevant sk_prot->socks debug field, this changes
205 * the previous behaviour of incrementing both the equivalent to
206 * answer->prot->socks (inet6_sock_nr) and inet_sock_nr.
208 * This allows better debug granularity as we'll know exactly how many
209 * UDPv6, TCPv6, etc socks were allocated, not the sum of all IPv6
210 * transport protocol socks. -acme
212 sk_refcnt_debug_inc(sk
);
215 /* It assumes that any protocol which allows
216 * the user to assign a number at socket
217 * creation time automatically shares.
219 inet
->sport
= htons(inet
->num
);
220 sk
->sk_prot
->hash(sk
);
222 if (sk
->sk_prot
->init
) {
223 err
= sk
->sk_prot
->init(sk
);
225 sk_common_release(sk
);
237 /* bind for INET6 API */
238 int inet6_bind(struct socket
*sock
, struct sockaddr
*uaddr
, int addr_len
)
240 struct sockaddr_in6
*addr
=(struct sockaddr_in6
*)uaddr
;
241 struct sock
*sk
= sock
->sk
;
242 struct inet_sock
*inet
= inet_sk(sk
);
243 struct ipv6_pinfo
*np
= inet6_sk(sk
);
244 struct net
*net
= sock_net(sk
);
250 /* If the socket has its own bind function then use it. */
251 if (sk
->sk_prot
->bind
)
252 return sk
->sk_prot
->bind(sk
, uaddr
, addr_len
);
254 if (addr_len
< SIN6_LEN_RFC2133
)
256 addr_type
= ipv6_addr_type(&addr
->sin6_addr
);
257 if ((addr_type
& IPV6_ADDR_MULTICAST
) && sock
->type
== SOCK_STREAM
)
260 snum
= ntohs(addr
->sin6_port
);
261 if (snum
&& snum
< PROT_SOCK
&& !capable(CAP_NET_BIND_SERVICE
))
266 /* Check these errors (active socket, double bind). */
267 if (sk
->sk_state
!= TCP_CLOSE
|| inet
->num
) {
272 /* Check if the address belongs to the host. */
273 if (addr_type
== IPV6_ADDR_MAPPED
) {
274 v4addr
= addr
->sin6_addr
.s6_addr32
[3];
275 if (inet_addr_type(net
, v4addr
) != RTN_LOCAL
) {
276 err
= -EADDRNOTAVAIL
;
280 if (addr_type
!= IPV6_ADDR_ANY
) {
281 struct net_device
*dev
= NULL
;
283 if (addr_type
& IPV6_ADDR_LINKLOCAL
) {
284 if (addr_len
>= sizeof(struct sockaddr_in6
) &&
285 addr
->sin6_scope_id
) {
286 /* Override any existing binding, if another one
287 * is supplied by user.
289 sk
->sk_bound_dev_if
= addr
->sin6_scope_id
;
292 /* Binding to link-local address requires an interface */
293 if (!sk
->sk_bound_dev_if
) {
297 dev
= dev_get_by_index(net
, sk
->sk_bound_dev_if
);
304 /* ipv4 addr of the socket is invalid. Only the
305 * unspecified and mapped address have a v4 equivalent.
307 v4addr
= LOOPBACK4_IPV6
;
308 if (!(addr_type
& IPV6_ADDR_MULTICAST
)) {
309 if (!ipv6_chk_addr(net
, &addr
->sin6_addr
,
313 err
= -EADDRNOTAVAIL
;
322 inet
->rcv_saddr
= v4addr
;
323 inet
->saddr
= v4addr
;
325 ipv6_addr_copy(&np
->rcv_saddr
, &addr
->sin6_addr
);
327 if (!(addr_type
& IPV6_ADDR_MULTICAST
))
328 ipv6_addr_copy(&np
->saddr
, &addr
->sin6_addr
);
330 /* Make sure we are allowed to bind here. */
331 if (sk
->sk_prot
->get_port(sk
, snum
)) {
332 inet_reset_saddr(sk
);
337 if (addr_type
!= IPV6_ADDR_ANY
)
338 sk
->sk_userlocks
|= SOCK_BINDADDR_LOCK
;
340 sk
->sk_userlocks
|= SOCK_BINDPORT_LOCK
;
341 inet
->sport
= htons(inet
->num
);
349 EXPORT_SYMBOL(inet6_bind
);
351 int inet6_release(struct socket
*sock
)
353 struct sock
*sk
= sock
->sk
;
359 ipv6_sock_mc_close(sk
);
362 ipv6_sock_ac_close(sk
);
364 return inet_release(sock
);
367 EXPORT_SYMBOL(inet6_release
);
369 void inet6_destroy_sock(struct sock
*sk
)
371 struct ipv6_pinfo
*np
= inet6_sk(sk
);
373 struct ipv6_txoptions
*opt
;
375 /* Release rx options */
377 if ((skb
= xchg(&np
->pktoptions
, NULL
)) != NULL
)
380 /* Free flowlabels */
381 fl6_free_socklist(sk
);
383 /* Free tx options */
385 if ((opt
= xchg(&np
->opt
, NULL
)) != NULL
)
386 sock_kfree_s(sk
, opt
, opt
->tot_len
);
389 EXPORT_SYMBOL_GPL(inet6_destroy_sock
);
392 * This does both peername and sockname.
395 int inet6_getname(struct socket
*sock
, struct sockaddr
*uaddr
,
396 int *uaddr_len
, int peer
)
398 struct sockaddr_in6
*sin
=(struct sockaddr_in6
*)uaddr
;
399 struct sock
*sk
= sock
->sk
;
400 struct inet_sock
*inet
= inet_sk(sk
);
401 struct ipv6_pinfo
*np
= inet6_sk(sk
);
403 sin
->sin6_family
= AF_INET6
;
404 sin
->sin6_flowinfo
= 0;
405 sin
->sin6_scope_id
= 0;
409 if (((1 << sk
->sk_state
) & (TCPF_CLOSE
| TCPF_SYN_SENT
)) &&
412 sin
->sin6_port
= inet
->dport
;
413 ipv6_addr_copy(&sin
->sin6_addr
, &np
->daddr
);
415 sin
->sin6_flowinfo
= np
->flow_label
;
417 if (ipv6_addr_any(&np
->rcv_saddr
))
418 ipv6_addr_copy(&sin
->sin6_addr
, &np
->saddr
);
420 ipv6_addr_copy(&sin
->sin6_addr
, &np
->rcv_saddr
);
422 sin
->sin6_port
= inet
->sport
;
424 if (ipv6_addr_type(&sin
->sin6_addr
) & IPV6_ADDR_LINKLOCAL
)
425 sin
->sin6_scope_id
= sk
->sk_bound_dev_if
;
426 *uaddr_len
= sizeof(*sin
);
430 EXPORT_SYMBOL(inet6_getname
);
432 int inet6_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
)
434 struct sock
*sk
= sock
->sk
;
435 struct net
*net
= sock_net(sk
);
440 return sock_get_timestamp(sk
, (struct timeval __user
*)arg
);
443 return sock_get_timestampns(sk
, (struct timespec __user
*)arg
);
448 return(ipv6_route_ioctl(net
, cmd
, (void __user
*)arg
));
451 return addrconf_add_ifaddr(net
, (void __user
*) arg
);
453 return addrconf_del_ifaddr(net
, (void __user
*) arg
);
455 return addrconf_set_dstaddr(net
, (void __user
*) arg
);
457 if (!sk
->sk_prot
->ioctl
)
459 return sk
->sk_prot
->ioctl(sk
, cmd
, arg
);
465 EXPORT_SYMBOL(inet6_ioctl
);
467 const struct proto_ops inet6_stream_ops
= {
469 .owner
= THIS_MODULE
,
470 .release
= inet6_release
,
472 .connect
= inet_stream_connect
, /* ok */
473 .socketpair
= sock_no_socketpair
, /* a do nothing */
474 .accept
= inet_accept
, /* ok */
475 .getname
= inet6_getname
,
476 .poll
= tcp_poll
, /* ok */
477 .ioctl
= inet6_ioctl
, /* must change */
478 .listen
= inet_listen
, /* ok */
479 .shutdown
= inet_shutdown
, /* ok */
480 .setsockopt
= sock_common_setsockopt
, /* ok */
481 .getsockopt
= sock_common_getsockopt
, /* ok */
482 .sendmsg
= tcp_sendmsg
, /* ok */
483 .recvmsg
= sock_common_recvmsg
, /* ok */
484 .mmap
= sock_no_mmap
,
485 .sendpage
= tcp_sendpage
,
486 .splice_read
= tcp_splice_read
,
488 .compat_setsockopt
= compat_sock_common_setsockopt
,
489 .compat_getsockopt
= compat_sock_common_getsockopt
,
493 const struct proto_ops inet6_dgram_ops
= {
495 .owner
= THIS_MODULE
,
496 .release
= inet6_release
,
498 .connect
= inet_dgram_connect
, /* ok */
499 .socketpair
= sock_no_socketpair
, /* a do nothing */
500 .accept
= sock_no_accept
, /* a do nothing */
501 .getname
= inet6_getname
,
502 .poll
= udp_poll
, /* ok */
503 .ioctl
= inet6_ioctl
, /* must change */
504 .listen
= sock_no_listen
, /* ok */
505 .shutdown
= inet_shutdown
, /* ok */
506 .setsockopt
= sock_common_setsockopt
, /* ok */
507 .getsockopt
= sock_common_getsockopt
, /* ok */
508 .sendmsg
= inet_sendmsg
, /* ok */
509 .recvmsg
= sock_common_recvmsg
, /* ok */
510 .mmap
= sock_no_mmap
,
511 .sendpage
= sock_no_sendpage
,
513 .compat_setsockopt
= compat_sock_common_setsockopt
,
514 .compat_getsockopt
= compat_sock_common_getsockopt
,
518 static struct net_proto_family inet6_family_ops
= {
520 .create
= inet6_create
,
521 .owner
= THIS_MODULE
,
524 int inet6_register_protosw(struct inet_protosw
*p
)
526 struct list_head
*lh
;
527 struct inet_protosw
*answer
;
528 struct list_head
*last_perm
;
529 int protocol
= p
->protocol
;
532 spin_lock_bh(&inetsw6_lock
);
535 if (p
->type
>= SOCK_MAX
)
538 /* If we are trying to override a permanent protocol, bail. */
541 last_perm
= &inetsw6
[p
->type
];
542 list_for_each(lh
, &inetsw6
[p
->type
]) {
543 answer
= list_entry(lh
, struct inet_protosw
, list
);
545 /* Check only the non-wild match. */
546 if (INET_PROTOSW_PERMANENT
& answer
->flags
) {
547 if (protocol
== answer
->protocol
)
557 /* Add the new entry after the last permanent entry if any, so that
558 * the new entry does not override a permanent entry when matched with
559 * a wild-card protocol. But it is allowed to override any existing
560 * non-permanent entry. This means that when we remove this entry, the
561 * system automatically returns to the old behavior.
563 list_add_rcu(&p
->list
, last_perm
);
566 spin_unlock_bh(&inetsw6_lock
);
570 printk(KERN_ERR
"Attempt to override permanent protocol %d.\n",
576 "Ignoring attempt to register invalid socket type %d.\n",
581 EXPORT_SYMBOL(inet6_register_protosw
);
584 inet6_unregister_protosw(struct inet_protosw
*p
)
586 if (INET_PROTOSW_PERMANENT
& p
->flags
) {
588 "Attempt to unregister permanent protocol %d.\n",
591 spin_lock_bh(&inetsw6_lock
);
592 list_del_rcu(&p
->list
);
593 spin_unlock_bh(&inetsw6_lock
);
599 EXPORT_SYMBOL(inet6_unregister_protosw
);
601 int inet6_sk_rebuild_header(struct sock
*sk
)
604 struct dst_entry
*dst
;
605 struct ipv6_pinfo
*np
= inet6_sk(sk
);
607 dst
= __sk_dst_check(sk
, np
->dst_cookie
);
610 struct inet_sock
*inet
= inet_sk(sk
);
611 struct in6_addr
*final_p
= NULL
, final
;
614 memset(&fl
, 0, sizeof(fl
));
615 fl
.proto
= sk
->sk_protocol
;
616 ipv6_addr_copy(&fl
.fl6_dst
, &np
->daddr
);
617 ipv6_addr_copy(&fl
.fl6_src
, &np
->saddr
);
618 fl
.fl6_flowlabel
= np
->flow_label
;
619 fl
.oif
= sk
->sk_bound_dev_if
;
620 fl
.fl_ip_dport
= inet
->dport
;
621 fl
.fl_ip_sport
= inet
->sport
;
622 security_sk_classify_flow(sk
, &fl
);
624 if (np
->opt
&& np
->opt
->srcrt
) {
625 struct rt0_hdr
*rt0
= (struct rt0_hdr
*) np
->opt
->srcrt
;
626 ipv6_addr_copy(&final
, &fl
.fl6_dst
);
627 ipv6_addr_copy(&fl
.fl6_dst
, rt0
->addr
);
631 err
= ip6_dst_lookup(sk
, &dst
, &fl
);
633 sk
->sk_route_caps
= 0;
637 ipv6_addr_copy(&fl
.fl6_dst
, final_p
);
639 if ((err
= xfrm_lookup(&dst
, &fl
, sk
, 0)) < 0) {
640 sk
->sk_err_soft
= -err
;
644 __ip6_dst_store(sk
, dst
, NULL
, NULL
);
650 EXPORT_SYMBOL_GPL(inet6_sk_rebuild_header
);
652 int ipv6_opt_accepted(struct sock
*sk
, struct sk_buff
*skb
)
654 struct ipv6_pinfo
*np
= inet6_sk(sk
);
655 struct inet6_skb_parm
*opt
= IP6CB(skb
);
658 if ((opt
->hop
&& (np
->rxopt
.bits
.hopopts
||
659 np
->rxopt
.bits
.ohopopts
)) ||
660 ((IPV6_FLOWINFO_MASK
&
661 *(__be32
*)skb_network_header(skb
)) &&
662 np
->rxopt
.bits
.rxflow
) ||
663 (opt
->srcrt
&& (np
->rxopt
.bits
.srcrt
||
664 np
->rxopt
.bits
.osrcrt
)) ||
665 ((opt
->dst1
|| opt
->dst0
) &&
666 (np
->rxopt
.bits
.dstopts
|| np
->rxopt
.bits
.odstopts
)))
672 EXPORT_SYMBOL_GPL(ipv6_opt_accepted
);
674 static struct inet6_protocol
*ipv6_gso_pull_exthdrs(struct sk_buff
*skb
,
677 struct inet6_protocol
*ops
= NULL
;
680 struct ipv6_opt_hdr
*opth
;
683 if (proto
!= NEXTHDR_HOP
) {
684 ops
= rcu_dereference(inet6_protos
[proto
]);
689 if (!(ops
->flags
& INET6_PROTO_GSO_EXTHDR
))
693 if (unlikely(!pskb_may_pull(skb
, 8)))
696 opth
= (void *)skb
->data
;
697 len
= ipv6_optlen(opth
);
699 if (unlikely(!pskb_may_pull(skb
, len
)))
702 proto
= opth
->nexthdr
;
703 __skb_pull(skb
, len
);
709 static int ipv6_gso_send_check(struct sk_buff
*skb
)
711 struct ipv6hdr
*ipv6h
;
712 struct inet6_protocol
*ops
;
715 if (unlikely(!pskb_may_pull(skb
, sizeof(*ipv6h
))))
718 ipv6h
= ipv6_hdr(skb
);
719 __skb_pull(skb
, sizeof(*ipv6h
));
720 err
= -EPROTONOSUPPORT
;
723 ops
= ipv6_gso_pull_exthdrs(skb
, ipv6h
->nexthdr
);
724 if (likely(ops
&& ops
->gso_send_check
)) {
725 skb_reset_transport_header(skb
);
726 err
= ops
->gso_send_check(skb
);
734 static struct sk_buff
*ipv6_gso_segment(struct sk_buff
*skb
, int features
)
736 struct sk_buff
*segs
= ERR_PTR(-EINVAL
);
737 struct ipv6hdr
*ipv6h
;
738 struct inet6_protocol
*ops
;
740 if (!(features
& NETIF_F_V6_CSUM
))
741 features
&= ~NETIF_F_SG
;
743 if (unlikely(skb_shinfo(skb
)->gso_type
&
751 if (unlikely(!pskb_may_pull(skb
, sizeof(*ipv6h
))))
754 ipv6h
= ipv6_hdr(skb
);
755 __skb_pull(skb
, sizeof(*ipv6h
));
756 segs
= ERR_PTR(-EPROTONOSUPPORT
);
759 ops
= ipv6_gso_pull_exthdrs(skb
, ipv6h
->nexthdr
);
760 if (likely(ops
&& ops
->gso_segment
)) {
761 skb_reset_transport_header(skb
);
762 segs
= ops
->gso_segment(skb
, features
);
766 if (unlikely(IS_ERR(segs
)))
769 for (skb
= segs
; skb
; skb
= skb
->next
) {
770 ipv6h
= ipv6_hdr(skb
);
771 ipv6h
->payload_len
= htons(skb
->len
- skb
->mac_len
-
779 static struct packet_type ipv6_packet_type
= {
780 .type
= __constant_htons(ETH_P_IPV6
),
782 .gso_send_check
= ipv6_gso_send_check
,
783 .gso_segment
= ipv6_gso_segment
,
786 static int __init
ipv6_packet_init(void)
788 dev_add_pack(&ipv6_packet_type
);
792 static void ipv6_packet_cleanup(void)
794 dev_remove_pack(&ipv6_packet_type
);
797 static int __init
init_ipv6_mibs(void)
799 if (snmp_mib_init((void **)ipv6_statistics
,
800 sizeof(struct ipstats_mib
)) < 0)
802 if (snmp_mib_init((void **)icmpv6_statistics
,
803 sizeof(struct icmpv6_mib
)) < 0)
805 if (snmp_mib_init((void **)icmpv6msg_statistics
,
806 sizeof(struct icmpv6msg_mib
)) < 0)
807 goto err_icmpmsg_mib
;
808 if (snmp_mib_init((void **)udp_stats_in6
, sizeof (struct udp_mib
)) < 0)
810 if (snmp_mib_init((void **)udplite_stats_in6
,
811 sizeof (struct udp_mib
)) < 0)
812 goto err_udplite_mib
;
816 snmp_mib_free((void **)udp_stats_in6
);
818 snmp_mib_free((void **)icmpv6msg_statistics
);
820 snmp_mib_free((void **)icmpv6_statistics
);
822 snmp_mib_free((void **)ipv6_statistics
);
828 static void cleanup_ipv6_mibs(void)
830 snmp_mib_free((void **)ipv6_statistics
);
831 snmp_mib_free((void **)icmpv6_statistics
);
832 snmp_mib_free((void **)icmpv6msg_statistics
);
833 snmp_mib_free((void **)udp_stats_in6
);
834 snmp_mib_free((void **)udplite_stats_in6
);
837 static int inet6_net_init(struct net
*net
)
841 net
->ipv6
.sysctl
.bindv6only
= 0;
842 net
->ipv6
.sysctl
.flush_delay
= 0;
843 net
->ipv6
.sysctl
.ip6_rt_max_size
= 4096;
844 net
->ipv6
.sysctl
.ip6_rt_gc_min_interval
= HZ
/ 2;
845 net
->ipv6
.sysctl
.ip6_rt_gc_timeout
= 60*HZ
;
846 net
->ipv6
.sysctl
.ip6_rt_gc_interval
= 30*HZ
;
847 net
->ipv6
.sysctl
.ip6_rt_gc_elasticity
= 9;
848 net
->ipv6
.sysctl
.ip6_rt_mtu_expires
= 10*60*HZ
;
849 net
->ipv6
.sysctl
.ip6_rt_min_advmss
= IPV6_MIN_MTU
- 20 - 40;
850 net
->ipv6
.sysctl
.icmpv6_time
= 1*HZ
;
852 #ifdef CONFIG_PROC_FS
853 err
= udp6_proc_init(net
);
856 err
= tcp6_proc_init(net
);
859 err
= ac6_proc_init(net
);
866 #ifdef CONFIG_PROC_FS
875 static void inet6_net_exit(struct net
*net
)
877 #ifdef CONFIG_PROC_FS
884 static struct pernet_operations inet6_net_ops
= {
885 .init
= inet6_net_init
,
886 .exit
= inet6_net_exit
,
889 static int __init
inet6_init(void)
891 struct sk_buff
*dummy_skb
;
895 BUILD_BUG_ON(sizeof(struct inet6_skb_parm
) > sizeof(dummy_skb
->cb
));
897 err
= proto_register(&tcpv6_prot
, 1);
901 err
= proto_register(&udpv6_prot
, 1);
903 goto out_unregister_tcp_proto
;
905 err
= proto_register(&udplitev6_prot
, 1);
907 goto out_unregister_udp_proto
;
909 err
= proto_register(&rawv6_prot
, 1);
911 goto out_unregister_udplite_proto
;
914 /* Register the socket-side information for inet6_create. */
915 for(r
= &inetsw6
[0]; r
< &inetsw6
[SOCK_MAX
]; ++r
)
918 /* We MUST register RAW sockets before we create the ICMP6,
919 * IGMP6, or NDISC control sockets.
923 goto out_unregister_raw_proto
;
925 /* Register the family here so that the init calls below will
926 * be able to create sockets. (?? is this dangerous ??)
928 err
= sock_register(&inet6_family_ops
);
930 goto out_sock_register_fail
;
932 /* Initialise ipv6 mibs */
933 err
= init_ipv6_mibs();
935 goto out_unregister_sock
;
938 err
= ipv6_static_sysctl_register();
940 goto static_sysctl_fail
;
943 * ipngwg API draft makes clear that the correct semantics
944 * for TCP and UDP is to consider one TCP and UDP instance
945 * in a host availiable by both INET and INET6 APIs and
946 * able to communicate via both network protocols.
949 err
= register_pernet_subsys(&inet6_net_ops
);
951 goto register_pernet_fail
;
964 err
= ipv6_netfilter_init();
967 /* Create /proc/foo6 entries. */
968 #ifdef CONFIG_PROC_FS
970 if (raw6_proc_init())
972 if (udplite6_proc_init())
973 goto proc_udplite6_fail
;
974 if (ipv6_misc_proc_init())
975 goto proc_misc6_fail
;
979 err
= ip6_route_init();
982 err
= ip6_flowlabel_init();
984 goto ip6_flowlabel_fail
;
985 err
= addrconf_init();
989 /* Init v6 extension headers. */
990 err
= ipv6_exthdrs_init();
992 goto ipv6_exthdrs_fail
;
994 err
= ipv6_frag_init();
998 /* Init v6 transport protocols. */
1003 err
= udplitev6_init();
1005 goto udplitev6_fail
;
1011 err
= ipv6_packet_init();
1013 goto ipv6_packet_fail
;
1015 #ifdef CONFIG_SYSCTL
1016 err
= ipv6_sysctl_register();
1023 #ifdef CONFIG_SYSCTL
1025 ipv6_packet_cleanup();
1036 ipv6_exthdrs_exit();
1040 ip6_flowlabel_cleanup();
1042 ip6_route_cleanup();
1044 #ifdef CONFIG_PROC_FS
1047 ipv6_misc_proc_exit();
1049 udplite6_proc_exit();
1054 ipv6_netfilter_fini();
1064 unregister_pernet_subsys(&inet6_net_ops
);
1065 register_pernet_fail
:
1066 #ifdef CONFIG_SYSCTL
1067 ipv6_static_sysctl_unregister();
1070 cleanup_ipv6_mibs();
1071 out_unregister_sock
:
1072 sock_unregister(PF_INET6
);
1073 rtnl_unregister_all(PF_INET6
);
1074 out_sock_register_fail
:
1076 out_unregister_raw_proto
:
1077 proto_unregister(&rawv6_prot
);
1078 out_unregister_udplite_proto
:
1079 proto_unregister(&udplitev6_prot
);
1080 out_unregister_udp_proto
:
1081 proto_unregister(&udpv6_prot
);
1082 out_unregister_tcp_proto
:
1083 proto_unregister(&tcpv6_prot
);
1086 module_init(inet6_init
);
1088 static void __exit
inet6_exit(void)
1090 /* First of all disallow new sockets creation. */
1091 sock_unregister(PF_INET6
);
1092 /* Disallow any further netlink messages */
1093 rtnl_unregister_all(PF_INET6
);
1095 #ifdef CONFIG_SYSCTL
1096 ipv6_sysctl_unregister();
1102 /* Cleanup code parts. */
1103 ipv6_packet_cleanup();
1105 ipv6_exthdrs_exit();
1107 ip6_flowlabel_cleanup();
1108 ip6_route_cleanup();
1109 #ifdef CONFIG_PROC_FS
1111 /* Cleanup code parts. */
1113 ipv6_misc_proc_exit();
1114 udplite6_proc_exit();
1117 ipv6_netfilter_fini();
1124 unregister_pernet_subsys(&inet6_net_ops
);
1125 #ifdef CONFIG_SYSCTL
1126 ipv6_static_sysctl_unregister();
1128 cleanup_ipv6_mibs();
1129 proto_unregister(&rawv6_prot
);
1130 proto_unregister(&udplitev6_prot
);
1131 proto_unregister(&udpv6_prot
);
1132 proto_unregister(&tcpv6_prot
);
1134 module_exit(inet6_exit
);
1136 MODULE_ALIAS_NETPROTO(PF_INET6
);