summary refs log tree commit diff
path: root/src/core/dhcp/nm-dhcp-dhclient.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/dhcp/nm-dhcp-dhclient.c')
-rw-r--r--src/core/dhcp/nm-dhcp-dhclient.c125
1 files changed, 47 insertions, 78 deletions
diff --git a/src/core/dhcp/nm-dhcp-dhclient.c b/src/core/dhcp/nm-dhcp-dhclient.c
index 4aab4b1e..2a3af10a 100644
--- a/src/core/dhcp/nm-dhcp-dhclient.c
+++ b/src/core/dhcp/nm-dhcp-dhclient.c
@@ -148,56 +148,6 @@ get_dhclient_leasefile(int         addr_family,
     return NULL;
 }
 
-static gboolean
-merge_dhclient_config(NMDhcpDhclient     *self,
-                      int                 addr_family,
-                      const char         *iface,
-                      const char         *conf_file,
-                      GBytes             *client_id,
-                      const char         *anycast_address,
-                      const char         *hostname,
-                      guint32             timeout,
-                      gboolean            use_fqdn,
-                      NMDhcpHostnameFlags hostname_flags,
-                      const char         *mud_url,
-                      const char *const  *reject_servers,
-                      const char         *orig_path,
-                      GBytes            **out_new_client_id,
-                      GError            **error)
-{
-    gs_free char *orig = NULL;
-    gs_free char *new  = NULL;
-
-    g_return_val_if_fail(iface, FALSE);
-    g_return_val_if_fail(conf_file, FALSE);
-
-    if (orig_path && g_file_test(orig_path, G_FILE_TEST_EXISTS)) {
-        GError *read_error = NULL;
-
-        if (!g_file_get_contents(orig_path, &orig, NULL, &read_error)) {
-            _LOGW("error reading dhclient configuration %s: %s", orig_path, read_error->message);
-            g_error_free(read_error);
-        }
-    }
-
-    new = nm_dhcp_dhclient_create_config(iface,
-                                         addr_family,
-                                         client_id,
-                                         anycast_address,
-                                         hostname,
-                                         timeout,
-                                         use_fqdn,
-                                         hostname_flags,
-                                         mud_url,
-                                         reject_servers,
-                                         orig_path,
-                                         orig,
-                                         out_new_client_id);
-    nm_assert(new);
-
-    return g_file_set_contents(conf_file, new, -1, error);
-}
-
 static char *
 find_existing_config(NMDhcpDhclient *self, int addr_family, const char *iface, const char *uuid)
 {
@@ -283,6 +233,7 @@ create_dhclient_config(NMDhcpDhclient     *self,
                        const char         *iface,
                        const char         *uuid,
                        GBytes             *client_id,
+                       gboolean            send_client_id,
                        const char         *anycast_address,
                        const char         *hostname,
                        guint32             timeout,
@@ -292,44 +243,56 @@ create_dhclient_config(NMDhcpDhclient     *self,
                        const char *const  *reject_servers,
                        GBytes            **out_new_client_id)
 {
-    gs_free char *orig = NULL;
-    char *new          = NULL;
-    GError *error      = NULL;
+    gs_free char *orig_path    = NULL;
+    gs_free char *orig_content = NULL;
+    char         *new_path     = NULL;
+    gs_free char *new_content  = NULL;
+    GError       *error        = NULL;
 
     g_return_val_if_fail(iface != NULL, NULL);
 
-    new = g_strdup_printf(NMSTATEDIR "/dhclient%s-%s.conf",
-                          _addr_family_to_path_part(addr_family),
-                          iface);
-
-    _LOGD("creating composite dhclient config %s", new);
+    new_path = g_strdup_printf(NMSTATEDIR "/dhclient%s-%s.conf",
+                               _addr_family_to_path_part(addr_family),
+                               iface);
+    _LOGD("creating composite dhclient config %s", new_path);
 
-    orig = find_existing_config(self, addr_family, iface, uuid);
-    if (orig)
-        _LOGD("merging existing dhclient config %s", orig);
+    orig_path = find_existing_config(self, addr_family, iface, uuid);
+    if (orig_path)
+        _LOGD("merging existing dhclient config %s", orig_path);
     else
         _LOGD("no existing dhclient configuration to merge");
 
-    if (!merge_dhclient_config(self,
-                               addr_family,
-                               iface,
-                               new,
-                               client_id,
-                               anycast_address,
-                               hostname,
-                               timeout,
-                               use_fqdn,
-                               hostname_flags,
-                               mud_url,
-                               reject_servers,
-                               orig,
-                               out_new_client_id,
-                               &error)) {
+    if (orig_path && g_file_test(orig_path, G_FILE_TEST_EXISTS)) {
+        if (!g_file_get_contents(orig_path, &orig_content, NULL, &error)) {
+            _LOGW("error reading dhclient configuration %s: %s", orig_path, error->message);
+            g_error_free(error);
+        }
+    }
+
+    new_content = nm_dhcp_dhclient_create_config(iface,
+                                                 addr_family,
+                                                 client_id,
+                                                 send_client_id,
+                                                 anycast_address,
+                                                 hostname,
+                                                 timeout,
+                                                 use_fqdn,
+                                                 hostname_flags,
+                                                 mud_url,
+                                                 reject_servers,
+                                                 orig_path,
+                                                 orig_content,
+                                                 out_new_client_id);
+    nm_assert(new_content);
+
+    if (!g_file_set_contents(new_path, new_content, -1, &error)) {
         _LOGW("error creating dhclient configuration: %s", error->message);
-        g_clear_error(&error);
+        g_error_free(error);
+        g_free(new_path);
+        return NULL;
     }
 
-    return new;
+    return new_path;
 }
 
 static gboolean
@@ -547,11 +510,14 @@ ip4_start(NMDhcpClient *client, GError **error)
 
     client_config = nm_dhcp_client_get_config(client);
 
+    nm_assert(client_config->addr_family == AF_INET);
+
     priv->conf_file = create_dhclient_config(self,
                                              AF_INET,
                                              client_config->iface,
                                              client_config->uuid,
                                              client_config->client_id,
+                                             client_config->v4.send_client_id,
                                              client_config->anycast_address,
                                              client_config->hostname,
                                              client_config->timeout,
@@ -584,6 +550,8 @@ ip6_start(NMDhcpClient *client, const struct in6_addr *ll_addr, GError **error)
 
     config = nm_dhcp_client_get_config(client);
 
+    nm_assert(config->addr_family == AF_INET6);
+
     if (config->v6.iaid_explicit)
         _LOGW("dhclient does not support specifying an IAID for DHCPv6, it will be ignored");
 
@@ -592,6 +560,7 @@ ip6_start(NMDhcpClient *client, const struct in6_addr *ll_addr, GError **error)
                                              config->iface,
                                              config->uuid,
                                              NULL,
+                                             TRUE,
                                              config->anycast_address,
                                              config->hostname,
                                              config->timeout,