tcpv6_offload.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. static struct sk_buff **tcp6_gro_receive(struct sk_buff **head,
  18. struct sk_buff *skb)
  19. {
  20. /* Don't bother verifying checksum if we're going to flush anyway. */
  21. if (!NAPI_GRO_CB(skb)->flush &&
  22. skb_gro_checksum_validate(skb, IPPROTO_TCP,
  23. ip6_gro_compute_pseudo)) {
  24. NAPI_GRO_CB(skb)->flush = 1;
  25. return NULL;
  26. }
  27. return tcp_gro_receive(head, skb);
  28. }
  29. static int tcp6_gro_complete(struct sk_buff *skb, int thoff)
  30. {
  31. const struct ipv6hdr *iph = ipv6_hdr(skb);
  32. struct tcphdr *th = tcp_hdr(skb);
  33. th->check = ~tcp_v6_check(skb->len - thoff, &iph->saddr,
  34. &iph->daddr, 0);
  35. skb_shinfo(skb)->gso_type |= SKB_GSO_TCPV6;
  36. return tcp_gro_complete(skb);
  37. }
  38. static struct sk_buff *tcp6_gso_segment(struct sk_buff *skb,
  39. netdev_features_t features)
  40. {
  41. struct tcphdr *th;
  42. if (!(skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6))
  43. return ERR_PTR(-EINVAL);
  44. if (!pskb_may_pull(skb, sizeof(*th)))
  45. return ERR_PTR(-EINVAL);
  46. if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) {
  47. const struct ipv6hdr *ipv6h = ipv6_hdr(skb);
  48. struct tcphdr *th = tcp_hdr(skb);
  49. /* Set up pseudo header, usually expect stack to have done
  50. * this.
  51. */
  52. th->check = 0;
  53. skb->ip_summed = CHECKSUM_PARTIAL;
  54. __tcp_v6_send_check(skb, &ipv6h->saddr, &ipv6h->daddr);
  55. }
  56. return tcp_gso_segment(skb, features);
  57. }
  58. static const struct net_offload tcpv6_offload = {
  59. .callbacks = {
  60. .gso_segment = tcp6_gso_segment,
  61. .gro_receive = tcp6_gro_receive,
  62. .gro_complete = tcp6_gro_complete,
  63. },
  64. };
  65. int __init tcpv6_offload_init(void)
  66. {
  67. return inet6_add_offload(&tcpv6_offload, IPPROTO_TCP);
  68. }