diff options
author | Thomas Haller <thaller@redhat.com> | 2023-01-02 21:39:11 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2023-01-19 08:56:21 +0100 |
commit | a3cea7f6fbc74422d345d45624b020bd27c95c77 (patch) | |
tree | c5611df942e1a3b2c29c4242641c360fec6670f2 | |
parent | 0d458dbf07514d76743917d037b0d09e493bc902 (diff) |
platform: fix nmp_lookup_init_route_by_weak_id() to honor the route-table
The route table is part of the weak-id. You can see that with:
ip route replace unicast 1.2.3.4/32 dev eth0 table 57
ip route replace unicast 1.2.3.4/32 dev eth0 table 58
afterwards, `ip route show table all` will list both routes. The replace
operation is only per-table. Note that NMP_CACHE_ID_TYPE_ROUTES_BY_WEAK_ID
already got this right.
Fixes: 10ac675299cb ('platform: add support for routing tables to platform cache')
-rw-r--r-- | src/core/platform/tests/test-common.c | 11 | ||||
-rw-r--r-- | src/libnm-platform/nmp-object.c | 42 | ||||
-rw-r--r-- | src/libnm-platform/nmp-object.h | 14 |
3 files changed, 46 insertions, 21 deletions
diff --git a/src/core/platform/tests/test-common.c b/src/core/platform/tests/test-common.c index e408113ad4..6427071b8f 100644 --- a/src/core/platform/tests/test-common.c +++ b/src/core/platform/tests/test-common.c @@ -12,6 +12,7 @@ #include <sys/wait.h> #include <fcntl.h> #include <linux/if_tun.h> +#include <linux/rtnetlink.h> #include "n-acd/src/n-acd.h" @@ -540,7 +541,7 @@ _ip4_route_get(NMPlatform *platform, _init_platform(&platform, FALSE); - nmp_lookup_init_ip4_route_by_weak_id(&lookup, network, plen, metric, tos); + nmp_lookup_init_ip4_route_by_weak_id(&lookup, RT_TABLE_MAIN, network, plen, metric, tos); c = 0; nmp_cache_iter_for_each (&iter, nm_platform_lookup(platform, &lookup), &o) { @@ -633,7 +634,13 @@ _ip6_route_get(NMPlatform *platform, _init_platform(&platform, FALSE); - nmp_lookup_init_ip6_route_by_weak_id(&lookup, network, plen, metric, src, src_plen); + nmp_lookup_init_ip6_route_by_weak_id(&lookup, + RT_TABLE_MAIN, + network, + plen, + metric, + src, + src_plen); c = 0; nmp_cache_iter_for_each (&iter, nm_platform_lookup(platform, &lookup), &o) { diff --git a/src/libnm-platform/nmp-object.c b/src/libnm-platform/nmp-object.c index e510685b01..65dd06b4de 100644 --- a/src/libnm-platform/nmp-object.c +++ b/src/libnm-platform/nmp-object.c @@ -2336,19 +2336,23 @@ nmp_lookup_init_route_by_weak_id(NMPLookup *lookup, const NMPObject *obj) switch (NMP_OBJECT_GET_TYPE(obj)) { case NMP_OBJECT_TYPE_IP4_ROUTE: r4 = NMP_OBJECT_CAST_IP4_ROUTE(obj); - return nmp_lookup_init_ip4_route_by_weak_id(lookup, - r4->network, - r4->plen, - r4->metric, - r4->tos); + return nmp_lookup_init_ip4_route_by_weak_id( + lookup, + nm_platform_route_table_uncoerce(r4->table_coerced, TRUE), + r4->network, + r4->plen, + r4->metric, + r4->tos); case NMP_OBJECT_TYPE_IP6_ROUTE: r6 = NMP_OBJECT_CAST_IP6_ROUTE(obj); - return nmp_lookup_init_ip6_route_by_weak_id(lookup, - &r6->network, - r6->plen, - r6->metric, - &r6->src, - r6->src_plen); + return nmp_lookup_init_ip6_route_by_weak_id( + lookup, + nm_platform_route_table_uncoerce(r6->table_coerced, TRUE), + &r6->network, + r6->plen, + r6->metric, + &r6->src, + r6->src_plen); default: nm_assert_not_reached(); return NULL; @@ -2357,6 +2361,7 @@ nmp_lookup_init_route_by_weak_id(NMPLookup *lookup, const NMPObject *obj) const NMPLookup * nmp_lookup_init_ip4_route_by_weak_id(NMPLookup *lookup, + guint32 route_table, in_addr_t network, guint plen, guint32 metric, @@ -2367,9 +2372,10 @@ nmp_lookup_init_ip4_route_by_weak_id(NMPLookup *lookup, nm_assert(lookup); o = _nmp_object_stackinit_from_type(&lookup->selector_obj, NMP_OBJECT_TYPE_IP4_ROUTE); - o->ip4_route.ifindex = 1; - o->ip4_route.plen = plen; - o->ip4_route.metric = metric; + o->ip4_route.ifindex = 1; + o->ip4_route.plen = plen; + o->ip4_route.table_coerced = nm_platform_route_table_coerce(route_table); + o->ip4_route.metric = metric; if (network) o->ip4_route.network = network; o->ip4_route.tos = tos; @@ -2379,6 +2385,7 @@ nmp_lookup_init_ip4_route_by_weak_id(NMPLookup *lookup, const NMPLookup * nmp_lookup_init_ip6_route_by_weak_id(NMPLookup *lookup, + guint32 route_table, const struct in6_addr *network, guint plen, guint32 metric, @@ -2390,9 +2397,10 @@ nmp_lookup_init_ip6_route_by_weak_id(NMPLookup *lookup, nm_assert(lookup); o = _nmp_object_stackinit_from_type(&lookup->selector_obj, NMP_OBJECT_TYPE_IP6_ROUTE); - o->ip6_route.ifindex = 1; - o->ip6_route.plen = plen; - o->ip6_route.metric = metric; + o->ip6_route.ifindex = 1; + o->ip6_route.plen = plen; + o->ip6_route.table_coerced = nm_platform_route_table_coerce(route_table); + o->ip6_route.metric = metric; if (network) o->ip6_route.network = *network; if (src) diff --git a/src/libnm-platform/nmp-object.h b/src/libnm-platform/nmp-object.h index dcf431255e..4999f43661 100644 --- a/src/libnm-platform/nmp-object.h +++ b/src/libnm-platform/nmp-object.h @@ -869,11 +869,13 @@ nmp_lookup_init_object_by_ifindex(NMPLookup *lookup, NMPObjectType obj_type, int const NMPLookup *nmp_lookup_init_route_default(NMPLookup *lookup, NMPObjectType obj_type); const NMPLookup *nmp_lookup_init_route_by_weak_id(NMPLookup *lookup, const NMPObject *obj); const NMPLookup *nmp_lookup_init_ip4_route_by_weak_id(NMPLookup *lookup, + guint32 route_table, in_addr_t network, guint plen, guint32 metric, guint8 tos); const NMPLookup *nmp_lookup_init_ip6_route_by_weak_id(NMPLookup *lookup, + guint32 route_table, const struct in6_addr *network, guint plen, guint32 metric, @@ -1132,6 +1134,7 @@ nm_platform_lookup_route_default_clone(NMPlatform *platform, static inline const NMDedupMultiHeadEntry * nm_platform_lookup_ip4_route_by_weak_id(NMPlatform *platform, + guint32 route_table, in_addr_t network, guint plen, guint32 metric, @@ -1139,12 +1142,13 @@ nm_platform_lookup_ip4_route_by_weak_id(NMPlatform *platform, { NMPLookup lookup; - nmp_lookup_init_ip4_route_by_weak_id(&lookup, network, plen, metric, tos); + nmp_lookup_init_ip4_route_by_weak_id(&lookup, route_table, network, plen, metric, tos); return nm_platform_lookup(platform, &lookup); } static inline const NMDedupMultiHeadEntry * nm_platform_lookup_ip6_route_by_weak_id(NMPlatform *platform, + guint32 route_table, const struct in6_addr *network, guint plen, guint32 metric, @@ -1153,7 +1157,13 @@ nm_platform_lookup_ip6_route_by_weak_id(NMPlatform *platform, { NMPLookup lookup; - nmp_lookup_init_ip6_route_by_weak_id(&lookup, network, plen, metric, src, src_plen); + nmp_lookup_init_ip6_route_by_weak_id(&lookup, + route_table, + network, + plen, + metric, + src, + src_plen); return nm_platform_lookup(platform, &lookup); } |