2015-04-14 22:34:01 +02:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
|
|
|
|
/* nm-platform.c - Handle runtime kernel networking configuration
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2015 Red Hat, Inc.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef __NMP_OBJECT_H__
|
|
|
|
|
#define __NMP_OBJECT_H__
|
|
|
|
|
|
all: add base object type in "nm-obj.h"
Platform has it's own, simple implementation of object types:
NMPObject. Extract a base type and move it to "shared/nm-utils/nm-obj.h"
so it can be reused.
The base type is trival, but it allows us to implement other objects
which are compatible with NMPObjects. Currently there is no API for generic
NMObjBaseInst type, so compatible in this case only means, that they
can be used in the same context (see example below).
The only thing that you can do with a NMObjBaseInst is check it's
NMObjBaseClass.
Incidentally, NMObjBaseInst is also made compatible to GTypeInstance.
It means, an NMObjBaseInst is not necessarily a valid GTypeInstance (like NMPObject
is not), but it could be implemented as such.
For example, you could do:
if (NMP_CLASS_IS_VALID ((NMPClass *) obj->klass)) {
/* is an NMPObject */
} else if (G_TYPE_CHECK_INSTANCE_TYPE (obj, NM_TYPE_SOMETHING)) {
/* it a NMSometing GType */
} else {
/* something else? */
}
The reason why NMPObject is not implemented as proper GTypeInstance is
because it would require us to register a GType (like
g_type_register_fundamental). However, then the NMPClass struct can
no longer be const and immutable memory. But we could.
NMObjBaseInst may or may not be a GTypeInstance. In a sense, it's
a base type of GTypeInstance and all our objects should be based
on it (optionally, they we may make them valid GTypes too).
2017-06-04 20:45:23 +02:00
|
|
|
#include "nm-utils/nm-obj.h"
|
2017-06-12 18:39:53 +02:00
|
|
|
#include "nm-utils/nm-dedup-multi.h"
|
2016-02-12 14:44:52 +01:00
|
|
|
#include "nm-platform.h"
|
2015-04-14 22:34:01 +02:00
|
|
|
|
2017-03-12 15:54:02 +01:00
|
|
|
struct udev_device;
|
|
|
|
|
|
2015-04-14 23:14:06 +02:00
|
|
|
typedef enum { /*< skip >*/
|
|
|
|
|
NMP_OBJECT_TO_STRING_ID,
|
|
|
|
|
NMP_OBJECT_TO_STRING_PUBLIC,
|
|
|
|
|
NMP_OBJECT_TO_STRING_ALL,
|
|
|
|
|
} NMPObjectToStringMode;
|
|
|
|
|
|
|
|
|
|
typedef enum { /*< skip >*/
|
|
|
|
|
NMP_CACHE_OPS_UNCHANGED = NM_PLATFORM_SIGNAL_NONE,
|
|
|
|
|
NMP_CACHE_OPS_UPDATED = NM_PLATFORM_SIGNAL_CHANGED,
|
|
|
|
|
NMP_CACHE_OPS_ADDED = NM_PLATFORM_SIGNAL_ADDED,
|
|
|
|
|
NMP_CACHE_OPS_REMOVED = NM_PLATFORM_SIGNAL_REMOVED,
|
|
|
|
|
} NMPCacheOpsType;
|
|
|
|
|
|
|
|
|
|
/* The NMPCacheIdType are the different index types.
|
|
|
|
|
*
|
|
|
|
|
* An object of a certain object-type, can be candidate to being
|
|
|
|
|
* indexed by a certain NMPCacheIdType or not. For example, all
|
|
|
|
|
* objects are indexed via an index of type NMP_CACHE_ID_TYPE_OBJECT_TYPE,
|
2015-06-18 11:44:36 +02:00
|
|
|
* but only route objects can be indexed by NMP_CACHE_ID_TYPE_ROUTES_VISIBLE_NO_DEFAULT.
|
2015-04-14 23:14:06 +02:00
|
|
|
*
|
2015-06-18 11:44:36 +02:00
|
|
|
* Of one index type, there can be multiple indexes or not.
|
2017-07-04 12:05:07 +02:00
|
|
|
* For example, of the index type NMP_CACHE_ID_TYPE_ADDRROUTE_BY_IFINDEX there
|
2015-06-18 11:44:36 +02:00
|
|
|
* are multiple instances (for different route/addresses, v4/v6, per-ifindex).
|
2015-04-14 23:14:06 +02:00
|
|
|
*
|
2015-06-18 11:44:36 +02:00
|
|
|
* But one object, can only be indexed by one particular index of a
|
2015-04-14 23:14:06 +02:00
|
|
|
* type. For example, a certain address instance is only indexed by
|
2017-07-04 12:05:07 +02:00
|
|
|
* the index NMP_CACHE_ID_TYPE_ADDRROUTE_BY_IFINDEX with
|
2015-06-18 11:44:36 +02:00
|
|
|
* matching v4/v6 and ifindex -- or maybe not at all if it isn't visible.
|
2015-04-14 23:14:06 +02:00
|
|
|
* */
|
|
|
|
|
typedef enum { /*< skip >*/
|
2016-04-05 18:59:38 +02:00
|
|
|
NMP_CACHE_ID_TYPE_NONE,
|
|
|
|
|
|
platform: use NMDedupMultiIndex for routes in NMPCache
Rework platform object cache to use NMDedupMultiIndex.
Already previously, NMPCache used NMMultiIndex and had thus
O(1) for most operations. What is new is:
- Contrary to NMMultiIndex, NMDedupMultiIndex preserves the order of
the cached items. That is crucial to handle routes properly as kernel
will replace the first matching route based on network/plen/metric
properties. See related bug rh#1337855.
Without tracking the order of routes as they are exposed
by kernel, we cannot properly maintain the route cache.
- All NMPObject instances are now treated immutable, refcounted
and get de-duplicated via NMDedupMultiIndex. This allows
to have a global NMDedupMultiIndex that can be shared with
NMIP4Config and NMRouteManager. It also allows to share the
objects themselves.
Immutable objects are so much nicer. We can get rid of the
update pre-hook callback, which was required previously because
we would mutate the object inplace. Now, we can just update
the cache, and compare obj_old and obj_new after the fact.
- NMMultiIndex was treated as an internal of NMPCache. On the other
hand, NMDedupMultiIndex exposes NMDedupMultiHeadEntry, which is
basically an object that allows to iterate over all related
objects. That means, we can now lookup objects in the cache
and give the NMDedupMultiHeadEntry instance to the caller,
which then can iterate the list on it's own -- without need
for copying anything.
Currently, at various places we still create copies of lookup
results. That can be improved later.
The ability to share NMPObject instances should enable us to
significantly improve performance and scale with large number
of routes.
Of course there is a memory overhead of having an index for each list
entry. Each NMPObject may also require an NMDedupMultiEntry,
NMDedupMultiHeadEntry, and NMDedupMultiBox item, which are tracked
in a GHashTable. Optimally, one NMDedupMultiHeadEntry is the head
for multiple objects, and NMDedupMultiBox is able to deduplicate several
NMPObjects, so that there is a net saving.
Also, each object type has several indexes of type NMPCacheIdType.
So, worst case an NMPlatformIP4Route in the platform cache is tracked
by 8 NMPCacheIdType indexes, for each we require a NMDedupMultiEntry,
plus the shared NMDedupMultiHeadEntry. The NMDedupMultiBox instance
is shared between the 8 indexes (and possibly other).
2017-06-21 10:53:34 +02:00
|
|
|
/* all the objects of a certain type.
|
|
|
|
|
*
|
|
|
|
|
* This index is special. It is the only one that contains *all* object.
|
|
|
|
|
* Other indexes may consider some object as non "partitionable", hence
|
|
|
|
|
* they don't track all objects.
|
|
|
|
|
*
|
|
|
|
|
* Hence, this index type is used when looking at all objects (still
|
2017-07-04 11:44:27 +02:00
|
|
|
* partitioned by type).
|
|
|
|
|
*
|
|
|
|
|
* Also, note that links may be considered invisible. This index type
|
|
|
|
|
* expose all links, even invisible ones. For addresses/routes, this
|
|
|
|
|
* distiction doesn't exist, as all addresses/routes that are alive
|
|
|
|
|
* are visible as well. */
|
2015-04-14 23:14:06 +02:00
|
|
|
NMP_CACHE_ID_TYPE_OBJECT_TYPE,
|
|
|
|
|
|
2015-12-15 16:23:05 +01:00
|
|
|
/* index for the link objects by ifname. */
|
|
|
|
|
NMP_CACHE_ID_TYPE_LINK_BY_IFNAME,
|
|
|
|
|
|
2017-07-04 10:55:19 +02:00
|
|
|
/* indeces for the visible default-routes, ignoring ifindex.
|
|
|
|
|
* This index only contains two partitions: all visible default-routes,
|
|
|
|
|
* separate for IPv4 and IPv6. */
|
2017-07-04 12:05:07 +02:00
|
|
|
NMP_CACHE_ID_TYPE_DEFAULT_ROUTES,
|
2015-04-14 23:14:06 +02:00
|
|
|
|
2017-07-04 12:05:07 +02:00
|
|
|
/* all the addresses/routes (by object-type) for an ifindex. */
|
|
|
|
|
NMP_CACHE_ID_TYPE_ADDRROUTE_BY_IFINDEX,
|
2015-06-18 11:44:36 +02:00
|
|
|
|
2016-04-10 11:21:50 +02:00
|
|
|
/* Consider all the destination fields of a route, that is, the ID without the ifindex
|
|
|
|
|
* and gateway (meaning: network/plen,metric).
|
|
|
|
|
* The reason for this is that `ip route change` can replace an existing route
|
|
|
|
|
* and modify it's ifindex/gateway. Effectively, that means it deletes an existing
|
|
|
|
|
* route and adds a different one (as the ID of the route changes). However, it only
|
|
|
|
|
* sends one RTM_NEWADDR notification without notifying about the deletion. We detect
|
|
|
|
|
* that by having this index to contain overlapping routes which require special
|
|
|
|
|
* cache-resync. */
|
2017-06-26 17:30:32 +02:00
|
|
|
NMP_CACHE_ID_TYPE_ROUTES_BY_DESTINATION,
|
2016-04-10 11:21:50 +02:00
|
|
|
|
2015-04-14 23:14:06 +02:00
|
|
|
__NMP_CACHE_ID_TYPE_MAX,
|
|
|
|
|
NMP_CACHE_ID_TYPE_MAX = __NMP_CACHE_ID_TYPE_MAX - 1,
|
|
|
|
|
} NMPCacheIdType;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2017-06-12 18:39:53 +02:00
|
|
|
NMDedupMultiObjClass parent;
|
all: add base object type in "nm-obj.h"
Platform has it's own, simple implementation of object types:
NMPObject. Extract a base type and move it to "shared/nm-utils/nm-obj.h"
so it can be reused.
The base type is trival, but it allows us to implement other objects
which are compatible with NMPObjects. Currently there is no API for generic
NMObjBaseInst type, so compatible in this case only means, that they
can be used in the same context (see example below).
The only thing that you can do with a NMObjBaseInst is check it's
NMObjBaseClass.
Incidentally, NMObjBaseInst is also made compatible to GTypeInstance.
It means, an NMObjBaseInst is not necessarily a valid GTypeInstance (like NMPObject
is not), but it could be implemented as such.
For example, you could do:
if (NMP_CLASS_IS_VALID ((NMPClass *) obj->klass)) {
/* is an NMPObject */
} else if (G_TYPE_CHECK_INSTANCE_TYPE (obj, NM_TYPE_SOMETHING)) {
/* it a NMSometing GType */
} else {
/* something else? */
}
The reason why NMPObject is not implemented as proper GTypeInstance is
because it would require us to register a GType (like
g_type_register_fundamental). However, then the NMPClass struct can
no longer be const and immutable memory. But we could.
NMObjBaseInst may or may not be a GTypeInstance. In a sense, it's
a base type of GTypeInstance and all our objects should be based
on it (optionally, they we may make them valid GTypes too).
2017-06-04 20:45:23 +02:00
|
|
|
const char *obj_type_name;
|
|
|
|
|
int sizeof_data;
|
|
|
|
|
int sizeof_public;
|
2015-06-19 16:24:18 +02:00
|
|
|
NMPObjectType obj_type;
|
2015-04-14 23:14:06 +02:00
|
|
|
int addr_family;
|
|
|
|
|
int rtm_gettype;
|
2015-11-27 12:54:31 +01:00
|
|
|
NMPlatformSignalIdType signal_type_id;
|
2015-04-14 23:14:06 +02:00
|
|
|
const char *signal_type;
|
|
|
|
|
|
2016-04-05 18:59:38 +02:00
|
|
|
const guint8 *supported_cache_ids;
|
|
|
|
|
|
2015-10-29 11:27:55 +01:00
|
|
|
/* Only for NMPObjectLnk* types. */
|
|
|
|
|
NMLinkType lnk_link_type;
|
|
|
|
|
|
2017-06-12 18:39:53 +02:00
|
|
|
guint (*cmd_obj_hash) (const NMPObject *obj);
|
2015-10-12 13:19:10 +02:00
|
|
|
int (*cmd_obj_cmp) (const NMPObject *obj1, const NMPObject *obj2);
|
2015-04-14 23:14:06 +02:00
|
|
|
void (*cmd_obj_copy) (NMPObject *dst, const NMPObject *src);
|
|
|
|
|
void (*cmd_obj_dispose) (NMPObject *obj);
|
|
|
|
|
gboolean (*cmd_obj_is_alive) (const NMPObject *obj);
|
|
|
|
|
gboolean (*cmd_obj_is_visible) (const NMPObject *obj);
|
2015-10-27 18:30:20 +01:00
|
|
|
const char *(*cmd_obj_to_string) (const NMPObject *obj, NMPObjectToStringMode to_string_mode, char *buf, gsize buf_size);
|
2015-04-14 23:14:06 +02:00
|
|
|
|
|
|
|
|
/* functions that operate on NMPlatformObject */
|
|
|
|
|
void (*cmd_plobj_id_copy) (NMPlatformObject *dst, const NMPlatformObject *src);
|
2017-08-12 15:55:17 +02:00
|
|
|
int (*cmd_plobj_id_cmp) (const NMPlatformObject *obj1, const NMPlatformObject *obj2);
|
2015-04-14 23:14:06 +02:00
|
|
|
guint (*cmd_plobj_id_hash) (const NMPlatformObject *obj);
|
|
|
|
|
const char *(*cmd_plobj_to_string_id) (const NMPlatformObject *obj, char *buf, gsize buf_size);
|
2015-10-12 10:27:33 +02:00
|
|
|
const char *(*cmd_plobj_to_string) (const NMPlatformObject *obj, char *buf, gsize len);
|
2017-06-12 18:39:53 +02:00
|
|
|
guint (*cmd_plobj_hash) (const NMPlatformObject *obj);
|
2015-04-14 23:14:06 +02:00
|
|
|
int (*cmd_plobj_cmp) (const NMPlatformObject *obj1, const NMPlatformObject *obj2);
|
|
|
|
|
} NMPClass;
|
|
|
|
|
|
2015-06-24 15:29:01 +02:00
|
|
|
extern const NMPClass _nmp_classes[NMP_OBJECT_TYPE_MAX];
|
2015-04-14 23:14:06 +02:00
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
NMPlatformLink _public;
|
|
|
|
|
|
|
|
|
|
struct {
|
2015-11-20 12:01:46 +01:00
|
|
|
bool is_in_netlink;
|
2015-10-12 12:41:42 +02:00
|
|
|
|
|
|
|
|
/* Additional data that depends on the link-type (IFLA_INFO_DATA) */
|
core: remove NMDedupMultiBox object and track NMDedupMultiObj instances directly
Implement the reference counting of NMPObject as part of
NMDedupMultiObj and get rid of NMDedupMultiBox.
With this change, the NMPObject is aware in which NMDedupMultiIndex
instance it is tracked.
- this saves an additional GSlice allocation for the NMDedupMultiBox.
- it is immediately known, whether an NMPObject is tracked by a
certain NMDedupMultiIndex or not. This saves an additional hash
lookup.
- previously, when all idx-types cease to reference an NMDedupMultiObj
instance, it was removed. Now, a tracked objects stays in the
NMDedupMultiIndex until it's last reference is deleted. This possibly
extends the lifetime of the object and we may reuse it better.
- it is no longer possible to add one object to more then one
NMDedupMultiIndex instance. As we anyway want to have only one
instance to deduplicate the objects, this is fine.
- the ref-counting implementation is now part of NMDedupMultiObj.
Previously, NMDedupMultiIndex could also track objects that were
not ref-counted. Hoever, the object anyway *must* implement the
NMDedupMultiObj API, so this flexibility is unneeded and was not
used.
- a downside is, that NMPObject grows by one pointer size, even if
it isn't tracked in the NMDedupMultiIndex. But we really want to
put all objects into the index for sharing and deduplication. So
this downside should be acceptable. Still, code like
nmp_object_stackinit*() needs to handle a larger object.
2017-07-02 23:46:06 +02:00
|
|
|
const NMPObject *lnk;
|
2015-04-14 23:14:06 +02:00
|
|
|
} netlink;
|
|
|
|
|
|
|
|
|
|
struct {
|
2017-03-12 15:54:02 +01:00
|
|
|
/* note that "struct udev_device" references the library context
|
|
|
|
|
* "struct udev", but doesn't own it.
|
|
|
|
|
*
|
|
|
|
|
* Hence, the udev.device shall not be used after the library
|
|
|
|
|
* context is is destroyed.
|
|
|
|
|
*
|
|
|
|
|
* In case of NMPObjectLink instances that you obtained from the
|
|
|
|
|
* platform cache, that means that you shall no keep references
|
|
|
|
|
* to those instances that outlife the NMPlatform instance.
|
|
|
|
|
*
|
|
|
|
|
* In practice, the requirement is less strict and you'll be even
|
|
|
|
|
* fine if the platform instance (and the "struct udev" instance)
|
|
|
|
|
* are already destroyed while you still hold onto a reference to
|
|
|
|
|
* the NMPObjectLink instance. Just don't make use of udev functions
|
|
|
|
|
* that cause access to the udev library context.
|
|
|
|
|
*/
|
|
|
|
|
struct udev_device *device;
|
2015-04-14 23:14:06 +02:00
|
|
|
} udev;
|
|
|
|
|
} NMPObjectLink;
|
|
|
|
|
|
2015-10-12 15:15:21 +02:00
|
|
|
typedef struct {
|
|
|
|
|
NMPlatformLnkGre _public;
|
|
|
|
|
} NMPObjectLnkGre;
|
|
|
|
|
|
2015-10-15 15:47:14 +02:00
|
|
|
typedef struct {
|
|
|
|
|
NMPlatformLnkInfiniband _public;
|
|
|
|
|
} NMPObjectLnkInfiniband;
|
|
|
|
|
|
2015-11-27 22:22:25 +01:00
|
|
|
typedef struct {
|
|
|
|
|
NMPlatformLnkIp6Tnl _public;
|
|
|
|
|
} NMPObjectLnkIp6Tnl;
|
|
|
|
|
|
2015-11-27 14:01:56 +01:00
|
|
|
typedef struct {
|
|
|
|
|
NMPlatformLnkIpIp _public;
|
|
|
|
|
} NMPObjectLnkIpIp;
|
|
|
|
|
|
2016-06-30 18:20:09 +02:00
|
|
|
typedef struct {
|
|
|
|
|
NMPlatformLnkMacsec _public;
|
|
|
|
|
} NMPObjectLnkMacsec;
|
|
|
|
|
|
2015-10-12 15:15:21 +02:00
|
|
|
typedef struct {
|
|
|
|
|
NMPlatformLnkMacvlan _public;
|
|
|
|
|
} NMPObjectLnkMacvlan;
|
|
|
|
|
|
2015-12-04 09:49:39 +01:00
|
|
|
typedef NMPObjectLnkMacvlan NMPObjectLnkMacvtap;
|
|
|
|
|
|
2015-11-11 18:41:48 +01:00
|
|
|
typedef struct {
|
|
|
|
|
NMPlatformLnkSit _public;
|
|
|
|
|
} NMPObjectLnkSit;
|
|
|
|
|
|
2015-10-12 13:44:44 +02:00
|
|
|
typedef struct {
|
|
|
|
|
NMPlatformLnkVlan _public;
|
2015-10-27 16:14:54 +01:00
|
|
|
|
|
|
|
|
guint n_ingress_qos_map;
|
|
|
|
|
guint n_egress_qos_map;
|
|
|
|
|
const NMVlanQosMapping *ingress_qos_map;
|
|
|
|
|
const NMVlanQosMapping *egress_qos_map;
|
2015-10-12 13:44:44 +02:00
|
|
|
} NMPObjectLnkVlan;
|
|
|
|
|
|
2015-10-12 15:15:21 +02:00
|
|
|
typedef struct {
|
|
|
|
|
NMPlatformLnkVxlan _public;
|
|
|
|
|
} NMPObjectLnkVxlan;
|
|
|
|
|
|
2015-04-14 23:14:06 +02:00
|
|
|
typedef struct {
|
|
|
|
|
NMPlatformIP4Address _public;
|
|
|
|
|
} NMPObjectIP4Address;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
NMPlatformIP4Route _public;
|
|
|
|
|
} NMPObjectIP4Route;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
NMPlatformIP6Address _public;
|
|
|
|
|
} NMPObjectIP6Address;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
NMPlatformIP6Route _public;
|
|
|
|
|
} NMPObjectIP6Route;
|
|
|
|
|
|
|
|
|
|
struct _NMPObject {
|
all: add base object type in "nm-obj.h"
Platform has it's own, simple implementation of object types:
NMPObject. Extract a base type and move it to "shared/nm-utils/nm-obj.h"
so it can be reused.
The base type is trival, but it allows us to implement other objects
which are compatible with NMPObjects. Currently there is no API for generic
NMObjBaseInst type, so compatible in this case only means, that they
can be used in the same context (see example below).
The only thing that you can do with a NMObjBaseInst is check it's
NMObjBaseClass.
Incidentally, NMObjBaseInst is also made compatible to GTypeInstance.
It means, an NMObjBaseInst is not necessarily a valid GTypeInstance (like NMPObject
is not), but it could be implemented as such.
For example, you could do:
if (NMP_CLASS_IS_VALID ((NMPClass *) obj->klass)) {
/* is an NMPObject */
} else if (G_TYPE_CHECK_INSTANCE_TYPE (obj, NM_TYPE_SOMETHING)) {
/* it a NMSometing GType */
} else {
/* something else? */
}
The reason why NMPObject is not implemented as proper GTypeInstance is
because it would require us to register a GType (like
g_type_register_fundamental). However, then the NMPClass struct can
no longer be const and immutable memory. But we could.
NMObjBaseInst may or may not be a GTypeInstance. In a sense, it's
a base type of GTypeInstance and all our objects should be based
on it (optionally, they we may make them valid GTypes too).
2017-06-04 20:45:23 +02:00
|
|
|
union {
|
2017-06-12 18:39:53 +02:00
|
|
|
NMDedupMultiObj parent;
|
all: add base object type in "nm-obj.h"
Platform has it's own, simple implementation of object types:
NMPObject. Extract a base type and move it to "shared/nm-utils/nm-obj.h"
so it can be reused.
The base type is trival, but it allows us to implement other objects
which are compatible with NMPObjects. Currently there is no API for generic
NMObjBaseInst type, so compatible in this case only means, that they
can be used in the same context (see example below).
The only thing that you can do with a NMObjBaseInst is check it's
NMObjBaseClass.
Incidentally, NMObjBaseInst is also made compatible to GTypeInstance.
It means, an NMObjBaseInst is not necessarily a valid GTypeInstance (like NMPObject
is not), but it could be implemented as such.
For example, you could do:
if (NMP_CLASS_IS_VALID ((NMPClass *) obj->klass)) {
/* is an NMPObject */
} else if (G_TYPE_CHECK_INSTANCE_TYPE (obj, NM_TYPE_SOMETHING)) {
/* it a NMSometing GType */
} else {
/* something else? */
}
The reason why NMPObject is not implemented as proper GTypeInstance is
because it would require us to register a GType (like
g_type_register_fundamental). However, then the NMPClass struct can
no longer be const and immutable memory. But we could.
NMObjBaseInst may or may not be a GTypeInstance. In a sense, it's
a base type of GTypeInstance and all our objects should be based
on it (optionally, they we may make them valid GTypes too).
2017-06-04 20:45:23 +02:00
|
|
|
const NMPClass *_class;
|
|
|
|
|
};
|
2015-04-14 23:14:06 +02:00
|
|
|
union {
|
|
|
|
|
NMPlatformObject object;
|
|
|
|
|
|
|
|
|
|
NMPlatformLink link;
|
|
|
|
|
NMPObjectLink _link;
|
|
|
|
|
|
2015-10-12 15:15:21 +02:00
|
|
|
NMPlatformLnkGre lnk_gre;
|
|
|
|
|
NMPObjectLnkGre _lnk_gre;
|
|
|
|
|
|
2015-10-15 15:47:14 +02:00
|
|
|
NMPlatformLnkInfiniband lnk_infiniband;
|
|
|
|
|
NMPObjectLnkInfiniband _lnk_infiniband;
|
|
|
|
|
|
2015-11-27 14:01:56 +01:00
|
|
|
NMPlatformLnkIpIp lnk_ipip;
|
|
|
|
|
NMPObjectLnkIpIp _lnk_ipip;
|
|
|
|
|
|
2015-11-27 22:22:25 +01:00
|
|
|
NMPlatformLnkIp6Tnl lnk_ip6tnl;
|
|
|
|
|
NMPObjectLnkIp6Tnl _lnk_ip6tnl;
|
|
|
|
|
|
2016-06-30 18:20:09 +02:00
|
|
|
NMPlatformLnkMacsec lnk_macsec;
|
|
|
|
|
NMPObjectLnkMacsec _lnk_macsec;
|
|
|
|
|
|
2015-10-12 15:15:21 +02:00
|
|
|
NMPlatformLnkMacvlan lnk_macvlan;
|
|
|
|
|
NMPObjectLnkMacvlan _lnk_macvlan;
|
|
|
|
|
|
2015-11-11 18:41:48 +01:00
|
|
|
NMPlatformLnkSit lnk_sit;
|
|
|
|
|
NMPObjectLnkSit _lnk_sit;
|
|
|
|
|
|
2015-10-12 13:44:44 +02:00
|
|
|
NMPlatformLnkVlan lnk_vlan;
|
|
|
|
|
NMPObjectLnkVlan _lnk_vlan;
|
|
|
|
|
|
2015-10-12 15:15:21 +02:00
|
|
|
NMPlatformLnkVxlan lnk_vxlan;
|
|
|
|
|
NMPObjectLnkVxlan _lnk_vxlan;
|
|
|
|
|
|
2015-04-14 23:14:06 +02:00
|
|
|
NMPlatformIPAddress ip_address;
|
|
|
|
|
NMPlatformIPXAddress ipx_address;
|
|
|
|
|
NMPlatformIP4Address ip4_address;
|
|
|
|
|
NMPlatformIP6Address ip6_address;
|
|
|
|
|
NMPObjectIP4Address _ip4_address;
|
|
|
|
|
NMPObjectIP6Address _ip6_address;
|
|
|
|
|
|
|
|
|
|
NMPlatformIPRoute ip_route;
|
|
|
|
|
NMPlatformIPXRoute ipx_route;
|
|
|
|
|
NMPlatformIP4Route ip4_route;
|
|
|
|
|
NMPlatformIP6Route ip6_route;
|
|
|
|
|
NMPObjectIP4Route _ip4_route;
|
|
|
|
|
NMPObjectIP6Route _ip6_route;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static inline gboolean
|
|
|
|
|
NMP_CLASS_IS_VALID (const NMPClass *klass)
|
|
|
|
|
{
|
|
|
|
|
return klass >= &_nmp_classes[0]
|
|
|
|
|
&& klass <= &_nmp_classes[G_N_ELEMENTS (_nmp_classes)]
|
2017-03-09 15:12:05 +01:00
|
|
|
&& ((((char *) klass) - ((char *) _nmp_classes)) % (sizeof (_nmp_classes[0]))) == 0;
|
2015-04-14 23:14:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline NMPObject *
|
|
|
|
|
NMP_OBJECT_UP_CAST(const NMPlatformObject *plobj)
|
|
|
|
|
{
|
|
|
|
|
NMPObject *obj;
|
|
|
|
|
|
|
|
|
|
obj = plobj
|
|
|
|
|
? (NMPObject *) ( &(((char *) plobj)[-((int) G_STRUCT_OFFSET (NMPObject, object))]) )
|
|
|
|
|
: NULL;
|
core: remove NMDedupMultiBox object and track NMDedupMultiObj instances directly
Implement the reference counting of NMPObject as part of
NMDedupMultiObj and get rid of NMDedupMultiBox.
With this change, the NMPObject is aware in which NMDedupMultiIndex
instance it is tracked.
- this saves an additional GSlice allocation for the NMDedupMultiBox.
- it is immediately known, whether an NMPObject is tracked by a
certain NMDedupMultiIndex or not. This saves an additional hash
lookup.
- previously, when all idx-types cease to reference an NMDedupMultiObj
instance, it was removed. Now, a tracked objects stays in the
NMDedupMultiIndex until it's last reference is deleted. This possibly
extends the lifetime of the object and we may reuse it better.
- it is no longer possible to add one object to more then one
NMDedupMultiIndex instance. As we anyway want to have only one
instance to deduplicate the objects, this is fine.
- the ref-counting implementation is now part of NMDedupMultiObj.
Previously, NMDedupMultiIndex could also track objects that were
not ref-counted. Hoever, the object anyway *must* implement the
NMDedupMultiObj API, so this flexibility is unneeded and was not
used.
- a downside is, that NMPObject grows by one pointer size, even if
it isn't tracked in the NMDedupMultiIndex. But we really want to
put all objects into the index for sharing and deduplication. So
this downside should be acceptable. Still, code like
nmp_object_stackinit*() needs to handle a larger object.
2017-07-02 23:46:06 +02:00
|
|
|
nm_assert (!obj || (obj->parent._ref_count > 0 && NMP_CLASS_IS_VALID (obj->_class)));
|
2015-04-14 23:14:06 +02:00
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
#define NMP_OBJECT_UP_CAST(plobj) (NMP_OBJECT_UP_CAST ((const NMPlatformObject *) (plobj)))
|
|
|
|
|
|
|
|
|
|
static inline gboolean
|
|
|
|
|
NMP_OBJECT_IS_VALID (const NMPObject *obj)
|
|
|
|
|
{
|
|
|
|
|
nm_assert (!obj || ( obj
|
core: remove NMDedupMultiBox object and track NMDedupMultiObj instances directly
Implement the reference counting of NMPObject as part of
NMDedupMultiObj and get rid of NMDedupMultiBox.
With this change, the NMPObject is aware in which NMDedupMultiIndex
instance it is tracked.
- this saves an additional GSlice allocation for the NMDedupMultiBox.
- it is immediately known, whether an NMPObject is tracked by a
certain NMDedupMultiIndex or not. This saves an additional hash
lookup.
- previously, when all idx-types cease to reference an NMDedupMultiObj
instance, it was removed. Now, a tracked objects stays in the
NMDedupMultiIndex until it's last reference is deleted. This possibly
extends the lifetime of the object and we may reuse it better.
- it is no longer possible to add one object to more then one
NMDedupMultiIndex instance. As we anyway want to have only one
instance to deduplicate the objects, this is fine.
- the ref-counting implementation is now part of NMDedupMultiObj.
Previously, NMDedupMultiIndex could also track objects that were
not ref-counted. Hoever, the object anyway *must* implement the
NMDedupMultiObj API, so this flexibility is unneeded and was not
used.
- a downside is, that NMPObject grows by one pointer size, even if
it isn't tracked in the NMDedupMultiIndex. But we really want to
put all objects into the index for sharing and deduplication. So
this downside should be acceptable. Still, code like
nmp_object_stackinit*() needs to handle a larger object.
2017-07-02 23:46:06 +02:00
|
|
|
&& obj->parent._ref_count > 0
|
2015-04-14 23:14:06 +02:00
|
|
|
&& NMP_CLASS_IS_VALID (obj->_class)));
|
|
|
|
|
|
|
|
|
|
/* There isn't really much to check. Either @obj is NULL, or we must
|
|
|
|
|
* assume that it points to valid memory. */
|
|
|
|
|
return obj != NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline gboolean
|
|
|
|
|
NMP_OBJECT_IS_STACKINIT (const NMPObject *obj)
|
|
|
|
|
{
|
|
|
|
|
nm_assert (!obj || NMP_OBJECT_IS_VALID (obj));
|
|
|
|
|
|
core: remove NMDedupMultiBox object and track NMDedupMultiObj instances directly
Implement the reference counting of NMPObject as part of
NMDedupMultiObj and get rid of NMDedupMultiBox.
With this change, the NMPObject is aware in which NMDedupMultiIndex
instance it is tracked.
- this saves an additional GSlice allocation for the NMDedupMultiBox.
- it is immediately known, whether an NMPObject is tracked by a
certain NMDedupMultiIndex or not. This saves an additional hash
lookup.
- previously, when all idx-types cease to reference an NMDedupMultiObj
instance, it was removed. Now, a tracked objects stays in the
NMDedupMultiIndex until it's last reference is deleted. This possibly
extends the lifetime of the object and we may reuse it better.
- it is no longer possible to add one object to more then one
NMDedupMultiIndex instance. As we anyway want to have only one
instance to deduplicate the objects, this is fine.
- the ref-counting implementation is now part of NMDedupMultiObj.
Previously, NMDedupMultiIndex could also track objects that were
not ref-counted. Hoever, the object anyway *must* implement the
NMDedupMultiObj API, so this flexibility is unneeded and was not
used.
- a downside is, that NMPObject grows by one pointer size, even if
it isn't tracked in the NMDedupMultiIndex. But we really want to
put all objects into the index for sharing and deduplication. So
this downside should be acceptable. Still, code like
nmp_object_stackinit*() needs to handle a larger object.
2017-07-02 23:46:06 +02:00
|
|
|
return obj && obj->parent._ref_count == NM_OBJ_REF_COUNT_STACKINIT;
|
2015-04-14 23:14:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline const NMPClass *
|
|
|
|
|
NMP_OBJECT_GET_CLASS (const NMPObject *obj)
|
|
|
|
|
{
|
|
|
|
|
nm_assert (NMP_OBJECT_IS_VALID (obj));
|
|
|
|
|
|
|
|
|
|
return obj->_class;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-19 16:24:18 +02:00
|
|
|
static inline NMPObjectType
|
2015-04-14 23:14:06 +02:00
|
|
|
NMP_OBJECT_GET_TYPE (const NMPObject *obj)
|
|
|
|
|
{
|
|
|
|
|
nm_assert (!obj || NMP_OBJECT_IS_VALID (obj));
|
|
|
|
|
|
2015-06-24 15:29:01 +02:00
|
|
|
return obj ? obj->_class->obj_type : NMP_OBJECT_TYPE_UNKNOWN;
|
2015-04-14 23:14:06 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-04 12:49:47 +02:00
|
|
|
#define NMP_OBJECT_CAST_LINK(obj) \
|
|
|
|
|
({ \
|
2017-07-05 11:12:59 +02:00
|
|
|
typeof (obj) _obj = (obj); \
|
2017-07-04 12:49:47 +02:00
|
|
|
\
|
2017-07-05 11:12:59 +02:00
|
|
|
nm_assert (!_obj || NMP_OBJECT_GET_TYPE ((const NMPObject *) _obj) == NMP_OBJECT_TYPE_LINK); \
|
|
|
|
|
_obj ? &_NM_CONSTCAST (NMPObject, _obj)->link : NULL; \
|
2017-07-04 12:49:47 +02:00
|
|
|
})
|
|
|
|
|
|
2017-07-07 23:34:41 +02:00
|
|
|
#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; \
|
|
|
|
|
})
|
|
|
|
|
|
2017-07-04 12:49:47 +02:00
|
|
|
#define NMP_OBJECT_CAST_IP4_ADDRESS(obj) \
|
|
|
|
|
({ \
|
2017-07-05 11:12:59 +02:00
|
|
|
typeof (obj) _obj = (obj); \
|
2017-07-04 12:49:47 +02:00
|
|
|
\
|
2017-07-05 11:12:59 +02:00
|
|
|
nm_assert (!_obj || NMP_OBJECT_GET_TYPE ((const NMPObject *) _obj) == NMP_OBJECT_TYPE_IP4_ADDRESS); \
|
|
|
|
|
_obj ? &_NM_CONSTCAST (NMPObject, _obj)->ip4_address : NULL; \
|
2017-07-04 12:49:47 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
#define NMP_OBJECT_CAST_IP6_ADDRESS(obj) \
|
|
|
|
|
({ \
|
2017-07-05 11:12:59 +02:00
|
|
|
typeof (obj) _obj = (obj); \
|
2017-07-04 12:49:47 +02:00
|
|
|
\
|
2017-07-05 11:12:59 +02:00
|
|
|
nm_assert (!_obj || NMP_OBJECT_GET_TYPE ((const NMPObject *) _obj) == NMP_OBJECT_TYPE_IP6_ADDRESS); \
|
|
|
|
|
_obj ? &_NM_CONSTCAST (NMPObject, _obj)->ip6_address : NULL; \
|
2017-07-04 12:49:47 +02:00
|
|
|
})
|
|
|
|
|
|
2017-06-29 15:19:35 +02:00
|
|
|
#define NMP_OBJECT_CAST_IPX_ROUTE(obj) \
|
|
|
|
|
({ \
|
2017-07-05 11:12:59 +02:00
|
|
|
typeof (obj) _obj = (obj); \
|
2017-06-29 15:19:35 +02:00
|
|
|
\
|
2017-07-05 11:12:59 +02:00
|
|
|
nm_assert (!_obj || NM_IN_SET (NMP_OBJECT_GET_TYPE (_obj), NMP_OBJECT_TYPE_IP4_ROUTE, NMP_OBJECT_TYPE_IP6_ROUTE)); \
|
|
|
|
|
_obj ? &_NM_CONSTCAST (NMPObject, _obj)->ipx_route : NULL; \
|
2017-06-29 15:19:35 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
#define NMP_OBJECT_CAST_IP_ROUTE(obj) \
|
|
|
|
|
({ \
|
2017-07-05 11:12:59 +02:00
|
|
|
typeof (obj) _obj = (obj); \
|
2017-06-29 15:19:35 +02:00
|
|
|
\
|
2017-07-05 11:12:59 +02:00
|
|
|
nm_assert (!_obj || NM_IN_SET (NMP_OBJECT_GET_TYPE (_obj), NMP_OBJECT_TYPE_IP4_ROUTE, NMP_OBJECT_TYPE_IP6_ROUTE)); \
|
|
|
|
|
_obj ? &_NM_CONSTCAST (NMPObject, _obj)->ip_route : NULL; \
|
2017-06-29 15:19:35 +02:00
|
|
|
})
|
|
|
|
|
|
2017-06-29 13:05:52 +02:00
|
|
|
#define NMP_OBJECT_CAST_IP4_ROUTE(obj) \
|
|
|
|
|
({ \
|
2017-07-05 11:12:59 +02:00
|
|
|
typeof (obj) _obj = (obj); \
|
2017-06-29 13:05:52 +02:00
|
|
|
\
|
2017-07-05 11:12:59 +02:00
|
|
|
nm_assert (!_obj || NMP_OBJECT_GET_TYPE ((const NMPObject *) _obj) == NMP_OBJECT_TYPE_IP4_ROUTE); \
|
|
|
|
|
_obj ? &_NM_CONSTCAST (NMPObject, _obj)->ip4_route : NULL; \
|
2017-06-29 13:05:52 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
#define NMP_OBJECT_CAST_IP6_ROUTE(obj) \
|
|
|
|
|
({ \
|
2017-07-05 11:12:59 +02:00
|
|
|
typeof (obj) _obj = (obj); \
|
2017-06-29 13:05:52 +02:00
|
|
|
\
|
2017-07-05 11:12:59 +02:00
|
|
|
nm_assert (!_obj || NMP_OBJECT_GET_TYPE ((const NMPObject *) _obj) == NMP_OBJECT_TYPE_IP6_ROUTE); \
|
|
|
|
|
_obj ? &_NM_CONSTCAST (NMPObject, _obj)->ip6_route : NULL; \
|
2017-06-29 13:05:52 +02:00
|
|
|
})
|
2015-04-14 23:14:06 +02:00
|
|
|
|
2015-06-19 16:24:18 +02:00
|
|
|
const NMPClass *nmp_class_from_type (NMPObjectType obj_type);
|
2015-04-14 23:14:06 +02:00
|
|
|
|
core: remove NMDedupMultiBox object and track NMDedupMultiObj instances directly
Implement the reference counting of NMPObject as part of
NMDedupMultiObj and get rid of NMDedupMultiBox.
With this change, the NMPObject is aware in which NMDedupMultiIndex
instance it is tracked.
- this saves an additional GSlice allocation for the NMDedupMultiBox.
- it is immediately known, whether an NMPObject is tracked by a
certain NMDedupMultiIndex or not. This saves an additional hash
lookup.
- previously, when all idx-types cease to reference an NMDedupMultiObj
instance, it was removed. Now, a tracked objects stays in the
NMDedupMultiIndex until it's last reference is deleted. This possibly
extends the lifetime of the object and we may reuse it better.
- it is no longer possible to add one object to more then one
NMDedupMultiIndex instance. As we anyway want to have only one
instance to deduplicate the objects, this is fine.
- the ref-counting implementation is now part of NMDedupMultiObj.
Previously, NMDedupMultiIndex could also track objects that were
not ref-counted. Hoever, the object anyway *must* implement the
NMDedupMultiObj API, so this flexibility is unneeded and was not
used.
- a downside is, that NMPObject grows by one pointer size, even if
it isn't tracked in the NMDedupMultiIndex. But we really want to
put all objects into the index for sharing and deduplication. So
this downside should be acceptable. Still, code like
nmp_object_stackinit*() needs to handle a larger object.
2017-07-02 23:46:06 +02:00
|
|
|
static inline const NMPObject *
|
|
|
|
|
nmp_object_ref (const NMPObject *obj)
|
|
|
|
|
{
|
|
|
|
|
/* ref and unref accept const pointers. NMPObject is supposed to be shared
|
|
|
|
|
* and kept immutable. Disallowing to take/retrun a reference to a const
|
|
|
|
|
* NMPObject is cumbersome, because callers are precisely expected to
|
|
|
|
|
* keep a ref on the otherwise immutable object. */
|
|
|
|
|
g_return_val_if_fail (NMP_OBJECT_IS_VALID (obj), NULL);
|
|
|
|
|
g_return_val_if_fail (obj->parent._ref_count != NM_OBJ_REF_COUNT_STACKINIT, NULL);
|
|
|
|
|
|
|
|
|
|
return (const NMPObject *) nm_dedup_multi_obj_ref ((const NMDedupMultiObj *) obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline const NMPObject *
|
|
|
|
|
nmp_object_unref (const NMPObject *obj)
|
|
|
|
|
{
|
|
|
|
|
nm_dedup_multi_obj_unref ((const NMDedupMultiObj *) obj);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-19 16:24:18 +02:00
|
|
|
NMPObject *nmp_object_new (NMPObjectType obj_type, const NMPlatformObject *plob);
|
2015-04-14 23:14:06 +02:00
|
|
|
NMPObject *nmp_object_new_link (int ifindex);
|
|
|
|
|
|
2015-06-19 16:24:18 +02:00
|
|
|
const NMPObject *nmp_object_stackinit (NMPObject *obj, NMPObjectType obj_type, const NMPlatformObject *plobj);
|
2017-07-07 23:34:41 +02:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-14 23:14:06 +02:00
|
|
|
const NMPObject *nmp_object_stackinit_id (NMPObject *obj, const NMPObject *src);
|
|
|
|
|
const NMPObject *nmp_object_stackinit_id_link (NMPObject *obj, int ifindex);
|
2016-04-06 18:04:26 +02:00
|
|
|
const NMPObject *nmp_object_stackinit_id_ip4_address (NMPObject *obj, int ifindex, guint32 address, guint8 plen, guint32 peer_address);
|
2017-05-26 21:49:00 +02:00
|
|
|
const NMPObject *nmp_object_stackinit_id_ip6_address (NMPObject *obj, int ifindex, const struct in6_addr *address);
|
2016-04-06 14:19:05 +02:00
|
|
|
const NMPObject *nmp_object_stackinit_id_ip4_route (NMPObject *obj, int ifindex, guint32 network, guint8 plen, guint32 metric);
|
|
|
|
|
const NMPObject *nmp_object_stackinit_id_ip6_route (NMPObject *obj, int ifindex, const struct in6_addr *network, guint8 plen, guint32 metric);
|
2015-04-14 23:14:06 +02:00
|
|
|
|
|
|
|
|
const char *nmp_object_to_string (const NMPObject *obj, NMPObjectToStringMode to_string_mode, char *buf, gsize buf_size);
|
2017-06-12 18:39:53 +02:00
|
|
|
guint nmp_object_hash (const NMPObject *obj);
|
2015-04-14 23:14:06 +02:00
|
|
|
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);
|
2017-08-12 15:55:17 +02:00
|
|
|
|
|
|
|
|
int nmp_object_id_cmp (const NMPObject *obj1, const NMPObject *obj2);
|
2015-04-14 23:14:06 +02:00
|
|
|
guint nmp_object_id_hash (const NMPObject *obj);
|
2017-08-12 15:55:17 +02:00
|
|
|
|
|
|
|
|
static inline gboolean
|
|
|
|
|
nmp_object_id_equal (const NMPObject *obj1, const NMPObject *obj2)
|
|
|
|
|
{
|
|
|
|
|
return nmp_object_id_cmp (obj1, obj2) == 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-14 23:14:06 +02:00
|
|
|
gboolean nmp_object_is_alive (const NMPObject *obj);
|
|
|
|
|
gboolean nmp_object_is_visible (const NMPObject *obj);
|
|
|
|
|
|
platform: use NMDedupMultiIndex for routes in NMPCache
Rework platform object cache to use NMDedupMultiIndex.
Already previously, NMPCache used NMMultiIndex and had thus
O(1) for most operations. What is new is:
- Contrary to NMMultiIndex, NMDedupMultiIndex preserves the order of
the cached items. That is crucial to handle routes properly as kernel
will replace the first matching route based on network/plen/metric
properties. See related bug rh#1337855.
Without tracking the order of routes as they are exposed
by kernel, we cannot properly maintain the route cache.
- All NMPObject instances are now treated immutable, refcounted
and get de-duplicated via NMDedupMultiIndex. This allows
to have a global NMDedupMultiIndex that can be shared with
NMIP4Config and NMRouteManager. It also allows to share the
objects themselves.
Immutable objects are so much nicer. We can get rid of the
update pre-hook callback, which was required previously because
we would mutate the object inplace. Now, we can just update
the cache, and compare obj_old and obj_new after the fact.
- NMMultiIndex was treated as an internal of NMPCache. On the other
hand, NMDedupMultiIndex exposes NMDedupMultiHeadEntry, which is
basically an object that allows to iterate over all related
objects. That means, we can now lookup objects in the cache
and give the NMDedupMultiHeadEntry instance to the caller,
which then can iterate the list on it's own -- without need
for copying anything.
Currently, at various places we still create copies of lookup
results. That can be improved later.
The ability to share NMPObject instances should enable us to
significantly improve performance and scale with large number
of routes.
Of course there is a memory overhead of having an index for each list
entry. Each NMPObject may also require an NMDedupMultiEntry,
NMDedupMultiHeadEntry, and NMDedupMultiBox item, which are tracked
in a GHashTable. Optimally, one NMDedupMultiHeadEntry is the head
for multiple objects, and NMDedupMultiBox is able to deduplicate several
NMPObjects, so that there is a net saving.
Also, each object type has several indexes of type NMPCacheIdType.
So, worst case an NMPlatformIP4Route in the platform cache is tracked
by 8 NMPCacheIdType indexes, for each we require a NMDedupMultiEntry,
plus the shared NMDedupMultiHeadEntry. The NMDedupMultiBox instance
is shared between the 8 indexes (and possibly other).
2017-06-21 10:53:34 +02:00
|
|
|
void _nmp_object_fixup_link_udev_fields (NMPObject **obj_new, NMPObject *obj_orig, gboolean use_udev);
|
2015-04-14 23:14:06 +02:00
|
|
|
|
2015-10-20 14:43:31 +02:00
|
|
|
#define nm_auto_nmpobj __attribute__((cleanup(_nm_auto_nmpobj_cleanup)))
|
2015-04-14 23:14:06 +02:00
|
|
|
static inline void
|
platform: use NMDedupMultiIndex for routes in NMPCache
Rework platform object cache to use NMDedupMultiIndex.
Already previously, NMPCache used NMMultiIndex and had thus
O(1) for most operations. What is new is:
- Contrary to NMMultiIndex, NMDedupMultiIndex preserves the order of
the cached items. That is crucial to handle routes properly as kernel
will replace the first matching route based on network/plen/metric
properties. See related bug rh#1337855.
Without tracking the order of routes as they are exposed
by kernel, we cannot properly maintain the route cache.
- All NMPObject instances are now treated immutable, refcounted
and get de-duplicated via NMDedupMultiIndex. This allows
to have a global NMDedupMultiIndex that can be shared with
NMIP4Config and NMRouteManager. It also allows to share the
objects themselves.
Immutable objects are so much nicer. We can get rid of the
update pre-hook callback, which was required previously because
we would mutate the object inplace. Now, we can just update
the cache, and compare obj_old and obj_new after the fact.
- NMMultiIndex was treated as an internal of NMPCache. On the other
hand, NMDedupMultiIndex exposes NMDedupMultiHeadEntry, which is
basically an object that allows to iterate over all related
objects. That means, we can now lookup objects in the cache
and give the NMDedupMultiHeadEntry instance to the caller,
which then can iterate the list on it's own -- without need
for copying anything.
Currently, at various places we still create copies of lookup
results. That can be improved later.
The ability to share NMPObject instances should enable us to
significantly improve performance and scale with large number
of routes.
Of course there is a memory overhead of having an index for each list
entry. Each NMPObject may also require an NMDedupMultiEntry,
NMDedupMultiHeadEntry, and NMDedupMultiBox item, which are tracked
in a GHashTable. Optimally, one NMDedupMultiHeadEntry is the head
for multiple objects, and NMDedupMultiBox is able to deduplicate several
NMPObjects, so that there is a net saving.
Also, each object type has several indexes of type NMPCacheIdType.
So, worst case an NMPlatformIP4Route in the platform cache is tracked
by 8 NMPCacheIdType indexes, for each we require a NMDedupMultiEntry,
plus the shared NMDedupMultiHeadEntry. The NMDedupMultiBox instance
is shared between the 8 indexes (and possibly other).
2017-06-21 10:53:34 +02:00
|
|
|
_nm_auto_nmpobj_cleanup (gpointer p)
|
2015-04-14 23:14:06 +02:00
|
|
|
{
|
platform: use NMDedupMultiIndex for routes in NMPCache
Rework platform object cache to use NMDedupMultiIndex.
Already previously, NMPCache used NMMultiIndex and had thus
O(1) for most operations. What is new is:
- Contrary to NMMultiIndex, NMDedupMultiIndex preserves the order of
the cached items. That is crucial to handle routes properly as kernel
will replace the first matching route based on network/plen/metric
properties. See related bug rh#1337855.
Without tracking the order of routes as they are exposed
by kernel, we cannot properly maintain the route cache.
- All NMPObject instances are now treated immutable, refcounted
and get de-duplicated via NMDedupMultiIndex. This allows
to have a global NMDedupMultiIndex that can be shared with
NMIP4Config and NMRouteManager. It also allows to share the
objects themselves.
Immutable objects are so much nicer. We can get rid of the
update pre-hook callback, which was required previously because
we would mutate the object inplace. Now, we can just update
the cache, and compare obj_old and obj_new after the fact.
- NMMultiIndex was treated as an internal of NMPCache. On the other
hand, NMDedupMultiIndex exposes NMDedupMultiHeadEntry, which is
basically an object that allows to iterate over all related
objects. That means, we can now lookup objects in the cache
and give the NMDedupMultiHeadEntry instance to the caller,
which then can iterate the list on it's own -- without need
for copying anything.
Currently, at various places we still create copies of lookup
results. That can be improved later.
The ability to share NMPObject instances should enable us to
significantly improve performance and scale with large number
of routes.
Of course there is a memory overhead of having an index for each list
entry. Each NMPObject may also require an NMDedupMultiEntry,
NMDedupMultiHeadEntry, and NMDedupMultiBox item, which are tracked
in a GHashTable. Optimally, one NMDedupMultiHeadEntry is the head
for multiple objects, and NMDedupMultiBox is able to deduplicate several
NMPObjects, so that there is a net saving.
Also, each object type has several indexes of type NMPCacheIdType.
So, worst case an NMPlatformIP4Route in the platform cache is tracked
by 8 NMPCacheIdType indexes, for each we require a NMDedupMultiEntry,
plus the shared NMDedupMultiHeadEntry. The NMDedupMultiBox instance
is shared between the 8 indexes (and possibly other).
2017-06-21 10:53:34 +02:00
|
|
|
nmp_object_unref (*((const NMPObject **) p));
|
2015-04-14 23:14:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef struct _NMPCache NMPCache;
|
|
|
|
|
|
|
|
|
|
typedef void (*NMPCachePreHook) (NMPCache *cache, const NMPObject *old, const NMPObject *new, NMPCacheOpsType ops_type, gpointer user_data);
|
|
|
|
|
typedef gboolean (*NMPObjectMatchFn) (const NMPObject *obj, gpointer user_data);
|
|
|
|
|
|
platform: use NMDedupMultiIndex for routes in NMPCache
Rework platform object cache to use NMDedupMultiIndex.
Already previously, NMPCache used NMMultiIndex and had thus
O(1) for most operations. What is new is:
- Contrary to NMMultiIndex, NMDedupMultiIndex preserves the order of
the cached items. That is crucial to handle routes properly as kernel
will replace the first matching route based on network/plen/metric
properties. See related bug rh#1337855.
Without tracking the order of routes as they are exposed
by kernel, we cannot properly maintain the route cache.
- All NMPObject instances are now treated immutable, refcounted
and get de-duplicated via NMDedupMultiIndex. This allows
to have a global NMDedupMultiIndex that can be shared with
NMIP4Config and NMRouteManager. It also allows to share the
objects themselves.
Immutable objects are so much nicer. We can get rid of the
update pre-hook callback, which was required previously because
we would mutate the object inplace. Now, we can just update
the cache, and compare obj_old and obj_new after the fact.
- NMMultiIndex was treated as an internal of NMPCache. On the other
hand, NMDedupMultiIndex exposes NMDedupMultiHeadEntry, which is
basically an object that allows to iterate over all related
objects. That means, we can now lookup objects in the cache
and give the NMDedupMultiHeadEntry instance to the caller,
which then can iterate the list on it's own -- without need
for copying anything.
Currently, at various places we still create copies of lookup
results. That can be improved later.
The ability to share NMPObject instances should enable us to
significantly improve performance and scale with large number
of routes.
Of course there is a memory overhead of having an index for each list
entry. Each NMPObject may also require an NMDedupMultiEntry,
NMDedupMultiHeadEntry, and NMDedupMultiBox item, which are tracked
in a GHashTable. Optimally, one NMDedupMultiHeadEntry is the head
for multiple objects, and NMDedupMultiBox is able to deduplicate several
NMPObjects, so that there is a net saving.
Also, each object type has several indexes of type NMPCacheIdType.
So, worst case an NMPlatformIP4Route in the platform cache is tracked
by 8 NMPCacheIdType indexes, for each we require a NMDedupMultiEntry,
plus the shared NMDedupMultiHeadEntry. The NMDedupMultiBox instance
is shared between the 8 indexes (and possibly other).
2017-06-21 10:53:34 +02:00
|
|
|
const NMDedupMultiEntry *nmp_cache_lookup_entry_link (const NMPCache *cache, int ifindex);
|
2015-04-14 23:14:06 +02:00
|
|
|
|
|
|
|
|
const NMPObject *nmp_cache_lookup_obj (const NMPCache *cache, const NMPObject *obj);
|
|
|
|
|
const NMPObject *nmp_cache_lookup_link (const NMPCache *cache, int ifindex);
|
|
|
|
|
|
2017-06-29 14:46:32 +02:00
|
|
|
typedef struct _NMPLookup NMPLookup;
|
|
|
|
|
|
|
|
|
|
struct _NMPLookup {
|
platform: use NMDedupMultiIndex for routes in NMPCache
Rework platform object cache to use NMDedupMultiIndex.
Already previously, NMPCache used NMMultiIndex and had thus
O(1) for most operations. What is new is:
- Contrary to NMMultiIndex, NMDedupMultiIndex preserves the order of
the cached items. That is crucial to handle routes properly as kernel
will replace the first matching route based on network/plen/metric
properties. See related bug rh#1337855.
Without tracking the order of routes as they are exposed
by kernel, we cannot properly maintain the route cache.
- All NMPObject instances are now treated immutable, refcounted
and get de-duplicated via NMDedupMultiIndex. This allows
to have a global NMDedupMultiIndex that can be shared with
NMIP4Config and NMRouteManager. It also allows to share the
objects themselves.
Immutable objects are so much nicer. We can get rid of the
update pre-hook callback, which was required previously because
we would mutate the object inplace. Now, we can just update
the cache, and compare obj_old and obj_new after the fact.
- NMMultiIndex was treated as an internal of NMPCache. On the other
hand, NMDedupMultiIndex exposes NMDedupMultiHeadEntry, which is
basically an object that allows to iterate over all related
objects. That means, we can now lookup objects in the cache
and give the NMDedupMultiHeadEntry instance to the caller,
which then can iterate the list on it's own -- without need
for copying anything.
Currently, at various places we still create copies of lookup
results. That can be improved later.
The ability to share NMPObject instances should enable us to
significantly improve performance and scale with large number
of routes.
Of course there is a memory overhead of having an index for each list
entry. Each NMPObject may also require an NMDedupMultiEntry,
NMDedupMultiHeadEntry, and NMDedupMultiBox item, which are tracked
in a GHashTable. Optimally, one NMDedupMultiHeadEntry is the head
for multiple objects, and NMDedupMultiBox is able to deduplicate several
NMPObjects, so that there is a net saving.
Also, each object type has several indexes of type NMPCacheIdType.
So, worst case an NMPlatformIP4Route in the platform cache is tracked
by 8 NMPCacheIdType indexes, for each we require a NMDedupMultiEntry,
plus the shared NMDedupMultiHeadEntry. The NMDedupMultiBox instance
is shared between the 8 indexes (and possibly other).
2017-06-21 10:53:34 +02:00
|
|
|
NMPCacheIdType cache_id_type;
|
|
|
|
|
NMPObject selector_obj;
|
2017-06-29 14:46:32 +02:00
|
|
|
};
|
platform: use NMDedupMultiIndex for routes in NMPCache
Rework platform object cache to use NMDedupMultiIndex.
Already previously, NMPCache used NMMultiIndex and had thus
O(1) for most operations. What is new is:
- Contrary to NMMultiIndex, NMDedupMultiIndex preserves the order of
the cached items. That is crucial to handle routes properly as kernel
will replace the first matching route based on network/plen/metric
properties. See related bug rh#1337855.
Without tracking the order of routes as they are exposed
by kernel, we cannot properly maintain the route cache.
- All NMPObject instances are now treated immutable, refcounted
and get de-duplicated via NMDedupMultiIndex. This allows
to have a global NMDedupMultiIndex that can be shared with
NMIP4Config and NMRouteManager. It also allows to share the
objects themselves.
Immutable objects are so much nicer. We can get rid of the
update pre-hook callback, which was required previously because
we would mutate the object inplace. Now, we can just update
the cache, and compare obj_old and obj_new after the fact.
- NMMultiIndex was treated as an internal of NMPCache. On the other
hand, NMDedupMultiIndex exposes NMDedupMultiHeadEntry, which is
basically an object that allows to iterate over all related
objects. That means, we can now lookup objects in the cache
and give the NMDedupMultiHeadEntry instance to the caller,
which then can iterate the list on it's own -- without need
for copying anything.
Currently, at various places we still create copies of lookup
results. That can be improved later.
The ability to share NMPObject instances should enable us to
significantly improve performance and scale with large number
of routes.
Of course there is a memory overhead of having an index for each list
entry. Each NMPObject may also require an NMDedupMultiEntry,
NMDedupMultiHeadEntry, and NMDedupMultiBox item, which are tracked
in a GHashTable. Optimally, one NMDedupMultiHeadEntry is the head
for multiple objects, and NMDedupMultiBox is able to deduplicate several
NMPObjects, so that there is a net saving.
Also, each object type has several indexes of type NMPCacheIdType.
So, worst case an NMPlatformIP4Route in the platform cache is tracked
by 8 NMPCacheIdType indexes, for each we require a NMDedupMultiEntry,
plus the shared NMDedupMultiHeadEntry. The NMDedupMultiBox instance
is shared between the 8 indexes (and possibly other).
2017-06-21 10:53:34 +02:00
|
|
|
|
|
|
|
|
const NMDedupMultiHeadEntry *nmp_cache_lookup_all (const NMPCache *cache,
|
|
|
|
|
NMPCacheIdType cache_id_type,
|
|
|
|
|
const NMPObject *select_obj);
|
|
|
|
|
|
|
|
|
|
static inline const NMDedupMultiHeadEntry *
|
|
|
|
|
nmp_cache_lookup (const NMPCache *cache,
|
|
|
|
|
const NMPLookup *lookup)
|
|
|
|
|
{
|
|
|
|
|
return nmp_cache_lookup_all (cache, lookup->cache_id_type, &lookup->selector_obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NMPLookup *nmp_lookup_init_obj_type (NMPLookup *lookup,
|
2017-07-04 11:44:27 +02:00
|
|
|
NMPObjectType obj_type);
|
platform: use NMDedupMultiIndex for routes in NMPCache
Rework platform object cache to use NMDedupMultiIndex.
Already previously, NMPCache used NMMultiIndex and had thus
O(1) for most operations. What is new is:
- Contrary to NMMultiIndex, NMDedupMultiIndex preserves the order of
the cached items. That is crucial to handle routes properly as kernel
will replace the first matching route based on network/plen/metric
properties. See related bug rh#1337855.
Without tracking the order of routes as they are exposed
by kernel, we cannot properly maintain the route cache.
- All NMPObject instances are now treated immutable, refcounted
and get de-duplicated via NMDedupMultiIndex. This allows
to have a global NMDedupMultiIndex that can be shared with
NMIP4Config and NMRouteManager. It also allows to share the
objects themselves.
Immutable objects are so much nicer. We can get rid of the
update pre-hook callback, which was required previously because
we would mutate the object inplace. Now, we can just update
the cache, and compare obj_old and obj_new after the fact.
- NMMultiIndex was treated as an internal of NMPCache. On the other
hand, NMDedupMultiIndex exposes NMDedupMultiHeadEntry, which is
basically an object that allows to iterate over all related
objects. That means, we can now lookup objects in the cache
and give the NMDedupMultiHeadEntry instance to the caller,
which then can iterate the list on it's own -- without need
for copying anything.
Currently, at various places we still create copies of lookup
results. That can be improved later.
The ability to share NMPObject instances should enable us to
significantly improve performance and scale with large number
of routes.
Of course there is a memory overhead of having an index for each list
entry. Each NMPObject may also require an NMDedupMultiEntry,
NMDedupMultiHeadEntry, and NMDedupMultiBox item, which are tracked
in a GHashTable. Optimally, one NMDedupMultiHeadEntry is the head
for multiple objects, and NMDedupMultiBox is able to deduplicate several
NMPObjects, so that there is a net saving.
Also, each object type has several indexes of type NMPCacheIdType.
So, worst case an NMPlatformIP4Route in the platform cache is tracked
by 8 NMPCacheIdType indexes, for each we require a NMDedupMultiEntry,
plus the shared NMDedupMultiHeadEntry. The NMDedupMultiBox instance
is shared between the 8 indexes (and possibly other).
2017-06-21 10:53:34 +02:00
|
|
|
const NMPLookup *nmp_lookup_init_link_by_ifname (NMPLookup *lookup,
|
|
|
|
|
const char *ifname);
|
|
|
|
|
const NMPLookup *nmp_lookup_init_addrroute (NMPLookup *lookup,
|
|
|
|
|
NMPObjectType obj_type,
|
2017-07-04 11:44:27 +02:00
|
|
|
int ifindex);
|
platform: use NMDedupMultiIndex for routes in NMPCache
Rework platform object cache to use NMDedupMultiIndex.
Already previously, NMPCache used NMMultiIndex and had thus
O(1) for most operations. What is new is:
- Contrary to NMMultiIndex, NMDedupMultiIndex preserves the order of
the cached items. That is crucial to handle routes properly as kernel
will replace the first matching route based on network/plen/metric
properties. See related bug rh#1337855.
Without tracking the order of routes as they are exposed
by kernel, we cannot properly maintain the route cache.
- All NMPObject instances are now treated immutable, refcounted
and get de-duplicated via NMDedupMultiIndex. This allows
to have a global NMDedupMultiIndex that can be shared with
NMIP4Config and NMRouteManager. It also allows to share the
objects themselves.
Immutable objects are so much nicer. We can get rid of the
update pre-hook callback, which was required previously because
we would mutate the object inplace. Now, we can just update
the cache, and compare obj_old and obj_new after the fact.
- NMMultiIndex was treated as an internal of NMPCache. On the other
hand, NMDedupMultiIndex exposes NMDedupMultiHeadEntry, which is
basically an object that allows to iterate over all related
objects. That means, we can now lookup objects in the cache
and give the NMDedupMultiHeadEntry instance to the caller,
which then can iterate the list on it's own -- without need
for copying anything.
Currently, at various places we still create copies of lookup
results. That can be improved later.
The ability to share NMPObject instances should enable us to
significantly improve performance and scale with large number
of routes.
Of course there is a memory overhead of having an index for each list
entry. Each NMPObject may also require an NMDedupMultiEntry,
NMDedupMultiHeadEntry, and NMDedupMultiBox item, which are tracked
in a GHashTable. Optimally, one NMDedupMultiHeadEntry is the head
for multiple objects, and NMDedupMultiBox is able to deduplicate several
NMPObjects, so that there is a net saving.
Also, each object type has several indexes of type NMPCacheIdType.
So, worst case an NMPlatformIP4Route in the platform cache is tracked
by 8 NMPCacheIdType indexes, for each we require a NMDedupMultiEntry,
plus the shared NMDedupMultiHeadEntry. The NMDedupMultiBox instance
is shared between the 8 indexes (and possibly other).
2017-06-21 10:53:34 +02:00
|
|
|
const NMPLookup *nmp_lookup_init_route_visible (NMPLookup *lookup,
|
|
|
|
|
NMPObjectType obj_type,
|
|
|
|
|
int ifindex,
|
2017-07-04 10:55:19 +02:00
|
|
|
gboolean only_default);
|
platform: use NMDedupMultiIndex for routes in NMPCache
Rework platform object cache to use NMDedupMultiIndex.
Already previously, NMPCache used NMMultiIndex and had thus
O(1) for most operations. What is new is:
- Contrary to NMMultiIndex, NMDedupMultiIndex preserves the order of
the cached items. That is crucial to handle routes properly as kernel
will replace the first matching route based on network/plen/metric
properties. See related bug rh#1337855.
Without tracking the order of routes as they are exposed
by kernel, we cannot properly maintain the route cache.
- All NMPObject instances are now treated immutable, refcounted
and get de-duplicated via NMDedupMultiIndex. This allows
to have a global NMDedupMultiIndex that can be shared with
NMIP4Config and NMRouteManager. It also allows to share the
objects themselves.
Immutable objects are so much nicer. We can get rid of the
update pre-hook callback, which was required previously because
we would mutate the object inplace. Now, we can just update
the cache, and compare obj_old and obj_new after the fact.
- NMMultiIndex was treated as an internal of NMPCache. On the other
hand, NMDedupMultiIndex exposes NMDedupMultiHeadEntry, which is
basically an object that allows to iterate over all related
objects. That means, we can now lookup objects in the cache
and give the NMDedupMultiHeadEntry instance to the caller,
which then can iterate the list on it's own -- without need
for copying anything.
Currently, at various places we still create copies of lookup
results. That can be improved later.
The ability to share NMPObject instances should enable us to
significantly improve performance and scale with large number
of routes.
Of course there is a memory overhead of having an index for each list
entry. Each NMPObject may also require an NMDedupMultiEntry,
NMDedupMultiHeadEntry, and NMDedupMultiBox item, which are tracked
in a GHashTable. Optimally, one NMDedupMultiHeadEntry is the head
for multiple objects, and NMDedupMultiBox is able to deduplicate several
NMPObjects, so that there is a net saving.
Also, each object type has several indexes of type NMPCacheIdType.
So, worst case an NMPlatformIP4Route in the platform cache is tracked
by 8 NMPCacheIdType indexes, for each we require a NMDedupMultiEntry,
plus the shared NMDedupMultiHeadEntry. The NMDedupMultiBox instance
is shared between the 8 indexes (and possibly other).
2017-06-21 10:53:34 +02:00
|
|
|
const NMPLookup *nmp_lookup_init_route_by_dest (NMPLookup *lookup,
|
|
|
|
|
int addr_family,
|
|
|
|
|
gconstpointer network,
|
|
|
|
|
guint plen,
|
|
|
|
|
guint32 metric);
|
|
|
|
|
|
|
|
|
|
GArray *nmp_cache_lookup_to_array (const NMDedupMultiHeadEntry *head_entry,
|
2017-07-04 11:44:27 +02:00
|
|
|
NMPObjectType obj_type,
|
|
|
|
|
gboolean visible_only);
|
platform: use NMDedupMultiIndex for routes in NMPCache
Rework platform object cache to use NMDedupMultiIndex.
Already previously, NMPCache used NMMultiIndex and had thus
O(1) for most operations. What is new is:
- Contrary to NMMultiIndex, NMDedupMultiIndex preserves the order of
the cached items. That is crucial to handle routes properly as kernel
will replace the first matching route based on network/plen/metric
properties. See related bug rh#1337855.
Without tracking the order of routes as they are exposed
by kernel, we cannot properly maintain the route cache.
- All NMPObject instances are now treated immutable, refcounted
and get de-duplicated via NMDedupMultiIndex. This allows
to have a global NMDedupMultiIndex that can be shared with
NMIP4Config and NMRouteManager. It also allows to share the
objects themselves.
Immutable objects are so much nicer. We can get rid of the
update pre-hook callback, which was required previously because
we would mutate the object inplace. Now, we can just update
the cache, and compare obj_old and obj_new after the fact.
- NMMultiIndex was treated as an internal of NMPCache. On the other
hand, NMDedupMultiIndex exposes NMDedupMultiHeadEntry, which is
basically an object that allows to iterate over all related
objects. That means, we can now lookup objects in the cache
and give the NMDedupMultiHeadEntry instance to the caller,
which then can iterate the list on it's own -- without need
for copying anything.
Currently, at various places we still create copies of lookup
results. That can be improved later.
The ability to share NMPObject instances should enable us to
significantly improve performance and scale with large number
of routes.
Of course there is a memory overhead of having an index for each list
entry. Each NMPObject may also require an NMDedupMultiEntry,
NMDedupMultiHeadEntry, and NMDedupMultiBox item, which are tracked
in a GHashTable. Optimally, one NMDedupMultiHeadEntry is the head
for multiple objects, and NMDedupMultiBox is able to deduplicate several
NMPObjects, so that there is a net saving.
Also, each object type has several indexes of type NMPCacheIdType.
So, worst case an NMPlatformIP4Route in the platform cache is tracked
by 8 NMPCacheIdType indexes, for each we require a NMDedupMultiEntry,
plus the shared NMDedupMultiHeadEntry. The NMDedupMultiBox instance
is shared between the 8 indexes (and possibly other).
2017-06-21 10:53:34 +02:00
|
|
|
|
|
|
|
|
static inline gboolean
|
|
|
|
|
nmp_cache_iter_next (NMDedupMultiIter *iter, const NMPObject **out_obj)
|
|
|
|
|
{
|
|
|
|
|
gboolean has_next;
|
|
|
|
|
|
|
|
|
|
has_next = nm_dedup_multi_iter_next (iter);
|
|
|
|
|
if (has_next) {
|
core: remove NMDedupMultiBox object and track NMDedupMultiObj instances directly
Implement the reference counting of NMPObject as part of
NMDedupMultiObj and get rid of NMDedupMultiBox.
With this change, the NMPObject is aware in which NMDedupMultiIndex
instance it is tracked.
- this saves an additional GSlice allocation for the NMDedupMultiBox.
- it is immediately known, whether an NMPObject is tracked by a
certain NMDedupMultiIndex or not. This saves an additional hash
lookup.
- previously, when all idx-types cease to reference an NMDedupMultiObj
instance, it was removed. Now, a tracked objects stays in the
NMDedupMultiIndex until it's last reference is deleted. This possibly
extends the lifetime of the object and we may reuse it better.
- it is no longer possible to add one object to more then one
NMDedupMultiIndex instance. As we anyway want to have only one
instance to deduplicate the objects, this is fine.
- the ref-counting implementation is now part of NMDedupMultiObj.
Previously, NMDedupMultiIndex could also track objects that were
not ref-counted. Hoever, the object anyway *must* implement the
NMDedupMultiObj API, so this flexibility is unneeded and was not
used.
- a downside is, that NMPObject grows by one pointer size, even if
it isn't tracked in the NMDedupMultiIndex. But we really want to
put all objects into the index for sharing and deduplication. So
this downside should be acceptable. Still, code like
nmp_object_stackinit*() needs to handle a larger object.
2017-07-02 23:46:06 +02:00
|
|
|
nm_assert (NMP_OBJECT_IS_VALID (iter->current->obj));
|
|
|
|
|
NM_SET_OUT (out_obj, iter->current->obj);
|
platform: use NMDedupMultiIndex for routes in NMPCache
Rework platform object cache to use NMDedupMultiIndex.
Already previously, NMPCache used NMMultiIndex and had thus
O(1) for most operations. What is new is:
- Contrary to NMMultiIndex, NMDedupMultiIndex preserves the order of
the cached items. That is crucial to handle routes properly as kernel
will replace the first matching route based on network/plen/metric
properties. See related bug rh#1337855.
Without tracking the order of routes as they are exposed
by kernel, we cannot properly maintain the route cache.
- All NMPObject instances are now treated immutable, refcounted
and get de-duplicated via NMDedupMultiIndex. This allows
to have a global NMDedupMultiIndex that can be shared with
NMIP4Config and NMRouteManager. It also allows to share the
objects themselves.
Immutable objects are so much nicer. We can get rid of the
update pre-hook callback, which was required previously because
we would mutate the object inplace. Now, we can just update
the cache, and compare obj_old and obj_new after the fact.
- NMMultiIndex was treated as an internal of NMPCache. On the other
hand, NMDedupMultiIndex exposes NMDedupMultiHeadEntry, which is
basically an object that allows to iterate over all related
objects. That means, we can now lookup objects in the cache
and give the NMDedupMultiHeadEntry instance to the caller,
which then can iterate the list on it's own -- without need
for copying anything.
Currently, at various places we still create copies of lookup
results. That can be improved later.
The ability to share NMPObject instances should enable us to
significantly improve performance and scale with large number
of routes.
Of course there is a memory overhead of having an index for each list
entry. Each NMPObject may also require an NMDedupMultiEntry,
NMDedupMultiHeadEntry, and NMDedupMultiBox item, which are tracked
in a GHashTable. Optimally, one NMDedupMultiHeadEntry is the head
for multiple objects, and NMDedupMultiBox is able to deduplicate several
NMPObjects, so that there is a net saving.
Also, each object type has several indexes of type NMPCacheIdType.
So, worst case an NMPlatformIP4Route in the platform cache is tracked
by 8 NMPCacheIdType indexes, for each we require a NMDedupMultiEntry,
plus the shared NMDedupMultiHeadEntry. The NMDedupMultiBox instance
is shared between the 8 indexes (and possibly other).
2017-06-21 10:53:34 +02:00
|
|
|
}
|
|
|
|
|
return has_next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline gboolean
|
|
|
|
|
nmp_cache_iter_next_link (NMDedupMultiIter *iter, const NMPlatformLink **out_obj)
|
|
|
|
|
{
|
|
|
|
|
gboolean has_next;
|
|
|
|
|
|
|
|
|
|
has_next = nm_dedup_multi_iter_next (iter);
|
|
|
|
|
if (has_next) {
|
core: remove NMDedupMultiBox object and track NMDedupMultiObj instances directly
Implement the reference counting of NMPObject as part of
NMDedupMultiObj and get rid of NMDedupMultiBox.
With this change, the NMPObject is aware in which NMDedupMultiIndex
instance it is tracked.
- this saves an additional GSlice allocation for the NMDedupMultiBox.
- it is immediately known, whether an NMPObject is tracked by a
certain NMDedupMultiIndex or not. This saves an additional hash
lookup.
- previously, when all idx-types cease to reference an NMDedupMultiObj
instance, it was removed. Now, a tracked objects stays in the
NMDedupMultiIndex until it's last reference is deleted. This possibly
extends the lifetime of the object and we may reuse it better.
- it is no longer possible to add one object to more then one
NMDedupMultiIndex instance. As we anyway want to have only one
instance to deduplicate the objects, this is fine.
- the ref-counting implementation is now part of NMDedupMultiObj.
Previously, NMDedupMultiIndex could also track objects that were
not ref-counted. Hoever, the object anyway *must* implement the
NMDedupMultiObj API, so this flexibility is unneeded and was not
used.
- a downside is, that NMPObject grows by one pointer size, even if
it isn't tracked in the NMDedupMultiIndex. But we really want to
put all objects into the index for sharing and deduplication. So
this downside should be acceptable. Still, code like
nmp_object_stackinit*() needs to handle a larger object.
2017-07-02 23:46:06 +02:00
|
|
|
nm_assert (NMP_OBJECT_GET_TYPE (iter->current->obj) == NMP_OBJECT_TYPE_LINK);
|
|
|
|
|
NM_SET_OUT (out_obj, &(((const NMPObject *) iter->current->obj)->link));
|
platform: use NMDedupMultiIndex for routes in NMPCache
Rework platform object cache to use NMDedupMultiIndex.
Already previously, NMPCache used NMMultiIndex and had thus
O(1) for most operations. What is new is:
- Contrary to NMMultiIndex, NMDedupMultiIndex preserves the order of
the cached items. That is crucial to handle routes properly as kernel
will replace the first matching route based on network/plen/metric
properties. See related bug rh#1337855.
Without tracking the order of routes as they are exposed
by kernel, we cannot properly maintain the route cache.
- All NMPObject instances are now treated immutable, refcounted
and get de-duplicated via NMDedupMultiIndex. This allows
to have a global NMDedupMultiIndex that can be shared with
NMIP4Config and NMRouteManager. It also allows to share the
objects themselves.
Immutable objects are so much nicer. We can get rid of the
update pre-hook callback, which was required previously because
we would mutate the object inplace. Now, we can just update
the cache, and compare obj_old and obj_new after the fact.
- NMMultiIndex was treated as an internal of NMPCache. On the other
hand, NMDedupMultiIndex exposes NMDedupMultiHeadEntry, which is
basically an object that allows to iterate over all related
objects. That means, we can now lookup objects in the cache
and give the NMDedupMultiHeadEntry instance to the caller,
which then can iterate the list on it's own -- without need
for copying anything.
Currently, at various places we still create copies of lookup
results. That can be improved later.
The ability to share NMPObject instances should enable us to
significantly improve performance and scale with large number
of routes.
Of course there is a memory overhead of having an index for each list
entry. Each NMPObject may also require an NMDedupMultiEntry,
NMDedupMultiHeadEntry, and NMDedupMultiBox item, which are tracked
in a GHashTable. Optimally, one NMDedupMultiHeadEntry is the head
for multiple objects, and NMDedupMultiBox is able to deduplicate several
NMPObjects, so that there is a net saving.
Also, each object type has several indexes of type NMPCacheIdType.
So, worst case an NMPlatformIP4Route in the platform cache is tracked
by 8 NMPCacheIdType indexes, for each we require a NMDedupMultiEntry,
plus the shared NMDedupMultiHeadEntry. The NMDedupMultiBox instance
is shared between the 8 indexes (and possibly other).
2017-06-21 10:53:34 +02:00
|
|
|
}
|
|
|
|
|
return has_next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define nmp_cache_iter_for_each(iter, head, obj) \
|
|
|
|
|
for (nm_dedup_multi_iter_init ((iter), \
|
|
|
|
|
(head)); \
|
|
|
|
|
nmp_cache_iter_next ((iter), (obj)); \
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
#define nmp_cache_iter_for_each_link(iter, head, obj) \
|
|
|
|
|
for (nm_dedup_multi_iter_init ((iter), \
|
|
|
|
|
(head)); \
|
|
|
|
|
nmp_cache_iter_next_link ((iter), (obj)); \
|
|
|
|
|
)
|
|
|
|
|
|
2016-04-10 11:21:50 +02:00
|
|
|
const NMPObject *nmp_cache_find_other_route_for_same_destination (const NMPCache *cache, const NMPObject *route);
|
|
|
|
|
|
2015-04-14 23:14:06 +02:00
|
|
|
const NMPObject *nmp_cache_lookup_link_full (const NMPCache *cache,
|
|
|
|
|
int ifindex,
|
|
|
|
|
const char *ifname,
|
|
|
|
|
gboolean visible_only,
|
|
|
|
|
NMLinkType link_type,
|
|
|
|
|
NMPObjectMatchFn match_fn,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
2017-07-04 12:49:47 +02:00
|
|
|
gboolean nmp_cache_link_connected_for_slave (int ifindex_master, const NMPObject *slave);
|
2015-04-14 23:14:06 +02:00
|
|
|
gboolean nmp_cache_link_connected_needs_toggle (const NMPCache *cache, const NMPObject *master, const NMPObject *potential_slave, const NMPObject *ignore_slave);
|
|
|
|
|
const NMPObject *nmp_cache_link_connected_needs_toggle_by_ifindex (const NMPCache *cache, int master_ifindex, const NMPObject *potential_slave, const NMPObject *ignore_slave);
|
|
|
|
|
|
|
|
|
|
gboolean nmp_cache_use_udev_get (const NMPCache *cache);
|
|
|
|
|
|
|
|
|
|
void ASSERT_nmp_cache_is_consistent (const NMPCache *cache);
|
|
|
|
|
|
platform: use NMDedupMultiIndex for routes in NMPCache
Rework platform object cache to use NMDedupMultiIndex.
Already previously, NMPCache used NMMultiIndex and had thus
O(1) for most operations. What is new is:
- Contrary to NMMultiIndex, NMDedupMultiIndex preserves the order of
the cached items. That is crucial to handle routes properly as kernel
will replace the first matching route based on network/plen/metric
properties. See related bug rh#1337855.
Without tracking the order of routes as they are exposed
by kernel, we cannot properly maintain the route cache.
- All NMPObject instances are now treated immutable, refcounted
and get de-duplicated via NMDedupMultiIndex. This allows
to have a global NMDedupMultiIndex that can be shared with
NMIP4Config and NMRouteManager. It also allows to share the
objects themselves.
Immutable objects are so much nicer. We can get rid of the
update pre-hook callback, which was required previously because
we would mutate the object inplace. Now, we can just update
the cache, and compare obj_old and obj_new after the fact.
- NMMultiIndex was treated as an internal of NMPCache. On the other
hand, NMDedupMultiIndex exposes NMDedupMultiHeadEntry, which is
basically an object that allows to iterate over all related
objects. That means, we can now lookup objects in the cache
and give the NMDedupMultiHeadEntry instance to the caller,
which then can iterate the list on it's own -- without need
for copying anything.
Currently, at various places we still create copies of lookup
results. That can be improved later.
The ability to share NMPObject instances should enable us to
significantly improve performance and scale with large number
of routes.
Of course there is a memory overhead of having an index for each list
entry. Each NMPObject may also require an NMDedupMultiEntry,
NMDedupMultiHeadEntry, and NMDedupMultiBox item, which are tracked
in a GHashTable. Optimally, one NMDedupMultiHeadEntry is the head
for multiple objects, and NMDedupMultiBox is able to deduplicate several
NMPObjects, so that there is a net saving.
Also, each object type has several indexes of type NMPCacheIdType.
So, worst case an NMPlatformIP4Route in the platform cache is tracked
by 8 NMPCacheIdType indexes, for each we require a NMDedupMultiEntry,
plus the shared NMDedupMultiHeadEntry. The NMDedupMultiBox instance
is shared between the 8 indexes (and possibly other).
2017-06-21 10:53:34 +02:00
|
|
|
NMPCacheOpsType nmp_cache_remove (NMPCache *cache,
|
|
|
|
|
const NMPObject *obj_needle,
|
|
|
|
|
gboolean equals_by_ptr,
|
|
|
|
|
const NMPObject **out_obj_old);
|
|
|
|
|
NMPCacheOpsType nmp_cache_remove_netlink (NMPCache *cache,
|
|
|
|
|
const NMPObject *obj_needle,
|
|
|
|
|
const NMPObject **out_obj_old,
|
|
|
|
|
const NMPObject **out_obj_new);
|
|
|
|
|
NMPCacheOpsType nmp_cache_update_netlink (NMPCache *cache,
|
|
|
|
|
NMPObject *obj,
|
|
|
|
|
const NMPObject **out_obj_old,
|
|
|
|
|
const NMPObject **out_obj_new);
|
|
|
|
|
NMPCacheOpsType nmp_cache_update_link_udev (NMPCache *cache,
|
|
|
|
|
int ifindex,
|
|
|
|
|
struct udev_device *udevice,
|
|
|
|
|
const NMPObject **out_obj_old,
|
|
|
|
|
const NMPObject **out_obj_new);
|
|
|
|
|
NMPCacheOpsType nmp_cache_update_link_master_connected (NMPCache *cache,
|
|
|
|
|
int ifindex,
|
|
|
|
|
const NMPObject **out_obj_old,
|
|
|
|
|
const NMPObject **out_obj_new);
|
|
|
|
|
|
|
|
|
|
void nmp_cache_dirty_set_all (NMPCache *cache, NMPObjectType obj_type);
|
|
|
|
|
|
|
|
|
|
NMPCache *nmp_cache_new (NMDedupMultiIndex *multi_idx, gboolean use_udev);
|
2015-04-14 23:14:06 +02:00
|
|
|
void nmp_cache_free (NMPCache *cache);
|
|
|
|
|
|
platform: use NMDedupMultiIndex for routes in NMPCache
Rework platform object cache to use NMDedupMultiIndex.
Already previously, NMPCache used NMMultiIndex and had thus
O(1) for most operations. What is new is:
- Contrary to NMMultiIndex, NMDedupMultiIndex preserves the order of
the cached items. That is crucial to handle routes properly as kernel
will replace the first matching route based on network/plen/metric
properties. See related bug rh#1337855.
Without tracking the order of routes as they are exposed
by kernel, we cannot properly maintain the route cache.
- All NMPObject instances are now treated immutable, refcounted
and get de-duplicated via NMDedupMultiIndex. This allows
to have a global NMDedupMultiIndex that can be shared with
NMIP4Config and NMRouteManager. It also allows to share the
objects themselves.
Immutable objects are so much nicer. We can get rid of the
update pre-hook callback, which was required previously because
we would mutate the object inplace. Now, we can just update
the cache, and compare obj_old and obj_new after the fact.
- NMMultiIndex was treated as an internal of NMPCache. On the other
hand, NMDedupMultiIndex exposes NMDedupMultiHeadEntry, which is
basically an object that allows to iterate over all related
objects. That means, we can now lookup objects in the cache
and give the NMDedupMultiHeadEntry instance to the caller,
which then can iterate the list on it's own -- without need
for copying anything.
Currently, at various places we still create copies of lookup
results. That can be improved later.
The ability to share NMPObject instances should enable us to
significantly improve performance and scale with large number
of routes.
Of course there is a memory overhead of having an index for each list
entry. Each NMPObject may also require an NMDedupMultiEntry,
NMDedupMultiHeadEntry, and NMDedupMultiBox item, which are tracked
in a GHashTable. Optimally, one NMDedupMultiHeadEntry is the head
for multiple objects, and NMDedupMultiBox is able to deduplicate several
NMPObjects, so that there is a net saving.
Also, each object type has several indexes of type NMPCacheIdType.
So, worst case an NMPlatformIP4Route in the platform cache is tracked
by 8 NMPCacheIdType indexes, for each we require a NMDedupMultiEntry,
plus the shared NMDedupMultiHeadEntry. The NMDedupMultiBox instance
is shared between the 8 indexes (and possibly other).
2017-06-21 10:53:34 +02:00
|
|
|
static inline void
|
|
|
|
|
ASSERT_nmp_cache_ops (const NMPCache *cache,
|
|
|
|
|
NMPCacheOpsType ops_type,
|
|
|
|
|
const NMPObject *obj_old,
|
|
|
|
|
const NMPObject *obj_new)
|
|
|
|
|
{
|
|
|
|
|
#if NM_MORE_ASSERTS
|
|
|
|
|
nm_assert (cache);
|
|
|
|
|
nm_assert (obj_old || obj_new);
|
|
|
|
|
nm_assert (!obj_old || ( NMP_OBJECT_IS_VALID (obj_old)
|
|
|
|
|
&& !NMP_OBJECT_IS_STACKINIT (obj_old)
|
|
|
|
|
&& nmp_object_is_alive (obj_old)));
|
|
|
|
|
nm_assert (!obj_new || ( NMP_OBJECT_IS_VALID (obj_new)
|
|
|
|
|
&& !NMP_OBJECT_IS_STACKINIT (obj_new)
|
|
|
|
|
&& nmp_object_is_alive (obj_new)));
|
|
|
|
|
|
|
|
|
|
switch (ops_type) {
|
|
|
|
|
case NMP_CACHE_OPS_UNCHANGED:
|
|
|
|
|
nm_assert (obj_old == obj_new);
|
|
|
|
|
break;
|
|
|
|
|
case NMP_CACHE_OPS_ADDED:
|
|
|
|
|
nm_assert (!obj_old && obj_new);
|
|
|
|
|
break;
|
|
|
|
|
case NMP_CACHE_OPS_UPDATED:
|
|
|
|
|
nm_assert (obj_old && obj_new && obj_old != obj_new);
|
|
|
|
|
break;
|
|
|
|
|
case NMP_CACHE_OPS_REMOVED:
|
|
|
|
|
nm_assert (obj_old && !obj_new);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
nm_assert_not_reached ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nm_assert (obj_new == NULL || obj_old == NULL || nmp_object_id_equal (obj_new, obj_old));
|
|
|
|
|
nm_assert (!obj_old || !obj_new || NMP_OBJECT_GET_CLASS (obj_old) == NMP_OBJECT_GET_CLASS (obj_new));
|
|
|
|
|
|
|
|
|
|
nm_assert (obj_new == nmp_cache_lookup_obj (cache, obj_new ?: obj_old));
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-29 14:46:32 +02:00
|
|
|
static inline const NMDedupMultiHeadEntry *
|
|
|
|
|
nm_platform_lookup_obj_type (NMPlatform *platform,
|
2017-07-04 11:44:27 +02:00
|
|
|
NMPObjectType obj_type)
|
2017-06-29 14:46:32 +02:00
|
|
|
{
|
|
|
|
|
NMPLookup lookup;
|
|
|
|
|
|
2017-07-04 11:44:27 +02:00
|
|
|
nmp_lookup_init_obj_type (&lookup, obj_type);
|
2017-06-29 14:46:32 +02:00
|
|
|
return nm_platform_lookup (platform, &lookup);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline const NMDedupMultiHeadEntry *
|
|
|
|
|
nm_platform_lookup_link_by_ifname (NMPlatform *platform,
|
|
|
|
|
const char *ifname)
|
|
|
|
|
{
|
|
|
|
|
NMPLookup lookup;
|
|
|
|
|
|
|
|
|
|
nmp_lookup_init_link_by_ifname (&lookup, ifname);
|
|
|
|
|
return nm_platform_lookup (platform, &lookup);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline const NMDedupMultiHeadEntry *
|
|
|
|
|
nm_platform_lookup_addrroute (NMPlatform *platform,
|
|
|
|
|
NMPObjectType obj_type,
|
2017-07-04 11:44:27 +02:00
|
|
|
int ifindex)
|
2017-06-29 14:46:32 +02:00
|
|
|
{
|
|
|
|
|
NMPLookup lookup;
|
|
|
|
|
|
2017-07-04 11:44:27 +02:00
|
|
|
nmp_lookup_init_addrroute (&lookup, obj_type, ifindex);
|
2017-06-29 14:46:32 +02:00
|
|
|
return nm_platform_lookup (platform, &lookup);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline const NMDedupMultiHeadEntry *
|
|
|
|
|
nm_platform_lookup_route_visible (NMPlatform *platform,
|
|
|
|
|
NMPObjectType obj_type,
|
|
|
|
|
int ifindex,
|
2017-07-04 10:55:19 +02:00
|
|
|
gboolean only_default)
|
2017-06-29 14:46:32 +02:00
|
|
|
{
|
|
|
|
|
NMPLookup lookup;
|
|
|
|
|
|
2017-07-04 10:55:19 +02:00
|
|
|
nmp_lookup_init_route_visible (&lookup, obj_type, ifindex, only_default);
|
2017-06-29 14:46:32 +02:00
|
|
|
return nm_platform_lookup (platform, &lookup);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-29 15:19:35 +02:00
|
|
|
static inline GPtrArray *
|
|
|
|
|
nm_platform_lookup_route_visible_clone (NMPlatform *platform,
|
|
|
|
|
NMPObjectType obj_type,
|
|
|
|
|
int ifindex,
|
2017-07-04 10:55:19 +02:00
|
|
|
gboolean only_default,
|
2017-06-29 15:19:35 +02:00
|
|
|
gboolean (*predicate) (const NMPObject *obj, gpointer user_data),
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NMPLookup lookup;
|
|
|
|
|
|
2017-07-04 10:55:19 +02:00
|
|
|
nmp_lookup_init_route_visible (&lookup, obj_type, ifindex, only_default);
|
2017-06-29 15:19:35 +02:00
|
|
|
return nm_platform_lookup_clone (platform, &lookup, predicate, user_data);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-29 14:46:32 +02:00
|
|
|
static inline const NMDedupMultiHeadEntry *
|
|
|
|
|
nm_platform_lookup_route_by_dest (NMPlatform *platform,
|
|
|
|
|
int addr_family,
|
|
|
|
|
gconstpointer network,
|
|
|
|
|
guint plen,
|
|
|
|
|
guint32 metric)
|
|
|
|
|
{
|
|
|
|
|
NMPLookup lookup;
|
|
|
|
|
|
|
|
|
|
nmp_lookup_init_route_by_dest (&lookup, addr_family, network, plen, metric);
|
|
|
|
|
return nm_platform_lookup (platform, &lookup);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-14 22:34:01 +02:00
|
|
|
#endif /* __NMP_OBJECT_H__ */
|