f1841d4a24d030978e6ea471b901c04aa263a6ed
[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 #include_next <net/udp.h>
6
7 #ifndef HAVE_UDP_FLOW_SRC_PORT
8 static inline __be16 udp_flow_src_port(struct net *net, struct sk_buff *skb,
9                                        int min, int max, bool use_eth)
10 {
11         u32 hash;
12
13         if (min >= max) {
14                 /* Use default range */
15                 inet_get_local_port_range(net, &min, &max);
16         }
17
18         hash = skb_get_hash(skb);
19         if (unlikely(!hash) && use_eth) {
20                 /* Can't find a normal hash, caller has indicated an Ethernet
21                  * packet so use that to compute a hash.
22                  */
23                 hash = jhash(skb->data, 2 * ETH_ALEN,
24                              (__force u32) skb->protocol);
25         }
26
27         /* Since this is being sent on the wire obfuscate hash a bit
28          * to minimize possbility that any useful information to an
29          * attacker is leaked. Only upper 16 bits are relevant in the
30          * computation for 16 bit port value.
31          */
32         hash ^= hash << 16;
33
34         return htons((((u64) hash * (max - min)) >> 32) + min);
35 }
36 #endif
37
38 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,16,0)
39 static inline __sum16 udp_v4_check(int len, __be32 saddr,
40                                    __be32 daddr, __wsum base)
41 {
42         return csum_tcpudp_magic(saddr, daddr, len, IPPROTO_UDP, base);
43 }
44
45 void udp_set_csum(bool nocheck, struct sk_buff *skb,
46                   __be32 saddr, __be32 daddr, int len);
47 #endif
48
49 #endif