This patch sacrifices a few bits of hash quality from the 128-bit unique flow identifiers to make the UFIDs RFC4122-conformant as per the version 4 (random) UUID spec. Given that the 128-bit space is already quite large, this should not affect the spread of UFIDs in any meaningful way for hashing.
Signed-off-by: Joe Stringer <joestrin...@nicira.com> --- This is independent of the recent series "odp-util: Reuse UUID marshalling for UFID.", but may make more sense in the context of the discussion on that patch. --- lib/dpif.c | 2 ++ lib/uuid.c | 6 ++++++ lib/uuid.h | 1 + 3 files changed, 9 insertions(+) diff --git a/lib/dpif.c b/lib/dpif.c index b2f973c..783a715 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -46,6 +46,7 @@ #include "tnl-arp-cache.h" #include "tnl-ports.h" #include "util.h" +#include "uuid.h" #include "valgrind.h" #include "openvswitch/vlog.h" @@ -852,6 +853,7 @@ dpif_flow_hash(const struct dpif *dpif OVS_UNUSED, ovsthread_once_done(&once); } hash_bytes128(key, key_len, secret, hash); + uuid_set_bits_v4((struct uuid *)hash); } /* Deletes all flows from 'dpif'. Returns 0 if successful, otherwise a diff --git a/lib/uuid.c b/lib/uuid.c index df1206e..0f2a58e 100644 --- a/lib/uuid.c +++ b/lib/uuid.c @@ -98,6 +98,12 @@ uuid_generate(struct uuid *uuid) /* AES output is exactly 16 bytes, so we encrypt directly into 'uuid'. */ aes128_encrypt(&key, copy, uuid); + uuid_set_bits_v4(uuid); +} + +void +uuid_set_bits_v4(struct uuid *uuid) +{ /* Set bits to indicate a random UUID. See RFC 4122 section 4.4. */ uuid->parts[2] &= ~0xc0000000; uuid->parts[2] |= 0x80000000; diff --git a/lib/uuid.h b/lib/uuid.h index 37e01d0..8c6f2f1 100644 --- a/lib/uuid.h +++ b/lib/uuid.h @@ -78,5 +78,6 @@ bool uuid_is_zero(const struct uuid *); int uuid_compare_3way(const struct uuid *, const struct uuid *); bool uuid_from_string(struct uuid *, const char *); bool uuid_from_string_prefix(struct uuid *, const char *); +void uuid_set_bits_v4(struct uuid *); #endif /* uuid.h */ -- 2.1.4 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev