2020-09-29 16:42:22 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2019-09-25 13:13:40 +02:00
|
|
|
/*
|
2019-10-01 09:20:35 +02:00
|
|
|
* Copyright (C) 2011 - 2012 Red Hat, Inc.
|
2012-02-22 23:59:50 -06:00
|
|
|
*/
|
|
|
|
|
|
2016-02-19 14:57:48 +01:00
|
|
|
#include "nm-default.h"
|
2012-02-22 23:59:50 -06:00
|
|
|
|
2016-05-16 19:01:37 +02:00
|
|
|
#include "nm-device-vlan.h"
|
|
|
|
|
|
2012-03-02 08:56:46 +01:00
|
|
|
#include <sys/socket.h>
|
2012-02-22 23:59:50 -06:00
|
|
|
|
2013-07-20 21:48:06 +02:00
|
|
|
#include "nm-manager.h"
|
2012-02-22 23:59:50 -06:00
|
|
|
#include "nm-utils.h"
|
|
|
|
|
#include "NetworkManagerUtils.h"
|
|
|
|
|
#include "nm-device-private.h"
|
2016-11-21 00:43:52 +01:00
|
|
|
#include "settings/nm-settings.h"
|
2016-09-28 19:37:10 +02:00
|
|
|
#include "nm-act-request.h"
|
2014-07-17 17:06:44 -04:00
|
|
|
#include "nm-ip4-config.h"
|
2016-11-21 00:43:52 +01:00
|
|
|
#include "platform/nm-platform.h"
|
2014-09-08 10:24:11 -05:00
|
|
|
#include "nm-device-factory.h"
|
|
|
|
|
#include "nm-manager.h"
|
2014-10-21 22:09:52 -04:00
|
|
|
#include "nm-core-internal.h"
|
2016-11-21 00:43:52 +01:00
|
|
|
#include "platform/nmp-object.h"
|
2012-02-22 23:59:50 -06:00
|
|
|
|
2020-11-06 18:22:11 +01:00
|
|
|
#define _NMLOG_DEVICE_TYPE NMDeviceVlan
|
2014-08-02 15:14:26 +02:00
|
|
|
#include "nm-device-logging.h"
|
2012-02-22 23:59:50 -06:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
/*****************************************************************************/
|
2012-02-22 23:59:50 -06:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
NM_GOBJECT_PROPERTIES_DEFINE(NMDeviceVlan, PROP_VLAN_ID, );
|
2012-02-22 23:59:50 -06:00
|
|
|
|
|
|
|
|
typedef struct {
|
2016-01-04 10:29:06 +01:00
|
|
|
gulong parent_state_id;
|
|
|
|
|
gulong parent_hwaddr_id;
|
2017-10-12 19:36:09 +02:00
|
|
|
gulong parent_mtu_id;
|
2016-01-10 14:31:10 +01:00
|
|
|
guint vlan_id;
|
2012-02-22 23:59:50 -06:00
|
|
|
} NMDeviceVlanPrivate;
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
struct _NMDeviceVlan {
|
|
|
|
|
NMDevice parent;
|
|
|
|
|
NMDeviceVlanPrivate _priv;
|
|
|
|
|
};
|
2012-02-22 23:59:50 -06:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
struct _NMDeviceVlanClass {
|
|
|
|
|
NMDeviceClass parent;
|
2012-02-22 23:59:50 -06:00
|
|
|
};
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
G_DEFINE_TYPE(NMDeviceVlan, nm_device_vlan, NM_TYPE_DEVICE)
|
|
|
|
|
|
2017-11-09 11:42:24 +01:00
|
|
|
#define NM_DEVICE_VLAN_GET_PRIVATE(self) \
|
|
|
|
|
_NM_GET_PRIVATE(self, NMDeviceVlan, NM_IS_DEVICE_VLAN, NMDevice)
|
2016-09-29 13:49:01 +02:00
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
2012-02-22 23:59:50 -06:00
|
|
|
|
2015-04-29 10:06:51 +02:00
|
|
|
static void
|
|
|
|
|
parent_state_changed(NMDevice * parent,
|
|
|
|
|
NMDeviceState new_state,
|
|
|
|
|
NMDeviceState old_state,
|
|
|
|
|
NMDeviceStateReason reason,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceVlan *self = NM_DEVICE_VLAN(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)
|
2015-04-29 10:06:51 +02:00
|
|
|
return;
|
|
|
|
|
|
device: remove default-unmanaged and refactor unmanaged flags
Get rid of NM_UNMANAGED_DEFAULT and refine the interaction between
unmanaged flags, device state and managed property.
Previously, the NM_UNMANAGED_DEFAULT was special in that a device was
still considered managed if it had solely the NM_UNMANAGED_DEFAULT flag
set and its state was managed. Thus, whether the device (state) was managed,
depended on the device state too.
Now, a device is considered managed (or unmanaged) based on the unmanaged
flags and realization state alone. At the same time, the device state
directly corresponds to the managed property of the device. Of course,
while changing the unmanaged flags, that invariant is shortly violated
until the state transistion is complete.
Introduce more unmanaged flags whereas some of them are non-authorative.
For example, the EXTERNAL_DOWN flag has only effect as long as the user
didn't explicitly manage the device (NM_UNMANAGED_USER_EXPLICIT). In other
words, certain flags can render other flags ineffective. Whether the device
is considered managed depends on the flags but also at the explicitly unset flags.
In a way, this is similar to previous where NM_UNMANAGED_DEFAULT was ignored
(if no other flags were present).
Also, previously a device that was NM_UNMANAGED_DEFAULT and in disconnected
state would transition back to unmanaged. No longer do that. Once a device is
managed, it stays managed as long as the flags indicate it should be managed.
However, the user can also modify the unmanaged flags via the D-Bus API.
Also get rid or nm_device_finish_init(). That was previously called
by NMManager after add_device(). As we now realize devices (possibly
multiple times) this should be handled during realization.
https://bugzilla.gnome.org/show_bug.cgi?id=746566
2015-09-15 15:35:16 +02:00
|
|
|
nm_device_set_unmanaged_by_flags(NM_DEVICE(self),
|
|
|
|
|
NM_UNMANAGED_PARENT,
|
|
|
|
|
!nm_device_get_managed(parent, FALSE),
|
|
|
|
|
reason);
|
2015-04-29 10:06:51 +02:00
|
|
|
}
|
|
|
|
|
|
2017-10-12 19:36:09 +02:00
|
|
|
static void
|
|
|
|
|
parent_mtu_maybe_changed(NMDevice *parent, GParamSpec *pspec, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
/* the MTU of a VLAN device is limited by the parent's MTU.
|
|
|
|
|
*
|
|
|
|
|
* When the parent's MTU changes, try to re-set the MTU. */
|
|
|
|
|
nm_device_commit_mtu(user_data);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-06 15:21:29 +02:00
|
|
|
static void
|
2016-04-12 10:41:20 +02:00
|
|
|
parent_hwaddr_maybe_changed(NMDevice *parent, GParamSpec *pspec, gpointer user_data)
|
2015-10-06 15:21:29 +02:00
|
|
|
{
|
2017-03-13 15:34:14 +01:00
|
|
|
NMDevice * device = NM_DEVICE(user_data);
|
|
|
|
|
NMDeviceVlan * self = NM_DEVICE_VLAN(device);
|
2015-10-06 15:21:29 +02:00
|
|
|
NMConnection * connection;
|
2016-04-12 10:41:20 +02:00
|
|
|
const char * new_mac, *old_mac;
|
2016-01-11 11:05:11 +01:00
|
|
|
NMSettingIPConfig *s_ip6;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-10-06 15:21:29 +02:00
|
|
|
/* Never touch assumed devices */
|
2017-03-13 15:34:14 +01:00
|
|
|
if (nm_device_sys_iface_state_is_external_or_assume(device))
|
2015-10-06 15:21:29 +02:00
|
|
|
return;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-05-26 14:59:17 +02:00
|
|
|
connection = nm_device_get_applied_connection(device);
|
2015-10-06 15:21:29 +02:00
|
|
|
if (!connection)
|
|
|
|
|
return;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-10-06 15:21:29 +02:00
|
|
|
/* Update the VLAN MAC only if configuration does not specify one */
|
2018-05-26 14:59:17 +02:00
|
|
|
if (nm_device_hw_addr_is_explict(device))
|
device: extend MAC address handling including randomization for ethernet and wifi
Extend the "ethernet.cloned-mac-address" and "wifi.cloned-mac-address"
settings. Instead of specifying an explicit MAC address, the additional
special values "permanent", "preserve", "random", "random-bia", "stable" and
"stable-bia" are supported.
"permanent" means to use the permanent hardware address. Previously that
was the default if no explict cloned-mac-address was set. The default is
thus still "permanent", but it can be overwritten by global
configuration.
"preserve" means not to configure the MAC address when activating the
device. That was actually the default behavior before introducing MAC
address handling with commit 1b49f941a69af910b0e68530be7339e8053068e5.
"random" and "random-bia" use a randomized MAC address for each
connection. "stable" and "stable-bia" use a generated, stable
address based on some token. The "bia" suffix says to generate a
burned-in address. The stable method by default uses as token the
connection UUID, but the token can be explicitly choosen via
"stable:<TOKEN>" and "stable-bia:<TOKEN>".
On a D-Bus level, the "cloned-mac-address" is a bytestring and thus
cannot express the new forms. It is replaced by the new
"assigned-mac-address" field. For the GObject property, libnm's API,
nmcli, keyfile, etc. the old name "cloned-mac-address" is still used.
Deprecating the old field seems more complicated then just extending
the use of the existing "cloned-mac-address" field, although the name
doesn't match well with the extended meaning.
There is some overlap with the "wifi.mac-address-randomization" setting.
https://bugzilla.gnome.org/show_bug.cgi?id=705545
https://bugzilla.gnome.org/show_bug.cgi?id=708820
https://bugzilla.gnome.org/show_bug.cgi?id=758301
2016-05-24 15:57:16 +02:00
|
|
|
return;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-05-26 14:59:17 +02:00
|
|
|
old_mac = nm_device_get_hw_address(device);
|
2016-04-12 10:41:20 +02:00
|
|
|
new_mac = nm_device_get_hw_address(parent);
|
|
|
|
|
if (nm_streq0(old_mac, new_mac))
|
|
|
|
|
return;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-04-12 10:41:20 +02:00
|
|
|
_LOGD(LOGD_VLAN,
|
|
|
|
|
"parent hardware address changed to %s%s%s",
|
|
|
|
|
NM_PRINT_FMT_QUOTE_STRING(new_mac));
|
|
|
|
|
if (new_mac) {
|
2018-05-26 14:59:17 +02:00
|
|
|
nm_device_hw_addr_set(device, new_mac, "vlan-parent", TRUE);
|
2018-05-26 15:13:19 +02:00
|
|
|
nm_device_arp_announce(device);
|
2016-04-12 10:41:20 +02:00
|
|
|
/* When changing the hw address the interface is taken down,
|
|
|
|
|
* removing the IPv6 configuration; reapply it.
|
|
|
|
|
*/
|
|
|
|
|
s_ip6 = nm_connection_get_setting_ip6_config(connection);
|
|
|
|
|
if (s_ip6)
|
2020-10-29 12:50:39 +01:00
|
|
|
nm_device_reactivate_ip_config(device, AF_INET6, s_ip6, s_ip6);
|
2015-10-06 15:21:29 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-29 10:06:51 +02:00
|
|
|
static void
|
2017-01-02 09:57:43 +01:00
|
|
|
parent_changed_notify(NMDevice *device,
|
|
|
|
|
int old_ifindex,
|
|
|
|
|
NMDevice *old_parent,
|
|
|
|
|
int new_ifindex,
|
|
|
|
|
NMDevice *new_parent)
|
2015-04-29 10:06:51 +02:00
|
|
|
{
|
2017-01-02 09:57:43 +01:00
|
|
|
NMDeviceVlan * self = NM_DEVICE_VLAN(device);
|
2015-04-13 11:43:12 -05:00
|
|
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE(self);
|
|
|
|
|
|
2017-01-02 09:57:43 +01:00
|
|
|
NM_DEVICE_CLASS(nm_device_vlan_parent_class)
|
|
|
|
|
->parent_changed_notify(device, old_ifindex, old_parent, new_ifindex, new_parent);
|
2015-04-29 10:06:51 +02:00
|
|
|
|
2017-01-02 09:57:43 +01:00
|
|
|
/* 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);
|
|
|
|
|
nm_clear_g_signal_handler(old_parent, &priv->parent_hwaddr_id);
|
2017-10-12 19:36:09 +02:00
|
|
|
nm_clear_g_signal_handler(old_parent, &priv->parent_mtu_id);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-01-02 09:57:43 +01:00
|
|
|
if (new_parent) {
|
|
|
|
|
priv->parent_state_id = g_signal_connect(new_parent,
|
2015-12-07 19:42:59 +01:00
|
|
|
NM_DEVICE_STATE_CHANGED,
|
2015-04-29 10:06:51 +02:00
|
|
|
G_CALLBACK(parent_state_changed),
|
|
|
|
|
device);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-01-02 09:57:43 +01:00
|
|
|
priv->parent_hwaddr_id = g_signal_connect(new_parent,
|
|
|
|
|
"notify::" NM_DEVICE_HW_ADDRESS,
|
2016-04-12 10:41:20 +02:00
|
|
|
G_CALLBACK(parent_hwaddr_maybe_changed),
|
|
|
|
|
device);
|
2017-01-02 09:57:43 +01:00
|
|
|
parent_hwaddr_maybe_changed(new_parent, NULL, self);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-10-12 19:36:09 +02:00
|
|
|
priv->parent_mtu_id = g_signal_connect(new_parent,
|
|
|
|
|
"notify::" NM_DEVICE_MTU,
|
|
|
|
|
G_CALLBACK(parent_mtu_maybe_changed),
|
|
|
|
|
device);
|
|
|
|
|
parent_mtu_maybe_changed(new_parent, NULL, self);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-04-13 11:43:12 -05:00
|
|
|
/* Set parent-dependent unmanaged flag */
|
2016-01-13 12:03:47 +01:00
|
|
|
nm_device_set_unmanaged_by_flags(device,
|
|
|
|
|
NM_UNMANAGED_PARENT,
|
2017-01-02 09:57:43 +01:00
|
|
|
!nm_device_get_managed(new_parent, FALSE),
|
2016-01-13 12:03:47 +01:00
|
|
|
NM_DEVICE_STATE_REASON_PARENT_MANAGED_CHANGED);
|
2015-04-29 10:06:51 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-04-13 11:43:12 -05:00
|
|
|
/* Recheck availability now that the parent has changed */
|
2017-01-02 09:57:43 +01:00
|
|
|
if (new_ifindex > 0) {
|
|
|
|
|
nm_device_queue_recheck_available(device,
|
|
|
|
|
NM_DEVICE_STATE_REASON_PARENT_CHANGED,
|
|
|
|
|
NM_DEVICE_STATE_REASON_PARENT_CHANGED);
|
|
|
|
|
}
|
2015-04-29 10:06:51 +02:00
|
|
|
}
|
|
|
|
|
|
2014-09-05 08:50:02 -05:00
|
|
|
static void
|
2016-01-10 14:31:10 +01:00
|
|
|
update_properties(NMDevice *device)
|
2014-09-05 08:50:02 -05:00
|
|
|
{
|
2016-01-10 14:31:10 +01:00
|
|
|
NMDeviceVlanPrivate * priv;
|
|
|
|
|
const NMPlatformLink * plink = NULL;
|
|
|
|
|
const NMPlatformLnkVlan *plnk = NULL;
|
|
|
|
|
int ifindex;
|
2017-01-02 09:57:43 +01:00
|
|
|
int parent_ifindex = 0;
|
2016-01-10 14:31:10 +01:00
|
|
|
guint vlan_id;
|
2014-09-05 08:50:02 -05:00
|
|
|
|
2016-01-10 14:31:10 +01:00
|
|
|
g_return_if_fail(NM_IS_DEVICE_VLAN(device));
|
2014-09-05 08:50:02 -05:00
|
|
|
|
2020-02-14 10:50:25 +01:00
|
|
|
priv = NM_DEVICE_VLAN_GET_PRIVATE(device);
|
2014-09-05 08:50:02 -05:00
|
|
|
|
2016-01-10 14:31:10 +01:00
|
|
|
ifindex = nm_device_get_ifindex(device);
|
2014-09-05 08:50:02 -05:00
|
|
|
|
2016-01-10 14:31:10 +01:00
|
|
|
if (ifindex > 0)
|
2017-04-18 12:09:02 +02:00
|
|
|
plnk = nm_platform_link_get_lnk_vlan(nm_device_get_platform(device), ifindex, &plink);
|
2017-01-02 09:57:43 +01:00
|
|
|
|
|
|
|
|
if (plnk && plink->parent > 0)
|
|
|
|
|
parent_ifindex = plink->parent;
|
2014-09-05 08:50:02 -05:00
|
|
|
|
2016-01-10 14:31:10 +01:00
|
|
|
g_object_freeze_notify((GObject *) device);
|
2014-09-05 08:50:02 -05:00
|
|
|
|
2017-01-02 09:57:43 +01:00
|
|
|
nm_device_parent_set_ifindex(device, parent_ifindex);
|
2016-01-10 14:31:10 +01:00
|
|
|
|
|
|
|
|
vlan_id = plnk ? plnk->id : 0;
|
|
|
|
|
if (vlan_id != priv->vlan_id) {
|
|
|
|
|
priv->vlan_id = vlan_id;
|
2016-09-29 13:49:01 +02:00
|
|
|
_notify((NMDeviceVlan *) device, PROP_VLAN_ID);
|
2014-09-05 08:50:02 -05:00
|
|
|
}
|
|
|
|
|
|
2016-01-10 14:31:10 +01:00
|
|
|
g_object_thaw_notify((GObject *) device);
|
|
|
|
|
}
|
2014-09-05 08:50:02 -05:00
|
|
|
|
2016-01-10 14:31:10 +01:00
|
|
|
static void
|
2017-01-02 15:55:23 +01:00
|
|
|
link_changed(NMDevice *device, const NMPlatformLink *pllink)
|
2016-01-10 14:31:10 +01:00
|
|
|
{
|
2017-01-02 15:55:23 +01:00
|
|
|
NM_DEVICE_CLASS(nm_device_vlan_parent_class)->link_changed(device, pllink);
|
|
|
|
|
update_properties(device);
|
|
|
|
|
}
|
2014-09-05 08:50:02 -05:00
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
create_and_realize(NMDevice * device,
|
|
|
|
|
NMConnection * connection,
|
|
|
|
|
NMDevice * parent,
|
2015-12-09 15:13:57 +01:00
|
|
|
const NMPlatformLink **out_plink,
|
2014-09-05 08:50:02 -05:00
|
|
|
GError ** error)
|
|
|
|
|
{
|
2020-02-14 10:50:25 +01:00
|
|
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE(device);
|
2014-09-05 08:50:02 -05:00
|
|
|
const char * iface = nm_device_get_iface(device);
|
|
|
|
|
NMSettingVlan * s_vlan;
|
2016-01-10 14:31:10 +01:00
|
|
|
int parent_ifindex;
|
|
|
|
|
guint vlan_id;
|
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;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-09-05 08:50:02 -05:00
|
|
|
s_vlan = nm_connection_get_setting_vlan(connection);
|
|
|
|
|
g_assert(s_vlan);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
device: check for a parent device
The device creation can be attempted if the name can be determined. It
alone is doesn't mean that there's a parent device -- the name could
just have been hardcoded in the connection.
NetworkManager[21519]: nm_device_get_ifindex: assertion 'NM_IS_DEVICE (self)' failed
Program received signal SIGTRAP, Trace/breakpoint trap.
g_logv (log_domain=0x5555557fb2e5 "NetworkManager", log_level=G_LOG_LEVEL_CRITICAL, format=<optimized out>, args=args@entry=0x7fffffffd3d0) at gmessages.c:1046
1046 g_private_set (&g_log_depth, GUINT_TO_POINTER (depth));
(gdb) bt
#0 0x00007ffff4ec88c3 in g_logv (log_domain=0x5555557fb2e5 "NetworkManager", log_level=G_LOG_LEVEL_CRITICAL, format=<optimized out>, args=args@entry=0x7fffffffd3d0) at gmessages.c:1046
#1 0x00007ffff4ec8a3f in g_log (log_domain=<optimized out>, log_level=<optimized out>, format=<optimized out>) at gmessages.c:1079
#2 0x00005555555d2090 in nm_device_get_ifindex (self=0x0) at devices/nm-device.c:562
#3 0x00005555555ef77a in nm_device_supports_vlans (self=0x0) at devices/nm-device.c:9865
#4 0x00005555555bf2f9 in create_and_realize (device=0x555555c549b0 [NMDeviceVlan], connection=0x555555b451e0, parent=0x0, out_plink=0x7fffffffd5f8, error=0x7fffffffd700) at devices/nm-device-vlan.c:225
#5 0x00005555555d5757 in nm_device_create_and_realize (self=0x555555c549b0 [NMDeviceVlan], connection=0x555555b451e0, parent=0x0, error=0x7fffffffd700) at devices/nm-device.c:1783
#6 0x0000555555688601 in system_create_virtual_device (self=0x555555af51c0 [NMManager], connection=0x555555b451e0) at nm-manager.c:1120
#7 0x000055555568894e in connection_changed (settings=0x555555ae8220 [NMSettings], connection=0x555555b451e0, manager=0x555555af51c0 [NMManager]) at nm-manager.c:1172
#8 0x0000555555693448 in nm_manager_start (self=0x555555af51c0 [NMManager], error=0x7fffffffda30) at nm-manager.c:4466
#9 0x00005555555d166f in main (argc=1, argv=0x7fffffffdba8) at main.c:454
(gdb)
Fixes: 332994f1b19ded7cb343ef573443916bab05aaec
2016-04-19 12:02:02 +02:00
|
|
|
if (!parent) {
|
2017-09-14 09:26:51 +02:00
|
|
|
g_set_error(error,
|
|
|
|
|
NM_DEVICE_ERROR,
|
|
|
|
|
NM_DEVICE_ERROR_MISSING_DEPENDENCIES,
|
device: check for a parent device
The device creation can be attempted if the name can be determined. It
alone is doesn't mean that there's a parent device -- the name could
just have been hardcoded in the connection.
NetworkManager[21519]: nm_device_get_ifindex: assertion 'NM_IS_DEVICE (self)' failed
Program received signal SIGTRAP, Trace/breakpoint trap.
g_logv (log_domain=0x5555557fb2e5 "NetworkManager", log_level=G_LOG_LEVEL_CRITICAL, format=<optimized out>, args=args@entry=0x7fffffffd3d0) at gmessages.c:1046
1046 g_private_set (&g_log_depth, GUINT_TO_POINTER (depth));
(gdb) bt
#0 0x00007ffff4ec88c3 in g_logv (log_domain=0x5555557fb2e5 "NetworkManager", log_level=G_LOG_LEVEL_CRITICAL, format=<optimized out>, args=args@entry=0x7fffffffd3d0) at gmessages.c:1046
#1 0x00007ffff4ec8a3f in g_log (log_domain=<optimized out>, log_level=<optimized out>, format=<optimized out>) at gmessages.c:1079
#2 0x00005555555d2090 in nm_device_get_ifindex (self=0x0) at devices/nm-device.c:562
#3 0x00005555555ef77a in nm_device_supports_vlans (self=0x0) at devices/nm-device.c:9865
#4 0x00005555555bf2f9 in create_and_realize (device=0x555555c549b0 [NMDeviceVlan], connection=0x555555b451e0, parent=0x0, out_plink=0x7fffffffd5f8, error=0x7fffffffd700) at devices/nm-device-vlan.c:225
#5 0x00005555555d5757 in nm_device_create_and_realize (self=0x555555c549b0 [NMDeviceVlan], connection=0x555555b451e0, parent=0x0, error=0x7fffffffd700) at devices/nm-device.c:1783
#6 0x0000555555688601 in system_create_virtual_device (self=0x555555af51c0 [NMManager], connection=0x555555b451e0) at nm-manager.c:1120
#7 0x000055555568894e in connection_changed (settings=0x555555ae8220 [NMSettings], connection=0x555555b451e0, manager=0x555555af51c0 [NMManager]) at nm-manager.c:1172
#8 0x0000555555693448 in nm_manager_start (self=0x555555af51c0 [NMManager], error=0x7fffffffda30) at nm-manager.c:4466
#9 0x00005555555d166f in main (argc=1, argv=0x7fffffffdba8) at main.c:454
(gdb)
Fixes: 332994f1b19ded7cb343ef573443916bab05aaec
2016-04-19 12:02:02 +02:00
|
|
|
"VLAN devices can not be created without a parent interface");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
device: skip creating VLAN devices if parent device is not ready yet
do a check on parent ifindex before calling "nm_device_supports_vlans"
otherwise if the parent device is a software device and its ifindex
member has not been updated yet we will trigger the g_return_if_fail
statement in "nmp_cache_lookup_entry_link".
This has been osserved in NetworkManager CI test suite, on NetworkManager
boot, during the creation of a vlan on top of a bond interface.
CI test: vlan_update_mac_from_bond
[...]
<info> [1503323670.0229] manager: (bond0): new Bond device (/org/freedesktop/NetworkManager/Devices/23)
<debug> [1503323670.0231] device[0x555555c3e320] (vlan10): constructed (NMDeviceVlan)
<debug> [1503323670.0231] manager: (vlan-vlan10) create virtual device vlan10
<debug> [1503323670.0231] device[0x555555c3e320] (vlan10): unmanaged: flags set to [platform-init,!sleeping=0x10/0x11/unmanaged/unrealized], set-managed [sleeping=0x1])
<trace> [1503323670.0235] exported-object[0x555555c3e320]: export: "/org/freedesktop/NetworkManager/Devices/24"
<trace> [1503323670.0235] properties-changed[0x555555c3e320]: ignoring notification for prop g-object-path on type NMDeviceVlan
<trace> [1503323670.0236] properties-changed[0x555555c3e320]: ignoring notification for prop path on type NMDeviceVlan
<info> [1503323670.0237] manager: (vlan10): new VLAN device (/org/freedesktop/NetworkManager/Devices/24)
<debug> [1503323670.0239] device[0x555555c3e320] (vlan10): create (is nm-owned)
Program received signal SIGTRAP, Trace/breakpoint trap.
g_logv (log_domain=0x5555557c39a9 "NetworkManager", log_level=
G_LOG_LEVEL_CRITICAL, format=<optimized out>,
args=args@entry=0x7fffffffdef0) at gmessages.c:1086
1086 g_private_set (&g_log_depth, GUINT_TO_POINTER (depth));
(gdb) bt
#0 0x00007ffff5ce3643 in g_logv (log_domain=0x5555557c39a9 "NetworkManager", log_level=
G_LOG_LEVEL_CRITICAL, format=<optimized out>, args=args@entry=0x7fffffffdef0) at gmessages.c:1086
#1 0x00007ffff5ce37bf in g_log (log_domain=log_domain@entry=0x5555557c39a9 "NetworkManager", log_level=log_level@entry=G_LOG_LEVEL_CRITICAL, format=format@entry=0x7ffff5d51190 "%s: assertion '%s' failed") at gmessages.c:1119
#2 0x00007ffff5ce37f9 in g_return_if_fail_warning (log_domain=log_domain@entry=0x5555557c39a9 "NetworkManager", pretty_function=pretty_function@entry=0x5555557b2a20 <__func__.32407> "nmp_cache_lookup_entry_link", expression=expression@entry=0x5555557b1037 "ifindex > 0") at gmessages.c:1128
#3 0x000055555566688a in nmp_cache_lookup_entry_link (cache=0x555555a780f0, ifindex=<optimized out>) at src/platform/nmp-object.c:1449
#4 0x00005555556668f9 in nmp_cache_lookup_link (cache=<optimized out>, ifindex=ifindex@entry=0) at src/platform/nmp-object.c:1464
#5 0x00005555556515e9 in nm_platform_link_get_obj (self=self@entry=0x555555a88880 [NMLinuxPlatform], ifindex=ifindex@entry=0, visible_only=visible_only@entry=1) at src/platform/nm-platform.c:618
#6 0x0000555555633e91 in link_supports_vlans (platform=0x555555a88880 [NMLinuxPlatform], ifindex=0) at src/platform/nm-linux-platform.c:4482
#7 0x00005555556d6d41 in create_and_realize (device=0x555555c3e320 [NMDeviceVlan], connection=0x7fffdc007890, parent=0x555555c33560 [NMDeviceBond], out_plink=0x7fffffffe1f8, error=0x7fffffffe358) at src/devices/nm-device-vlan.c:239
#8 0x00005555556b934c in nm_device_create_and_realize (self=self@entry=0x555555c3e320 [NMDeviceVlan], connection=connection@entry=0x7fffdc007890, parent=0x555555c33560 [NMDeviceBond], error=error@entry=0x7fffffffe358)
at src/devices/nm-device.c:2946
#9 0x00005555555b84c7 in connection_changed (connection=0x7fffdc007890, self=0x555555ab1070 [NMManager]) at src/nm-manager.c:1381
#10 0x00005555555b84c7 in connection_changed (self=0x555555ab1070 [NMManager], connection=0x7fffdc007890) at src/nm-manager.c:1431
#11 0x00005555555b9130 in retry_connections_for_parent_device (self=self@entry=0x555555ab1070 [NMManager], device=device@entry=0x555555c33560 [NMDeviceBond])
at src/nm-manager.c:1416
#12 0x00005555555b95c7 in add_device (self=self@entry=0x555555ab1070 [NMManager], device=device@entry=0x555555c33560 [NMDeviceBond], error=error@entry=0x7fffffffe598) at src/nm-manager.c:2238
#13 0x00005555555b83e1 in connection_changed (connection=0x7fffdc007b30, self=0x555555ab1070 [NMManager]) at src/nm-manager.c:1352
#14 0x00005555555b83e1 in connection_changed (self=0x555555ab1070 [NMManager], connection=0x7fffdc007b30) at src/nm-manager.c:1431
#15 0x00005555555be25b in nm_manager_start (self=0x555555ab1070 [NMManager], error=error@entry=0x7fffffffe720) at src/nm-manager.c:5202
#16 0x0000555555586b13 in main (argc=1, argv=0x7fffffffe888) at src/main.c:413
2017-08-21 17:41:29 +02:00
|
|
|
parent_ifindex = nm_device_get_ifindex(parent);
|
|
|
|
|
if (parent_ifindex <= 0) {
|
2017-09-14 09:26:51 +02:00
|
|
|
g_set_error(error,
|
|
|
|
|
NM_DEVICE_ERROR,
|
|
|
|
|
NM_DEVICE_ERROR_MISSING_DEPENDENCIES,
|
2017-09-14 10:25:36 +02:00
|
|
|
"cannot retrieve ifindex of interface %s (%s)",
|
device: skip creating VLAN devices if parent device is not ready yet
do a check on parent ifindex before calling "nm_device_supports_vlans"
otherwise if the parent device is a software device and its ifindex
member has not been updated yet we will trigger the g_return_if_fail
statement in "nmp_cache_lookup_entry_link".
This has been osserved in NetworkManager CI test suite, on NetworkManager
boot, during the creation of a vlan on top of a bond interface.
CI test: vlan_update_mac_from_bond
[...]
<info> [1503323670.0229] manager: (bond0): new Bond device (/org/freedesktop/NetworkManager/Devices/23)
<debug> [1503323670.0231] device[0x555555c3e320] (vlan10): constructed (NMDeviceVlan)
<debug> [1503323670.0231] manager: (vlan-vlan10) create virtual device vlan10
<debug> [1503323670.0231] device[0x555555c3e320] (vlan10): unmanaged: flags set to [platform-init,!sleeping=0x10/0x11/unmanaged/unrealized], set-managed [sleeping=0x1])
<trace> [1503323670.0235] exported-object[0x555555c3e320]: export: "/org/freedesktop/NetworkManager/Devices/24"
<trace> [1503323670.0235] properties-changed[0x555555c3e320]: ignoring notification for prop g-object-path on type NMDeviceVlan
<trace> [1503323670.0236] properties-changed[0x555555c3e320]: ignoring notification for prop path on type NMDeviceVlan
<info> [1503323670.0237] manager: (vlan10): new VLAN device (/org/freedesktop/NetworkManager/Devices/24)
<debug> [1503323670.0239] device[0x555555c3e320] (vlan10): create (is nm-owned)
Program received signal SIGTRAP, Trace/breakpoint trap.
g_logv (log_domain=0x5555557c39a9 "NetworkManager", log_level=
G_LOG_LEVEL_CRITICAL, format=<optimized out>,
args=args@entry=0x7fffffffdef0) at gmessages.c:1086
1086 g_private_set (&g_log_depth, GUINT_TO_POINTER (depth));
(gdb) bt
#0 0x00007ffff5ce3643 in g_logv (log_domain=0x5555557c39a9 "NetworkManager", log_level=
G_LOG_LEVEL_CRITICAL, format=<optimized out>, args=args@entry=0x7fffffffdef0) at gmessages.c:1086
#1 0x00007ffff5ce37bf in g_log (log_domain=log_domain@entry=0x5555557c39a9 "NetworkManager", log_level=log_level@entry=G_LOG_LEVEL_CRITICAL, format=format@entry=0x7ffff5d51190 "%s: assertion '%s' failed") at gmessages.c:1119
#2 0x00007ffff5ce37f9 in g_return_if_fail_warning (log_domain=log_domain@entry=0x5555557c39a9 "NetworkManager", pretty_function=pretty_function@entry=0x5555557b2a20 <__func__.32407> "nmp_cache_lookup_entry_link", expression=expression@entry=0x5555557b1037 "ifindex > 0") at gmessages.c:1128
#3 0x000055555566688a in nmp_cache_lookup_entry_link (cache=0x555555a780f0, ifindex=<optimized out>) at src/platform/nmp-object.c:1449
#4 0x00005555556668f9 in nmp_cache_lookup_link (cache=<optimized out>, ifindex=ifindex@entry=0) at src/platform/nmp-object.c:1464
#5 0x00005555556515e9 in nm_platform_link_get_obj (self=self@entry=0x555555a88880 [NMLinuxPlatform], ifindex=ifindex@entry=0, visible_only=visible_only@entry=1) at src/platform/nm-platform.c:618
#6 0x0000555555633e91 in link_supports_vlans (platform=0x555555a88880 [NMLinuxPlatform], ifindex=0) at src/platform/nm-linux-platform.c:4482
#7 0x00005555556d6d41 in create_and_realize (device=0x555555c3e320 [NMDeviceVlan], connection=0x7fffdc007890, parent=0x555555c33560 [NMDeviceBond], out_plink=0x7fffffffe1f8, error=0x7fffffffe358) at src/devices/nm-device-vlan.c:239
#8 0x00005555556b934c in nm_device_create_and_realize (self=self@entry=0x555555c3e320 [NMDeviceVlan], connection=connection@entry=0x7fffdc007890, parent=0x555555c33560 [NMDeviceBond], error=error@entry=0x7fffffffe358)
at src/devices/nm-device.c:2946
#9 0x00005555555b84c7 in connection_changed (connection=0x7fffdc007890, self=0x555555ab1070 [NMManager]) at src/nm-manager.c:1381
#10 0x00005555555b84c7 in connection_changed (self=0x555555ab1070 [NMManager], connection=0x7fffdc007890) at src/nm-manager.c:1431
#11 0x00005555555b9130 in retry_connections_for_parent_device (self=self@entry=0x555555ab1070 [NMManager], device=device@entry=0x555555c33560 [NMDeviceBond])
at src/nm-manager.c:1416
#12 0x00005555555b95c7 in add_device (self=self@entry=0x555555ab1070 [NMManager], device=device@entry=0x555555c33560 [NMDeviceBond], error=error@entry=0x7fffffffe598) at src/nm-manager.c:2238
#13 0x00005555555b83e1 in connection_changed (connection=0x7fffdc007b30, self=0x555555ab1070 [NMManager]) at src/nm-manager.c:1352
#14 0x00005555555b83e1 in connection_changed (self=0x555555ab1070 [NMManager], connection=0x7fffdc007b30) at src/nm-manager.c:1431
#15 0x00005555555be25b in nm_manager_start (self=0x555555ab1070 [NMManager], error=error@entry=0x7fffffffe720) at src/nm-manager.c:5202
#16 0x0000555555586b13 in main (argc=1, argv=0x7fffffffe888) at src/main.c:413
2017-08-21 17:41:29 +02:00
|
|
|
nm_device_get_iface(parent),
|
|
|
|
|
nm_device_get_type_desc(parent));
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-09-05 08:50:02 -05:00
|
|
|
if (!nm_device_supports_vlans(parent)) {
|
|
|
|
|
g_set_error(error,
|
|
|
|
|
NM_DEVICE_ERROR,
|
|
|
|
|
NM_DEVICE_ERROR_FAILED,
|
|
|
|
|
"no support for VLANs on interface %s of type %s",
|
|
|
|
|
nm_device_get_iface(parent),
|
|
|
|
|
nm_device_get_type_desc(parent));
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-09-05 08:50:02 -05:00
|
|
|
vlan_id = nm_setting_vlan_get_id(s_vlan);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
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_vlan_add(nm_device_get_platform(device),
|
|
|
|
|
iface,
|
|
|
|
|
parent_ifindex,
|
|
|
|
|
vlan_id,
|
|
|
|
|
nm_setting_vlan_get_flags(s_vlan),
|
|
|
|
|
out_plink);
|
|
|
|
|
if (r < 0) {
|
2014-09-05 08:50:02 -05:00
|
|
|
g_set_error(error,
|
|
|
|
|
NM_DEVICE_ERROR,
|
|
|
|
|
NM_DEVICE_ERROR_CREATION_FAILED,
|
|
|
|
|
"Failed to create VLAN 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));
|
2014-09-05 08:50:02 -05:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-01-02 09:57:43 +01:00
|
|
|
nm_device_parent_set_ifindex(device, parent_ifindex);
|
2016-01-10 14:31:10 +01:00
|
|
|
if (vlan_id != priv->vlan_id) {
|
|
|
|
|
priv->vlan_id = vlan_id;
|
2016-09-29 13:49:01 +02:00
|
|
|
_notify((NMDeviceVlan *) device, PROP_VLAN_ID);
|
2016-01-10 14:31:10 +01:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-09-05 08:50:02 -05:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-24 15:13:19 -05:00
|
|
|
static void
|
2016-01-10 15:19:58 +01:00
|
|
|
unrealize_notify(NMDevice *device)
|
2014-09-24 15:13:19 -05:00
|
|
|
{
|
2017-01-02 09:57:43 +01:00
|
|
|
NMDeviceVlan * self = NM_DEVICE_VLAN(device);
|
|
|
|
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE(self);
|
|
|
|
|
|
2016-01-10 15:19:58 +01:00
|
|
|
NM_DEVICE_CLASS(nm_device_vlan_parent_class)->unrealize_notify(device);
|
2014-09-24 15:13:19 -05:00
|
|
|
|
2017-01-02 09:57:43 +01:00
|
|
|
if (priv->vlan_id != 0) {
|
|
|
|
|
priv->vlan_id = 0;
|
|
|
|
|
_notify(self, PROP_VLAN_ID);
|
|
|
|
|
}
|
2014-09-24 15:13:19 -05:00
|
|
|
}
|
|
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
2014-09-05 08:50:02 -05:00
|
|
|
|
2014-10-06 17:17:54 -05:00
|
|
|
static NMDeviceCapabilities
|
2017-01-02 09:57:43 +01:00
|
|
|
get_generic_capabilities(NMDevice *device)
|
2014-10-06 17:17:54 -05:00
|
|
|
{
|
|
|
|
|
/* We assume VLAN interfaces always support carrier detect */
|
|
|
|
|
return NM_DEVICE_CAP_CARRIER_DETECT | NM_DEVICE_CAP_IS_SOFTWARE;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
2014-10-06 17:17:54 -05:00
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
is_available(NMDevice *device, NMDeviceCheckDevAvailableFlags flags)
|
|
|
|
|
{
|
2017-01-02 09:57:43 +01:00
|
|
|
if (!nm_device_parent_get_device(device))
|
2014-10-06 17:17:54 -05:00
|
|
|
return FALSE;
|
|
|
|
|
return NM_DEVICE_CLASS(nm_device_vlan_parent_class)->is_available(device, flags);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
2015-04-29 10:06:51 +02:00
|
|
|
|
2012-02-22 23:59:50 -06:00
|
|
|
static gboolean
|
2018-06-27 17:00:55 +02:00
|
|
|
check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error)
|
2012-02-22 23:59:50 -06:00
|
|
|
{
|
2020-02-14 10:50:25 +01:00
|
|
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE(device);
|
2012-02-22 23:59:50 -06:00
|
|
|
NMSettingVlan * s_vlan;
|
2018-06-27 17:00:55 +02:00
|
|
|
const char * parent;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-06-27 17:00:55 +02:00
|
|
|
if (!NM_DEVICE_CLASS(nm_device_vlan_parent_class)
|
|
|
|
|
->check_connection_compatible(device, connection, error))
|
2013-03-07 07:44:36 -05:00
|
|
|
return FALSE;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-09-24 16:58:07 -05:00
|
|
|
if (nm_device_is_real(device)) {
|
2018-06-27 17:00:55 +02:00
|
|
|
s_vlan = nm_connection_get_setting_vlan(connection);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-06-27 17:00:55 +02:00
|
|
|
if (nm_setting_vlan_get_id(s_vlan) != priv->vlan_id) {
|
|
|
|
|
nm_utils_error_set_literal(error,
|
|
|
|
|
NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY,
|
|
|
|
|
"vlan id setting mismatches");
|
2012-02-22 23:59:50 -06:00
|
|
|
return FALSE;
|
2018-06-27 17:00:55 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-09-24 16:58:07 -05:00
|
|
|
/* Check parent interface; could be an interface name or a UUID */
|
|
|
|
|
parent = nm_setting_vlan_get_parent(s_vlan);
|
|
|
|
|
if (parent) {
|
2018-06-27 17:00:55 +02:00
|
|
|
if (!nm_device_match_parent(device, parent)) {
|
|
|
|
|
nm_utils_error_set_literal(error,
|
|
|
|
|
NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY,
|
|
|
|
|
"vlan parent setting differs");
|
2014-09-24 16:58:07 -05:00
|
|
|
return FALSE;
|
2018-06-27 17:00:55 +02:00
|
|
|
}
|
2014-09-24 16:58:07 -05:00
|
|
|
} else {
|
|
|
|
|
/* Parent could be a MAC address in an NMSettingWired */
|
2018-06-27 17:00:55 +02:00
|
|
|
if (!nm_device_match_parent_hwaddr(device, connection, TRUE)) {
|
|
|
|
|
nm_utils_error_set_literal(error,
|
|
|
|
|
NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY,
|
|
|
|
|
"vlan parent mac setting differs");
|
2014-09-24 16:58:07 -05:00
|
|
|
return FALSE;
|
2018-06-27 17:00:55 +02:00
|
|
|
}
|
2014-09-24 16:58:07 -05:00
|
|
|
}
|
2012-02-22 23:59:50 -06:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2012-02-22 23:59:50 -06:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-04 11:57:22 +01:00
|
|
|
static gboolean
|
|
|
|
|
check_connection_available(NMDevice * device,
|
|
|
|
|
NMConnection * connection,
|
|
|
|
|
NMDeviceCheckConAvailableFlags flags,
|
2018-06-27 16:21:43 +02:00
|
|
|
const char * specific_object,
|
|
|
|
|
GError ** error)
|
2016-01-04 11:57:22 +01:00
|
|
|
{
|
|
|
|
|
if (!nm_device_is_real(device))
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
2018-06-27 16:21:43 +02:00
|
|
|
return NM_DEVICE_CLASS(nm_device_vlan_parent_class)
|
|
|
|
|
->check_connection_available(device, connection, flags, specific_object, error);
|
2016-01-04 11:57:22 +01:00
|
|
|
}
|
|
|
|
|
|
2012-02-22 23:59:50 -06:00
|
|
|
static gboolean
|
2012-09-27 12:12:15 -04:00
|
|
|
complete_connection(NMDevice * device,
|
|
|
|
|
NMConnection * connection,
|
|
|
|
|
const char * specific_object,
|
core: avoid clone of all-connections list for nm_utils_complete_generic()
NMSettings exposes a cached list of all connection. We don't need
to clone it. Note that this is not save against concurrent modification,
meaning, add/remove of connections in NMSettings will invalidate the
list.
However, it wasn't save against that previously either, because
altough we cloned the container (GSList), we didn't take an additional
reference to the elements.
This is purely a performance optimization, we don't need to clone the
list. Also, since the original list is of type "NMConnection *const*",
use that type insistently, instead of dependent API requiring GSList.
IMO, GSList is anyway not a very nice API for many use cases because
it requires an additional slice allocation for each element. It's
slower, and often less convenient to use.
2018-03-14 08:57:42 +01:00
|
|
|
NMConnection *const *existing_connections,
|
2012-09-27 12:12:15 -04:00
|
|
|
GError ** error)
|
2012-02-22 23:59:50 -06:00
|
|
|
{
|
|
|
|
|
NMSettingVlan *s_vlan;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-18 12:09:02 +02:00
|
|
|
nm_utils_complete_generic(nm_device_get_platform(device),
|
2016-03-08 13:57:20 +01:00
|
|
|
connection,
|
2012-02-22 23:59:50 -06:00
|
|
|
NM_SETTING_VLAN_SETTING_NAME,
|
|
|
|
|
existing_connections,
|
|
|
|
|
NULL,
|
2014-08-25 16:21:59 +02:00
|
|
|
_("VLAN connection"),
|
2020-09-28 16:03:33 +02:00
|
|
|
NULL,
|
2014-08-05 17:11:57 -04:00
|
|
|
NULL,
|
2012-02-22 23:59:50 -06:00
|
|
|
TRUE);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2012-02-22 23:59:50 -06:00
|
|
|
s_vlan = nm_connection_get_setting_vlan(connection);
|
|
|
|
|
if (!s_vlan) {
|
2014-09-22 12:28:06 -04:00
|
|
|
g_set_error_literal(error,
|
|
|
|
|
NM_DEVICE_ERROR,
|
|
|
|
|
NM_DEVICE_ERROR_INVALID_CONNECTION,
|
2012-02-22 23:59:50 -06:00
|
|
|
"A 'vlan' setting is required.");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2012-02-22 23:59:50 -06:00
|
|
|
/* If there's no VLAN interface, no parent, and no hardware address in the
|
|
|
|
|
* settings, then there's not enough information to complete the setting.
|
|
|
|
|
*/
|
all: standardize on NMSettingWired:mac-address for all VLANs
Currently, ethernet-based VLANs can specify the hardware address of
the parent device (and, in theory, the cloned hardware address and MTU
of the VLAN device) by using an NMSettingWired in addition to the
NMSettingVlan.
The theory was that non-ethernet-based VLANs, when we eventually
supported them, would likewise use the setting type corresponding to
their parent device. However, this turns out to be both complicated
(the settings plugins and connection editor would have a
hard-to-impossible time figuring out which setting type to use in some
cases) and incorrect (for most L2 settings [eg, BSSID, bond mode,
etc], the VLAN can't have its own values separate from the parent
device).
What we should have done was just have :mac-address,
:cloned-mac-address, and :mtu properties on NMSettingVlan. However, at
this point, for backward-compatibility, we will just stick with using
a combination of NMSettingVlan and NMSettingWired, but we will use
NMSettingWired regardless of the underlying hardware type.
2013-09-09 09:40:40 -04:00
|
|
|
if (!nm_setting_vlan_get_parent(s_vlan)
|
2018-06-27 22:48:50 +02:00
|
|
|
&& !nm_device_match_parent_hwaddr(device, connection, TRUE)) {
|
2014-09-22 12:28:06 -04:00
|
|
|
g_set_error_literal(
|
|
|
|
|
error,
|
|
|
|
|
NM_DEVICE_ERROR,
|
|
|
|
|
NM_DEVICE_ERROR_INVALID_CONNECTION,
|
all: standardize on NMSettingWired:mac-address for all VLANs
Currently, ethernet-based VLANs can specify the hardware address of
the parent device (and, in theory, the cloned hardware address and MTU
of the VLAN device) by using an NMSettingWired in addition to the
NMSettingVlan.
The theory was that non-ethernet-based VLANs, when we eventually
supported them, would likewise use the setting type corresponding to
their parent device. However, this turns out to be both complicated
(the settings plugins and connection editor would have a
hard-to-impossible time figuring out which setting type to use in some
cases) and incorrect (for most L2 settings [eg, BSSID, bond mode,
etc], the VLAN can't have its own values separate from the parent
device).
What we should have done was just have :mac-address,
:cloned-mac-address, and :mtu properties on NMSettingVlan. However, at
this point, for backward-compatibility, we will just stick with using
a combination of NMSettingVlan and NMSettingWired, but we will use
NMSettingWired regardless of the underlying hardware type.
2013-09-09 09:40:40 -04:00
|
|
|
"The 'vlan' setting had no interface name, parent, or hardware address.");
|
|
|
|
|
return FALSE;
|
2012-02-22 23:59:50 -06:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2012-02-22 23:59:50 -06:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-20 21:48:06 +02:00
|
|
|
static void
|
|
|
|
|
update_connection(NMDevice *device, NMConnection *connection)
|
|
|
|
|
{
|
shared: rework _NM_GET_PRIVATE() to use _Generic()
_NM_GET_PRIVATE() used typeof() to propagate constness of the @self
pointer. However, that means, it could only be used with a self pointer
of the exact type. That means, you explicitly had to cast from (GObject *)
or from (void *).
The requirement is cumbersome, and often led us to either create @self
pointer we didn't need:
NMDeviceVlan *self = NM_DEVICE_VLAN (device);
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self);
or casting:
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE ((NMDevice *) device);
In both cases we forcefully cast the source variable, loosing help from
the compiler to detect a bug.
For "nm-linux-platform.c", instead we commonly have a pointer of type
NMPlatform. Hence, we always forcefully cast the type via _NM_GET_PRIVATE_VOID().
Rework the macro to use _Generic(). If compiler supports _Generic(), then we
will get all compile time checks as desired. If the compiler doesn't support
_Generic(), it will still work. You don't get the compile-time checking of course,
but you'd notice that something is wrong once you build with a suitable
compiler.
2017-11-09 10:05:00 +01:00
|
|
|
NMDeviceVlanPrivate * priv = NM_DEVICE_VLAN_GET_PRIVATE(device);
|
2013-07-20 21:48:06 +02:00
|
|
|
NMSettingVlan * s_vlan = nm_connection_get_setting_vlan(connection);
|
|
|
|
|
int ifindex = nm_device_get_ifindex(device);
|
2015-10-12 13:44:44 +02:00
|
|
|
const NMPlatformLink *plink;
|
2015-10-30 11:02:44 +01:00
|
|
|
const NMPObject * polnk;
|
2016-01-10 14:31:10 +01:00
|
|
|
guint vlan_id;
|
|
|
|
|
guint vlan_flags;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-07-20 21:48:06 +02:00
|
|
|
if (!s_vlan) {
|
|
|
|
|
s_vlan = (NMSettingVlan *) nm_setting_vlan_new();
|
|
|
|
|
nm_connection_add_setting(connection, (NMSetting *) s_vlan);
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-18 12:09:02 +02:00
|
|
|
polnk = nm_platform_link_get_lnk(nm_device_get_platform(device),
|
|
|
|
|
ifindex,
|
|
|
|
|
NM_LINK_TYPE_VLAN,
|
|
|
|
|
&plink);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-01-10 14:31:10 +01:00
|
|
|
if (polnk)
|
|
|
|
|
vlan_id = polnk->lnk_vlan.id;
|
2015-08-17 17:48:37 +02:00
|
|
|
else
|
2016-01-10 14:31:10 +01:00
|
|
|
vlan_id = priv->vlan_id;
|
|
|
|
|
if (vlan_id != nm_setting_vlan_get_id(s_vlan))
|
|
|
|
|
g_object_set(s_vlan, NM_SETTING_VLAN_ID, vlan_id, NULL);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-08-17 22:18:17 +02:00
|
|
|
g_object_set(s_vlan,
|
|
|
|
|
NM_SETTING_VLAN_PARENT,
|
|
|
|
|
nm_device_parent_find_for_connection(device, nm_setting_vlan_get_parent(s_vlan)),
|
|
|
|
|
NULL);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-01-10 14:31:10 +01:00
|
|
|
if (polnk)
|
|
|
|
|
vlan_flags = polnk->lnk_vlan.flags;
|
|
|
|
|
else
|
|
|
|
|
vlan_flags = NM_VLAN_FLAG_REORDER_HEADERS;
|
|
|
|
|
if (vlan_flags != nm_setting_vlan_get_flags(s_vlan))
|
|
|
|
|
g_object_set(s_vlan, NM_SETTING_VLAN_FLAGS, (NMVlanFlags) vlan_flags, NULL);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-01-10 14:31:10 +01:00
|
|
|
if (polnk) {
|
|
|
|
|
_nm_setting_vlan_set_priorities(s_vlan,
|
|
|
|
|
NM_VLAN_INGRESS_MAP,
|
|
|
|
|
polnk->_lnk_vlan.ingress_qos_map,
|
|
|
|
|
polnk->_lnk_vlan.n_ingress_qos_map);
|
|
|
|
|
_nm_setting_vlan_set_priorities(s_vlan,
|
|
|
|
|
NM_VLAN_EGRESS_MAP,
|
|
|
|
|
polnk->_lnk_vlan.egress_qos_map,
|
|
|
|
|
polnk->_lnk_vlan.n_egress_qos_map);
|
|
|
|
|
} else {
|
|
|
|
|
_nm_setting_vlan_set_priorities(s_vlan, NM_VLAN_INGRESS_MAP, NULL, 0);
|
|
|
|
|
_nm_setting_vlan_set_priorities(s_vlan, NM_VLAN_EGRESS_MAP, NULL, 0);
|
|
|
|
|
}
|
2012-02-22 23:59:50 -06:00
|
|
|
}
|
|
|
|
|
|
2013-09-03 14:03:52 -04:00
|
|
|
static NMActStageReturn
|
2017-02-22 17:04:00 +01:00
|
|
|
act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason)
|
2013-09-03 14:03:52 -04:00
|
|
|
{
|
2017-01-02 09:57:43 +01:00
|
|
|
NMDevice * parent_device;
|
2013-09-03 14:03:52 -04:00
|
|
|
NMSettingVlan *s_vlan;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-04-12 10:41:20 +02:00
|
|
|
/* Change MAC address to parent's one if needed */
|
2017-01-02 09:57:43 +01:00
|
|
|
parent_device = nm_device_parent_get_device(device);
|
2017-10-12 19:36:09 +02:00
|
|
|
if (parent_device) {
|
2017-01-02 09:57:43 +01:00
|
|
|
parent_hwaddr_maybe_changed(parent_device, NULL, device);
|
2017-10-12 19:36:09 +02:00
|
|
|
parent_mtu_maybe_changed(parent_device, NULL, device);
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-10-22 13:06:27 +02:00
|
|
|
s_vlan = nm_device_get_applied_setting(device, NM_TYPE_SETTING_VLAN);
|
2013-09-03 14:03:52 -04:00
|
|
|
if (s_vlan) {
|
2015-10-30 11:02:44 +01:00
|
|
|
gs_free NMVlanQosMapping *ingress_map = NULL;
|
|
|
|
|
gs_free NMVlanQosMapping *egress_map = NULL;
|
2019-08-22 07:41:34 +02:00
|
|
|
guint n_ingress_map = 0;
|
|
|
|
|
guint n_egress_map = 0;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-10-30 11:02:44 +01:00
|
|
|
_nm_setting_vlan_get_priorities(s_vlan, NM_VLAN_INGRESS_MAP, &ingress_map, &n_ingress_map);
|
|
|
|
|
_nm_setting_vlan_get_priorities(s_vlan, NM_VLAN_EGRESS_MAP, &egress_map, &n_egress_map);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-18 12:09:02 +02:00
|
|
|
nm_platform_link_vlan_change(nm_device_get_platform(device),
|
2017-01-02 09:57:43 +01:00
|
|
|
nm_device_get_ifindex(device),
|
2015-10-30 11:02:44 +01:00
|
|
|
NM_VLAN_FLAGS_ALL,
|
|
|
|
|
nm_setting_vlan_get_flags(s_vlan),
|
|
|
|
|
TRUE,
|
|
|
|
|
ingress_map,
|
|
|
|
|
n_ingress_map,
|
|
|
|
|
TRUE,
|
|
|
|
|
egress_map,
|
|
|
|
|
n_egress_map);
|
2013-09-03 14:03:52 -04:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-08-22 07:41:34 +02:00
|
|
|
return NM_ACT_STAGE_RETURN_SUCCESS;
|
2013-09-03 14:03:52 -04:00
|
|
|
}
|
|
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
2012-02-22 23:59:50 -06:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
|
|
|
|
{
|
shared: rework _NM_GET_PRIVATE() to use _Generic()
_NM_GET_PRIVATE() used typeof() to propagate constness of the @self
pointer. However, that means, it could only be used with a self pointer
of the exact type. That means, you explicitly had to cast from (GObject *)
or from (void *).
The requirement is cumbersome, and often led us to either create @self
pointer we didn't need:
NMDeviceVlan *self = NM_DEVICE_VLAN (device);
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self);
or casting:
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE ((NMDevice *) device);
In both cases we forcefully cast the source variable, loosing help from
the compiler to detect a bug.
For "nm-linux-platform.c", instead we commonly have a pointer of type
NMPlatform. Hence, we always forcefully cast the type via _NM_GET_PRIVATE_VOID().
Rework the macro to use _Generic(). If compiler supports _Generic(), then we
will get all compile time checks as desired. If the compiler doesn't support
_Generic(), it will still work. You don't get the compile-time checking of course,
but you'd notice that something is wrong once you build with a suitable
compiler.
2017-11-09 10:05:00 +01:00
|
|
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE(object);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2012-02-22 23:59:50 -06:00
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_VLAN_ID:
|
|
|
|
|
g_value_set_uint(value, priv->vlan_id);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2012-02-22 23:59:50 -06:00
|
|
|
static void
|
2016-09-29 13:49:01 +02:00
|
|
|
nm_device_vlan_init(NMDeviceVlan *self)
|
2012-02-22 23:59:50 -06: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
|
|
|
static const NMDBusInterfaceInfoExtended interface_info_device_vlan = {
|
|
|
|
|
.parent = NM_DEFINE_GDBUS_INTERFACE_INFO_INIT(
|
|
|
|
|
NM_DBUS_INTERFACE_DEVICE_VLAN,
|
|
|
|
|
.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("HwAddress",
|
|
|
|
|
"s",
|
|
|
|
|
NM_DEVICE_HW_ADDRESS),
|
|
|
|
|
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L("Carrier", "b", NM_DEVICE_CARRIER),
|
|
|
|
|
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L("Parent", "o", NM_DEVICE_PARENT),
|
|
|
|
|
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L("VlanId",
|
|
|
|
|
"u",
|
|
|
|
|
NM_DEVICE_VLAN_ID), ), ),
|
|
|
|
|
.legacy_property_changed = TRUE,
|
|
|
|
|
};
|
|
|
|
|
|
2012-02-22 23:59:50 -06:00
|
|
|
static void
|
|
|
|
|
nm_device_vlan_class_init(NMDeviceVlanClass *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);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2012-02-22 23:59:50 -06:00
|
|
|
object_class->get_property = get_property;
|
2020-09-28 16:03:33 +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_vlan);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-07-10 09:26:42 +02:00
|
|
|
device_class->connection_type_supported = NM_SETTING_VLAN_SETTING_NAME;
|
2018-06-27 17:00:55 +02:00
|
|
|
device_class->connection_type_check_compatible = NM_SETTING_VLAN_SETTING_NAME;
|
2018-07-10 09:26:42 +02:00
|
|
|
device_class->link_types = NM_DEVICE_DEFINE_LINK_TYPES(NM_LINK_TYPE_VLAN);
|
2019-09-12 17:29:49 +02:00
|
|
|
device_class->mtu_parent_delta = 0; /* VLANs can have the same MTU of parent */
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-07-10 07:45:35 +02:00
|
|
|
device_class->create_and_realize = create_and_realize;
|
|
|
|
|
device_class->link_changed = link_changed;
|
|
|
|
|
device_class->unrealize_notify = unrealize_notify;
|
|
|
|
|
device_class->get_generic_capabilities = get_generic_capabilities;
|
2019-08-22 09:57:55 +02:00
|
|
|
device_class->act_stage1_prepare_set_hwaddr_ethernet = TRUE;
|
2018-07-10 07:45:35 +02:00
|
|
|
device_class->act_stage1_prepare = act_stage1_prepare;
|
2019-09-12 17:29:49 +02:00
|
|
|
device_class->get_configured_mtu = nm_device_get_configured_mtu_wired_parent;
|
2018-07-10 07:45:35 +02:00
|
|
|
device_class->is_available = is_available;
|
|
|
|
|
device_class->parent_changed_notify = parent_changed_notify;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-07-10 07:45:35 +02:00
|
|
|
device_class->check_connection_compatible = check_connection_compatible;
|
|
|
|
|
device_class->check_connection_available = check_connection_available;
|
|
|
|
|
device_class->complete_connection = complete_connection;
|
|
|
|
|
device_class->update_connection = update_connection;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
obj_properties[PROP_VLAN_ID] = g_param_spec_uint(NM_DEVICE_VLAN_ID,
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
0,
|
|
|
|
|
4095,
|
|
|
|
|
0,
|
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties);
|
2012-02-22 23:59:50 -06:00
|
|
|
}
|
2014-09-08 10:24:11 -05:00
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
2014-09-08 10:24:11 -05:00
|
|
|
|
2016-10-07 17:00:59 +02:00
|
|
|
#define NM_TYPE_VLAN_DEVICE_FACTORY (nm_vlan_device_factory_get_type())
|
|
|
|
|
#define NM_VLAN_DEVICE_FACTORY(obj) \
|
|
|
|
|
(G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_VLAN_DEVICE_FACTORY, NMVlanDeviceFactory))
|
2014-09-08 10:24:11 -05:00
|
|
|
|
|
|
|
|
static NMDevice *
|
2014-09-05 08:50:02 -05:00
|
|
|
create_device(NMDeviceFactory * factory,
|
|
|
|
|
const char * iface,
|
2016-01-10 15:13:20 +01:00
|
|
|
const NMPlatformLink *plink,
|
2014-09-05 08:50:02 -05:00
|
|
|
NMConnection * connection,
|
|
|
|
|
gboolean * out_ignore)
|
2014-09-08 10:24:11 -05:00
|
|
|
{
|
2014-09-05 08:50:02 -05:00
|
|
|
return (NMDevice *) g_object_new(NM_TYPE_DEVICE_VLAN,
|
|
|
|
|
NM_DEVICE_IFACE,
|
|
|
|
|
iface,
|
|
|
|
|
NM_DEVICE_DRIVER,
|
|
|
|
|
"8021q",
|
|
|
|
|
NM_DEVICE_TYPE_DESC,
|
|
|
|
|
"VLAN",
|
|
|
|
|
NM_DEVICE_DEVICE_TYPE,
|
|
|
|
|
NM_DEVICE_TYPE_VLAN,
|
2015-12-08 14:51:12 +01:00
|
|
|
NM_DEVICE_LINK_TYPE,
|
|
|
|
|
NM_LINK_TYPE_VLAN,
|
2014-09-05 08:50:02 -05:00
|
|
|
NULL);
|
2014-09-08 10:24:11 -05:00
|
|
|
}
|
|
|
|
|
|
2014-09-18 17:50:47 -05:00
|
|
|
static const char *
|
|
|
|
|
get_connection_parent(NMDeviceFactory *factory, NMConnection *connection)
|
|
|
|
|
{
|
|
|
|
|
NMSettingVlan * s_vlan;
|
|
|
|
|
NMSettingWired *s_wired;
|
|
|
|
|
const char * parent = NULL;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail(nm_connection_is_type(connection, NM_SETTING_VLAN_SETTING_NAME), NULL);
|
|
|
|
|
|
|
|
|
|
s_vlan = nm_connection_get_setting_vlan(connection);
|
|
|
|
|
g_assert(s_vlan);
|
|
|
|
|
|
|
|
|
|
parent = nm_setting_vlan_get_parent(s_vlan);
|
|
|
|
|
if (parent)
|
|
|
|
|
return parent;
|
|
|
|
|
|
|
|
|
|
/* Try the hardware address from the VLAN 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 *
|
2016-02-17 15:11:02 +01:00
|
|
|
get_connection_iface(NMDeviceFactory *factory, NMConnection *connection, const char *parent_iface)
|
2014-09-18 17:50:47 -05:00
|
|
|
{
|
|
|
|
|
const char * ifname;
|
|
|
|
|
NMSettingVlan *s_vlan;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail(nm_connection_is_type(connection, NM_SETTING_VLAN_SETTING_NAME), NULL);
|
|
|
|
|
|
|
|
|
|
s_vlan = nm_connection_get_setting_vlan(connection);
|
|
|
|
|
g_assert(s_vlan);
|
|
|
|
|
|
|
|
|
|
if (!parent_iface)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
ifname = nm_connection_get_interface_name(connection);
|
|
|
|
|
if (ifname)
|
|
|
|
|
return g_strdup(ifname);
|
|
|
|
|
|
|
|
|
|
/* If the connection doesn't specify the interface name for the VLAN
|
|
|
|
|
* device, we create one for it using the VLAN ID and the parent
|
|
|
|
|
* interface's name.
|
|
|
|
|
*/
|
|
|
|
|
return nm_utils_new_vlan_name(parent_iface, nm_setting_vlan_get_id(s_vlan));
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-17 14:17:30 -05:00
|
|
|
NM_DEVICE_FACTORY_DEFINE_INTERNAL(
|
|
|
|
|
VLAN,
|
|
|
|
|
Vlan,
|
|
|
|
|
vlan,
|
|
|
|
|
NM_DEVICE_FACTORY_DECLARE_LINK_TYPES(NM_LINK_TYPE_VLAN)
|
|
|
|
|
NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES(NM_SETTING_VLAN_SETTING_NAME),
|
2016-10-07 16:05:43 +02:00
|
|
|
factory_class->create_device = create_device;
|
|
|
|
|
factory_class->get_connection_parent = get_connection_parent;
|
|
|
|
|
factory_class->get_connection_iface = get_connection_iface;);
|