From 4f719da32d77af1e8a39df22800cce84ae0aadd7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 19 Jan 2023 16:08:08 +0100 Subject: [PATCH] libnm: valide IPv4 ECMP routes in NMIPRoute as unicast routes Kernel does not allow ECMP routes for route types other than unicast. Reject that in NetworkManager settings too. Fixes: 3cd02b6ed6e7 ('libnm,platform: fix range for "weight" property of next hops for routes') https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1507 --- src/libnm-core-impl/nm-setting-ip-config.c | 23 ++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-ip-config.c b/src/libnm-core-impl/nm-setting-ip-config.c index bea0ee7f11..3a31848e84 100644 --- a/src/libnm-core-impl/nm-setting-ip-config.c +++ b/src/libnm-core-impl/nm-setting-ip-config.c @@ -1303,8 +1303,9 @@ nm_ip_route_get_variant_attribute_spec(void) } typedef struct { - int type; - int scope; + int type; + int scope; + gint16 weight; } IPRouteAttrParseData; static gboolean @@ -1440,6 +1441,8 @@ _ip_route_attribute_validate(const char *name, _("route weight cannot be larger than 256")); return FALSE; } + if (parse_data) + parse_data->weight = (guint16) u32; break; case '\0': break; @@ -1490,8 +1493,9 @@ _nm_ip_route_attribute_validate_all(const NMIPRoute *route, GError **error) guint attrs_len; guint i; IPRouteAttrParseData parse_data = { - .type = RTN_UNICAST, - .scope = -1, + .type = RTN_UNICAST, + .scope = -1, + .weight = 0, }; g_return_val_if_fail(route, FALSE); @@ -1540,6 +1544,17 @@ _nm_ip_route_attribute_validate_all(const NMIPRoute *route, GError **error) break; } + if (parse_data.weight > 0) { + if (parse_data.type != RTN_UNICAST) { + g_set_error(error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("a %s route cannot have a ECMP multi-hop \"weight\""), + nm_net_aux_rtnl_rtntype_n2a(parse_data.type)); + return FALSE; + } + } + return TRUE; }