ifcfg-rh: read/write ipv4.dad-timeout using ARPING_WAIT
authorJiří Klimeš <jklimes@redhat.com>
Tue, 8 Sep 2015 08:55:11 +0000 (10:55 +0200)
committerBeniamino Galvani <bgalvani@redhat.com>
Wed, 20 Jan 2016 10:53:47 +0000 (11:53 +0100)
ARPING_WAIT is used for DAD by Red Hat initscrips (ifup-eth).

libnm-core/nm-setting-ip4-config.c
src/settings/plugins/ifcfg-rh/reader.c
src/settings/plugins/ifcfg-rh/writer.c

index 7708b6c..35dbba4 100644 (file)
@@ -682,6 +682,16 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *ip4_class)
                                      G_PARAM_READWRITE |
                                      G_PARAM_STATIC_STRINGS));
 
+       /* ---ifcfg-rh---
+        * property: dad-timeout
+        * variable: ARPING_WAIT
+        * default: missing variable means global default (config override or 3)
+        * description: Timeout (in seconds) for performing DAD before configuring
+        * IPv4 addresses. 0 turns off the DAD completely, -1 means default value.
+        * example: ARPING_WAIT=2
+        * ---end---
+        */
+
        /**
         * NMSettingIP4Config:dhcp-timeout:
         *
index bcb726a..6f20dc1 100644 (file)
@@ -924,6 +924,7 @@ make_ip4_setting (shvarFile *ifcfg,
        shvarFile *network_ifcfg;
        shvarFile *route_ifcfg;
        gboolean never_default = FALSE;
+       gint64 timeout;
 
        s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
 
@@ -1199,6 +1200,11 @@ make_ip4_setting (shvarFile *ifcfg,
                }
        }
 
+       timeout = svGetValueInt64 (ifcfg, "ARPING_WAIT", 10, -1,
+                                  NM_SETTING_IP_CONFIG_DAD_TIMEOUT_MAX / 1000, -1);
+       g_object_set (s_ip4, NM_SETTING_IP_CONFIG_DAD_TIMEOUT,
+                     (gint) (timeout <= 0 ? timeout : timeout * 1000), NULL);
+
        return NM_SETTING (s_ip4);
 
 done:
index 5770d66..ec174a5 100644 (file)
@@ -1947,7 +1947,7 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
        gint32 j;
        guint32 i, n, num;
        gint64 route_metric;
-       int dhcp_timeout;
+       int timeout;
        GString *searches;
        gboolean success = FALSE;
        gboolean fake_ip4 = FALSE;
@@ -2156,8 +2156,8 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
                if (value)
                        svSetValue (ifcfg, "DHCP_CLIENT_ID", value, FALSE);
 
-               dhcp_timeout = nm_setting_ip4_config_get_dhcp_timeout (NM_SETTING_IP4_CONFIG (s_ip4));
-               tmp = dhcp_timeout ? g_strdup_printf ("%d", dhcp_timeout) : NULL;
+               timeout = nm_setting_ip4_config_get_dhcp_timeout (NM_SETTING_IP4_CONFIG (s_ip4));
+               tmp = timeout ? g_strdup_printf ("%d", timeout) : NULL;
                svSetValue (ifcfg, "IPV4_DHCP_TIMEOUT", tmp, FALSE);
                g_free (tmp);
        }
@@ -2248,6 +2248,16 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
                        goto out;
        }
 
+       timeout = nm_setting_ip_config_get_dad_timeout (s_ip4);
+       if (timeout < 0)
+               svSetValue (ifcfg, "ARPING_WAIT", NULL, FALSE);
+       else if (timeout == 0)
+               svSetValue (ifcfg, "ARPING_WAIT", "0", FALSE);
+       else {
+               /* Round the value up to next integer */
+               svSetValueInt64 (ifcfg, "ARPING_WAIT", (timeout - 1) / 1000 + 1);
+       }
+
        success = TRUE;
 
 out: