core: add NMNetns to bundle platform and route managers

NMPlatform, NMRouteManager and NMDefaultRouteManager are singletons
instances. Users of those are for example NMDevice, which registers
to GObject signals of both NMPlatform and NMRouteManager.

Hence, as NMDevice:dispose() disconnects the signal handlers, it must
ensure that those singleton instances live longer then the NMDevice
instance. That is usually accomplished by having users of singleton
instances own a reference to those instances.
For NMDevice that effectively means that it shall own a reference to
several singletons.

NMPlatform, NMRouteManager, and NMDefaultRouteManager are all
per-namespace. In general it doesn't make sense to have more then
one instances of these per name space. Nnote that currently we don't
support multiple namespaces yet. If we will ever support multiple
namespaces, then a NMDevice would have a reference to all of these
manager instances. Hence, introduce a new class NMNetns which bundles
them together.
This commit is contained in:
Thomas Haller 2017-04-17 18:40:52 +02:00
parent df537d2eac
commit 0af2f5c28b
17 changed files with 333 additions and 70 deletions

View file

@ -1445,6 +1445,8 @@ src_libNetworkManager_la_SOURCES = \
src/nm-connectivity.h \
src/nm-dcb.c \
src/nm-dcb.h \
src/nm-netns.c \
src/nm-netns.h \
src/nm-default-route-manager.c \
src/nm-default-route-manager.h \
src/nm-dhcp4-config.c \

View file

@ -52,6 +52,7 @@
#include "nm-connectivity.h"
#include "dns/nm-dns-manager.h"
#include "systemd/nm-sd.h"
#include "nm-netns.h"
#if !defined(NM_DIST_VERSION)
# define NM_DIST_VERSION VERSION
@ -371,6 +372,11 @@ main (int argc, char *argv[])
#endif
);
/* Set up platform interaction layer */
nm_linux_platform_setup ();
NM_UTILS_KEEP_ALIVE (config, nm_netns_get (), "NMConfig-depends-on-NMNetns");
nm_auth_manager_setup (nm_config_data_get_value_boolean (nm_config_get_data_orig (config),
NM_CONFIG_KEYFILE_GROUP_MAIN,
NM_CONFIG_KEYFILE_KEY_MAIN_AUTH_POLKIT,
@ -388,10 +394,6 @@ main (int argc, char *argv[])
}
}
/* Set up platform interaction layer */
nm_linux_platform_setup ();
NM_UTILS_KEEP_ALIVE (config, NM_PLATFORM_GET, "NMConfig-depends-on-NMPlatform");
#if WITH_CONCHECK
NM_UTILS_KEEP_ALIVE (nm_manager_get (), nm_connectivity_get (), "NMManager-depends-on-NMConnectivity");
#endif

View file

@ -36,12 +36,16 @@
/*****************************************************************************/
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
PROP_LOG_WITH_PTR,
PROP_PLATFORM,
);
typedef struct {
GPtrArray *entries_ip4;
GPtrArray *entries_ip6;
NMPlatform *platform;
struct {
guint guard;
guint backoff_wait_time_ms;
@ -56,9 +60,9 @@ typedef struct {
* pointers.
* Guard every publicly accessible function to return early if the instance
* is already disposing. */
gboolean disposed;
bool disposed;
NMPlatform *platform;
bool log_with_ptr;
} NMDefaultRouteManagerPrivate;
struct _NMDefaultRouteManager {
@ -74,8 +78,6 @@ G_DEFINE_TYPE (NMDefaultRouteManager, nm_default_route_manager, G_TYPE_OBJECT)
#define NM_DEFAULT_ROUTE_MANAGER_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMDefaultRouteManager, NM_IS_DEFAULT_ROUTE_MANAGER)
NM_DEFINE_SINGLETON_GETTER (NMDefaultRouteManager, nm_default_route_manager_get, NM_TYPE_DEFAULT_ROUTE_MANAGER);
/*****************************************************************************/
#define _NMLOG_PREFIX_NAME "default-route"
@ -99,7 +101,7 @@ NM_DEFINE_SINGLETON_GETTER (NMDefaultRouteManager, nm_default_route_manager_get,
\
_nm_log (__level, __domain, 0, NULL, NULL, \
"%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
self != singleton_instance \
NM_DEFAULT_ROUTE_MANAGER_GET_PRIVATE (self)->log_with_ptr \
? nm_sprintf_buf (__prefix_buf, "%s%c[%p]", \
_NMLOG2_PREFIX_NAME, \
__addr_family == AF_INET ? '4' : (__addr_family == AF_INET6 ? '6' : '-'), \
@ -125,7 +127,7 @@ NM_DEFINE_SINGLETON_GETTER (NMDefaultRouteManager, nm_default_route_manager_get,
\
_nm_log (__level, __domain, 0, NULL, NULL, \
"%s: entry[%u/%s:%p:%s:%chas:%csync]: "_NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
self != singleton_instance \
NM_DEFAULT_ROUTE_MANAGER_GET_PRIVATE (self)->log_with_ptr \
? nm_sprintf_buf (__prefix_buf, "%s%c[%p]", \
_NMLOG2_PREFIX_NAME, \
__addr_family == AF_INET ? '4' : (__addr_family == AF_INET6 ? '6' : '-'), \
@ -1454,6 +1456,10 @@ set_property (GObject *object, guint prop_id,
NMDefaultRouteManagerPrivate *priv = NM_DEFAULT_ROUTE_MANAGER_GET_PRIVATE (self);
switch (prop_id) {
case PROP_LOG_WITH_PTR:
/* construct-only */
priv->log_with_ptr = g_value_get_boolean (value);
break;
case PROP_PLATFORM:
/* construct-only */
priv->platform = g_value_get_object (value) ? : NM_PLATFORM_GET;
@ -1490,9 +1496,10 @@ constructed (GObject *object)
}
NMDefaultRouteManager *
nm_default_route_manager_new (NMPlatform *platform)
nm_default_route_manager_new (gboolean log_with_ptr, NMPlatform *platform)
{
return g_object_new (NM_TYPE_DEFAULT_ROUTE_MANAGER,
NM_DEFAULT_ROUTE_MANAGER_LOG_WITH_PTR, log_with_ptr,
NM_DEFAULT_ROUTE_MANAGER_PLATFORM, platform,
NULL);
}
@ -1540,6 +1547,13 @@ nm_default_route_manager_class_init (NMDefaultRouteManagerClass *klass)
object_class->dispose = dispose;
object_class->set_property = set_property;
obj_properties[PROP_LOG_WITH_PTR] =
g_param_spec_boolean (NM_DEFAULT_ROUTE_MANAGER_LOG_WITH_PTR, "", "",
FALSE,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_PLATFORM] =
g_param_spec_object (NM_DEFAULT_ROUTE_MANAGER_PLATFORM, "", "",
NM_TYPE_PLATFORM,

View file

@ -30,14 +30,15 @@
#define NM_IS_DEFAULT_ROUTE_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEFAULT_ROUTE_MANAGER))
#define NM_DEFAULT_ROUTE_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEFAULT_ROUTE_MANAGER, NMDefaultRouteManagerClass))
#define NM_DEFAULT_ROUTE_MANAGER_PLATFORM "platform"
#define NM_DEFAULT_ROUTE_MANAGER_LOG_WITH_PTR "log-with-ptr"
#define NM_DEFAULT_ROUTE_MANAGER_PLATFORM "platform"
typedef struct _NMDefaultRouteManagerClass NMDefaultRouteManagerClass;
GType nm_default_route_manager_get_type (void);
NMDefaultRouteManager *nm_default_route_manager_get (void);
NMDefaultRouteManager *nm_default_route_manager_new (NMPlatform *platform);
NMDefaultRouteManager *nm_default_route_manager_new (gboolean log_with_ptr, NMPlatform *platform);
gboolean nm_default_route_manager_ip4_update_default_route (NMDefaultRouteManager *manager, gpointer source);
gboolean nm_default_route_manager_ip6_update_default_route (NMDefaultRouteManager *manager, gpointer source);

View file

@ -42,6 +42,7 @@
#include "nm-utils.h"
#include "nm-setting-ip6-config.h"
#include "systemd/nm-sd.h"
#include "nm-route-manager.h"
#if !defined(NM_DIST_VERSION)
# define NM_DIST_VERSION VERSION
@ -97,6 +98,10 @@ static struct {
/*****************************************************************************/
NM_DEFINE_SINGLETON_GETTER (NMRouteManager, nm_route_manager_get, NM_TYPE_ROUTE_MANAGER);
/*****************************************************************************/
static void
dhcp4_state_changed (NMDhcpClient *client,
NMDhcpState state,

190
src/nm-netns.c Normal file
View file

@ -0,0 +1,190 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* 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 of the License, 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.
*/
#include "nm-default.h"
#include "nm-netns.h"
#include "platform/nm-platform.h"
#include "platform/nmp-netns.h"
#include "nm-route-manager.h"
#include "nm-default-route-manager.h"
#include "nm-core-internal.h"
#include "NetworkManagerUtils.h"
/*****************************************************************************/
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
PROP_PLATFORM,
);
typedef struct {
NMPlatform *platform;
NMPNetns *platform_netns;
NMRouteManager *route_manager;
NMDefaultRouteManager *default_route_manager;
bool log_with_ptr;
} NMNetnsPrivate;
struct _NMNetns {
GObject parent;
NMNetnsPrivate _priv;
};
struct _NMNetnsClass {
GObjectClass parent;
};
G_DEFINE_TYPE (NMNetns, nm_netns, G_TYPE_OBJECT);
#define NM_NETNS_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMNetns, NM_IS_NETNS)
/*****************************************************************************/
NM_DEFINE_SINGLETON_GETTER (NMNetns, nm_netns_get, NM_TYPE_NETNS);
/*****************************************************************************/
NMRouteManager *
nm_route_manager_get (void)
{
return nm_netns_get_route_manager (NM_NETNS_GET);
}
NMDefaultRouteManager *
nm_default_route_manager_get (void)
{
return nm_netns_get_default_route_manager (NM_NETNS_GET);
}
/*****************************************************************************/
NMPNetns *
nm_netns_get_platform_netns (NMNetns *self)
{
return NM_NETNS_GET_PRIVATE (self)->platform_netns;
}
NMPlatform *
nm_netns_get_platform (NMNetns *self)
{
return NM_NETNS_GET_PRIVATE (self)->platform;
}
NMDefaultRouteManager *
nm_netns_get_default_route_manager (NMNetns *self)
{
return NM_NETNS_GET_PRIVATE (self)->default_route_manager;
}
NMRouteManager *
nm_netns_get_route_manager (NMNetns *self)
{
return NM_NETNS_GET_PRIVATE (self)->route_manager;
}
/*****************************************************************************/
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMNetns *self = NM_NETNS (object);
NMNetnsPrivate *priv = NM_NETNS_GET_PRIVATE (self);
switch (prop_id) {
case PROP_PLATFORM:
/* construct-only */
priv->platform = g_value_get_object (value) ?: NM_PLATFORM_GET;
if (!priv->platform)
g_return_if_reached ();
g_object_ref (priv->platform);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
/*****************************************************************************/
static void
nm_netns_init (NMNetns *self)
{
}
static void
constructed (GObject *object)
{
NMNetns *self = NM_NETNS (object);
NMNetnsPrivate *priv = NM_NETNS_GET_PRIVATE (self);
gboolean log_with_ptr;
if (!priv->platform)
g_return_if_reached ();
log_with_ptr = nm_platform_get_log_with_ptr (priv->platform);
priv->platform_netns = nm_platform_netns_get (priv->platform);
priv->route_manager = nm_route_manager_new (log_with_ptr, priv->platform);
priv->default_route_manager = nm_default_route_manager_new (log_with_ptr, priv->platform);
G_OBJECT_CLASS (nm_netns_parent_class)->constructed (object);
}
NMNetns *
nm_netns_new (NMPlatform *platform)
{
return g_object_new (NM_TYPE_NETNS,
NM_NETNS_PLATFORM, platform,
NULL);
}
static void
dispose (GObject *object)
{
NMNetns *self = NM_NETNS (object);
NMNetnsPrivate *priv = NM_NETNS_GET_PRIVATE (self);
g_clear_object (&priv->route_manager);
g_clear_object (&priv->default_route_manager);
g_clear_object (&priv->platform);
G_OBJECT_CLASS (nm_netns_parent_class)->dispose (object);
}
static void
nm_netns_class_init (NMNetnsClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructed = constructed;
object_class->set_property = set_property;
object_class->dispose = dispose;
obj_properties[PROP_PLATFORM] =
g_param_spec_object (NM_NETNS_PLATFORM, "", "",
NM_TYPE_PLATFORM,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
}

47
src/nm-netns.h Normal file
View file

@ -0,0 +1,47 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* 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 of the License, 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_NETNS_H__
#define __NM_NETNS_H__
#define NM_TYPE_NETNS (nm_netns_get_type ())
#define NM_NETNS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_NETNS, NMNetns))
#define NM_NETNS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_NETNS, NMNetnsClass))
#define NM_IS_NETNS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_NETNS))
#define NM_IS_NETNS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_NETNS))
#define NM_NETNS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_NETNS, NMNetnsClass))
#define NM_NETNS_PLATFORM "platform"
typedef struct _NMNetnsClass NMNetnsClass;
GType nm_netns_get_type (void);
NMNetns *nm_netns_get (void);
NMNetns *nm_netns_new (NMPlatform *platform);
NMPlatform *nm_netns_get_platform (NMNetns *self);
NMPNetns *nm_netns_get_platform_netns (NMNetns *self);
NMRouteManager *nm_netns_get_route_manager (NMNetns *self);
NMDefaultRouteManager *nm_netns_get_default_route_manager (NMNetns *self);
#define NM_NETNS_GET (nm_netns_get ())
#endif /* __NM_NETNS_H__ */

View file

@ -70,6 +70,7 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
PROP_LOG_WITH_PTR,
PROP_PLATFORM,
);
@ -82,6 +83,8 @@ typedef struct {
GHashTable *entries;
guint gc_id;
} ip4_device_routes;
bool log_with_ptr;
} NMRouteManagerPrivate;
struct _NMRouteManager {
@ -99,10 +102,6 @@ G_DEFINE_TYPE (NMRouteManager, nm_route_manager, G_TYPE_OBJECT);
/*****************************************************************************/
NM_DEFINE_SINGLETON_GETTER (NMRouteManager, nm_route_manager_get, NM_TYPE_ROUTE_MANAGER);
/*****************************************************************************/
typedef struct {
const NMPlatformVTableRoute *vt;
@ -156,7 +155,7 @@ static const VTableIP vtable_v4, vtable_v6;
char __ch = __addr_family == AF_INET ? '4' : (__addr_family == AF_INET6 ? '6' : '-'); \
char __prefix[30] = _NMLOG_PREFIX_NAME; \
\
if ((self) != singleton_instance) \
if (NM_ROUTE_MANAGER_GET_PRIVATE (self)->log_with_ptr) \
g_snprintf (__prefix, sizeof (__prefix), "%s%c[%p]", _NMLOG_PREFIX_NAME, __ch, (self)); \
else \
__prefix[NM_STRLEN (_NMLOG_PREFIX_NAME)] = __ch; \
@ -1207,6 +1206,10 @@ set_property (GObject *object, guint prop_id,
NMRouteManagerPrivate *priv = NM_ROUTE_MANAGER_GET_PRIVATE (self);
switch (prop_id) {
case PROP_LOG_WITH_PTR:
/* construct-only */
priv->log_with_ptr = g_value_get_boolean (value);
break;
case PROP_PLATFORM:
/* construct-only */
priv->platform = g_value_get_object (value) ? : NM_PLATFORM_GET;
@ -1242,9 +1245,10 @@ nm_route_manager_init (NMRouteManager *self)
}
NMRouteManager *
nm_route_manager_new (NMPlatform *platform)
nm_route_manager_new (gboolean log_with_ptr, NMPlatform *platform)
{
return g_object_new (NM_TYPE_ROUTE_MANAGER,
NM_ROUTE_MANAGER_LOG_WITH_PTR, log_with_ptr,
NM_ROUTE_MANAGER_PLATFORM, platform,
NULL);
}
@ -1291,6 +1295,13 @@ nm_route_manager_class_init (NMRouteManagerClass *klass)
object_class->dispose = dispose;
object_class->finalize = finalize;
obj_properties[PROP_LOG_WITH_PTR] =
g_param_spec_boolean (NM_ROUTE_MANAGER_LOG_WITH_PTR, "", "",
FALSE,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_PLATFORM] =
g_param_spec_object (NM_ROUTE_MANAGER_PLATFORM, "", "",
NM_TYPE_PLATFORM,

View file

@ -28,7 +28,8 @@
#define NM_IS_ROUTE_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_ROUTE_MANAGER))
#define NM_ROUTE_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_ROUTE_MANAGER, NMRouteManagerClass))
#define NM_ROUTE_MANAGER_PLATFORM "platform"
#define NM_ROUTE_MANAGER_LOG_WITH_PTR "log-with-ptr"
#define NM_ROUTE_MANAGER_PLATFORM "platform"
#define NM_ROUTE_MANAGER_IP4_ROUTES_CHANGED "ip4-routes-changed"
@ -44,6 +45,6 @@ gboolean nm_route_manager_ip4_routes_shadowed (NMRouteManager *self, int ifindex
void nm_route_manager_ip4_route_register_device_route_purge_list (NMRouteManager *self, GArray *device_route_purge_list);
NMRouteManager *nm_route_manager_get (void);
NMRouteManager *nm_route_manager_new (NMPlatform *platform);
NMRouteManager *nm_route_manager_new (gboolean log_with_ptr, NMPlatform *platform);
#endif /* __NM_ROUTE_MANAGER_H__ */

View file

@ -46,6 +46,7 @@ typedef struct _NMProxyConfig NMProxyConfig;
typedef struct _NMIP4Config NMIP4Config;
typedef struct _NMIP6Config NMIP6Config;
typedef struct _NMManager NMManager;
typedef struct _NMNetns NMNetns;
typedef struct _NMPolicy NMPolicy;
typedef struct _NMRfkillManager NMRfkillManager;
typedef struct _NMPacrunnerManager NMPacrunnerManager;

View file

@ -82,9 +82,9 @@ G_DEFINE_TYPE (NMFakePlatform, nm_fake_platform, NM_TYPE_PLATFORM)
if (nm_logging_enabled (__level, __domain)) { \
char __prefix[32]; \
const char *__p_prefix = _NMLOG_PREFIX_NAME; \
const void *const __self = (self); \
NMPlatform *const __self = (self); \
\
if (__self && __self != nm_platform_try_get ()) { \
if (__self && nm_platform_get_log_with_ptr (self)) { \
g_snprintf (__prefix, sizeof (__prefix), "%s[%p]", _NMLOG_PREFIX_NAME, __self); \
__p_prefix = __prefix; \
} \
@ -1400,7 +1400,9 @@ nm_fake_platform_setup (void)
{
NMPlatform *platform;
platform = g_object_new (NM_TYPE_FAKE_PLATFORM, NULL);
platform = g_object_new (NM_TYPE_FAKE_PLATFORM,
NM_PLATFORM_LOG_WITH_PTR, FALSE,
NULL);
nm_platform_setup (platform);

View file

@ -145,9 +145,9 @@
G_STMT_START { \
char __prefix[32]; \
const char *__p_prefix = _NMLOG_PREFIX_NAME; \
const void *const __self = (self); \
NMPlatform *const __self = (self); \
\
if (__self && __self != nm_platform_try_get ()) { \
if (__self && nm_platform_get_log_with_ptr (__self)) { \
g_snprintf (__prefix, sizeof (__prefix), "%s[%p]", _NMLOG_PREFIX_NAME, __self); \
__p_prefix = __prefix; \
} \
@ -2583,10 +2583,10 @@ G_DEFINE_TYPE (NMLinuxPlatform, nm_linux_platform, NM_TYPE_PLATFORM)
#define NM_LINUX_PLATFORM_GET_PRIVATE(self) _NM_GET_PRIVATE_VOID(self, NMLinuxPlatform, NM_IS_LINUX_PLATFORM)
NMPlatform *
nm_linux_platform_new (gboolean netns_support)
nm_linux_platform_new (gboolean log_with_ptr, gboolean netns_support)
{
return g_object_new (NM_TYPE_LINUX_PLATFORM,
NM_PLATFORM_REGISTER_SINGLETON, FALSE,
NM_PLATFORM_LOG_WITH_PTR, log_with_ptr,
NM_PLATFORM_NETNS_SUPPORT, netns_support,
NULL);
}
@ -2594,10 +2594,7 @@ nm_linux_platform_new (gboolean netns_support)
void
nm_linux_platform_setup (void)
{
g_object_new (NM_TYPE_LINUX_PLATFORM,
NM_PLATFORM_REGISTER_SINGLETON, TRUE,
NM_PLATFORM_NETNS_SUPPORT, FALSE,
NULL);
nm_platform_setup (nm_linux_platform_new (FALSE, FALSE));
}
static void

View file

@ -35,7 +35,7 @@ typedef struct _NMLinuxPlatformClass NMLinuxPlatformClass;
GType nm_linux_platform_get_type (void);
NMPlatform *nm_linux_platform_new (gboolean netns_support);
NMPlatform *nm_linux_platform_new (gboolean log_with_ptr, gboolean netns_support);
void nm_linux_platform_setup (void);

View file

@ -62,9 +62,9 @@ G_STATIC_ASSERT (G_STRUCT_OFFSET (NMPlatformIPRoute, network_ptr) == G_STRUCT_OF
if (nm_logging_enabled (__level, _NMLOG_DOMAIN)) { \
char __prefix[32]; \
const char *__p_prefix = _NMLOG_PREFIX_NAME; \
const void *const __self = (self); \
const NMPlatform *const __self = (self); \
\
if (__self && __self != nm_platform_try_get ()) { \
if (__self && NM_PLATFORM_GET_PRIVATE (__self)->log_with_ptr) { \
g_snprintf (__prefix, sizeof (__prefix), "%s[%p]", _NMLOG_PREFIX_NAME, __self); \
__p_prefix = __prefix; \
} \
@ -83,12 +83,12 @@ static guint signals[_NM_PLATFORM_SIGNAL_ID_LAST] = { 0 };
enum {
PROP_0,
PROP_NETNS_SUPPORT,
PROP_REGISTER_SINGLETON,
PROP_LOG_WITH_PTR,
LAST_PROP,
};
typedef struct _NMPlatformPrivate {
bool register_singleton:1;
bool log_with_ptr:1;
} NMPlatformPrivate;
G_DEFINE_TYPE (NMPlatform, nm_platform, G_TYPE_OBJECT)
@ -97,6 +97,14 @@ G_DEFINE_TYPE (NMPlatform, nm_platform, G_TYPE_OBJECT)
/*****************************************************************************/
gboolean
nm_platform_get_log_with_ptr (NMPlatform *self)
{
return NM_PLATFORM_GET_PRIVATE (self)->log_with_ptr;
}
/*****************************************************************************/
guint
_nm_platform_signal_id_get (NMPlatformSignalIdType signal_type)
{
@ -187,12 +195,6 @@ nm_platform_get ()
return singleton_instance;
}
NMPlatform *
nm_platform_try_get (void)
{
return singleton_instance;
}
/*****************************************************************************/
/**
@ -4596,9 +4598,9 @@ set_property (GObject *object, guint prop_id,
self->_netns = g_object_ref (netns);
}
break;
case PROP_REGISTER_SINGLETON:
case PROP_LOG_WITH_PTR:
/* construct-only */
priv->register_singleton = g_value_get_boolean (value);
priv->log_with_ptr = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -4606,18 +4608,6 @@ set_property (GObject *object, guint prop_id,
}
}
static void
constructed (GObject *object)
{
NMPlatform *self = NM_PLATFORM (object);
NMPlatformPrivate *priv = NM_PLATFORM_GET_PRIVATE (self);
G_OBJECT_CLASS (nm_platform_parent_class)->constructed (object);
if (priv->register_singleton)
nm_platform_setup (self);
}
static void
nm_platform_init (NMPlatform *self)
{
@ -4640,7 +4630,6 @@ nm_platform_class_init (NMPlatformClass *platform_class)
g_type_class_add_private (object_class, sizeof (NMPlatformPrivate));
object_class->set_property = set_property;
object_class->constructed = constructed;
object_class->finalize = finalize;
platform_class->wifi_set_powersave = wifi_set_powersave;
@ -4654,8 +4643,8 @@ nm_platform_class_init (NMPlatformClass *platform_class)
G_PARAM_STATIC_STRINGS));
g_object_class_install_property
(object_class, PROP_REGISTER_SINGLETON,
g_param_spec_boolean (NM_PLATFORM_REGISTER_SINGLETON, "", "",
(object_class, PROP_LOG_WITH_PTR,
g_param_spec_boolean (NM_PLATFORM_LOG_WITH_PTR, "", "",
FALSE,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY |

View file

@ -45,7 +45,7 @@
/*****************************************************************************/
#define NM_PLATFORM_NETNS_SUPPORT "netns-support"
#define NM_PLATFORM_REGISTER_SINGLETON "register-singleton"
#define NM_PLATFORM_LOG_WITH_PTR "log-with-ptr"
/*****************************************************************************/
@ -719,7 +719,6 @@ GType nm_platform_get_type (void);
void nm_platform_setup (NMPlatform *instance);
NMPlatform *nm_platform_get (void);
NMPlatform *nm_platform_try_get (void);
#define NM_PLATFORM_GET (nm_platform_get ())
@ -742,6 +741,8 @@ _nm_platform_uint8_inv (guint8 scope)
return (guint8) ~scope;
}
gboolean nm_platform_get_log_with_ptr (NMPlatform *self);
NMPNetns *nm_platform_netns_get (NMPlatform *self);
gboolean nm_platform_netns_push (NMPlatform *platform, NMPNetns **netns);

View file

@ -35,7 +35,7 @@ test_init_linux_platform (void)
{
gs_unref_object NMPlatform *platform = NULL;
platform = nm_linux_platform_new (NM_PLATFORM_NETNS_SUPPORT_DEFAULT);
platform = nm_linux_platform_new (TRUE, NM_PLATFORM_NETNS_SUPPORT_DEFAULT);
}
/*****************************************************************************/
@ -46,7 +46,7 @@ test_link_get_all (void)
gs_unref_object NMPlatform *platform = NULL;
gs_unref_array GArray *links = NULL;
platform = nm_linux_platform_new (NM_PLATFORM_NETNS_SUPPORT_DEFAULT);
platform = nm_linux_platform_new (TRUE, NM_PLATFORM_NETNS_SUPPORT_DEFAULT);
links = nm_platform_link_get_all (platform);
}

View file

@ -1900,7 +1900,7 @@ _test_netns_create_platform (void)
netns = nmp_netns_new ();
g_assert (NMP_IS_NETNS (netns));
platform = nm_linux_platform_new (TRUE);
platform = nm_linux_platform_new (TRUE, TRUE);
g_assert (NM_IS_LINUX_PLATFORM (platform));
nmp_netns_pop (netns);
@ -1961,7 +1961,7 @@ test_netns_general (gpointer fixture, gconstpointer test_data)
if (_test_netns_check_skip ())
return;
platform_1 = nm_linux_platform_new (TRUE);
platform_1 = nm_linux_platform_new (TRUE, TRUE);
platform_2 = _test_netns_create_platform ();
/* add some dummy devices. The "other-*" devices are there to bump the ifindex */
@ -2061,7 +2061,7 @@ test_netns_set_netns (gpointer fixture, gconstpointer test_data)
if (_test_netns_check_skip ())
return;
platforms[0] = platform_0 = nm_linux_platform_new (TRUE);
platforms[0] = platform_0 = nm_linux_platform_new (TRUE, TRUE);
platforms[1] = platform_1 = _test_netns_create_platform ();
platforms[2] = platform_2 = _test_netns_create_platform ();
@ -2156,7 +2156,7 @@ test_netns_push (gpointer fixture, gconstpointer test_data)
if (_test_netns_check_skip ())
return;
pl[0].platform = platform_0 = nm_linux_platform_new (TRUE);
pl[0].platform = platform_0 = nm_linux_platform_new (TRUE, TRUE);
pl[1].platform = platform_1 = _test_netns_create_platform ();
pl[2].platform = platform_2 = _test_netns_create_platform ();
@ -2288,7 +2288,7 @@ test_netns_bind_to_path (gpointer fixture, gconstpointer test_data)
if (_test_netns_check_skip ())
return;
platforms[0] = platform_0 = nm_linux_platform_new (TRUE);
platforms[0] = platform_0 = nm_linux_platform_new (TRUE, TRUE);
platforms[1] = platform_1 = _test_netns_create_platform ();
platforms[2] = platform_2 = _test_netns_create_platform ();
@ -2433,7 +2433,7 @@ test_sysctl_netns_switch (void)
if (_test_netns_check_skip ())
return;
platforms[0] = platform_0 = nm_linux_platform_new (TRUE);
platforms[0] = platform_0 = nm_linux_platform_new (TRUE, TRUE);
platforms[1] = platform_1 = _test_netns_create_platform ();
platforms[2] = platform_2 = _test_netns_create_platform ();
PL = platforms[nmtst_get_rand_int () % 3];