1 #ifndef __NET_UDP_WRAPPER_H
2 #define __NET_UDP_WRAPPER_H 1
4 #include <linux/version.h>
5 #include_next <net/udp.h>
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)
14 /* Use default range */
15 inet_get_local_port_range(net, &min, &max);
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.
23 hash = jhash(skb->data, 2 * ETH_ALEN,
24 (__force u32) skb->protocol);
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.
34 return htons((((u64) hash * (max - min)) >> 32) + min);
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)
42 return csum_tcpudp_magic(saddr, daddr, len, IPPROTO_UDP, base);
45 void udp_set_csum(bool nocheck, struct sk_buff *skb,
46 __be32 saddr, __be32 daddr, int len);