fixup! platform: fix handling "weight" for IPv4 routes

This commit is contained in:
Thomas Haller 2023-11-29 12:33:33 +01:00
parent 335f62fe52
commit 2c208b3060
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
5 changed files with 16 additions and 49 deletions

View file

@ -2512,7 +2512,7 @@ nm_l3_config_data_get_blacklisted_ip4_routes(const NML3ConfigData *self, gboolea
.metric = NM_PLATFORM_ROUTE_METRIC_IP4_DEVICE_ROUTE,
.scope_inv = nm_platform_route_scope_inv(NM_RT_SCOPE_LINK),
};
nm_platform_ip_route_normalize(AF_INET, &rx.rx, NMP_IP_ROUTE_NORMALIZE_FLAGS_NONE);
nm_platform_ip_route_normalize(AF_INET, &rx.rx);
if (nm_l3_config_data_lookup_route(self, AF_INET, &rx.rx)) {
/* we track such a route explicitly. Don't blacklist it. */
@ -2693,9 +2693,7 @@ nm_l3_config_data_add_dependent_device_routes(NML3ConfigData *self,
.plen = plen,
};
nm_platform_ip_route_normalize(addr_family,
&rx.rx,
NMP_IP_ROUTE_NORMALIZE_FLAGS_NONE);
nm_platform_ip_route_normalize(addr_family, &rx.rx);
nm_l3_config_data_add_route(self, addr_family, NULL, &rx.rx);
}
}

View file

@ -3911,7 +3911,7 @@ _l3cfg_update_combined_config(NML3Cfg *self,
.type_coerced = nm_platform_route_type_coerce(RTN_LOCAL),
.pref_src = NM_IPV4LO_ADDR1,
};
nm_platform_ip_route_normalize(AF_INET, &rx.rx, NMP_IP_ROUTE_NORMALIZE_FLAGS_NONE);
nm_platform_ip_route_normalize(AF_INET, &rx.rx);
if (!nm_l3_config_data_lookup_route(l3cd, AF_INET, &rx.rx)) {
nm_l3_config_data_add_route_4(l3cd, &rx.r4);
}

View file

@ -719,9 +719,7 @@ test_ip4_route_options(gconstpointer test_data)
for (i = 0; i < rts_n; i++) {
rts_cmp[i] = rts_add[i];
nm_platform_ip_route_normalize(AF_INET,
NM_PLATFORM_IP_ROUTE_CAST(&rts_cmp[i]),
NMP_IP_ROUTE_NORMALIZE_FLAGS_NONE);
nm_platform_ip_route_normalize(AF_INET, NM_PLATFORM_IP_ROUTE_CAST(&rts_cmp[i]));
}
routes = nmtstp_ip4_route_get_all(NM_PLATFORM_GET, IFINDEX);
@ -893,9 +891,7 @@ test_ip6_route_options(gconstpointer test_data)
for (i = 0; i < rts_n; i++) {
rts_cmp[i] = rts_add[i];
nm_platform_ip_route_normalize(AF_INET6,
NM_PLATFORM_IP_ROUTE_CAST(&rts_cmp[i]),
NMP_IP_ROUTE_NORMALIZE_FLAGS_NONE);
nm_platform_ip_route_normalize(AF_INET6, NM_PLATFORM_IP_ROUTE_CAST(&rts_cmp[i]));
}
routes = nmtstp_ip6_route_get_all(NM_PLATFORM_GET, IFINDEX);
@ -1940,7 +1936,7 @@ test_blackhole(gconstpointer test_data)
};
}
nm_platform_ip_route_normalize(addr_family, &rr.rx, NMP_IP_ROUTE_NORMALIZE_FLAGS_NONE);
nm_platform_ip_route_normalize(addr_family, &rr.rx);
if (IS_IPv4)
r = nm_platform_ip4_route_add(NM_PLATFORM_GET, NMP_NLM_FLAG_APPEND, &rr.r4, NULL);

View file

@ -5318,14 +5318,14 @@ _ip4_route_weight_normalize(guint n_nexthops, guint16 weight, gboolean keep_ecmp
* Note that a positive "weight" of IPv4 single hop routes is not meaningful in
* kernel. While we track such routes at upper layers, they don't exist in
* kernel (well, they exist, with their weight set to zero, which makes them a
* different route according to NM_PLATFORM_IP_ROUTE_CMP_TYPE_ID. The
* NMP_IP_ROUTE_NORMALIZE_FLAGS_KEEP_ECMP_WEIGHT flag can be used to prevent
* such normalization.
* different route according to NM_PLATFORM_IP_ROUTE_CMP_TYPE_ID. It will
* be normalized to zero too, making basically it a different route.
*
* Also, "metric_any" is normalized to FALSE. This also makes it a different route
* according to NM_PLATFORM_IP_ROUTE_CMP_TYPE_ID.
*/
void
nm_platform_ip_route_normalize(int addr_family,
NMPlatformIPRoute *route,
NMPIPRouteNormalizeFlags flags)
nm_platform_ip_route_normalize(int addr_family, NMPlatformIPRoute *route)
{
NMPlatformIP4Route *r4;
NMPlatformIP6Route *r6;
@ -5344,10 +5344,7 @@ nm_platform_ip_route_normalize(int addr_family,
r4->network = nm_ip4_addr_clear_host_address(r4->network, r4->plen);
r4->scope_inv = _ip_route_scope_inv_get_normalized(r4);
r4->n_nexthops = nm_platform_ip4_route_get_n_nexthops(r4);
r4->weight = _ip4_route_weight_normalize(
r4->n_nexthops,
r4->weight,
NM_FLAGS_HAS(flags, NMP_IP_ROUTE_NORMALIZE_FLAGS_KEEP_ECMP_WEIGHT));
r4->weight = _ip4_route_weight_normalize(r4->n_nexthops, r4->weight, FALSE);
break;
case AF_INET6:
r6 = (NMPlatformIP6Route *) route;
@ -5385,8 +5382,7 @@ _ip_route_add(NMPlatform *self, NMPNlmFlags flags, NMPObject *obj_stack, char **
|| obj_stack->ip4_route.n_nexthops <= 1u || obj_stack->_ip4_route.extra_nexthops);
nm_platform_ip_route_normalize(NMP_OBJECT_GET_ADDR_FAMILY((obj_stack)),
NMP_OBJECT_CAST_IP_ROUTE(obj_stack),
NMP_IP_ROUTE_NORMALIZE_FLAGS_NONE);
NMP_OBJECT_CAST_IP_ROUTE(obj_stack));
ifindex = obj_stack->ip_route.ifindex;
@ -9458,9 +9454,7 @@ nm_platform_ip4_address_generate_device_route(const NMPlatformIP4Address *addr,
.scope_inv = nm_platform_route_scope_inv(NM_RT_SCOPE_LINK),
};
nm_platform_ip_route_normalize(AF_INET,
(NMPlatformIPRoute *) dst,
NMP_IP_ROUTE_NORMALIZE_FLAGS_NONE);
nm_platform_ip_route_normalize(AF_INET, (NMPlatformIPRoute *) dst);
return dst;
}

View file

@ -2270,28 +2270,7 @@ nm_platform_ip_address_get_prune_list(NMPlatform *self,
gboolean nm_platform_ip_address_flush(NMPlatform *self, int addr_family, int ifindex);
typedef enum {
/* No flags. */
NMP_IP_ROUTE_NORMALIZE_FLAGS_NONE = 0,
/* Don't normalize the "weight" for IPv4 single hop routes.
* nm_platform_ip_route_normalize() aims to normalize a route as it
* can exist in kernel. But in kernel, a IPv4 single hop route cannot
* have a (non-zero) weight. Normalization would usually loose that
* information.
*
* However, it can be useful to normalize routes, but not the "weight".
* Upper layers want to track single hop routes with positive weight for
* internal purposes, while normalizing all other fields. This flag
* allows to opt-out from that normalization. The result may not ever
* exist in kernel (as far as NM_PLATFORM_IP_ROUTE_CMP_TYPE_ID is concerned).
*/
NMP_IP_ROUTE_NORMALIZE_FLAGS_KEEP_ECMP_WEIGHT = 0x1,
} NMPIPRouteNormalizeFlags;
void nm_platform_ip_route_normalize(int addr_family,
NMPlatformIPRoute *route,
NMPIPRouteNormalizeFlags flags);
void nm_platform_ip_route_normalize(int addr_family, NMPlatformIPRoute *route);
static inline guint32
nm_platform_ip4_route_get_effective_metric(const NMPlatformIP4Route *r)