ifcfg-rh: treat missing IPv6 setting as IPv6 "auto" method (rh #830434)
This commit is contained in:
@@ -12508,6 +12508,124 @@ test_write_vlan_only_vlanid (void)
|
|||||||
g_object_unref (reread);
|
g_object_unref (reread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_write_ethernet_missing_ipv6 (void)
|
||||||
|
{
|
||||||
|
NMConnection *connection;
|
||||||
|
NMConnection *reread;
|
||||||
|
NMSettingConnection *s_con;
|
||||||
|
NMSettingWired *s_wired;
|
||||||
|
NMSettingIP4Config *s_ip4;
|
||||||
|
NMSettingIP6Config *s_ip6;
|
||||||
|
char *uuid;
|
||||||
|
gboolean success;
|
||||||
|
GError *error = NULL;
|
||||||
|
char *testfile = NULL;
|
||||||
|
char *unmanaged = NULL;
|
||||||
|
char *keyfile = NULL;
|
||||||
|
char *routefile = NULL;
|
||||||
|
char *route6file = NULL;
|
||||||
|
gboolean ignore_error = FALSE;
|
||||||
|
|
||||||
|
connection = nm_connection_new ();
|
||||||
|
g_assert (connection);
|
||||||
|
|
||||||
|
/* Connection setting */
|
||||||
|
s_con = (NMSettingConnection *) nm_setting_connection_new ();
|
||||||
|
g_assert (s_con);
|
||||||
|
nm_connection_add_setting (connection, NM_SETTING (s_con));
|
||||||
|
|
||||||
|
uuid = nm_utils_uuid_generate ();
|
||||||
|
g_object_set (s_con,
|
||||||
|
NM_SETTING_CONNECTION_ID, "Test Write Ethernet Without IPv6 Setting",
|
||||||
|
NM_SETTING_CONNECTION_UUID, uuid,
|
||||||
|
NM_SETTING_CONNECTION_AUTOCONNECT, TRUE,
|
||||||
|
NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
|
||||||
|
NULL);
|
||||||
|
g_free (uuid);
|
||||||
|
|
||||||
|
/* Wired setting */
|
||||||
|
s_wired = (NMSettingWired *) nm_setting_wired_new ();
|
||||||
|
g_assert (s_wired);
|
||||||
|
nm_connection_add_setting (connection, NM_SETTING (s_wired));
|
||||||
|
|
||||||
|
/* IP4 setting */
|
||||||
|
s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
|
||||||
|
g_assert (s_ip4);
|
||||||
|
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
|
||||||
|
g_object_set (s_ip4,
|
||||||
|
NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
|
||||||
|
NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, "random-client-id-00:22:33",
|
||||||
|
NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES, TRUE,
|
||||||
|
NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, TRUE,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
/* IP6 setting */
|
||||||
|
/*
|
||||||
|
* We intentionally don't add IPv6 setting here. ifcfg-rh plugin should regard
|
||||||
|
* missing IPv6 as IPv6 with NM_SETTING_IP6_CONFIG_METHOD_AUTO method.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ASSERT (nm_connection_verify (connection, &error) == TRUE,
|
||||||
|
"ethernet-missing-ipv6", "failed to verify connection: %s",
|
||||||
|
(error && error->message) ? error->message : "(unknown)");
|
||||||
|
|
||||||
|
/* Save the ifcfg */
|
||||||
|
success = writer_new_connection (connection,
|
||||||
|
TEST_SCRATCH_DIR "/network-scripts/",
|
||||||
|
&testfile,
|
||||||
|
&error);
|
||||||
|
ASSERT (success == TRUE,
|
||||||
|
"ethernet-missing-ipv6", "failed to write connection to disk: %s",
|
||||||
|
(error && error->message) ? error->message : "(unknown)");
|
||||||
|
|
||||||
|
ASSERT (testfile != NULL,
|
||||||
|
"ethernet-missing-ipv6", "didn't get ifcfg file path back after writing connection");
|
||||||
|
|
||||||
|
/* re-read the connection for comparison */
|
||||||
|
reread = connection_from_file (testfile,
|
||||||
|
NULL,
|
||||||
|
TYPE_ETHERNET,
|
||||||
|
NULL,
|
||||||
|
&unmanaged,
|
||||||
|
&keyfile,
|
||||||
|
&routefile,
|
||||||
|
&route6file,
|
||||||
|
&error,
|
||||||
|
&ignore_error);
|
||||||
|
unlink (testfile);
|
||||||
|
|
||||||
|
ASSERT (reread != NULL,
|
||||||
|
"ethernet-missing-ipv6-reread", "failed to read %s: %s", testfile, error->message);
|
||||||
|
|
||||||
|
ASSERT (nm_connection_verify (reread, &error),
|
||||||
|
"ethernet-missing-ipv6-reread-verify", "failed to verify %s: %s", testfile, error->message);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We need to add IPv6 setting to the original connection now so that
|
||||||
|
* the comparison can succeed. Missing IPv6 setting should have been
|
||||||
|
* written out (and re-read) as Automatic IPv6.
|
||||||
|
*/
|
||||||
|
s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
|
||||||
|
g_assert (s_ip6);
|
||||||
|
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
|
||||||
|
g_object_set (s_ip6,
|
||||||
|
NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
|
||||||
|
NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
ASSERT (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT) == TRUE,
|
||||||
|
"ethernet-missing-ipv6", "written and re-read connection weren't the same.");
|
||||||
|
|
||||||
|
g_free (testfile);
|
||||||
|
g_free (unmanaged);
|
||||||
|
g_free (keyfile);
|
||||||
|
g_free (routefile);
|
||||||
|
g_free (route6file);
|
||||||
|
g_object_unref (connection);
|
||||||
|
g_object_unref (reread);
|
||||||
|
}
|
||||||
|
|
||||||
#define TEST_IFCFG_BOND_MAIN TEST_IFCFG_DIR"/network-scripts/ifcfg-test-bond-main"
|
#define TEST_IFCFG_BOND_MAIN TEST_IFCFG_DIR"/network-scripts/ifcfg-test-bond-main"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -13403,6 +13521,7 @@ int main (int argc, char **argv)
|
|||||||
test_write_infiniband ();
|
test_write_infiniband ();
|
||||||
test_write_vlan ();
|
test_write_vlan ();
|
||||||
test_write_vlan_only_vlanid ();
|
test_write_vlan_only_vlanid ();
|
||||||
|
test_write_ethernet_missing_ipv6 ();
|
||||||
|
|
||||||
/* iSCSI / ibft */
|
/* iSCSI / ibft */
|
||||||
test_read_ibft_dhcp ();
|
test_read_ibft_dhcp ();
|
||||||
|
@@ -1897,9 +1897,15 @@ write_ip6_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
|
|||||||
|
|
||||||
s_ip6 = nm_connection_get_setting_ip6_config (connection);
|
s_ip6 = nm_connection_get_setting_ip6_config (connection);
|
||||||
if (!s_ip6) {
|
if (!s_ip6) {
|
||||||
g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
|
/* Treat missing IPv6 setting as a setting with method "auto" */
|
||||||
"Missing '%s' setting", NM_SETTING_IP6_CONFIG_SETTING_NAME);
|
svSetValue (ifcfg, "IPV6INIT", "yes", FALSE);
|
||||||
return FALSE;
|
svSetValue (ifcfg, "IPV6_AUTOCONF", "yes", FALSE);
|
||||||
|
svSetValue (ifcfg, "DHCPV6C", NULL, FALSE);
|
||||||
|
svSetValue (ifcfg, "IPV6_DEFROUTE", "yes", FALSE);
|
||||||
|
svSetValue (ifcfg, "IPV6_PEERDNS", "yes", FALSE);
|
||||||
|
svSetValue (ifcfg, "IPV6_PEERROUTES", "yes", FALSE);
|
||||||
|
svSetValue (ifcfg, "IPV6_FAILURE_FATAL", "no", FALSE);
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = nm_setting_ip6_config_get_method (s_ip6);
|
value = nm_setting_ip6_config_get_method (s_ip6);
|
||||||
@@ -2210,10 +2216,8 @@ write_connection (NMConnection *connection,
|
|||||||
if (!write_ip4_setting (connection, ifcfg, error))
|
if (!write_ip4_setting (connection, ifcfg, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (nm_connection_get_setting_ip6_config (connection)) {
|
if (!write_ip6_setting (connection, ifcfg, error))
|
||||||
if (!write_ip6_setting (connection, ifcfg, error))
|
goto out;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
write_connection_setting (s_con, ifcfg);
|
write_connection_setting (s_con, ifcfg);
|
||||||
|
Reference in New Issue
Block a user