2013-05-06 09:16:17 -04:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
|
|
|
|
/* NetworkManager -- Network link manager
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2013 Red Hat, Inc.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "nm-device-macvlan.h"
|
2013-05-29 12:57:13 -03:00
|
|
|
#include "nm-device-private.h"
|
2015-07-17 14:38:54 +02:00
|
|
|
#include "nm-default.h"
|
2013-05-06 09:16:17 -04:00
|
|
|
#include "nm-manager.h"
|
|
|
|
|
#include "nm-platform.h"
|
2014-09-08 11:11:19 -05:00
|
|
|
#include "nm-device-factory.h"
|
2013-05-06 09:16:17 -04:00
|
|
|
|
2015-04-15 14:53:30 -04:00
|
|
|
#include "nmdbus-device-macvlan.h"
|
2013-05-06 09:16:17 -04:00
|
|
|
|
2014-08-02 15:14:26 +02:00
|
|
|
#include "nm-device-logging.h"
|
|
|
|
|
_LOG_DECLARE_SELF(NMDeviceMacvlan);
|
|
|
|
|
|
2013-05-06 09:16:17 -04:00
|
|
|
G_DEFINE_TYPE (NMDeviceMacvlan, nm_device_macvlan, NM_TYPE_DEVICE_GENERIC)
|
|
|
|
|
|
|
|
|
|
#define NM_DEVICE_MACVLAN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_MACVLAN, NMDeviceMacvlanPrivate))
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2015-10-12 15:15:21 +02:00
|
|
|
int parent_ifindex;
|
|
|
|
|
NMPlatformLnkMacvlan props;
|
2013-05-06 09:16:17 -04:00
|
|
|
} NMDeviceMacvlanPrivate;
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
PROP_0,
|
|
|
|
|
PROP_PARENT,
|
|
|
|
|
PROP_MODE,
|
|
|
|
|
PROP_NO_PROMISC,
|
|
|
|
|
|
|
|
|
|
LAST_PROP
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**************************************************************/
|
|
|
|
|
|
|
|
|
|
/**************************************************************/
|
|
|
|
|
|
2015-12-03 15:44:33 +01:00
|
|
|
static const char *
|
|
|
|
|
macvlan_mode_to_string (guint mode)
|
|
|
|
|
{
|
|
|
|
|
switch (mode) {
|
|
|
|
|
case MACVLAN_MODE_PRIVATE:
|
|
|
|
|
return "private";
|
|
|
|
|
case MACVLAN_MODE_VEPA:
|
|
|
|
|
return "vepa";
|
|
|
|
|
case MACVLAN_MODE_BRIDGE:
|
|
|
|
|
return "bridge";
|
|
|
|
|
case MACVLAN_MODE_PASSTHRU:
|
|
|
|
|
return "passthru";
|
|
|
|
|
default:
|
|
|
|
|
return "unknown";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-06 09:16:17 -04:00
|
|
|
static void
|
2013-08-21 12:36:14 +02:00
|
|
|
update_properties (NMDevice *device)
|
2013-05-06 09:16:17 -04:00
|
|
|
{
|
2014-08-02 15:14:26 +02:00
|
|
|
NMDeviceMacvlan *self = NM_DEVICE_MACVLAN (device);
|
2013-05-06 09:16:17 -04:00
|
|
|
NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE (device);
|
|
|
|
|
GObject *object = G_OBJECT (device);
|
2015-10-12 15:15:21 +02:00
|
|
|
const NMPlatformLnkMacvlan *props;
|
|
|
|
|
const NMPlatformLink *plink;
|
2013-05-06 09:16:17 -04:00
|
|
|
|
2015-10-12 15:15:21 +02:00
|
|
|
props = nm_platform_link_get_lnk_macvlan (NM_PLATFORM_GET, nm_device_get_ifindex (device), &plink);
|
|
|
|
|
if (!props) {
|
|
|
|
|
_LOGW (LOGD_HW, "could not get macvlan properties");
|
2013-05-06 09:16:17 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_freeze_notify (object);
|
|
|
|
|
|
2015-10-12 15:15:21 +02:00
|
|
|
if (priv->parent_ifindex != plink->parent)
|
2013-05-06 09:16:17 -04:00
|
|
|
g_object_notify (object, NM_DEVICE_MACVLAN_PARENT);
|
2015-12-03 15:44:33 +01:00
|
|
|
if (priv->props.mode != props->mode)
|
2013-05-06 09:16:17 -04:00
|
|
|
g_object_notify (object, NM_DEVICE_MACVLAN_MODE);
|
2015-10-12 15:15:21 +02:00
|
|
|
if (priv->props.no_promisc != props->no_promisc)
|
2013-05-06 09:16:17 -04:00
|
|
|
g_object_notify (object, NM_DEVICE_MACVLAN_NO_PROMISC);
|
|
|
|
|
|
2015-10-12 15:15:21 +02:00
|
|
|
priv->parent_ifindex = plink->parent;
|
|
|
|
|
priv->props = *props;
|
2013-05-06 09:16:17 -04:00
|
|
|
|
|
|
|
|
g_object_thaw_notify (object);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-21 12:36:14 +02:00
|
|
|
static void
|
|
|
|
|
link_changed (NMDevice *device, NMPlatformLink *info)
|
|
|
|
|
{
|
|
|
|
|
NM_DEVICE_CLASS (nm_device_macvlan_parent_class)->link_changed (device, info);
|
|
|
|
|
update_properties (device);
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-06 09:16:17 -04:00
|
|
|
/**************************************************************/
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
nm_device_macvlan_init (NMDeviceMacvlan *self)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
constructed (GObject *object)
|
|
|
|
|
{
|
2013-08-21 12:36:14 +02:00
|
|
|
update_properties (NM_DEVICE (object));
|
2013-05-06 09:16:17 -04:00
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (nm_device_macvlan_parent_class)->constructed (object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
get_property (GObject *object, guint prop_id,
|
|
|
|
|
GValue *value, GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE (object);
|
2014-02-26 13:32:30 -05:00
|
|
|
NMDevice *parent;
|
2013-05-06 09:16:17 -04:00
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_PARENT:
|
2015-10-12 15:15:21 +02:00
|
|
|
if (priv->parent_ifindex > 0)
|
|
|
|
|
parent = nm_manager_get_device_by_ifindex (nm_manager_get (), priv->parent_ifindex);
|
2015-08-17 17:48:37 +02:00
|
|
|
else
|
|
|
|
|
parent = NULL;
|
2015-04-03 10:08:52 -04:00
|
|
|
nm_utils_g_value_set_object_path (value, parent);
|
2013-05-06 09:16:17 -04:00
|
|
|
break;
|
|
|
|
|
case PROP_MODE:
|
2015-12-03 15:44:33 +01:00
|
|
|
g_value_set_string (value, macvlan_mode_to_string (priv->props.mode));
|
2013-05-06 09:16:17 -04:00
|
|
|
break;
|
|
|
|
|
case PROP_NO_PROMISC:
|
|
|
|
|
g_value_set_boolean (value, priv->props.no_promisc);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
nm_device_macvlan_class_init (NMDeviceMacvlanClass *klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
|
|
|
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (NMDeviceMacvlanPrivate));
|
|
|
|
|
|
2014-10-09 12:42:29 -05:00
|
|
|
NM_DEVICE_CLASS_DECLARE_TYPES (klass, NULL, NM_LINK_TYPE_MACVLAN, NM_LINK_TYPE_MACVTAP)
|
|
|
|
|
|
2013-05-06 09:16:17 -04:00
|
|
|
object_class->constructed = constructed;
|
|
|
|
|
object_class->get_property = get_property;
|
|
|
|
|
|
|
|
|
|
device_class->link_changed = link_changed;
|
|
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
|
g_object_class_install_property
|
|
|
|
|
(object_class, PROP_PARENT,
|
2015-04-15 14:53:30 -04:00
|
|
|
g_param_spec_string (NM_DEVICE_MACVLAN_PARENT, "", "",
|
|
|
|
|
NULL,
|
|
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
2013-05-06 09:16:17 -04:00
|
|
|
|
|
|
|
|
g_object_class_install_property
|
|
|
|
|
(object_class, PROP_MODE,
|
2014-06-09 16:17:37 -04:00
|
|
|
g_param_spec_string (NM_DEVICE_MACVLAN_MODE, "", "",
|
2013-05-06 09:16:17 -04:00
|
|
|
NULL,
|
2014-06-09 16:17:37 -04:00
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
2013-05-06 09:16:17 -04:00
|
|
|
|
|
|
|
|
g_object_class_install_property
|
|
|
|
|
(object_class, PROP_NO_PROMISC,
|
2014-06-09 16:17:37 -04:00
|
|
|
g_param_spec_boolean (NM_DEVICE_MACVLAN_NO_PROMISC, "", "",
|
2013-05-06 09:16:17 -04:00
|
|
|
FALSE,
|
2014-06-09 16:17:37 -04:00
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
2013-05-06 09:16:17 -04:00
|
|
|
|
2015-04-13 13:31:42 -04:00
|
|
|
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
|
2015-04-15 14:53:30 -04:00
|
|
|
NMDBUS_TYPE_DEVICE_MACVLAN_SKELETON,
|
|
|
|
|
NULL);
|
2013-05-06 09:16:17 -04:00
|
|
|
}
|
2014-09-08 11:11:19 -05:00
|
|
|
|
|
|
|
|
/*************************************************************/
|
|
|
|
|
|
|
|
|
|
#define NM_TYPE_MACVLAN_FACTORY (nm_macvlan_factory_get_type ())
|
|
|
|
|
#define NM_MACVLAN_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_MACVLAN_FACTORY, NMMacvlanFactory))
|
|
|
|
|
|
|
|
|
|
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 11:11:19 -05:00
|
|
|
{
|
2015-12-08 14:51:12 +01:00
|
|
|
g_return_val_if_fail (plink, NULL);
|
|
|
|
|
|
2014-09-17 14:17:30 -05:00
|
|
|
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_MACVLAN,
|
2014-09-05 08:50:02 -05:00
|
|
|
NM_DEVICE_IFACE, iface,
|
2014-09-17 14:17:30 -05:00
|
|
|
NM_DEVICE_TYPE_DESC, "Macvlan",
|
|
|
|
|
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_GENERIC,
|
2015-12-08 14:51:12 +01:00
|
|
|
NM_DEVICE_LINK_TYPE, plink->type,
|
2014-09-17 14:17:30 -05:00
|
|
|
NULL);
|
2014-09-08 11:11:19 -05:00
|
|
|
}
|
|
|
|
|
|
2014-09-17 14:17:30 -05:00
|
|
|
NM_DEVICE_FACTORY_DEFINE_INTERNAL (MACVLAN, Macvlan, macvlan,
|
|
|
|
|
NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_MACVLAN, NM_LINK_TYPE_MACVTAP),
|
2014-09-05 08:50:02 -05:00
|
|
|
factory_iface->create_device = create_device;
|
2014-09-08 11:11:19 -05:00
|
|
|
)
|
|
|
|
|
|