2019-09-10 11:19:01 +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) 2013 - 2015 Red Hat, Inc.
|
2013-05-06 09:16:17 -04:00
|
|
|
*/
|
|
|
|
|
|
2016-02-19 14:57:48 +01:00
|
|
|
#include "nm-default.h"
|
2013-05-06 09:16:17 -04:00
|
|
|
|
2016-05-16 19:01:37 +02:00
|
|
|
#include "nm-device-macvlan.h"
|
|
|
|
|
|
2018-11-12 15:23:36 +01:00
|
|
|
#include <linux/if_link.h>
|
2013-05-06 09:16:17 -04:00
|
|
|
|
2013-05-29 12:57:13 -03:00
|
|
|
#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"
|
2013-05-06 09:16:17 -04:00
|
|
|
#include "nm-manager.h"
|
2016-11-21 00:43:52 +01:00
|
|
|
#include "platform/nm-platform.h"
|
2014-09-08 11:11:19 -05:00
|
|
|
#include "nm-device-factory.h"
|
2015-10-01 11:06:42 +02:00
|
|
|
#include "nm-setting-macvlan.h"
|
|
|
|
|
#include "nm-setting-wired.h"
|
|
|
|
|
#include "nm-active-connection.h"
|
|
|
|
|
#include "nm-ip4-config.h"
|
|
|
|
|
#include "nm-utils.h"
|
2013-05-06 09:16:17 -04:00
|
|
|
|
2014-08-02 15:14:26 +02:00
|
|
|
#include "nm-device-logging.h"
|
|
|
|
|
_LOG_DECLARE_SELF(NMDeviceMacvlan);
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
/*****************************************************************************/
|
2013-05-06 09:16:17 -04:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
NM_GOBJECT_PROPERTIES_DEFINE (NMDeviceMacvlan,
|
|
|
|
|
PROP_MODE,
|
|
|
|
|
PROP_NO_PROMISC,
|
|
|
|
|
PROP_TAP,
|
|
|
|
|
);
|
2013-05-06 09:16:17 -04:00
|
|
|
|
|
|
|
|
typedef struct {
|
2016-01-04 10:29:06 +01:00
|
|
|
gulong parent_state_id;
|
2019-09-13 11:40:51 +02:00
|
|
|
gulong parent_mtu_id;
|
2015-10-12 15:15:21 +02:00
|
|
|
NMPlatformLnkMacvlan props;
|
2013-05-06 09:16:17 -04:00
|
|
|
} NMDeviceMacvlanPrivate;
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
struct _NMDeviceMacvlan {
|
|
|
|
|
NMDevice parent;
|
|
|
|
|
NMDeviceMacvlanPrivate _priv;
|
|
|
|
|
};
|
2013-05-06 09:16:17 -04:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
struct _NMDeviceMacvlanClass {
|
|
|
|
|
NMDeviceClass parent;
|
2013-05-06 09:16:17 -04:00
|
|
|
};
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
G_DEFINE_TYPE (NMDeviceMacvlan, nm_device_macvlan, NM_TYPE_DEVICE)
|
|
|
|
|
|
2020-02-14 10:50:25 +01:00
|
|
|
#define NM_DEVICE_MACVLAN_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMDeviceMacvlan, NM_IS_DEVICE_MACVLAN, NMDevice)
|
2016-09-29 13:49:01 +02:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2015-10-01 11:06:42 +02:00
|
|
|
static int modes[][2] = {
|
|
|
|
|
{ NM_SETTING_MACVLAN_MODE_VEPA, MACVLAN_MODE_VEPA },
|
|
|
|
|
{ NM_SETTING_MACVLAN_MODE_BRIDGE, MACVLAN_MODE_BRIDGE },
|
|
|
|
|
{ NM_SETTING_MACVLAN_MODE_PRIVATE, MACVLAN_MODE_PRIVATE },
|
|
|
|
|
{ NM_SETTING_MACVLAN_MODE_PASSTHRU, MACVLAN_MODE_PASSTHRU },
|
|
|
|
|
};
|
2013-05-06 09:16:17 -04:00
|
|
|
|
2015-10-01 11:06:42 +02:00
|
|
|
static int
|
|
|
|
|
setting_mode_to_platform (int mode)
|
|
|
|
|
{
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (modes); i++) {
|
|
|
|
|
if (modes[i][0] == mode)
|
|
|
|
|
return modes[i][1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
platform_mode_to_setting (int mode)
|
|
|
|
|
{
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (modes); i++) {
|
|
|
|
|
if (modes[i][1] == mode)
|
|
|
|
|
return modes[i][0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2013-05-06 09:16:17 -04:00
|
|
|
|
2015-12-03 15:44:33 +01:00
|
|
|
static const char *
|
2015-10-01 11:06:42 +02:00
|
|
|
platform_mode_to_string (guint mode)
|
2015-12-03 15:44:33 +01:00
|
|
|
{
|
|
|
|
|
switch (mode) {
|
|
|
|
|
case MACVLAN_MODE_PRIVATE:
|
|
|
|
|
return "private";
|
|
|
|
|
case MACVLAN_MODE_VEPA:
|
|
|
|
|
return "vepa";
|
|
|
|
|
case MACVLAN_MODE_BRIDGE:
|
|
|
|
|
return "bridge";
|
|
|
|
|
case MACVLAN_MODE_PASSTHRU:
|
|
|
|
|
return "passthru";
|
|
|
|
|
default:
|
|
|
|
|
return "unknown";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
2015-10-01 11:06:42 +02:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
parent_state_changed (NMDevice *parent,
|
|
|
|
|
NMDeviceState new_state,
|
|
|
|
|
NMDeviceState old_state,
|
|
|
|
|
NMDeviceStateReason reason,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceMacvlan *self = NM_DEVICE_MACVLAN (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-10-01 11:06:42 +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-10-01 11:06:42 +02:00
|
|
|
}
|
|
|
|
|
|
2019-09-13 11:40:51 +02:00
|
|
|
static void
|
|
|
|
|
parent_mtu_maybe_changed (NMDevice *parent,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
/* the MTU of a macvlan/macvtap 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-01 11:06:42 +02:00
|
|
|
static void
|
2017-01-02 09:27:20 +01:00
|
|
|
parent_changed_notify (NMDevice *device,
|
|
|
|
|
int old_ifindex,
|
|
|
|
|
NMDevice *old_parent,
|
|
|
|
|
int new_ifindex,
|
|
|
|
|
NMDevice *new_parent)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceMacvlan *self = NM_DEVICE_MACVLAN (device);
|
2015-10-01 11:06:42 +02:00
|
|
|
NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE (self);
|
|
|
|
|
|
2017-01-02 09:27:20 +01:00
|
|
|
NM_DEVICE_CLASS (nm_device_macvlan_parent_class)->parent_changed_notify (device, old_ifindex, old_parent, new_ifindex, new_parent);
|
2015-10-01 11:06:42 +02:00
|
|
|
|
2017-01-02 09:27:20 +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);
|
2019-09-13 11:40:51 +02:00
|
|
|
nm_clear_g_signal_handler (old_parent, &priv->parent_mtu_id);
|
2015-10-01 11:06:42 +02:00
|
|
|
|
2017-01-02 09:27:20 +01:00
|
|
|
if (new_parent) {
|
|
|
|
|
priv->parent_state_id = g_signal_connect (new_parent,
|
2017-01-14 16:36:33 +01:00
|
|
|
NM_DEVICE_STATE_CHANGED,
|
2015-10-01 11:06:42 +02:00
|
|
|
G_CALLBACK (parent_state_changed),
|
|
|
|
|
device);
|
2019-09-13 11:40:51 +02:00
|
|
|
priv->parent_mtu_id = g_signal_connect (new_parent, "notify::" NM_DEVICE_MTU,
|
|
|
|
|
G_CALLBACK (parent_mtu_maybe_changed), device);
|
2015-10-01 11:06:42 +02: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:27:20 +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-10-01 11:06:42 +02:00
|
|
|
}
|
|
|
|
|
|
2017-01-02 09:27:20 +01:00
|
|
|
if (new_ifindex > 0) {
|
|
|
|
|
/* Recheck availability now that the parent has changed */
|
|
|
|
|
nm_device_queue_recheck_available (device,
|
|
|
|
|
NM_DEVICE_STATE_REASON_PARENT_CHANGED,
|
|
|
|
|
NM_DEVICE_STATE_REASON_PARENT_CHANGED);
|
|
|
|
|
}
|
2015-10-01 11:06:42 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-06 09:16:17 -04:00
|
|
|
static void
|
2013-08-21 12:36:14 +02:00
|
|
|
update_properties (NMDevice *device)
|
2013-05-06 09:16:17 -04:00
|
|
|
{
|
2014-08-02 15:14:26 +02:00
|
|
|
NMDeviceMacvlan *self = NM_DEVICE_MACVLAN (device);
|
2016-09-29 13:49:01 +02:00
|
|
|
NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE (self);
|
2013-05-06 09:16:17 -04:00
|
|
|
GObject *object = G_OBJECT (device);
|
2015-10-12 15:15:21 +02:00
|
|
|
const NMPlatformLnkMacvlan *props;
|
|
|
|
|
const NMPlatformLink *plink;
|
2015-10-01 11:06:42 +02:00
|
|
|
|
|
|
|
|
if (priv->props.tap)
|
2017-04-18 12:09:02 +02:00
|
|
|
props = nm_platform_link_get_lnk_macvtap (nm_device_get_platform (device), nm_device_get_ifindex (device), &plink);
|
2015-10-01 11:06:42 +02:00
|
|
|
else
|
2017-04-18 12:09:02 +02:00
|
|
|
props = nm_platform_link_get_lnk_macvlan (nm_device_get_platform (device), nm_device_get_ifindex (device), &plink);
|
2013-05-06 09:16:17 -04:00
|
|
|
|
2015-10-12 15:15:21 +02:00
|
|
|
if (!props) {
|
2016-10-06 21:28:40 +02:00
|
|
|
_LOGW (LOGD_PLATFORM, "could not get %s properties", priv->props.tap ? "macvtap" : "macvlan");
|
2013-05-06 09:16:17 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_freeze_notify (object);
|
|
|
|
|
|
2017-01-02 09:27:20 +01:00
|
|
|
nm_device_parent_set_ifindex (device, plink->parent);
|
2013-05-06 09:16:17 -04:00
|
|
|
|
2018-03-05 15:23:31 +01:00
|
|
|
#define CHECK_PROPERTY_CHANGED(field, prop) \
|
|
|
|
|
G_STMT_START { \
|
|
|
|
|
if (priv->props.field != props->field) { \
|
|
|
|
|
priv->props.field = props->field; \
|
|
|
|
|
_notify (self, prop); \
|
|
|
|
|
} \
|
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
|
|
|
|
CHECK_PROPERTY_CHANGED (mode, PROP_MODE);
|
|
|
|
|
CHECK_PROPERTY_CHANGED (no_promisc, PROP_NO_PROMISC);
|
2013-05-06 09:16:17 -04:00
|
|
|
|
|
|
|
|
g_object_thaw_notify (object);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-21 12:36:14 +02:00
|
|
|
static void
|
2017-01-02 15:38:24 +01:00
|
|
|
link_changed (NMDevice *device,
|
|
|
|
|
const NMPlatformLink *pllink)
|
2013-08-21 12:36:14 +02:00
|
|
|
{
|
2017-01-02 15:38:24 +01:00
|
|
|
NM_DEVICE_CLASS (nm_device_macvlan_parent_class)->link_changed (device, pllink);
|
2013-08-21 12:36:14 +02:00
|
|
|
update_properties (device);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-01 11:06:42 +02:00
|
|
|
static gboolean
|
|
|
|
|
create_and_realize (NMDevice *device,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
NMDevice *parent,
|
2015-12-09 15:13:57 +01:00
|
|
|
const NMPlatformLink **out_plink,
|
2015-10-01 11:06:42 +02:00
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
const char *iface = nm_device_get_iface (device);
|
|
|
|
|
NMSettingMacvlan *s_macvlan;
|
|
|
|
|
NMPlatformLnkMacvlan lnk = { };
|
|
|
|
|
int parent_ifindex;
|
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;
|
2015-10-01 11:06:42 +02:00
|
|
|
|
|
|
|
|
s_macvlan = nm_connection_get_setting_macvlan (connection);
|
2017-01-02 09:27:20 +01:00
|
|
|
g_return_val_if_fail (s_macvlan, FALSE);
|
|
|
|
|
|
|
|
|
|
parent_ifindex = parent ? nm_device_get_ifindex (parent) : 0;
|
2015-10-01 11:06:42 +02:00
|
|
|
|
2017-01-02 09:27:20 +01:00
|
|
|
if (parent_ifindex <= 0) {
|
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
|
|
|
"MACVLAN devices can not be created without a parent interface");
|
2017-01-02 09:27:20 +01:00
|
|
|
g_return_val_if_fail (!parent, FALSE);
|
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
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-01 11:06:42 +02:00
|
|
|
lnk.mode = setting_mode_to_platform (nm_setting_macvlan_get_mode (s_macvlan));
|
|
|
|
|
if (!lnk.mode) {
|
2016-04-19 11:59:48 +02:00
|
|
|
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
|
|
|
|
|
"unsupported MACVLAN mode %u in connection %s",
|
2015-10-01 11:06:42 +02:00
|
|
|
nm_setting_macvlan_get_mode (s_macvlan),
|
|
|
|
|
nm_connection_get_uuid (connection));
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
lnk.no_promisc = !nm_setting_macvlan_get_promiscuous (s_macvlan);
|
|
|
|
|
lnk.tap = nm_setting_macvlan_get_tap (s_macvlan);
|
|
|
|
|
|
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_macvlan_add (nm_device_get_platform (device), iface, parent_ifindex, &lnk, out_plink);
|
|
|
|
|
if (r < 0) {
|
2015-10-01 11:06:42 +02:00
|
|
|
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
|
|
|
|
|
"Failed to create %s interface '%s' for '%s': %s",
|
|
|
|
|
lnk.tap ? "macvtap" : "macvlan",
|
|
|
|
|
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));
|
2015-10-01 11:06:42 +02:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
2015-10-01 11:06:42 +02:00
|
|
|
|
|
|
|
|
static NMDeviceCapabilities
|
2019-08-28 16:03:02 +02:00
|
|
|
get_generic_capabilities (NMDevice *device)
|
2015-10-01 11:06:42 +02:00
|
|
|
{
|
|
|
|
|
/* We assume MACVLAN interfaces always support carrier detect */
|
|
|
|
|
return NM_DEVICE_CAP_CARRIER_DETECT | NM_DEVICE_CAP_IS_SOFTWARE;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
2015-10-01 11:06:42 +02:00
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
is_available (NMDevice *device, NMDeviceCheckDevAvailableFlags flags)
|
|
|
|
|
{
|
2017-01-02 09:27:20 +01:00
|
|
|
if (!nm_device_parent_get_device (device))
|
2015-10-01 11:06:42 +02:00
|
|
|
return FALSE;
|
|
|
|
|
return NM_DEVICE_CLASS (nm_device_macvlan_parent_class)->is_available (device, flags);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
2013-05-06 09:16:17 -04:00
|
|
|
|
2015-10-01 11:06:42 +02:00
|
|
|
static gboolean
|
2018-06-27 17:00:55 +02:00
|
|
|
check_connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
|
2015-10-01 11:06:42 +02:00
|
|
|
{
|
2020-02-14 10:50:25 +01:00
|
|
|
NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE (device);
|
2015-10-01 11:06:42 +02:00
|
|
|
NMSettingMacvlan *s_macvlan;
|
2016-02-16 16:50:00 +01:00
|
|
|
const char *parent = NULL;
|
2015-10-01 11:06:42 +02:00
|
|
|
|
2018-06-27 17:00:55 +02:00
|
|
|
if (!NM_DEVICE_CLASS (nm_device_macvlan_parent_class)->check_connection_compatible (device, connection, error))
|
2015-10-01 11:06:42 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
s_macvlan = nm_connection_get_setting_macvlan (connection);
|
|
|
|
|
|
2018-06-27 17:00:55 +02:00
|
|
|
if (nm_setting_macvlan_get_tap (s_macvlan) != priv->props.tap) {
|
|
|
|
|
if (priv->props.tap) {
|
|
|
|
|
nm_utils_error_set_literal (error, NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY,
|
|
|
|
|
"macvtap device does not match macvlan profile");
|
|
|
|
|
} else {
|
|
|
|
|
nm_utils_error_set_literal (error, NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY,
|
|
|
|
|
"macvlan device does not match macvtap profile");
|
|
|
|
|
}
|
2015-10-01 11:06:42 +02:00
|
|
|
return FALSE;
|
2018-06-27 17:00:55 +02:00
|
|
|
}
|
2015-10-01 11:06:42 +02:00
|
|
|
|
|
|
|
|
/* Before the device is realized some properties will not be set */
|
|
|
|
|
if (nm_device_is_real (device)) {
|
|
|
|
|
|
2018-06-27 17:00:55 +02:00
|
|
|
if (setting_mode_to_platform (nm_setting_macvlan_get_mode (s_macvlan)) != priv->props.mode) {
|
|
|
|
|
nm_utils_error_set_literal (error, NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY,
|
|
|
|
|
"macvlan mode setting differs");
|
2015-10-01 11:06:42 +02:00
|
|
|
return FALSE;
|
2018-06-27 17:00:55 +02:00
|
|
|
}
|
2015-10-01 11:06:42 +02:00
|
|
|
|
2018-06-27 17:00:55 +02:00
|
|
|
if (nm_setting_macvlan_get_promiscuous (s_macvlan) == priv->props.no_promisc) {
|
|
|
|
|
nm_utils_error_set_literal (error, NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY,
|
|
|
|
|
"macvlan promiscuous setting differs");
|
2015-10-01 11:06:42 +02:00
|
|
|
return FALSE;
|
2018-06-27 17:00:55 +02:00
|
|
|
}
|
2015-10-01 11:06:42 +02:00
|
|
|
|
|
|
|
|
/* Check parent interface; could be an interface name or a UUID */
|
|
|
|
|
parent = nm_setting_macvlan_get_parent (s_macvlan);
|
|
|
|
|
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,
|
|
|
|
|
"macvlan parent setting differs");
|
2015-10-01 11:06:42 +02:00
|
|
|
return FALSE;
|
2018-06-27 17:00:55 +02:00
|
|
|
}
|
2015-10-01 11:06:42 +02: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,
|
|
|
|
|
"macvlan parent mac setting differs");
|
2015-10-01 11:06:42 +02:00
|
|
|
return FALSE;
|
2018-06-27 17:00:55 +02:00
|
|
|
}
|
2015-10-01 11:06:42 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
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,
|
2015-10-01 11:06:42 +02:00
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
NMSettingMacvlan *s_macvlan;
|
|
|
|
|
|
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,
|
2015-10-01 11:06:42 +02:00
|
|
|
NM_SETTING_MACVLAN_SETTING_NAME,
|
|
|
|
|
existing_connections,
|
|
|
|
|
NULL,
|
|
|
|
|
_("MACVLAN connection"),
|
|
|
|
|
NULL,
|
2019-05-07 10:15:10 +02:00
|
|
|
NULL,
|
2015-10-01 11:06:42 +02:00
|
|
|
TRUE);
|
|
|
|
|
|
|
|
|
|
s_macvlan = nm_connection_get_setting_macvlan (connection);
|
|
|
|
|
if (!s_macvlan) {
|
|
|
|
|
g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION,
|
|
|
|
|
"A 'macvlan' setting is required.");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If there's no MACVLAN interface, no parent, and no hardware address in the
|
|
|
|
|
* settings, then there's not enough information to complete the setting.
|
|
|
|
|
*/
|
|
|
|
|
if ( !nm_setting_macvlan_get_parent (s_macvlan)
|
2018-06-27 22:48:50 +02:00
|
|
|
&& !nm_device_match_parent_hwaddr (device, connection, TRUE)) {
|
2015-10-01 11:06:42 +02:00
|
|
|
g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION,
|
|
|
|
|
"The 'macvlan' setting had no interface name, parent, or hardware address.");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-06 09:16:17 -04:00
|
|
|
static void
|
2015-10-01 11:06:42 +02:00
|
|
|
update_connection (NMDevice *device, NMConnection *connection)
|
2013-05-06 09:16:17 -04:00
|
|
|
{
|
2020-02-14 10:50:25 +01:00
|
|
|
NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE (device);
|
2015-10-01 11:06:42 +02:00
|
|
|
NMSettingMacvlan *s_macvlan = nm_connection_get_setting_macvlan (connection);
|
|
|
|
|
int new_mode;
|
|
|
|
|
|
|
|
|
|
if (!s_macvlan) {
|
|
|
|
|
s_macvlan = (NMSettingMacvlan *) nm_setting_macvlan_new ();
|
|
|
|
|
nm_connection_add_setting (connection, (NMSetting *) s_macvlan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
new_mode = platform_mode_to_setting (priv->props.mode);
|
|
|
|
|
if (new_mode != nm_setting_macvlan_get_mode (s_macvlan))
|
|
|
|
|
g_object_set (s_macvlan, NM_SETTING_MACVLAN_MODE, new_mode, NULL);
|
|
|
|
|
|
|
|
|
|
if (priv->props.no_promisc == nm_setting_macvlan_get_promiscuous (s_macvlan))
|
|
|
|
|
g_object_set (s_macvlan, NM_SETTING_MACVLAN_PROMISCUOUS, !priv->props.no_promisc, NULL);
|
|
|
|
|
|
|
|
|
|
if (priv->props.tap != nm_setting_macvlan_get_tap (s_macvlan))
|
|
|
|
|
g_object_set (s_macvlan, NM_SETTING_MACVLAN_TAP, !!priv->props.tap, NULL);
|
|
|
|
|
|
2018-08-17 22:18:17 +02:00
|
|
|
g_object_set (s_macvlan,
|
|
|
|
|
NM_SETTING_MACVLAN_PARENT,
|
|
|
|
|
nm_device_parent_find_for_connection (device,
|
|
|
|
|
nm_setting_macvlan_get_parent (s_macvlan)),
|
|
|
|
|
NULL);
|
2015-10-01 11:06:42 +02:00
|
|
|
}
|
|
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
2015-10-01 11:06:42 +02:00
|
|
|
|
2013-05-06 09:16:17 -04:00
|
|
|
static void
|
|
|
|
|
get_property (GObject *object, guint prop_id,
|
|
|
|
|
GValue *value, GParamSpec *pspec)
|
|
|
|
|
{
|
2020-02-14 10:50:25 +01:00
|
|
|
NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE (object);
|
2013-05-06 09:16:17 -04:00
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_MODE:
|
2015-10-01 11:06:42 +02:00
|
|
|
g_value_set_string (value, platform_mode_to_string (priv->props.mode));
|
2013-05-06 09:16:17 -04:00
|
|
|
break;
|
|
|
|
|
case PROP_NO_PROMISC:
|
|
|
|
|
g_value_set_boolean (value, priv->props.no_promisc);
|
|
|
|
|
break;
|
2015-10-01 11:06:42 +02:00
|
|
|
case PROP_TAP:
|
|
|
|
|
g_value_set_boolean (value, priv->props.tap);
|
|
|
|
|
break;
|
2013-05-06 09:16:17 -04:00
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-01 11:06:42 +02:00
|
|
|
static void
|
|
|
|
|
set_property (GObject *object, guint prop_id,
|
2016-09-29 13:49:01 +02:00
|
|
|
const GValue *value, GParamSpec *pspec)
|
2015-10-01 11:06:42 +02:00
|
|
|
{
|
2020-02-14 10:50:25 +01:00
|
|
|
NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE (object);
|
2015-10-01 11:06:42 +02:00
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_TAP:
|
|
|
|
|
priv->props.tap = g_value_get_boolean (value);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
nm_device_macvlan_init (NMDeviceMacvlan *self)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-05 11:19:31 +02:00
|
|
|
#if NM_MORE_ASSERTS
|
2019-09-13 11:40:51 +02:00
|
|
|
static void
|
|
|
|
|
dispose (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
G_OBJECT_CLASS (nm_device_macvlan_parent_class)->dispose (object);
|
|
|
|
|
|
2020-05-05 11:19:31 +02:00
|
|
|
nm_assert (NM_DEVICE_MACVLAN_GET_PRIVATE (object)->parent_state_id == 0);
|
|
|
|
|
nm_assert (NM_DEVICE_MACVLAN_GET_PRIVATE (object)->parent_mtu_id == 0);
|
2019-09-13 11:40:51 +02:00
|
|
|
}
|
2020-05-05 11:19:31 +02:00
|
|
|
#endif
|
2019-09-13 11:40:51 +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
|
|
|
static const NMDBusInterfaceInfoExtended interface_info_device_macvlan = {
|
|
|
|
|
.parent = NM_DEFINE_GDBUS_INTERFACE_INFO_INIT (
|
|
|
|
|
NM_DBUS_INTERFACE_DEVICE_MACVLAN,
|
|
|
|
|
.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 ("Mode", "s", NM_DEVICE_MACVLAN_MODE),
|
|
|
|
|
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("NoPromisc", "b", NM_DEVICE_MACVLAN_NO_PROMISC),
|
|
|
|
|
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("Tab", "b", NM_DEVICE_MACVLAN_TAP),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
.legacy_property_changed = TRUE,
|
|
|
|
|
};
|
|
|
|
|
|
2013-05-06 09:16:17 -04:00
|
|
|
static void
|
|
|
|
|
nm_device_macvlan_class_init (NMDeviceMacvlanClass *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);
|
2013-05-06 09:16:17 -04:00
|
|
|
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
|
|
|
|
|
|
2020-05-07 11:14:26 +02:00
|
|
|
#if NM_MORE_ASSERTS
|
2019-09-13 11:40:51 +02:00
|
|
|
object_class->dispose = dispose;
|
2020-05-07 11:14:26 +02:00
|
|
|
#endif
|
2013-05-06 09:16:17 -04:00
|
|
|
object_class->get_property = get_property;
|
2015-10-01 11:06:42 +02:00
|
|
|
object_class->set_property = set_property;
|
|
|
|
|
|
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_macvlan);
|
|
|
|
|
|
2018-07-10 09:26:42 +02:00
|
|
|
device_class->connection_type_supported = NM_SETTING_MACVLAN_SETTING_NAME;
|
2018-06-27 17:00:55 +02:00
|
|
|
device_class->connection_type_check_compatible = NM_SETTING_MACVLAN_SETTING_NAME;
|
2018-07-10 09:26:42 +02:00
|
|
|
device_class->link_types = NM_DEVICE_DEFINE_LINK_TYPES (NM_LINK_TYPE_MACVLAN, NM_LINK_TYPE_MACVTAP);
|
2019-09-13 11:40:51 +02:00
|
|
|
device_class->mtu_parent_delta = 0;
|
2018-07-10 09:26:42 +02:00
|
|
|
|
2019-08-22 09:40:45 +02:00
|
|
|
device_class->act_stage1_prepare_set_hwaddr_ethernet = TRUE;
|
2015-10-01 11:06:42 +02:00
|
|
|
device_class->check_connection_compatible = check_connection_compatible;
|
|
|
|
|
device_class->complete_connection = complete_connection;
|
|
|
|
|
device_class->create_and_realize = create_and_realize;
|
|
|
|
|
device_class->get_generic_capabilities = get_generic_capabilities;
|
2019-09-13 11:40:51 +02:00
|
|
|
device_class->get_configured_mtu = nm_device_get_configured_mtu_wired_parent;
|
2015-10-01 11:06:42 +02:00
|
|
|
device_class->is_available = is_available;
|
2013-05-06 09:16:17 -04:00
|
|
|
device_class->link_changed = link_changed;
|
2017-01-02 09:27:20 +01:00
|
|
|
device_class->parent_changed_notify = parent_changed_notify;
|
2015-10-01 11:06:42 +02:00
|
|
|
device_class->update_connection = update_connection;
|
2013-05-06 09:16:17 -04:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
obj_properties[PROP_MODE] =
|
|
|
|
|
g_param_spec_string (NM_DEVICE_MACVLAN_MODE, "", "",
|
|
|
|
|
NULL,
|
|
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
|
|
obj_properties[PROP_NO_PROMISC] =
|
|
|
|
|
g_param_spec_boolean (NM_DEVICE_MACVLAN_NO_PROMISC, "", "",
|
|
|
|
|
FALSE,
|
|
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
|
|
obj_properties[PROP_TAP] =
|
|
|
|
|
g_param_spec_boolean (NM_DEVICE_MACVLAN_TAP, "", "",
|
|
|
|
|
FALSE,
|
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
|
|
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
|
2013-05-06 09:16:17 -04:00
|
|
|
}
|
2014-09-08 11:11:19 -05:00
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
2014-09-08 11:11:19 -05:00
|
|
|
|
2016-10-07 17:00:59 +02:00
|
|
|
#define NM_TYPE_MACVLAN_DEVICE_FACTORY (nm_macvlan_device_factory_get_type ())
|
|
|
|
|
#define NM_MACVLAN_DEVICE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_MACVLAN_DEVICE_FACTORY, NMMacvlanDeviceFactory))
|
2014-09-08 11:11:19 -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 11:11:19 -05:00
|
|
|
{
|
2015-10-01 11:06:42 +02:00
|
|
|
NMSettingMacvlan *s_macvlan;
|
|
|
|
|
NMLinkType link_type;
|
|
|
|
|
gboolean tap;
|
|
|
|
|
|
|
|
|
|
if (connection) {
|
|
|
|
|
s_macvlan = nm_connection_get_setting_macvlan (connection);
|
|
|
|
|
g_assert (s_macvlan);
|
|
|
|
|
tap = nm_setting_macvlan_get_tap (s_macvlan);
|
|
|
|
|
} else {
|
|
|
|
|
g_assert (plink);
|
|
|
|
|
tap = plink->type == NM_LINK_TYPE_MACVTAP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
link_type = tap ? NM_LINK_TYPE_MACVTAP : NM_LINK_TYPE_MACVLAN;
|
2015-12-08 14:51:12 +01:00
|
|
|
|
2014-09-17 14:17:30 -05:00
|
|
|
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_MACVLAN,
|
2014-09-05 08:50:02 -05:00
|
|
|
NM_DEVICE_IFACE, iface,
|
2014-09-17 14:17:30 -05:00
|
|
|
NM_DEVICE_TYPE_DESC, "Macvlan",
|
2015-10-01 11:06:42 +02:00
|
|
|
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_MACVLAN,
|
|
|
|
|
NM_DEVICE_LINK_TYPE, link_type,
|
|
|
|
|
NM_DEVICE_MACVLAN_TAP, tap,
|
2014-09-17 14:17:30 -05:00
|
|
|
NULL);
|
2014-09-08 11:11:19 -05:00
|
|
|
}
|
|
|
|
|
|
2015-10-01 11:06:42 +02:00
|
|
|
static const char *
|
|
|
|
|
get_connection_parent (NMDeviceFactory *factory, NMConnection *connection)
|
|
|
|
|
{
|
|
|
|
|
NMSettingMacvlan *s_macvlan;
|
|
|
|
|
NMSettingWired *s_wired;
|
|
|
|
|
const char *parent = NULL;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (nm_connection_is_type (connection, NM_SETTING_MACVLAN_SETTING_NAME), NULL);
|
|
|
|
|
|
|
|
|
|
s_macvlan = nm_connection_get_setting_macvlan (connection);
|
|
|
|
|
g_assert (s_macvlan);
|
|
|
|
|
|
|
|
|
|
parent = nm_setting_macvlan_get_parent (s_macvlan);
|
|
|
|
|
if (parent)
|
|
|
|
|
return parent;
|
|
|
|
|
|
|
|
|
|
/* Try the hardware address from the MACVLAN 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)
|
2015-10-01 11:06:42 +02:00
|
|
|
{
|
|
|
|
|
NMSettingMacvlan *s_macvlan;
|
|
|
|
|
const char *ifname;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (nm_connection_is_type (connection, NM_SETTING_MACVLAN_SETTING_NAME), NULL);
|
|
|
|
|
|
|
|
|
|
s_macvlan = nm_connection_get_setting_macvlan (connection);
|
|
|
|
|
g_assert (s_macvlan);
|
|
|
|
|
|
|
|
|
|
if (!parent_iface)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
ifname = nm_connection_get_interface_name (connection);
|
|
|
|
|
return g_strdup (ifname);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-17 14:17:30 -05:00
|
|
|
NM_DEVICE_FACTORY_DEFINE_INTERNAL (MACVLAN, Macvlan, macvlan,
|
2015-10-01 11:06:42 +02:00
|
|
|
NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_MACVLAN, NM_LINK_TYPE_MACVTAP)
|
|
|
|
|
NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_MACVLAN_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;
|
2016-09-29 13:49:01 +02:00
|
|
|
);
|