platform: move the NMPCache from linux platform to NMPlatform

We want to expose the NMPLookup and NMDedupMultiHeadEntry to the users
of NMPlatform, so that they can iterate the cache directly.

That means, NMPCache becames an integral part of NMPlatform's API
and must also be implemented by NMFakePlatform.
This commit is contained in:
Thomas Haller
2017-06-29 11:18:10 +02:00
parent 485551286c
commit e160928b9e
4 changed files with 121 additions and 82 deletions

View File

@@ -1290,6 +1290,7 @@ src_libNetworkManagerBase_la_SOURCES = \
src/platform/nm-platform-utils.h \ src/platform/nm-platform-utils.h \
src/platform/nm-platform.c \ src/platform/nm-platform.c \
src/platform/nm-platform.h \ src/platform/nm-platform.h \
src/platform/nm-platform-private.h \
src/platform/nm-linux-platform.c \ src/platform/nm-linux-platform.c \
src/platform/nm-linux-platform.h \ src/platform/nm-linux-platform.h \
src/platform/wifi/wifi-utils-nl80211.c \ src/platform/wifi/wifi-utils-nl80211.c \

View File

@@ -48,6 +48,7 @@
#include "nmp-object.h" #include "nmp-object.h"
#include "nmp-netns.h" #include "nmp-netns.h"
#include "nm-platform-utils.h" #include "nm-platform-utils.h"
#include "nm-platform-private.h"
#include "wifi/wifi-utils.h" #include "wifi/wifi-utils.h"
#include "wifi/wifi-utils-wext.h" #include "wifi/wifi-utils-wext.h"
#include "nm-utils/unaligned.h" #include "nm-utils/unaligned.h"
@@ -2573,7 +2574,6 @@ typedef struct {
guint32 nlh_seq_last_handled; guint32 nlh_seq_last_handled;
#endif #endif
guint32 nlh_seq_last_seen; guint32 nlh_seq_last_seen;
NMPCache *cache;
GIOChannel *event_channel; GIOChannel *event_channel;
guint event_id; guint event_id;
@@ -2936,7 +2936,7 @@ do_emit_signal (NMPlatform *platform,
nm_assert (NM_IN_SET ((NMPlatformSignalChangeType) cache_op, (NMPlatformSignalChangeType) NMP_CACHE_OPS_UNCHANGED, NM_PLATFORM_SIGNAL_ADDED, NM_PLATFORM_SIGNAL_CHANGED, NM_PLATFORM_SIGNAL_REMOVED)); nm_assert (NM_IN_SET ((NMPlatformSignalChangeType) cache_op, (NMPlatformSignalChangeType) NMP_CACHE_OPS_UNCHANGED, NM_PLATFORM_SIGNAL_ADDED, NM_PLATFORM_SIGNAL_CHANGED, NM_PLATFORM_SIGNAL_REMOVED));
ASSERT_nmp_cache_ops (NM_LINUX_PLATFORM_GET_PRIVATE (platform)->cache, cache_op, obj_old, obj_new); ASSERT_nmp_cache_ops (nm_platform_get_cache (platform), cache_op, obj_old, obj_new);
ASSERT_NETNS_CURRENT (platform); ASSERT_NETNS_CURRENT (platform);
@@ -3161,12 +3161,11 @@ delayed_action_wait_for_nl_response_complete_all (NMPlatform *platform,
static void static void
delayed_action_handle_MASTER_CONNECTED (NMPlatform *platform, int master_ifindex) delayed_action_handle_MASTER_CONNECTED (NMPlatform *platform, int master_ifindex)
{ {
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
nm_auto_nmpobj const NMPObject *obj_old = NULL; nm_auto_nmpobj const NMPObject *obj_old = NULL;
nm_auto_nmpobj const NMPObject *obj_new = NULL; nm_auto_nmpobj const NMPObject *obj_new = NULL;
NMPCacheOpsType cache_op; NMPCacheOpsType cache_op;
cache_op = nmp_cache_update_link_master_connected (priv->cache, master_ifindex, &obj_old, &obj_new); cache_op = nmp_cache_update_link_master_connected (nm_platform_get_cache (platform), master_ifindex, &obj_old, &obj_new);
if (cache_op == NMP_CACHE_OPS_UNCHANGED) if (cache_op == NMP_CACHE_OPS_UNCHANGED)
return; return;
cache_on_change (platform, cache_op, obj_old, obj_new); cache_on_change (platform, cache_op, obj_old, obj_new);
@@ -3356,17 +3355,17 @@ delayed_action_schedule_WAIT_FOR_NL_RESPONSE (NMPlatform *platform,
static void static void
cache_prune_one_type (NMPlatform *platform, NMPObjectType obj_type) cache_prune_one_type (NMPlatform *platform, NMPObjectType obj_type)
{ {
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
NMDedupMultiIter iter; NMDedupMultiIter iter;
const NMPObject *obj; const NMPObject *obj;
NMPCacheOpsType cache_op; NMPCacheOpsType cache_op;
NMPLookup lookup; NMPLookup lookup;
NMPCache *cache = nm_platform_get_cache (platform);
nmp_lookup_init_obj_type (&lookup, nmp_lookup_init_obj_type (&lookup,
obj_type, obj_type,
FALSE); FALSE);
nm_dedup_multi_iter_init (&iter, nm_dedup_multi_iter_init (&iter,
nmp_cache_lookup (priv->cache, nmp_cache_lookup (cache,
&lookup)); &lookup));
while (nm_dedup_multi_iter_next (&iter)) { while (nm_dedup_multi_iter_next (&iter)) {
if (iter.current->dirty) { if (iter.current->dirty) {
@@ -3374,7 +3373,7 @@ cache_prune_one_type (NMPlatform *platform, NMPObjectType obj_type)
obj = iter.current->box->obj; obj = iter.current->box->obj;
_LOGt ("cache-prune: prune %s", nmp_object_to_string (obj, NMP_OBJECT_TO_STRING_ALL, NULL, 0)); _LOGt ("cache-prune: prune %s", nmp_object_to_string (obj, NMP_OBJECT_TO_STRING_ALL, NULL, 0));
cache_op = nmp_cache_remove (priv->cache, obj, TRUE, &obj_old); cache_op = nmp_cache_remove (cache, obj, TRUE, &obj_old);
nm_assert (cache_op == NMP_CACHE_OPS_REMOVED); nm_assert (cache_op == NMP_CACHE_OPS_REMOVED);
cache_on_change (platform, cache_op, obj_old, NULL); cache_on_change (platform, cache_op, obj_old, NULL);
do_emit_signal (platform, cache_op, obj_old, NULL); do_emit_signal (platform, cache_op, obj_old, NULL);
@@ -3405,12 +3404,12 @@ cache_on_change (NMPlatform *platform,
const NMPObject *obj_old, const NMPObject *obj_old,
const NMPObject *obj_new) const NMPObject *obj_new)
{ {
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
const NMPClass *klass; const NMPClass *klass;
char str_buf[sizeof (_nm_utils_to_string_buffer)]; char str_buf[sizeof (_nm_utils_to_string_buffer)];
char str_buf2[sizeof (_nm_utils_to_string_buffer)]; char str_buf2[sizeof (_nm_utils_to_string_buffer)];
NMPCache *cache = nm_platform_get_cache (platform);
ASSERT_nmp_cache_ops (priv->cache, cache_op, obj_old, obj_new); ASSERT_nmp_cache_ops (cache, cache_op, obj_old, obj_new);
if (cache_op == NMP_CACHE_OPS_UNCHANGED) if (cache_op == NMP_CACHE_OPS_UNCHANGED)
return; return;
@@ -3437,17 +3436,17 @@ cache_on_change (NMPlatform *platform,
{ {
/* check whether changing a slave link can cause a master link (bridge or bond) to go up/down */ /* check whether changing a slave link can cause a master link (bridge or bond) to go up/down */
if ( obj_old if ( obj_old
&& nmp_cache_link_connected_needs_toggle_by_ifindex (priv->cache, obj_old->link.master, obj_new, obj_old)) && nmp_cache_link_connected_needs_toggle_by_ifindex (cache, obj_old->link.master, obj_new, obj_old))
delayed_action_schedule (platform, DELAYED_ACTION_TYPE_MASTER_CONNECTED, GINT_TO_POINTER (obj_old->link.master)); delayed_action_schedule (platform, DELAYED_ACTION_TYPE_MASTER_CONNECTED, GINT_TO_POINTER (obj_old->link.master));
if ( obj_new if ( obj_new
&& (!obj_old || obj_old->link.master != obj_new->link.master) && (!obj_old || obj_old->link.master != obj_new->link.master)
&& nmp_cache_link_connected_needs_toggle_by_ifindex (priv->cache, obj_new->link.master, obj_new, obj_old)) && nmp_cache_link_connected_needs_toggle_by_ifindex (cache, obj_new->link.master, obj_new, obj_old))
delayed_action_schedule (platform, DELAYED_ACTION_TYPE_MASTER_CONNECTED, GINT_TO_POINTER (obj_new->link.master)); delayed_action_schedule (platform, DELAYED_ACTION_TYPE_MASTER_CONNECTED, GINT_TO_POINTER (obj_new->link.master));
} }
{ {
/* check whether we are about to change a master link that needs toggling connected state. */ /* check whether we are about to change a master link that needs toggling connected state. */
if ( obj_new /* <-- nonsensical, make coverity happy */ if ( obj_new /* <-- nonsensical, make coverity happy */
&& nmp_cache_link_connected_needs_toggle (priv->cache, obj_new, obj_new, obj_old)) && nmp_cache_link_connected_needs_toggle (cache, obj_new, obj_new, obj_old))
delayed_action_schedule (platform, DELAYED_ACTION_TYPE_MASTER_CONNECTED, GINT_TO_POINTER (obj_new->link.ifindex)); delayed_action_schedule (platform, DELAYED_ACTION_TYPE_MASTER_CONNECTED, GINT_TO_POINTER (obj_new->link.ifindex));
} }
{ {
@@ -3497,7 +3496,7 @@ cache_on_change (NMPlatform *platform,
nmp_lookup_init_link (&lookup, FALSE); nmp_lookup_init_link (&lookup, FALSE);
nmp_cache_iter_for_each_link (&iter, nmp_cache_iter_for_each_link (&iter,
nmp_cache_lookup (priv->cache, &lookup), nmp_cache_lookup (cache, &lookup),
&l) { &l) {
if (l->parent == ifindex) if (l->parent == ifindex)
delayed_action_schedule (platform, DELAYED_ACTION_TYPE_REFRESH_LINK, GINT_TO_POINTER (l->ifindex)); delayed_action_schedule (platform, DELAYED_ACTION_TYPE_REFRESH_LINK, GINT_TO_POINTER (l->ifindex));
@@ -3637,8 +3636,6 @@ cache_post (NMPlatform *platform,
const NMPObject *obj_old, const NMPObject *obj_old,
const NMPObject *obj_new) const NMPObject *obj_new)
{ {
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
if (msghdr->nlmsg_type == RTM_NEWROUTE) { if (msghdr->nlmsg_type == RTM_NEWROUTE) {
DelayedActionType action_type; DelayedActionType action_type;
@@ -3646,7 +3643,7 @@ cache_post (NMPlatform *platform,
? DELAYED_ACTION_TYPE_REFRESH_ALL_IP4_ROUTES ? DELAYED_ACTION_TYPE_REFRESH_ALL_IP4_ROUTES
: DELAYED_ACTION_TYPE_REFRESH_ALL_IP6_ROUTES; : DELAYED_ACTION_TYPE_REFRESH_ALL_IP6_ROUTES;
if ( !delayed_action_refresh_all_in_progress (platform, action_type) if ( !delayed_action_refresh_all_in_progress (platform, action_type)
&& nmp_cache_find_other_route_for_same_destination (priv->cache, obj)) { && nmp_cache_find_other_route_for_same_destination (nm_platform_get_cache (platform), obj)) {
/* via `iproute route change` the user can update an existing route which effectively /* via `iproute route change` the user can update an existing route which effectively
* means that a new object (with a different ID) comes into existance, replacing the * means that a new object (with a different ID) comes into existance, replacing the
* old on. In other words, as the ID of the object changes, we really see a new * old on. In other words, as the ID of the object changes, we really see a new
@@ -3708,7 +3705,7 @@ do_request_link_no_delayed_actions (NMPlatform *platform, int ifindex, const cha
if (ifindex > 0) { if (ifindex > 0) {
const NMDedupMultiEntry *entry; const NMDedupMultiEntry *entry;
entry = nmp_cache_lookup_entry_link (priv->cache, ifindex); entry = nmp_cache_lookup_entry_link (nm_platform_get_cache (platform), ifindex);
if (entry) { if (entry) {
priv->pruning[DELAYED_ACTION_IDX_REFRESH_ALL_LINKS] = TRUE; priv->pruning[DELAYED_ACTION_IDX_REFRESH_ALL_LINKS] = TRUE;
nm_dedup_multi_entry_set_dirty (entry, TRUE); nm_dedup_multi_entry_set_dirty (entry, TRUE);
@@ -3745,7 +3742,7 @@ do_request_all_no_delayed_actions (NMPlatform *platform, DelayedActionType actio
FOR_EACH_DELAYED_ACTION (iflags, action_type) { FOR_EACH_DELAYED_ACTION (iflags, action_type) {
priv->pruning[delayed_action_refresh_all_to_idx (iflags)] = TRUE; priv->pruning[delayed_action_refresh_all_to_idx (iflags)] = TRUE;
nmp_cache_dirty_set_all (priv->cache, nmp_cache_dirty_set_all (nm_platform_get_cache (platform),
delayed_action_refresh_to_object_type (iflags)); delayed_action_refresh_to_object_type (iflags));
} }
@@ -3870,12 +3867,12 @@ event_seq_check (NMPlatform *platform, guint32 seq_number, WaitForNlResponseResu
static void static void
event_valid_msg (NMPlatform *platform, struct nl_msg *msg, gboolean handle_events) event_valid_msg (NMPlatform *platform, struct nl_msg *msg, gboolean handle_events)
{ {
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
nm_auto_nmpobj NMPObject *obj = NULL; nm_auto_nmpobj NMPObject *obj = NULL;
NMPCacheOpsType cache_op; NMPCacheOpsType cache_op;
struct nlmsghdr *msghdr; struct nlmsghdr *msghdr;
char buf_nlmsg_type[16]; char buf_nlmsg_type[16];
gboolean id_only = FALSE; gboolean id_only = FALSE;
NMPCache *cache = nm_platform_get_cache (platform);
msghdr = nlmsg_hdr (msg); msghdr = nlmsg_hdr (msg);
@@ -3891,7 +3888,7 @@ event_valid_msg (NMPlatform *platform, struct nl_msg *msg, gboolean handle_event
id_only = TRUE; id_only = TRUE;
} }
obj = nmp_object_new_from_nl (platform, priv->cache, msg, id_only); obj = nmp_object_new_from_nl (platform, cache, msg, id_only);
if (!obj) { if (!obj) {
_LOGT ("event-notification: %s, seq %u: ignore", _LOGT ("event-notification: %s, seq %u: ignore",
_nl_nlmsg_type_to_str (msghdr->nlmsg_type, buf_nlmsg_type, sizeof (buf_nlmsg_type)), _nl_nlmsg_type_to_str (msghdr->nlmsg_type, buf_nlmsg_type, sizeof (buf_nlmsg_type)),
@@ -3914,7 +3911,7 @@ event_valid_msg (NMPlatform *platform, struct nl_msg *msg, gboolean handle_event
case RTM_NEWADDR: case RTM_NEWADDR:
case RTM_NEWROUTE: case RTM_NEWROUTE:
case RTM_GETLINK: case RTM_GETLINK:
cache_op = nmp_cache_update_netlink (priv->cache, obj, &obj_old, &obj_new); cache_op = nmp_cache_update_netlink (cache, obj, &obj_old, &obj_new);
cache_on_change (platform, cache_op, obj_old, obj_new); cache_on_change (platform, cache_op, obj_old, obj_new);
cache_post (platform, msghdr, cache_op, obj, obj_old, obj_new); cache_post (platform, msghdr, cache_op, obj, obj_old, obj_new);
do_emit_signal (platform, cache_op, obj_old, obj_new); do_emit_signal (platform, cache_op, obj_old, obj_new);
@@ -3923,7 +3920,7 @@ event_valid_msg (NMPlatform *platform, struct nl_msg *msg, gboolean handle_event
case RTM_DELLINK: case RTM_DELLINK:
case RTM_DELADDR: case RTM_DELADDR:
case RTM_DELROUTE: case RTM_DELROUTE:
cache_op = nmp_cache_remove_netlink (priv->cache, obj, &obj_old, &obj_new); cache_op = nmp_cache_remove_netlink (cache, obj, &obj_old, &obj_new);
if (cache_op != NMP_CACHE_OPS_UNCHANGED) { if (cache_op != NMP_CACHE_OPS_UNCHANGED) {
cache_on_change (platform, cache_op, obj_old, obj_new); cache_on_change (platform, cache_op, obj_old, obj_new);
do_emit_signal (platform, cache_op, obj_old, obj_new); do_emit_signal (platform, cache_op, obj_old, obj_new);
@@ -3943,7 +3940,7 @@ cache_lookup_link (NMPlatform *platform, int ifindex)
{ {
const NMPObject *obj_cache; const NMPObject *obj_cache;
obj_cache = nmp_cache_lookup_link (NM_LINUX_PLATFORM_GET_PRIVATE (platform)->cache, ifindex); obj_cache = nmp_cache_lookup_link (nm_platform_get_cache (platform), ifindex);
if (!nmp_object_is_visible (obj_cache)) if (!nmp_object_is_visible (obj_cache))
return NULL; return NULL;
@@ -3953,11 +3950,10 @@ cache_lookup_link (NMPlatform *platform, int ifindex)
static GArray * static GArray *
link_get_all (NMPlatform *platform) link_get_all (NMPlatform *platform)
{ {
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
NMPLookup lookup; NMPLookup lookup;
nmp_lookup_init_link (&lookup, TRUE); nmp_lookup_init_link (&lookup, TRUE);
return nmp_cache_lookup_to_array (nmp_cache_lookup (priv->cache, &lookup), return nmp_cache_lookup_to_array (nmp_cache_lookup (nm_platform_get_cache (platform), &lookup),
NMP_OBJECT_TYPE_LINK); NMP_OBJECT_TYPE_LINK);
} }
@@ -3977,7 +3973,7 @@ _nm_platform_link_get_by_ifname (NMPlatform *platform,
const NMPObject *obj = NULL; const NMPObject *obj = NULL;
if (ifname && *ifname) { if (ifname && *ifname) {
obj = nmp_cache_lookup_link_full (NM_LINUX_PLATFORM_GET_PRIVATE (platform)->cache, obj = nmp_cache_lookup_link_full (nm_platform_get_cache (platform),
0, ifname, TRUE, NM_LINK_TYPE_NONE, NULL, NULL); 0, ifname, TRUE, NM_LINK_TYPE_NONE, NULL, NULL);
} }
return obj ? &obj->link : NULL; return obj ? &obj->link : NULL;
@@ -4010,7 +4006,7 @@ _nm_platform_link_get_by_address (NMPlatform *platform,
if (!address) if (!address)
return NULL; return NULL;
obj = nmp_cache_lookup_link_full (NM_LINUX_PLATFORM_GET_PRIVATE (platform)->cache, obj = nmp_cache_lookup_link_full (nm_platform_get_cache (platform),
0, NULL, TRUE, NM_LINK_TYPE_NONE, 0, NULL, TRUE, NM_LINK_TYPE_NONE,
(NMPObjectMatchFn) _nm_platform_link_get_by_address_match_link, &d); (NMPObjectMatchFn) _nm_platform_link_get_by_address_match_link, &d);
return obj ? &obj->link : NULL; return obj ? &obj->link : NULL;
@@ -4047,19 +4043,19 @@ do_add_link_with_lookup (NMPlatform *platform,
struct nl_msg *nlmsg, struct nl_msg *nlmsg,
const NMPlatformLink **out_link) const NMPlatformLink **out_link)
{ {
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
const NMPObject *obj = NULL; const NMPObject *obj = NULL;
WaitForNlResponseResult seq_result = WAIT_FOR_NL_RESPONSE_RESULT_UNKNOWN; WaitForNlResponseResult seq_result = WAIT_FOR_NL_RESPONSE_RESULT_UNKNOWN;
int nle; int nle;
char s_buf[256]; char s_buf[256];
NMPCache *cache = nm_platform_get_cache (platform);
event_handler_read_netlink (platform, FALSE); event_handler_read_netlink (platform, FALSE);
if (nmp_cache_lookup_link_full (priv->cache, 0, name, FALSE, NM_LINK_TYPE_NONE, NULL, NULL)) { if (nmp_cache_lookup_link_full (cache, 0, name, FALSE, NM_LINK_TYPE_NONE, NULL, NULL)) {
/* hm, a link with such a name already exists. Try reloading first. */ /* hm, a link with such a name already exists. Try reloading first. */
do_request_link (platform, 0, name); do_request_link (platform, 0, name);
obj = nmp_cache_lookup_link_full (priv->cache, 0, name, FALSE, NM_LINK_TYPE_NONE, NULL, NULL); obj = nmp_cache_lookup_link_full (cache, 0, name, FALSE, NM_LINK_TYPE_NONE, NULL, NULL);
if (obj) { if (obj) {
_LOGE ("do-add-link[%s/%s]: link already exists: %s", _LOGE ("do-add-link[%s/%s]: link already exists: %s",
name, name,
@@ -4091,13 +4087,13 @@ do_add_link_with_lookup (NMPlatform *platform,
wait_for_nl_response_to_string (seq_result, s_buf, sizeof (s_buf))); wait_for_nl_response_to_string (seq_result, s_buf, sizeof (s_buf)));
if (seq_result == WAIT_FOR_NL_RESPONSE_RESULT_RESPONSE_OK) if (seq_result == WAIT_FOR_NL_RESPONSE_RESULT_RESPONSE_OK)
obj = nmp_cache_lookup_link_full (priv->cache, 0, name, FALSE, link_type, NULL, NULL); obj = nmp_cache_lookup_link_full (cache, 0, name, FALSE, link_type, NULL, NULL);
if (!obj) { if (!obj) {
/* either kernel signaled failure, or it signaled success and the link object /* either kernel signaled failure, or it signaled success and the link object
* is not (yet) in the cache. Try to reload it... */ * is not (yet) in the cache. Try to reload it... */
do_request_link (platform, 0, name); do_request_link (platform, 0, name);
obj = nmp_cache_lookup_link_full (priv->cache, 0, name, FALSE, link_type, NULL, NULL); obj = nmp_cache_lookup_link_full (cache, 0, name, FALSE, link_type, NULL, NULL);
} }
if (out_link) if (out_link)
@@ -4108,11 +4104,11 @@ do_add_link_with_lookup (NMPlatform *platform,
static gboolean static gboolean
do_add_addrroute (NMPlatform *platform, const NMPObject *obj_id, struct nl_msg *nlmsg) do_add_addrroute (NMPlatform *platform, const NMPObject *obj_id, struct nl_msg *nlmsg)
{ {
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
WaitForNlResponseResult seq_result = WAIT_FOR_NL_RESPONSE_RESULT_UNKNOWN; WaitForNlResponseResult seq_result = WAIT_FOR_NL_RESPONSE_RESULT_UNKNOWN;
int nle; int nle;
char s_buf[256]; char s_buf[256];
const NMPObject *obj; const NMPObject *obj;
NMPCache *cache = nm_platform_get_cache (platform);
nm_assert (NM_IN_SET (NMP_OBJECT_GET_TYPE (obj_id), nm_assert (NM_IN_SET (NMP_OBJECT_GET_TYPE (obj_id),
NMP_OBJECT_TYPE_IP4_ADDRESS, NMP_OBJECT_TYPE_IP6_ADDRESS, NMP_OBJECT_TYPE_IP4_ADDRESS, NMP_OBJECT_TYPE_IP6_ADDRESS,
@@ -4150,10 +4146,10 @@ do_add_addrroute (NMPlatform *platform, const NMPObject *obj_id, struct nl_msg *
* FIXME: if the object already existed previously, we might not notice a * FIXME: if the object already existed previously, we might not notice a
* missing update. It's not clear how to fix that reliably without refechting * missing update. It's not clear how to fix that reliably without refechting
* all the time. */ * all the time. */
obj = nmp_cache_lookup_obj (priv->cache, obj_id); obj = nmp_cache_lookup_obj (cache, obj_id);
if (!obj) { if (!obj) {
do_request_one_type (platform, NMP_OBJECT_GET_TYPE (obj_id)); do_request_one_type (platform, NMP_OBJECT_GET_TYPE (obj_id));
obj = nmp_cache_lookup_obj (priv->cache, obj_id); obj = nmp_cache_lookup_obj (cache, obj_id);
} }
/* Adding is only successful, if kernel reported success *and* we have the /* Adding is only successful, if kernel reported success *and* we have the
@@ -4164,12 +4160,12 @@ do_add_addrroute (NMPlatform *platform, const NMPObject *obj_id, struct nl_msg *
static gboolean static gboolean
do_delete_object (NMPlatform *platform, const NMPObject *obj_id, struct nl_msg *nlmsg) do_delete_object (NMPlatform *platform, const NMPObject *obj_id, struct nl_msg *nlmsg)
{ {
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
WaitForNlResponseResult seq_result = WAIT_FOR_NL_RESPONSE_RESULT_UNKNOWN; WaitForNlResponseResult seq_result = WAIT_FOR_NL_RESPONSE_RESULT_UNKNOWN;
int nle; int nle;
char s_buf[256]; char s_buf[256];
gboolean success = TRUE; gboolean success = TRUE;
const char *log_detail = ""; const char *log_detail = "";
NMPCache *cache = nm_platform_get_cache (platform);
event_handler_read_netlink (platform, FALSE); event_handler_read_netlink (platform, FALSE);
@@ -4208,13 +4204,13 @@ do_delete_object (NMPlatform *platform, const NMPObject *obj_id, struct nl_msg *
log_detail); log_detail);
out: out:
if (!nmp_cache_lookup_obj (priv->cache, obj_id)) if (!nmp_cache_lookup_obj (cache, obj_id))
return TRUE; return TRUE;
/* such an object still exists in the cache. To be sure, refetch it (and /* such an object still exists in the cache. To be sure, refetch it (and
* hope it's gone) */ * hope it's gone) */
do_request_one_type (platform, NMP_OBJECT_GET_TYPE (obj_id)); do_request_one_type (platform, NMP_OBJECT_GET_TYPE (obj_id));
return !!nmp_cache_lookup_obj (priv->cache, obj_id); return !!nmp_cache_lookup_obj (cache, obj_id);
} }
static WaitForNlResponseResult static WaitForNlResponseResult
@@ -4349,11 +4345,10 @@ static gboolean
link_delete (NMPlatform *platform, int ifindex) link_delete (NMPlatform *platform, int ifindex)
{ {
nm_auto_nlmsg struct nl_msg *nlmsg = NULL; nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
NMPObject obj_id; NMPObject obj_id;
const NMPObject *obj; const NMPObject *obj;
obj = nmp_cache_lookup_link (priv->cache, ifindex); obj = nmp_cache_lookup_link (nm_platform_get_cache (platform), ifindex);
if (!obj || !obj->_link.netlink.is_in_netlink) if (!obj || !obj->_link.netlink.is_in_netlink)
return FALSE; return FALSE;
@@ -4392,12 +4387,11 @@ link_get_type_name (NMPlatform *platform, int ifindex)
static gboolean static gboolean
link_get_unmanaged (NMPlatform *platform, int ifindex, gboolean *unmanaged) link_get_unmanaged (NMPlatform *platform, int ifindex, gboolean *unmanaged)
{ {
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
const NMPObject *link; const NMPObject *link;
struct udev_device *udevice = NULL; struct udev_device *udevice = NULL;
const char *uproperty; const char *uproperty;
link = nmp_cache_lookup_link (priv->cache, ifindex); link = nmp_cache_lookup_link (nm_platform_get_cache (platform), ifindex);
if (!link) if (!link)
return FALSE; return FALSE;
@@ -4523,7 +4517,7 @@ link_get_udev_device (NMPlatform *platform, int ifindex)
* we want to return whatever we have, even if the link itself * we want to return whatever we have, even if the link itself
* appears invisible via other platform functions. */ * appears invisible via other platform functions. */
obj_cache = nmp_cache_lookup_link (NM_LINUX_PLATFORM_GET_PRIVATE (platform)->cache, ifindex); obj_cache = nmp_cache_lookup_link (nm_platform_get_cache (platform), ifindex);
return obj_cache ? obj_cache->_link.udev.device : NULL; return obj_cache ? obj_cache->_link.udev.device : NULL;
} }
@@ -4661,7 +4655,7 @@ link_set_address (NMPlatform *platform, int ifindex, gconstpointer address, size
/* workaround ENFILE which may be wrongly returned (bgo #770456). /* workaround ENFILE which may be wrongly returned (bgo #770456).
* If the MAC address is as expected, assume success? */ * If the MAC address is as expected, assume success? */
obj_cache = nmp_cache_lookup_link (NM_LINUX_PLATFORM_GET_PRIVATE (platform)->cache, ifindex); obj_cache = nmp_cache_lookup_link (nm_platform_get_cache (platform), ifindex);
if ( obj_cache if ( obj_cache
&& obj_cache->link.addr.len == length && obj_cache->link.addr.len == length
&& memcmp (obj_cache->link.addr.data, address, length) == 0) { && memcmp (obj_cache->link.addr.data, address, length) == 0) {
@@ -5344,7 +5338,6 @@ link_vlan_change (NMPlatform *platform,
const NMVlanQosMapping *egress_map, const NMVlanQosMapping *egress_map,
gsize n_egress_map) gsize n_egress_map)
{ {
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
const NMPObject *obj_cache; const NMPObject *obj_cache;
nm_auto_nlmsg struct nl_msg *nlmsg = NULL; nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
const NMPObjectLnkVlan *lnk; const NMPObjectLnkVlan *lnk;
@@ -5356,7 +5349,7 @@ link_vlan_change (NMPlatform *platform,
char s_ingress[256]; char s_ingress[256];
char s_egress[256]; char s_egress[256];
obj_cache = nmp_cache_lookup_link (priv->cache, ifindex); obj_cache = nmp_cache_lookup_link (nm_platform_get_cache (platform), ifindex);
if ( !obj_cache if ( !obj_cache
|| !obj_cache->_link.netlink.is_in_netlink) { || !obj_cache->_link.netlink.is_in_netlink) {
_LOGD ("link: change %d: %s: link does not exist", ifindex, "vlan"); _LOGD ("link: change %d: %s: link does not exist", ifindex, "vlan");
@@ -5475,7 +5468,7 @@ tun_add (NMPlatform *platform, const char *name, gboolean tap,
return FALSE; return FALSE;
} }
do_request_link (platform, 0, name); do_request_link (platform, 0, name);
obj = nmp_cache_lookup_link_full (NM_LINUX_PLATFORM_GET_PRIVATE (platform)->cache, obj = nmp_cache_lookup_link_full (nm_platform_get_cache (platform),
0, name, FALSE, 0, name, FALSE,
tap ? NM_LINK_TYPE_TAP : NM_LINK_TYPE_TUN, tap ? NM_LINK_TYPE_TAP : NM_LINK_TYPE_TUN,
NULL, NULL); NULL, NULL);
@@ -5525,7 +5518,6 @@ _infiniband_partition_action (NMPlatform *platform,
int p_key, int p_key,
const NMPlatformLink **out_link) const NMPlatformLink **out_link)
{ {
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
nm_auto_close int dirfd = -1; nm_auto_close int dirfd = -1;
char ifname_parent[IFNAMSIZ]; char ifname_parent[IFNAMSIZ];
const NMPObject *obj; const NMPObject *obj;
@@ -5561,7 +5553,7 @@ _infiniband_partition_action (NMPlatform *platform,
if (action == INFINIBAND_ACTION_DELETE_CHILD) if (action == INFINIBAND_ACTION_DELETE_CHILD)
return TRUE; return TRUE;
obj = nmp_cache_lookup_link_full (priv->cache, 0, name, FALSE, obj = nmp_cache_lookup_link_full (nm_platform_get_cache (platform), 0, name, FALSE,
NM_LINK_TYPE_INFINIBAND, NULL, NULL); NM_LINK_TYPE_INFINIBAND, NULL, NULL);
if (out_link) if (out_link)
*out_link = obj ? &obj->link : NULL; *out_link = obj ? &obj->link : NULL;
@@ -5699,10 +5691,10 @@ wifi_indicate_addressing_running (NMPlatform *platform, int ifindex, gboolean ru
static gboolean static gboolean
link_can_assume (NMPlatform *platform, int ifindex) link_can_assume (NMPlatform *platform, int ifindex)
{ {
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
NMPLookup lookup; NMPLookup lookup;
const NMPObject *link, *o; const NMPObject *link, *o;
NMDedupMultiIter iter; NMDedupMultiIter iter;
NMPCache *cache = nm_platform_get_cache (platform);
if (ifindex <= 0) if (ifindex <= 0)
return FALSE; return FALSE;
@@ -5721,7 +5713,7 @@ link_can_assume (NMPlatform *platform, int ifindex)
NMP_OBJECT_TYPE_IP4_ADDRESS, NMP_OBJECT_TYPE_IP4_ADDRESS,
ifindex, ifindex,
TRUE); TRUE);
if (nmp_cache_lookup (priv->cache, &lookup)) if (nmp_cache_lookup (cache, &lookup))
return TRUE; return TRUE;
nmp_lookup_init_addrroute (&lookup, nmp_lookup_init_addrroute (&lookup,
@@ -5729,7 +5721,7 @@ link_can_assume (NMPlatform *platform, int ifindex)
ifindex, ifindex,
TRUE); TRUE);
nmp_cache_iter_for_each (&iter, nmp_cache_iter_for_each (&iter,
nmp_cache_lookup (priv->cache, &lookup), nmp_cache_lookup (cache, &lookup),
&o) { &o) {
nm_assert (NMP_OBJECT_GET_TYPE (o) == NMP_OBJECT_TYPE_IP6_ADDRESS); nm_assert (NMP_OBJECT_GET_TYPE (o) == NMP_OBJECT_TYPE_IP6_ADDRESS);
if (!IN6_IS_ADDR_LINKLOCAL (&o->ip6_address.address)) if (!IN6_IS_ADDR_LINKLOCAL (&o->ip6_address.address))
@@ -5811,7 +5803,6 @@ link_get_driver_info (NMPlatform *platform,
static GArray * static GArray *
ipx_address_get_all (NMPlatform *platform, int ifindex, NMPObjectType obj_type) ipx_address_get_all (NMPlatform *platform, int ifindex, NMPObjectType obj_type)
{ {
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
NMPLookup lookup; NMPLookup lookup;
nm_assert (NM_IN_SET (obj_type, NMP_OBJECT_TYPE_IP4_ADDRESS, NMP_OBJECT_TYPE_IP6_ADDRESS)); nm_assert (NM_IN_SET (obj_type, NMP_OBJECT_TYPE_IP4_ADDRESS, NMP_OBJECT_TYPE_IP6_ADDRESS));
@@ -5819,7 +5810,7 @@ ipx_address_get_all (NMPlatform *platform, int ifindex, NMPObjectType obj_type)
obj_type, obj_type,
ifindex, ifindex,
TRUE); TRUE);
return nmp_cache_lookup_to_array (nmp_cache_lookup (priv->cache, &lookup), return nmp_cache_lookup_to_array (nmp_cache_lookup (nm_platform_get_cache (platform), &lookup),
obj_type); obj_type);
} }
@@ -5953,7 +5944,7 @@ ip4_address_get (NMPlatform *platform, int ifindex, in_addr_t addr, guint8 plen,
const NMPObject *obj; const NMPObject *obj;
nmp_object_stackinit_id_ip4_address (&obj_id, ifindex, addr, plen, peer_address); nmp_object_stackinit_id_ip4_address (&obj_id, ifindex, addr, plen, peer_address);
obj = nmp_cache_lookup_obj (NM_LINUX_PLATFORM_GET_PRIVATE (platform)->cache, &obj_id); obj = nmp_cache_lookup_obj (nm_platform_get_cache (platform), &obj_id);
if (nmp_object_is_visible (obj)) if (nmp_object_is_visible (obj))
return &obj->ip4_address; return &obj->ip4_address;
return NULL; return NULL;
@@ -5966,7 +5957,7 @@ ip6_address_get (NMPlatform *platform, int ifindex, struct in6_addr addr)
const NMPObject *obj; const NMPObject *obj;
nmp_object_stackinit_id_ip6_address (&obj_id, ifindex, &addr); nmp_object_stackinit_id_ip6_address (&obj_id, ifindex, &addr);
obj = nmp_cache_lookup_obj (NM_LINUX_PLATFORM_GET_PRIVATE (platform)->cache, &obj_id); obj = nmp_cache_lookup_obj (nm_platform_get_cache (platform), &obj_id);
if (nmp_object_is_visible (obj)) if (nmp_object_is_visible (obj))
return &obj->ip6_address; return &obj->ip6_address;
return NULL; return NULL;
@@ -5977,7 +5968,6 @@ ip6_address_get (NMPlatform *platform, int ifindex, struct in6_addr addr)
static GArray * static GArray *
ipx_route_get_all (NMPlatform *platform, int ifindex, NMPObjectType obj_type, NMPlatformGetRouteFlags flags) ipx_route_get_all (NMPlatform *platform, int ifindex, NMPObjectType obj_type, NMPlatformGetRouteFlags flags)
{ {
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
NMDedupMultiIter iter; NMDedupMultiIter iter;
NMPLookup lookup; NMPLookup lookup;
const NMDedupMultiHeadEntry *head_entry; const NMDedupMultiHeadEntry *head_entry;
@@ -5993,7 +5983,7 @@ ipx_route_get_all (NMPlatform *platform, int ifindex, NMPObjectType obj_type, NM
klass = nmp_class_from_type (obj_type); klass = nmp_class_from_type (obj_type);
head_entry = nmp_cache_lookup (priv->cache, head_entry = nmp_cache_lookup (nm_platform_get_cache (platform),
nmp_lookup_init_route_visible (&lookup, nmp_lookup_init_route_visible (&lookup,
obj_type, obj_type,
ifindex, ifindex,
@@ -6112,7 +6102,6 @@ ip6_route_add (NMPlatform *platform, const NMPlatformIP6Route *route)
static gboolean static gboolean
ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, guint8 plen, guint32 metric) ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, guint8 plen, guint32 metric)
{ {
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
nm_auto_nlmsg struct nl_msg *nlmsg = NULL; nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
NMPObject obj_id; NMPObject obj_id;
@@ -6121,6 +6110,8 @@ ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, guint8 p
nmp_object_stackinit_id_ip4_route (&obj_id, ifindex, network, plen, metric); nmp_object_stackinit_id_ip4_route (&obj_id, ifindex, network, plen, metric);
if (metric == 0) { if (metric == 0) {
NMPCache *cache = nm_platform_get_cache (platform);
/* Deleting an IPv4 route with metric 0 does not only delete an exectly matching route. /* Deleting an IPv4 route with metric 0 does not only delete an exectly matching route.
* If no route with metric 0 exists, it might delete another route to the same destination. * If no route with metric 0 exists, it might delete another route to the same destination.
* For nm_platform_ip4_route_delete() we don't want this semantic. * For nm_platform_ip4_route_delete() we don't want this semantic.
@@ -6129,7 +6120,7 @@ ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, guint8 p
* delayed actions (including re-reading data from netlink). */ * delayed actions (including re-reading data from netlink). */
delayed_action_handle_all (platform, TRUE); delayed_action_handle_all (platform, TRUE);
if (!nmp_cache_lookup_obj (priv->cache, &obj_id)) { if (!nmp_cache_lookup_obj (cache, &obj_id)) {
/* hmm... we are about to delete an IP4 route with metric 0. We must only /* hmm... we are about to delete an IP4 route with metric 0. We must only
* send the delete request if such a route really exists. Above we refreshed * send the delete request if such a route really exists. Above we refreshed
* the platform cache, still no such route exists. * the platform cache, still no such route exists.
@@ -6144,7 +6135,7 @@ ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, guint8 p
* additional expensive cache-resync. */ * additional expensive cache-resync. */
do_request_one_type (platform, NMP_OBJECT_TYPE_IP4_ROUTE); do_request_one_type (platform, NMP_OBJECT_TYPE_IP4_ROUTE);
if (!nmp_cache_lookup_obj (priv->cache, &obj_id)) if (!nmp_cache_lookup_obj (cache, &obj_id))
return TRUE; return TRUE;
} }
} }
@@ -6222,7 +6213,7 @@ ip4_route_get (NMPlatform *platform, int ifindex, in_addr_t network, guint8 plen
const NMPObject *obj; const NMPObject *obj;
nmp_object_stackinit_id_ip4_route (&obj_id, ifindex, network, plen, metric); nmp_object_stackinit_id_ip4_route (&obj_id, ifindex, network, plen, metric);
obj = nmp_cache_lookup_obj (NM_LINUX_PLATFORM_GET_PRIVATE (platform)->cache, &obj_id); obj = nmp_cache_lookup_obj (nm_platform_get_cache (platform), &obj_id);
if (nmp_object_is_visible (obj)) if (nmp_object_is_visible (obj))
return &obj->ip4_route; return &obj->ip4_route;
return NULL; return NULL;
@@ -6237,7 +6228,7 @@ ip6_route_get (NMPlatform *platform, int ifindex, struct in6_addr network, guint
metric = nm_utils_ip6_route_metric_normalize (metric); metric = nm_utils_ip6_route_metric_normalize (metric);
nmp_object_stackinit_id_ip6_route (&obj_id, ifindex, &network, plen, metric); nmp_object_stackinit_id_ip6_route (&obj_id, ifindex, &network, plen, metric);
obj = nmp_cache_lookup_obj (NM_LINUX_PLATFORM_GET_PRIVATE (platform)->cache, &obj_id); obj = nmp_cache_lookup_obj (nm_platform_get_cache (platform), &obj_id);
if (nmp_object_is_visible (obj)) if (nmp_object_is_visible (obj))
return &obj->ip6_route; return &obj->ip6_route;
return NULL; return NULL;
@@ -6603,12 +6594,11 @@ cache_update_link_udev (NMPlatform *platform,
int ifindex, int ifindex,
struct udev_device *udevice) struct udev_device *udevice)
{ {
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
nm_auto_nmpobj const NMPObject *obj_old = NULL; nm_auto_nmpobj const NMPObject *obj_old = NULL;
nm_auto_nmpobj const NMPObject *obj_new = NULL; nm_auto_nmpobj const NMPObject *obj_new = NULL;
NMPCacheOpsType cache_op; NMPCacheOpsType cache_op;
cache_op = nmp_cache_update_link_udev (priv->cache, ifindex, udevice, &obj_old, &obj_new); cache_op = nmp_cache_update_link_udev (nm_platform_get_cache (platform), ifindex, udevice, &obj_old, &obj_new);
if (cache_op != NMP_CACHE_OPS_UNCHANGED) { if (cache_op != NMP_CACHE_OPS_UNCHANGED) {
nm_auto_pop_netns NMPNetns *netns = NULL; nm_auto_pop_netns NMPNetns *netns = NULL;
@@ -6672,7 +6662,7 @@ udev_device_removed (NMPlatform *platform,
if (ifindex <= 0) { if (ifindex <= 0) {
const NMPObject *obj; const NMPObject *obj;
obj = nmp_cache_lookup_link_full (NM_LINUX_PLATFORM_GET_PRIVATE (platform)->cache, obj = nmp_cache_lookup_link_full (nm_platform_get_cache (platform),
0, NULL, FALSE, NM_LINK_TYPE_NONE, _udev_device_removed_match_link, udevice); 0, NULL, FALSE, NM_LINK_TYPE_NONE, _udev_device_removed_match_link, udevice);
if (obj) if (obj)
ifindex = obj->link.ifindex; ifindex = obj->link.ifindex;
@@ -6748,9 +6738,6 @@ constructed (GObject *_object)
handle_udev_event, platform); handle_udev_event, platform);
} }
priv->cache = nmp_cache_new (nm_platform_get_multi_idx (platform),
priv->udev_client != NULL);
_LOGD ("create (%s netns, %s, %s udev)", _LOGD ("create (%s netns, %s, %s udev)",
!platform->_netns ? "ignore" : "use", !platform->_netns ? "ignore" : "use",
!platform->_netns && nmp_netns_is_initial () !platform->_netns && nmp_netns_is_initial ()
@@ -6760,7 +6747,7 @@ constructed (GObject *_object)
: nm_sprintf_bufa (100, "in netns[%p]%s", : nm_sprintf_bufa (100, "in netns[%p]%s",
nmp_netns_get_current (), nmp_netns_get_current (),
nmp_netns_get_current () == nmp_netns_get_initial () ? "/main" : "")), nmp_netns_get_current () == nmp_netns_get_initial () ? "/main" : "")),
nmp_cache_use_udev_get (priv->cache) ? "use" : "no"); nm_platform_get_use_udev (platform) ? "use" : "no");
priv->nlh = nl_socket_alloc (); priv->nlh = nl_socket_alloc ();
g_assert (priv->nlh); g_assert (priv->nlh);
@@ -6869,8 +6856,6 @@ finalize (GObject *object)
{ {
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (object); NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (object);
nmp_cache_free (priv->cache);
g_ptr_array_unref (priv->delayed_action.list_master_connected); g_ptr_array_unref (priv->delayed_action.list_master_connected);
g_ptr_array_unref (priv->delayed_action.list_refresh_link); g_ptr_array_unref (priv->delayed_action.list_refresh_link);
g_array_unref (priv->delayed_action.list_wait_for_nl_response); g_array_unref (priv->delayed_action.list_wait_for_nl_response);

View File

@@ -0,0 +1,29 @@
/* -*- 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) 2017 Red Hat, Inc.
*/
#ifndef __NM_PLATFORM_PRIVATE_H__
#define __NM_PLATFORM_PRIVATE_H__
#include "nm-platform.h"
#include "nmp-object.h"
NMPCache *nm_platform_get_cache (NMPlatform *self);
#endif /* __NM_PLATFORM_PRIVATE_H__ */

View File

@@ -39,6 +39,7 @@
#include "nm-core-utils.h" #include "nm-core-utils.h"
#include "nm-platform-utils.h" #include "nm-platform-utils.h"
#include "nm-platform-private.h"
#include "nmp-object.h" #include "nmp-object.h"
#include "nmp-netns.h" #include "nmp-netns.h"
@@ -89,6 +90,7 @@ typedef struct _NMPlatformPrivate {
bool use_udev:1; bool use_udev:1;
bool log_with_ptr:1; bool log_with_ptr:1;
NMDedupMultiIndex *multi_idx; NMDedupMultiIndex *multi_idx;
NMPCache *cache;
} NMPlatformPrivate; } NMPlatformPrivate;
G_DEFINE_TYPE (NMPlatform, nm_platform, G_TYPE_OBJECT) G_DEFINE_TYPE (NMPlatform, nm_platform, G_TYPE_OBJECT)
@@ -206,16 +208,9 @@ nm_platform_get ()
NMDedupMultiIndex * NMDedupMultiIndex *
nm_platform_get_multi_idx (NMPlatform *self) nm_platform_get_multi_idx (NMPlatform *self)
{ {
NMPlatformPrivate *priv;
g_return_val_if_fail (NM_IS_PLATFORM (self), NULL); g_return_val_if_fail (NM_IS_PLATFORM (self), NULL);
priv = NM_PLATFORM_GET_PRIVATE (self); return NM_PLATFORM_GET_PRIVATE (self)->multi_idx;
if (G_UNLIKELY (!priv->multi_idx))
priv->multi_idx = nm_dedup_multi_index_new ();
return priv->multi_idx;
} }
/*****************************************************************************/ /*****************************************************************************/
@@ -4800,6 +4795,12 @@ log_ip6_route (NMPlatform *self, NMPObjectType obj_type, int ifindex, NMPlatform
/*****************************************************************************/ /*****************************************************************************/
NMPCache *
nm_platform_get_cache (NMPlatform *self)
{
return NM_PLATFORM_GET_PRIVATE (self)->cache;
}
NMPNetns * NMPNetns *
nm_platform_netns_get (NMPlatform *self) nm_platform_netns_get (NMPlatform *self)
{ {
@@ -4957,15 +4958,37 @@ nm_platform_init (NMPlatform *self)
self->_priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NM_TYPE_PLATFORM, NMPlatformPrivate); self->_priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NM_TYPE_PLATFORM, NMPlatformPrivate);
} }
static GObject *
constructor (GType type,
guint n_construct_params,
GObjectConstructParam *construct_params)
{
GObject *object;
NMPlatform *self;
NMPlatformPrivate *priv;
object = G_OBJECT_CLASS (nm_platform_parent_class)->constructor (type,
n_construct_params,
construct_params);
self = NM_PLATFORM (object);
priv = NM_PLATFORM_GET_PRIVATE (self);
priv->multi_idx = nm_dedup_multi_index_new ();
priv->cache = nmp_cache_new (nm_platform_get_multi_idx (self),
priv->use_udev);
return object;
}
static void static void
finalize (GObject *object) finalize (GObject *object)
{ {
NMPlatform *self = NM_PLATFORM (object); NMPlatform *self = NM_PLATFORM (object);
NMPlatformPrivate *priv = NM_PLATFORM_GET_PRIVATE (self); NMPlatformPrivate *priv = NM_PLATFORM_GET_PRIVATE (self);
if (priv->multi_idx)
nm_dedup_multi_index_unref (priv->multi_idx);
g_clear_object (&self->_netns); g_clear_object (&self->_netns);
nm_dedup_multi_index_unref (priv->multi_idx);
nmp_cache_free (priv->cache);
} }
static void static void
@@ -4975,6 +4998,7 @@ nm_platform_class_init (NMPlatformClass *platform_class)
g_type_class_add_private (object_class, sizeof (NMPlatformPrivate)); g_type_class_add_private (object_class, sizeof (NMPlatformPrivate));
object_class->constructor = constructor;
object_class->set_property = set_property; object_class->set_property = set_property;
object_class->finalize = finalize; object_class->finalize = finalize;