summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-04-11 17:35:29 +0200
committerThomas Haller <thaller@redhat.com>2016-04-11 18:39:39 +0200
commit64acf8b059418948e0c19d83184ed310f84a62a7 (patch)
tree2641cdb24b392518b857f09c312f9b547568f59a
parentfd73668c839cb828191ca6e5d8e596e9a986b54f (diff)
downloadNetworkManager-64acf8b059418948e0c19d83184ed310f84a62a7.tar.gz
platform: extend NMIPConfigSource to preserve the rtm_protocol field
For addresses (NMPlatformIPAddress) the @addr_source field is ignored on a platform level. That is, all addresses inside the platform cache have this value set to NM_IP_CONFIG_SOURCE_KERNEL. Maybe, for that reason, the source should not be a part of the NMPlatformIPAddress structure, but it is convenient for users to piggy back the source inside the platform address structure. For routes, the source is stored in NMPlatformIPRoute's @rt_source field. When adding a route to kernel, we set the @rtm_protocol of the route depending on the source. However, we want to map different source values to the same protocol value. On the other hand, when kernel sends us a route that gets put inside the cache, we must preserve the protocol value and must not map different protocol values to the same source. The reason is, that a user can add two routes that only differ by @rtm_protocol. In that sense, the @rtm_protocol fields is part of the unique ID of a kernel route, and thus different values must map to different sources. Fix this, by extending the range of NMIPConfigSource to contain a range of protocol fields.
-rw-r--r--src/nm-types.h22
-rw-r--r--src/platform/nm-fake-platform.c5
-rw-r--r--src/platform/nm-linux-platform.c2
-rw-r--r--src/platform/nm-platform-utils.c123
-rw-r--r--src/platform/nm-platform-utils.h8
-rw-r--r--src/platform/nm-platform.h6
-rw-r--r--src/platform/tests/test-route.c16
-rw-r--r--src/tests/Makefile.am2
-rw-r--r--src/tests/test-route-manager.c101
9 files changed, 195 insertions, 90 deletions
diff --git a/src/nm-types.h b/src/nm-types.h
index db0b944e06..fa70372c43 100644
--- a/src/nm-types.h
+++ b/src/nm-types.h
@@ -54,10 +54,20 @@ typedef struct _NMLldpListener NMLldpListener;
typedef enum {
/* In priority order; higher number == higher priority */
- NM_IP_CONFIG_SOURCE_UNKNOWN,
- /* routes from platform with protocol RTPROT_KERNEL. */
- NM_IP_CONFIG_SOURCE_RTPROT_KERNEL,
+ NM_IP_CONFIG_SOURCE_UNKNOWN = 0,
+
+ /* for routes, the source is mapped to the uint8 field rtm_protocol.
+ * Reserve the range [1,0x100] for native RTPROT values. */
+
+ NM_IP_CONFIG_SOURCE_RTPROT_UNSPEC = 1 + 0,
+ NM_IP_CONFIG_SOURCE_RTPROT_REDIRECT = 1 + 1,
+ NM_IP_CONFIG_SOURCE_RTPROT_KERNEL = 1 + 2,
+ NM_IP_CONFIG_SOURCE_RTPROT_BOOT = 1 + 3,
+ NM_IP_CONFIG_SOURCE_RTPROT_STATIC = 1 + 4,
+ NM_IP_CONFIG_SOURCE_RTPROT_RA = 1 + 9,
+ NM_IP_CONFIG_SOURCE_RTPROT_DHCP = 1 + 16,
+ _NM_IP_CONFIG_SOURCE_RTPROT_LAST = 1 + 0xFF,
NM_IP_CONFIG_SOURCE_KERNEL,
NM_IP_CONFIG_SOURCE_SHARED,
@@ -70,6 +80,12 @@ typedef enum {
NM_IP_CONFIG_SOURCE_USER,
} NMIPConfigSource;
+inline static gboolean
+NM_IS_IP_CONFIG_SOURCE_RTPROT (NMIPConfigSource source)
+{
+ return source > NM_IP_CONFIG_SOURCE_UNKNOWN && source <= _NM_IP_CONFIG_SOURCE_RTPROT_LAST;
+}
+
/* platform */
typedef struct _NMPlatform NMPlatform;
typedef struct _NMPlatformIP4Address NMPlatformIP4Address;
diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c
index cbe8ed4996..39b5f3c080 100644
--- a/src/platform/nm-fake-platform.c
+++ b/src/platform/nm-fake-platform.c
@@ -31,6 +31,7 @@
#include "nm-utils.h"
#include "nm-core-utils.h"
+#include "nm-platform-utils.h"
#include "nmp-object.h"
#include "nm-test-utils.h"
@@ -1195,7 +1196,7 @@ ip4_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
memset (&route, 0, sizeof (route));
route.ifindex = ifindex;
- route.rt_source = source;
+ route.rt_source = nmp_utils_ip_config_source_round_trip_rtprot (source);
route.network = nm_utils_ip4_address_clear_host_address (network, plen);
route.plen = plen;
route.gateway = gateway;
@@ -1260,7 +1261,7 @@ ip6_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
memset (&route, 0, sizeof (route));
route.ifindex = ifindex;
- route.rt_source = source;
+ route.rt_source = nmp_utils_ip_config_source_round_trip_rtprot (source);
nm_utils_ip6_address_clear_host_address (&route.network, &network, plen);
route.plen = plen;
route.gateway = gateway;
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index 4554de66a2..11c2e965b2 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -2246,7 +2246,7 @@ _nl_msg_new_route (int nlmsg_type,
.rtm_family = family,
.rtm_tos = 0,
.rtm_table = RT_TABLE_MAIN, /* omit setting RTA_TABLE attribute */
- .rtm_protocol = nmp_utils_ip_config_source_to_rtprot (source),
+ .rtm_protocol = nmp_utils_ip_config_source_coerce_to_rtprot (source),
.rtm_scope = scope,
.rtm_type = RTN_UNICAST,
.rtm_flags = 0,
diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c
index 36fe699389..7fb4b95553 100644
--- a/src/platform/nm-platform-utils.c
+++ b/src/platform/nm-platform-utils.c
@@ -433,14 +433,38 @@ nmp_utils_device_exists (const char *name)
return g_file_test (sysdir, G_FILE_TEST_EXISTS);
}
-guint
-nmp_utils_ip_config_source_to_rtprot (NMIPConfigSource source)
+NMIPConfigSource
+nmp_utils_ip_config_source_from_rtprot (guint8 rtprot)
{
- switch (source) {
- case NM_IP_CONFIG_SOURCE_UNKNOWN:
+ return ((int) rtprot) + 1;
+}
+
+NMIPConfigSource
+nmp_utils_ip_config_source_round_trip_rtprot (NMIPConfigSource source)
+{
+ /* when adding a route to kernel for a give @source, the resulting route
+ * will be put into the cache with a source of NM_IP_CONFIG_SOURCE_RTPROT_*.
+ * This function returns that. */
+ return nmp_utils_ip_config_source_from_rtprot (nmp_utils_ip_config_source_coerce_to_rtprot (source));
+}
+
+guint8
+nmp_utils_ip_config_source_coerce_to_rtprot (NMIPConfigSource source)
+{
+ /* when adding a route to kernel, we coerce the @source field
+ * to rtm_protocol. This is not lossless as we map different
+ * source values to the same RTPROT uint8 value. */
+ if (source <= NM_IP_CONFIG_SOURCE_UNKNOWN)
return RTPROT_UNSPEC;
+
+ if (source <= _NM_IP_CONFIG_SOURCE_RTPROT_LAST) {
+ nm_assert (NM_IS_IP_CONFIG_SOURCE_RTPROT (source));
+ return source - 1;
+ } else
+ nm_assert (!NM_IS_IP_CONFIG_SOURCE_RTPROT (source));
+
+ switch (source) {
case NM_IP_CONFIG_SOURCE_KERNEL:
- case NM_IP_CONFIG_SOURCE_RTPROT_KERNEL:
return RTPROT_KERNEL;
case NM_IP_CONFIG_SOURCE_DHCP:
return RTPROT_DHCP;
@@ -453,18 +477,32 @@ nmp_utils_ip_config_source_to_rtprot (NMIPConfigSource source)
}
NMIPConfigSource
-nmp_utils_ip_config_source_from_rtprot (guint rtprot)
+nmp_utils_ip_config_source_coerce_from_rtprot (NMIPConfigSource source)
{
- switch (rtprot) {
- case RTPROT_UNSPEC:
+ /* When we receive a route from kernel and put it into the platform cache,
+ * we preserve the protocol field by converting it to a NMIPConfigSource
+ * via nmp_utils_ip_config_source_from_rtprot().
+ *
+ * However, that is not the inverse of nmp_utils_ip_config_source_coerce_to_rtprot().
+ * Instead, to go back to the original value, you need another step:
+ * nmp_utils_ip_config_source_coerce_from_rtprot (nmp_utils_ip_config_source_from_rtprot (rtprot)).
+ *
+ * This might partly restore the original source value, but of course that
+ * is not really possible because nmp_utils_ip_config_source_coerce_to_rtprot()
+ * is not injective.
+ * */
+ switch (source) {
+ case NM_IP_CONFIG_SOURCE_RTPROT_UNSPEC:
return NM_IP_CONFIG_SOURCE_UNKNOWN;
- case RTPROT_KERNEL:
- return NM_IP_CONFIG_SOURCE_RTPROT_KERNEL;
- case RTPROT_REDIRECT:
+
+ case NM_IP_CONFIG_SOURCE_RTPROT_KERNEL:
+ case NM_IP_CONFIG_SOURCE_RTPROT_REDIRECT:
return NM_IP_CONFIG_SOURCE_KERNEL;
- case RTPROT_RA:
+
+ case NM_IP_CONFIG_SOURCE_RTPROT_RA:
return NM_IP_CONFIG_SOURCE_RDISC;
- case RTPROT_DHCP:
+
+ case NM_IP_CONFIG_SOURCE_RTPROT_DHCP:
return NM_IP_CONFIG_SOURCE_DHCP;
default:
@@ -472,17 +510,50 @@ nmp_utils_ip_config_source_from_rtprot (guint rtprot)
}
}
-NM_UTILS_ENUM2STR_DEFINE (nmp_utils_ip_config_source_to_string, NMIPConfigSource,
- NM_UTILS_ENUM2STR (NM_IP_CONFIG_SOURCE_UNKNOWN, "unknown"),
- NM_UTILS_ENUM2STR (NM_IP_CONFIG_SOURCE_RTPROT_KERNEL, "rtprot-kernel"),
- NM_UTILS_ENUM2STR (NM_IP_CONFIG_SOURCE_KERNEL, "kernel"),
- NM_UTILS_ENUM2STR (NM_IP_CONFIG_SOURCE_SHARED, "shared"),
- NM_UTILS_ENUM2STR (NM_IP_CONFIG_SOURCE_IP4LL, "ipv4ll"),
- NM_UTILS_ENUM2STR (NM_IP_CONFIG_SOURCE_PPP, "ppp"),
- NM_UTILS_ENUM2STR (NM_IP_CONFIG_SOURCE_WWAN, "wwan"),
- NM_UTILS_ENUM2STR (NM_IP_CONFIG_SOURCE_VPN, "vpn"),
- NM_UTILS_ENUM2STR (NM_IP_CONFIG_SOURCE_DHCP, "dhcp"),
- NM_UTILS_ENUM2STR (NM_IP_CONFIG_SOURCE_RDISC, "rdisc"),
- NM_UTILS_ENUM2STR (NM_IP_CONFIG_SOURCE_USER, "user"),
-);
+const char *
+nmp_utils_ip_config_source_to_string (NMIPConfigSource source, char *buf, gsize len)
+{
+ const char *s = NULL;
+ nm_utils_to_string_buffer_init (&buf, &len); \
+
+ if (!len)
+ return buf;
+
+ switch (source) {
+ case NM_IP_CONFIG_SOURCE_UNKNOWN: s = "unknown"; break;
+
+ case NM_IP_CONFIG_SOURCE_RTPROT_UNSPEC: s = "rt-unspec"; break;
+ case NM_IP_CONFIG_SOURCE_RTPROT_REDIRECT: s = "rt-redirect"; break;
+ case NM_IP_CONFIG_SOURCE_RTPROT_KERNEL: s = "rt-kernel"; break;
+ case NM_IP_CONFIG_SOURCE_RTPROT_BOOT: s = "rt-boot"; break;
+ case NM_IP_CONFIG_SOURCE_RTPROT_STATIC: s = "rt-static"; break;
+ case NM_IP_CONFIG_SOURCE_RTPROT_DHCP: s = "rt-dhcp"; break;
+ case NM_IP_CONFIG_SOURCE_RTPROT_RA: s = "rt-ra"; break;
+
+ case NM_IP_CONFIG_SOURCE_KERNEL: s = "kernel"; break;
+ case NM_IP_CONFIG_SOURCE_SHARED: s = "shared"; break;
+ case NM_IP_CONFIG_SOURCE_IP4LL: s = "ipv4ll"; break;
+ case NM_IP_CONFIG_SOURCE_PPP: s = "ppp"; break;
+ case NM_IP_CONFIG_SOURCE_WWAN: s = "wwan"; break;
+ case NM_IP_CONFIG_SOURCE_VPN: s = "vpn"; break;
+ case NM_IP_CONFIG_SOURCE_DHCP: s = "dhcp"; break;
+ case NM_IP_CONFIG_SOURCE_RDISC: s = "rdisc"; break;
+ case NM_IP_CONFIG_SOURCE_USER: s = "user"; break;
+ default:
+ break;
+ }
+
+ if (source >= 1 && source <= 0x100) {
+ if (s)
+ g_snprintf (buf, len, "%s", s);
+ else
+ g_snprintf (buf, len, "rt-%d", ((int) source) - 1);
+ } else {
+ if (s)
+ g_strlcpy (buf, s, len);
+ else
+ g_snprintf (buf, len, "(%d)", source);
+ }
+ return buf;
+}
diff --git a/src/platform/nm-platform-utils.h b/src/platform/nm-platform-utils.h
index 5b1fc0e8dc..df7abcef89 100644
--- a/src/platform/nm-platform-utils.h
+++ b/src/platform/nm-platform-utils.h
@@ -54,8 +54,10 @@ const char *nmp_utils_udev_get_driver (GUdevDevice *device);
gboolean nmp_utils_device_exists (const char *name);
-guint nmp_utils_ip_config_source_to_rtprot (NMIPConfigSource source);
-NMIPConfigSource nmp_utils_ip_config_source_from_rtprot (guint rtprot);
-const char * nmp_utils_ip_config_source_to_string (NMIPConfigSource source, char *buf, gsize len);
+NMIPConfigSource nmp_utils_ip_config_source_from_rtprot (guint8 rtprot);
+guint8 nmp_utils_ip_config_source_coerce_to_rtprot (NMIPConfigSource source);
+NMIPConfigSource nmp_utils_ip_config_source_coerce_from_rtprot (NMIPConfigSource source);
+NMIPConfigSource nmp_utils_ip_config_source_round_trip_rtprot (NMIPConfigSource source);
+const char * nmp_utils_ip_config_source_to_string (NMIPConfigSource source, char *buf, gsize len);
#endif /* __NM_PLATFORM_UTILS_H__ */
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index 39cfc31ccc..2c1823c21d 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -303,7 +303,13 @@ typedef union {
#define __NMPlatformIPRoute_COMMON \
__NMPlatformObject_COMMON; \
+ \
+ /* The NMIPConfigSource. For routes that we receive from cache this corresponds
+ * to the rtm_protocol field (and is one of the NM_IP_CONFIG_SOURCE_RTPROT_* values).
+ * When adding a route, the source will be coerced to the protocol using
+ * nmp_utils_ip_config_source_coerce_to_rtprot(). */ \
NMIPConfigSource rt_source; \
+ \
guint8 plen; \
\
/* the route has rtm_flags set to RTM_F_CLONED. Such a route
diff --git a/src/platform/tests/test-route.c b/src/platform/tests/test-route.c
index c78b24c771..360404e944 100644
--- a/src/platform/tests/test-route.c
+++ b/src/platform/tests/test-route.c
@@ -23,9 +23,9 @@
#include <linux/rtnetlink.h>
#include "nm-core-utils.h"
-#include "test-common.h"
+#include "nm-platform-utils.h"
-#include "nm-test-utils.h"
+#include "test-common.h"
#define DEVICE_NAME "nm-test-device"
@@ -178,7 +178,7 @@ test_ip4_route (void)
/* Test route listing */
routes = nm_platform_ip4_route_get_all (NM_PLATFORM_GET, ifindex, NM_PLATFORM_GET_ROUTE_FLAGS_WITH_DEFAULT | NM_PLATFORM_GET_ROUTE_FLAGS_WITH_NON_DEFAULT);
memset (rts, 0, sizeof (rts));
- rts[0].rt_source = NM_IP_CONFIG_SOURCE_USER;
+ rts[0].rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER);
rts[0].network = gateway;
rts[0].plen = 32;
rts[0].ifindex = ifindex;
@@ -186,7 +186,7 @@ test_ip4_route (void)
rts[0].metric = metric;
rts[0].mss = mss;
rts[0].scope_inv = nm_platform_route_scope_inv (RT_SCOPE_LINK);
- rts[1].rt_source = NM_IP_CONFIG_SOURCE_USER;
+ rts[1].rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER);
rts[1].network = network;
rts[1].plen = plen;
rts[1].ifindex = ifindex;
@@ -194,7 +194,7 @@ test_ip4_route (void)
rts[1].metric = metric;
rts[1].mss = mss;
rts[1].scope_inv = nm_platform_route_scope_inv (RT_SCOPE_UNIVERSE);
- rts[2].rt_source = NM_IP_CONFIG_SOURCE_USER;
+ rts[2].rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER);
rts[2].network = 0;
rts[2].plen = 0;
rts[2].ifindex = ifindex;
@@ -265,21 +265,21 @@ test_ip6_route (void)
/* Test route listing */
routes = nm_platform_ip6_route_get_all (NM_PLATFORM_GET, ifindex, NM_PLATFORM_GET_ROUTE_FLAGS_WITH_DEFAULT | NM_PLATFORM_GET_ROUTE_FLAGS_WITH_NON_DEFAULT);
memset (rts, 0, sizeof (rts));
- rts[0].rt_source = NM_IP_CONFIG_SOURCE_USER;
+ rts[0].rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER);
rts[0].network = gateway;
rts[0].plen = 128;
rts[0].ifindex = ifindex;
rts[0].gateway = in6addr_any;
rts[0].metric = nm_utils_ip6_route_metric_normalize (metric);
rts[0].mss = mss;
- rts[1].rt_source = NM_IP_CONFIG_SOURCE_USER;
+ rts[1].rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER);
rts[1].network = network;
rts[1].plen = plen;
rts[1].ifindex = ifindex;
rts[1].gateway = gateway;
rts[1].metric = nm_utils_ip6_route_metric_normalize (metric);
rts[1].mss = mss;
- rts[2].rt_source = NM_IP_CONFIG_SOURCE_USER;
+ rts[2].rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER);
rts[2].network = in6addr_any;
rts[2].plen = 0;
rts[2].ifindex = ifindex;
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
index b93d4da3b9..0912c4ccd0 100644
--- a/src/tests/Makefile.am
+++ b/src/tests/Makefile.am
@@ -52,6 +52,7 @@ test_ip6_config_LDADD = \
test_route_manager_fake_CPPFLAGS = \
$(AM_CPPFLAGS) \
+ $(GUDEV_CFLAGS) \
-I$(top_srcdir)/src/platform/tests \
-DSETUP=nm_fake_platform_setup \
-DKERNEL_HACKS=0
@@ -69,6 +70,7 @@ test_route_manager_linux_SOURCES = \
test_route_manager_linux_CPPFLAGS = \
$(AM_CPPFLAGS) \
+ $(GUDEV_CFLAGS) \
-I$(top_srcdir)/src/platform/tests \
-DSETUP=nm_linux_platform_setup \
-DKERNEL_HACKS=1
diff --git a/src/tests/test-route-manager.c b/src/tests/test-route-manager.c
index 4335f8f46d..b81c263c08 100644
--- a/src/tests/test-route-manager.c
+++ b/src/tests/test-route-manager.c
@@ -23,12 +23,11 @@
#include <arpa/inet.h>
#include <linux/rtnetlink.h>
-#include "test-common.h"
-
#include "nm-platform.h"
+#include "nm-platform-utils.h"
#include "nm-route-manager.h"
-#include "nm-test-utils.h"
+#include "test-common.h"
typedef struct {
int ifindex0, ifindex1;
@@ -45,7 +44,7 @@ setup_dev0_ip4 (int ifindex, guint mss_of_first_route, guint32 metric_of_second_
route.ifindex = ifindex;
route.mss = 0;
- route.rt_source = NM_IP_CONFIG_SOURCE_USER;
+ route.rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER);
inet_pton (AF_INET, "6.6.6.0", &route.network);
route.plen = 24;
route.gateway = INADDR_ANY;
@@ -53,7 +52,7 @@ setup_dev0_ip4 (int ifindex, guint mss_of_first_route, guint32 metric_of_second_
route.mss = mss_of_first_route;
g_array_append_val (routes, route);
- route.rt_source = NM_IP_CONFIG_SOURCE_USER;
+ route.rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER);
inet_pton (AF_INET, "7.0.0.0", &route.network);
route.plen = 8;
inet_pton (AF_INET, "6.6.6.1", &route.gateway);
@@ -87,21 +86,21 @@ setup_dev1_ip4 (int ifindex)
route.mss))
g_assert_not_reached ();
- route.rt_source = NM_IP_CONFIG_SOURCE_USER;
+ route.rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER);
inet_pton (AF_INET, "6.6.6.0", &route.network);
route.plen = 24;
route.gateway = INADDR_ANY;
route.metric = 20;
g_array_append_val (routes, route);
- route.rt_source = NM_IP_CONFIG_SOURCE_USER;
+ route.rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER);
inet_pton (AF_INET, "7.0.0.0", &route.network);
route.plen = 8;
route.gateway = INADDR_ANY;
route.metric = 22;
g_array_append_val (routes, route);
- route.rt_source = NM_IP_CONFIG_SOURCE_USER;
+ route.rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER);
inet_pton (AF_INET, "8.0.0.0", &route.network);
route.plen = 8;
inet_pton (AF_INET, "6.6.6.2", &route.gateway);
@@ -121,14 +120,14 @@ update_dev0_ip4 (int ifindex)
route.ifindex = ifindex;
route.mss = 0;
- route.rt_source = NM_IP_CONFIG_SOURCE_USER;
+ route.rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER);
inet_pton (AF_INET, "6.6.6.0", &route.network);
route.plen = 24;
route.gateway = INADDR_ANY;
route.metric = 20;
g_array_append_val (routes, route);
- route.rt_source = NM_IP_CONFIG_SOURCE_USER;
+ route.rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER);
inet_pton (AF_INET, "7.0.0.0", &route.network);
route.plen = 8;
route.gateway = INADDR_ANY;
@@ -163,7 +162,7 @@ test_ip4 (test_fixture *fixture, gconstpointer user_data)
NMPlatformIP4Route state1[] = {
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = nmtst_inet4_from_string ("6.6.6.0"),
.plen = 24,
.ifindex = fixture->ifindex0,
@@ -173,7 +172,7 @@ test_ip4 (test_fixture *fixture, gconstpointer user_data)
.scope_inv = nm_platform_route_scope_inv (RT_SCOPE_LINK),
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = nmtst_inet4_from_string ("7.0.0.0"),
.plen = 8,
.ifindex = fixture->ifindex0,
@@ -183,7 +182,7 @@ test_ip4 (test_fixture *fixture, gconstpointer user_data)
.scope_inv = nm_platform_route_scope_inv (RT_SCOPE_UNIVERSE),
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = nmtst_inet4_from_string ("7.0.0.0"),
.plen = 8,
.ifindex = fixture->ifindex1,
@@ -193,7 +192,7 @@ test_ip4 (test_fixture *fixture, gconstpointer user_data)
.scope_inv = nm_platform_route_scope_inv (RT_SCOPE_LINK),
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = nmtst_inet4_from_string ("6.6.6.0"),
.plen = 24,
.ifindex = fixture->ifindex1,
@@ -203,7 +202,7 @@ test_ip4 (test_fixture *fixture, gconstpointer user_data)
.scope_inv = nm_platform_route_scope_inv (RT_SCOPE_LINK),
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = nmtst_inet4_from_string ("8.0.0.0"),
.plen = 8,
.ifindex = fixture->ifindex1,
@@ -216,7 +215,7 @@ test_ip4 (test_fixture *fixture, gconstpointer user_data)
NMPlatformIP4Route state2[] = {
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = nmtst_inet4_from_string ("6.6.6.0"),
.plen = 24,
.ifindex = fixture->ifindex0,
@@ -226,7 +225,7 @@ test_ip4 (test_fixture *fixture, gconstpointer user_data)
.scope_inv = nm_platform_route_scope_inv (RT_SCOPE_LINK),
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = nmtst_inet4_from_string ("7.0.0.0"),
.plen = 8,
.ifindex = fixture->ifindex0,
@@ -236,7 +235,7 @@ test_ip4 (test_fixture *fixture, gconstpointer user_data)
.scope_inv = nm_platform_route_scope_inv (RT_SCOPE_LINK),
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = nmtst_inet4_from_string ("7.0.0.0"),
.plen = 8,
.ifindex = fixture->ifindex1,
@@ -246,7 +245,7 @@ test_ip4 (test_fixture *fixture, gconstpointer user_data)
.scope_inv = nm_platform_route_scope_inv (RT_SCOPE_LINK),
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = nmtst_inet4_from_string ("6.6.6.0"),
.plen = 24,
.ifindex = fixture->ifindex1,
@@ -256,7 +255,7 @@ test_ip4 (test_fixture *fixture, gconstpointer user_data)
.scope_inv = nm_platform_route_scope_inv (RT_SCOPE_LINK),
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = nmtst_inet4_from_string ("8.0.0.0"),
.plen = 8,
.ifindex = fixture->ifindex1,
@@ -269,7 +268,7 @@ test_ip4 (test_fixture *fixture, gconstpointer user_data)
NMPlatformIP4Route state3[] = {
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = nmtst_inet4_from_string ("7.0.0.0"),
.plen = 8,
.ifindex = fixture->ifindex1,
@@ -279,7 +278,7 @@ test_ip4 (test_fixture *fixture, gconstpointer user_data)
.scope_inv = nm_platform_route_scope_inv (RT_SCOPE_LINK),
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = nmtst_inet4_from_string ("6.6.6.0"),
.plen = 24,
.ifindex = fixture->ifindex1,
@@ -289,7 +288,7 @@ test_ip4 (test_fixture *fixture, gconstpointer user_data)
.scope_inv = nm_platform_route_scope_inv (RT_SCOPE_LINK),
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = nmtst_inet4_from_string ("8.0.0.0"),
.plen = 8,
.ifindex = fixture->ifindex1,
@@ -299,7 +298,7 @@ test_ip4 (test_fixture *fixture, gconstpointer user_data)
.scope_inv = nm_platform_route_scope_inv (RT_SCOPE_UNIVERSE),
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = nmtst_inet4_from_string ("6.6.6.0"),
.plen = 24,
.ifindex = fixture->ifindex1,
@@ -542,7 +541,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data)
NMPlatformIP6Route state1[] = {
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = *nmtst_inet6_from_string ("2001:db8:8086::"),
.plen = 48,
.ifindex = fixture->ifindex0,
@@ -551,7 +550,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data)
.mss = 0,
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = *nmtst_inet6_from_string ("2001:db8:1337::"),
.plen = 48,
.ifindex = fixture->ifindex0,
@@ -560,7 +559,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data)
.mss = 0,
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = *nmtst_inet6_from_string ("2001:db8:abad:c0de::"),
.plen = 64,
.ifindex = fixture->ifindex0,
@@ -569,7 +568,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data)
.mss = 0,
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = *nmtst_inet6_from_string ("2001:db8:abad:c0de::"),
.plen = 64,
.ifindex = fixture->ifindex1,
@@ -578,7 +577,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data)
.mss = 0,
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = *nmtst_inet6_from_string ("2001:db8:1337::"),
.plen = 48,
.ifindex = fixture->ifindex1,
@@ -587,7 +586,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data)
.mss = 0,
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = *nmtst_inet6_from_string ("2001:db8:8086::"),
.plen = 48,
.ifindex = fixture->ifindex1,
@@ -596,7 +595,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data)
.mss = 0,
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = *nmtst_inet6_from_string ("2001:db8:d34d::"),
.plen = 64,
.ifindex = fixture->ifindex1,
@@ -608,7 +607,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data)
NMPlatformIP6Route state2[] = {
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = *nmtst_inet6_from_string ("2001:db8:8086::"),
.plen = 48,
.ifindex = fixture->ifindex0,
@@ -617,7 +616,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data)
.mss = 0,
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = *nmtst_inet6_from_string ("2001:db8:1337::"),
.plen = 48,
.ifindex = fixture->ifindex0,
@@ -626,7 +625,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data)
.mss = 0,
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = *nmtst_inet6_from_string ("2001:db8:abad:c0de::"),
.plen = 64,
.ifindex = fixture->ifindex0,
@@ -635,7 +634,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data)
.mss = 0,
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = *nmtst_inet6_from_string ("2001:db8:abad:c0de::"),
.plen = 64,
.ifindex = fixture->ifindex1,
@@ -644,7 +643,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data)
.mss = 0,
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = *nmtst_inet6_from_string ("2001:db8:1337::"),
.plen = 48,
.ifindex = fixture->ifindex1,
@@ -653,7 +652,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data)
.mss = 0,
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = *nmtst_inet6_from_string ("2001:db8:8086::"),
.plen = 48,
.ifindex = fixture->ifindex1,
@@ -662,7 +661,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data)
.mss = 0,
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = *nmtst_inet6_from_string ("2001:db8:d34d::"),
.plen = 64,
.ifindex = fixture->ifindex1,
@@ -674,7 +673,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data)
NMPlatformIP6Route state3[] = {
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = *nmtst_inet6_from_string ("2001:db8:abad:c0de::"),
.plen = 64,
.ifindex = fixture->ifindex1,
@@ -683,7 +682,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data)
.mss = 0,
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = *nmtst_inet6_from_string ("2001:db8:8086::"),
.plen = 48,
.ifindex = fixture->ifindex1,
@@ -692,7 +691,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data)
.mss = 0,
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = *nmtst_inet6_from_string ("2001:db8:1337::"),
.plen = 48,
.ifindex = fixture->ifindex1,
@@ -701,7 +700,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data)
.mss = 0,
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = *nmtst_inet6_from_string ("2001:db8:1337::"),
.plen = 48,
.ifindex = fixture->ifindex1,
@@ -710,7 +709,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data)
.mss = 0,
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = *nmtst_inet6_from_string ("2001:db8:8086::"),
.plen = 48,
.ifindex = fixture->ifindex1,
@@ -719,7 +718,7 @@ test_ip6 (test_fixture *fixture, gconstpointer user_data)
.mss = 0,
},
{
- .rt_source = NM_IP_CONFIG_SOURCE_USER,
+ .rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER),
.network = *nmtst_inet6_from_string ("2001:db8:d34d::"),
.plen = 64,
.ifindex = fixture->ifindex1,
@@ -787,6 +786,7 @@ static void
_assert_route_check (const NMPlatformVTableRoute *vtable, gboolean has, const NMPlatformIPXRoute *route)
{
const NMPlatformIPXRoute *r;
+ NMPlatformIPXRoute c;
g_assert (route);
@@ -800,11 +800,18 @@ _assert_route_check (const NMPlatformVTableRoute *vtable, gboolean has, const NM
} else {
char buf[sizeof (_nm_utils_to_string_buffer)];
- if (!r || vtable->route_cmp (route, r) != 0)
+ if (r) {
+ if (vtable->is_ip4)
+ c.r4 = route->r4;
+ else
+ c.r6 = route->r6;
+ c.rx.rt_source = nmp_utils_ip_config_source_round_trip_rtprot (c.rx.rt_source);
+ }
+ if (!r || vtable->route_cmp (r, &c) != 0) {
g_error ("Invalid route. Expect %s, has %s",
- vtable->route_to_string (route, NULL, 0),
+ vtable->route_to_string (&c, NULL, 0),
vtable->route_to_string (r, buf, sizeof (buf)));
- g_assert (r);
+ }
}
}