2 * IPV6 GSO/GRO offload support
3 * Linux INET6 implementation
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.
12 #include <linux/skbuff.h>
13 #include <linux/netdevice.h>
14 #include <net/protocol.h>
17 #include <net/ip6_checksum.h>
18 #include "ip6_offload.h"
20 static struct sk_buff *udp6_tunnel_segment(struct sk_buff *skb,
21 netdev_features_t features)
23 struct sk_buff *segs = ERR_PTR(-EINVAL);
25 if (skb->encapsulation && skb_shinfo(skb)->gso_type &
26 (SKB_GSO_UDP_TUNNEL|SKB_GSO_UDP_TUNNEL_CSUM))
27 segs = skb_udp_tunnel_segment(skb, features, true);
32 static struct sk_buff **udp6_gro_receive(struct sk_buff **head,
35 struct udphdr *uh = udp_gro_udphdr(skb);
40 /* Don't bother verifying checksum if we're going to flush anyway. */
41 if (NAPI_GRO_CB(skb)->flush)
44 if (skb_gro_checksum_validate_zero_check(skb, IPPROTO_UDP, uh->check,
45 ip6_gro_compute_pseudo))
48 skb_gro_checksum_try_convert(skb, IPPROTO_UDP, uh->check,
49 ip6_gro_compute_pseudo);
52 NAPI_GRO_CB(skb)->is_ipv6 = 1;
53 return udp_gro_receive(head, skb, uh, udp6_lib_lookup_skb);
56 NAPI_GRO_CB(skb)->flush = 1;
60 static int udp6_gro_complete(struct sk_buff *skb, int nhoff)
62 const struct ipv6hdr *ipv6h = ipv6_hdr(skb);
63 struct udphdr *uh = (struct udphdr *)(skb->data + nhoff);
66 skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL_CSUM;
67 uh->check = ~udp_v6_check(skb->len - nhoff, &ipv6h->saddr,
70 skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL;
73 return udp_gro_complete(skb, nhoff, udp6_lib_lookup_skb);
76 static const struct net_offload udpv6_offload = {
78 .gso_segment = udp6_tunnel_segment,
79 .gro_receive = udp6_gro_receive,
80 .gro_complete = udp6_gro_complete,
84 int udpv6_offload_init(void)
86 return inet6_add_offload(&udpv6_offload, IPPROTO_UDP);
89 int udpv6_offload_exit(void)
91 return inet6_del_offload(&udpv6_offload, IPPROTO_UDP);