21 #define pr_fmt(fmt) "IPv6: " fmt
23 #include <linux/module.h>
24 #include <linux/capability.h>
25 #include <linux/errno.h>
26 #include <linux/types.h>
27 #include <linux/socket.h>
29 #include <linux/kernel.h>
31 #include <linux/string.h>
33 #include <linux/net.h>
34 #include <linux/fcntl.h>
38 #include <linux/stat.h>
40 #include <linux/slab.h>
43 #include <linux/netdevice.h>
44 #include <linux/icmpv6.h>
45 #include <linux/netfilter_ipv6.h>
59 #ifdef CONFIG_IPV6_TUNNEL
63 #include <asm/uaccess.h>
64 #include <linux/mroute6.h>
81 static int disable_ipv6_mod;
106 struct proto *answer_prot;
107 unsigned char answer_flags;
108 char answer_no_check;
109 int try_loading_module = 0;
121 list_for_each_entry_rcu(answer, &inetsw6[sock->
type],
list) {
141 if (try_loading_module < 2) {
147 if (++try_loading_module == 1)
148 request_module(
"net-pf-%d-proto-%d-type-%d",
155 request_module(
"net-pf-%d-proto-%d",
157 goto lookup_protocol;
167 answer_prot = answer->
prot;
169 answer_flags = answer->
flags;
201 inet_sk(sk)->pinet6 = np = inet6_sk_generic(sk);
206 np->
ipv6only = net->ipv6.sysctl.bindv6only;
240 sk->sk_prot->hash(sk);
242 if (sk->sk_prot->init) {
243 err = sk->sk_prot->init(sk);
261 struct sock *sk = sock->
sk;
264 struct net *net = sock_net(sk);
271 if (sk->sk_prot->bind)
272 return sk->sk_prot->bind(sk, uaddr, addr_len);
280 addr_type = ipv6_addr_type(&addr->
sin6_addr);
335 if (!sk->sk_bound_dev_if) {
350 if (!(addr_type & IPV6_ADDR_MULTICAST)) {
362 inet->inet_rcv_saddr = v4addr;
367 if (!(addr_type & IPV6_ADDR_MULTICAST))
371 if (sk->sk_prot->get_port(sk, snum)) {
372 inet_reset_saddr(sk);
386 inet->inet_daddr = 0;
398 struct sock *sk = sock->
sk;
445 int *uaddr_len,
int peer)
448 struct sock *sk = sock->
sk;
475 *uaddr_len =
sizeof(*sin);
482 struct sock *sk = sock->
sk;
483 struct net *net = sock_net(sk);
504 if (!sk->sk_prot->ioctl)
506 return sk->sk_prot->ioctl(sk, cmd, arg);
566 .create = inet6_create,
578 spin_lock_bh(&inetsw6_lock);
587 last_perm = &inetsw6[p->
type];
609 list_add_rcu(&p->
list, last_perm);
612 spin_unlock_bh(&inetsw6_lock);
616 pr_err(
"Attempt to override permanent protocol %d\n", protocol);
620 pr_err(
"Ignoring attempt to register invalid socket type %d\n",
630 pr_err(
"Attempt to unregister permanent protocol %d\n",
633 spin_lock_bh(&inetsw6_lock);
634 list_del_rcu(&p->
list);
635 spin_unlock_bh(&inetsw6_lock);
654 memset(&fl6, 0,
sizeof(fl6));
659 fl6.flowi6_oif = sk->sk_bound_dev_if;
663 security_sk_classify_flow(sk, flowi6_to_flowi(&fl6));
674 __ip6_dst_store(sk, dst,
NULL,
NULL);
690 *(
__be32 *)skb_network_header(skb)) &&
704 const struct inet6_protocol *
ops =
NULL;
716 if (!(ops->flags & INET6_PROTO_GSO_EXTHDR))
720 if (
unlikely(!pskb_may_pull(skb, 8)))
723 opth = (
void *)skb->
data;
726 if (
unlikely(!pskb_may_pull(skb, len)))
730 __skb_pull(skb, len);
736 static int ipv6_gso_send_check(
struct sk_buff *skb)
739 const struct inet6_protocol *ops;
742 if (
unlikely(!pskb_may_pull(skb,
sizeof(*ipv6h))))
745 ipv6h = ipv6_hdr(skb);
746 __skb_pull(skb,
sizeof(*ipv6h));
751 ipv6_gso_pull_exthdrs(skb, ipv6h->
nexthdr)]);
753 if (
likely(ops && ops->gso_send_check)) {
754 skb_reset_transport_header(skb);
755 err = ops->gso_send_check(skb);
768 const struct inet6_protocol *ops;
771 unsigned int unfrag_ip6hlen;
778 if (
unlikely(skb_shinfo(skb)->gso_type &
786 if (
unlikely(!pskb_may_pull(skb,
sizeof(*ipv6h))))
789 ipv6h = ipv6_hdr(skb);
790 __skb_pull(skb,
sizeof(*ipv6h));
793 proto = ipv6_gso_pull_exthdrs(skb, ipv6h->
nexthdr);
796 if (
likely(ops && ops->gso_segment)) {
797 skb_reset_transport_header(skb);
798 segs = ops->gso_segment(skb, features);
805 for (skb = segs;
skb; skb = skb->
next) {
806 ipv6h = ipv6_hdr(skb);
811 fptr = (
struct frag_hdr *)(skb_network_header(skb) +
828 const struct inet6_protocol *ops;
839 off = skb_gro_offset(skb);
840 hlen = off +
sizeof(*iph);
841 iph = skb_gro_header_fast(skb, off);
842 if (skb_gro_header_hard(skb, hlen)) {
843 iph = skb_gro_header_slow(skb, hlen, off);
848 skb_gro_pull(skb,
sizeof(*iph));
849 skb_set_transport_header(skb, skb_gro_offset(skb));
851 flush +=
ntohs(iph->payload_len) != skb_gro_len(skb);
854 proto = iph->nexthdr;
856 if (!ops || !ops->gro_receive) {
857 __pskb_pull(skb, skb_gro_offset(skb));
858 proto = ipv6_gso_pull_exthdrs(skb, proto);
859 skb_gro_pull(skb, -skb_transport_offset(skb));
860 skb_reset_transport_header(skb);
861 __skb_push(skb, skb_gro_offset(skb));
864 if (!ops || !ops->gro_receive)
873 nlen = skb_network_header_len(skb);
875 for (p = *head;
p; p = p->
next) {
886 if (nlen != skb_network_header_len(p) ||
887 (first_word &
htonl(0xF00FFFFF)) ||
901 skb_postpull_rcsum(skb, iph, skb_network_header_len(skb));
903 pp = ops->gro_receive(head, skb);
916 static int ipv6_gro_complete(
struct sk_buff *skb)
918 const struct inet6_protocol *ops;
919 struct ipv6hdr *iph = ipv6_hdr(skb);
927 if (
WARN_ON(!ops || !ops->gro_complete))
930 err = ops->gro_complete(skb);
941 .gso_send_check = ipv6_gso_send_check,
942 .gso_segment = ipv6_gso_segment,
943 .gro_receive = ipv6_gro_receive,
944 .gro_complete = ipv6_gro_complete,
947 static int __init ipv6_packet_init(
void)
953 static void ipv6_packet_cleanup(
void)
958 static int __net_init ipv6_init_mibs(
struct net *net)
962 __alignof__(
struct udp_mib)) < 0)
966 __alignof__(
struct udp_mib)) < 0)
967 goto err_udplite_mib;
978 if (!net->
mib.icmpv6msg_statistics)
979 goto err_icmpmsg_mib;
993 static void ipv6_cleanup_mibs(
struct net *net)
999 kfree(net->
mib.icmpv6msg_statistics);
1002 static int __net_init inet6_net_init(
struct net *net)
1006 net->ipv6.sysctl.bindv6only = 0;
1007 net->ipv6.sysctl.icmpv6_time = 1*
HZ;
1009 err = ipv6_init_mibs(net);
1012 #ifdef CONFIG_PROC_FS
1013 err = udp6_proc_init(net);
1016 err = tcp6_proc_init(net);
1018 goto proc_tcp6_fail;
1019 err = ac6_proc_init(net);
1025 #ifdef CONFIG_PROC_FS
1027 tcp6_proc_exit(net);
1029 udp6_proc_exit(net);
1031 ipv6_cleanup_mibs(net);
1036 static void __net_exit inet6_net_exit(
struct net *net)
1038 #ifdef CONFIG_PROC_FS
1039 udp6_proc_exit(net);
1040 tcp6_proc_exit(net);
1043 ipv6_cleanup_mibs(net);
1047 .init = inet6_net_init,
1048 .exit = inet6_net_exit,
1051 static int __init inet6_init(
void)
1060 for (r = &inetsw6[0]; r < &inetsw6[
SOCK_MAX]; ++
r)
1063 if (disable_ipv6_mod) {
1064 pr_info(
"Loaded, but administratively disabled, reboot required to enable\n");
1074 goto out_unregister_tcp_proto;
1078 goto out_unregister_udp_proto;
1082 goto out_unregister_udplite_proto;
1090 goto out_unregister_raw_proto;
1097 goto out_sock_register_fail;
1110 goto register_pernet_fail;
1125 goto netfilter_fail;
1127 #ifdef CONFIG_PROC_FS
1129 if (raw6_proc_init())
1130 goto proc_raw6_fail;
1131 if (udplite6_proc_init())
1132 goto proc_udplite6_fail;
1134 goto proc_misc6_fail;
1135 if (if6_proc_init())
1140 goto ip6_route_fail;
1143 goto ip6_flowlabel_fail;
1151 goto ipv6_exthdrs_fail;
1155 goto ipv6_frag_fail;
1164 goto udplitev6_fail;
1170 err = ipv6_packet_init();
1172 goto ipv6_packet_fail;
1174 #ifdef CONFIG_SYSCTL
1182 #ifdef CONFIG_SYSCTL
1184 ipv6_packet_cleanup();
1203 #ifdef CONFIG_PROC_FS
1208 udplite6_proc_exit();
1224 register_pernet_fail:
1227 out_sock_register_fail:
1229 out_unregister_raw_proto:
1231 out_unregister_udplite_proto:
1233 out_unregister_udp_proto:
1235 out_unregister_tcp_proto:
1241 static void __exit inet6_exit(
void)
1243 if (disable_ipv6_mod)
1256 ipv6_packet_cleanup();
1262 #ifdef CONFIG_PROC_FS
1267 udplite6_proc_exit();