From f13c7e3bbd87492446ab53c925c3d4a887b7f27b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 20 Feb 2020 14:24:40 +0100 Subject: [PATCH 1/5] shared: extend NM_GOBJECT_PROPERTIES_DEFINE*() macros to append suffix to defined names This way, we will be able to use the macro multiple times in the same source file by using different suffixes. --- shared/nm-glib-aux/nm-macros-internal.h | 38 ++++++++++++++----------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/shared/nm-glib-aux/nm-macros-internal.h b/shared/nm-glib-aux/nm-macros-internal.h index 3cb11a973f..56353a46fb 100644 --- a/shared/nm-glib-aux/nm-macros-internal.h +++ b/shared/nm-glib-aux/nm-macros-internal.h @@ -1043,17 +1043,17 @@ nm_str_realloc (char *str) /*****************************************************************************/ -#define NM_GOBJECT_PROPERTIES_DEFINE_BASE(...) \ +#define NM_GOBJECT_PROPERTIES_DEFINE_BASE_FULL(suffix, ...) \ typedef enum { \ - PROP_0, \ + PROP_0##suffix, \ __VA_ARGS__ \ - _PROPERTY_ENUMS_LAST, \ -} _PropertyEnums; \ -static GParamSpec *obj_properties[_PROPERTY_ENUMS_LAST] = { NULL, } + _PROPERTY_ENUMS_LAST##suffix, \ +} _PropertyEnums##suffix; \ +static GParamSpec *obj_properties##suffix[_PROPERTY_ENUMS_LAST##suffix] = { NULL, } -#define NM_GOBJECT_PROPERTIES_DEFINE_NOTIFY(obj_type, obj_properties, property_enums_type, prop_0) \ +#define NM_GOBJECT_PROPERTIES_DEFINE_NOTIFY(suffix, obj_type) \ static inline void \ -_nm_gobject_notify_together_impl (obj_type *obj, guint n, const property_enums_type *props) \ +_nm_gobject_notify_together_impl (obj_type *obj, guint n, const _PropertyEnums##suffix *props) \ { \ const gboolean freeze_thaw = (n > 1); \ \ @@ -1063,12 +1063,12 @@ _nm_gobject_notify_together_impl (obj_type *obj, guint n, const property_enums_t if (freeze_thaw) \ g_object_freeze_notify ((GObject *) obj); \ while (n-- > 0) { \ - const property_enums_type prop = *props++; \ + const _PropertyEnums##suffix prop = *props++; \ \ - if (prop != prop_0) { \ - nm_assert ((gsize) prop < G_N_ELEMENTS (obj_properties)); \ - nm_assert (obj_properties[prop]); \ - g_object_notify_by_pspec ((GObject *) obj, obj_properties[prop]); \ + if (prop != PROP_0##suffix) { \ + nm_assert ((gsize) prop < G_N_ELEMENTS (obj_properties##suffix)); \ + nm_assert (obj_properties##suffix[prop]); \ + g_object_notify_by_pspec ((GObject *) obj, obj_properties##suffix[prop]); \ } \ } \ if (freeze_thaw) \ @@ -1076,20 +1076,26 @@ _nm_gobject_notify_together_impl (obj_type *obj, guint n, const property_enums_t } \ \ _nm_unused static inline void \ -_notify (obj_type *obj, property_enums_type prop) \ +_notify (obj_type *obj, _PropertyEnums##suffix prop) \ { \ _nm_gobject_notify_together_impl (obj, 1, &prop); \ } \ +#define NM_GOBJECT_PROPERTIES_DEFINE_BASE(...) \ + NM_GOBJECT_PROPERTIES_DEFINE_BASE_FULL (, __VA_ARGS__); \ + #define NM_GOBJECT_PROPERTIES_DEFINE(obj_type, ...) \ -NM_GOBJECT_PROPERTIES_DEFINE_BASE (__VA_ARGS__); \ -NM_GOBJECT_PROPERTIES_DEFINE_NOTIFY (obj_type, obj_properties, _PropertyEnums, PROP_0) + NM_GOBJECT_PROPERTIES_DEFINE_BASE_FULL (, __VA_ARGS__); \ + NM_GOBJECT_PROPERTIES_DEFINE_NOTIFY (, obj_type) /* invokes _notify() for all arguments (of type _PropertyEnums). Note, that if * there are more than one prop arguments, this will involve a freeze/thaw * of GObject property notifications. */ +#define nm_gobject_notify_together_full(suffix, obj, ...) \ + _nm_gobject_notify_together_impl (obj, NM_NARG (__VA_ARGS__), (const _PropertyEnums##suffix[]) { __VA_ARGS__ }) + #define nm_gobject_notify_together(obj, ...) \ - _nm_gobject_notify_together_impl (obj, NM_NARG (__VA_ARGS__), (const _PropertyEnums[]) { __VA_ARGS__ }) + nm_gobject_notify_together_full (, obj, __VA_ARGS__) /*****************************************************************************/ From c8d043dd9463c9fb9688c86209dc7b9a46d2430b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 20 Feb 2020 15:11:20 +0100 Subject: [PATCH 2/5] core: avoid duplicate lookup in nm_utils_strdict_to_variant() Collect the full list of key and values, while sorting the key. This way, we don't need to lookup the values by key later. --- src/nm-core-utils.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c index 1ff0764777..a5275963c4 100644 --- a/src/nm-core-utils.c +++ b/src/nm-core-utils.c @@ -4055,18 +4055,18 @@ GVariant * nm_utils_strdict_to_variant (GHashTable *options) { GVariantBuilder builder; - gs_free const char **keys = NULL; + gs_free NMUtilsNamedValue *values = NULL; guint i; - guint nkeys; + guint n; - keys = nm_utils_strdict_get_keys (options, TRUE, &nkeys); + values = nm_utils_named_values_from_str_dict (options, &n); g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); - for (i = 0; i < nkeys; i++) { + for (i = 0; i < n; i++) { g_variant_builder_add (&builder, "{sv}", - keys[i], - g_variant_new_string (g_hash_table_lookup (options, keys[i]))); + values[i].name, + g_variant_new_string (values[i].value_str)); } return g_variant_builder_end (&builder); } From cd03d39a6d2bad0c1133832f97723634456eea29 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 20 Feb 2020 14:09:33 +0100 Subject: [PATCH 3/5] core: rename "nm-dhcp4-config.[ch]" to "nm-dhcp-config.[hc]" before merge NMDhcp4Config and NMDhcp6Config will get a common base type NMDhcpConfig and be merged. In preparation, rename the file. --- Makefile.am | 4 ++-- src/devices/nm-device.c | 2 +- src/dhcp/nm-dhcp-manager.h | 2 +- src/meson.build | 2 +- src/{nm-dhcp4-config.c => nm-dhcp-config.c} | 2 +- src/{nm-dhcp4-config.h => nm-dhcp-config.h} | 0 src/nm-dispatcher.c | 2 +- src/nm-policy.c | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) rename src/{nm-dhcp4-config.c => nm-dhcp-config.c} (99%) rename src/{nm-dhcp4-config.h => nm-dhcp-config.h} (100%) diff --git a/Makefile.am b/Makefile.am index 84a4589292..b53b7e5613 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2277,8 +2277,8 @@ src_libNetworkManager_la_SOURCES = \ src/nm-dcb.h \ src/nm-netns.c \ src/nm-netns.h \ - src/nm-dhcp4-config.c \ - src/nm-dhcp4-config.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 \ diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index dbda4d8501..27164e4380 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -43,7 +43,7 @@ #include "nm-ip6-config.h" #include "nm-pacrunner-manager.h" #include "dnsmasq/nm-dnsmasq-manager.h" -#include "nm-dhcp4-config.h" +#include "nm-dhcp-config.h" #include "nm-dhcp6-config.h" #include "nm-rfkill-manager.h" #include "nm-firewall-manager.h" diff --git a/src/dhcp/nm-dhcp-manager.h b/src/dhcp/nm-dhcp-manager.h index fb1c98346b..1b793c22f8 100644 --- a/src/dhcp/nm-dhcp-manager.h +++ b/src/dhcp/nm-dhcp-manager.h @@ -9,7 +9,7 @@ #include "nm-dhcp-client.h" #include "nm-ip4-config.h" -#include "nm-dhcp4-config.h" +#include "nm-dhcp-config.h" #define NM_TYPE_DHCP_MANAGER (nm_dhcp_manager_get_type ()) #define NM_DHCP_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DHCP_MANAGER, NMDhcpManager)) diff --git a/src/meson.build b/src/meson.build index bc816a8543..1cee986b88 100644 --- a/src/meson.build +++ b/src/meson.build @@ -135,7 +135,7 @@ sources = files( 'nm-config-data.c', 'nm-connectivity.c', 'nm-dcb.c', - 'nm-dhcp4-config.c', + 'nm-dhcp-config.c', 'nm-dhcp6-config.c', 'nm-dispatcher.c', 'nm-firewall-manager.c', diff --git a/src/nm-dhcp4-config.c b/src/nm-dhcp-config.c similarity index 99% rename from src/nm-dhcp4-config.c rename to src/nm-dhcp-config.c index f64c72574b..896e39268f 100644 --- a/src/nm-dhcp4-config.c +++ b/src/nm-dhcp-config.c @@ -5,7 +5,7 @@ #include "nm-default.h" -#include "nm-dhcp4-config.h" +#include "nm-dhcp-config.h" #include "nm-dbus-interface.h" #include "nm-utils.h" diff --git a/src/nm-dhcp4-config.h b/src/nm-dhcp-config.h similarity index 100% rename from src/nm-dhcp4-config.h rename to src/nm-dhcp-config.h diff --git a/src/nm-dispatcher.c b/src/nm-dispatcher.c index 54b0567bc3..f53f95ad30 100644 --- a/src/nm-dispatcher.c +++ b/src/nm-dispatcher.c @@ -14,7 +14,7 @@ #include "nm-connectivity.h" #include "nm-act-request.h" #include "devices/nm-device.h" -#include "nm-dhcp4-config.h" +#include "nm-dhcp-config.h" #include "nm-dhcp6-config.h" #include "nm-proxy-config.h" #include "nm-ip4-config.h" diff --git a/src/nm-policy.c b/src/nm-policy.c index 7a5ed42b6c..c6f3ecc6b3 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -29,7 +29,7 @@ #include "settings/nm-settings.h" #include "settings/nm-settings-connection.h" #include "settings/nm-agent-manager.h" -#include "nm-dhcp4-config.h" +#include "nm-dhcp-config.h" #include "nm-dhcp6-config.h" #include "nm-config.h" #include "nm-netns.h" From 26f208aec30cf1c9add0b3d37dc8781b291d87e1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 20 Feb 2020 14:12:31 +0100 Subject: [PATCH 4/5] 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. --- Makefile.am | 2 - src/devices/nm-device.c | 51 +++++------ src/devices/nm-device.h | 4 +- src/meson.build | 1 - src/nm-dhcp-config.c | 197 +++++++++++++++++++++++++++++----------- src/nm-dhcp-config.h | 38 ++++---- src/nm-dhcp6-config.c | 156 ------------------------------- src/nm-dhcp6-config.h | 31 ------- src/nm-dispatcher.c | 16 ++-- src/nm-manager.c | 10 +- src/nm-policy.c | 18 ++-- src/nm-types.h | 3 +- 12 files changed, 211 insertions(+), 316 deletions(-) delete mode 100644 src/nm-dhcp6-config.c delete mode 100644 src/nm-dhcp6-config.h diff --git a/Makefile.am b/Makefile.am index b53b7e5613..3ca9eac098 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 27164e4380..9e9d037fd8 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -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); diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index 26b064ae92..b00f2e6c30 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -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, diff --git a/src/meson.build b/src/meson.build index 1cee986b88..a7a99bc214 100644 --- a/src/meson.build +++ b/src/meson.build @@ -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', diff --git a/src/nm-dhcp-config.c b/src/nm-dhcp-config.c index 896e39268f..3b9211df99 100644 --- a/src/nm-dhcp-config.c +++ b/src/nm-dhcp-config.c @@ -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; } diff --git a/src/nm-dhcp-config.h b/src/nm-dhcp-config.h index 3cad1e82f5..da192e778f 100644 --- a/src/nm-dhcp-config.h +++ b/src/nm-dhcp-config.h @@ -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__ */ diff --git a/src/nm-dhcp6-config.c b/src/nm-dhcp6-config.c deleted file mode 100644 index a50abd1285..0000000000 --- a/src/nm-dhcp6-config.c +++ /dev/null @@ -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); -} diff --git a/src/nm-dhcp6-config.h b/src/nm-dhcp6-config.h deleted file mode 100644 index e5697e0469..0000000000 --- a/src/nm-dhcp6-config.h +++ /dev/null @@ -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__ */ diff --git a/src/nm-dispatcher.c b/src/nm-dispatcher.c index f53f95ad30..957f029f3a 100644 --- a/src/nm-dispatcher.c +++ b/src/nm-dispatcher.c @@ -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 diff --git a/src/nm-manager.c b/src/nm-manager.c index dd71aea990..b594b899d6 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -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, diff --git a/src/nm-policy.c b/src/nm-policy.c index c6f3ecc6b3..6f2cfa6020 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -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]) { diff --git a/src/nm-types.h b/src/nm-types.h index 8dc1feeb51..4db9a19b13 100644 --- a/src/nm-types.h +++ b/src/nm-types.h @@ -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; From 121d44635423f91b8184e1ccd3fb6b1f628c6abf Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 20 Feb 2020 15:06:47 +0100 Subject: [PATCH 5/5] device: merge nm_device_get_dhcp[46]_config() to nm_device_get_dhcp_config() --- src/devices/nm-device.c | 16 ++++++---------- src/devices/nm-device.h | 3 +-- src/nm-dispatcher.c | 4 ++-- src/nm-manager.c | 2 +- src/nm-policy.c | 4 ++-- 5 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 9e9d037fd8..d9d9eea280 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -12824,11 +12824,15 @@ nm_device_set_proxy_config (NMDevice *self, const char *pac_url) /* IP Configuration stuff */ NMDhcpConfig * -nm_device_get_dhcp4_config (NMDevice *self) +nm_device_get_dhcp_config (NMDevice *self, int addr_family) { + const gboolean IS_IPv4 = (addr_family == AF_INET); + g_return_val_if_fail (NM_IS_DEVICE (self), NULL); - return NM_DEVICE_GET_PRIVATE (self)->dhcp_data_4.config; + nm_assert_addr_family (addr_family); + + return NM_DEVICE_GET_PRIVATE (self)->dhcp_data_x[IS_IPv4].config; } NMIP4Config * @@ -13082,14 +13086,6 @@ nm_device_replace_vpn6_config (NMDevice *self, NMIP6Config *old, NMIP6Config *co _LOGW (LOGD_IP6, "failed to set VPN routes for device"); } -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; -} - NMIP6Config * nm_device_get_ip6_config (NMDevice *self) { diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index b00f2e6c30..28f86e825e 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -504,8 +504,7 @@ const char * nm_device_get_initial_hw_address (NMDevice *dev); NMProxyConfig * nm_device_get_proxy_config (NMDevice *dev); -NMDhcpConfig * nm_device_get_dhcp4_config (NMDevice *dev); -NMDhcpConfig * nm_device_get_dhcp6_config (NMDevice *dev); +NMDhcpConfig * nm_device_get_dhcp_config (NMDevice *dev, int addr_family); NMIP4Config * nm_device_get_ip4_config (NMDevice *dev); void nm_device_replace_vpn4_config (NMDevice *dev, NMIP4Config *old, diff --git a/src/nm-dispatcher.c b/src/nm-dispatcher.c index 957f029f3a..e5584cd651 100644 --- a/src/nm-dispatcher.c +++ b/src/nm-dispatcher.c @@ -358,11 +358,11 @@ fill_device_props (NMDevice *device, if (ip6_config) dump_ip6_to_props (ip6_config, ip6_builder); - dhcp_config = nm_device_get_dhcp4_config (device); + dhcp_config = nm_device_get_dhcp_config (device, AF_INET); if (dhcp_config) *dhcp4_props = nm_g_variant_ref (nm_dhcp_config_get_options (dhcp_config)); - dhcp_config = nm_device_get_dhcp6_config (device); + dhcp_config = nm_device_get_dhcp_config (device, AF_INET6); if (dhcp_config) *dhcp6_props = nm_g_variant_ref (nm_dhcp_config_get_options (dhcp_config)); } diff --git a/src/nm-manager.c b/src/nm-manager.c index b594b899d6..75bee452de 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -6534,7 +6534,7 @@ 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); - dhcp_config = nm_device_get_dhcp4_config (device); + dhcp_config = nm_device_get_dhcp_config (device, AF_INET); 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"); diff --git a/src/nm-policy.c b/src/nm-policy.c index 6f2cfa6020..914c965163 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -746,7 +746,7 @@ update_system_hostname (NMPolicy *self, const char *msg) if (priv->default_ac4) { /* Grab a hostname out of the device's DHCP4 config */ - dhcp_config = nm_device_get_dhcp4_config (get_default_device (self, AF_INET)); + dhcp_config = nm_device_get_dhcp_config (get_default_device (self, AF_INET), AF_INET); if (dhcp_config) { dhcp_hostname = nm_dhcp_config_get_option (dhcp_config, "host_name"); if (dhcp_hostname && dhcp_hostname[0]) { @@ -764,7 +764,7 @@ update_system_hostname (NMPolicy *self, const char *msg) if (priv->default_ac6) { /* Grab a hostname out of the device's DHCP6 config */ - dhcp_config = nm_device_get_dhcp6_config (get_default_device (self, AF_INET6)); + dhcp_config = nm_device_get_dhcp_config (get_default_device (self, AF_INET6), AF_INET6); if (dhcp_config) { dhcp_hostname = nm_dhcp_config_get_option (dhcp_config, "host_name"); if (dhcp_hostname && dhcp_hostname[0]) {