ifcfg-rh: fix IPv6-only configurations (rh #538499)

This commit is contained in:
Dan Williams
2010-04-12 16:24:07 -07:00
parent 9000c68839
commit dc7fe96e3f
5 changed files with 364 additions and 27 deletions

View File

@@ -15,7 +15,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2008 - 2009 Red Hat, Inc.
* Copyright (C) 2008 - 2010 Red Hat, Inc.
*/
#include <stdlib.h>
@@ -1115,6 +1115,7 @@ static NMSetting *
make_ip4_setting (shvarFile *ifcfg,
const char *network_file,
const char *iscsiadm_path,
gboolean valid_ip6_config,
GError **error)
{
NMSettingIP4Config *s_ip4 = NULL;
@@ -1192,14 +1193,17 @@ make_ip4_setting (shvarFile *ifcfg,
g_set_error (error, ifcfg_plugin_error_quark (), 0,
"Unknown BOOTPROTO '%s'", value);
g_free (value);
goto error;
goto done;
}
g_free (value);
} else {
char *tmp_ip4, *tmp_prefix, *tmp_netmask;
/* If there is no BOOTPROTO, no IPADDR, no PREFIX, and no NETMASK,
* assume DHCP is to be used. Happens with minimal ifcfg files like:
/* 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.
* Happens with minimal ifcfg files like the following that anaconda
* sometimes used to write out:
*
* DEVICE=eth0
* HWADDR=11:22:33:44:55:66
@@ -1208,8 +1212,14 @@ make_ip4_setting (shvarFile *ifcfg,
tmp_ip4 = svGetValue (ifcfg, "IPADDR", FALSE);
tmp_prefix = svGetValue (ifcfg, "PREFIX", FALSE);
tmp_netmask = svGetValue (ifcfg, "NETMASK", FALSE);
if (!tmp_ip4 && !tmp_prefix && !tmp_netmask)
if (!tmp_ip4 && !tmp_prefix && !tmp_netmask) {
if (valid_ip6_config) {
/* Nope, no IPv4 */
goto done;
}
method = NM_SETTING_IP4_CONFIG_METHOD_AUTO;
}
g_free (tmp_ip4);
g_free (tmp_prefix);
g_free (tmp_netmask);
@@ -1229,7 +1239,7 @@ make_ip4_setting (shvarFile *ifcfg,
for (i = 1; i < 256; i++) {
addr = read_full_ip4_address (ifcfg, network_file, i, error);
if (error && *error)
goto error;
goto done;
if (!addr)
break;
@@ -1271,7 +1281,7 @@ make_ip4_setting (shvarFile *ifcfg,
}
if (!tmp_success) {
g_free (tag);
goto error;
goto done;
}
g_clear_error (error);
}
@@ -1305,7 +1315,7 @@ make_ip4_setting (shvarFile *ifcfg,
if (!route_path) {
g_set_error (error, ifcfg_plugin_error_quark (), 0,
"Could not get route file path for '%s'", ifcfg->fileName);
goto error;
goto done;
}
/* First test new/legacy syntax */
@@ -1319,7 +1329,7 @@ make_ip4_setting (shvarFile *ifcfg,
route = read_one_ip4_route (route_ifcfg, network_file, i, error);
if (error && *error) {
svCloseFile (route_ifcfg);
goto error;
goto done;
}
if (!route)
break;
@@ -1334,7 +1344,7 @@ make_ip4_setting (shvarFile *ifcfg,
read_route_file_legacy (route_path, s_ip4, error);
g_free (route_path);
if (error && *error)
goto error;
goto done;
}
/* Legacy value NM used for a while but is incorrect (rh #459370) */
@@ -1360,7 +1370,7 @@ make_ip4_setting (shvarFile *ifcfg,
return NM_SETTING (s_ip4);
error:
done:
g_object_unref (s_ip4);
return NULL;
}
@@ -3058,6 +3068,7 @@ connection_from_file (const char *filename,
NMSetting *s_ip4, *s_ip6;
const char *ifcfg_name = NULL;
gboolean nm_controlled = TRUE;
gboolean ip6_used = FALSE;
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (unmanaged != NULL, NULL);
@@ -3161,22 +3172,27 @@ connection_from_file (const char *filename,
if (!connection || *unmanaged)
goto done;
s_ip4 = make_ip4_setting (parsed, network_file, iscsiadm_path, error);
if (*error) {
g_object_unref (connection);
connection = NULL;
goto done;
} else if (s_ip4) {
nm_connection_add_setting (connection, s_ip4);
}
s_ip6 = make_ip6_setting (parsed, network_file, iscsiadm_path, error);
if (*error) {
g_object_unref (connection);
connection = NULL;
goto done;
} else if (s_ip6)
} else if (s_ip6) {
const char *method;
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))
ip6_used = TRUE;
}
s_ip4 = make_ip4_setting (parsed, network_file, iscsiadm_path, ip6_used, error);
if (*error) {
g_object_unref (connection);
connection = NULL;
goto done;
} else if (s_ip4)
nm_connection_add_setting (connection, s_ip4);
/* iSCSI / ibft connections are read-only since their settings are
* stored in NVRAM and can only be changed in BIOS.