Commit 6d9c3eab authored by Thomas Haller's avatar Thomas Haller

platform: let NMPObject implement NMDedupIndexObj

parent f9202c2a
......@@ -190,6 +190,19 @@ nm_utils_exp10 (gint16 ex)
/*****************************************************************************/
guint
nm_utils_in6_addr_hash (const struct in6_addr *addr)
{
guint hash = (guint) 0x897da53981a13ULL;
int i;
for (i = 0; i < sizeof (*addr); i++)
hash = NM_HASH_COMBINE (hash, ((const guint8 *) addr)[i]);
return hash;
}
/*****************************************************************************/
/*
* nm_ethernet_address_is_valid:
* @addr: pointer to a binary or ASCII Ethernet address
......
......@@ -109,6 +109,8 @@ extern const NMIPAddr nm_ip_addr_zero;
/*****************************************************************************/
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);
......
......@@ -4290,6 +4290,26 @@ nm_platform_lnk_vxlan_cmp (const NMPlatformLnkVxlan *a, const NMPlatformLnkVxlan
return 0;
}
guint
nm_platform_ip4_address_hash (const NMPlatformIP4Address *obj)
{
guint h = 469681301;
if (obj) {
h = NM_HASH_COMBINE (h, obj->ifindex);
h = NM_HASH_COMBINE (h, obj->address);
h = NM_HASH_COMBINE (h, obj->plen);
h = NM_HASH_COMBINE (h, obj->peer_address);
h = NM_HASH_COMBINE (h, obj->addr_source);
h = NM_HASH_COMBINE (h, obj->timestamp);
h = NM_HASH_COMBINE (h, obj->lifetime);
h = NM_HASH_COMBINE (h, obj->preferred);
h = NM_HASH_COMBINE (h, obj->n_ifa_flags);
h = NM_HASH_COMBINE (h, g_str_hash (obj->label));
}
return h;
}
int
nm_platform_ip4_address_cmp (const NMPlatformIP4Address *a, const NMPlatformIP4Address *b)
{
......@@ -4307,6 +4327,25 @@ nm_platform_ip4_address_cmp (const NMPlatformIP4Address *a, const NMPlatformIP4A
return 0;
}
guint
nm_platform_ip6_address_hash (const NMPlatformIP6Address *obj)
{
guint h = 605908909;
if (obj) {
h = NM_HASH_COMBINE (h, obj->ifindex);
h = NM_HASH_COMBINE (h, nm_utils_in6_addr_hash (&obj->address));
h = NM_HASH_COMBINE (h, obj->plen);
h = NM_HASH_COMBINE (h, nm_utils_in6_addr_hash (&obj->peer_address));
h = NM_HASH_COMBINE (h, obj->addr_source);
h = NM_HASH_COMBINE (h, obj->timestamp);
h = NM_HASH_COMBINE (h, obj->lifetime);
h = NM_HASH_COMBINE (h, obj->preferred);
h = NM_HASH_COMBINE (h, obj->n_ifa_flags);
}
return h;
}
int
nm_platform_ip6_address_cmp (const NMPlatformIP6Address *a, const NMPlatformIP6Address *b)
{
......@@ -4327,6 +4366,37 @@ nm_platform_ip6_address_cmp (const NMPlatformIP6Address *a, const NMPlatformIP6A
return 0;
}
guint
nm_platform_ip4_route_hash (const NMPlatformIP4Route *obj)
{
guint h = 1228913327;
if (obj) {
h = NM_HASH_COMBINE (h, obj->ifindex);
h = NM_HASH_COMBINE (h, obj->network);
h = NM_HASH_COMBINE (h, obj->plen);
h = NM_HASH_COMBINE (h, obj->metric);
h = NM_HASH_COMBINE (h, obj->gateway);
h = NM_HASH_COMBINE (h, obj->rt_source);
h = NM_HASH_COMBINE (h, obj->mss);
h = NM_HASH_COMBINE (h, obj->scope_inv);
h = NM_HASH_COMBINE (h, obj->pref_src);
h = NM_HASH_COMBINE (h, obj->rt_cloned);
h = NM_HASH_COMBINE (h, obj->tos);
h = NM_HASH_COMBINE (h, obj->lock_window);
h = NM_HASH_COMBINE (h, obj->lock_cwnd);
h = NM_HASH_COMBINE (h, obj->lock_initcwnd);
h = NM_HASH_COMBINE (h, obj->lock_initrwnd);
h = NM_HASH_COMBINE (h, obj->lock_mtu);
h = NM_HASH_COMBINE (h, obj->window);
h = NM_HASH_COMBINE (h, obj->cwnd);
h = NM_HASH_COMBINE (h, obj->initcwnd);
h = NM_HASH_COMBINE (h, obj->initrwnd);
h = NM_HASH_COMBINE (h, obj->mtu);
}
return h;
}
int
nm_platform_ip4_route_cmp_full (const NMPlatformIP4Route *a, const NMPlatformIP4Route *b, gboolean consider_host_part)
{
......@@ -4360,6 +4430,38 @@ nm_platform_ip4_route_cmp_full (const NMPlatformIP4Route *a, const NMPlatformIP4
return 0;
}
guint
nm_platform_ip6_route_hash (const NMPlatformIP6Route *obj)
{
guint h = 1053326051;
if (obj) {
h = NM_HASH_COMBINE (h, obj->ifindex);
h = NM_HASH_COMBINE (h, nm_utils_in6_addr_hash (&obj->network));
h = NM_HASH_COMBINE (h, obj->plen);
h = NM_HASH_COMBINE (h, obj->metric);
h = NM_HASH_COMBINE (h, nm_utils_in6_addr_hash (&obj->gateway));
h = NM_HASH_COMBINE (h, nm_utils_in6_addr_hash (&obj->pref_src));
h = NM_HASH_COMBINE (h, nm_utils_in6_addr_hash (&obj->src));
h = NM_HASH_COMBINE (h, obj->src_plen);
h = NM_HASH_COMBINE (h, obj->rt_source);
h = NM_HASH_COMBINE (h, obj->mss);
h = NM_HASH_COMBINE (h, obj->rt_cloned);
h = NM_HASH_COMBINE (h, obj->tos);
h = NM_HASH_COMBINE (h, obj->lock_window);
h = NM_HASH_COMBINE (h, obj->lock_cwnd);
h = NM_HASH_COMBINE (h, obj->lock_initcwnd);
h = NM_HASH_COMBINE (h, obj->lock_initrwnd);
h = NM_HASH_COMBINE (h, obj->lock_mtu);
h = NM_HASH_COMBINE (h, obj->window);
h = NM_HASH_COMBINE (h, obj->cwnd);
h = NM_HASH_COMBINE (h, obj->initcwnd);
h = NM_HASH_COMBINE (h, obj->initrwnd);
h = NM_HASH_COMBINE (h, obj->mtu);
}
return h;
}
int
nm_platform_ip6_route_cmp_full (const NMPlatformIP6Route *a, const NMPlatformIP6Route *b, gboolean consider_host_part)
{
......
......@@ -1024,6 +1024,11 @@ nm_platform_ip6_route_cmp (const NMPlatformIP6Route *a, const NMPlatformIP6Route
return nm_platform_ip6_route_cmp_full (a, b, TRUE);
}
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);
guint nm_platform_ip6_route_hash (const NMPlatformIP6Route *obj);
gboolean nm_platform_check_support_kernel_extended_ifa_flags (NMPlatform *self);
gboolean nm_platform_check_support_user_ipv6ll (NMPlatform *self);
......
This diff is collapsed.
......@@ -22,6 +22,7 @@
#define __NMP_OBJECT_H__
#include "nm-utils/nm-obj.h"
#include "nm-utils/nm-dedup-multi.h"
#include "nm-platform.h"
#include "nm-multi-index.h"
......@@ -139,7 +140,7 @@ struct _NMPCacheId {
};
typedef struct {
NMObjBaseClass parent;
NMDedupMultiObjClass parent;
const char *obj_type_name;
int sizeof_data;
int sizeof_public;
......@@ -158,6 +159,7 @@ typedef struct {
* initialize @id and set @out_id to it. Otherwise, @out_id is NULL. */
gboolean (*cmd_obj_init_cache_id) (const NMPObject *obj, NMPCacheIdType id_type, NMPCacheId *id, const NMPCacheId **out_id);
guint (*cmd_obj_hash) (const NMPObject *obj);
int (*cmd_obj_cmp) (const NMPObject *obj1, const NMPObject *obj2);
void (*cmd_obj_copy) (NMPObject *dst, const NMPObject *src);
void (*cmd_obj_stackinit_id) (NMPObject *obj, const NMPObject *src);
......@@ -172,6 +174,7 @@ typedef struct {
guint (*cmd_plobj_id_hash) (const NMPlatformObject *obj);
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);
int (*cmd_plobj_cmp) (const NMPlatformObject *obj1, const NMPlatformObject *obj2);
} NMPClass;
......@@ -269,7 +272,7 @@ typedef struct {
struct _NMPObject {
union {
NMObjBaseInst parent;
NMDedupMultiObj parent;
const NMPClass *_class;
};
guint _ref_count;
......@@ -398,6 +401,7 @@ const NMPObject *nmp_object_stackinit_id_ip4_route (NMPObject *obj, int ifindex,
const NMPObject *nmp_object_stackinit_id_ip6_route (NMPObject *obj, int ifindex, const struct in6_addr *network, guint8 plen, guint32 metric);
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);
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);
......
......@@ -59,18 +59,15 @@ test_obj_base (void)
STATIC_ASSERT (sizeof (o->parent) == sizeof (GTypeInstance));
STATIC_ASSERT (&c->parent == (void *) c);
STATIC_ASSERT (&c->parent.g_type_class == (void *) c);
STATIC_ASSERT (&c->parent.g_type == (void *) c);
STATIC_ASSERT (&c->parent.g_type == &k->g_type);
STATIC_ASSERT (&c->parent.parent.g_type_class == (void *) c);
STATIC_ASSERT (&c->parent.parent.g_type == (void *) c);
STATIC_ASSERT (&c->parent.parent.g_type == &k->g_type);
STATIC_ASSERT (sizeof (c->parent) == sizeof (GTypeClass));
STATIC_ASSERT (sizeof (c->parent.parent) == sizeof (GTypeClass));
STATIC_ASSERT (&o->parent == (void *) o);
STATIC_ASSERT (&o->parent.klass == (void *) &o->_class);
STATIC_ASSERT (G_STRUCT_OFFSET (NMPObject, _ref_count) == sizeof (NMObjBaseInst));
STATIC_ASSERT (G_STRUCT_OFFSET (NMPClass, obj_type_name) == sizeof (NMObjBaseClass));
obj = (NMObjBaseInst *) obj_cancellable;
g_assert (!NMP_CLASS_IS_VALID ((NMPClass *) obj->klass));
g_assert (G_TYPE_CHECK_INSTANCE_TYPE (obj, G_TYPE_CANCELLABLE));
......
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