Commit 769e0726 authored by Beniamino Galvani's avatar Beniamino Galvani

cli: strictly validate SR-IOV attributes

Report an error when the user tries to add an unknown attribute
instead of silently accepting (and ignoring) it.

Note that this commit also changes the behavior of public API
nm_utils_sriov_vf_from_str() to return an error when an unknown
attribute is found. I think the previous behavior was buggy as wrong
attributes were simply ignored without any way for the user to know.

Fixes: a9b4532f
parent 3e4b30b2
......@@ -252,7 +252,7 @@ gboolean _nm_ip_route_attribute_validate_all (const NMIPRoute *route);
const char **_nm_ip_route_get_attribute_names (const NMIPRoute *route, gboolean sorted, guint *out_length);
GHashTable *_nm_ip_route_get_attributes_direct (NMIPRoute *route);
NMSriovVF *_nm_utils_sriov_vf_from_strparts (const char *index, const char *detail, GError **error);
NMSriovVF *_nm_utils_sriov_vf_from_strparts (const char *index, const char *detail, gboolean ignore_unknown, GError **error);
gboolean _nm_sriov_vf_attribute_validate_all (const NMSriovVF *vf, GError **error);
static inline void
......
......@@ -152,7 +152,7 @@ sriov_vfs_parser (KeyfileReaderInfo *info, NMSetting *setting, const char *key)
keys[i],
NULL);
vf = _nm_utils_sriov_vf_from_strparts (rest, value, NULL);
vf = _nm_utils_sriov_vf_from_strparts (rest, value, TRUE, NULL);
if (vf)
g_ptr_array_add (vfs, vf);
}
......
......@@ -2737,11 +2737,14 @@ nm_utils_sriov_vf_from_str (const char *str, GError **error)
detail++;
}
return _nm_utils_sriov_vf_from_strparts (str, detail, error);
return _nm_utils_sriov_vf_from_strparts (str, detail, FALSE, error);
}
NMSriovVF *
_nm_utils_sriov_vf_from_strparts (const char *index, const char *detail, GError **error)
_nm_utils_sriov_vf_from_strparts (const char *index,
const char *detail,
gboolean ignore_unknown,
GError **error)
{
NMSriovVF *vf;
guint32 n_index;
......@@ -2761,7 +2764,12 @@ _nm_utils_sriov_vf_from_strparts (const char *index, const char *detail, GError
vf = nm_sriov_vf_new (n_index);
if (detail) {
ht = nm_utils_parse_variant_attributes (detail, ' ', '=', TRUE, _nm_sriov_vf_attribute_spec, error);
ht = nm_utils_parse_variant_attributes (detail,
' ',
'=',
ignore_unknown,
_nm_sriov_vf_attribute_spec,
error);
if (!ht) {
nm_sriov_vf_unref (vf);
return NULL;
......
......@@ -2263,7 +2263,7 @@ make_sriov_setting (shvarFile *ifcfg)
key += NM_STRLEN ("SRIOV_VF");
vf = _nm_utils_sriov_vf_from_strparts (key, value, &error);
vf = _nm_utils_sriov_vf_from_strparts (key, value, TRUE, &error);
if (!vf) {
PARSE_WARNING ("ignoring invalid SR-IOV VF '%s %s': %s",
key, value, error->message);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment