ifcfg-rh: handle disabled IPv4 correctly
authorDan Williams <dcbw@redhat.com>
Thu, 15 Apr 2010 21:52:43 +0000 (14:52 -0700)
committerDan Williams <dcbw@redhat.com>
Thu, 15 Apr 2010 21:52:43 +0000 (14:52 -0700)
Instead of not including the IP4 setting, set its method to disabled.
In reality either one is legal, but including the IP4 setting wtih
the method set to 'disabled' is more explicit.

system-settings/plugins/ifcfg-rh/reader.c
system-settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
system-settings/plugins/ifcfg-rh/writer.c

index 32575f3..378aff4 100644 (file)
@@ -1215,7 +1215,10 @@ make_ip4_setting (shvarFile *ifcfg,
                if (!tmp_ip4 && !tmp_prefix && !tmp_netmask) {
                        if (valid_ip6_config) {
                                /* Nope, no IPv4 */
-                               goto done;
+                               g_object_set (s_ip4,
+                                             NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED,
+                                             NULL);
+                               return NM_SETTING (s_ip4);
                        }
 
                        method = NM_SETTING_IP4_CONFIG_METHOD_AUTO;
index cfe93d6..2f77be2 100644 (file)
@@ -2165,6 +2165,7 @@ test_read_wired_ipv6_only (void)
        const char *expected_dns1 = "1:2:3:4::a";
        NMIP6Address *ip6_addr;
        struct in6_addr addr;
+       const char *method;
 
        connection = connection_from_file (TEST_IFCFG_WIRED_IPV6_ONLY,
                                           NULL,
@@ -2217,11 +2218,18 @@ test_read_wired_ipv6_only (void)
        /* ===== IPv4 SETTING ===== */
 
        s_ip4 = NM_SETTING_IP4_CONFIG (nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG));
-       ASSERT (s_ip4 == NULL,
-               "wired-ipv6-only-verify-ip4", "failed to verify %s: unexpected %s setting",
+       ASSERT (s_ip4 != NULL,
+               "wired-ipv6-only-verify-ip4", "failed to verify %s: missing %s setting",
                TEST_IFCFG_WIRED_IPV6_MANUAL,
                NM_SETTING_IP4_CONFIG_SETTING_NAME);
 
+       method = nm_setting_ip4_config_get_method (s_ip4);
+       ASSERT (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0,
+               "wired-ipv6-only-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
+               TEST_IFCFG_WIRED_IPV6_MANUAL,
+               NM_SETTING_IP4_CONFIG_SETTING_NAME,
+               NM_SETTING_IP4_CONFIG_METHOD);
+
        /* ===== IPv6 SETTING ===== */
 
        s_ip6 = NM_SETTING_IP6_CONFIG (nm_connection_get_setting (connection, NM_TYPE_SETTING_IP6_CONFIG));
@@ -5264,6 +5272,7 @@ test_write_wired_static_ip6_only (void)
        NMConnection *reread;
        NMSettingConnection *s_con;
        NMSettingWired *s_wired;
+       NMSettingIP4Config *s_ip4;
        NMSettingIP6Config *s_ip6;
        static unsigned char tmpmac[] = { 0x31, 0x33, 0x33, 0x37, 0xbe, 0xcd };
        GByteArray *mac;
@@ -5317,6 +5326,17 @@ test_write_wired_static_ip6_only (void)
        g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac, NULL);
        g_byte_array_free (mac, TRUE);
 
+       /* IP4 setting */
+       s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+       ASSERT (s_ip4 != NULL,
+               "wired-static-ip6-only-write", "failed to allocate new %s setting",
+               NM_SETTING_IP4_CONFIG_SETTING_NAME);
+       nm_connection_add_setting (connection, NM_SETTING (s_ip4));
+
+       g_object_set (s_ip4,
+                     NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED,
+                     NULL);
+
        /* IP6 setting */
        s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
        ASSERT (s_ip6 != NULL,
@@ -5373,9 +5393,6 @@ test_write_wired_static_ip6_only (void)
        ASSERT (nm_connection_verify (reread, &error),
                "wired-static-ip6-only-write-reread-verify", "failed to verify %s: %s", testfile, error->message);
 
-       ASSERT (nm_connection_get_setting (reread, NM_TYPE_SETTING_IP4_CONFIG) == NULL,
-               "wired-static-ip6-only-write-reread-verify", "unexpected IPv4 setting");
-
        ASSERT (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT) == TRUE,
                "wired-static-ip6-only-write", "written and re-read connection weren't the same.");
 
index cc24a96..8085584 100644 (file)
@@ -908,9 +908,13 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
        guint32 i, num;
        GString *searches;
        gboolean success = FALSE;
+       const char *method = NULL;
 
        s_ip4 = (NMSettingIP4Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG);
-       if (!s_ip4) {
+       if (s_ip4)
+               method = nm_setting_ip4_config_get_method (s_ip4);
+
+       if (!s_ip4 || (method && !strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED))) {
                int result;
 
                /* IPv4 disabled, clear IPv4 related parameters */