[patch NetworkManager v2 1/2] ifcfg-rh: reader: allow device to not have ipv4 setting.
- From: Jiri Pirko <jiri resnulli us>
- To: networkmanager-list gnome org
- Subject: [patch NetworkManager v2 1/2] ifcfg-rh: reader: allow device to not have ipv4 setting.
- Date: Thu, 22 Aug 2013 14:17:46 +0200
If BOOTPROTO is set to "none", user states that no ipv4 setting should
be set. So respect that.
Introduce helper is_any_ip4_address_defined() along the way to make the
code more readable.
Signed-off-by: Jiri Pirko <jiri resnulli us>
---
libnm-util/nm-setting-ip4-config.c | 27 ---------
libnm-util/nm-setting-ip6-config.c | 27 ---------
src/settings/plugins/ifcfg-rh/reader.c | 102 ++++++++++++++++++---------------
3 files changed, 56 insertions(+), 100 deletions(-)
diff --git a/libnm-util/nm-setting-ip4-config.c b/libnm-util/nm-setting-ip4-config.c
index 196ff1d..6caf864 100644
--- a/libnm-util/nm-setting-ip4-config.c
+++ b/libnm-util/nm-setting-ip4-config.c
@@ -691,15 +691,6 @@ nm_setting_ip4_config_get_may_fail (NMSettingIP4Config *setting)
return NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting)->may_fail;
}
-static gint
-find_setting_by_name (gconstpointer a, gconstpointer b)
-{
- NMSetting *setting = NM_SETTING (a);
- const char *str = (const char *) b;
-
- return strcmp (nm_setting_get_name (setting), str);
-}
-
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
@@ -768,24 +759,6 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
- /* Disabled method is not allowed when IPv6 is set to 'ignore' */
- if (!strcmp (priv->method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) {
- GSList *list = g_slist_find_custom (all_settings, NM_SETTING_IP6_CONFIG_SETTING_NAME,
find_setting_by_name);
- if (list) {
- NMSettingIP6Config *s_ip6 = g_slist_nth_data (list, 0);
- if ( s_ip6
- && !g_strcmp0 (nm_setting_ip6_config_get_method (s_ip6),
NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) {
- g_set_error (error,
- NM_SETTING_IP4_CONFIG_ERROR,
- NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY,
- _("IPv4 method '%s' is not allowed when IPv6 method 'ignore' is
set"),
- priv->method);
- g_prefix_error (error, "%s.%s: ", NM_SETTING_IP4_CONFIG_SETTING_NAME,
NM_SETTING_IP4_CONFIG_METHOD);
- return FALSE;
- }
- }
- }
-
if (priv->dhcp_client_id && !strlen (priv->dhcp_client_id)) {
g_set_error_literal (error,
NM_SETTING_IP4_CONFIG_ERROR,
diff --git a/libnm-util/nm-setting-ip6-config.c b/libnm-util/nm-setting-ip6-config.c
index 7127724..950a70c 100644
--- a/libnm-util/nm-setting-ip6-config.c
+++ b/libnm-util/nm-setting-ip6-config.c
@@ -675,15 +675,6 @@ nm_setting_ip6_config_get_ip6_privacy (NMSettingIP6Config *setting)
return NM_SETTING_IP6_CONFIG_GET_PRIVATE (setting)->ip6_privacy;
}
-static gint
-find_setting_by_name (gconstpointer a, gconstpointer b)
-{
- NMSetting *setting = NM_SETTING (a);
- const char *str = (const char *) b;
-
- return strcmp (nm_setting_get_name (setting), str);
-}
-
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
@@ -752,24 +743,6 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
- /* Method 'ignore' is not allowed when IPv4 is set to 'disabled' */
- if (!strcmp (priv->method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) {
- GSList *list = g_slist_find_custom (all_settings, NM_SETTING_IP4_CONFIG_SETTING_NAME,
find_setting_by_name);
- if (list) {
- NMSettingIP4Config *s_ip4 = g_slist_nth_data (list, 0);
- if ( s_ip4
- && !g_strcmp0 (nm_setting_ip4_config_get_method (s_ip4),
NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) {
- g_set_error (error,
- NM_SETTING_IP6_CONFIG_ERROR,
- NM_SETTING_IP6_CONFIG_ERROR_INVALID_PROPERTY,
- _("IPv6 method '%s' is not allowed when IPv4 method 'disabled'
is set"),
- priv->method);
- g_prefix_error (error, "%s.%s: ", NM_SETTING_IP6_CONFIG_SETTING_NAME,
NM_SETTING_IP6_CONFIG_METHOD);
- return FALSE;
- }
- }
- }
-
if (priv->dhcp_hostname && !strlen (priv->dhcp_hostname)) {
g_set_error_literal (error,
NM_SETTING_IP6_CONFIG_ERROR,
diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c
index 17681c6..cafcd95 100644
--- a/src/settings/plugins/ifcfg-rh/reader.c
+++ b/src/settings/plugins/ifcfg-rh/reader.c
@@ -589,6 +589,50 @@ parse_ip6_address (const char *value,
return TRUE;
}
+static gchar *
+get_numbered_tag (gchar *tag_name, gint32 which)
+{
+ if (which == -1)
+ return g_strdup (tag_name);
+ return g_strdup_printf ("%s%u", tag_name, which);
+}
+
+static gboolean
+is_any_ip4_address_defined (shvarFile *ifcfg)
+{
+ gint32 i;
+
+ for (i = -1; i <= 2; i++) {
+ gchar *tag;
+ char *value;
+
+ tag = get_numbered_tag ("IPADDR", i);
+ value = svGetValue (ifcfg, tag, FALSE);
+ g_free (tag);
+ if (value) {
+ g_free (value);
+ return TRUE;
+ }
+
+ tag = get_numbered_tag ("PREFIX", i);
+ value = svGetValue (ifcfg, tag, FALSE);
+ g_free(tag);
+ if (value) {
+ g_free (value);
+ return TRUE;
+ }
+
+ tag = get_numbered_tag ("NETMASK", i);
+ value = svGetValue (ifcfg, tag, FALSE);
+ g_free(tag);
+ if (value) {
+ g_free (value);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
/* Returns TRUE on missing address or valid address */
static gboolean
read_full_ip4_address (shvarFile *ifcfg,
@@ -613,17 +657,10 @@ read_full_ip4_address (shvarFile *ifcfg,
g_return_val_if_fail (*error == NULL, FALSE);
addr = nm_ip4_address_new ();
- if (which == -1) {
- ip_tag = g_strdup ("IPADDR");
- prefix_tag = g_strdup ("PREFIX");
- netmask_tag = g_strdup ("NETMASK");
- gw_tag = g_strdup ("GATEWAY");
- } else {
- ip_tag = g_strdup_printf ("IPADDR%u", which);
- prefix_tag = g_strdup_printf ("PREFIX%u", which);
- netmask_tag = g_strdup_printf ("NETMASK%u", which);
- gw_tag = g_strdup_printf ("GATEWAY%u", which);
- }
+ ip_tag = get_numbered_tag ("IPADDR", which);
+ prefix_tag = get_numbered_tag ("PREFIX", which);
+ netmask_tag = get_numbered_tag ("NETMASK", which);
+ gw_tag = get_numbered_tag ("GATEWAY", which);
/* IP address */
if (!read_ip4_address (ifcfg, ip_tag, &tmp, error))
@@ -1231,6 +1268,7 @@ make_ip4_setting (shvarFile *ifcfg,
shvarFile *network_ifcfg;
shvarFile *route_ifcfg;
gboolean never_default = FALSE;
+ gboolean bootproto_none = FALSE;
s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
@@ -1289,7 +1327,10 @@ make_ip4_setting (shvarFile *ifcfg,
NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, never_default,
NULL);
return NM_SETTING (s_ip4);
- } else if (!g_ascii_strcasecmp (value, "none") || !g_ascii_strcasecmp (value, "static")) {
+ } else if (!g_ascii_strcasecmp (value, "none")) {
+ bootproto_none = TRUE;
+ can_disable_ip4 = TRUE;
+ } else if (!g_ascii_strcasecmp (value, "static")) {
/* Static IP */
} else if (strlen (value)) {
g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
@@ -1298,12 +1339,8 @@ make_ip4_setting (shvarFile *ifcfg,
goto done;
}
g_free (value);
- } else {
- char *tmp_ip4, *tmp_prefix, *tmp_netmask;
- char *tmp_ip4_0, *tmp_prefix_0, *tmp_netmask_0;
- char *tmp_ip4_1, *tmp_prefix_1, *tmp_netmask_1;
- char *tmp_ip4_2, *tmp_prefix_2, *tmp_netmask_2;
-
+ }
+ if (!value || bootproto_none) {
/* If there is no BOOTPROTO, no IPADDR, no PREFIX, no NETMASK, but
* valid IPv6 configuration, assume that IPv4 is disabled. Otherwise,
* if there is no IPv6 configuration, assume DHCP is to be used.
@@ -1314,40 +1351,13 @@ make_ip4_setting (shvarFile *ifcfg,
* HWADDR=11:22:33:44:55:66
*
*/
- tmp_ip4 = svGetValue (ifcfg, "IPADDR", FALSE);
- tmp_prefix = svGetValue (ifcfg, "PREFIX", FALSE);
- tmp_netmask = svGetValue (ifcfg, "NETMASK", FALSE);
- tmp_ip4_0 = svGetValue (ifcfg, "IPADDR0", FALSE);
- tmp_prefix_0 = svGetValue (ifcfg, "PREFIX0", FALSE);
- tmp_netmask_0 = svGetValue (ifcfg, "NETMASK0", FALSE);
- tmp_ip4_1 = svGetValue (ifcfg, "IPADDR1", FALSE);
- tmp_prefix_1 = svGetValue (ifcfg, "PREFIX1", FALSE);
- tmp_netmask_1 = svGetValue (ifcfg, "NETMASK1", FALSE);
- tmp_ip4_2 = svGetValue (ifcfg, "IPADDR2", FALSE);
- tmp_prefix_2 = svGetValue (ifcfg, "PREFIX2", FALSE);
- tmp_netmask_2 = svGetValue (ifcfg, "NETMASK2", FALSE);
- if ( !tmp_ip4 && !tmp_prefix && !tmp_netmask
- && !tmp_ip4_0 && !tmp_prefix_0 && !tmp_netmask_0
- && !tmp_ip4_1 && !tmp_prefix_1 && !tmp_netmask_1
- && !tmp_ip4_2 && !tmp_prefix_2 && !tmp_netmask_2) {
+ if (!is_any_ip4_address_defined (ifcfg)) {
if (can_disable_ip4)
/* Nope, no IPv4 */
method = NM_SETTING_IP4_CONFIG_METHOD_DISABLED;
else
method = NM_SETTING_IP4_CONFIG_METHOD_AUTO;
}
- g_free (tmp_ip4);
- g_free (tmp_prefix);
- g_free (tmp_netmask);
- g_free (tmp_ip4_0);
- g_free (tmp_prefix_0);
- g_free (tmp_netmask_0);
- g_free (tmp_ip4_1);
- g_free (tmp_prefix_1);
- g_free (tmp_netmask_1);
- g_free (tmp_ip4_2);
- g_free (tmp_prefix_2);
- g_free (tmp_netmask_2);
}
g_object_set (s_ip4,
--
1.8.3.1
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]