summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiří Klimeš <jklimes@redhat.com>2014-10-27 12:55:55 +0100
committerJiří Klimeš <jklimes@redhat.com>2014-10-30 08:30:48 +0100
commitd31c456033de925e197a63d5ecd7a5b0fba7d24f (patch)
treeb025e7372796276b035d0321f03dd9cc5faf2416
parentafde052445f8b0571a70b11935561fd15d762cd2 (diff)
downloadNetworkManager-d31c456033de925e197a63d5ecd7a5b0fba7d24f.tar.gz
cli: check IP configuration when setting connection.master in editor
If IPv4 and/or IPv6 are present on setting connection.master, offer their removal.
-rw-r--r--clients/cli/connections.c6
-rw-r--r--clients/cli/settings.c35
-rw-r--r--clients/cli/settings.h3
3 files changed, 43 insertions, 1 deletions
diff --git a/clients/cli/connections.c b/clients/cli/connections.c
index eddb40bc93..c3a8ba466b 100644
--- a/clients/cli/connections.c
+++ b/clients/cli/connections.c
@@ -7688,6 +7688,8 @@ editor_init_new_connection (NmCli *nmc, NMConnection *connection)
/* Initialize new connection according to its type using sensible defaults. */
+ nmc_setting_connection_connect_handlers (s_con, connection);
+
if (g_strcmp0 (con_type, "bond-slave") == 0)
slave_type = NM_SETTING_BOND_SETTING_NAME;
if (g_strcmp0 (con_type, "team-slave") == 0)
@@ -7790,10 +7792,12 @@ editor_init_existing_connection (NMConnection *connection)
NMSettingIP4Config *s_ip4;
NMSettingIP6Config *s_ip6;
NMSettingWireless *s_wireless;
+ NMSettingConnection *s_con;
s_ip4 = nm_connection_get_setting_ip4_config (connection);
s_ip6 = nm_connection_get_setting_ip6_config (connection);
s_wireless = nm_connection_get_setting_wireless (connection);
+ s_con = nm_connection_get_setting_connection (connection);
if (s_ip4)
nmc_setting_ip4_connect_handlers (s_ip4);
@@ -7801,6 +7805,8 @@ editor_init_existing_connection (NMConnection *connection)
nmc_setting_ip6_connect_handlers (s_ip6);
if (s_wireless)
nmc_setting_wireless_connect_handlers (s_wireless);
+ if (s_con)
+ nmc_setting_connection_connect_handlers (s_con, connection);
}
static NMCResultCode
diff --git a/clients/cli/settings.c b/clients/cli/settings.c
index 6a78e5e1f7..d00361897d 100644
--- a/clients/cli/settings.c
+++ b/clients/cli/settings.c
@@ -1848,6 +1848,32 @@ wireless_band_channel_changed_cb (GObject *object, GParamSpec *pspec, gpointer u
}
}
+static void
+connection_master_changed_cb (GObject *object, GParamSpec *pspec, gpointer user_data)
+{
+ NMSettingConnection *s_con = NM_SETTING_CONNECTION (object);
+ NMConnection *connection = NM_CONNECTION (user_data);
+ NMSetting *s_ipv4, *s_ipv6;
+ const char *value, *tmp_str;
+
+ value = nm_setting_connection_get_master (s_con);
+ if (value) {
+ s_ipv4 = nm_connection_get_setting_by_name (connection, NM_SETTING_IP4_CONFIG_SETTING_NAME);
+ s_ipv6 = nm_connection_get_setting_by_name (connection, NM_SETTING_IP6_CONFIG_SETTING_NAME);
+ if (s_ipv4 || s_ipv6) {
+ g_print (_("Warning: setting %s.%s requires removing ipv4 and ipv6 settings\n"),
+ nm_setting_get_name (NM_SETTING (s_con)), g_param_spec_get_name (pspec));
+ tmp_str = nmc_get_user_input (_("Do you want to remove them? [yes] "));
+ if (!tmp_str || matches (tmp_str, "yes") == 0) {
+ if (s_ipv4)
+ nm_connection_remove_setting (connection, G_OBJECT_TYPE (s_ipv4));
+ if (s_ipv6)
+ nm_connection_remove_setting (connection, G_OBJECT_TYPE (s_ipv6));
+ }
+ }
+ }
+}
+
void
nmc_setting_ip4_connect_handlers (NMSettingIP4Config *setting)
{
@@ -1881,6 +1907,15 @@ nmc_setting_wireless_connect_handlers (NMSettingWireless *setting)
G_CALLBACK (wireless_band_channel_changed_cb), NULL);
}
+void
+nmc_setting_connection_connect_handlers (NMSettingConnection *setting, NMConnection *connection)
+{
+ g_return_if_fail (NM_IS_SETTING_CONNECTION (setting));
+
+ g_signal_connect (setting, "notify::" NM_SETTING_CONNECTION_MASTER,
+ G_CALLBACK (connection_master_changed_cb), connection);
+}
+
/*
* Customize some properties of the setting so that the setting has sensible
* values.
diff --git a/clients/cli/settings.h b/clients/cli/settings.h
index 5960586512..d9e9483889 100644
--- a/clients/cli/settings.h
+++ b/clients/cli/settings.h
@@ -14,7 +14,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * (C) Copyright 2010 - 2013 Red Hat, Inc.
+ * Copyright 2010 - 2014 Red Hat, Inc.
*/
#ifndef NMC_SETTINGS_H
@@ -33,6 +33,7 @@ void nmc_setting_custom_init (NMSetting *setting);
void nmc_setting_ip4_connect_handlers (NMSettingIP4Config *setting);
void nmc_setting_ip6_connect_handlers (NMSettingIP6Config *setting);
void nmc_setting_wireless_connect_handlers (NMSettingWireless *setting);
+void nmc_setting_connection_connect_handlers (NMSettingConnection *setting, NMConnection *connection);
char **nmc_setting_get_valid_properties (NMSetting *setting);
char *nmc_setting_get_property_desc (NMSetting *setting, const char *prop);