blob: 455fd4e39333233289e9a844de512f200119ff1a [file] [log] [blame]
Vlad Yasevich5edbb072012-11-15 08:49:18 +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 * UDPv6 GSO support
11 */
12#include <linux/skbuff.h>
Tom Herbert57c67ff2014-08-22 13:34:44 -070013#include <linux/netdevice.h>
Vlad Yasevich5edbb072012-11-15 08:49:18 +000014#include <net/protocol.h>
15#include <net/ipv6.h>
16#include <net/udp.h>
Vlad Yasevichd4d0d352012-11-15 16:35:37 +000017#include <net/ip6_checksum.h>
Vlad Yasevich5edbb072012-11-15 08:49:18 +000018#include "ip6_offload.h"
19
David S. Miller6800b2e2017-07-07 10:30:55 +010020static struct sk_buff *udp6_tunnel_segment(struct sk_buff *skb,
21 netdev_features_t features)
Vlad Yasevich5edbb072012-11-15 08:49:18 +000022{
23 struct sk_buff *segs = ERR_PTR(-EINVAL);
Vlad Yasevich5edbb072012-11-15 08:49:18 +000024
Tom Herbert0f4f4ff2014-06-04 17:20:16 -070025 if (skb->encapsulation && skb_shinfo(skb)->gso_type &
26 (SKB_GSO_UDP_TUNNEL|SKB_GSO_UDP_TUNNEL_CSUM))
Tom Herbert8bce6d72014-09-29 20:22:29 -070027 segs = skb_udp_tunnel_segment(skb, features, true);
Tom Herbertf71470b2014-09-20 14:52:29 -070028
Vlad Yasevich5edbb072012-11-15 08:49:18 +000029 return segs;
30}
Tom Herbert57c67ff2014-08-22 13:34:44 -070031
32static struct sk_buff **udp6_gro_receive(struct sk_buff **head,
33 struct sk_buff *skb)
34{
35 struct udphdr *uh = udp_gro_udphdr(skb);
36
Tom Herbert2abb7cd2014-08-31 15:12:43 -070037 if (unlikely(!uh))
38 goto flush;
Tom Herbert57c67ff2014-08-22 13:34:44 -070039
Tom Herbert2abb7cd2014-08-31 15:12:43 -070040 /* Don't bother verifying checksum if we're going to flush anyway. */
Scott Wood2d8f7e22014-09-10 21:23:18 -050041 if (NAPI_GRO_CB(skb)->flush)
Tom Herbert2abb7cd2014-08-31 15:12:43 -070042 goto skip;
43
44 if (skb_gro_checksum_validate_zero_check(skb, IPPROTO_UDP, uh->check,
45 ip6_gro_compute_pseudo))
46 goto flush;
47 else if (uh->check)
48 skb_gro_checksum_try_convert(skb, IPPROTO_UDP, uh->check,
49 ip6_gro_compute_pseudo);
50
51skip:
Tom Herbertefc98d02014-10-03 15:48:08 -070052 NAPI_GRO_CB(skb)->is_ipv6 = 1;
Tom Herberta6024562016-04-05 08:22:51 -070053 return udp_gro_receive(head, skb, uh, udp6_lib_lookup_skb);
Tom Herbert2abb7cd2014-08-31 15:12:43 -070054
55flush:
56 NAPI_GRO_CB(skb)->flush = 1;
57 return NULL;
Tom Herbert57c67ff2014-08-22 13:34:44 -070058}
59
Eric Dumazetcc9c6682014-09-09 08:16:17 -070060static int udp6_gro_complete(struct sk_buff *skb, int nhoff)
Tom Herbert57c67ff2014-08-22 13:34:44 -070061{
62 const struct ipv6hdr *ipv6h = ipv6_hdr(skb);
63 struct udphdr *uh = (struct udphdr *)(skb->data + nhoff);
64
Tom Herbert6db93ea2015-02-10 16:30:29 -080065 if (uh->check) {
66 skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL_CSUM;
Tom Herbert57c67ff2014-08-22 13:34:44 -070067 uh->check = ~udp_v6_check(skb->len - nhoff, &ipv6h->saddr,
68 &ipv6h->daddr, 0);
Tom Herbert6db93ea2015-02-10 16:30:29 -080069 } else {
70 skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL;
71 }
Tom Herbert57c67ff2014-08-22 13:34:44 -070072
Tom Herberta6024562016-04-05 08:22:51 -070073 return udp_gro_complete(skb, nhoff, udp6_lib_lookup_skb);
Tom Herbert57c67ff2014-08-22 13:34:44 -070074}
75
Vlad Yasevich5edbb072012-11-15 08:49:18 +000076static const struct net_offload udpv6_offload = {
Vlad Yasevichf191a1d2012-11-15 08:49:23 +000077 .callbacks = {
David S. Miller6800b2e2017-07-07 10:30:55 +010078 .gso_segment = udp6_tunnel_segment,
Tom Herbert57c67ff2014-08-22 13:34:44 -070079 .gro_receive = udp6_gro_receive,
80 .gro_complete = udp6_gro_complete,
Vlad Yasevichf191a1d2012-11-15 08:49:23 +000081 },
Vlad Yasevich5edbb072012-11-15 08:49:18 +000082};
83
Tom Herberta6024562016-04-05 08:22:51 -070084int udpv6_offload_init(void)
Vlad Yasevich5edbb072012-11-15 08:49:18 +000085{
86 return inet6_add_offload(&udpv6_offload, IPPROTO_UDP);
87}
Tom Herberta6024562016-04-05 08:22:51 -070088
89int udpv6_offload_exit(void)
90{
91 return inet6_del_offload(&udpv6_offload, IPPROTO_UDP);
92}