cli: use nmc_string_to_ternary() to parse ternary in _set_fcn_ethtool()
nmc_string_to_ternary() is much more flexible, in that it case insensitive and accepts any unambiguous abbreviation. Also, nmc_string_to_ternary() accepts "unknown" as alias for "default". Also, nmc_string_to_ternary() accepts numeric values -1, 0, 1. By using nmc_string_to_ternary(), we treat ethtool boolean options like other ternary properties and accept the same keywords.
This commit is contained in:
@@ -4284,10 +4284,9 @@ static gconstpointer _get_fcn_ethtool(ARGS_GET_FCN)
|
||||
|
||||
static gboolean _set_fcn_ethtool(ARGS_SET_FCN)
|
||||
{
|
||||
NMEthtoolID ethtool_id = property_info->property_typ_data->subtype.ethtool.ethtool_id;
|
||||
gs_free char *value_to_free = NULL;
|
||||
gint64 i64;
|
||||
gboolean b;
|
||||
NMEthtoolID ethtool_id = property_info->property_typ_data->subtype.ethtool.ethtool_id;
|
||||
gint64 i64;
|
||||
NMTernary t;
|
||||
|
||||
if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value))
|
||||
goto do_unset;
|
||||
@@ -4311,14 +4310,10 @@ static gboolean _set_fcn_ethtool(ARGS_SET_FCN)
|
||||
|
||||
nm_assert(nm_ethtool_id_is_feature(ethtool_id) || nm_ethtool_id_is_pause(ethtool_id));
|
||||
|
||||
value = nm_strstrip_avoid_copy_a(300, value, &value_to_free);
|
||||
if (NM_IN_STRSET(value, "1", "yes", "true", "on"))
|
||||
b = TRUE;
|
||||
else if (NM_IN_STRSET(value, "0", "no", "false", "off"))
|
||||
b = FALSE;
|
||||
else if (NM_IN_STRSET(value, "", "ignore", "default"))
|
||||
goto do_unset;
|
||||
else {
|
||||
if (!nmc_string_to_ternary_full(value,
|
||||
NMC_STRING_TO_TERNARY_FLAGS_IGNORE_FOR_DEFAULT,
|
||||
&t,
|
||||
error)) {
|
||||
g_set_error(error,
|
||||
NM_UTILS_ERROR,
|
||||
NM_UTILS_ERROR_INVALID_ARGUMENT,
|
||||
@@ -4326,8 +4321,10 @@ static gboolean _set_fcn_ethtool(ARGS_SET_FCN)
|
||||
value);
|
||||
return FALSE;
|
||||
}
|
||||
if (t == NM_TERNARY_DEFAULT)
|
||||
goto do_unset;
|
||||
|
||||
nm_setting_option_set_boolean(setting, nm_ethtool_data[ethtool_id]->optname, b);
|
||||
nm_setting_option_set_boolean(setting, nm_ethtool_data[ethtool_id]->optname, !!t);
|
||||
return TRUE;
|
||||
|
||||
do_unset:
|
||||
|
Reference in New Issue
Block a user