Tidy up CNAME representaion.

Use an explicit discriminator for the target union.
This commit is contained in:
Simon Kelley
2019-10-30 12:58:28 +00:00
parent 376cb97685
commit 1fd56c0e33
3 changed files with 15 additions and 21 deletions

View File

@@ -276,10 +276,10 @@ char *cache_get_name(struct crec *crecp)
char *cache_get_cname_target(struct crec *crecp) char *cache_get_cname_target(struct crec *crecp)
{ {
if (crecp->addr.cname.uid != SRC_PTR) if (crecp->addr.cname.is_name_ptr)
return crecp->addr.cname.target.name;
else
return cache_get_name(crecp->addr.cname.target.cache); return cache_get_name(crecp->addr.cname.target.cache);
return crecp->addr.cname.target.name;
} }
@@ -309,7 +309,7 @@ struct crec *cache_enumerate(int init)
static int is_outdated_cname_pointer(struct crec *crecp) static int is_outdated_cname_pointer(struct crec *crecp)
{ {
if (!(crecp->flags & F_CNAME) || crecp->addr.cname.uid == SRC_PTR) if (!(crecp->flags & F_CNAME) || crecp->addr.cname.is_name_ptr)
return 0; return 0;
/* NB. record may be reused as DS or DNSKEY, where uid is /* NB. record may be reused as DS or DNSKEY, where uid is
@@ -776,13 +776,11 @@ int cache_recv_insert(time_t now, int fd)
the order reversal on the new_chain. */ the order reversal on the new_chain. */
if (newc) if (newc)
{ {
if (!crecp) newc->addr.cname.is_name_ptr = 0;
{
newc->addr.cname.target.cache = NULL; if (!crecp)
/* anything other than zero, to avoid being mistaken for CNAME to interface-name */ newc->addr.cname.target.cache = NULL;
newc->addr.cname.uid = 1; else
}
else
{ {
next_uid(crecp); next_uid(crecp);
newc->addr.cname.target.cache = crecp; newc->addr.cname.target.cache = crecp;
@@ -1226,7 +1224,7 @@ void cache_reload(void)
cache->ttd = a->ttl; cache->ttd = a->ttl;
cache->name.namep = a->alias; cache->name.namep = a->alias;
cache->addr.cname.target.name = a->target; cache->addr.cname.target.name = a->target;
cache->addr.cname.uid = SRC_PTR; cache->addr.cname.is_name_ptr = 1;
cache->uid = UID_NONE; cache->uid = UID_NONE;
cache_hash(cache); cache_hash(cache);
make_non_terminals(cache); make_non_terminals(cache);

View File

@@ -289,7 +289,8 @@ union all_addr {
struct crec *cache; struct crec *cache;
char *name; char *name;
} target; } target;
unsigned int uid; /* 0 if union is char * */ unsigned int uid;
int is_name_ptr; /* disciminates target union */
} cname; } cname;
struct { struct {
struct blockdata *keydata; struct blockdata *keydata;
@@ -483,10 +484,6 @@ struct crec {
#define UID_NONE 0 #define UID_NONE 0
/* Values of uid in crecs with F_CONFIG bit set. */ /* Values of uid in crecs with F_CONFIG bit set. */
/* cname to uid SRC_PTR are to locally-configured CNAME
so use UID_NONE for that to
eliminate clashes with any other uid */
#define SRC_PTR UID_NONE
#define SRC_CONFIG 1 #define SRC_CONFIG 1
#define SRC_HOSTS 2 #define SRC_HOSTS 2
#define SRC_AH 3 #define SRC_AH 3

View File

@@ -784,12 +784,11 @@ int extract_addresses(struct dns_header *header, size_t qlen, char *name, time_t
{ {
if (!cname_count--) if (!cname_count--)
return 0; /* looped CNAMES */ return 0; /* looped CNAMES */
newc = cache_insert(name, NULL, C_IN, now, attl, F_CNAME | F_FORWARD | secflag);
if (newc) if ((newc = cache_insert(name, NULL, C_IN, now, attl, F_CNAME | F_FORWARD | secflag)))
{ {
newc->addr.cname.target.cache = NULL; newc->addr.cname.target.cache = NULL;
/* anything other than zero, to avoid being mistaken for a local CNAME */ newc->addr.cname.is_name_ptr = 0;
newc->addr.cname.uid = 1;
if (cpp) if (cpp)
{ {
next_uid(newc); next_uid(newc);