X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fflow.c;h=093dec8407c8141b574d3329719a70aba5492229;hb=28c5588e8e1a8d091c5d2275232c35f2968a97fa;hp=c6e5e070f28ae547c90cd43052c27989e2e914ad;hpb=b7807e4f64c8c64bb6000767de72368306a95c90;p=sliver-openvswitch.git diff --git a/lib/flow.c b/lib/flow.c index c6e5e070f..093dec840 100644 --- a/lib/flow.c +++ b/lib/flow.c @@ -943,10 +943,38 @@ flow_wildcards_set_reg_mask(struct flow_wildcards *wc, int idx, uint32_t mask) wc->masks.regs[idx] = mask; } +/* Calculates the 5-tuple hash from the given flow. */ +uint32_t +miniflow_hash_5tuple(const struct miniflow *flow, uint32_t basis) +{ + uint32_t hash = 0; + + if (!flow) { + return 0; + } + + hash = mhash_add(basis, + miniflow_get_u32(flow, offsetof(struct flow, nw_src))); + hash = mhash_add(hash, + miniflow_get_u32(flow, offsetof(struct flow, nw_dst))); + hash = mhash_add(hash, + miniflow_get_u32(flow, offsetof(struct flow, tp_src))); + hash = mhash_add(hash, + miniflow_get_u8(flow, offsetof(struct flow, nw_proto))); + + return mhash_finish(hash, 13); +} + +BUILD_ASSERT_DECL(offsetof(struct flow, tp_src) + 2 + == offsetof(struct flow, tp_dst) && + offsetof(struct flow, tp_src) / 4 + == offsetof(struct flow, tp_dst) / 4); + /* Calculates the 5-tuple hash from the given flow. */ uint32_t flow_hash_5tuple(const struct flow *flow, uint32_t basis) { + const uint32_t *flow_u32 = (const uint32_t *)flow; uint32_t hash = 0; if (!flow) { @@ -955,8 +983,7 @@ flow_hash_5tuple(const struct flow *flow, uint32_t basis) hash = mhash_add(basis, (OVS_FORCE uint32_t) flow->nw_src); hash = mhash_add(hash, (OVS_FORCE uint32_t) flow->nw_dst); - hash = mhash_add(hash, ((OVS_FORCE uint32_t) flow->tp_src << 16) - | (OVS_FORCE uint32_t) flow->tp_dst); + hash = mhash_add(hash, flow_u32[offsetof(struct flow, tp_src) / 4]); hash = mhash_add(hash, flow->nw_proto); return mhash_finish(hash, 13); @@ -1813,13 +1840,11 @@ miniflow_hash_in_minimask(const struct miniflow *flow, const struct minimask *mask, uint32_t basis) { const uint32_t *p = mask->masks.values; - uint32_t hash; - uint64_t map; - - hash = basis; + uint32_t hash = basis; + uint32_t flow_u32; - for (map = mask->masks.map; map; map = zero_rightmost_1bit(map)) { - hash = mhash_add(hash, miniflow_get(flow, raw_ctz(map)) & *p++); + MINIFLOW_FOR_EACH_IN_MAP(flow_u32, flow, mask->masks.map) { + hash = mhash_add(hash, flow_u32 & *p++); } return mhash_finish(hash, (p - mask->masks.values) * 4);