diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index 1f4aa2170..8c4d120d1 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -420,13 +420,15 @@ _dedup_obj_destroy (NMDedupMultiObj *obj) g_slice_free (DedupObj, o); } -static guint -_dedup_obj_full_hash (const NMDedupMultiObj *obj) +static void +_dedup_obj_full_hash_update (const NMDedupMultiObj *obj, NMHashState *h) { const DedupObj *o; o = _dedup_obj_assert (obj); - return (o->val * 33) + o->other; + nm_hash_update_vals (h, + o->val, + o->other); } static gboolean @@ -443,7 +445,7 @@ _dedup_obj_full_equal (const NMDedupMultiObj *obj_a, static const NMDedupMultiObjClass dedup_obj_class = { .obj_clone = _dedup_obj_clone, .obj_destroy = _dedup_obj_destroy, - .obj_full_hash = _dedup_obj_full_hash, + .obj_full_hash_update = _dedup_obj_full_hash_update, .obj_full_equal = _dedup_obj_full_equal, }; @@ -478,20 +480,19 @@ _dedup_idx_assert (const NMDedupMultiIdxType *idx_type) return t; } -static guint -_dedup_idx_obj_id_hash (const NMDedupMultiIdxType *idx_type, - const NMDedupMultiObj *obj) +static void +_dedup_idx_obj_id_hash_update (const NMDedupMultiIdxType *idx_type, + const NMDedupMultiObj *obj, + NMHashState *h) { const DedupIdxType *t; const DedupObj *o; - guint h; t = _dedup_idx_assert (idx_type); o = _dedup_obj_assert (obj); - h = o->val / t->partition_size; - h = (h * 33) + (o->val % t->val_mod); - return h; + nm_hash_update_val (h, o->val / t->partition_size); + nm_hash_update_val (h, o->val % t->val_mod); } static gboolean @@ -511,9 +512,10 @@ _dedup_idx_obj_id_equal (const NMDedupMultiIdxType *idx_type, && (o_a->val % t->val_mod) == (o_b->val % t->val_mod); } -static guint -_dedup_idx_obj_partition_hash (const NMDedupMultiIdxType *idx_type, - const NMDedupMultiObj *obj) +static void +_dedup_idx_obj_partition_hash_update (const NMDedupMultiIdxType *idx_type, + const NMDedupMultiObj *obj, + NMHashState *h) { const DedupIdxType *t; const DedupObj *o; @@ -521,7 +523,7 @@ _dedup_idx_obj_partition_hash (const NMDedupMultiIdxType *idx_type, t = _dedup_idx_assert (idx_type); o = _dedup_obj_assert (obj); - return o->val / t->partition_size; + nm_hash_update_val (h, o->val / t->partition_size); } static gboolean @@ -541,9 +543,9 @@ _dedup_idx_obj_partition_equal (const NMDedupMultiIdxType *idx_type, } static const NMDedupMultiIdxTypeClass dedup_idx_type_class = { - .idx_obj_id_hash = _dedup_idx_obj_id_hash, + .idx_obj_id_hash_update = _dedup_idx_obj_id_hash_update, .idx_obj_id_equal = _dedup_idx_obj_id_equal, - .idx_obj_partition_hash = _dedup_idx_obj_partition_hash, + .idx_obj_partition_hash_update = _dedup_idx_obj_partition_hash_update, .idx_obj_partition_equal = _dedup_idx_obj_partition_equal, }; diff --git a/shared/nm-utils/nm-dedup-multi.c b/shared/nm-utils/nm-dedup-multi.c index fb57f6c1a..8a59f1c46 100644 --- a/shared/nm-utils/nm-dedup-multi.c +++ b/shared/nm-utils/nm-dedup-multi.c @@ -55,9 +55,9 @@ ASSERT_idx_type (const NMDedupMultiIdxType *idx_type) nm_assert (idx_type); #if NM_MORE_ASSERTS > 10 nm_assert (idx_type->klass); - nm_assert (idx_type->klass->idx_obj_id_hash); + nm_assert (idx_type->klass->idx_obj_id_hash_update); nm_assert (idx_type->klass->idx_obj_id_equal); - nm_assert (!!idx_type->klass->idx_obj_partition_hash == !!idx_type->klass->idx_obj_partition_equal); + nm_assert (!!idx_type->klass->idx_obj_partition_hash_update == !!idx_type->klass->idx_obj_partition_equal); nm_assert (idx_type->lst_idx_head.next); #endif } @@ -181,13 +181,13 @@ _dict_idx_entries_hash (const NMDedupMultiEntry *entry) _entry_unpack (entry, &idx_type, &obj, &lookup_head); nm_hash_init (&h, 1914869417u); - if (idx_type->klass->idx_obj_partition_hash) { + if (idx_type->klass->idx_obj_partition_hash_update) { nm_assert (obj); - nm_hash_update_val (&h, idx_type->klass->idx_obj_partition_hash (idx_type, obj)); + idx_type->klass->idx_obj_partition_hash_update (idx_type, obj, &h); } if (!lookup_head) - nm_hash_update_val (&h, idx_type->klass->idx_obj_id_hash (idx_type, obj)); + idx_type->klass->idx_obj_id_hash_update (idx_type, obj, &h); nm_hash_update_val (&h, idx_type); return nm_hash_complete (&h); @@ -797,7 +797,11 @@ nm_dedup_multi_index_dirty_remove_idx (NMDedupMultiIndex *self, static guint _dict_idx_objs_hash (const NMDedupMultiObj *obj) { - return obj->klass->obj_full_hash (obj); + NMHashState h; + + nm_hash_init (&h, 1748638583u); + obj->klass->obj_full_hash_update (obj, &h); + return nm_hash_complete (&h); } static gboolean diff --git a/shared/nm-utils/nm-dedup-multi.h b/shared/nm-utils/nm-dedup-multi.h index ecce791d4..bebfe43d3 100644 --- a/shared/nm-utils/nm-dedup-multi.h +++ b/shared/nm-utils/nm-dedup-multi.h @@ -27,6 +27,8 @@ /*****************************************************************************/ +struct _NMHashState; + typedef struct _NMDedupMultiObj NMDedupMultiObj; typedef struct _NMDedupMultiObjClass NMDedupMultiObjClass; typedef struct _NMDedupMultiIdxType NMDedupMultiIdxType; @@ -69,9 +71,10 @@ struct _NMDedupMultiObjClass { void (*obj_destroy) (NMDedupMultiObj *obj); - /* the NMDedupMultiObj can be deduplicated. For that the obj_full_hash() + /* the NMDedupMultiObj can be deduplicated. For that the obj_full_hash_update() * and obj_full_equal() compare *all* fields of the object, even minor ones. */ - guint (*obj_full_hash) (const NMDedupMultiObj *obj); + void (*obj_full_hash_update) (const NMDedupMultiObj *obj, + struct _NMHashState *h); gboolean (*obj_full_equal) (const NMDedupMultiObj *obj_a, const NMDedupMultiObj *obj_b); }; @@ -152,8 +155,9 @@ void nm_dedup_multi_idx_type_init (NMDedupMultiIdxType *idx_type, struct _NMDedupMultiIdxTypeClass { NMObjBaseClass parent; - guint (*idx_obj_id_hash) (const NMDedupMultiIdxType *idx_type, - const NMDedupMultiObj *obj); + void (*idx_obj_id_hash_update) (const NMDedupMultiIdxType *idx_type, + const NMDedupMultiObj *obj, + struct _NMHashState *h); gboolean (*idx_obj_id_equal) (const NMDedupMultiIdxType *idx_type, const NMDedupMultiObj *obj_a, const NMDedupMultiObj *obj_b); @@ -167,8 +171,9 @@ struct _NMDedupMultiIdxTypeClass { * object is not partitionable, it is never added to the NMDedupMultiIndex. */ gboolean (*idx_obj_partitionable) (const NMDedupMultiIdxType *idx_type, const NMDedupMultiObj *obj); - guint (*idx_obj_partition_hash) (const NMDedupMultiIdxType *idx_type, - const NMDedupMultiObj *obj); + void (*idx_obj_partition_hash_update) (const NMDedupMultiIdxType *idx_type, + const NMDedupMultiObj *obj, + struct _NMHashState *h); gboolean (*idx_obj_partition_equal) (const NMDedupMultiIdxType *idx_type, const NMDedupMultiObj *obj_a, const NMDedupMultiObj *obj_b); diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index 657ea6346..e2f99e24d 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -57,11 +57,12 @@ _route_valid (const NMPlatformIP4Route *r) /*****************************************************************************/ -static guint -_idx_obj_id_hash (const NMDedupMultiIdxType *idx_type, - const NMDedupMultiObj *obj) +static void +_idx_obj_id_hash_update (const NMDedupMultiIdxType *idx_type, + const NMDedupMultiObj *obj, + NMHashState *h) { - return nmp_object_id_hash ((NMPObject *) obj); + nmp_object_id_hash_update ((NMPObject *) obj, h); } static gboolean @@ -77,7 +78,7 @@ nm_ip_config_dedup_multi_idx_type_init (NMIPConfigDedupMultiIdxType *idx_type, NMPObjectType obj_type) { static const NMDedupMultiIdxTypeClass idx_type_class = { - .idx_obj_id_hash = _idx_obj_id_hash, + .idx_obj_id_hash_update = _idx_obj_id_hash_update, .idx_obj_id_equal = _idx_obj_id_equal, }; diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 83b6744ce..cd0e474a6 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -5123,36 +5123,32 @@ nm_platform_ip6_route_to_string (const NMPlatformIP6Route *route, char *buf, gsi return buf; } -guint -nm_platform_link_hash (const NMPlatformLink *obj) +void +nm_platform_link_hash_update (const NMPlatformLink *obj, NMHashState *h) { - NMHashState h; - - nm_hash_init (&h, 99413953u); - nm_hash_update_vals (&h, + nm_hash_update_vals (h, obj->ifindex, obj->master, obj->parent); - nm_hash_update_val (&h, obj->type); - nm_hash_update_strarr (&h, obj->name); - nm_hash_update_vals (&h, + nm_hash_update_val (h, obj->type); + nm_hash_update_strarr (h, obj->name); + nm_hash_update_vals (h, obj->n_ifi_flags, obj->mtu); - nm_hash_update_bools (&h, obj->connected, - obj->initialized); - nm_hash_update_val (&h, obj->arptype); - nm_hash_update_val (&h, obj->inet6_addr_gen_mode_inv); - nm_hash_update_str0 (&h, obj->kind); - nm_hash_update_str0 (&h, obj->driver); + nm_hash_update_bools (h, obj->connected, + obj->initialized); + nm_hash_update_val (h, obj->arptype); + nm_hash_update_val (h, obj->inet6_addr_gen_mode_inv); + nm_hash_update_str0 (h, obj->kind); + nm_hash_update_str0 (h, obj->driver); /* nm_hash_update_mem() also hashes the length obj->addr.len */ - nm_hash_update_mem (&h, obj->addr.data, obj->addr.len); - nm_hash_update (&h, &obj->inet6_token, sizeof (obj->inet6_token)); - nm_hash_update_vals (&h, + nm_hash_update_mem (h, obj->addr.data, obj->addr.len); + nm_hash_update (h, &obj->inet6_token, sizeof (obj->inet6_token)); + nm_hash_update_vals (h, obj->rx_packets, obj->rx_bytes, obj->tx_packets, obj->tx_bytes); - return nm_hash_complete (&h); } int @@ -5183,23 +5179,19 @@ nm_platform_link_cmp (const NMPlatformLink *a, const NMPlatformLink *b) return 0; } -guint -nm_platform_lnk_gre_hash (const NMPlatformLnkGre *obj) +void +nm_platform_lnk_gre_hash_update (const NMPlatformLnkGre *obj, NMHashState *h) { - NMHashState h; - - nm_hash_init (&h, 1887023311u); - nm_hash_update_val (&h, obj->parent_ifindex); - nm_hash_update_val (&h, obj->input_flags); - nm_hash_update_val (&h, obj->output_flags); - nm_hash_update_val (&h, obj->input_key); - nm_hash_update_val (&h, obj->output_key); - nm_hash_update_val (&h, obj->local); - nm_hash_update_val (&h, obj->remote); - nm_hash_update_val (&h, obj->ttl); - nm_hash_update_val (&h, obj->tos); - nm_hash_update_bool (&h, obj->path_mtu_discovery); - return nm_hash_complete (&h); + nm_hash_update_val (h, obj->parent_ifindex); + nm_hash_update_val (h, obj->input_flags); + nm_hash_update_val (h, obj->output_flags); + nm_hash_update_val (h, obj->input_key); + nm_hash_update_val (h, obj->output_key); + nm_hash_update_val (h, obj->local); + nm_hash_update_val (h, obj->remote); + nm_hash_update_val (h, obj->ttl); + nm_hash_update_val (h, obj->tos); + nm_hash_update_bool (h, obj->path_mtu_discovery); } int @@ -5219,15 +5211,11 @@ nm_platform_lnk_gre_cmp (const NMPlatformLnkGre *a, const NMPlatformLnkGre *b) return 0; } -guint -nm_platform_lnk_infiniband_hash (const NMPlatformLnkInfiniband *obj) +void +nm_platform_lnk_infiniband_hash_update (const NMPlatformLnkInfiniband *obj, NMHashState *h) { - NMHashState h; - - nm_hash_init (&h, 1748638583u); - nm_hash_update_val (&h, obj->p_key); - nm_hash_update_str0 (&h, obj->mode); - return nm_hash_complete (&h); + nm_hash_update_val (h, obj->p_key); + nm_hash_update_str0 (h, obj->mode); } int @@ -5239,21 +5227,17 @@ nm_platform_lnk_infiniband_cmp (const NMPlatformLnkInfiniband *a, const NMPlatfo return 0; } -guint -nm_platform_lnk_ip6tnl_hash (const NMPlatformLnkIp6Tnl *obj) +void +nm_platform_lnk_ip6tnl_hash_update (const NMPlatformLnkIp6Tnl *obj, NMHashState *h) { - NMHashState h; - - nm_hash_init (&h, 1651660009u); - nm_hash_update_val (&h, obj->parent_ifindex); - nm_hash_update_in6addr (&h, &obj->local); - nm_hash_update_in6addr (&h, &obj->remote); - nm_hash_update_val (&h, obj->ttl); - nm_hash_update_val (&h, obj->tclass); - nm_hash_update_val (&h, obj->encap_limit); - nm_hash_update_val (&h, obj->flow_label); - nm_hash_update_val (&h, obj->proto); - return nm_hash_complete (&h); + nm_hash_update_val (h, obj->parent_ifindex); + nm_hash_update_in6addr (h, &obj->local); + nm_hash_update_in6addr (h, &obj->remote); + nm_hash_update_val (h, obj->ttl); + nm_hash_update_val (h, obj->tclass); + nm_hash_update_val (h, obj->encap_limit); + nm_hash_update_val (h, obj->flow_label); + nm_hash_update_val (h, obj->proto); } int @@ -5271,19 +5255,15 @@ nm_platform_lnk_ip6tnl_cmp (const NMPlatformLnkIp6Tnl *a, const NMPlatformLnkIp6 return 0; } -guint -nm_platform_lnk_ipip_hash (const NMPlatformLnkIpIp *obj) +void +nm_platform_lnk_ipip_hash_update (const NMPlatformLnkIpIp *obj, NMHashState *h) { - NMHashState h; - - nm_hash_init (&h, 861934429u); - nm_hash_update_val (&h, obj->parent_ifindex); - nm_hash_update_val (&h, obj->local); - nm_hash_update_val (&h, obj->remote); - nm_hash_update_val (&h, obj->ttl); - nm_hash_update_val (&h, obj->tos); - nm_hash_update_bool (&h, obj->path_mtu_discovery); - return nm_hash_complete (&h); + nm_hash_update_val (h, obj->parent_ifindex); + nm_hash_update_val (h, obj->local); + nm_hash_update_val (h, obj->remote); + nm_hash_update_val (h, obj->ttl); + nm_hash_update_val (h, obj->tos); + nm_hash_update_bool (h, obj->path_mtu_discovery); } int @@ -5299,28 +5279,24 @@ nm_platform_lnk_ipip_cmp (const NMPlatformLnkIpIp *a, const NMPlatformLnkIpIp *b return 0; } -guint -nm_platform_lnk_macsec_hash (const NMPlatformLnkMacsec *obj) +void +nm_platform_lnk_macsec_hash_update (const NMPlatformLnkMacsec *obj, NMHashState *h) { - NMHashState h; - - nm_hash_init (&h, 226984267u); - nm_hash_update_val (&h, obj->parent_ifindex); - nm_hash_update_val (&h, obj->window); - nm_hash_update_vals (&h, + nm_hash_update_val (h, obj->parent_ifindex); + nm_hash_update_val (h, obj->window); + nm_hash_update_vals (h, obj->cipher_suite, obj->sci); - nm_hash_update_vals (&h, + nm_hash_update_vals (h, obj->icv_length, obj->encoding_sa, obj->validation); - nm_hash_update_bools (&h, obj->encrypt, - obj->protect, - obj->include_sci, - obj->es, - obj->scb, - obj->replay_protect); - return nm_hash_complete (&h); + nm_hash_update_bools (h, obj->encrypt, + obj->protect, + obj->include_sci, + obj->es, + obj->scb, + obj->replay_protect); } int @@ -5343,16 +5319,12 @@ nm_platform_lnk_macsec_cmp (const NMPlatformLnkMacsec *a, const NMPlatformLnkMac return 0; } -guint -nm_platform_lnk_macvlan_hash (const NMPlatformLnkMacvlan *obj) +void +nm_platform_lnk_macvlan_hash_update (const NMPlatformLnkMacvlan *obj, NMHashState *h ) { - NMHashState h; - - nm_hash_init (&h, 771014989u); - nm_hash_update_val (&h, obj->mode); - nm_hash_update_bools (&h, obj->no_promisc, - obj->tap); - return nm_hash_complete (&h); + nm_hash_update_val (h, obj->mode); + nm_hash_update_bools (h, obj->no_promisc, + obj->tap); } int @@ -5365,21 +5337,17 @@ nm_platform_lnk_macvlan_cmp (const NMPlatformLnkMacvlan *a, const NMPlatformLnkM return 0; } -guint -nm_platform_lnk_sit_hash (const NMPlatformLnkSit *obj) +void +nm_platform_lnk_sit_hash_update (const NMPlatformLnkSit *obj, NMHashState *h) { - NMHashState h; - - nm_hash_init (&h, 1690154969u); - nm_hash_update_val (&h, obj->parent_ifindex); - nm_hash_update_val (&h, obj->local); - nm_hash_update_val (&h, obj->remote); - nm_hash_update_val (&h, obj->ttl); - nm_hash_update_val (&h, obj->tos); - nm_hash_update_bool (&h, obj->path_mtu_discovery); - nm_hash_update_val (&h, obj->flags); - nm_hash_update_val (&h, obj->proto); - return nm_hash_complete (&h); + nm_hash_update_val (h, obj->parent_ifindex); + nm_hash_update_val (h, obj->local); + nm_hash_update_val (h, obj->remote); + nm_hash_update_val (h, obj->ttl); + nm_hash_update_val (h, obj->tos); + nm_hash_update_bool (h, obj->path_mtu_discovery); + nm_hash_update_val (h, obj->flags); + nm_hash_update_val (h, obj->proto); } int @@ -5397,15 +5365,11 @@ nm_platform_lnk_sit_cmp (const NMPlatformLnkSit *a, const NMPlatformLnkSit *b) return 0; } -guint -nm_platform_lnk_vlan_hash (const NMPlatformLnkVlan *obj) +void +nm_platform_lnk_vlan_hash_update (const NMPlatformLnkVlan *obj, NMHashState *h) { - NMHashState h; - - nm_hash_init (&h, 58751383u); - nm_hash_update_val (&h, obj->id); - nm_hash_update_val (&h, obj->flags); - return nm_hash_complete (&h); + nm_hash_update_val (h, obj->id); + nm_hash_update_val (h, obj->flags); } int @@ -5417,31 +5381,27 @@ nm_platform_lnk_vlan_cmp (const NMPlatformLnkVlan *a, const NMPlatformLnkVlan *b return 0; } -guint -nm_platform_lnk_vxlan_hash (const NMPlatformLnkVxlan *obj) +void +nm_platform_lnk_vxlan_hash_update (const NMPlatformLnkVxlan *obj, NMHashState *h) { - NMHashState h; - - nm_hash_init (&h, 461041297u); - nm_hash_update_val (&h, obj->parent_ifindex); - nm_hash_update_val (&h, obj->id); - nm_hash_update_val (&h, obj->group); - nm_hash_update_val (&h, obj->local); - nm_hash_update_in6addr (&h, &obj->group6); - nm_hash_update_in6addr (&h, &obj->local6); - nm_hash_update_val (&h, obj->tos); - nm_hash_update_val (&h, obj->ttl); - nm_hash_update_val (&h, obj->ageing); - nm_hash_update_val (&h, obj->limit); - nm_hash_update_val (&h, obj->dst_port); - nm_hash_update_val (&h, obj->src_port_min); - nm_hash_update_val (&h, obj->src_port_max); - nm_hash_update_bools (&h, obj->learning, - obj->proxy, - obj->rsc, - obj->l2miss, - obj->l3miss); - return nm_hash_complete (&h); + nm_hash_update_val (h, obj->parent_ifindex); + nm_hash_update_val (h, obj->id); + nm_hash_update_val (h, obj->group); + nm_hash_update_val (h, obj->local); + nm_hash_update_in6addr (h, &obj->group6); + nm_hash_update_in6addr (h, &obj->local6); + nm_hash_update_val (h, obj->tos); + nm_hash_update_val (h, obj->ttl); + nm_hash_update_val (h, obj->ageing); + nm_hash_update_val (h, obj->limit); + nm_hash_update_val (h, obj->dst_port); + nm_hash_update_val (h, obj->src_port_min); + nm_hash_update_val (h, obj->src_port_max); + nm_hash_update_bools (h, obj->learning, + obj->proxy, + obj->rsc, + obj->l2miss, + obj->l3miss); } int @@ -5469,25 +5429,19 @@ nm_platform_lnk_vxlan_cmp (const NMPlatformLnkVxlan *a, const NMPlatformLnkVxlan return 0; } -guint -nm_platform_ip4_address_hash (const NMPlatformIP4Address *obj) +void +nm_platform_ip4_address_hash_update (const NMPlatformIP4Address *obj, NMHashState *h) { - NMHashState h; - - nm_hash_init (&h, 469681301u); - if (obj) { - nm_hash_update_val (&h, obj->ifindex); - nm_hash_update_val (&h, obj->address); - nm_hash_update_val (&h, obj->plen); - nm_hash_update_val (&h, obj->peer_address); - nm_hash_update_val (&h, obj->addr_source); - nm_hash_update_val (&h, obj->timestamp); - nm_hash_update_val (&h, obj->lifetime); - nm_hash_update_val (&h, obj->preferred); - nm_hash_update_val (&h, obj->n_ifa_flags); - nm_hash_update_strarr (&h, obj->label); - } - return nm_hash_complete (&h); + nm_hash_update_val (h, obj->ifindex); + nm_hash_update_val (h, obj->address); + nm_hash_update_val (h, obj->plen); + nm_hash_update_val (h, obj->peer_address); + nm_hash_update_val (h, obj->addr_source); + nm_hash_update_val (h, obj->timestamp); + nm_hash_update_val (h, obj->lifetime); + nm_hash_update_val (h, obj->preferred); + nm_hash_update_val (h, obj->n_ifa_flags); + nm_hash_update_strarr (h, obj->label); } int @@ -5507,24 +5461,18 @@ nm_platform_ip4_address_cmp (const NMPlatformIP4Address *a, const NMPlatformIP4A return 0; } -guint -nm_platform_ip6_address_hash (const NMPlatformIP6Address *obj) +void +nm_platform_ip6_address_hash_update (const NMPlatformIP6Address *obj, NMHashState *h) { - NMHashState h; - - nm_hash_init (&h, 605908909u); - if (obj) { - nm_hash_update_val (&h, obj->ifindex); - nm_hash_update_in6addr (&h, &obj->address); - nm_hash_update_val (&h, obj->plen); - nm_hash_update_in6addr (&h, &obj->peer_address); - nm_hash_update_val (&h, obj->addr_source); - nm_hash_update_val (&h, obj->timestamp); - nm_hash_update_val (&h, obj->lifetime); - nm_hash_update_val (&h, obj->preferred); - nm_hash_update_val (&h, obj->n_ifa_flags); - } - return nm_hash_complete (&h); + nm_hash_update_val (h, obj->ifindex); + nm_hash_update_in6addr (h, &obj->address); + nm_hash_update_val (h, obj->plen); + nm_hash_update_in6addr (h, &obj->peer_address); + nm_hash_update_val (h, obj->addr_source); + nm_hash_update_val (h, obj->timestamp); + nm_hash_update_val (h, obj->lifetime); + nm_hash_update_val (h, obj->preferred); + nm_hash_update_val (h, obj->n_ifa_flags); } int @@ -5547,65 +5495,62 @@ nm_platform_ip6_address_cmp (const NMPlatformIP6Address *a, const NMPlatformIP6A return 0; } -guint -nm_platform_ip4_route_hash (const NMPlatformIP4Route *obj, NMPlatformIPRouteCmpType cmp_type) +void +nm_platform_ip4_route_hash_update (const NMPlatformIP4Route *obj, NMPlatformIPRouteCmpType cmp_type, NMHashState *h) { - NMHashState h; - - nm_hash_init (&h, 1228913327u); - nm_hash_update_val (&h, cmp_type); + nm_hash_update_val (h, cmp_type); if (obj) { switch (cmp_type) { case NM_PLATFORM_IP_ROUTE_CMP_TYPE_WEAK_ID: case NM_PLATFORM_IP_ROUTE_CMP_TYPE_ID: - nm_hash_update_val (&h, nm_platform_route_table_uncoerce (obj->table_coerced, TRUE)); - nm_hash_update_val (&h, nm_utils_ip4_address_clear_host_address (obj->network, obj->plen)); - nm_hash_update_val (&h, obj->plen); - nm_hash_update_val (&h, obj->metric); - nm_hash_update_val (&h, obj->tos); + nm_hash_update_val (h, nm_platform_route_table_uncoerce (obj->table_coerced, TRUE)); + nm_hash_update_val (h, nm_utils_ip4_address_clear_host_address (obj->network, obj->plen)); + nm_hash_update_val (h, obj->plen); + nm_hash_update_val (h, obj->metric); + nm_hash_update_val (h, obj->tos); if (cmp_type == NM_PLATFORM_IP_ROUTE_CMP_TYPE_ID) { - nm_hash_update_val (&h, obj->ifindex); - nm_hash_update_val (&h, nmp_utils_ip_config_source_round_trip_rtprot (obj->rt_source)); - nm_hash_update_val (&h, _ip_route_scope_inv_get_normalized (obj)); - nm_hash_update_val (&h, obj->gateway); - nm_hash_update_val (&h, obj->mss); - nm_hash_update_val (&h, obj->pref_src); - nm_hash_update_vals (&h, + nm_hash_update_val (h, obj->ifindex); + nm_hash_update_val (h, nmp_utils_ip_config_source_round_trip_rtprot (obj->rt_source)); + nm_hash_update_val (h, _ip_route_scope_inv_get_normalized (obj)); + nm_hash_update_val (h, obj->gateway); + nm_hash_update_val (h, obj->mss); + nm_hash_update_val (h, obj->pref_src); + nm_hash_update_vals (h, obj->window, obj->cwnd, obj->initcwnd, obj->initrwnd, obj->mtu); - nm_hash_update_bools (&h, obj->lock_window, - obj->lock_cwnd, - obj->lock_initcwnd, - obj->lock_initrwnd, - obj->lock_mtu); + nm_hash_update_bools (h, obj->lock_window, + obj->lock_cwnd, + obj->lock_initcwnd, + obj->lock_initrwnd, + obj->lock_mtu); } break; case NM_PLATFORM_IP_ROUTE_CMP_TYPE_SEMANTICALLY: case NM_PLATFORM_IP_ROUTE_CMP_TYPE_FULL: if (cmp_type == NM_PLATFORM_IP_ROUTE_CMP_TYPE_SEMANTICALLY) - nm_hash_update_val (&h, nm_platform_route_table_uncoerce (obj->table_coerced, TRUE)); + nm_hash_update_val (h, nm_platform_route_table_uncoerce (obj->table_coerced, TRUE)); else - nm_hash_update_val (&h, obj->table_coerced); - nm_hash_update_val (&h, obj->ifindex); + nm_hash_update_val (h, obj->table_coerced); + nm_hash_update_val (h, obj->ifindex); if (cmp_type == NM_PLATFORM_IP_ROUTE_CMP_TYPE_SEMANTICALLY) - nm_hash_update_val (&h, nm_utils_ip4_address_clear_host_address (obj->network, obj->plen)); + nm_hash_update_val (h, nm_utils_ip4_address_clear_host_address (obj->network, obj->plen)); else - nm_hash_update_val (&h, obj->network); - nm_hash_update_val (&h, obj->plen); - nm_hash_update_val (&h, obj->metric); - nm_hash_update_val (&h, obj->gateway); + nm_hash_update_val (h, obj->network); + nm_hash_update_val (h, obj->plen); + nm_hash_update_val (h, obj->metric); + nm_hash_update_val (h, obj->gateway); if (cmp_type == NM_PLATFORM_IP_ROUTE_CMP_TYPE_SEMANTICALLY) { - nm_hash_update_val (&h, nmp_utils_ip_config_source_round_trip_rtprot (obj->rt_source)); - nm_hash_update_val (&h, _ip_route_scope_inv_get_normalized (obj)); + nm_hash_update_val (h, nmp_utils_ip_config_source_round_trip_rtprot (obj->rt_source)); + nm_hash_update_val (h, _ip_route_scope_inv_get_normalized (obj)); } else { - nm_hash_update_val (&h, obj->rt_source); - nm_hash_update_val (&h, obj->scope_inv); + nm_hash_update_val (h, obj->rt_source); + nm_hash_update_val (h, obj->scope_inv); } - nm_hash_update_val (&h, obj->tos); - nm_hash_update_vals (&h, + nm_hash_update_val (h, obj->tos); + nm_hash_update_vals (h, obj->mss, obj->pref_src, obj->window, @@ -5613,16 +5558,15 @@ nm_platform_ip4_route_hash (const NMPlatformIP4Route *obj, NMPlatformIPRouteCmpT obj->initcwnd, obj->initrwnd, obj->mtu); - nm_hash_update_bools (&h, obj->rt_cloned, - obj->lock_window, - obj->lock_cwnd, - obj->lock_initcwnd, - obj->lock_initrwnd, - obj->lock_mtu); + nm_hash_update_bools (h, obj->rt_cloned, + obj->lock_window, + obj->lock_cwnd, + obj->lock_initcwnd, + obj->lock_initrwnd, + obj->lock_mtu); break; } } - return nm_hash_complete (&h); } int @@ -5702,75 +5646,71 @@ nm_platform_ip4_route_cmp (const NMPlatformIP4Route *a, const NMPlatformIP4Route return 0; } -guint -nm_platform_ip6_route_hash (const NMPlatformIP6Route *obj, NMPlatformIPRouteCmpType cmp_type) +void +nm_platform_ip6_route_hash_update (const NMPlatformIP6Route *obj, NMPlatformIPRouteCmpType cmp_type, NMHashState *h) { - NMHashState h; - - nm_hash_init (&h, 1053326051u); - nm_hash_update_val (&h, cmp_type); + nm_hash_update_val (h, cmp_type); if (obj) { switch (cmp_type) { case NM_PLATFORM_IP_ROUTE_CMP_TYPE_WEAK_ID: case NM_PLATFORM_IP_ROUTE_CMP_TYPE_ID: - nm_hash_update_val (&h, nm_platform_route_table_uncoerce (obj->table_coerced, TRUE)); - nm_hash_update_in6addr_prefix (&h, &obj->network, obj->plen); - nm_hash_update_val (&h, obj->plen); - nm_hash_update_val (&h, nm_utils_ip6_route_metric_normalize (obj->metric)); - nm_hash_update_in6addr_prefix (&h, &obj->src, obj->src_plen); - nm_hash_update_val (&h, obj->src_plen); + nm_hash_update_val (h, nm_platform_route_table_uncoerce (obj->table_coerced, TRUE)); + nm_hash_update_in6addr_prefix (h, &obj->network, obj->plen); + nm_hash_update_val (h, obj->plen); + nm_hash_update_val (h, nm_utils_ip6_route_metric_normalize (obj->metric)); + nm_hash_update_in6addr_prefix (h, &obj->src, obj->src_plen); + nm_hash_update_val (h, obj->src_plen); if (cmp_type == NM_PLATFORM_IP_ROUTE_CMP_TYPE_ID) { - nm_hash_update_val (&h, obj->ifindex); - nm_hash_update_in6addr (&h, &obj->gateway); + nm_hash_update_val (h, obj->ifindex); + nm_hash_update_in6addr (h, &obj->gateway); } break; case NM_PLATFORM_IP_ROUTE_CMP_TYPE_SEMANTICALLY: case NM_PLATFORM_IP_ROUTE_CMP_TYPE_FULL: if (cmp_type == NM_PLATFORM_IP_ROUTE_CMP_TYPE_SEMANTICALLY) - nm_hash_update_val (&h, nm_platform_route_table_uncoerce (obj->table_coerced, TRUE)); + nm_hash_update_val (h, nm_platform_route_table_uncoerce (obj->table_coerced, TRUE)); else - nm_hash_update_val (&h, obj->table_coerced); - nm_hash_update_val (&h, obj->ifindex); + nm_hash_update_val (h, obj->table_coerced); + nm_hash_update_val (h, obj->ifindex); if (cmp_type == NM_PLATFORM_IP_ROUTE_CMP_TYPE_SEMANTICALLY) - nm_hash_update_in6addr_prefix (&h, &obj->network, obj->plen); + nm_hash_update_in6addr_prefix (h, &obj->network, obj->plen); else - nm_hash_update_in6addr (&h, &obj->network); - nm_hash_update_val (&h, obj->plen); + nm_hash_update_in6addr (h, &obj->network); + nm_hash_update_val (h, obj->plen); if (cmp_type == NM_PLATFORM_IP_ROUTE_CMP_TYPE_SEMANTICALLY) - nm_hash_update_val (&h, nm_utils_ip6_route_metric_normalize (obj->metric)); + nm_hash_update_val (h, nm_utils_ip6_route_metric_normalize (obj->metric)); else - nm_hash_update_val (&h, obj->metric); - nm_hash_update_in6addr (&h, &obj->gateway); - nm_hash_update_in6addr (&h, &obj->pref_src); + nm_hash_update_val (h, obj->metric); + nm_hash_update_in6addr (h, &obj->gateway); + nm_hash_update_in6addr (h, &obj->pref_src); if (cmp_type == NM_PLATFORM_IP_ROUTE_CMP_TYPE_SEMANTICALLY) { - nm_hash_update_in6addr_prefix (&h, &obj->src, obj->src_plen); - nm_hash_update_val (&h, obj->src_plen); - nm_hash_update_val (&h, nmp_utils_ip_config_source_round_trip_rtprot (obj->rt_source)); + nm_hash_update_in6addr_prefix (h, &obj->src, obj->src_plen); + nm_hash_update_val (h, obj->src_plen); + nm_hash_update_val (h, nmp_utils_ip_config_source_round_trip_rtprot (obj->rt_source)); } else { - nm_hash_update_in6addr (&h, &obj->src); - nm_hash_update_val (&h, obj->src_plen); - nm_hash_update_val (&h, obj->rt_source); + nm_hash_update_in6addr (h, &obj->src); + nm_hash_update_val (h, obj->src_plen); + nm_hash_update_val (h, obj->rt_source); } - nm_hash_update_val (&h, obj->mss); - nm_hash_update_bools (&h, obj->rt_cloned, - obj->lock_window, - obj->lock_cwnd, - obj->lock_initcwnd, - obj->lock_initrwnd, - obj->lock_mtu); - nm_hash_update_val (&h, obj->window); - nm_hash_update_val (&h, obj->cwnd); - nm_hash_update_val (&h, obj->initcwnd); - nm_hash_update_val (&h, obj->initrwnd); - nm_hash_update_val (&h, obj->mtu); + nm_hash_update_val (h, obj->mss); + nm_hash_update_bools (h, obj->rt_cloned, + obj->lock_window, + obj->lock_cwnd, + obj->lock_initcwnd, + obj->lock_initrwnd, + obj->lock_mtu); + nm_hash_update_val (h, obj->window); + nm_hash_update_val (h, obj->cwnd); + nm_hash_update_val (h, obj->initcwnd); + nm_hash_update_val (h, obj->initrwnd); + nm_hash_update_val (h, obj->mtu); if (cmp_type == NM_PLATFORM_IP_ROUTE_CMP_TYPE_SEMANTICALLY) - nm_hash_update_val (&h, _route_pref_normalize (obj->rt_pref)); + nm_hash_update_val (h, _route_pref_normalize (obj->rt_pref)); else - nm_hash_update_val (&h, obj->rt_pref); + nm_hash_update_val (h, obj->rt_pref); break; } } - return nm_hash_complete (&h); } int diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index ee08a40f4..b01c54447 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -1300,32 +1300,20 @@ nm_platform_ip6_route_cmp_full (const NMPlatformIP6Route *a, const NMPlatformIP6 return nm_platform_ip6_route_cmp (a, b, NM_PLATFORM_IP_ROUTE_CMP_TYPE_FULL); } -guint nm_platform_link_hash (const NMPlatformLink *obj); -guint nm_platform_ip4_address_hash (const NMPlatformIP4Address *obj); -guint nm_platform_ip6_address_hash (const NMPlatformIP6Address *obj); -guint nm_platform_ip4_route_hash (const NMPlatformIP4Route *obj, NMPlatformIPRouteCmpType cmp_type); -guint nm_platform_ip6_route_hash (const NMPlatformIP6Route *obj, NMPlatformIPRouteCmpType cmp_type); -guint nm_platform_lnk_gre_hash (const NMPlatformLnkGre *obj); -guint nm_platform_lnk_infiniband_hash (const NMPlatformLnkInfiniband *obj); -guint nm_platform_lnk_ip6tnl_hash (const NMPlatformLnkIp6Tnl *obj); -guint nm_platform_lnk_ipip_hash (const NMPlatformLnkIpIp *obj); -guint nm_platform_lnk_macsec_hash (const NMPlatformLnkMacsec *obj); -guint nm_platform_lnk_macvlan_hash (const NMPlatformLnkMacvlan *obj); -guint nm_platform_lnk_sit_hash (const NMPlatformLnkSit *obj); -guint nm_platform_lnk_vlan_hash (const NMPlatformLnkVlan *obj); -guint nm_platform_lnk_vxlan_hash (const NMPlatformLnkVxlan *obj); - -static inline guint -nm_platform_ip4_route_hash_full (const NMPlatformIP4Route *obj) -{ - return nm_platform_ip4_route_hash (obj, NM_PLATFORM_IP_ROUTE_CMP_TYPE_FULL); -} - -static inline guint -nm_platform_ip6_route_hash_full (const NMPlatformIP6Route *obj) -{ - return nm_platform_ip6_route_hash (obj, NM_PLATFORM_IP_ROUTE_CMP_TYPE_FULL); -} +void nm_platform_link_hash_update (const NMPlatformLink *obj, NMHashState *h); +void nm_platform_ip4_address_hash_update (const NMPlatformIP4Address *obj, NMHashState *h); +void nm_platform_ip6_address_hash_update (const NMPlatformIP6Address *obj, NMHashState *h); +void nm_platform_ip4_route_hash_update (const NMPlatformIP4Route *obj, NMPlatformIPRouteCmpType cmp_type, NMHashState *h); +void nm_platform_ip6_route_hash_update (const NMPlatformIP6Route *obj, NMPlatformIPRouteCmpType cmp_type, NMHashState *h); +void nm_platform_lnk_gre_hash_update (const NMPlatformLnkGre *obj, NMHashState *h); +void nm_platform_lnk_infiniband_hash_update (const NMPlatformLnkInfiniband *obj, NMHashState *h); +void nm_platform_lnk_ip6tnl_hash_update (const NMPlatformLnkIp6Tnl *obj, NMHashState *h); +void nm_platform_lnk_ipip_hash_update (const NMPlatformLnkIpIp *obj, NMHashState *h); +void nm_platform_lnk_macsec_hash_update (const NMPlatformLnkMacsec *obj, NMHashState *h); +void nm_platform_lnk_macvlan_hash_update (const NMPlatformLnkMacvlan *obj, NMHashState *h); +void nm_platform_lnk_sit_hash_update (const NMPlatformLnkSit *obj, NMHashState *h); +void nm_platform_lnk_vlan_hash_update (const NMPlatformLnkVlan *obj, NMHashState *h); +void nm_platform_lnk_vxlan_hash_update (const NMPlatformLnkVxlan *obj, NMHashState *h); NMPlatformKernelSupportFlags nm_platform_check_kernel_support (NMPlatform *self, NMPlatformKernelSupportFlags request_flags); diff --git a/src/platform/nmp-object.c b/src/platform/nmp-object.c index bec3f44a3..376bb24c3 100644 --- a/src/platform/nmp-object.c +++ b/src/platform/nmp-object.c @@ -86,16 +86,17 @@ struct _NMPCache { static const NMDedupMultiIdxTypeClass _dedup_multi_idx_type_class; -static guint -_idx_obj_id_hash (const NMDedupMultiIdxType *idx_type, - const NMDedupMultiObj *obj) +static void +_idx_obj_id_hash_update (const NMDedupMultiIdxType *idx_type, + const NMDedupMultiObj *obj, + NMHashState *h) { const NMPObject *o = (NMPObject *) obj; nm_assert (idx_type && idx_type->klass == &_dedup_multi_idx_type_class); nm_assert (NMP_OBJECT_GET_TYPE (o) != NMP_OBJECT_TYPE_UNKNOWN); - return nmp_object_id_hash (o); + nmp_object_id_hash_update (o, h); } static gboolean @@ -113,33 +114,11 @@ _idx_obj_id_equal (const NMDedupMultiIdxType *idx_type, return nmp_object_id_equal (o_a, o_b); } -/* the return value of _idx_obj_part() encodes 3 things: - * 1) for idx_obj_partitionable(), it returns 0 or non-zero. - * 2) for idx_obj_partition_hash(), it returns the hash value (which - * must never be zero not to clash with idx_obj_partitionable(). - * 3) for idx_obj_partition_equal(), returns 0 or 1 depending - * on whether the objects are equal. - * - * _HASH_NON_ZERO() is used to for case 2), to avoid that the a zero hash value - * is returned. - * - * Actually, nm_hash_complete() never returns zero. This code is only - * here as a safeguard and a reminder that the has MUST not be zero. */ -static inline guint -_HASH_NON_ZERO (NMHashState *h) -{ - guint v; - - v = nm_hash_complete (h); - nm_assert (v != 0); - return v; -} - static guint _idx_obj_part (const DedupMultiIdxType *idx_type, - gboolean request_hash, const NMPObject *obj_a, - const NMPObject *obj_b) + const NMPObject *obj_b, + NMHashState *h) { NMPObjectType obj_type; @@ -151,21 +130,17 @@ _idx_obj_part (const DedupMultiIdxType *idx_type, nm_assert (obj_a); nm_assert (NMP_OBJECT_GET_TYPE (obj_a) != NMP_OBJECT_TYPE_UNKNOWN); nm_assert (!obj_b || (NMP_OBJECT_GET_TYPE (obj_b) != NMP_OBJECT_TYPE_UNKNOWN)); - nm_assert (!request_hash || !obj_b); + nm_assert (!h || !obj_b); switch (idx_type->cache_id_type) { case NMP_CACHE_ID_TYPE_OBJECT_TYPE: if (obj_b) return NMP_OBJECT_GET_TYPE (obj_a) == NMP_OBJECT_GET_TYPE (obj_b); - if (request_hash) { - NMHashState h; - - nm_hash_init (&h, 487703243u); - nm_hash_update_vals (&h, + if (h) { + nm_hash_update_vals (h, idx_type->cache_id_type, NMP_OBJECT_GET_TYPE (obj_a)); - return _HASH_NON_ZERO (&h); } return 1; @@ -174,6 +149,8 @@ _idx_obj_part (const DedupMultiIdxType *idx_type, /* first check, whether obj_a is suitable for this idx_type. * If not, return 0 (which is correct for partitionable(), hash() and equal() * functions. */ + if (h) + nm_hash_update_val (h, obj_a); return 0; } if (obj_b) { @@ -181,14 +158,9 @@ _idx_obj_part (const DedupMultiIdxType *idx_type, return NMP_OBJECT_GET_TYPE (obj_b) == NMP_OBJECT_TYPE_LINK && nm_streq (obj_a->link.name, obj_b->link.name); } - if (request_hash) { - NMHashState h; - - /* we request a hash from obj_a. Hash the relevant parts. */ - nm_hash_init (&h, 2126752699u); - nm_hash_update_val (&h, idx_type->cache_id_type); - nm_hash_update_strarr (&h, obj_a->link.name); - return _HASH_NON_ZERO (&h); + if (h) { + nm_hash_update_val (h, idx_type->cache_id_type); + nm_hash_update_strarr (h, obj_a->link.name); } /* just return 1, to indicate that obj_a is partitionable by this idx_type. */ return 1; @@ -197,21 +169,20 @@ _idx_obj_part (const DedupMultiIdxType *idx_type, if ( !NM_IN_SET (NMP_OBJECT_GET_TYPE (obj_a), NMP_OBJECT_TYPE_IP4_ROUTE, NMP_OBJECT_TYPE_IP6_ROUTE) || !NM_PLATFORM_IP_ROUTE_IS_DEFAULT (&obj_a->ip_route) - || !nmp_object_is_visible (obj_a)) + || !nmp_object_is_visible (obj_a)) { + if (h) + nm_hash_update_val (h, obj_a); return 0; + } if (obj_b) { return NMP_OBJECT_GET_TYPE (obj_a) == NMP_OBJECT_GET_TYPE (obj_b) && NM_PLATFORM_IP_ROUTE_IS_DEFAULT (&obj_b->ip_route) && nmp_object_is_visible (obj_b); } - if (request_hash) { - NMHashState h; - - nm_hash_init (&h, 4278960223u); - nm_hash_update_vals (&h, + if (h) { + nm_hash_update_vals (h, idx_type->cache_id_type, NMP_OBJECT_GET_TYPE (obj_a)); - return _HASH_NON_ZERO (&h); } return 1; @@ -220,22 +191,21 @@ _idx_obj_part (const DedupMultiIdxType *idx_type, NMP_OBJECT_TYPE_IP6_ADDRESS, NMP_OBJECT_TYPE_IP4_ROUTE, NMP_OBJECT_TYPE_IP6_ROUTE) - || !nmp_object_is_visible (obj_a)) + || !nmp_object_is_visible (obj_a)) { + if (h) + nm_hash_update_val (h, obj_a); return 0; + } nm_assert (obj_a->object.ifindex > 0); if (obj_b) { return NMP_OBJECT_GET_TYPE (obj_a) == NMP_OBJECT_GET_TYPE (obj_b) && obj_a->object.ifindex == obj_b->object.ifindex && nmp_object_is_visible (obj_b); } - if (request_hash) { - NMHashState h; - - nm_hash_init (&h, 920415631u); - nm_hash_update_vals (&h, + if (h) { + nm_hash_update_vals (h, idx_type->cache_id_type, obj_a->object.ifindex); - return _HASH_NON_ZERO (&h); } return 1; @@ -243,8 +213,11 @@ _idx_obj_part (const DedupMultiIdxType *idx_type, obj_type = NMP_OBJECT_GET_TYPE (obj_a); if ( !NM_IN_SET (obj_type, NMP_OBJECT_TYPE_IP4_ROUTE, NMP_OBJECT_TYPE_IP6_ROUTE) - || obj_a->object.ifindex <= 0) + || obj_a->object.ifindex <= 0) { + if (h) + nm_hash_update_val (h, obj_a); return 0; + } if (obj_b) { return obj_type == NMP_OBJECT_GET_TYPE (obj_b) && obj_b->object.ifindex > 0 @@ -252,19 +225,12 @@ _idx_obj_part (const DedupMultiIdxType *idx_type, ? (nm_platform_ip4_route_cmp (&obj_a->ip4_route, &obj_b->ip4_route, NM_PLATFORM_IP_ROUTE_CMP_TYPE_WEAK_ID) == 0) : (nm_platform_ip6_route_cmp (&obj_a->ip6_route, &obj_b->ip6_route, NM_PLATFORM_IP_ROUTE_CMP_TYPE_WEAK_ID) == 0)); } - 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_vals (&h, - idx_type->cache_id_type, - h2); - return _HASH_NON_ZERO (&h); + if (h) { + nm_hash_update_val (h, idx_type->cache_id_type); + if (obj_type == NMP_OBJECT_TYPE_IP4_ROUTE) + nm_platform_ip4_route_hash_update (&obj_a->ip4_route, NM_PLATFORM_IP_ROUTE_CMP_TYPE_WEAK_ID, h); + else + nm_platform_ip6_route_hash_update (&obj_a->ip6_route, NM_PLATFORM_IP_ROUTE_CMP_TYPE_WEAK_ID, h); } return 1; @@ -281,19 +247,20 @@ _idx_obj_partitionable (const NMDedupMultiIdxType *idx_type, const NMDedupMultiObj *obj) { return _idx_obj_part ((DedupMultiIdxType *) idx_type, - FALSE, (NMPObject *) obj, + NULL, NULL) != 0; } -static guint -_idx_obj_partition_hash (const NMDedupMultiIdxType *idx_type, - const NMDedupMultiObj *obj) +static void +_idx_obj_partition_hash_update (const NMDedupMultiIdxType *idx_type, + const NMDedupMultiObj *obj, + NMHashState *h) { - return _idx_obj_part ((DedupMultiIdxType *) idx_type, - TRUE, - (NMPObject *) obj, - NULL); + _idx_obj_part ((DedupMultiIdxType *) idx_type, + (NMPObject *) obj, + NULL, + h); } static gboolean @@ -302,16 +269,16 @@ _idx_obj_partition_equal (const NMDedupMultiIdxType *idx_type, const NMDedupMultiObj *obj_b) { return _idx_obj_part ((DedupMultiIdxType *) idx_type, - FALSE, (NMPObject *) obj_a, - (NMPObject *) obj_b); + (NMPObject *) obj_b, + NULL); } static const NMDedupMultiIdxTypeClass _dedup_multi_idx_type_class = { - .idx_obj_id_hash = _idx_obj_id_hash, + .idx_obj_id_hash_update = _idx_obj_id_hash_update, .idx_obj_id_equal = _idx_obj_id_equal, .idx_obj_partitionable = _idx_obj_partitionable, - .idx_obj_partition_hash = _idx_obj_partition_hash, + .idx_obj_partition_hash_update = _idx_obj_partition_hash_update, .idx_obj_partition_equal = _idx_obj_partition_equal, }; @@ -771,63 +738,48 @@ _vt_cmd_plobj_to_string_id (ip4_address, NMPlatformIP4Address, "%d: %s/%d%s%s", obj->peer_address != obj->address ? nm_utils_inet4_ntop (nm_utils_ip4_address_clear_host_address (obj->peer_address, obj->plen), buf2) : ""); _vt_cmd_plobj_to_string_id (ip6_address, NMPlatformIP6Address, "%d: %s", obj->ifindex, nm_utils_inet6_ntop (&obj->address, buf1)); -guint -nmp_object_hash (const NMPObject *obj) +void +nmp_object_hash_update (const NMPObject *obj, NMHashState *h) { const NMPClass *klass; - NMHashState h; - if (!obj) - return 0; - - g_return_val_if_fail (NMP_OBJECT_IS_VALID (obj), 0); + g_return_if_fail (NMP_OBJECT_IS_VALID (obj)); klass = NMP_OBJECT_GET_CLASS (obj); - nm_hash_init (&h, 816200863u); - nm_hash_update_val (&h, klass->obj_type); - if (klass->cmd_obj_hash) - nm_hash_update_val (&h, klass->cmd_obj_hash (obj)); - else if (klass->cmd_plobj_hash) - nm_hash_update_val (&h, klass->cmd_plobj_hash (&obj->object)); + nm_hash_update_val (h, klass->obj_type); + if (klass->cmd_obj_hash_update) + klass->cmd_obj_hash_update (obj, h); + else if (klass->cmd_plobj_hash_update) + klass->cmd_plobj_hash_update (&obj->object, h); else - nm_hash_update_val (&h, obj); - - return nm_hash_complete (&h); + nm_hash_update_val (h, obj); } -static guint -_vt_cmd_obj_hash_link (const NMPObject *obj) +static void +_vt_cmd_obj_hash_update_link (const NMPObject *obj, NMHashState *h) { - NMHashState h; - nm_assert (NMP_OBJECT_GET_TYPE (obj) == NMP_OBJECT_TYPE_LINK); - nm_hash_init (&h, 3448776161u); - nm_hash_update_val (&h, nm_platform_link_hash (&obj->link)); - nm_hash_update_val (&h, obj->_link.netlink.is_in_netlink); + nm_platform_link_hash_update (&obj->link, h); + nm_hash_update_val (h, obj->_link.netlink.is_in_netlink); if (obj->_link.netlink.lnk) - 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); + nmp_object_hash_update (obj->_link.netlink.lnk, h); + nm_hash_update_val (h, obj->_link.udev.device); } -static guint -_vt_cmd_obj_hash_lnk_vlan (const NMPObject *obj) +static void +_vt_cmd_obj_hash_update_lnk_vlan (const NMPObject *obj, NMHashState *h) { - NMHashState h; - nm_assert (NMP_OBJECT_GET_TYPE (obj) == NMP_OBJECT_TYPE_LNK_VLAN); - nm_hash_init (&h, 914932607u); - nm_hash_update_val (&h, nm_platform_lnk_vlan_hash (&obj->lnk_vlan)); + nm_platform_lnk_vlan_hash_update (&obj->lnk_vlan, h); _vlan_xgress_qos_mappings_hash_update (obj->_lnk_vlan.n_ingress_qos_map, obj->_lnk_vlan.ingress_qos_map, - &h); + h); _vlan_xgress_qos_mappings_hash_update (obj->_lnk_vlan.n_egress_qos_map, obj->_lnk_vlan.egress_qos_map, - &h); - return nm_hash_complete (&h); + h); } int @@ -1033,7 +985,7 @@ nmp_object_id_cmp (const NMPObject *obj1, const NMPObject *obj2) g_return_val_if_fail (NMP_OBJECT_IS_VALID (obj2), FALSE); klass = NMP_OBJECT_GET_CLASS (obj1); - nm_assert (!klass->cmd_plobj_id_hash == !klass->cmd_plobj_id_cmp); + nm_assert (!klass->cmd_plobj_id_hash_update == !klass->cmd_plobj_id_cmp); klass2 = NMP_OBJECT_GET_CLASS (obj2); nm_assert (klass); @@ -1095,63 +1047,84 @@ _vt_cmd_plobj_id_cmp_ip6_route (const NMPlatformObject *obj1, const NMPlatformOb return nm_platform_ip6_route_cmp ((NMPlatformIP6Route *) obj1, (NMPlatformIP6Route *) obj2, NM_PLATFORM_IP_ROUTE_CMP_TYPE_ID); } +void +nmp_object_id_hash_update (const NMPObject *obj, NMHashState *h) +{ + const NMPClass *klass; + + g_return_if_fail (NMP_OBJECT_IS_VALID (obj)); + + klass = NMP_OBJECT_GET_CLASS (obj); + + nm_assert (!klass->cmd_plobj_id_hash_update == !klass->cmd_plobj_id_cmp); + + if (!klass->cmd_plobj_id_hash_update) { + /* The klass doesn't implement ID compare. It means, to use pointer + * equality. */ + nm_hash_update_val (h, obj); + return; + } + + nm_hash_update_val (h, klass->obj_type); + klass->cmd_plobj_id_hash_update (&obj->object, h); +} + guint nmp_object_id_hash (const NMPObject *obj) { - const NMPClass *klass; + NMHashState h; if (!obj) return 0; - g_return_val_if_fail (NMP_OBJECT_IS_VALID (obj), 0); - - klass = NMP_OBJECT_GET_CLASS (obj); - - nm_assert (!klass->cmd_plobj_id_hash == !klass->cmd_plobj_id_cmp); - - if (!klass->cmd_plobj_id_hash) { - /* The klass doesn't implement ID compare. It means, to use pointer - * equality. */ - return nm_hash_ptr (obj); - } - - return klass->cmd_plobj_id_hash (&obj->object); + nm_hash_init (&h, 914932607u); + nmp_object_id_hash_update (obj, &h); + return nm_hash_complete (&h); } -#define _vt_cmd_plobj_id_hash(type, plat_type, hash_seed, cmd) \ -static guint \ -_vt_cmd_plobj_id_hash_##type (const NMPlatformObject *_obj) \ +#define _vt_cmd_plobj_id_hash_update(type, plat_type, cmd) \ +static void \ +_vt_cmd_plobj_id_hash_update_##type (const NMPlatformObject *_obj, NMHashState *h) \ { \ const plat_type *const obj = (const plat_type *) _obj; \ - NMHashState h; \ - nm_hash_init (&h, (hash_seed)); \ { cmd; } \ - return nm_hash_complete (&h); \ } -_vt_cmd_plobj_id_hash (link, NMPlatformLink, 3982791431u, { - nm_hash_update_val (&h, obj->ifindex); +_vt_cmd_plobj_id_hash_update (link, NMPlatformLink, { + nm_hash_update_val (h, obj->ifindex); }) -_vt_cmd_plobj_id_hash (ip4_address, NMPlatformIP4Address, 3591309853u, { - nm_hash_update_vals (&h, +_vt_cmd_plobj_id_hash_update (ip4_address, NMPlatformIP4Address, { + 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_vals (&h, +_vt_cmd_plobj_id_hash_update (ip6_address, NMPlatformIP6Address, { + 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_val (&h, nm_platform_ip4_route_hash (obj, NM_PLATFORM_IP_ROUTE_CMP_TYPE_ID)); +_vt_cmd_plobj_id_hash_update (ip4_route, NMPlatformIP4Route, { + nm_platform_ip4_route_hash_update (obj, NM_PLATFORM_IP_ROUTE_CMP_TYPE_ID, h); }) -_vt_cmd_plobj_id_hash (ip6_route, NMPlatformIP6Route, 1233384151u, { - nm_hash_update_val (&h, nm_platform_ip6_route_hash (obj, NM_PLATFORM_IP_ROUTE_CMP_TYPE_ID)); +_vt_cmd_plobj_id_hash_update (ip6_route, NMPlatformIP6Route, { + nm_platform_ip6_route_hash_update (obj, NM_PLATFORM_IP_ROUTE_CMP_TYPE_ID, h); }) +static inline void +_vt_cmd_plobj_hash_update_ip4_route (const NMPlatformObject *obj, NMHashState *h) +{ + return nm_platform_ip4_route_hash_update ((const NMPlatformIP4Route *) obj, NM_PLATFORM_IP_ROUTE_CMP_TYPE_FULL, h); +} + +static inline void +_vt_cmd_plobj_hash_update_ip6_route (const NMPlatformObject *obj, NMHashState *h) +{ + return nm_platform_ip6_route_hash_update ((const NMPlatformIP6Route *) obj, NM_PLATFORM_IP_ROUTE_CMP_TYPE_FULL, h); +} + gboolean nmp_object_is_alive (const NMPObject *obj) { @@ -1271,26 +1244,12 @@ _vt_dedup_obj_clone (const NMDedupMultiObj *obj) return (const NMDedupMultiObj *) nmp_object_clone ((const NMPObject *) obj, FALSE); } -static guint -_vt_dedup_obj_full_hash (const NMDedupMultiObj *obj) -{ - return nmp_object_hash ((NMPObject *) obj); -} - -static gboolean -_vt_dedup_obj_full_equal (const NMDedupMultiObj *obj_a, - const NMDedupMultiObj *obj_b) -{ - return nmp_object_equal ((NMPObject *) obj_a, - (NMPObject *) obj_b); -} - #define DEDUP_MULTI_OBJ_CLASS_INIT() \ { \ .obj_clone = _vt_dedup_obj_clone, \ .obj_destroy = _vt_dedup_obj_destroy, \ - .obj_full_hash = _vt_dedup_obj_full_hash, \ - .obj_full_equal = _vt_dedup_obj_full_equal, \ + .obj_full_hash_update = (void (*)(const NMDedupMultiObj *obj, NMHashState *h)) nmp_object_hash_update, \ + .obj_full_equal = (gboolean (*)(const NMDedupMultiObj *obj_a, const NMDedupMultiObj *obj_b)) nmp_object_equal, \ } /*****************************************************************************/ @@ -1523,7 +1482,6 @@ _L (const NMPLookup *lookup) nm_assert (lookup); _dedup_multi_idx_type_init (&idx_type, lookup->cache_id_type); nm_assert (idx_type.parent.klass->idx_obj_partitionable ((NMDedupMultiIdxType *) &idx_type, (NMDedupMultiObj *) &lookup->selector_obj)); - nm_assert (idx_type.parent.klass->idx_obj_partition_hash ((NMDedupMultiIdxType *) &idx_type, (NMDedupMultiObj *) &lookup->selector_obj) > 0); #endif return lookup; } @@ -2515,7 +2473,7 @@ const NMPClass _nmp_classes[NMP_OBJECT_TYPE_MAX] = { .signal_type_id = NM_PLATFORM_SIGNAL_ID_LINK, .signal_type = NM_PLATFORM_SIGNAL_LINK_CHANGED, .supported_cache_ids = _supported_cache_ids_link, - .cmd_obj_hash = _vt_cmd_obj_hash_link, + .cmd_obj_hash_update = _vt_cmd_obj_hash_update_link, .cmd_obj_cmp = _vt_cmd_obj_cmp_link, .cmd_obj_copy = _vt_cmd_obj_copy_link, .cmd_obj_dispose = _vt_cmd_obj_dispose_link, @@ -2524,10 +2482,10 @@ const NMPClass _nmp_classes[NMP_OBJECT_TYPE_MAX] = { .cmd_obj_to_string = _vt_cmd_obj_to_string_link, .cmd_plobj_id_copy = _vt_cmd_plobj_id_copy_link, .cmd_plobj_id_cmp = _vt_cmd_plobj_id_cmp_link, - .cmd_plobj_id_hash = _vt_cmd_plobj_id_hash_link, + .cmd_plobj_id_hash_update = _vt_cmd_plobj_id_hash_update_link, .cmd_plobj_to_string_id = _vt_cmd_plobj_to_string_id_link, .cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj, char *buf, gsize len)) nm_platform_link_to_string, - .cmd_plobj_hash = (guint (*) (const NMPlatformObject *obj)) nm_platform_link_hash, + .cmd_plobj_hash_update = (void (*) (const NMPlatformObject *obj, NMHashState *h)) nm_platform_link_hash_update, .cmd_plobj_cmp = (int (*) (const NMPlatformObject *obj1, const NMPlatformObject *obj2)) nm_platform_link_cmp, }, [NMP_OBJECT_TYPE_IP4_ADDRESS - 1] = { @@ -2544,10 +2502,10 @@ const NMPClass _nmp_classes[NMP_OBJECT_TYPE_MAX] = { .cmd_obj_is_alive = _vt_cmd_obj_is_alive_ipx_address, .cmd_plobj_id_copy = _vt_cmd_plobj_id_copy_ip4_address, .cmd_plobj_id_cmp = _vt_cmd_plobj_id_cmp_ip4_address, - .cmd_plobj_id_hash = _vt_cmd_plobj_id_hash_ip4_address, + .cmd_plobj_id_hash_update = _vt_cmd_plobj_id_hash_update_ip4_address, .cmd_plobj_to_string_id = _vt_cmd_plobj_to_string_id_ip4_address, .cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj, char *buf, gsize len)) nm_platform_ip4_address_to_string, - .cmd_plobj_hash = (guint (*) (const NMPlatformObject *obj)) nm_platform_ip4_address_hash, + .cmd_plobj_hash_update = (void (*) (const NMPlatformObject *obj, NMHashState *h)) nm_platform_ip4_address_hash_update, .cmd_plobj_cmp = (int (*) (const NMPlatformObject *obj1, const NMPlatformObject *obj2)) nm_platform_ip4_address_cmp, }, [NMP_OBJECT_TYPE_IP6_ADDRESS - 1] = { @@ -2564,10 +2522,10 @@ const NMPClass _nmp_classes[NMP_OBJECT_TYPE_MAX] = { .cmd_obj_is_alive = _vt_cmd_obj_is_alive_ipx_address, .cmd_plobj_id_copy = _vt_cmd_plobj_id_copy_ip6_address, .cmd_plobj_id_cmp = _vt_cmd_plobj_id_cmp_ip6_address, - .cmd_plobj_id_hash = _vt_cmd_plobj_id_hash_ip6_address, + .cmd_plobj_id_hash_update = _vt_cmd_plobj_id_hash_update_ip6_address, .cmd_plobj_to_string_id = _vt_cmd_plobj_to_string_id_ip6_address, .cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj, char *buf, gsize len)) nm_platform_ip6_address_to_string, - .cmd_plobj_hash = (guint (*) (const NMPlatformObject *obj)) nm_platform_ip6_address_hash, + .cmd_plobj_hash_update = (void (*) (const NMPlatformObject *obj, NMHashState *h)) nm_platform_ip6_address_hash_update, .cmd_plobj_cmp = (int (*) (const NMPlatformObject *obj1, const NMPlatformObject *obj2)) nm_platform_ip6_address_cmp }, [NMP_OBJECT_TYPE_IP4_ROUTE - 1] = { @@ -2584,10 +2542,10 @@ const NMPClass _nmp_classes[NMP_OBJECT_TYPE_MAX] = { .cmd_obj_is_alive = _vt_cmd_obj_is_alive_ipx_route, .cmd_plobj_id_copy = _vt_cmd_plobj_id_copy_ip4_route, .cmd_plobj_id_cmp = _vt_cmd_plobj_id_cmp_ip4_route, - .cmd_plobj_id_hash = _vt_cmd_plobj_id_hash_ip4_route, + .cmd_plobj_id_hash_update = _vt_cmd_plobj_id_hash_update_ip4_route, .cmd_plobj_to_string_id = (const char *(*) (const NMPlatformObject *obj, char *buf, gsize len)) nm_platform_ip4_route_to_string, .cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj, char *buf, gsize len)) nm_platform_ip4_route_to_string, - .cmd_plobj_hash = (guint (*) (const NMPlatformObject *obj)) nm_platform_ip4_route_hash_full, + .cmd_plobj_hash_update = _vt_cmd_plobj_hash_update_ip4_route, .cmd_plobj_cmp = (int (*) (const NMPlatformObject *obj1, const NMPlatformObject *obj2)) nm_platform_ip4_route_cmp_full, }, [NMP_OBJECT_TYPE_IP6_ROUTE - 1] = { @@ -2604,10 +2562,10 @@ const NMPClass _nmp_classes[NMP_OBJECT_TYPE_MAX] = { .cmd_obj_is_alive = _vt_cmd_obj_is_alive_ipx_route, .cmd_plobj_id_copy = _vt_cmd_plobj_id_copy_ip6_route, .cmd_plobj_id_cmp = _vt_cmd_plobj_id_cmp_ip6_route, - .cmd_plobj_id_hash = _vt_cmd_plobj_id_hash_ip6_route, + .cmd_plobj_id_hash_update = _vt_cmd_plobj_id_hash_update_ip6_route, .cmd_plobj_to_string_id = (const char *(*) (const NMPlatformObject *obj, char *buf, gsize len)) nm_platform_ip6_route_to_string, .cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj, char *buf, gsize len)) nm_platform_ip6_route_to_string, - .cmd_plobj_hash = (guint (*) (const NMPlatformObject *obj)) nm_platform_ip6_route_hash_full, + .cmd_plobj_hash_update = _vt_cmd_plobj_hash_update_ip6_route, .cmd_plobj_cmp = (int (*) (const NMPlatformObject *obj1, const NMPlatformObject *obj2)) nm_platform_ip6_route_cmp_full, }, [NMP_OBJECT_TYPE_LNK_GRE - 1] = { @@ -2618,7 +2576,7 @@ const NMPClass _nmp_classes[NMP_OBJECT_TYPE_MAX] = { .obj_type_name = "gre", .lnk_link_type = NM_LINK_TYPE_GRE, .cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj, char *buf, gsize len)) nm_platform_lnk_gre_to_string, - .cmd_plobj_hash = (guint (*) (const NMPlatformObject *obj)) nm_platform_lnk_gre_hash, + .cmd_plobj_hash_update = (void (*) (const NMPlatformObject *obj, NMHashState *h)) nm_platform_lnk_gre_hash_update, .cmd_plobj_cmp = (int (*) (const NMPlatformObject *obj1, const NMPlatformObject *obj2)) nm_platform_lnk_gre_cmp, }, [NMP_OBJECT_TYPE_LNK_INFINIBAND - 1] = { @@ -2629,7 +2587,7 @@ const NMPClass _nmp_classes[NMP_OBJECT_TYPE_MAX] = { .obj_type_name = "infiniband", .lnk_link_type = NM_LINK_TYPE_INFINIBAND, .cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj, char *buf, gsize len)) nm_platform_lnk_infiniband_to_string, - .cmd_plobj_hash = (guint (*) (const NMPlatformObject *obj)) nm_platform_lnk_infiniband_hash, + .cmd_plobj_hash_update = (void (*) (const NMPlatformObject *obj, NMHashState *h)) nm_platform_lnk_infiniband_hash_update, .cmd_plobj_cmp = (int (*) (const NMPlatformObject *obj1, const NMPlatformObject *obj2)) nm_platform_lnk_infiniband_cmp, }, [NMP_OBJECT_TYPE_LNK_IP6TNL - 1] = { @@ -2640,7 +2598,7 @@ const NMPClass _nmp_classes[NMP_OBJECT_TYPE_MAX] = { .obj_type_name = "ip6tnl", .lnk_link_type = NM_LINK_TYPE_IP6TNL, .cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj, char *buf, gsize len)) nm_platform_lnk_ip6tnl_to_string, - .cmd_plobj_hash = (guint (*) (const NMPlatformObject *obj)) nm_platform_lnk_ip6tnl_hash, + .cmd_plobj_hash_update = (void (*) (const NMPlatformObject *obj, NMHashState *h)) nm_platform_lnk_ip6tnl_hash_update, .cmd_plobj_cmp = (int (*) (const NMPlatformObject *obj1, const NMPlatformObject *obj2)) nm_platform_lnk_ip6tnl_cmp, }, [NMP_OBJECT_TYPE_LNK_IPIP - 1] = { @@ -2651,7 +2609,7 @@ const NMPClass _nmp_classes[NMP_OBJECT_TYPE_MAX] = { .obj_type_name = "ipip", .lnk_link_type = NM_LINK_TYPE_IPIP, .cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj, char *buf, gsize len)) nm_platform_lnk_ipip_to_string, - .cmd_plobj_hash = (guint (*) (const NMPlatformObject *obj)) nm_platform_lnk_ipip_hash, + .cmd_plobj_hash_update = (void (*) (const NMPlatformObject *obj, NMHashState *h)) nm_platform_lnk_ipip_hash_update, .cmd_plobj_cmp = (int (*) (const NMPlatformObject *obj1, const NMPlatformObject *obj2)) nm_platform_lnk_ipip_cmp, }, [NMP_OBJECT_TYPE_LNK_MACSEC - 1] = { @@ -2662,7 +2620,7 @@ const NMPClass _nmp_classes[NMP_OBJECT_TYPE_MAX] = { .obj_type_name = "macsec", .lnk_link_type = NM_LINK_TYPE_MACSEC, .cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj, char *buf, gsize len)) nm_platform_lnk_macsec_to_string, - .cmd_plobj_hash = (guint (*) (const NMPlatformObject *obj)) nm_platform_lnk_macsec_hash, + .cmd_plobj_hash_update = (void (*) (const NMPlatformObject *obj, NMHashState *h)) nm_platform_lnk_macsec_hash_update, .cmd_plobj_cmp = (int (*) (const NMPlatformObject *obj1, const NMPlatformObject *obj2)) nm_platform_lnk_macsec_cmp, }, [NMP_OBJECT_TYPE_LNK_MACVLAN - 1] = { @@ -2673,7 +2631,7 @@ const NMPClass _nmp_classes[NMP_OBJECT_TYPE_MAX] = { .obj_type_name = "macvlan", .lnk_link_type = NM_LINK_TYPE_MACVLAN, .cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj, char *buf, gsize len)) nm_platform_lnk_macvlan_to_string, - .cmd_plobj_hash = (guint (*) (const NMPlatformObject *obj)) nm_platform_lnk_macvlan_hash, + .cmd_plobj_hash_update = (void (*) (const NMPlatformObject *obj, NMHashState *h)) nm_platform_lnk_macvlan_hash_update, .cmd_plobj_cmp = (int (*) (const NMPlatformObject *obj1, const NMPlatformObject *obj2)) nm_platform_lnk_macvlan_cmp, }, [NMP_OBJECT_TYPE_LNK_MACVTAP - 1] = { @@ -2684,7 +2642,7 @@ const NMPClass _nmp_classes[NMP_OBJECT_TYPE_MAX] = { .obj_type_name = "macvtap", .lnk_link_type = NM_LINK_TYPE_MACVTAP, .cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj, char *buf, gsize len)) nm_platform_lnk_macvlan_to_string, - .cmd_plobj_hash = (guint (*) (const NMPlatformObject *obj)) nm_platform_lnk_macvlan_hash, + .cmd_plobj_hash_update = (void (*) (const NMPlatformObject *obj, NMHashState *h)) nm_platform_lnk_macvlan_hash_update, .cmd_plobj_cmp = (int (*) (const NMPlatformObject *obj1, const NMPlatformObject *obj2)) nm_platform_lnk_macvlan_cmp, }, [NMP_OBJECT_TYPE_LNK_SIT - 1] = { @@ -2695,7 +2653,7 @@ const NMPClass _nmp_classes[NMP_OBJECT_TYPE_MAX] = { .obj_type_name = "sit", .lnk_link_type = NM_LINK_TYPE_SIT, .cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj, char *buf, gsize len)) nm_platform_lnk_sit_to_string, - .cmd_plobj_hash = (guint (*) (const NMPlatformObject *obj)) nm_platform_lnk_sit_hash, + .cmd_plobj_hash_update = (void (*) (const NMPlatformObject *obj, NMHashState *h)) nm_platform_lnk_sit_hash_update, .cmd_plobj_cmp = (int (*) (const NMPlatformObject *obj1, const NMPlatformObject *obj2)) nm_platform_lnk_sit_cmp, }, [NMP_OBJECT_TYPE_LNK_VLAN - 1] = { @@ -2705,13 +2663,13 @@ const NMPClass _nmp_classes[NMP_OBJECT_TYPE_MAX] = { .sizeof_public = sizeof (NMPlatformLnkVlan), .obj_type_name = "vlan", .lnk_link_type = NM_LINK_TYPE_VLAN, - .cmd_obj_hash = _vt_cmd_obj_hash_lnk_vlan, + .cmd_obj_hash_update = _vt_cmd_obj_hash_update_lnk_vlan, .cmd_obj_cmp = _vt_cmd_obj_cmp_lnk_vlan, .cmd_obj_copy = _vt_cmd_obj_copy_lnk_vlan, .cmd_obj_dispose = _vt_cmd_obj_dispose_lnk_vlan, .cmd_obj_to_string = _vt_cmd_obj_to_string_lnk_vlan, .cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj, char *buf, gsize len)) nm_platform_lnk_vlan_to_string, - .cmd_plobj_hash = (guint (*) (const NMPlatformObject *obj)) nm_platform_lnk_vlan_hash, + .cmd_plobj_hash_update = (void (*) (const NMPlatformObject *obj, NMHashState *h)) nm_platform_lnk_vlan_hash_update, .cmd_plobj_cmp = (int (*) (const NMPlatformObject *obj1, const NMPlatformObject *obj2)) nm_platform_lnk_vlan_cmp, }, [NMP_OBJECT_TYPE_LNK_VXLAN - 1] = { @@ -2722,7 +2680,7 @@ const NMPClass _nmp_classes[NMP_OBJECT_TYPE_MAX] = { .obj_type_name = "vxlan", .lnk_link_type = NM_LINK_TYPE_VXLAN, .cmd_plobj_to_string = (const char *(*) (const NMPlatformObject *obj, char *buf, gsize len)) nm_platform_lnk_vxlan_to_string, - .cmd_plobj_hash = (guint (*) (const NMPlatformObject *obj)) nm_platform_lnk_vxlan_hash, + .cmd_plobj_hash_update = (void (*) (const NMPlatformObject *obj, NMHashState *h)) nm_platform_lnk_vxlan_hash_update, .cmd_plobj_cmp = (int (*) (const NMPlatformObject *obj1, const NMPlatformObject *obj2)) nm_platform_lnk_vxlan_cmp, }, }; diff --git a/src/platform/nmp-object.h b/src/platform/nmp-object.h index 48c27fa12..41fd08cb7 100644 --- a/src/platform/nmp-object.h +++ b/src/platform/nmp-object.h @@ -115,7 +115,7 @@ typedef struct { /* Only for NMPObjectLnk* types. */ NMLinkType lnk_link_type; - guint (*cmd_obj_hash) (const NMPObject *obj); + void (*cmd_obj_hash_update) (const NMPObject *obj, NMHashState *h); int (*cmd_obj_cmp) (const NMPObject *obj1, const NMPObject *obj2); void (*cmd_obj_copy) (NMPObject *dst, const NMPObject *src); void (*cmd_obj_dispose) (NMPObject *obj); @@ -126,10 +126,10 @@ typedef struct { /* functions that operate on NMPlatformObject */ void (*cmd_plobj_id_copy) (NMPlatformObject *dst, const NMPlatformObject *src); int (*cmd_plobj_id_cmp) (const NMPlatformObject *obj1, const NMPlatformObject *obj2); - guint (*cmd_plobj_id_hash) (const NMPlatformObject *obj); + void (*cmd_plobj_id_hash_update) (const NMPlatformObject *obj, NMHashState *h); const char *(*cmd_plobj_to_string_id) (const NMPlatformObject *obj, char *buf, gsize buf_size); const char *(*cmd_plobj_to_string) (const NMPlatformObject *obj, char *buf, gsize len); - guint (*cmd_plobj_hash) (const NMPlatformObject *obj); + void (*cmd_plobj_hash_update) (const NMPlatformObject *obj, NMHashState *h); int (*cmd_plobj_cmp) (const NMPlatformObject *obj1, const NMPlatformObject *obj2); } NMPClass; @@ -469,13 +469,14 @@ const NMPObject *nmp_object_stackinit_id_ip4_address (NMPObject *obj, int ifinde const NMPObject *nmp_object_stackinit_id_ip6_address (NMPObject *obj, int ifindex, const struct in6_addr *address); const char *nmp_object_to_string (const NMPObject *obj, NMPObjectToStringMode to_string_mode, char *buf, gsize buf_size); -guint nmp_object_hash (const NMPObject *obj); +void nmp_object_hash_update (const NMPObject *obj, NMHashState *h); int nmp_object_cmp (const NMPObject *obj1, const NMPObject *obj2); gboolean nmp_object_equal (const NMPObject *obj1, const NMPObject *obj2); void nmp_object_copy (NMPObject *dst, const NMPObject *src, gboolean id_only); NMPObject *nmp_object_clone (const NMPObject *obj, gboolean id_only); int nmp_object_id_cmp (const NMPObject *obj1, const NMPObject *obj2); +void nmp_object_id_hash_update (const NMPObject *obj, NMHashState *h); guint nmp_object_id_hash (const NMPObject *obj); static inline gboolean