summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-11-08 14:27:16 +0100
committerThomas Haller <thaller@redhat.com>2017-11-08 14:46:31 +0100
commit10d38a950dbd182408e6b6cc10da165fbce961df (patch)
tree07ba17525dccae94e3d70631506e34b3c0c86ccf
parent157932f7dd00271ce4c8876c1a6086d81c4995c3 (diff)
downloadNetworkManager-10d38a950dbd182408e6b6cc10da165fbce961df.tar.gz
core: add generic opaque NMIPConfig type
One day, I hope to merge NMIP4Config and NMIP6Config implementations. A small step, and a typesafe cast-macro.
-rw-r--r--src/nm-ip4-config.h33
-rw-r--r--src/nm-types.h1
2 files changed, 34 insertions, 0 deletions
diff --git a/src/nm-ip4-config.h b/src/nm-ip4-config.h
index 978471df29..a698857cfd 100644
--- a/src/nm-ip4-config.h
+++ b/src/nm-ip4-config.h
@@ -267,4 +267,37 @@ gboolean nm_ip4_config_nmpobj_remove (NMIP4Config *self,
void nm_ip4_config_hash (const NMIP4Config *self, GChecksum *sum, gboolean dns_only);
gboolean nm_ip4_config_equal (const NMIP4Config *a, const NMIP4Config *b);
+/*****************************************************************************/
+
+#include "nm-ip6-config.h"
+
+#if _NM_CC_SUPPORT_GENERIC
+#define NM_IP_CONFIG_CAST(config) \
+ ({ \
+ const void *const _config = (config); \
+ \
+ nm_assert (_Generic ((config), \
+ const void *: (NM_IS_IP4_CONFIG (_config) || NM_IS_IP6_CONFIG (_config)), \
+ void *: (NM_IS_IP4_CONFIG (_config) || NM_IS_IP6_CONFIG (_config)), \
+ const NMIPConfig *: (NM_IS_IP4_CONFIG (_config) || NM_IS_IP6_CONFIG (_config)), \
+ NMIPConfig *: (NM_IS_IP4_CONFIG (_config) || NM_IS_IP6_CONFIG (_config)), \
+ const NMIP4Config *: (NM_IS_IP4_CONFIG (_config)), \
+ NMIP4Config *: (NM_IS_IP4_CONFIG (_config)), \
+ const NMIP6Config *: (NM_IS_IP6_CONFIG (_config)), \
+ NMIP6Config *: (NM_IS_IP6_CONFIG (_config)))); \
+ \
+ _Generic ((config), \
+ const void *: ((const NMIPConfig *) _config), \
+ void *: (( NMIPConfig *) _config), \
+ const NMIPConfig *: ((const NMIPConfig *) _config), \
+ NMIPConfig *: (( NMIPConfig *) _config), \
+ const NMIP4Config *: ((const NMIPConfig *) _config), \
+ NMIP4Config *: (( NMIPConfig *) _config), \
+ const NMIP6Config *: ((const NMIPConfig *) _config), \
+ NMIP6Config *: (( NMIPConfig *) _config)); \
+ })
+#else
+#define NM_IP_CONFIG_CAST(config) ((NMIPConfig *) (config))
+#endif
+
#endif /* __NETWORKMANAGER_IP4_CONFIG_H__ */
diff --git a/src/nm-types.h b/src/nm-types.h
index e01c48b0a5..cad3c0315a 100644
--- a/src/nm-types.h
+++ b/src/nm-types.h
@@ -42,6 +42,7 @@ typedef struct _NMDevice NMDevice;
typedef struct _NMDhcp4Config NMDhcp4Config;
typedef struct _NMDhcp6Config NMDhcp6Config;
typedef struct _NMProxyConfig NMProxyConfig;
+typedef struct _NMIPConfig NMIPConfig;
typedef struct _NMIP4Config NMIP4Config;
typedef struct _NMIP6Config NMIP6Config;
typedef struct _NMManager NMManager;