mirror of
https://github.com/pi-hole/dnsmasq.git
synced 2025-12-19 10:18:25 +00:00
Tidy up CNAME representaion.
Use an explicit discriminator for the target union.
This commit is contained in:
22
src/cache.c
22
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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user