changeset 1175:023d61dad33c draft

We should only send short hostnames as qualfied ones confuse ISC DHCP server. If a FQDN is required, then use that option instead of the hostname. Backported from trunk, r1174.
author Roy Marples <roy@marples.name>
date Mon, 26 Jan 2009 12:00:35 +0000
parents 799259f7cc1b
children efb5a8686dd8
files dhcp.c dhcpcd.c dhcpcd.h
diffstat 3 files changed, 24 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/dhcp.c	Mon Jan 26 09:14:54 2009 +0000
+++ b/dhcp.c	Mon Jan 26 12:00:35 2009 +0000
@@ -767,6 +767,7 @@
 	uint16_t sz;
 	const struct dhcp_opt *opt;
 	size_t len;
+	const char *hp;
 
 	dhcp = xzalloc(sizeof (*dhcp));
 	m = (uint8_t *)dhcp;
@@ -886,10 +887,23 @@
 			}
 		}
 
+		/* Regardless of RFC2132, we should always send a hostname
+		 * upto the first dot (the short hostname) as otherwise
+		 * confuses some DHCP servers when updating DNS.
+		 * The FQDN option should be used if a FQDN is required. */
 		if (options->hostname[0]) {
 			*p++ = DHO_HOSTNAME;
-			memcpy(p, options->hostname, options->hostname[0] + 1);
-			p += options->hostname[0] + 1;
+			hp = strchr(options->hostname, '.');
+			if (hp) {
+				*p++ = hp - options->hostname;
+				memcpy(p, options->hostname, hp - options->hostname);
+				p += hp - options->hostname;
+			} else {
+				len = strlen(options->hostname);
+				*p++ = len;
+				memcpy(p, options->hostname, len);
+				p += len;
+			}
 		}
 		if (options->fqdn != FQDN_DISABLE) {
 			/* IETF DHC-FQDN option (81), RFC4702 */
@@ -909,8 +923,8 @@
 			*p++ = (options->fqdn & 0x09) | 0x04;
 			*p++ = 0; /* from server for PTR RR */
 			*p++ = 0; /* from server for A RR if S=1 */
-			ul = encode_rfc1035(options->hostname + 1, p,
-					options->hostname[0]);
+			ul = encode_rfc1035(options->hostname, p,
+					    strlen(options->hostname));
 			*lp += ul;
 			p += ul;
 		}
--- a/dhcpcd.c	Mon Jan 26 09:14:54 2009 +0000
+++ b/dhcpcd.c	Mon Jan 26 12:00:35 2009 +0000
@@ -648,13 +648,12 @@
 	}
 #endif
 
-	gethostname(options->hostname + 1, HOSTNAME_MAX_LEN);
+	gethostname(options->hostname, HOSTNAME_MAX_LEN);
 	/* Ensure that the hostname is NULL terminated */ 
-	options->hostname[HOSTNAME_MAX_LEN + 1] = '\0';
-	if (strcmp(options->hostname + 1, "(none)") == 0 ||
-	    strcmp(options->hostname + 1, "localhost") == 0)
-		options->hostname[1] = '\0';
-	*options->hostname = strlen(options->hostname + 1);
+	options->hostname[HOSTNAME_MAX_LEN] = '\0';
+	if (strcmp(options->hostname, "(none)") == 0 ||
+	    strcmp(options->hostname, "localhost") == 0)
+		options->hostname[0] = '\0';
 
 	while ((opt = getopt_long(argc, argv, OPTS EXTRA_OPTS,
 				  longopts, &option_index)) != -1)
--- a/dhcpcd.h	Mon Jan 26 09:14:54 2009 +0000
+++ b/dhcpcd.h	Mon Jan 26 12:00:35 2009 +0000
@@ -82,7 +82,7 @@
 	char script[PATH_MAX];
 	char pidfile[PATH_MAX];
 
-	char hostname[HOSTNAME_MAX_LEN + 2];
+	char hostname[HOSTNAME_MAX_LEN + 1]; /* We don't store the lenth */
 	int fqdn;
 	uint8_t vendorclassid[VENDORCLASSID_MAX_LEN + 2];
 	char clientid[CLIENTID_MAX_LEN + 2];