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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
2012-03-02 08:56:46 +01:00
|
|
|
#include <sys/socket.h>
|
2012-02-22 23:59:50 -06:00
|
|
|
|
2015-07-17 14:38:54 +02:00
|
|
|
#include "nm-default.h"
|
2012-02-22 23:59:50 -06:00
|
|
|
#include "nm-device-vlan.h"
|
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"
|
|
|
|
|
#include "nm-enum-types.h"
|
2014-07-17 17:06:44 -04:00
|
|
|
#include "nm-connection-provider.h"
|
|
|
|
|
#include "nm-activation-request.h"
|
|
|
|
|
#include "nm-ip4-config.h"
|
2013-01-21 15:12:24 +01:00
|
|
|
#include "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"
|
2015-10-30 11:02:44 +01:00
|
|
|
#include "nmp-object.h"
|
2012-02-22 23:59:50 -06:00
|
|
|
|
2015-04-15 14:53:30 -04:00
|
|
|
#include "nmdbus-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
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (NMDeviceVlan, nm_device_vlan, NM_TYPE_DEVICE)
|
|
|
|
|
|
|
|
|
|
#define NM_DEVICE_VLAN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_VLAN, NMDeviceVlanPrivate))
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
NMDevice *parent;
|
|
|
|
|
guint parent_state_id;
|
2015-10-06 15:21:29 +02:00
|
|
|
guint parent_hwaddr_id;
|
2013-07-20 21:48:06 +02:00
|
|
|
int vlan_id;
|
2012-02-22 23:59:50 -06:00
|
|
|
} NMDeviceVlanPrivate;
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
PROP_0,
|
2013-09-03 14:23:16 -04:00
|
|
|
PROP_PARENT,
|
2012-02-22 23:59:50 -06:00
|
|
|
PROP_VLAN_ID,
|
|
|
|
|
|
|
|
|
|
LAST_PROP
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
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. */
|
|
|
|
|
if (reason == NM_DEVICE_STATE_REASON_CARRIER)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
nm_device_set_unmanaged (NM_DEVICE (self), NM_UNMANAGED_PARENT, !nm_device_get_managed (parent), reason);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-06 15:21:29 +02:00
|
|
|
static void
|
|
|
|
|
parent_hwaddr_changed (NMDevice *parent,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceVlan *self = NM_DEVICE_VLAN (user_data);
|
|
|
|
|
NMConnection *connection;
|
|
|
|
|
NMSettingWired *s_wired;
|
|
|
|
|
const char *cloned_mac = NULL;
|
|
|
|
|
|
|
|
|
|
/* Never touch assumed devices */
|
|
|
|
|
if (nm_device_uses_assumed_connection (self))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
connection = nm_device_get_applied_connection (self);
|
|
|
|
|
if (!connection)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* Update the VLAN MAC only if configuration does not specify one */
|
|
|
|
|
s_wired = nm_connection_get_setting_wired (connection);
|
|
|
|
|
if (s_wired)
|
|
|
|
|
cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired);
|
|
|
|
|
|
|
|
|
|
if (!cloned_mac) {
|
|
|
|
|
_LOGD (LOGD_VLAN, "parent hardware address changed");
|
|
|
|
|
nm_device_set_hw_addr (self, nm_device_get_hw_address (parent),
|
|
|
|
|
"set", LOGD_VLAN);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-29 10:06:51 +02:00
|
|
|
static void
|
2014-09-05 08:50:02 -05:00
|
|
|
nm_device_vlan_set_parent (NMDeviceVlan *self, NMDevice *parent)
|
2015-04-29 10:06:51 +02:00
|
|
|
{
|
2015-04-13 11:43:12 -05:00
|
|
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self);
|
|
|
|
|
NMDevice *device = NM_DEVICE (self);
|
|
|
|
|
|
|
|
|
|
if (parent == priv->parent)
|
|
|
|
|
return;
|
2015-04-29 10:06:51 +02:00
|
|
|
|
2015-10-06 15:21:29 +02:00
|
|
|
nm_clear_g_signal_handler (priv->parent, &priv->parent_state_id);
|
|
|
|
|
nm_clear_g_signal_handler (priv->parent, &priv->parent_hwaddr_id);
|
2015-04-29 10:06:51 +02:00
|
|
|
g_clear_object (&priv->parent);
|
|
|
|
|
|
|
|
|
|
if (parent) {
|
|
|
|
|
priv->parent = g_object_ref (parent);
|
|
|
|
|
priv->parent_state_id = g_signal_connect (priv->parent,
|
|
|
|
|
"state-changed",
|
|
|
|
|
G_CALLBACK (parent_state_changed),
|
|
|
|
|
device);
|
2015-04-13 11:43:12 -05:00
|
|
|
|
2015-10-06 15:21:29 +02:00
|
|
|
priv->parent_hwaddr_id = g_signal_connect (priv->parent, "notify::" NM_DEVICE_HW_ADDRESS,
|
|
|
|
|
G_CALLBACK (parent_hwaddr_changed), device);
|
|
|
|
|
|
2015-04-13 11:43:12 -05:00
|
|
|
/* Set parent-dependent unmanaged flag */
|
2014-09-05 08:50:02 -05:00
|
|
|
nm_device_set_unmanaged (device,
|
|
|
|
|
NM_UNMANAGED_PARENT,
|
|
|
|
|
!nm_device_get_managed (parent),
|
|
|
|
|
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 */
|
|
|
|
|
nm_device_queue_recheck_available (self,
|
|
|
|
|
NM_DEVICE_STATE_REASON_PARENT_CHANGED,
|
|
|
|
|
NM_DEVICE_STATE_REASON_PARENT_CHANGED);
|
2015-04-29 10:06:51 +02:00
|
|
|
g_object_notify (G_OBJECT (device), NM_DEVICE_VLAN_PARENT);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-05 08:50:02 -05:00
|
|
|
static void
|
|
|
|
|
setup (NMDevice *device, NMPlatformLink *plink)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceVlan *self = NM_DEVICE_VLAN (device);
|
|
|
|
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self);
|
|
|
|
|
|
|
|
|
|
NM_DEVICE_CLASS (nm_device_vlan_parent_class)->setup (device, plink);
|
|
|
|
|
|
|
|
|
|
_LOGI (LOGD_HW | LOGD_VLAN, "VLAN ID %d with parent %s",
|
|
|
|
|
priv->vlan_id, nm_device_get_iface (priv->parent));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
realize (NMDevice *device,
|
|
|
|
|
NMPlatformLink *plink,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (device);
|
|
|
|
|
NMDevice *parent;
|
2015-10-12 13:44:44 +02:00
|
|
|
const NMPlatformLnkVlan *plnk;
|
2014-09-05 08:50:02 -05:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (plink, FALSE);
|
|
|
|
|
|
|
|
|
|
g_assert (plink->type == NM_LINK_TYPE_VLAN);
|
|
|
|
|
|
2015-10-12 13:44:44 +02:00
|
|
|
plnk = nm_platform_link_get_lnk_vlan (NM_PLATFORM_GET, plink->ifindex, NULL);
|
|
|
|
|
if (!plnk) {
|
2014-09-05 08:50:02 -05:00
|
|
|
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
|
2015-10-12 13:44:44 +02:00
|
|
|
"(%s): failed to get VLAN properties", plink->name);
|
2014-09-05 08:50:02 -05:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-12 13:44:44 +02:00
|
|
|
if (plnk->id < 0) {
|
2014-09-05 08:50:02 -05:00
|
|
|
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
|
|
|
|
|
"(%s): VLAN ID invalid", plink->name);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-12 13:44:44 +02:00
|
|
|
if (plink->parent != NM_PLATFORM_LINK_OTHER_NETNS) {
|
|
|
|
|
parent = nm_manager_get_device_by_ifindex (nm_manager_get (), plink->parent);
|
2015-08-17 17:48:37 +02:00
|
|
|
if (!parent) {
|
|
|
|
|
nm_log_dbg (LOGD_HW, "(%s): VLAN parent interface unknown", plink->name);
|
2015-09-08 09:46:56 +02:00
|
|
|
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
|
|
|
|
|
"(%s): VLAN parent interface unknown", plink->name);
|
2015-08-17 17:48:37 +02:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
parent = NULL;
|
2014-09-05 08:50:02 -05:00
|
|
|
|
|
|
|
|
g_warn_if_fail (priv->parent == NULL);
|
|
|
|
|
nm_device_vlan_set_parent (NM_DEVICE_VLAN (device), parent);
|
2015-10-12 13:44:44 +02:00
|
|
|
priv->vlan_id = plnk->id;
|
2014-09-05 08:50:02 -05:00
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
create_and_realize (NMDevice *device,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
NMDevice *parent,
|
|
|
|
|
NMPlatformLink *out_plink,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (device);
|
|
|
|
|
const char *iface = nm_device_get_iface (device);
|
|
|
|
|
NMSettingVlan *s_vlan;
|
|
|
|
|
int parent_ifindex, vlan_id;
|
|
|
|
|
NMPlatformError plerr;
|
|
|
|
|
|
|
|
|
|
g_assert (out_plink);
|
|
|
|
|
|
|
|
|
|
s_vlan = nm_connection_get_setting_vlan (connection);
|
|
|
|
|
g_assert (s_vlan);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
plerr = nm_platform_vlan_add (NM_PLATFORM_GET,
|
|
|
|
|
iface,
|
|
|
|
|
parent_ifindex,
|
|
|
|
|
vlan_id,
|
|
|
|
|
nm_setting_vlan_get_flags (s_vlan),
|
|
|
|
|
out_plink);
|
|
|
|
|
if (plerr != NM_PLATFORM_ERROR_SUCCESS && plerr != NM_PLATFORM_ERROR_EXISTS) {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_warn_if_fail (priv->parent == NULL);
|
|
|
|
|
nm_device_vlan_set_parent (NM_DEVICE_VLAN (device), parent);
|
|
|
|
|
priv->vlan_id = vlan_id;
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
2014-10-06 17:17:54 -05:00
|
|
|
static NMDeviceCapabilities
|
|
|
|
|
get_generic_capabilities (NMDevice *dev)
|
|
|
|
|
{
|
|
|
|
|
/* We assume VLAN interfaces always support carrier detect */
|
|
|
|
|
return NM_DEVICE_CAP_CARRIER_DETECT | NM_DEVICE_CAP_IS_SOFTWARE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
bring_up (NMDevice *dev, gboolean *no_firmware)
|
|
|
|
|
{
|
|
|
|
|
gboolean success = FALSE;
|
|
|
|
|
guint i = 20;
|
|
|
|
|
|
|
|
|
|
while (i-- > 0 && !success) {
|
|
|
|
|
success = NM_DEVICE_CLASS (nm_device_vlan_parent_class)->bring_up (dev, no_firmware);
|
|
|
|
|
g_usleep (50);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
is_available (NMDevice *device, NMDeviceCheckDevAvailableFlags flags)
|
|
|
|
|
{
|
|
|
|
|
if (!NM_DEVICE_VLAN_GET_PRIVATE (device)->parent)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
return NM_DEVICE_CLASS (nm_device_vlan_parent_class)->is_available (device, flags);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-13 11:43:12 -05:00
|
|
|
static gboolean
|
|
|
|
|
component_added (NMDevice *device, GObject *component)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceVlan *self = NM_DEVICE_VLAN (device);
|
|
|
|
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self);
|
|
|
|
|
NMDevice *added_device;
|
2015-10-12 13:44:44 +02:00
|
|
|
const NMPlatformLink *plink;
|
|
|
|
|
const NMPlatformLnkVlan *plnk;
|
2015-04-13 11:43:12 -05:00
|
|
|
|
|
|
|
|
if (priv->parent)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (!NM_IS_DEVICE (component))
|
|
|
|
|
return FALSE;
|
|
|
|
|
added_device = NM_DEVICE (component);
|
|
|
|
|
|
2015-10-12 13:44:44 +02:00
|
|
|
plnk = nm_platform_link_get_lnk_vlan (NM_PLATFORM_GET, nm_device_get_ifindex (device), &plink);
|
|
|
|
|
if (!plnk) {
|
2015-04-13 11:43:12 -05:00
|
|
|
_LOGW (LOGD_VLAN, "failed to get VLAN interface info while checking added component.");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-12 13:44:44 +02:00
|
|
|
if ( plink->parent <= 0
|
|
|
|
|
|| nm_device_get_ifindex (added_device) != plink->parent)
|
2015-04-13 11:43:12 -05:00
|
|
|
return FALSE;
|
|
|
|
|
|
2014-09-05 08:50:02 -05:00
|
|
|
nm_device_vlan_set_parent (self, added_device);
|
2015-04-13 11:43:12 -05:00
|
|
|
|
|
|
|
|
/* Don't claim parent exclusively */
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (parent != NULL, FALSE);
|
|
|
|
|
|
2015-04-13 11:43:12 -05:00
|
|
|
if (!priv->parent)
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
parent_req = nm_device_get_act_request (priv->parent);
|
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 */
|
2014-05-30 13:44:53 -05:00
|
|
|
if (g_strcmp0 (parent, nm_device_get_ip_iface (priv->parent)) != 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)
|
|
|
|
|
{
|
|
|
|
|
NMSettingWired *s_wired;
|
2014-07-30 10:57:45 -04:00
|
|
|
const char *setting_mac;
|
2014-06-21 12:44:56 -04:00
|
|
|
const char *device_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
|
|
|
|
|
|
|
|
s_wired = nm_connection_get_setting_wired (connection);
|
|
|
|
|
if (!s_wired)
|
|
|
|
|
return !fail_if_no_hwaddr;
|
|
|
|
|
|
2014-07-30 10:57:45 -04:00
|
|
|
setting_mac = nm_setting_wired_get_mac_address (s_wired);
|
|
|
|
|
if (!setting_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
|
|
|
return !fail_if_no_hwaddr;
|
|
|
|
|
|
2014-06-21 12:44:56 -04:00
|
|
|
device_mac = nm_device_get_hw_address (device);
|
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
|
|
|
|
2014-07-30 10:57:45 -04:00
|
|
|
return nm_utils_hwaddr_matches (setting_mac, -1, device_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
|
|
|
{
|
2013-03-06 16:16:54 -05:00
|
|
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (device);
|
2012-02-22 23:59:50 -06:00
|
|
|
NMSettingVlan *s_vlan;
|
|
|
|
|
const char *parent, *iface = NULL;
|
|
|
|
|
|
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-05-30 13:44:53 -05:00
|
|
|
if (nm_setting_vlan_get_id (s_vlan) != priv->vlan_id)
|
2012-02-22 23:59:50 -06:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
/* Check parent interface; could be an interface name or a UUID */
|
|
|
|
|
parent = nm_setting_vlan_get_parent (s_vlan);
|
|
|
|
|
if (parent) {
|
2014-05-30 13:44:53 -05:00
|
|
|
if (!match_parent (NM_DEVICE_VLAN (device), parent))
|
2012-02-22 23:59:50 -06:00
|
|
|
return FALSE;
|
|
|
|
|
} else {
|
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
|
|
|
/* Parent could be a MAC address in an NMSettingWired */
|
2014-05-30 13:44:53 -05:00
|
|
|
if (!match_hwaddr (device, connection, TRUE))
|
2012-02-22 23:59:50 -06:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Ensure the interface name matches. If not specified we assume a match
|
|
|
|
|
* since both the parent interface and the VLAN ID matched by the time we
|
|
|
|
|
* get here.
|
|
|
|
|
*/
|
2014-08-07 10:47:56 -04:00
|
|
|
iface = nm_connection_get_interface_name (connection);
|
2012-02-22 23:59:50 -06:00
|
|
|
if (iface) {
|
2014-05-30 13:44:53 -05:00
|
|
|
if (g_strcmp0 (nm_device_get_ip_iface (device), iface) != 0)
|
2012-02-22 23:59:50 -06:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
nm_utils_complete_generic (connection,
|
|
|
|
|
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)
|
|
|
|
|
{
|
2014-08-02 15:14:26 +02:00
|
|
|
NMDeviceVlan *self = NM_DEVICE_VLAN (device);
|
2013-07-20 21:48:06 +02:00
|
|
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (device);
|
|
|
|
|
NMSettingVlan *s_vlan = nm_connection_get_setting_vlan (connection);
|
|
|
|
|
int ifindex = nm_device_get_ifindex (device);
|
|
|
|
|
NMDevice *parent;
|
|
|
|
|
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;
|
|
|
|
|
nm_auto_nmpobj NMPObject *polnk_ref = NULL;
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-30 11:02:44 +01:00
|
|
|
polnk = nm_platform_link_get_lnk (NM_PLATFORM_GET, ifindex, NM_LINK_TYPE_VLAN, &plink);
|
|
|
|
|
if (!polnk) {
|
2014-08-02 15:14:26 +02:00
|
|
|
_LOGW (LOGD_VLAN, "failed to get VLAN interface info while updating connection.");
|
2013-11-13 18:24:42 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2015-10-30 11:02:44 +01:00
|
|
|
polnk_ref = nmp_object_ref ((NMPObject *) polnk);
|
2013-11-13 18:24:42 +01:00
|
|
|
|
2015-10-30 11:02:44 +01:00
|
|
|
if (priv->vlan_id != polnk->lnk_vlan.id) {
|
|
|
|
|
priv->vlan_id = polnk->lnk_vlan.id;
|
2013-07-20 21:48:06 +02:00
|
|
|
g_object_notify (G_OBJECT (device), NM_DEVICE_VLAN_ID);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-30 11:02:44 +01:00
|
|
|
if (polnk->lnk_vlan.id != nm_setting_vlan_get_id (s_vlan))
|
2013-07-20 21:48:06 +02:00
|
|
|
g_object_set (s_vlan, NM_SETTING_VLAN_ID, priv->vlan_id, NULL);
|
|
|
|
|
|
2015-10-12 13:44:44 +02:00
|
|
|
if (plink->parent != NM_PLATFORM_LINK_OTHER_NETNS)
|
|
|
|
|
parent = nm_manager_get_device_by_ifindex (nm_manager_get (), plink->parent);
|
2015-08-17 17:48:37 +02:00
|
|
|
else
|
|
|
|
|
parent = NULL;
|
2014-09-05 08:50:02 -05:00
|
|
|
nm_device_vlan_set_parent (NM_DEVICE_VLAN (device), parent);
|
2013-07-20 21:48:06 +02:00
|
|
|
|
|
|
|
|
/* Update parent in the connection; default to parent's interface name */
|
2015-08-17 17:48:37 +02:00
|
|
|
if (parent) {
|
|
|
|
|
new_parent = nm_device_get_iface (parent);
|
|
|
|
|
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 */
|
|
|
|
|
parent_connection = nm_connection_provider_get_connection_by_uuid (nm_connection_provider_get (), setting_parent);
|
|
|
|
|
if (parent_connection && nm_device_check_connection_compatible (parent, parent_connection))
|
|
|
|
|
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
|
|
|
|
|
|
|
|
if (polnk->lnk_vlan.flags != nm_setting_vlan_get_flags (s_vlan))
|
|
|
|
|
g_object_set (s_vlan, NM_SETTING_VLAN_FLAGS, (NMVlanFlags) polnk->lnk_vlan.flags, NULL);
|
|
|
|
|
|
|
|
|
|
_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);
|
2012-02-22 23:59:50 -06:00
|
|
|
}
|
|
|
|
|
|
2013-09-03 14:03:52 -04:00
|
|
|
static NMActStageReturn
|
|
|
|
|
act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
|
|
|
|
|
{
|
|
|
|
|
NMActRequest *req;
|
|
|
|
|
NMConnection *connection;
|
|
|
|
|
NMSettingVlan *s_vlan;
|
2013-09-08 13:39:03 -04:00
|
|
|
NMSettingWired *s_wired;
|
2014-07-30 10:57:45 -04:00
|
|
|
const char *cloned_mac;
|
2013-09-03 14:03:52 -04:00
|
|
|
NMActStageReturn ret;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (reason != NULL, NM_ACT_STAGE_RETURN_FAILURE);
|
|
|
|
|
|
|
|
|
|
ret = NM_DEVICE_CLASS (nm_device_vlan_parent_class)->act_stage1_prepare (dev, reason);
|
|
|
|
|
if (ret != NM_ACT_STAGE_RETURN_SUCCESS)
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
req = nm_device_get_act_request (dev);
|
|
|
|
|
g_return_val_if_fail (req != NULL, NM_ACT_STAGE_RETURN_FAILURE);
|
|
|
|
|
|
2015-07-14 16:53:24 +02:00
|
|
|
connection = nm_act_request_get_applied_connection (req);
|
2013-09-03 14:03:52 -04:00
|
|
|
g_return_val_if_fail (connection != NULL, NM_ACT_STAGE_RETURN_FAILURE);
|
|
|
|
|
|
2013-09-08 13:39:03 -04:00
|
|
|
s_wired = nm_connection_get_setting_wired (connection);
|
|
|
|
|
if (s_wired) {
|
|
|
|
|
/* Set device MAC address if the connection wants to change it */
|
|
|
|
|
cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired);
|
2014-07-30 10:57:45 -04:00
|
|
|
if (cloned_mac)
|
|
|
|
|
nm_device_set_hw_addr (dev, cloned_mac, "set", LOGD_VLAN);
|
2013-09-08 13:39:03 -04:00
|
|
|
}
|
|
|
|
|
|
2013-09-03 14:03:52 -04:00
|
|
|
s_vlan = nm_connection_get_setting_vlan (connection);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
nm_platform_link_vlan_change (NM_PLATFORM_GET,
|
|
|
|
|
nm_device_get_ifindex (dev),
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-08 13:39:03 -04:00
|
|
|
static void
|
|
|
|
|
ip4_config_pre_commit (NMDevice *device, NMIP4Config *config)
|
|
|
|
|
{
|
|
|
|
|
NMConnection *connection;
|
|
|
|
|
NMSettingWired *s_wired;
|
|
|
|
|
guint32 mtu;
|
|
|
|
|
|
2015-07-14 16:53:24 +02:00
|
|
|
connection = nm_device_get_applied_connection (device);
|
2013-09-08 13:39:03 -04:00
|
|
|
g_assert (connection);
|
|
|
|
|
|
|
|
|
|
s_wired = nm_connection_get_setting_wired (connection);
|
|
|
|
|
if (s_wired) {
|
|
|
|
|
mtu = nm_setting_wired_get_mtu (s_wired);
|
|
|
|
|
if (mtu)
|
2014-10-09 18:51:11 +02:00
|
|
|
nm_ip4_config_set_mtu (config, mtu, NM_IP_CONFIG_SOURCE_USER);
|
2013-09-08 13:39:03 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
deactivate (NMDevice *device)
|
|
|
|
|
{
|
|
|
|
|
/* Reset MAC address back to initial address */
|
2014-10-03 17:37:26 -05:00
|
|
|
if (nm_device_get_initial_hw_address (device))
|
|
|
|
|
nm_device_set_hw_addr (device, nm_device_get_initial_hw_address (device), "reset", LOGD_VLAN);
|
2013-09-08 13:39:03 -04:00
|
|
|
}
|
|
|
|
|
|
2012-02-22 23:59:50 -06:00
|
|
|
/******************************************************************/
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
nm_device_vlan_init (NMDeviceVlan * self)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
get_property (GObject *object, guint prop_id,
|
|
|
|
|
GValue *value, GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2014-07-21 12:15:54 +02:00
|
|
|
case PROP_PARENT:
|
2015-04-03 10:08:52 -04:00
|
|
|
nm_utils_g_value_set_object_path (value, priv->parent);
|
2014-07-21 12:15:54 +02:00
|
|
|
break;
|
2012-02-22 23:59:50 -06:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
set_property (GObject *object, guint prop_id,
|
|
|
|
|
const GValue *value, GParamSpec *pspec)
|
|
|
|
|
{
|
2014-09-05 08:50:02 -05:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
2012-02-22 23:59:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
dispose (GObject *object)
|
|
|
|
|
{
|
2014-09-05 08:50:02 -05:00
|
|
|
nm_device_vlan_set_parent (NM_DEVICE_VLAN (object), NULL);
|
2012-08-24 11:23:18 -05:00
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (nm_device_vlan_parent_class)->dispose (object);
|
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);
|
|
|
|
|
|
2013-07-20 21:48:06 +02:00
|
|
|
parent_class->connection_type = NM_SETTING_VLAN_SETTING_NAME;
|
|
|
|
|
|
2012-02-22 23:59:50 -06:00
|
|
|
g_type_class_add_private (object_class, sizeof (NMDeviceVlanPrivate));
|
|
|
|
|
|
|
|
|
|
/* virtual methods */
|
|
|
|
|
object_class->get_property = get_property;
|
|
|
|
|
object_class->set_property = set_property;
|
|
|
|
|
object_class->dispose = dispose;
|
|
|
|
|
|
2014-09-05 08:50:02 -05:00
|
|
|
parent_class->create_and_realize = create_and_realize;
|
|
|
|
|
parent_class->realize = realize;
|
|
|
|
|
parent_class->setup = setup;
|
2012-09-27 12:12:15 -04:00
|
|
|
parent_class->get_generic_capabilities = get_generic_capabilities;
|
2013-06-13 15:13:58 -05:00
|
|
|
parent_class->bring_up = bring_up;
|
2013-09-03 14:03:52 -04:00
|
|
|
parent_class->act_stage1_prepare = act_stage1_prepare;
|
2013-09-08 13:39:03 -04:00
|
|
|
parent_class->ip4_config_pre_commit = ip4_config_pre_commit;
|
|
|
|
|
parent_class->deactivate = deactivate;
|
2015-04-13 11:43:12 -05:00
|
|
|
parent_class->is_available = is_available;
|
|
|
|
|
parent_class->component_added = component_added;
|
2012-09-27 12:12:15 -04:00
|
|
|
|
|
|
|
|
parent_class->check_connection_compatible = check_connection_compatible;
|
|
|
|
|
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
|
|
|
|
|
|
|
|
/* properties */
|
2013-09-03 14:23:16 -04:00
|
|
|
g_object_class_install_property
|
|
|
|
|
(object_class, PROP_PARENT,
|
2015-04-15 14:53:30 -04:00
|
|
|
g_param_spec_string (NM_DEVICE_VLAN_PARENT, "", "",
|
|
|
|
|
NULL,
|
|
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
2012-02-22 23:59:50 -06:00
|
|
|
g_object_class_install_property
|
|
|
|
|
(object_class, PROP_VLAN_ID,
|
2014-06-09 16:17:37 -04:00
|
|
|
g_param_spec_uint (NM_DEVICE_VLAN_ID, "", "",
|
2012-02-22 23:59:50 -06:00
|
|
|
0, 4095, 0,
|
2014-09-05 08:50:02 -05:00
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
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
|
|
|
|
|
|
|
|
/*************************************************************/
|
|
|
|
|
|
|
|
|
|
#define NM_TYPE_VLAN_FACTORY (nm_vlan_factory_get_type ())
|
|
|
|
|
#define NM_VLAN_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_VLAN_FACTORY, NMVlanFactory))
|
|
|
|
|
|
|
|
|
|
static NMDevice *
|
2014-09-05 08:50:02 -05:00
|
|
|
create_device (NMDeviceFactory *factory,
|
|
|
|
|
const char *iface,
|
|
|
|
|
NMPlatformLink *plink,
|
|
|
|
|
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,
|
|
|
|
|
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 *
|
|
|
|
|
get_virtual_iface_name (NMDeviceFactory *factory,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
const char *parent_iface)
|
|
|
|
|
{
|
|
|
|
|
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),
|
2014-09-05 08:50:02 -05:00
|
|
|
factory_iface->create_device = create_device;
|
2014-09-18 17:50:47 -05:00
|
|
|
factory_iface->get_connection_parent = get_connection_parent;
|
|
|
|
|
factory_iface->get_virtual_iface_name = get_virtual_iface_name;
|
2014-09-08 10:24:11 -05:00
|
|
|
)
|
|
|
|
|
|