blob: dbb3d9262bf66837a10e6ecc764dbcd0ea327264 [file] [log] [blame]
Vlad Yasevich8663e022012-11-15 08:49:17 +00001/*
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
18static 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
35static struct sk_buff **tcp6_gro_receive(struct sk_buff **head,
36 struct sk_buff *skb)
37{
Herbert Xucc5c00b2013-11-22 10:31:29 +080038 /* Don't bother verifying checksum if we're going to flush anyway. */
Tom Herbert149d0772014-08-22 13:34:30 -070039 if (!NAPI_GRO_CB(skb)->flush &&
40 skb_gro_checksum_validate(skb, IPPROTO_TCP,
41 ip6_gro_compute_pseudo)) {
Vlad Yasevich8663e022012-11-15 08:49:17 +000042 NAPI_GRO_CB(skb)->flush = 1;
43 return NULL;
Vlad Yasevich8663e022012-11-15 08:49:17 +000044 }
45
46 return tcp_gro_receive(head, skb);
47}
48
Jerry Chu299603e82013-12-11 20:53:45 -080049static int tcp6_gro_complete(struct sk_buff *skb, int thoff)
Vlad Yasevich8663e022012-11-15 08:49:17 +000050{
51 const struct ipv6hdr *iph = ipv6_hdr(skb);
52 struct tcphdr *th = tcp_hdr(skb);
53
Jerry Chu299603e82013-12-11 20:53:45 -080054 th->check = ~tcp_v6_check(skb->len - thoff, &iph->saddr,
55 &iph->daddr, 0);
Jerry Chuc3caf112014-07-14 15:54:46 -070056 skb_shinfo(skb)->gso_type |= SKB_GSO_TCPV6;
Vlad Yasevich8663e022012-11-15 08:49:17 +000057
58 return tcp_gro_complete(skb);
59}
60
61static const struct net_offload tcpv6_offload = {
Vlad Yasevichf191a1d2012-11-15 08:49:23 +000062 .callbacks = {
63 .gso_send_check = tcp_v6_gso_send_check,
Eric Dumazet28be6e02013-10-18 10:36:17 -070064 .gso_segment = tcp_gso_segment,
Vlad Yasevichf191a1d2012-11-15 08:49:23 +000065 .gro_receive = tcp6_gro_receive,
66 .gro_complete = tcp6_gro_complete,
67 },
Vlad Yasevich8663e022012-11-15 08:49:17 +000068};
69
70int __init tcpv6_offload_init(void)
71{
72 return inet6_add_offload(&tcpv6_offload, IPPROTO_TCP);
73}