2013-04-17 10:41:15 -04: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.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2013 Red Hat, Inc.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-02-19 14:57:48 +01:00
|
|
|
#include "nm-default.h"
|
2013-04-17 10:41:15 -04:00
|
|
|
|
|
|
|
|
#include "nm-device-generic.h"
|
2016-09-29 13:49:01 +02:00
|
|
|
|
2013-04-17 10:41:15 -04:00
|
|
|
#include "nm-device-private.h"
|
2013-04-26 12:06:15 -04:00
|
|
|
#include "nm-platform.h"
|
2014-10-21 22:09:52 -04:00
|
|
|
#include "nm-core-internal.h"
|
2013-04-17 10:41:15 -04:00
|
|
|
|
2015-04-15 14:53:30 -04:00
|
|
|
#include "nmdbus-device-generic.h"
|
2013-04-17 10:41:15 -04:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
/*****************************************************************************/
|
2013-04-17 10:41:15 -04:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
|
|
|
|
|
PROP_TYPE_DESCRIPTION,
|
|
|
|
|
);
|
2013-04-17 10:41:15 -04:00
|
|
|
|
|
|
|
|
typedef struct {
|
2013-04-26 12:06:15 -04:00
|
|
|
char *type_description;
|
2013-04-17 10:41:15 -04:00
|
|
|
} NMDeviceGenericPrivate;
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
struct _NMDeviceGeneric {
|
|
|
|
|
NMDevice parent;
|
|
|
|
|
NMDeviceGenericPrivate _priv;
|
|
|
|
|
};
|
2013-04-26 12:06:15 -04:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
struct _NMDeviceGenericClass {
|
|
|
|
|
NMDeviceClass parent;
|
2013-04-26 12:06:15 -04:00
|
|
|
};
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
G_DEFINE_TYPE (NMDeviceGeneric, nm_device_generic, NM_TYPE_DEVICE)
|
|
|
|
|
|
|
|
|
|
#define NM_DEVICE_GENERIC_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMDeviceGeneric, NM_IS_DEVICE_GENERIC)
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2015-04-17 15:15:38 +02:00
|
|
|
static NMDeviceCapabilities
|
2013-05-20 15:38:54 -03:00
|
|
|
get_generic_capabilities (NMDevice *dev)
|
|
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
if (nm_platform_link_supports_carrier_detect (NM_PLATFORM_GET, nm_device_get_ifindex (dev)))
|
2013-05-20 15:38:54 -03:00
|
|
|
return NM_DEVICE_CAP_CARRIER_DETECT;
|
|
|
|
|
else
|
|
|
|
|
return NM_DEVICE_CAP_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-15 15:00:07 +02:00
|
|
|
static const char *
|
|
|
|
|
get_type_description (NMDevice *device)
|
|
|
|
|
{
|
2016-09-29 13:49:01 +02:00
|
|
|
if (NM_DEVICE_GENERIC_GET_PRIVATE ((NMDeviceGeneric *) device)->type_description)
|
|
|
|
|
return NM_DEVICE_GENERIC_GET_PRIVATE ((NMDeviceGeneric *) device)->type_description;
|
2015-05-15 15:00:07 +02:00
|
|
|
return NM_DEVICE_CLASS (nm_device_generic_parent_class)->get_type_description (device);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-05 08:50:02 -05:00
|
|
|
static void
|
2016-01-08 17:24:24 +01:00
|
|
|
realize_start_notify (NMDevice *device, const NMPlatformLink *plink)
|
2014-09-05 08:50:02 -05:00
|
|
|
{
|
|
|
|
|
NMDeviceGeneric *self = NM_DEVICE_GENERIC (device);
|
|
|
|
|
NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (self);
|
|
|
|
|
int ifindex;
|
|
|
|
|
|
2016-01-08 17:24:24 +01:00
|
|
|
NM_DEVICE_CLASS (nm_device_generic_parent_class)->realize_start_notify (device, plink);
|
2014-09-05 08:50:02 -05:00
|
|
|
|
|
|
|
|
g_clear_pointer (&priv->type_description, g_free);
|
|
|
|
|
ifindex = nm_device_get_ip_ifindex (NM_DEVICE (self));
|
|
|
|
|
if (ifindex > 0)
|
|
|
|
|
priv->type_description = g_strdup (nm_platform_link_get_type_name (NM_PLATFORM_GET, ifindex));
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-17 10:41:15 -04:00
|
|
|
static gboolean
|
2014-05-30 13:44:53 -05:00
|
|
|
check_connection_compatible (NMDevice *device, NMConnection *connection)
|
2013-04-17 10:41:15 -04:00
|
|
|
{
|
|
|
|
|
NMSettingConnection *s_con;
|
|
|
|
|
|
2014-05-30 13:44:53 -05:00
|
|
|
if (!NM_DEVICE_CLASS (nm_device_generic_parent_class)->check_connection_compatible (device, connection))
|
2013-04-17 10:41:15 -04:00
|
|
|
return FALSE;
|
|
|
|
|
|
2014-05-30 13:44:53 -05:00
|
|
|
if (!nm_connection_is_type (connection, NM_SETTING_GENERIC_SETTING_NAME))
|
2013-04-17 10:41:15 -04:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
s_con = nm_connection_get_setting_connection (connection);
|
2014-05-30 13:44:53 -05:00
|
|
|
if (!nm_setting_connection_get_interface_name (s_con))
|
2013-04-17 10:41:15 -04:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-06 20:57:45 -06:00
|
|
|
static void
|
|
|
|
|
update_connection (NMDevice *device, NMConnection *connection)
|
|
|
|
|
{
|
2013-11-14 09:58:30 -06:00
|
|
|
NMSettingConnection *s_con;
|
|
|
|
|
|
2013-11-06 20:57:45 -06:00
|
|
|
if (!nm_connection_get_setting_generic (connection))
|
|
|
|
|
nm_connection_add_setting (connection, nm_setting_generic_new ());
|
2013-11-14 09:58:30 -06:00
|
|
|
|
|
|
|
|
s_con = nm_connection_get_setting_connection (connection);
|
|
|
|
|
g_assert (s_con);
|
|
|
|
|
g_object_set (G_OBJECT (s_con),
|
|
|
|
|
NM_SETTING_CONNECTION_INTERFACE_NAME, nm_device_get_iface (device),
|
|
|
|
|
NULL);
|
2013-11-06 20:57:45 -06:00
|
|
|
}
|
|
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
2013-04-17 10:41:15 -04:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
static void
|
|
|
|
|
get_property (GObject *object, guint prop_id,
|
|
|
|
|
GValue *value, GParamSpec *pspec)
|
2013-04-17 10:41:15 -04:00
|
|
|
{
|
2016-09-29 13:49:01 +02:00
|
|
|
NMDeviceGeneric *self = NM_DEVICE_GENERIC (object);
|
|
|
|
|
NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (self);
|
2013-04-17 10:41:15 -04:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_TYPE_DESCRIPTION:
|
|
|
|
|
g_value_set_string (value, priv->type_description);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-04-17 10:41:15 -04:00
|
|
|
}
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
static void
|
|
|
|
|
set_property (GObject *object, guint prop_id,
|
|
|
|
|
const GValue *value, GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceGeneric *self = NM_DEVICE_GENERIC (object);
|
|
|
|
|
NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (self);
|
|
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_TYPE_DESCRIPTION:
|
|
|
|
|
priv->type_description = g_value_dup_string (value);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2013-04-17 10:41:15 -04:00
|
|
|
static void
|
|
|
|
|
nm_device_generic_init (NMDeviceGeneric *self)
|
|
|
|
|
{
|
2015-06-29 18:06:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GObject *
|
|
|
|
|
constructor (GType type,
|
|
|
|
|
guint n_construct_params,
|
|
|
|
|
GObjectConstructParam *construct_params)
|
|
|
|
|
{
|
|
|
|
|
GObject *object;
|
|
|
|
|
|
|
|
|
|
object = G_OBJECT_CLASS (nm_device_generic_parent_class)->constructor (type,
|
|
|
|
|
n_construct_params,
|
|
|
|
|
construct_params);
|
|
|
|
|
|
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_flags ((NMDevice *) object, NM_UNMANAGED_BY_DEFAULT, TRUE);
|
2015-06-29 18:06:12 +02:00
|
|
|
|
|
|
|
|
return object;
|
2013-04-17 10:41:15 -04:00
|
|
|
}
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
NMDevice *
|
|
|
|
|
nm_device_generic_new (const NMPlatformLink *plink, gboolean nm_plugin_missing)
|
2013-04-26 12:06:15 -04:00
|
|
|
{
|
2016-09-29 13:49:01 +02:00
|
|
|
g_return_val_if_fail (plink != NULL, NULL);
|
2013-04-26 12:06:15 -04:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_GENERIC,
|
|
|
|
|
NM_DEVICE_IFACE, plink->name,
|
|
|
|
|
NM_DEVICE_TYPE_DESC, "Generic",
|
|
|
|
|
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_GENERIC,
|
|
|
|
|
NM_DEVICE_NM_PLUGIN_MISSING, nm_plugin_missing,
|
|
|
|
|
NULL);
|
2013-04-26 12:06:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2016-09-29 13:49:01 +02:00
|
|
|
dispose (GObject *object)
|
2013-04-26 12:06:15 -04:00
|
|
|
{
|
|
|
|
|
NMDeviceGeneric *self = NM_DEVICE_GENERIC (object);
|
|
|
|
|
NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (self);
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
g_clear_pointer (&priv->type_description, g_free);
|
2013-04-26 12:06:15 -04:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
G_OBJECT_CLASS (nm_device_generic_parent_class)->dispose (object);
|
2013-04-26 12:06:15 -04:00
|
|
|
}
|
|
|
|
|
|
2013-04-17 10:41:15 -04:00
|
|
|
static void
|
|
|
|
|
nm_device_generic_class_init (NMDeviceGenericClass *klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
NMDeviceClass *parent_class = NM_DEVICE_CLASS (klass);
|
|
|
|
|
|
2014-10-09 12:42:29 -05:00
|
|
|
NM_DEVICE_CLASS_DECLARE_TYPES (klass, NM_SETTING_GENERIC_SETTING_NAME, NM_LINK_TYPE_ANY)
|
2013-11-06 20:57:45 -06:00
|
|
|
|
2015-06-29 18:06:12 +02:00
|
|
|
object_class->constructor = constructor;
|
2013-04-26 12:06:15 -04:00
|
|
|
object_class->dispose = dispose;
|
|
|
|
|
object_class->get_property = get_property;
|
|
|
|
|
object_class->set_property = set_property;
|
|
|
|
|
|
2016-01-08 17:24:24 +01:00
|
|
|
parent_class->realize_start_notify = realize_start_notify;
|
2013-05-20 15:38:54 -03:00
|
|
|
parent_class->get_generic_capabilities = get_generic_capabilities;
|
2015-05-15 15:00:07 +02:00
|
|
|
parent_class->get_type_description = get_type_description;
|
2013-04-17 10:41:15 -04:00
|
|
|
parent_class->check_connection_compatible = check_connection_compatible;
|
2013-11-06 20:57:45 -06:00
|
|
|
parent_class->update_connection = update_connection;
|
2013-04-17 10:41:15 -04:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
obj_properties[PROP_TYPE_DESCRIPTION] =
|
|
|
|
|
g_param_spec_string (NM_DEVICE_GENERIC_TYPE_DESCRIPTION, "", "",
|
|
|
|
|
NULL,
|
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
|
G_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
|
|
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
|
2013-04-26 12:06:15 -04:00
|
|
|
|
2015-04-13 13:31:42 -04:00
|
|
|
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
|
2015-04-15 14:53:30 -04:00
|
|
|
NMDBUS_TYPE_DEVICE_GENERIC_SKELETON,
|
|
|
|
|
NULL);
|
2013-04-17 10:41:15 -04:00
|
|
|
}
|