inet_ntop(AF_INET6, addr, ipbuf, sizeof(ipbuf) - 1);
- if (ctxt->c->length == 128 && ctxt->c->hostname) {
+ if (ctxt->c->length == 128 && ctxt->c->hostname &&
+ !(ctxt->c->flags & OAF_BROKEN_HOSTNAME)) {
fputs(ipbuf, ctxt->fp);
char b[256];
odhcpd_hexlify(duidbuf, ctxt.c->clid_data, ctxt.c->clid_len);
/* iface DUID iaid hostname lifetime assigned length [addrs...] */
- ctxt.buf_idx = snprintf(ctxt.buf, ctxt.buf_len, "# %s %s %x %s %ld %x %u ",
+ ctxt.buf_idx = snprintf(ctxt.buf, ctxt.buf_len, "# %s %s %x %s%s %ld %x %u ",
ctxt.iface->ifname, duidbuf, ntohl(ctxt.c->iaid),
+ (ctxt.c->flags & OAF_BROKEN_HOSTNAME) ? "broken\\x20" : "",
(ctxt.c->hostname ? ctxt.c->hostname : "-"),
(ctxt.c->valid_until > now ?
(ctxt.c->valid_until - now + wall_time) :
odhcpd_hexlify(duidbuf, c->hwaddr, sizeof(c->hwaddr));
/* iface DUID iaid hostname lifetime assigned length [addrs...] */
- ctxt.buf_idx = snprintf(ctxt.buf, ctxt.buf_len, "# %s %s ipv4 %s %ld %x 32 ",
+ ctxt.buf_idx = snprintf(ctxt.buf, ctxt.buf_len, "# %s %s ipv4 %s%s %ld %x 32 ",
ctxt.iface->ifname, duidbuf,
+ (c->flags & OAF_BROKEN_HOSTNAME) ? "broken\\x20" : "",
(c->hostname ? c->hostname : "-"),
(c->valid_until > now ?
(c->valid_until - now + wall_time) :
struct in_addr addr = {.s_addr = c->addr};
inet_ntop(AF_INET, &addr, ipbuf, sizeof(ipbuf) - 1);
- if (c->hostname) {
+ if (c->hostname && !(c->flags & OAF_BROKEN_HOSTNAME)) {
fputs(ipbuf, ctxt.fp);
char b[256];
if (a->hostname) {
memcpy(a->hostname, hostname, hostname_len);
a->hostname[hostname_len] = 0;
+
+ if (odhcpd_valid_hostname(a->hostname))
+ a->flags &= ~OAF_BROKEN_HOSTNAME;
+ else
+ a->flags |= OAF_BROKEN_HOSTNAME;
}
}
a->accept_reconf = accept_reconf;
return true;
}
+
+bool odhcpd_valid_hostname(const char *name)
+{
+#define MAX_LABEL 63
+ const char *c, *label, *label_end;
+ int label_sz = 0;
+
+ for (c = name, label_sz = 0, label = name, label_end = name + strcspn(name, ".") - 1;
+ *c && label_sz <= MAX_LABEL; c++) {
+ if ((*c >= '0' && *c <= '9') ||
+ (*c >= 'A' && *c <= 'Z') ||
+ (*c >= 'a' && *c <= 'z')) {
+ label_sz++;
+ continue;
+ }
+
+ if ((*c == '_' || *c == '-') && c != label && c != label_end) {
+ label_sz++;
+ continue;
+ }
+
+ if (*c == '.') {
+ if (*(c + 1)) {
+ label = c + 1;
+ label_end = label + strcspn(label, ".") - 1;
+ label_sz = 0;
+ }
+ continue;
+ }
+
+ return false;
+ }
+
+ return (label_sz && label_sz <= MAX_LABEL ? true : false);
+}
enum odhcpd_assignment_flags {
- OAF_TENTATIVE = (1 << 0),
- OAF_BOUND = (1 << 1),
- OAF_STATIC = (1 << 2),
+ OAF_TENTATIVE = (1 << 0),
+ OAF_BOUND = (1 << 1),
+ OAF_STATIC = (1 << 2),
+ OAF_BROKEN_HOSTNAME = (1 << 3),
};
struct config {
int odhcpd_netmask2bitlen(bool v6, void *mask);
bool odhcpd_bitlen2netmask(bool v6, unsigned int bits, void *mask);
+bool odhcpd_valid_hostname(const char *name);
int config_parse_interface(void *data, size_t len, const char *iname, bool overwrite);
if (c->flags & OAF_STATIC)
blobmsg_add_string(&b, NULL, "static");
+
+ if (c->flags & OAF_BROKEN_HOSTNAME)
+ blobmsg_add_string(&b, NULL, "broken-hostname");
blobmsg_close_array(&b, m);
buf = blobmsg_alloc_string_buffer(&b, "address", INET_ADDRSTRLEN);