summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2013-09-26 16:36:55 -0400
committerDan Winship <danw@gnome.org>2013-10-11 12:24:34 -0400
commit0a77cf6320c23661485fc91d365e312f2c399f1d (patch)
treeff78576dd3310d35009de5bcf8ac826a52ff9f89
parent68f12b4e9c134d41e42cc8a1986cad6bb3c07b7a (diff)
downloadNetworkManager-0a77cf6320c23661485fc91d365e312f2c399f1d.tar.gz
ifcfg-rh: fix handling of minimal ifcfg files
ifcfg-rh had the rule that if an ifcfg file had no BOOTPROTO and no IPv4 addresses, then it should be treated as method=auto for compatibility. But in fact, current ifup treats it as method=disabled, so we should too. https://bugzilla.gnome.org/show_bug.cgi?id=708875
-rw-r--r--src/settings/plugins/ifcfg-rh/reader.c109
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c12
2 files changed, 50 insertions, 71 deletions
diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c
index 4831247aea..e900fa19cf 100644
--- a/src/settings/plugins/ifcfg-rh/reader.c
+++ b/src/settings/plugins/ifcfg-rh/reader.c
@@ -1265,18 +1265,16 @@ static NMSetting *
make_ip4_setting (shvarFile *ifcfg,
const char *network_file,
const char *iscsiadm_path,
- gboolean can_disable_ip4,
GError **error)
{
NMSettingIP4Config *s_ip4 = NULL;
char *value = NULL;
char *route_path = NULL;
- char *method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL;
+ char *method;
gint32 i;
shvarFile *network_ifcfg;
shvarFile *route_ifcfg;
gboolean never_default = FALSE;
- gboolean bootproto_none = FALSE;
s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
@@ -1308,65 +1306,47 @@ make_ip4_setting (shvarFile *ifcfg,
}
value = svGetValue (ifcfg, "BOOTPROTO", FALSE);
- if (value) {
- if (!g_ascii_strcasecmp (value, "bootp") || !g_ascii_strcasecmp (value, "dhcp"))
- method = NM_SETTING_IP4_CONFIG_METHOD_AUTO;
- else if (!g_ascii_strcasecmp (value, "ibft")) {
- g_free (value);
- g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, never_default, NULL);
- /* iSCSI Boot Firmware Table: need to read values from the iSCSI
- * firmware for this device and create the IP4 setting using those.
- */
- if (fill_ip4_setting_from_ibft (ifcfg, s_ip4, iscsiadm_path, error))
- return NM_SETTING (s_ip4);
- g_object_unref (s_ip4);
- return NULL;
- } else if (!g_ascii_strcasecmp (value, "autoip")) {
- g_free (value);
- g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL,
- NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, never_default,
- NULL);
- return NM_SETTING (s_ip4);
- } else if (!g_ascii_strcasecmp (value, "shared")) {
- g_free (value);
- g_object_set (s_ip4,
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_SHARED,
- NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, never_default,
- NULL);
- return NM_SETTING (s_ip4);
- } 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,
- "Unknown BOOTPROTO '%s'", value);
- g_free (value);
- goto done;
- }
+
+ if (!value || !*value || !g_ascii_strcasecmp (value, "none")) {
+ if (is_any_ip4_address_defined (ifcfg))
+ method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL;
+ else
+ method = NM_SETTING_IP4_CONFIG_METHOD_DISABLED;
+ } else if (!g_ascii_strcasecmp (value, "bootp") || !g_ascii_strcasecmp (value, "dhcp")) {
+ method = NM_SETTING_IP4_CONFIG_METHOD_AUTO;
+ } else if (!g_ascii_strcasecmp (value, "static")) {
+ method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL;
+ } else if (!g_ascii_strcasecmp (value, "ibft")) {
g_free (value);
- }
- if (!value || bootproto_none) {
- /* If there is no BOOTPROTO (or BOOTPROTO=none), 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.
- * Happens with minimal ifcfg files like the following that anaconda
- * sometimes used to write out:
- *
- * DEVICE=eth0
- * HWADDR=11:22:33:44:55:66
- *
+ g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, never_default, NULL);
+ /* iSCSI Boot Firmware Table: need to read values from the iSCSI
+ * firmware for this device and create the IP4 setting using those.
*/
- 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;
- }
+ if (fill_ip4_setting_from_ibft (ifcfg, s_ip4, iscsiadm_path, error))
+ return NM_SETTING (s_ip4);
+ g_object_unref (s_ip4);
+ return NULL;
+ } else if (!g_ascii_strcasecmp (value, "autoip")) {
+ g_free (value);
+ g_object_set (s_ip4,
+ NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL,
+ NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, never_default,
+ NULL);
+ return NM_SETTING (s_ip4);
+ } else if (!g_ascii_strcasecmp (value, "shared")) {
+ g_free (value);
+ g_object_set (s_ip4,
+ NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_SHARED,
+ NM_SETTING_IP4_CONFIG_NEVER_DEFAULT, never_default,
+ NULL);
+ return NM_SETTING (s_ip4);
+ } else {
+ g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
+ "Unknown BOOTPROTO '%s'", value);
+ g_free (value);
+ goto done;
}
+ g_free (value);
g_object_set (s_ip4,
NM_SETTING_IP4_CONFIG_METHOD, method,
@@ -4503,7 +4483,6 @@ connection_from_file (const char *filename,
NMSetting *s_ip4, *s_ip6, *s_port;
const char *ifcfg_name = NULL;
gboolean nm_controlled = TRUE;
- gboolean can_disable_ip4 = FALSE;
char *unmanaged = NULL;
g_return_val_if_fail (filename != NULL, NULL);
@@ -4647,16 +4626,10 @@ connection_from_file (const char *filename,
g_object_unref (connection);
connection = NULL;
goto done;
- } else {
- const char *method;
-
+ } else
nm_connection_add_setting (connection, s_ip6);
- method = nm_setting_ip6_config_get_method (NM_SETTING_IP6_CONFIG (s_ip6));
- if (method && strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE))
- can_disable_ip4 = TRUE;
- }
- s_ip4 = make_ip4_setting (parsed, network_file, iscsiadm_path, can_disable_ip4, error);
+ s_ip4 = make_ip4_setting (parsed, network_file, iscsiadm_path, error);
if (!s_ip4) {
g_object_unref (connection);
connection = NULL;
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 7c79dbc7ad..43d07bcee7 100644
--- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
+++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
@@ -182,6 +182,7 @@ test_read_basic (void)
NMSettingConnection *s_con;
NMSettingWired *s_wired;
NMSettingIP4Config *s_ip4;
+ NMSettingIP6Config *s_ip6;
GError *error = NULL;
const GByteArray *array;
char expected_mac_address[ETH_ALEN] = { 0x00, 0x16, 0x41, 0x11, 0x22, 0x33 };
@@ -221,12 +222,17 @@ test_read_basic (void)
g_assert (memcmp (array->data, &expected_mac_address[0], ETH_ALEN) == 0);
/* ===== IPv4 SETTING ===== */
-
s_ip4 = nm_connection_get_setting_ip4_config (connection);
g_assert (s_ip4);
- g_assert_cmpstr (nm_setting_ip4_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
+ g_assert_cmpstr (nm_setting_ip4_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED);
g_assert (nm_setting_ip4_config_get_never_default (s_ip4) == FALSE);
+ /* ===== IPv6 SETTING ===== */
+ s_ip6 = nm_connection_get_setting_ip6_config (connection);
+ g_assert (s_ip6);
+ g_assert_cmpstr (nm_setting_ip6_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_IGNORE);
+ g_assert (nm_setting_ip6_config_get_never_default (s_ip6) == FALSE);
+
g_object_unref (connection);
}
@@ -275,7 +281,7 @@ test_read_variables_corner_cases (void)
/* ===== IPv4 SETTING ===== */
s_ip4 = nm_connection_get_setting_ip4_config (connection);
g_assert (s_ip4);
- g_assert_cmpstr (nm_setting_ip4_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
+ g_assert_cmpstr (nm_setting_ip4_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED);
g_assert (nm_setting_ip4_config_get_never_default (s_ip4) == FALSE);
g_object_unref (connection);