mirror of
https://github.com/fail0verflow/switch-linux.git
synced 2025-05-04 02:34:21 -04:00
udp: In udp_flow_src_port use random hash value if skb_get_hash fails
In the unlikely event that skb_get_hash is unable to deduce a hash in udp_flow_src_port we use a consistent random value instead. This is specified in GRE/UDP draft section 3.2.1: https://tools.ietf.org/html/draft-ietf-tsvwg-gre-in-udp-encap-04 Signed-off-by: Tom Herbert <therbert@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
fed0a159c8
commit
723b8e460d
2 changed files with 25 additions and 6 deletions
|
@ -194,6 +194,8 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
|
||||||
int (*)(const struct sock *, const struct sock *),
|
int (*)(const struct sock *, const struct sock *),
|
||||||
unsigned int hash2_nulladdr);
|
unsigned int hash2_nulladdr);
|
||||||
|
|
||||||
|
u32 udp_flow_hashrnd(void);
|
||||||
|
|
||||||
static inline __be16 udp_flow_src_port(struct net *net, struct sk_buff *skb,
|
static inline __be16 udp_flow_src_port(struct net *net, struct sk_buff *skb,
|
||||||
int min, int max, bool use_eth)
|
int min, int max, bool use_eth)
|
||||||
{
|
{
|
||||||
|
@ -205,12 +207,19 @@ static inline __be16 udp_flow_src_port(struct net *net, struct sk_buff *skb,
|
||||||
}
|
}
|
||||||
|
|
||||||
hash = skb_get_hash(skb);
|
hash = skb_get_hash(skb);
|
||||||
if (unlikely(!hash) && use_eth) {
|
if (unlikely(!hash)) {
|
||||||
/* Can't find a normal hash, caller has indicated an Ethernet
|
if (use_eth) {
|
||||||
* packet so use that to compute a hash.
|
/* Can't find a normal hash, caller has indicated an
|
||||||
*/
|
* Ethernet packet so use that to compute a hash.
|
||||||
hash = jhash(skb->data, 2 * ETH_ALEN,
|
*/
|
||||||
(__force u32) skb->protocol);
|
hash = jhash(skb->data, 2 * ETH_ALEN,
|
||||||
|
(__force u32) skb->protocol);
|
||||||
|
} else {
|
||||||
|
/* Can't derive any sort of hash for the packet, set
|
||||||
|
* to some consistent random value.
|
||||||
|
*/
|
||||||
|
hash = udp_flow_hashrnd();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Since this is being sent on the wire obfuscate hash a bit
|
/* Since this is being sent on the wire obfuscate hash a bit
|
||||||
|
|
|
@ -2525,6 +2525,16 @@ void __init udp_table_init(struct udp_table *table, const char *name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u32 udp_flow_hashrnd(void)
|
||||||
|
{
|
||||||
|
static u32 hashrnd __read_mostly;
|
||||||
|
|
||||||
|
net_get_random_once(&hashrnd, sizeof(hashrnd));
|
||||||
|
|
||||||
|
return hashrnd;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(udp_flow_hashrnd);
|
||||||
|
|
||||||
void __init udp_init(void)
|
void __init udp_init(void)
|
||||||
{
|
{
|
||||||
unsigned long limit;
|
unsigned long limit;
|
||||||
|
|
Loading…
Add table
Reference in a new issue