mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-10-06 16:21:50 +00:00
ethtool: fail build on missing handling of ethtool types
Convert the open-coded conditions to a switch/case so that the compilation will fail if a new ethtool type is added and is not handled in various places.
This commit is contained in:
parent
123ca26770
commit
55d31ab11d
|
@ -298,11 +298,16 @@ nm_ethtool_id_to_type(NMEthtoolID id)
|
|||
const GVariantType *
|
||||
nm_ethtool_id_get_variant_type(NMEthtoolID ethtool_id)
|
||||
{
|
||||
if (nm_ethtool_id_is_feature(ethtool_id) || nm_ethtool_id_is_pause(ethtool_id))
|
||||
switch (nm_ethtool_id_to_type(ethtool_id)) {
|
||||
case NM_ETHTOOL_TYPE_FEATURE:
|
||||
case NM_ETHTOOL_TYPE_PAUSE:
|
||||
return G_VARIANT_TYPE_BOOLEAN;
|
||||
|
||||
if (nm_ethtool_id_is_coalesce(ethtool_id) || nm_ethtool_id_is_ring(ethtool_id))
|
||||
case NM_ETHTOOL_TYPE_COALESCE:
|
||||
case NM_ETHTOOL_TYPE_RING:
|
||||
return G_VARIANT_TYPE_UINT32;
|
||||
|
||||
return NULL;
|
||||
case NM_ETHTOOL_TYPE_UNKNOWN:
|
||||
nm_assert(ethtool_id == NM_ETHTOOL_ID_UNKNOWN);
|
||||
return NULL;
|
||||
}
|
||||
return nm_assert_unreachable_val(NULL);
|
||||
}
|
||||
|
|
|
@ -4421,26 +4421,31 @@ _get_fcn_ethtool(ARGS_GET_FCN)
|
|||
|
||||
RETURN_UNSUPPORTED_GET_TYPE();
|
||||
|
||||
if (nm_ethtool_id_is_coalesce(ethtool_id) || nm_ethtool_id_is_ring(ethtool_id)) {
|
||||
switch (nm_ethtool_id_to_type(ethtool_id)) {
|
||||
case NM_ETHTOOL_TYPE_COALESCE:
|
||||
case NM_ETHTOOL_TYPE_RING:
|
||||
if (!nm_setting_option_get_uint32(setting, nm_ethtool_data[ethtool_id]->optname, &u32)) {
|
||||
NM_SET_OUT(out_is_default, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RETURN_STR_TO_FREE(nm_strdup_int(u32));
|
||||
case NM_ETHTOOL_TYPE_FEATURE:
|
||||
case NM_ETHTOOL_TYPE_PAUSE:
|
||||
if (!nm_setting_option_get_boolean(setting, nm_ethtool_data[ethtool_id]->optname, &b)) {
|
||||
NM_SET_OUT(out_is_default, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
s = b ? N_("on") : N_("off");
|
||||
if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
|
||||
s = gettext(s);
|
||||
return s;
|
||||
case NM_ETHTOOL_TYPE_UNKNOWN:
|
||||
nm_assert_not_reached();
|
||||
}
|
||||
|
||||
nm_assert(nm_ethtool_id_is_feature(ethtool_id) || nm_ethtool_id_is_pause(ethtool_id));
|
||||
|
||||
if (!nm_setting_option_get_boolean(setting, nm_ethtool_data[ethtool_id]->optname, &b)) {
|
||||
NM_SET_OUT(out_is_default, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
s = b ? N_("on") : N_("off");
|
||||
if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
|
||||
s = gettext(s);
|
||||
return s;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -4453,7 +4458,9 @@ _set_fcn_ethtool(ARGS_SET_FCN)
|
|||
if (_SET_FCN_DO_RESET_DEFAULT(property_info, modifier, value))
|
||||
goto do_unset;
|
||||
|
||||
if (nm_ethtool_id_is_coalesce(ethtool_id) || nm_ethtool_id_is_ring(ethtool_id)) {
|
||||
switch (nm_ethtool_id_to_type(ethtool_id)) {
|
||||
case NM_ETHTOOL_TYPE_COALESCE:
|
||||
case NM_ETHTOOL_TYPE_RING:
|
||||
i64 = _nm_utils_ascii_str_to_int64(value, 10, 0, G_MAXUINT32, -1);
|
||||
if (i64 == -1) {
|
||||
nm_utils_error_set(
|
||||
|
@ -4468,25 +4475,27 @@ _set_fcn_ethtool(ARGS_SET_FCN)
|
|||
|
||||
nm_setting_option_set_uint32(setting, nm_ethtool_data[ethtool_id]->optname, i64);
|
||||
return TRUE;
|
||||
case NM_ETHTOOL_TYPE_FEATURE:
|
||||
case NM_ETHTOOL_TYPE_PAUSE:
|
||||
if (!nmc_string_to_ternary_full(value,
|
||||
NMC_STRING_TO_TERNARY_FLAGS_IGNORE_FOR_DEFAULT,
|
||||
&t,
|
||||
NULL)) {
|
||||
nm_utils_error_set(error,
|
||||
NM_UTILS_ERROR_INVALID_ARGUMENT,
|
||||
_("'%s' is not valid; use 'on', 'off', or 'ignore'"),
|
||||
value);
|
||||
return FALSE;
|
||||
}
|
||||
if (t == NM_TERNARY_DEFAULT)
|
||||
goto do_unset;
|
||||
|
||||
nm_setting_option_set_boolean(setting, nm_ethtool_data[ethtool_id]->optname, !!t);
|
||||
return TRUE;
|
||||
case NM_ETHTOOL_TYPE_UNKNOWN:
|
||||
nm_assert_not_reached();
|
||||
}
|
||||
|
||||
nm_assert(nm_ethtool_id_is_feature(ethtool_id) || nm_ethtool_id_is_pause(ethtool_id));
|
||||
|
||||
if (!nmc_string_to_ternary_full(value,
|
||||
NMC_STRING_TO_TERNARY_FLAGS_IGNORE_FOR_DEFAULT,
|
||||
&t,
|
||||
NULL)) {
|
||||
nm_utils_error_set(error,
|
||||
NM_UTILS_ERROR_INVALID_ARGUMENT,
|
||||
_("'%s' is not valid; use 'on', 'off', or 'ignore'"),
|
||||
value);
|
||||
return FALSE;
|
||||
}
|
||||
if (t == NM_TERNARY_DEFAULT)
|
||||
goto do_unset;
|
||||
|
||||
nm_setting_option_set_boolean(setting, nm_ethtool_data[ethtool_id]->optname, !!t);
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
|
||||
do_unset:
|
||||
nm_setting_option_set(setting, nm_ethtool_data[ethtool_id]->optname, NULL);
|
||||
|
|
|
@ -111,10 +111,17 @@ get_ethtool_format(const NMMetaPropertyInfo *prop_info)
|
|||
|
||||
ethtool_id = prop_info->property_typ_data->subtype.ethtool.ethtool_id;
|
||||
|
||||
if (nm_ethtool_id_is_coalesce(ethtool_id) || nm_ethtool_id_is_ring(ethtool_id))
|
||||
switch (nm_ethtool_id_to_type(ethtool_id)) {
|
||||
case NM_ETHTOOL_TYPE_COALESCE:
|
||||
case NM_ETHTOOL_TYPE_RING:
|
||||
return g_strdup("integer");
|
||||
else if (nm_ethtool_id_is_feature(ethtool_id) || nm_ethtool_id_is_pause(ethtool_id))
|
||||
case NM_ETHTOOL_TYPE_FEATURE:
|
||||
case NM_ETHTOOL_TYPE_PAUSE:
|
||||
return g_strdup("ternary");
|
||||
case NM_ETHTOOL_TYPE_UNKNOWN:
|
||||
nm_assert_not_reached();
|
||||
};
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -301,10 +308,18 @@ append_ethtool_valid_values(const NMMetaPropertyInfo *prop_info, GPtrArray *vali
|
|||
|
||||
ethtool_id = prop_info->property_typ_data->subtype.ethtool.ethtool_id;
|
||||
|
||||
if (nm_ethtool_id_is_coalesce(ethtool_id) || nm_ethtool_id_is_ring(ethtool_id))
|
||||
switch (nm_ethtool_id_to_type(ethtool_id)) {
|
||||
case NM_ETHTOOL_TYPE_COALESCE:
|
||||
case NM_ETHTOOL_TYPE_RING:
|
||||
g_ptr_array_add(valid_values, g_strdup_printf("0 - %u", G_MAXUINT32));
|
||||
else if (nm_ethtool_id_is_feature(ethtool_id) || nm_ethtool_id_is_pause(ethtool_id))
|
||||
break;
|
||||
case NM_ETHTOOL_TYPE_FEATURE:
|
||||
case NM_ETHTOOL_TYPE_PAUSE:
|
||||
append_vals(valid_values, "on", "off", "ignore");
|
||||
break;
|
||||
case NM_ETHTOOL_TYPE_UNKNOWN:
|
||||
nm_assert_not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in a new issue