2019-09-10 11:19:01 +02:00
|
|
|
// SPDX-License-Identifier: LGPL-2.1+
|
2018-05-25 12:05:24 +02:00
|
|
|
/*
|
2019-10-01 09:20:35 +02:00
|
|
|
* Copyright (C) 2018 Red Hat, Inc.
|
2018-05-25 12:05:24 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "nm-default.h"
|
|
|
|
|
|
|
|
|
|
#include "nm-setting-sriov.h"
|
2019-01-11 08:32:54 +01:00
|
|
|
|
2018-05-25 12:05:24 +02:00
|
|
|
#include "nm-setting-private.h"
|
|
|
|
|
#include "nm-utils-private.h"
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* SECTION:nm-setting-sriov
|
|
|
|
|
* @short_description: Describes SR-IOV connection properties
|
|
|
|
|
* @include: nm-setting-sriov.h
|
|
|
|
|
**/
|
|
|
|
|
|
2019-01-11 08:32:54 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
NM_GOBJECT_PROPERTIES_DEFINE (NMSettingSriov,
|
|
|
|
|
PROP_TOTAL_VFS,
|
|
|
|
|
PROP_VFS,
|
|
|
|
|
PROP_AUTOPROBE_DRIVERS,
|
|
|
|
|
);
|
|
|
|
|
|
2018-05-25 12:05:24 +02:00
|
|
|
/**
|
|
|
|
|
* NMSettingSriov:
|
|
|
|
|
*
|
2020-03-10 11:47:46 +01:00
|
|
|
* SR-IOV settings
|
2018-05-25 12:05:24 +02:00
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
*/
|
|
|
|
|
struct _NMSettingSriov {
|
|
|
|
|
NMSetting parent;
|
|
|
|
|
GPtrArray *vfs;
|
|
|
|
|
guint total_vfs;
|
|
|
|
|
NMTernary autoprobe_drivers;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct _NMSettingSriovClass {
|
|
|
|
|
NMSettingClass parent;
|
|
|
|
|
};
|
|
|
|
|
|
libnm: use NMMetaSettingInfo for tracking setting priority
Previously, each (non abstract) NMSetting class had to register
its name and priority via _nm_register_setting().
Note, that libnm-core.la already links against "nm-meta-setting.c",
which also redundantly keeps track of the settings name and gtype
as well.
Re-use NMMetaSettingInfo also in libnm-core.la, to track this meta
data.
The goal is to get rid of private data structures that track
meta data about NMSetting classes. In this case, "registered_settings"
hash. Instead, we should have one place where all this meta data
is tracked. This was, it is also accessible as internal API,
which can be useful (for keyfile).
Note that NMSettingClass has some overlap with NMMetaSettingInfo.
One difference is, that NMMetaSettingInfo is const, while NMSettingClass
is only initialized during the class_init() method. Appart from that,
it's mostly a matter of taste, whether we attach meta data to
NMSettingClass, to NMMetaSettingInfo, or to a static-array indexed
by NMMetaSettingType.
Note, that previously, _nm_register_setting() was private API. That
means, no user could subclass a functioning NMSetting instance. The same
is still true: NMMetaSettingInfo is internal API and users cannot access
it to create their own NMSetting subclasses. But that is almost desired.
libnm is not designed, to be extensible via subclassing, nor is it
clear why that would be a useful thing to do. One day, we should remove
the NMSetting and NMSettingClass definitions from public headers. Their
only use is subclassing the types, which however does not work.
While libnm-core was linking already against nm-meta-setting.c,
nm_meta_setting_infos was unreferenced. So, this change increases
the binary size of libnm and NetworkManager (1032 bytes). Note however
that roughly the same information was previously allocated at runtime.
2018-07-27 14:08:14 +02:00
|
|
|
G_DEFINE_TYPE (NMSettingSriov, nm_setting_sriov, NM_TYPE_SETTING)
|
2018-05-25 12:05:24 +02:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
G_DEFINE_BOXED_TYPE (NMSriovVF, nm_sriov_vf, nm_sriov_vf_dup, nm_sriov_vf_unref)
|
|
|
|
|
|
|
|
|
|
struct _NMSriovVF {
|
|
|
|
|
guint refcount;
|
|
|
|
|
guint index;
|
|
|
|
|
GHashTable *attributes;
|
|
|
|
|
GHashTable *vlans;
|
|
|
|
|
guint *vlan_ids;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
guint id;
|
|
|
|
|
guint qos;
|
|
|
|
|
NMSriovVFVlanProtocol protocol;
|
|
|
|
|
} VFVlan;
|
|
|
|
|
|
|
|
|
|
static guint
|
|
|
|
|
_vf_vlan_hash (gconstpointer ptr)
|
|
|
|
|
{
|
|
|
|
|
return nm_hash_val (1348254767u, *((guint *) ptr));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
_vf_vlan_equal (gconstpointer a, gconstpointer b)
|
|
|
|
|
{
|
|
|
|
|
return *((guint *) a) == *((guint *) b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GHashTable *
|
|
|
|
|
_vf_vlan_create_hash (void)
|
|
|
|
|
{
|
|
|
|
|
G_STATIC_ASSERT_EXPR (G_STRUCT_OFFSET (VFVlan, id) == 0);
|
|
|
|
|
return g_hash_table_new_full (_vf_vlan_hash,
|
|
|
|
|
_vf_vlan_equal,
|
|
|
|
|
NULL,
|
|
|
|
|
nm_g_slice_free_fcn (VFVlan));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-03-19 15:04:54 +01:00
|
|
|
* nm_sriov_vf_new:
|
2018-05-25 12:05:24 +02:00
|
|
|
* @index: the VF index
|
|
|
|
|
*
|
|
|
|
|
* Creates a new #NMSriovVF object.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer full): the new #NMSriovVF object.
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
**/
|
|
|
|
|
NMSriovVF *
|
|
|
|
|
nm_sriov_vf_new (guint index)
|
|
|
|
|
{
|
|
|
|
|
NMSriovVF *vf;
|
|
|
|
|
|
2019-12-20 14:46:58 +01:00
|
|
|
vf = g_slice_new (NMSriovVF);
|
|
|
|
|
*vf = (NMSriovVF) {
|
|
|
|
|
.refcount = 1,
|
|
|
|
|
.index = index,
|
|
|
|
|
.attributes = g_hash_table_new_full (nm_str_hash,
|
|
|
|
|
g_str_equal,
|
|
|
|
|
g_free,
|
|
|
|
|
(GDestroyNotify) g_variant_unref),
|
|
|
|
|
};
|
2018-05-25 12:05:24 +02:00
|
|
|
return vf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_sriov_vf_ref:
|
|
|
|
|
* @vf: the #NMSriovVF
|
|
|
|
|
*
|
|
|
|
|
* Increases the reference count of the object.
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
nm_sriov_vf_ref (NMSriovVF *vf)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (vf);
|
|
|
|
|
g_return_if_fail (vf->refcount > 0);
|
|
|
|
|
|
|
|
|
|
vf->refcount++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_sriov_vf_unref:
|
|
|
|
|
* @vf: the #NMSriovVF
|
|
|
|
|
*
|
|
|
|
|
* Decreases the reference count of the object. If the reference count
|
|
|
|
|
* reaches zero, the object will be destroyed.
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
nm_sriov_vf_unref (NMSriovVF *vf)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (vf);
|
|
|
|
|
g_return_if_fail (vf->refcount > 0);
|
|
|
|
|
|
|
|
|
|
vf->refcount--;
|
|
|
|
|
if (vf->refcount == 0) {
|
|
|
|
|
g_hash_table_unref (vf->attributes);
|
|
|
|
|
if (vf->vlans)
|
|
|
|
|
g_hash_table_unref (vf->vlans);
|
|
|
|
|
g_free (vf->vlan_ids);
|
2019-12-20 14:46:58 +01:00
|
|
|
nm_g_slice_free (vf);
|
2018-05-25 12:05:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_sriov_vf_equal:
|
|
|
|
|
* @vf: the #NMSriovVF
|
|
|
|
|
* @other: the #NMSriovVF to compare @vf to.
|
|
|
|
|
*
|
|
|
|
|
* Determines if two #NMSriovVF objects have the same index,
|
|
|
|
|
* attributes and VLANs.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the objects contain the same values, %FALSE
|
|
|
|
|
* if they do not.
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
**/
|
|
|
|
|
gboolean
|
|
|
|
|
nm_sriov_vf_equal (const NMSriovVF *vf, const NMSriovVF *other)
|
|
|
|
|
{
|
|
|
|
|
GHashTableIter iter;
|
|
|
|
|
const char *key;
|
|
|
|
|
GVariant *value, *value2;
|
|
|
|
|
VFVlan *vlan, *vlan2;
|
|
|
|
|
guint n_vlans;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (vf, FALSE);
|
|
|
|
|
g_return_val_if_fail (vf->refcount > 0, FALSE);
|
|
|
|
|
g_return_val_if_fail (other, FALSE);
|
|
|
|
|
g_return_val_if_fail (other->refcount > 0, FALSE);
|
|
|
|
|
|
|
|
|
|
if (vf == other)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
if (vf->index != other->index)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (g_hash_table_size (vf->attributes) != g_hash_table_size (other->attributes))
|
|
|
|
|
return FALSE;
|
|
|
|
|
g_hash_table_iter_init (&iter, vf->attributes);
|
|
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &value)) {
|
|
|
|
|
value2 = g_hash_table_lookup (other->attributes, key);
|
|
|
|
|
if (!value2)
|
|
|
|
|
return FALSE;
|
|
|
|
|
if (!g_variant_equal (value, value2))
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n_vlans = vf->vlans ? g_hash_table_size (vf->vlans) : 0u;
|
|
|
|
|
if (n_vlans != (other->vlans ? g_hash_table_size (other->vlans) : 0u))
|
|
|
|
|
return FALSE;
|
|
|
|
|
if (n_vlans > 0) {
|
|
|
|
|
g_hash_table_iter_init (&iter, vf->vlans);
|
|
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer *) &vlan, NULL)) {
|
|
|
|
|
vlan2 = g_hash_table_lookup (other->vlans, vlan);
|
|
|
|
|
if (!vlan2)
|
|
|
|
|
return FALSE;
|
|
|
|
|
if ( vlan->qos != vlan2->qos
|
|
|
|
|
|| vlan->protocol != vlan2->protocol)
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
vf_add_vlan (NMSriovVF *vf,
|
|
|
|
|
guint vlan_id,
|
|
|
|
|
guint qos,
|
|
|
|
|
NMSriovVFVlanProtocol protocol)
|
|
|
|
|
{
|
|
|
|
|
VFVlan *vlan;
|
|
|
|
|
|
2019-12-20 14:46:58 +01:00
|
|
|
vlan = g_slice_new (VFVlan);
|
|
|
|
|
*vlan = (VFVlan) {
|
|
|
|
|
.id = vlan_id,
|
|
|
|
|
.qos = qos,
|
|
|
|
|
.protocol = protocol,
|
|
|
|
|
};
|
2018-05-25 12:05:24 +02:00
|
|
|
|
|
|
|
|
if (!vf->vlans)
|
|
|
|
|
vf->vlans = _vf_vlan_create_hash ();
|
|
|
|
|
|
|
|
|
|
g_hash_table_add (vf->vlans, vlan);
|
2020-03-23 11:00:43 +01:00
|
|
|
nm_clear_g_free (&vf->vlan_ids);
|
2018-05-25 12:05:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_sriov_vf_dup:
|
|
|
|
|
* @vf: the #NMSriovVF
|
|
|
|
|
*
|
|
|
|
|
* Creates a copy of @vf.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer full): a copy of @vf
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
**/
|
|
|
|
|
NMSriovVF *
|
|
|
|
|
nm_sriov_vf_dup (const NMSriovVF *vf)
|
|
|
|
|
{
|
|
|
|
|
NMSriovVF *copy;
|
|
|
|
|
GHashTableIter iter;
|
|
|
|
|
const char *name;
|
|
|
|
|
GVariant *variant;
|
|
|
|
|
VFVlan *vlan;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (vf, NULL);
|
|
|
|
|
g_return_val_if_fail (vf->refcount > 0, NULL);
|
|
|
|
|
|
|
|
|
|
copy = nm_sriov_vf_new (vf->index);
|
|
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, vf->attributes);
|
|
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer *) &name, (gpointer *) &variant))
|
|
|
|
|
nm_sriov_vf_set_attribute (copy, name, variant);
|
|
|
|
|
|
|
|
|
|
if (vf->vlans) {
|
|
|
|
|
g_hash_table_iter_init (&iter, vf->vlans);
|
|
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer *) &vlan, NULL))
|
|
|
|
|
vf_add_vlan (copy, vlan->id, vlan->qos, vlan->protocol);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_sriov_vf_get_index:
|
|
|
|
|
* @vf: the #NMSriovVF
|
|
|
|
|
*
|
|
|
|
|
* Gets the index property of this VF object.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the VF index
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
**/
|
|
|
|
|
guint
|
|
|
|
|
nm_sriov_vf_get_index (const NMSriovVF *vf)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (vf, 0);
|
|
|
|
|
g_return_val_if_fail (vf->refcount > 0, 0);
|
|
|
|
|
|
|
|
|
|
return vf->index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_sriov_vf_set_attribute:
|
|
|
|
|
* @vf: the #NMSriovVF
|
|
|
|
|
* @name: the name of a route attribute
|
|
|
|
|
* @value: (transfer none) (allow-none): the value
|
|
|
|
|
*
|
|
|
|
|
* Sets the named attribute on @vf to the given value.
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
nm_sriov_vf_set_attribute (NMSriovVF *vf, const char *name, GVariant *value)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (vf);
|
|
|
|
|
g_return_if_fail (vf->refcount > 0);
|
|
|
|
|
g_return_if_fail (name && *name != '\0');
|
|
|
|
|
g_return_if_fail (!nm_streq (name, "index"));
|
|
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
|
g_hash_table_insert (vf->attributes,
|
|
|
|
|
g_strdup (name),
|
|
|
|
|
g_variant_ref_sink (value));
|
|
|
|
|
} else
|
|
|
|
|
g_hash_table_remove (vf->attributes, name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_sriov_vf_get_attribute_names:
|
|
|
|
|
* @vf: the #NMSriovVF
|
|
|
|
|
*
|
|
|
|
|
* Gets an array of attribute names defined on @vf.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer container): a %NULL-terminated array of attribute names
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
**/
|
|
|
|
|
const char **
|
|
|
|
|
nm_sriov_vf_get_attribute_names (const NMSriovVF *vf)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (vf, NULL);
|
|
|
|
|
g_return_val_if_fail (vf->refcount > 0, NULL);
|
|
|
|
|
|
|
|
|
|
return nm_utils_strdict_get_keys (vf->attributes, TRUE, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_sriov_vf_get_attribute:
|
|
|
|
|
* @vf: the #NMSriovVF
|
|
|
|
|
* @name: the name of a VF attribute
|
|
|
|
|
*
|
|
|
|
|
* Gets the value of the attribute with name @name on @vf
|
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer none): the value of the attribute with name @name on
|
|
|
|
|
* @vf, or %NULL if @vf has no such attribute.
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
**/
|
|
|
|
|
GVariant *
|
|
|
|
|
nm_sriov_vf_get_attribute (const NMSriovVF *vf, const char *name)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (vf, NULL);
|
|
|
|
|
g_return_val_if_fail (vf->refcount > 0, NULL);
|
|
|
|
|
g_return_val_if_fail (name && *name != '\0', NULL);
|
|
|
|
|
|
|
|
|
|
return g_hash_table_lookup (vf->attributes, name);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-01 11:56:29 +02:00
|
|
|
const NMVariantAttributeSpec *const _nm_sriov_vf_attribute_spec[] = {
|
|
|
|
|
NM_VARIANT_ATTRIBUTE_SPEC_DEFINE (NM_SRIOV_VF_ATTRIBUTE_MAC, G_VARIANT_TYPE_STRING, .str_type = 'm', ),
|
|
|
|
|
NM_VARIANT_ATTRIBUTE_SPEC_DEFINE (NM_SRIOV_VF_ATTRIBUTE_SPOOF_CHECK, G_VARIANT_TYPE_BOOLEAN, ),
|
|
|
|
|
NM_VARIANT_ATTRIBUTE_SPEC_DEFINE (NM_SRIOV_VF_ATTRIBUTE_TRUST, G_VARIANT_TYPE_BOOLEAN, ),
|
|
|
|
|
NM_VARIANT_ATTRIBUTE_SPEC_DEFINE (NM_SRIOV_VF_ATTRIBUTE_MIN_TX_RATE, G_VARIANT_TYPE_UINT32, ),
|
|
|
|
|
NM_VARIANT_ATTRIBUTE_SPEC_DEFINE (NM_SRIOV_VF_ATTRIBUTE_MAX_TX_RATE, G_VARIANT_TYPE_UINT32, ),
|
2018-05-25 12:05:24 +02:00
|
|
|
/* D-Bus only, synthetic attributes */
|
2019-05-01 11:56:29 +02:00
|
|
|
NM_VARIANT_ATTRIBUTE_SPEC_DEFINE ("vlans", G_VARIANT_TYPE_STRING, .str_type = 'd', ),
|
2018-05-25 12:05:24 +02:00
|
|
|
NULL,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_sriov_vf_attribute_validate:
|
|
|
|
|
* @name: the attribute name
|
|
|
|
|
* @value: the attribute value
|
|
|
|
|
* @known: (out): on return, whether the attribute name is a known one
|
|
|
|
|
* @error: (allow-none): return location for a #GError, or %NULL
|
|
|
|
|
*
|
|
|
|
|
* Validates a VF attribute, i.e. checks that the attribute is a known one,
|
|
|
|
|
* the value is of the correct type and well-formed.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the attribute is valid, %FALSE otherwise
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
nm_sriov_vf_attribute_validate (const char *name,
|
|
|
|
|
GVariant *value,
|
|
|
|
|
gboolean *known,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
const NMVariantAttributeSpec *const *iter;
|
|
|
|
|
const NMVariantAttributeSpec *spec = NULL;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (name, FALSE);
|
|
|
|
|
g_return_val_if_fail (value, FALSE);
|
|
|
|
|
g_return_val_if_fail (!error || !*error, FALSE);
|
|
|
|
|
|
|
|
|
|
for (iter = _nm_sriov_vf_attribute_spec; *iter; iter++) {
|
|
|
|
|
if (nm_streq (name, (*iter)->name)) {
|
|
|
|
|
spec = *iter;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!spec || spec->str_type == 'd') {
|
|
|
|
|
NM_SET_OUT (known, FALSE);
|
|
|
|
|
g_set_error_literal (error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_FAILED,
|
|
|
|
|
_("unknown attribute"));
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NM_SET_OUT (known, TRUE);
|
|
|
|
|
|
|
|
|
|
if (!g_variant_is_of_type (value, spec->type)) {
|
|
|
|
|
g_set_error (error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_FAILED,
|
|
|
|
|
_("invalid attribute type '%s'"),
|
|
|
|
|
g_variant_get_type_string (value));
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-04 09:36:11 +02:00
|
|
|
if (g_variant_type_equal (spec->type, G_VARIANT_TYPE_STRING)) {
|
2018-05-25 12:05:24 +02:00
|
|
|
const char *string;
|
|
|
|
|
|
|
|
|
|
switch (spec->str_type) {
|
|
|
|
|
case 'm': /* MAC address */
|
|
|
|
|
string = g_variant_get_string (value, NULL);
|
|
|
|
|
if (!nm_utils_hwaddr_valid (string, -1)) {
|
|
|
|
|
g_set_error (error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_FAILED,
|
|
|
|
|
_("'%s' is not a valid MAC address"),
|
|
|
|
|
string);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
_nm_sriov_vf_attribute_validate_all (const NMSriovVF *vf, GError **error)
|
|
|
|
|
{
|
|
|
|
|
GHashTableIter iter;
|
|
|
|
|
const char *name;
|
|
|
|
|
GVariant *variant;
|
|
|
|
|
GVariant *min, *max;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (vf, FALSE);
|
|
|
|
|
g_return_val_if_fail (vf->refcount > 0, FALSE);
|
|
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, vf->attributes);
|
|
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer *) &name, (gpointer *) &variant)) {
|
|
|
|
|
if (!nm_sriov_vf_attribute_validate (name, variant, NULL, error)) {
|
|
|
|
|
g_prefix_error (error, "attribute '%s':", name);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
min = g_hash_table_lookup (vf->attributes, NM_SRIOV_VF_ATTRIBUTE_MIN_TX_RATE);
|
|
|
|
|
max = g_hash_table_lookup (vf->attributes, NM_SRIOV_VF_ATTRIBUTE_MAX_TX_RATE);
|
|
|
|
|
if ( min
|
|
|
|
|
&& max
|
|
|
|
|
&& g_variant_get_uint32 (min) > g_variant_get_uint32 (max)) {
|
|
|
|
|
g_set_error (error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_FAILED,
|
|
|
|
|
"min_tx_rate is greater than max_tx_rate");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_sriov_vf_add_vlan:
|
|
|
|
|
* @vf: the #NMSriovVF
|
|
|
|
|
* @vlan_id: the VLAN id
|
|
|
|
|
*
|
|
|
|
|
* Adds a VLAN to the VF.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the VLAN was added; %FALSE if it already existed
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
**/
|
|
|
|
|
gboolean
|
|
|
|
|
nm_sriov_vf_add_vlan (NMSriovVF *vf, guint vlan_id)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (vf, FALSE);
|
|
|
|
|
g_return_val_if_fail (vf->refcount > 0, FALSE);
|
|
|
|
|
|
|
|
|
|
if ( vf->vlans
|
|
|
|
|
&& g_hash_table_contains (vf->vlans, &vlan_id))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
vf_add_vlan (vf, vlan_id, 0, NM_SRIOV_VF_VLAN_PROTOCOL_802_1Q);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_sriov_vf_remove_vlan:
|
|
|
|
|
* @vf: the #NMSriovVF
|
|
|
|
|
* @vlan_id: the VLAN id
|
|
|
|
|
*
|
|
|
|
|
* Removes a VLAN from a VF.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the VLAN was removed, %FALSE if the VLAN @vlan_id
|
|
|
|
|
* did not belong to the VF.
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
nm_sriov_vf_remove_vlan (NMSriovVF *vf, guint vlan_id)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (vf, FALSE);
|
|
|
|
|
g_return_val_if_fail (vf->refcount > 0, FALSE);
|
|
|
|
|
|
|
|
|
|
if ( !vf->vlans
|
|
|
|
|
|| !g_hash_table_remove (vf->vlans, &vlan_id))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2020-03-23 11:00:43 +01:00
|
|
|
nm_clear_g_free (&vf->vlan_ids);
|
2018-05-25 12:05:24 +02:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
vlan_id_compare (gconstpointer a, gconstpointer b, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
guint id_a = *(guint *) a;
|
|
|
|
|
guint id_b = *(guint *) b;
|
|
|
|
|
|
|
|
|
|
if (id_a < id_b)
|
|
|
|
|
return -1;
|
|
|
|
|
else if (id_a > id_b)
|
|
|
|
|
return 1;
|
|
|
|
|
else return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_sriov_vf_get_vlan_ids:
|
|
|
|
|
* @vf: the #NMSriovVF
|
|
|
|
|
* @length: (out) (allow-none): on return, the number of VLANs configured
|
|
|
|
|
*
|
|
|
|
|
* Returns the VLANs currently configured on the VF.
|
|
|
|
|
*
|
2019-12-20 14:42:03 +01:00
|
|
|
* Returns: (transfer none) (array length=length): a list of VLAN ids configured on the VF.
|
2018-05-25 12:05:24 +02:00
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
*/
|
|
|
|
|
const guint *
|
|
|
|
|
nm_sriov_vf_get_vlan_ids (const NMSriovVF *vf, guint *length)
|
|
|
|
|
{
|
|
|
|
|
GHashTableIter iter;
|
|
|
|
|
VFVlan *vlan;
|
|
|
|
|
guint num, i;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (vf, NULL);
|
|
|
|
|
g_return_val_if_fail (vf->refcount > 0, NULL);
|
|
|
|
|
|
|
|
|
|
num = vf->vlans ? g_hash_table_size (vf->vlans) : 0u;
|
|
|
|
|
NM_SET_OUT (length, num);
|
|
|
|
|
|
|
|
|
|
if (vf->vlan_ids)
|
|
|
|
|
return vf->vlan_ids;
|
|
|
|
|
if (num == 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
/* vf is const, however, vlan_ids is a mutable field caching the
|
|
|
|
|
* result ("mutable" in C++ terminology) */
|
|
|
|
|
((NMSriovVF *) vf)->vlan_ids = g_new0 (guint, num);
|
|
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
g_hash_table_iter_init (&iter, vf->vlans);
|
|
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer *) &vlan, NULL))
|
|
|
|
|
vf->vlan_ids[i++] = vlan->id;
|
|
|
|
|
|
|
|
|
|
nm_assert (num == i);
|
|
|
|
|
|
|
|
|
|
g_qsort_with_data (vf->vlan_ids, num, sizeof (guint), vlan_id_compare, NULL);
|
|
|
|
|
|
|
|
|
|
return vf->vlan_ids;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_sriov_vf_set_vlan_qos:
|
|
|
|
|
* @vf: the #NMSriovVF
|
|
|
|
|
* @vlan_id: the VLAN id
|
|
|
|
|
* @qos: a QoS (priority) value
|
|
|
|
|
*
|
|
|
|
|
* Sets a QoS value for the given VLAN.
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
nm_sriov_vf_set_vlan_qos (NMSriovVF *vf, guint vlan_id, guint32 qos)
|
|
|
|
|
{
|
|
|
|
|
VFVlan *vlan;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (vf);
|
|
|
|
|
g_return_if_fail (vf->refcount > 0);
|
|
|
|
|
|
|
|
|
|
if ( !vf->vlans
|
|
|
|
|
|| !(vlan = g_hash_table_lookup (vf->vlans, &vlan_id)))
|
|
|
|
|
g_return_if_reached ();
|
|
|
|
|
|
|
|
|
|
vlan->qos = qos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_sriov_vf_set_vlan_protocol:
|
|
|
|
|
* @vf: the #NMSriovVF
|
|
|
|
|
* @vlan_id: the VLAN id
|
|
|
|
|
* @protocol: the VLAN protocol
|
|
|
|
|
*
|
|
|
|
|
* Sets the protocol for the given VLAN.
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
nm_sriov_vf_set_vlan_protocol (NMSriovVF *vf, guint vlan_id, NMSriovVFVlanProtocol protocol)
|
|
|
|
|
{
|
|
|
|
|
VFVlan *vlan;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (vf);
|
|
|
|
|
g_return_if_fail (vf->refcount > 0);
|
|
|
|
|
|
|
|
|
|
if ( !vf->vlans
|
|
|
|
|
|| !(vlan = g_hash_table_lookup (vf->vlans, &vlan_id)))
|
|
|
|
|
g_return_if_reached ();
|
|
|
|
|
|
|
|
|
|
vlan->protocol = protocol;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_sriov_vf_get_vlan_qos:
|
|
|
|
|
* @vf: the #NMSriovVF
|
|
|
|
|
* @vlan_id: the VLAN id
|
|
|
|
|
*
|
|
|
|
|
* Returns the QoS value for the given VLAN.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the QoS value
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
*/
|
|
|
|
|
guint32
|
|
|
|
|
nm_sriov_vf_get_vlan_qos (const NMSriovVF *vf, guint vlan_id)
|
|
|
|
|
{
|
|
|
|
|
VFVlan *vlan;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (vf, 0);
|
|
|
|
|
g_return_val_if_fail (vf->refcount > 0, 0);
|
|
|
|
|
|
|
|
|
|
if ( !vf->vlans
|
|
|
|
|
|| !(vlan = g_hash_table_lookup (vf->vlans, &vlan_id)))
|
|
|
|
|
g_return_val_if_reached (0);
|
|
|
|
|
|
|
|
|
|
return vlan->qos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* nm_sriov_vf_get_vlan_protocol:
|
|
|
|
|
* @vf: the #NMSriovVF
|
|
|
|
|
* @vlan_id: the VLAN id
|
|
|
|
|
*
|
|
|
|
|
* Returns the configured protocol for the given VLAN.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the configured protocol
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
*/
|
|
|
|
|
NMSriovVFVlanProtocol
|
|
|
|
|
nm_sriov_vf_get_vlan_protocol (const NMSriovVF *vf, guint vlan_id)
|
|
|
|
|
{
|
|
|
|
|
VFVlan *vlan;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (vf, NM_SRIOV_VF_VLAN_PROTOCOL_802_1Q);
|
|
|
|
|
g_return_val_if_fail (vf->refcount > 0, NM_SRIOV_VF_VLAN_PROTOCOL_802_1Q);
|
|
|
|
|
|
|
|
|
|
if ( !vf->vlans
|
|
|
|
|
|| !(vlan = g_hash_table_lookup (vf->vlans, &vlan_id)))
|
|
|
|
|
g_return_val_if_reached (NM_SRIOV_VF_VLAN_PROTOCOL_802_1Q);
|
|
|
|
|
|
|
|
|
|
return vlan->protocol;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_setting_sriov_get_total_vfs:
|
|
|
|
|
* @setting: the #NMSettingSriov
|
|
|
|
|
*
|
|
|
|
|
* Returns the value contained in the #NMSettingSriov:total-vfs
|
|
|
|
|
* property.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the total number of SR-IOV virtual functions to create
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
**/
|
|
|
|
|
guint
|
|
|
|
|
nm_setting_sriov_get_total_vfs (NMSettingSriov *setting)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (NM_IS_SETTING_SRIOV (setting), 0);
|
|
|
|
|
|
|
|
|
|
return setting->total_vfs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_setting_sriov_get_num_vfs:
|
|
|
|
|
* @setting: the #NMSettingSriov
|
|
|
|
|
*
|
|
|
|
|
* Returns: the number of configured VFs
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
**/
|
|
|
|
|
guint
|
|
|
|
|
nm_setting_sriov_get_num_vfs (NMSettingSriov *setting)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (NM_IS_SETTING_SRIOV (setting), 0);
|
|
|
|
|
|
|
|
|
|
return setting->vfs->len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_setting_sriov_get_vf:
|
|
|
|
|
* @setting: the #NMSettingSriov
|
|
|
|
|
* @idx: index number of the VF to return
|
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer none): the VF at index @idx
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
**/
|
|
|
|
|
NMSriovVF *
|
|
|
|
|
nm_setting_sriov_get_vf (NMSettingSriov *setting, guint idx)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (NM_IS_SETTING_SRIOV (setting), NULL);
|
|
|
|
|
g_return_val_if_fail (idx < setting->vfs->len, NULL);
|
|
|
|
|
|
|
|
|
|
return setting->vfs->pdata[idx];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_setting_sriov_add_vf:
|
|
|
|
|
* @setting: the #NMSettingSriov
|
|
|
|
|
* @vf: the VF to add
|
|
|
|
|
*
|
|
|
|
|
* Appends a new VF and associated information to the setting. The
|
|
|
|
|
* given VF is duplicated internally and is not changed by this function.
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
nm_setting_sriov_add_vf (NMSettingSriov *setting, NMSriovVF *vf)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (NM_IS_SETTING_SRIOV (setting));
|
|
|
|
|
g_return_if_fail (vf);
|
|
|
|
|
g_return_if_fail (vf->refcount > 0);
|
|
|
|
|
|
|
|
|
|
g_ptr_array_add (setting->vfs, nm_sriov_vf_dup (vf));
|
2019-01-11 08:28:26 +01:00
|
|
|
_notify (setting, PROP_VFS);
|
2018-05-25 12:05:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_setting_sriov_remove_vf:
|
|
|
|
|
* @setting: the #NMSettingSriov
|
|
|
|
|
* @idx: index number of the VF
|
|
|
|
|
*
|
|
|
|
|
* Removes the VF at index @idx.
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
nm_setting_sriov_remove_vf (NMSettingSriov *setting, guint idx)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (NM_IS_SETTING_SRIOV (setting));
|
|
|
|
|
g_return_if_fail (idx < setting->vfs->len);
|
|
|
|
|
|
|
|
|
|
g_ptr_array_remove_index (setting->vfs, idx);
|
2019-01-11 08:28:26 +01:00
|
|
|
_notify (setting, PROP_VFS);
|
2018-05-25 12:05:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_setting_sriov_remove_vf_by_index:
|
|
|
|
|
* @setting: the #NMSettingSriov
|
|
|
|
|
* @index: the VF index of the VF to remove
|
|
|
|
|
*
|
|
|
|
|
* Removes the VF with VF index @index.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the VF was found and removed; %FALSE if it was not
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
**/
|
|
|
|
|
gboolean
|
|
|
|
|
nm_setting_sriov_remove_vf_by_index (NMSettingSriov *setting,
|
|
|
|
|
guint index)
|
|
|
|
|
{
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (NM_IS_SETTING_SRIOV (setting), FALSE);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < setting->vfs->len; i++) {
|
|
|
|
|
if (nm_sriov_vf_get_index (setting->vfs->pdata[i]) == index) {
|
|
|
|
|
g_ptr_array_remove_index (setting->vfs, i);
|
2019-01-11 08:28:26 +01:00
|
|
|
_notify (setting, PROP_VFS);
|
2018-05-25 12:05:24 +02:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_setting_sriov_clear_vfs:
|
|
|
|
|
* @setting: the #NMSettingSriov
|
|
|
|
|
*
|
|
|
|
|
* Removes all configured VFs.
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
nm_setting_sriov_clear_vfs (NMSettingSriov *setting)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (NM_IS_SETTING_SRIOV (setting));
|
|
|
|
|
|
|
|
|
|
if (setting->vfs->len != 0) {
|
|
|
|
|
g_ptr_array_set_size (setting->vfs, 0);
|
2019-01-11 08:28:26 +01:00
|
|
|
_notify (setting, PROP_VFS);
|
2018-05-25 12:05:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_setting_sriov_get_autoprobe_drivers:
|
|
|
|
|
* @setting: the #NMSettingSriov
|
|
|
|
|
*
|
|
|
|
|
* Returns the value contained in the #NMSettingSriov:autoprobe-drivers
|
|
|
|
|
* property.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the autoprobe-drivers property value
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
**/
|
|
|
|
|
NMTernary
|
|
|
|
|
nm_setting_sriov_get_autoprobe_drivers (NMSettingSriov *setting)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (NM_IS_SETTING_SRIOV (setting), NM_TERNARY_DEFAULT);
|
|
|
|
|
|
|
|
|
|
return setting->autoprobe_drivers;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-08 12:54:17 +02:00
|
|
|
static int
|
2018-05-25 12:05:24 +02:00
|
|
|
vf_index_compare (gconstpointer a, gconstpointer b)
|
|
|
|
|
{
|
|
|
|
|
NMSriovVF *vf_a = *(NMSriovVF **) a;
|
|
|
|
|
NMSriovVF *vf_b = *(NMSriovVF **) b;
|
|
|
|
|
|
|
|
|
|
if (vf_a->index < vf_b->index)
|
|
|
|
|
return -1;
|
|
|
|
|
else if (vf_a->index > vf_b->index)
|
|
|
|
|
return 1;
|
|
|
|
|
else
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
_nm_setting_sriov_sort_vfs (NMSettingSriov *setting)
|
|
|
|
|
{
|
|
|
|
|
gboolean need_sort = FALSE;
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
for (i = 1; i < setting->vfs->len; i++) {
|
|
|
|
|
NMSriovVF *vf_prev = setting->vfs->pdata[i - 1];
|
|
|
|
|
NMSriovVF *vf = setting->vfs->pdata[i];
|
|
|
|
|
|
|
|
|
|
if (vf->index <= vf_prev->index) {
|
|
|
|
|
need_sort = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 09:50:06 +01:00
|
|
|
if (need_sort) {
|
2018-05-25 12:05:24 +02:00
|
|
|
g_ptr_array_sort (setting->vfs, vf_index_compare);
|
2019-03-20 09:50:06 +01:00
|
|
|
_notify (setting, PROP_VFS);
|
|
|
|
|
}
|
2018-05-25 12:05:24 +02:00
|
|
|
|
|
|
|
|
return need_sort;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static GVariant *
|
2019-04-24 17:41:32 +02:00
|
|
|
vfs_to_dbus (const NMSettInfoSetting *sett_info,
|
|
|
|
|
guint property_idx,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
NMSetting *setting,
|
2019-06-27 09:07:16 +02:00
|
|
|
NMConnectionSerializationFlags flags,
|
|
|
|
|
const NMConnectionSerializationOptions *options)
|
2018-05-25 12:05:24 +02:00
|
|
|
{
|
|
|
|
|
gs_unref_ptrarray GPtrArray *vfs = NULL;
|
|
|
|
|
GVariantBuilder builder;
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
g_object_get (setting, NM_SETTING_SRIOV_VFS, &vfs, NULL);
|
|
|
|
|
g_variant_builder_init (&builder, G_VARIANT_TYPE ("aa{sv}"));
|
|
|
|
|
|
|
|
|
|
if (vfs) {
|
|
|
|
|
for (i = 0; i < vfs->len; i++) {
|
|
|
|
|
gs_free const char **attr_names = NULL;
|
|
|
|
|
NMSriovVF *vf = vfs->pdata[i];
|
|
|
|
|
GVariantBuilder vf_builder;
|
|
|
|
|
const guint *vlan_ids;
|
|
|
|
|
const char **name;
|
2019-02-03 11:15:11 +01:00
|
|
|
guint num_vlans = 0;
|
2018-05-25 12:05:24 +02:00
|
|
|
|
|
|
|
|
g_variant_builder_init (&vf_builder, G_VARIANT_TYPE_VARDICT);
|
|
|
|
|
g_variant_builder_add (&vf_builder, "{sv}", "index",
|
|
|
|
|
g_variant_new_uint32 (nm_sriov_vf_get_index (vf)));
|
|
|
|
|
|
|
|
|
|
attr_names = nm_utils_strdict_get_keys (vf->attributes, TRUE, NULL);
|
|
|
|
|
if (attr_names) {
|
|
|
|
|
for (name = attr_names; *name; name++) {
|
|
|
|
|
g_variant_builder_add (&vf_builder,
|
|
|
|
|
"{sv}",
|
|
|
|
|
*name,
|
|
|
|
|
nm_sriov_vf_get_attribute (vf, *name));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* VLANs are translated into an array of maps, where each map has
|
|
|
|
|
* keys 'id', 'qos' and 'proto'. This guarantees enough flexibility
|
2018-09-15 07:20:54 -04:00
|
|
|
* to accommodate any future new option. */
|
2018-05-25 12:05:24 +02:00
|
|
|
vlan_ids = nm_sriov_vf_get_vlan_ids (vf, &num_vlans);
|
|
|
|
|
if (num_vlans) {
|
|
|
|
|
GVariantBuilder vlans_builder;
|
|
|
|
|
guint j;
|
|
|
|
|
|
|
|
|
|
g_variant_builder_init (&vlans_builder, G_VARIANT_TYPE ("aa{sv}"));
|
|
|
|
|
for (j = 0; j < num_vlans; j++) {
|
|
|
|
|
GVariantBuilder vlan_builder;
|
|
|
|
|
|
|
|
|
|
g_variant_builder_init (&vlan_builder, G_VARIANT_TYPE ("a{sv}"));
|
|
|
|
|
g_variant_builder_add (&vlan_builder,
|
|
|
|
|
"{sv}", "id",
|
|
|
|
|
g_variant_new_uint32 (vlan_ids[j]));
|
|
|
|
|
g_variant_builder_add (&vlan_builder,
|
|
|
|
|
"{sv}", "qos",
|
|
|
|
|
g_variant_new_uint32 (nm_sriov_vf_get_vlan_qos (vf,
|
|
|
|
|
vlan_ids[j])));
|
|
|
|
|
g_variant_builder_add (&vlan_builder,
|
|
|
|
|
"{sv}", "protocol",
|
|
|
|
|
g_variant_new_uint32 (nm_sriov_vf_get_vlan_protocol (vf,
|
|
|
|
|
vlan_ids[j])));
|
|
|
|
|
g_variant_builder_add (&vlans_builder,
|
|
|
|
|
"a{sv}",
|
|
|
|
|
&vlan_builder);
|
|
|
|
|
}
|
|
|
|
|
g_variant_builder_add (&vf_builder , "{sv}", "vlans", g_variant_builder_end (&vlans_builder));
|
|
|
|
|
}
|
|
|
|
|
g_variant_builder_add (&builder, "a{sv}", &vf_builder);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return g_variant_builder_end (&builder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
vfs_from_dbus (NMSetting *setting,
|
|
|
|
|
GVariant *connection_dict,
|
|
|
|
|
const char *property,
|
|
|
|
|
GVariant *value,
|
|
|
|
|
NMSettingParseFlags parse_flags,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
GPtrArray *vfs;
|
|
|
|
|
GVariantIter vf_iter;
|
|
|
|
|
GVariant *vf_var;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (g_variant_is_of_type (value, G_VARIANT_TYPE ("aa{sv}")), FALSE);
|
|
|
|
|
|
|
|
|
|
vfs = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_sriov_vf_unref);
|
|
|
|
|
g_variant_iter_init (&vf_iter, value);
|
|
|
|
|
while (g_variant_iter_next (&vf_iter, "@a{sv}", &vf_var)) {
|
|
|
|
|
NMSriovVF *vf;
|
|
|
|
|
guint32 index;
|
|
|
|
|
GVariantIter attr_iter;
|
|
|
|
|
const char *attr_name;
|
|
|
|
|
GVariant *attr_var, *vlans_var;
|
|
|
|
|
|
|
|
|
|
if (!g_variant_lookup (vf_var, "index", "u", &index))
|
|
|
|
|
goto next;
|
|
|
|
|
|
|
|
|
|
vf = nm_sriov_vf_new (index);
|
|
|
|
|
|
|
|
|
|
g_variant_iter_init (&attr_iter, vf_var);
|
|
|
|
|
while (g_variant_iter_next (&attr_iter, "{&sv}", &attr_name, &attr_var)) {
|
|
|
|
|
if (!NM_IN_STRSET (attr_name, "index", "vlans"))
|
|
|
|
|
nm_sriov_vf_set_attribute (vf, attr_name, attr_var);
|
|
|
|
|
g_variant_unref (attr_var);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (g_variant_lookup (vf_var, "vlans", "@aa{sv}", &vlans_var)) {
|
|
|
|
|
GVariantIter vlan_iter;
|
|
|
|
|
GVariant *vlan_var;
|
|
|
|
|
|
|
|
|
|
g_variant_iter_init (&vlan_iter, vlans_var);
|
|
|
|
|
while (g_variant_iter_next (&vlan_iter, "@a{sv}", &vlan_var)) {
|
|
|
|
|
NMSriovVFVlanProtocol proto = NM_SRIOV_VF_VLAN_PROTOCOL_802_1Q;
|
|
|
|
|
gint64 vlan_id = -1;
|
|
|
|
|
guint qos = 0;
|
|
|
|
|
|
|
|
|
|
g_variant_iter_init (&attr_iter, vlan_var);
|
|
|
|
|
while (g_variant_iter_next (&attr_iter, "{&sv}", &attr_name, &attr_var)) {
|
|
|
|
|
if ( nm_streq (attr_name, "id")
|
|
|
|
|
&& g_variant_is_of_type (attr_var, G_VARIANT_TYPE_UINT32))
|
|
|
|
|
vlan_id = g_variant_get_uint32 (attr_var);
|
|
|
|
|
else if ( nm_streq (attr_name, "qos")
|
|
|
|
|
&& g_variant_is_of_type (attr_var, G_VARIANT_TYPE_UINT32))
|
|
|
|
|
qos = g_variant_get_uint32 (attr_var);
|
|
|
|
|
else if ( nm_streq (attr_name, "protocol")
|
|
|
|
|
&& g_variant_is_of_type (attr_var, G_VARIANT_TYPE_UINT32))
|
|
|
|
|
proto = g_variant_get_uint32 (attr_var);
|
|
|
|
|
g_variant_unref (attr_var);
|
|
|
|
|
}
|
|
|
|
|
if (vlan_id != -1)
|
|
|
|
|
vf_add_vlan (vf, vlan_id, qos, proto);
|
|
|
|
|
g_variant_unref (vlan_var);
|
|
|
|
|
}
|
|
|
|
|
g_variant_unref (vlans_var);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_ptr_array_add (vfs, vf);
|
|
|
|
|
next:
|
|
|
|
|
g_variant_unref (vf_var);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_set (setting, NM_SETTING_SRIOV_VFS, vfs, NULL);
|
|
|
|
|
g_ptr_array_unref (vfs);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
verify (NMSetting *setting, NMConnection *connection, GError **error)
|
|
|
|
|
{
|
|
|
|
|
NMSettingSriov *self = NM_SETTING_SRIOV (setting);
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
if (self->vfs->len) {
|
|
|
|
|
gs_unref_hashtable GHashTable *h = NULL;
|
|
|
|
|
|
|
|
|
|
h = g_hash_table_new (nm_direct_hash, NULL);
|
|
|
|
|
for (i = 0; i < self->vfs->len; i++) {
|
|
|
|
|
NMSriovVF *vf = self->vfs->pdata[i];
|
|
|
|
|
gs_free_error GError *local = NULL;
|
|
|
|
|
|
|
|
|
|
if (vf->index >= self->total_vfs) {
|
|
|
|
|
g_set_error (error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
|
|
|
_("VF with index %u, but the total number of VFs is %u"),
|
|
|
|
|
vf->index, self->total_vfs);
|
|
|
|
|
g_prefix_error (error, "%s.%s: ", NM_SETTING_SRIOV_SETTING_NAME,
|
|
|
|
|
NM_SETTING_SRIOV_VFS);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!_nm_sriov_vf_attribute_validate_all (vf, &local)) {
|
|
|
|
|
g_set_error (error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
|
|
|
_("invalid VF %u: %s"),
|
|
|
|
|
vf->index,
|
|
|
|
|
local->message);
|
|
|
|
|
g_prefix_error (error, "%s.%s: ", NM_SETTING_SRIOV_SETTING_NAME,
|
|
|
|
|
NM_SETTING_SRIOV_VFS);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (g_hash_table_contains (h, GUINT_TO_POINTER (vf->index))) {
|
|
|
|
|
g_set_error (error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
|
|
|
_("duplicate VF index %u"), vf->index);
|
|
|
|
|
g_prefix_error (error, "%s.%s: ", NM_SETTING_SRIOV_SETTING_NAME,
|
|
|
|
|
NM_SETTING_SRIOV_VFS);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_hash_table_add (h, GUINT_TO_POINTER (vf->index));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Failures from here on are NORMALIZABLE... */
|
|
|
|
|
|
|
|
|
|
if (self->vfs->len) {
|
|
|
|
|
for (i = 1; i < self->vfs->len; i++) {
|
|
|
|
|
NMSriovVF *vf_prev = self->vfs->pdata[i - 1];
|
|
|
|
|
NMSriovVF *vf = self->vfs->pdata[i];
|
|
|
|
|
|
|
|
|
|
if (vf->index <= vf_prev->index) {
|
|
|
|
|
g_set_error (error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
|
|
|
_("VFs %d and %d are not sorted by ascending index"),
|
|
|
|
|
vf_prev->index, vf->index);
|
|
|
|
|
g_prefix_error (error, "%s.%s: ", NM_SETTING_SRIOV_SETTING_NAME,
|
|
|
|
|
NM_SETTING_SRIOV_VFS);
|
|
|
|
|
return NM_SETTING_VERIFY_NORMALIZABLE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-11 08:32:54 +01:00
|
|
|
static NMTernary
|
|
|
|
|
compare_property (const NMSettInfoSetting *sett_info,
|
|
|
|
|
guint property_idx,
|
2019-04-25 10:17:47 +02:00
|
|
|
NMConnection *con_a,
|
|
|
|
|
NMSetting *set_a,
|
|
|
|
|
NMConnection *con_b,
|
|
|
|
|
NMSetting *set_b,
|
2019-01-11 08:32:54 +01:00
|
|
|
NMSettingCompareFlags flags)
|
|
|
|
|
{
|
|
|
|
|
NMSettingSriov *a;
|
|
|
|
|
NMSettingSriov *b;
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
if (nm_streq (sett_info->property_infos[property_idx].name, NM_SETTING_SRIOV_VFS)) {
|
2019-04-25 10:17:47 +02:00
|
|
|
if (set_b) {
|
|
|
|
|
a = NM_SETTING_SRIOV (set_a);
|
|
|
|
|
b = NM_SETTING_SRIOV (set_b);
|
2019-01-11 08:32:54 +01:00
|
|
|
|
|
|
|
|
if (a->vfs->len != b->vfs->len)
|
|
|
|
|
return FALSE;
|
|
|
|
|
for (i = 0; i < a->vfs->len; i++) {
|
|
|
|
|
if (!nm_sriov_vf_equal (a->vfs->pdata[i], b->vfs->pdata[i]))
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NM_SETTING_CLASS (nm_setting_sriov_parent_class)->compare_property (sett_info,
|
|
|
|
|
property_idx,
|
2019-04-25 10:17:47 +02:00
|
|
|
con_a,
|
|
|
|
|
set_a,
|
|
|
|
|
con_b,
|
|
|
|
|
set_b,
|
2019-01-11 08:32:54 +01:00
|
|
|
flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2018-05-25 12:05:24 +02:00
|
|
|
static void
|
2019-01-11 08:32:54 +01:00
|
|
|
get_property (GObject *object, guint prop_id,
|
|
|
|
|
GValue *value, GParamSpec *pspec)
|
2018-05-25 12:05:24 +02:00
|
|
|
{
|
|
|
|
|
NMSettingSriov *self = NM_SETTING_SRIOV (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_TOTAL_VFS:
|
2019-01-11 08:32:54 +01:00
|
|
|
g_value_set_uint (value, self->total_vfs);
|
2018-05-25 12:05:24 +02:00
|
|
|
break;
|
|
|
|
|
case PROP_VFS:
|
2019-01-11 08:32:54 +01:00
|
|
|
g_value_take_boxed (value, _nm_utils_copy_array (self->vfs,
|
|
|
|
|
(NMUtilsCopyFunc) nm_sriov_vf_dup,
|
|
|
|
|
(GDestroyNotify) nm_sriov_vf_unref));
|
2018-05-25 12:05:24 +02:00
|
|
|
break;
|
|
|
|
|
case PROP_AUTOPROBE_DRIVERS:
|
2019-01-11 08:32:54 +01:00
|
|
|
g_value_set_enum (value, self->autoprobe_drivers);
|
2018-05-25 12:05:24 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2019-01-11 08:32:54 +01:00
|
|
|
set_property (GObject *object, guint prop_id,
|
|
|
|
|
const GValue *value, GParamSpec *pspec)
|
2018-05-25 12:05:24 +02:00
|
|
|
{
|
|
|
|
|
NMSettingSriov *self = NM_SETTING_SRIOV (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_TOTAL_VFS:
|
2019-01-11 08:32:54 +01:00
|
|
|
self->total_vfs = g_value_get_uint (value);
|
2018-05-25 12:05:24 +02:00
|
|
|
break;
|
|
|
|
|
case PROP_VFS:
|
2019-01-11 08:32:54 +01:00
|
|
|
g_ptr_array_unref (self->vfs);
|
|
|
|
|
self->vfs = _nm_utils_copy_array (g_value_get_boxed (value),
|
|
|
|
|
(NMUtilsCopyFunc) nm_sriov_vf_dup,
|
|
|
|
|
(GDestroyNotify) nm_sriov_vf_unref);
|
2018-05-25 12:05:24 +02:00
|
|
|
break;
|
|
|
|
|
case PROP_AUTOPROBE_DRIVERS:
|
2019-01-11 08:32:54 +01:00
|
|
|
self->autoprobe_drivers = g_value_get_enum (value);
|
2018-05-25 12:05:24 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-11 08:32:54 +01:00
|
|
|
/*****************************************************************************/
|
2018-05-25 12:05:24 +02:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
nm_setting_sriov_init (NMSettingSriov *setting)
|
|
|
|
|
{
|
|
|
|
|
setting->vfs = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_sriov_vf_unref);
|
2019-12-12 11:52:11 +01:00
|
|
|
|
|
|
|
|
setting->autoprobe_drivers = NM_TERNARY_DEFAULT;
|
2018-05-25 12:05:24 +02:00
|
|
|
}
|
|
|
|
|
|
2019-01-11 08:32:54 +01:00
|
|
|
/**
|
|
|
|
|
* nm_setting_sriov_new:
|
|
|
|
|
*
|
|
|
|
|
* Creates a new #NMSettingSriov object with default values.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer full): the new empty #NMSettingSriov object
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
**/
|
|
|
|
|
NMSetting *
|
|
|
|
|
nm_setting_sriov_new (void)
|
|
|
|
|
{
|
|
|
|
|
return (NMSetting *) g_object_new (NM_TYPE_SETTING_SRIOV, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-25 12:05:24 +02:00
|
|
|
static void
|
|
|
|
|
finalize (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
NMSettingSriov *self = NM_SETTING_SRIOV (object);
|
|
|
|
|
|
|
|
|
|
g_ptr_array_unref (self->vfs);
|
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (nm_setting_sriov_parent_class)->finalize (object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
libnm/trivial: cleanup variable names in settings' class-init functions
- Don't use @parent_class name. This local variable (and @object_class) is
the class instance up-cast to the pointer types of the parents. The point
here is not that it is the direct parent. The point is, that it's the
NMSettingClass type.
Also, it can only be used inconsistently, in face of NMSettingIP4Config,
who's parent type is NMSettingIPConfig. Clearly, inside
nm-setting-ip4-config.c we wouldn't want to use the "parent_class"
name. Consistently rename @parent_class to @setting_class.
- Also rename the pointer to the own class to @klass. "setting_class" is also the
wrong name for that, because the right name would be something like
"setting_6lowpan_class".
However, "klass" is preferred over the latter, because we commonly create new
GObject implementations by copying an existing one. Generic names like "klass"
and "self" inside a type implementation make that simpler.
- drop useless comments like
/* virtual functions */
/* Properties */
It's better to logically and visually structure the code, and avoid trival
remarks about that. They only end up being used inconsistently. If you
even need a stronger visual separator, then an 80 char /****/ line
should be preferred.
2018-07-28 10:43:21 +02:00
|
|
|
nm_setting_sriov_class_init (NMSettingSriovClass *klass)
|
2018-05-25 12:05:24 +02:00
|
|
|
{
|
libnm/trivial: cleanup variable names in settings' class-init functions
- Don't use @parent_class name. This local variable (and @object_class) is
the class instance up-cast to the pointer types of the parents. The point
here is not that it is the direct parent. The point is, that it's the
NMSettingClass type.
Also, it can only be used inconsistently, in face of NMSettingIP4Config,
who's parent type is NMSettingIPConfig. Clearly, inside
nm-setting-ip4-config.c we wouldn't want to use the "parent_class"
name. Consistently rename @parent_class to @setting_class.
- Also rename the pointer to the own class to @klass. "setting_class" is also the
wrong name for that, because the right name would be something like
"setting_6lowpan_class".
However, "klass" is preferred over the latter, because we commonly create new
GObject implementations by copying an existing one. Generic names like "klass"
and "self" inside a type implementation make that simpler.
- drop useless comments like
/* virtual functions */
/* Properties */
It's better to logically and visually structure the code, and avoid trival
remarks about that. They only end up being used inconsistently. If you
even need a stronger visual separator, then an 80 char /****/ line
should be preferred.
2018-07-28 10:43:21 +02:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
NMSettingClass *setting_class = NM_SETTING_CLASS (klass);
|
libnm: rework setting metadata for property handling
NMSetting internally already tracked a list of all proper GObject properties
and D-Bus-only properties.
Rework the tracking of the list, so that:
- instead of attaching the data to the GType of the setting via
g_type_set_qdata(), it is tracked in a static array indexed by
NMMetaSettingType. This allows to find the setting-data by simple
pointer arithmetic, instead of taking a look and iterating (like
g_type_set_qdata() does).
Note, that this is still thread safe, because the static table entry is
initialized in the class-init function with _nm_setting_class_commit().
And it only accessed by following a NMSettingClass instance, thus
the class constructor already ran (maybe not for all setting classes,
but for the particular one that we look up).
I think this makes initialization of the metadata simpler to
understand.
Previously, in a first phase each class would attach the metadata
to the GType as setting_property_overrides_quark(). Then during
nm_setting_class_ensure_properties() it would merge them and
set as setting_properties_quark(). Now, during the first phase,
we only incrementally build a properties_override GArray, which
we finally hand over during nm_setting_class_commit().
- sort the property infos by name and do binary search.
Also expose this meta data types as internal API in nm-setting-private.h.
While not accessed yet, it can prove beneficial, to have direct (internal)
access to these structures.
Also, rename NMSettingProperty to NMSettInfoProperty to use a distinct
naming scheme. We already have 40+ subclasses of NMSetting that are called
NMSetting*. Likewise, NMMetaSetting* is heavily used already. So, choose a
new, distinct name.
2018-07-28 15:26:03 +02:00
|
|
|
GArray *properties_override = _nm_sett_info_property_override_create_array ();
|
2018-05-25 12:05:24 +02:00
|
|
|
|
|
|
|
|
object_class->get_property = get_property;
|
|
|
|
|
object_class->set_property = set_property;
|
libnm/trivial: cleanup variable names in settings' class-init functions
- Don't use @parent_class name. This local variable (and @object_class) is
the class instance up-cast to the pointer types of the parents. The point
here is not that it is the direct parent. The point is, that it's the
NMSettingClass type.
Also, it can only be used inconsistently, in face of NMSettingIP4Config,
who's parent type is NMSettingIPConfig. Clearly, inside
nm-setting-ip4-config.c we wouldn't want to use the "parent_class"
name. Consistently rename @parent_class to @setting_class.
- Also rename the pointer to the own class to @klass. "setting_class" is also the
wrong name for that, because the right name would be something like
"setting_6lowpan_class".
However, "klass" is preferred over the latter, because we commonly create new
GObject implementations by copying an existing one. Generic names like "klass"
and "self" inside a type implementation make that simpler.
- drop useless comments like
/* virtual functions */
/* Properties */
It's better to logically and visually structure the code, and avoid trival
remarks about that. They only end up being used inconsistently. If you
even need a stronger visual separator, then an 80 char /****/ line
should be preferred.
2018-07-28 10:43:21 +02:00
|
|
|
object_class->finalize = finalize;
|
|
|
|
|
|
|
|
|
|
setting_class->compare_property = compare_property;
|
|
|
|
|
setting_class->verify = verify;
|
2018-05-25 12:05:24 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* NMSettingSriov:total-vfs
|
|
|
|
|
*
|
|
|
|
|
* The total number of virtual functions to create.
|
|
|
|
|
*
|
2018-12-01 17:53:22 +01:00
|
|
|
* Note that when the sriov setting is present NetworkManager
|
|
|
|
|
* enforces the number of virtual functions on the interface
|
2020-03-15 09:49:55 +01:00
|
|
|
* (also when it is zero) during activation and resets it
|
|
|
|
|
* upon deactivation. To prevent any changes to SR-IOV
|
2018-12-01 17:53:22 +01:00
|
|
|
* parameters don't add a sriov setting to the connection.
|
|
|
|
|
*
|
2018-05-25 12:05:24 +02:00
|
|
|
* Since: 1.14
|
|
|
|
|
**/
|
2018-05-24 17:32:37 +02:00
|
|
|
/* ---ifcfg-rh---
|
|
|
|
|
* property: total-vfs
|
|
|
|
|
* variable: SRIOV_TOTAL_VFS(+)
|
|
|
|
|
* description: The total number of virtual functions to create
|
|
|
|
|
* example: SRIOV_TOTAL_VFS=16
|
|
|
|
|
* ---end---
|
|
|
|
|
*/
|
2019-01-11 08:28:26 +01:00
|
|
|
obj_properties[PROP_TOTAL_VFS] =
|
|
|
|
|
g_param_spec_uint (NM_SETTING_SRIOV_TOTAL_VFS, "", "",
|
|
|
|
|
0, G_MAXUINT32, 0,
|
|
|
|
|
NM_SETTING_PARAM_FUZZY_IGNORE |
|
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
2018-05-25 12:05:24 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* NMSettingSriov:vfs: (type GPtrArray(NMSriovVF))
|
|
|
|
|
*
|
|
|
|
|
* Array of virtual function descriptors.
|
|
|
|
|
*
|
|
|
|
|
* Each VF descriptor is a dictionary mapping attribute names
|
|
|
|
|
* to GVariant values. The 'index' entry is mandatory for
|
|
|
|
|
* each VF.
|
|
|
|
|
*
|
|
|
|
|
* When represented as string a VF is in the form:
|
|
|
|
|
*
|
|
|
|
|
* "INDEX [ATTR=VALUE[ ATTR=VALUE]...]".
|
|
|
|
|
*
|
|
|
|
|
* for example:
|
|
|
|
|
*
|
|
|
|
|
* "2 mac=00:11:22:33:44:55 spoof-check=true".
|
|
|
|
|
*
|
2018-12-01 17:53:22 +01:00
|
|
|
* Multiple VFs can be specified using a comma as separator.
|
|
|
|
|
* Currently the following attributes are supported: mac,
|
|
|
|
|
* spoof-check, trust, min-tx-rate, max-tx-rate, vlans.
|
|
|
|
|
*
|
2018-09-30 11:30:18 -03:00
|
|
|
* The "vlans" attribute is represented as a semicolon-separated
|
2018-05-25 12:05:24 +02:00
|
|
|
* list of VLAN descriptors, where each descriptor has the form
|
|
|
|
|
*
|
|
|
|
|
* "ID[.PRIORITY[.PROTO]]".
|
|
|
|
|
*
|
|
|
|
|
* PROTO can be either 'q' for 802.1Q (the default) or 'ad' for
|
|
|
|
|
* 802.1ad.
|
|
|
|
|
*
|
2018-12-01 17:53:22 +01:00
|
|
|
|
2018-05-25 12:05:24 +02:00
|
|
|
* Since: 1.14
|
|
|
|
|
**/
|
2018-05-24 17:32:37 +02:00
|
|
|
/* ---ifcfg-rh---
|
|
|
|
|
* property: vfs
|
|
|
|
|
* variable: SRIOV_VF1(+), SRIOV_VF2(+), ...
|
|
|
|
|
* description: SR-IOV virtual function descriptors
|
|
|
|
|
* example: SRIOV_VF10="mac=00:11:22:33:44:55", ...
|
|
|
|
|
* ---end---
|
|
|
|
|
*/
|
2019-01-11 08:28:26 +01:00
|
|
|
obj_properties[PROP_VFS] =
|
|
|
|
|
g_param_spec_boxed (NM_SETTING_SRIOV_VFS, "", "",
|
|
|
|
|
G_TYPE_PTR_ARRAY,
|
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
NM_SETTING_PARAM_INFERRABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
2019-09-22 15:32:04 +02:00
|
|
|
_nm_properties_override_gobj (properties_override,
|
|
|
|
|
obj_properties[PROP_VFS],
|
|
|
|
|
NM_SETT_INFO_PROPERT_TYPE (
|
|
|
|
|
.dbus_type = NM_G_VARIANT_TYPE ("aa{sv}"),
|
|
|
|
|
.to_dbus_fcn = vfs_to_dbus,
|
|
|
|
|
.from_dbus_fcn = vfs_from_dbus,
|
|
|
|
|
));
|
2018-05-25 12:05:24 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* NMSettingSriov:autoprobe-drivers
|
|
|
|
|
*
|
|
|
|
|
* Whether to autoprobe virtual functions by a compatible driver.
|
|
|
|
|
*
|
|
|
|
|
* If set to %NM_TERNARY_TRUE, the kernel will try to bind VFs to
|
|
|
|
|
* a compatible driver and if this succeeds a new network
|
|
|
|
|
* interface will be instantiated for each VF.
|
|
|
|
|
*
|
|
|
|
|
* If set to %NM_TERNARY_FALSE, VFs will not be claimed and no
|
|
|
|
|
* network interfaces will be created for them.
|
|
|
|
|
*
|
|
|
|
|
* When set to %NM_TERNARY_DEFAULT, the global default is used; in
|
|
|
|
|
* case the global default is unspecified it is assumed to be
|
|
|
|
|
* %NM_TERNARY_TRUE.
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.14
|
|
|
|
|
**/
|
2018-05-24 17:32:37 +02:00
|
|
|
/* ---ifcfg-rh---
|
|
|
|
|
* property: autoprobe-drivers
|
|
|
|
|
* variable: SRIOV_AUTOPROBE_DRIVERS(+)
|
|
|
|
|
* default: missing variable means global default
|
|
|
|
|
* description: Whether to autoprobe virtual functions by a compatible driver
|
|
|
|
|
* example: SRIOV_AUTOPROBE_DRIVERS=0,1
|
|
|
|
|
* ---end---
|
|
|
|
|
*/
|
2019-01-11 08:28:26 +01:00
|
|
|
obj_properties[PROP_AUTOPROBE_DRIVERS] =
|
|
|
|
|
g_param_spec_enum (NM_SETTING_SRIOV_AUTOPROBE_DRIVERS, "", "",
|
wireguard: support configuring policy routing to avoid routing loops
For WireGuard (like for all IP-tunnels and IP-based VPNs), the IP addresses of
the peers must be reached outside the tunnel/VPN itself.
For VPN connections, NetworkManager usually adds a direct /32 route to
the external VPN gateway to the underlying device. For WireGuard that is
not done, because injecting a route to another device is ugly and error
prone. Worse: WireGuard with automatic roaming and multiple peers makes this
more complicated.
This is commonly a problem when setting the default-route via the VPN,
but there are also other subtle setups where special care must be taken
to prevent such routing loops.
WireGuard's wg-quick provides a simple, automatic solution by adding two policy
routing rules and relying on the WireGuard packets having a fwmark set (see [1]).
Let's also do that. Add new properties "wireguard.ip4-auto-default-route"
and "wireguard.ip6-auto-default-route" to enable/disable this. Note that
the default value lets NetworkManager automatically choose whether to
enable it (depending on whether there are any peers that have a default
route). This means, common scenarios should now work well without additional
configuration.
Note that this is also a change in behavior and upon package upgrade
NetworkManager may start adding policy routes (if there are peers that
have a default-route). This is a change in behavior, as the user already
clearly had this setup working and configured some working solution
already.
The new automatism picks the rule priority automatically and adds the
default-route to the routing table that has the same number as the fwmark.
If any of this is unsuitable, then the user is free to disable this
automatism. Note that since 1.18.0 NetworkManager supports policy routing (*).
That means, what this automatism does can be also achieved via explicit
configuration of the profile, which gives the user more flexibility to
adjust all parameters explicitly).
(*) but only since 1.20.0 NetworkManager supports the "suppress_prefixlength"
rule attribute, which makes it impossible to configure exactly this rule-based
solution with 1.18.0 NetworkManager.
[1] https://www.wireguard.com/netns/#improved-rule-based-routing
2019-04-30 17:48:46 +02:00
|
|
|
NM_TYPE_TERNARY,
|
2019-01-11 08:28:26 +01:00
|
|
|
NM_TERNARY_DEFAULT,
|
|
|
|
|
NM_SETTING_PARAM_FUZZY_IGNORE |
|
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
|
|
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
|
libnm: rework setting metadata for property handling
NMSetting internally already tracked a list of all proper GObject properties
and D-Bus-only properties.
Rework the tracking of the list, so that:
- instead of attaching the data to the GType of the setting via
g_type_set_qdata(), it is tracked in a static array indexed by
NMMetaSettingType. This allows to find the setting-data by simple
pointer arithmetic, instead of taking a look and iterating (like
g_type_set_qdata() does).
Note, that this is still thread safe, because the static table entry is
initialized in the class-init function with _nm_setting_class_commit().
And it only accessed by following a NMSettingClass instance, thus
the class constructor already ran (maybe not for all setting classes,
but for the particular one that we look up).
I think this makes initialization of the metadata simpler to
understand.
Previously, in a first phase each class would attach the metadata
to the GType as setting_property_overrides_quark(). Then during
nm_setting_class_ensure_properties() it would merge them and
set as setting_properties_quark(). Now, during the first phase,
we only incrementally build a properties_override GArray, which
we finally hand over during nm_setting_class_commit().
- sort the property infos by name and do binary search.
Also expose this meta data types as internal API in nm-setting-private.h.
While not accessed yet, it can prove beneficial, to have direct (internal)
access to these structures.
Also, rename NMSettingProperty to NMSettInfoProperty to use a distinct
naming scheme. We already have 40+ subclasses of NMSetting that are called
NMSetting*. Likewise, NMMetaSetting* is heavily used already. So, choose a
new, distinct name.
2018-07-28 15:26:03 +02:00
|
|
|
|
|
|
|
|
_nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_SRIOV,
|
|
|
|
|
NULL, properties_override);
|
2018-05-25 12:05:24 +02:00
|
|
|
}
|