cli: merge branch 'th/cli-ethtool-ternary'

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/849
This commit is contained in:
Thomas Haller 2021-05-14 09:23:09 +02:00
commit d7594ae9c9
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
3 changed files with 39 additions and 17 deletions

View file

@ -130,7 +130,10 @@ nmc_string_to_bool(const char *str, gboolean *val_bool, GError **error)
}
gboolean
nmc_string_to_ternary(const char *str, NMTernary *val, GError **error)
nmc_string_to_ternary_full(const char * str,
NMCStringToTernaryFlags flags,
NMTernary * val,
GError ** error)
{
gs_free char *str_to_free = NULL;
int i;
@ -156,9 +159,16 @@ nmc_string_to_ternary(const char *str, NMTernary *val, GError **error)
*val = NM_TERNARY_TRUE;
else if (nmc_string_is_valid(str, NM_MAKE_STRV("false", "no", "off"), NULL))
*val = NM_TERNARY_FALSE;
else if (nmc_string_is_valid(str, NM_MAKE_STRV("unknown", "default"), NULL))
else if (nmc_string_is_valid(
str,
NM_MAKE_STRV("unknown",
"default",
NM_FLAGS_HAS(flags, NMC_STRING_TO_TERNARY_FLAGS_IGNORE_FOR_DEFAULT)
? "ignore"
: NULL),
NULL))
*val = NM_TERNARY_DEFAULT;
else if ((i = _nm_utils_ascii_str_to_int64(str, 0, -1, 1, -2)) >= -1)
else if ((i = _nm_utils_ascii_str_to_int64(str, 0, -1, 1, -2)) != -2)
*val = (NMTernary) i;
else {
nm_utils_error_set(error,

View file

@ -23,7 +23,22 @@ gboolean nmc_string_to_uint(const char * str,
unsigned long int max,
unsigned long int *value);
gboolean nmc_string_to_bool(const char *str, gboolean *val_bool, GError **error);
gboolean nmc_string_to_ternary(const char *str, NMTernary *val, GError **error);
typedef enum {
NMC_STRING_TO_TERNARY_FLAGS_NONE = 0,
NMC_STRING_TO_TERNARY_FLAGS_IGNORE_FOR_DEFAULT = (1LL << 0),
} NMCStringToTernaryFlags;
gboolean nmc_string_to_ternary_full(const char * str,
NMCStringToTernaryFlags flags,
NMTernary * val,
GError ** error);
static inline gboolean
nmc_string_to_ternary(const char *str, NMTernary *val, GError **error)
{
return nmc_string_to_ternary_full(str, NMC_STRING_TO_TERNARY_FLAGS_NONE, val, error);
}
gboolean matches(const char *cmd, const char *pattern);

View file

@ -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: