Don't silently discard all-zeroes adddresses in --host-record.

This commit is contained in:
Simon Kelley
2019-10-25 17:46:49 +01:00
parent 1292e1a557
commit 157d8cfd6a
3 changed files with 15 additions and 6 deletions

View File

@@ -1290,7 +1290,7 @@ void cache_reload(void)
for (hr = daemon->host_records; hr; hr = hr->next) for (hr = daemon->host_records; hr; hr = hr->next)
for (nl = hr->names; nl; nl = nl->next) for (nl = hr->names; nl; nl = nl->next)
{ {
if (hr->addr.s_addr != 0 && if ((hr->flags & HR_4) &&
(cache = whine_malloc(SIZEOF_POINTER_CREC))) (cache = whine_malloc(SIZEOF_POINTER_CREC)))
{ {
cache->name.namep = nl->name; cache->name.namep = nl->name;
@@ -1299,7 +1299,7 @@ void cache_reload(void)
add_hosts_entry(cache, (union all_addr *)&hr->addr, INADDRSZ, SRC_CONFIG, (struct crec **)daemon->packet, revhashsz); add_hosts_entry(cache, (union all_addr *)&hr->addr, INADDRSZ, SRC_CONFIG, (struct crec **)daemon->packet, revhashsz);
} }
if (!IN6_IS_ADDR_UNSPECIFIED(&hr->addr6) && if ((hr->flags & HR_6) &&
(cache = whine_malloc(SIZEOF_POINTER_CREC))) (cache = whine_malloc(SIZEOF_POINTER_CREC)))
{ {
cache->name.namep = nl->name; cache->name.namep = nl->name;

View File

@@ -397,9 +397,11 @@ struct auth_zone {
struct auth_zone *next; struct auth_zone *next;
}; };
#define HR_6 1
#define HR_4 2
struct host_record { struct host_record {
int ttl; int ttl, flags;
struct name_list { struct name_list {
char *name; char *name;
struct name_list *next; struct name_list *next;

View File

@@ -4321,6 +4321,7 @@ err:
new = opt_malloc(sizeof(struct host_record)); new = opt_malloc(sizeof(struct host_record));
memset(new, 0, sizeof(struct host_record)); memset(new, 0, sizeof(struct host_record));
new->ttl = -1; new->ttl = -1;
new->flags = 0;
while (arg) while (arg)
{ {
@@ -4333,9 +4334,15 @@ err:
if (*dig == 0) if (*dig == 0)
new->ttl = atoi(arg); new->ttl = atoi(arg);
else if (inet_pton(AF_INET, arg, &addr.addr4)) else if (inet_pton(AF_INET, arg, &addr.addr4))
{
new->addr = addr.addr4; new->addr = addr.addr4;
new->flags |= HR_4;
}
else if (inet_pton(AF_INET6, arg, &addr.addr6)) else if (inet_pton(AF_INET6, arg, &addr.addr6))
{
new->addr6 = addr.addr6; new->addr6 = addr.addr6;
new->flags |= HR_6;
}
else else
{ {
int nomem; int nomem;
@@ -5083,7 +5090,7 @@ void read_opts(int argc, char **argv, char *compile_opts)
#define NOLOOP 1 #define NOLOOP 1
#define TESTLOOP 2 #define TESTLOOP 2
/* Fill in TTL for CNAMES noe we have local_ttl. /* Fill in TTL for CNAMES now we have local_ttl.
Also prepare to do loop detection. */ Also prepare to do loop detection. */
for (cn = daemon->cnames; cn; cn = cn->next) for (cn = daemon->cnames; cn; cn = cn->next)
{ {