diff options
author | Thomas Haller <thaller@redhat.com> | 2017-04-13 22:34:32 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2017-04-13 23:22:21 +0200 |
commit | 1b6edf9eb2bb72052effad6701efafb5d37cf0cd (patch) | |
tree | 80b2fbe8121931e771cf3d7a53657e686b0b0ddc | |
parent | b166027f92173be338f649c9cccaea5fb87f961d (diff) | |
download | NetworkManager-th/route-zero-host-part-rh1439376.tar.gz |
core: ignore host part when comparing routes for route-managerth/route-zero-host-part-rh1439376
-rw-r--r-- | src/nm-route-manager.c | 2 | ||||
-rw-r--r-- | src/platform/nm-platform.c | 25 | ||||
-rw-r--r-- | src/platform/nm-platform.h | 18 | ||||
-rw-r--r-- | src/tests/test-route-manager.c | 2 |
4 files changed, 36 insertions, 11 deletions
diff --git a/src/nm-route-manager.c b/src/nm-route-manager.c index d97d868af4..76c672ee7c 100644 --- a/src/nm-route-manager.c +++ b/src/nm-route-manager.c @@ -377,7 +377,7 @@ _route_equals_ignoring_ifindex (const VTableIP *vtable, const NMPlatformIPXRoute r2_backup.rx.metric = (guint32) r2_metric; r2 = &r2_backup; } - return vtable->vt->route_cmp (r1, r2) == 0; + return vtable->vt->route_cmp (r1, r2, FALSE) == 0; } static NMPlatformIPXRoute * diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 6eb4a1f807..bb81749d73 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -4291,11 +4291,16 @@ nm_platform_ip6_address_cmp (const NMPlatformIP6Address *a, const NMPlatformIP6A } int -nm_platform_ip4_route_cmp (const NMPlatformIP4Route *a, const NMPlatformIP4Route *b) +nm_platform_ip4_route_cmp_full (const NMPlatformIP4Route *a, const NMPlatformIP4Route *b, gboolean consider_host_part) { _CMP_SELF (a, b); _CMP_FIELD (a, b, ifindex); - _CMP_FIELD (a, b, network); + if (consider_host_part) + _CMP_FIELD (a, b, network); + else { + _CMP_DIRECT (nm_utils_ip4_address_clear_host_address (a->network, a->plen), + nm_utils_ip4_address_clear_host_address (b->network, b->plen)); + } _CMP_FIELD (a, b, plen); _CMP_FIELD (a, b, metric); _CMP_FIELD (a, b, gateway); @@ -4319,11 +4324,19 @@ nm_platform_ip4_route_cmp (const NMPlatformIP4Route *a, const NMPlatformIP4Route } int -nm_platform_ip6_route_cmp (const NMPlatformIP6Route *a, const NMPlatformIP6Route *b) +nm_platform_ip6_route_cmp_full (const NMPlatformIP6Route *a, const NMPlatformIP6Route *b, gboolean consider_host_part) { _CMP_SELF (a, b); _CMP_FIELD (a, b, ifindex); - _CMP_FIELD_MEMCMP (a, b, network); + if (consider_host_part) + _CMP_FIELD_MEMCMP (a, b, network); + else { + struct in6_addr n1, n2; + + nm_utils_ip6_address_clear_host_address (&n1, &a->network, a->plen); + nm_utils_ip6_address_clear_host_address (&n2, &b->network, b->plen); + _CMP_DIRECT_MEMCMP (&n1, &n2, sizeof (struct in6_addr)); + } _CMP_FIELD (a, b, plen); _CMP_FIELD (a, b, metric); _CMP_FIELD_MEMCMP (a, b, gateway); @@ -4541,7 +4554,7 @@ const NMPlatformVTableRoute nm_platform_vtable_route_v4 = { .is_ip4 = TRUE, .addr_family = AF_INET, .sizeof_route = sizeof (NMPlatformIP4Route), - .route_cmp = (int (*) (const NMPlatformIPXRoute *a, const NMPlatformIPXRoute *b)) nm_platform_ip4_route_cmp, + .route_cmp = (int (*) (const NMPlatformIPXRoute *a, const NMPlatformIPXRoute *b, gboolean consider_host_part)) nm_platform_ip4_route_cmp_full, .route_to_string = (const char *(*) (const NMPlatformIPXRoute *route, char *buf, gsize len)) nm_platform_ip4_route_to_string, .route_get_all = nm_platform_ip4_route_get_all, .route_add = _vtr_v4_route_add, @@ -4554,7 +4567,7 @@ const NMPlatformVTableRoute nm_platform_vtable_route_v6 = { .is_ip4 = FALSE, .addr_family = AF_INET6, .sizeof_route = sizeof (NMPlatformIP6Route), - .route_cmp = (int (*) (const NMPlatformIPXRoute *a, const NMPlatformIPXRoute *b)) nm_platform_ip6_route_cmp, + .route_cmp = (int (*) (const NMPlatformIPXRoute *a, const NMPlatformIPXRoute *b, gboolean consider_host_part)) nm_platform_ip6_route_cmp_full, .route_to_string = (const char *(*) (const NMPlatformIPXRoute *route, char *buf, gsize len)) nm_platform_ip6_route_to_string, .route_get_all = nm_platform_ip6_route_get_all, .route_add = _vtr_v6_route_add, diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 5eb46b42f2..468e889188 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -392,7 +392,7 @@ typedef struct { gboolean is_ip4; int addr_family; gsize sizeof_route; - int (*route_cmp) (const NMPlatformIPXRoute *a, const NMPlatformIPXRoute *b); + int (*route_cmp) (const NMPlatformIPXRoute *a, const NMPlatformIPXRoute *b, gboolean consider_host_part); const char *(*route_to_string) (const NMPlatformIPXRoute *route, char *buf, gsize len); GArray *(*route_get_all) (NMPlatform *self, int ifindex, NMPlatformGetRouteFlags flags); gboolean (*route_add) (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *route, gint64 metric); @@ -1019,8 +1019,20 @@ int nm_platform_lnk_vlan_cmp (const NMPlatformLnkVlan *a, const NMPlatformLnkVla int nm_platform_lnk_vxlan_cmp (const NMPlatformLnkVxlan *a, const NMPlatformLnkVxlan *b); int nm_platform_ip4_address_cmp (const NMPlatformIP4Address *a, const NMPlatformIP4Address *b); int nm_platform_ip6_address_cmp (const NMPlatformIP6Address *a, const NMPlatformIP6Address *b); -int nm_platform_ip4_route_cmp (const NMPlatformIP4Route *a, const NMPlatformIP4Route *b); -int nm_platform_ip6_route_cmp (const NMPlatformIP6Route *a, const NMPlatformIP6Route *b); +int nm_platform_ip4_route_cmp_full (const NMPlatformIP4Route *a, const NMPlatformIP4Route *b, gboolean consider_host_part); +int nm_platform_ip6_route_cmp_full (const NMPlatformIP6Route *a, const NMPlatformIP6Route *b, gboolean consider_host_part); + +static inline int +nm_platform_ip4_route_cmp (const NMPlatformIP4Route *a, const NMPlatformIP4Route *b) +{ + return nm_platform_ip4_route_cmp_full (a, b, TRUE); +} + +static inline int +nm_platform_ip6_route_cmp (const NMPlatformIP6Route *a, const NMPlatformIP6Route *b) +{ + return nm_platform_ip6_route_cmp_full (a, b, TRUE); +} gboolean nm_platform_check_support_kernel_extended_ifa_flags (NMPlatform *self); gboolean nm_platform_check_support_user_ipv6ll (NMPlatform *self); diff --git a/src/tests/test-route-manager.c b/src/tests/test-route-manager.c index ba7834e9ea..d534075753 100644 --- a/src/tests/test-route-manager.c +++ b/src/tests/test-route-manager.c @@ -806,7 +806,7 @@ _assert_route_check (const NMPlatformVTableRoute *vtable, gboolean has, const NM 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) { + if (!r || vtable->route_cmp (r, &c, TRUE) != 0) { g_error ("Invalid route. Expect %s, has %s", vtable->route_to_string (&c, NULL, 0), vtable->route_to_string (r, buf, sizeof (buf))); |