summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-04-05 18:35:20 +0200
committerThomas Haller <thaller@redhat.com>2014-05-03 03:44:23 +0200
commit59a56a0aff33adf5ec5cea7c46cfd01e7637ff6a (patch)
tree0986bb881413d2bce7083ba64762ec3555040530
parent78b8af6651ddbaca4633b3a275df5c5c13f89695 (diff)
downloadNetworkManager-59a56a0aff33adf5ec5cea7c46cfd01e7637ff6a.tar.gz
platform: add function nm_platform_link_cmp()
Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r--src/platform/nm-platform.c25
-rw-r--r--src/platform/nm-platform.h1
-rw-r--r--src/platform/tests/test-common.c1
3 files changed, 27 insertions, 0 deletions
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index 083359eec6..64802212ec 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -2271,6 +2271,13 @@ nm_platform_ip6_route_to_string (const NMPlatformIP6Route *route)
return c < 0 ? -1 : 1; \
} G_STMT_END
+#define _CMP_FIELD_STR0(a, b, field) \
+ G_STMT_START { \
+ int c = g_strcmp0 ((a)->field, (b)->field); \
+ if (c != 0) \
+ return c < 0 ? -1 : 1; \
+ } G_STMT_END
+
#define _CMP_FIELD_MEMCMP(a, b, field) \
G_STMT_START { \
int c = memcmp (&((a)->field), &((b)->field), \
@@ -2280,6 +2287,24 @@ nm_platform_ip6_route_to_string (const NMPlatformIP6Route *route)
} G_STMT_END
int
+nm_platform_link_cmp (const NMPlatformLink *a, const NMPlatformLink *b)
+{
+ _CMP_POINTER (a, b);
+ _CMP_FIELD (a, b, type);
+ _CMP_FIELD_STR (a, b, name);
+ _CMP_FIELD (a, b, master);
+ _CMP_FIELD (a, b, parent);
+ _CMP_FIELD (a, b, up);
+ _CMP_FIELD (a, b, connected);
+ _CMP_FIELD (a, b, arp);
+ _CMP_FIELD (a, b, mtu);
+ _CMP_FIELD_STR0 (a, b, type_name);
+ _CMP_FIELD_STR0 (a, b, udi);
+ _CMP_FIELD_STR0 (a, b, driver);
+ return 0;
+}
+
+int
nm_platform_ip4_address_cmp (const NMPlatformIP4Address *a, const NMPlatformIP4Address *b)
{
_CMP_POINTER (a, b);
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index b07d74ee51..28800f895e 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -586,6 +586,7 @@ const char *nm_platform_ip6_address_to_string (const NMPlatformIP6Address *addre
const char *nm_platform_ip4_route_to_string (const NMPlatformIP4Route *route);
const char *nm_platform_ip6_route_to_string (const NMPlatformIP6Route *route);
+int nm_platform_link_cmp (const NMPlatformLink *a, const NMPlatformLink *b);
int nm_platform_ip4_address_cmp (const NMPlatformIP4Address *a, const NMPlatformIP4Address *b);
int nm_platform_ip6_address_cmp (const NMPlatformIP6Address *a, const NMPlatformIP6Address *b);
int nm_platform_ip4_route_cmp (const NMPlatformIP4Route *a, const NMPlatformIP4Route *b);
diff --git a/src/platform/tests/test-common.c b/src/platform/tests/test-common.c
index b556782514..fc5bfaf23a 100644
--- a/src/platform/tests/test-common.c
+++ b/src/platform/tests/test-common.c
@@ -101,6 +101,7 @@ link_callback (NMPlatform *platform, int ifindex, NMPlatformLink *received, NMPl
for (i = 0; i < links->len; i++) {
cached = &g_array_index (links, NMPlatformLink, i);
if (cached->ifindex == received->ifindex) {
+ g_assert_cmpint (nm_platform_link_cmp (cached, received), ==, 0);
g_assert (!memcmp (cached, received, sizeof (*cached)));
if (data->change_type == NM_PLATFORM_SIGNAL_REMOVED)
g_error ("Deleted link still found in the local cache.");