summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-01-19 16:08:08 +0100
committerThomas Haller <thaller@redhat.com>2023-01-20 15:09:31 +0100
commit4f719da32d77af1e8a39df22800cce84ae0aadd7 (patch)
tree7cc03e5412351e46ba62bb828d58430475f270e0
parent9ee42c0979d3889655a4394129c41133f7651b49 (diff)
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
-rw-r--r--src/libnm-core-impl/nm-setting-ip-config.c23
1 files 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;
}