diff options
author | Thomas Haller <thaller@redhat.com> | 2020-07-29 19:30:22 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-08-05 12:47:55 +0200 |
commit | c9409f8692d21c2a926ffca0136a93d9dc6cc864 (patch) | |
tree | 10c391ec663c4f9f818a098141db72c03c79c443 /src | |
parent | adec7bd887102ade0556a33b094d3a31de1ea73f (diff) | |
download | NetworkManager-c9409f8692d21c2a926ffca0136a93d9dc6cc864.tar.gz |
core: add NMIPConfig as base class for NMIP[46]Config
NMIP[46]Config will become much simpler than it is today.
It's sole responsibility will be to expose current settings
on D-Bus, in it's function as a NMDBusObject subtype.
However, it still make sense to let them share a common base class.
Add it.
Diffstat (limited to 'src')
-rw-r--r-- | src/meson.build | 7 | ||||
-rw-r--r-- | src/nm-ip-config.c | 135 | ||||
-rw-r--r-- | src/nm-ip-config.h | 44 | ||||
-rw-r--r-- | src/nm-ip4-config.c | 16 | ||||
-rw-r--r-- | src/nm-ip4-config.h | 3 | ||||
-rw-r--r-- | src/nm-ip6-config.c | 16 | ||||
-rw-r--r-- | src/nm-ip6-config.h | 1 |
7 files changed, 205 insertions, 17 deletions
diff --git a/src/meson.build b/src/meson.build index 468f2159da..b2ea2ba0a1 100644 --- a/src/meson.build +++ b/src/meson.build @@ -43,6 +43,10 @@ sources = files( 'nm-core-utils.c', 'nm-dbus-object.c', 'nm-dbus-utils.c', + 'nm-netns.c', + 'nm-l3-config-data.c', + 'nm-l3cfg.c', + 'nm-ip-config.c', 'nm-ip4-config.c', 'nm-ip6-config.c', 'nm-logging.c', @@ -131,8 +135,6 @@ sources = files( 'nm-auth-manager.c', 'nm-auth-utils.c', 'nm-dbus-manager.c', - 'nm-l3-config-data.c', - 'nm-l3cfg.c', 'nm-checkpoint.c', 'nm-checkpoint-manager.c', 'nm-config.c', @@ -145,7 +147,6 @@ sources = files( 'nm-hostname-manager.c', 'nm-keep-alive.c', 'nm-manager.c', - 'nm-netns.c', 'nm-pacrunner-manager.c', 'nm-policy.c', 'nm-proxy-config.c', diff --git a/src/nm-ip-config.c b/src/nm-ip-config.c new file mode 100644 index 0000000000..a7207a5f57 --- /dev/null +++ b/src/nm-ip-config.c @@ -0,0 +1,135 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2005 - 2017 Red Hat, Inc. + * Copyright (C) 2006 - 2008 Novell, Inc. + */ + +#include "nm-default.h" + +#include "nm-ip-config.h" + +#include "nm-l3cfg.h" + +/*****************************************************************************/ + +NM_GOBJECT_PROPERTIES_DEFINE (NMIPConfig, + PROP_L3CFG, + PROP_IS_VPN, +); + +typedef struct _NMIPConfigPrivate { + NML3Cfg *l3cfg; + bool is_vpn:1; +} NMIPConfigPrivate; + +G_DEFINE_ABSTRACT_TYPE (NMIPConfig, nm_ip_config, NM_TYPE_DBUS_OBJECT) + +#define NM_IP_CONFIG_GET_PRIVATE(self) _NM_GET_PRIVATE_PTR(self, NMIPConfig, NM_IS_IP_CONFIG) + +/*****************************************************************************/ + +static void +get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + NMIPConfig *self = NM_IP_CONFIG (object); + NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (self); + + (void) priv; + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + NMIPConfig *self = NM_IP_CONFIG (object); + NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (self); + + switch (prop_id) { + case PROP_L3CFG: + /* construct-only */ + priv->l3cfg = nm_g_object_ref (g_value_get_pointer (value)); + nm_assert (!priv->l3cfg || NM_IS_L3CFG (priv->l3cfg)); + break; + case PROP_IS_VPN: + /* construct-only */ + priv->is_vpn = g_value_get_boolean (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +/*****************************************************************************/ + +static void +nm_ip_config_init (NMIPConfig *self) +{ + NMIPConfigPrivate *priv; + + priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NM_TYPE_IP_CONFIG, NMIPConfigPrivate); + + self->_priv = priv; +} + +NMIPConfig * +nm_ip_config_new (int addr_family, + NML3Cfg *l3cfg, + gboolean is_vpn) +{ + nm_assert_addr_family (addr_family); + nm_assert (NM_L3CFG (l3cfg)); + + return g_object_new ( NM_IS_IPv4 (addr_family) + ? nm_ip4_config_get_type () + : nm_ip6_config_get_type (), + NM_IP_CONFIG_L3CFG, l3cfg, + NM_IP_CONFIG_IS_VPN, is_vpn, + NULL); +} + +static void +finalize (GObject *object) +{ + NMIPConfig *self = NM_IP_CONFIG (object); + NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (self); + + nm_g_object_unref (priv->l3cfg); + + G_OBJECT_CLASS (nm_ip_config_parent_class)->finalize (object); +} + +static void +nm_ip_config_class_init (NMIPConfigClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (NMIPConfigPrivate)); + + object_class->get_property = get_property; + object_class->set_property = set_property; + object_class->finalize = finalize; + + obj_properties[PROP_L3CFG] = + g_param_spec_pointer (NM_IP_CONFIG_L3CFG, "", "", + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS); + + obj_properties[PROP_IS_VPN] = + g_param_spec_boolean (NM_IP_CONFIG_IS_VPN, "", "", + FALSE, + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); +} diff --git a/src/nm-ip-config.h b/src/nm-ip-config.h new file mode 100644 index 0000000000..2b6e88534d --- /dev/null +++ b/src/nm-ip-config.h @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2008 - 2013 Red Hat, Inc. + */ + +#ifndef __NM_IP_CONFIG_H__ +#define __NM_IP_CONFIG_H__ + +#include "nm-dbus-object.h" + +/*****************************************************************************/ + +#define NM_TYPE_IP_CONFIG (nm_ip_config_get_type ()) +#define NM_IP_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_IP_CONFIG, NMIPConfig)) +#define NM_IP_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_IP_CONFIG, NMIPConfigClass)) +#define NM_IS_IP_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_IP_CONFIG)) +#define NM_IS_IP_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_IP_CONFIG)) +#define NM_IP_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_IP_CONFIG, NMIPConfigClass)) + +#define NM_IP_CONFIG_L3CFG "l3cfg" +#define NM_IP_CONFIG_IS_VPN "is-vpn" + +struct _NMIPConfigPrivate; + +struct _NMIPConfig { + NMDBusObject parent; + struct _NMIPConfigPrivate *_priv; +}; + +typedef struct { + NMDBusObjectClass parent; + gboolean is_ipv4; + int addr_family; +} NMIPConfigClass; + +GType nm_ip_config_get_type (void); +GType nm_ip4_config_get_type (void); +GType nm_ip6_config_get_type (void); + +NMIPConfig *nm_ip_config_new (int addr_family, + NML3Cfg *l3cfg, + gboolean is_vpn); + +#endif /* __NM_IP_CONFIG_H__ */ diff --git a/src/nm-ip4-config.c b/src/nm-ip4-config.c index 9dc237e97f..e71432c51f 100644 --- a/src/nm-ip4-config.c +++ b/src/nm-ip4-config.c @@ -307,15 +307,15 @@ typedef struct { } NMIP4ConfigPrivate; struct _NMIP4Config { - NMDBusObject parent; + NMIPConfig parent; NMIP4ConfigPrivate _priv; }; struct _NMIP4ConfigClass { - NMDBusObjectClass parent; + NMIPConfigClass parent; }; -G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, NM_TYPE_DBUS_OBJECT) +G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, NM_TYPE_IP_CONFIG) #define NM_IP4_CONFIG_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMIP4Config, NM_IS_IP4_CONFIG) @@ -3172,10 +3172,14 @@ static const NMDBusInterfaceInfoExtended interface_info_ip4_config = { }; static void -nm_ip4_config_class_init (NMIP4ConfigClass *config_class) +nm_ip4_config_class_init (NMIP4ConfigClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (config_class); - NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (config_class); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (klass); + NMIPConfigClass *ip_config_class = NM_IP_CONFIG_CLASS (klass); + + ip_config_class->is_ipv4 = TRUE; + ip_config_class->addr_family = AF_INET; dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/IP4Config"); dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_ip4_config); diff --git a/src/nm-ip4-config.h b/src/nm-ip4-config.h index 65b3d0eb30..d876f69ce0 100644 --- a/src/nm-ip4-config.h +++ b/src/nm-ip4-config.h @@ -12,6 +12,7 @@ #include "nm-glib-aux/nm-dedup-multi.h" #include "platform/nmp-object.h" +#include "nm-ip-config.h" /*****************************************************************************/ @@ -273,8 +274,6 @@ NM_IS_IP_CONFIG_ADDR_FAMILY (gconstpointer config, int addr_family) g_return_val_if_reached (FALSE); } -#define NM_IS_IP_CONFIG(config) NM_IS_IP_CONFIG_ADDR_FAMILY ((config), AF_UNSPEC) - #if _NM_CC_SUPPORT_GENERIC /* _NM_IS_IP_CONFIG() is a bit unusual. If _Generic() is supported, * it checks whether @config is either NM_IS_IP4_CONFIG() or NM_IS_IP6_CONFIG(), diff --git a/src/nm-ip6-config.c b/src/nm-ip6-config.c index 446e6f9ed3..69b74c7298 100644 --- a/src/nm-ip6-config.c +++ b/src/nm-ip6-config.c @@ -67,15 +67,15 @@ typedef struct { } NMIP6ConfigPrivate; struct _NMIP6Config { - NMDBusObject parent; + NMIPConfig parent; NMIP6ConfigPrivate _priv; }; struct _NMIP6ConfigClass { - NMDBusObjectClass parent; + NMIPConfigClass parent; }; -G_DEFINE_TYPE (NMIP6Config, nm_ip6_config, NM_TYPE_DBUS_OBJECT) +G_DEFINE_TYPE (NMIP6Config, nm_ip6_config, NM_TYPE_IP_CONFIG) #define NM_IP6_CONFIG_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMIP6Config, NM_IS_IP6_CONFIG) @@ -2655,10 +2655,14 @@ static const NMDBusInterfaceInfoExtended interface_info_ip6_config = { }; static void -nm_ip6_config_class_init (NMIP6ConfigClass *config_class) +nm_ip6_config_class_init (NMIP6ConfigClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (config_class); - NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (config_class); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (klass); + NMIPConfigClass *ip_config_class = NM_IP_CONFIG_CLASS (klass); + + ip_config_class->is_ipv4 = FALSE; + ip_config_class->addr_family = AF_INET6; dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/IP6Config"); dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_ip6_config); diff --git a/src/nm-ip6-config.h b/src/nm-ip6-config.h index 079005e477..187da967a9 100644 --- a/src/nm-ip6-config.h +++ b/src/nm-ip6-config.h @@ -12,6 +12,7 @@ #include "nm-glib-aux/nm-dedup-multi.h" #include "platform/nmp-object.h" +#include "nm-ip-config.h" /*****************************************************************************/ |