diff options
author | Vlad Yasevich <vyasevic@redhat.com> | 2012-11-15 03:49:16 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-11-15 17:36:17 -0500 |
commit | d1da932ed4ecad2a14cbcc01ed589d617d0f0f09 (patch) | |
tree | 4bb87010518230535875ac19872139e650003bcb /net | |
parent | 3336288a9feaa809839adbaf05778dc2f16665dc (diff) |
ipv6: Separate ipv6 offload support
Separate IPv6 offload functionality into its own file
in preparation for the move out of the module
Signed-off-by: Vlad Yasevich <vyasevic@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/ipv6/Makefile | 3 | ||||
-rw-r--r-- | net/ipv6/af_inet6.c | 249 | ||||
-rw-r--r-- | net/ipv6/ip6_offload.c | 273 | ||||
-rw-r--r-- | net/ipv6/ip6_offload.h | 17 |
4 files changed, 296 insertions, 246 deletions
diff --git a/net/ipv6/Makefile b/net/ipv6/Makefile index b6d3f79151e2..45bd9cdd9244 100644 --- a/net/ipv6/Makefile +++ b/net/ipv6/Makefile | |||
@@ -10,6 +10,8 @@ ipv6-objs := af_inet6.o anycast.o ip6_output.o ip6_input.o addrconf.o \ | |||
10 | raw.o protocol.o icmp.o mcast.o reassembly.o tcp_ipv6.o \ | 10 | raw.o protocol.o icmp.o mcast.o reassembly.o tcp_ipv6.o \ |
11 | exthdrs.o datagram.o ip6_flowlabel.o inet6_connection_sock.o | 11 | exthdrs.o datagram.o ip6_flowlabel.o inet6_connection_sock.o |
12 | 12 | ||
13 | ipv6-offload := ip6_offload.o | ||
14 | |||
13 | ipv6-$(CONFIG_SYSCTL) = sysctl_net_ipv6.o | 15 | ipv6-$(CONFIG_SYSCTL) = sysctl_net_ipv6.o |
14 | ipv6-$(CONFIG_IPV6_MROUTE) += ip6mr.o | 16 | ipv6-$(CONFIG_IPV6_MROUTE) += ip6mr.o |
15 | 17 | ||
@@ -21,6 +23,7 @@ ipv6-$(CONFIG_PROC_FS) += proc.o | |||
21 | ipv6-$(CONFIG_SYN_COOKIES) += syncookies.o | 23 | ipv6-$(CONFIG_SYN_COOKIES) += syncookies.o |
22 | 24 | ||
23 | ipv6-objs += $(ipv6-y) | 25 | ipv6-objs += $(ipv6-y) |
26 | ipv6-objs += $(ipv6-offload) | ||
24 | 27 | ||
25 | obj-$(CONFIG_INET6_AH) += ah6.o | 28 | obj-$(CONFIG_INET6_AH) += ah6.o |
26 | obj-$(CONFIG_INET6_ESP) += esp6.o | 29 | obj-$(CONFIG_INET6_ESP) += esp6.o |
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c index eb63dac68728..c84d5ba60cdd 100644 --- a/net/ipv6/af_inet6.c +++ b/net/ipv6/af_inet6.c | |||
@@ -62,6 +62,7 @@ | |||
62 | 62 | ||
63 | #include <asm/uaccess.h> | 63 | #include <asm/uaccess.h> |
64 | #include <linux/mroute6.h> | 64 | #include <linux/mroute6.h> |
65 | #include "ip6_offload.h" | ||
65 | 66 | ||
66 | MODULE_AUTHOR("Cast of dozens"); | 67 | MODULE_AUTHOR("Cast of dozens"); |
67 | MODULE_DESCRIPTION("IPv6 protocol stack for Linux"); | 68 | MODULE_DESCRIPTION("IPv6 protocol stack for Linux"); |
@@ -699,266 +700,22 @@ bool ipv6_opt_accepted(const struct sock *sk, const struct sk_buff *skb) | |||
699 | } | 700 | } |
700 | EXPORT_SYMBOL_GPL(ipv6_opt_accepted); | 701 | EXPORT_SYMBOL_GPL(ipv6_opt_accepted); |
701 | 702 | ||
702 | static int ipv6_gso_pull_exthdrs(struct sk_buff *skb, int proto) | ||
703 | { | ||
704 | const struct net_offload *ops = NULL; | ||
705 | |||
706 | for (;;) { | ||
707 | struct ipv6_opt_hdr *opth; | ||
708 | int len; | ||
709 | |||
710 | if (proto != NEXTHDR_HOP) { | ||
711 | ops = rcu_dereference(inet6_offloads[proto]); | ||
712 | |||
713 | if (unlikely(!ops)) | ||
714 | break; | ||
715 | |||
716 | if (!(ops->flags & INET6_PROTO_GSO_EXTHDR)) | ||
717 | break; | ||
718 | } | ||
719 | |||
720 | if (unlikely(!pskb_may_pull(skb, 8))) | ||
721 | break; | ||
722 | |||
723 | opth = (void *)skb->data; | ||
724 | len = ipv6_optlen(opth); | ||
725 | |||
726 | if (unlikely(!pskb_may_pull(skb, len))) | ||
727 | break; | ||
728 | |||
729 | proto = opth->nexthdr; | ||
730 | __skb_pull(skb, len); | ||
731 | } | ||
732 | |||
733 | return proto; | ||
734 | } | ||
735 | |||
736 | static int ipv6_gso_send_check(struct sk_buff *skb) | ||
737 | { | ||
738 | const struct ipv6hdr *ipv6h; | ||
739 | const struct net_offload *ops; | ||
740 | int err = -EINVAL; | ||
741 | |||
742 | if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h)))) | ||
743 | goto out; | ||
744 | |||
745 | ipv6h = ipv6_hdr(skb); | ||
746 | __skb_pull(skb, sizeof(*ipv6h)); | ||
747 | err = -EPROTONOSUPPORT; | ||
748 | |||
749 | rcu_read_lock(); | ||
750 | ops = rcu_dereference(inet6_offloads[ | ||
751 | ipv6_gso_pull_exthdrs(skb, ipv6h->nexthdr)]); | ||
752 | |||
753 | if (likely(ops && ops->gso_send_check)) { | ||
754 | skb_reset_transport_header(skb); | ||
755 | err = ops->gso_send_check(skb); | ||
756 | } | ||
757 | rcu_read_unlock(); | ||
758 | |||
759 | out: | ||
760 | return err; | ||
761 | } | ||
762 | |||
763 | static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb, | ||
764 | netdev_features_t features) | ||
765 | { | ||
766 | struct sk_buff *segs = ERR_PTR(-EINVAL); | ||
767 | struct ipv6hdr *ipv6h; | ||
768 | const struct net_offload *ops; | ||
769 | int proto; | ||
770 | struct frag_hdr *fptr; | ||
771 | unsigned int unfrag_ip6hlen; | ||
772 | u8 *prevhdr; | ||
773 | int offset = 0; | ||
774 | |||
775 | if (!(features & NETIF_F_V6_CSUM)) | ||
776 | features &= ~NETIF_F_SG; | ||
777 | |||
778 | if (unlikely(skb_shinfo(skb)->gso_type & | ||
779 | ~(SKB_GSO_UDP | | ||
780 | SKB_GSO_DODGY | | ||
781 | SKB_GSO_TCP_ECN | | ||
782 | SKB_GSO_TCPV6 | | ||
783 | 0))) | ||
784 | goto out; | ||
785 | |||
786 | if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h)))) | ||
787 | goto out; | ||
788 | |||
789 | ipv6h = ipv6_hdr(skb); | ||
790 | __skb_pull(skb, sizeof(*ipv6h)); | ||
791 | segs = ERR_PTR(-EPROTONOSUPPORT); | ||
792 | |||
793 | proto = ipv6_gso_pull_exthdrs(skb, ipv6h->nexthdr); | ||
794 | rcu_read_lock(); | ||
795 | ops = rcu_dereference(inet6_offloads[proto]); | ||
796 | if (likely(ops && ops->gso_segment)) { | ||
797 | skb_reset_transport_header(skb); | ||
798 | segs = ops->gso_segment(skb, features); | ||
799 | } | ||
800 | rcu_read_unlock(); | ||
801 | |||
802 | if (IS_ERR(segs)) | ||
803 | goto out; | ||
804 | |||
805 | for (skb = segs; skb; skb = skb->next) { | ||
806 | ipv6h = ipv6_hdr(skb); | ||
807 | ipv6h->payload_len = htons(skb->len - skb->mac_len - | ||
808 | sizeof(*ipv6h)); | ||
809 | if (proto == IPPROTO_UDP) { | ||
810 | unfrag_ip6hlen = ip6_find_1stfragopt(skb, &prevhdr); | ||
811 | fptr = (struct frag_hdr *)(skb_network_header(skb) + | ||
812 | unfrag_ip6hlen); | ||
813 | fptr->frag_off = htons(offset); | ||
814 | if (skb->next != NULL) | ||
815 | fptr->frag_off |= htons(IP6_MF); | ||
816 | offset += (ntohs(ipv6h->payload_len) - | ||
817 | sizeof(struct frag_hdr)); | ||
818 | } | ||
819 | } | ||
820 | |||
821 | out: | ||
822 | return segs; | ||
823 | } | ||
824 | |||
825 | static struct sk_buff **ipv6_gro_receive(struct sk_buff **head, | ||
826 | struct sk_buff *skb) | ||
827 | { | ||
828 | const struct net_offload *ops; | ||
829 | struct sk_buff **pp = NULL; | ||
830 | struct sk_buff *p; | ||
831 | struct ipv6hdr *iph; | ||
832 | unsigned int nlen; | ||
833 | unsigned int hlen; | ||
834 | unsigned int off; | ||
835 | int flush = 1; | ||
836 | int proto; | ||
837 | __wsum csum; | ||
838 | |||
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); | ||
844 | if (unlikely(!iph)) | ||
845 | goto out; | ||
846 | } | ||
847 | |||
848 | skb_gro_pull(skb, sizeof(*iph)); | ||
849 | skb_set_transport_header(skb, skb_gro_offset(skb)); | ||
850 | |||
851 | flush += ntohs(iph->payload_len) != skb_gro_len(skb); | ||
852 | |||
853 | rcu_read_lock(); | ||
854 | proto = iph->nexthdr; | ||
855 | ops = rcu_dereference(inet6_offloads[proto]); | ||
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)); | ||
862 | |||
863 | ops = rcu_dereference(inet6_offloads[proto]); | ||
864 | if (!ops || !ops->gro_receive) | ||
865 | goto out_unlock; | ||
866 | |||
867 | iph = ipv6_hdr(skb); | ||
868 | } | ||
869 | |||
870 | NAPI_GRO_CB(skb)->proto = proto; | ||
871 | |||
872 | flush--; | ||
873 | nlen = skb_network_header_len(skb); | ||
874 | |||
875 | for (p = *head; p; p = p->next) { | ||
876 | const struct ipv6hdr *iph2; | ||
877 | __be32 first_word; /* <Version:4><Traffic_Class:8><Flow_Label:20> */ | ||
878 | |||
879 | if (!NAPI_GRO_CB(p)->same_flow) | ||
880 | continue; | ||
881 | |||
882 | iph2 = ipv6_hdr(p); | ||
883 | first_word = *(__be32 *)iph ^ *(__be32 *)iph2 ; | ||
884 | |||
885 | /* All fields must match except length and Traffic Class. */ | ||
886 | if (nlen != skb_network_header_len(p) || | ||
887 | (first_word & htonl(0xF00FFFFF)) || | ||
888 | memcmp(&iph->nexthdr, &iph2->nexthdr, | ||
889 | nlen - offsetof(struct ipv6hdr, nexthdr))) { | ||
890 | NAPI_GRO_CB(p)->same_flow = 0; | ||
891 | continue; | ||
892 | } | ||
893 | /* flush if Traffic Class fields are different */ | ||
894 | NAPI_GRO_CB(p)->flush |= !!(first_word & htonl(0x0FF00000)); | ||
895 | NAPI_GRO_CB(p)->flush |= flush; | ||
896 | } | ||
897 | |||
898 | NAPI_GRO_CB(skb)->flush |= flush; | ||
899 | |||
900 | csum = skb->csum; | ||
901 | skb_postpull_rcsum(skb, iph, skb_network_header_len(skb)); | ||
902 | |||
903 | pp = ops->gro_receive(head, skb); | ||
904 | |||
905 | skb->csum = csum; | ||
906 | |||
907 | out_unlock: | ||
908 | rcu_read_unlock(); | ||
909 | |||
910 | out: | ||
911 | NAPI_GRO_CB(skb)->flush |= flush; | ||
912 | |||
913 | return pp; | ||
914 | } | ||
915 | |||
916 | static int ipv6_gro_complete(struct sk_buff *skb) | ||
917 | { | ||
918 | const struct net_offload *ops; | ||
919 | struct ipv6hdr *iph = ipv6_hdr(skb); | ||
920 | int err = -ENOSYS; | ||
921 | |||
922 | iph->payload_len = htons(skb->len - skb_network_offset(skb) - | ||
923 | sizeof(*iph)); | ||
924 | |||
925 | rcu_read_lock(); | ||
926 | ops = rcu_dereference(inet6_offloads[NAPI_GRO_CB(skb)->proto]); | ||
927 | if (WARN_ON(!ops || !ops->gro_complete)) | ||
928 | goto out_unlock; | ||
929 | |||
930 | err = ops->gro_complete(skb); | ||
931 | |||
932 | out_unlock: | ||
933 | rcu_read_unlock(); | ||
934 | |||
935 | return err; | ||
936 | } | ||
937 | |||
938 | static struct packet_type ipv6_packet_type __read_mostly = { | 703 | static struct packet_type ipv6_packet_type __read_mostly = { |
939 | .type = cpu_to_be16(ETH_P_IPV6), | 704 | .type = cpu_to_be16(ETH_P_IPV6), |
940 | .func = ipv6_rcv, | 705 | .func = ipv6_rcv, |
941 | }; | 706 | }; |
942 | 707 | ||
943 | static struct packet_offload ipv6_packet_offload __read_mostly = { | ||
944 | .type = cpu_to_be16(ETH_P_IPV6), | ||
945 | .gso_send_check = ipv6_gso_send_check, | ||
946 | .gso_segment = ipv6_gso_segment, | ||
947 | .gro_receive = ipv6_gro_receive, | ||
948 | .gro_complete = ipv6_gro_complete, | ||
949 | }; | ||
950 | |||
951 | static int __init ipv6_packet_init(void) | 708 | static int __init ipv6_packet_init(void) |
952 | { | 709 | { |
953 | dev_add_offload(&ipv6_packet_offload); | 710 | ipv6_offload_init(); |
954 | dev_add_pack(&ipv6_packet_type); | 711 | dev_add_pack(&ipv6_packet_type); |
955 | return 0; | 712 | return 0; |
956 | } | 713 | } |
957 | 714 | ||
958 | static void ipv6_packet_cleanup(void) | 715 | static void ipv6_packet_cleanup(void) |
959 | { | 716 | { |
717 | ipv6_offload_cleanup(); | ||
960 | dev_remove_pack(&ipv6_packet_type); | 718 | dev_remove_pack(&ipv6_packet_type); |
961 | dev_remove_offload(&ipv6_packet_offload); | ||
962 | } | 719 | } |
963 | 720 | ||
964 | static int __net_init ipv6_init_mibs(struct net *net) | 721 | static int __net_init ipv6_init_mibs(struct net *net) |
diff --git a/net/ipv6/ip6_offload.c b/net/ipv6/ip6_offload.c new file mode 100644 index 000000000000..01cf9835a581 --- /dev/null +++ b/net/ipv6/ip6_offload.c | |||
@@ -0,0 +1,273 @@ | |||
1 | /* | ||
2 | * IPV6 GSO/GRO offload support | ||
3 | * Linux INET6 implementation | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU General Public License | ||
7 | * as published by the Free Software Foundation; either version | ||
8 | * 2 of the License, or (at your option) any later version. | ||
9 | */ | ||
10 | |||
11 | #include <linux/kernel.h> | ||
12 | #include <linux/socket.h> | ||
13 | #include <linux/netdevice.h> | ||
14 | #include <linux/skbuff.h> | ||
15 | |||
16 | #include <net/protocol.h> | ||
17 | #include <net/ipv6.h> | ||
18 | |||
19 | #include "ip6_offload.h" | ||
20 | |||
21 | static int ipv6_gso_pull_exthdrs(struct sk_buff *skb, int proto) | ||
22 | { | ||
23 | const struct net_offload *ops = NULL; | ||
24 | |||
25 | for (;;) { | ||
26 | struct ipv6_opt_hdr *opth; | ||
27 | int len; | ||
28 | |||
29 | if (proto != NEXTHDR_HOP) { | ||
30 | ops = rcu_dereference(inet6_offloads[proto]); | ||
31 | |||
32 | if (unlikely(!ops)) | ||
33 | break; | ||
34 | |||
35 | if (!(ops->flags & INET6_PROTO_GSO_EXTHDR)) | ||
36 | break; | ||
37 | } | ||
38 | |||
39 | if (unlikely(!pskb_may_pull(skb, 8))) | ||
40 | break; | ||
41 | |||
42 | opth = (void *)skb->data; | ||
43 | len = ipv6_optlen(opth); | ||
44 | |||
45 | if (unlikely(!pskb_may_pull(skb, len))) | ||
46 | break; | ||
47 | |||
48 | proto = opth->nexthdr; | ||
49 | __skb_pull(skb, len); | ||
50 | } | ||
51 | |||
52 | return proto; | ||
53 | } | ||
54 | |||
55 | static int ipv6_gso_send_check(struct sk_buff *skb) | ||
56 | { | ||
57 | const struct ipv6hdr *ipv6h; | ||
58 | const struct net_offload *ops; | ||
59 | int err = -EINVAL; | ||
60 | |||
61 | if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h)))) | ||
62 | goto out; | ||
63 | |||
64 | ipv6h = ipv6_hdr(skb); | ||
65 | __skb_pull(skb, sizeof(*ipv6h)); | ||
66 | err = -EPROTONOSUPPORT; | ||
67 | |||
68 | rcu_read_lock(); | ||
69 | ops = rcu_dereference(inet6_offloads[ | ||
70 | ipv6_gso_pull_exthdrs(skb, ipv6h->nexthdr)]); | ||
71 | |||
72 | if (likely(ops && ops->gso_send_check)) { | ||
73 | skb_reset_transport_header(skb); | ||
74 | err = ops->gso_send_check(skb); | ||
75 | } | ||
76 | rcu_read_unlock(); | ||
77 | |||
78 | out: | ||
79 | return err; | ||
80 | } | ||
81 | |||
82 | static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb, | ||
83 | netdev_features_t features) | ||
84 | { | ||
85 | struct sk_buff *segs = ERR_PTR(-EINVAL); | ||
86 | struct ipv6hdr *ipv6h; | ||
87 | const struct net_offload *ops; | ||
88 | int proto; | ||
89 | struct frag_hdr *fptr; | ||
90 | unsigned int unfrag_ip6hlen; | ||
91 | u8 *prevhdr; | ||
92 | int offset = 0; | ||
93 | |||
94 | if (!(features & NETIF_F_V6_CSUM)) | ||
95 | features &= ~NETIF_F_SG; | ||
96 | |||
97 | if (unlikely(skb_shinfo(skb)->gso_type & | ||
98 | ~(SKB_GSO_UDP | | ||
99 | SKB_GSO_DODGY | | ||
100 | SKB_GSO_TCP_ECN | | ||
101 | SKB_GSO_TCPV6 | | ||
102 | 0))) | ||
103 | goto out; | ||
104 | |||
105 | if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h)))) | ||
106 | goto out; | ||
107 | |||
108 | ipv6h = ipv6_hdr(skb); | ||
109 | __skb_pull(skb, sizeof(*ipv6h)); | ||
110 | segs = ERR_PTR(-EPROTONOSUPPORT); | ||
111 | |||
112 | proto = ipv6_gso_pull_exthdrs(skb, ipv6h->nexthdr); | ||
113 | rcu_read_lock(); | ||
114 | ops = rcu_dereference(inet6_offloads[proto]); | ||
115 | if (likely(ops && ops->gso_segment)) { | ||
116 | skb_reset_transport_header(skb); | ||
117 | segs = ops->gso_segment(skb, features); | ||
118 | } | ||
119 | rcu_read_unlock(); | ||
120 | |||
121 | if (IS_ERR(segs)) | ||
122 | goto out; | ||
123 | |||
124 | for (skb = segs; skb; skb = skb->next) { | ||
125 | ipv6h = ipv6_hdr(skb); | ||
126 | ipv6h->payload_len = htons(skb->len - skb->mac_len - | ||
127 | sizeof(*ipv6h)); | ||
128 | if (proto == IPPROTO_UDP) { | ||
129 | unfrag_ip6hlen = ip6_find_1stfragopt(skb, &prevhdr); | ||
130 | fptr = (struct frag_hdr *)(skb_network_header(skb) + | ||
131 | unfrag_ip6hlen); | ||
132 | fptr->frag_off = htons(offset); | ||
133 | if (skb->next != NULL) | ||
134 | fptr->frag_off |= htons(IP6_MF); | ||
135 | offset += (ntohs(ipv6h->payload_len) - | ||
136 | sizeof(struct frag_hdr)); | ||
137 | } | ||
138 | } | ||
139 | |||
140 | out: | ||
141 | return segs; | ||
142 | } | ||
143 | |||
144 | static struct sk_buff **ipv6_gro_receive(struct sk_buff **head, | ||
145 | struct sk_buff *skb) | ||
146 | { | ||
147 | const struct net_offload *ops; | ||
148 | struct sk_buff **pp = NULL; | ||
149 | struct sk_buff *p; | ||
150 | struct ipv6hdr *iph; | ||
151 | unsigned int nlen; | ||
152 | unsigned int hlen; | ||
153 | unsigned int off; | ||
154 | int flush = 1; | ||
155 | int proto; | ||
156 | __wsum csum; | ||
157 | |||
158 | off = skb_gro_offset(skb); | ||
159 | hlen = off + sizeof(*iph); | ||
160 | iph = skb_gro_header_fast(skb, off); | ||
161 | if (skb_gro_header_hard(skb, hlen)) { | ||
162 | iph = skb_gro_header_slow(skb, hlen, off); | ||
163 | if (unlikely(!iph)) | ||
164 | goto out; | ||
165 | } | ||
166 | |||
167 | skb_gro_pull(skb, sizeof(*iph)); | ||
168 | skb_set_transport_header(skb, skb_gro_offset(skb)); | ||
169 | |||
170 | flush += ntohs(iph->payload_len) != skb_gro_len(skb); | ||
171 | |||
172 | rcu_read_lock(); | ||
173 | proto = iph->nexthdr; | ||
174 | ops = rcu_dereference(inet6_offloads[proto]); | ||
175 | if (!ops || !ops->gro_receive) { | ||
176 | __pskb_pull(skb, skb_gro_offset(skb)); | ||
177 | proto = ipv6_gso_pull_exthdrs(skb, proto); | ||
178 | skb_gro_pull(skb, -skb_transport_offset(skb)); | ||
179 | skb_reset_transport_header(skb); | ||
180 | __skb_push(skb, skb_gro_offset(skb)); | ||
181 | |||
182 | ops = rcu_dereference(inet6_offloads[proto]); | ||
183 | if (!ops || !ops->gro_receive) | ||
184 | goto out_unlock; | ||
185 | |||
186 | iph = ipv6_hdr(skb); | ||
187 | } | ||
188 | |||
189 | NAPI_GRO_CB(skb)->proto = proto; | ||
190 | |||
191 | flush--; | ||
192 | nlen = skb_network_header_len(skb); | ||
193 | |||
194 | for (p = *head; p; p = p->next) { | ||
195 | const struct ipv6hdr *iph2; | ||
196 | __be32 first_word; /* <Version:4><Traffic_Class:8><Flow_Label:20> */ | ||
197 | |||
198 | if (!NAPI_GRO_CB(p)->same_flow) | ||
199 | continue; | ||
200 | |||
201 | iph2 = ipv6_hdr(p); | ||
202 | first_word = *(__be32 *)iph ^ *(__be32 *)iph2 ; | ||
203 | |||
204 | /* All fields must match except length and Traffic Class. */ | ||
205 | if (nlen != skb_network_header_len(p) || | ||
206 | (first_word & htonl(0xF00FFFFF)) || | ||
207 | memcmp(&iph->nexthdr, &iph2->nexthdr, | ||
208 | nlen - offsetof(struct ipv6hdr, nexthdr))) { | ||
209 | NAPI_GRO_CB(p)->same_flow = 0; | ||
210 | continue; | ||
211 | } | ||
212 | /* flush if Traffic Class fields are different */ | ||
213 | NAPI_GRO_CB(p)->flush |= !!(first_word & htonl(0x0FF00000)); | ||
214 | NAPI_GRO_CB(p)->flush |= flush; | ||
215 | } | ||
216 | |||
217 | NAPI_GRO_CB(skb)->flush |= flush; | ||
218 | |||
219 | csum = skb->csum; | ||
220 | skb_postpull_rcsum(skb, iph, skb_network_header_len(skb)); | ||
221 | |||
222 | pp = ops->gro_receive(head, skb); | ||
223 | |||
224 | skb->csum = csum; | ||
225 | |||
226 | out_unlock: | ||
227 | rcu_read_unlock(); | ||
228 | |||
229 | out: | ||
230 | NAPI_GRO_CB(skb)->flush |= flush; | ||
231 | |||
232 | return pp; | ||
233 | } | ||
234 | |||
235 | static int ipv6_gro_complete(struct sk_buff *skb) | ||
236 | { | ||
237 | const struct net_offload *ops; | ||
238 | struct ipv6hdr *iph = ipv6_hdr(skb); | ||
239 | int err = -ENOSYS; | ||
240 | |||
241 | iph->payload_len = htons(skb->len - skb_network_offset(skb) - | ||
242 | sizeof(*iph)); | ||
243 | |||
244 | rcu_read_lock(); | ||
245 | ops = rcu_dereference(inet6_offloads[NAPI_GRO_CB(skb)->proto]); | ||
246 | if (WARN_ON(!ops || !ops->gro_complete)) | ||
247 | goto out_unlock; | ||
248 | |||
249 | err = ops->gro_complete(skb); | ||
250 | |||
251 | out_unlock: | ||
252 | rcu_read_unlock(); | ||
253 | |||
254 | return err; | ||
255 | } | ||
256 | |||
257 | static struct packet_offload ipv6_packet_offload __read_mostly = { | ||
258 | .type = cpu_to_be16(ETH_P_IPV6), | ||
259 | .gso_send_check = ipv6_gso_send_check, | ||
260 | .gso_segment = ipv6_gso_segment, | ||
261 | .gro_receive = ipv6_gro_receive, | ||
262 | .gro_complete = ipv6_gro_complete, | ||
263 | }; | ||
264 | |||
265 | void __init ipv6_offload_init(void) | ||
266 | { | ||
267 | dev_add_offload(&ipv6_packet_offload); | ||
268 | } | ||
269 | |||
270 | void ipv6_offload_cleanup(void) | ||
271 | { | ||
272 | dev_remove_offload(&ipv6_packet_offload); | ||
273 | } | ||
diff --git a/net/ipv6/ip6_offload.h b/net/ipv6/ip6_offload.h new file mode 100644 index 000000000000..c09614eaa929 --- /dev/null +++ b/net/ipv6/ip6_offload.h | |||
@@ -0,0 +1,17 @@ | |||
1 | /* | ||
2 | * IPV6 GSO/GRO offload support | ||
3 | * Linux INET6 implementation | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU General Public License | ||
7 | * as published by the Free Software Foundation; either version | ||
8 | * 2 of the License, or (at your option) any later version. | ||
9 | */ | ||
10 | |||
11 | #ifndef __ip6_offload_h | ||
12 | #define __ip6_offload_h | ||
13 | |||
14 | extern void ipv6_offload_init(void); | ||
15 | extern void ipv6_offload_cleanup(void); | ||
16 | |||
17 | #endif | ||