platform: add function nm_platform_link_cmp()

Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
Thomas Haller
2014-04-05 18:35:20 +02:00
parent 78b8af6651
commit 59a56a0aff
3 changed files with 27 additions and 0 deletions

View File

@@ -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), \
@@ -2279,6 +2286,24 @@ nm_platform_ip6_route_to_string (const NMPlatformIP6Route *route)
return c < 0 ? -1 : 1; \
} 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)
{

View File

@@ -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);

View File

@@ -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.");