platform: fix IPv6 route methods for metric 0
Handling a route with metric 0 effectively means a metric of 1024 (user default). Adjust the add(), delete() and exist() functions to consider routes with metric 0 as 1024.
This commit is contained in:
@@ -3845,6 +3845,8 @@ ip6_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
|
|||||||
struct in6_addr network, int plen, struct in6_addr gateway,
|
struct in6_addr network, int plen, struct in6_addr gateway,
|
||||||
guint32 metric, guint32 mss)
|
guint32 metric, guint32 mss)
|
||||||
{
|
{
|
||||||
|
metric = nm_utils_ip6_route_metric_normalize (metric);
|
||||||
|
|
||||||
return add_object (platform, build_rtnl_route (AF_INET6, ifindex, source, &network, plen, &gateway, NULL, metric, mss));
|
return add_object (platform, build_rtnl_route (AF_INET6, ifindex, source, &network, plen, &gateway, NULL, metric, mss));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3962,6 +3964,8 @@ ip6_route_delete (NMPlatform *platform, int ifindex, struct in6_addr network, in
|
|||||||
{
|
{
|
||||||
struct in6_addr gateway = IN6ADDR_ANY_INIT;
|
struct in6_addr gateway = IN6ADDR_ANY_INIT;
|
||||||
|
|
||||||
|
metric = nm_utils_ip6_route_metric_normalize (metric);
|
||||||
|
|
||||||
return delete_object (platform, build_rtnl_route (AF_INET6, ifindex, NM_IP_CONFIG_SOURCE_UNKNOWN ,&network, plen, &gateway, NULL, metric, 0), FALSE) &&
|
return delete_object (platform, build_rtnl_route (AF_INET6, ifindex, NM_IP_CONFIG_SOURCE_UNKNOWN ,&network, plen, &gateway, NULL, metric, 0), FALSE) &&
|
||||||
refresh_route (platform, AF_INET6, ifindex, &network, plen, metric);
|
refresh_route (platform, AF_INET6, ifindex, &network, plen, metric);
|
||||||
}
|
}
|
||||||
@@ -3989,6 +3993,8 @@ ip4_route_exists (NMPlatform *platform, int ifindex, in_addr_t network, int plen
|
|||||||
static gboolean
|
static gboolean
|
||||||
ip6_route_exists (NMPlatform *platform, int ifindex, struct in6_addr network, int plen, guint32 metric)
|
ip6_route_exists (NMPlatform *platform, int ifindex, struct in6_addr network, int plen, guint32 metric)
|
||||||
{
|
{
|
||||||
|
metric = nm_utils_ip6_route_metric_normalize (metric);
|
||||||
|
|
||||||
return ip_route_exists (platform, AF_INET6, ifindex, &network, plen, metric);
|
return ip_route_exists (platform, AF_INET6, ifindex, &network, plen, metric);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "test-common.h"
|
#include "test-common.h"
|
||||||
#include "nm-test-utils.h"
|
#include "nm-test-utils.h"
|
||||||
|
#include "NetworkManagerUtils.h"
|
||||||
|
|
||||||
#define DEVICE_NAME "nm-test-device"
|
#define DEVICE_NAME "nm-test-device"
|
||||||
|
|
||||||
@@ -205,21 +206,21 @@ test_ip6_route (void)
|
|||||||
rts[0].plen = 128;
|
rts[0].plen = 128;
|
||||||
rts[0].ifindex = ifindex;
|
rts[0].ifindex = ifindex;
|
||||||
rts[0].gateway = in6addr_any;
|
rts[0].gateway = in6addr_any;
|
||||||
rts[0].metric = metric;
|
rts[0].metric = nm_utils_ip6_route_metric_normalize (metric);
|
||||||
rts[0].mss = mss;
|
rts[0].mss = mss;
|
||||||
rts[1].source = NM_IP_CONFIG_SOURCE_USER;
|
rts[1].source = NM_IP_CONFIG_SOURCE_USER;
|
||||||
rts[1].network = network;
|
rts[1].network = network;
|
||||||
rts[1].plen = plen;
|
rts[1].plen = plen;
|
||||||
rts[1].ifindex = ifindex;
|
rts[1].ifindex = ifindex;
|
||||||
rts[1].gateway = gateway;
|
rts[1].gateway = gateway;
|
||||||
rts[1].metric = metric;
|
rts[1].metric = nm_utils_ip6_route_metric_normalize (metric);
|
||||||
rts[1].mss = mss;
|
rts[1].mss = mss;
|
||||||
rts[2].source = NM_IP_CONFIG_SOURCE_USER;
|
rts[2].source = NM_IP_CONFIG_SOURCE_USER;
|
||||||
rts[2].network = in6addr_any;
|
rts[2].network = in6addr_any;
|
||||||
rts[2].plen = 0;
|
rts[2].plen = 0;
|
||||||
rts[2].ifindex = ifindex;
|
rts[2].ifindex = ifindex;
|
||||||
rts[2].gateway = gateway;
|
rts[2].gateway = gateway;
|
||||||
rts[2].metric = metric;
|
rts[2].metric = nm_utils_ip6_route_metric_normalize (metric);
|
||||||
rts[2].mss = mss;
|
rts[2].mss = mss;
|
||||||
g_assert_cmpint (routes->len, ==, 3);
|
g_assert_cmpint (routes->len, ==, 3);
|
||||||
g_assert (!memcmp (routes->data, rts, sizeof (rts)));
|
g_assert (!memcmp (routes->data, rts, sizeof (rts)));
|
||||||
|
Reference in New Issue
Block a user