summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2009-01-26 12:00:35 +0000
committerRoy Marples <roy@marples.name>2009-01-26 12:00:35 +0000
commitf85bbdcf703c4947dc517cea889cb8bf170f0525 (patch)
treed1cdd87ffcc7638565b8b9e330904589db697bb0
parentd5a1ddc98e056a4dc33ef238f8075aaf511a83b0 (diff)
downloaddhcpcd-f85bbdcf703c4947dc517cea889cb8bf170f0525.tar.xz
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.
-rw-r--r--dhcp.c22
-rw-r--r--dhcpcd.c11
-rw-r--r--dhcpcd.h2
3 files changed, 24 insertions, 11 deletions
diff --git a/dhcp.c b/dhcp.c
index 4fe38976..d5869845 100644
--- a/dhcp.c
+++ b/dhcp.c
@@ -767,6 +767,7 @@ make_message(struct dhcp_message **message,
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 @@ make_message(struct dhcp_message **message,
}
}
+ /* 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 @@ make_message(struct dhcp_message **message,
*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;
}
diff --git a/dhcpcd.c b/dhcpcd.c
index 58321ef7..1626e395 100644
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -648,13 +648,12 @@ main(int argc, char **argv)
}
#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)
diff --git a/dhcpcd.h b/dhcpcd.h
index 0aeffaed..7d933154 100644
--- a/dhcpcd.h
+++ b/dhcpcd.h
@@ -82,7 +82,7 @@ struct options {
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];