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: 3cd02b6ed6 ('libnm,platform: fix range for "weight" property of next hops for routes')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1507
This commit is contained in:
Thomas Haller 2023-01-19 16:08:08 +01:00
parent 9ee42c0979
commit 4f719da32d
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -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;
}