From: Roy Marples Date: Mon, 26 Jan 2009 12:00:01 +0000 (+0000) Subject: We should only send short hostnames as qualfied ones confuse ISC DHCP server. If... X-Git-Tag: v5.0.0~101 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d9af32de8a952e1dd93f38206acea8fb18f48c8;p=thirdparty%2Fdhcpcd.git 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. --- diff --git a/dhcp.c b/dhcp.c index a1029c93..b157c6f8 100644 --- a/dhcp.c +++ b/dhcp.c @@ -766,6 +766,7 @@ make_message(struct dhcp_message **message, uint32_t ul; uint16_t sz; size_t len; + const char *hp; const struct dhcp_opt *opt; const struct if_options *ifo = iface->state->options; const struct dhcp_lease *lease = &iface->state->lease; @@ -889,10 +890,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 (ifo->hostname[0]) { *p++ = DHO_HOSTNAME; - memcpy(p, ifo->hostname, ifo->hostname[0] + 1); - p += ifo->hostname[0] + 1; + hp = strchr(ifo->hostname, '.'); + if (hp) { + *p++ = hp - ifo->hostname; + memcpy(p, ifo->hostname, hp - ifo->hostname); + p += hp - ifo->hostname; + } else { + len = strlen(ifo->hostname); + *p++ = len; + memcpy(p, ifo->hostname, len); + p += len; + } } if (ifo->fqdn != FQDN_DISABLE) { /* IETF DHC-FQDN option (81), RFC4702 */ @@ -912,8 +926,8 @@ make_message(struct dhcp_message **message, *p++ = (ifo->fqdn & 0x09) | 0x04; *p++ = 0; /* from server for PTR RR */ *p++ = 0; /* from server for A RR if S=1 */ - ul = encode_rfc1035(ifo->hostname + 1, p, - ifo->hostname[0]); + ul = encode_rfc1035(ifo->hostname, p, + strlen(ifo->hostname)); *lp += ul; p += ul; } diff --git a/if-options.c b/if-options.c index e8eb5186..36dd1a0d 100644 --- a/if-options.c +++ b/if-options.c @@ -676,13 +676,12 @@ read_config(const char *file, const char *ifname, const char *ssid) ifo->timeout = DEFAULT_TIMEOUT; ifo->reboot = DEFAULT_REBOOT; ifo->metric = -1; - gethostname(ifo->hostname + 1, HOSTNAME_MAX_LEN); + gethostname(ifo->hostname, HOSTNAME_MAX_LEN); /* Ensure that the hostname is NULL terminated */ - ifo->hostname[HOSTNAME_MAX_LEN + 1] = '\0'; - if (strcmp(ifo->hostname + 1, "(none)") == 0 || - strcmp(ifo->hostname + 1, "localhost") == 0) - ifo->hostname[1] = '\0'; - *ifo->hostname = strlen(ifo->hostname + 1); + ifo->hostname[HOSTNAME_MAX_LEN] = '\0'; + if (strcmp(ifo->hostname, "(none)") == 0 || + strcmp(ifo->hostname, "localhost") == 0) + ifo->hostname[0] = '\0'; strlcpy(ifo->script, SCRIPT, sizeof(ifo->script)); ifo->vendorclassid[0] = snprintf((char *)ifo->vendorclassid + 1, VENDORCLASSID_MAX_LEN, diff --git a/if-options.h b/if-options.h index 5a8b8aaf..02f5f2dc 100644 --- a/if-options.h +++ b/if-options.h @@ -88,8 +88,8 @@ struct if_options { char **environ; char script[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];