summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nm-default-route-manager.c1
-rw-r--r--src/nm-test-utils-core.h5
-rw-r--r--src/platform/nm-fake-platform.c3
-rw-r--r--src/platform/nm-linux-platform.c10
-rw-r--r--src/platform/nm-platform.c23
-rw-r--r--src/platform/nm-platform.h5
-rw-r--r--src/platform/tests/test-cleanup.c6
-rw-r--r--src/platform/tests/test-route.c20
-rw-r--r--src/tests/test-ip6-config.c10
-rw-r--r--src/tests/test-route-manager.c1
10 files changed, 55 insertions, 29 deletions
diff --git a/src/nm-default-route-manager.c b/src/nm-default-route-manager.c
index 5944654cff..428c343673 100644
--- a/src/nm-default-route-manager.c
+++ b/src/nm-default-route-manager.c
@@ -317,6 +317,7 @@ _platform_route_sync_add (const VTableIP *vtable, NMDefaultRouteManager *self, g
in6addr_any,
0,
entry->route.r6.gateway,
+ entry->route.r6.pref_src,
entry->effective_metric,
entry->route.rx.mss);
}
diff --git a/src/nm-test-utils-core.h b/src/nm-test-utils-core.h
index 546e2361f2..7cd08ce57a 100644
--- a/src/nm-test-utils-core.h
+++ b/src/nm-test-utils-core.h
@@ -162,7 +162,7 @@ nmtst_platform_ip4_route_full (const char *network, guint plen, const char *gate
}
static inline NMPlatformIP6Route *
-nmtst_platform_ip6_route (const char *network, guint plen, const char *gateway)
+nmtst_platform_ip6_route (const char *network, guint plen, const char *gateway, const char *pref_src)
{
static NMPlatformIP6Route route;
@@ -172,6 +172,7 @@ nmtst_platform_ip6_route (const char *network, guint plen, const char *gateway)
route.network = *nmtst_inet6_from_string (network);
route.plen = plen;
route.gateway = *nmtst_inet6_from_string (gateway);
+ route.pref_src = *nmtst_inet6_from_string (pref_src);
return &route;
}
@@ -181,7 +182,7 @@ nmtst_platform_ip6_route_full (const char *network, guint plen, const char *gate
int ifindex, NMIPConfigSource source,
guint metric, guint mss)
{
- NMPlatformIP6Route *route = nmtst_platform_ip6_route (network, plen, gateway);
+ NMPlatformIP6Route *route = nmtst_platform_ip6_route (network, plen, gateway, NULL);
route->ifindex = ifindex;
route->rt_source = source;
diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c
index b92f56ce21..447188e631 100644
--- a/src/platform/nm-fake-platform.c
+++ b/src/platform/nm-fake-platform.c
@@ -1295,7 +1295,7 @@ ip4_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
static gboolean
ip6_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
struct in6_addr network, guint8 plen, struct in6_addr gateway,
- guint32 metric, guint32 mss)
+ struct in6_addr pref_src, guint32 metric, guint32 mss)
{
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE ((NMFakePlatform *) platform);
NMPlatformIP6Route route;
@@ -1311,6 +1311,7 @@ ip6_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
route.gateway = gateway;
route.metric = metric;
route.mss = mss;
+ route.pref_src = pref_src;
if (!IN6_IS_ADDR_UNSPECIFIED(&gateway)) {
for (i = 0; i < priv->ip6_routes->len; i++) {
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index 3138b171bc..abc26e37f3 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -1980,9 +1980,11 @@ _new_from_nl_route (struct nlmsghdr *nlh, gboolean id_only)
if (is_v4)
obj->ip4_route.scope_inv = nm_platform_route_scope_inv (rtm->rtm_scope);
- if (is_v4) {
- if (_check_addr_or_errout (tb, RTA_PREFSRC, addr_len))
+ if (_check_addr_or_errout (tb, RTA_PREFSRC, addr_len)) {
+ if (is_v4)
memcpy (&obj->ip4_route.pref_src, nla_data (tb[RTA_PREFSRC]), addr_len);
+ else
+ memcpy (&obj->ip6_route.pref_src, nla_data (tb[RTA_PREFSRC]), addr_len);
}
obj->ip_route.mss = mss;
@@ -5929,7 +5931,7 @@ ip4_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
static gboolean
ip6_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
struct in6_addr network, guint8 plen, struct in6_addr gateway,
- guint32 metric, guint32 mss)
+ struct in6_addr pref_src, guint32 metric, guint32 mss)
{
NMPObject obj_id;
nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
@@ -5945,7 +5947,7 @@ ip6_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
&gateway,
metric,
mss,
- NULL);
+ !IN6_IS_ADDR_UNSPECIFIED (&pref_src) ? &pref_src : NULL);
nmp_object_stackinit_id_ip6_route (&obj_id, ifindex, &network, plen, metric);
return do_add_addrroute (platform, &obj_id, nlmsg);
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index b72534420e..713fccb32c 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -3168,7 +3168,7 @@ gboolean
nm_platform_ip6_route_add (NMPlatform *self,
int ifindex, NMIPConfigSource source,
struct in6_addr network, guint8 plen, struct in6_addr gateway,
- guint32 metric, guint32 mss)
+ struct in6_addr pref_src, guint32 metric, guint32 mss)
{
_CHECK_SELF (self, klass, FALSE);
@@ -3182,12 +3182,13 @@ nm_platform_ip6_route_add (NMPlatform *self,
route.network = network;
route.plen = plen;
route.gateway = gateway;
+ route.pref_src = pref_src;
route.metric = metric;
route.mss = mss;
_LOGD ("route: adding or updating IPv6 route: %s", nm_platform_ip6_route_to_string (&route, NULL, 0));
}
- return klass->ip6_route_add (self, ifindex, source, network, plen, gateway, metric, mss);
+ return klass->ip6_route_add (self, ifindex, source, network, plen, gateway, pref_src, metric, mss);
}
gboolean
@@ -3950,14 +3951,19 @@ nm_platform_ip4_route_to_string (const NMPlatformIP4Route *route, char *buf, gsi
const char *
nm_platform_ip6_route_to_string (const NMPlatformIP6Route *route, char *buf, gsize len)
{
- char s_network[INET6_ADDRSTRLEN], s_gateway[INET6_ADDRSTRLEN];
+ char s_network[INET6_ADDRSTRLEN], s_gateway[INET6_ADDRSTRLEN], s_pref_src[INET6_ADDRSTRLEN];
char str_dev[TO_STRING_DEV_BUF_SIZE], s_source[50];
if (!nm_utils_to_string_buffer_init_null (route, &buf, &len))
return buf;
- inet_ntop (AF_INET6, &route->network, s_network, sizeof(s_network));
- inet_ntop (AF_INET6, &route->gateway, s_gateway, sizeof(s_gateway));
+ inet_ntop (AF_INET6, &route->network, s_network, sizeof (s_network));
+ inet_ntop (AF_INET6, &route->gateway, s_gateway, sizeof (s_gateway));
+
+ if (IN6_IS_ADDR_UNSPECIFIED (&route->pref_src))
+ s_pref_src[0] = 0;
+ else
+ inet_ntop (AF_INET6, &route->pref_src, s_pref_src, sizeof (s_pref_src));
_to_string_dev (NULL, route->ifindex, str_dev, sizeof (str_dev));
@@ -3969,6 +3975,7 @@ nm_platform_ip6_route_to_string (const NMPlatformIP6Route *route, char *buf, gsi
" mss %"G_GUINT32_FORMAT
" src %s" /* source */
"%s" /* cloned */
+ "%s%s" /* pref-src */
"",
s_network,
route->plen,
@@ -3977,7 +3984,9 @@ nm_platform_ip6_route_to_string (const NMPlatformIP6Route *route, char *buf, gsi
route->metric,
route->mss,
nmp_utils_ip_config_source_to_string (route->rt_source, s_source, sizeof (s_source)),
- route->rt_cloned ? " cloned" : "");
+ route->rt_cloned ? " cloned" : "",
+ s_pref_src[0] ? " pref-src " : "",
+ s_pref_src[0] ? s_pref_src : "");
return buf;
}
@@ -4278,6 +4287,7 @@ nm_platform_ip6_route_cmp (const NMPlatformIP6Route *a, const NMPlatformIP6Route
_CMP_FIELD (a, b, plen);
_CMP_FIELD (a, b, metric);
_CMP_FIELD_MEMCMP (a, b, gateway);
+ _CMP_FIELD_MEMCMP (a, b, pref_src);
_CMP_FIELD (a, b, rt_source);
_CMP_FIELD (a, b, mss);
_CMP_FIELD (a, b, rt_cloned);
@@ -4431,6 +4441,7 @@ _vtr_v6_route_add (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *rout
route->r6.network,
route->rx.plen,
route->r6.gateway,
+ route->r6.pref_src,
metric >= 0 ? (guint32) metric : route->rx.metric,
route->rx.mss);
}
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index 63dbe5a07c..3cc96f3c05 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -358,6 +358,7 @@ struct _NMPlatformIP6Route {
__NMPlatformIPRoute_COMMON;
struct in6_addr network;
struct in6_addr gateway;
+ struct in6_addr pref_src;
};
typedef union {
@@ -672,7 +673,7 @@ typedef struct {
in_addr_t pref_src, guint32 metric, guint32 mss);
gboolean (*ip6_route_add) (NMPlatform *, int ifindex, NMIPConfigSource source,
struct in6_addr network, guint8 plen, struct in6_addr gateway,
- guint32 metric, guint32 mss);
+ struct in6_addr pref_src, guint32 metric, guint32 mss);
gboolean (*ip4_route_delete) (NMPlatform *, int ifindex, in_addr_t network, guint8 plen, guint32 metric);
gboolean (*ip6_route_delete) (NMPlatform *, int ifindex, struct in6_addr network, guint8 plen, guint32 metric);
const NMPlatformIP4Route *(*ip4_route_get) (NMPlatform *, int ifindex, in_addr_t network, guint8 plen, guint32 metric);
@@ -974,7 +975,7 @@ gboolean nm_platform_ip4_route_add (NMPlatform *self, int ifindex, NMIPConfigSou
in_addr_t pref_src, guint32 metric, guint32 mss);
gboolean nm_platform_ip6_route_add (NMPlatform *self, int ifindex, NMIPConfigSource source,
struct in6_addr network, guint8 plen, struct in6_addr gateway,
- guint32 metric, guint32 mss);
+ struct in6_addr pref_src, guint32 metric, guint32 mss);
gboolean nm_platform_ip4_route_delete (NMPlatform *self, int ifindex, in_addr_t network, guint8 plen, guint32 metric);
gboolean nm_platform_ip6_route_delete (NMPlatform *self, int ifindex, struct in6_addr network, guint8 plen, guint32 metric);
diff --git a/src/platform/tests/test-cleanup.c b/src/platform/tests/test-cleanup.c
index 4ac4929895..41f59d07aa 100644
--- a/src/platform/tests/test-cleanup.c
+++ b/src/platform/tests/test-cleanup.c
@@ -68,9 +68,9 @@ test_cleanup_internal (void)
g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, gateway4, 32, INADDR_ANY, 0, metric, mss));
g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network4, plen4, gateway4, 0, metric, mss));
g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, 0, 0, gateway4, 0, metric, mss));
- g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, gateway6, 128, in6addr_any, metric, mss));
- g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network6, plen6, gateway6, metric, mss));
- g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, in6addr_any, 0, gateway6, metric, mss));
+ g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, gateway6, 128, in6addr_any, in6addr_any, metric, mss));
+ g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network6, plen6, gateway6, in6addr_any, metric, mss));
+ g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, in6addr_any, 0, gateway6, in6addr_any, metric, mss));
addresses4 = nm_platform_ip4_address_get_all (NM_PLATFORM_GET, ifindex);
addresses6 = nm_platform_ip6_address_get_all (NM_PLATFORM_GET, ifindex);
diff --git a/src/platform/tests/test-route.c b/src/platform/tests/test-route.c
index 59a05bd492..df0e748a90 100644
--- a/src/platform/tests/test-route.c
+++ b/src/platform/tests/test-route.c
@@ -238,36 +238,41 @@ test_ip6_route (void)
NMPlatformIP6Route rts[3];
struct in6_addr network;
guint8 plen = 64;
- struct in6_addr gateway;
+ struct in6_addr gateway, pref_src;
/* Choose a high metric so that we hopefully don't conflict. */
int metric = 22987;
int mss = 1000;
inet_pton (AF_INET6, "2001:db8:a:b:0:0:0:0", &network);
inet_pton (AF_INET6, "2001:db8:c:d:1:2:3:4", &gateway);
+ inet_pton (AF_INET6, "::42", &pref_src);
+
+ g_assert (nm_platform_ip6_address_add (NM_PLATFORM_GET, ifindex, pref_src, 128, in6addr_any,
+ NM_PLATFORM_LIFETIME_PERMANENT, NM_PLATFORM_LIFETIME_PERMANENT, 0));
+ accept_signals (route_added, 0, 1);
/* Add route to gateway */
- g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, gateway, 128, in6addr_any, metric, mss));
+ g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, gateway, 128, in6addr_any, in6addr_any, metric, mss));
accept_signal (route_added);
/* Add route */
g_assert (!nm_platform_ip6_route_get (NM_PLATFORM_GET, ifindex, network, plen, metric));
- g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, metric, mss));
+ g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, pref_src, metric, mss));
g_assert (nm_platform_ip6_route_get (NM_PLATFORM_GET, ifindex, network, plen, metric));
accept_signal (route_added);
/* Add route again */
- g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, metric, mss));
+ g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, pref_src, metric, mss));
accept_signals (route_changed, 0, 1);
/* Add default route */
g_assert (!nm_platform_ip6_route_get (NM_PLATFORM_GET, ifindex, in6addr_any, 0, metric));
- g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, in6addr_any, 0, gateway, metric, mss));
+ g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, in6addr_any, 0, gateway, in6addr_any, metric, mss));
g_assert (nm_platform_ip6_route_get (NM_PLATFORM_GET, ifindex, in6addr_any, 0, metric));
accept_signal (route_added);
/* Add default route again */
- g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, in6addr_any, 0, gateway, metric, mss));
+ g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, in6addr_any, 0, gateway, in6addr_any, metric, mss));
accept_signals (route_changed, 0, 1);
/* Test route listing */
@@ -278,6 +283,7 @@ test_ip6_route (void)
rts[0].plen = 128;
rts[0].ifindex = ifindex;
rts[0].gateway = in6addr_any;
+ rts[0].pref_src = in6addr_any;
rts[0].metric = nm_utils_ip6_route_metric_normalize (metric);
rts[0].mss = mss;
rts[1].rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER);
@@ -285,6 +291,7 @@ test_ip6_route (void)
rts[1].plen = plen;
rts[1].ifindex = ifindex;
rts[1].gateway = gateway;
+ rts[1].pref_src = pref_src;
rts[1].metric = nm_utils_ip6_route_metric_normalize (metric);
rts[1].mss = mss;
rts[2].rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER);
@@ -292,6 +299,7 @@ test_ip6_route (void)
rts[2].plen = 0;
rts[2].ifindex = ifindex;
rts[2].gateway = gateway;
+ rts[2].pref_src = in6addr_any;
rts[2].metric = nm_utils_ip6_route_metric_normalize (metric);
rts[2].mss = mss;
g_assert_cmpint (routes->len, ==, 3);
diff --git a/src/tests/test-ip6-config.c b/src/tests/test-ip6-config.c
index 505f9a5d19..7e83625c5b 100644
--- a/src/tests/test-ip6-config.c
+++ b/src/tests/test-ip6-config.c
@@ -37,8 +37,8 @@ build_test_config (void)
config = nm_ip6_config_new (1);
nm_ip6_config_add_address (config, nmtst_platform_ip6_address ("abcd:1234:4321::cdde", "1:2:3:4::5", 64));
- nm_ip6_config_add_route (config, nmtst_platform_ip6_route ("abcd:1234:4321::", 24, "abcd:1234:4321:cdde::2"));
- nm_ip6_config_add_route (config, nmtst_platform_ip6_route ("2001:abba::", 16, "2001:abba::2234"));
+ nm_ip6_config_add_route (config, nmtst_platform_ip6_route ("abcd:1234:4321::", 24, "abcd:1234:4321:cdde::2", NULL));
+ nm_ip6_config_add_route (config, nmtst_platform_ip6_route ("2001:abba::", 16, "2001:abba::2234", NULL));
nm_ip6_config_set_gateway (config, nmtst_inet6_from_string ("3001:abba::3234"));
@@ -74,7 +74,7 @@ test_subtract (void)
/* add a couple more things to the test config */
dst = build_test_config ();
nm_ip6_config_add_address (dst, nmtst_platform_ip6_address (expected_addr, NULL, expected_addr_plen));
- nm_ip6_config_add_route (dst, nmtst_platform_ip6_route (expected_route_dest, expected_route_plen, expected_route_next_hop));
+ nm_ip6_config_add_route (dst, nmtst_platform_ip6_route (expected_route_dest, expected_route_plen, expected_route_next_hop, NULL));
expected_ns1 = *nmtst_inet6_from_string ("2222:3333:4444::5555");
nm_ip6_config_add_nameserver (dst, &expected_ns1);
@@ -139,7 +139,7 @@ test_compare_with_source (void)
nm_ip6_config_add_address (b, &addr);
/* Route */
- route = *nmtst_platform_ip6_route ("abcd:1234:4321::", 24, "abcd:1234:4321:cdde::2");
+ route = *nmtst_platform_ip6_route ("abcd:1234:4321::", 24, "abcd:1234:4321:cdde::2", NULL);
route.rt_source = NM_IP_CONFIG_SOURCE_USER;
nm_ip6_config_add_route (a, &route);
@@ -203,7 +203,7 @@ test_add_route_with_source (void)
a = nm_ip6_config_new (1);
/* Test that a higher priority source is not overwritten */
- route = *nmtst_platform_ip6_route ("abcd:1234:4321::", 24, "abcd:1234:4321:cdde::2");
+ route = *nmtst_platform_ip6_route ("abcd:1234:4321::", 24, "abcd:1234:4321:cdde::2", NULL);
route.rt_source = NM_IP_CONFIG_SOURCE_USER;
nm_ip6_config_add_route (a, &route);
diff --git a/src/tests/test-route-manager.c b/src/tests/test-route-manager.c
index df43dd987a..38e945ce4c 100644
--- a/src/tests/test-route-manager.c
+++ b/src/tests/test-route-manager.c
@@ -427,6 +427,7 @@ setup_dev1_ip6 (int ifindex)
*nmtst_inet6_from_string ("2001:db8:8088::"),
48,
in6addr_any,
+ in6addr_any,
10,
0))
g_assert_not_reached ();