1 #ifndef __NET_UDP_WRAPPER_H
2 #define __NET_UDP_WRAPPER_H 1
4 #include <linux/version.h>
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
13 #include_next <net/udp.h>
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)
23 /* Use default range */
24 inet_get_local_port_range(net, &min, &max);
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.
32 hash = jhash(skb->data, 2 * ETH_ALEN,
33 (__force u32) skb->protocol);
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.
43 return htons((((u64) hash * (max - min)) >> 32) + min);
46 #define udp_flow_src_port rpl_udp_flow_src_port
49 #ifndef HAVE_UDP_V4_CHECK
50 static inline __sum16 udp_v4_check(int len, __be32 saddr,
51 __be32 daddr, __wsum base)
53 return csum_tcpudp_magic(saddr, daddr, len, IPPROTO_UDP, base);
57 #ifndef HAVE_UDP_SET_CSUM
58 void udp_set_csum(bool nocheck, struct sk_buff *skb,
59 __be32 saddr, __be32 daddr, int len);