mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-11 06:00:35 +01:00
We need to react to platform changes. Also, we usually want to delay the reaction to an idle handler. Instead of subscribing each NML3Cfg instance itself to platform changes, let only NMNetns do that. The goal is of course that each platform event only needs to notify the NML3Cfg instance, which collects the events and schedules them on the idle handler.
144 lines
3.7 KiB
C
144 lines
3.7 KiB
C
// SPDX-License-Identifier: LGPL-2.1+
|
|
|
|
#include "nm-default.h"
|
|
|
|
#include "nm-l3cfg.h"
|
|
|
|
#include "platform/nm-platform.h"
|
|
#include "nm-netns.h"
|
|
|
|
/*****************************************************************************/
|
|
|
|
NM_GOBJECT_PROPERTIES_DEFINE (NML3Cfg,
|
|
PROP_NETNS,
|
|
PROP_IFINDEX,
|
|
);
|
|
|
|
struct _NML3CfgClass {
|
|
GObjectClass parent;
|
|
};
|
|
|
|
G_DEFINE_TYPE (NML3Cfg, nm_l3cfg, G_TYPE_OBJECT)
|
|
|
|
/*****************************************************************************/
|
|
|
|
#define _NMLOG_DOMAIN LOGD_CORE
|
|
#define _NMLOG_PREFIX_NAME "l3cfg"
|
|
#define _NMLOG(level, ...) \
|
|
G_STMT_START { \
|
|
nm_log ((level), (_NMLOG_DOMAIN), NULL, NULL, \
|
|
"l3cfg["NM_HASH_OBFUSCATE_PTR_FMT",ifindex=%d]: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
|
|
NM_HASH_OBFUSCATE_PTR (self), \
|
|
nm_l3cfg_get_ifindex (self) \
|
|
_NM_UTILS_MACRO_REST(__VA_ARGS__)); \
|
|
} G_STMT_END
|
|
|
|
/*****************************************************************************/
|
|
|
|
void
|
|
_nm_l3cfg_notify_platform_change_on_idle (NML3Cfg *self, guint32 obj_type_flags)
|
|
{
|
|
}
|
|
|
|
/*****************************************************************************/
|
|
|
|
static void
|
|
set_property (GObject *object,
|
|
guint prop_id,
|
|
const GValue *value,
|
|
GParamSpec *pspec)
|
|
{
|
|
NML3Cfg *self = NM_L3CFG (object);
|
|
|
|
switch (prop_id) {
|
|
case PROP_NETNS:
|
|
/* construct-only */
|
|
self->priv.netns = g_object_ref (g_value_get_pointer (value));
|
|
nm_assert (NM_IS_NETNS (self->priv.netns));
|
|
break;
|
|
case PROP_IFINDEX:
|
|
/* construct-only */
|
|
self->priv.ifindex = g_value_get_int (value);
|
|
nm_assert (self->priv.ifindex > 0);
|
|
break;
|
|
default:
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
break;
|
|
}
|
|
}
|
|
|
|
/*****************************************************************************/
|
|
|
|
static void
|
|
nm_l3cfg_init (NML3Cfg *self)
|
|
{
|
|
}
|
|
|
|
static void
|
|
constructed (GObject *object)
|
|
{
|
|
NML3Cfg *self = NM_L3CFG (object);
|
|
|
|
nm_assert (NM_IS_NETNS (self->priv.netns));
|
|
nm_assert (self->priv.ifindex > 0);
|
|
|
|
self->priv.platform = g_object_ref (nm_netns_get_platform (self->priv.netns));
|
|
nm_assert (NM_IS_PLATFORM (self->priv.platform));
|
|
|
|
_LOGT ("created (netns="NM_HASH_OBFUSCATE_PTR_FMT")",
|
|
NM_HASH_OBFUSCATE_PTR (self->priv.netns));
|
|
|
|
G_OBJECT_CLASS (nm_l3cfg_parent_class)->constructed (object);
|
|
}
|
|
|
|
NML3Cfg *
|
|
nm_l3cfg_new (NMNetns *netns, int ifindex)
|
|
{
|
|
nm_assert (NM_IS_NETNS (netns));
|
|
nm_assert (ifindex > 0);
|
|
|
|
return g_object_new (NM_TYPE_L3CFG,
|
|
NM_L3CFG_NETNS, netns,
|
|
NM_L3CFG_IFINDEX, ifindex,
|
|
NULL);
|
|
}
|
|
|
|
static void
|
|
finalize (GObject *object)
|
|
{
|
|
NML3Cfg *self = NM_L3CFG (object);
|
|
|
|
g_clear_object (&self->priv.netns);
|
|
g_clear_object (&self->priv.platform);
|
|
|
|
_LOGT ("finalized");
|
|
|
|
G_OBJECT_CLASS (nm_l3cfg_parent_class)->finalize (object);
|
|
}
|
|
|
|
static void
|
|
nm_l3cfg_class_init (NML3CfgClass *klass)
|
|
{
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
object_class->set_property = set_property;
|
|
object_class->constructed = constructed;
|
|
object_class->finalize = finalize;
|
|
|
|
obj_properties[PROP_NETNS] =
|
|
g_param_spec_pointer (NM_L3CFG_NETNS, "", "",
|
|
G_PARAM_WRITABLE |
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
G_PARAM_STATIC_STRINGS);
|
|
|
|
obj_properties[PROP_IFINDEX] =
|
|
g_param_spec_int (NM_L3CFG_IFINDEX, "", "",
|
|
0,
|
|
G_MAXINT,
|
|
0,
|
|
G_PARAM_WRITABLE |
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
G_PARAM_STATIC_STRINGS);
|
|
|
|
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
|
|
}
|