compat: Fix RHEL7 build.
[cascardo/ovs.git] / datapath / linux / compat / udp.c
1 #include <linux/version.h>
2
3 #ifndef HAVE_UDP_SET_CSUM
4
5 #include <net/udp.h>
6
7 /* Function to set UDP checksum for an IPv4 UDP packet. This is intended
8  * for the simple case like when setting the checksum for a UDP tunnel.
9  */
10 void udp_set_csum(bool nocheck, struct sk_buff *skb,
11                   __be32 saddr, __be32 daddr, int len)
12 {
13         struct udphdr *uh = udp_hdr(skb);
14
15         if (nocheck)
16                 uh->check = 0;
17         else if (skb_is_gso(skb))
18                 uh->check = ~udp_v4_check(len, saddr, daddr, 0);
19         else if (skb_dst(skb) && skb_dst(skb)->dev &&
20                  (skb_dst(skb)->dev->features & NETIF_F_V4_CSUM)) {
21
22                 BUG_ON(skb->ip_summed == CHECKSUM_PARTIAL);
23
24                 skb->ip_summed = CHECKSUM_PARTIAL;
25                 skb->csum_start = skb_transport_header(skb) - skb->head;
26                 skb->csum_offset = offsetof(struct udphdr, check);
27                 uh->check = ~udp_v4_check(len, saddr, daddr, 0);
28         } else {
29                 __wsum csum;
30
31                 BUG_ON(skb->ip_summed == CHECKSUM_PARTIAL);
32
33                 uh->check = 0;
34                 csum = skb_checksum(skb, 0, len, 0);
35                 uh->check = udp_v4_check(len, saddr, daddr, csum);
36                 if (uh->check == 0)
37                         uh->check = CSUM_MANGLED_0;
38
39                 skb->ip_summed = CHECKSUM_UNNECESSARY;
40         }
41 }
42
43 #endif /* Linux version < 3.16 */