summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-11-06 18:22:11 +0100
committerThomas Haller <thaller@redhat.com>2020-11-09 17:53:16 +0100
commitcc35dc3bdf5f76cac5ed37127ca89eef18bb9998 (patch)
tree8d0aa7b8cd627d125956d5b98c094d96795ce005
parent7d5ec103df5209ca7fbf74309df53af87dd42e5e (diff)
downloadNetworkManager-cc35dc3bdf5f76cac5ed37127ca89eef18bb9998.tar.gz
device: improve "nm-device-logging.h" to support a self pointer of NMDevice type
"nm-device-logging.h" defines logging macros for a NMDevice instance. It also expects a "self" variable in the call environment, and that variable had to be in the type of NMDevice or the NMDevice subclass. Extend the macro foo, so that @self can be either a NMDevice* pointer or a NMDevice$SUBTYPE. Of course, that would have always been possible, if we would simply cast to "(NMDevice *)" where we need it. The trick is that the macro only works if @self is one of the two expected types, and not some arbitrary unrelated type.
-rw-r--r--src/devices/adsl/nm-device-adsl.c2
-rw-r--r--src/devices/bluetooth/nm-device-bt.c2
-rw-r--r--src/devices/nm-device-6lowpan.c2
-rw-r--r--src/devices/nm-device-bond.c2
-rw-r--r--src/devices/nm-device-bridge.c2
-rw-r--r--src/devices/nm-device-dummy.c2
-rw-r--r--src/devices/nm-device-ethernet.c2
-rw-r--r--src/devices/nm-device-ip-tunnel.c2
-rw-r--r--src/devices/nm-device-logging.h58
-rw-r--r--src/devices/nm-device-macsec.c2
-rw-r--r--src/devices/nm-device-macvlan.c2
-rw-r--r--src/devices/nm-device-ppp.c2
-rw-r--r--src/devices/nm-device-tun.c2
-rw-r--r--src/devices/nm-device-veth.c2
-rw-r--r--src/devices/nm-device-vlan.c2
-rw-r--r--src/devices/nm-device-vrf.c2
-rw-r--r--src/devices/nm-device-vxlan.c2
-rw-r--r--src/devices/nm-device-wireguard.c2
-rw-r--r--src/devices/nm-device-wpan.c2
-rw-r--r--src/devices/nm-device.c1
-rw-r--r--src/devices/ovs/nm-device-ovs-bridge.c2
-rw-r--r--src/devices/ovs/nm-device-ovs-interface.c2
-rw-r--r--src/devices/ovs/nm-device-ovs-port.c2
-rw-r--r--src/devices/team/nm-device-team.c2
-rw-r--r--src/devices/wifi/nm-device-iwd.c2
-rw-r--r--src/devices/wifi/nm-device-olpc-mesh.c2
-rw-r--r--src/devices/wifi/nm-device-wifi-p2p.c2
-rw-r--r--src/devices/wifi/nm-device-wifi.c2
-rw-r--r--src/devices/wwan/nm-device-modem.c2
29 files changed, 58 insertions, 55 deletions
diff --git a/src/devices/adsl/nm-device-adsl.c b/src/devices/adsl/nm-device-adsl.c
index 3261562399..556dfd829b 100644
--- a/src/devices/adsl/nm-device-adsl.c
+++ b/src/devices/adsl/nm-device-adsl.c
@@ -23,8 +23,8 @@
#include "nm-setting-adsl.h"
#include "nm-utils.h"
+#define _NMLOG_DEVICE_TYPE NMDeviceAdsl
#include "devices/nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDeviceAdsl);
/*****************************************************************************/
diff --git a/src/devices/bluetooth/nm-device-bt.c b/src/devices/bluetooth/nm-device-bt.c
index c31961df92..ca2a59731d 100644
--- a/src/devices/bluetooth/nm-device-bt.c
+++ b/src/devices/bluetooth/nm-device-bt.c
@@ -30,8 +30,8 @@
#include "devices/wwan/nm-modem-manager.h"
#include "devices/wwan/nm-modem.h"
+#define _NMLOG_DEVICE_TYPE NMDeviceBt
#include "devices/nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDeviceBt);
/*****************************************************************************/
diff --git a/src/devices/nm-device-6lowpan.c b/src/devices/nm-device-6lowpan.c
index bf63fb7337..5ab0b933f6 100644
--- a/src/devices/nm-device-6lowpan.c
+++ b/src/devices/nm-device-6lowpan.c
@@ -14,8 +14,8 @@
#include "nm-setting-6lowpan.h"
#include "nm-utils.h"
+#define _NMLOG_DEVICE_TYPE NMDevice6Lowpan
#include "nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDevice6Lowpan);
/*****************************************************************************/
diff --git a/src/devices/nm-device-bond.c b/src/devices/nm-device-bond.c
index 43f2a92ef4..0fa4be9158 100644
--- a/src/devices/nm-device-bond.c
+++ b/src/devices/nm-device-bond.c
@@ -17,8 +17,8 @@
#include "nm-core-internal.h"
#include "nm-ip4-config.h"
+#define _NMLOG_DEVICE_TYPE NMDeviceBond
#include "nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDeviceBond);
/*****************************************************************************/
diff --git a/src/devices/nm-device-bridge.c b/src/devices/nm-device-bridge.c
index 48dcec1b1d..930c93489f 100644
--- a/src/devices/nm-device-bridge.c
+++ b/src/devices/nm-device-bridge.c
@@ -15,8 +15,8 @@
#include "nm-device-factory.h"
#include "nm-core-internal.h"
+#define _NMLOG_DEVICE_TYPE NMDeviceBridge
#include "nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDeviceBridge);
/*****************************************************************************/
diff --git a/src/devices/nm-device-dummy.c b/src/devices/nm-device-dummy.c
index 4f6b8cc234..364a634647 100644
--- a/src/devices/nm-device-dummy.c
+++ b/src/devices/nm-device-dummy.c
@@ -18,8 +18,8 @@
#include "nm-setting-dummy.h"
#include "nm-core-internal.h"
+#define _NMLOG_DEVICE_TYPE NMDeviceDummy
#include "nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDeviceDummy);
/*****************************************************************************/
diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c
index 2569c4262c..a1ea1cf93a 100644
--- a/src/devices/nm-device-ethernet.c
+++ b/src/devices/nm-device-ethernet.c
@@ -35,8 +35,8 @@
#include "NetworkManagerUtils.h"
#include "nm-udev-aux/nm-udev-utils.h"
+#define _NMLOG_DEVICE_TYPE NMDeviceEthernet
#include "nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDeviceEthernet);
/*****************************************************************************/
diff --git a/src/devices/nm-device-ip-tunnel.c b/src/devices/nm-device-ip-tunnel.c
index e01cc7ff74..21307cab9e 100644
--- a/src/devices/nm-device-ip-tunnel.c
+++ b/src/devices/nm-device-ip-tunnel.c
@@ -22,8 +22,8 @@
#include "nm-act-request.h"
#include "nm-ip4-config.h"
+#define _NMLOG_DEVICE_TYPE NMDeviceIPTunnel
#include "nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDeviceIPTunnel);
/*****************************************************************************/
diff --git a/src/devices/nm-device-logging.h b/src/devices/nm-device-logging.h
index d12910207e..ff3d4180dc 100644
--- a/src/devices/nm-device-logging.h
+++ b/src/devices/nm-device-logging.h
@@ -8,36 +8,40 @@
#include "nm-device.h"
-#define _LOG_DECLARE_SELF(t) \
- _nm_unused static inline NMDevice *_nm_device_log_self_to_device(t *self) \
- { \
- return (NMDevice *) self; \
- }
+#if !_NM_CC_SUPPORT_GENERIC
+ #define _NM_DEVICE_CAST(self) ((NMDevice *) (self))
+#elif !defined(_NMLOG_DEVICE_TYPE)
+ #define _NM_DEVICE_CAST(self) _NM_ENSURE_TYPE(NMDevice *, self)
+#else
+ #define _NM_DEVICE_CAST(self) \
+ _Generic((self), _NMLOG_DEVICE_TYPE * \
+ : ((NMDevice *) (self)), NMDevice * \
+ : ((NMDevice *) (self)))
+#endif
#undef _NMLOG_ENABLED
#define _NMLOG_ENABLED(level, domain) (nm_logging_enabled((level), (domain)))
-#define _NMLOG(level, domain, ...) \
- G_STMT_START \
- { \
- const NMLogLevel _level = (level); \
- const NMLogDomain _domain = (domain); \
- \
- if (nm_logging_enabled(_level, _domain)) { \
- typeof(*self) *const _self = (self); \
- const char *const _ifname = \
- _nm_device_get_iface(_nm_device_log_self_to_device(_self)); \
- \
- nm_log_obj(_level, \
- _domain, \
- _ifname, \
- NULL, \
- _self, \
- "device", \
- "%s%s%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
- NM_PRINT_FMT_QUOTED(_ifname, "(", _ifname, ")", "[null]") \
- _NM_UTILS_MACRO_REST(__VA_ARGS__)); \
- } \
- } \
+#define _NMLOG(level, domain, ...) \
+ G_STMT_START \
+ { \
+ const NMLogLevel _level = (level); \
+ const NMLogDomain _domain = (domain); \
+ \
+ if (nm_logging_enabled(_level, _domain)) { \
+ typeof(*self) *const _self = (self); \
+ const char *const _ifname = _nm_device_get_iface(_NM_DEVICE_CAST(_self)); \
+ \
+ nm_log_obj(_level, \
+ _domain, \
+ _ifname, \
+ NULL, \
+ _self, \
+ "device", \
+ "%s%s%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
+ NM_PRINT_FMT_QUOTED(_ifname, "(", _ifname, ")", "[null]") \
+ _NM_UTILS_MACRO_REST(__VA_ARGS__)); \
+ } \
+ } \
G_STMT_END
#endif /* __NETWORKMANAGER_DEVICE_LOGGING_H__ */
diff --git a/src/devices/nm-device-macsec.c b/src/devices/nm-device-macsec.c
index 7d738b4243..3e3ed30f4d 100644
--- a/src/devices/nm-device-macsec.c
+++ b/src/devices/nm-device-macsec.c
@@ -18,8 +18,8 @@
#include "supplicant/nm-supplicant-interface.h"
#include "supplicant/nm-supplicant-config.h"
+#define _NMLOG_DEVICE_TYPE NMDeviceMacsec
#include "nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDeviceMacsec);
/*****************************************************************************/
diff --git a/src/devices/nm-device-macvlan.c b/src/devices/nm-device-macvlan.c
index d9e71c8ca8..12c53a3b08 100644
--- a/src/devices/nm-device-macvlan.c
+++ b/src/devices/nm-device-macvlan.c
@@ -21,8 +21,8 @@
#include "nm-ip4-config.h"
#include "nm-utils.h"
+#define _NMLOG_DEVICE_TYPE NMDeviceMacvlan
#include "nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDeviceMacvlan);
/*****************************************************************************/
diff --git a/src/devices/nm-device-ppp.c b/src/devices/nm-device-ppp.c
index 82861bdafc..0cdb7ac935 100644
--- a/src/devices/nm-device-ppp.c
+++ b/src/devices/nm-device-ppp.c
@@ -18,8 +18,8 @@
#include "ppp/nm-ppp-manager-call.h"
#include "ppp/nm-ppp-status.h"
+#define _NMLOG_DEVICE_TYPE NMDevicePpp
#include "nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDevicePpp);
/*****************************************************************************/
diff --git a/src/devices/nm-device-tun.c b/src/devices/nm-device-tun.c
index 9480525502..ae1550809b 100644
--- a/src/devices/nm-device-tun.c
+++ b/src/devices/nm-device-tun.c
@@ -19,8 +19,8 @@
#include "nm-setting-tun.h"
#include "nm-core-internal.h"
+#define _NMLOG_DEVICE_TYPE NMDeviceTun
#include "nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDeviceTun);
/*****************************************************************************/
diff --git a/src/devices/nm-device-veth.c b/src/devices/nm-device-veth.c
index f61bc99f2a..7982a7faa4 100644
--- a/src/devices/nm-device-veth.c
+++ b/src/devices/nm-device-veth.c
@@ -13,8 +13,8 @@
#include "platform/nm-platform.h"
#include "nm-device-factory.h"
+#define _NMLOG_DEVICE_TYPE NMDeviceVeth
#include "nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDeviceVeth);
/*****************************************************************************/
diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c
index 8a743d1e62..5f036cd54b 100644
--- a/src/devices/nm-device-vlan.c
+++ b/src/devices/nm-device-vlan.c
@@ -22,8 +22,8 @@
#include "nm-core-internal.h"
#include "platform/nmp-object.h"
+#define _NMLOG_DEVICE_TYPE NMDeviceVlan
#include "nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDeviceVlan);
/*****************************************************************************/
diff --git a/src/devices/nm-device-vrf.c b/src/devices/nm-device-vrf.c
index ae0ecc60aa..9c3927e146 100644
--- a/src/devices/nm-device-vrf.c
+++ b/src/devices/nm-device-vrf.c
@@ -12,8 +12,8 @@
#include "platform/nm-platform.h"
#include "settings/nm-settings.h"
+#define _NMLOG_DEVICE_TYPE NMDeviceVrf
#include "nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDeviceVrf);
/*****************************************************************************/
diff --git a/src/devices/nm-device-vxlan.c b/src/devices/nm-device-vxlan.c
index 2ed66a644d..e9dd969886 100644
--- a/src/devices/nm-device-vxlan.c
+++ b/src/devices/nm-device-vxlan.c
@@ -19,8 +19,8 @@
#include "nm-ip4-config.h"
#include "nm-core-internal.h"
+#define _NMLOG_DEVICE_TYPE NMDeviceVxlan
#include "nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDeviceVxlan);
/*****************************************************************************/
diff --git a/src/devices/nm-device-wireguard.c b/src/devices/nm-device-wireguard.c
index 9bd23e6564..c8bc4bfcb2 100644
--- a/src/devices/nm-device-wireguard.c
+++ b/src/devices/nm-device-wireguard.c
@@ -22,8 +22,8 @@
#include "nm-act-request.h"
#include "dns/nm-dns-manager.h"
+#define _NMLOG_DEVICE_TYPE NMDeviceWireGuard
#include "nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDeviceWireGuard);
/*****************************************************************************/
diff --git a/src/devices/nm-device-wpan.c b/src/devices/nm-device-wpan.c
index 195603dcde..f8e2b641ca 100644
--- a/src/devices/nm-device-wpan.c
+++ b/src/devices/nm-device-wpan.c
@@ -20,8 +20,8 @@
#include "nm-setting-wpan.h"
#include "nm-core-internal.h"
+#define _NMLOG_DEVICE_TYPE NMDeviceWpan
#include "nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDeviceWpan);
/*****************************************************************************/
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 6e53048bb4..df3669aceb 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -74,7 +74,6 @@
#include "nm-device-wireguard.h"
#include "nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDevice);
/*****************************************************************************/
diff --git a/src/devices/ovs/nm-device-ovs-bridge.c b/src/devices/ovs/nm-device-ovs-bridge.c
index a7b7a539e2..6c92544c9c 100644
--- a/src/devices/ovs/nm-device-ovs-bridge.c
+++ b/src/devices/ovs/nm-device-ovs-bridge.c
@@ -14,8 +14,8 @@
#include "nm-setting-connection.h"
#include "nm-setting-ovs-bridge.h"
+#define _NMLOG_DEVICE_TYPE NMDeviceOvsBridge
#include "devices/nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDeviceOvsBridge);
/*****************************************************************************/
diff --git a/src/devices/ovs/nm-device-ovs-interface.c b/src/devices/ovs/nm-device-ovs-interface.c
index 16b6e04da0..0084c8bc58 100644
--- a/src/devices/ovs/nm-device-ovs-interface.c
+++ b/src/devices/ovs/nm-device-ovs-interface.c
@@ -14,8 +14,8 @@
#include "nm-setting-ovs-interface.h"
#include "nm-setting-ovs-port.h"
+#define _NMLOG_DEVICE_TYPE NMDeviceOvsInterface
#include "devices/nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDeviceOvsInterface);
/*****************************************************************************/
diff --git a/src/devices/ovs/nm-device-ovs-port.c b/src/devices/ovs/nm-device-ovs-port.c
index de98e29e06..d3a462753a 100644
--- a/src/devices/ovs/nm-device-ovs-port.c
+++ b/src/devices/ovs/nm-device-ovs-port.c
@@ -15,8 +15,8 @@
#include "nm-setting-ovs-port.h"
#include "nm-setting-ovs-port.h"
+#define _NMLOG_DEVICE_TYPE NMDeviceOvsPort
#include "devices/nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDeviceOvsPort);
/*****************************************************************************/
diff --git a/src/devices/team/nm-device-team.c b/src/devices/team/nm-device-team.c
index 27aa300430..65fd70c78a 100644
--- a/src/devices/team/nm-device-team.c
+++ b/src/devices/team/nm-device-team.c
@@ -25,8 +25,8 @@
#include "nm-ip4-config.h"
#include "nm-std-aux/nm-dbus-compat.h"
+#define _NMLOG_DEVICE_TYPE NMDeviceTeam
#include "devices/nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDeviceTeam);
/*****************************************************************************/
diff --git a/src/devices/wifi/nm-device-iwd.c b/src/devices/wifi/nm-device-iwd.c
index c479b3d453..e59dafdefe 100644
--- a/src/devices/wifi/nm-device-iwd.c
+++ b/src/devices/wifi/nm-device-iwd.c
@@ -28,8 +28,8 @@
#include "settings/nm-settings.h"
#include "supplicant/nm-supplicant-types.h"
+#define _NMLOG_DEVICE_TYPE NMDeviceIwd
#include "devices/nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDeviceIwd);
/*****************************************************************************/
diff --git a/src/devices/wifi/nm-device-olpc-mesh.c b/src/devices/wifi/nm-device-olpc-mesh.c
index 22e94a6dcc..4b9c640149 100644
--- a/src/devices/wifi/nm-device-olpc-mesh.c
+++ b/src/devices/wifi/nm-device-olpc-mesh.c
@@ -30,8 +30,8 @@
#include "nm-manager.h"
#include "platform/nm-platform.h"
+#define _NMLOG_DEVICE_TYPE NMDeviceOlpcMesh
#include "devices/nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDeviceOlpcMesh);
/*****************************************************************************/
diff --git a/src/devices/wifi/nm-device-wifi-p2p.c b/src/devices/wifi/nm-device-wifi-p2p.c
index 2e5317fd95..0780d80b34 100644
--- a/src/devices/wifi/nm-device-wifi-p2p.c
+++ b/src/devices/wifi/nm-device-wifi-p2p.c
@@ -27,8 +27,8 @@
#include "platform/nmp-object.h"
#include "settings/nm-settings.h"
+#define _NMLOG_DEVICE_TYPE NMDeviceWifiP2P
#include "devices/nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDeviceWifiP2P);
/*****************************************************************************/
diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c
index 7c749f1e3c..24de0cdeca 100644
--- a/src/devices/wifi/nm-device-wifi.c
+++ b/src/devices/wifi/nm-device-wifi.c
@@ -41,8 +41,8 @@
#include "nm-core-internal.h"
#include "nm-config.h"
+#define _NMLOG_DEVICE_TYPE NMDeviceWifi
#include "devices/nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDeviceWifi);
#define SCAN_INTERVAL_SEC_MIN 3
#define SCAN_INTERVAL_SEC_STEP 20
diff --git a/src/devices/wwan/nm-device-modem.c b/src/devices/wwan/nm-device-modem.c
index f77de85aac..5b8b3bd29d 100644
--- a/src/devices/wwan/nm-device-modem.c
+++ b/src/devices/wwan/nm-device-modem.c
@@ -16,8 +16,8 @@
#include "NetworkManagerUtils.h"
#include "nm-core-internal.h"
+#define _NMLOG_DEVICE_TYPE NMDeviceModem
#include "devices/nm-device-logging.h"
-_LOG_DECLARE_SELF(NMDeviceModem);
/*****************************************************************************/