summary refs log tree commit diff
path: root/src/dhcp-manager/nm-dhcp-dhclient-utils.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2016-01-20 16:26:51 +0100
committerMichael Biebl <biebl@debian.org>2016-01-20 16:26:51 +0100
commit494f296a3baab08522617b24b1f126d8f9a17502 (patch)
treec8ef32fb0dd1c4ff35a0b38e787abb58692de0cd /src/dhcp-manager/nm-dhcp-dhclient-utils.c
parent54f6333410ffd570e62717d9e77c5c987175e397 (diff)
Imported Upstream version 1.1.90 upstream/1.1.90
Diffstat (limited to 'src/dhcp-manager/nm-dhcp-dhclient-utils.c')
-rw-r--r--src/dhcp-manager/nm-dhcp-dhclient-utils.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/dhcp-manager/nm-dhcp-dhclient-utils.c b/src/dhcp-manager/nm-dhcp-dhclient-utils.c
index 41ce5354..5340d21a 100644
--- a/src/dhcp-manager/nm-dhcp-dhclient-utils.c
+++ b/src/dhcp-manager/nm-dhcp-dhclient-utils.c
@@ -19,19 +19,17 @@
 
 #include "config.h"
 
-#include <glib.h>
-#include <glib/gi18n.h>
 #include <string.h>
 #include <ctype.h>
 #include <arpa/inet.h>
 
+#include "nm-default.h"
 #include "nm-dhcp-dhclient-utils.h"
 #include "nm-dhcp-utils.h"
 #include "nm-ip4-config.h"
 #include "nm-utils.h"
 #include "nm-platform.h"
 #include "NetworkManagerUtils.h"
-#include "gsystem-local-alloc.h"
 #include "nm-macros-internal.h"
 
 #define CLIENTID_TAG            "send dhcp-client-identifier"
@@ -57,24 +55,29 @@ add_also_request (GPtrArray *array, const char *item)
 }
 
 static void
-add_hostname4 (GString *str, const char *format, const char *hostname)
+add_hostname4 (GString *str, const char *hostname, const char *fqdn)
 {
 	char *plain_hostname, *dot;
 
-	if (hostname) {
+	if (fqdn) {
+		g_string_append_printf (str, FQDN_FORMAT "\n", fqdn);
+		g_string_append (str,
+		                 "send fqdn.encoded on;\n"
+		                 "send fqdn.server-update on;\n");
+	} else if (hostname) {
 		plain_hostname = g_strdup (hostname);
 		dot = strchr (plain_hostname, '.');
 		/* get rid of the domain */
 		if (dot)
 			*dot = '\0';
 
-		g_string_append_printf (str, format, plain_hostname);
+		g_string_append_printf (str, HOSTNAME4_FORMAT "\n", plain_hostname);
 		g_free (plain_hostname);
 	}
 }
 
 static void
-add_ip4_config (GString *str, GBytes *client_id, const char *hostname)
+add_ip4_config (GString *str, GBytes *client_id, const char *hostname, const char *fqdn)
 {
 	if (client_id) {
 		const char *p;
@@ -109,7 +112,7 @@ add_ip4_config (GString *str, GBytes *client_id, const char *hostname)
 		g_string_append (str, "; # added by NetworkManager\n");
 	}
 
-	add_hostname4 (str, HOSTNAME4_FORMAT "\n", hostname);
+	add_hostname4 (str, hostname, fqdn);
 
 	g_string_append_c (str, '\n');
 
@@ -197,6 +200,7 @@ nm_dhcp_dhclient_create_config (const char *interface,
                                 GBytes *client_id,
                                 const char *anycast_addr,
                                 const char *hostname,
+                                const char *fqdn,
                                 const char *orig_path,
                                 const char *orig_contents,
                                 GBytes **out_new_client_id)
@@ -234,7 +238,7 @@ nm_dhcp_dhclient_create_config (const char *interface,
 			}
 
 			/* Override config file hostname and use one from the connection */
-			if (hostname) {
+			if (hostname || fqdn) {
 				if (strncmp (p, HOSTNAME4_TAG, strlen (HOSTNAME4_TAG)) == 0)
 					continue;
 				if (strncmp (p, FQDN_TAG, strlen (FQDN_TAG)) == 0)
@@ -300,7 +304,7 @@ nm_dhcp_dhclient_create_config (const char *interface,
 		add_also_request (alsoreq, "dhcp6.domain-search");
 		add_also_request (alsoreq, "dhcp6.client-id");
 	} else {
-		add_ip4_config (new_contents, client_id, hostname);
+		add_ip4_config (new_contents, client_id, hostname, fqdn);
 		add_also_request (alsoreq, "rfc3442-classless-static-routes");
 		add_also_request (alsoreq, "ms-classless-static-routes");
 		add_also_request (alsoreq, "static-routes");
@@ -576,6 +580,7 @@ lease_validity_span (const char *str_expire, GDateTime *now)
 /**
  * nm_dhcp_dhclient_read_lease_ip_configs:
  * @iface: the interface name to match leases with
+ * @ifindex: interface index of @iface
  * @contents: the contents of a dhclient leasefile
  * @ipv6: whether to read IPv4 or IPv6 leases
  * @now: the current UTC date/time; pass %NULL to automatically use current
@@ -589,6 +594,7 @@ lease_validity_span (const char *str_expire, GDateTime *now)
  */
 GSList *
 nm_dhcp_dhclient_read_lease_ip_configs (const char *iface,
+                                        int ifindex,
                                         const char *contents,
                                         gboolean ipv6,
                                         GDateTime *now)
@@ -675,6 +681,7 @@ nm_dhcp_dhclient_read_lease_ip_configs (const char *iface,
 			continue;
 		if (!inet_pton (AF_INET, value, &address.address))
 			continue;
+		address.peer_address = address.address;
 
 		/* Gateway */
 		value = g_hash_table_lookup (hash, "option routers");
@@ -696,7 +703,7 @@ nm_dhcp_dhclient_read_lease_ip_configs (const char *iface,
 		address.lifetime = address.preferred = expiry;
 		address.source = NM_IP_CONFIG_SOURCE_DHCP;
 
-		ip4 = nm_ip4_config_new ();
+		ip4 = nm_ip4_config_new (ifindex);
 		nm_ip4_config_add_address (ip4, &address);
 		nm_ip4_config_set_gateway (ip4, gw);