summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-04-06 15:33:53 +0200
committerThomas Haller <thaller@redhat.com>2016-04-11 11:26:32 +0200
commit2e6ec6d8ac8a4ec0ee51a03b8bd1118a72f0f59b (patch)
treef2de9a1a93de6bc347db58fc8f7470edbba51179 /shared
parent0e78ce5ed6ef20fc54623d601cc3d0c3fea67d05 (diff)
downloadNetworkManager-2e6ec6d8ac8a4ec0ee51a03b8bd1118a72f0f59b.tar.gz
nmtst: add nmtst_platform_ip4_address() util
Diffstat (limited to 'shared')
-rw-r--r--shared/nm-test-utils.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/shared/nm-test-utils.h b/shared/nm-test-utils.h
index 8e21186dda..b792a69c85 100644
--- a/shared/nm-test-utils.h
+++ b/shared/nm-test-utils.h
@@ -1179,11 +1179,54 @@ _nmtst_assert_resolve_relative_path_equals (const char *f1, const char *f2, cons
#ifdef __NETWORKMANAGER_PLATFORM_H__
+inline static NMPlatformIP4Address *
+nmtst_platform_ip4_address (const char *address, const char *peer_address, guint plen)
+{
+ static NMPlatformIP4Address addr;
+
+ g_assert (plen <= 32);
+
+ memset (&addr, 0, sizeof (addr));
+ addr.address = nmtst_inet4_from_string (address);
+ if (peer_address)
+ addr.peer_address = nmtst_inet4_from_string (peer_address);
+ else
+ addr.peer_address = addr.address;
+ addr.plen = plen;
+
+ return &addr;
+}
+
+inline static NMPlatformIP4Address *
+nmtst_platform_ip4_address_full (const char *address, const char *peer_address, guint plen,
+ int ifindex, NMIPConfigSource source, guint32 timestamp,
+ guint32 lifetime, guint32 preferred, guint32 flags,
+ const char *label)
+{
+ NMPlatformIP4Address *addr = nmtst_platform_ip4_address (address, peer_address, plen);
+
+ G_STATIC_ASSERT (IFNAMSIZ == sizeof (addr->label));
+ g_assert (!label || strlen (label) < IFNAMSIZ);
+
+ addr->ifindex = ifindex;
+ addr->source = source;
+ addr->timestamp = timestamp;
+ addr->lifetime = lifetime;
+ addr->preferred = preferred;
+ addr->n_ifa_flags = flags;
+ if (label)
+ g_strlcpy (addr->label, label, sizeof (addr->label));
+
+ return addr;
+}
+
inline static NMPlatformIP6Address *
nmtst_platform_ip6_address (const char *address, const char *peer_address, guint plen)
{
static NMPlatformIP6Address addr;
+ g_assert (plen <= 128);
+
memset (&addr, 0, sizeof (addr));
addr.address = *nmtst_inet6_from_string (address);
addr.peer_address = *nmtst_inet6_from_string (peer_address);
@@ -1214,6 +1257,8 @@ nmtst_platform_ip4_route (const char *network, guint plen, const char *gateway)
{
static NMPlatformIP4Route route;
+ g_assert (plen <= 32);
+
memset (&route, 0, sizeof (route));
route.network = nmtst_inet4_from_string (network);
route.plen = plen;
@@ -1246,6 +1291,8 @@ nmtst_platform_ip6_route (const char *network, guint plen, const char *gateway)
{
static NMPlatformIP6Route route;
+ nm_assert (plen <= 128);
+
memset (&route, 0, sizeof (route));
route.network = *nmtst_inet6_from_string (network);
route.plen = plen;