2017-06-06 15:55:08 +02:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
|
|
|
|
/* NetworkManager -- Network link manager
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2017 Red Hat, Inc.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "nm-default.h"
|
|
|
|
|
|
|
|
|
|
#include "nm-device-ppp.h"
|
|
|
|
|
|
2017-07-03 16:24:59 +02:00
|
|
|
#include "nm-act-request.h"
|
2017-06-06 15:55:08 +02:00
|
|
|
#include "nm-device-factory.h"
|
|
|
|
|
#include "nm-device-private.h"
|
2017-07-03 16:24:59 +02:00
|
|
|
#include "nm-manager.h"
|
|
|
|
|
#include "nm-setting-pppoe.h"
|
2017-06-06 15:55:08 +02:00
|
|
|
#include "platform/nm-platform.h"
|
2017-07-03 16:24:59 +02:00
|
|
|
#include "ppp/nm-ppp-manager.h"
|
|
|
|
|
#include "ppp/nm-ppp-manager-call.h"
|
|
|
|
|
#include "ppp/nm-ppp-status.h"
|
2017-06-06 15:55:08 +02:00
|
|
|
|
|
|
|
|
#include "nm-device-logging.h"
|
|
|
|
|
_LOG_DECLARE_SELF(NMDevicePpp);
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
typedef struct _NMDevicePppPrivate {
|
2017-07-03 16:24:59 +02:00
|
|
|
NMPPPManager *ppp_manager;
|
2018-01-08 16:55:07 +01:00
|
|
|
NMIP4Config *ip4_config;
|
2017-06-06 15:55:08 +02:00
|
|
|
} NMDevicePppPrivate;
|
|
|
|
|
|
|
|
|
|
struct _NMDevicePpp {
|
|
|
|
|
NMDevice parent;
|
|
|
|
|
NMDevicePppPrivate _priv;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct _NMDevicePppClass {
|
|
|
|
|
NMDeviceClass parent;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (NMDevicePpp, nm_device_ppp, NM_TYPE_DEVICE)
|
|
|
|
|
|
|
|
|
|
#define NM_DEVICE_PPP_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMDevicePpp, NM_IS_DEVICE_PPP)
|
|
|
|
|
|
|
|
|
|
static NMDeviceCapabilities
|
|
|
|
|
get_generic_capabilities (NMDevice *device)
|
|
|
|
|
{
|
|
|
|
|
return NM_DEVICE_CAP_IS_SOFTWARE;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-03 16:24:59 +02:00
|
|
|
static void
|
|
|
|
|
ppp_state_changed (NMPPPManager *ppp_manager, NMPPPStatus status, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NMDevice *device = NM_DEVICE (user_data);
|
|
|
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
|
case NM_PPP_STATUS_DISCONNECT:
|
|
|
|
|
nm_device_state_changed (device, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_PPP_DISCONNECT);
|
|
|
|
|
break;
|
|
|
|
|
case NM_PPP_STATUS_DEAD:
|
|
|
|
|
nm_device_state_changed (device, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_PPP_FAILED);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 16:45:43 +01:00
|
|
|
static void
|
|
|
|
|
ppp_ifindex_set (NMPPPManager *ppp_manager,
|
|
|
|
|
int ifindex,
|
|
|
|
|
const char *iface,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NMDevice *device = NM_DEVICE (user_data);
|
|
|
|
|
gs_free char *old_name = NULL;
|
|
|
|
|
|
|
|
|
|
if (!nm_device_take_over_link (device, ifindex, &old_name)) {
|
|
|
|
|
nm_device_state_changed (device, NM_DEVICE_STATE_FAILED,
|
|
|
|
|
NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (old_name)
|
|
|
|
|
nm_manager_remove_device (nm_manager_get (), old_name, NM_DEVICE_TYPE_PPP);
|
|
|
|
|
|
|
|
|
|
nm_device_activate_schedule_stage3_ip_config_start (device);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-03 16:24:59 +02:00
|
|
|
static void
|
|
|
|
|
ppp_ip4_config (NMPPPManager *ppp_manager,
|
|
|
|
|
NMIP4Config *config,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NMDevice *device = NM_DEVICE (user_data);
|
|
|
|
|
NMDevicePpp *self = NM_DEVICE_PPP (device);
|
|
|
|
|
NMDevicePppPrivate *priv = NM_DEVICE_PPP_GET_PRIVATE (self);
|
|
|
|
|
|
|
|
|
|
_LOGT (LOGD_DEVICE | LOGD_PPP, "received IPv4 config from pppd");
|
|
|
|
|
|
|
|
|
|
if (nm_device_get_state (device) == NM_DEVICE_STATE_IP_CONFIG) {
|
|
|
|
|
if (nm_device_activate_ip4_state_in_conf (device)) {
|
|
|
|
|
nm_device_activate_schedule_ip4_config_result (device, config);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2018-01-08 16:55:07 +01:00
|
|
|
if (priv->ip4_config)
|
|
|
|
|
g_object_unref (priv->ip4_config);
|
|
|
|
|
priv->ip4_config = g_object_ref (config);
|
2017-07-03 16:24:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NMActStageReturn
|
|
|
|
|
act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason)
|
|
|
|
|
{
|
|
|
|
|
NMDevicePpp *self = NM_DEVICE_PPP (device);
|
|
|
|
|
NMDevicePppPrivate *priv = NM_DEVICE_PPP_GET_PRIVATE (self);
|
|
|
|
|
NMSettingPppoe *s_pppoe;
|
|
|
|
|
NMActRequest *req;
|
2017-10-04 15:21:21 +02:00
|
|
|
GError *error = NULL;
|
2017-07-03 16:24:59 +02:00
|
|
|
|
|
|
|
|
req = nm_device_get_act_request (NM_DEVICE (self));
|
|
|
|
|
g_return_val_if_fail (req, NM_ACT_STAGE_RETURN_FAILURE);
|
|
|
|
|
|
|
|
|
|
s_pppoe = (NMSettingPppoe *) nm_device_get_applied_setting ((NMDevice *) self, NM_TYPE_SETTING_PPPOE);
|
|
|
|
|
g_return_val_if_fail (s_pppoe, NM_ACT_STAGE_RETURN_FAILURE);
|
|
|
|
|
|
2018-01-08 16:55:07 +01:00
|
|
|
g_clear_object (&priv->ip4_config);
|
2017-07-03 16:24:59 +02:00
|
|
|
|
2017-10-04 15:21:21 +02:00
|
|
|
priv->ppp_manager = nm_ppp_manager_create (nm_setting_pppoe_get_parent (s_pppoe), &error);
|
|
|
|
|
|
|
|
|
|
if (priv->ppp_manager) {
|
|
|
|
|
nm_ppp_manager_set_route_parameters (priv->ppp_manager,
|
|
|
|
|
nm_device_get_route_table (device, AF_INET, TRUE),
|
|
|
|
|
nm_device_get_route_metric (device, AF_INET),
|
|
|
|
|
nm_device_get_route_table (device, AF_INET6, TRUE),
|
|
|
|
|
nm_device_get_route_metric (device, AF_INET6));
|
|
|
|
|
}
|
2017-07-03 16:24:59 +02:00
|
|
|
|
|
|
|
|
if ( !priv->ppp_manager
|
|
|
|
|
|| !nm_ppp_manager_start (priv->ppp_manager, req,
|
|
|
|
|
nm_setting_pppoe_get_username (s_pppoe),
|
2017-10-04 15:21:21 +02:00
|
|
|
30, 0, &error)) {
|
|
|
|
|
_LOGW (LOGD_DEVICE | LOGD_PPP, "PPPoE failed to start: %s", error->message);
|
|
|
|
|
g_error_free (error);
|
2017-07-03 16:24:59 +02:00
|
|
|
|
|
|
|
|
g_clear_object (&priv->ppp_manager);
|
|
|
|
|
|
|
|
|
|
NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_PPP_START_FAILED);
|
|
|
|
|
return NM_ACT_STAGE_RETURN_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_STATE_CHANGED,
|
|
|
|
|
G_CALLBACK (ppp_state_changed),
|
|
|
|
|
self);
|
2018-01-08 16:45:43 +01:00
|
|
|
g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_IFINDEX_SET,
|
|
|
|
|
G_CALLBACK (ppp_ifindex_set),
|
|
|
|
|
self);
|
2017-07-03 16:24:59 +02:00
|
|
|
g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_IP4_CONFIG,
|
|
|
|
|
G_CALLBACK (ppp_ip4_config),
|
|
|
|
|
self);
|
|
|
|
|
|
|
|
|
|
return NM_ACT_STAGE_RETURN_POSTPONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NMActStageReturn
|
|
|
|
|
act_stage3_ip4_config_start (NMDevice *device,
|
|
|
|
|
NMIP4Config **out_config,
|
|
|
|
|
NMDeviceStateReason *out_failure_reason)
|
|
|
|
|
{
|
|
|
|
|
NMDevicePpp *self = NM_DEVICE_PPP (device);
|
|
|
|
|
NMDevicePppPrivate *priv = NM_DEVICE_PPP_GET_PRIVATE (self);
|
|
|
|
|
|
2018-01-08 16:55:07 +01:00
|
|
|
if (priv->ip4_config) {
|
2017-07-03 16:24:59 +02:00
|
|
|
if (out_config)
|
2018-01-08 16:55:07 +01:00
|
|
|
*out_config = g_steal_pointer (&priv->ip4_config);
|
2017-07-03 16:24:59 +02:00
|
|
|
else
|
2018-01-08 16:55:07 +01:00
|
|
|
g_clear_object (&priv->ip4_config);
|
2017-07-03 16:24:59 +02:00
|
|
|
return NM_ACT_STAGE_RETURN_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Wait IPCP termination */
|
|
|
|
|
return NM_ACT_STAGE_RETURN_POSTPONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
create_and_realize (NMDevice *device,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
NMDevice *parent,
|
|
|
|
|
const NMPlatformLink **out_plink,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
int parent_ifindex;
|
|
|
|
|
|
|
|
|
|
if (!parent) {
|
2017-09-14 09:26:51 +02:00
|
|
|
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_MISSING_DEPENDENCIES,
|
2017-07-03 16:24:59 +02:00
|
|
|
"PPP devices can not be created without a parent interface");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parent_ifindex = nm_device_get_ifindex (parent);
|
|
|
|
|
g_warn_if_fail (parent_ifindex > 0);
|
|
|
|
|
|
|
|
|
|
nm_device_parent_set_ifindex (device, parent_ifindex);
|
|
|
|
|
|
|
|
|
|
/* The interface is created later */
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
deactivate (NMDevice *device)
|
|
|
|
|
{
|
|
|
|
|
NMDevicePpp *self = NM_DEVICE_PPP (device);
|
|
|
|
|
NMDevicePppPrivate *priv = NM_DEVICE_PPP_GET_PRIVATE (self);
|
|
|
|
|
|
|
|
|
|
if (priv->ppp_manager) {
|
ppp-manager: rework stopping NMPPPManager by merging async/sync methods
Previously, there were two functions nm_ppp_manager_stop_sync() and
nm_ppp_manager_stop_async().
However, stop-sync() would still kill the process asynchronously (with a
2 seconds timeout before sending SIGKILL).
On the other hand, stop-async() did pretty much the same thing as
sync-code, except also using the GAsyncResult.
Merge the two functions. Stopping the instance for the most part can be
done entirely synchrnous. The only thing that is asynchronous, is
to wait for the process to terminate. For that, add a new callback
argument to nm_ppp_manager_stop(). This replaces the GAsyncResult
pattern.
Also, always ensure that NetworkManager runs the mainloop at least as
long until the process really terminated. Currently we don't get that
right, and during shutdown we just stop iterating the mainloop. However,
fix this from point of view of NMPPPManager and register a wait-object,
that later will correctly delay shutdown.
Also, NMDeviceWwan cared to wait (asynchronously) until pppd really
terminated. Keep that functionality. nm_ppp_manager_stop() returns
a handle that can be used to cancel the asynchrounous request and invoke
the callback right away. However note, that even when cancelling the
request, the wait-object that prevents shutdown of NetworkManager is
kept around, so that we can be sure to properly clean up.
2018-05-18 12:14:46 +02:00
|
|
|
nm_ppp_manager_stop (priv->ppp_manager, NULL, NULL);
|
2017-07-03 16:24:59 +02:00
|
|
|
g_clear_object (&priv->ppp_manager);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-06 15:55:08 +02:00
|
|
|
static void
|
|
|
|
|
nm_device_ppp_init (NMDevicePpp *self)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
dispose (GObject *object)
|
|
|
|
|
{
|
2017-07-03 16:24:59 +02:00
|
|
|
NMDevicePpp *self = NM_DEVICE_PPP (object);
|
|
|
|
|
NMDevicePppPrivate *priv = NM_DEVICE_PPP_GET_PRIVATE (self);
|
|
|
|
|
|
2018-01-08 16:55:07 +01:00
|
|
|
g_clear_object (&priv->ip4_config);
|
2017-07-03 16:24:59 +02:00
|
|
|
|
2017-06-06 15:55:08 +02:00
|
|
|
G_OBJECT_CLASS (nm_device_ppp_parent_class)->dispose (object);
|
|
|
|
|
}
|
|
|
|
|
|
core/dbus: rework D-Bus implementation to use lower layer GDBusConnection API
Previously, we used the generated GDBusInterfaceSkeleton types and glued
them via the NMExportedObject base class to our NM types. We also used
GDBusObjectManagerServer.
Don't do that anymore. The resulting code was more complicated despite (or
because?) using generated classes. It was hard to understand, complex, had
ordering-issues, and had a runtime and memory overhead.
This patch refactors this entirely and uses the lower layer API GDBusConnection
directly. It replaces the generated code, GDBusInterfaceSkeleton, and
GDBusObjectManagerServer. All this is now done by NMDbusObject and NMDBusManager
and static descriptor instances of type GDBusInterfaceInfo.
This adds a net plus of more then 1300 lines of hand written code. I claim
that this implementation is easier to understand. Note that previously we
also required extensive and complex glue code to bind our objects to the
generated skeleton objects. Instead, now glue our objects directly to
GDBusConnection. The result is more immediate and gets rid of layers of
code in between.
Now that the D-Bus glue us more under our control, we can address issus and
bottlenecks better, instead of adding code to bend the generated skeletons
to our needs.
Note that the current implementation now only supports one D-Bus connection.
That was effectively the case already, although there were places (and still are)
where the code pretends it could also support connections from a private socket.
We dropped private socket support mainly because it was unused, untested and
buggy, but also because GDBusObjectManagerServer could not export the same
objects on multiple connections. Now, it would be rather straight forward to
fix that and re-introduce ObjectManager on each private connection. But this
commit doesn't do that yet, and the new code intentionally supports only one
D-Bus connection.
Also, the D-Bus startup was simplified. There is no retry, either nm_dbus_manager_start()
succeeds, or it detects the initrd case. In the initrd case, bus manager never tries to
connect to D-Bus. Since the initrd scenario is not yet used/tested, this is good enough
for the moment. It could be easily extended later, for example with polling whether the
system bus appears (like was done previously). Also, restart of D-Bus daemon isn't
supported either -- just like before.
Note how NMDBusManager now implements the ObjectManager D-Bus interface
directly.
Also, this fixes race issues in the server, by no longer delaying
PropertiesChanged signals. NMExportedObject would collect changed
properties and send the signal out in idle_emit_properties_changed()
on idle. This messes up the ordering of change events w.r.t. other
signals and events on the bus. Note that not only NMExportedObject
messed up the ordering. Also the generated code would hook into
notify() and process change events in and idle handle, exhibiting the
same ordering issue too.
No longer do that. PropertiesChanged signals will be sent right away
by hooking into dispatch_properties_changed(). This means, changing
a property in quick succession will no longer be combined and is
guaranteed to emit signals for each individual state. Quite possibly
we emit now more PropertiesChanged signals then before.
However, we are now able to group a set of changes by using standard
g_object_freeze_notify()/g_object_thaw_notify(). We probably should
make more use of that.
Also, now that our signals are all handled in the right order, we
might find places where we still emit them in the wrong order. But that
is then due to the order in which our GObjects emit signals, not due
to an ill behavior of the D-Bus glue. Possibly we need to identify
such ordering issues and fix them.
Numbers (for contrib/rpm --without debug on x86_64):
- the patch changes the code size of NetworkManager by
- 2809360 bytes
+ 2537528 bytes (-9.7%)
- Runtime measurements are harder because there is a large variance
during testing. In other words, the numbers are not reproducible.
Currently, the implementation performs no caching of GVariants at all,
but it would be rather simple to add it, if that turns out to be
useful.
Anyway, without strong claim, it seems that the new form tends to
perform slightly better. That would be no surprise.
$ time (for i in {1..1000}; do nmcli >/dev/null || break; echo -n .; done)
- real 1m39.355s
+ real 1m37.432s
$ time (for i in {1..2000}; do busctl call org.freedesktop.NetworkManager /org/freedesktop org.freedesktop.DBus.ObjectManager GetManagedObjects > /dev/null || break; echo -n .; done)
- real 0m26.843s
+ real 0m25.281s
- Regarding RSS size, just looking at the processes in similar
conditions, doesn't give a large difference. On my system they
consume about 19MB RSS. It seems that the new version has a
slightly smaller RSS size.
- 19356 RSS
+ 18660 RSS
2018-02-26 13:51:52 +01:00
|
|
|
static const NMDBusInterfaceInfoExtended interface_info_device_ppp = {
|
|
|
|
|
.parent = NM_DEFINE_GDBUS_INTERFACE_INFO_INIT (
|
|
|
|
|
NM_DBUS_INTERFACE_DEVICE_PPP,
|
|
|
|
|
.signals = NM_DEFINE_GDBUS_SIGNAL_INFOS (
|
|
|
|
|
&nm_signal_info_property_changed_legacy,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
.legacy_property_changed = TRUE,
|
|
|
|
|
};
|
|
|
|
|
|
2017-06-06 15:55:08 +02:00
|
|
|
static void
|
|
|
|
|
nm_device_ppp_class_init (NMDevicePppClass *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);
|
2017-06-06 15:55:08 +02:00
|
|
|
|
|
|
|
|
object_class->dispose = dispose;
|
2017-07-03 16:24:59 +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_ppp);
|
|
|
|
|
|
2018-07-10 09:26:42 +02:00
|
|
|
device_class->connection_type_supported = NM_SETTING_PPPOE_SETTING_NAME;
|
2018-06-27 17:00:55 +02:00
|
|
|
device_class->connection_type_check_compatible = NM_SETTING_PPPOE_SETTING_NAME;
|
2018-07-10 09:26:42 +02:00
|
|
|
device_class->link_types = NM_DEVICE_DEFINE_LINK_TYPES (NM_LINK_TYPE_PPP);
|
|
|
|
|
|
2018-07-10 07:45:35 +02:00
|
|
|
device_class->act_stage2_config = act_stage2_config;
|
|
|
|
|
device_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start;
|
|
|
|
|
device_class->create_and_realize = create_and_realize;
|
|
|
|
|
device_class->deactivate = deactivate;
|
|
|
|
|
device_class->get_generic_capabilities = get_generic_capabilities;
|
2017-06-06 15:55:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#define NM_TYPE_PPP_DEVICE_FACTORY (nm_ppp_device_factory_get_type ())
|
|
|
|
|
#define NM_PPP_DEVICE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_PPP_DEVICE_FACTORY, NMPppDeviceFactory))
|
|
|
|
|
|
|
|
|
|
static NMDevice *
|
|
|
|
|
create_device (NMDeviceFactory *factory,
|
|
|
|
|
const char *iface,
|
|
|
|
|
const NMPlatformLink *plink,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
gboolean *out_ignore)
|
|
|
|
|
{
|
|
|
|
|
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_PPP,
|
|
|
|
|
NM_DEVICE_IFACE, iface,
|
|
|
|
|
NM_DEVICE_TYPE_DESC, "Ppp",
|
|
|
|
|
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_PPP,
|
|
|
|
|
NM_DEVICE_LINK_TYPE, NM_LINK_TYPE_PPP,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-03 16:24:59 +02:00
|
|
|
static gboolean
|
|
|
|
|
match_connection (NMDeviceFactory *factory, NMConnection *connection)
|
|
|
|
|
{
|
|
|
|
|
NMSettingPppoe *s_pppoe;
|
|
|
|
|
|
|
|
|
|
s_pppoe = nm_connection_get_setting_pppoe (connection);
|
|
|
|
|
nm_assert (s_pppoe);
|
|
|
|
|
|
|
|
|
|
return !!nm_setting_pppoe_get_parent (s_pppoe);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
|
get_connection_parent (NMDeviceFactory *factory, NMConnection *connection)
|
|
|
|
|
{
|
|
|
|
|
NMSettingPppoe *s_pppoe;
|
|
|
|
|
|
|
|
|
|
nm_assert (nm_connection_is_type (connection, NM_SETTING_PPPOE_SETTING_NAME));
|
|
|
|
|
|
|
|
|
|
s_pppoe = nm_connection_get_setting_pppoe (connection);
|
|
|
|
|
nm_assert (s_pppoe);
|
|
|
|
|
|
|
|
|
|
return nm_setting_pppoe_get_parent (s_pppoe);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
|
get_connection_iface (NMDeviceFactory *factory,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
const char *parent_iface)
|
|
|
|
|
{
|
|
|
|
|
nm_assert (nm_connection_is_type (connection, NM_SETTING_PPPOE_SETTING_NAME));
|
|
|
|
|
|
|
|
|
|
if (!parent_iface)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
return g_strdup (nm_connection_get_interface_name (connection));
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-06 15:55:08 +02:00
|
|
|
NM_DEVICE_FACTORY_DEFINE_INTERNAL (PPP, Ppp, ppp,
|
2017-07-03 16:24:59 +02:00
|
|
|
NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_PPP)
|
|
|
|
|
NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_PPPOE_SETTING_NAME),
|
|
|
|
|
factory_class->get_connection_parent = get_connection_parent;
|
|
|
|
|
factory_class->get_connection_iface = get_connection_iface;
|
2017-06-06 15:55:08 +02:00
|
|
|
factory_class->create_device = create_device;
|
2017-07-03 16:24:59 +02:00
|
|
|
factory_class->match_connection = match_connection;
|
2017-06-06 15:55:08 +02:00
|
|
|
);
|