Vlad Yasevich | 8663e02 | 2012-11-15 08:49:17 +0000 | [diff] [blame] | 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 | * TCPv6 GSO/GRO support |
| 11 | */ |
| 12 | #include <linux/skbuff.h> |
| 13 | #include <net/protocol.h> |
| 14 | #include <net/tcp.h> |
| 15 | #include <net/ip6_checksum.h> |
| 16 | #include "ip6_offload.h" |
| 17 | |
| 18 | static int tcp_v6_gso_send_check(struct sk_buff *skb) |
| 19 | { |
Vlad Yasevich | 8663e02 | 2012-11-15 08:49:17 +0000 | [diff] [blame] | 20 | return 0; |
| 21 | } |
| 22 | |
| 23 | static struct sk_buff **tcp6_gro_receive(struct sk_buff **head, |
| 24 | struct sk_buff *skb) |
| 25 | { |
Herbert Xu | cc5c00b | 2013-11-22 10:31:29 +0800 | [diff] [blame] | 26 | /* Don't bother verifying checksum if we're going to flush anyway. */ |
Tom Herbert | 149d077 | 2014-08-22 13:34:30 -0700 | [diff] [blame] | 27 | if (!NAPI_GRO_CB(skb)->flush && |
| 28 | skb_gro_checksum_validate(skb, IPPROTO_TCP, |
| 29 | ip6_gro_compute_pseudo)) { |
Vlad Yasevich | 8663e02 | 2012-11-15 08:49:17 +0000 | [diff] [blame] | 30 | NAPI_GRO_CB(skb)->flush = 1; |
| 31 | return NULL; |
Vlad Yasevich | 8663e02 | 2012-11-15 08:49:17 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | return tcp_gro_receive(head, skb); |
| 35 | } |
| 36 | |
Jerry Chu | 299603e8 | 2013-12-11 20:53:45 -0800 | [diff] [blame] | 37 | static int tcp6_gro_complete(struct sk_buff *skb, int thoff) |
Vlad Yasevich | 8663e02 | 2012-11-15 08:49:17 +0000 | [diff] [blame] | 38 | { |
| 39 | const struct ipv6hdr *iph = ipv6_hdr(skb); |
| 40 | struct tcphdr *th = tcp_hdr(skb); |
| 41 | |
Jerry Chu | 299603e8 | 2013-12-11 20:53:45 -0800 | [diff] [blame] | 42 | th->check = ~tcp_v6_check(skb->len - thoff, &iph->saddr, |
| 43 | &iph->daddr, 0); |
Jerry Chu | c3caf11 | 2014-07-14 15:54:46 -0700 | [diff] [blame] | 44 | skb_shinfo(skb)->gso_type |= SKB_GSO_TCPV6; |
Vlad Yasevich | 8663e02 | 2012-11-15 08:49:17 +0000 | [diff] [blame] | 45 | |
| 46 | return tcp_gro_complete(skb); |
| 47 | } |
| 48 | |
Tom Herbert | d020f8f | 2014-09-20 14:52:28 -0700 | [diff] [blame^] | 49 | struct sk_buff *tcp6_gso_segment(struct sk_buff *skb, |
| 50 | netdev_features_t features) |
| 51 | { |
| 52 | struct tcphdr *th; |
| 53 | |
| 54 | if (!pskb_may_pull(skb, sizeof(*th))) |
| 55 | return ERR_PTR(-EINVAL); |
| 56 | |
| 57 | if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) { |
| 58 | const struct ipv6hdr *ipv6h = ipv6_hdr(skb); |
| 59 | struct tcphdr *th = tcp_hdr(skb); |
| 60 | |
| 61 | /* Set up pseudo header, usually expect stack to have done |
| 62 | * this. |
| 63 | */ |
| 64 | |
| 65 | th->check = 0; |
| 66 | skb->ip_summed = CHECKSUM_PARTIAL; |
| 67 | __tcp_v6_send_check(skb, &ipv6h->saddr, &ipv6h->daddr); |
| 68 | } |
| 69 | |
| 70 | return tcp_gso_segment(skb, features); |
| 71 | } |
Vlad Yasevich | 8663e02 | 2012-11-15 08:49:17 +0000 | [diff] [blame] | 72 | static const struct net_offload tcpv6_offload = { |
Vlad Yasevich | f191a1d | 2012-11-15 08:49:23 +0000 | [diff] [blame] | 73 | .callbacks = { |
| 74 | .gso_send_check = tcp_v6_gso_send_check, |
Tom Herbert | d020f8f | 2014-09-20 14:52:28 -0700 | [diff] [blame^] | 75 | .gso_segment = tcp6_gso_segment, |
Vlad Yasevich | f191a1d | 2012-11-15 08:49:23 +0000 | [diff] [blame] | 76 | .gro_receive = tcp6_gro_receive, |
| 77 | .gro_complete = tcp6_gro_complete, |
| 78 | }, |
Vlad Yasevich | 8663e02 | 2012-11-15 08:49:17 +0000 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | int __init tcpv6_offload_init(void) |
| 82 | { |
| 83 | return inet6_add_offload(&tcpv6_offload, IPPROTO_TCP); |
| 84 | } |