[PATCH v2 1/1] platform: extract common fields of platform objects to base struct
- From: Thomas Haller <thaller redhat com>
- To: Network Manager <networkmanager-list gnome org>
- Subject: [PATCH v2 1/1] platform: extract common fields of platform objects to base struct
- Date: Mon, 7 Apr 2014 21:03:38 +0200
Especially the calculation of timestamps is identicall for addresses.
By creating a "base struct", we can use the same code for that, because
NMPlatformIP4Address and NMPlatformIP6Address can now both be treated as
NMPlatformIPAddress.
Signed-off-by: Thomas Haller <thaller redhat com>
---
src/platform/nm-platform.h | 68 ++++++++++++++++++++++++++++++----------------
1 file changed, 45 insertions(+), 23 deletions(-)
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index acca60b..715fadd 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -112,8 +112,12 @@ typedef enum {
NM_LINK_TYPE_TEAM,
} NMLinkType;
+#define __NMPlatformObject_COMMON \
+ int ifindex; \
+ ;
+
typedef struct {
- int ifindex;
+ __NMPlatformObject_COMMON;
char name[IFNAMSIZ];
NMLinkType type;
const char *type_name;
@@ -149,19 +153,37 @@ typedef enum {
NM_PLATFORM_SOURCE_USER,
} NMPlatformSource;
+typedef struct {
+ __NMPlatformObject_COMMON;
+} NMPlatformObject;
+
+#define __NMPlatformIPAddress_COMMON \
+ __NMPlatformObject_COMMON; \
+ NMPlatformSource source; \
+ guint32 timestamp; /* nm_utils_get_monotonic_timestamp_s() */ \
+ guint32 lifetime; /* seconds */ \
+ guint32 preferred; /* seconds */ \
+ int plen; \
+ ;
+
+/**
+ * NMPlatformIPAddress:
+ *
+ * Common parts of NMPlatformIP4Address and NMPlatformIP6Address.
+ **/
+typedef struct {
+ __NMPlatformIPAddress_COMMON;
+ guint8 address_ptr[1];
+} NMPlatformIPAddress;
+
/**
* NMPlatformIP4Address:
* @timestamp: timestamp as returned by nm_utils_get_monotonic_timestamp_s()
**/
typedef struct {
- int ifindex;
- NMPlatformSource source;
+ __NMPlatformIPAddress_COMMON;
in_addr_t address;
in_addr_t peer_address; /* PTP peer address */
- int plen;
- guint32 timestamp;
- guint32 lifetime; /* seconds */
- guint32 preferred; /* seconds */
char label[IFNAMSIZ];
} NMPlatformIP4Address;
@@ -170,37 +192,37 @@ typedef struct {
* @timestamp: timestamp as returned by nm_utils_get_monotonic_timestamp_s()
**/
typedef struct {
- int ifindex;
- NMPlatformSource source;
+ __NMPlatformIPAddress_COMMON;
struct in6_addr address;
struct in6_addr peer_address;
- int plen;
- guint32 timestamp; /* seconds */
- guint32 lifetime; /* seconds */
- guint32 preferred;
guint flags; /* ifa_flags from <linux/if_addr.h>, field type "unsigned int" is as used in
rtnl_addr_get_flags. */
} NMPlatformIP6Address;
#define NM_PLATFORM_ROUTE_METRIC_DEFAULT 1024
+#define __NMPlatformIPRoute_COMMON \
+ __NMPlatformObject_COMMON; \
+ NMPlatformSource source; \
+ int plen; \
+ guint metric; \
+ guint mss; \
+ ;
+
+typedef struct {
+ __NMPlatformIPRoute_COMMON;
+ guint8 network_ptr[1];
+} NMPlatformIPRoute;
+
typedef struct {
- int ifindex;
- NMPlatformSource source;
+ __NMPlatformIPRoute_COMMON;
in_addr_t network;
- int plen;
in_addr_t gateway;
- guint metric;
- guint mss;
} NMPlatformIP4Route;
typedef struct {
- int ifindex;
- NMPlatformSource source;
+ __NMPlatformIPRoute_COMMON;
struct in6_addr network;
- int plen;
struct in6_addr gateway;
- guint metric;
- guint mss;
} NMPlatformIP6Route;
typedef struct {
--
1.9.0
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]