From 4efc6f030a786bcfd47aee31979d87859158bec0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 15 Apr 2021 21:00:09 +0200 Subject: [PATCH 1/6] glib-aux: add NM_CAST_PPTR() macro --- src/libnm-glib-aux/nm-macros-internal.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/libnm-glib-aux/nm-macros-internal.h b/src/libnm-glib-aux/nm-macros-internal.h index cc3b19c3a1..aaf5cff61a 100644 --- a/src/libnm-glib-aux/nm-macros-internal.h +++ b/src/libnm-glib-aux/nm-macros-internal.h @@ -683,6 +683,21 @@ NM_G_ERROR_MSG(GError *error) #define NM_STRUCT_OFFSET_ENSURE_TYPE(type, container, field) G_STRUCT_OFFSET(container, field) #endif +/* Casts (arg) to (type**), but also having a compile time check that + * the arg is some sort of pointer to a pointer. + * + * The only purpose of this macro is some additional compile time safety, + * that the argument is a pointer to pointer. But then it will C cast any kind + * of such argument. */ +#define NM_CAST_PPTR(type, arg) \ + ({ \ + typeof(*(arg)) *const _arg = (arg); \ + typeof(*_arg) _arg2 = _arg ? *_arg : NULL; \ + _nm_unused const void *const _arg3 = _arg2; \ + \ + (type **) _arg; \ + }) + #if _NM_CC_SUPPORT_GENERIC /* these macros cast (value) to * - "const char **" (for "MC", mutable-const) From 80f6f4e115a513029720049065d2d4e24115ef75 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 15 Apr 2021 19:44:31 +0200 Subject: [PATCH 2/6] core: use NM_CAST_PPTR() for nm_dbus_object_clear_and_unexport() This ensures that the argument is some pointer to pointer. This gives a bit of additional compile time safety, but in general, it still casts any pointer to pointer (because that's what we require, as most arguments won't be of type NMDBusObject to begin with). --- src/core/nm-dbus-object.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/nm-dbus-object.h b/src/core/nm-dbus-object.h index d94bd5df45..94eb2d0d76 100644 --- a/src/core/nm-dbus-object.h +++ b/src/core/nm-dbus-object.h @@ -168,7 +168,7 @@ void nm_dbus_object_unexport_on_idle(gpointer /* (NMDBusObject *) */ self_take); void _nm_dbus_object_clear_and_unexport(NMDBusObject **location); #define nm_dbus_object_clear_and_unexport(location) \ - _nm_dbus_object_clear_and_unexport((NMDBusObject **) (location)) + _nm_dbus_object_clear_and_unexport(NM_CAST_PPTR(NMDBusObject, (location))) void nm_dbus_object_emit_signal_variant(NMDBusObject * self, const NMDBusInterfaceInfoExtended *interface_info, From d1457410fd21e680472a9eab303cb1e0d27d4f84 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 15 Apr 2021 19:44:31 +0200 Subject: [PATCH 3/6] core: return boolean result from nm_dbus_object_clear_and_unexport() To indicate, whether something was cleared. This will be used later. --- src/core/nm-dbus-object.c | 10 ++++++---- src/core/nm-dbus-object.h | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/core/nm-dbus-object.c b/src/core/nm-dbus-object.c index 6f294fe2ec..0414973929 100644 --- a/src/core/nm-dbus-object.c +++ b/src/core/nm-dbus-object.c @@ -183,23 +183,25 @@ nm_dbus_object_unexport_on_idle(gpointer /* (NMDBusObject *) */ self_take) /*****************************************************************************/ -void +gboolean _nm_dbus_object_clear_and_unexport(NMDBusObject **location) { NMDBusObject *self; - g_return_if_fail(location); + g_return_val_if_fail(location, FALSE); + if (!*location) - return; + return FALSE; self = g_steal_pointer(location); - g_return_if_fail(NM_IS_DBUS_OBJECT(self)); + g_return_val_if_fail(NM_IS_DBUS_OBJECT(self), FALSE); if (self->internal.path) nm_dbus_object_unexport(self); g_object_unref(self); + return TRUE; } /*****************************************************************************/ diff --git a/src/core/nm-dbus-object.h b/src/core/nm-dbus-object.h index 94eb2d0d76..c7c1b4f445 100644 --- a/src/core/nm-dbus-object.h +++ b/src/core/nm-dbus-object.h @@ -166,7 +166,7 @@ void nm_dbus_object_unexport(gpointer /* (NMDBusObject *) */ self); void nm_dbus_object_unexport_on_idle(gpointer /* (NMDBusObject *) */ self_take); -void _nm_dbus_object_clear_and_unexport(NMDBusObject **location); +gboolean _nm_dbus_object_clear_and_unexport(NMDBusObject **location); #define nm_dbus_object_clear_and_unexport(location) \ _nm_dbus_object_clear_and_unexport(NM_CAST_PPTR(NMDBusObject, (location))) From 5e77c67e0f77cf32675a6bcf4f99309c802bda0a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 15 Apr 2021 21:19:56 +0200 Subject: [PATCH 4/6] core: cleanup #include of "nm-dnsmasq-utils.c" --- src/core/dnsmasq/nm-dnsmasq-utils.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/dnsmasq/nm-dnsmasq-utils.c b/src/core/dnsmasq/nm-dnsmasq-utils.c index 86e18b5640..c2791b9e6c 100644 --- a/src/core/dnsmasq/nm-dnsmasq-utils.c +++ b/src/core/dnsmasq/nm-dnsmasq-utils.c @@ -5,9 +5,10 @@ #include "src/core/nm-default-daemon.h" +#include "nm-dnsmasq-utils.h" + #include -#include "nm-dnsmasq-utils.h" #include "libnm-platform/nm-platform.h" #include "nm-utils.h" From f7dec0ab1d228a63039681981b12954c5724cd42 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 16 Apr 2021 17:17:21 +0200 Subject: [PATCH 5/6] core: implement nm_dhcp_client_get_addr_family() This was already forward declared in the header, but not defined. Implement it. Will be used later. --- src/core/nm-dhcp-config.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/core/nm-dhcp-config.c b/src/core/nm-dhcp-config.c index c26b371dca..c77e0adbaf 100644 --- a/src/core/nm-dhcp-config.c +++ b/src/core/nm-dhcp-config.c @@ -59,6 +59,7 @@ struct _NMDhcpConfig { struct _NMDhcpConfigClass { NMDBusObjectClass parent; + int addr_family; }; G_DEFINE_ABSTRACT_TYPE(NMDhcpConfig, nm_dhcp_config, NM_TYPE_DBUS_OBJECT) @@ -67,6 +68,14 @@ G_DEFINE_ABSTRACT_TYPE(NMDhcpConfig, nm_dhcp_config, NM_TYPE_DBUS_OBJECT) /*****************************************************************************/ +int +nm_dhcp_config_get_addr_family(NMDhcpConfig *self) +{ + return NM_DHCP_CONFIG_GET_CLASS(self)->addr_family; +} + +/*****************************************************************************/ + void nm_dhcp_config_set_options(NMDhcpConfig *self, GHashTable *options) { @@ -197,10 +206,13 @@ static void nm_dhcp4_config_class_init(NMDhcp4ConfigClass *klass) { NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); + NMDhcpConfigClass *dhcp_config_class = NM_DHCP_CONFIG_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; + + dhcp_config_class->addr_family = AF_INET; } /*****************************************************************************/ @@ -234,8 +246,11 @@ static void nm_dhcp6_config_class_init(NMDhcp6ConfigClass *klass) { NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS(klass); + NMDhcpConfigClass *dhcp_config_class = NM_DHCP_CONFIG_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; + + dhcp_config_class->addr_family = AF_INET6; } From 5a6dbcefa3dbbae4f721c0e3de4b5c0cb9a4638a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 16 Apr 2021 17:56:30 +0200 Subject: [PATCH 6/6] core/trival: style cleanup --- src/core/ppp/nm-ppp-manager.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/ppp/nm-ppp-manager.c b/src/core/ppp/nm-ppp-manager.c index 137fccf31f..85f8d9aba6 100644 --- a/src/core/ppp/nm-ppp-manager.c +++ b/src/core/ppp/nm-ppp-manager.c @@ -1446,8 +1446,8 @@ nm_ppp_manager_class_init(NMPPPManagerClass *manager_class) NULL, G_TYPE_NONE, 2, - G_TYPE_UINT /*guint32 in_bytes*/, - G_TYPE_UINT /*guint32 out_bytes*/); + G_TYPE_UINT, /* guint32 in_bytes */ + G_TYPE_UINT); /* guint32 out_bytes */ } NMPPPOps ppp_ops = {