[PATCH 3/6] bridge: add bridging settings class (NMSettingBridge)



Support to read/write bridging ifcfg files and convert it to
a NMSettingBridge. Test case included as well.
---
 docs/api/generate-settings-spec.c                  |    2 +
 docs/libnm-util/libnm-util-docs.sgml               |    1 +
 libnm-util/Makefile.am                             |    2 +
 libnm-util/libnm-util.ver                          |   13 +
 libnm-util/nm-connection.c                         |   25 +-
 libnm-util/nm-connection.h                         |    2 +
 libnm-util/nm-setting-bridge.c                     |  557 ++++++++++++++++++++
 libnm-util/nm-setting-bridge.h                     |  105 ++++
 src/settings/plugins/ifcfg-rh/reader.c             |  134 +++++-
 .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c         |  172 ++++++-
 src/settings/plugins/ifcfg-rh/writer.c             |   53 ++
 11 files changed, 1060 insertions(+), 6 deletions(-)
 create mode 100644 libnm-util/nm-setting-bridge.c
 create mode 100644 libnm-util/nm-setting-bridge.h

diff --git a/docs/api/generate-settings-spec.c b/docs/api/generate-settings-spec.c
index 7a540e3..9363c45 100644
--- a/docs/api/generate-settings-spec.c
+++ b/docs/api/generate-settings-spec.c
@@ -48,6 +48,7 @@
 #include <nm-setting-wireless-security.h>
 #include <nm-setting-infiniband.h>
 #include <nm-setting-bond.h>
+#include <nm-setting-bridge.h>
 #include <nm-setting-vlan.h>
 
 #include <nm-utils.h>
@@ -58,6 +59,7 @@ static SettingNewFunc funcs[] = {
 	nm_setting_802_1x_new,
 	nm_setting_bluetooth_new,
 	nm_setting_bond_new,
+	nm_setting_bridge_new,
 	nm_setting_cdma_new,
 	nm_setting_connection_new,
 	nm_setting_gsm_new,
diff --git a/docs/libnm-util/libnm-util-docs.sgml b/docs/libnm-util/libnm-util-docs.sgml
index f389971..6c6fffc 100644
--- a/docs/libnm-util/libnm-util-docs.sgml
+++ b/docs/libnm-util/libnm-util-docs.sgml
@@ -28,6 +28,7 @@
     <xi:include href="xml/nm-setting-gsm.xml"/>
     <xi:include href="xml/nm-setting-wimax.xml"/>
     <xi:include href="xml/nm-setting-bond.xml"/>
+    <xi:include href="xml/nm-setting-bridge.xml"/>
     <xi:include href="xml/nm-setting-infiniband.xml"/>
     <xi:include href="xml/nm-setting-vlan.xml"/>
     <xi:include href="xml/nm-setting-olpc-mesh.xml"/>
diff --git a/libnm-util/Makefile.am b/libnm-util/Makefile.am
index c4ea954..3bca469 100644
--- a/libnm-util/Makefile.am
+++ b/libnm-util/Makefile.am
@@ -19,6 +19,7 @@ libnm_util_include_HEADERS = 		\
 	nm-setting-adsl.h		\
 	nm-setting-bluetooth.h		\
 	nm-setting-bond.h		\
+	nm-setting-bridge.h		\
 	nm-setting-connection.h		\
 	nm-setting-infiniband.h		\
 	nm-setting-ip4-config.h		\
@@ -53,6 +54,7 @@ libnm_util_la_csources = \
 	nm-setting-adsl.c		\
 	nm-setting-bluetooth.c		\
 	nm-setting-bond.c		\
+	nm-setting-bridge.c		\
 	nm-setting-connection.c		\
 	nm-setting-infiniband.c		\
 	nm-setting-ip4-config.c		\
diff --git a/libnm-util/libnm-util.ver b/libnm-util/libnm-util.ver
index d8850a5..5a5916b 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_bridge;
 	nm_connection_get_setting_by_name;
 	nm_connection_get_setting_cdma;
 	nm_connection_get_setting_connection;
@@ -201,6 +202,18 @@ global:
 	nm_setting_bond_get_valid_options;
 	nm_setting_bond_new;
 	nm_setting_bond_remove_option;
+	nm_setting_bridge_add_option;
+	nm_setting_bridge_error_get_type;
+	nm_setting_bridge_error_quark;
+	nm_setting_bridge_get_interface_name;
+	nm_setting_bridge_get_num_options;
+	nm_setting_bridge_get_option;
+	nm_setting_bridge_get_option_by_name;
+	nm_setting_bridge_get_option_default;
+	nm_setting_bridge_get_type;
+	nm_setting_bridge_get_valid_options;
+	nm_setting_bridge_new;
+	nm_setting_bridge_remove_option;
 	nm_setting_cdma_error_get_type;
 	nm_setting_cdma_error_quark;
 	nm_setting_cdma_get_number;
diff --git a/libnm-util/nm-connection.c b/libnm-util/nm-connection.c
index 80a4996..818f56e 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-bridge.h"
 #include "nm-setting-vlan.h"
 #include "nm-setting-serial.h"
 #include "nm-setting-gsm.h"
@@ -118,7 +119,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
 
 static GHashTable *registered_settings = NULL;
 
-#define DEFAULT_MAP_SIZE 20
+#define DEFAULT_MAP_SIZE 21
 
 static struct SettingInfo {
 	const char *name;
@@ -230,6 +231,11 @@ register_default_settings (void)
 	                      NM_SETTING_BOND_ERROR,
 	                      1, TRUE);
 
+	register_one_setting (NM_SETTING_BRIDGE_SETTING_NAME,
+	                      NM_TYPE_SETTING_BRIDGE,
+	                      NM_SETTING_BRIDGE_ERROR,
+	                      1, TRUE);
+
 	register_one_setting (NM_SETTING_INFINIBAND_SETTING_NAME,
 	                      NM_TYPE_SETTING_INFINIBAND,
 	                      NM_SETTING_INFINIBAND_ERROR,
@@ -1410,6 +1416,23 @@ nm_connection_get_setting_bond (NMConnection *connection)
 }
 
 /**
+ * nm_connection_get_setting_bridge:
+ * @connection: the #NMConnection
+ *
+ * A shortcut to return any #NMSettingBridge the connection might contain.
+ *
+ * Returns: (transfer none): an #NMSettingBridge if the connection contains one, otherwise NULL
+ **/
+NMSettingBridge *
+nm_connection_get_setting_bridge (NMConnection *connection)
+{
+	g_return_val_if_fail (connection != NULL, NULL);
+	g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
+
+	return (NMSettingBridge *) nm_connection_get_setting (connection, NM_TYPE_SETTING_BRIDGE);
+}
+
+/**
  * nm_connection_get_setting_cdma:
  * @connection: the #NMConnection
  *
diff --git a/libnm-util/nm-connection.h b/libnm-util/nm-connection.h
index ca29d15..bb4017a 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-bridge.h>
 #include <nm-setting-cdma.h>
 #include <nm-setting-connection.h>
 #include <nm-setting-gsm.h>
@@ -188,6 +189,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);
+NMSettingBridge *          nm_connection_get_setting_bridge            (NMConnection *connection);
 NMSettingCdma *            nm_connection_get_setting_cdma              (NMConnection *connection);
 NMSettingConnection *      nm_connection_get_setting_connection        (NMConnection *connection);
 NMSettingGsm *             nm_connection_get_setting_gsm               (NMConnection *connection);
diff --git a/libnm-util/nm-setting-bridge.c b/libnm-util/nm-setting-bridge.c
new file mode 100644
index 0000000..01adfce
--- /dev/null
+++ b/libnm-util/nm-setting-bridge.c
@@ -0,0 +1,557 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+
+/*
+ * Thomas Graf <tgraf redhat com>
+ *
+ * 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.
+ *
+ * (C) Copyright 2011 - 2012 Red Hat, Inc.
+ */
+
+#include <string.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <dbus/dbus-glib.h>
+
+#include "nm-setting-bridge.h"
+#include "nm-param-spec-specialized.h"
+#include "nm-utils.h"
+#include "nm-utils-private.h"
+#include "nm-dbus-glib-types.h"
+
+/**
+ * SECTION:nm-setting-bridge
+ * @short_description: Describes connection properties for bridges
+ * @include: nm-setting-bridge.h
+ *
+ * The #NMSettingBridge object is a #NMSetting subclass that describes properties
+ * necessary for bridging connections.
+ **/
+
+/**
+ * nm_setting_bridge_error_quark:
+ *
+ * Registers an error quark for #NMSettingBridge if necessary.
+ *
+ * Returns: the error quark used for #NMSettingBridge errors.
+ **/
+GQuark
+nm_setting_bridge_error_quark (void)
+{
+	static GQuark quark;
+
+	if (G_UNLIKELY (!quark))
+		quark = g_quark_from_static_string ("nm-setting-bridge-error-quark");
+	return quark;
+}
+
+
+G_DEFINE_TYPE (NMSettingBridge, nm_setting_bridge, NM_TYPE_SETTING)
+
+#define NM_SETTING_BRIDGE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_BRIDGE, NMSettingBridgePrivate))
+
+typedef struct {
+	char *interface_name;
+	GHashTable *options;
+} NMSettingBridgePrivate;
+
+enum {
+	PROP_0,
+	PROP_INTERFACE_NAME,
+	PROP_OPTIONS,
+	LAST_PROP
+};
+
+typedef struct {
+	const char *opt;
+	const char *val;
+} BridgeDefault;
+
+static const BridgeDefault defaults[] = {
+	{ NM_SETTING_BRIDGE_OPTION_STP,           "yes" },
+	{ NM_SETTING_BRIDGE_OPTION_PRIO,          NULL  },
+	{ NM_SETTING_BRIDGE_OPTION_FORWARD_DELAY, "15"  },
+	{ NM_SETTING_BRIDGE_OPTION_HELLO_TIME,    "2"   },
+	{ NM_SETTING_BRIDGE_OPTION_MAX_AGE,       "20"  },
+	{ NM_SETTING_BRIDGE_OPTION_PATH_COST,     NULL  },
+	{ NM_SETTING_BRIDGE_OPTION_PORT_PRIO,     NULL  },
+	{ NM_SETTING_BRIDGE_OPTION_AGEING_TIME,   NULL  },
+};
+
+/**
+ * nm_setting_bridge_new:
+ *
+ * Creates a new #NMSettingBridge object with default values.
+ *
+ * Returns: (transfer full): the new empty #NMSettingBridge object
+ **/
+NMSetting *
+nm_setting_bridge_new (void)
+{
+	return (NMSetting *) g_object_new (NM_TYPE_SETTING_BRIDGE, NULL);
+}
+
+/**
+ * nm_setting_bridge_get_interface_name
+ * @setting: the #NMSettingBridge
+ *
+ * Returns: the #NMSettingBridge:interface-name property of the setting
+ **/
+const char *
+nm_setting_bridge_get_interface_name (NMSettingBridge *setting)
+{
+	g_return_val_if_fail (NM_IS_SETTING_BRIDGE (setting), 0);
+
+	return NM_SETTING_BRIDGE_GET_PRIVATE (setting)->interface_name;
+}
+
+/**
+ * nm_setting_bridge_get_num_options:
+ * @setting: the #NMSettingBridge
+ *
+ * Returns the number of options that should be set for this bridge when it
+ * is activated. This can be used to retrieve each option individually
+ * using nm_setting_bridge_get_option().
+ *
+ * Returns: the number of bridging options
+ **/
+guint32
+nm_setting_bridge_get_num_options (NMSettingBridge *setting)
+{
+	g_return_val_if_fail (NM_IS_SETTING_BRIDGE (setting), 0);
+
+	return g_hash_table_size (NM_SETTING_BRIDGE_GET_PRIVATE (setting)->options);
+}
+
+/**
+ * nm_setting_bridge_get_option:
+ * @setting: the #NMSettingBridge
+ * @idx: index of the desired option, from 0 to
+ * nm_setting_bridge_get_num_options() - 1
+ * @out_name: (out): on return, the name of the bridging option; this
+ * value is owned by the setting and should not be modified
+ * @out_value: (out): on return, the value of the name of the bridging
+ * option; this value is owned by the setting and should not be modified
+ *
+ * Given an index, return the value of the bridging option at that index.  Indexes
+ * are *not* guaranteed to be static across modifications to options done by
+ * nm_setting_bridge_add_option() and nm_setting_bridge_remove_option(),
+ * and should not be used to refer to options except for short periods of time
+ * such as during option iteration.
+ *
+ * Returns: %TRUE on success if the index was valid and an option was found,
+ * %FALSE if the index was invalid (ie, greater than the number of options
+ * currently held by the setting)
+ **/
+gboolean
+nm_setting_bridge_get_option (NMSettingBridge *setting,
+                              guint32 idx,
+                              const char **out_name,
+                              const char **out_value)
+{
+	NMSettingBridgePrivate *priv;
+	GList *keys;
+	const char *_key = NULL, *_value = NULL;
+
+	g_return_val_if_fail (NM_IS_SETTING_BRIDGE (setting), FALSE);
+
+	priv = NM_SETTING_BRIDGE_GET_PRIVATE (setting);
+
+	if (idx >= nm_setting_bridge_get_num_options (setting))
+		return FALSE;
+
+	keys = g_hash_table_get_keys (priv->options);
+	_key = g_list_nth_data (keys, idx);
+	_value = g_hash_table_lookup (priv->options, _key);
+
+	if (out_name)
+		*out_name = _key;
+	if (out_value)
+		*out_value = _value;
+
+	g_list_free (keys);
+	return TRUE;
+}
+
+static gboolean
+validate_option_name (const char *name)
+{
+	guint i;
+
+	g_return_val_if_fail (name != NULL, FALSE);
+	g_return_val_if_fail (name[0] != '\0', FALSE);
+
+	for (i = 0; i < G_N_ELEMENTS (defaults); i++) {
+		if (g_strcmp0 (defaults[i].opt, name) == 0)
+			return TRUE;
+	}
+	return FALSE;
+}
+
+/**
+ * nm_setting_bridge_get_option_by_name:
+ * @setting: the #NMSettingBridge
+ * @name: the option name for which to retrieve the value
+ *
+ * Returns the value associated with the briding option specified by
+ * @name, if it exists.
+ *
+ * Returns: the value, or %NULL if the key/value pair was never added to the
+ * setting; the value is owned by the setting and must not be modified
+ **/
+const char *
+nm_setting_bridge_get_option_by_name (NMSettingBridge *setting,
+                                      const char *name)
+{
+	g_return_val_if_fail (NM_IS_SETTING_BRIDGE (setting), NULL);
+	g_return_val_if_fail (validate_option_name (name), NULL);
+
+	return g_hash_table_lookup (NM_SETTING_BRIDGE_GET_PRIVATE (setting)->options, name);
+}
+
+/**
+ * nm_setting_bridge_add_option:
+ * @setting: the #NMSettingBridge
+ * @name: name for the option
+ * @value: value for the option
+ *
+ * Add an option to the table.  The option is compared to an internal list
+ * of allowed options.  Option names may contain only alphanumeric characters
+ * (ie [a-zA-Z0-9]).  Adding a new name replaces any existing name/value pair
+ * that may already exist.
+ *
+ * Returns: %TRUE if the option was valid and was added to the internal option
+ * list, %FALSE if it was not.
+ **/
+gboolean nm_setting_bridge_add_option (NMSettingBridge *setting,
+                                       const char *name,
+                                       const char *value)
+{
+	NMSettingBridgePrivate *priv;
+	size_t value_len;
+
+	g_return_val_if_fail (NM_IS_SETTING_BRIDGE (setting), FALSE);
+	g_return_val_if_fail (validate_option_name (name), FALSE);
+	g_return_val_if_fail (value != NULL, FALSE);
+
+	priv = NM_SETTING_BRIDGE_GET_PRIVATE (setting);
+
+	value_len = strlen (value);
+	g_return_val_if_fail (value_len > 0 && value_len < 200, FALSE);
+
+	g_hash_table_insert (priv->options, g_strdup (name), g_strdup (value));
+
+	return TRUE;
+}
+
+/**
+ * nm_setting_bridge_remove_option:
+ * @setting: the #NMSettingBridge
+ * @name: name of the option to remove
+ *
+ * Remove the briding option referenced by @name from the internal option
+ * list.
+ *
+ * Returns: %TRUE if the option was found and removed from the internal option
+ * list, %FALSE if it was not.
+ **/
+gboolean
+nm_setting_bridge_remove_option (NMSettingBridge *setting,
+                                 const char *name)
+{
+	g_return_val_if_fail (NM_IS_SETTING_BRIDGE (setting), FALSE);
+	g_return_val_if_fail (validate_option_name (name), FALSE);
+
+	return g_hash_table_remove (NM_SETTING_BRIDGE_GET_PRIVATE (setting)->options, name);
+}
+
+/**
+ * nm_setting_bridge_get_valid_options:
+ * @setting: the #NMSettingBridge
+ *
+ * Returns a list of valid bridge options.
+ *
+ * Returns: a NULL-terminated array of strings of valid bridge options.
+ **/
+const char **
+nm_setting_bridge_get_valid_options  (NMSettingBridge *setting)
+{
+	static const char *array[G_N_ELEMENTS (defaults) + 1] = { NULL };
+	int i;
+
+	/* initialize the array once */
+	if (G_UNLIKELY (array[0] == NULL)) {
+		for (i = 0; i < G_N_ELEMENTS (defaults); i++)
+			array[i] = defaults[i].opt;
+		array[i] = NULL;
+	}
+	return array;
+}
+
+/**
+ * nm_setting_bridge_get_option_default:
+ * @setting: the #NMSettingBridge
+ * @name: the name of the option
+ *
+ * Returns: the value of the bridge option if not overridden by an entry in
+ *   the #NMSettingBridge:options property.
+ **/
+const char *
+nm_setting_bridge_get_option_default (NMSettingBridge *setting, const char *name)
+{
+	guint i;
+
+	g_return_val_if_fail (NM_IS_SETTING_BRIDGE (setting), NULL);
+	g_return_val_if_fail (validate_option_name (name), NULL);
+
+	for (i = 0; i < G_N_ELEMENTS (defaults); i++) {
+		if (g_strcmp0 (defaults[i].opt, name) == 0)
+			return defaults[i].val;
+	}
+	/* Any option that passes validate_option_name() should also be found in defaults */
+	g_assert_not_reached ();
+}
+
+static gboolean
+check_range (NMSettingBridgePrivate *priv, const char *option, int min, int max,
+             GError **error)
+{
+	const char *value;
+
+	value = g_hash_table_lookup (priv->options, option);
+	if (value) {
+		int ival = atoi(value);
+		if (ival < min || ival > max) {
+			g_set_error (error,
+			             NM_SETTING_BRIDGE_ERROR,
+			             NM_SETTING_BRIDGE_ERROR_INVALID_OPTION,
+						 option);
+			return FALSE;
+		}
+	}
+
+	return TRUE;
+}
+
+static gboolean
+verify (NMSetting *setting, GSList *all_settings, GError **error)
+{
+	NMSettingBridgePrivate *priv = NM_SETTING_BRIDGE_GET_PRIVATE (setting);
+	GHashTableIter iter;
+	const char *key, *value;
+	const char *valid_stp[] = { "on", "off",
+	                            "yes", "no",
+	                            NULL };
+
+	if (!priv->interface_name || !strlen(priv->interface_name)) {
+		g_set_error (error,
+		             NM_SETTING_BRIDGE_ERROR,
+		             NM_SETTING_BRIDGE_ERROR_MISSING_PROPERTY,
+		             NM_SETTING_BRIDGE_INTERFACE_NAME);
+		return FALSE;
+	}
+
+	if (!nm_utils_iface_valid_name (priv->interface_name)) {
+		g_set_error (error,
+		             NM_SETTING_BRIDGE_ERROR,
+		             NM_SETTING_BRIDGE_ERROR_INVALID_PROPERTY,
+		             NM_SETTING_BRIDGE_INTERFACE_NAME);
+		return FALSE;
+	}
+
+	g_hash_table_iter_init (&iter, priv->options);
+	while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value)) {
+		if (   !validate_option_name (key)
+		    || !value[0]
+		    || (strlen (value) > 200)
+		    || strchr (value, ' ')) {
+			g_set_error_literal (error,
+			                     NM_SETTING_BRIDGE_ERROR,
+			                     NM_SETTING_BRIDGE_ERROR_INVALID_OPTION,
+			                     key);
+			return FALSE;
+		}
+	}
+
+	value = g_hash_table_lookup (priv->options, NM_SETTING_BRIDGE_OPTION_STP);
+	if (!_nm_utils_string_in_list (value, valid_stp)) {
+		g_set_error (error,
+		             NM_SETTING_BRIDGE_ERROR,
+		             NM_SETTING_BRIDGE_ERROR_INVALID_OPTION,
+		             NM_SETTING_BRIDGE_OPTION_STP);
+		return FALSE;
+	}
+
+	/* As documented in the kernel source and brctl(8) */
+	if (!check_range (priv, NM_SETTING_BRIDGE_OPTION_PRIO, 0, 65535, error))
+		return FALSE;
+
+	/* IEEE 802.1D-1998 limits */
+	if (!check_range (priv, NM_SETTING_BRIDGE_OPTION_FORWARD_DELAY, 0, 30, error))
+		return FALSE;
+
+	/* IEEE 802.1D-1998 limits */
+	if (!check_range (priv, NM_SETTING_BRIDGE_OPTION_HELLO_TIME, 1, 10, error))
+		return FALSE;
+
+	/* IEEE 802.1D-1998 limits */
+	if (!check_range (priv, NM_SETTING_BRIDGE_OPTION_MAX_AGE, 6, 40, error))
+		return FALSE;
+
+	/* IEEE 802.1D-1998 limits */
+	if (!check_range (priv, NM_SETTING_BRIDGE_OPTION_PATH_COST, 1, 65535, error))
+		return FALSE;
+
+	if (!check_range (priv, NM_SETTING_BRIDGE_OPTION_AGEING_TIME, 0, INT_MAX, error))
+		return FALSE;
+
+	/* enforce 8bit int */
+	if (!check_range (priv, NM_SETTING_BRIDGE_OPTION_PORT_PRIO, 0, 255, error))
+		return FALSE;
+
+	return TRUE;
+}
+
+static const char *
+get_virtual_iface_name (NMSetting *setting)
+{
+	NMSettingBridge *self = NM_SETTING_BRIDGE (setting);
+
+	return nm_setting_bridge_get_interface_name (self);
+}
+
+static void
+nm_setting_bridge_init (NMSettingBridge *setting)
+{
+	NMSettingBridgePrivate *priv = NM_SETTING_BRIDGE_GET_PRIVATE (setting);
+
+	g_object_set (setting, NM_SETTING_NAME, NM_SETTING_BRIDGE_SETTING_NAME,
+	              NULL);
+
+	priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+
+	/* Default values: */
+	nm_setting_bridge_add_option (setting, NM_SETTING_BRIDGE_OPTION_STP, "yes");
+}
+
+static void
+finalize (GObject *object)
+{
+	NMSettingBridgePrivate *priv = NM_SETTING_BRIDGE_GET_PRIVATE (object);
+
+	g_free (priv->interface_name);
+	g_hash_table_destroy (priv->options);
+
+	G_OBJECT_CLASS (nm_setting_bridge_parent_class)->finalize (object);
+}
+
+static void
+copy_hash (gpointer key, gpointer value, gpointer user_data)
+{
+	g_hash_table_insert ((GHashTable *) user_data, g_strdup (key), g_strdup (value));
+}
+
+static void
+set_property (GObject *object, guint prop_id,
+              const GValue *value, GParamSpec *pspec)
+{
+	NMSettingBridgePrivate *priv = NM_SETTING_BRIDGE_GET_PRIVATE (object);
+	GHashTable *new_hash;
+
+	switch (prop_id) {
+	case PROP_INTERFACE_NAME:
+		priv->interface_name = g_value_dup_string (value);
+		break;
+	case PROP_OPTIONS:
+		/* Must make a deep copy of the hash table here... */
+		g_hash_table_remove_all (priv->options);
+		new_hash = g_value_get_boxed (value);
+		if (new_hash)
+			g_hash_table_foreach (new_hash, copy_hash, priv->options);
+		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)
+{
+	NMSettingBridgePrivate *priv = NM_SETTING_BRIDGE_GET_PRIVATE (object);
+	NMSettingBridge *setting = NM_SETTING_BRIDGE (object);
+
+	switch (prop_id) {
+	case PROP_INTERFACE_NAME:
+		g_value_set_string (value, nm_setting_bridge_get_interface_name (setting));
+		break;
+	case PROP_OPTIONS:
+		g_value_set_boxed (value, priv->options);
+        break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+static void
+nm_setting_bridge_class_init (NMSettingBridgeClass *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 (NMSettingBridgePrivate));
+
+	/* 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 */
+	/**
+	 * NMSettingBridge:interface-name:
+	 *
+	 * The name of the virtual in-kernel briding network interface
+	 **/
+	g_object_class_install_property
+		(object_class, PROP_INTERFACE_NAME,
+		 g_param_spec_string (NM_SETTING_BRIDGE_INTERFACE_NAME,
+		                      "InterfaceName",
+		                      "The name of the virtual in-kernel bridging network interface",
+		                      NULL,
+		                      G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
+
+	/**
+	 * NMSettingBridge:options:
+	 *
+	 * Dictionary of key/value pairs of briding options.  Both keys
+	 * and values must be strings. Option names must contain only
+	 * alphanumeric characters (ie, [a-zA-Z0-9]).
+	 **/
+	 g_object_class_install_property
+		 (object_class, PROP_OPTIONS,
+		 _nm_param_spec_specialized (NM_SETTING_BRIDGE_OPTIONS,
+		                             "Options",
+		                             "Dictionary of key/value pairs of bridging "
+		                             "options.  Both keys and values must be "
+		                             "strings.  Option names must contain only "
+		                             "alphanumeric characters (ie, [a-zA-Z0-9]).",
+		                             DBUS_TYPE_G_MAP_OF_STRING,
+		                             G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
+}
diff --git a/libnm-util/nm-setting-bridge.h b/libnm-util/nm-setting-bridge.h
new file mode 100644
index 0000000..24121de
--- /dev/null
+++ b/libnm-util/nm-setting-bridge.h
@@ -0,0 +1,105 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+
+/*
+ * Thomas Graf <tgraf redhat com>
+ *
+ * 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.
+ *
+ * (C) Copyright 2011 - 2012 Red Hat, Inc.
+ */
+
+#ifndef NM_SETTING_BRIDGE_H
+#define NM_SETTING_BRIDGE_H
+
+#include <nm-setting.h>
+
+G_BEGIN_DECLS
+
+#define NM_TYPE_SETTING_BRIDGE            (nm_setting_bridge_get_type ())
+#define NM_SETTING_BRIDGE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_BRIDGE, NMSettingBridge))
+#define NM_SETTING_BRIDGE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_BRIDGE, NMSettingBridgeClass))
+#define NM_IS_SETTING_BRIDGE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_BRIDGE))
+#define NM_IS_SETTING_BRIDGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_SETTING_BRIDGE))
+#define NM_SETTING_BRIDGE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_BRIDGE, NMSettingBridgeClass))
+
+#define NM_SETTING_BRIDGE_SETTING_NAME "bridge"
+
+/**
+ * NMSettingBridgeError:
+ */
+typedef enum {
+	NM_SETTING_BRIDGE_ERROR_UNKNOWN = 0,      /*< nick=UnknownError >*/
+	NM_SETTING_BRIDGE_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
+	NM_SETTING_BRIDGE_ERROR_MISSING_PROPERTY, /*< nick=MissingProperty >*/
+	NM_SETTING_BRIDGE_ERROR_INVALID_OPTION,   /*< nick=InvalidOption >*/
+	NM_SETTING_BRIDGE_ERROR_MISSING_OPTION,   /*< nick=MissingOption >*/
+} NMSettingBridgeError;
+
+#define NM_SETTING_BRIDGE_ERROR nm_setting_bridge_error_quark ()
+GQuark nm_setting_bridge_error_quark (void);
+
+#define NM_SETTING_BRIDGE_INTERFACE_NAME "interface-name"
+#define NM_SETTING_BRIDGE_OPTIONS "options"
+
+/* Valid options for the 'options' property */
+#define NM_SETTING_BRIDGE_OPTION_STP           "stp"
+#define NM_SETTING_BRIDGE_OPTION_PRIO          "prio"
+#define NM_SETTING_BRIDGE_OPTION_FORWARD_DELAY "forward_delay"
+#define NM_SETTING_BRIDGE_OPTION_HELLO_TIME    "hello_time"
+#define NM_SETTING_BRIDGE_OPTION_MAX_AGE       "max_age"
+#define NM_SETTING_BRIDGE_OPTION_PATH_COST     "path_cost"
+#define NM_SETTING_BRIDGE_OPTION_PORT_PRIO     "port_prio"
+#define NM_SETTING_BRIDGE_OPTION_AGEING_TIME   "ageing_time"
+
+typedef struct {
+	NMSetting parent;
+} NMSettingBridge;
+
+typedef struct {
+	NMSettingClass parent;
+
+	/* Padding for future expansion */
+	void (*_reserved1) (void);
+	void (*_reserved2) (void);
+	void (*_reserved3) (void);
+	void (*_reserved4) (void);
+} NMSettingBridgeClass;
+
+GType nm_setting_bridge_get_type (void);
+
+NMSetting *  nm_setting_bridge_new                (void);
+const char * nm_setting_bridge_get_interface_name (NMSettingBridge *setting);
+guint32      nm_setting_bridge_get_num_options    (NMSettingBridge *setting);
+gboolean     nm_setting_bridge_get_option         (NMSettingBridge *setting,
+                                                   guint32 idx,
+                                                   const char **out_name,
+                                                   const char **out_value);
+const char * nm_setting_bridge_get_option_by_name (NMSettingBridge *setting,
+                                                   const char *name);
+gboolean     nm_setting_bridge_add_option         (NMSettingBridge *setting,
+                                                   const char *name,
+                                                   const char *value);
+gboolean     nm_setting_bridge_remove_option      (NMSettingBridge *setting,
+                                                   const char *name);
+
+const char **nm_setting_bridge_get_valid_options  (NMSettingBridge *setting);
+
+const char * nm_setting_bridge_get_option_default (NMSettingBridge *setting,
+                                                   const char *name);
+
+G_END_DECLS
+
+#endif /* NM_SETTING_BRIDGE_H */
diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c
index a2b08e4..8d490bf 100644
--- a/src/settings/plugins/ifcfg-rh/reader.c
+++ b/src/settings/plugins/ifcfg-rh/reader.c
@@ -45,6 +45,7 @@
 #include <nm-setting-wireless.h>
 #include <nm-setting-8021x.h>
 #include <nm-setting-bond.h>
+#include <nm-setting-bridge.h>
 #include <nm-utils.h>
 
 #include "wifi-utils.h"
@@ -3672,6 +3673,136 @@ bond_connection_from_ifcfg (const char *file,
 	return connection;
 }
 
+static void
+handle_bridge_option (NMSettingBridge *s_bridge,
+                      const char *key,
+                      const char *value)
+{
+	if (!nm_setting_bridge_add_option (s_bridge, key, value))
+		PLUGIN_WARN (IFCFG_PLUGIN_NAME, "    warning: invalid bridging option '%s'", key);
+}
+
+static NMSetting *
+make_bridge_setting (shvarFile *ifcfg,
+                     const char *file,
+                     gboolean nm_controlled,
+                     char **unmanaged,
+                     GError **error)
+{
+	NMSettingBridge *s_bridge;
+	char *value;
+
+	s_bridge = NM_SETTING_BRIDGE (nm_setting_bridge_new ());
+
+	value = svGetValue (ifcfg, "DEVICE", FALSE);
+	if (!value || !strlen (value)) {
+		g_set_error (error, IFCFG_PLUGIN_ERROR, 0, "mandatory DEVICE keyword missing");
+		goto error;
+	}
+
+	g_object_set (s_bridge, NM_SETTING_BRIDGE_INTERFACE_NAME, value, NULL);
+	g_free (value);
+
+	value = svGetValue (ifcfg, "STP", FALSE);
+	if (value) {
+		nm_setting_bridge_add_option (s_bridge, NM_SETTING_BRIDGE_OPTION_STP, value);
+		g_free (value);
+	}
+
+	value = svGetValue (ifcfg, "DELAY", FALSE);
+	if (value) {
+		nm_setting_bridge_add_option (s_bridge, NM_SETTING_BRIDGE_OPTION_FORWARD_DELAY, value);
+		g_free (value);
+	}
+
+	value = svGetValue (ifcfg, "BRIDGING_OPTS", FALSE);
+	if (value) {
+		char **items, **iter;
+
+		items = g_strsplit_set (value, " ", -1);
+		for (iter = items; iter && *iter; iter++) {
+			if (strlen (*iter)) {
+				char **keys, *key, *val;
+
+				keys = g_strsplit_set (*iter, "=", 2);
+				if (keys && *keys) {
+					key = *keys;
+					val = *(keys + 1);
+					if (val && strlen(key) && strlen(val))
+						handle_bridge_option (s_bridge, key, val);
+				}
+
+				g_strfreev (keys);
+			}
+		}
+		g_free (value);
+		g_strfreev (items);
+	}
+
+	return (NMSetting *) s_bridge;
+
+error:
+	g_object_unref (s_bridge);
+	return NULL;
+}
+
+static NMConnection *
+bridge_connection_from_ifcfg (const char *file,
+                              shvarFile *ifcfg,
+                              gboolean nm_controlled,
+                              char **unmanaged,
+                              GError **error)
+{
+	NMConnection *connection = NULL;
+	NMSetting *con_setting = NULL;
+	NMSetting *bridge_setting = NULL;
+	NMSetting *wired_setting = NULL;
+	NMSetting8021x *s_8021x = NULL;
+
+	g_return_val_if_fail (file != NULL, NULL);
+	g_return_val_if_fail (ifcfg != NULL, NULL);
+
+	connection = nm_connection_new ();
+	if (!connection) {
+		g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
+		             "Failed to allocate new connection for %s.", file);
+		return NULL;
+	}
+
+	con_setting = make_connection_setting (file, ifcfg, NM_SETTING_BRIDGE_SETTING_NAME, NULL, _("Bridge"));
+	if (!con_setting) {
+		g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
+		             "Failed to create connection setting.");
+		g_object_unref (connection);
+		return NULL;
+	}
+	nm_connection_add_setting (connection, con_setting);
+
+	bridge_setting = make_bridge_setting (ifcfg, file, nm_controlled, unmanaged, error);
+	if (!bridge_setting) {
+		g_object_unref (connection);
+		return NULL;
+	}
+	nm_connection_add_setting (connection, bridge_setting);
+
+	wired_setting = make_wired_setting (ifcfg, file, nm_controlled, unmanaged, &s_8021x, error);
+	if (!wired_setting) {
+		g_object_unref (connection);
+		return NULL;
+	}
+	nm_connection_add_setting (connection, wired_setting);
+
+	if (s_8021x)
+		nm_connection_add_setting (connection, NM_SETTING (s_8021x));
+
+	if (!nm_connection_verify (connection, error)) {
+		g_object_unref (connection);
+		return NULL;
+	}
+
+	return connection;
+}
+
 static gboolean
 is_bond_device (const char *name, shvarFile *parsed)
 {
@@ -4048,8 +4179,7 @@ connection_from_file (const char *filename,
 	else if (!strcasecmp (type, TYPE_VLAN))
 		connection = vlan_connection_from_ifcfg (filename, parsed, nm_controlled, unmanaged, &error);
 	else if (!strcasecmp (type, TYPE_BRIDGE))
-		g_set_error (&error, IFCFG_PLUGIN_ERROR, 0,
-		             "Bridge connections are not yet supported");
+		connection = bridge_connection_from_ifcfg (filename, parsed, nm_controlled, unmanaged, &error);
 	else {
 		g_set_error (&error, IFCFG_PLUGIN_ERROR, 0,
 		             "Unknown connection type '%s'", type);
diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
index 62882a7..fa25dce 100644
--- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
+++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
@@ -11784,6 +11784,7 @@ static void
 test_read_bridge_main (void)
 {
 	NMConnection *connection;
+	NMSettingBridge *s_bridge;
 	char *unmanaged = NULL;
 	char *keyfile = NULL;
 	char *routefile = NULL;
@@ -11801,13 +11802,176 @@ test_read_bridge_main (void)
 	                                   &route6file,
 	                                   &error,
 	                                   &ignore_error);
-	ASSERT (connection == NULL,
-	        "bridge-main-read", "unexpected success reading %s", TEST_IFCFG_BRIDGE_MAIN);
+	ASSERT (connection != NULL,
+	        "bridge-main-read", "unexpected failure reading %s", TEST_IFCFG_BRIDGE_MAIN);
+
+	ASSERT (nm_connection_verify (connection, &error),
+	        "bridge-main-read", "failed to verify %s: %s", TEST_IFCFG_BRIDGE_MAIN, error->message);
+
+	/* ===== Bridging SETTING ===== */
+
+	s_bridge = nm_connection_get_setting_bridge (connection);
+	ASSERT (s_bridge != NULL,
+	        "bridge-main", "failed to verify %s: missing %s setting",
+	        TEST_IFCFG_BRIDGE_MAIN,
+	        NM_SETTING_BRIDGE_SETTING_NAME);
+
+	ASSERT (g_strcmp0 (nm_setting_bridge_get_interface_name (s_bridge), "br0") == 0,
+	        "bridge-main", "failed to verify %s: DEVICE=%s does not match br0",
+	        TEST_IFCFG_BRIDGE_MAIN, nm_setting_bridge_get_interface_name (s_bridge));
+
+	ASSERT (g_strcmp0 (nm_setting_bridge_get_option_by_name (s_bridge, NM_SETTING_BRIDGE_OPTION_FORWARD_DELAY), "0") == 0,
+	        "bridge-main", "failed to verify %s: DELAY=%s does not match 0",
+	        TEST_IFCFG_BRIDGE_MAIN, nm_setting_bridge_get_option_by_name (s_bridge, NM_SETTING_BRIDGE_OPTION_FORWARD_DELAY));
+
+	ASSERT (g_strcmp0 (nm_setting_bridge_get_option_by_name (s_bridge, NM_SETTING_BRIDGE_OPTION_STP), "on") == 0,
+	        "bridge-main", "failed to verify %s: STP=%s does not match \"on\"",
+	        TEST_IFCFG_BRIDGE_MAIN, nm_setting_bridge_get_option_by_name (s_bridge, NM_SETTING_BRIDGE_OPTION_STP));
+
+	g_free (unmanaged);
+	g_free (keyfile);
+	g_free (routefile);
+	g_free (route6file);
+	g_object_unref (connection);
+}
+
+static void
+test_write_bridge_main (void)
+{
+	NMConnection *connection;
+	NMConnection *reread;
+	NMSettingConnection *s_con;
+	NMSettingBridge *s_bridge;
+	NMSettingIP4Config *s_ip4;
+	NMSettingIP6Config *s_ip6;
+	NMSettingWired *s_wired;
+	char *uuid;
+	const guint32 ip1 = htonl (0x01010103);
+	const guint32 gw = htonl (0x01010101);
+	const guint32 prefix = 24;
+	NMIP4Address *addr;
+	gboolean success;
+	GError *error = NULL;
+	char *testfile = NULL;
+	char *unmanaged = NULL;
+	char *keyfile = NULL;
+	char *routefile = NULL;
+	char *route6file = NULL;
+	gboolean ignore_error = FALSE;
+
+	connection = nm_connection_new ();
+	ASSERT (connection != NULL,
+	        "bridge-main-write", "failed to allocate new connection");
+
+	/* Connection setting */
+	s_con = (NMSettingConnection *) nm_setting_connection_new ();
+	ASSERT (s_con != NULL,
+	        "bridge-main-write", "failed to allocate new %s setting",
+	        NM_SETTING_CONNECTION_SETTING_NAME);
+	nm_connection_add_setting (connection, NM_SETTING (s_con));
+
+	uuid = nm_utils_uuid_generate ();
+	g_object_set (s_con,
+	              NM_SETTING_CONNECTION_ID, "Test Write Bridge Main",
+	              NM_SETTING_CONNECTION_UUID, uuid,
+	              NM_SETTING_CONNECTION_AUTOCONNECT, TRUE,
+	              NM_SETTING_CONNECTION_TYPE, NM_SETTING_BRIDGE_SETTING_NAME,
+	              NULL);
+	g_free (uuid);
+
+	/* Wired setting */
+	s_wired = (NMSettingWired *) nm_setting_wired_new ();
+	ASSERT (s_wired != NULL,
+	        "bridge-main-write", "failed to allocate new %s setting",
+	        NM_SETTING_WIRED_SETTING_NAME);
+	nm_connection_add_setting (connection, NM_SETTING (s_wired));
+
+	/* bridge setting */
+	s_bridge = (NMSettingBridge *) nm_setting_bridge_new ();
+	ASSERT (s_bridge != NULL,
+	        "bridge-main-write", "failed to allocate new %s setting",
+	        NM_SETTING_BRIDGE_SETTING_NAME);
+	nm_connection_add_setting (connection, NM_SETTING (s_bridge));
+
+	g_object_set (s_bridge,
+	              NM_SETTING_BRIDGE_INTERFACE_NAME, "br0",
+	              NULL);
+
+	/* IP4 setting */
+	s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+	ASSERT (s_ip4 != NULL,
+			"bridge-main-write", "failed to allocate new %s setting",
+			NM_SETTING_IP4_CONFIG_SETTING_NAME);
+	nm_connection_add_setting (connection, NM_SETTING (s_ip4));
+
+	g_object_set (s_ip4,
+	              NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
+	              NM_SETTING_IP4_CONFIG_MAY_FAIL, TRUE,
+	              NULL);
+
+	addr = nm_ip4_address_new ();
+	nm_ip4_address_set_address (addr, ip1);
+	nm_ip4_address_set_prefix (addr, prefix);
+	nm_ip4_address_set_gateway (addr, gw);
+	nm_setting_ip4_config_add_address (s_ip4, addr);
+	nm_ip4_address_unref (addr);
+
+	/* IP6 setting */
+	s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+	ASSERT (s_ip6 != NULL,
+	        "bridge-main-write", "failed to allocate new %s setting",
+	        NM_SETTING_IP6_CONFIG_SETTING_NAME);
+	nm_connection_add_setting (connection, NM_SETTING (s_ip6));
+
+	g_object_set (s_ip6,
+	              NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
+	              NULL);
+
+	ASSERT (nm_connection_verify (connection, &error) == TRUE,
+	        "bridge-main-write", "failed to verify connection: %s",
+	        (error && error->message) ? error->message : "(unknown)");
+
+	/* Save the ifcfg */
+	success = writer_new_connection (connection,
+	                                 TEST_SCRATCH_DIR "/network-scripts/",
+	                                 &testfile,
+	                                 &error);
+	ASSERT (success == TRUE,
+	        "bridge-main-write", "failed to write connection to disk: %s",
+	        (error && error->message) ? error->message : "(unknown)");
+
+	ASSERT (testfile != NULL,
+	        "bridge-main-write", "didn't get ifcfg file path back after writing connection");
+
+	/* re-read the connection for comparison */
+	reread = connection_from_file (testfile,
+	                               NULL,
+	                               TYPE_BRIDGE,
+	                               NULL,
+	                               &unmanaged,
+	                               &keyfile,
+	                               &routefile,
+	                               &route6file,
+	                               &error,
+	                               &ignore_error);
+	unlink (testfile);
+
+	ASSERT (reread != NULL,
+	        "bridge-main-write-reread", "failed to read %s: %s", testfile, error->message);
+
+	ASSERT (nm_connection_verify (reread, &error),
+	        "bridge-main-write-reread-verify", "failed to verify %s: %s", testfile, error->message);
 
+	ASSERT (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT) == TRUE,
+	        "bridge-main-write", "written and re-read connection weren't the same.");
+
+	g_free (testfile);
 	g_free (unmanaged);
 	g_free (keyfile);
 	g_free (routefile);
 	g_free (route6file);
+	g_object_unref (connection);
+	g_object_unref (reread);
 }
 
 #define TEST_IFCFG_BRIDGE_COMPONENT TEST_IFCFG_DIR"/network-scripts/ifcfg-test-bridge-component"
@@ -12890,12 +13054,14 @@ int main (int argc, char **argv)
 	test_write_bond_main ();
 	test_write_bond_slave ();
 
+	test_read_bridge_main ();
+	test_write_bridge_main ();
+
 	/* Stuff we expect to fail for now */
 	test_write_wired_pppoe ();
 	test_write_vpn ();
 	test_write_mobile_broadband (TRUE);
 	test_write_mobile_broadband (FALSE);
-	test_read_bridge_main ();
 	test_read_bridge_component ();
 
 	base = g_path_get_basename (argv[0]);
diff --git a/src/settings/plugins/ifcfg-rh/writer.c b/src/settings/plugins/ifcfg-rh/writer.c
index a431a30..7e4ce77 100644
--- a/src/settings/plugins/ifcfg-rh/writer.c
+++ b/src/settings/plugins/ifcfg-rh/writer.c
@@ -1254,6 +1254,56 @@ write_bonding_setting (NMConnection *connection, shvarFile *ifcfg, GError **erro
 	return TRUE;
 }
 
+static gboolean
+write_bridge_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
+{
+	NMSettingBridge *s_bridge;
+	const char *iface;
+	guint32 i, num_opts;
+
+	s_bridge = nm_connection_get_setting_bridge (connection);
+	if (!s_bridge) {
+		g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
+		             "Missing '%s' setting", NM_SETTING_BRIDGE_SETTING_NAME);
+		return FALSE;
+	}
+
+	iface = nm_setting_bridge_get_interface_name (s_bridge);
+	if (!iface) {
+		g_set_error (error, IFCFG_PLUGIN_ERROR, 0, "Missing interface name");
+		return FALSE;
+	}
+
+	svSetValue (ifcfg, "DEVICE", iface, FALSE);
+	svSetValue (ifcfg, "BRIDGING_OPTS", NULL, FALSE);
+
+	num_opts = nm_setting_bridge_get_num_options (s_bridge);
+	if (num_opts > 0) {
+		GString *str = g_string_sized_new (64);
+
+		for (i = 0; i < nm_setting_bridge_get_num_options (s_bridge); i++) {
+			const char *key, *value;
+
+			if (!nm_setting_bridge_get_option (s_bridge, i, &key, &value))
+				continue;
+
+			if (str->len)
+				g_string_append_c (str, ' ');
+
+			g_string_append_printf (str, "%s=%s", key, value);
+		}
+
+		if (str->len)
+			svSetValue (ifcfg, "BRIDGING_OPTS", str->str, FALSE);
+
+		g_string_free (str, TRUE);
+	}
+
+	svSetValue (ifcfg, "TYPE", TYPE_BRIDGE, FALSE);
+
+	return TRUE;
+}
+
 static void
 write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg)
 {
@@ -1998,6 +2048,9 @@ write_connection (NMConnection *connection,
 	} else if (!strcmp (type, NM_SETTING_BOND_SETTING_NAME)) {
 		if (!write_bonding_setting (connection, ifcfg, error))
 			goto out;
+	} else if (!strcmp (type, NM_SETTING_BRIDGE_SETTING_NAME)) {
+		if (!write_bridge_setting (connection, ifcfg, error))
+			goto out;
 	} else {
 		g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
 		             "Can't write connection type '%s'", type);
-- 
1.7.7.6



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