Commit df30651b authored by Thomas Haller's avatar Thomas Haller

libnm, cli, ifcfg-rh: add NMSettingEthtool setting

Note that in NetworkManager API (D-Bus, libnm, and nmcli),
the features are called "feature-xyz". The "feature-" prefix
is used, because NMSettingEthtool possibly will gain support
for options that are not only -K|--offload|--features, for
example -C|--coalesce.

The "xzy" suffix is either how ethtool utility calls the feature
("tso", "rx"). Or, if ethtool utility specifies no alias for that
feature, it's the name from kernel's ETH_SS_FEATURES ("tx-tcp6-segmentation").
If possible, we prefer ethtool utility's naming.

Also note, how the features "feature-sg", "feature-tso", and
"feature-tx" actually refer to multiple underlying kernel features
at once. This too follows what ethtool utility does.

The functionality is not yet implemented server-side.
parent 4e0f1b16
......@@ -453,6 +453,7 @@ libnm_core_lib_h_pub_real = \
libnm-core/nm-setting-connection.h \
libnm-core/nm-setting-dcb.h \
libnm-core/nm-setting-dummy.h \
libnm-core/nm-setting-ethtool.h \
libnm-core/nm-setting-generic.h \
libnm-core/nm-setting-gsm.h \
libnm-core/nm-setting-infiniband.h \
......@@ -502,6 +503,7 @@ libnm_core_lib_h_priv = \
shared/nm-utils/nm-shared-utils.h \
shared/nm-utils/nm-random-utils.h \
shared/nm-utils/nm-udev-utils.h \
shared/nm-ethtool-utils.h \
shared/nm-meta-setting.h \
libnm-core/crypto.h \
libnm-core/nm-connection-private.h \
......@@ -524,6 +526,7 @@ libnm_core_lib_c_settings_real = \
libnm-core/nm-setting-connection.c \
libnm-core/nm-setting-dcb.c \
libnm-core/nm-setting-dummy.c \
libnm-core/nm-setting-ethtool.c \
libnm-core/nm-setting-generic.c \
libnm-core/nm-setting-gsm.c \
libnm-core/nm-setting-infiniband.c \
......@@ -565,6 +568,7 @@ libnm_core_lib_c_real = \
shared/nm-utils/nm-shared-utils.c \
shared/nm-utils/nm-random-utils.c \
shared/nm-utils/nm-udev-utils.c \
shared/nm-ethtool-utils.c \
shared/nm-meta-setting.c \
libnm-core/crypto.c \
libnm-core/nm-connection.c \
......@@ -2390,6 +2394,7 @@ EXTRA_DIST += \
src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3.expected \
src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4 \
src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4.expected \
src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test_write_wired_auto_negotiate_on.cexpected \
src/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-dynamic-wep-leap \
src/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-leap \
src/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wep \
......@@ -3425,6 +3430,9 @@ clients_common_libnmc_la_SOURCES = \
shared/nm-meta-setting.c \
shared/nm-meta-setting.h \
\
shared/nm-ethtool-utils.c \
shared/nm-ethtool-utils.h \
\
clients/common/nm-meta-setting-desc.c \
clients/common/nm-meta-setting-desc.h \
clients/common/nm-meta-setting-access.c \
......
......@@ -770,7 +770,8 @@ const NmcMetaGenericInfo *const metagen_con_active_vpn[_NMC_GENERIC_INFO_TYPE_CO
NM_SETTING_6LOWPAN_SETTING_NAME","\
NM_SETTING_PROXY_SETTING_NAME"," \
NM_SETTING_TC_CONFIG_SETTING_NAME"," \
NM_SETTING_SRIOV_SETTING_NAME
NM_SETTING_SRIOV_SETTING_NAME"," \
NM_SETTING_ETHTOOL_SETTING_NAME
// NM_SETTING_DUMMY_SETTING_NAME
// NM_SETTING_WIMAX_SETTING_NAME
......
......@@ -59,7 +59,7 @@ libnmc = static_library(
sources: files(
'nm-meta-setting-access.c',
'nm-meta-setting-desc.c'
) + shared_nm_meta_setting_c + [settings_docs_source],
) + shared_nm_meta_setting_c + shared_nm_ethtool_utils_c + [settings_docs_source],
dependencies: deps,
c_args: cflags,
link_with: libnmc_base,
......
This diff is collapsed.
......@@ -22,6 +22,7 @@
#include "nm-utils/nm-obj.h"
#include "nm-meta-setting.h"
#include "nm-ethtool-utils.h"
struct _NMDevice;
......@@ -263,6 +264,9 @@ struct _NMMetaPropertyTypData {
struct {
NMMetaPropertyTypeMacMode mode;
} mac;
struct {
NMEthtoolID ethtool_id;
} ethtool;
} subtype;
const char *const*values_static;
const NMMetaPropertyTypDataNested *nested;
......
......@@ -202,6 +202,7 @@ print ("NetworkManager version " + client.get_version())]]></programlisting></in
<xi:include href="xml/nm-setting-cdma.xml"/>
<xi:include href="xml/nm-setting-dcb.xml"/>
<xi:include href="xml/nm-setting-dummy.xml"/>
<xi:include href="xml/nm-setting-ethtool.xml"/>
<xi:include href="xml/nm-setting-generic.xml"/>
<xi:include href="xml/nm-setting-gsm.xml"/>
<xi:include href="xml/nm-setting-infiniband.xml"/>
......
......@@ -69,6 +69,7 @@ libnm_core_settings_sources = files(
'nm-setting-connection.c',
'nm-setting-dcb.c',
'nm-setting-dummy.c',
'nm-setting-ethtool.c',
'nm-setting-generic.c',
'nm-setting-gsm.c',
'nm-setting-infiniband.c',
......@@ -154,6 +155,7 @@ endif
libnm_core_sources_all = libnm_core_sources
libnm_core_sources_all += libnm_core_enum
libnm_core_sources_all += shared_nm_meta_setting_c
libnm_core_sources_all += shared_nm_ethtool_utils_c
libnm_core_sources_all += shared_files_libnm_core
libnm_core_sources_all += [version_header]
......
......@@ -201,6 +201,11 @@ GVariant *const*nm_setting_gendata_get_all_values (NMSetting *setting);
/*****************************************************************************/
guint nm_setting_ethtool_init_features (NMSettingEthtool *setting,
NMTernary *requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */);
/*****************************************************************************/
#define NM_UTILS_HWADDR_LEN_MAX_STR (NM_UTILS_HWADDR_LEN_MAX * 3)
guint8 *_nm_utils_hwaddr_aton (const char *asc, gpointer buffer, gsize buffer_length, gsize *out_length);
......
......@@ -40,6 +40,7 @@ typedef struct _NMSettingCdma NMSettingCdma;
typedef struct _NMSettingConnection NMSettingConnection;
typedef struct _NMSettingDcb NMSettingDcb;
typedef struct _NMSettingDummy NMSettingDummy;
typedef struct _NMSettingEthtool NMSettingEthtool;
typedef struct _NMSettingGeneric NMSettingGeneric;
typedef struct _NMSettingGsm NMSettingGsm;
typedef struct _NMSettingInfiniband NMSettingInfiniband;
......
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2018 Red Hat, Inc.
*/
#include "nm-default.h"
#include "nm-setting-ethtool.h"
#include "nm-setting-private.h"
#include "nm-ethtool-utils.h"
/*****************************************************************************/
/**
* SECTION:nm-setting-ethtool
* @short_description: Describes connection properties for ethtool related options
*
* The #NMSettingEthtool object is a #NMSetting subclass that describes properties
* to control network driver and hardware settings.
**/
/*****************************************************************************/
/**
* nm_ethtool_optname_is_feature:
* @optname: the option name to check
*
* Checks whether @optname is a valid option name for an offload feature.
*
* %Returns: %TRUE, if @optname is valid
*
* Since: 1.14
*/
gboolean
nm_ethtool_optname_is_feature (const char *optname)
{
return optname && nm_ethtool_id_is_feature (nm_ethtool_id_get_by_name (optname));
}
/*****************************************************************************/
/**
* NMSettingEthtool:
*
* Ethtool Ethernet Settings
*
* Since: 1.14
*/
struct _NMSettingEthtool {
NMSetting parent;
};
struct _NMSettingEthtoolClass {
NMSettingClass parent;
};
G_DEFINE_TYPE (NMSettingEthtool, nm_setting_ethtool, NM_TYPE_SETTING)
#define NM_SETTING_ETHTOOL_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMSettingEthtool, NM_IS_SETTING_ETHTOOL, NMSetting)
/*****************************************************************************/
static void
_notify_attributes (NMSettingEthtool *self)
{
_nm_setting_gendata_notify (NM_SETTING (self), TRUE);
}
/*****************************************************************************/
/**
* nm_setting_ethtool_get_feature:
* @setting: the #NMSettingEthtool
* @optname: option name of the offload feature to get
*
* Gets and offload feature setting. Returns %NM_TERNARY_DEFAULT if the
* feature is not set.
*
* Returns: a #NMTernary value indicating whether the offload feature
* is enabled, disabled, or left untouched.
*
* Since: 1.14
*/
NMTernary
nm_setting_ethtool_get_feature (NMSettingEthtool *setting,
const char *optname)
{
GVariant *v;
g_return_val_if_fail (NM_IS_SETTING_ETHTOOL (setting), NM_TERNARY_DEFAULT);
g_return_val_if_fail (optname && nm_ethtool_optname_is_feature (optname), NM_TERNARY_DEFAULT);
v = nm_setting_gendata_get (NM_SETTING (setting), optname);
if ( v
&& g_variant_is_of_type (v, G_VARIANT_TYPE_BOOLEAN)) {
return g_variant_get_boolean (v)
? NM_TERNARY_TRUE
: NM_TERNARY_FALSE;
}
return NM_TERNARY_DEFAULT;
}
/**
* nm_setting_ethtool_set_feature:
* @setting: the #NMSettingEthtool
* @optname: option name of the offload feature to get
* @value: the new value to set. The special value %NM_TERNARY_DEFAULT
* means to clear the offload feature setting.
*
* Sets and offload feature setting.
*
* Since: 1.14
*/
void
nm_setting_ethtool_set_feature (NMSettingEthtool *setting,
const char *optname,
NMTernary value)
{
GHashTable *hash;
GVariant *v;
g_return_if_fail (NM_IS_SETTING_ETHTOOL (setting));
g_return_if_fail (optname && nm_ethtool_optname_is_feature (optname));
g_return_if_fail (NM_IN_SET (value, NM_TERNARY_DEFAULT,
NM_TERNARY_FALSE,
NM_TERNARY_TRUE));
hash = _nm_setting_gendata_hash (NM_SETTING (setting),
value != NM_TERNARY_DEFAULT);
if (value == NM_TERNARY_DEFAULT) {
if (hash) {
if (g_hash_table_remove (hash, optname))
_notify_attributes (setting);
}
return;
}
v = g_hash_table_lookup (hash, optname);
if ( v
&& g_variant_is_of_type (v, G_VARIANT_TYPE_BOOLEAN)) {
if (g_variant_get_boolean (v)) {
if (value == NM_TERNARY_TRUE)
return;
} else {
if (value == NM_TERNARY_FALSE)
return;
}
}
v = g_variant_ref_sink (g_variant_new_boolean (value != NM_TERNARY_FALSE));
g_hash_table_insert (hash,
g_strdup (optname),
v);
_notify_attributes (setting);
}
/**
* nm_setting_ethtool_clear_features:
* @setting: the #NMSettingEthtool
*
* Clears all offload features settings
*
* Since: 1.14
*/
void
nm_setting_ethtool_clear_features (NMSettingEthtool *setting)
{
GHashTable *hash;
GHashTableIter iter;
const char *name;
gboolean changed = FALSE;
g_return_if_fail (NM_IS_SETTING_ETHTOOL (setting));
hash = _nm_setting_gendata_hash (NM_SETTING (setting), FALSE);
if (!hash)
return;
g_hash_table_iter_init (&iter, hash);
while (g_hash_table_iter_next (&iter, (gpointer *) &name, NULL)) {
if (nm_ethtool_optname_is_feature (name)) {
g_hash_table_iter_remove (&iter);
changed = TRUE;
}
}
if (changed)
_notify_attributes (setting);
}
guint
nm_setting_ethtool_init_features (NMSettingEthtool *setting,
NMTernary *requested /* indexed by NMEthtoolID - _NM_ETHTOOL_ID_FEATURE_FIRST */)
{
GHashTable *hash;
GHashTableIter iter;
guint i;
guint n_req = 0;
const char *name;
GVariant *variant;
nm_assert (NM_IS_SETTING_ETHTOOL (setting));
nm_assert (requested);
for (i = 0; i < _NM_ETHTOOL_ID_FEATURE_NUM; i++)
requested[i] = NM_TERNARY_DEFAULT;
hash = _nm_setting_gendata_hash (NM_SETTING (setting), FALSE);
if (!hash)
return 0;
g_hash_table_iter_init (&iter, hash);
while (g_hash_table_iter_next (&iter, (gpointer *) &name, (gpointer *) &variant)) {
NMEthtoolID ethtool_id = nm_ethtool_id_get_by_name (name);
if (!nm_ethtool_id_is_feature (ethtool_id))
continue;
if (!g_variant_is_of_type (variant, G_VARIANT_TYPE_BOOLEAN))
continue;
requested[ethtool_id - _NM_ETHTOOL_ID_FEATURE_FIRST] = g_variant_get_boolean (variant)
? NM_TERNARY_TRUE
: NM_TERNARY_FALSE;
n_req++;
}
return n_req;
}
/*****************************************************************************/
static gboolean
verify (NMSetting *setting, NMConnection *connection, GError **error)
{
GHashTable *hash;
GHashTableIter iter;
const char *optname;
GVariant *variant;
hash = _nm_setting_gendata_hash (setting, FALSE);
if (!hash)
goto out;
g_hash_table_iter_init (&iter, hash);
while (g_hash_table_iter_next (&iter, (gpointer *) &optname, (gpointer *) &variant)) {
if (!nm_ethtool_optname_is_feature (optname)) {
g_set_error_literal (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
_("unsupported offload feature"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_ETHTOOL_SETTING_NAME, optname);
return FALSE;
}
if (!g_variant_is_of_type (variant, G_VARIANT_TYPE_BOOLEAN)) {
g_set_error_literal (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
_("offload feature has invalid variant type"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_ETHTOOL_SETTING_NAME, optname);
return FALSE;
}
}
out:
return TRUE;
}
/*****************************************************************************/
static const GVariantType *
get_variant_type (const NMSettInfoSetting *sett_info,
const char *name,
GError **error)
{
if (nm_ethtool_optname_is_feature (name))
return G_VARIANT_TYPE_BOOLEAN;
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
_("unknown ethtool option '%s'"),
name);
return NULL;
}
/*****************************************************************************/
static void
nm_setting_ethtool_init (NMSettingEthtool *setting)
{
}
/**
* nm_setting_ethtool_new:
*
* Creates a new #NMSettingEthtool object with default values.
*
* Returns: (transfer full): the new empty #NMSettingEthtool object
*
* Since: 1.14
**/
NMSetting *
nm_setting_ethtool_new (void)
{
return g_object_new (NM_TYPE_SETTING_ETHTOOL, NULL);
}
static void
nm_setting_ethtool_class_init (NMSettingEthtoolClass *klass)
{
NMSettingClass *setting_class = NM_SETTING_CLASS (klass);
setting_class->verify = verify;
_nm_setting_class_commit_full (setting_class,
NM_META_SETTING_TYPE_ETHTOOL,
NM_SETT_INFO_SETT_DETAIL (
.gendata_info = NM_SETT_INFO_SETT_GENDATA (
.get_variant_type = get_variant_type,
),
),
NULL);
}
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2018 Red Hat, Inc.
*/
#ifndef __NM_SETTING_ETHTOOL_H__
#define __NM_SETTING_ETHTOOL_H__
#if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION)
#error "Only <NetworkManager.h> can be included directly."
#endif
#include "nm-setting.h"
G_BEGIN_DECLS
/*****************************************************************************/
#define NM_ETHTOOL_OPTNAME_FEATURE_GRO "feature-gro"
#define NM_ETHTOOL_OPTNAME_FEATURE_GSO "feature-gso"
#define NM_ETHTOOL_OPTNAME_FEATURE_LRO "feature-lro"
#define NM_ETHTOOL_OPTNAME_FEATURE_NTUPLE "feature-ntuple"
#define NM_ETHTOOL_OPTNAME_FEATURE_RX "feature-rx"
#define NM_ETHTOOL_OPTNAME_FEATURE_RXHASH "feature-rxhash"
#define NM_ETHTOOL_OPTNAME_FEATURE_RXVLAN "feature-rxvlan"
#define NM_ETHTOOL_OPTNAME_FEATURE_SG "feature-sg"
#define NM_ETHTOOL_OPTNAME_FEATURE_TSO "feature-tso"
#define NM_ETHTOOL_OPTNAME_FEATURE_TX "feature-tx"
#define NM_ETHTOOL_OPTNAME_FEATURE_TXVLAN "feature-txvlan"
gboolean nm_ethtool_optname_is_feature (const char *optname);
/*****************************************************************************/
#define NM_TYPE_SETTING_ETHTOOL (nm_setting_ethtool_get_type ())
#define NM_SETTING_ETHTOOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_ETHTOOL, NMSettingEthtool))
#define NM_SETTING_ETHTOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_ETHTOOL, NMSettingEthtoolClass))
#define NM_IS_SETTING_ETHTOOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_ETHTOOL))
#define NM_IS_SETTING_ETHTOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_ETHTOOL))
#define NM_SETTING_ETHTOOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_ETHTOOL, NMSettingEthtoolClass))
#define NM_SETTING_ETHTOOL_SETTING_NAME "ethtool"
/*****************************************************************************/
typedef struct _NMSettingEthtoolClass NMSettingEthtoolClass;
NM_AVAILABLE_IN_1_14
GType nm_setting_ethtool_get_type (void);
NM_AVAILABLE_IN_1_14
NMSetting *nm_setting_ethtool_new (void);
/*****************************************************************************/
NM_AVAILABLE_IN_1_14
NMTernary nm_setting_ethtool_get_feature (NMSettingEthtool *setting,
const char *optname);
NM_AVAILABLE_IN_1_14
void nm_setting_ethtool_set_feature (NMSettingEthtool *setting,
const char *optname,
NMTernary value);
NM_AVAILABLE_IN_1_14
void nm_setting_ethtool_clear_features (NMSettingEthtool *setting);
G_END_DECLS
#endif /* __NM_SETTING_ETHTOOL_H__ */
......@@ -2095,6 +2095,20 @@ _nm_setting_gendata_notify (NMSetting *setting,
* values cache. Otherwise, the names cache must be invalidated too. */
nm_clear_g_free (&gendata->names);
}
/* Note, that currently there is now way to notify the subclass when gendata changed.
* gendata is only changed in two situations:
* 1) from within NMSetting itself, for example when creating a NMSetting instance
* from keyfile or a D-Bus GVariant.
* 2) actively from the subclass itself
* For 2), we don't need the notification, because the subclass knows that something
* changed.
* For 1), we currently don't need the notification either, because all that the subclass
* currently would do, is emit a g_object_notify() signal. However, 1) only happens when
* the setting instance is newly created, at that point, nobody listens to the signal.
*
* If we ever need it, then we would need to call a virtual function to notify the subclass
* that gendata changed. */
}
GVariant *
......
......@@ -43,6 +43,7 @@
#include "nm-setting-bridge-port.h"
#include "nm-setting-cdma.h"
#include "nm-setting-connection.h"
#include "nm-setting-ethtool.h"
#include "nm-setting-generic.h"
#include "nm-setting-gsm.h"
#include "nm-setting-infiniband.h"
......@@ -65,6 +66,7 @@
#include "nm-simple-connection.h"
#include "nm-keyfile-internal.h"
#include "nm-utils/nm-dedup-multi.h"
#include "nm-ethtool-utils.h"
#include "test-general-enums.h"
......@@ -7058,6 +7060,22 @@ test_nm_va_args_macros (void)
/*****************************************************************************/
static void
test_ethtool_offload (void)
{
const NMEthtoolData *d;
g_assert_cmpint (nm_ethtool_id_get_by_name ("invalid"), ==, NM_ETHTOOL_ID_UNKNOWN);
g_assert_cmpint (nm_ethtool_id_get_by_name ("feature-rx"), ==, NM_ETHTOOL_ID_FEATURE_RX);
d = nm_ethtool_data_get_by_optname (NM_ETHTOOL_OPTNAME_FEATURE_RXHASH);
g_assert (d);
g_assert_cmpint (d->id, ==, NM_ETHTOOL_ID_FEATURE_RXHASH);
g_assert_cmpstr (d->optname, ==, NM_ETHTOOL_OPTNAME_FEATURE_RXHASH);
}
/*****************************************************************************/
NMTST_DEFINE ();
int main (int argc, char **argv)
......@@ -7212,8 +7230,8 @@ int main (int argc, char **argv)
g_test_add_func ("/core/general/route_attributes/format", test_route_attributes_format);
g_test_add_func ("/core/general/get_start_time_for_pid", test_get_start_time_for_pid);
g_test_add_func ("/core/general/test_nm_va_args_macros", test_nm_va_args_macros);
g_test_add_func ("/core/general/test_ethtool_offload", test_ethtool_offload);
return g_test_run ();
}
......
......@@ -28,6 +28,7 @@
#include "nm-setting-8021x.h"
#include "nm-setting-bond.h"
#include "nm-setting-dcb.h"
#include "nm-setting-ethtool.h"
#include "nm-setting-team.h"
#include "nm-setting-team-port.h"
#include "nm-setting-tc-config.h"
......@@ -36,6 +37,7 @@
#include "nm-simple-connection.h"
#include "nm-setting-connection.h"
#include "nm-errors.h"
#include "nm-keyfile-internal.h"
#include "nm-utils/nm-test-utils.h"
......@@ -1264,6 +1266,79 @@ test_team_port_full_config (void)
/*****************************************************************************/
static void
test_ethtool_1 (void)
{
gs_unref_object NMConnection *con = NULL;
gs_unref_object NMConnection *con2 = NULL;
gs_unref_object NMConnection *con3 = NULL;
gs_unref_variant GVariant *variant = NULL;
gs_free_error GError *error = NULL;
gs_unref_keyfile GKeyFile *keyfile = NULL;
NMSettingConnection *s_con;
NMSettingEthtool *s_ethtool;
NMSettingEthtool *s_ethtool2;
NMSettingEthtool *s_ethtool3;
con = nmtst_create_minimal_connection ("ethtool-1",
NULL,
NM_SETTING_WIRED_SETTING_NAME,
&s_con);
s_ethtool = NM_SETTING_ETHTOOL (nm_setting_ethtool_new ());
nm_connection_add_setting (con, NM_SETTING (s_ethtool));
nm_setting_ethtool_set_feature (s_ethtool,
NM_ETHTOOL_OPTNAME_FEATURE_RX,
NM_TERNARY_TRUE);
nm_setting_ethtool_set_feature (s_ethtool,
NM_ETHTOOL_OPTNAME_FEATURE_LRO,
NM_TERNARY_FALSE);
g_assert_cmpint (nm_setting_ethtool_get_feature (s_ethtool, NM_ETHTOOL_OPTNAME_FEATURE_RX), ==, NM_TERNARY_TRUE);
g_assert_cmpint (nm_setting_ethtool_get_feature (s_ethtool, NM_ETHTOOL_OPTNAME_FEATURE_LRO), ==, NM_TERNARY_FALSE);
g_assert_cmpint (nm_setting_ethtool_get_feature (s_ethtool, NM_ETHTOOL_OPTNAME_FEATURE_SG), ==, NM_TERNARY_DEFAULT);
nmtst_connection_normalize (con);
variant = nm_connection_to_dbus (con, NM_CONNECTION_SERIALIZE_ALL);
con2 = nm_simple_connection_new_from_dbus (variant, &error);
nmtst_assert_success (con2, error);
s_ethtool2 = NM_SETTING_ETHTOOL (nm_connection_get_setting (con2, NM_TYPE_SETTING_ETHTOOL));
g_assert_cmpint (nm_setting_ethtool_get_feature (s_ethtool2, NM_ETHTOOL_OPTNAME_FEATURE_RX), ==, NM_TERNARY_TRUE);
g_assert_cmpint (nm_setting_ethtool_get_feature (s_ethtool2, NM_ETHTOOL_OPTNAME_FEATURE_LRO), ==, NM_TERNARY_FALSE);
g_assert_cmpint (nm_setting_ethtool_get_feature (s_ethtool2, NM_ETHTOOL_OPTNAME_FEATURE_SG), ==, NM_TERNARY_DEFAULT);
nmtst_assert_connection_verifies_without_normalization (con2);
nmtst_assert_connection_equals (con, FALSE, con2, FALSE);
keyfile = nm_keyfile_write (con, NULL, NULL, &error);
nmtst_assert_success (keyfile, error);
con3 = nm_keyfile_read (keyfile,
"ethtool-keyfile-name",
NULL,
NULL,
NULL,
&error);
nmtst_assert_success (con3, error);
nmtst_connection_normalize (con3);
nmtst_assert_connection_equals (con, FALSE, con3, FALSE);
s_ethtool3 = NM_SETTING_ETHTOOL (nm_connection_get_setting (con3, NM_TYPE_SETTING_ETHTOOL));
g_assert_cmpint (nm_setting_ethtool_get_feature (s_ethtool3, NM_ETHTOOL_OPTNAME_FEATURE_RX), ==, NM_TERNARY_TRUE);
g_assert_cmpint (nm_setting_ethtool_get_feature (s_ethtool3, NM_ETHTOOL_OPTNAME_FEATURE_LRO), ==, NM_TERNARY_FALSE);
g_assert_cmpint (nm_setting_ethtool_get_feature (s_ethtool3, NM_ETHTOOL_OPTNAME_FEATURE_SG), ==, NM_TERNARY_DEFAULT);
}
/*****************************************************************************/
static void