tcpv6_offload.c 1.9 KB

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