summaryrefslogtreecommitdiff
path: root/src/platform/nmp-object.h
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-07-07 23:34:41 +0200
committerThomas Haller <thaller@redhat.com>2017-07-25 06:44:12 +0200
commit22edeb5b691befd796c534cf71901b32f0b7945b (patch)
tree98cdbd184ae8d73242d267d27f4882094ecbf236 /src/platform/nmp-object.h
parent74816a22374091f1cde34372387f8c6bfcd688dc (diff)
downloadNetworkManager-22edeb5b691befd796c534cf71901b32f0b7945b.tar.gz
core: track addresses for NMIP4Config/NMIP6Config via NMDedupMultiIndex
Reasons: - it adds an O(1) lookup index for accessing NMIPxConfig's addresses. Hence, operations like merge/intersect have now runtime O(n) instead of O(n^2). Arguably, we expect low numbers of addresses in general. For low numbers, the O(n^2) doesn't matter and quite likely in those cases the previous implementation was just fine -- maybe even faster. But the simple case works fine either way. It's important to scale well in the exceptional case. - the tracked objects can be shared between the various NMPI4Config, NMIP6Config instances with NMPlatform and everybody else. - the NMPObject can be treated generically, meaning it enables code to handle both IPv4 and IPv6, or addresses and routes. See for example _nm_ip_config_add_obj(). - I want core to evolve to somewhere where we don't keep copies of NMPlatformIP4Address, et al. instances. Instead they shall all be shared. I hope this will reduce memory consumption (although tracking a reference consumes some memory too). Also, it shortcuts nmp_object_equal() when comparing the same object. Calling nmp_object_equal() on the identical objects would be a common case after the hash function pre-evaluates equality.
Diffstat (limited to 'src/platform/nmp-object.h')
-rw-r--r--src/platform/nmp-object.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/platform/nmp-object.h b/src/platform/nmp-object.h
index 9cdad2e808..b63265ee11 100644
--- a/src/platform/nmp-object.h
+++ b/src/platform/nmp-object.h
@@ -345,6 +345,22 @@ NMP_OBJECT_GET_TYPE (const NMPObject *obj)
_obj ? &_NM_CONSTCAST (NMPObject, _obj)->link : NULL; \
})
+#define NMP_OBJECT_CAST_IP_ADDRESS(obj) \
+ ({ \
+ typeof (obj) _obj = (obj); \
+ \
+ nm_assert (!_obj || NM_IN_SET (NMP_OBJECT_GET_TYPE (_obj), NMP_OBJECT_TYPE_IP4_ADDRESS, NMP_OBJECT_TYPE_IP6_ADDRESS)); \
+ _obj ? &_NM_CONSTCAST (NMPObject, _obj)->ip_address : NULL; \
+ })
+
+#define NMP_OBJECT_CAST_IPX_ADDRESS(obj) \
+ ({ \
+ typeof (obj) _obj = (obj); \
+ \
+ nm_assert (!_obj || NM_IN_SET (NMP_OBJECT_GET_TYPE (_obj), NMP_OBJECT_TYPE_IP4_ADDRESS, NMP_OBJECT_TYPE_IP6_ADDRESS)); \
+ _obj ? &_NM_CONSTCAST (NMPObject, _obj)->ipx_address : NULL; \
+ })
+
#define NMP_OBJECT_CAST_IP4_ADDRESS(obj) \
({ \
typeof (obj) _obj = (obj); \
@@ -419,6 +435,15 @@ NMPObject *nmp_object_new (NMPObjectType obj_type, const NMPlatformObject *plob)
NMPObject *nmp_object_new_link (int ifindex);
const NMPObject *nmp_object_stackinit (NMPObject *obj, NMPObjectType obj_type, const NMPlatformObject *plobj);
+
+static inline NMPObject *
+nmp_object_stackinit_obj (NMPObject *obj, const NMPObject *src)
+{
+ return obj == src
+ ? obj
+ : (NMPObject *) nmp_object_stackinit (obj, NMP_OBJECT_GET_TYPE (src), &src->object);
+}
+
const NMPObject *nmp_object_stackinit_id (NMPObject *obj, const NMPObject *src);
const NMPObject *nmp_object_stackinit_id_link (NMPObject *obj, int ifindex);
const NMPObject *nmp_object_stackinit_id_ip4_address (NMPObject *obj, int ifindex, guint32 address, guint8 plen, guint32 peer_address);