forked from mirrors/linux
		
	flowi: Abstract out functions to get flow hash based on flowi
Create __get_hash_from_flowi6 and __get_hash_from_flowi4 to get the flow keys and hash based on flowi structures. These are called by __skb_get_hash_flowi6 and __skb_get_hash_flowi4. Also, created get_hash_from_flowi6 and get_hash_from_flowi4 which can be called when just the hash value for a flowi is needed. Signed-off-by: Tom Herbert <tom@herbertland.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
		
							parent
							
								
									bcc83839ff
								
							
						
					
					
						commit
						c6cc1ca7f4
					
				
					 4 changed files with 69 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -1030,8 +1030,12 @@ __u32 __skb_get_hash_flowi6(struct sk_buff *skb, struct flowi6 *fl6);
 | 
			
		|||
 | 
			
		||||
static inline __u32 skb_get_hash_flowi6(struct sk_buff *skb, struct flowi6 *fl6)
 | 
			
		||||
{
 | 
			
		||||
	if (!skb->l4_hash && !skb->sw_hash)
 | 
			
		||||
		__skb_get_hash_flowi6(skb, fl6);
 | 
			
		||||
	if (!skb->l4_hash && !skb->sw_hash) {
 | 
			
		||||
		struct flow_keys keys;
 | 
			
		||||
 | 
			
		||||
		__skb_set_sw_hash(skb, __get_hash_from_flowi6(fl6, &keys),
 | 
			
		||||
				  flow_keys_have_l4(&keys));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return skb->hash;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1040,8 +1044,12 @@ __u32 __skb_get_hash_flowi4(struct sk_buff *skb, struct flowi4 *fl);
 | 
			
		|||
 | 
			
		||||
static inline __u32 skb_get_hash_flowi4(struct sk_buff *skb, struct flowi4 *fl4)
 | 
			
		||||
{
 | 
			
		||||
	if (!skb->l4_hash && !skb->sw_hash)
 | 
			
		||||
		__skb_get_hash_flowi4(skb, fl4);
 | 
			
		||||
	if (!skb->l4_hash && !skb->sw_hash) {
 | 
			
		||||
		struct flow_keys keys;
 | 
			
		||||
 | 
			
		||||
		__skb_set_sw_hash(skb, __get_hash_from_flowi4(fl4, &keys),
 | 
			
		||||
				  flow_keys_have_l4(&keys));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return skb->hash;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,6 +10,7 @@
 | 
			
		|||
#include <linux/socket.h>
 | 
			
		||||
#include <linux/in6.h>
 | 
			
		||||
#include <linux/atomic.h>
 | 
			
		||||
#include <net/flow_dissector.h>
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * ifindex generation is per-net namespace, and loopback is
 | 
			
		||||
| 
						 | 
				
			
			@ -243,4 +244,22 @@ void flow_cache_flush(struct net *net);
 | 
			
		|||
void flow_cache_flush_deferred(struct net *net);
 | 
			
		||||
extern atomic_t flow_cache_genid;
 | 
			
		||||
 | 
			
		||||
__u32 __get_hash_from_flowi6(struct flowi6 *fl6, struct flow_keys *keys);
 | 
			
		||||
 | 
			
		||||
static inline __u32 get_hash_from_flowi6(struct flowi6 *fl6)
 | 
			
		||||
{
 | 
			
		||||
	struct flow_keys keys;
 | 
			
		||||
 | 
			
		||||
	return __get_hash_from_flowi6(fl6, &keys);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
__u32 __get_hash_from_flowi4(struct flowi4 *fl4, struct flow_keys *keys);
 | 
			
		||||
 | 
			
		||||
static inline __u32 get_hash_from_flowi4(struct flowi4 *fl4)
 | 
			
		||||
{
 | 
			
		||||
	struct flow_keys keys;
 | 
			
		||||
 | 
			
		||||
	return __get_hash_from_flowi4(fl4, &keys);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -172,4 +172,6 @@ static inline bool flow_keys_have_l4(struct flow_keys *keys)
 | 
			
		|||
	return (keys->ports.ports || keys->tags.flow_label);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
u32 flow_hash_from_keys(struct flow_keys *keys);
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,6 +22,7 @@
 | 
			
		|||
#include <linux/cpumask.h>
 | 
			
		||||
#include <linux/mutex.h>
 | 
			
		||||
#include <net/flow.h>
 | 
			
		||||
#include <net/flow_dissector.h>
 | 
			
		||||
#include <linux/atomic.h>
 | 
			
		||||
#include <linux/security.h>
 | 
			
		||||
#include <net/net_namespace.h>
 | 
			
		||||
| 
						 | 
				
			
			@ -509,3 +510,38 @@ void flow_cache_fini(struct net *net)
 | 
			
		|||
	fc->percpu = NULL;
 | 
			
		||||
}
 | 
			
		||||
EXPORT_SYMBOL(flow_cache_fini);
 | 
			
		||||
 | 
			
		||||
__u32 __get_hash_from_flowi6(struct flowi6 *fl6, struct flow_keys *keys)
 | 
			
		||||
{
 | 
			
		||||
	memset(keys, 0, sizeof(*keys));
 | 
			
		||||
 | 
			
		||||
	memcpy(&keys->addrs.v6addrs.src, &fl6->saddr,
 | 
			
		||||
	    sizeof(keys->addrs.v6addrs.src));
 | 
			
		||||
	memcpy(&keys->addrs.v6addrs.dst, &fl6->daddr,
 | 
			
		||||
	    sizeof(keys->addrs.v6addrs.dst));
 | 
			
		||||
	keys->control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
 | 
			
		||||
	keys->ports.src = fl6->fl6_sport;
 | 
			
		||||
	keys->ports.dst = fl6->fl6_dport;
 | 
			
		||||
	keys->keyid.keyid = fl6->fl6_gre_key;
 | 
			
		||||
	keys->tags.flow_label = (__force u32)fl6->flowlabel;
 | 
			
		||||
	keys->basic.ip_proto = fl6->flowi6_proto;
 | 
			
		||||
 | 
			
		||||
	return flow_hash_from_keys(keys);
 | 
			
		||||
}
 | 
			
		||||
EXPORT_SYMBOL(__get_hash_from_flowi6);
 | 
			
		||||
 | 
			
		||||
__u32 __get_hash_from_flowi4(struct flowi4 *fl4, struct flow_keys *keys)
 | 
			
		||||
{
 | 
			
		||||
	memset(keys, 0, sizeof(*keys));
 | 
			
		||||
 | 
			
		||||
	keys->addrs.v4addrs.src = fl4->saddr;
 | 
			
		||||
	keys->addrs.v4addrs.dst = fl4->daddr;
 | 
			
		||||
	keys->control.addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS;
 | 
			
		||||
	keys->ports.src = fl4->fl4_sport;
 | 
			
		||||
	keys->ports.dst = fl4->fl4_dport;
 | 
			
		||||
	keys->keyid.keyid = fl4->fl4_gre_key;
 | 
			
		||||
	keys->basic.ip_proto = fl4->flowi4_proto;
 | 
			
		||||
 | 
			
		||||
	return flow_hash_from_keys(keys);
 | 
			
		||||
}
 | 
			
		||||
EXPORT_SYMBOL(__get_hash_from_flowi4);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue