Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[platform/kernel/linux-rpi.git] / net / ipv6 / udp_offload.c
1 /*
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>
13 #include <linux/netdevice.h>
14 #include <net/protocol.h>
15 #include <net/ipv6.h>
16 #include <net/udp.h>
17 #include <net/ip6_checksum.h>
18 #include "ip6_offload.h"
19
20 static struct sk_buff *udp6_tunnel_segment(struct sk_buff *skb,
21                                            netdev_features_t features)
22 {
23         struct sk_buff *segs = ERR_PTR(-EINVAL);
24
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);
28
29         return segs;
30 }
31
32 static 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
37         if (unlikely(!uh))
38                 goto flush;
39
40         /* Don't bother verifying checksum if we're going to flush anyway. */
41         if (NAPI_GRO_CB(skb)->flush)
42                 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
51 skip:
52         NAPI_GRO_CB(skb)->is_ipv6 = 1;
53         return udp_gro_receive(head, skb, uh, udp6_lib_lookup_skb);
54
55 flush:
56         NAPI_GRO_CB(skb)->flush = 1;
57         return NULL;
58 }
59
60 static int udp6_gro_complete(struct sk_buff *skb, int nhoff)
61 {
62         const struct ipv6hdr *ipv6h = ipv6_hdr(skb);
63         struct udphdr *uh = (struct udphdr *)(skb->data + nhoff);
64
65         if (uh->check) {
66                 skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL_CSUM;
67                 uh->check = ~udp_v6_check(skb->len - nhoff, &ipv6h->saddr,
68                                           &ipv6h->daddr, 0);
69         } else {
70                 skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL;
71         }
72
73         return udp_gro_complete(skb, nhoff, udp6_lib_lookup_skb);
74 }
75
76 static const struct net_offload udpv6_offload = {
77         .callbacks = {
78                 .gso_segment    =       udp6_tunnel_segment,
79                 .gro_receive    =       udp6_gro_receive,
80                 .gro_complete   =       udp6_gro_complete,
81         },
82 };
83
84 int udpv6_offload_init(void)
85 {
86         return inet6_add_offload(&udpv6_offload, IPPROTO_UDP);
87 }
88
89 int udpv6_offload_exit(void)
90 {
91         return inet6_del_offload(&udpv6_offload, IPPROTO_UDP);
92 }