[PATCH 5/9] connection-setting: implement ability to define a master connection



Adds a MASTER= directive to ifcfg-rh permitting a connection to define
a master/slave relationship. This is intended to be used to implement
bonding and eventually bridging connections.

Signed-off-by: Thomas Graf <tgraf redhat com>
---
 libnm-util/libnm-util.ver              |    1 +
 libnm-util/nm-setting-connection.c     |   39 ++++++++++++++++++++++++++++++++
 libnm-util/nm-setting-connection.h     |    2 +
 src/settings/plugins/ifcfg-rh/reader.c |    6 +++++
 4 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/libnm-util/libnm-util.ver b/libnm-util/libnm-util.ver
index 8c28edf..0c7aab0 100644
--- a/libnm-util/libnm-util.ver
+++ b/libnm-util/libnm-util.ver
@@ -195,6 +195,7 @@ global:
 	nm_setting_connection_get_connection_type;
 	nm_setting_connection_get_id;
 	nm_setting_connection_get_num_permissions;
+	nm_setting_connection_get_master;
 	nm_setting_connection_get_permission;
 	nm_setting_connection_get_read_only;
 	nm_setting_connection_get_timestamp;
diff --git a/libnm-util/nm-setting-connection.c b/libnm-util/nm-setting-connection.c
index e9030b1..5ca6b60 100644
--- a/libnm-util/nm-setting-connection.c
+++ b/libnm-util/nm-setting-connection.c
@@ -97,6 +97,7 @@ typedef struct {
 	char *id;
 	char *uuid;
 	char *type;
+	char *master;
 	GSList *permissions; /* list of Permission structs */
 	gboolean autoconnect;
 	guint64 timestamp;
@@ -112,6 +113,7 @@ enum {
 	PROP_AUTOCONNECT,
 	PROP_TIMESTAMP,
 	PROP_READ_ONLY,
+	PROP_MASTER,
 
 	LAST_PROP
 };
@@ -478,6 +480,22 @@ nm_setting_connection_get_read_only (NMSettingConnection *setting)
 	return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->read_only;
 }
 
+/**
+ * nm_setting_connection_get_master:
+ * @setting: the #NMSettingConnection
+ *
+ * Returns the #NMSettingConnection:master property of the connection.
+ *
+ * Returns: Name of the master device
+ */
+const char *
+nm_setting_connection_get_master (NMSettingConnection *setting)
+{
+	g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), NULL);
+
+	return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->master;
+}
+
 static gint
 find_setting_by_name (gconstpointer a, gconstpointer b)
 {
@@ -591,6 +609,7 @@ finalize (GObject *object)
 	g_free (priv->id);
 	g_free (priv->uuid);
 	g_free (priv->type);
+	g_free (priv->master);
 	nm_utils_slist_free (priv->permissions, (GDestroyNotify) permission_free);
 
 	G_OBJECT_CLASS (nm_setting_connection_parent_class)->finalize (object);
@@ -644,6 +663,10 @@ set_property (GObject *object, guint prop_id,
 	case PROP_READ_ONLY:
 		priv->read_only = g_value_get_boolean (value);
 		break;
+	case PROP_MASTER:
+		g_free (priv->master);
+		priv->master = g_value_dup_string (value);
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -689,6 +712,9 @@ get_property (GObject *object, guint prop_id,
 	case PROP_READ_ONLY:
 		g_value_set_boolean (value, nm_setting_connection_get_read_only (setting));
 		break;
+	case PROP_MASTER:
+		g_value_set_string (value, nm_setting_connection_get_master (setting));
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -876,4 +902,17 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class)
 	                      "cannot yet write updated connections back out.",
 	                      FALSE,
 	                      G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_FUZZY_IGNORE));
+
+	/**
+	 * NMSettingConnection:master:
+	 *
+	 * Name of the master deviec or UUID of the master connection
+	 **/
+	g_object_class_install_property
+		(object_class, PROP_MASTER,
+		 g_param_spec_string (NM_SETTING_CONNECTION_MASTER,
+						  "Master",
+						  "Name of the master device or UUID of the master connection",
+						  NULL,
+						  G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE | NM_SETTING_PARAM_FUZZY_IGNORE));
 }
diff --git a/libnm-util/nm-setting-connection.h b/libnm-util/nm-setting-connection.h
index 1ec5bf1..0768bd6 100644
--- a/libnm-util/nm-setting-connection.h
+++ b/libnm-util/nm-setting-connection.h
@@ -75,6 +75,7 @@ GQuark nm_setting_connection_error_quark (void);
 #define NM_SETTING_CONNECTION_TIMESTAMP   "timestamp"
 #define NM_SETTING_CONNECTION_READ_ONLY   "read-only"
 #define NM_SETTING_CONNECTION_PERMISSIONS "permissions"
+#define NM_SETTING_CONNECTION_MASTER      "master"
 
 /**
  * NMSettingConnection:
@@ -119,6 +120,7 @@ gboolean    nm_setting_connection_add_permission       (NMSettingConnection *set
                                                         const char *detail);
 void        nm_setting_connection_remove_permission    (NMSettingConnection *setting,
                                                         guint32 idx);
+const char *nm_setting_connection_get_master           (NMSettingConnection *setting);
 
 G_END_DECLS
 
diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c
index f20b6cc..1b12069 100644
--- a/src/settings/plugins/ifcfg-rh/reader.c
+++ b/src/settings/plugins/ifcfg-rh/reader.c
@@ -139,6 +139,12 @@ make_connection_setting (const char *file,
 	              svTrueValue (ifcfg, "ONBOOT", TRUE),
 	              NULL);
 
+	value = svGetValue (ifcfg, "MASTER", FALSE);
+	if (value) {
+		g_object_set (s_con, NM_SETTING_CONNECTION_MASTER, value, NULL);
+		g_free (value);
+	}
+
 	value = svGetValue (ifcfg, "USERS", FALSE);
 	if (value) {
 		char **items, **iter;
-- 
1.7.6



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