compat: Fix RHEL7 build.
[cascardo/ovs.git] / datapath / linux / compat / include / net / udp.h
1 #ifndef __NET_UDP_WRAPPER_H
2 #define __NET_UDP_WRAPPER_H  1
3
4 #include <linux/version.h>
5
6 #ifdef inet_get_local_port_range
7 /* RHEL7 backports udp_flow_src_port() using an older version of
8  * inet_get_local_port_range(). */
9 #undef inet_get_local_port_range
10 #include_next <net/udp.h>
11 #define inet_get_local_port_range rpl_inet_get_local_port_range
12 #else
13 #include_next <net/udp.h>
14 #endif
15
16 #ifndef HAVE_UDP_FLOW_SRC_PORT
17 static inline __be16 rpl_udp_flow_src_port(struct net *net, struct sk_buff *skb,
18                                            int min, int max, bool use_eth)
19 {
20         u32 hash;
21
22         if (min >= max) {
23                 /* Use default range */
24                 inet_get_local_port_range(net, &min, &max);
25         }
26
27         hash = skb_get_hash(skb);
28         if (unlikely(!hash) && use_eth) {
29                 /* Can't find a normal hash, caller has indicated an Ethernet
30                  * packet so use that to compute a hash.
31                  */
32                 hash = jhash(skb->data, 2 * ETH_ALEN,
33                              (__force u32) skb->protocol);
34         }
35
36         /* Since this is being sent on the wire obfuscate hash a bit
37          * to minimize possbility that any useful information to an
38          * attacker is leaked. Only upper 16 bits are relevant in the
39          * computation for 16 bit port value.
40          */
41         hash ^= hash << 16;
42
43         return htons((((u64) hash * (max - min)) >> 32) + min);
44 }
45
46 #define udp_flow_src_port rpl_udp_flow_src_port
47 #endif
48
49 #ifndef HAVE_UDP_V4_CHECK
50 static inline __sum16 udp_v4_check(int len, __be32 saddr,
51                                    __be32 daddr, __wsum base)
52 {
53         return csum_tcpudp_magic(saddr, daddr, len, IPPROTO_UDP, base);
54 }
55 #endif
56
57 #ifndef HAVE_UDP_SET_CSUM
58 void udp_set_csum(bool nocheck, struct sk_buff *skb,
59                   __be32 saddr, __be32 daddr, int len);
60 #endif
61
62 #endif