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 | { |
| 20 | const struct ipv6hdr *ipv6h; |
| 21 | struct tcphdr *th; |
| 22 | |
| 23 | if (!pskb_may_pull(skb, sizeof(*th))) |
| 24 | return -EINVAL; |
| 25 | |
| 26 | ipv6h = ipv6_hdr(skb); |
| 27 | th = tcp_hdr(skb); |
| 28 | |
| 29 | th->check = 0; |
| 30 | skb->ip_summed = CHECKSUM_PARTIAL; |
| 31 | __tcp_v6_send_check(skb, &ipv6h->saddr, &ipv6h->daddr); |
| 32 | return 0; |
| 33 | } |
| 34 | |
| 35 | static struct sk_buff **tcp6_gro_receive(struct sk_buff **head, |
| 36 | struct sk_buff *skb) |
| 37 | { |
| 38 | const struct ipv6hdr *iph = skb_gro_network_header(skb); |
| 39 | __wsum wsum; |
| 40 | __sum16 sum; |
| 41 | |
Herbert Xu | cc5c00b | 2013-11-22 10:31:29 +0800 | [diff] [blame^] | 42 | /* Don't bother verifying checksum if we're going to flush anyway. */ |
| 43 | if (NAPI_GRO_CB(skb)->flush) |
| 44 | goto skip_csum; |
| 45 | |
Vlad Yasevich | 8663e02 | 2012-11-15 08:49:17 +0000 | [diff] [blame] | 46 | switch (skb->ip_summed) { |
| 47 | case CHECKSUM_COMPLETE: |
| 48 | if (!tcp_v6_check(skb_gro_len(skb), &iph->saddr, &iph->daddr, |
| 49 | skb->csum)) { |
| 50 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 51 | break; |
| 52 | } |
| 53 | flush: |
| 54 | NAPI_GRO_CB(skb)->flush = 1; |
| 55 | return NULL; |
| 56 | |
| 57 | case CHECKSUM_NONE: |
| 58 | wsum = ~csum_unfold(csum_ipv6_magic(&iph->saddr, &iph->daddr, |
| 59 | skb_gro_len(skb), |
| 60 | IPPROTO_TCP, 0)); |
| 61 | sum = csum_fold(skb_checksum(skb, |
| 62 | skb_gro_offset(skb), |
| 63 | skb_gro_len(skb), |
| 64 | wsum)); |
| 65 | if (sum) |
| 66 | goto flush; |
| 67 | |
| 68 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 69 | break; |
| 70 | } |
| 71 | |
Herbert Xu | cc5c00b | 2013-11-22 10:31:29 +0800 | [diff] [blame^] | 72 | skip_csum: |
Vlad Yasevich | 8663e02 | 2012-11-15 08:49:17 +0000 | [diff] [blame] | 73 | return tcp_gro_receive(head, skb); |
| 74 | } |
| 75 | |
| 76 | static int tcp6_gro_complete(struct sk_buff *skb) |
| 77 | { |
| 78 | const struct ipv6hdr *iph = ipv6_hdr(skb); |
| 79 | struct tcphdr *th = tcp_hdr(skb); |
| 80 | |
| 81 | th->check = ~tcp_v6_check(skb->len - skb_transport_offset(skb), |
| 82 | &iph->saddr, &iph->daddr, 0); |
| 83 | skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6; |
| 84 | |
| 85 | return tcp_gro_complete(skb); |
| 86 | } |
| 87 | |
| 88 | static const struct net_offload tcpv6_offload = { |
Vlad Yasevich | f191a1d | 2012-11-15 08:49:23 +0000 | [diff] [blame] | 89 | .callbacks = { |
| 90 | .gso_send_check = tcp_v6_gso_send_check, |
Eric Dumazet | 28be6e0 | 2013-10-18 10:36:17 -0700 | [diff] [blame] | 91 | .gso_segment = tcp_gso_segment, |
Vlad Yasevich | f191a1d | 2012-11-15 08:49:23 +0000 | [diff] [blame] | 92 | .gro_receive = tcp6_gro_receive, |
| 93 | .gro_complete = tcp6_gro_complete, |
| 94 | }, |
Vlad Yasevich | 8663e02 | 2012-11-15 08:49:17 +0000 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | int __init tcpv6_offload_init(void) |
| 98 | { |
| 99 | return inet6_add_offload(&tcpv6_offload, IPPROTO_TCP); |
| 100 | } |