core: add common base class NMDhcpConfig for NMDhcp[46]Config and merge them

The advantage is that the API is now the same for IPv4 and IPv6: it's
all nm_dhcp_config_*() and we can (easier) treat the address family
generically.

We still need two distinct GObject types, mainly because of the
glue code for exposing the object on D-Bus as NMDBusObject. Of course,
that could be solved differently, but as it is, it's quite nice.
This commit is contained in:
Thomas Haller 2020-02-20 14:12:31 +01:00
parent cd03d39a6d
commit 26f208aec3
12 changed files with 211 additions and 316 deletions

View file

@ -2279,8 +2279,6 @@ src_libNetworkManager_la_SOURCES = \
src/nm-netns.h \
src/nm-dhcp-config.c \
src/nm-dhcp-config.h \
src/nm-dhcp6-config.c \
src/nm-dhcp6-config.h \
src/nm-dispatcher.c \
src/nm-dispatcher.h \
src/nm-firewall-manager.c \

View file

@ -44,7 +44,6 @@
#include "nm-pacrunner-manager.h"
#include "dnsmasq/nm-dnsmasq-manager.h"
#include "nm-dhcp-config.h"
#include "nm-dhcp6-config.h"
#include "nm-rfkill-manager.h"
#include "nm-firewall-manager.h"
#include "settings/nm-settings-connection.h"
@ -161,11 +160,7 @@ typedef struct {
typedef struct {
NMDhcpClient *client;
union {
NMDhcp4Config *config_4;
NMDhcp6Config *config_6;
gpointer config;
};
NMDhcpConfig *config;
gulong state_sigid;
guint grace_id;
bool grace_pending:1;
@ -7628,8 +7623,8 @@ dhcp4_cleanup (NMDevice *self, CleanupType cleanup_type, gboolean release)
g_clear_object (&priv->dhcp_data_4.client);
}
if (priv->dhcp_data_4.config_4) {
nm_dbus_object_clear_and_unexport (&priv->dhcp_data_4.config_4);
if (priv->dhcp_data_4.config) {
nm_dbus_object_clear_and_unexport (&priv->dhcp_data_4.config);
_notify (self, PROP_DHCP4_CONFIG);
}
}
@ -8002,9 +7997,9 @@ dhcp4_fail (NMDevice *self, NMDhcpState dhcp_state)
clear_config:
/* The previous configuration is no longer valid */
if (priv->dhcp_data_4.config_4) {
nm_dbus_object_clear_and_unexport (&priv->dhcp_data_4.config_4);
priv->dhcp_data_4.config_4 = nm_dhcp4_config_new ();
if (priv->dhcp_data_4.config) {
nm_dbus_object_clear_and_unexport (&priv->dhcp_data_4.config);
priv->dhcp_data_4.config = nm_dhcp_config_new (AF_INET);
_notify (self, PROP_DHCP4_CONFIG);
}
}
@ -8067,7 +8062,7 @@ dhcp4_state_changed (NMDhcpClient *client,
g_free (priv->dhcp4.root_path);
priv->dhcp4.root_path = g_strdup (g_hash_table_lookup (options, "root_path"));
nm_dhcp4_config_set_options (priv->dhcp_data_4.config_4, options);
nm_dhcp_config_set_options (priv->dhcp_data_4.config, options);
_notify (self, PROP_DHCP4_CONFIG);
if (priv->ip_state_4 == NM_DEVICE_IP_STATE_CONF) {
@ -8446,8 +8441,8 @@ dhcp4_start (NMDevice *self)
s_ip4 = nm_connection_get_setting_ip4_config (connection);
/* Clear old exported DHCP options */
nm_dbus_object_clear_and_unexport (&priv->dhcp_data_4.config_4);
priv->dhcp_data_4.config_4 = nm_dhcp4_config_new ();
nm_dbus_object_clear_and_unexport (&priv->dhcp_data_4.config);
priv->dhcp_data_4.config = nm_dhcp_config_new (AF_INET);
pllink = nm_platform_link_get (nm_device_get_platform (self), nm_device_get_ip_ifindex (self));
if (pllink) {
@ -8692,8 +8687,8 @@ dhcp6_cleanup (NMDevice *self, CleanupType cleanup_type, gboolean release)
g_clear_object (&priv->dhcp_data_6.client);
}
if (priv->dhcp_data_6.config_6) {
nm_dbus_object_clear_and_unexport (&priv->dhcp_data_6.config_6);
if (priv->dhcp_data_6.config) {
nm_dbus_object_clear_and_unexport (&priv->dhcp_data_6.config);
_notify (self, PROP_DHCP6_CONFIG);
}
}
@ -8779,9 +8774,9 @@ dhcp6_fail (NMDevice *self, NMDhcpState dhcp_state)
clear_config:
/* The previous configuration is no longer valid */
if (priv->dhcp_data_6.config_6) {
nm_dbus_object_clear_and_unexport (&priv->dhcp_data_6.config_6);
priv->dhcp_data_6.config_6 = nm_dhcp6_config_new ();
if (priv->dhcp_data_6.config) {
nm_dbus_object_clear_and_unexport (&priv->dhcp_data_6.config);
priv->dhcp_data_6.config = nm_dhcp_config_new (AF_INET6);
_notify (self, PROP_DHCP6_CONFIG);
}
}
@ -8825,7 +8820,7 @@ dhcp6_state_changed (NMDhcpClient *client,
if (ip6_config) {
applied_config_init (&priv->dhcp6.ip6_config, ip6_config);
priv->dhcp6.event_id = g_strdup (event_id);
nm_dhcp6_config_set_options (priv->dhcp_data_6.config_6, options);
nm_dhcp_config_set_options (priv->dhcp_data_6.config, options);
_notify (self, PROP_DHCP6_CONFIG);
} else
applied_config_clear (&priv->dhcp6.ip6_config);
@ -9300,8 +9295,8 @@ dhcp6_start (NMDevice *self, gboolean wait_for_ll)
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
NMConnection *connection;
nm_dbus_object_clear_and_unexport (&priv->dhcp_data_6.config_6);
priv->dhcp_data_6.config_6 = nm_dhcp6_config_new ();
nm_dbus_object_clear_and_unexport (&priv->dhcp_data_6.config);
priv->dhcp_data_6.config = nm_dhcp_config_new (AF_INET6);
nm_assert (!applied_config_get_current (&priv->dhcp6.ip6_config));
applied_config_clear (&priv->dhcp6.ip6_config);
@ -12828,12 +12823,12 @@ nm_device_set_proxy_config (NMDevice *self, const char *pac_url)
}
/* IP Configuration stuff */
NMDhcp4Config *
NMDhcpConfig *
nm_device_get_dhcp4_config (NMDevice *self)
{
g_return_val_if_fail (NM_IS_DEVICE (self), NULL);
return NM_DEVICE_GET_PRIVATE (self)->dhcp_data_4.config_4;
return NM_DEVICE_GET_PRIVATE (self)->dhcp_data_4.config;
}
NMIP4Config *
@ -13087,12 +13082,12 @@ nm_device_replace_vpn6_config (NMDevice *self, NMIP6Config *old, NMIP6Config *co
_LOGW (LOGD_IP6, "failed to set VPN routes for device");
}
NMDhcp6Config *
NMDhcpConfig *
nm_device_get_dhcp6_config (NMDevice *self)
{
g_return_val_if_fail (NM_IS_DEVICE (self), NULL);
return NM_DEVICE_GET_PRIVATE (self)->dhcp_data_6.config_6;
return NM_DEVICE_GET_PRIVATE (self)->dhcp_data_6.config;
}
NMIP6Config *
@ -17434,13 +17429,13 @@ get_property (GObject *object, guint prop_id,
nm_dbus_utils_g_value_set_object_path (value, ip_config_valid (priv->state) ? priv->ip_config_4 : NULL);
break;
case PROP_DHCP4_CONFIG:
nm_dbus_utils_g_value_set_object_path (value, ip_config_valid (priv->state) ? priv->dhcp_data_4.config_4 : NULL);
nm_dbus_utils_g_value_set_object_path (value, ip_config_valid (priv->state) ? priv->dhcp_data_4.config : NULL);
break;
case PROP_IP6_CONFIG:
nm_dbus_utils_g_value_set_object_path (value, ip_config_valid (priv->state) ? priv->ip_config_6 : NULL);
break;
case PROP_DHCP6_CONFIG:
nm_dbus_utils_g_value_set_object_path (value, ip_config_valid (priv->state) ? priv->dhcp_data_6.config_6 : NULL);
nm_dbus_utils_g_value_set_object_path (value, ip_config_valid (priv->state) ? priv->dhcp_data_6.config : NULL);
break;
case PROP_STATE:
g_value_set_uint (value, priv->state);

View file

@ -504,8 +504,8 @@ const char * nm_device_get_initial_hw_address (NMDevice *dev);
NMProxyConfig * nm_device_get_proxy_config (NMDevice *dev);
NMDhcp4Config * nm_device_get_dhcp4_config (NMDevice *dev);
NMDhcp6Config * nm_device_get_dhcp6_config (NMDevice *dev);
NMDhcpConfig * nm_device_get_dhcp4_config (NMDevice *dev);
NMDhcpConfig * nm_device_get_dhcp6_config (NMDevice *dev);
NMIP4Config * nm_device_get_ip4_config (NMDevice *dev);
void nm_device_replace_vpn4_config (NMDevice *dev,
NMIP4Config *old,

View file

@ -136,7 +136,6 @@ sources = files(
'nm-connectivity.c',
'nm-dcb.c',
'nm-dhcp-config.c',
'nm-dhcp6-config.c',
'nm-dispatcher.c',
'nm-firewall-manager.c',
'nm-hostname-manager.c',

View file

@ -14,66 +14,95 @@
/*****************************************************************************/
NM_GOBJECT_PROPERTIES_DEFINE (NMDhcp4Config,
#define NM_TYPE_DHCP4_CONFIG (nm_dhcp4_config_get_type ())
#define NM_DHCP4_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DHCP4_CONFIG, NMDhcp4Config))
#define NM_DHCP4_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DHCP4_CONFIG, NMDhcp4ConfigClass))
#define NM_IS_DHCP4_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DHCP4_CONFIG))
#define NM_IS_DHCP4_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DHCP4_CONFIG))
#define NM_DHCP4_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DHCP4_CONFIG, NMDhcp4ConfigClass))
typedef struct _NMDhcp4Config NMDhcp4Config;
typedef struct _NMDhcp4ConfigClass NMDhcp4ConfigClass;
static GType nm_dhcp4_config_get_type (void);
#define NM_TYPE_DHCP6_CONFIG (nm_dhcp6_config_get_type ())
#define NM_DHCP6_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DHCP6_CONFIG, NMDhcp6Config))
#define NM_DHCP6_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DHCP6_CONFIG, NMDhcp6ConfigClass))
#define NM_IS_DHCP6_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DHCP6_CONFIG))
#define NM_IS_DHCP6_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DHCP6_CONFIG))
#define NM_DHCP6_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DHCP6_CONFIG, NMDhcp6ConfigClass))
typedef struct _NMDhcp6Config NMDhcp6Config;
typedef struct _NMDhcp6ConfigClass NMDhcp6ConfigClass;
static GType nm_dhcp6_config_get_type (void);
/*****************************************************************************/
NM_GOBJECT_PROPERTIES_DEFINE (NMDhcpConfig,
PROP_OPTIONS,
);
typedef struct {
GVariant *options;
} NMDhcp4ConfigPrivate;
} NMDhcpConfigPrivate;
struct _NMDhcp4Config {
struct _NMDhcpConfig {
NMDBusObject parent;
NMDhcp4ConfigPrivate _priv;
NMDhcpConfigPrivate _priv;
};
struct _NMDhcp4ConfigClass {
struct _NMDhcpConfigClass {
NMDBusObjectClass parent;
};
G_DEFINE_TYPE (NMDhcp4Config, nm_dhcp4_config, NM_TYPE_DBUS_OBJECT)
G_DEFINE_ABSTRACT_TYPE (NMDhcpConfig, nm_dhcp_config, NM_TYPE_DBUS_OBJECT)
#define NM_DHCP4_CONFIG_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMDhcp4Config, NM_IS_DHCP4_CONFIG)
#define NM_DHCP_CONFIG_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMDhcpConfig, NM_IS_DHCP_CONFIG)
/*****************************************************************************/
void
nm_dhcp4_config_set_options (NMDhcp4Config *self,
GHashTable *options)
nm_dhcp_config_set_options (NMDhcpConfig *self,
GHashTable *options)
{
NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (self);
GVariant *val;
NMDhcpConfigPrivate *priv;
g_return_if_fail (NM_IS_DHCP4_CONFIG (self));
g_return_if_fail (NM_IS_DHCP_CONFIG (self));
g_return_if_fail (options);
val = nm_utils_strdict_to_variant (options);
g_variant_unref (priv->options);
priv->options = g_variant_ref_sink (val);
priv = NM_DHCP_CONFIG_GET_PRIVATE (self);
nm_g_variant_unref (priv->options);
priv->options = g_variant_ref_sink (nm_utils_strdict_to_variant (options));
_notify (self, PROP_OPTIONS);
}
const char *
nm_dhcp4_config_get_option (NMDhcp4Config *self, const char *key)
nm_dhcp_config_get_option (NMDhcpConfig *self, const char *key)
{
NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (self);
NMDhcpConfigPrivate *priv;
const char *value;
g_return_val_if_fail (NM_IS_DHCP4_CONFIG (self), NULL);
g_return_val_if_fail (key != NULL, NULL);
g_return_val_if_fail (NM_IS_DHCP_CONFIG (self), NULL);
g_return_val_if_fail (key, NULL);
if (g_variant_lookup (priv->options, key, "&s", &value))
priv = NM_DHCP_CONFIG_GET_PRIVATE (self);
if ( priv->options
&& g_variant_lookup (priv->options, key, "&s", &value))
return value;
else
return NULL;
}
GVariant *
nm_dhcp4_config_get_options (NMDhcp4Config *self)
nm_dhcp_config_get_options (NMDhcpConfig *self)
{
g_return_val_if_fail (NM_IS_DHCP4_CONFIG (self), NULL);
g_return_val_if_fail (NM_IS_DHCP_CONFIG (self), NULL);
return g_variant_ref (NM_DHCP4_CONFIG_GET_PRIVATE (self)->options);
return NM_DHCP_CONFIG_GET_PRIVATE (self)->options;
}
/*****************************************************************************/
@ -82,11 +111,12 @@ static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object);
NMDhcpConfigPrivate *priv = NM_DHCP_CONFIG_GET_PRIVATE (object);
switch (prop_id) {
case PROP_OPTIONS:
g_value_set_variant (value, priv->options);
g_value_set_variant (value, priv->options
?: g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -97,28 +127,64 @@ get_property (GObject *object, guint prop_id,
/*****************************************************************************/
static void
nm_dhcp4_config_init (NMDhcp4Config *self)
nm_dhcp_config_init (NMDhcpConfig *self)
{
NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (self);
priv->options = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
g_variant_ref_sink (priv->options);
}
NMDhcp4Config *
nm_dhcp4_config_new (void)
NMDhcpConfig *
nm_dhcp_config_new (int addr_family)
{
return NM_DHCP4_CONFIG (g_object_new (NM_TYPE_DHCP4_CONFIG, NULL));
nm_assert_addr_family (addr_family);
return g_object_new ( addr_family != AF_INET
? NM_TYPE_DHCP6_CONFIG
: NM_TYPE_DHCP4_CONFIG,
NULL);
}
static void
finalize (GObject *object)
{
NMDhcp4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (object);
NMDhcpConfigPrivate *priv = NM_DHCP_CONFIG_GET_PRIVATE (object);
g_variant_unref (priv->options);
nm_g_variant_unref (priv->options);
G_OBJECT_CLASS (nm_dhcp4_config_parent_class)->finalize (object);
G_OBJECT_CLASS (nm_dhcp_config_parent_class)->finalize (object);
}
static void
nm_dhcp_config_class_init (NMDhcpConfigClass *config_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (config_class);
object_class->get_property = get_property;
object_class->finalize = finalize;
obj_properties[PROP_OPTIONS] =
g_param_spec_variant (NM_DHCP_CONFIG_OPTIONS, "", "",
G_VARIANT_TYPE ("a{sv}"),
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
}
/*****************************************************************************/
struct _NMDhcp4Config {
NMDhcpConfig parent;
};
struct _NMDhcp4ConfigClass {
NMDhcpConfigClass parent;
};
G_DEFINE_TYPE (NMDhcp4Config, nm_dhcp4_config, NM_TYPE_DHCP_CONFIG)
static void
nm_dhcp4_config_init (NMDhcp4Config *self)
{
}
static const NMDBusInterfaceInfoExtended interface_info_dhcp4_config = {
@ -128,31 +194,58 @@ static const NMDBusInterfaceInfoExtended interface_info_dhcp4_config = {
&nm_signal_info_property_changed_legacy,
),
.properties = NM_DEFINE_GDBUS_PROPERTY_INFOS (
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("Options", "a{sv}", NM_DHCP4_CONFIG_OPTIONS),
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("Options", "a{sv}", NM_DHCP_CONFIG_OPTIONS),
),
),
.legacy_property_changed = TRUE,
};
static void
nm_dhcp4_config_class_init (NMDhcp4ConfigClass *config_class)
nm_dhcp4_config_class_init (NMDhcp4ConfigClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (config_class);
NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (config_class);
object_class->get_property = get_property;
object_class->finalize = finalize;
NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (klass);
dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/DHCP4Config");
dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_dhcp4_config);
dbus_object_class->export_on_construction = TRUE;
obj_properties[PROP_OPTIONS] =
g_param_spec_variant (NM_DHCP4_CONFIG_OPTIONS, "", "",
G_VARIANT_TYPE ("a{sv}"),
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
}
/*****************************************************************************/
struct _NMDhcp6Config {
NMDhcpConfig parent;
};
struct _NMDhcp6ConfigClass {
NMDhcpConfigClass parent;
};
G_DEFINE_TYPE (NMDhcp6Config, nm_dhcp6_config, NM_TYPE_DHCP_CONFIG)
static void
nm_dhcp6_config_init (NMDhcp6Config *self)
{
}
static const NMDBusInterfaceInfoExtended interface_info_dhcp6_config = {
.parent = NM_DEFINE_GDBUS_INTERFACE_INFO_INIT (
NM_DBUS_INTERFACE_DHCP6_CONFIG,
.signals = NM_DEFINE_GDBUS_SIGNAL_INFOS (
&nm_signal_info_property_changed_legacy,
),
.properties = NM_DEFINE_GDBUS_PROPERTY_INFOS (
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("Options", "a{sv}", NM_DHCP_CONFIG_OPTIONS),
),
),
.legacy_property_changed = TRUE,
};
static void
nm_dhcp6_config_class_init (NMDhcp6ConfigClass *klass)
{
NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (klass);
dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/DHCP6Config");
dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_dhcp6_config);
dbus_object_class->export_on_construction = TRUE;
}

View file

@ -3,29 +3,33 @@
* Copyright (C) 2008 Red Hat, Inc.
*/
#ifndef __NETWORKMANAGER_DHCP4_CONFIG_H__
#define __NETWORKMANAGER_DHCP4_CONFIG_H__
#ifndef __NM_DHCP_CONFIG_H__
#define __NM_DHCP_CONFIG_H__
#define NM_TYPE_DHCP4_CONFIG (nm_dhcp4_config_get_type ())
#define NM_DHCP4_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DHCP4_CONFIG, NMDhcp4Config))
#define NM_DHCP4_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DHCP4_CONFIG, NMDhcp4ConfigClass))
#define NM_IS_DHCP4_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DHCP4_CONFIG))
#define NM_IS_DHCP4_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DHCP4_CONFIG))
#define NM_DHCP4_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DHCP4_CONFIG, NMDhcp4ConfigClass))
/*****************************************************************************/
#define NM_DHCP4_CONFIG_OPTIONS "options"
#define NM_TYPE_DHCP_CONFIG (nm_dhcp_config_get_type ())
#define NM_DHCP_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DHCP_CONFIG, NMDhcpConfig))
#define NM_DHCP_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DHCP_CONFIG, NMDhcpConfigClass))
#define NM_IS_DHCP_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DHCP_CONFIG))
#define NM_IS_DHCP_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DHCP_CONFIG))
#define NM_DHCP_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DHCP_CONFIG, NMDhcpConfigClass))
typedef struct _NMDhcp4ConfigClass NMDhcp4ConfigClass;
#define NM_DHCP_CONFIG_OPTIONS "options"
GType nm_dhcp4_config_get_type (void);
typedef struct _NMDhcpConfigClass NMDhcpConfigClass;
NMDhcp4Config *nm_dhcp4_config_new (void);
GType nm_dhcp_config_get_type (void);
void nm_dhcp4_config_set_options (NMDhcp4Config *config,
GHashTable *options);
NMDhcpConfig *nm_dhcp_config_new (int addr_family);
const char *nm_dhcp4_config_get_option (NMDhcp4Config *config, const char *option);
int nm_dhcp_config_get_addr_family (NMDhcpConfig *self);
GVariant *nm_dhcp4_config_get_options (NMDhcp4Config *config);
void nm_dhcp_config_set_options (NMDhcpConfig *self,
GHashTable *options);
#endif /* __NETWORKMANAGER_DHCP4_CONFIG_H__ */
const char *nm_dhcp_config_get_option (NMDhcpConfig *self, const char *option);
GVariant *nm_dhcp_config_get_options (NMDhcpConfig *self);
#endif /* __NM_DHCP_CONFIG_H__ */

View file

@ -1,156 +0,0 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (C) 2008 Red Hat, Inc.
*/
#include "nm-default.h"
#include "nm-dhcp6-config.h"
#include "nm-dbus-interface.h"
#include "nm-utils.h"
#include "nm-dbus-object.h"
#include "nm-core-utils.h"
/*****************************************************************************/
NM_GOBJECT_PROPERTIES_DEFINE (NMDhcp6Config,
PROP_OPTIONS,
);
typedef struct {
GVariant *options;
} NMDhcp6ConfigPrivate;
struct _NMDhcp6Config {
NMDBusObject parent;
NMDhcp6ConfigPrivate _priv;
};
struct _NMDhcp6ConfigClass {
NMDBusObjectClass parent;
};
G_DEFINE_TYPE (NMDhcp6Config, nm_dhcp6_config, NM_TYPE_DBUS_OBJECT)
#define NM_DHCP6_CONFIG_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMDhcp6Config, NM_IS_DHCP6_CONFIG)
/*****************************************************************************/
void
nm_dhcp6_config_set_options (NMDhcp6Config *self,
GHashTable *options)
{
NMDhcp6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (self);
GVariant *val;
g_return_if_fail (NM_IS_DHCP6_CONFIG (self));
g_return_if_fail (options);
val = nm_utils_strdict_to_variant (options);
g_variant_unref (priv->options);
priv->options = g_variant_ref_sink (val);
_notify (self, PROP_OPTIONS);
}
const char *
nm_dhcp6_config_get_option (NMDhcp6Config *self, const char *key)
{
NMDhcp6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (self);
const char *value;
g_return_val_if_fail (NM_IS_DHCP6_CONFIG (self), NULL);
g_return_val_if_fail (key != NULL, NULL);
if (g_variant_lookup (priv->options, key, "&s", &value))
return value;
else
return NULL;
}
GVariant *
nm_dhcp6_config_get_options (NMDhcp6Config *self)
{
g_return_val_if_fail (NM_IS_DHCP6_CONFIG (self), NULL);
return g_variant_ref (NM_DHCP6_CONFIG_GET_PRIVATE (self)->options);
}
/*****************************************************************************/
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMDhcp6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (object);
switch (prop_id) {
case PROP_OPTIONS:
g_value_set_variant (value, priv->options);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_dhcp6_config_init (NMDhcp6Config *self)
{
NMDhcp6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (self);
priv->options = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
g_variant_ref_sink (priv->options);
}
NMDhcp6Config *
nm_dhcp6_config_new (void)
{
return NM_DHCP6_CONFIG (g_object_new (NM_TYPE_DHCP6_CONFIG, NULL));
}
static void
finalize (GObject *object)
{
NMDhcp6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (object);
g_variant_unref (priv->options);
G_OBJECT_CLASS (nm_dhcp6_config_parent_class)->finalize (object);
}
static const NMDBusInterfaceInfoExtended interface_info_dhcp6_config = {
.parent = NM_DEFINE_GDBUS_INTERFACE_INFO_INIT (
NM_DBUS_INTERFACE_DHCP6_CONFIG,
.signals = NM_DEFINE_GDBUS_SIGNAL_INFOS (
&nm_signal_info_property_changed_legacy,
),
.properties = NM_DEFINE_GDBUS_PROPERTY_INFOS (
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("Options", "a{sv}", NM_DHCP6_CONFIG_OPTIONS),
),
),
.legacy_property_changed = TRUE,
};
static void
nm_dhcp6_config_class_init (NMDhcp6ConfigClass *config_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (config_class);
NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (config_class);
object_class->get_property = get_property;
object_class->finalize = finalize;
dbus_object_class->export_path = NM_DBUS_EXPORT_PATH_NUMBERED (NM_DBUS_PATH"/DHCP6Config");
dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_dhcp6_config);
dbus_object_class->export_on_construction = TRUE;
obj_properties[PROP_OPTIONS] =
g_param_spec_variant (NM_DHCP6_CONFIG_OPTIONS, "", "",
G_VARIANT_TYPE ("a{sv}"),
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
}

View file

@ -1,31 +0,0 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (C) 2008 Red Hat, Inc.
*/
#ifndef __NETWORKMANAGER_DHCP6_CONFIG_H__
#define __NETWORKMANAGER_DHCP6_CONFIG_H__
#define NM_TYPE_DHCP6_CONFIG (nm_dhcp6_config_get_type ())
#define NM_DHCP6_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DHCP6_CONFIG, NMDhcp6Config))
#define NM_DHCP6_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DHCP6_CONFIG, NMDhcp6ConfigClass))
#define NM_IS_DHCP6_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DHCP6_CONFIG))
#define NM_IS_DHCP6_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DHCP6_CONFIG))
#define NM_DHCP6_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DHCP6_CONFIG, NMDhcp6ConfigClass))
#define NM_DHCP6_CONFIG_OPTIONS "options"
typedef struct _NMDhcp6ConfigClass NMDhcp6ConfigClass;
GType nm_dhcp6_config_get_type (void);
NMDhcp6Config *nm_dhcp6_config_new (void);
void nm_dhcp6_config_set_options (NMDhcp6Config *config,
GHashTable *options);
const char *nm_dhcp6_config_get_option (NMDhcp6Config *config, const char *option);
GVariant *nm_dhcp6_config_get_options (NMDhcp6Config *self);
#endif /* __NETWORKMANAGER_DHCP6_CONFIG_H__ */

View file

@ -15,7 +15,6 @@
#include "nm-act-request.h"
#include "devices/nm-device.h"
#include "nm-dhcp-config.h"
#include "nm-dhcp6-config.h"
#include "nm-proxy-config.h"
#include "nm-ip4-config.h"
#include "nm-ip6-config.h"
@ -331,8 +330,7 @@ fill_device_props (NMDevice *device,
NMProxyConfig *proxy_config;
NMIP4Config *ip4_config;
NMIP6Config *ip6_config;
NMDhcp4Config *dhcp4_config;
NMDhcp6Config *dhcp6_config;
NMDhcpConfig *dhcp_config;
/* If the action is for a VPN, send the VPN's IP interface instead of the device's */
g_variant_builder_add (dev_builder, "{sv}", NMD_DEVICE_PROPS_IP_INTERFACE,
@ -360,13 +358,13 @@ fill_device_props (NMDevice *device,
if (ip6_config)
dump_ip6_to_props (ip6_config, ip6_builder);
dhcp4_config = nm_device_get_dhcp4_config (device);
if (dhcp4_config)
*dhcp4_props = nm_dhcp4_config_get_options (dhcp4_config);
dhcp_config = nm_device_get_dhcp4_config (device);
if (dhcp_config)
*dhcp4_props = nm_g_variant_ref (nm_dhcp_config_get_options (dhcp_config));
dhcp6_config = nm_device_get_dhcp6_config (device);
if (dhcp6_config)
*dhcp6_props = nm_dhcp6_config_get_options (dhcp6_config);
dhcp_config = nm_device_get_dhcp6_config (device);
if (dhcp_config)
*dhcp6_props = nm_g_variant_ref (nm_dhcp_config_get_options (dhcp_config));
}
static void

View file

@ -6496,7 +6496,7 @@ nm_manager_write_device_state (NMManager *self, NMDevice *device)
guint32 route_metric_default_aspired;
guint32 route_metric_default_effective;
int nm_owned;
NMDhcp4Config *dhcp4_config;
NMDhcpConfig *dhcp_config;
const char *next_server = NULL;
const char *root_path = NULL;
@ -6534,10 +6534,10 @@ nm_manager_write_device_state (NMManager *self, NMDevice *device)
route_metric_default_effective = _device_route_metric_get (self, ifindex, NM_DEVICE_TYPE_UNKNOWN,
TRUE, &route_metric_default_aspired);
dhcp4_config = nm_device_get_dhcp4_config (device);
if (dhcp4_config) {
root_path = nm_dhcp4_config_get_option (dhcp4_config, "root_path");
next_server = nm_dhcp4_config_get_option (dhcp4_config, "next_server");
dhcp_config = nm_device_get_dhcp4_config (device);
if (dhcp_config) {
root_path = nm_dhcp_config_get_option (dhcp_config, "root_path");
next_server = nm_dhcp_config_get_option (dhcp_config, "next_server");
}
return nm_config_device_state_write (ifindex,

View file

@ -30,7 +30,6 @@
#include "settings/nm-settings-connection.h"
#include "settings/nm-agent-manager.h"
#include "nm-dhcp-config.h"
#include "nm-dhcp6-config.h"
#include "nm-config.h"
#include "nm-netns.h"
#include "nm-hostname-manager.h"
@ -692,6 +691,7 @@ update_system_hostname (NMPolicy *self, const char *msg)
const NMPlatformIP4Address *addr4;
const NMPlatformIP6Address *addr6;
NMDevice *device;
NMDhcpConfig *dhcp_config;
g_return_if_fail (self != NULL);
@ -745,12 +745,10 @@ update_system_hostname (NMPolicy *self, const char *msg)
}
if (priv->default_ac4) {
NMDhcp4Config *dhcp4_config;
/* Grab a hostname out of the device's DHCP4 config */
dhcp4_config = nm_device_get_dhcp4_config (get_default_device (self, AF_INET));
if (dhcp4_config) {
dhcp_hostname = nm_dhcp4_config_get_option (dhcp4_config, "host_name");
dhcp_config = nm_device_get_dhcp4_config (get_default_device (self, AF_INET));
if (dhcp_config) {
dhcp_hostname = nm_dhcp_config_get_option (dhcp_config, "host_name");
if (dhcp_hostname && dhcp_hostname[0]) {
p = nm_str_skip_leading_spaces (dhcp_hostname);
if (p[0]) {
@ -765,12 +763,10 @@ update_system_hostname (NMPolicy *self, const char *msg)
}
if (priv->default_ac6) {
NMDhcp6Config *dhcp6_config;
/* Grab a hostname out of the device's DHCP6 config */
dhcp6_config = nm_device_get_dhcp6_config (get_default_device (self, AF_INET6));
if (dhcp6_config) {
dhcp_hostname = nm_dhcp6_config_get_option (dhcp6_config, "host_name");
dhcp_config = nm_device_get_dhcp6_config (get_default_device (self, AF_INET6));
if (dhcp_config) {
dhcp_hostname = nm_dhcp_config_get_option (dhcp_config, "host_name");
if (dhcp_hostname && dhcp_hostname[0]) {
p = nm_str_skip_leading_spaces (dhcp_hostname);
if (p[0]) {

View file

@ -24,8 +24,7 @@ typedef struct _NMConfig NMConfig;
typedef struct _NMConfigData NMConfigData;
typedef struct _NMConnectivity NMConnectivity;
typedef struct _NMDevice NMDevice;
typedef struct _NMDhcp4Config NMDhcp4Config;
typedef struct _NMDhcp6Config NMDhcp6Config;
typedef struct _NMDhcpConfig NMDhcpConfig;
typedef struct _NMProxyConfig NMProxyConfig;
typedef struct _NMIPConfig NMIPConfig;
typedef struct _NMIP4Config NMIP4Config;