diff options
author | Ilya Maximets <i.maximets@ovn.org> | 2019-12-08 18:09:53 +0100 |
---|---|---|
committer | Ilya Maximets <i.maximets@ovn.org> | 2020-01-08 16:02:37 +0100 |
commit | 7a5e0ee7cc1c8911d3b0085a066facab076647d5 (patch) | |
tree | c2755c6dfa2a932dcbb0c2137d5dd54855e90fb5 /lib/odp-util.c | |
parent | e988b8abeec9d4be94b519c5d4ed4586ff71fde0 (diff) | |
download | openvswitch-7a5e0ee7cc1c8911d3b0085a066facab076647d5.tar.gz |
dpif: Turn dpif_flow_hash function into generic odp_flow_key_hash.
Current implementation of dpif_flow_hash() doesn't depend on datapath
interface and only complicates the callers by forcing them to figure
out what is their current 'dpif'. If we'll need different hashing
for different 'dpif's we'll implement an API for dpif-providers
and each dpif implementation will be able to use their local function
directly without calling it via dpif API.
This change will allow us to not store 'dpif' pointer in the userspace
datapath implementation which is broken and will be removed in next
commits.
This patch moves dpif_flow_hash() to odp-util module and replaces
unused odp_flow_key_hash() by it, along with removing of unused 'dpif'
argument.
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'lib/odp-util.c')
-rw-r--r-- | lib/odp-util.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/odp-util.c b/lib/odp-util.c index d6cb9e62a..122572415 100644 --- a/lib/odp-util.c +++ b/lib/odp-util.c @@ -6435,11 +6435,20 @@ odp_key_to_dp_packet(const struct nlattr *key, size_t key_len, } } -uint32_t -odp_flow_key_hash(const struct nlattr *key, size_t key_len) +/* Places the hash of the 'key_len' bytes starting at 'key' into '*hash'. + * Generated value has format of random UUID. */ +void +odp_flow_key_hash(const void *key, size_t key_len, ovs_u128 *hash) { - BUILD_ASSERT_DECL(!(NLA_ALIGNTO % sizeof(uint32_t))); - return hash_bytes32(ALIGNED_CAST(const uint32_t *, key), key_len, 0); + static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; + static uint32_t secret; + + if (ovsthread_once_start(&once)) { + secret = random_uint32(); + ovsthread_once_done(&once); + } + hash_bytes128(key, key_len, secret, hash); + uuid_set_bits_v4((struct uuid *)hash); } static void |