tcpv6_offload.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * IPV6 GSO/GRO offload support
  4. * Linux INET6 implementation
  5. *
  6. * TCPv6 GSO/GRO support
  7. */
  8. #include <linux/indirect_call_wrapper.h>
  9. #include <linux/skbuff.h>
  10. #include <net/gro.h>
  11. #include <net/protocol.h>
  12. #include <net/tcp.h>
  13. #include <net/ip6_checksum.h>
  14. #include "ip6_offload.h"
  15. INDIRECT_CALLABLE_SCOPE
  16. struct sk_buff *tcp6_gro_receive(struct list_head *head, struct sk_buff *skb)
  17. {
  18. /* Don't bother verifying checksum if we're going to flush anyway. */
  19. if (!NAPI_GRO_CB(skb)->flush &&
  20. skb_gro_checksum_validate(skb, IPPROTO_TCP,
  21. ip6_gro_compute_pseudo)) {
  22. NAPI_GRO_CB(skb)->flush = 1;
  23. return NULL;
  24. }
  25. return tcp_gro_receive(head, skb);
  26. }
  27. INDIRECT_CALLABLE_SCOPE int tcp6_gro_complete(struct sk_buff *skb, int thoff)
  28. {
  29. const struct ipv6hdr *iph = ipv6_hdr(skb);
  30. struct tcphdr *th = tcp_hdr(skb);
  31. th->check = ~tcp_v6_check(skb->len - thoff, &iph->saddr,
  32. &iph->daddr, 0);
  33. skb_shinfo(skb)->gso_type |= SKB_GSO_TCPV6;
  34. return tcp_gro_complete(skb);
  35. }
  36. static struct sk_buff *tcp6_gso_segment(struct sk_buff *skb,
  37. netdev_features_t features)
  38. {
  39. struct tcphdr *th;
  40. if (!(skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6))
  41. return ERR_PTR(-EINVAL);
  42. if (!pskb_may_pull(skb, sizeof(*th)))
  43. return ERR_PTR(-EINVAL);
  44. if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) {
  45. const struct ipv6hdr *ipv6h = ipv6_hdr(skb);
  46. struct tcphdr *th = tcp_hdr(skb);
  47. /* Set up pseudo header, usually expect stack to have done
  48. * this.
  49. */
  50. th->check = 0;
  51. skb->ip_summed = CHECKSUM_PARTIAL;
  52. __tcp_v6_send_check(skb, &ipv6h->saddr, &ipv6h->daddr);
  53. }
  54. return tcp_gso_segment(skb, features);
  55. }
  56. static const struct net_offload tcpv6_offload = {
  57. .callbacks = {
  58. .gso_segment = tcp6_gso_segment,
  59. .gro_receive = tcp6_gro_receive,
  60. .gro_complete = tcp6_gro_complete,
  61. },
  62. };
  63. int __init tcpv6_offload_init(void)
  64. {
  65. return inet6_add_offload(&tcpv6_offload, IPPROTO_TCP);
  66. }