2012-11-15 16:49:18 +08:00
|
|
|
/*
|
|
|
|
* IPV6 GSO/GRO offload support
|
|
|
|
* Linux INET6 implementation
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* UDPv6 GSO support
|
|
|
|
*/
|
|
|
|
#include <linux/skbuff.h>
|
2014-08-23 04:34:44 +08:00
|
|
|
#include <linux/netdevice.h>
|
2012-11-15 16:49:18 +08:00
|
|
|
#include <net/protocol.h>
|
|
|
|
#include <net/ipv6.h>
|
|
|
|
#include <net/udp.h>
|
2012-11-16 00:35:37 +08:00
|
|
|
#include <net/ip6_checksum.h>
|
2012-11-15 16:49:18 +08:00
|
|
|
#include "ip6_offload.h"
|
|
|
|
|
2017-07-07 17:30:55 +08:00
|
|
|
static struct sk_buff *udp6_tunnel_segment(struct sk_buff *skb,
|
|
|
|
netdev_features_t features)
|
2012-11-15 16:49:18 +08:00
|
|
|
{
|
|
|
|
struct sk_buff *segs = ERR_PTR(-EINVAL);
|
|
|
|
|
2014-06-05 08:20:16 +08:00
|
|
|
if (skb->encapsulation && skb_shinfo(skb)->gso_type &
|
|
|
|
(SKB_GSO_UDP_TUNNEL|SKB_GSO_UDP_TUNNEL_CSUM))
|
2014-09-30 11:22:29 +08:00
|
|
|
segs = skb_udp_tunnel_segment(skb, features, true);
|
2012-11-15 16:49:18 +08:00
|
|
|
|
|
|
|
return segs;
|
|
|
|
}
|
2014-08-23 04:34:44 +08:00
|
|
|
|
|
|
|
static struct sk_buff **udp6_gro_receive(struct sk_buff **head,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct udphdr *uh = udp_gro_udphdr(skb);
|
|
|
|
|
2014-09-01 06:12:43 +08:00
|
|
|
if (unlikely(!uh))
|
|
|
|
goto flush;
|
|
|
|
|
2014-08-23 04:34:44 +08:00
|
|
|
/* Don't bother verifying checksum if we're going to flush anyway. */
|
2014-09-11 10:23:18 +08:00
|
|
|
if (NAPI_GRO_CB(skb)->flush)
|
2014-09-01 06:12:43 +08:00
|
|
|
goto skip;
|
2014-08-23 04:34:44 +08:00
|
|
|
|
2014-09-01 06:12:43 +08:00
|
|
|
if (skb_gro_checksum_validate_zero_check(skb, IPPROTO_UDP, uh->check,
|
|
|
|
ip6_gro_compute_pseudo))
|
|
|
|
goto flush;
|
|
|
|
else if (uh->check)
|
|
|
|
skb_gro_checksum_try_convert(skb, IPPROTO_UDP, uh->check,
|
|
|
|
ip6_gro_compute_pseudo);
|
|
|
|
|
|
|
|
skip:
|
2014-10-04 06:48:08 +08:00
|
|
|
NAPI_GRO_CB(skb)->is_ipv6 = 1;
|
2016-04-05 23:22:51 +08:00
|
|
|
return udp_gro_receive(head, skb, uh, udp6_lib_lookup_skb);
|
2014-09-01 06:12:43 +08:00
|
|
|
|
|
|
|
flush:
|
|
|
|
NAPI_GRO_CB(skb)->flush = 1;
|
|
|
|
return NULL;
|
2014-08-23 04:34:44 +08:00
|
|
|
}
|
|
|
|
|
2014-09-09 23:16:17 +08:00
|
|
|
static int udp6_gro_complete(struct sk_buff *skb, int nhoff)
|
2014-08-23 04:34:44 +08:00
|
|
|
{
|
|
|
|
const struct ipv6hdr *ipv6h = ipv6_hdr(skb);
|
|
|
|
struct udphdr *uh = (struct udphdr *)(skb->data + nhoff);
|
|
|
|
|
2015-02-11 08:30:29 +08:00
|
|
|
if (uh->check) {
|
|
|
|
skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL_CSUM;
|
2014-08-23 04:34:44 +08:00
|
|
|
uh->check = ~udp_v6_check(skb->len - nhoff, &ipv6h->saddr,
|
|
|
|
&ipv6h->daddr, 0);
|
2015-02-11 08:30:29 +08:00
|
|
|
} else {
|
|
|
|
skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL;
|
|
|
|
}
|
2014-08-23 04:34:44 +08:00
|
|
|
|
2016-04-05 23:22:51 +08:00
|
|
|
return udp_gro_complete(skb, nhoff, udp6_lib_lookup_skb);
|
2014-08-23 04:34:44 +08:00
|
|
|
}
|
|
|
|
|
2012-11-15 16:49:18 +08:00
|
|
|
static const struct net_offload udpv6_offload = {
|
2012-11-15 16:49:23 +08:00
|
|
|
.callbacks = {
|
2017-07-07 17:30:55 +08:00
|
|
|
.gso_segment = udp6_tunnel_segment,
|
2014-08-23 04:34:44 +08:00
|
|
|
.gro_receive = udp6_gro_receive,
|
|
|
|
.gro_complete = udp6_gro_complete,
|
2012-11-15 16:49:23 +08:00
|
|
|
},
|
2012-11-15 16:49:18 +08:00
|
|
|
};
|
|
|
|
|
2016-04-05 23:22:51 +08:00
|
|
|
int udpv6_offload_init(void)
|
2012-11-15 16:49:18 +08:00
|
|
|
{
|
|
|
|
return inet6_add_offload(&udpv6_offload, IPPROTO_UDP);
|
|
|
|
}
|
2016-04-05 23:22:51 +08:00
|
|
|
|
|
|
|
int udpv6_offload_exit(void)
|
|
|
|
{
|
|
|
|
return inet6_del_offload(&udpv6_offload, IPPROTO_UDP);
|
|
|
|
}
|