2020-09-29 16:42:22 +02:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2017-08-01 18:36:34 +02:00
|
|
|
/*
|
2019-10-01 09:20:35 +02:00
|
|
|
* Copyright (C) 2017 Red Hat, Inc.
|
2017-08-01 18:36:34 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "nm-default.h"
|
|
|
|
|
|
|
|
|
|
#include "nm-setting-ovs-interface.h"
|
|
|
|
|
|
|
|
|
|
#include "nm-connection-private.h"
|
|
|
|
|
#include "nm-setting-connection.h"
|
|
|
|
|
#include "nm-setting-private.h"
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* SECTION:nm-setting-ovs-interface
|
2018-06-27 16:53:05 +02:00
|
|
|
* @short_description: Describes connection properties for Open vSwitch interfaces.
|
2017-08-01 18:36:34 +02:00
|
|
|
*
|
|
|
|
|
* The #NMSettingOvsInterface object is a #NMSetting subclass that describes properties
|
2018-06-27 16:53:05 +02:00
|
|
|
* necessary for Open vSwitch interfaces.
|
2017-08-01 18:36:34 +02:00
|
|
|
**/
|
|
|
|
|
|
2019-01-11 08:32:54 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_TYPE, );
|
2017-08-01 18:36:34 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* NMSettingOvsInterface:
|
|
|
|
|
*
|
2018-06-27 16:53:05 +02:00
|
|
|
* Open vSwitch Interface Settings
|
2017-08-01 18:36:34 +02:00
|
|
|
*/
|
|
|
|
|
struct _NMSettingOvsInterface {
|
2020-09-28 16:03:33 +02:00
|
|
|
NMSetting parent;
|
2017-08-01 18:36:34 +02:00
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
char *type;
|
2017-08-01 18:36:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct _NMSettingOvsInterfaceClass {
|
2020-09-28 16:03:33 +02:00
|
|
|
NMSettingClass parent;
|
2017-08-01 18:36:34 +02:00
|
|
|
};
|
|
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
G_DEFINE_TYPE(NMSettingOvsInterface, nm_setting_ovs_interface, NM_TYPE_SETTING)
|
2017-08-01 18:36:34 +02:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_setting_ovs_interface_get_interface_type:
|
|
|
|
|
* @self: the #NMSettingOvsInterface
|
|
|
|
|
*
|
|
|
|
|
* Returns: the #NMSettingOvsInterface:type property of the setting
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.10
|
|
|
|
|
**/
|
|
|
|
|
const char *
|
2020-09-28 16:03:33 +02:00
|
|
|
nm_setting_ovs_interface_get_interface_type(NMSettingOvsInterface *self)
|
2017-08-01 18:36:34 +02:00
|
|
|
{
|
2020-09-28 16:03:33 +02:00
|
|
|
g_return_val_if_fail(NM_IS_SETTING_OVS_INTERFACE(self), NULL);
|
2017-08-01 18:36:34 +02:00
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
return self->type;
|
2017-08-01 18:36:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2017-10-27 14:30:18 +02:00
|
|
|
int
|
2020-09-28 16:03:33 +02:00
|
|
|
_nm_setting_ovs_interface_verify_interface_type(NMSettingOvsInterface *self,
|
|
|
|
|
const char * type,
|
|
|
|
|
NMConnection * connection,
|
|
|
|
|
gboolean normalize,
|
|
|
|
|
gboolean * out_modified,
|
|
|
|
|
const char ** out_normalized_type,
|
|
|
|
|
GError ** error)
|
2017-10-27 14:30:18 +02:00
|
|
|
{
|
2020-09-28 16:03:33 +02:00
|
|
|
const char *type_from_setting = NULL;
|
|
|
|
|
const char *type_setting = NULL;
|
|
|
|
|
const char *connection_type;
|
|
|
|
|
gboolean is_ovs_connection_type;
|
|
|
|
|
|
|
|
|
|
if (normalize) {
|
|
|
|
|
g_return_val_if_fail(NM_IS_SETTING_OVS_INTERFACE(self), FALSE);
|
|
|
|
|
g_return_val_if_fail(NM_IS_CONNECTION(connection), FALSE);
|
|
|
|
|
nm_assert(self == nm_connection_get_setting_ovs_interface(connection));
|
|
|
|
|
} else {
|
|
|
|
|
g_return_val_if_fail(!self || NM_IS_SETTING_OVS_INTERFACE(self), FALSE);
|
|
|
|
|
g_return_val_if_fail(!connection || NM_IS_CONNECTION(connection), FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NM_SET_OUT(out_modified, FALSE);
|
|
|
|
|
NM_SET_OUT(out_normalized_type, NULL);
|
|
|
|
|
|
|
|
|
|
if (type && !NM_IN_STRSET(type, "internal", "system", "patch", "dpdk")) {
|
|
|
|
|
g_set_error(error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
|
|
|
_("'%s' is not a valid interface type"),
|
|
|
|
|
type);
|
|
|
|
|
g_prefix_error(error,
|
|
|
|
|
"%s.%s: ",
|
|
|
|
|
NM_SETTING_OVS_INTERFACE_SETTING_NAME,
|
|
|
|
|
NM_SETTING_OVS_INTERFACE_TYPE);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!connection) {
|
|
|
|
|
NM_SET_OUT(out_normalized_type, type);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connection_type = nm_connection_get_connection_type(connection);
|
|
|
|
|
if (!connection_type) {
|
|
|
|
|
/* if we have an ovs-interface, then the connection type must be either
|
2020-09-28 14:50:01 +02:00
|
|
|
* "ovs-interface" (for non "system" type) or anything else (for "system" type).
|
|
|
|
|
*
|
|
|
|
|
* The connection type usually can be normalized based on the presence of a
|
|
|
|
|
* base setting. However, in this case, if the connection type is missing,
|
|
|
|
|
* that is too complicate to guess what the user wanted.
|
|
|
|
|
*
|
|
|
|
|
* Require the use to be explicit and fail. */
|
2020-09-28 16:03:33 +02:00
|
|
|
g_set_error(error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
|
|
|
_("A connection with a '%s' setting needs connection.type explicitly set"),
|
|
|
|
|
NM_SETTING_OVS_INTERFACE_SETTING_NAME);
|
|
|
|
|
g_prefix_error(error,
|
|
|
|
|
"%s.%s: ",
|
|
|
|
|
NM_SETTING_CONNECTION_SETTING_NAME,
|
|
|
|
|
NM_SETTING_CONNECTION_TYPE);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (nm_streq(connection_type, NM_SETTING_OVS_INTERFACE_SETTING_NAME)) {
|
|
|
|
|
if (type && nm_streq(type, "system")) {
|
|
|
|
|
g_set_error(error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
|
|
|
_("A connection of type '%s' cannot have ovs-interface.type \"system\""),
|
|
|
|
|
NM_SETTING_OVS_INTERFACE_SETTING_NAME);
|
|
|
|
|
g_prefix_error(error,
|
|
|
|
|
"%s.%s: ",
|
|
|
|
|
NM_SETTING_OVS_INTERFACE_SETTING_NAME,
|
|
|
|
|
NM_SETTING_OVS_INTERFACE_TYPE);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
is_ovs_connection_type = TRUE;
|
|
|
|
|
} else {
|
|
|
|
|
if (type && !nm_streq(type, "system")) {
|
|
|
|
|
g_set_error(error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
|
|
|
_("A connection of type '%s' cannot have an ovs-interface.type \"%s\""),
|
|
|
|
|
connection_type,
|
|
|
|
|
type);
|
|
|
|
|
g_prefix_error(error,
|
|
|
|
|
"%s.%s: ",
|
|
|
|
|
NM_SETTING_OVS_INTERFACE_SETTING_NAME,
|
|
|
|
|
NM_SETTING_OVS_INTERFACE_TYPE);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
is_ovs_connection_type = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (nm_connection_get_setting_by_name(connection, NM_SETTING_OVS_PATCH_SETTING_NAME)) {
|
|
|
|
|
type_from_setting = "patch";
|
|
|
|
|
type_setting = NM_SETTING_OVS_PATCH_SETTING_NAME;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (nm_connection_get_setting_by_name(connection, NM_SETTING_OVS_DPDK_SETTING_NAME)) {
|
|
|
|
|
if (type_from_setting) {
|
|
|
|
|
g_set_error(error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
|
|
|
_("A connection can not have both '%s' and '%s' settings at the same time"),
|
|
|
|
|
NM_SETTING_OVS_DPDK_SETTING_NAME,
|
|
|
|
|
type_setting);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
type_from_setting = "dpdk";
|
|
|
|
|
type_setting = NM_SETTING_OVS_DPDK_SETTING_NAME;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (type_from_setting) {
|
|
|
|
|
if (!is_ovs_connection_type) {
|
|
|
|
|
g_set_error(error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
|
|
|
_("A connection with '%s' setting must be of connection.type "
|
|
|
|
|
"\"ovs-interface\" but is \"%s\""),
|
|
|
|
|
NM_SETTING_OVS_PATCH_SETTING_NAME,
|
|
|
|
|
connection_type);
|
|
|
|
|
g_prefix_error(error,
|
|
|
|
|
"%s.%s: ",
|
|
|
|
|
NM_SETTING_OVS_INTERFACE_SETTING_NAME,
|
|
|
|
|
NM_SETTING_OVS_INTERFACE_TYPE);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (type) {
|
|
|
|
|
if (!nm_streq(type, type_from_setting)) {
|
|
|
|
|
g_set_error(error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
|
|
|
_("A connection with '%s' setting needs to be of '%s' interface type, "
|
|
|
|
|
"not '%s'"),
|
|
|
|
|
type_setting,
|
|
|
|
|
type_from_setting,
|
|
|
|
|
type);
|
|
|
|
|
g_prefix_error(error,
|
|
|
|
|
"%s.%s: ",
|
|
|
|
|
NM_SETTING_OVS_INTERFACE_SETTING_NAME,
|
|
|
|
|
NM_SETTING_OVS_INTERFACE_TYPE);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
NM_SET_OUT(out_normalized_type, type);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
type = type_from_setting;
|
|
|
|
|
goto normalize;
|
|
|
|
|
} else {
|
|
|
|
|
if (nm_streq0(type, "patch")) {
|
|
|
|
|
g_set_error(
|
|
|
|
|
error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_MISSING_SETTING,
|
|
|
|
|
_("A connection with ovs-interface.type '%s' setting a 'ovs-patch' setting"),
|
|
|
|
|
type);
|
|
|
|
|
g_prefix_error(error,
|
|
|
|
|
"%s.%s: ",
|
|
|
|
|
NM_SETTING_OVS_INTERFACE_SETTING_NAME,
|
|
|
|
|
NM_SETTING_OVS_INTERFACE_TYPE);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (type) {
|
|
|
|
|
NM_SET_OUT(out_normalized_type, type);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (is_ovs_connection_type)
|
|
|
|
|
type = "internal";
|
|
|
|
|
else
|
|
|
|
|
type = "system";
|
|
|
|
|
|
|
|
|
|
NM_SET_OUT(out_normalized_type, type);
|
2020-02-06 17:17:49 +01:00
|
|
|
|
2017-10-27 14:30:18 +02:00
|
|
|
normalize:
|
2020-09-28 16:03:33 +02:00
|
|
|
if (!normalize) {
|
|
|
|
|
if (!self) {
|
|
|
|
|
g_set_error(error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_MISSING_SETTING,
|
|
|
|
|
_("Missing ovs interface setting"));
|
|
|
|
|
g_prefix_error(error, "%s: ", NM_SETTING_OVS_INTERFACE_SETTING_NAME);
|
|
|
|
|
} else {
|
|
|
|
|
g_set_error(error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_MISSING_PROPERTY,
|
|
|
|
|
_("Missing ovs interface type"));
|
|
|
|
|
g_prefix_error(error,
|
|
|
|
|
"%s.%s: ",
|
|
|
|
|
NM_SETTING_OVS_INTERFACE_SETTING_NAME,
|
|
|
|
|
NM_SETTING_OVS_INTERFACE_TYPE);
|
|
|
|
|
}
|
|
|
|
|
return NM_SETTING_VERIFY_NORMALIZABLE_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!self) {
|
|
|
|
|
self = NM_SETTING_OVS_INTERFACE(nm_setting_ovs_interface_new());
|
|
|
|
|
nm_connection_add_setting(connection, NM_SETTING(self));
|
|
|
|
|
}
|
|
|
|
|
g_object_set(self, NM_SETTING_OVS_INTERFACE_TYPE, type, NULL);
|
|
|
|
|
NM_SET_OUT(out_modified, TRUE);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
2017-10-27 14:30:18 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-01 18:36:34 +02:00
|
|
|
static int
|
2020-09-28 16:03:33 +02:00
|
|
|
verify(NMSetting *setting, NMConnection *connection, GError **error)
|
2017-08-01 18:36:34 +02:00
|
|
|
{
|
2020-09-28 16:03:33 +02:00
|
|
|
NMSettingOvsInterface *self = NM_SETTING_OVS_INTERFACE(setting);
|
|
|
|
|
NMSettingConnection * s_con = NULL;
|
|
|
|
|
|
|
|
|
|
if (connection) {
|
|
|
|
|
const char *slave_type;
|
|
|
|
|
|
|
|
|
|
s_con = nm_connection_get_setting_connection(connection);
|
|
|
|
|
if (!s_con) {
|
|
|
|
|
g_set_error(error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_MISSING_SETTING,
|
|
|
|
|
_("missing setting"));
|
|
|
|
|
g_prefix_error(error, "%s: ", NM_SETTING_CONNECTION_SETTING_NAME);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!nm_setting_connection_get_master(s_con)) {
|
|
|
|
|
g_set_error(error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
|
|
|
_("A connection with a '%s' setting must have a master."),
|
|
|
|
|
NM_SETTING_OVS_INTERFACE_SETTING_NAME);
|
|
|
|
|
g_prefix_error(error,
|
|
|
|
|
"%s.%s: ",
|
|
|
|
|
NM_SETTING_CONNECTION_SETTING_NAME,
|
|
|
|
|
NM_SETTING_CONNECTION_MASTER);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
slave_type = nm_setting_connection_get_slave_type(s_con);
|
|
|
|
|
if (slave_type && !nm_streq(slave_type, NM_SETTING_OVS_PORT_SETTING_NAME)) {
|
|
|
|
|
g_set_error(error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
|
|
|
_("A connection with a '%s' setting must have the slave-type set to '%s'. "
|
|
|
|
|
"Instead it is '%s'"),
|
|
|
|
|
NM_SETTING_OVS_INTERFACE_SETTING_NAME,
|
|
|
|
|
NM_SETTING_OVS_PORT_SETTING_NAME,
|
|
|
|
|
slave_type);
|
|
|
|
|
g_prefix_error(error,
|
|
|
|
|
"%s.%s: ",
|
|
|
|
|
NM_SETTING_CONNECTION_SETTING_NAME,
|
|
|
|
|
NM_SETTING_CONNECTION_SLAVE_TYPE);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _nm_setting_ovs_interface_verify_interface_type(self,
|
|
|
|
|
self->type,
|
|
|
|
|
connection,
|
|
|
|
|
FALSE,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
error);
|
2017-08-01 18:36:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void
|
2020-09-28 16:03:33 +02:00
|
|
|
get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
2017-08-01 18:36:34 +02:00
|
|
|
{
|
2020-09-28 16:03:33 +02:00
|
|
|
NMSettingOvsInterface *self = NM_SETTING_OVS_INTERFACE(object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_TYPE:
|
|
|
|
|
g_value_set_string(value, self->type);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-08-01 18:36:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-09-28 16:03:33 +02:00
|
|
|
set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
2017-08-01 18:36:34 +02:00
|
|
|
{
|
2020-09-28 16:03:33 +02:00
|
|
|
NMSettingOvsInterface *self = NM_SETTING_OVS_INTERFACE(object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_TYPE:
|
|
|
|
|
g_free(self->type);
|
|
|
|
|
self->type = g_value_dup_string(value);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-08-01 18:36:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void
|
2020-09-28 16:03:33 +02:00
|
|
|
nm_setting_ovs_interface_init(NMSettingOvsInterface *self)
|
|
|
|
|
{}
|
2017-08-01 18:36:34 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_setting_ovs_interface_new:
|
|
|
|
|
*
|
|
|
|
|
* Creates a new #NMSettingOvsInterface object with default values.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer full): the new empty #NMSettingOvsInterface object
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.10
|
|
|
|
|
**/
|
|
|
|
|
NMSetting *
|
2020-09-28 16:03:33 +02:00
|
|
|
nm_setting_ovs_interface_new(void)
|
2017-08-01 18:36:34 +02:00
|
|
|
{
|
2020-09-28 16:03:33 +02:00
|
|
|
return (NMSetting *) g_object_new(NM_TYPE_SETTING_OVS_INTERFACE, NULL);
|
2017-08-01 18:36:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-09-28 16:03:33 +02:00
|
|
|
finalize(GObject *object)
|
2017-08-01 18:36:34 +02:00
|
|
|
{
|
2020-09-28 16:03:33 +02:00
|
|
|
NMSettingOvsInterface *self = NM_SETTING_OVS_INTERFACE(object);
|
2017-08-01 18:36:34 +02:00
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
g_free(self->type);
|
2017-08-01 18:36:34 +02:00
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
G_OBJECT_CLASS(nm_setting_ovs_interface_parent_class)->finalize(object);
|
2017-08-01 18:36:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-09-28 16:03:33 +02:00
|
|
|
nm_setting_ovs_interface_class_init(NMSettingOvsInterfaceClass *klass)
|
2017-08-01 18:36:34 +02:00
|
|
|
{
|
2020-09-28 16:03:33 +02:00
|
|
|
GObjectClass * object_class = G_OBJECT_CLASS(klass);
|
|
|
|
|
NMSettingClass *setting_class = NM_SETTING_CLASS(klass);
|
2017-08-01 18:36:34 +02:00
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
object_class->get_property = get_property;
|
|
|
|
|
object_class->set_property = set_property;
|
|
|
|
|
object_class->finalize = finalize;
|
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
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
setting_class->verify = verify;
|
2017-08-01 18:36:34 +02:00
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
/**
|
2020-09-28 14:50:01 +02:00
|
|
|
* NMSettingOvsInterface:type:
|
|
|
|
|
*
|
|
|
|
|
* The interface type. Either "internal", "system", "patch", "dpdk", or empty.
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.10
|
|
|
|
|
**/
|
2020-09-28 16:03:33 +02:00
|
|
|
obj_properties[PROP_TYPE] = g_param_spec_string(NM_SETTING_OVS_INTERFACE_TYPE,
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
NULL,
|
|
|
|
|
G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE
|
|
|
|
|
| G_PARAM_STATIC_STRINGS);
|
2019-01-11 08:28:26 +01:00
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
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
|
|
|
|
2020-09-28 16:03:33 +02:00
|
|
|
_nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_OVS_INTERFACE);
|
2017-08-01 18:36:34 +02:00
|
|
|
}
|