2016-06-30 18:20:22 +02:00
|
|
|
/* NetworkManager -- Network link manager
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2017 Red Hat, Inc.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "nm-default.h"
|
|
|
|
|
|
|
|
|
|
#include "nm-device-macsec.h"
|
|
|
|
|
|
2016-06-30 18:20:50 +02:00
|
|
|
#include "nm-act-request.h"
|
2016-06-30 18:20:22 +02:00
|
|
|
#include "nm-device-private.h"
|
|
|
|
|
#include "platform/nm-platform.h"
|
|
|
|
|
#include "nm-device-factory.h"
|
|
|
|
|
#include "nm-manager.h"
|
2016-06-30 18:20:50 +02:00
|
|
|
#include "nm-setting-macsec.h"
|
2016-06-30 18:20:22 +02:00
|
|
|
#include "nm-core-internal.h"
|
2016-06-30 18:20:50 +02:00
|
|
|
#include "supplicant/nm-supplicant-manager.h"
|
|
|
|
|
#include "supplicant/nm-supplicant-interface.h"
|
|
|
|
|
#include "supplicant/nm-supplicant-config.h"
|
2016-06-30 18:20:22 +02:00
|
|
|
|
|
|
|
|
#include "nm-device-logging.h"
|
|
|
|
|
_LOG_DECLARE_SELF(NMDeviceMacsec);
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2016-06-30 18:20:50 +02:00
|
|
|
typedef struct Supplicant {
|
|
|
|
|
NMSupplicantManager *mgr;
|
|
|
|
|
NMSupplicantInterface *iface;
|
|
|
|
|
|
|
|
|
|
/* signal handler ids */
|
|
|
|
|
gulong iface_state_id;
|
|
|
|
|
|
|
|
|
|
/* Timeouts and idles */
|
|
|
|
|
guint con_timeout_id;
|
|
|
|
|
} Supplicant;
|
|
|
|
|
|
2016-06-30 18:20:22 +02:00
|
|
|
NM_GOBJECT_PROPERTIES_DEFINE (NMDeviceMacsec,
|
|
|
|
|
PROP_SCI,
|
|
|
|
|
PROP_CIPHER_SUITE,
|
|
|
|
|
PROP_ICV_LENGTH,
|
|
|
|
|
PROP_WINDOW,
|
|
|
|
|
PROP_ENCODING_SA,
|
|
|
|
|
PROP_ENCRYPT,
|
|
|
|
|
PROP_PROTECT,
|
|
|
|
|
PROP_INCLUDE_SCI,
|
|
|
|
|
PROP_ES,
|
|
|
|
|
PROP_SCB,
|
|
|
|
|
PROP_REPLAY_PROTECT,
|
|
|
|
|
PROP_VALIDATION,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
NMPlatformLnkMacsec props;
|
|
|
|
|
gulong parent_state_id;
|
2016-06-30 18:20:50 +02:00
|
|
|
Supplicant supplicant;
|
|
|
|
|
guint supplicant_timeout_id;
|
2017-11-24 16:24:40 +01:00
|
|
|
NMActRequestGetSecretsCallId *macsec_secrets_id;
|
2016-06-30 18:20:22 +02:00
|
|
|
} NMDeviceMacsecPrivate;
|
|
|
|
|
|
|
|
|
|
struct _NMDeviceMacsec {
|
|
|
|
|
NMDevice parent;
|
|
|
|
|
NMDeviceMacsecPrivate _priv;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct _NMDeviceMacsecClass {
|
|
|
|
|
NMDeviceClass parent;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (NMDeviceMacsec, nm_device_macsec, NM_TYPE_DEVICE)
|
|
|
|
|
|
|
|
|
|
#define NM_DEVICE_MACSEC_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMDeviceMacsec, NM_IS_DEVICE_MACSEC)
|
|
|
|
|
|
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
2016-06-30 18:20:50 +02:00
|
|
|
static void macsec_secrets_cancel (NMDeviceMacsec *self);
|
|
|
|
|
|
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
2016-06-30 18:20:22 +02:00
|
|
|
NM_UTILS_LOOKUP_STR_DEFINE_STATIC (validation_mode_to_string, guint8,
|
|
|
|
|
NM_UTILS_LOOKUP_DEFAULT_WARN ("<unknown>"),
|
|
|
|
|
NM_UTILS_LOOKUP_STR_ITEM (0, "disable"),
|
|
|
|
|
NM_UTILS_LOOKUP_STR_ITEM (1, "check"),
|
|
|
|
|
NM_UTILS_LOOKUP_STR_ITEM (2, "strict"),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
parent_state_changed (NMDevice *parent,
|
|
|
|
|
NMDeviceState new_state,
|
|
|
|
|
NMDeviceState old_state,
|
|
|
|
|
NMDeviceStateReason reason,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceMacsec *self = NM_DEVICE_MACSEC (user_data);
|
|
|
|
|
|
|
|
|
|
/* We'll react to our own carrier state notifications. Ignore the parent's. */
|
2017-02-23 15:19:03 +01:00
|
|
|
if (nm_device_state_reason_check (reason) == NM_DEVICE_STATE_REASON_CARRIER)
|
2016-06-30 18:20:22 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
nm_device_set_unmanaged_by_flags (NM_DEVICE (self), NM_UNMANAGED_PARENT, !nm_device_get_managed (parent, FALSE), reason);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
parent_changed_notify (NMDevice *device,
|
|
|
|
|
int old_ifindex,
|
|
|
|
|
NMDevice *old_parent,
|
|
|
|
|
int new_ifindex,
|
|
|
|
|
NMDevice *new_parent)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceMacsec *self = NM_DEVICE_MACSEC (device);
|
|
|
|
|
NMDeviceMacsecPrivate *priv = NM_DEVICE_MACSEC_GET_PRIVATE (self);
|
|
|
|
|
|
|
|
|
|
NM_DEVICE_CLASS (nm_device_macsec_parent_class)->parent_changed_notify (device,
|
|
|
|
|
old_ifindex,
|
|
|
|
|
old_parent,
|
|
|
|
|
new_ifindex,
|
|
|
|
|
new_parent);
|
|
|
|
|
|
|
|
|
|
/* note that @self doesn't have to clear @parent_state_id on dispose,
|
|
|
|
|
* because NMDevice's dispose() will unset the parent, which in turn calls
|
|
|
|
|
* parent_changed_notify(). */
|
|
|
|
|
nm_clear_g_signal_handler (old_parent, &priv->parent_state_id);
|
|
|
|
|
|
|
|
|
|
if (new_parent) {
|
|
|
|
|
priv->parent_state_id = g_signal_connect (new_parent,
|
|
|
|
|
NM_DEVICE_STATE_CHANGED,
|
|
|
|
|
G_CALLBACK (parent_state_changed),
|
|
|
|
|
device);
|
|
|
|
|
|
|
|
|
|
/* Set parent-dependent unmanaged flag */
|
|
|
|
|
nm_device_set_unmanaged_by_flags (device,
|
|
|
|
|
NM_UNMANAGED_PARENT,
|
|
|
|
|
!nm_device_get_managed (new_parent, FALSE),
|
|
|
|
|
NM_DEVICE_STATE_REASON_PARENT_MANAGED_CHANGED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Recheck availability now that the parent has changed */
|
|
|
|
|
if (new_ifindex > 0) {
|
|
|
|
|
nm_device_queue_recheck_available (device,
|
|
|
|
|
NM_DEVICE_STATE_REASON_PARENT_CHANGED,
|
|
|
|
|
NM_DEVICE_STATE_REASON_PARENT_CHANGED);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
update_properties (NMDevice *device)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceMacsec *self;
|
|
|
|
|
NMDeviceMacsecPrivate *priv;
|
|
|
|
|
const NMPlatformLink *plink = NULL;
|
|
|
|
|
const NMPlatformLnkMacsec *props = NULL;
|
|
|
|
|
int ifindex;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (NM_IS_DEVICE_MACSEC (device));
|
|
|
|
|
self = NM_DEVICE_MACSEC (device);
|
|
|
|
|
priv = NM_DEVICE_MACSEC_GET_PRIVATE (self);
|
|
|
|
|
|
|
|
|
|
ifindex = nm_device_get_ifindex (device);
|
|
|
|
|
g_return_if_fail (ifindex > 0);
|
2017-04-18 12:09:02 +02:00
|
|
|
props = nm_platform_link_get_lnk_macsec (nm_device_get_platform (device), ifindex, &plink);
|
2016-06-30 18:20:22 +02:00
|
|
|
|
|
|
|
|
if (!props) {
|
|
|
|
|
_LOGW (LOGD_PLATFORM, "could not get macsec properties");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_freeze_notify ((GObject *) device);
|
|
|
|
|
|
|
|
|
|
if (priv->props.parent_ifindex != props->parent_ifindex)
|
|
|
|
|
nm_device_parent_set_ifindex (device, props->parent_ifindex);
|
|
|
|
|
|
|
|
|
|
#define CHECK_PROPERTY_CHANGED(field, prop) \
|
2018-03-05 15:23:31 +01:00
|
|
|
G_STMT_START { \
|
|
|
|
|
if (priv->props.field != props->field) { \
|
|
|
|
|
priv->props.field = props->field; \
|
|
|
|
|
_notify (self, prop); \
|
|
|
|
|
} \
|
|
|
|
|
} G_STMT_END
|
2016-06-30 18:20:22 +02:00
|
|
|
|
|
|
|
|
CHECK_PROPERTY_CHANGED (sci, PROP_SCI);
|
|
|
|
|
CHECK_PROPERTY_CHANGED (cipher_suite, PROP_CIPHER_SUITE);
|
|
|
|
|
CHECK_PROPERTY_CHANGED (window, PROP_WINDOW);
|
|
|
|
|
CHECK_PROPERTY_CHANGED (icv_length, PROP_ICV_LENGTH);
|
|
|
|
|
CHECK_PROPERTY_CHANGED (encoding_sa, PROP_ENCODING_SA);
|
|
|
|
|
CHECK_PROPERTY_CHANGED (validation, PROP_VALIDATION);
|
|
|
|
|
CHECK_PROPERTY_CHANGED (encrypt, PROP_ENCRYPT);
|
|
|
|
|
CHECK_PROPERTY_CHANGED (protect, PROP_PROTECT);
|
|
|
|
|
CHECK_PROPERTY_CHANGED (include_sci, PROP_INCLUDE_SCI);
|
|
|
|
|
CHECK_PROPERTY_CHANGED (es, PROP_ES);
|
|
|
|
|
CHECK_PROPERTY_CHANGED (scb, PROP_SCB);
|
|
|
|
|
CHECK_PROPERTY_CHANGED (replay_protect, PROP_REPLAY_PROTECT);
|
|
|
|
|
|
|
|
|
|
g_object_thaw_notify ((GObject *) device);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-30 18:20:50 +02:00
|
|
|
static NMSupplicantConfig *
|
|
|
|
|
build_supplicant_config (NMDeviceMacsec *self, GError **error)
|
|
|
|
|
{
|
2018-10-22 13:06:27 +02:00
|
|
|
gs_unref_object NMSupplicantConfig *config = NULL;
|
2016-06-30 18:20:50 +02:00
|
|
|
NMSettingMacsec *s_macsec;
|
|
|
|
|
NMSetting8021x *s_8021x;
|
|
|
|
|
NMConnection *connection;
|
|
|
|
|
const char *con_uuid;
|
|
|
|
|
guint32 mtu;
|
|
|
|
|
|
|
|
|
|
connection = nm_device_get_applied_connection (NM_DEVICE (self));
|
2018-10-22 13:06:27 +02:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (connection, NULL);
|
|
|
|
|
|
2016-06-30 18:20:50 +02:00
|
|
|
con_uuid = nm_connection_get_uuid (connection);
|
2017-04-18 12:09:02 +02:00
|
|
|
mtu = nm_platform_link_get_mtu (nm_device_get_platform (NM_DEVICE (self)),
|
2016-06-30 18:20:50 +02:00
|
|
|
nm_device_get_ifindex (NM_DEVICE (self)));
|
|
|
|
|
|
2018-01-17 18:06:54 +01:00
|
|
|
config = nm_supplicant_config_new (FALSE, FALSE);
|
2016-06-30 18:20:50 +02:00
|
|
|
|
2018-10-22 13:06:27 +02:00
|
|
|
s_macsec = nm_device_get_applied_setting (NM_DEVICE (self), NM_TYPE_SETTING_MACSEC);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (s_macsec, NULL);
|
2016-06-30 18:20:50 +02:00
|
|
|
|
|
|
|
|
if (!nm_supplicant_config_add_setting_macsec (config, s_macsec, error)) {
|
|
|
|
|
g_prefix_error (error, "macsec-setting: ");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (nm_setting_macsec_get_mode (s_macsec) == NM_SETTING_MACSEC_MODE_EAP) {
|
|
|
|
|
s_8021x = nm_connection_get_setting_802_1x (connection);
|
|
|
|
|
if (!nm_supplicant_config_add_setting_8021x (config, s_8021x, con_uuid, mtu, TRUE, error)) {
|
|
|
|
|
g_prefix_error (error, "802-1x-setting: ");
|
2018-10-22 13:06:27 +02:00
|
|
|
return NULL;
|
2016-06-30 18:20:50 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-22 13:06:27 +02:00
|
|
|
return g_steal_pointer (&config);
|
2016-06-30 18:20:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2017-02-14 19:30:21 +01:00
|
|
|
supplicant_interface_release (NMDeviceMacsec *self)
|
2016-06-30 18:20:50 +02:00
|
|
|
{
|
|
|
|
|
NMDeviceMacsecPrivate *priv = NM_DEVICE_MACSEC_GET_PRIVATE (self);
|
|
|
|
|
|
|
|
|
|
nm_clear_g_source (&priv->supplicant_timeout_id);
|
|
|
|
|
nm_clear_g_source (&priv->supplicant.con_timeout_id);
|
|
|
|
|
nm_clear_g_signal_handler (priv->supplicant.iface, &priv->supplicant.iface_state_id);
|
|
|
|
|
|
|
|
|
|
if (priv->supplicant.iface) {
|
|
|
|
|
nm_supplicant_interface_disconnect (priv->supplicant.iface);
|
|
|
|
|
g_clear_object (&priv->supplicant.iface);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2017-02-14 19:30:21 +01:00
|
|
|
supplicant_iface_assoc_cb (NMSupplicantInterface *iface,
|
|
|
|
|
GError *error,
|
|
|
|
|
gpointer user_data)
|
2016-06-30 18:20:50 +02:00
|
|
|
{
|
|
|
|
|
NMDeviceMacsec *self = NM_DEVICE_MACSEC (user_data);
|
|
|
|
|
|
2017-02-14 19:30:21 +01:00
|
|
|
if (error && !nm_utils_error_is_cancelled (error, TRUE)) {
|
|
|
|
|
supplicant_interface_release (self);
|
|
|
|
|
nm_device_queue_state (NM_DEVICE (self),
|
|
|
|
|
NM_DEVICE_STATE_FAILED,
|
|
|
|
|
NM_DEVICE_STATE_REASON_SUPPLICANT_CONFIG_FAILED);
|
|
|
|
|
}
|
2016-06-30 18:20:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
macsec_secrets_cb (NMActRequest *req,
|
2017-11-24 16:24:40 +01:00
|
|
|
NMActRequestGetSecretsCallId *call_id,
|
2016-06-30 18:20:50 +02:00
|
|
|
NMSettingsConnection *connection,
|
|
|
|
|
GError *error,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceMacsec *self = NM_DEVICE_MACSEC (user_data);
|
|
|
|
|
NMDevice *device = NM_DEVICE (self);
|
|
|
|
|
NMDeviceMacsecPrivate *priv;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (NM_IS_DEVICE_MACSEC (self));
|
|
|
|
|
g_return_if_fail (NM_IS_ACT_REQUEST (req));
|
|
|
|
|
|
|
|
|
|
priv = NM_DEVICE_MACSEC_GET_PRIVATE (self);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (priv->macsec_secrets_id == call_id);
|
|
|
|
|
|
|
|
|
|
priv->macsec_secrets_id = NULL;
|
|
|
|
|
|
|
|
|
|
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (req == nm_device_get_act_request (device));
|
|
|
|
|
g_return_if_fail (nm_device_get_state (device) == NM_DEVICE_STATE_NEED_AUTH);
|
|
|
|
|
g_return_if_fail (nm_act_request_get_settings_connection (req) == connection);
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
_LOGW (LOGD_ETHER, "%s", error->message);
|
|
|
|
|
nm_device_state_changed (device,
|
|
|
|
|
NM_DEVICE_STATE_FAILED,
|
|
|
|
|
NM_DEVICE_STATE_REASON_NO_SECRETS);
|
|
|
|
|
} else
|
|
|
|
|
nm_device_activate_schedule_stage1_device_prepare (device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
macsec_secrets_cancel (NMDeviceMacsec *self)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceMacsecPrivate *priv = NM_DEVICE_MACSEC_GET_PRIVATE (self);
|
|
|
|
|
|
|
|
|
|
if (priv->macsec_secrets_id)
|
|
|
|
|
nm_act_request_cancel_secrets (NULL, priv->macsec_secrets_id);
|
|
|
|
|
nm_assert (!priv->macsec_secrets_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
macsec_secrets_get_secrets (NMDeviceMacsec *self,
|
|
|
|
|
const char *setting_name,
|
|
|
|
|
NMSecretAgentGetSecretsFlags flags)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceMacsecPrivate *priv = NM_DEVICE_MACSEC_GET_PRIVATE (self);
|
|
|
|
|
NMActRequest *req;
|
|
|
|
|
|
|
|
|
|
macsec_secrets_cancel (self);
|
|
|
|
|
|
|
|
|
|
req = nm_device_get_act_request (NM_DEVICE (self));
|
|
|
|
|
g_return_if_fail (NM_IS_ACT_REQUEST (req));
|
|
|
|
|
|
|
|
|
|
priv->macsec_secrets_id = nm_act_request_get_secrets (req,
|
|
|
|
|
TRUE,
|
|
|
|
|
setting_name,
|
|
|
|
|
flags,
|
|
|
|
|
NULL,
|
|
|
|
|
macsec_secrets_cb,
|
|
|
|
|
self);
|
|
|
|
|
g_return_if_fail (priv->macsec_secrets_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
link_timeout_cb (gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceMacsec *self = NM_DEVICE_MACSEC (user_data);
|
|
|
|
|
NMDeviceMacsecPrivate *priv = NM_DEVICE_MACSEC_GET_PRIVATE (self);
|
|
|
|
|
NMDevice *dev = NM_DEVICE (self);
|
|
|
|
|
NMActRequest *req;
|
|
|
|
|
NMConnection *applied_connection;
|
|
|
|
|
const char *setting_name;
|
|
|
|
|
|
|
|
|
|
priv->supplicant_timeout_id = 0;
|
|
|
|
|
|
|
|
|
|
req = nm_device_get_act_request (dev);
|
|
|
|
|
|
|
|
|
|
if (nm_device_get_state (dev) == NM_DEVICE_STATE_ACTIVATED) {
|
|
|
|
|
nm_device_state_changed (dev,
|
|
|
|
|
NM_DEVICE_STATE_FAILED,
|
|
|
|
|
NM_DEVICE_STATE_REASON_SUPPLICANT_TIMEOUT);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Disconnect event during initial authentication and credentials
|
|
|
|
|
* ARE checked - we are likely to have wrong key. Ask the user for
|
|
|
|
|
* another one.
|
|
|
|
|
*/
|
|
|
|
|
if (nm_device_get_state (dev) != NM_DEVICE_STATE_CONFIG)
|
|
|
|
|
goto time_out;
|
|
|
|
|
|
|
|
|
|
nm_active_connection_clear_secrets (NM_ACTIVE_CONNECTION (req));
|
|
|
|
|
|
|
|
|
|
applied_connection = nm_act_request_get_applied_connection (req);
|
|
|
|
|
setting_name = nm_connection_need_secrets (applied_connection, NULL);
|
|
|
|
|
if (!setting_name)
|
|
|
|
|
goto time_out;
|
|
|
|
|
|
|
|
|
|
_LOGI (LOGD_DEVICE | LOGD_ETHER,
|
|
|
|
|
"Activation: disconnected during authentication, asking for new key.");
|
|
|
|
|
supplicant_interface_release (self);
|
|
|
|
|
|
|
|
|
|
nm_device_state_changed (dev, NM_DEVICE_STATE_NEED_AUTH, NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT);
|
|
|
|
|
macsec_secrets_get_secrets (self, setting_name, NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
time_out:
|
|
|
|
|
_LOGW (LOGD_DEVICE | LOGD_ETHER, "link timed out.");
|
|
|
|
|
nm_device_state_changed (dev, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
supplicant_iface_state_cb (NMSupplicantInterface *iface,
|
2017-02-14 01:30:25 +01:00
|
|
|
int new_state_i,
|
|
|
|
|
int old_state_i,
|
2016-06-30 18:20:50 +02:00
|
|
|
int disconnect_reason,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceMacsec *self = NM_DEVICE_MACSEC (user_data);
|
|
|
|
|
NMDeviceMacsecPrivate *priv = NM_DEVICE_MACSEC_GET_PRIVATE (self);
|
|
|
|
|
NMDevice *device = NM_DEVICE (self);
|
|
|
|
|
NMSupplicantConfig *config;
|
|
|
|
|
NMDeviceState devstate;
|
|
|
|
|
GError *error = NULL;
|
2017-02-14 01:30:25 +01:00
|
|
|
NMSupplicantInterfaceState new_state = new_state_i;
|
|
|
|
|
NMSupplicantInterfaceState old_state = old_state_i;
|
2016-06-30 18:20:50 +02:00
|
|
|
|
|
|
|
|
if (new_state == old_state)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_LOGI (LOGD_DEVICE, "supplicant interface state: %s -> %s",
|
|
|
|
|
nm_supplicant_interface_state_to_string (old_state),
|
|
|
|
|
nm_supplicant_interface_state_to_string (new_state));
|
|
|
|
|
|
|
|
|
|
devstate = nm_device_get_state (device);
|
|
|
|
|
|
|
|
|
|
switch (new_state) {
|
|
|
|
|
case NM_SUPPLICANT_INTERFACE_STATE_READY:
|
|
|
|
|
config = build_supplicant_config (self, &error);
|
|
|
|
|
if (config) {
|
2017-02-14 19:30:21 +01:00
|
|
|
nm_supplicant_interface_assoc (priv->supplicant.iface, config,
|
|
|
|
|
supplicant_iface_assoc_cb, self);
|
2016-06-30 18:20:50 +02:00
|
|
|
g_object_unref (config);
|
|
|
|
|
} else {
|
|
|
|
|
_LOGE (LOGD_DEVICE,
|
|
|
|
|
"Activation: couldn't build security configuration: %s",
|
|
|
|
|
error->message);
|
|
|
|
|
g_clear_error (&error);
|
|
|
|
|
|
|
|
|
|
nm_device_state_changed (device,
|
|
|
|
|
NM_DEVICE_STATE_FAILED,
|
|
|
|
|
NM_DEVICE_STATE_REASON_SUPPLICANT_CONFIG_FAILED);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case NM_SUPPLICANT_INTERFACE_STATE_COMPLETED:
|
2017-02-14 19:30:21 +01:00
|
|
|
nm_clear_g_source (&priv->supplicant_timeout_id);
|
|
|
|
|
nm_clear_g_source (&priv->supplicant.con_timeout_id);
|
2016-06-30 18:20:50 +02:00
|
|
|
nm_device_bring_up (device, TRUE, NULL);
|
|
|
|
|
|
|
|
|
|
/* If this is the initial association during device activation,
|
|
|
|
|
* schedule the next activation stage.
|
|
|
|
|
*/
|
|
|
|
|
if (devstate == NM_DEVICE_STATE_CONFIG) {
|
|
|
|
|
_LOGI (LOGD_DEVICE,
|
|
|
|
|
"Activation: Stage 2 of 5 (Device Configure) successful.");
|
|
|
|
|
nm_device_activate_schedule_stage3_ip_config_start (device);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case NM_SUPPLICANT_INTERFACE_STATE_DISCONNECTED:
|
|
|
|
|
if ((devstate == NM_DEVICE_STATE_ACTIVATED) || nm_device_is_activating (device)) {
|
|
|
|
|
/* Start the link timeout so we allow some time for reauthentication */
|
|
|
|
|
if (!priv->supplicant_timeout_id)
|
|
|
|
|
priv->supplicant_timeout_id = g_timeout_add_seconds (15, link_timeout_cb, device);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case NM_SUPPLICANT_INTERFACE_STATE_DOWN:
|
|
|
|
|
supplicant_interface_release (self);
|
|
|
|
|
|
|
|
|
|
if ((devstate == NM_DEVICE_STATE_ACTIVATED) || nm_device_is_activating (device)) {
|
|
|
|
|
nm_device_state_changed (device,
|
|
|
|
|
NM_DEVICE_STATE_FAILED,
|
|
|
|
|
NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NMActStageReturn
|
|
|
|
|
handle_auth_or_fail (NMDeviceMacsec *self,
|
|
|
|
|
NMActRequest *req,
|
|
|
|
|
gboolean new_secrets)
|
|
|
|
|
{
|
|
|
|
|
const char *setting_name;
|
|
|
|
|
NMConnection *applied_connection;
|
|
|
|
|
|
2017-11-02 10:56:30 +01:00
|
|
|
if (!nm_device_auth_retries_try_next (NM_DEVICE (self)))
|
2016-06-30 18:20:50 +02:00
|
|
|
return NM_ACT_STAGE_RETURN_FAILURE;
|
2017-01-19 17:25:31 +01:00
|
|
|
|
2016-06-30 18:20:50 +02:00
|
|
|
nm_device_state_changed (NM_DEVICE (self), NM_DEVICE_STATE_NEED_AUTH, NM_DEVICE_STATE_REASON_NONE);
|
|
|
|
|
|
|
|
|
|
nm_active_connection_clear_secrets (NM_ACTIVE_CONNECTION (req));
|
|
|
|
|
|
2017-10-24 11:11:18 +02:00
|
|
|
applied_connection = nm_act_request_get_applied_connection (req);
|
2016-06-30 18:20:50 +02:00
|
|
|
setting_name = nm_connection_need_secrets (applied_connection, NULL);
|
2018-04-12 14:16:25 +02:00
|
|
|
if (!setting_name) {
|
2016-06-30 18:20:50 +02:00
|
|
|
_LOGI (LOGD_DEVICE, "Cleared secrets, but setting didn't need any secrets.");
|
2018-04-12 14:13:23 +02:00
|
|
|
return NM_ACT_STAGE_RETURN_FAILURE;
|
|
|
|
|
}
|
2016-06-30 18:20:50 +02:00
|
|
|
|
2018-04-12 14:16:25 +02:00
|
|
|
macsec_secrets_get_secrets (self, setting_name,
|
|
|
|
|
NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION
|
|
|
|
|
| (new_secrets ? NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW : 0));
|
2016-06-30 18:20:50 +02:00
|
|
|
return NM_ACT_STAGE_RETURN_POSTPONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
supplicant_connection_timeout_cb (gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceMacsec *self = NM_DEVICE_MACSEC (user_data);
|
|
|
|
|
NMDeviceMacsecPrivate *priv = NM_DEVICE_MACSEC_GET_PRIVATE (self);
|
|
|
|
|
NMDevice *device = NM_DEVICE (self);
|
|
|
|
|
NMActRequest *req;
|
|
|
|
|
NMSettingsConnection *connection;
|
|
|
|
|
guint64 timestamp = 0;
|
|
|
|
|
gboolean new_secrets = TRUE;
|
|
|
|
|
|
|
|
|
|
priv->supplicant.con_timeout_id = 0;
|
|
|
|
|
|
|
|
|
|
/* Authentication failed; either driver problems, the encryption key is
|
|
|
|
|
* wrong, the passwords or certificates were wrong or the Ethernet switch's
|
|
|
|
|
* port is not configured for 802.1x. */
|
|
|
|
|
_LOGW (LOGD_DEVICE,
|
|
|
|
|
"Activation: (macsec) association took too long.");
|
|
|
|
|
|
|
|
|
|
supplicant_interface_release (self);
|
|
|
|
|
req = nm_device_get_act_request (device);
|
|
|
|
|
g_assert (req);
|
|
|
|
|
|
|
|
|
|
connection = nm_act_request_get_settings_connection (req);
|
|
|
|
|
g_assert (connection);
|
|
|
|
|
|
|
|
|
|
/* Ask for new secrets only if we've never activated this connection
|
|
|
|
|
* before. If we've connected before, don't bother the user with dialogs,
|
|
|
|
|
* just retry or fail, and if we never connect the user can fix the
|
|
|
|
|
* password somewhere else. */
|
|
|
|
|
if (nm_settings_connection_get_timestamp (connection, ×tamp))
|
|
|
|
|
new_secrets = !timestamp;
|
|
|
|
|
|
|
|
|
|
if (handle_auth_or_fail (self, req, new_secrets) == NM_ACT_STAGE_RETURN_POSTPONE)
|
|
|
|
|
_LOGW (LOGD_DEVICE, "Activation: (macsec) asking for new secrets");
|
|
|
|
|
else
|
|
|
|
|
nm_device_state_changed (device, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_NO_SECRETS);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
supplicant_interface_init (NMDeviceMacsec *self)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceMacsecPrivate *priv = NM_DEVICE_MACSEC_GET_PRIVATE (self);
|
|
|
|
|
NMDevice *parent;
|
2017-01-19 17:25:29 +01:00
|
|
|
guint timeout;
|
2016-06-30 18:20:50 +02:00
|
|
|
|
|
|
|
|
parent = nm_device_parent_get_device (NM_DEVICE (self));
|
|
|
|
|
g_return_val_if_fail (parent, FALSE);
|
|
|
|
|
|
|
|
|
|
supplicant_interface_release (self);
|
|
|
|
|
|
|
|
|
|
priv->supplicant.iface = nm_supplicant_manager_create_interface (priv->supplicant.mgr,
|
|
|
|
|
nm_device_get_iface (parent),
|
|
|
|
|
NM_SUPPLICANT_DRIVER_MACSEC);
|
|
|
|
|
|
|
|
|
|
if (!priv->supplicant.iface) {
|
|
|
|
|
_LOGE (LOGD_DEVICE,
|
|
|
|
|
"Couldn't initialize supplicant interface");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Listen for its state signals */
|
|
|
|
|
priv->supplicant.iface_state_id = g_signal_connect (priv->supplicant.iface,
|
|
|
|
|
NM_SUPPLICANT_INTERFACE_STATE,
|
|
|
|
|
G_CALLBACK (supplicant_iface_state_cb),
|
|
|
|
|
self);
|
|
|
|
|
|
2017-01-19 17:25:29 +01:00
|
|
|
/* Set up a timeout on the connection attempt */
|
|
|
|
|
timeout = nm_device_get_supplicant_timeout (NM_DEVICE (self));
|
|
|
|
|
priv->supplicant.con_timeout_id = g_timeout_add_seconds (timeout,
|
|
|
|
|
supplicant_connection_timeout_cb,
|
|
|
|
|
self);
|
2016-06-30 18:20:50 +02:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NMActStageReturn
|
2017-02-22 17:04:00 +01:00
|
|
|
act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason)
|
2016-06-30 18:20:50 +02:00
|
|
|
{
|
|
|
|
|
NMDeviceMacsec *self = NM_DEVICE_MACSEC (device);
|
|
|
|
|
NMDeviceMacsecPrivate *priv = NM_DEVICE_MACSEC_GET_PRIVATE (self);
|
|
|
|
|
NMConnection *connection;
|
|
|
|
|
NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE;
|
|
|
|
|
const char *setting_name;
|
|
|
|
|
|
|
|
|
|
connection = nm_device_get_applied_connection (NM_DEVICE (self));
|
2018-10-22 13:06:27 +02:00
|
|
|
|
2017-02-22 17:04:00 +01:00
|
|
|
g_return_val_if_fail (connection, NM_ACT_STAGE_RETURN_FAILURE);
|
2016-06-30 18:20:50 +02:00
|
|
|
|
|
|
|
|
if (!priv->supplicant.mgr)
|
|
|
|
|
priv->supplicant.mgr = g_object_ref (nm_supplicant_manager_get ());
|
|
|
|
|
|
|
|
|
|
/* If we need secrets, get them */
|
|
|
|
|
setting_name = nm_connection_need_secrets (connection, NULL);
|
|
|
|
|
if (setting_name) {
|
|
|
|
|
NMActRequest *req = nm_device_get_act_request (NM_DEVICE (self));
|
|
|
|
|
|
|
|
|
|
_LOGI (LOGD_DEVICE,
|
|
|
|
|
"Activation: connection '%s' has security, but secrets are required.",
|
|
|
|
|
nm_connection_get_id (connection));
|
|
|
|
|
|
|
|
|
|
ret = handle_auth_or_fail (self, req, FALSE);
|
|
|
|
|
if (ret != NM_ACT_STAGE_RETURN_POSTPONE)
|
2017-02-22 17:04:00 +01:00
|
|
|
NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_NO_SECRETS);
|
2016-06-30 18:20:50 +02:00
|
|
|
} else {
|
|
|
|
|
_LOGI (LOGD_DEVICE | LOGD_ETHER,
|
|
|
|
|
"Activation: connection '%s' requires no security. No secrets needed.",
|
|
|
|
|
nm_connection_get_id (connection));
|
|
|
|
|
|
|
|
|
|
if (supplicant_interface_init (self))
|
|
|
|
|
ret = NM_ACT_STAGE_RETURN_POSTPONE;
|
|
|
|
|
else
|
2017-02-22 17:04:00 +01:00
|
|
|
NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_CONFIG_FAILED);
|
2016-06-30 18:20:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
deactivate (NMDevice *device)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceMacsec *self = NM_DEVICE_MACSEC (device);
|
|
|
|
|
|
|
|
|
|
supplicant_interface_release (self);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-30 18:20:22 +02:00
|
|
|
/******************************************************************/
|
|
|
|
|
|
|
|
|
|
static NMDeviceCapabilities
|
|
|
|
|
get_generic_capabilities (NMDevice *dev)
|
|
|
|
|
{
|
|
|
|
|
/* We assume MACsec interfaces always support carrier detect */
|
|
|
|
|
return NM_DEVICE_CAP_CARRIER_DETECT | NM_DEVICE_CAP_IS_SOFTWARE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
is_available (NMDevice *device, NMDeviceCheckDevAvailableFlags flags)
|
|
|
|
|
{
|
|
|
|
|
if (!nm_device_parent_get_device (device))
|
|
|
|
|
return FALSE;
|
|
|
|
|
return NM_DEVICE_CLASS (nm_device_macsec_parent_class)->is_available (device, flags);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-30 18:20:50 +02:00
|
|
|
static gboolean
|
|
|
|
|
create_and_realize (NMDevice *device,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
NMDevice *parent,
|
|
|
|
|
const NMPlatformLink **out_plink,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
const char *iface = nm_device_get_iface (device);
|
|
|
|
|
NMSettingMacsec *s_macsec;
|
|
|
|
|
NMPlatformLnkMacsec lnk = { };
|
|
|
|
|
int parent_ifindex;
|
|
|
|
|
const char *hw_addr;
|
|
|
|
|
union {
|
|
|
|
|
struct {
|
|
|
|
|
guint8 mac[6];
|
|
|
|
|
guint16 port;
|
|
|
|
|
} s;
|
|
|
|
|
guint64 u;
|
|
|
|
|
} sci;
|
platform: merge NMPlatformError with nm-error
Platform had it's own scheme for reporting errors: NMPlatformError.
Before, NMPlatformError indicated success via zero, negative integer
values are numbers from <errno.h>, and positive integer values are
platform specific codes. This changes now according to nm-error:
success is still zero. Negative values indicate a failure, where the
numeric value is either from <errno.h> or one of our error codes.
The meaning of positive values depends on the functions. Most functions
can only report an error reason (negative) and success (zero). For such
functions, positive values should never be returned (but the caller
should anticipate them).
For some functions, positive values could mean additional information
(but still success). That depends.
This is also what systemd does, except that systemd only returns
(negative) integers from <errno.h>, while we merge our own error codes
into the range of <errno.h>.
The advantage is to get rid of one way how to signal errors. The other
advantage is, that these error codes are compatible with all other
nm-errno values. For example, previously negative values indicated error
codes from <errno.h>, but it did not entail error codes from netlink.
2018-12-22 14:13:05 +01:00
|
|
|
int r;
|
2016-06-30 18:20:50 +02:00
|
|
|
|
|
|
|
|
s_macsec = nm_connection_get_setting_macsec (connection);
|
|
|
|
|
g_assert (s_macsec);
|
|
|
|
|
|
|
|
|
|
if (!parent) {
|
2017-09-14 09:26:51 +02:00
|
|
|
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_MISSING_DEPENDENCIES,
|
2016-06-30 18:20:50 +02:00
|
|
|
"MACsec devices can not be created without a parent interface");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lnk.encrypt = nm_setting_macsec_get_encrypt (s_macsec);
|
|
|
|
|
|
|
|
|
|
hw_addr = nm_device_get_hw_address (parent);
|
|
|
|
|
if (!hw_addr) {
|
|
|
|
|
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
|
|
|
|
|
"can't read parent MAC");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nm_utils_hwaddr_aton (hw_addr, sci.s.mac, ETH_ALEN);
|
|
|
|
|
sci.s.port = htons (nm_setting_macsec_get_port (s_macsec));
|
|
|
|
|
lnk.sci = be64toh (sci.u);
|
|
|
|
|
lnk.validation = nm_setting_macsec_get_validation (s_macsec);
|
2018-06-06 15:26:17 +02:00
|
|
|
lnk.include_sci = nm_setting_macsec_get_send_sci (s_macsec);
|
2016-06-30 18:20:50 +02:00
|
|
|
|
|
|
|
|
parent_ifindex = nm_device_get_ifindex (parent);
|
|
|
|
|
g_warn_if_fail (parent_ifindex > 0);
|
|
|
|
|
|
platform: merge NMPlatformError with nm-error
Platform had it's own scheme for reporting errors: NMPlatformError.
Before, NMPlatformError indicated success via zero, negative integer
values are numbers from <errno.h>, and positive integer values are
platform specific codes. This changes now according to nm-error:
success is still zero. Negative values indicate a failure, where the
numeric value is either from <errno.h> or one of our error codes.
The meaning of positive values depends on the functions. Most functions
can only report an error reason (negative) and success (zero). For such
functions, positive values should never be returned (but the caller
should anticipate them).
For some functions, positive values could mean additional information
(but still success). That depends.
This is also what systemd does, except that systemd only returns
(negative) integers from <errno.h>, while we merge our own error codes
into the range of <errno.h>.
The advantage is to get rid of one way how to signal errors. The other
advantage is, that these error codes are compatible with all other
nm-errno values. For example, previously negative values indicated error
codes from <errno.h>, but it did not entail error codes from netlink.
2018-12-22 14:13:05 +01:00
|
|
|
r = nm_platform_link_macsec_add (nm_device_get_platform (device), iface, parent_ifindex, &lnk, out_plink);
|
|
|
|
|
if (r < 0) {
|
2016-06-30 18:20:50 +02:00
|
|
|
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
|
|
|
|
|
"Failed to create macsec interface '%s' for '%s': %s",
|
|
|
|
|
iface,
|
|
|
|
|
nm_connection_get_id (connection),
|
platform: merge NMPlatformError with nm-error
Platform had it's own scheme for reporting errors: NMPlatformError.
Before, NMPlatformError indicated success via zero, negative integer
values are numbers from <errno.h>, and positive integer values are
platform specific codes. This changes now according to nm-error:
success is still zero. Negative values indicate a failure, where the
numeric value is either from <errno.h> or one of our error codes.
The meaning of positive values depends on the functions. Most functions
can only report an error reason (negative) and success (zero). For such
functions, positive values should never be returned (but the caller
should anticipate them).
For some functions, positive values could mean additional information
(but still success). That depends.
This is also what systemd does, except that systemd only returns
(negative) integers from <errno.h>, while we merge our own error codes
into the range of <errno.h>.
The advantage is to get rid of one way how to signal errors. The other
advantage is, that these error codes are compatible with all other
nm-errno values. For example, previously negative values indicated error
codes from <errno.h>, but it did not entail error codes from netlink.
2018-12-22 14:13:05 +01:00
|
|
|
nm_strerror (r));
|
2016-06-30 18:20:50 +02:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nm_device_parent_set_ifindex (device, parent_ifindex);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-30 18:20:22 +02:00
|
|
|
static void
|
|
|
|
|
link_changed (NMDevice *device,
|
|
|
|
|
const NMPlatformLink *pllink)
|
|
|
|
|
{
|
|
|
|
|
NM_DEVICE_CLASS (nm_device_macsec_parent_class)->link_changed (device, pllink);
|
|
|
|
|
update_properties (device);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-30 18:20:50 +02:00
|
|
|
static void
|
|
|
|
|
device_state_changed (NMDevice *device,
|
|
|
|
|
NMDeviceState new_state,
|
|
|
|
|
NMDeviceState old_state,
|
|
|
|
|
NMDeviceStateReason reason)
|
|
|
|
|
{
|
|
|
|
|
if (new_state > NM_DEVICE_STATE_ACTIVATED)
|
|
|
|
|
macsec_secrets_cancel (NM_DEVICE_MACSEC (device));
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-30 18:20:22 +02:00
|
|
|
/******************************************************************/
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
get_property (GObject *object, guint prop_id,
|
|
|
|
|
GValue *value, GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceMacsec *self = NM_DEVICE_MACSEC (object);
|
|
|
|
|
NMDeviceMacsecPrivate *priv = NM_DEVICE_MACSEC_GET_PRIVATE (self);
|
|
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_SCI:
|
|
|
|
|
g_value_set_uint64 (value, priv->props.sci);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_CIPHER_SUITE:
|
|
|
|
|
g_value_set_uint64 (value, priv->props.cipher_suite);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_ICV_LENGTH:
|
|
|
|
|
g_value_set_uchar (value, priv->props.icv_length);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_WINDOW:
|
|
|
|
|
g_value_set_uint (value, priv->props.window);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_ENCODING_SA:
|
|
|
|
|
g_value_set_uchar (value, priv->props.encoding_sa);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_ENCRYPT:
|
|
|
|
|
g_value_set_boolean (value, priv->props.encrypt);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_PROTECT:
|
|
|
|
|
g_value_set_boolean (value, priv->props.protect);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_INCLUDE_SCI:
|
|
|
|
|
g_value_set_boolean (value, priv->props.include_sci);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_ES:
|
|
|
|
|
g_value_set_boolean (value, priv->props.es);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_SCB:
|
|
|
|
|
g_value_set_boolean (value, priv->props.scb);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_REPLAY_PROTECT:
|
|
|
|
|
g_value_set_boolean (value, priv->props.replay_protect);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_VALIDATION:
|
|
|
|
|
g_value_set_string (value,
|
|
|
|
|
validation_mode_to_string (priv->props.validation));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2017-10-24 11:11:18 +02:00
|
|
|
nm_device_macsec_init (NMDeviceMacsec *self)
|
2016-06-30 18:20:22 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-30 18:20:50 +02:00
|
|
|
static void
|
|
|
|
|
dispose (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceMacsec *self = NM_DEVICE_MACSEC (object);
|
|
|
|
|
|
|
|
|
|
macsec_secrets_cancel (self);
|
|
|
|
|
supplicant_interface_release (self);
|
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (nm_device_macsec_parent_class)->dispose (object);
|
|
|
|
|
}
|
|
|
|
|
|
core/dbus: rework D-Bus implementation to use lower layer GDBusConnection API
Previously, we used the generated GDBusInterfaceSkeleton types and glued
them via the NMExportedObject base class to our NM types. We also used
GDBusObjectManagerServer.
Don't do that anymore. The resulting code was more complicated despite (or
because?) using generated classes. It was hard to understand, complex, had
ordering-issues, and had a runtime and memory overhead.
This patch refactors this entirely and uses the lower layer API GDBusConnection
directly. It replaces the generated code, GDBusInterfaceSkeleton, and
GDBusObjectManagerServer. All this is now done by NMDbusObject and NMDBusManager
and static descriptor instances of type GDBusInterfaceInfo.
This adds a net plus of more then 1300 lines of hand written code. I claim
that this implementation is easier to understand. Note that previously we
also required extensive and complex glue code to bind our objects to the
generated skeleton objects. Instead, now glue our objects directly to
GDBusConnection. The result is more immediate and gets rid of layers of
code in between.
Now that the D-Bus glue us more under our control, we can address issus and
bottlenecks better, instead of adding code to bend the generated skeletons
to our needs.
Note that the current implementation now only supports one D-Bus connection.
That was effectively the case already, although there were places (and still are)
where the code pretends it could also support connections from a private socket.
We dropped private socket support mainly because it was unused, untested and
buggy, but also because GDBusObjectManagerServer could not export the same
objects on multiple connections. Now, it would be rather straight forward to
fix that and re-introduce ObjectManager on each private connection. But this
commit doesn't do that yet, and the new code intentionally supports only one
D-Bus connection.
Also, the D-Bus startup was simplified. There is no retry, either nm_dbus_manager_start()
succeeds, or it detects the initrd case. In the initrd case, bus manager never tries to
connect to D-Bus. Since the initrd scenario is not yet used/tested, this is good enough
for the moment. It could be easily extended later, for example with polling whether the
system bus appears (like was done previously). Also, restart of D-Bus daemon isn't
supported either -- just like before.
Note how NMDBusManager now implements the ObjectManager D-Bus interface
directly.
Also, this fixes race issues in the server, by no longer delaying
PropertiesChanged signals. NMExportedObject would collect changed
properties and send the signal out in idle_emit_properties_changed()
on idle. This messes up the ordering of change events w.r.t. other
signals and events on the bus. Note that not only NMExportedObject
messed up the ordering. Also the generated code would hook into
notify() and process change events in and idle handle, exhibiting the
same ordering issue too.
No longer do that. PropertiesChanged signals will be sent right away
by hooking into dispatch_properties_changed(). This means, changing
a property in quick succession will no longer be combined and is
guaranteed to emit signals for each individual state. Quite possibly
we emit now more PropertiesChanged signals then before.
However, we are now able to group a set of changes by using standard
g_object_freeze_notify()/g_object_thaw_notify(). We probably should
make more use of that.
Also, now that our signals are all handled in the right order, we
might find places where we still emit them in the wrong order. But that
is then due to the order in which our GObjects emit signals, not due
to an ill behavior of the D-Bus glue. Possibly we need to identify
such ordering issues and fix them.
Numbers (for contrib/rpm --without debug on x86_64):
- the patch changes the code size of NetworkManager by
- 2809360 bytes
+ 2537528 bytes (-9.7%)
- Runtime measurements are harder because there is a large variance
during testing. In other words, the numbers are not reproducible.
Currently, the implementation performs no caching of GVariants at all,
but it would be rather simple to add it, if that turns out to be
useful.
Anyway, without strong claim, it seems that the new form tends to
perform slightly better. That would be no surprise.
$ time (for i in {1..1000}; do nmcli >/dev/null || break; echo -n .; done)
- real 1m39.355s
+ real 1m37.432s
$ time (for i in {1..2000}; do busctl call org.freedesktop.NetworkManager /org/freedesktop org.freedesktop.DBus.ObjectManager GetManagedObjects > /dev/null || break; echo -n .; done)
- real 0m26.843s
+ real 0m25.281s
- Regarding RSS size, just looking at the processes in similar
conditions, doesn't give a large difference. On my system they
consume about 19MB RSS. It seems that the new version has a
slightly smaller RSS size.
- 19356 RSS
+ 18660 RSS
2018-02-26 13:51:52 +01:00
|
|
|
static const NMDBusInterfaceInfoExtended interface_info_device_macsec = {
|
|
|
|
|
.parent = NM_DEFINE_GDBUS_INTERFACE_INFO_INIT (
|
|
|
|
|
NM_DBUS_INTERFACE_DEVICE_MACSEC,
|
|
|
|
|
.signals = NM_DEFINE_GDBUS_SIGNAL_INFOS (
|
|
|
|
|
&nm_signal_info_property_changed_legacy,
|
|
|
|
|
),
|
|
|
|
|
.properties = NM_DEFINE_GDBUS_PROPERTY_INFOS (
|
|
|
|
|
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("Parent", "o", NM_DEVICE_PARENT),
|
|
|
|
|
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("Sci", "t", NM_DEVICE_MACSEC_SCI),
|
|
|
|
|
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("IcvLength", "y", NM_DEVICE_MACSEC_ICV_LENGTH),
|
|
|
|
|
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("CipherSuite", "t", NM_DEVICE_MACSEC_CIPHER_SUITE),
|
|
|
|
|
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("Window", "u", NM_DEVICE_MACSEC_WINDOW),
|
|
|
|
|
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("EncodingSa", "y", NM_DEVICE_MACSEC_ENCODING_SA),
|
|
|
|
|
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("Validation", "s", NM_DEVICE_MACSEC_VALIDATION),
|
|
|
|
|
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("Encrypt", "b", NM_DEVICE_MACSEC_ENCRYPT),
|
|
|
|
|
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("Protect", "b", NM_DEVICE_MACSEC_PROTECT),
|
|
|
|
|
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("IncludeSci", "b", NM_DEVICE_MACSEC_INCLUDE_SCI),
|
|
|
|
|
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("Es", "b", NM_DEVICE_MACSEC_ES),
|
|
|
|
|
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("Scb", "b", NM_DEVICE_MACSEC_SCB),
|
|
|
|
|
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("ReplayProtect", "b", NM_DEVICE_MACSEC_REPLAY_PROTECT),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
.legacy_property_changed = TRUE,
|
|
|
|
|
};
|
|
|
|
|
|
2016-06-30 18:20:22 +02:00
|
|
|
static void
|
|
|
|
|
nm_device_macsec_class_init (NMDeviceMacsecClass *klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
core/dbus: rework D-Bus implementation to use lower layer GDBusConnection API
Previously, we used the generated GDBusInterfaceSkeleton types and glued
them via the NMExportedObject base class to our NM types. We also used
GDBusObjectManagerServer.
Don't do that anymore. The resulting code was more complicated despite (or
because?) using generated classes. It was hard to understand, complex, had
ordering-issues, and had a runtime and memory overhead.
This patch refactors this entirely and uses the lower layer API GDBusConnection
directly. It replaces the generated code, GDBusInterfaceSkeleton, and
GDBusObjectManagerServer. All this is now done by NMDbusObject and NMDBusManager
and static descriptor instances of type GDBusInterfaceInfo.
This adds a net plus of more then 1300 lines of hand written code. I claim
that this implementation is easier to understand. Note that previously we
also required extensive and complex glue code to bind our objects to the
generated skeleton objects. Instead, now glue our objects directly to
GDBusConnection. The result is more immediate and gets rid of layers of
code in between.
Now that the D-Bus glue us more under our control, we can address issus and
bottlenecks better, instead of adding code to bend the generated skeletons
to our needs.
Note that the current implementation now only supports one D-Bus connection.
That was effectively the case already, although there were places (and still are)
where the code pretends it could also support connections from a private socket.
We dropped private socket support mainly because it was unused, untested and
buggy, but also because GDBusObjectManagerServer could not export the same
objects on multiple connections. Now, it would be rather straight forward to
fix that and re-introduce ObjectManager on each private connection. But this
commit doesn't do that yet, and the new code intentionally supports only one
D-Bus connection.
Also, the D-Bus startup was simplified. There is no retry, either nm_dbus_manager_start()
succeeds, or it detects the initrd case. In the initrd case, bus manager never tries to
connect to D-Bus. Since the initrd scenario is not yet used/tested, this is good enough
for the moment. It could be easily extended later, for example with polling whether the
system bus appears (like was done previously). Also, restart of D-Bus daemon isn't
supported either -- just like before.
Note how NMDBusManager now implements the ObjectManager D-Bus interface
directly.
Also, this fixes race issues in the server, by no longer delaying
PropertiesChanged signals. NMExportedObject would collect changed
properties and send the signal out in idle_emit_properties_changed()
on idle. This messes up the ordering of change events w.r.t. other
signals and events on the bus. Note that not only NMExportedObject
messed up the ordering. Also the generated code would hook into
notify() and process change events in and idle handle, exhibiting the
same ordering issue too.
No longer do that. PropertiesChanged signals will be sent right away
by hooking into dispatch_properties_changed(). This means, changing
a property in quick succession will no longer be combined and is
guaranteed to emit signals for each individual state. Quite possibly
we emit now more PropertiesChanged signals then before.
However, we are now able to group a set of changes by using standard
g_object_freeze_notify()/g_object_thaw_notify(). We probably should
make more use of that.
Also, now that our signals are all handled in the right order, we
might find places where we still emit them in the wrong order. But that
is then due to the order in which our GObjects emit signals, not due
to an ill behavior of the D-Bus glue. Possibly we need to identify
such ordering issues and fix them.
Numbers (for contrib/rpm --without debug on x86_64):
- the patch changes the code size of NetworkManager by
- 2809360 bytes
+ 2537528 bytes (-9.7%)
- Runtime measurements are harder because there is a large variance
during testing. In other words, the numbers are not reproducible.
Currently, the implementation performs no caching of GVariants at all,
but it would be rather simple to add it, if that turns out to be
useful.
Anyway, without strong claim, it seems that the new form tends to
perform slightly better. That would be no surprise.
$ time (for i in {1..1000}; do nmcli >/dev/null || break; echo -n .; done)
- real 1m39.355s
+ real 1m37.432s
$ time (for i in {1..2000}; do busctl call org.freedesktop.NetworkManager /org/freedesktop org.freedesktop.DBus.ObjectManager GetManagedObjects > /dev/null || break; echo -n .; done)
- real 0m26.843s
+ real 0m25.281s
- Regarding RSS size, just looking at the processes in similar
conditions, doesn't give a large difference. On my system they
consume about 19MB RSS. It seems that the new version has a
slightly smaller RSS size.
- 19356 RSS
+ 18660 RSS
2018-02-26 13:51:52 +01:00
|
|
|
NMDBusObjectClass *dbus_object_class = NM_DBUS_OBJECT_CLASS (klass);
|
2018-07-10 07:45:35 +02:00
|
|
|
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
|
2016-06-30 18:20:22 +02:00
|
|
|
|
|
|
|
|
object_class->get_property = get_property;
|
2016-06-30 18:20:50 +02:00
|
|
|
object_class->dispose = dispose;
|
2016-06-30 18:20:22 +02:00
|
|
|
|
core/dbus: rework D-Bus implementation to use lower layer GDBusConnection API
Previously, we used the generated GDBusInterfaceSkeleton types and glued
them via the NMExportedObject base class to our NM types. We also used
GDBusObjectManagerServer.
Don't do that anymore. The resulting code was more complicated despite (or
because?) using generated classes. It was hard to understand, complex, had
ordering-issues, and had a runtime and memory overhead.
This patch refactors this entirely and uses the lower layer API GDBusConnection
directly. It replaces the generated code, GDBusInterfaceSkeleton, and
GDBusObjectManagerServer. All this is now done by NMDbusObject and NMDBusManager
and static descriptor instances of type GDBusInterfaceInfo.
This adds a net plus of more then 1300 lines of hand written code. I claim
that this implementation is easier to understand. Note that previously we
also required extensive and complex glue code to bind our objects to the
generated skeleton objects. Instead, now glue our objects directly to
GDBusConnection. The result is more immediate and gets rid of layers of
code in between.
Now that the D-Bus glue us more under our control, we can address issus and
bottlenecks better, instead of adding code to bend the generated skeletons
to our needs.
Note that the current implementation now only supports one D-Bus connection.
That was effectively the case already, although there were places (and still are)
where the code pretends it could also support connections from a private socket.
We dropped private socket support mainly because it was unused, untested and
buggy, but also because GDBusObjectManagerServer could not export the same
objects on multiple connections. Now, it would be rather straight forward to
fix that and re-introduce ObjectManager on each private connection. But this
commit doesn't do that yet, and the new code intentionally supports only one
D-Bus connection.
Also, the D-Bus startup was simplified. There is no retry, either nm_dbus_manager_start()
succeeds, or it detects the initrd case. In the initrd case, bus manager never tries to
connect to D-Bus. Since the initrd scenario is not yet used/tested, this is good enough
for the moment. It could be easily extended later, for example with polling whether the
system bus appears (like was done previously). Also, restart of D-Bus daemon isn't
supported either -- just like before.
Note how NMDBusManager now implements the ObjectManager D-Bus interface
directly.
Also, this fixes race issues in the server, by no longer delaying
PropertiesChanged signals. NMExportedObject would collect changed
properties and send the signal out in idle_emit_properties_changed()
on idle. This messes up the ordering of change events w.r.t. other
signals and events on the bus. Note that not only NMExportedObject
messed up the ordering. Also the generated code would hook into
notify() and process change events in and idle handle, exhibiting the
same ordering issue too.
No longer do that. PropertiesChanged signals will be sent right away
by hooking into dispatch_properties_changed(). This means, changing
a property in quick succession will no longer be combined and is
guaranteed to emit signals for each individual state. Quite possibly
we emit now more PropertiesChanged signals then before.
However, we are now able to group a set of changes by using standard
g_object_freeze_notify()/g_object_thaw_notify(). We probably should
make more use of that.
Also, now that our signals are all handled in the right order, we
might find places where we still emit them in the wrong order. But that
is then due to the order in which our GObjects emit signals, not due
to an ill behavior of the D-Bus glue. Possibly we need to identify
such ordering issues and fix them.
Numbers (for contrib/rpm --without debug on x86_64):
- the patch changes the code size of NetworkManager by
- 2809360 bytes
+ 2537528 bytes (-9.7%)
- Runtime measurements are harder because there is a large variance
during testing. In other words, the numbers are not reproducible.
Currently, the implementation performs no caching of GVariants at all,
but it would be rather simple to add it, if that turns out to be
useful.
Anyway, without strong claim, it seems that the new form tends to
perform slightly better. That would be no surprise.
$ time (for i in {1..1000}; do nmcli >/dev/null || break; echo -n .; done)
- real 1m39.355s
+ real 1m37.432s
$ time (for i in {1..2000}; do busctl call org.freedesktop.NetworkManager /org/freedesktop org.freedesktop.DBus.ObjectManager GetManagedObjects > /dev/null || break; echo -n .; done)
- real 0m26.843s
+ real 0m25.281s
- Regarding RSS size, just looking at the processes in similar
conditions, doesn't give a large difference. On my system they
consume about 19MB RSS. It seems that the new version has a
slightly smaller RSS size.
- 19356 RSS
+ 18660 RSS
2018-02-26 13:51:52 +01:00
|
|
|
dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS (&interface_info_device_macsec);
|
|
|
|
|
|
2018-07-10 09:26:42 +02:00
|
|
|
device_class->connection_type_supported = NM_SETTING_MACSEC_SETTING_NAME;
|
2018-06-27 17:00:55 +02:00
|
|
|
device_class->connection_type_check_compatible = NM_SETTING_MACSEC_SETTING_NAME;
|
2018-07-10 09:26:42 +02:00
|
|
|
device_class->link_types = NM_DEVICE_DEFINE_LINK_TYPES (NM_LINK_TYPE_MACSEC);
|
|
|
|
|
|
2018-07-10 07:45:35 +02:00
|
|
|
device_class->act_stage2_config = act_stage2_config;
|
|
|
|
|
device_class->create_and_realize = create_and_realize;
|
|
|
|
|
device_class->deactivate = deactivate;
|
|
|
|
|
device_class->get_generic_capabilities = get_generic_capabilities;
|
|
|
|
|
device_class->link_changed = link_changed;
|
|
|
|
|
device_class->is_available = is_available;
|
|
|
|
|
device_class->parent_changed_notify = parent_changed_notify;
|
|
|
|
|
device_class->state_changed = device_state_changed;
|
|
|
|
|
device_class->get_configured_mtu = nm_device_get_configured_mtu_for_wired;
|
|
|
|
|
|
2016-06-30 18:20:22 +02:00
|
|
|
obj_properties[PROP_SCI] =
|
|
|
|
|
g_param_spec_uint64 (NM_DEVICE_MACSEC_SCI, "", "",
|
|
|
|
|
0, G_MAXUINT64, 0,
|
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
obj_properties[PROP_CIPHER_SUITE] =
|
|
|
|
|
g_param_spec_uint64 (NM_DEVICE_MACSEC_CIPHER_SUITE, "", "",
|
|
|
|
|
0, G_MAXUINT64, 0,
|
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
obj_properties[PROP_ICV_LENGTH] =
|
|
|
|
|
g_param_spec_uchar (NM_DEVICE_MACSEC_ICV_LENGTH, "", "",
|
|
|
|
|
0, G_MAXUINT8, 0,
|
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
obj_properties[PROP_WINDOW] =
|
|
|
|
|
g_param_spec_uint (NM_DEVICE_MACSEC_WINDOW, "", "",
|
|
|
|
|
0, G_MAXUINT32, 0,
|
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
obj_properties[PROP_ENCODING_SA] =
|
|
|
|
|
g_param_spec_uchar (NM_DEVICE_MACSEC_ENCODING_SA, "", "",
|
|
|
|
|
0, 3, 0,
|
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
obj_properties[PROP_VALIDATION] =
|
|
|
|
|
g_param_spec_string (NM_DEVICE_MACSEC_VALIDATION, "", "",
|
|
|
|
|
NULL,
|
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
obj_properties[PROP_ENCRYPT] =
|
|
|
|
|
g_param_spec_boolean (NM_DEVICE_MACSEC_ENCRYPT, "", "",
|
|
|
|
|
FALSE,
|
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
obj_properties[PROP_PROTECT] =
|
|
|
|
|
g_param_spec_boolean (NM_DEVICE_MACSEC_PROTECT, "", "",
|
|
|
|
|
FALSE,
|
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
obj_properties[PROP_INCLUDE_SCI] =
|
|
|
|
|
g_param_spec_boolean (NM_DEVICE_MACSEC_INCLUDE_SCI, "", "",
|
|
|
|
|
FALSE,
|
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
obj_properties[PROP_ES] =
|
|
|
|
|
g_param_spec_boolean (NM_DEVICE_MACSEC_ES, "", "",
|
|
|
|
|
FALSE,
|
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
obj_properties[PROP_SCB] =
|
|
|
|
|
g_param_spec_boolean (NM_DEVICE_MACSEC_SCB, "", "",
|
|
|
|
|
FALSE,
|
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
obj_properties[PROP_REPLAY_PROTECT] =
|
|
|
|
|
g_param_spec_boolean (NM_DEVICE_MACSEC_REPLAY_PROTECT, "", "",
|
|
|
|
|
FALSE,
|
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
|
|
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*************************************************************/
|
|
|
|
|
|
|
|
|
|
#define NM_TYPE_MACSEC_DEVICE_FACTORY (nm_macsec_device_factory_get_type ())
|
|
|
|
|
#define NM_MACSEC_DEVICE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_MACSEC_DEVICE_FACTORY, NMMacsecDeviceFactory))
|
|
|
|
|
|
|
|
|
|
static NMDevice *
|
|
|
|
|
create_device (NMDeviceFactory *factory,
|
|
|
|
|
const char *iface,
|
|
|
|
|
const NMPlatformLink *plink,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
gboolean *out_ignore)
|
|
|
|
|
{
|
|
|
|
|
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_MACSEC,
|
|
|
|
|
NM_DEVICE_IFACE, iface,
|
|
|
|
|
NM_DEVICE_TYPE_DESC, "Macsec",
|
|
|
|
|
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_MACSEC,
|
|
|
|
|
NM_DEVICE_LINK_TYPE, NM_LINK_TYPE_MACSEC,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-30 18:20:50 +02:00
|
|
|
static const char *
|
|
|
|
|
get_connection_parent (NMDeviceFactory *factory, NMConnection *connection)
|
|
|
|
|
{
|
|
|
|
|
NMSettingMacsec *s_macsec;
|
|
|
|
|
NMSettingWired *s_wired;
|
|
|
|
|
const char *parent = NULL;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (nm_connection_is_type (connection, NM_SETTING_MACSEC_SETTING_NAME), NULL);
|
|
|
|
|
|
|
|
|
|
s_macsec = nm_connection_get_setting_macsec (connection);
|
|
|
|
|
g_assert (s_macsec);
|
|
|
|
|
|
|
|
|
|
parent = nm_setting_macsec_get_parent (s_macsec);
|
|
|
|
|
if (parent)
|
|
|
|
|
return parent;
|
|
|
|
|
|
|
|
|
|
/* Try the hardware address from the MACsec connection's hardware setting */
|
|
|
|
|
s_wired = nm_connection_get_setting_wired (connection);
|
|
|
|
|
if (s_wired)
|
|
|
|
|
return nm_setting_wired_get_mac_address (s_wired);
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
|
get_connection_iface (NMDeviceFactory *factory,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
const char *parent_iface)
|
|
|
|
|
{
|
|
|
|
|
NMSettingMacsec *s_macsec;
|
|
|
|
|
const char *ifname;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (nm_connection_is_type (connection, NM_SETTING_MACSEC_SETTING_NAME), NULL);
|
|
|
|
|
|
|
|
|
|
s_macsec = nm_connection_get_setting_macsec (connection);
|
|
|
|
|
g_assert (s_macsec);
|
|
|
|
|
|
|
|
|
|
if (!parent_iface)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
ifname = nm_connection_get_interface_name (connection);
|
|
|
|
|
return g_strdup (ifname);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-30 18:20:22 +02:00
|
|
|
NM_DEVICE_FACTORY_DEFINE_INTERNAL (MACSEC, Macsec, macsec,
|
2016-06-30 18:20:50 +02:00
|
|
|
NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_MACSEC)
|
|
|
|
|
NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_MACSEC_SETTING_NAME),
|
2016-06-30 18:20:22 +02:00
|
|
|
factory_class->create_device = create_device;
|
2016-06-30 18:20:50 +02:00
|
|
|
factory_class->get_connection_parent = get_connection_parent;
|
|
|
|
|
factory_class->get_connection_iface = get_connection_iface;
|
2016-06-30 18:20:22 +02:00
|
|
|
)
|