aboutsummaryrefslogtreecommitdiffstats
path: root/net/core
diff options
context:
space:
mode:
Diffstat (limited to 'net/core')
-rw-r--r--net/core/flow_dissector.c44
1 files changed, 28 insertions, 16 deletions
diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
index c2b53c1b21d2..2ff8cd4dfc5f 100644
--- a/net/core/flow_dissector.c
+++ b/net/core/flow_dissector.c
@@ -202,6 +202,33 @@ static __always_inline u32 __flow_hash_1word(u32 a)
202 return jhash_1word(a, hashrnd); 202 return jhash_1word(a, hashrnd);
203} 203}
204 204
205static inline u32 __flow_hash_from_keys(struct flow_keys *keys)
206{
207 u32 hash;
208
209 /* get a consistent hash (same value on both flow directions) */
210 if (((__force u32)keys->dst < (__force u32)keys->src) ||
211 (((__force u32)keys->dst == (__force u32)keys->src) &&
212 ((__force u16)keys->port16[1] < (__force u16)keys->port16[0]))) {
213 swap(keys->dst, keys->src);
214 swap(keys->port16[0], keys->port16[1]);
215 }
216
217 hash = __flow_hash_3words((__force u32)keys->dst,
218 (__force u32)keys->src,
219 (__force u32)keys->ports);
220 if (!hash)
221 hash = 1;
222
223 return hash;
224}
225
226u32 flow_hash_from_keys(struct flow_keys *keys)
227{
228 return __flow_hash_from_keys(keys);
229}
230EXPORT_SYMBOL(flow_hash_from_keys);
231
205/* 232/*
206 * __skb_get_hash: calculate a flow hash based on src/dst addresses 233 * __skb_get_hash: calculate a flow hash based on src/dst addresses
207 * and src/dst port numbers. Sets hash in skb to non-zero hash value 234 * and src/dst port numbers. Sets hash in skb to non-zero hash value
@@ -211,7 +238,6 @@ static __always_inline u32 __flow_hash_1word(u32 a)
211void __skb_get_hash(struct sk_buff *skb) 238void __skb_get_hash(struct sk_buff *skb)
212{ 239{
213 struct flow_keys keys; 240 struct flow_keys keys;
214 u32 hash;
215 241
216 if (!skb_flow_dissect(skb, &keys)) 242 if (!skb_flow_dissect(skb, &keys))
217 return; 243 return;
@@ -219,21 +245,7 @@ void __skb_get_hash(struct sk_buff *skb)
219 if (keys.ports) 245 if (keys.ports)
220 skb->l4_hash = 1; 246 skb->l4_hash = 1;
221 247
222 /* get a consistent hash (same value on both flow directions) */ 248 skb->hash = __flow_hash_from_keys(&keys);
223 if (((__force u32)keys.dst < (__force u32)keys.src) ||
224 (((__force u32)keys.dst == (__force u32)keys.src) &&
225 ((__force u16)keys.port16[1] < (__force u16)keys.port16[0]))) {
226 swap(keys.dst, keys.src);
227 swap(keys.port16[0], keys.port16[1]);
228 }
229
230 hash = __flow_hash_3words((__force u32)keys.dst,
231 (__force u32)keys.src,
232 (__force u32)keys.ports);
233 if (!hash)
234 hash = 1;
235
236 skb->hash = hash;
237} 249}
238EXPORT_SYMBOL(__skb_get_hash); 250EXPORT_SYMBOL(__skb_get_hash);
239 251