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"
|
|
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
|
|
2012-03-02 08:56:46 +01:00
|
|
|
#include <sys/socket.h>
|
|
|
|
|
#include <linux/if.h>
|
2012-02-22 23:59:50 -06:00
|
|
|
#include <netinet/ether.h>
|
|
|
|
|
|
|
|
|
|
#include "nm-device-vlan.h"
|
|
|
|
|
#include "nm-logging.h"
|
|
|
|
|
#include "nm-utils.h"
|
|
|
|
|
#include "NetworkManagerUtils.h"
|
|
|
|
|
#include "nm-device-private.h"
|
|
|
|
|
#include "nm-enum-types.h"
|
2013-05-07 12:18:41 -04:00
|
|
|
#include "nm-dbus-manager.h"
|
2013-01-21 15:12:24 +01:00
|
|
|
#include "nm-platform.h"
|
2012-02-22 23:59:50 -06:00
|
|
|
|
|
|
|
|
#include "nm-device-vlan-glue.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
|
|
|
|
|
#define NM_VLAN_ERROR (nm_vlan_error_quark ())
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
gboolean disposed;
|
2013-09-03 14:23:16 -04:00
|
|
|
gboolean invalid;
|
2012-02-22 23:59:50 -06:00
|
|
|
|
|
|
|
|
NMDevice *parent;
|
|
|
|
|
guint parent_state_id;
|
|
|
|
|
|
|
|
|
|
guint vlan_id;
|
|
|
|
|
} 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
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
|
|
|
|
static GQuark
|
|
|
|
|
nm_vlan_error_quark (void)
|
|
|
|
|
{
|
|
|
|
|
static GQuark quark = 0;
|
|
|
|
|
if (!quark)
|
|
|
|
|
quark = g_quark_from_static_string ("nm-vlan-error");
|
|
|
|
|
return quark;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
|
|
|
|
static guint32
|
2012-09-27 12:12:15 -04:00
|
|
|
get_generic_capabilities (NMDevice *dev)
|
2012-02-22 23:59:50 -06:00
|
|
|
{
|
|
|
|
|
/* We assume VLAN interfaces always support carrier detect */
|
2013-05-17 10:58:38 -05:00
|
|
|
return NM_DEVICE_CAP_CARRIER_DETECT;
|
2012-02-22 23:59:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2013-06-13 15:13:58 -05:00
|
|
|
bring_up (NMDevice *dev, gboolean *no_firmware)
|
2012-02-22 23:59:50 -06:00
|
|
|
{
|
2013-01-21 15:12:24 +01:00
|
|
|
gboolean success = FALSE;
|
2012-03-06 12:53:11 -06:00
|
|
|
guint i = 20;
|
|
|
|
|
|
|
|
|
|
while (i-- > 0 && !success) {
|
2013-06-13 15:13:58 -05:00
|
|
|
success = NM_DEVICE_CLASS (nm_device_vlan_parent_class)->bring_up (dev, no_firmware);
|
2012-03-06 12:53:11 -06:00
|
|
|
g_usleep (50);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return success;
|
2012-02-22 23:59:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
match_parent (NMDeviceVlan *self, const char *parent, GError **error)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (parent != NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
if (!parent_req) {
|
|
|
|
|
g_set_error_literal (error, NM_VLAN_ERROR, NM_VLAN_ERROR_CONNECTION_INVALID,
|
|
|
|
|
"Parent interface not active; could not match UUID");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parent_connection = nm_active_connection_get_connection (NM_ACTIVE_CONNECTION (parent_req));
|
|
|
|
|
if (!parent_connection) {
|
|
|
|
|
g_set_error_literal (error, NM_VLAN_ERROR, NM_VLAN_ERROR_CONNECTION_INVALID,
|
|
|
|
|
"Parent interface had no connection; could not match UUID");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
if (g_strcmp0 (parent, nm_connection_get_uuid (parent_connection)) != 0) {
|
|
|
|
|
g_set_error_literal (error, NM_VLAN_ERROR, NM_VLAN_ERROR_CONNECTION_INVALID,
|
|
|
|
|
"Parent interface UUID did not match connection UUID");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* interface name */
|
|
|
|
|
if (g_strcmp0 (parent, nm_device_get_ip_iface (priv->parent)) != 0) {
|
|
|
|
|
g_set_error_literal (error, NM_VLAN_ERROR, NM_VLAN_ERROR_CONNECTION_INVALID,
|
|
|
|
|
"Parent interface name did not match connection");
|
|
|
|
|
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;
|
|
|
|
|
const GByteArray *mac;
|
|
|
|
|
const guint8 *device_mac;
|
|
|
|
|
guint device_mac_len;
|
|
|
|
|
|
|
|
|
|
s_wired = nm_connection_get_setting_wired (connection);
|
|
|
|
|
if (!s_wired)
|
|
|
|
|
return !fail_if_no_hwaddr;
|
|
|
|
|
|
|
|
|
|
mac = nm_setting_wired_get_mac_address (s_wired);
|
|
|
|
|
if (!mac)
|
|
|
|
|
return !fail_if_no_hwaddr;
|
|
|
|
|
|
|
|
|
|
device_mac = nm_device_get_hw_address (device, &device_mac_len);
|
|
|
|
|
|
|
|
|
|
return ( mac->len == device_mac_len
|
|
|
|
|
&& memcmp (mac->data, device_mac, device_mac_len) == 0);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-22 23:59:50 -06:00
|
|
|
static gboolean
|
2013-03-06 16:16:54 -05:00
|
|
|
check_connection_compatible (NMDevice *device,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
GError **error)
|
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;
|
|
|
|
|
|
2013-03-07 07:44:36 -05:00
|
|
|
if (!NM_DEVICE_CLASS (nm_device_vlan_parent_class)->check_connection_compatible (device, connection, error))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2012-02-22 23:59:50 -06:00
|
|
|
s_vlan = nm_connection_get_setting_vlan (connection);
|
|
|
|
|
if (!s_vlan) {
|
|
|
|
|
g_set_error (error, NM_VLAN_ERROR, NM_VLAN_ERROR_CONNECTION_INVALID,
|
|
|
|
|
"The connection was not a VLAN connection.");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (nm_setting_vlan_get_id (s_vlan) != priv->vlan_id) {
|
|
|
|
|
g_set_error (error, NM_VLAN_ERROR, NM_VLAN_ERROR_CONNECTION_INVALID,
|
|
|
|
|
"The connection's VLAN ID did not match the device's VLAN ID.");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check parent interface; could be an interface name or a UUID */
|
|
|
|
|
parent = nm_setting_vlan_get_parent (s_vlan);
|
|
|
|
|
if (parent) {
|
2013-03-06 16:16:54 -05:00
|
|
|
if (!match_parent (NM_DEVICE_VLAN (device), parent, error))
|
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 */
|
|
|
|
|
if (!match_hwaddr (device, connection, TRUE)) {
|
2012-02-22 23:59:50 -06:00
|
|
|
g_set_error (error, NM_VLAN_ERROR, NM_VLAN_ERROR_CONNECTION_INVALID,
|
|
|
|
|
"Failed to match the VLAN parent interface via hardware address.");
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
iface = nm_connection_get_virtual_iface_name (connection);
|
|
|
|
|
if (iface) {
|
2013-03-06 16:16:54 -05:00
|
|
|
if (g_strcmp0 (nm_device_get_ip_iface (device), iface) != 0) {
|
2012-02-22 23:59:50 -06:00
|
|
|
g_set_error (error, NM_VLAN_ERROR, NM_VLAN_ERROR_CONNECTION_INVALID,
|
|
|
|
|
"The VLAN connection virtual interface name did not match.");
|
|
|
|
|
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,
|
2012-03-09 17:39:58 -06:00
|
|
|
_("VLAN connection %d"),
|
2012-02-22 23:59:50 -06:00
|
|
|
NULL,
|
|
|
|
|
TRUE);
|
|
|
|
|
|
|
|
|
|
s_vlan = nm_connection_get_setting_vlan (connection);
|
|
|
|
|
if (!s_vlan) {
|
|
|
|
|
g_set_error_literal (error, NM_VLAN_ERROR, NM_VLAN_ERROR_CONNECTION_INVALID,
|
|
|
|
|
"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)) {
|
|
|
|
|
g_set_error_literal (error, NM_VLAN_ERROR, NM_VLAN_ERROR_CONNECTION_INVALID,
|
|
|
|
|
"The 'vlan' setting had no interface name, parent, or hardware address.");
|
|
|
|
|
return FALSE;
|
2012-02-22 23:59:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2013-03-06 14:58:03 -05:00
|
|
|
match_l2_config (NMDevice *device, NMConnection *connection)
|
2012-02-22 23:59:50 -06:00
|
|
|
{
|
|
|
|
|
NMSettingVlan *s_vlan;
|
|
|
|
|
gboolean fail_if_no_hwaddr = FALSE;
|
|
|
|
|
|
|
|
|
|
s_vlan = nm_connection_get_setting_vlan (connection);
|
2013-03-06 14:58:03 -05:00
|
|
|
g_assert (s_vlan);
|
2012-02-22 23:59:50 -06:00
|
|
|
|
2013-03-06 14:58:03 -05:00
|
|
|
if ( !nm_setting_vlan_get_parent (s_vlan)
|
|
|
|
|
&& !nm_setting_vlan_get_interface_name (s_vlan)) {
|
2012-02-22 23:59:50 -06:00
|
|
|
/* If there's no parent and no interface name given, then the only way
|
|
|
|
|
* we have to identify the VLAN interface the connection matches is
|
|
|
|
|
* a hardware-specific setting's hardware address property, so we want
|
|
|
|
|
* to fail the match below if we there is none.
|
|
|
|
|
*/
|
2013-03-06 14:58:03 -05:00
|
|
|
fail_if_no_hwaddr = TRUE;
|
2012-02-22 23:59:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* MAC address check; we ask the parent to check our own MAC address,
|
|
|
|
|
* because only the parent knows what kind of NMSetting the MAC
|
|
|
|
|
* address will be in. The VLAN device shouldn't have to know what kind
|
|
|
|
|
* of interface the parent is.
|
|
|
|
|
*/
|
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 (!match_hwaddr (device, connection, fail_if_no_hwaddr))
|
2012-02-22 23:59:50 -06:00
|
|
|
return FALSE;
|
|
|
|
|
|
2013-03-06 14:58:03 -05:00
|
|
|
/* FIXME: any more L2 checks? */
|
2012-02-22 23:59:50 -06:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-03 14:03:52 -04:00
|
|
|
static NMActStageReturn
|
|
|
|
|
act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
|
|
|
|
|
{
|
|
|
|
|
NMActRequest *req;
|
|
|
|
|
NMConnection *connection;
|
|
|
|
|
NMSettingVlan *s_vlan;
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
connection = nm_act_request_get_connection (req);
|
|
|
|
|
g_return_val_if_fail (connection != NULL, NM_ACT_STAGE_RETURN_FAILURE);
|
|
|
|
|
|
|
|
|
|
s_vlan = nm_connection_get_setting_vlan (connection);
|
|
|
|
|
if (s_vlan) {
|
|
|
|
|
int ifindex = nm_device_get_ifindex (dev);
|
|
|
|
|
int num, i;
|
|
|
|
|
guint32 from, to;
|
|
|
|
|
|
|
|
|
|
num = nm_setting_vlan_get_num_priorities (s_vlan, NM_VLAN_INGRESS_MAP);
|
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
|
if (nm_setting_vlan_get_priority (s_vlan, NM_VLAN_INGRESS_MAP, i, &from, &to))
|
|
|
|
|
nm_platform_vlan_set_ingress_map (ifindex, from, to);
|
|
|
|
|
}
|
|
|
|
|
num = nm_setting_vlan_get_num_priorities (s_vlan, NM_VLAN_EGRESS_MAP);
|
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
|
if (nm_setting_vlan_get_priority (s_vlan, NM_VLAN_EGRESS_MAP, i, &from, &to))
|
|
|
|
|
nm_platform_vlan_set_egress_map (ifindex, from, to);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-22 23:59:50 -06: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);
|
|
|
|
|
|
2013-05-07 10:23:44 -04:00
|
|
|
/* We'll react to our own carrier state notifications. Ignore the parent's. */
|
|
|
|
|
if (reason == NM_DEVICE_STATE_REASON_CARRIER)
|
|
|
|
|
return;
|
|
|
|
|
|
2012-02-22 23:59:50 -06:00
|
|
|
if (new_state < NM_DEVICE_STATE_DISCONNECTED) {
|
|
|
|
|
/* If the parent becomes unavailable or unmanaged so does the VLAN */
|
|
|
|
|
nm_device_state_changed (NM_DEVICE (self), new_state, reason);
|
|
|
|
|
} else if ( new_state == NM_DEVICE_STATE_DISCONNECTED
|
|
|
|
|
&& old_state < NM_DEVICE_STATE_DISCONNECTED) {
|
|
|
|
|
/* Mark VLAN interface as available/disconnected when the parent
|
2013-05-07 10:23:44 -04:00
|
|
|
* becomes available as a result of becoming initialized.
|
2012-02-22 23:59:50 -06:00
|
|
|
*/
|
|
|
|
|
nm_device_state_changed (NM_DEVICE (self), new_state, reason);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
|
|
|
|
NMDevice *
|
2013-09-03 14:23:16 -04:00
|
|
|
nm_device_vlan_new (NMPlatformLink *platform_device, NMDevice *parent)
|
2012-02-22 23:59:50 -06:00
|
|
|
{
|
|
|
|
|
NMDevice *device;
|
|
|
|
|
|
2013-09-03 14:23:16 -04:00
|
|
|
g_return_val_if_fail (platform_device != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail (NM_IS_DEVICE (parent), NULL);
|
2012-02-22 23:59:50 -06:00
|
|
|
|
|
|
|
|
device = (NMDevice *) g_object_new (NM_TYPE_DEVICE_VLAN,
|
2013-09-03 14:23:16 -04:00
|
|
|
NM_DEVICE_PLATFORM_DEVICE, platform_device,
|
|
|
|
|
NM_DEVICE_VLAN_PARENT, parent,
|
2012-02-22 23:59:50 -06:00
|
|
|
NM_DEVICE_DRIVER, "8021q",
|
|
|
|
|
NM_DEVICE_TYPE_DESC, "VLAN",
|
|
|
|
|
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_VLAN,
|
|
|
|
|
NULL);
|
2013-09-03 14:23:16 -04:00
|
|
|
if (NM_DEVICE_VLAN_GET_PRIVATE (device)->invalid) {
|
|
|
|
|
g_object_unref (device);
|
|
|
|
|
device = NULL;
|
|
|
|
|
}
|
2012-02-22 23:59:50 -06:00
|
|
|
|
2013-09-03 14:23:16 -04:00
|
|
|
return device;
|
|
|
|
|
}
|
2012-02-22 23:59:50 -06:00
|
|
|
|
2013-09-03 14:23:16 -04:00
|
|
|
NMDevice *
|
|
|
|
|
nm_device_vlan_new_for_connection (NMConnection *connection, NMDevice *parent)
|
|
|
|
|
{
|
|
|
|
|
NMDevice *device;
|
|
|
|
|
NMSettingVlan *s_vlan;
|
|
|
|
|
char *iface;
|
2012-02-22 23:59:50 -06:00
|
|
|
|
2013-09-03 14:23:16 -04:00
|
|
|
g_return_val_if_fail (connection != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail (NM_IS_DEVICE (parent), NULL);
|
|
|
|
|
|
|
|
|
|
s_vlan = nm_connection_get_setting_vlan (connection);
|
|
|
|
|
g_return_val_if_fail (s_vlan != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
iface = g_strdup (nm_connection_get_virtual_iface_name (connection));
|
|
|
|
|
if (!iface) {
|
|
|
|
|
iface = nm_utils_new_vlan_name (nm_device_get_ip_iface (parent),
|
|
|
|
|
nm_setting_vlan_get_id (s_vlan));
|
|
|
|
|
}
|
2012-02-22 23:59:50 -06:00
|
|
|
|
2013-09-03 14:23:16 -04:00
|
|
|
if ( !nm_platform_vlan_add (iface,
|
|
|
|
|
nm_device_get_ifindex (parent),
|
|
|
|
|
nm_setting_vlan_get_id (s_vlan),
|
|
|
|
|
nm_setting_vlan_get_flags (s_vlan))
|
|
|
|
|
&& nm_platform_get_error () != NM_PLATFORM_ERROR_EXISTS) {
|
|
|
|
|
nm_log_warn (LOGD_DEVICE | LOGD_VLAN, "(%s): failed to add VLAN interface for '%s'",
|
|
|
|
|
iface, nm_connection_get_id (connection));
|
|
|
|
|
g_free (iface);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
device = (NMDevice *) g_object_new (NM_TYPE_DEVICE_VLAN,
|
|
|
|
|
NM_DEVICE_IFACE, iface,
|
|
|
|
|
NM_DEVICE_VLAN_PARENT, parent,
|
|
|
|
|
NM_DEVICE_DRIVER, "8021q",
|
|
|
|
|
NM_DEVICE_TYPE_DESC, "VLAN",
|
|
|
|
|
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_VLAN,
|
|
|
|
|
NULL);
|
|
|
|
|
g_free (iface);
|
|
|
|
|
if (NM_DEVICE_VLAN_GET_PRIVATE (device)->invalid) {
|
|
|
|
|
g_object_unref (device);
|
|
|
|
|
device = NULL;
|
2012-02-22 23:59:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return device;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
nm_device_vlan_init (NMDeviceVlan * self)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-03 14:23:16 -04:00
|
|
|
static void
|
|
|
|
|
constructed (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (object);
|
|
|
|
|
NMDevice *device = NM_DEVICE (object);
|
|
|
|
|
const char *iface = nm_device_get_iface (device);
|
|
|
|
|
int ifindex = nm_device_get_ifindex (device);
|
|
|
|
|
int parent_ifindex = -1, itype;
|
|
|
|
|
int vlan_id;
|
|
|
|
|
|
|
|
|
|
if (G_OBJECT_CLASS (nm_device_vlan_parent_class)->constructed)
|
|
|
|
|
G_OBJECT_CLASS (nm_device_vlan_parent_class)->constructed (object);
|
|
|
|
|
|
|
|
|
|
if (!priv->parent) {
|
|
|
|
|
nm_log_err (LOGD_VLAN, "(%s): no parent specified.", iface);
|
|
|
|
|
priv->invalid = TRUE;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
itype = nm_platform_link_get_type (ifindex);
|
|
|
|
|
if (itype != NM_LINK_TYPE_VLAN) {
|
|
|
|
|
nm_log_err (LOGD_VLAN, "(%s): failed to get VLAN interface type.", iface);
|
|
|
|
|
priv->invalid = TRUE;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!nm_platform_vlan_get_info (ifindex, &parent_ifindex, &vlan_id)) {
|
|
|
|
|
nm_log_warn (LOGD_VLAN, "(%s): failed to get VLAN interface info.", iface);
|
|
|
|
|
priv->invalid = TRUE;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( parent_ifindex < 0
|
|
|
|
|
|| parent_ifindex != nm_device_get_ip_ifindex (priv->parent)
|
|
|
|
|
|| vlan_id < 0) {
|
|
|
|
|
nm_log_warn (LOGD_VLAN, "(%s): VLAN parent ifindex (%d) or VLAN ID (%d) invalid.",
|
|
|
|
|
iface, parent_ifindex, priv->vlan_id);
|
|
|
|
|
priv->invalid = TRUE;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
priv->vlan_id = vlan_id;
|
|
|
|
|
nm_log_dbg (LOGD_HW | LOGD_VLAN, "(%s): kernel ifindex %d", iface, ifindex);
|
|
|
|
|
nm_log_info (LOGD_HW | LOGD_VLAN, "(%s): VLAN ID %d with parent %s",
|
|
|
|
|
iface, priv->vlan_id, nm_device_get_iface (priv->parent));
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-22 23:59:50 -06:00
|
|
|
static void
|
|
|
|
|
get_property (GObject *object, guint prop_id,
|
|
|
|
|
GValue *value, GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (object);
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
set_property (GObject *object, guint prop_id,
|
|
|
|
|
const GValue *value, GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2013-09-03 14:23:16 -04:00
|
|
|
case PROP_PARENT:
|
|
|
|
|
priv->parent = g_value_dup_object (value);
|
|
|
|
|
priv->parent_state_id = g_signal_connect (priv->parent,
|
|
|
|
|
"state-changed",
|
|
|
|
|
G_CALLBACK (parent_state_changed),
|
|
|
|
|
object);
|
|
|
|
|
break;
|
2012-02-22 23:59:50 -06:00
|
|
|
case PROP_VLAN_ID:
|
|
|
|
|
priv->vlan_id = g_value_get_uint (value);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
dispose (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceVlan *self = NM_DEVICE_VLAN (object);
|
|
|
|
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (self);
|
|
|
|
|
|
|
|
|
|
if (priv->disposed) {
|
|
|
|
|
G_OBJECT_CLASS (nm_device_vlan_parent_class)->dispose (object);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
priv->disposed = TRUE;
|
|
|
|
|
|
|
|
|
|
g_signal_handler_disconnect (priv->parent, priv->parent_state_id);
|
|
|
|
|
g_object_unref (priv->parent);
|
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);
|
|
|
|
|
|
|
|
|
|
g_type_class_add_private (object_class, sizeof (NMDeviceVlanPrivate));
|
|
|
|
|
|
|
|
|
|
/* virtual methods */
|
2013-09-03 14:23:16 -04:00
|
|
|
object_class->constructed = constructed;
|
2012-02-22 23:59:50 -06:00
|
|
|
object_class->get_property = get_property;
|
|
|
|
|
object_class->set_property = set_property;
|
|
|
|
|
object_class->dispose = dispose;
|
|
|
|
|
|
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;
|
2012-09-27 12:12:15 -04:00
|
|
|
|
|
|
|
|
parent_class->check_connection_compatible = check_connection_compatible;
|
|
|
|
|
parent_class->complete_connection = complete_connection;
|
2013-03-06 14:58:03 -05:00
|
|
|
parent_class->match_l2_config = match_l2_config;
|
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,
|
|
|
|
|
g_param_spec_object (NM_DEVICE_VLAN_PARENT,
|
|
|
|
|
"Parent",
|
|
|
|
|
"Parent",
|
|
|
|
|
NM_TYPE_DEVICE,
|
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
2012-02-22 23:59:50 -06:00
|
|
|
g_object_class_install_property
|
|
|
|
|
(object_class, PROP_VLAN_ID,
|
|
|
|
|
g_param_spec_uint (NM_DEVICE_VLAN_ID,
|
|
|
|
|
"VLAN ID",
|
|
|
|
|
"VLAN ID",
|
|
|
|
|
0, 4095, 0,
|
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
|
|
2013-05-07 12:18:41 -04:00
|
|
|
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
|
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
|
&dbus_glib_nm_device_vlan_object_info);
|
2012-02-22 23:59:50 -06:00
|
|
|
|
|
|
|
|
dbus_g_error_domain_register (NM_VLAN_ERROR, NULL, NM_TYPE_VLAN_ERROR);
|
|
|
|
|
}
|