summaryrefslogtreecommitdiff
path: root/src/platform
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2017-02-09 17:26:04 +0100
committerBeniamino Galvani <bgalvani@redhat.com>2017-03-06 15:20:25 +0100
commit36d9e252d2733f43765597d54bcdd9efa750531d (patch)
treef62f1b8772501c9079b3255611735d7767bfcb77 /src/platform
parentc55c6312330288c4b1b1afcbeef7ef99a7a95810 (diff)
downloadNetworkManager-36d9e252d2733f43765597d54bcdd9efa750531d.tar.gz
platform: support preferred source option for IPv6 routes
Extend the support for the preferred source route option (RTA_PREFSRC) to IPv6.
Diffstat (limited to 'src/platform')
-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
6 files changed, 45 insertions, 22 deletions
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);