X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fflow.c;h=093dec8407c8141b574d3329719a70aba5492229;hb=c5cf10598f8c9f4428291e9df3ecd72a05fb1ccf;hp=8319dde94ddafadc52b8ea19cd7781a20486e8b6;hpb=2abf78ff5562b9550558c52b2a16431de71a3378;p=sliver-openvswitch.git diff --git a/lib/flow.c b/lib/flow.c index 8319dde94..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);