Commit 2f56de74 authored by Thomas Haller's avatar Thomas Haller

all: add helper functions for nm_hash_update*()

By using a macro, we don't cast all the types to guint. Instead,
we use their native types directly. Hence, we don't need
nm_hash_update_uint64() nor nm_hash_update_ptr().
Also, for types smaller then guint like char, we save hashing
the all zero bytes.
parent ee76b097
......@@ -4006,7 +4006,7 @@ guint
_nm_utils_strstrdictkey_hash (gconstpointer a)
{
const NMUtilsStrStrDictKey *k = a;
const signed char *p;
const char *p;
NMHashState h;
nm_hash_init (&h, 76642997u);
......@@ -4014,17 +4014,18 @@ _nm_utils_strstrdictkey_hash (gconstpointer a)
if (((int) k->type) & ~STRSTRDICTKEY_ALL_SET)
g_return_val_if_reached (0);
nm_hash_update_uint (&h, k->type);
nm_hash_update_val (&h, k->type);
if (k->type & STRSTRDICTKEY_ALL_SET) {
p = (void *) k->data;
for (; *p != '\0'; p++)
nm_hash_update_uint (&h, *p);
gsize n;
n = 0;
p = strchr (k->data, '\0');
if (k->type == STRSTRDICTKEY_ALL_SET) {
/* the key contains two strings. Continue... */
nm_hash_update_uint (&h, '\0');
for (p++; *p != '\0'; p++)
nm_hash_update_uint (&h, *p);
p = strchr (p + 1, '\0');
}
if (p != k->data)
nm_hash_update (&h, k->data, p - k->data);
}
}
return nm_hash_complete (&h);
......
......@@ -79,6 +79,41 @@ G_STATIC_ASSERT (sizeof (bool) <= sizeof (int));
/*****************************************************************************/
typedef struct _nm_packed {
int v0;
char v1;
double v2;
guint8 v3;
} TestHashStruct;
static void
_test_hash_struct (int v0, char v1, double v2, guint8 v3)
{
const TestHashStruct s = {
.v0 = v0,
.v1 = v1,
.v2 = v2,
.v3 = v3,
};
NMHashState h;
guint hh;
nm_hash_init (&h, 100);
nm_hash_update (&h, &s, sizeof (s));
hh = nm_hash_complete (&h);
nm_hash_init (&h, 100);
nm_hash_update_val (&h, v0);
nm_hash_update_val (&h, v1);
nm_hash_update_val (&h, v2);
nm_hash_update_val (&h, v3);
g_assert_cmpint (hh, ==, nm_hash_complete (&h));
nm_hash_init (&h, 100);
nm_hash_update_vals (&h, v0, v1, v2, v3);
g_assert_cmpint (hh, ==, nm_hash_complete (&h));
}
static guint
_test_hash_str (const char *str)
{
......@@ -102,6 +137,34 @@ _test_hash_str (const char *str)
return v;
}
#define _test_hash_vals(type, ...) \
G_STMT_START { \
NMHashState h0, h1, h2, h3; \
const type v[] = { __VA_ARGS__ }; \
guint h; \
guint i; \
\
nm_hash_init (&h0, 10); \
nm_hash_init (&h1, 10); \
nm_hash_init (&h2, 10); \
nm_hash_init (&h3, 10); \
\
/* assert that it doesn't matter, whether we hash the values individually,
* or all at once, or via the convenience macros nm_hash_update_val()
* and nm_hash_update_vals(). */ \
for (i = 0; i < G_N_ELEMENTS (v); i++) { \
nm_hash_update (&h0, &v[i], sizeof (type)); \
nm_hash_update_val (&h1, v[i]); \
} \
nm_hash_update_vals (&h2, __VA_ARGS__); \
nm_hash_update (&h3, v, sizeof (v)); \
\
h = nm_hash_complete (&h0); \
g_assert_cmpint (h, ==, nm_hash_complete (&h1)); \
g_assert_cmpint (h, ==, nm_hash_complete (&h2)); \
g_assert_cmpint (h, ==, nm_hash_complete (&h3)); \
} G_STMT_END
static void
test_nm_hash (void)
{
......@@ -109,6 +172,26 @@ test_nm_hash (void)
_test_hash_str ("a");
_test_hash_str ("aa");
_test_hash_str ("diceros bicornis longipes");
/* assert that nm_hash_update_vals() is the same as calling nm_hash_update_val() multiple times. */
_test_hash_vals (int, 1);
_test_hash_vals (int, 1, 2);
_test_hash_vals (int, 1, 2, 3);
_test_hash_vals (int, 1, 2, 3, 4);
_test_hash_vals (long, 1l);
_test_hash_vals (long, 1l, 2l, 3l, 4l, 5l);
_test_hash_struct (10, 'a', 5.4, 7);
_test_hash_struct (-10, '\0', -5.4e49, 255);
g_assert_cmpint (NM_HASH_COMBINE_BOOLS (guint8, 1, 0), ==, 0x002);
g_assert_cmpint (NM_HASH_COMBINE_BOOLS (guint8, 1, 1), ==, 0x003);
g_assert_cmpint (NM_HASH_COMBINE_BOOLS (guint8, 1, 1, 0, 0, 0, 0), ==, 0x030);
g_assert_cmpint (NM_HASH_COMBINE_BOOLS (guint8, 1, 1, 0, 0, 0, 1), ==, 0x031);
g_assert_cmpint (NM_HASH_COMBINE_BOOLS (guint8, 0, 0, 1, 1, 0, 0, 0, 1), ==, 0x031);
g_assert_cmpint (NM_HASH_COMBINE_BOOLS (guint16, 0, 0, 1, 1, 0, 0, 0, 1), ==, 0x031);
g_assert_cmpint (NM_HASH_COMBINE_BOOLS (guint16, 0, 0, 0, 1, 1, 0, 0, 0, 1), ==, 0x031);
g_assert_cmpint (NM_HASH_COMBINE_BOOLS (guint16, 1, 0, 0, 1, 1, 0, 0, 0, 1), ==, 0x131);
}
/*****************************************************************************/
......
......@@ -183,13 +183,13 @@ _dict_idx_entries_hash (const NMDedupMultiEntry *entry)
nm_hash_init (&h, 1914869417u);
if (idx_type->klass->idx_obj_partition_hash) {
nm_assert (obj);
nm_hash_update_uint (&h, idx_type->klass->idx_obj_partition_hash (idx_type, obj));
nm_hash_update_val (&h, idx_type->klass->idx_obj_partition_hash (idx_type, obj));
}
if (!lookup_head)
nm_hash_update_uint (&h, idx_type->klass->idx_obj_id_hash (idx_type, obj));
nm_hash_update_val (&h, idx_type->klass->idx_obj_id_hash (idx_type, obj));
nm_hash_update_ptr (&h, idx_type);
nm_hash_update_val (&h, idx_type);
return nm_hash_complete (&h);
}
......
......@@ -23,10 +23,13 @@
#define __NM_HASH_UTILS_H__
#include "siphash24.h"
#include "nm-macros-internal.h"
typedef struct {
struct _NMHashState {
struct siphash _state;
} NMHashState;
};
typedef struct _NMHashState NMHashState;
void nm_hash_init (NMHashState *state, guint static_seed);
......@@ -55,23 +58,101 @@ nm_hash_update (NMHashState *state, const void *ptr, gsize n)
siphash24_compress (ptr, n, &state->_state);
}
static inline void
nm_hash_update_uint (NMHashState *state, guint val)
{
nm_hash_update (state, &val, sizeof (val));
}
#define nm_hash_update_val(state, val) \
G_STMT_START { \
typeof (val) _val = (val); \
\
nm_hash_update ((state), &_val, sizeof (_val)); \
} G_STMT_END
static inline void
nm_hash_update_uint64 (NMHashState *state, guint64 val)
nm_hash_update_bool (NMHashState *state, bool val)
{
nm_hash_update (state, &val, sizeof (val));
}
static inline void
nm_hash_update_ptr (NMHashState *state, gconstpointer ptr)
{
nm_hash_update (state, &ptr, sizeof (ptr));
}
#define _NM_HASH_COMBINE_BOOLS_x_1( t, y) ((y) ? ((t) (1ull << 0)) : ((t) 0ull))
#define _NM_HASH_COMBINE_BOOLS_x_2( t, y, ...) ((y) ? ((t) (1ull << 1)) : ((t) 0ull)) | _NM_HASH_COMBINE_BOOLS_x_1 (t, __VA_ARGS__)
#define _NM_HASH_COMBINE_BOOLS_x_3( t, y, ...) ((y) ? ((t) (1ull << 2)) : ((t) 0ull)) | _NM_HASH_COMBINE_BOOLS_x_2 (t, __VA_ARGS__)
#define _NM_HASH_COMBINE_BOOLS_x_4( t, y, ...) ((y) ? ((t) (1ull << 3)) : ((t) 0ull)) | _NM_HASH_COMBINE_BOOLS_x_3 (t, __VA_ARGS__)
#define _NM_HASH_COMBINE_BOOLS_x_5( t, y, ...) ((y) ? ((t) (1ull << 4)) : ((t) 0ull)) | _NM_HASH_COMBINE_BOOLS_x_4 (t, __VA_ARGS__)
#define _NM_HASH_COMBINE_BOOLS_x_6( t, y, ...) ((y) ? ((t) (1ull << 5)) : ((t) 0ull)) | _NM_HASH_COMBINE_BOOLS_x_5 (t, __VA_ARGS__)
#define _NM_HASH_COMBINE_BOOLS_x_7( t, y, ...) ((y) ? ((t) (1ull << 6)) : ((t) 0ull)) | _NM_HASH_COMBINE_BOOLS_x_6 (t, __VA_ARGS__)
#define _NM_HASH_COMBINE_BOOLS_x_8( t, y, ...) ((y) ? ((t) (1ull << 7)) : ((t) 0ull)) | _NM_HASH_COMBINE_BOOLS_x_7 (t, __VA_ARGS__)
#define _NM_HASH_COMBINE_BOOLS_x_9( t, y, ...) ((y) ? ((t) (1ull << 8)) : ((t) 0ull)) | (G_STATIC_ASSERT_EXPR (sizeof (t) >= 2), (_NM_HASH_COMBINE_BOOLS_x_8 (t, __VA_ARGS__)))
#define _NM_HASH_COMBINE_BOOLS_x_10(t, y, ...) ((y) ? ((t) (1ull << 9)) : ((t) 0ull)) | _NM_HASH_COMBINE_BOOLS_x_9 (t, __VA_ARGS__)
#define _NM_HASH_COMBINE_BOOLS_x_11(t, y, ...) ((y) ? ((t) (1ull << 10)) : ((t) 0ull)) | _NM_HASH_COMBINE_BOOLS_x_10 (t, __VA_ARGS__)
#define _NM_HASH_COMBINE_BOOLS_n2(t, n, ...) _NM_HASH_COMBINE_BOOLS_x_##n (t, __VA_ARGS__)
#define _NM_HASH_COMBINE_BOOLS_n(t, n, ...) _NM_HASH_COMBINE_BOOLS_n2(t, n, __VA_ARGS__)
#define NM_HASH_COMBINE_BOOLS(type, ...) ((type) (_NM_HASH_COMBINE_BOOLS_n(type, NM_NARG (__VA_ARGS__), __VA_ARGS__)))
#define nm_hash_update_bools(state, ...) \
nm_hash_update_val (state, NM_HASH_COMBINE_BOOLS (guint8, __VA_ARGS__))
#define _NM_HASH_COMBINE_VALS_typ_x_1( y) typeof (y) _v1;
#define _NM_HASH_COMBINE_VALS_typ_x_2( y, ...) typeof (y) _v2; _NM_HASH_COMBINE_VALS_typ_x_1 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_typ_x_3( y, ...) typeof (y) _v3; _NM_HASH_COMBINE_VALS_typ_x_2 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_typ_x_4( y, ...) typeof (y) _v4; _NM_HASH_COMBINE_VALS_typ_x_3 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_typ_x_5( y, ...) typeof (y) _v5; _NM_HASH_COMBINE_VALS_typ_x_4 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_typ_x_6( y, ...) typeof (y) _v6; _NM_HASH_COMBINE_VALS_typ_x_5 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_typ_x_7( y, ...) typeof (y) _v7; _NM_HASH_COMBINE_VALS_typ_x_6 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_typ_x_8( y, ...) typeof (y) _v8; _NM_HASH_COMBINE_VALS_typ_x_7 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_typ_x_9( y, ...) typeof (y) _v9; _NM_HASH_COMBINE_VALS_typ_x_8 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_typ_x_10(y, ...) typeof (y) _v10; _NM_HASH_COMBINE_VALS_typ_x_9 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_typ_x_11(y, ...) typeof (y) _v11; _NM_HASH_COMBINE_VALS_typ_x_10 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_typ_x_12(y, ...) typeof (y) _v12; _NM_HASH_COMBINE_VALS_typ_x_11 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_typ_x_13(y, ...) typeof (y) _v13; _NM_HASH_COMBINE_VALS_typ_x_12 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_typ_x_14(y, ...) typeof (y) _v14; _NM_HASH_COMBINE_VALS_typ_x_13 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_typ_x_15(y, ...) typeof (y) _v15; _NM_HASH_COMBINE_VALS_typ_x_14 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_typ_x_16(y, ...) typeof (y) _v16; _NM_HASH_COMBINE_VALS_typ_x_15 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_typ_x_17(y, ...) typeof (y) _v17; _NM_HASH_COMBINE_VALS_typ_x_16 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_typ_x_18(y, ...) typeof (y) _v18; _NM_HASH_COMBINE_VALS_typ_x_17 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_typ_x_19(y, ...) typeof (y) _v19; _NM_HASH_COMBINE_VALS_typ_x_18 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_typ_x_20(y, ...) typeof (y) _v20; _NM_HASH_COMBINE_VALS_typ_x_19 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_typ_n2(n, ...) _NM_HASH_COMBINE_VALS_typ_x_##n (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_typ_n(n, ...) _NM_HASH_COMBINE_VALS_typ_n2(n, __VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_val_x_1( y) ._v1 = (y),
#define _NM_HASH_COMBINE_VALS_val_x_2( y, ...) ._v2 = (y), _NM_HASH_COMBINE_VALS_val_x_1 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_val_x_3( y, ...) ._v3 = (y), _NM_HASH_COMBINE_VALS_val_x_2 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_val_x_4( y, ...) ._v4 = (y), _NM_HASH_COMBINE_VALS_val_x_3 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_val_x_5( y, ...) ._v5 = (y), _NM_HASH_COMBINE_VALS_val_x_4 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_val_x_6( y, ...) ._v6 = (y), _NM_HASH_COMBINE_VALS_val_x_5 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_val_x_7( y, ...) ._v7 = (y), _NM_HASH_COMBINE_VALS_val_x_6 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_val_x_8( y, ...) ._v8 = (y), _NM_HASH_COMBINE_VALS_val_x_7 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_val_x_9( y, ...) ._v9 = (y), _NM_HASH_COMBINE_VALS_val_x_8 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_val_x_10(y, ...) ._v10 = (y), _NM_HASH_COMBINE_VALS_val_x_9 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_val_x_11(y, ...) ._v11 = (y), _NM_HASH_COMBINE_VALS_val_x_10 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_val_x_12(y, ...) ._v12 = (y), _NM_HASH_COMBINE_VALS_val_x_11 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_val_x_13(y, ...) ._v13 = (y), _NM_HASH_COMBINE_VALS_val_x_12 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_val_x_14(y, ...) ._v14 = (y), _NM_HASH_COMBINE_VALS_val_x_13 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_val_x_15(y, ...) ._v15 = (y), _NM_HASH_COMBINE_VALS_val_x_14 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_val_x_16(y, ...) ._v16 = (y), _NM_HASH_COMBINE_VALS_val_x_15 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_val_x_17(y, ...) ._v17 = (y), _NM_HASH_COMBINE_VALS_val_x_16 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_val_x_18(y, ...) ._v18 = (y), _NM_HASH_COMBINE_VALS_val_x_17 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_val_x_19(y, ...) ._v19 = (y), _NM_HASH_COMBINE_VALS_val_x_18 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_val_x_20(y, ...) ._v20 = (y), _NM_HASH_COMBINE_VALS_val_x_19 (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_val_n2(n, ...) _NM_HASH_COMBINE_VALS_val_x_##n (__VA_ARGS__)
#define _NM_HASH_COMBINE_VALS_val_n(n, ...) _NM_HASH_COMBINE_VALS_val_n2(n, __VA_ARGS__)
/* NM_HASH_COMBINE_VALS() is faster then nm_hash_update_val() as it combines multiple
* calls to nm_hash_update() using a packed structure. */
#define NM_HASH_COMBINE_VALS(var, ...) \
const struct _nm_packed { \
_NM_HASH_COMBINE_VALS_typ_n (NM_NARG (__VA_ARGS__), __VA_ARGS__) \
} var _nm_alignas (guint64) = { \
_NM_HASH_COMBINE_VALS_val_n (NM_NARG (__VA_ARGS__), __VA_ARGS__) \
}
/* nm_hash_update_vals() is faster then nm_hash_update_val() as it combines multiple
* calls to nm_hash_update() using a packed structure. */
#define nm_hash_update_vals(state, ...) \
G_STMT_START { \
NM_HASH_COMBINE_VALS (_val, __VA_ARGS__); \
\
nm_hash_update ((state), &_val, sizeof (_val)); \
} G_STMT_END
static inline void
nm_hash_update_mem (NMHashState *state, const void *ptr, gsize n)
......
......@@ -2861,8 +2861,8 @@ _v4_has_shadowed_routes_detect_hash (const IP4RPFilterData *d)
NMHashState h;
nm_hash_init (&h, 1105201169u);
nm_hash_update_uint (&h, d->network);
nm_hash_update_uint (&h, d->plen);
nm_hash_update_val (&h, d->network);
nm_hash_update_val (&h, d->plen);
return nm_hash_complete (&h);
}
......
......@@ -279,8 +279,9 @@ lldp_neighbor_id_hash (gconstpointer ptr)
nm_hash_init (&h, 23423423u);
nm_hash_update_str0 (&h, neigh->chassis_id);
nm_hash_update_str0 (&h, neigh->port_id);
nm_hash_update_uint (&h, neigh->chassis_id_type);
nm_hash_update_uint (&h, neigh->port_id_type);
nm_hash_update_vals (&h,
neigh->chassis_id_type,
neigh->port_id_type);
return nm_hash_complete (&h);
}
......
......@@ -186,18 +186,6 @@ nm_utils_exp10 (gint16 ex)
/*****************************************************************************/
guint
nm_utils_in6_addr_hash (const struct in6_addr *addr)
{
NMHashState h;
nm_hash_init (&h, 3675559913u);
nm_hash_update_in6addr (&h, addr);
return nm_hash_complete (&h);
}
/*****************************************************************************/
/*
* nm_ethernet_address_is_valid:
* @addr: pointer to a binary or ASCII Ethernet address
......
......@@ -92,8 +92,6 @@ GETTER (void) \
/*****************************************************************************/
guint nm_utils_in6_addr_hash (const struct in6_addr *addr);
gboolean nm_ethernet_address_is_valid (gconstpointer addr, gssize len);
gconstpointer nm_utils_ipx_address_clear_host_address (int family, gpointer dst, gconstpointer src, guint8 plen);
......@@ -131,7 +129,9 @@ nm_utils_ip6_address_same_prefix (const struct in6_addr *addr_a, const struct in
static inline void
nm_hash_update_in6addr (NMHashState *h, const struct in6_addr *addr)
{
nm_hash_update_mem (h, addr, addr ? sizeof (*addr) : 0);
nm_assert (addr);
nm_hash_update (h, addr, sizeof (*addr));
}
static inline void
......@@ -139,8 +139,7 @@ nm_hash_update_in6addr_prefix (NMHashState *h, const struct in6_addr *addr, guin
{
struct in6_addr a;
if (!addr)
g_return_if_reached ();
nm_assert (addr);
nm_utils_ip6_address_clear_host_address (&a, addr, plen);
/* we don't hash plen itself. The caller may want to do that.*/
......
This diff is collapsed.
......@@ -162,8 +162,9 @@ _idx_obj_part (const DedupMultiIdxType *idx_type,
NMHashState h;
nm_hash_init (&h, 487703243u);
nm_hash_update_uint (&h, idx_type->cache_id_type);
nm_hash_update_uint (&h, NMP_OBJECT_GET_TYPE (obj_a));
nm_hash_update_vals (&h,
idx_type->cache_id_type,
NMP_OBJECT_GET_TYPE (obj_a));
return _HASH_NON_ZERO (&h);
}
return 1;
......@@ -185,7 +186,7 @@ _idx_obj_part (const DedupMultiIdxType *idx_type,
/* we request a hash from obj_a. Hash the relevant parts. */
nm_hash_init (&h, 2126752699u);
nm_hash_update_uint (&h, idx_type->cache_id_type);
nm_hash_update_val (&h, idx_type->cache_id_type);
nm_hash_update_strarr (&h, obj_a->link.name);
return _HASH_NON_ZERO (&h);
}
......@@ -207,8 +208,9 @@ _idx_obj_part (const DedupMultiIdxType *idx_type,
NMHashState h;
nm_hash_init (&h, 4278960223u);
nm_hash_update_uint (&h, idx_type->cache_id_type);
nm_hash_update_uint (&h, NMP_OBJECT_GET_TYPE (obj_a));
nm_hash_update_vals (&h,
idx_type->cache_id_type,
NMP_OBJECT_GET_TYPE (obj_a));
return _HASH_NON_ZERO (&h);
}
return 1;
......@@ -230,9 +232,9 @@ _idx_obj_part (const DedupMultiIdxType *idx_type,
NMHashState h;
nm_hash_init (&h, 920415631u);
nm_hash_update_uint (&h, idx_type->cache_id_type);
nm_hash_update_uint (&h, NMP_OBJECT_GET_TYPE (obj_a));
nm_hash_update_uint (&h, obj_a->object.ifindex);
nm_hash_update_vals (&h,
idx_type->cache_id_type,
obj_a->object.ifindex);
return _HASH_NON_ZERO (&h);
}
return 1;
......@@ -252,13 +254,16 @@ _idx_obj_part (const DedupMultiIdxType *idx_type,
}
if (request_hash) {
NMHashState h;
guint h2;
h2 = (obj_type == NMP_OBJECT_TYPE_IP4_ROUTE)
? nm_platform_ip4_route_hash (&obj_a->ip4_route, NM_PLATFORM_IP_ROUTE_CMP_TYPE_WEAK_ID)
: nm_platform_ip6_route_hash (&obj_a->ip6_route, NM_PLATFORM_IP_ROUTE_CMP_TYPE_WEAK_ID);
nm_hash_init (&h, 778646573u);
nm_hash_update_uint (&h, idx_type->cache_id_type);
if (obj_type == NMP_OBJECT_TYPE_IP4_ROUTE)
nm_hash_update_uint (&h, nm_platform_ip4_route_hash (&obj_a->ip4_route, NM_PLATFORM_IP_ROUTE_CMP_TYPE_WEAK_ID));
else
nm_hash_update_uint (&h, nm_platform_ip6_route_hash (&obj_a->ip6_route, NM_PLATFORM_IP_ROUTE_CMP_TYPE_WEAK_ID));
nm_hash_update_vals (&h,
idx_type->cache_id_type,
h2);
return _HASH_NON_ZERO (&h);
}
return 1;
......@@ -325,13 +330,12 @@ _vlan_xgress_qos_mappings_hash_update (guint n_map,
const NMVlanQosMapping *map,
NMHashState *h)
{
guint i;
/* ensure no padding. */
G_STATIC_ASSERT (sizeof (NMVlanQosMapping) == 2 * sizeof (guint32));
nm_hash_update_uint (h, 1453577309u);
for (i = 0; i < n_map; i++) {
nm_hash_update_uint (h, map[i].from);
nm_hash_update_uint (h, map[i].to);
}
nm_hash_update_val (h, n_map);
if (n_map)
nm_hash_update (h, map, n_map * sizeof (*map));
}
static int
......@@ -781,13 +785,13 @@ nmp_object_hash (const NMPObject *obj)
klass = NMP_OBJECT_GET_CLASS (obj);
nm_hash_init (&h, 816200863u);
nm_hash_update_uint (&h, klass->obj_type);
nm_hash_update_val (&h, klass->obj_type);
if (klass->cmd_obj_hash)
nm_hash_update_uint (&h, klass->cmd_obj_hash (obj));
nm_hash_update_val (&h, klass->cmd_obj_hash (obj));
else if (klass->cmd_plobj_hash)
nm_hash_update_uint (&h, klass->cmd_plobj_hash (&obj->object));
nm_hash_update_val (&h, klass->cmd_plobj_hash (&obj->object));
else
nm_hash_update_ptr (&h, obj);
nm_hash_update_val (&h, obj);
return nm_hash_complete (&h);
}
......@@ -800,11 +804,11 @@ _vt_cmd_obj_hash_link (const NMPObject *obj)
nm_assert (NMP_OBJECT_GET_TYPE (obj) == NMP_OBJECT_TYPE_LINK);
nm_hash_init (&h, 3448776161u);
nm_hash_update_uint (&h, nm_platform_link_hash (&obj->link));
nm_hash_update_uint (&h, obj->_link.netlink.is_in_netlink);
nm_hash_update_val (&h, nm_platform_link_hash (&obj->link));
nm_hash_update_val (&h, obj->_link.netlink.is_in_netlink);
if (obj->_link.netlink.lnk)
nm_hash_update_uint (&h, nmp_object_hash (obj->_link.netlink.lnk));
nm_hash_update_ptr (&h, obj->_link.udev.device);
nm_hash_update_val (&h, nmp_object_hash (obj->_link.netlink.lnk));
nm_hash_update_val (&h, obj->_link.udev.device);
return nm_hash_complete (&h);
}
......@@ -816,7 +820,7 @@ _vt_cmd_obj_hash_lnk_vlan (const NMPObject *obj)
nm_assert (NMP_OBJECT_GET_TYPE (obj) == NMP_OBJECT_TYPE_LNK_VLAN);
nm_hash_init (&h, 914932607u);
nm_hash_update_uint (&h, nm_platform_lnk_vlan_hash (&obj->lnk_vlan));
nm_hash_update_val (&h, nm_platform_lnk_vlan_hash (&obj->lnk_vlan));
_vlan_xgress_qos_mappings_hash_update (obj->_lnk_vlan.n_ingress_qos_map,
obj->_lnk_vlan.ingress_qos_map,
&h);
......@@ -1125,25 +1129,27 @@ _vt_cmd_plobj_id_hash_##type (const NMPlatformObject *_obj) \
return nm_hash_complete (&h); \
}
_vt_cmd_plobj_id_hash (link, NMPlatformLink, 3982791431u, {
nm_hash_update_uint (&h, obj->ifindex);
nm_hash_update_val (&h, obj->ifindex);
})
_vt_cmd_plobj_id_hash (ip4_address, NMPlatformIP4Address, 3591309853u, {
nm_hash_update_uint (&h, obj->ifindex);
nm_hash_update_uint (&h, obj->plen);
nm_hash_update_uint (&h, obj->address);
/* for IPv4 we must also consider the net-part of the peer-address (IFA_ADDRESS) */
nm_hash_update_uint (&h, nm_utils_ip4_address_clear_host_address (obj->peer_address, obj->plen));
nm_hash_update_vals (&h,
obj->ifindex,
obj->plen,
obj->address,
/* for IPv4 we must also consider the net-part of the peer-address (IFA_ADDRESS) */
nm_utils_ip4_address_clear_host_address (obj->peer_address, obj->plen));
})
_vt_cmd_plobj_id_hash (ip6_address, NMPlatformIP6Address, 2907861637u, {
nm_hash_update_uint (&h, obj->ifindex);
/* for IPv6 addresses, the prefix length is not part of the primary identifier. */
nm_hash_update_in6addr (&h, &obj->address);
nm_hash_update_vals (&h,
obj->ifindex,
/* for IPv6 addresses, the prefix length is not part of the primary identifier. */
obj->address);
})
_vt_cmd_plobj_id_hash (ip4_route, NMPlatformIP4Route, 1038302471u, {
nm_hash_update_uint (&h, nm_platform_ip4_route_hash (obj, NM_PLATFORM_IP_ROUTE_CMP_TYPE_ID));
nm_hash_update_val (&h, nm_platform_ip4_route_hash (obj, NM_PLATFORM_IP_ROUTE_CMP_TYPE_ID));
})
_vt_cmd_plobj_id_hash (ip6_route, NMPlatformIP6Route, 1233384151u, {
nm_hash_update_uint (&h, nm_platform_ip6_route_hash (obj, NM_PLATFORM_IP_ROUTE_CMP_TYPE_ID));
nm_hash_update_val (&h, nm_platform_ip6_route_hash (obj, NM_PLATFORM_IP_ROUTE_CMP_TYPE_ID));
})
gboolean
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment