2020-09-29 16:42:22 +02:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2016-06-30 18:20:43 +02:00
|
|
|
/*
|
2019-10-01 09:20:35 +02:00
|
|
|
* Copyright (C) 2017 Red Hat, Inc.
|
2016-06-30 18:20:43 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "nm-default.h"
|
|
|
|
|
|
|
|
|
|
#include "nm-setting-macsec.h"
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
2019-04-15 08:16:00 +02:00
|
|
|
#include "nm-glib-aux/nm-secret-utils.h"
|
2018-09-27 16:51:56 +02:00
|
|
|
|
2016-06-30 18:20:43 +02:00
|
|
|
#include "nm-utils.h"
|
|
|
|
|
#include "nm-core-types-internal.h"
|
|
|
|
|
#include "nm-setting-connection.h"
|
|
|
|
|
#include "nm-setting-private.h"
|
|
|
|
|
#include "nm-setting-wired.h"
|
|
|
|
|
#include "nm-connection-private.h"
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* SECTION:nm-setting-macsec
|
|
|
|
|
* @short_description: Describes connection properties for MACSEC interfaces
|
|
|
|
|
*
|
|
|
|
|
* The #NMSettingMacsec object is a #NMSetting subclass that describes properties
|
|
|
|
|
* necessary for connection to MACsec (IEEE 802.1AE) interfaces.
|
|
|
|
|
**/
|
|
|
|
|
|
2019-01-11 08:32:54 +01:00
|
|
|
/*****************************************************************************/
|
2016-06-30 18:20:43 +02:00
|
|
|
|
2019-01-11 08:32:54 +01:00
|
|
|
NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_PARENT,
|
|
|
|
|
PROP_MODE,
|
|
|
|
|
PROP_ENCRYPT,
|
|
|
|
|
PROP_MKA_CAK,
|
|
|
|
|
PROP_MKA_CAK_FLAGS,
|
|
|
|
|
PROP_MKA_CKN,
|
|
|
|
|
PROP_PORT,
|
|
|
|
|
PROP_VALIDATION,
|
|
|
|
|
PROP_SEND_SCI, );
|
2016-06-30 18:20:43 +02:00
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
char * parent;
|
|
|
|
|
char * mka_cak;
|
|
|
|
|
char * mka_ckn;
|
|
|
|
|
int port;
|
2019-12-12 11:51:21 +01:00
|
|
|
NMSettingMacsecMode mode;
|
|
|
|
|
NMSettingSecretFlags mka_cak_flags;
|
2016-06-30 18:20:43 +02:00
|
|
|
NMSettingMacsecValidation validation;
|
2019-12-12 11:51:21 +01:00
|
|
|
bool encrypt : 1;
|
|
|
|
|
bool send_sci : 1;
|
2016-06-30 18:20:43 +02:00
|
|
|
} NMSettingMacsecPrivate;
|
|
|
|
|
|
2019-01-11 08:32:54 +01:00
|
|
|
G_DEFINE_TYPE(NMSettingMacsec, nm_setting_macsec, NM_TYPE_SETTING)
|
2016-06-30 18:20:43 +02:00
|
|
|
|
2019-01-11 08:32:54 +01:00
|
|
|
#define NM_SETTING_MACSEC_GET_PRIVATE(o) \
|
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE((o), NM_TYPE_SETTING_MACSEC, NMSettingMacsecPrivate))
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2016-06-30 18:20:43 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_setting_macsec_get_parent:
|
|
|
|
|
* @setting: the #NMSettingMacsec
|
|
|
|
|
*
|
|
|
|
|
* Returns: the #NMSettingMacsec:parent property of the setting
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.6
|
|
|
|
|
**/
|
|
|
|
|
const char *
|
|
|
|
|
nm_setting_macsec_get_parent(NMSettingMacsec *setting)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail(NM_IS_SETTING_MACSEC(setting), NULL);
|
|
|
|
|
return NM_SETTING_MACSEC_GET_PRIVATE(setting)->parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_setting_macsec_get_mode:
|
|
|
|
|
* @setting: the #NMSettingMacsec
|
|
|
|
|
*
|
|
|
|
|
* Returns: the #NMSettingMacsec:mode property of the setting
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.6
|
|
|
|
|
**/
|
|
|
|
|
NMSettingMacsecMode
|
|
|
|
|
nm_setting_macsec_get_mode(NMSettingMacsec *setting)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail(NM_IS_SETTING_MACSEC(setting), NM_SETTING_MACSEC_MODE_PSK);
|
|
|
|
|
return NM_SETTING_MACSEC_GET_PRIVATE(setting)->mode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_setting_macsec_get_encrypt:
|
|
|
|
|
* @setting: the #NMSettingMacsec
|
|
|
|
|
*
|
|
|
|
|
* Returns: the #NMSettingMacsec:encrypt property of the setting
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.6
|
|
|
|
|
**/
|
|
|
|
|
gboolean
|
|
|
|
|
nm_setting_macsec_get_encrypt(NMSettingMacsec *setting)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail(NM_IS_SETTING_MACSEC(setting), TRUE);
|
|
|
|
|
return NM_SETTING_MACSEC_GET_PRIVATE(setting)->encrypt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_setting_macsec_get_mka_cak
|
|
|
|
|
* @setting: the #NMSettingMacsec
|
|
|
|
|
*
|
|
|
|
|
* Returns: the #NMSettingMacsec:mka-cak property of the setting
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.6
|
|
|
|
|
**/
|
|
|
|
|
const char *
|
|
|
|
|
nm_setting_macsec_get_mka_cak(NMSettingMacsec *setting)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail(NM_IS_SETTING_MACSEC(setting), NULL);
|
|
|
|
|
return NM_SETTING_MACSEC_GET_PRIVATE(setting)->mka_cak;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_setting_macsec_get_mka_cak_flags:
|
|
|
|
|
* @setting: the #NMSettingMacsec
|
|
|
|
|
*
|
|
|
|
|
* Returns: the #NMSettingSecretFlags pertaining to the #NMSettingMacsec:mka-cak
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.6
|
|
|
|
|
**/
|
|
|
|
|
NMSettingSecretFlags
|
|
|
|
|
nm_setting_macsec_get_mka_cak_flags(NMSettingMacsec *setting)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail(NM_IS_SETTING_MACSEC(setting), NM_SETTING_SECRET_FLAG_NONE);
|
|
|
|
|
|
|
|
|
|
return NM_SETTING_MACSEC_GET_PRIVATE(setting)->mka_cak_flags;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_setting_macsec_get_mka_ckn:
|
|
|
|
|
* @setting: the #NMSettingMacsec
|
|
|
|
|
*
|
|
|
|
|
* Returns: the #NMSettingMacsec:mka-ckn property of the setting
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.6
|
|
|
|
|
**/
|
|
|
|
|
const char *
|
|
|
|
|
nm_setting_macsec_get_mka_ckn(NMSettingMacsec *setting)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail(NM_IS_SETTING_MACSEC(setting), NULL);
|
|
|
|
|
return NM_SETTING_MACSEC_GET_PRIVATE(setting)->mka_ckn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_setting_macsec_get_port:
|
|
|
|
|
* @setting: the #NMSettingMacsec
|
|
|
|
|
*
|
|
|
|
|
* Returns: the #NMSettingMacsec:port property of the setting
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.6
|
|
|
|
|
**/
|
|
|
|
|
int
|
|
|
|
|
nm_setting_macsec_get_port(NMSettingMacsec *setting)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail(NM_IS_SETTING_MACSEC(setting), 1);
|
|
|
|
|
return NM_SETTING_MACSEC_GET_PRIVATE(setting)->port;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_setting_macsec_get_validation:
|
|
|
|
|
* @setting: the #NMSettingMacsec
|
|
|
|
|
*
|
|
|
|
|
* Returns: the #NMSettingMacsec:validation property of the setting
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.6
|
|
|
|
|
**/
|
|
|
|
|
NMSettingMacsecValidation
|
|
|
|
|
nm_setting_macsec_get_validation(NMSettingMacsec *setting)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail(NM_IS_SETTING_MACSEC(setting), NM_SETTING_MACSEC_VALIDATION_DISABLE);
|
|
|
|
|
return NM_SETTING_MACSEC_GET_PRIVATE(setting)->validation;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-06 15:26:17 +02:00
|
|
|
/**
|
|
|
|
|
* nm_setting_macsec_get_send_sci:
|
|
|
|
|
* @setting: the #NMSettingMacsec
|
|
|
|
|
*
|
|
|
|
|
* Returns: the #NMSettingMacsec:send-sci property of the setting
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.12
|
|
|
|
|
**/
|
|
|
|
|
gboolean
|
|
|
|
|
nm_setting_macsec_get_send_sci(NMSettingMacsec *setting)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail(NM_IS_SETTING_MACSEC(setting), TRUE);
|
|
|
|
|
return NM_SETTING_MACSEC_GET_PRIVATE(setting)->send_sci;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-30 18:20:43 +02:00
|
|
|
static GPtrArray *
|
|
|
|
|
need_secrets(NMSetting *setting)
|
|
|
|
|
{
|
|
|
|
|
NMSettingMacsecPrivate *priv = NM_SETTING_MACSEC_GET_PRIVATE(setting);
|
|
|
|
|
GPtrArray * secrets = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-06-30 18:20:43 +02:00
|
|
|
if (priv->mode == NM_SETTING_MACSEC_MODE_PSK) {
|
|
|
|
|
if (!priv->mka_cak
|
|
|
|
|
&& !NM_FLAGS_HAS(priv->mka_cak_flags, NM_SETTING_SECRET_FLAG_NOT_REQUIRED)) {
|
|
|
|
|
secrets = g_ptr_array_sized_new(1);
|
|
|
|
|
g_ptr_array_add(secrets, NM_SETTING_MACSEC_MKA_CAK);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-06-30 18:20:43 +02:00
|
|
|
return secrets;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*********************************************************************/
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
verify_macsec_key(const char *key, gboolean cak, GError **error)
|
|
|
|
|
{
|
|
|
|
|
int req_len;
|
|
|
|
|
|
2018-11-02 10:54:26 +01:00
|
|
|
/* CAK is a connection secret and can be NULL for various
|
|
|
|
|
* reasons (agent-owned, no permissions to get secrets, etc.)
|
|
|
|
|
*/
|
|
|
|
|
if (cak && !key)
|
|
|
|
|
return TRUE;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-06-30 18:20:43 +02:00
|
|
|
if (!key || !key[0]) {
|
|
|
|
|
g_set_error_literal(error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
|
|
|
_("the key is empty"));
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-06-30 18:20:43 +02:00
|
|
|
req_len = cak ? NM_SETTING_MACSEC_MKA_CAK_LENGTH : NM_SETTING_MACSEC_MKA_CKN_LENGTH;
|
2018-09-27 16:51:56 +02:00
|
|
|
if (strlen(key) != (gsize) req_len) {
|
2016-06-30 18:20:43 +02:00
|
|
|
g_set_error(error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
|
|
|
_("the key must be %d characters"),
|
|
|
|
|
req_len);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-06-30 18:20:43 +02:00
|
|
|
if (!NM_STRCHAR_ALL(key, ch, g_ascii_isxdigit(ch))) {
|
|
|
|
|
g_set_error_literal(error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
2017-03-17 15:57:50 +02:00
|
|
|
_("the key contains non-hexadecimal characters"));
|
2016-06-30 18:20:43 +02:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-06-30 18:20:43 +02:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
verify(NMSetting *setting, NMConnection *connection, GError **error)
|
|
|
|
|
{
|
|
|
|
|
NMSettingMacsecPrivate *priv = NM_SETTING_MACSEC_GET_PRIVATE(setting);
|
|
|
|
|
NMSettingConnection * s_con = NULL;
|
|
|
|
|
NMSettingWired * s_wired = NULL;
|
|
|
|
|
NMSetting8021x * s_8021x = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-06-30 18:20:43 +02:00
|
|
|
if (connection) {
|
|
|
|
|
s_con = nm_connection_get_setting_connection(connection);
|
|
|
|
|
s_wired = nm_connection_get_setting_wired(connection);
|
|
|
|
|
s_8021x = nm_connection_get_setting_802_1x(connection);
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-06-30 18:20:43 +02:00
|
|
|
if (priv->parent) {
|
|
|
|
|
if (nm_utils_is_uuid(priv->parent)) {
|
|
|
|
|
/* If we have an NMSettingConnection:master with slave-type="macsec",
|
|
|
|
|
* then it must be the same UUID.
|
|
|
|
|
*/
|
|
|
|
|
if (s_con) {
|
|
|
|
|
const char *master = NULL, *slave_type = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-06-30 18:20:43 +02:00
|
|
|
slave_type = nm_setting_connection_get_slave_type(s_con);
|
|
|
|
|
if (!g_strcmp0(slave_type, NM_SETTING_MACSEC_SETTING_NAME))
|
|
|
|
|
master = nm_setting_connection_get_master(s_con);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-06-30 18:20:43 +02:00
|
|
|
if (master && g_strcmp0(priv->parent, master) != 0) {
|
|
|
|
|
g_set_error(error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
|
|
|
_("'%s' value doesn't match '%s=%s'"),
|
|
|
|
|
priv->parent,
|
|
|
|
|
NM_SETTING_CONNECTION_MASTER,
|
|
|
|
|
master);
|
|
|
|
|
g_prefix_error(error,
|
|
|
|
|
"%s.%s: ",
|
|
|
|
|
NM_SETTING_MACSEC_SETTING_NAME,
|
|
|
|
|
NM_SETTING_MACSEC_PARENT);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
}
|
2016-06-30 18:20:43 +02:00
|
|
|
} else if (!nm_utils_iface_valid_name(priv->parent)) {
|
|
|
|
|
/* parent must be either a UUID or an interface name */
|
|
|
|
|
g_set_error(error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
|
|
|
_("'%s' is neither an UUID nor an interface name"),
|
|
|
|
|
priv->parent);
|
|
|
|
|
g_prefix_error(error,
|
|
|
|
|
"%s.%s: ",
|
|
|
|
|
NM_SETTING_MACSEC_SETTING_NAME,
|
|
|
|
|
NM_SETTING_MACSEC_PARENT);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* If parent is NULL, the parent must be specified via
|
|
|
|
|
* NMSettingWired:mac-address.
|
|
|
|
|
*/
|
|
|
|
|
if (connection && (!s_wired || !nm_setting_wired_get_mac_address(s_wired))) {
|
|
|
|
|
g_set_error(error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_MISSING_PROPERTY,
|
|
|
|
|
_("property is not specified and neither is '%s:%s'"),
|
|
|
|
|
NM_SETTING_WIRED_SETTING_NAME,
|
|
|
|
|
NM_SETTING_WIRED_MAC_ADDRESS);
|
|
|
|
|
g_prefix_error(error,
|
|
|
|
|
"%s.%s: ",
|
|
|
|
|
NM_SETTING_MACSEC_SETTING_NAME,
|
|
|
|
|
NM_SETTING_MACSEC_PARENT);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
}
|
|
|
|
|
|
2016-06-30 18:20:43 +02:00
|
|
|
if (priv->mode == NM_SETTING_MACSEC_MODE_PSK) {
|
|
|
|
|
if (!verify_macsec_key(priv->mka_ckn, FALSE, error)) {
|
|
|
|
|
g_prefix_error(error,
|
|
|
|
|
"%s.%s: ",
|
|
|
|
|
NM_SETTING_MACSEC_SETTING_NAME,
|
|
|
|
|
NM_SETTING_MACSEC_MKA_CKN);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2018-09-27 16:51:56 +02:00
|
|
|
if (!verify_macsec_key(priv->mka_cak, TRUE, error)) {
|
|
|
|
|
g_prefix_error(error,
|
|
|
|
|
"%s.%s: ",
|
|
|
|
|
NM_SETTING_MACSEC_SETTING_NAME,
|
|
|
|
|
NM_SETTING_MACSEC_MKA_CAK);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2016-06-30 18:20:43 +02:00
|
|
|
} else if (priv->mode == NM_SETTING_MACSEC_MODE_EAP) {
|
|
|
|
|
if (!s_8021x) {
|
|
|
|
|
g_set_error(error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_MISSING_SETTING,
|
|
|
|
|
_("EAP key management requires '%s' setting presence"),
|
|
|
|
|
NM_SETTING_802_1X_SETTING_NAME);
|
|
|
|
|
g_prefix_error(error, "%s: ", NM_SETTING_MACSEC_SETTING_NAME);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2018-09-27 16:51:56 +02:00
|
|
|
} else {
|
|
|
|
|
g_set_error_literal(error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
|
|
|
_("must be either psk (0) or eap (1)"));
|
|
|
|
|
g_prefix_error(error, "%s.%s: ", NM_SETTING_MACSEC_SETTING_NAME, NM_SETTING_MACSEC_MODE);
|
|
|
|
|
return FALSE;
|
2016-06-30 18:20:43 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-06-30 18:20:43 +02:00
|
|
|
if (priv->port <= 0 || priv->port > 65534) {
|
|
|
|
|
g_set_error(error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_MISSING_PROPERTY,
|
|
|
|
|
_("invalid port %d"),
|
|
|
|
|
priv->port);
|
|
|
|
|
g_prefix_error(error, "%s.%s: ", NM_SETTING_MACSEC_SETTING_NAME, NM_SETTING_MACSEC_PORT);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-09-27 16:51:56 +02:00
|
|
|
if (priv->mode != NM_SETTING_MACSEC_MODE_PSK && (priv->mka_cak || priv->mka_ckn)) {
|
|
|
|
|
g_set_error_literal(error,
|
|
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
|
|
|
_("only valid for psk mode"));
|
|
|
|
|
g_prefix_error(error,
|
|
|
|
|
"%s.%s: ",
|
|
|
|
|
NM_SETTING_MACSEC_SETTING_NAME,
|
|
|
|
|
priv->mka_cak ? NM_SETTING_MACSEC_MKA_CAK : NM_SETTING_MACSEC_MKA_CKN);
|
|
|
|
|
return NM_SETTING_VERIFY_NORMALIZABLE;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-06-30 18:20:43 +02:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-11 08:32:54 +01:00
|
|
|
/*****************************************************************************/
|
2016-06-30 18:20:43 +02:00
|
|
|
|
|
|
|
|
static void
|
2019-01-11 08:32:54 +01:00
|
|
|
get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
2016-06-30 18:20:43 +02:00
|
|
|
{
|
|
|
|
|
NMSettingMacsec * setting = NM_SETTING_MACSEC(object);
|
|
|
|
|
NMSettingMacsecPrivate *priv = NM_SETTING_MACSEC_GET_PRIVATE(setting);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-06-30 18:20:43 +02:00
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_PARENT:
|
2019-01-11 08:32:54 +01:00
|
|
|
g_value_set_string(value, priv->parent);
|
2016-06-30 18:20:43 +02:00
|
|
|
break;
|
|
|
|
|
case PROP_MODE:
|
2019-01-11 08:32:54 +01:00
|
|
|
g_value_set_int(value, priv->mode);
|
2016-06-30 18:20:43 +02:00
|
|
|
break;
|
|
|
|
|
case PROP_ENCRYPT:
|
2019-01-11 08:32:54 +01:00
|
|
|
g_value_set_boolean(value, priv->encrypt);
|
2016-06-30 18:20:43 +02:00
|
|
|
break;
|
|
|
|
|
case PROP_MKA_CAK:
|
2019-01-11 08:32:54 +01:00
|
|
|
g_value_set_string(value, priv->mka_cak);
|
2016-06-30 18:20:43 +02:00
|
|
|
break;
|
|
|
|
|
case PROP_MKA_CAK_FLAGS:
|
2019-01-11 08:32:54 +01:00
|
|
|
g_value_set_flags(value, priv->mka_cak_flags);
|
2016-06-30 18:20:43 +02:00
|
|
|
break;
|
|
|
|
|
case PROP_MKA_CKN:
|
2019-01-11 08:32:54 +01:00
|
|
|
g_value_set_string(value, priv->mka_ckn);
|
2016-06-30 18:20:43 +02:00
|
|
|
break;
|
|
|
|
|
case PROP_PORT:
|
2019-01-11 08:32:54 +01:00
|
|
|
g_value_set_int(value, priv->port);
|
2016-06-30 18:20:43 +02:00
|
|
|
break;
|
|
|
|
|
case PROP_VALIDATION:
|
2019-01-11 08:32:54 +01:00
|
|
|
g_value_set_int(value, priv->validation);
|
2016-06-30 18:20:43 +02:00
|
|
|
break;
|
2018-06-06 15:26:17 +02:00
|
|
|
case PROP_SEND_SCI:
|
2019-01-11 08:32:54 +01:00
|
|
|
g_value_set_boolean(value, priv->send_sci);
|
2018-06-06 15:26:17 +02:00
|
|
|
break;
|
2016-06-30 18:20:43 +02:00
|
|
|
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)
|
2016-06-30 18:20:43 +02:00
|
|
|
{
|
|
|
|
|
NMSettingMacsec * setting = NM_SETTING_MACSEC(object);
|
|
|
|
|
NMSettingMacsecPrivate *priv = NM_SETTING_MACSEC_GET_PRIVATE(setting);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-06-30 18:20:43 +02:00
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_PARENT:
|
2019-01-11 08:32:54 +01:00
|
|
|
g_free(priv->parent);
|
|
|
|
|
priv->parent = g_value_dup_string(value);
|
2016-06-30 18:20:43 +02:00
|
|
|
break;
|
|
|
|
|
case PROP_MODE:
|
2019-01-11 08:32:54 +01:00
|
|
|
priv->mode = g_value_get_int(value);
|
2016-06-30 18:20:43 +02:00
|
|
|
break;
|
|
|
|
|
case PROP_ENCRYPT:
|
2019-01-11 08:32:54 +01:00
|
|
|
priv->encrypt = g_value_get_boolean(value);
|
2016-06-30 18:20:43 +02:00
|
|
|
break;
|
|
|
|
|
case PROP_MKA_CAK:
|
2019-01-11 08:32:54 +01:00
|
|
|
nm_free_secret(priv->mka_cak);
|
|
|
|
|
priv->mka_cak = g_value_dup_string(value);
|
2016-06-30 18:20:43 +02:00
|
|
|
break;
|
|
|
|
|
case PROP_MKA_CAK_FLAGS:
|
2019-01-11 08:32:54 +01:00
|
|
|
priv->mka_cak_flags = g_value_get_flags(value);
|
2016-06-30 18:20:43 +02:00
|
|
|
break;
|
|
|
|
|
case PROP_MKA_CKN:
|
2019-01-11 08:32:54 +01:00
|
|
|
g_free(priv->mka_ckn);
|
|
|
|
|
priv->mka_ckn = g_value_dup_string(value);
|
2016-06-30 18:20:43 +02:00
|
|
|
break;
|
|
|
|
|
case PROP_PORT:
|
2019-01-11 08:32:54 +01:00
|
|
|
priv->port = g_value_get_int(value);
|
2016-06-30 18:20:43 +02:00
|
|
|
break;
|
|
|
|
|
case PROP_VALIDATION:
|
2019-01-11 08:32:54 +01:00
|
|
|
priv->validation = g_value_get_int(value);
|
2016-06-30 18:20:43 +02:00
|
|
|
break;
|
2018-06-06 15:26:17 +02:00
|
|
|
case PROP_SEND_SCI:
|
2019-01-11 08:32:54 +01:00
|
|
|
priv->send_sci = g_value_get_boolean(value);
|
2018-06-06 15:26:17 +02:00
|
|
|
break;
|
2016-06-30 18:20:43 +02:00
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-11 08:32:54 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void
|
2019-12-12 11:52:11 +01:00
|
|
|
nm_setting_macsec_init(NMSettingMacsec *self)
|
2019-01-11 08:32:54 +01:00
|
|
|
{
|
2019-12-12 11:52:11 +01:00
|
|
|
NMSettingMacsecPrivate *priv = NM_SETTING_MACSEC_GET_PRIVATE(self);
|
|
|
|
|
|
|
|
|
|
nm_assert(priv->mode == NM_SETTING_MACSEC_MODE_PSK);
|
|
|
|
|
priv->encrypt = TRUE;
|
|
|
|
|
priv->port = 1;
|
|
|
|
|
priv->send_sci = TRUE;
|
|
|
|
|
priv->validation = NM_SETTING_MACSEC_VALIDATION_STRICT;
|
2019-01-11 08:32:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_setting_macsec_new:
|
|
|
|
|
*
|
|
|
|
|
* Creates a new #NMSettingMacsec object with default values.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer full): the new empty #NMSettingMacsec object
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.6
|
|
|
|
|
**/
|
|
|
|
|
NMSetting *
|
|
|
|
|
nm_setting_macsec_new(void)
|
|
|
|
|
{
|
2020-11-12 15:57:06 +01:00
|
|
|
return g_object_new(NM_TYPE_SETTING_MACSEC, NULL);
|
2019-01-11 08:32:54 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-30 18:20:43 +02:00
|
|
|
static void
|
|
|
|
|
finalize(GObject *object)
|
|
|
|
|
{
|
|
|
|
|
NMSettingMacsec * setting = NM_SETTING_MACSEC(object);
|
|
|
|
|
NMSettingMacsecPrivate *priv = NM_SETTING_MACSEC_GET_PRIVATE(setting);
|
|
|
|
|
|
|
|
|
|
g_free(priv->parent);
|
2018-09-27 16:51:56 +02:00
|
|
|
nm_free_secret(priv->mka_cak);
|
2016-06-30 18:20:43 +02:00
|
|
|
g_free(priv->mka_ckn);
|
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS(nm_setting_macsec_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_macsec_class_init(NMSettingMacsecClass *klass)
|
2016-06-30 18:20:43 +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);
|
2016-06-30 18:20:43 +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
|
|
|
g_type_class_add_private(klass, sizeof(NMSettingMacsecPrivate));
|
2016-06-30 18:20:43 +02:00
|
|
|
|
|
|
|
|
object_class->get_property = get_property;
|
2019-01-11 08:32:54 +01:00
|
|
|
object_class->set_property = set_property;
|
2016-06-30 18:20:43 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
setting_class->verify = verify;
|
|
|
|
|
setting_class->need_secrets = need_secrets;
|
2016-06-30 18:20:43 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* NMSettingMacsec:parent:
|
|
|
|
|
*
|
|
|
|
|
* If given, specifies the parent interface name or parent connection UUID
|
|
|
|
|
* from which this MACSEC interface should be created. If this property is
|
|
|
|
|
* not specified, the connection must contain an #NMSettingWired setting
|
|
|
|
|
* with a #NMSettingWired:mac-address property.
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.6
|
|
|
|
|
**/
|
|
|
|
|
obj_properties[PROP_PARENT] = g_param_spec_string(
|
|
|
|
|
NM_SETTING_MACSEC_PARENT,
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
NULL,
|
|
|
|
|
G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-06-30 18:20:43 +02:00
|
|
|
/**
|
|
|
|
|
* NMSettingMacsec:mode:
|
|
|
|
|
*
|
|
|
|
|
* Specifies how the CAK (Connectivity Association Key) for MKA (MACsec Key
|
|
|
|
|
* Agreement) is obtained.
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.6
|
|
|
|
|
**/
|
|
|
|
|
obj_properties[PROP_MODE] =
|
|
|
|
|
g_param_spec_int(NM_SETTING_MACSEC_MODE,
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
G_MININT,
|
|
|
|
|
G_MAXINT,
|
|
|
|
|
NM_SETTING_MACSEC_MODE_PSK,
|
|
|
|
|
G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-06-30 18:20:43 +02:00
|
|
|
/**
|
|
|
|
|
* NMSettingMacsec:encrypt:
|
|
|
|
|
*
|
|
|
|
|
* Whether the transmitted traffic must be encrypted.
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.6
|
|
|
|
|
**/
|
|
|
|
|
obj_properties[PROP_ENCRYPT] = g_param_spec_boolean(NM_SETTING_MACSEC_ENCRYPT,
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
TRUE,
|
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* NMSettingMacsec:mka-cak:
|
|
|
|
|
*
|
|
|
|
|
* The pre-shared CAK (Connectivity Association Key) for MACsec
|
|
|
|
|
* Key Agreement.
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.6
|
|
|
|
|
**/
|
|
|
|
|
obj_properties[PROP_MKA_CAK] =
|
|
|
|
|
g_param_spec_string(NM_SETTING_MACSEC_MKA_CAK,
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
NULL,
|
|
|
|
|
G_PARAM_READWRITE | NM_SETTING_PARAM_SECRET | G_PARAM_STATIC_STRINGS);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-06-30 18:20:43 +02:00
|
|
|
/**
|
|
|
|
|
* NMSettingMacsec:mka-cak-flags:
|
|
|
|
|
*
|
|
|
|
|
* Flags indicating how to handle the #NMSettingMacsec:mka-cak
|
|
|
|
|
* property.
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.6
|
|
|
|
|
**/
|
|
|
|
|
obj_properties[PROP_MKA_CAK_FLAGS] =
|
|
|
|
|
g_param_spec_flags(NM_SETTING_MACSEC_MKA_CAK_FLAGS,
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
NM_TYPE_SETTING_SECRET_FLAGS,
|
|
|
|
|
NM_SETTING_SECRET_FLAG_NONE,
|
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-06-30 18:20:43 +02:00
|
|
|
/**
|
|
|
|
|
* NMSettingMacsec:mka-ckn:
|
|
|
|
|
*
|
|
|
|
|
* The pre-shared CKN (Connectivity-association Key Name) for
|
|
|
|
|
* MACsec Key Agreement.
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.6
|
|
|
|
|
**/
|
|
|
|
|
obj_properties[PROP_MKA_CKN] = g_param_spec_string(NM_SETTING_MACSEC_MKA_CKN,
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
NULL,
|
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* NMSettingMacsec:port:
|
|
|
|
|
*
|
|
|
|
|
* The port component of the SCI (Secure Channel Identifier), between 1 and 65534.
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.6
|
|
|
|
|
**/
|
|
|
|
|
obj_properties[PROP_PORT] =
|
|
|
|
|
g_param_spec_int(NM_SETTING_MACSEC_PORT,
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
1,
|
|
|
|
|
65534,
|
|
|
|
|
1,
|
|
|
|
|
G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-06-30 18:20:43 +02:00
|
|
|
/**
|
|
|
|
|
* NMSettingMacsec:validation:
|
|
|
|
|
*
|
|
|
|
|
* Specifies the validation mode for incoming frames.
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.6
|
|
|
|
|
**/
|
|
|
|
|
obj_properties[PROP_VALIDATION] =
|
|
|
|
|
g_param_spec_int(NM_SETTING_MACSEC_VALIDATION,
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
G_MININT,
|
|
|
|
|
G_MAXINT,
|
|
|
|
|
NM_SETTING_MACSEC_VALIDATION_STRICT,
|
|
|
|
|
G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-06-06 15:26:17 +02:00
|
|
|
/**
|
|
|
|
|
* NMSettingMacsec:send-sci:
|
|
|
|
|
*
|
|
|
|
|
* Specifies whether the SCI (Secure Channel Identifier) is included
|
|
|
|
|
* in every packet.
|
|
|
|
|
*
|
|
|
|
|
* Since: 1.12
|
|
|
|
|
**/
|
|
|
|
|
obj_properties[PROP_SEND_SCI] =
|
|
|
|
|
g_param_spec_boolean(NM_SETTING_MACSEC_SEND_SCI,
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
TRUE,
|
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
2016-06-30 18:20:43 +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
|
|
|
|
|
|
|
|
_nm_setting_class_commit(setting_class, NM_META_SETTING_TYPE_MACSEC);
|
2016-06-30 18:20:43 +02:00
|
|
|
}
|