/*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
static inline size_t
flow_hash(const struct flow *flow, uint32_t basis)
{
- return hash_words64((const uint64_t *)flow,
- sizeof *flow / sizeof(uint64_t), basis);
+ return hash_bytes64((const uint64_t *)flow, sizeof *flow, basis);
}
static inline uint16_t
/*
- * Copyright (c) 2008, 2009, 2010, 2012, 2013, 2014 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2012, 2013, 2014, 2016 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
}
#endif
+static inline uint32_t
+hash_bytes32(const uint32_t p[], size_t n_bytes, uint32_t basis)
+{
+ return hash_words(p, n_bytes / 4, basis);
+}
+
+static inline uint32_t
+hash_bytes64(const uint64_t p[], size_t n_bytes, uint32_t basis)
+{
+ return hash_words64(p, n_bytes / 8, basis);
+}
+
static inline uint32_t hash_string(const char *s, uint32_t basis)
{
return hash_bytes(s, strlen(s), basis);
/*
- * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
odp_flow_key_hash(const struct nlattr *key, size_t key_len)
{
BUILD_ASSERT_DECL(!(NLA_ALIGNTO % sizeof(uint32_t)));
- return hash_words(ALIGNED_CAST(const uint32_t *, key),
- key_len / sizeof(uint32_t), 0);
+ return hash_bytes32(ALIGNED_CAST(const uint32_t *, key), key_len, 0);
}
static void
/*
- * Copyright (c) 2012, 2013, 2014, 2015 Nicira, Inc.
+ * Copyright (c) 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
static uint32_t
ofphdrs_hash(const struct ofphdrs *hdrs)
{
- BUILD_ASSERT_DECL(sizeof *hdrs == 12);
- return hash_words((const uint32_t *) hdrs, 3, 0);
+ BUILD_ASSERT_DECL(sizeof *hdrs % 4 == 0);
+ return hash_bytes32((const uint32_t *) hdrs, sizeof *hdrs, 0);
}
static bool
if (flow_tnl_dst_is_set(state->metadata.tunnel)) {
/* We may leave remainder bytes unhashed, but that is unlikely as
* the tunnel is not in the datapath format. */
- hash = hash_words64((const uint64_t *) state->metadata.tunnel,
- flow_tnl_size(state->metadata.tunnel)
- / sizeof(uint64_t), hash);
+ hash = hash_bytes64((const uint64_t *) state->metadata.tunnel,
+ flow_tnl_size(state->metadata.tunnel), hash);
}
hash = hash_boolean(state->conntracked, hash);
- hash = hash_words64((const uint64_t *) &state->metadata.metadata,
- (sizeof state->metadata - sizeof state->metadata.tunnel)
- / sizeof(uint64_t),
+ hash = hash_bytes64((const uint64_t *) &state->metadata.metadata,
+ sizeof state->metadata - sizeof state->metadata.tunnel,
hash);
if (state->stack && state->stack->size != 0) {
- hash = hash_words64((const uint64_t *) state->stack->data,
- state->stack->size / sizeof(uint64_t), hash);
+ hash = hash_bytes64((const uint64_t *) state->stack->data,
+ state->stack->size, hash);
}
hash = hash_int(state->mirrors, hash);
hash = hash_int(state->action_set_len, hash);
if (state->ofpacts_len) {
- hash = hash_words64(ALIGNED_CAST(const uint64_t *, state->ofpacts),
- state->ofpacts_len / sizeof(uint64_t),
- hash);
+ hash = hash_bytes64(ALIGNED_CAST(const uint64_t *, state->ofpacts),
+ state->ofpacts_len, hash);
}
return hash;
}