libnm: add nm_setting_ethtool_get_optnames() function

It's rather limiting if we have no API to ask NMSettingEthtool which
options are set.

Note that currently NMSettingEthtool only supports offload features.
In the future, it should also support other options like coalesce
or ring options. Hence, this returns all option names, not only
features.

If a caller needs to know whether the name is an option name, he/she
should call nm_ethtool_optname_is_feature().
This commit is contained in:
Thomas Haller 2019-06-11 11:20:53 +02:00
parent 1850dc4952
commit 356a159731
3 changed files with 39 additions and 0 deletions

View file

@ -91,6 +91,9 @@ _notify_attributes (NMSettingEthtool *self)
* Gets and offload feature setting. Returns %NM_TERNARY_DEFAULT if the
* feature is not set.
*
* Note that @optname must be a valid name for a feature, according to
* nm_ethtool_optname_is_feature().
*
* Returns: a #NMTernary value indicating whether the offload feature
* is enabled, disabled, or left untouched.
*
@ -124,6 +127,9 @@ nm_setting_ethtool_get_feature (NMSettingEthtool *setting,
*
* Sets and offload feature setting.
*
* Note that @optname must be a valid name for a feature, according to
* nm_ethtool_optname_is_feature().
*
* Since: 1.14
*/
void
@ -245,6 +251,34 @@ nm_setting_ethtool_init_features (NMSettingEthtool *setting,
/*****************************************************************************/
/**
* nm_setting_ethtool_get_optnames:
* @setting: the #NMSettingEthtool instance.
* @out_length: (out) (optional): return location for the number of keys returned, or %NULL
*
* This returns all options names that are set. This includes the feature names
* like %NM_ETHTOOL_OPTNAME_FEATURE_GRO. See nm_ethtool_optname_is_feature() to
* check whether the option name is valid for offload features.
*
* Returns: (array zero-terminated=1) (transfer container): list of set option
* names or %NULL if no options are set. The option names are still owned by
* @setting and may get invalidated when @setting gets modified.
*
* Since: 1.20
*/
const char **
nm_setting_ethtool_get_optnames (NMSettingEthtool *setting,
guint *out_length)
{
g_return_val_if_fail (NM_IS_SETTING_ETHTOOL (setting), NULL);
return nm_utils_strdict_get_keys (_nm_setting_gendata_hash (NM_SETTING (setting), FALSE),
TRUE,
out_length);
}
/*****************************************************************************/
static gboolean
verify (NMSetting *setting, NMConnection *connection, GError **error)
{

View file

@ -119,6 +119,10 @@ void nm_setting_ethtool_set_feature (NMSettingEthtool *setting,
NM_AVAILABLE_IN_1_14
void nm_setting_ethtool_clear_features (NMSettingEthtool *setting);
NM_AVAILABLE_IN_1_20
const char ** nm_setting_ethtool_get_optnames (NMSettingEthtool *setting,
guint *out_length);
G_END_DECLS
#endif /* __NM_SETTING_ETHTOOL_H__ */

View file

@ -1610,4 +1610,5 @@ global:
nm_device_modem_get_apn;
nm_device_modem_get_device_id;
nm_device_modem_get_operator_code;
nm_setting_ethtool_get_optnames;
} libnm_1_18_0;