Skip to content

Commit

Permalink
dpif: Always generate RFC4122 UUIDs for UFID.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
joestringer committed Jun 10, 2015
1 parent 19ba142 commit 78145f6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/dpif.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions lib/uuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions lib/uuid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit 78145f6

Please sign in to comment.