[PATCH 5/6] bridge: add bridge device type
- From: Thomas Graf <tgraf redhat com>
- To: networkmanager-list gnome org
- Cc: Thomas Graf <tgraf redhat com>
- Subject: [PATCH 5/6] bridge: add bridge device type
- Date: Wed, 23 May 2012 16:19:29 +0200
This adds a new device type 'bridge'. Kernel devices are created
on demand.
---
docs/libnm-glib/libnm-glib-docs.xml | 1 +
docs/libnm-glib/libnm-glib.types | 2 +
include/NetworkManager.h | 4 +
introspection/Makefile.am | 1 +
introspection/all.xml.in | 1 +
introspection/nm-device-bridge.xml | 27 ++
introspection/nm-device.xml | 5 +
libnm-glib/Makefile.am | 2 +
libnm-glib/libnm-glib.ver | 6 +
libnm-glib/nm-device-bridge.c | 301 +++++++++++++++++++
libnm-glib/nm-device-bridge.h | 82 +++++
libnm-glib/nm-device.c | 3 +
src/Makefile.am | 6 +
src/nm-device-bridge.c | 560 +++++++++++++++++++++++++++++++++++
src/nm-device-bridge.h | 65 ++++
src/nm-device-wired.c | 3 +
src/nm-manager.c | 28 ++-
src/nm-udev-manager.c | 3 +
18 files changed, 1097 insertions(+), 3 deletions(-)
create mode 100644 introspection/nm-device-bridge.xml
create mode 100644 libnm-glib/nm-device-bridge.c
create mode 100644 libnm-glib/nm-device-bridge.h
create mode 100644 src/nm-device-bridge.c
create mode 100644 src/nm-device-bridge.h
diff --git a/docs/libnm-glib/libnm-glib-docs.xml b/docs/libnm-glib/libnm-glib-docs.xml
index 7f855aa..0f8dc3a 100644
--- a/docs/libnm-glib/libnm-glib-docs.xml
+++ b/docs/libnm-glib/libnm-glib-docs.xml
@@ -89,6 +89,7 @@
<xi:include href="xml/nm-device-bt.xml"/>
<xi:include href="xml/nm-device-wimax.xml"/>
<xi:include href="xml/nm-device-bond.xml"/>
+ <xi:include href="xml/nm-device-bridge.xml"/>
<xi:include href="xml/nm-device-infiniband.xml"/>
<xi:include href="xml/nm-device-vlan.xml"/>
<xi:include href="xml/nm-device-olpc-mesh.xml"/>
diff --git a/docs/libnm-glib/libnm-glib.types b/docs/libnm-glib/libnm-glib.types
index 9f6419d..746bc8c 100644
--- a/docs/libnm-glib/libnm-glib.types
+++ b/docs/libnm-glib/libnm-glib.types
@@ -9,6 +9,7 @@
#include <nm-device-olpc-mesh.h>
#include <nm-device-infiniband.h>
#include <nm-device-bond.h>
+#include <nm-device-bridge.h>
#include <nm-device-vlan.h>
#include <nm-access-point.h>
#include <nm-ip4-config.h>
@@ -32,6 +33,7 @@ nm_device_wimax_get_type
nm_device_olpc_mesh_get_type
nm_device_infiniband_get_type
nm_device_bond_get_type
+nm_device_bridge_get_type
nm_device_vlan_get_type
nm_wimax_nsp_get_type
nm_access_point_get_type
diff --git a/include/NetworkManager.h b/include/NetworkManager.h
index 96b132e..954c928 100644
--- a/include/NetworkManager.h
+++ b/include/NetworkManager.h
@@ -52,6 +52,7 @@
#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_VLAN NM_DBUS_INTERFACE_DEVICE ".Vlan"
+#define NM_DBUS_INTERFACE_DEVICE_BRIDGE NM_DBUS_INTERFACE_DEVICE ".Bridge"
#define NM_DBUS_IFACE_SETTINGS "org.freedesktop.NetworkManager.Settings"
@@ -108,7 +109,9 @@ typedef enum {
* GSM/UMTS, or LTE network access protocols
* @NM_DEVICE_TYPE_INFINIBAND: an IP-over-InfiniBand device
* @NM_DEVICE_TYPE_BOND: a bond master interface
+ * @NM_DEVICE_TYPE_VLAN: a vlan interface
* @NM_DEVICE_TYPE_ADSL: ADSL modem
+ * @NM_DEVICE_TYPE_BRIDGE: a bridge interface
*
* #NMDeviceType values indicate the type of hardware represented by
* an #NMDevice.
@@ -127,6 +130,7 @@ typedef enum {
NM_DEVICE_TYPE_BOND = 10,
NM_DEVICE_TYPE_VLAN = 11,
NM_DEVICE_TYPE_ADSL = 12,
+ NM_DEVICE_TYPE_BRIDGE = 13,
} NMDeviceType;
/**
diff --git a/introspection/Makefile.am b/introspection/Makefile.am
index a267b51..3850a23 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-bridge.xml \
nm-device-vlan.xml \
nm-device.xml \
nm-ip4-config.xml \
diff --git a/introspection/all.xml.in b/introspection/all.xml.in
index e9e7b0e..a8cea61 100644
--- a/introspection/all.xml.in
+++ b/introspection/all.xml.in
@@ -36,6 +36,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.</
<xi:include href="nm-device-wimax.xml"/>
<xi:include href="nm-device-infiniband.xml"/>
<xi:include href="nm-device-bond.xml"/>
+<xi:include href="nm-device-bridge.xml"/>
<xi:include href="nm-device-vlan.xml"/>
<xi:include href="nm-device-adsl.xml"/>
<xi:include href="nm-wimax-nsp.xml"/>
diff --git a/introspection/nm-device-bridge.xml b/introspection/nm-device-bridge.xml
new file mode 100644
index 0000000..67ce419
--- /dev/null
+++ b/introspection/nm-device-bridge.xml
@@ -0,0 +1,27 @@
+<?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.Bridge">
+
+ <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>
+
+ <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/introspection/nm-device.xml b/introspection/nm-device.xml
index 2161bc4..d823c16 100644
--- a/introspection/nm-device.xml
+++ b/introspection/nm-device.xml
@@ -256,6 +256,11 @@
The device is a VLAN interface.
</tp:docstring>
</tp:enumvalue>
+ <tp:enumvalue suffix="BRIDGE" value="13">
+ <tp:docstring>
+ The device is a bridge interface.
+ </tp:docstring>
+ </tp:enumvalue>
</tp:enum>
<tp:flags name="NM_DEVICE_CAP" value-prefix="NM_DEVICE_CAP" type="u">
diff --git a/libnm-glib/Makefile.am b/libnm-glib/Makefile.am
index b5f8b16..8d4872d 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-bridge.h \
nm-device-vlan.h \
nm-access-point.h \
nm-ip4-config.h \
@@ -98,6 +99,7 @@ libnm_glib_la_csources = \
nm-device-bt.c \
nm-device-olpc-mesh.c \
nm-device-bond.c \
+ nm-device-bridge.c \
nm-device-vlan.c \
nm-access-point.c \
nm-ip4-config.c \
diff --git a/libnm-glib/libnm-glib.ver b/libnm-glib/libnm-glib.ver
index 7de80c7..efea678 100644
--- a/libnm-glib/libnm-glib.ver
+++ b/libnm-glib/libnm-glib.ver
@@ -69,6 +69,12 @@ global:
nm_device_bond_get_hw_address;
nm_device_bond_get_type;
nm_device_bond_new;
+ nm_device_bridge_error_get_type;
+ nm_device_bridge_error_quark;
+ nm_device_bridge_get_carrier;
+ nm_device_bridge_get_hw_address;
+ nm_device_bridge_get_type;
+ nm_device_bridge_new;
nm_device_bt_error_get_type;
nm_device_bt_error_quark;
nm_device_bt_get_capabilities;
diff --git a/libnm-glib/nm-device-bridge.c b/libnm-glib/nm-device-bridge.c
new file mode 100644
index 0000000..63a436f
--- /dev/null
+++ b/libnm-glib/nm-device-bridge.c
@@ -0,0 +1,301 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * libnm_glib -- Access network status & information from glib applications
+ *
+ * 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.
+ *
+ * Copyright (C) 2012 Red Hat, Inc.
+ */
+
+#include <config.h>
+#include <string.h>
+#include <netinet/ether.h>
+
+#include "nm-glib-compat.h"
+
+#include <nm-setting-connection.h>
+#include <nm-setting-bridge.h>
+#include <nm-utils.h>
+
+#include "nm-device-bridge.h"
+#include "nm-device-private.h"
+#include "nm-object-private.h"
+
+G_DEFINE_TYPE (NMDeviceBridge, nm_device_bridge, NM_TYPE_DEVICE)
+
+#define NM_DEVICE_BRIDGE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_BRIDGE, NMDeviceBridgePrivate))
+
+typedef struct {
+ DBusGProxy *proxy;
+
+ char *hw_address;
+ gboolean carrier;
+} NMDeviceBridgePrivate;
+
+enum {
+ PROP_0,
+ PROP_HW_ADDRESS,
+ PROP_CARRIER,
+
+ LAST_PROP
+};
+
+#define DBUS_PROP_HW_ADDRESS "HwAddress"
+#define DBUS_PROP_CARRIER "Carrier"
+
+/**
+ * nm_device_bridge_error_quark:
+ *
+ * Registers an error quark for #NMDeviceBridge if necessary.
+ *
+ * Returns: the error quark used for #NMDeviceBridge errors.
+ **/
+GQuark
+nm_device_bridge_error_quark (void)
+{
+ static GQuark quark = 0;
+
+ if (G_UNLIKELY (quark == 0))
+ quark = g_quark_from_static_string ("nm-device-bridge-error-quark");
+ return quark;
+}
+
+/**
+ * nm_device_bridge_new:
+ * @connection: the #DBusGConnection
+ * @path: the DBus object path of the device
+ *
+ * Creates a new #NMDeviceBridge.
+ *
+ * Returns: (transfer full): a new device
+ **/
+GObject *
+nm_device_bridge_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_BRIDGE,
+ NM_OBJECT_DBUS_CONNECTION, connection,
+ NM_OBJECT_DBUS_PATH, path,
+ NULL);
+ _nm_object_ensure_inited (NM_OBJECT (device));
+ return device;
+}
+
+/**
+ * nm_device_bridge_get_hw_address:
+ * @device: a #NMDeviceBridge
+ *
+ * Gets the hardware (MAC) address of the #NMDeviceBridge
+ *
+ * Returns: the hardware address. This is the internal string used by the
+ * device, and must not be modified.
+ **/
+const char *
+nm_device_bridge_get_hw_address (NMDeviceBridge *device)
+{
+ g_return_val_if_fail (NM_IS_DEVICE_BRIDGE (device), NULL);
+
+ _nm_object_ensure_inited (NM_OBJECT (device));
+ return NM_DEVICE_BRIDGE_GET_PRIVATE (device)->hw_address;
+}
+
+/**
+ * nm_device_bridge_get_carrier:
+ * @device: a #NMDeviceBridge
+ *
+ * Whether the device has carrier.
+ *
+ * Returns: %TRUE if the device has carrier
+ **/
+gboolean
+nm_device_bridge_get_carrier (NMDeviceBridge *device)
+{
+ g_return_val_if_fail (NM_IS_DEVICE_BRIDGE (device), FALSE);
+
+ _nm_object_ensure_inited (NM_OBJECT (device));
+ return NM_DEVICE_BRIDGE_GET_PRIVATE (device)->carrier;
+}
+
+static gboolean
+connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
+{
+ NMSettingConnection *s_con;
+ NMSettingBridge *s_bridge;
+ const char *ctype, *dev_iface_name, *bridge_iface_name;
+
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ 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_BRIDGE_SETTING_NAME) != 0) {
+ g_set_error (error, NM_DEVICE_BRIDGE_ERROR, NM_DEVICE_BRIDGE_ERROR_NOT_BRIDGE_CONNECTION,
+ "The connection was not a bridge connection.");
+ return FALSE;
+ }
+
+ s_bridge = nm_connection_get_setting_bridge (connection);
+ if (!s_bridge) {
+ g_set_error (error, NM_DEVICE_BRIDGE_ERROR, NM_DEVICE_BRIDGE_ERROR_INVALID_BRIDGE_CONNECTION,
+ "The connection was not a valid bridge connection.");
+ return FALSE;
+ }
+
+ dev_iface_name = nm_device_get_iface (device);
+ bridge_iface_name = nm_setting_bridge_get_interface_name (s_bridge);
+ if (g_strcmp0 (dev_iface_name, bridge_iface_name) != 0) {
+ g_set_error (error, NM_DEVICE_BRIDGE_ERROR, NM_DEVICE_BRIDGE_ERROR_INTERFACE_MISMATCH,
+ "The interfaces of the device and the connection didn't match.");
+ return FALSE;
+ }
+
+ /* FIXME: check slaves? But we can't... */
+
+ return TRUE;
+}
+
+/***********************************************************/
+
+static void
+nm_device_bridge_init (NMDeviceBridge *device)
+{
+ _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_BRIDGE);
+}
+
+static void
+register_properties (NMDeviceBridge *device)
+{
+ NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (device);
+ const NMPropertiesInfo property_info[] = {
+ { NM_DEVICE_BRIDGE_HW_ADDRESS, &priv->hw_address },
+ { NM_DEVICE_BRIDGE_CARRIER, &priv->carrier },
+ { NULL },
+ };
+
+ _nm_object_register_properties (NM_OBJECT (device),
+ priv->proxy,
+ property_info);
+}
+
+static void
+constructed (GObject *object)
+{
+ NMDeviceBridgePrivate *priv;
+
+ G_OBJECT_CLASS (nm_device_bridge_parent_class)->constructed (object);
+
+ priv = NM_DEVICE_BRIDGE_GET_PRIVATE (object);
+
+ priv->proxy = dbus_g_proxy_new_for_name (nm_object_get_connection (NM_OBJECT (object)),
+ NM_DBUS_SERVICE,
+ nm_object_get_path (NM_OBJECT (object)),
+ NM_DBUS_INTERFACE_DEVICE_BRIDGE);
+
+ register_properties (NM_DEVICE_BRIDGE (object));
+}
+
+static void
+dispose (GObject *object)
+{
+ NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (object);
+
+ g_clear_object (&priv->proxy);
+
+ G_OBJECT_CLASS (nm_device_bridge_parent_class)->dispose (object);
+}
+
+static void
+finalize (GObject *object)
+{
+ NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (object);
+
+ g_free (priv->hw_address);
+
+ G_OBJECT_CLASS (nm_device_bridge_parent_class)->finalize (object);
+}
+
+static void
+get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ NMDeviceBridge *device = NM_DEVICE_BRIDGE (object);
+
+ _nm_object_ensure_inited (NM_OBJECT (object));
+
+ switch (prop_id) {
+ case PROP_HW_ADDRESS:
+ g_value_set_string (value, nm_device_bridge_get_hw_address (device));
+ break;
+ case PROP_CARRIER:
+ g_value_set_boolean (value, nm_device_bridge_get_carrier (device));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+nm_device_bridge_class_init (NMDeviceBridgeClass *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 (NMDeviceBridgePrivate));
+
+ /* 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 */
+
+ /**
+ * NMDeviceBridge: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_BRIDGE_HW_ADDRESS,
+ "Active MAC Address",
+ "Currently set hardware MAC address",
+ NULL,
+ G_PARAM_READABLE));
+
+ /**
+ * NMDeviceBridge:carrier:
+ *
+ * Whether the device has carrier.
+ **/
+ g_object_class_install_property
+ (object_class, PROP_CARRIER,
+ g_param_spec_boolean (NM_DEVICE_BRIDGE_CARRIER,
+ "Carrier",
+ "Carrier",
+ FALSE,
+ G_PARAM_READABLE));
+
+}
diff --git a/libnm-glib/nm-device-bridge.h b/libnm-glib/nm-device-bridge.h
new file mode 100644
index 0000000..135c816
--- /dev/null
+++ b/libnm-glib/nm-device-bridge.h
@@ -0,0 +1,82 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * libnm_glib -- Access network status & information from glib applications
+ *
+ * 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.
+ *
+ * Copyright (C) 2012 Red Hat, Inc.
+ */
+
+#ifndef NM_DEVICE_BRIDGE_H
+#define NM_DEVICE_BRIDGE_H
+
+#include "nm-device.h"
+
+G_BEGIN_DECLS
+
+#define NM_TYPE_DEVICE_BRIDGE (nm_device_bridge_get_type ())
+#define NM_DEVICE_BRIDGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_BRIDGE, NMDeviceBridge))
+#define NM_DEVICE_BRIDGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_BRIDGE, NMDeviceBridgeClass))
+#define NM_IS_DEVICE_BRIDGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_BRIDGE))
+#define NM_IS_DEVICE_BRIDGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_DEVICE_BRIDGE))
+#define NM_DEVICE_BRIDGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_BRIDGE, NMDeviceBridgeClass))
+
+/**
+ * NMDeviceBridgeError:
+ * @NM_DEVICE_BRIDGE_ERROR_UNKNOWN: unknown or unclassified error
+ * @NM_DEVICE_BRIDGE_ERROR_NOT_BRIDGE_CONNECTION: the connection was not of bridge type
+ * @NM_DEVICE_BRIDGE_ERROR_INVALID_BRIDGE_CONNECTION: the bridge connection was invalid
+ * @NM_DEVICE_BRIDGE_ERROR_INTERFACE_MISMATCH: the interfaces of the connection and the device mismatched
+ */
+typedef enum {
+ NM_DEVICE_BRIDGE_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
+ NM_DEVICE_BRIDGE_ERROR_NOT_BRIDGE_CONNECTION, /*< nick=NotBridgeConnection >*/
+ NM_DEVICE_BRIDGE_ERROR_INVALID_BRIDGE_CONNECTION, /*< nick=InvalidBridgeConnection >*/
+ NM_DEVICE_BRIDGE_ERROR_INTERFACE_MISMATCH, /*< nick=InterfaceMismatch >*/
+} NMDeviceBridgeError;
+
+#define NM_DEVICE_BRIDGE_ERROR nm_device_bridge_error_quark ()
+GQuark nm_device_bridge_error_quark (void);
+
+#define NM_DEVICE_BRIDGE_HW_ADDRESS "hw-address"
+#define NM_DEVICE_BRIDGE_CARRIER "carrier"
+
+typedef struct {
+ NMDevice parent;
+} NMDeviceBridge;
+
+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);
+} NMDeviceBridgeClass;
+
+GType nm_device_bridge_get_type (void);
+
+GObject * nm_device_bridge_new (DBusGConnection *connection, const char *path);
+
+const char * nm_device_bridge_get_hw_address (NMDeviceBridge *device);
+gboolean nm_device_bridge_get_carrier (NMDeviceBridge *device);
+
+G_END_DECLS
+
+#endif /* NM_DEVICE_BRIDGE_H */
diff --git a/libnm-glib/nm-device.c b/libnm-glib/nm-device.c
index 6f79d81..a09010c 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-bridge.h"
#include "nm-device-vlan.h"
#include "nm-device.h"
#include "nm-device-private.h"
@@ -220,6 +221,8 @@ _nm_device_gtype_from_dtype (NMDeviceType dtype)
return NM_TYPE_DEVICE_BOND;
case NM_DEVICE_TYPE_VLAN:
return NM_TYPE_DEVICE_VLAN;
+ case NM_DEVICE_TYPE_BRIDGE:
+ return NM_TYPE_DEVICE_BRIDGE;
default:
g_warning ("Unknown device type %d", dtype);
return G_TYPE_INVALID;
diff --git a/src/Makefile.am b/src/Makefile.am
index 7930c28..8c2ca67 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -138,6 +138,8 @@ NetworkManager_SOURCES = \
nm-device-infiniband.h \
nm-device-bond.c \
nm-device-bond.h \
+ nm-device-bridge.c \
+ nm-device-bridge.h \
nm-device-vlan.c \
nm-device-vlan.h \
nm-wifi-ap.c \
@@ -239,6 +241,9 @@ nm-device-olpc-mesh-glue.h: $(top_srcdir)/introspection/nm-device-olpc-mesh.xml
nm-device-bond-glue.h: $(top_srcdir)/introspection/nm-device-bond.xml
$(AM_V_GEN) dbus-binding-tool --prefix=nm_device_bond --mode=glib-server --output=$@ $<
+nm-device-bridge-glue.h: $(top_srcdir)/introspection/nm-device-bridge.xml
+ $(AM_V_GEN) dbus-binding-tool --prefix=nm_device_bridge --mode=glib-server --output=$@ $<
+
nm-device-vlan-glue.h: $(top_srcdir)/introspection/nm-device-vlan.xml
$(AM_V_GEN) dbus-binding-tool --prefix=nm_device_vlan --mode=glib-server --output=$@ $<
@@ -267,6 +272,7 @@ BUILT_SOURCES = \
nm-device-ethernet-glue.h \
nm-device-infiniband-glue.h \
nm-device-bond-glue.h \
+ nm-device-bridge-glue.h \
nm-device-vlan-glue.h \
nm-device-adsl-glue.h \
nm-device-wifi-glue.h \
diff --git a/src/nm-device-bridge.c b/src/nm-device-bridge.c
new file mode 100644
index 0000000..729eb97
--- /dev/null
+++ b/src/nm-device-bridge.c
@@ -0,0 +1,560 @@
+/* -*- 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>
+
+#include <netinet/ether.h>
+
+#include "nm-device-bridge.h"
+#include "nm-logging.h"
+#include "nm-properties-changed-signal.h"
+#include "nm-utils.h"
+#include "NetworkManagerUtils.h"
+#include "nm-device-private.h"
+#include "nm-netlink-monitor.h"
+#include "nm-enum-types.h"
+#include "nm-system.h"
+
+#include "nm-device-bridge-glue.h"
+
+
+G_DEFINE_TYPE (NMDeviceBridge, nm_device_bridge, NM_TYPE_DEVICE_WIRED)
+
+#define NM_DEVICE_BRIDGE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_BRIDGE, NMDeviceBridgePrivate))
+
+#define NM_BRIDGE_ERROR (nm_bridge_error_quark ())
+
+typedef struct {
+ GSList *slaves;
+} NMDeviceBridgePrivate;
+
+enum {
+ PROPERTIES_CHANGED,
+
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+enum {
+ PROP_0,
+ PROP_HW_ADDRESS,
+ PROP_CARRIER,
+
+ LAST_PROP
+};
+
+/******************************************************************/
+
+static GQuark
+nm_bridge_error_quark (void)
+{
+ static GQuark quark = 0;
+ if (!quark)
+ quark = g_quark_from_static_string ("nm-bridge-error");
+ return quark;
+}
+
+/******************************************************************/
+
+static void
+device_state_changed (NMDevice *device,
+ NMDeviceState new_state,
+ NMDeviceState old_state,
+ NMDeviceStateReason reason,
+ gpointer user_data)
+{
+ if (new_state == NM_DEVICE_STATE_UNAVAILABLE) {
+ /* Use NM_DEVICE_STATE_REASON_CARRIER to make sure num retries is reset */
+ nm_device_queue_state (device, NM_DEVICE_STATE_DISCONNECTED, NM_DEVICE_STATE_REASON_CARRIER);
+ }
+}
+
+static void
+real_update_hw_address (NMDevice *dev)
+{
+ const guint8 *hw_addr;
+ guint8 old_addr[NM_UTILS_HWADDR_LEN_MAX];
+ int addrtype, addrlen;
+
+ addrtype = nm_device_wired_get_hwaddr_type (NM_DEVICE_WIRED (dev));
+ g_assert (addrtype >= 0);
+ addrlen = nm_utils_hwaddr_len (addrtype);
+ g_assert (addrlen > 0);
+
+ hw_addr = nm_device_wired_get_hwaddr (NM_DEVICE_WIRED (dev));
+ memcpy (old_addr, hw_addr, addrlen);
+
+ NM_DEVICE_CLASS (nm_device_bridge_parent_class)->update_hw_address (dev);
+
+ hw_addr = nm_device_wired_get_hwaddr (NM_DEVICE_WIRED (dev));
+ if (memcmp (old_addr, hw_addr, addrlen))
+ g_object_notify (G_OBJECT (dev), NM_DEVICE_BRIDGE_HW_ADDRESS);
+}
+
+static guint32
+real_get_generic_capabilities (NMDevice *dev)
+{
+ return NM_DEVICE_CAP_CARRIER_DETECT | NM_DEVICE_CAP_NM_SUPPORTED;
+}
+
+static gboolean
+match_bridge_connection (NMDevice *device, NMConnection *connection, GError **error)
+{
+ const char *iface;
+ NMSettingBridge *s_bridge;
+
+ s_bridge = nm_connection_get_setting_bridge (connection);
+ if (!s_bridge || !nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME)) {
+ g_set_error (error, NM_BRIDGE_ERROR, NM_BRIDGE_ERROR_CONNECTION_NOT_BRIDGE,
+ "The connection was not a bridge connection.");
+ return FALSE;
+ }
+
+ /* Bridge 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_BRIDGE_ERROR, NM_BRIDGE_ERROR_CONNECTION_NOT_BRIDGE,
+ "The bridge connection virtual interface name did not match.");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static NMConnection *
+real_get_best_auto_connection (NMDevice *dev,
+ GSList *connections,
+ char **specific_object)
+{
+ GSList *iter;
+
+ for (iter = connections; iter; iter = g_slist_next (iter)) {
+ NMConnection *connection = NM_CONNECTION (iter->data);
+ NMSettingConnection *s_con;
+
+ s_con = nm_connection_get_setting_connection (connection);
+ g_assert (s_con);
+ if ( nm_setting_connection_get_autoconnect (s_con)
+ && match_bridge_connection (dev, connection, NULL))
+ return connection;
+ }
+ return NULL;
+}
+
+static gboolean
+real_check_connection_compatible (NMDevice *device,
+ NMConnection *connection,
+ GError **error)
+{
+ return match_bridge_connection (device, connection, error);
+}
+
+static gboolean
+real_complete_connection (NMDevice *device,
+ NMConnection *connection,
+ const char *specific_object,
+ const GSList *existing_connections,
+ GError **error)
+{
+ NMSettingBridge *s_bridge, *tmp;
+ guint32 i = 0;
+ char *name;
+ const GSList *iter;
+ gboolean found;
+
+ nm_utils_complete_generic (connection,
+ NM_SETTING_BRIDGE_SETTING_NAME,
+ existing_connections,
+ _("Bridge connection %d"),
+ NULL,
+ TRUE);
+
+ s_bridge = nm_connection_get_setting_bridge (connection);
+ if (!s_bridge) {
+ s_bridge = (NMSettingBridge *) nm_setting_bridge_new ();
+ nm_connection_add_setting (connection, NM_SETTING (s_bridge));
+ }
+
+ /* Grab the first name that doesn't exist in either our connections
+ * or a device on the system.
+ */
+ while (i < 500 && !nm_setting_bridge_get_interface_name (s_bridge)) {
+ name = g_strdup_printf ("bridge%u", i);
+ /* check interface names */
+ if (nm_netlink_iface_to_index (name) < 0) {
+ /* check existing bridge connections */
+ for (iter = existing_connections, found = FALSE; iter; iter = g_slist_next (iter)) {
+ NMConnection *candidate = iter->data;
+
+ tmp = nm_connection_get_setting_bridge (candidate);
+ if (tmp && nm_connection_is_type (candidate, NM_SETTING_BRIDGE_SETTING_NAME)) {
+ if (g_strcmp0 (nm_setting_bridge_get_interface_name (tmp), name) == 0) {
+ found = TRUE;
+ break;
+ }
+ }
+ }
+
+ if (!found)
+ g_object_set (G_OBJECT (s_bridge), NM_SETTING_BRIDGE_INTERFACE_NAME, name, NULL);
+ }
+
+ g_free (name);
+ i++;
+ }
+
+ return TRUE;
+}
+
+static gboolean
+spec_match_list (NMDevice *device, const GSList *specs)
+{
+ char *hwaddr;
+ gboolean matched;
+
+ hwaddr = nm_utils_hwaddr_ntoa (nm_device_wired_get_hwaddr (NM_DEVICE_WIRED (device)), ARPHRD_ETHER);
+ matched = nm_match_spec_hwaddr (specs, hwaddr);
+ g_free (hwaddr);
+
+ return matched;
+}
+
+static gboolean
+bridge_match_config (NMDevice *self, NMConnection *connection)
+{
+ NMSettingBridge *s_bridge;
+ const char *ifname;
+
+ s_bridge = nm_connection_get_setting_bridge (connection);
+ if (!s_bridge)
+ return FALSE;
+
+ /* Interface name */
+ ifname = nm_setting_bridge_get_interface_name (s_bridge);
+ if (g_strcmp0 (ifname, nm_device_get_ip_iface (self)) != 0)
+ return FALSE;
+
+ return TRUE;
+}
+
+static NMConnection *
+connection_match_config (NMDevice *self, const GSList *connections)
+{
+ const GSList *iter;
+ GSList *bridge_matches;
+ NMConnection *match;
+
+ /* First narrow @connections down to those that match in their
+ * NMSettingBridge configuration.
+ */
+ bridge_matches = NULL;
+ for (iter = connections; iter; iter = iter->next) {
+ NMConnection *candidate = NM_CONNECTION (iter->data);
+
+ if (!nm_connection_is_type (candidate, NM_SETTING_BRIDGE_SETTING_NAME))
+ continue;
+ if (!bridge_match_config (self, candidate))
+ continue;
+
+ bridge_matches = g_slist_prepend (bridge_matches, candidate);
+ }
+
+ /* Now pass those to the super method, which will check IP config */
+ bridge_matches = g_slist_reverse (bridge_matches);
+ match = NM_DEVICE_CLASS (nm_device_bridge_parent_class)->connection_match_config (self, bridge_matches);
+ g_slist_free (bridge_matches);
+
+ return match;
+}
+
+/******************************************************************/
+
+static NMActStageReturn
+real_act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
+{
+ NMActStageReturn ret = NM_ACT_STAGE_RETURN_SUCCESS;
+#if 0
+ NMConnection *connection;
+ NMSettingBridge *s_bridge;
+#endif
+
+ g_return_val_if_fail (reason != NULL, NM_ACT_STAGE_RETURN_FAILURE);
+
+ ret = NM_DEVICE_CLASS (nm_device_bridge_parent_class)->act_stage1_prepare (dev, reason);
+ if (ret == NM_ACT_STAGE_RETURN_SUCCESS) {
+#if 0
+ connection = nm_device_get_connection (dev);
+ g_assert (connection);
+ s_bridge = nm_connection_get_setting_bridge (connection);
+ g_assert (s_bridge);
+#endif
+
+ /* FIXME: apply settings */
+ }
+ return ret;
+}
+
+static void
+slave_state_changed (NMDevice *slave,
+ NMDeviceState new_state,
+ NMDeviceState old_state,
+ NMDeviceStateReason reason,
+ gpointer user_data)
+{
+ NMDeviceBridge *self = NM_DEVICE_BRIDGE (user_data);
+
+ nm_log_dbg (LOGD_DEVICE, "(%s): slave %s state change %d -> %d",
+ nm_device_get_iface (NM_DEVICE (self)),
+ nm_device_get_iface (slave),
+ old_state,
+ new_state);
+
+ if ( old_state > NM_DEVICE_STATE_DISCONNECTED
+ && new_state <= NM_DEVICE_STATE_DISCONNECTED) {
+ /* Slave is no longer available or managed; can't use it */
+ nm_device_release_slave (NM_DEVICE (self), slave);
+ }
+}
+
+typedef struct {
+ NMDevice *slave;
+ guint state_id;
+} SlaveInfo;
+
+static SlaveInfo *
+find_slave_info_by_device (NMDeviceBridge *self, NMDevice *slave)
+{
+ NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (self);
+ GSList *iter;
+
+ for (iter = priv->slaves; iter; iter = g_slist_next (iter)) {
+ if (((SlaveInfo *) iter->data)->slave == slave)
+ return iter->data;
+ }
+ return NULL;
+}
+
+static void
+free_slave_info (SlaveInfo *sinfo)
+{
+ g_return_if_fail (sinfo != NULL);
+ g_return_if_fail (sinfo->slave != NULL);
+
+ g_signal_handler_disconnect (sinfo->slave, sinfo->state_id);
+ g_object_unref (sinfo->slave);
+ memset (sinfo, 0, sizeof (*sinfo));
+ g_free (sinfo);
+}
+
+static gboolean
+enslave_slave (NMDevice *device, NMDevice *slave)
+{
+ NMDeviceBridge *self = NM_DEVICE_BRIDGE (device);
+ NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (self);
+ gboolean success;
+
+ if (find_slave_info_by_device (self, slave))
+ return TRUE;
+
+ success = nm_system_bridge_attach (nm_device_get_ip_ifindex (device),
+ nm_device_get_ip_iface (device),
+ nm_device_get_ip_ifindex (slave),
+ nm_device_get_ip_iface (slave));
+ if (success) {
+ SlaveInfo *sinfo;
+
+ sinfo = g_malloc0 (sizeof (*slave));
+ sinfo->slave = g_object_ref (slave);
+ sinfo->state_id = g_signal_connect (slave,
+ "state-changed",
+ (GCallback) slave_state_changed,
+ self);
+ priv->slaves = g_slist_append (priv->slaves, sinfo);
+
+ nm_log_dbg (LOGD_DEVICE, "(%s): attached bridge component %s",
+ nm_device_get_ip_iface (device),
+ nm_device_get_ip_iface (slave));
+ }
+
+ return success;
+}
+
+static gboolean
+release_slave (NMDevice *device, NMDevice *slave)
+{
+ NMDeviceBridge *self = NM_DEVICE_BRIDGE (device);
+ NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (self);
+ gboolean success;
+ SlaveInfo *sinfo;
+
+ sinfo = find_slave_info_by_device (self, slave);
+ if (!sinfo)
+ return FALSE;
+
+ success = nm_system_bridge_detach (nm_device_get_ip_ifindex (device),
+ nm_device_get_ip_iface (device),
+ nm_device_get_ip_ifindex (slave),
+ nm_device_get_ip_iface (slave));
+ nm_log_dbg (LOGD_DEVICE, "(%s): detached bridge component %s (success %d)",
+ nm_device_get_ip_iface (device),
+ nm_device_get_ip_iface (slave),
+ success);
+ priv->slaves = g_slist_remove (priv->slaves, sinfo);
+ free_slave_info (sinfo);
+ return success;
+}
+
+/******************************************************************/
+
+NMDevice *
+nm_device_bridge_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_BRIDGE,
+ NM_DEVICE_UDI, udi,
+ NM_DEVICE_IFACE, iface,
+ NM_DEVICE_DRIVER, "bridge",
+ NM_DEVICE_TYPE_DESC, "Bridge",
+ NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_BRIDGE,
+ NULL);
+}
+
+static void
+constructed (GObject *object)
+{
+ G_OBJECT_CLASS (nm_device_bridge_parent_class)->constructed (object);
+
+ nm_log_dbg (LOGD_HW | LOGD_DEVICE, "(%s): kernel ifindex %d",
+ nm_device_get_iface (NM_DEVICE (object)),
+ nm_device_get_ifindex (NM_DEVICE (object)));
+}
+
+static void
+nm_device_bridge_init (NMDeviceBridge * self)
+{
+ g_signal_connect (self, "state-changed", G_CALLBACK (device_state_changed), NULL);
+}
+
+static void
+get_property (GObject *object, guint prop_id,
+ GValue *value, GParamSpec *pspec)
+{
+ const guint8 *current_addr;
+
+ switch (prop_id) {
+ case PROP_HW_ADDRESS:
+ current_addr = nm_device_wired_get_hwaddr (NM_DEVICE_WIRED (object));
+ g_value_take_string (value, nm_utils_hwaddr_ntoa (current_addr, ARPHRD_ETHER));
+ break;
+ case PROP_CARRIER:
+ g_value_set_boolean (value, nm_device_wired_get_carrier (NM_DEVICE_WIRED (object)));
+ 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
+dispose (GObject *object)
+{
+ NMDeviceBridge *self = NM_DEVICE_BRIDGE (object);
+ NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (self);
+ GSList *iter;
+
+ for (iter = priv->slaves; iter; iter = g_slist_next (iter))
+ release_slave (NM_DEVICE (self), ((SlaveInfo *) iter->data)->slave);
+ g_slist_free (priv->slaves);
+ priv->slaves = NULL;
+
+ G_OBJECT_CLASS (nm_device_bridge_parent_class)->dispose (object);
+}
+
+static void
+nm_device_bridge_class_init (NMDeviceBridgeClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ NMDeviceClass *parent_class = NM_DEVICE_CLASS (klass);
+
+ g_type_class_add_private (object_class, sizeof (NMDeviceBridgePrivate));
+
+ /* virtual methods */
+ object_class->constructed = constructed;
+ object_class->get_property = get_property;
+ object_class->set_property = set_property;
+ object_class->dispose = dispose;
+
+ parent_class->get_generic_capabilities = real_get_generic_capabilities;
+ parent_class->update_hw_address = real_update_hw_address;
+ parent_class->get_best_auto_connection = real_get_best_auto_connection;
+ parent_class->check_connection_compatible = real_check_connection_compatible;
+ parent_class->complete_connection = real_complete_connection;
+
+ parent_class->spec_match_list = spec_match_list;
+ parent_class->connection_match_config = connection_match_config;
+
+ parent_class->act_stage1_prepare = real_act_stage1_prepare;
+ parent_class->enslave_slave = enslave_slave;
+ parent_class->release_slave = release_slave;
+
+ /* properties */
+ g_object_class_install_property
+ (object_class, PROP_HW_ADDRESS,
+ g_param_spec_string (NM_DEVICE_BRIDGE_HW_ADDRESS,
+ "Active MAC Address",
+ "Currently set hardware MAC address",
+ NULL,
+ G_PARAM_READABLE));
+
+ g_object_class_install_property
+ (object_class, PROP_CARRIER,
+ g_param_spec_boolean (NM_DEVICE_BRIDGE_CARRIER,
+ "Carrier",
+ "Carrier",
+ FALSE,
+ G_PARAM_READABLE));
+
+ /* Signals */
+ signals[PROPERTIES_CHANGED] =
+ nm_properties_changed_signal_new (object_class,
+ G_STRUCT_OFFSET (NMDeviceBridgeClass, properties_changed));
+
+ dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (klass),
+ &dbus_glib_nm_device_bridge_object_info);
+
+ dbus_g_error_domain_register (NM_BRIDGE_ERROR, NULL, NM_TYPE_BRIDGE_ERROR);
+}
diff --git a/src/nm-device-bridge.h b/src/nm-device-bridge.h
new file mode 100644
index 0000000..0ab0775
--- /dev/null
+++ b/src/nm-device-bridge.h
@@ -0,0 +1,65 @@
+/* -*- 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 2012 Red Hat, Inc.
+ */
+
+#ifndef NM_DEVICE_BRIDGE_H
+#define NM_DEVICE_BRIDGE_H
+
+#include <glib-object.h>
+
+#include "nm-device-wired.h"
+
+G_BEGIN_DECLS
+
+#define NM_TYPE_DEVICE_BRIDGE (nm_device_bridge_get_type ())
+#define NM_DEVICE_BRIDGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_BRIDGE, NMDeviceBridge))
+#define NM_DEVICE_BRIDGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_BRIDGE, NMDeviceBridgeClass))
+#define NM_IS_DEVICE_BRIDGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_BRIDGE))
+#define NM_IS_DEVICE_BRIDGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_BRIDGE))
+#define NM_DEVICE_BRIDGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_BRIDGE, NMDeviceBridgeClass))
+
+typedef enum {
+ NM_BRIDGE_ERROR_CONNECTION_NOT_BRIDGE = 0, /*< nick=ConnectionNotBridge >*/
+ NM_BRIDGE_ERROR_CONNECTION_INVALID, /*< nick=ConnectionInvalid >*/
+ NM_BRIDGE_ERROR_CONNECTION_INCOMPATIBLE, /*< nick=ConnectionIncompatible >*/
+} NMBridgeError;
+
+#define NM_DEVICE_BRIDGE_HW_ADDRESS "hw-address"
+#define NM_DEVICE_BRIDGE_CARRIER "carrier"
+
+typedef struct {
+ NMDeviceWired parent;
+} NMDeviceBridge;
+
+typedef struct {
+ NMDeviceWiredClass parent;
+
+ /* Signals */
+ void (*properties_changed) (NMDeviceBridge *device, GHashTable *properties);
+} NMDeviceBridgeClass;
+
+
+GType nm_device_bridge_get_type (void);
+
+NMDevice *nm_device_bridge_new (const char *udi,
+ const char *iface);
+
+G_END_DECLS
+
+#endif /* NM_DEVICE_BRIDGE_H */
diff --git a/src/nm-device-wired.c b/src/nm-device-wired.c
index 60e5f26..47c93c0 100644
--- a/src/nm-device-wired.c
+++ b/src/nm-device-wired.c
@@ -304,6 +304,9 @@ constructor (GType type,
/* We may not know the hardware address type until a slave is added */
priv->hw_addr_type = ARPHRD_ETHER;
priv->hw_addr_len = ETH_ALEN;
+ } else if (nm_device_get_device_type (self) == NM_DEVICE_TYPE_BRIDGE) {
+ priv->hw_addr_type = ARPHRD_ETHER;
+ priv->hw_addr_len = ETH_ALEN;
} else
g_assert_not_reached ();
diff --git a/src/nm-manager.c b/src/nm-manager.c
index 7e03bc6..1b35c4e 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -47,6 +47,7 @@
#include "nm-device-modem.h"
#include "nm-device-infiniband.h"
#include "nm-device-bond.h"
+#include "nm-device-bridge.h"
#include "nm-device-vlan.h"
#include "nm-device-adsl.h"
#include "nm-system.h"
@@ -1015,6 +1016,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_BRIDGE_SETTING_NAME))
+ return g_strdup (nm_connection_get_virtual_iface_name (connection));
+
if (nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME)) {
NMSettingVlan *s_vlan;
const char *ifname;
@@ -1046,9 +1050,9 @@ get_virtual_iface_name (NMManager *self,
static gboolean
connection_needs_virtual_device (NMConnection *connection)
{
- if (nm_connection_is_type (connection, NM_SETTING_BOND_SETTING_NAME))
- return TRUE;
- if (nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME))
+ if ( nm_connection_is_type (connection, NM_SETTING_BOND_SETTING_NAME)
+ || nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME)
+ || nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME))
return TRUE;
return FALSE;
@@ -1110,6 +1114,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_BRIDGE_SETTING_NAME)) {
+ if (!nm_system_create_bridge (iface)) {
+ nm_log_warn (LOGD_DEVICE, "(%s): failed to add bridging interface for '%s'",
+ iface, nm_connection_get_id (connection));
+ goto out;
+ }
+
+ udi = get_virtual_iface_placeholder_udi ();
+ device = nm_device_bridge_new (udi, iface);
+ g_free (udi);
} else if (nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME)) {
g_return_val_if_fail (parent != NULL, FALSE);
@@ -2021,6 +2035,12 @@ is_bond (int ifindex)
}
static gboolean
+is_bridge (int ifindex)
+{
+ return (nm_system_get_iface_type (ifindex, NULL) == NM_IFACE_TYPE_BRIDGE);
+}
+
+static gboolean
is_vlan (int ifindex)
{
return (nm_system_get_iface_type (ifindex, NULL) == NM_IFACE_TYPE_VLAN);
@@ -2099,6 +2119,8 @@ udev_device_added_cb (NMUdevManager *udev_mgr,
device = nm_device_infiniband_new (sysfs_path, iface, driver);
else if (is_bond (ifindex))
device = nm_device_bond_new (sysfs_path, iface);
+ else if (is_bridge (ifindex))
+ device = nm_device_bridge_new (sysfs_path, iface);
else if (is_vlan (ifindex)) {
int parent_ifindex = -1;
NMDevice *parent;
diff --git a/src/nm-udev-manager.c b/src/nm-udev-manager.c
index 57b36d3..7bcc3e2 100644
--- a/src/nm-udev-manager.c
+++ b/src/nm-udev-manager.c
@@ -389,6 +389,9 @@ dev_get_attrs (GUdevDevice *udev_device,
case NM_IFACE_TYPE_BOND:
driver = "bonding";
break;
+ case NM_IFACE_TYPE_BRIDGE:
+ driver = "bridge";
+ break;
case NM_IFACE_TYPE_VLAN:
driver = "8021q";
break;
--
1.7.7.6
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]