2012-02-22 23:59:50 -06: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 2011 - 2012 Red Hat, Inc.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-02-19 14:57:48 +01:00
|
|
|
#include "nm-default.h"
|
2012-02-22 23:59:50 -06:00
|
|
|
|
2016-05-16 19:01:37 +02:00
|
|
|
#include "nm-device-vlan.h"
|
|
|
|
|
|
2012-03-02 08:56:46 +01:00
|
|
|
#include <sys/socket.h>
|
2012-02-22 23:59:50 -06:00
|
|
|
|
2013-07-20 21:48:06 +02:00
|
|
|
#include "nm-manager.h"
|
2012-02-22 23:59:50 -06:00
|
|
|
#include "nm-utils.h"
|
|
|
|
|
#include "NetworkManagerUtils.h"
|
|
|
|
|
#include "nm-device-private.h"
|
2016-11-21 00:43:52 +01:00
|
|
|
#include "settings/nm-settings.h"
|
2016-09-28 19:37:10 +02:00
|
|
|
#include "nm-act-request.h"
|
2014-07-17 17:06:44 -04:00
|
|
|
#include "nm-ip4-config.h"
|
2016-11-21 00:43:52 +01:00
|
|
|
#include "platform/nm-platform.h"
|
2014-09-08 10:24:11 -05:00
|
|
|
#include "nm-device-factory.h"
|
|
|
|
|
#include "nm-manager.h"
|
2014-10-21 22:09:52 -04:00
|
|
|
#include "nm-core-internal.h"
|
2016-11-21 00:43:52 +01:00
|
|
|
#include "platform/nmp-object.h"
|
2012-02-22 23:59:50 -06:00
|
|
|
|
2016-11-23 13:14:08 +01:00
|
|
|
#include "introspection/org.freedesktop.NetworkManager.Device.Vlan.h"
|
2012-02-22 23:59:50 -06:00
|
|
|
|
2014-08-02 15:14:26 +02:00
|
|
|
#include "nm-device-logging.h"
|
|
|
|
|
_LOG_DECLARE_SELF(NMDeviceVlan);
|
2012-02-22 23:59:50 -06:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
/*****************************************************************************/
|
2012-02-22 23:59:50 -06:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
NM_GOBJECT_PROPERTIES_DEFINE (NMDeviceVlan,
|
|
|
|
|
PROP_VLAN_ID,
|
|
|
|
|
);
|
2012-02-22 23:59:50 -06:00
|
|
|
|
|
|
|
|
typedef struct {
|
2016-01-04 10:29:06 +01:00
|
|
|
gulong parent_state_id;
|
|
|
|
|
gulong parent_hwaddr_id;
|
2016-01-10 14:31:10 +01:00
|
|
|
guint vlan_id;
|
2012-02-22 23:59:50 -06:00
|
|
|
} NMDeviceVlanPrivate;
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
struct _NMDeviceVlan {
|
|
|
|
|
NMDevice parent;
|
|
|
|
|
NMDeviceVlanPrivate _priv;
|
|
|
|
|
};
|
2012-02-22 23:59:50 -06:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
struct _NMDeviceVlanClass {
|
|
|
|
|
NMDeviceClass parent;
|
2012-02-22 23:59:50 -06:00
|
|
|
};
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
G_DEFINE_TYPE (NMDeviceVlan, nm_device_vlan, NM_TYPE_DEVICE)
|
|
|
|
|
|
|
|
|
|
#define NM_DEVICE_VLAN_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMDeviceVlan, NM_IS_DEVICE_VLAN)
|
|
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
2012-02-22 23:59:50 -06:00
|
|
|
|
2015-04-29 10:06:51 +02:00
|
|
|
static void
|
|
|
|
|
parent_state_changed (NMDevice *parent,
|
|
|
|
|
NMDeviceState new_state,
|
|
|
|
|
NMDeviceState old_state,
|
|
|
|
|
NMDeviceStateReason reason,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceVlan *self = NM_DEVICE_VLAN (user_data);
|
|
|
|
|
|
|
|
|
|
/* We'll react to our own carrier state notifications. Ignore the parent's. */
|
2017-02-23 15:19:03 +01:00
|
|
|
if (nm_device_state_reason_check (reason) == NM_DEVICE_STATE_REASON_CARRIER)
|
2015-04-29 10:06:51 +02:00
|
|
|
return;
|
|
|
|
|
|
device: remove default-unmanaged and refactor unmanaged flags
Get rid of NM_UNMANAGED_DEFAULT and refine the interaction between
unmanaged flags, device state and managed property.
Previously, the NM_UNMANAGED_DEFAULT was special in that a device was
still considered managed if it had solely the NM_UNMANAGED_DEFAULT flag
set and its state was managed. Thus, whether the device (state) was managed,
depended on the device state too.
Now, a device is considered managed (or unmanaged) based on the unmanaged
flags and realization state alone. At the same time, the device state
directly corresponds to the managed property of the device. Of course,
while changing the unmanaged flags, that invariant is shortly violated
until the state transistion is complete.
Introduce more unmanaged flags whereas some of them are non-authorative.
For example, the EXTERNAL_DOWN flag has only effect as long as the user
didn't explicitly manage the device (NM_UNMANAGED_USER_EXPLICIT). In other
words, certain flags can render other flags ineffective. Whether the device
is considered managed depends on the flags but also at the explicitly unset flags.
In a way, this is similar to previous where NM_UNMANAGED_DEFAULT was ignored
(if no other flags were present).
Also, previously a device that was NM_UNMANAGED_DEFAULT and in disconnected
state would transition back to unmanaged. No longer do that. Once a device is
managed, it stays managed as long as the flags indicate it should be managed.
However, the user can also modify the unmanaged flags via the D-Bus API.
Also get rid or nm_device_finish_init(). That was previously called
by NMManager after add_device(). As we now realize devices (possibly
multiple times) this should be handled during realization.
https://bugzilla.gnome.org/show_bug.cgi?id=746566
2015-09-15 15:35:16 +02:00
|
|
|
nm_device_set_unmanaged_by_flags (NM_DEVICE (self), NM_UNMANAGED_PARENT, !nm_device_get_managed (parent, FALSE), reason);
|
2015-04-29 10:06:51 +02:00
|
|
|
}
|
|
|
|
|
|
2015-10-06 15:21:29 +02:00
|
|
|
static void
|
2016-04-12 10:41:20 +02:00
|
|
|
parent_hwaddr_maybe_changed (NMDevice *parent,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
gpointer user_data)
|
2015-10-06 15:21:29 +02:00
|
|
|
{
|
2017-03-13 15:34:14 +01:00
|
|
|
NMDevice *device = NM_DEVICE (user_data);
|
|
|
|
|
NMDeviceVlan *self = NM_DEVICE_VLAN (device);
|
2015-10-06 15:21:29 +02:00
|
|
|
NMConnection *connection;
|
2016-04-12 10:41:20 +02:00
|
|
|
const char *new_mac, *old_mac;
|
2016-01-11 11:05:11 +01:00
|
|
|
NMSettingIPConfig *s_ip6;
|
2015-10-06 15:21:29 +02:00
|
|
|
|
|
|
|
|
/* Never touch assumed devices */
|
2017-03-13 15:34:14 +01:00
|
|
|
if (nm_device_sys_iface_state_is_external_or_assume (device))
|
2015-10-06 15:21:29 +02:00
|
|
|
return;
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
connection = nm_device_get_applied_connection ((NMDevice *) self);
|
2015-10-06 15:21:29 +02:00
|
|
|
if (!connection)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* Update the VLAN MAC only if configuration does not specify one */
|
2016-09-29 13:49:01 +02:00
|
|
|
if (nm_device_hw_addr_is_explict ((NMDevice *) self))
|
device: extend MAC address handling including randomization for ethernet and wifi
Extend the "ethernet.cloned-mac-address" and "wifi.cloned-mac-address"
settings. Instead of specifying an explicit MAC address, the additional
special values "permanent", "preserve", "random", "random-bia", "stable" and
"stable-bia" are supported.
"permanent" means to use the permanent hardware address. Previously that
was the default if no explict cloned-mac-address was set. The default is
thus still "permanent", but it can be overwritten by global
configuration.
"preserve" means not to configure the MAC address when activating the
device. That was actually the default behavior before introducing MAC
address handling with commit 1b49f941a69af910b0e68530be7339e8053068e5.
"random" and "random-bia" use a randomized MAC address for each
connection. "stable" and "stable-bia" use a generated, stable
address based on some token. The "bia" suffix says to generate a
burned-in address. The stable method by default uses as token the
connection UUID, but the token can be explicitly choosen via
"stable:<TOKEN>" and "stable-bia:<TOKEN>".
On a D-Bus level, the "cloned-mac-address" is a bytestring and thus
cannot express the new forms. It is replaced by the new
"assigned-mac-address" field. For the GObject property, libnm's API,
nmcli, keyfile, etc. the old name "cloned-mac-address" is still used.
Deprecating the old field seems more complicated then just extending
the use of the existing "cloned-mac-address" field, although the name
doesn't match well with the extended meaning.
There is some overlap with the "wifi.mac-address-randomization" setting.
https://bugzilla.gnome.org/show_bug.cgi?id=705545
https://bugzilla.gnome.org/show_bug.cgi?id=708820
https://bugzilla.gnome.org/show_bug.cgi?id=758301
2016-05-24 15:57:16 +02:00
|
|
|
return;
|
2015-10-06 15:21:29 +02:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
old_mac = nm_device_get_hw_address ((NMDevice *) self);
|
2016-04-12 10:41:20 +02:00
|
|
|
new_mac = nm_device_get_hw_address (parent);
|
|
|
|
|
if (nm_streq0 (old_mac, new_mac))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_LOGD (LOGD_VLAN, "parent hardware address changed to %s%s%s",
|
|
|
|
|
NM_PRINT_FMT_QUOTE_STRING (new_mac));
|
|
|
|
|
if (new_mac) {
|
2016-10-25 16:41:42 +02:00
|
|
|
nm_device_hw_addr_set ((NMDevice *) self, new_mac, "vlan-parent", TRUE);
|
2016-04-12 10:41:20 +02:00
|
|
|
/* When changing the hw address the interface is taken down,
|
|
|
|
|
* removing the IPv6 configuration; reapply it.
|
|
|
|
|
*/
|
|
|
|
|
s_ip6 = nm_connection_get_setting_ip6_config (connection);
|
|
|
|
|
if (s_ip6)
|
2017-03-16 14:54:16 +01:00
|
|
|
nm_device_reactivate_ip6_config (NM_DEVICE (self), s_ip6, s_ip6, FALSE);
|
2015-10-06 15:21:29 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-29 10:06:51 +02:00
|
|
|
static void
|
2017-01-02 09:57:43 +01:00
|
|
|
parent_changed_notify (NMDevice *device,
|
|
|
|
|
int old_ifindex,
|
|
|
|
|
NMDevice *old_parent,
|
|
|
|
|
int new_ifindex,
|
|
|
|
|
NMDevice *new_parent)
|
2015-04-29 10:06:51 +02:00
|
|
|
{
|
2017-01-02 09:57:43 +01:00
|
|
|
NMDeviceVlan *self = NM_DEVICE_VLAN (device);
|
2015-04-13 11:43:12 -05:00
|
|
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self);
|
|
|
|
|
|
2017-01-02 09:57:43 +01:00
|
|
|
NM_DEVICE_CLASS (nm_device_vlan_parent_class)->parent_changed_notify (device, old_ifindex, old_parent, new_ifindex, new_parent);
|
2015-04-29 10:06:51 +02:00
|
|
|
|
2017-01-02 09:57:43 +01:00
|
|
|
/* note that @self doesn't have to clear @parent_state_id on dispose,
|
|
|
|
|
* because NMDevice's dispose() will unset the parent, which in turn calls
|
|
|
|
|
* parent_changed_notify(). */
|
|
|
|
|
nm_clear_g_signal_handler (old_parent, &priv->parent_state_id);
|
|
|
|
|
nm_clear_g_signal_handler (old_parent, &priv->parent_hwaddr_id);
|
2015-04-29 10:06:51 +02:00
|
|
|
|
2017-01-02 09:57:43 +01:00
|
|
|
if (new_parent) {
|
|
|
|
|
priv->parent_state_id = g_signal_connect (new_parent,
|
2015-12-07 19:42:59 +01:00
|
|
|
NM_DEVICE_STATE_CHANGED,
|
2015-04-29 10:06:51 +02:00
|
|
|
G_CALLBACK (parent_state_changed),
|
|
|
|
|
device);
|
2015-04-13 11:43:12 -05:00
|
|
|
|
2017-01-02 09:57:43 +01:00
|
|
|
priv->parent_hwaddr_id = g_signal_connect (new_parent, "notify::" NM_DEVICE_HW_ADDRESS,
|
2016-04-12 10:41:20 +02:00
|
|
|
G_CALLBACK (parent_hwaddr_maybe_changed), device);
|
2017-01-02 09:57:43 +01:00
|
|
|
parent_hwaddr_maybe_changed (new_parent, NULL, self);
|
2015-10-06 15:21:29 +02:00
|
|
|
|
2015-04-13 11:43:12 -05:00
|
|
|
/* Set parent-dependent unmanaged flag */
|
2016-01-13 12:03:47 +01:00
|
|
|
nm_device_set_unmanaged_by_flags (device,
|
|
|
|
|
NM_UNMANAGED_PARENT,
|
2017-01-02 09:57:43 +01:00
|
|
|
!nm_device_get_managed (new_parent, FALSE),
|
2016-01-13 12:03:47 +01:00
|
|
|
NM_DEVICE_STATE_REASON_PARENT_MANAGED_CHANGED);
|
2015-04-29 10:06:51 +02:00
|
|
|
}
|
2015-04-13 11:43:12 -05:00
|
|
|
|
|
|
|
|
/* Recheck availability now that the parent has changed */
|
2017-01-02 09:57:43 +01:00
|
|
|
if (new_ifindex > 0) {
|
|
|
|
|
nm_device_queue_recheck_available (device,
|
|
|
|
|
NM_DEVICE_STATE_REASON_PARENT_CHANGED,
|
|
|
|
|
NM_DEVICE_STATE_REASON_PARENT_CHANGED);
|
|
|
|
|
}
|
2015-04-29 10:06:51 +02:00
|
|
|
}
|
|
|
|
|
|
2014-09-05 08:50:02 -05:00
|
|
|
static void
|
2016-01-10 14:31:10 +01:00
|
|
|
update_properties (NMDevice *device)
|
2014-09-05 08:50:02 -05:00
|
|
|
{
|
2016-01-10 14:31:10 +01:00
|
|
|
NMDeviceVlanPrivate *priv;
|
|
|
|
|
const NMPlatformLink *plink = NULL;
|
|
|
|
|
const NMPlatformLnkVlan *plnk = NULL;
|
|
|
|
|
int ifindex;
|
2017-01-02 09:57:43 +01:00
|
|
|
int parent_ifindex = 0;
|
2016-01-10 14:31:10 +01:00
|
|
|
guint vlan_id;
|
2014-09-05 08:50:02 -05:00
|
|
|
|
2016-01-10 14:31:10 +01:00
|
|
|
g_return_if_fail (NM_IS_DEVICE_VLAN (device));
|
2014-09-05 08:50:02 -05:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
priv = NM_DEVICE_VLAN_GET_PRIVATE ((NMDeviceVlan *) device);
|
2014-09-05 08:50:02 -05:00
|
|
|
|
2016-01-10 14:31:10 +01:00
|
|
|
ifindex = nm_device_get_ifindex (device);
|
2014-09-05 08:50:02 -05:00
|
|
|
|
2016-01-10 14:31:10 +01:00
|
|
|
if (ifindex > 0)
|
2017-04-18 12:09:02 +02:00
|
|
|
plnk = nm_platform_link_get_lnk_vlan (nm_device_get_platform (device), ifindex, &plink);
|
2017-01-02 09:57:43 +01:00
|
|
|
|
2016-01-10 14:31:10 +01:00
|
|
|
if ( plnk
|
2017-01-02 09:57:43 +01:00
|
|
|
&& plink->parent > 0)
|
|
|
|
|
parent_ifindex = plink->parent;
|
2014-09-05 08:50:02 -05:00
|
|
|
|
2016-01-10 14:31:10 +01:00
|
|
|
g_object_freeze_notify ((GObject *) device);
|
2014-09-05 08:50:02 -05:00
|
|
|
|
2017-01-02 09:57:43 +01:00
|
|
|
nm_device_parent_set_ifindex (device, parent_ifindex);
|
2016-01-10 14:31:10 +01:00
|
|
|
|
|
|
|
|
vlan_id = plnk ? plnk->id : 0;
|
|
|
|
|
if (vlan_id != priv->vlan_id) {
|
|
|
|
|
priv->vlan_id = vlan_id;
|
2016-09-29 13:49:01 +02:00
|
|
|
_notify ((NMDeviceVlan *) device, PROP_VLAN_ID);
|
2014-09-05 08:50:02 -05:00
|
|
|
}
|
|
|
|
|
|
2016-01-10 14:31:10 +01:00
|
|
|
g_object_thaw_notify ((GObject *) device);
|
|
|
|
|
}
|
2014-09-05 08:50:02 -05:00
|
|
|
|
2016-01-10 14:31:10 +01:00
|
|
|
static void
|
2017-01-02 15:55:23 +01:00
|
|
|
link_changed (NMDevice *device,
|
|
|
|
|
const NMPlatformLink *pllink)
|
2016-01-10 14:31:10 +01:00
|
|
|
{
|
2017-01-02 15:55:23 +01:00
|
|
|
NM_DEVICE_CLASS (nm_device_vlan_parent_class)->link_changed (device, pllink);
|
|
|
|
|
update_properties (device);
|
|
|
|
|
}
|
2014-09-05 08:50:02 -05:00
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
create_and_realize (NMDevice *device,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
NMDevice *parent,
|
2015-12-09 15:13:57 +01:00
|
|
|
const NMPlatformLink **out_plink,
|
2014-09-05 08:50:02 -05:00
|
|
|
GError **error)
|
|
|
|
|
{
|
2016-09-29 13:49:01 +02:00
|
|
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE ((NMDeviceVlan *) device);
|
2014-09-05 08:50:02 -05:00
|
|
|
const char *iface = nm_device_get_iface (device);
|
|
|
|
|
NMSettingVlan *s_vlan;
|
2016-01-10 14:31:10 +01:00
|
|
|
int parent_ifindex;
|
|
|
|
|
guint vlan_id;
|
2014-09-05 08:50:02 -05:00
|
|
|
NMPlatformError plerr;
|
|
|
|
|
|
|
|
|
|
s_vlan = nm_connection_get_setting_vlan (connection);
|
|
|
|
|
g_assert (s_vlan);
|
|
|
|
|
|
device: check for a parent device
The device creation can be attempted if the name can be determined. It
alone is doesn't mean that there's a parent device -- the name could
just have been hardcoded in the connection.
NetworkManager[21519]: nm_device_get_ifindex: assertion 'NM_IS_DEVICE (self)' failed
Program received signal SIGTRAP, Trace/breakpoint trap.
g_logv (log_domain=0x5555557fb2e5 "NetworkManager", log_level=G_LOG_LEVEL_CRITICAL, format=<optimized out>, args=args@entry=0x7fffffffd3d0) at gmessages.c:1046
1046 g_private_set (&g_log_depth, GUINT_TO_POINTER (depth));
(gdb) bt
#0 0x00007ffff4ec88c3 in g_logv (log_domain=0x5555557fb2e5 "NetworkManager", log_level=G_LOG_LEVEL_CRITICAL, format=<optimized out>, args=args@entry=0x7fffffffd3d0) at gmessages.c:1046
#1 0x00007ffff4ec8a3f in g_log (log_domain=<optimized out>, log_level=<optimized out>, format=<optimized out>) at gmessages.c:1079
#2 0x00005555555d2090 in nm_device_get_ifindex (self=0x0) at devices/nm-device.c:562
#3 0x00005555555ef77a in nm_device_supports_vlans (self=0x0) at devices/nm-device.c:9865
#4 0x00005555555bf2f9 in create_and_realize (device=0x555555c549b0 [NMDeviceVlan], connection=0x555555b451e0, parent=0x0, out_plink=0x7fffffffd5f8, error=0x7fffffffd700) at devices/nm-device-vlan.c:225
#5 0x00005555555d5757 in nm_device_create_and_realize (self=0x555555c549b0 [NMDeviceVlan], connection=0x555555b451e0, parent=0x0, error=0x7fffffffd700) at devices/nm-device.c:1783
#6 0x0000555555688601 in system_create_virtual_device (self=0x555555af51c0 [NMManager], connection=0x555555b451e0) at nm-manager.c:1120
#7 0x000055555568894e in connection_changed (settings=0x555555ae8220 [NMSettings], connection=0x555555b451e0, manager=0x555555af51c0 [NMManager]) at nm-manager.c:1172
#8 0x0000555555693448 in nm_manager_start (self=0x555555af51c0 [NMManager], error=0x7fffffffda30) at nm-manager.c:4466
#9 0x00005555555d166f in main (argc=1, argv=0x7fffffffdba8) at main.c:454
(gdb)
Fixes: 332994f1b19ded7cb343ef573443916bab05aaec
2016-04-19 12:02:02 +02:00
|
|
|
if (!parent) {
|
|
|
|
|
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
|
|
|
|
|
"VLAN devices can not be created without a parent interface");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-05 08:50:02 -05:00
|
|
|
if (!nm_device_supports_vlans (parent)) {
|
|
|
|
|
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
|
|
|
|
|
"no support for VLANs on interface %s of type %s",
|
|
|
|
|
nm_device_get_iface (parent),
|
|
|
|
|
nm_device_get_type_desc (parent));
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parent_ifindex = nm_device_get_ifindex (parent);
|
|
|
|
|
g_warn_if_fail (parent_ifindex > 0);
|
|
|
|
|
|
|
|
|
|
vlan_id = nm_setting_vlan_get_id (s_vlan);
|
|
|
|
|
|
2017-04-18 12:09:02 +02:00
|
|
|
plerr = nm_platform_link_vlan_add (nm_device_get_platform (device),
|
2015-12-09 16:14:49 +01:00
|
|
|
iface,
|
|
|
|
|
parent_ifindex,
|
|
|
|
|
vlan_id,
|
|
|
|
|
nm_setting_vlan_get_flags (s_vlan),
|
|
|
|
|
out_plink);
|
2016-01-25 13:03:51 +01:00
|
|
|
if (plerr != NM_PLATFORM_ERROR_SUCCESS) {
|
2014-09-05 08:50:02 -05:00
|
|
|
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
|
|
|
|
|
"Failed to create VLAN interface '%s' for '%s': %s",
|
|
|
|
|
iface,
|
|
|
|
|
nm_connection_get_id (connection),
|
|
|
|
|
nm_platform_error_to_string (plerr));
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-02 09:57:43 +01:00
|
|
|
nm_device_parent_set_ifindex (device, parent_ifindex);
|
2016-01-10 14:31:10 +01:00
|
|
|
if (vlan_id != priv->vlan_id) {
|
|
|
|
|
priv->vlan_id = vlan_id;
|
2016-09-29 13:49:01 +02:00
|
|
|
_notify ((NMDeviceVlan *) device, PROP_VLAN_ID);
|
2016-01-10 14:31:10 +01:00
|
|
|
}
|
2014-09-05 08:50:02 -05:00
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-24 15:13:19 -05:00
|
|
|
static void
|
2016-01-10 15:19:58 +01:00
|
|
|
unrealize_notify (NMDevice *device)
|
2014-09-24 15:13:19 -05:00
|
|
|
{
|
2017-01-02 09:57:43 +01:00
|
|
|
NMDeviceVlan *self = NM_DEVICE_VLAN (device);
|
|
|
|
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self);
|
|
|
|
|
|
2016-01-10 15:19:58 +01:00
|
|
|
NM_DEVICE_CLASS (nm_device_vlan_parent_class)->unrealize_notify (device);
|
2014-09-24 15:13:19 -05:00
|
|
|
|
2017-01-02 09:57:43 +01:00
|
|
|
if (priv->vlan_id != 0) {
|
|
|
|
|
priv->vlan_id = 0;
|
|
|
|
|
_notify (self, PROP_VLAN_ID);
|
|
|
|
|
}
|
2014-09-24 15:13:19 -05:00
|
|
|
}
|
|
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
2014-09-05 08:50:02 -05:00
|
|
|
|
2014-10-06 17:17:54 -05:00
|
|
|
static NMDeviceCapabilities
|
2017-01-02 09:57:43 +01:00
|
|
|
get_generic_capabilities (NMDevice *device)
|
2014-10-06 17:17:54 -05:00
|
|
|
{
|
|
|
|
|
/* We assume VLAN interfaces always support carrier detect */
|
|
|
|
|
return NM_DEVICE_CAP_CARRIER_DETECT | NM_DEVICE_CAP_IS_SOFTWARE;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
2014-10-06 17:17:54 -05:00
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
is_available (NMDevice *device, NMDeviceCheckDevAvailableFlags flags)
|
|
|
|
|
{
|
2017-01-02 09:57:43 +01:00
|
|
|
if (!nm_device_parent_get_device (device))
|
2014-10-06 17:17:54 -05:00
|
|
|
return FALSE;
|
|
|
|
|
return NM_DEVICE_CLASS (nm_device_vlan_parent_class)->is_available (device, flags);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
2015-04-29 10:06:51 +02:00
|
|
|
|
2012-02-22 23:59:50 -06:00
|
|
|
static gboolean
|
2014-05-30 13:44:53 -05:00
|
|
|
match_parent (NMDeviceVlan *self, const char *parent)
|
2012-02-22 23:59:50 -06:00
|
|
|
{
|
2017-01-02 09:57:43 +01:00
|
|
|
NMDevice *parent_device;
|
2012-02-22 23:59:50 -06:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (parent != NULL, FALSE);
|
|
|
|
|
|
2017-01-02 09:57:43 +01:00
|
|
|
parent_device = nm_device_parent_get_device (NM_DEVICE (self));
|
|
|
|
|
if (!parent_device)
|
2015-04-13 11:43:12 -05:00
|
|
|
return FALSE;
|
|
|
|
|
|
2012-02-22 23:59:50 -06:00
|
|
|
if (nm_utils_is_uuid (parent)) {
|
|
|
|
|
NMActRequest *parent_req;
|
|
|
|
|
NMConnection *parent_connection;
|
|
|
|
|
|
|
|
|
|
/* If the parent is a UUID, the connection matches if our parent
|
|
|
|
|
* device has that connection activated.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-01-02 09:57:43 +01:00
|
|
|
parent_req = nm_device_get_act_request (parent_device);
|
2014-05-30 13:44:53 -05:00
|
|
|
if (!parent_req)
|
2012-02-22 23:59:50 -06:00
|
|
|
return FALSE;
|
|
|
|
|
|
2015-07-14 16:53:24 +02:00
|
|
|
parent_connection = nm_active_connection_get_applied_connection (NM_ACTIVE_CONNECTION (parent_req));
|
2014-05-30 13:44:53 -05:00
|
|
|
if (!parent_connection)
|
2012-02-22 23:59:50 -06:00
|
|
|
return FALSE;
|
2014-05-30 13:44:53 -05:00
|
|
|
|
|
|
|
|
if (g_strcmp0 (parent, nm_connection_get_uuid (parent_connection)) != 0)
|
2012-02-22 23:59:50 -06:00
|
|
|
return FALSE;
|
|
|
|
|
} else {
|
|
|
|
|
/* interface name */
|
2017-01-02 09:57:43 +01:00
|
|
|
if (g_strcmp0 (parent, nm_device_get_ip_iface (parent_device)) != 0)
|
2012-02-22 23:59:50 -06:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
all: standardize on NMSettingWired:mac-address for all VLANs
Currently, ethernet-based VLANs can specify the hardware address of
the parent device (and, in theory, the cloned hardware address and MTU
of the VLAN device) by using an NMSettingWired in addition to the
NMSettingVlan.
The theory was that non-ethernet-based VLANs, when we eventually
supported them, would likewise use the setting type corresponding to
their parent device. However, this turns out to be both complicated
(the settings plugins and connection editor would have a
hard-to-impossible time figuring out which setting type to use in some
cases) and incorrect (for most L2 settings [eg, BSSID, bond mode,
etc], the VLAN can't have its own values separate from the parent
device).
What we should have done was just have :mac-address,
:cloned-mac-address, and :mtu properties on NMSettingVlan. However, at
this point, for backward-compatibility, we will just stick with using
a combination of NMSettingVlan and NMSettingWired, but we will use
NMSettingWired regardless of the underlying hardware type.
2013-09-09 09:40:40 -04:00
|
|
|
static gboolean
|
|
|
|
|
match_hwaddr (NMDevice *device, NMConnection *connection, gboolean fail_if_no_hwaddr)
|
|
|
|
|
{
|
2016-06-15 13:43:34 +02:00
|
|
|
NMSettingWired *s_wired;
|
2017-01-02 09:57:43 +01:00
|
|
|
NMDevice *parent_device;
|
2016-06-15 13:43:34 +02:00
|
|
|
const char *setting_mac;
|
|
|
|
|
const char *parent_mac;
|
all: standardize on NMSettingWired:mac-address for all VLANs
Currently, ethernet-based VLANs can specify the hardware address of
the parent device (and, in theory, the cloned hardware address and MTU
of the VLAN device) by using an NMSettingWired in addition to the
NMSettingVlan.
The theory was that non-ethernet-based VLANs, when we eventually
supported them, would likewise use the setting type corresponding to
their parent device. However, this turns out to be both complicated
(the settings plugins and connection editor would have a
hard-to-impossible time figuring out which setting type to use in some
cases) and incorrect (for most L2 settings [eg, BSSID, bond mode,
etc], the VLAN can't have its own values separate from the parent
device).
What we should have done was just have :mac-address,
:cloned-mac-address, and :mtu properties on NMSettingVlan. However, at
this point, for backward-compatibility, we will just stick with using
a combination of NMSettingVlan and NMSettingWired, but we will use
NMSettingWired regardless of the underlying hardware type.
2013-09-09 09:40:40 -04:00
|
|
|
|
2016-06-15 13:43:34 +02:00
|
|
|
s_wired = nm_connection_get_setting_wired (connection);
|
|
|
|
|
if (!s_wired)
|
|
|
|
|
return !fail_if_no_hwaddr;
|
all: standardize on NMSettingWired:mac-address for all VLANs
Currently, ethernet-based VLANs can specify the hardware address of
the parent device (and, in theory, the cloned hardware address and MTU
of the VLAN device) by using an NMSettingWired in addition to the
NMSettingVlan.
The theory was that non-ethernet-based VLANs, when we eventually
supported them, would likewise use the setting type corresponding to
their parent device. However, this turns out to be both complicated
(the settings plugins and connection editor would have a
hard-to-impossible time figuring out which setting type to use in some
cases) and incorrect (for most L2 settings [eg, BSSID, bond mode,
etc], the VLAN can't have its own values separate from the parent
device).
What we should have done was just have :mac-address,
:cloned-mac-address, and :mtu properties on NMSettingVlan. However, at
this point, for backward-compatibility, we will just stick with using
a combination of NMSettingVlan and NMSettingWired, but we will use
NMSettingWired regardless of the underlying hardware type.
2013-09-09 09:40:40 -04:00
|
|
|
|
2016-06-15 13:43:34 +02:00
|
|
|
setting_mac = nm_setting_wired_get_mac_address (s_wired);
|
|
|
|
|
if (!setting_mac)
|
|
|
|
|
return !fail_if_no_hwaddr;
|
all: standardize on NMSettingWired:mac-address for all VLANs
Currently, ethernet-based VLANs can specify the hardware address of
the parent device (and, in theory, the cloned hardware address and MTU
of the VLAN device) by using an NMSettingWired in addition to the
NMSettingVlan.
The theory was that non-ethernet-based VLANs, when we eventually
supported them, would likewise use the setting type corresponding to
their parent device. However, this turns out to be both complicated
(the settings plugins and connection editor would have a
hard-to-impossible time figuring out which setting type to use in some
cases) and incorrect (for most L2 settings [eg, BSSID, bond mode,
etc], the VLAN can't have its own values separate from the parent
device).
What we should have done was just have :mac-address,
:cloned-mac-address, and :mtu properties on NMSettingVlan. However, at
this point, for backward-compatibility, we will just stick with using
a combination of NMSettingVlan and NMSettingWired, but we will use
NMSettingWired regardless of the underlying hardware type.
2013-09-09 09:40:40 -04:00
|
|
|
|
2017-01-02 09:57:43 +01:00
|
|
|
parent_device = nm_device_parent_get_device (device);
|
|
|
|
|
if (!parent_device)
|
2016-06-15 13:43:34 +02:00
|
|
|
return !fail_if_no_hwaddr;
|
all: standardize on NMSettingWired:mac-address for all VLANs
Currently, ethernet-based VLANs can specify the hardware address of
the parent device (and, in theory, the cloned hardware address and MTU
of the VLAN device) by using an NMSettingWired in addition to the
NMSettingVlan.
The theory was that non-ethernet-based VLANs, when we eventually
supported them, would likewise use the setting type corresponding to
their parent device. However, this turns out to be both complicated
(the settings plugins and connection editor would have a
hard-to-impossible time figuring out which setting type to use in some
cases) and incorrect (for most L2 settings [eg, BSSID, bond mode,
etc], the VLAN can't have its own values separate from the parent
device).
What we should have done was just have :mac-address,
:cloned-mac-address, and :mtu properties on NMSettingVlan. However, at
this point, for backward-compatibility, we will just stick with using
a combination of NMSettingVlan and NMSettingWired, but we will use
NMSettingWired regardless of the underlying hardware type.
2013-09-09 09:40:40 -04:00
|
|
|
|
2017-01-02 09:57:43 +01:00
|
|
|
parent_mac = nm_device_get_permanent_hw_address (parent_device);
|
2016-06-15 13:43:34 +02:00
|
|
|
return parent_mac && nm_utils_hwaddr_matches (setting_mac, -1, parent_mac, -1);
|
all: standardize on NMSettingWired:mac-address for all VLANs
Currently, ethernet-based VLANs can specify the hardware address of
the parent device (and, in theory, the cloned hardware address and MTU
of the VLAN device) by using an NMSettingWired in addition to the
NMSettingVlan.
The theory was that non-ethernet-based VLANs, when we eventually
supported them, would likewise use the setting type corresponding to
their parent device. However, this turns out to be both complicated
(the settings plugins and connection editor would have a
hard-to-impossible time figuring out which setting type to use in some
cases) and incorrect (for most L2 settings [eg, BSSID, bond mode,
etc], the VLAN can't have its own values separate from the parent
device).
What we should have done was just have :mac-address,
:cloned-mac-address, and :mtu properties on NMSettingVlan. However, at
this point, for backward-compatibility, we will just stick with using
a combination of NMSettingVlan and NMSettingWired, but we will use
NMSettingWired regardless of the underlying hardware type.
2013-09-09 09:40:40 -04:00
|
|
|
}
|
|
|
|
|
|
2012-02-22 23:59:50 -06:00
|
|
|
static gboolean
|
2014-05-30 13:44:53 -05:00
|
|
|
check_connection_compatible (NMDevice *device, NMConnection *connection)
|
2012-02-22 23:59:50 -06:00
|
|
|
{
|
2016-09-29 13:49:01 +02:00
|
|
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE ((NMDeviceVlan *) device);
|
2012-02-22 23:59:50 -06:00
|
|
|
NMSettingVlan *s_vlan;
|
2016-02-16 16:50:00 +01:00
|
|
|
const char *parent = NULL;
|
2012-02-22 23:59:50 -06:00
|
|
|
|
2014-05-30 13:44:53 -05:00
|
|
|
if (!NM_DEVICE_CLASS (nm_device_vlan_parent_class)->check_connection_compatible (device, connection))
|
2013-03-07 07:44:36 -05:00
|
|
|
return FALSE;
|
|
|
|
|
|
2012-02-22 23:59:50 -06:00
|
|
|
s_vlan = nm_connection_get_setting_vlan (connection);
|
2014-05-30 13:44:53 -05:00
|
|
|
if (!s_vlan)
|
2012-02-22 23:59:50 -06:00
|
|
|
return FALSE;
|
|
|
|
|
|
2014-09-24 16:58:07 -05:00
|
|
|
/* Before the device is realized some properties will not be set */
|
|
|
|
|
if (nm_device_is_real (device)) {
|
|
|
|
|
if (nm_setting_vlan_get_id (s_vlan) != priv->vlan_id)
|
2012-02-22 23:59:50 -06:00
|
|
|
return FALSE;
|
2014-09-24 16:58:07 -05:00
|
|
|
|
|
|
|
|
/* Check parent interface; could be an interface name or a UUID */
|
|
|
|
|
parent = nm_setting_vlan_get_parent (s_vlan);
|
|
|
|
|
if (parent) {
|
|
|
|
|
if (!match_parent (NM_DEVICE_VLAN (device), parent))
|
|
|
|
|
return FALSE;
|
|
|
|
|
} else {
|
|
|
|
|
/* Parent could be a MAC address in an NMSettingWired */
|
|
|
|
|
if (!match_hwaddr (device, connection, TRUE))
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2012-02-22 23:59:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-04 11:57:22 +01:00
|
|
|
static gboolean
|
|
|
|
|
check_connection_available (NMDevice *device,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
NMDeviceCheckConAvailableFlags flags,
|
|
|
|
|
const char *specific_object)
|
|
|
|
|
{
|
|
|
|
|
if (!nm_device_is_real (device))
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
return NM_DEVICE_CLASS (nm_device_vlan_parent_class)->check_connection_available (device, connection, flags, specific_object);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-22 23:59:50 -06:00
|
|
|
static gboolean
|
2012-09-27 12:12:15 -04:00
|
|
|
complete_connection (NMDevice *device,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
const char *specific_object,
|
|
|
|
|
const GSList *existing_connections,
|
|
|
|
|
GError **error)
|
2012-02-22 23:59:50 -06:00
|
|
|
{
|
|
|
|
|
NMSettingVlan *s_vlan;
|
|
|
|
|
|
2017-04-18 12:09:02 +02:00
|
|
|
nm_utils_complete_generic (nm_device_get_platform (device),
|
2016-03-08 13:57:20 +01:00
|
|
|
connection,
|
2012-02-22 23:59:50 -06:00
|
|
|
NM_SETTING_VLAN_SETTING_NAME,
|
|
|
|
|
existing_connections,
|
|
|
|
|
NULL,
|
2014-08-25 16:21:59 +02:00
|
|
|
_("VLAN connection"),
|
2014-08-05 17:11:57 -04:00
|
|
|
NULL,
|
2012-02-22 23:59:50 -06:00
|
|
|
TRUE);
|
|
|
|
|
|
|
|
|
|
s_vlan = nm_connection_get_setting_vlan (connection);
|
|
|
|
|
if (!s_vlan) {
|
2014-09-22 12:28:06 -04:00
|
|
|
g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION,
|
2012-02-22 23:59:50 -06:00
|
|
|
"A 'vlan' setting is required.");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If there's no VLAN interface, no parent, and no hardware address in the
|
|
|
|
|
* settings, then there's not enough information to complete the setting.
|
|
|
|
|
*/
|
all: standardize on NMSettingWired:mac-address for all VLANs
Currently, ethernet-based VLANs can specify the hardware address of
the parent device (and, in theory, the cloned hardware address and MTU
of the VLAN device) by using an NMSettingWired in addition to the
NMSettingVlan.
The theory was that non-ethernet-based VLANs, when we eventually
supported them, would likewise use the setting type corresponding to
their parent device. However, this turns out to be both complicated
(the settings plugins and connection editor would have a
hard-to-impossible time figuring out which setting type to use in some
cases) and incorrect (for most L2 settings [eg, BSSID, bond mode,
etc], the VLAN can't have its own values separate from the parent
device).
What we should have done was just have :mac-address,
:cloned-mac-address, and :mtu properties on NMSettingVlan. However, at
this point, for backward-compatibility, we will just stick with using
a combination of NMSettingVlan and NMSettingWired, but we will use
NMSettingWired regardless of the underlying hardware type.
2013-09-09 09:40:40 -04:00
|
|
|
if ( !nm_setting_vlan_get_parent (s_vlan)
|
|
|
|
|
&& !match_hwaddr (device, connection, TRUE)) {
|
2014-09-22 12:28:06 -04:00
|
|
|
g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION,
|
all: standardize on NMSettingWired:mac-address for all VLANs
Currently, ethernet-based VLANs can specify the hardware address of
the parent device (and, in theory, the cloned hardware address and MTU
of the VLAN device) by using an NMSettingWired in addition to the
NMSettingVlan.
The theory was that non-ethernet-based VLANs, when we eventually
supported them, would likewise use the setting type corresponding to
their parent device. However, this turns out to be both complicated
(the settings plugins and connection editor would have a
hard-to-impossible time figuring out which setting type to use in some
cases) and incorrect (for most L2 settings [eg, BSSID, bond mode,
etc], the VLAN can't have its own values separate from the parent
device).
What we should have done was just have :mac-address,
:cloned-mac-address, and :mtu properties on NMSettingVlan. However, at
this point, for backward-compatibility, we will just stick with using
a combination of NMSettingVlan and NMSettingWired, but we will use
NMSettingWired regardless of the underlying hardware type.
2013-09-09 09:40:40 -04:00
|
|
|
"The 'vlan' setting had no interface name, parent, or hardware address.");
|
|
|
|
|
return FALSE;
|
2012-02-22 23:59:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-20 21:48:06 +02:00
|
|
|
static void
|
|
|
|
|
update_connection (NMDevice *device, NMConnection *connection)
|
|
|
|
|
{
|
2016-09-29 13:49:01 +02:00
|
|
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE ((NMDeviceVlan *) device);
|
2013-07-20 21:48:06 +02:00
|
|
|
NMSettingVlan *s_vlan = nm_connection_get_setting_vlan (connection);
|
|
|
|
|
int ifindex = nm_device_get_ifindex (device);
|
|
|
|
|
const char *setting_parent, *new_parent;
|
2015-10-12 13:44:44 +02:00
|
|
|
const NMPlatformLink *plink;
|
2015-10-30 11:02:44 +01:00
|
|
|
const NMPObject *polnk;
|
2017-01-02 09:57:43 +01:00
|
|
|
NMDevice *parent_device;
|
2016-01-10 14:31:10 +01:00
|
|
|
guint vlan_id;
|
|
|
|
|
guint vlan_flags;
|
2012-02-22 23:59:50 -06:00
|
|
|
|
2013-07-20 21:48:06 +02:00
|
|
|
if (!s_vlan) {
|
|
|
|
|
s_vlan = (NMSettingVlan *) nm_setting_vlan_new ();
|
|
|
|
|
nm_connection_add_setting (connection, (NMSetting *) s_vlan);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-18 12:09:02 +02:00
|
|
|
polnk = nm_platform_link_get_lnk (nm_device_get_platform (device), ifindex, NM_LINK_TYPE_VLAN, &plink);
|
2013-11-13 18:24:42 +01:00
|
|
|
|
2016-01-10 14:31:10 +01:00
|
|
|
if (polnk)
|
|
|
|
|
vlan_id = polnk->lnk_vlan.id;
|
2015-08-17 17:48:37 +02:00
|
|
|
else
|
2016-01-10 14:31:10 +01:00
|
|
|
vlan_id = priv->vlan_id;
|
|
|
|
|
if (vlan_id != nm_setting_vlan_get_id (s_vlan))
|
|
|
|
|
g_object_set (s_vlan, NM_SETTING_VLAN_ID, vlan_id, NULL);
|
2013-07-20 21:48:06 +02:00
|
|
|
|
|
|
|
|
/* Update parent in the connection; default to parent's interface name */
|
2017-01-02 09:57:43 +01:00
|
|
|
parent_device = nm_device_parent_get_device (device);
|
|
|
|
|
if ( parent_device
|
2016-01-10 14:31:10 +01:00
|
|
|
&& polnk
|
|
|
|
|
&& plink->parent > 0
|
2017-01-02 09:57:43 +01:00
|
|
|
&& nm_device_get_ifindex (parent_device) == plink->parent) {
|
|
|
|
|
new_parent = nm_device_get_iface (parent_device);
|
2015-08-17 17:48:37 +02:00
|
|
|
setting_parent = nm_setting_vlan_get_parent (s_vlan);
|
|
|
|
|
if (setting_parent && nm_utils_is_uuid (setting_parent)) {
|
|
|
|
|
NMConnection *parent_connection;
|
|
|
|
|
|
|
|
|
|
/* Don't change a parent specified by UUID if it's still valid */
|
2016-05-16 19:01:37 +02:00
|
|
|
parent_connection = (NMConnection *) nm_settings_get_connection_by_uuid (nm_device_get_settings (device), setting_parent);
|
2017-01-02 09:57:43 +01:00
|
|
|
if (parent_connection && nm_device_check_connection_compatible (parent_device, parent_connection))
|
2015-08-17 17:48:37 +02:00
|
|
|
new_parent = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (new_parent)
|
|
|
|
|
g_object_set (s_vlan, NM_SETTING_VLAN_PARENT, new_parent, NULL);
|
|
|
|
|
} else
|
|
|
|
|
g_object_set (s_vlan, NM_SETTING_VLAN_PARENT, NULL, NULL);
|
2015-10-30 11:02:44 +01:00
|
|
|
|
2016-01-10 14:31:10 +01:00
|
|
|
if (polnk)
|
|
|
|
|
vlan_flags = polnk->lnk_vlan.flags;
|
|
|
|
|
else
|
|
|
|
|
vlan_flags = NM_VLAN_FLAG_REORDER_HEADERS;
|
|
|
|
|
if (vlan_flags != nm_setting_vlan_get_flags (s_vlan))
|
|
|
|
|
g_object_set (s_vlan, NM_SETTING_VLAN_FLAGS, (NMVlanFlags) vlan_flags, NULL);
|
|
|
|
|
|
|
|
|
|
if (polnk) {
|
|
|
|
|
_nm_setting_vlan_set_priorities (s_vlan, NM_VLAN_INGRESS_MAP,
|
|
|
|
|
polnk->_lnk_vlan.ingress_qos_map,
|
|
|
|
|
polnk->_lnk_vlan.n_ingress_qos_map);
|
|
|
|
|
_nm_setting_vlan_set_priorities (s_vlan, NM_VLAN_EGRESS_MAP,
|
|
|
|
|
polnk->_lnk_vlan.egress_qos_map,
|
|
|
|
|
polnk->_lnk_vlan.n_egress_qos_map);
|
|
|
|
|
} else {
|
|
|
|
|
_nm_setting_vlan_set_priorities (s_vlan, NM_VLAN_INGRESS_MAP, NULL, 0);
|
|
|
|
|
_nm_setting_vlan_set_priorities (s_vlan, NM_VLAN_EGRESS_MAP, NULL, 0);
|
|
|
|
|
}
|
2012-02-22 23:59:50 -06:00
|
|
|
}
|
|
|
|
|
|
2013-09-03 14:03:52 -04:00
|
|
|
static NMActStageReturn
|
2017-02-22 17:04:00 +01:00
|
|
|
act_stage1_prepare (NMDevice *device, NMDeviceStateReason *out_failure_reason)
|
2013-09-03 14:03:52 -04:00
|
|
|
{
|
2017-01-02 09:57:43 +01:00
|
|
|
NMDevice *parent_device;
|
2013-09-03 14:03:52 -04:00
|
|
|
NMSettingVlan *s_vlan;
|
|
|
|
|
NMActStageReturn ret;
|
|
|
|
|
|
2017-02-22 17:04:00 +01:00
|
|
|
ret = NM_DEVICE_CLASS (nm_device_vlan_parent_class)->act_stage1_prepare (device, out_failure_reason);
|
2013-09-03 14:03:52 -04:00
|
|
|
if (ret != NM_ACT_STAGE_RETURN_SUCCESS)
|
|
|
|
|
return ret;
|
|
|
|
|
|
2017-01-02 09:57:43 +01:00
|
|
|
if (!nm_device_hw_addr_set_cloned (device, nm_device_get_applied_connection (device), FALSE))
|
2016-06-18 19:14:33 +02:00
|
|
|
return NM_ACT_STAGE_RETURN_FAILURE;
|
2013-09-08 13:39:03 -04:00
|
|
|
|
2016-04-12 10:41:20 +02:00
|
|
|
/* Change MAC address to parent's one if needed */
|
2017-01-02 09:57:43 +01:00
|
|
|
parent_device = nm_device_parent_get_device (device);
|
|
|
|
|
if (parent_device)
|
|
|
|
|
parent_hwaddr_maybe_changed (parent_device, NULL, device);
|
2016-04-12 10:41:20 +02:00
|
|
|
|
2017-01-02 09:57:43 +01:00
|
|
|
s_vlan = (NMSettingVlan *) nm_device_get_applied_setting (device, NM_TYPE_SETTING_VLAN);
|
2013-09-03 14:03:52 -04:00
|
|
|
if (s_vlan) {
|
2015-10-30 11:02:44 +01:00
|
|
|
gs_free NMVlanQosMapping *ingress_map = NULL;
|
|
|
|
|
gs_free NMVlanQosMapping *egress_map = NULL;
|
|
|
|
|
guint n_ingress_map = 0, n_egress_map = 0;
|
|
|
|
|
|
|
|
|
|
_nm_setting_vlan_get_priorities (s_vlan,
|
|
|
|
|
NM_VLAN_INGRESS_MAP,
|
|
|
|
|
&ingress_map,
|
|
|
|
|
&n_ingress_map);
|
|
|
|
|
_nm_setting_vlan_get_priorities (s_vlan,
|
|
|
|
|
NM_VLAN_EGRESS_MAP,
|
|
|
|
|
&egress_map,
|
|
|
|
|
&n_egress_map);
|
|
|
|
|
|
2017-04-18 12:09:02 +02:00
|
|
|
nm_platform_link_vlan_change (nm_device_get_platform (device),
|
2017-01-02 09:57:43 +01:00
|
|
|
nm_device_get_ifindex (device),
|
2015-10-30 11:02:44 +01:00
|
|
|
NM_VLAN_FLAGS_ALL,
|
|
|
|
|
nm_setting_vlan_get_flags (s_vlan),
|
|
|
|
|
TRUE,
|
|
|
|
|
ingress_map,
|
|
|
|
|
n_ingress_map,
|
|
|
|
|
TRUE,
|
|
|
|
|
egress_map,
|
|
|
|
|
n_egress_map);
|
2013-09-03 14:03:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-18 11:25:38 +01:00
|
|
|
static guint32
|
|
|
|
|
get_configured_mtu (NMDevice *self, gboolean *out_is_user_config)
|
|
|
|
|
{
|
|
|
|
|
guint32 mtu = 0;
|
|
|
|
|
int ifindex;
|
|
|
|
|
|
|
|
|
|
mtu = nm_device_get_configured_mtu_for_wired (self, out_is_user_config);
|
|
|
|
|
if (*out_is_user_config)
|
|
|
|
|
return mtu;
|
|
|
|
|
|
|
|
|
|
/* Inherit the MTU from parent device, if any */
|
|
|
|
|
ifindex = nm_device_parent_get_ifindex (self);
|
|
|
|
|
if (ifindex > 0)
|
2017-04-18 12:09:02 +02:00
|
|
|
mtu = nm_platform_link_get_mtu (nm_device_get_platform (NM_DEVICE (self)), ifindex);
|
2017-01-18 11:25:38 +01:00
|
|
|
|
|
|
|
|
return mtu ?: NM_DEVICE_DEFAULT_MTU_WIRED;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
2012-02-22 23:59:50 -06:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
get_property (GObject *object, guint prop_id,
|
|
|
|
|
GValue *value, GParamSpec *pspec)
|
|
|
|
|
{
|
2016-09-29 13:49:01 +02:00
|
|
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE ((NMDeviceVlan *) object);
|
2012-02-22 23:59:50 -06:00
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_VLAN_ID:
|
|
|
|
|
g_value_set_uint (value, priv->vlan_id);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2012-02-22 23:59:50 -06:00
|
|
|
static void
|
2016-09-29 13:49:01 +02:00
|
|
|
nm_device_vlan_init (NMDeviceVlan * self)
|
2012-02-22 23:59:50 -06:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
nm_device_vlan_class_init (NMDeviceVlanClass *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_VLAN_SETTING_NAME, NM_LINK_TYPE_VLAN)
|
2013-07-20 21:48:06 +02:00
|
|
|
|
2012-02-22 23:59:50 -06:00
|
|
|
object_class->get_property = get_property;
|
|
|
|
|
|
2014-09-05 08:50:02 -05:00
|
|
|
parent_class->create_and_realize = create_and_realize;
|
2017-01-02 15:55:23 +01:00
|
|
|
parent_class->link_changed = link_changed;
|
2016-01-10 15:18:31 +01:00
|
|
|
parent_class->unrealize_notify = unrealize_notify;
|
2012-09-27 12:12:15 -04:00
|
|
|
parent_class->get_generic_capabilities = get_generic_capabilities;
|
2013-09-03 14:03:52 -04:00
|
|
|
parent_class->act_stage1_prepare = act_stage1_prepare;
|
2017-01-18 11:25:38 +01:00
|
|
|
parent_class->get_configured_mtu = get_configured_mtu;
|
2015-04-13 11:43:12 -05:00
|
|
|
parent_class->is_available = is_available;
|
2017-01-02 09:57:43 +01:00
|
|
|
parent_class->parent_changed_notify = parent_changed_notify;
|
2012-09-27 12:12:15 -04:00
|
|
|
|
|
|
|
|
parent_class->check_connection_compatible = check_connection_compatible;
|
2016-01-04 11:57:22 +01:00
|
|
|
parent_class->check_connection_available = check_connection_available;
|
2012-09-27 12:12:15 -04:00
|
|
|
parent_class->complete_connection = complete_connection;
|
2013-07-20 21:48:06 +02:00
|
|
|
parent_class->update_connection = update_connection;
|
2012-02-22 23:59:50 -06:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
obj_properties[PROP_VLAN_ID] =
|
|
|
|
|
g_param_spec_uint (NM_DEVICE_VLAN_ID, "", "",
|
|
|
|
|
0, 4095, 0,
|
|
|
|
|
G_PARAM_READABLE
|
|
|
|
|
| G_PARAM_STATIC_STRINGS);
|
|
|
|
|
|
|
|
|
|
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
|
2014-07-21 12:15:54 +02: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_VLAN_SKELETON,
|
|
|
|
|
NULL);
|
2012-02-22 23:59:50 -06:00
|
|
|
}
|
2014-09-08 10:24:11 -05:00
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
2014-09-08 10:24:11 -05:00
|
|
|
|
2016-10-07 17:00:59 +02:00
|
|
|
#define NM_TYPE_VLAN_DEVICE_FACTORY (nm_vlan_device_factory_get_type ())
|
|
|
|
|
#define NM_VLAN_DEVICE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VLAN_DEVICE_FACTORY, NMVlanDeviceFactory))
|
2014-09-08 10:24:11 -05:00
|
|
|
|
|
|
|
|
static NMDevice *
|
2014-09-05 08:50:02 -05:00
|
|
|
create_device (NMDeviceFactory *factory,
|
|
|
|
|
const char *iface,
|
2016-01-10 15:13:20 +01:00
|
|
|
const NMPlatformLink *plink,
|
2014-09-05 08:50:02 -05:00
|
|
|
NMConnection *connection,
|
|
|
|
|
gboolean *out_ignore)
|
2014-09-08 10:24:11 -05:00
|
|
|
{
|
2014-09-05 08:50:02 -05:00
|
|
|
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_VLAN,
|
|
|
|
|
NM_DEVICE_IFACE, iface,
|
|
|
|
|
NM_DEVICE_DRIVER, "8021q",
|
|
|
|
|
NM_DEVICE_TYPE_DESC, "VLAN",
|
|
|
|
|
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_VLAN,
|
2015-12-08 14:51:12 +01:00
|
|
|
NM_DEVICE_LINK_TYPE, NM_LINK_TYPE_VLAN,
|
2014-09-05 08:50:02 -05:00
|
|
|
NULL);
|
2014-09-08 10:24:11 -05:00
|
|
|
}
|
|
|
|
|
|
2014-09-18 17:50:47 -05:00
|
|
|
static const char *
|
|
|
|
|
get_connection_parent (NMDeviceFactory *factory, NMConnection *connection)
|
|
|
|
|
{
|
|
|
|
|
NMSettingVlan *s_vlan;
|
|
|
|
|
NMSettingWired *s_wired;
|
|
|
|
|
const char *parent = NULL;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME), NULL);
|
|
|
|
|
|
|
|
|
|
s_vlan = nm_connection_get_setting_vlan (connection);
|
|
|
|
|
g_assert (s_vlan);
|
|
|
|
|
|
|
|
|
|
parent = nm_setting_vlan_get_parent (s_vlan);
|
|
|
|
|
if (parent)
|
|
|
|
|
return parent;
|
|
|
|
|
|
|
|
|
|
/* Try the hardware address from the VLAN connection's hardware setting */
|
|
|
|
|
s_wired = nm_connection_get_setting_wired (connection);
|
|
|
|
|
if (s_wired)
|
|
|
|
|
return nm_setting_wired_get_mac_address (s_wired);
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char *
|
2016-02-17 15:11:02 +01:00
|
|
|
get_connection_iface (NMDeviceFactory *factory,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
const char *parent_iface)
|
2014-09-18 17:50:47 -05:00
|
|
|
{
|
|
|
|
|
const char *ifname;
|
|
|
|
|
NMSettingVlan *s_vlan;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME), NULL);
|
|
|
|
|
|
|
|
|
|
s_vlan = nm_connection_get_setting_vlan (connection);
|
|
|
|
|
g_assert (s_vlan);
|
|
|
|
|
|
|
|
|
|
if (!parent_iface)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
ifname = nm_connection_get_interface_name (connection);
|
|
|
|
|
if (ifname)
|
|
|
|
|
return g_strdup (ifname);
|
|
|
|
|
|
|
|
|
|
/* If the connection doesn't specify the interface name for the VLAN
|
|
|
|
|
* device, we create one for it using the VLAN ID and the parent
|
|
|
|
|
* interface's name.
|
|
|
|
|
*/
|
|
|
|
|
return nm_utils_new_vlan_name (parent_iface, nm_setting_vlan_get_id (s_vlan));
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-17 14:17:30 -05:00
|
|
|
NM_DEVICE_FACTORY_DEFINE_INTERNAL (VLAN, Vlan, vlan,
|
|
|
|
|
NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_VLAN)
|
|
|
|
|
NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_VLAN_SETTING_NAME),
|
2016-10-07 16:05:43 +02:00
|
|
|
factory_class->create_device = create_device;
|
|
|
|
|
factory_class->get_connection_parent = get_connection_parent;
|
|
|
|
|
factory_class->get_connection_iface = get_connection_iface;
|
2016-09-29 13:49:01 +02:00
|
|
|
);
|