[patch NetworkManager 1/6] add support for team device



Signed-off-by: Jiri Pirko <jiri resnulli us>
---
 include/NetworkManager.h         |   3 +
 introspection/Makefile.am        |   1 +
 introspection/nm-device-team.xml |  34 ++++
 libnm-glib/Makefile.am           |   2 +
 libnm-glib/libnm-glib.ver        |   7 +
 libnm-glib/nm-device-team.c      | 337 +++++++++++++++++++++++++++++++++++++
 libnm-glib/nm-device-team.h      |  82 +++++++++
 libnm-glib/nm-device.c           |   3 +
 libnm-util/Makefile.am           |   2 +
 libnm-util/libnm-util.ver        |   6 +
 libnm-util/nm-connection.c       |  17 ++
 libnm-util/nm-connection.h       |   2 +
 libnm-util/nm-setting-team.c     | 253 ++++++++++++++++++++++++++++
 libnm-util/nm-setting-team.h     |  78 +++++++++
 src/Makefile.am                  |   3 +
 src/devices/nm-device-ethernet.c |   1 +
 src/devices/nm-device-team.c     | 355 +++++++++++++++++++++++++++++++++++++++
 src/devices/nm-device-team.h     |  62 +++++++
 src/devices/nm-device.c          |  43 ++---
 src/logging/nm-logging.c         |   3 +-
 src/logging/nm-logging.h         |   1 +
 src/nm-activation-request.c      |   4 +-
 src/nm-manager.c                 |  35 +++-
 23 files changed, 1305 insertions(+), 29 deletions(-)
 create mode 100644 introspection/nm-device-team.xml
 create mode 100644 libnm-glib/nm-device-team.c
 create mode 100644 libnm-glib/nm-device-team.h
 create mode 100644 libnm-util/nm-setting-team.c
 create mode 100644 libnm-util/nm-setting-team.h
 create mode 100644 src/devices/nm-device-team.c
 create mode 100644 src/devices/nm-device-team.h

diff --git a/include/NetworkManager.h b/include/NetworkManager.h
index 7736056..27c20f6 100644
--- a/include/NetworkManager.h
+++ b/include/NetworkManager.h
@@ -51,6 +51,7 @@
 #define NM_DBUS_INTERFACE_DHCP6_CONFIG      NM_DBUS_INTERFACE ".DHCP6Config"
 #define NM_DBUS_INTERFACE_DEVICE_INFINIBAND NM_DBUS_INTERFACE_DEVICE ".Infiniband"
 #define NM_DBUS_INTERFACE_DEVICE_BOND       NM_DBUS_INTERFACE_DEVICE ".Bond"
+#define NM_DBUS_INTERFACE_DEVICE_TEAM       NM_DBUS_INTERFACE_DEVICE ".Team"
 #define NM_DBUS_INTERFACE_DEVICE_VLAN       NM_DBUS_INTERFACE_DEVICE ".Vlan"
 #define NM_DBUS_INTERFACE_DEVICE_BRIDGE     NM_DBUS_INTERFACE_DEVICE ".Bridge"
 #define NM_DBUS_INTERFACE_DEVICE_GENERIC    NM_DBUS_INTERFACE_DEVICE ".Generic"
@@ -118,6 +119,7 @@ typedef enum {
  * @NM_DEVICE_TYPE_VLAN: an 802.1Q VLAN interface
  * @NM_DEVICE_TYPE_ADSL: ADSL modem
  * @NM_DEVICE_TYPE_BRIDGE: a bridge master interface
+ * @NM_DEVICE_TYPE_TEAM: a team master interface
  *
  * #NMDeviceType values indicate the type of hardware represented by
  * an #NMDevice.
@@ -138,6 +140,7 @@ typedef enum {
        NM_DEVICE_TYPE_ADSL       = 12,
        NM_DEVICE_TYPE_BRIDGE     = 13,
        NM_DEVICE_TYPE_GENERIC    = 14,
+       NM_DEVICE_TYPE_TEAM       = 15,
 } NMDeviceType;
 
 /**
diff --git a/introspection/Makefile.am b/introspection/Makefile.am
index fc2d773..1cbb17e 100644
--- a/introspection/Makefile.am
+++ b/introspection/Makefile.am
@@ -13,6 +13,7 @@ EXTRA_DIST = \
        nm-device-wimax.xml \
        nm-device-infiniband.xml \
        nm-device-bond.xml \
+       nm-device-team.xml \
        nm-device-bridge.xml \
        nm-device-vlan.xml \
        nm-device-generic.xml \
diff --git a/introspection/nm-device-team.xml b/introspection/nm-device-team.xml
new file mode 100644
index 0000000..baf39fa
--- /dev/null
+++ b/introspection/nm-device-team.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0";>
+  <interface name="org.freedesktop.NetworkManager.Device.Team">
+
+    <property name="HwAddress" type="s" access="read">
+      <tp:docstring>
+        Hardware address of the device.
+      </tp:docstring>
+    </property>
+
+    <property name="Carrier" type="b" access="read">
+      <tp:docstring>
+        Indicates whether the physical carrier is found (e.g. whether a cable is plugged in or not).
+      </tp:docstring>
+    </property>
+
+    <property name="Slaves" type="ao" access="read">
+      <tp:docstring>
+        Array of object paths representing devices which are currently
+       slaved to this device.
+      </tp:docstring>
+    </property>
+
+    <signal name="PropertiesChanged">
+        <arg name="properties" type="a{sv}" tp:type="String_Variant_Map">
+            <tp:docstring>
+                A dictionary mapping property names to variant boxed values
+            </tp:docstring>
+        </arg>
+    </signal>
+
+  </interface>
+</node>
diff --git a/libnm-glib/Makefile.am b/libnm-glib/Makefile.am
index d4b97c0..c4f8299 100644
--- a/libnm-glib/Makefile.am
+++ b/libnm-glib/Makefile.am
@@ -64,6 +64,7 @@ libnminclude_HEADERS = \
        nm-device-bt.h \
        nm-device-olpc-mesh.h \
        nm-device-bond.h \
+       nm-device-team.h \
        nm-device-bridge.h \
        nm-device-vlan.h \
        nm-device-generic.h \
@@ -101,6 +102,7 @@ libnm_glib_la_csources = \
        nm-device-bt.c \
        nm-device-olpc-mesh.c \
        nm-device-bond.c \
+       nm-device-team.c \
        nm-device-bridge.c \
        nm-device-vlan.c \
        nm-device-generic.c \
diff --git a/libnm-glib/libnm-glib.ver b/libnm-glib/libnm-glib.ver
index 668fbac..6469171 100644
--- a/libnm-glib/libnm-glib.ver
+++ b/libnm-glib/libnm-glib.ver
@@ -149,6 +149,13 @@ global:
        nm_device_olpc_mesh_get_type;
        nm_device_olpc_mesh_new;
        nm_device_set_autoconnect;
+       nm_device_team_error_get_type;
+       nm_device_team_error_quark;
+       nm_device_team_get_carrier;
+       nm_device_team_get_hw_address;
+       nm_device_team_get_slaves;
+       nm_device_team_get_type;
+       nm_device_team_new;
        nm_device_vlan_error_get_type;
        nm_device_vlan_error_quark;
        nm_device_vlan_get_carrier;
diff --git a/libnm-glib/nm-device-team.c b/libnm-glib/nm-device-team.c
new file mode 100644
index 0000000..e2254bb
--- /dev/null
+++ b/libnm-glib/nm-device-team.c
@@ -0,0 +1,337 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2013 Jiri Pirko <jiri resnulli us>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ */
+
+#include <config.h>
+#include <string.h>
+#include <netinet/ether.h>
+
+#include "nm-glib-compat.h"
+
+#include <nm-setting-connection.h>
+#include <nm-setting-team.h>
+#include <nm-utils.h>
+
+#include "nm-device-team.h"
+#include "nm-device-private.h"
+#include "nm-object-private.h"
+#include "nm-types.h"
+
+G_DEFINE_TYPE (NMDeviceTeam, nm_device_team, NM_TYPE_DEVICE)
+
+#define NM_DEVICE_TEAM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_TEAM, 
NMDeviceTeamPrivate))
+
+typedef struct {
+       DBusGProxy *proxy;
+
+       char *hw_address;
+       gboolean carrier;
+       GPtrArray *slaves;
+} NMDeviceTeamPrivate;
+
+enum {
+       PROP_0,
+       PROP_HW_ADDRESS,
+       PROP_CARRIER,
+       PROP_SLAVES,
+
+       LAST_PROP
+};
+
+#define DBUS_PROP_HW_ADDRESS "HwAddress"
+#define DBUS_PROP_CARRIER "Carrier"
+#define DBUS_PROP_SLAVES "Slaves"
+
+/**
+ * nm_device_team_error_quark:
+ *
+ * Registers an error quark for #NMDeviceTeam if necessary.
+ *
+ * Returns: the error quark used for #NMDeviceTeam errors.
+ **/
+GQuark
+nm_device_team_error_quark (void)
+{
+       static GQuark quark = 0;
+
+       if (G_UNLIKELY (quark == 0))
+               quark = g_quark_from_static_string ("nm-device-team-error-quark");
+       return quark;
+}
+
+/**
+ * nm_device_team_new:
+ * @connection: the #DBusGConnection
+ * @path: the DBus object path of the device
+ *
+ * Creates a new #NMDeviceTeam.
+ *
+ * Returns: (transfer full): a new device
+ **/
+GObject *
+nm_device_team_new (DBusGConnection *connection, const char *path)
+{
+       GObject *device;
+
+       g_return_val_if_fail (connection != NULL, NULL);
+       g_return_val_if_fail (path != NULL, NULL);
+
+       device = g_object_new (NM_TYPE_DEVICE_TEAM,
+                              NM_OBJECT_DBUS_CONNECTION, connection,
+                              NM_OBJECT_DBUS_PATH, path,
+                              NULL);
+       _nm_object_ensure_inited (NM_OBJECT (device));
+       return device;
+}
+
+/**
+ * nm_device_team_get_hw_address:
+ * @device: a #NMDeviceTeam
+ *
+ * Gets the hardware (MAC) address of the #NMDeviceTeam
+ *
+ * Returns: the hardware address. This is the internal string used by the
+ * device, and must not be modified.
+ **/
+const char *
+nm_device_team_get_hw_address (NMDeviceTeam *device)
+{
+       g_return_val_if_fail (NM_IS_DEVICE_TEAM (device), NULL);
+
+       _nm_object_ensure_inited (NM_OBJECT (device));
+       return NM_DEVICE_TEAM_GET_PRIVATE (device)->hw_address;
+}
+
+/**
+ * nm_device_team_get_carrier:
+ * @device: a #NMDeviceTeam
+ *
+ * Whether the device has carrier.
+ *
+ * Returns: %TRUE if the device has carrier
+ **/
+gboolean
+nm_device_team_get_carrier (NMDeviceTeam *device)
+{
+       g_return_val_if_fail (NM_IS_DEVICE_TEAM (device), FALSE);
+
+       _nm_object_ensure_inited (NM_OBJECT (device));
+       return NM_DEVICE_TEAM_GET_PRIVATE (device)->carrier;
+}
+
+/**
+ * nm_device_team_get_slaves:
+ * @device: a #NMDeviceTeam
+ *
+ * Gets the devices currently enslaved to @device.
+ *
+ * Returns: (element-type NMClient.Device): the #GPtrArray containing
+ * #NMDevice<!-- -->s that are slaves of @device. This is the internal
+ * copy used by the device, and must not be modified.
+ **/
+const GPtrArray *
+nm_device_team_get_slaves (NMDeviceTeam *device)
+{
+       g_return_val_if_fail (NM_IS_DEVICE_TEAM (device), FALSE);
+
+       _nm_object_ensure_inited (NM_OBJECT (device));
+       return handle_ptr_array_return (NM_DEVICE_TEAM_GET_PRIVATE (device)->slaves);
+}
+
+static gboolean
+connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
+{
+       NMSettingConnection *s_con;
+       NMSettingTeam *s_team;
+       const char *ctype, *dev_iface_name, *team_iface_name;
+
+       s_con = nm_connection_get_setting_connection (connection);
+       g_assert (s_con);
+
+       ctype = nm_setting_connection_get_connection_type (s_con);
+       if (strcmp (ctype, NM_SETTING_TEAM_SETTING_NAME) != 0) {
+               g_set_error (error, NM_DEVICE_TEAM_ERROR, NM_DEVICE_TEAM_ERROR_NOT_TEAM_CONNECTION,
+                            "The connection was not a team connection.");
+               return FALSE;
+       }
+
+       s_team = nm_connection_get_setting_team (connection);
+       if (!s_team) {
+               g_set_error (error, NM_DEVICE_TEAM_ERROR, NM_DEVICE_TEAM_ERROR_INVALID_TEAM_CONNECTION,
+                            "The connection was not a valid team connection.");
+               return FALSE;
+       }
+
+       dev_iface_name = nm_device_get_iface (device);
+       team_iface_name = nm_setting_team_get_interface_name (s_team);
+       if (g_strcmp0 (dev_iface_name, team_iface_name) != 0) {
+               g_set_error (error, NM_DEVICE_TEAM_ERROR, NM_DEVICE_TEAM_ERROR_INTERFACE_MISMATCH,
+                            "The interfaces of the device and the connection didn't match.");
+               return FALSE;
+       }
+
+       /* FIXME: check slaves? */
+
+       return NM_DEVICE_CLASS (nm_device_team_parent_class)->connection_compatible (device, connection, 
error);
+}
+
+/***********************************************************/
+
+static void
+nm_device_team_init (NMDeviceTeam *device)
+{
+       _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_TEAM);
+}
+
+static void
+register_properties (NMDeviceTeam *device)
+{
+       NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (device);
+       const NMPropertiesInfo property_info[] = {
+               { NM_DEVICE_TEAM_HW_ADDRESS, &priv->hw_address },
+               { NM_DEVICE_TEAM_CARRIER,    &priv->carrier },
+               { NM_DEVICE_TEAM_SLAVES,     &priv->slaves, NULL, NM_TYPE_DEVICE },
+               { NULL },
+       };
+
+       _nm_object_register_properties (NM_OBJECT (device),
+                                       priv->proxy,
+                                       property_info);
+}
+
+static void
+constructed (GObject *object)
+{
+       NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (object);
+
+       G_OBJECT_CLASS (nm_device_team_parent_class)->constructed (object);
+
+       priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, NM_DBUS_INTERFACE_DEVICE_TEAM);
+       register_properties (NM_DEVICE_TEAM (object));
+}
+
+static void
+dispose (GObject *object)
+{
+       NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (object);
+
+       g_clear_object (&priv->proxy);
+
+       if (priv->slaves) {
+               g_ptr_array_foreach (priv->slaves, (GFunc) g_object_unref, NULL);
+               g_ptr_array_free (priv->slaves, TRUE);
+               priv->slaves = NULL;
+       }
+
+       G_OBJECT_CLASS (nm_device_team_parent_class)->dispose (object);
+}
+
+static void
+finalize (GObject *object)
+{
+       NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (object);
+
+       g_free (priv->hw_address);
+
+       G_OBJECT_CLASS (nm_device_team_parent_class)->finalize (object);
+}
+
+static void
+get_property (GObject *object,
+              guint prop_id,
+              GValue *value,
+              GParamSpec *pspec)
+{
+       NMDeviceTeam *device = NM_DEVICE_TEAM (object);
+
+       _nm_object_ensure_inited (NM_OBJECT (object));
+
+       switch (prop_id) {
+       case PROP_HW_ADDRESS:
+               g_value_set_string (value, nm_device_team_get_hw_address (device));
+               break;
+       case PROP_CARRIER:
+               g_value_set_boolean (value, nm_device_team_get_carrier (device));
+               break;
+       case PROP_SLAVES:
+               g_value_set_boxed (value, nm_device_team_get_slaves (device));
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+static void
+nm_device_team_class_init (NMDeviceTeamClass *eth_class)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (eth_class);
+       NMDeviceClass *device_class = NM_DEVICE_CLASS (eth_class);
+
+       g_type_class_add_private (eth_class, sizeof (NMDeviceTeamPrivate));
+
+       /* virtual methods */
+       object_class->constructed = constructed;
+       object_class->dispose = dispose;
+       object_class->finalize = finalize;
+       object_class->get_property = get_property;
+       device_class->connection_compatible = connection_compatible;
+
+       /* properties */
+
+       /**
+        * NMDeviceTeam:hw-address:
+        *
+        * The hardware (MAC) address of the device.
+        **/
+       g_object_class_install_property
+               (object_class, PROP_HW_ADDRESS,
+                g_param_spec_string (NM_DEVICE_TEAM_HW_ADDRESS,
+                                     "Active MAC Address",
+                                     "Currently set hardware MAC address",
+                                     NULL,
+                                     G_PARAM_READABLE));
+
+       /**
+        * NMDeviceTeam:carrier:
+        *
+        * Whether the device has carrier.
+        **/
+       g_object_class_install_property
+               (object_class, PROP_CARRIER,
+                g_param_spec_boolean (NM_DEVICE_TEAM_CARRIER,
+                                      "Carrier",
+                                      "Carrier",
+                                      FALSE,
+                                      G_PARAM_READABLE));
+
+       /**
+        * NMDeviceTeam:slaves:
+        *
+        * The devices (#NMDevice) enslaved to the team device.
+        **/
+       g_object_class_install_property
+               (object_class, PROP_SLAVES,
+                g_param_spec_boxed (NM_DEVICE_TEAM_SLAVES,
+                                    "Slaves",
+                                    "Slaves",
+                                    NM_TYPE_OBJECT_ARRAY,
+                                    G_PARAM_READABLE));
+}
+
diff --git a/libnm-glib/nm-device-team.h b/libnm-glib/nm-device-team.h
new file mode 100644
index 0000000..9e848da
--- /dev/null
+++ b/libnm-glib/nm-device-team.h
@@ -0,0 +1,82 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2013 Jiri Pirko <jiri resnulli us>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ */
+
+#ifndef NM_DEVICE_TEAM_H
+#define NM_DEVICE_TEAM_H
+
+#include "nm-device.h"
+
+G_BEGIN_DECLS
+
+#define NM_TYPE_DEVICE_TEAM            (nm_device_team_get_type ())
+#define NM_DEVICE_TEAM(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_TEAM, 
NMDeviceTeam))
+#define NM_DEVICE_TEAM_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_TEAM, 
NMDeviceTeamClass))
+#define NM_IS_DEVICE_TEAM(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_TEAM))
+#define NM_IS_DEVICE_TEAM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_TEAM))
+#define NM_DEVICE_TEAM_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_TEAM, 
NMDeviceTeamClass))
+
+/**
+ * NMDeviceTeamError:
+ * @NM_DEVICE_TEAM_ERROR_UNKNOWN: unknown or unclassified error
+ * @NM_DEVICE_TEAM_ERROR_NOT_TEAM_CONNECTION: the connection was not of team type
+ * @NM_DEVICE_TEAM_ERROR_INVALID_TEAM_CONNECTION: the team connection was invalid
+ * @NM_DEVICE_TEAM_ERROR_INTERFACE_MISMATCH: the interfaces of the connection and the device mismatched
+ */
+typedef enum {
+       NM_DEVICE_TEAM_ERROR_UNKNOWN = 0,             /*< nick=UnknownError >*/
+       NM_DEVICE_TEAM_ERROR_NOT_TEAM_CONNECTION,     /*< nick=NotTeamConnection >*/
+       NM_DEVICE_TEAM_ERROR_INVALID_TEAM_CONNECTION, /*< nick=InvalidTeamConnection >*/
+       NM_DEVICE_TEAM_ERROR_INTERFACE_MISMATCH,      /*< nick=InterfaceMismatch >*/
+} NMDeviceTeamError;
+
+#define NM_DEVICE_TEAM_ERROR nm_device_team_error_quark ()
+GQuark nm_device_team_error_quark (void);
+
+#define NM_DEVICE_TEAM_HW_ADDRESS  "hw-address"
+#define NM_DEVICE_TEAM_CARRIER     "carrier"
+#define NM_DEVICE_TEAM_SLAVES      "slaves"
+
+typedef struct {
+       NMDevice parent;
+} NMDeviceTeam;
+
+typedef struct {
+       NMDeviceClass parent;
+
+       /* Padding for future expansion */
+       void (*_reserved1) (void);
+       void (*_reserved2) (void);
+       void (*_reserved3) (void);
+       void (*_reserved4) (void);
+       void (*_reserved5) (void);
+       void (*_reserved6) (void);
+} NMDeviceTeamClass;
+
+GType nm_device_team_get_type (void);
+
+GObject *nm_device_team_new (DBusGConnection *connection, const char *path);
+
+const char      *nm_device_team_get_hw_address (NMDeviceTeam *device);
+gboolean         nm_device_team_get_carrier    (NMDeviceTeam *device);
+const GPtrArray *nm_device_team_get_slaves     (NMDeviceTeam *device);
+
+G_END_DECLS
+
+#endif /* NM_DEVICE_TEAM_H */
diff --git a/libnm-glib/nm-device.c b/libnm-glib/nm-device.c
index a40d263..c68b38d 100644
--- a/libnm-glib/nm-device.c
+++ b/libnm-glib/nm-device.c
@@ -35,6 +35,7 @@
 #include "nm-device-wimax.h"
 #include "nm-device-infiniband.h"
 #include "nm-device-bond.h"
+#include "nm-device-team.h"
 #include "nm-device-bridge.h"
 #include "nm-device-vlan.h"
 #include "nm-device-generic.h"
@@ -298,6 +299,8 @@ _nm_device_gtype_from_dtype (NMDeviceType dtype)
                return NM_TYPE_DEVICE_INFINIBAND;
        case NM_DEVICE_TYPE_BOND:
                return NM_TYPE_DEVICE_BOND;
+       case NM_DEVICE_TYPE_TEAM:
+               return NM_TYPE_DEVICE_TEAM;
        case NM_DEVICE_TYPE_BRIDGE:
                return NM_TYPE_DEVICE_BRIDGE;
        case NM_DEVICE_TYPE_VLAN:
diff --git a/libnm-util/Makefile.am b/libnm-util/Makefile.am
index 7c92114..495a42d 100644
--- a/libnm-util/Makefile.am
+++ b/libnm-util/Makefile.am
@@ -18,6 +18,7 @@ libnm_util_include_HEADERS =          \
        nm-setting-adsl.h               \
        nm-setting-bluetooth.h          \
        nm-setting-bond.h               \
+       nm-setting-team.h               \
        nm-setting-bridge.h             \
        nm-setting-bridge-port.h        \
        nm-setting-connection.h         \
@@ -55,6 +56,7 @@ libnm_util_la_csources = \
        nm-setting-adsl.c               \
        nm-setting-bluetooth.c          \
        nm-setting-bond.c               \
+       nm-setting-team.c               \
        nm-setting-bridge.c             \
        nm-setting-bridge-port.c        \
        nm-setting-connection.c         \
diff --git a/libnm-util/libnm-util.ver b/libnm-util/libnm-util.ver
index e1101f7..f946fb3 100644
--- a/libnm-util/libnm-util.ver
+++ b/libnm-util/libnm-util.ver
@@ -18,6 +18,7 @@ global:
        nm_connection_get_setting_adsl;
        nm_connection_get_setting_bluetooth;
        nm_connection_get_setting_bond;
+       nm_connection_get_setting_team;
        nm_connection_get_setting_bridge;
        nm_connection_get_setting_bridge_port;
        nm_connection_get_setting_by_name;
@@ -205,6 +206,11 @@ global:
        nm_setting_bond_get_valid_options;
        nm_setting_bond_new;
        nm_setting_bond_remove_option;
+       nm_setting_team_error_quark;
+       nm_setting_team_get_interface_name;
+       nm_setting_team_get_type;
+       nm_setting_team_new;
+       nm_setting_team_get_config;
        nm_setting_bridge_error_get_type;
        nm_setting_bridge_error_quark;
        nm_setting_bridge_get_ageing_time;
diff --git a/libnm-util/nm-connection.c b/libnm-util/nm-connection.c
index 3101546..631fdae 100644
--- a/libnm-util/nm-connection.c
+++ b/libnm-util/nm-connection.c
@@ -48,6 +48,7 @@
 #include "nm-setting-vpn.h"
 #include "nm-setting-olpc-mesh.h"
 #include "nm-setting-bond.h"
+#include "nm-setting-team.h"
 #include "nm-setting-bridge.h"
 #include "nm-setting-bridge-port.h"
 #include "nm-setting-vlan.h"
@@ -1242,6 +1243,22 @@ nm_connection_get_setting_bond (NMConnection *connection)
 }
 
 /**
+ * nm_connection_get_setting_team:
+ * @connection: the #NMConnection
+ *
+ * A shortcut to return any #NMSettingTeam the connection might contain.
+ *
+ * Returns: (transfer none): an #NMSettingTeam if the connection contains one, otherwise %NULL
+ **/
+NMSettingTeam *
+nm_connection_get_setting_team (NMConnection *connection)
+{
+       g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
+
+       return (NMSettingTeam *) nm_connection_get_setting (connection, NM_TYPE_SETTING_TEAM);
+}
+
+/**
  * nm_connection_get_setting_bridge:
  * @connection: the #NMConnection
  *
diff --git a/libnm-util/nm-connection.h b/libnm-util/nm-connection.h
index e402a96..7897628 100644
--- a/libnm-util/nm-connection.h
+++ b/libnm-util/nm-connection.h
@@ -33,6 +33,7 @@
 #include <nm-setting-8021x.h>
 #include <nm-setting-bluetooth.h>
 #include <nm-setting-bond.h>
+#include <nm-setting-team.h>
 #include <nm-setting-bridge.h>
 #include <nm-setting-bridge-port.h>
 #include <nm-setting-cdma.h>
@@ -200,6 +201,7 @@ const char *  nm_connection_get_id        (NMConnection *connection);
 NMSetting8021x *           nm_connection_get_setting_802_1x            (NMConnection *connection);
 NMSettingBluetooth *       nm_connection_get_setting_bluetooth         (NMConnection *connection);
 NMSettingBond *            nm_connection_get_setting_bond              (NMConnection *connection);
+NMSettingTeam *            nm_connection_get_setting_team              (NMConnection *connection);
 NMSettingBridge *          nm_connection_get_setting_bridge            (NMConnection *connection);
 NMSettingBridgePort *      nm_connection_get_setting_bridge_port       (NMConnection *connection);
 NMSettingCdma *            nm_connection_get_setting_cdma              (NMConnection *connection);
diff --git a/libnm-util/nm-setting-team.c b/libnm-util/nm-setting-team.c
new file mode 100644
index 0000000..d52eeac
--- /dev/null
+++ b/libnm-util/nm-setting-team.c
@@ -0,0 +1,253 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2013 Jiri Pirko <jiri resnulli us>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ */
+
+#include <string.h>
+#include <stdlib.h>
+#include <dbus/dbus-glib.h>
+#include <glib/gi18n.h>
+
+#include "nm-setting-team.h"
+#include "nm-param-spec-specialized.h"
+#include "nm-utils.h"
+#include "nm-utils-private.h"
+#include "nm-dbus-glib-types.h"
+#include "nm-setting-private.h"
+
+/**
+ * SECTION:nm-setting-team
+ * @short_description: Describes connection properties for teams
+ * @include: nm-setting-team.h
+ *
+ * The #NMSettingTeam object is a #NMSetting subclass that describes properties
+ * necessary for team connections.
+ **/
+
+/**
+ * nm_setting_team_error_quark:
+ *
+ * Registers an error quark for #NMSettingTeam if necessary.
+ *
+ * Returns: the error quark used for #NMSettingTeam errors.
+ **/
+GQuark
+nm_setting_team_error_quark (void)
+{
+       static GQuark quark;
+
+       if (G_UNLIKELY (!quark))
+               quark = g_quark_from_static_string ("nm-setting-team-error-quark");
+       return quark;
+}
+
+
+G_DEFINE_TYPE_WITH_CODE (NMSettingTeam, nm_setting_team, NM_TYPE_SETTING,
+                         _nm_register_setting (NM_SETTING_TEAM_SETTING_NAME,
+                                               g_define_type_id,
+                                               1,
+                                               NM_SETTING_TEAM_ERROR))
+NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_TEAM)
+
+#define NM_SETTING_TEAM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_TEAM, 
NMSettingTeamPrivate))
+
+typedef struct {
+       char *interface_name;
+       char *config;
+} NMSettingTeamPrivate;
+
+enum {
+       PROP_0,
+       PROP_INTERFACE_NAME,
+       PROP_CONFIG,
+       LAST_PROP
+};
+
+/**
+ * nm_setting_team_new:
+ *
+ * Creates a new #NMSettingTeam object with default values.
+ *
+ * Returns: (transfer full): the new empty #NMSettingTeam object
+ **/
+NMSetting *
+nm_setting_team_new (void)
+{
+       return (NMSetting *) g_object_new (NM_TYPE_SETTING_TEAM, NULL);
+}
+
+/**
+ * nm_setting_team_get_interface_name:
+ * @setting: the #NMSettingTeam
+ *
+ * Returns: the #NMSettingTeam:interface-name property of the setting
+ **/
+const char *
+nm_setting_team_get_interface_name (NMSettingTeam *setting)
+{
+       g_return_val_if_fail (NM_IS_SETTING_TEAM (setting), NULL);
+
+       return NM_SETTING_TEAM_GET_PRIVATE (setting)->interface_name;
+}
+
+/**
+ * nm_setting_team_get_config:
+ * @setting: the #NMSettingTeam
+ *
+ * Returns: the #NMSettingTeam:config property of the setting
+ **/
+const char *
+nm_setting_team_get_config (NMSettingTeam *setting)
+{
+       g_return_val_if_fail (NM_IS_SETTING_TEAM (setting), NULL);
+
+       return NM_SETTING_TEAM_GET_PRIVATE (setting)->config;
+}
+
+static gboolean
+verify (NMSetting *setting, GSList *all_settings, GError **error)
+{
+       NMSettingTeamPrivate *priv = NM_SETTING_TEAM_GET_PRIVATE (setting);
+
+       if (!priv->interface_name || !strlen(priv->interface_name)) {
+               g_set_error_literal (error,
+                                    NM_SETTING_TEAM_ERROR,
+                                    NM_SETTING_TEAM_ERROR_MISSING_PROPERTY,
+                                    _("property is missing"));
+               g_prefix_error (error, "%s.%s: ", NM_SETTING_TEAM_SETTING_NAME, 
NM_SETTING_TEAM_INTERFACE_NAME);
+               return FALSE;
+       }
+
+       if (!nm_utils_iface_valid_name (priv->interface_name)) {
+               g_set_error_literal (error,
+                                    NM_SETTING_TEAM_ERROR,
+                                    NM_SETTING_TEAM_ERROR_INVALID_PROPERTY,
+                                    _("property is invalid"));
+               g_prefix_error (error, "%s.%s: ", NM_SETTING_TEAM_SETTING_NAME, 
NM_SETTING_TEAM_INTERFACE_NAME);
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
+static const char *
+get_virtual_iface_name (NMSetting *setting)
+{
+       NMSettingTeam *self = NM_SETTING_TEAM (setting);
+
+       return nm_setting_team_get_interface_name (self);
+}
+
+static void
+nm_setting_team_init (NMSettingTeam *setting)
+{
+       g_object_set (setting, NM_SETTING_NAME, NM_SETTING_TEAM_SETTING_NAME,
+                     NULL);
+}
+
+static void
+finalize (GObject *object)
+{
+       NMSettingTeamPrivate *priv = NM_SETTING_TEAM_GET_PRIVATE (object);
+
+       g_free (priv->interface_name);
+       g_free (priv->config);
+
+       G_OBJECT_CLASS (nm_setting_team_parent_class)->finalize (object);
+}
+
+static void
+set_property (GObject *object, guint prop_id,
+              const GValue *value, GParamSpec *pspec)
+{
+       NMSettingTeamPrivate *priv = NM_SETTING_TEAM_GET_PRIVATE (object);
+
+       switch (prop_id) {
+       case PROP_INTERFACE_NAME:
+               priv->interface_name = g_value_dup_string (value);
+               break;
+       case PROP_CONFIG:
+               priv->config = g_value_dup_string (value);
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+static void
+get_property (GObject *object, guint prop_id,
+              GValue *value, GParamSpec *pspec)
+{
+       NMSettingTeam *setting = NM_SETTING_TEAM (object);
+
+       switch (prop_id) {
+       case PROP_INTERFACE_NAME:
+               g_value_set_string (value, nm_setting_team_get_interface_name (setting));
+               break;
+       case PROP_CONFIG:
+               g_value_set_string (value, nm_setting_team_get_config (setting));
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+static void
+nm_setting_team_class_init (NMSettingTeamClass *setting_class)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
+       NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
+
+       g_type_class_add_private (setting_class, sizeof (NMSettingTeamPrivate));
+
+       /* virtual methods */
+       object_class->set_property = set_property;
+       object_class->get_property = get_property;
+       object_class->finalize     = finalize;
+       parent_class->verify       = verify;
+       parent_class->get_virtual_iface_name = get_virtual_iface_name;
+
+       /* Properties */
+       /**
+        * NMSettingTeam:interface-name:
+        *
+        * The name of the virtual in-kernel team network interface
+        **/
+       g_object_class_install_property
+               (object_class, PROP_INTERFACE_NAME,
+                g_param_spec_string (NM_SETTING_TEAM_INTERFACE_NAME,
+                                     "InterfaceName",
+                                     "The name of the virtual in-kernel team network interface",
+                                     NULL,
+                                     G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
+
+       /**
+        * NMSettingTeam:config:
+        *
+        * The config of team network interface
+        **/
+       g_object_class_install_property
+               (object_class, PROP_CONFIG,
+                g_param_spec_string (NM_SETTING_TEAM_CONFIG,
+                                     "Config",
+                                     "The config of team network interface",
+                                     NULL,
+                                     G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
+}
diff --git a/libnm-util/nm-setting-team.h b/libnm-util/nm-setting-team.h
new file mode 100644
index 0000000..d40b01c
--- /dev/null
+++ b/libnm-util/nm-setting-team.h
@@ -0,0 +1,78 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2013 Jiri Pirko <jiri resnulli us>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ */
+
+#ifndef NM_SETTING_TEAM_H
+#define NM_SETTING_TEAM_H
+
+#include <nm-setting.h>
+
+G_BEGIN_DECLS
+
+#define NM_TYPE_SETTING_TEAM            (nm_setting_team_get_type ())
+#define NM_SETTING_TEAM(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_TEAM, 
NMSettingTeam))
+#define NM_SETTING_TEAM_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_TEAM, 
NMSettingTeamClass))
+#define NM_IS_SETTING_TEAM(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_TEAM))
+#define NM_IS_SETTING_TEAM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_TEAM))
+#define NM_SETTING_TEAM_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_TEAM, 
NMSettingTeamClass))
+
+#define NM_SETTING_TEAM_SETTING_NAME "team"
+
+/**
+ * NMSettingTeamError:
+ * @NM_SETTING_TEAM_ERROR_UNKNOWN: unknown or unclassified error
+ * @NM_SETTING_TEAM_ERROR_INVALID_PROPERTY: the property was invalid
+ * @NM_SETTING_TEAM_ERROR_MISSING_PROPERTY: the property was missing and is
+ * required
+ */
+typedef enum {
+       NM_SETTING_TEAM_ERROR_UNKNOWN = 0,      /*< nick=UnknownError >*/
+       NM_SETTING_TEAM_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
+       NM_SETTING_TEAM_ERROR_MISSING_PROPERTY, /*< nick=MissingProperty >*/
+} NMSettingTeamError;
+
+#define NM_SETTING_TEAM_ERROR nm_setting_team_error_quark ()
+GQuark nm_setting_team_error_quark (void);
+
+#define NM_SETTING_TEAM_INTERFACE_NAME "interface-name"
+#define NM_SETTING_TEAM_CONFIG "config"
+
+typedef struct {
+       NMSetting parent;
+} NMSettingTeam;
+
+typedef struct {
+       NMSettingClass parent;
+
+       /* Padding for future expansion */
+       void (*_reserved1) (void);
+       void (*_reserved2) (void);
+       void (*_reserved3) (void);
+       void (*_reserved4) (void);
+} NMSettingTeamClass;
+
+GType nm_setting_team_get_type (void);
+
+NMSetting *  nm_setting_team_new                (void);
+const char * nm_setting_team_get_interface_name (NMSettingTeam *setting);
+const char * nm_setting_team_get_config (NMSettingTeam *setting);
+
+G_END_DECLS
+
+#endif /* NM_SETTING_TEAM_H */
diff --git a/src/Makefile.am b/src/Makefile.am
index e0a7125..44499ed 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -87,6 +87,8 @@ nm_sources = \
        devices/nm-device-olpc-mesh.c \
        devices/nm-device-olpc-mesh.h \
        devices/nm-device-private.h \
+       devices/nm-device-team.c \
+       devices/nm-device-team.h \
        devices/nm-device-tun.c \
        devices/nm-device-tun.h \
        devices/nm-device-veth.c \
@@ -320,6 +322,7 @@ glue_sources = \
        nm-device-macvlan-glue.h \
        nm-device-modem-glue.h \
        nm-device-olpc-mesh-glue.h \
+       nm-device-team-glue.h \
        nm-device-tun-glue.h \
        nm-device-veth-glue.h \
        nm-device-vlan-glue.h \
diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c
index 22f3e6b..51f0e21 100644
--- a/src/devices/nm-device-ethernet.c
+++ b/src/devices/nm-device-ethernet.c
@@ -50,6 +50,7 @@
 #include "nm-setting-8021x.h"
 #include "nm-setting-pppoe.h"
 #include "nm-setting-bond.h"
+#include "nm-setting-team.h"
 #include "ppp-manager/nm-ppp-manager.h"
 #include "nm-logging.h"
 #include "nm-utils.h"
diff --git a/src/devices/nm-device-team.c b/src/devices/nm-device-team.c
new file mode 100644
index 0000000..5052a8c
--- /dev/null
+++ b/src/devices/nm-device-team.c
@@ -0,0 +1,355 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager -- Network link manager
+ *
+ * Copyright (C) 2013 Jiri Pirko <jiri resnulli us>
+ *
+ * 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.
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+
+#include <netinet/ether.h>
+
+#include "nm-device-team.h"
+#include "nm-logging.h"
+#include "nm-utils.h"
+#include "NetworkManagerUtils.h"
+#include "nm-device-private.h"
+#include "nm-platform.h"
+#include "nm-dbus-glib-types.h"
+#include "nm-dbus-manager.h"
+#include "nm-enum-types.h"
+#include "nm-system.h"
+
+#include "nm-device-team-glue.h"
+
+
+G_DEFINE_TYPE (NMDeviceTeam, nm_device_team, NM_TYPE_DEVICE)
+
+#define NM_DEVICE_TEAM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_TEAM, 
NMDeviceTeamPrivate))
+
+#define NM_TEAM_ERROR (nm_team_error_quark ())
+
+typedef struct {
+       int dummy;
+} NMDeviceTeamPrivate;
+
+enum {
+       PROP_0,
+       PROP_SLAVES,
+
+       LAST_PROP
+};
+
+/******************************************************************/
+
+static GQuark
+nm_team_error_quark (void)
+{
+       static GQuark quark = 0;
+       if (!quark)
+               quark = g_quark_from_static_string ("nm-team-error");
+       return quark;
+}
+
+/******************************************************************/
+
+static guint32
+get_generic_capabilities (NMDevice *dev)
+{
+       return NM_DEVICE_CAP_CARRIER_DETECT;
+}
+
+static gboolean
+is_available (NMDevice *dev)
+{
+       if (NM_DEVICE_GET_CLASS (dev)->is_up)
+               return NM_DEVICE_GET_CLASS (dev)->is_up (dev);
+       return FALSE;
+}
+
+static gboolean
+check_connection_compatible (NMDevice *device,
+                             NMConnection *connection,
+                             GError **error)
+{
+       const char *iface;
+       NMSettingTeam *s_team;
+
+       if (!NM_DEVICE_CLASS (nm_device_team_parent_class)->check_connection_compatible (device, connection, 
error))
+               return FALSE;
+
+       s_team = nm_connection_get_setting_team (connection);
+       if (!s_team || !nm_connection_is_type (connection, NM_SETTING_TEAM_SETTING_NAME)) {
+               g_set_error (error, NM_TEAM_ERROR, NM_TEAM_ERROR_CONNECTION_NOT_TEAM,
+                            "The connection was not a team connection.");
+               return FALSE;
+       }
+
+       /* Team connections must specify the virtual interface name */
+       iface = nm_connection_get_virtual_iface_name (connection);
+       if (!iface || strcmp (nm_device_get_iface (device), iface)) {
+               g_set_error (error, NM_TEAM_ERROR, NM_TEAM_ERROR_CONNECTION_NOT_TEAM,
+                            "The team connection virtual interface name did not match.");
+               return FALSE;
+       }
+
+       /* FIXME: match team properties like mode, etc? */
+
+       return TRUE;
+}
+
+static gboolean
+complete_connection (NMDevice *device,
+                     NMConnection *connection,
+                     const char *specific_object,
+                     const GSList *existing_connections,
+                     GError **error)
+{
+       NMSettingTeam *s_team, *tmp;
+       guint32 i = 0;
+       char *name;
+       const GSList *iter;
+       gboolean found;
+
+       nm_utils_complete_generic (connection,
+                                  NM_SETTING_TEAM_SETTING_NAME,
+                                  existing_connections,
+                                  _("Team connection %d"),
+                                  NULL,
+                                  TRUE);
+
+       s_team = nm_connection_get_setting_team (connection);
+       if (!s_team) {
+               s_team = (NMSettingTeam *) nm_setting_team_new ();
+               nm_connection_add_setting (connection, NM_SETTING (s_team));
+       }
+
+       /* Grab the first name that doesn't exist in either our connections
+        * or a device on the system.
+        */
+       while (i < 500 && !nm_setting_team_get_interface_name (s_team)) {
+               name = g_strdup_printf ("team%u", i);
+               /* check interface names */
+               if (!nm_platform_link_exists (name)) {
+                       /* check existing team connections */
+                       for (iter = existing_connections, found = FALSE; iter; iter = g_slist_next (iter)) {
+                               NMConnection *candidate = iter->data;
+
+                               tmp = nm_connection_get_setting_team (candidate);
+                               if (tmp && nm_connection_is_type (candidate, NM_SETTING_TEAM_SETTING_NAME)) {
+                                       if (g_strcmp0 (nm_setting_team_get_interface_name (tmp), name) == 0) {
+                                               found = TRUE;
+                                               break;
+                                       }
+                               }
+                       }
+
+                       if (!found)
+                               g_object_set (G_OBJECT (s_team), NM_SETTING_TEAM_INTERFACE_NAME, name, NULL);
+               }
+
+               g_free (name);
+               i++;
+       }
+
+       return TRUE;
+}
+
+static gboolean
+match_l2_config (NMDevice *self, NMConnection *connection)
+{
+       /* FIXME */
+       return TRUE;
+}
+
+/******************************************************************/
+
+static NMActStageReturn
+act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
+{
+       NMActStageReturn ret = NM_ACT_STAGE_RETURN_SUCCESS;
+       NMConnection *connection;
+       NMSettingTeam *s_team;
+
+       g_return_val_if_fail (reason != NULL, NM_ACT_STAGE_RETURN_FAILURE);
+
+       ret = NM_DEVICE_CLASS (nm_device_team_parent_class)->act_stage1_prepare (dev, reason);
+       if (ret == NM_ACT_STAGE_RETURN_SUCCESS) {
+               connection = nm_device_get_connection (dev);
+               g_assert (connection);
+               s_team = nm_connection_get_setting_team (connection);
+               g_assert (s_team);
+       }
+       return ret;
+}
+
+static gboolean
+enslave_slave (NMDevice *device, NMDevice *slave, NMConnection *connection)
+{
+       gboolean success, no_firmware = FALSE;
+       const char *iface = nm_device_get_ip_iface (device);
+       const char *slave_iface = nm_device_get_ip_iface (slave);
+
+       nm_device_take_down (slave, TRUE);
+
+       success = nm_platform_link_enslave (nm_device_get_ip_ifindex (device),
+                                           nm_device_get_ip_ifindex (slave));
+
+       nm_device_bring_up (slave, TRUE, &no_firmware);
+
+       if (success) {
+               nm_log_info (LOGD_TEAM, "(%s): enslaved team port %s", iface, slave_iface);
+               g_object_notify (G_OBJECT (device), "slaves");
+       }
+
+       return success;
+}
+
+static gboolean
+release_slave (NMDevice *device, NMDevice *slave)
+{
+       gboolean success, no_firmware = FALSE;
+
+       success = nm_platform_link_release (nm_device_get_ip_ifindex (device),
+                                           nm_device_get_ip_ifindex (slave));
+
+       nm_log_info (LOGD_TEAM, "(%s): released team port %s (success %d)",
+                    nm_device_get_ip_iface (device),
+                    nm_device_get_ip_iface (slave),
+                    success);
+       g_object_notify (G_OBJECT (device), "slaves");
+
+       /* Kernel team code "closes" the port when releasing it, (which clears
+        * IFF_UP), so we must bring it back up here to ensure carrier changes and
+        * other state is noticed by the now-released port.
+        */
+       if (!nm_device_bring_up (slave, TRUE, &no_firmware)) {
+               nm_log_warn (LOGD_TEAM, "(%s): released team port could not be brought up.",
+                            nm_device_get_iface (slave));
+       }
+
+       return success;
+}
+
+/******************************************************************/
+
+NMDevice *
+nm_device_team_new (const char *udi, const char *iface)
+{
+       g_return_val_if_fail (udi != NULL, NULL);
+       g_return_val_if_fail (iface != NULL, NULL);
+
+       return (NMDevice *) g_object_new (NM_TYPE_DEVICE_TEAM,
+                                         NM_DEVICE_UDI, udi,
+                                         NM_DEVICE_IFACE, iface,
+                                         NM_DEVICE_DRIVER, "team",
+                                         NM_DEVICE_TYPE_DESC, "Team",
+                                         NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_TEAM,
+                                         NM_DEVICE_IS_MASTER, TRUE,
+                                         NULL);
+}
+
+static void
+constructed (GObject *object)
+{
+       G_OBJECT_CLASS (nm_device_team_parent_class)->constructed (object);
+
+       nm_log_dbg (LOGD_HW | LOGD_TEAM, "(%s): kernel ifindex %d",
+                   nm_device_get_iface (NM_DEVICE (object)),
+                   nm_device_get_ifindex (NM_DEVICE (object)));
+}
+
+static void
+nm_device_team_init (NMDeviceTeam * self)
+{
+}
+
+static void
+get_property (GObject *object, guint prop_id,
+              GValue *value, GParamSpec *pspec)
+{
+       GPtrArray *slaves;
+       GSList *list, *iter;
+
+       switch (prop_id) {
+               break;
+       case PROP_SLAVES:
+               slaves = g_ptr_array_new ();
+               list = nm_device_master_get_slaves (NM_DEVICE (object));
+               for (iter = list; iter; iter = iter->next)
+                       g_ptr_array_add (slaves, g_strdup (nm_device_get_path (NM_DEVICE (iter->data))));
+               g_slist_free (list);
+               g_value_take_boxed (value, slaves);
+               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)
+{
+       switch (prop_id) {
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+static void
+nm_device_team_class_init (NMDeviceTeamClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       NMDeviceClass *parent_class = NM_DEVICE_CLASS (klass);
+
+       g_type_class_add_private (object_class, sizeof (NMDeviceTeamPrivate));
+
+       /* virtual methods */
+       object_class->constructed = constructed;
+       object_class->get_property = get_property;
+       object_class->set_property = set_property;
+
+       parent_class->get_generic_capabilities = get_generic_capabilities;
+       parent_class->is_available = is_available;
+       parent_class->check_connection_compatible = check_connection_compatible;
+       parent_class->complete_connection = complete_connection;
+
+       parent_class->match_l2_config = match_l2_config;
+
+       parent_class->act_stage1_prepare = act_stage1_prepare;
+       parent_class->enslave_slave = enslave_slave;
+       parent_class->release_slave = release_slave;
+
+       /* properties */
+       g_object_class_install_property
+               (object_class, PROP_SLAVES,
+                g_param_spec_boxed (NM_DEVICE_TEAM_SLAVES,
+                                    "Slaves",
+                                    "Slaves",
+                                    DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH,
+                                    G_PARAM_READABLE));
+
+       nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
+                                               G_TYPE_FROM_CLASS (klass),
+                                               &dbus_glib_nm_device_team_object_info);
+
+       dbus_g_error_domain_register (NM_TEAM_ERROR, NULL, NM_TYPE_TEAM_ERROR);
+}
diff --git a/src/devices/nm-device-team.h b/src/devices/nm-device-team.h
new file mode 100644
index 0000000..1a10313
--- /dev/null
+++ b/src/devices/nm-device-team.h
@@ -0,0 +1,62 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager -- Network link manager
+ *
+ * Copyright (C) 2013 Jiri Pirko <jiri resnulli us>
+ *
+ * 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.
+ */
+
+#ifndef NM_DEVICE_TEAM_H
+#define NM_DEVICE_TEAM_H
+
+#include <glib-object.h>
+
+#include "nm-device.h"
+
+G_BEGIN_DECLS
+
+#define NM_TYPE_DEVICE_TEAM            (nm_device_team_get_type ())
+#define NM_DEVICE_TEAM(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_TEAM, 
NMDeviceTeam))
+#define NM_DEVICE_TEAM_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  NM_TYPE_DEVICE_TEAM, 
NMDeviceTeamClass))
+#define NM_IS_DEVICE_TEAM(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_TEAM))
+#define NM_IS_DEVICE_TEAM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  NM_TYPE_DEVICE_TEAM))
+#define NM_DEVICE_TEAM_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  NM_TYPE_DEVICE_TEAM, 
NMDeviceTeamClass))
+
+typedef enum {
+       NM_TEAM_ERROR_CONNECTION_NOT_TEAM = 0, /*< nick=ConnectionNotTeam >*/
+       NM_TEAM_ERROR_CONNECTION_INVALID,      /*< nick=ConnectionInvalid >*/
+       NM_TEAM_ERROR_CONNECTION_INCOMPATIBLE, /*< nick=ConnectionIncompatible >*/
+} NMTeamError;
+
+#define NM_DEVICE_TEAM_SLAVES "slaves"
+
+typedef struct {
+       NMDevice parent;
+} NMDeviceTeam;
+
+typedef struct {
+       NMDeviceClass parent;
+
+} NMDeviceTeamClass;
+
+
+GType nm_device_team_get_type (void);
+
+NMDevice *nm_device_team_new (const char *udi,
+                              const char *iface);
+
+G_END_DECLS
+
+#endif /* NM_DEVICE_TEAM_H */
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index f6cfadf..79a74ff 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -279,7 +279,7 @@ typedef struct {
        /* allow autoconnect feature */
        gboolean        autoconnect;
 
-       /* master interface for bridge/bond slave */
+       /* master interface for bridge/bond/team slave */
        NMDevice *      master;
        gboolean        enslaved;
 
@@ -799,16 +799,18 @@ nm_device_get_priority (NMDevice *dev)
                return 4;
        case NM_DEVICE_TYPE_BOND:
                return 5;
-       case NM_DEVICE_TYPE_VLAN:
+       case NM_DEVICE_TYPE_TEAM:
                return 6;
-       case NM_DEVICE_TYPE_MODEM:
+       case NM_DEVICE_TYPE_VLAN:
                return 7;
-       case NM_DEVICE_TYPE_BT:
+       case NM_DEVICE_TYPE_MODEM:
                return 8;
-       case NM_DEVICE_TYPE_WIFI:
+       case NM_DEVICE_TYPE_BT:
                return 9;
-       case NM_DEVICE_TYPE_OLPC_MESH:
+       case NM_DEVICE_TYPE_WIFI:
                return 10;
+       case NM_DEVICE_TYPE_OLPC_MESH:
+               return 11;
        default:
                return 20;
        }
@@ -894,8 +896,8 @@ free_slave_info (SlaveInfo *info)
  * @slave: the slave device to enslave
  * @connection: the slave device's connection
  *
- * If @dev is capable of enslaving other devices (ie it's a bridge, bond, etc)
- * then this function enslaves @slave.
+ * If @dev is capable of enslaving other devices (ie it's a bridge, bond, team,
+ * etc) then this function enslaves @slave.
  *
  * Returns: %TRUE on success, %FALSE on failure or if this device cannot enslave
  *  other devices.
@@ -948,8 +950,8 @@ nm_device_enslave_slave (NMDevice *dev, NMDevice *slave, NMConnection *connectio
  * @slave: the slave device to release
  * @failed: %TRUE if the release was unexpected, ie the master failed
  *
- * If @dev is capable of enslaving other devices (ie it's a bridge, bond, etc)
- * then this function releases the previously enslaved @slave.
+ * If @dev is capable of enslaving other devices (ie it's a bridge, bond, team,
+ * etc) then this function releases the previously enslaved @slave.
  *
  * Returns: %TRUE on success, %FALSE on failure, if this device cannot enslave
  *  other devices, or if @slave was never enslaved.
@@ -994,9 +996,9 @@ carrier_changed (NMDevice *device, gboolean carrier)
                return;
 
        if (nm_device_is_master (device)) {
-               /* Bridge/bond carrier does not affect its own activation, but
-                * when carrier comes on, if there are slaves waiting, it will
-                * restart them.
+               /* Bridge/bond/team carrier does not affect its own activation,
+                * but when carrier comes on, if there are slaves waiting,
+                * it will restart them.
                 */
                if (!carrier)
                        return;
@@ -1008,8 +1010,9 @@ carrier_changed (NMDevice *device, gboolean carrier)
 
                return;
        } else if (nm_device_get_enslaved (device) && !carrier) {
-               /* Slaves don't deactivate when they lose carrier; for bonds
-                * in particular that would be actively counterproductive.
+               /* Slaves don't deactivate when they lose carrier; for
+                * bonds/teams in particular that would be actively
+                * counterproductive.
                 */
                return;
        }
@@ -1161,7 +1164,7 @@ slave_state_changed (NMDevice *slave,
 
        if (release) {
                nm_device_release_one_slave (self, slave, FALSE);
-               /* Bridge/bond interfaces are left up until manually deactivated */
+               /* Bridge/bond/team interfaces are left up until manually deactivated */
                if (priv->slaves == NULL && priv->state == NM_DEVICE_STATE_ACTIVATED) {
                        nm_log_dbg (LOGD_DEVICE, "(%s): last slave removed; remaining activated",
                                    nm_device_get_iface (self));
@@ -1174,8 +1177,8 @@ slave_state_changed (NMDevice *slave,
  * @dev: the master device
  * @slave: the slave device to enslave
  *
- * If @dev is capable of enslaving other devices (ie it's a bridge, bond, etc)
- * then this function adds @slave to the slave list for later enslavement.
+ * If @dev is capable of enslaving other devices (ie it's a bridge, bond, team,
+ * etc) then this function adds @slave to the slave list for later enslavement.
  *
  * Returns: %TRUE on success, %FALSE on failure
  */
@@ -1246,7 +1249,7 @@ nm_device_master_get_slave_by_ifindex (NMDevice *dev, int ifindex)
  * nm_device_is_master:
  * @dev: the device
  *
- * Returns: whether @dev can enslave other devices (eg, bridge or bond)
+ * Returns: whether @dev can enslave other devices (eg, bridge or bond or team)
  */
 gboolean
 nm_device_is_master (NMDevice *dev)
@@ -1335,7 +1338,7 @@ nm_device_slave_notify_enslaved (NMDevice *dev,
  * @device: the #NMDevice
  *
  * Returns: %TRUE if the device is enslaved to a master device (eg bridge or
- * bond), %FALSE if not
+ * bond or team), %FALSE if not
  */
 gboolean
 nm_device_get_enslaved (NMDevice *device)
diff --git a/src/logging/nm-logging.c b/src/logging/nm-logging.c
index 1f45c55..69c9553 100644
--- a/src/logging/nm-logging.c
+++ b/src/logging/nm-logging.c
@@ -49,7 +49,7 @@ nm_log_handler (const gchar *log_domain,
         LOGD_SUPPLICANT | LOGD_AGENTS | LOGD_SETTINGS | LOGD_SUSPEND | \
         LOGD_CORE | LOGD_DEVICE | LOGD_OLPC_MESH | LOGD_WIMAX | \
         LOGD_INFINIBAND | LOGD_FIREWALL | LOGD_ADSL | LOGD_BOND | \
-        LOGD_VLAN | LOGD_BRIDGE)
+        LOGD_VLAN | LOGD_BRIDGE | LOGD_TEAM)
 
 #define LOGD_DEFAULT (LOGD_ALL & ~LOGD_WIFI_SCAN)
 
@@ -102,6 +102,7 @@ static const LogDesc domain_descs[] = {
        { LOGD_BOND,      "BOND" },
        { LOGD_VLAN,      "VLAN" },
        { LOGD_BRIDGE,    "BRIDGE" },
+       { LOGD_TEAM,      "TEAM" },
        { 0, NULL }
 };
 
diff --git a/src/logging/nm-logging.h b/src/logging/nm-logging.h
index c5df38f..ca16fb3 100644
--- a/src/logging/nm-logging.h
+++ b/src/logging/nm-logging.h
@@ -58,6 +58,7 @@ enum {
        LOGD_BOND       = 0x08000000,
        LOGD_VLAN       = 0x10000000,
        LOGD_BRIDGE     = 0x20000000,
+       LOGD_TEAM       = 0x40000000,
 };
 
 #define LOGD_DHCP (LOGD_DHCP4 | LOGD_DHCP6)
diff --git a/src/nm-activation-request.c b/src/nm-activation-request.c
index 359a68e..bd375e4 100644
--- a/src/nm-activation-request.c
+++ b/src/nm-activation-request.c
@@ -360,8 +360,8 @@ device_state_changed (NMDevice *device, GParamSpec *pspec, NMActRequest *self)
  *    existing connection made before this instance of NM started
  * @device: the device/interface to configure according to @connection
  * @master: if the activation depends on another device (ie, bond or bridge
- *    master to which this device will be enslaved) pass the #NMDevice that this
- *    activation request be enslaved to
+ *    or team master to which this device will be enslaved) pass the #NMDevice
+ *    that this activation request be enslaved to
  *
  * Begins activation of @device using the given @connection and other details.
  *
diff --git a/src/nm-manager.c b/src/nm-manager.c
index d6025f0..1ce7be4 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -48,6 +48,7 @@
 #include "nm-device-modem.h"
 #include "nm-device-infiniband.h"
 #include "nm-device-bond.h"
+#include "nm-device-team.h"
 #include "nm-device-bridge.h"
 #include "nm-device-vlan.h"
 #include "nm-device-adsl.h"
@@ -1096,6 +1097,9 @@ get_virtual_iface_name (NMManager *self,
        if (nm_connection_is_type (connection, NM_SETTING_BOND_SETTING_NAME))
                return g_strdup (nm_connection_get_virtual_iface_name (connection));
 
+       if (nm_connection_is_type (connection, NM_SETTING_TEAM_SETTING_NAME))
+               return g_strdup (nm_connection_get_virtual_iface_name (connection));
+
        if (nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME))
                return g_strdup (nm_connection_get_virtual_iface_name (connection));
 
@@ -1166,6 +1170,7 @@ static gboolean
 connection_needs_virtual_device (NMConnection *connection)
 {
        if (   nm_connection_is_type (connection, NM_SETTING_BOND_SETTING_NAME)
+           || nm_connection_is_type (connection, NM_SETTING_TEAM_SETTING_NAME)
            || nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME)
            || nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME))
                return TRUE;
@@ -1324,6 +1329,16 @@ system_create_virtual_device (NMManager *self, NMConnection *connection)
                udi = get_virtual_iface_placeholder_udi ();
                device = nm_device_bond_new (udi, iface);
                g_free (udi);
+       } else if (nm_connection_is_type (connection, NM_SETTING_TEAM_SETTING_NAME)) {
+               if (!nm_platform_team_add (iface)) {
+                       nm_log_warn (LOGD_DEVICE, "(%s): failed to add team master interface for '%s'",
+                                    iface, nm_connection_get_id (connection));
+                       goto out;
+               }
+
+               udi = get_virtual_iface_placeholder_udi ();
+               device = nm_device_team_new (udi, iface);
+               g_free (udi);
        } else if (nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME)) {
                gboolean result;
 
@@ -2305,6 +2320,9 @@ platform_link_added_cb (NMPlatform *platform,
                case NM_LINK_TYPE_BOND:
                        device = nm_device_bond_new (link->udi, link->name);
                        break;
+               case NM_LINK_TYPE_TEAM:
+                       device = nm_device_team_new (link->udi, link->name);
+                       break;
                case NM_LINK_TYPE_BRIDGE:
                        /* FIXME: always create device when we handle bridges non-destructively */
                        if (bridge_created_by_nm (self, link->name))
@@ -2693,7 +2711,9 @@ ensure_master_active_connection (NMManager *self,
                        for (iter = connections; iter; iter = g_slist_next (iter)) {
                                NMConnection *candidate = NM_CONNECTION (iter->data);
 
-                               /* Ensure eg bond slave and the candidate master is a bond master */
+                               /* Ensure eg bond/team slave and the candidate master is a
+                                * bond/team master
+                                */
                                if (!is_compatible_with_slave (candidate, connection))
                                        continue;
 
@@ -2908,10 +2928,11 @@ nm_manager_activate_connection (NMManager *manager,
                        }
                }
        } else {
-               /* Virtual connections (VLAN, bond, etc) may not specify a device
-                * path because the device may not be created yet, or it be given
-                * by the connection's properties instead.  Find the device the
-                * connection refers to, or create it if needed.
+               /* Virtual connections (VLAN, bond, team, etc) may not specify
+                * a device path because the device may not be created yet,
+                * or it be given by the connection's properties instead.
+                * Find the device the connection refers to, or create it
+                * if needed.
                 */
                if (!connection_needs_virtual_device (connection)) {
                        g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_DEVICE,
@@ -2989,7 +3010,9 @@ nm_manager_activate_connection (NMManager *manager,
                                    nm_device_get_ip_iface (master_device));
                }
 
-               /* Ensure eg bond slave and the candidate master is a bond master */
+               /* Ensure eg bond/team slave and the candidate master is
+                * a bond/team master
+                */
                if (master_connection && !is_compatible_with_slave (master_connection, connection)) {
                        g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_DEPENDENCY_FAILED,
                                                     "The master connection was not compatible");
-- 
1.8.1.4



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]