From 1fd56c0e333e1e800221581b6da4de79b381195e Mon Sep 17 00:00:00 2001 From: Simon Kelley Date: Wed, 30 Oct 2019 12:58:28 +0000 Subject: [PATCH] Tidy up CNAME representaion. Use an explicit discriminator for the target union. --- src/cache.c | 22 ++++++++++------------ src/dnsmasq.h | 7 ++----- src/rfc1035.c | 7 +++---- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/cache.c b/src/cache.c index 37f0a89..6168073 100644 --- a/src/cache.c +++ b/src/cache.c @@ -276,10 +276,10 @@ char *cache_get_name(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 crecp->addr.cname.target.name; } @@ -309,7 +309,7 @@ struct crec *cache_enumerate(int init) 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; /* 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. */ if (newc) { - if (!crecp) - { - newc->addr.cname.target.cache = NULL; - /* anything other than zero, to avoid being mistaken for CNAME to interface-name */ - newc->addr.cname.uid = 1; - } - else + newc->addr.cname.is_name_ptr = 0; + + if (!crecp) + newc->addr.cname.target.cache = NULL; + else { next_uid(crecp); newc->addr.cname.target.cache = crecp; @@ -1226,7 +1224,7 @@ void cache_reload(void) cache->ttd = a->ttl; cache->name.namep = a->alias; 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_hash(cache); make_non_terminals(cache); diff --git a/src/dnsmasq.h b/src/dnsmasq.h index c81e00a..78f808d 100644 --- a/src/dnsmasq.h +++ b/src/dnsmasq.h @@ -289,7 +289,8 @@ union all_addr { struct crec *cache; char *name; } target; - unsigned int uid; /* 0 if union is char * */ + unsigned int uid; + int is_name_ptr; /* disciminates target union */ } cname; struct { struct blockdata *keydata; @@ -483,10 +484,6 @@ struct crec { #define UID_NONE 0 /* 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_HOSTS 2 #define SRC_AH 3 diff --git a/src/rfc1035.c b/src/rfc1035.c index 6c6f66d..502744b 100644 --- a/src/rfc1035.c +++ b/src/rfc1035.c @@ -784,12 +784,11 @@ int extract_addresses(struct dns_header *header, size_t qlen, char *name, time_t { if (!cname_count--) 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; - /* anything other than zero, to avoid being mistaken for a local CNAME */ - newc->addr.cname.uid = 1; + newc->addr.cname.is_name_ptr = 0; if (cpp) { next_uid(newc);