Merge branch 'pspacek/dns-name-attributes-struct' into 'main'

Replace #define DNS_NAMEATTR_* with struct of booleans

See merge request isc-projects/bind9!6902
This commit is contained in:
Petr Špaček 2022-10-13 15:22:57 +00:00
commit 4fc04b6011
17 changed files with 162 additions and 196 deletions

View file

@ -1,3 +1,7 @@
5993. [cleanup] Store dns_name_t attributes as boolean members of
the structure. Remove DNS_NAMEATTR_* macros.
Fix latent attribute handling bug in RBT. [GL !6902]
5992. [func] Introduce the new isc_mem_*x() APIs that takes extra
flags as the last argument. Currently ISC_MEM_ZERO
and ISC_MEM_ALIGN(n) flags have been implemented that

View file

@ -2583,7 +2583,7 @@ send_update(dns_name_t *zone, isc_sockaddr_t *primary) {
/* Windows doesn't like the tsig name to be compressed. */
if (updatemsg->tsigname) {
updatemsg->tsigname->attributes |= DNS_NAMEATTR_NOCOMPRESS;
updatemsg->tsigname->attributes.nocompress = true;
}
result = dns_request_create(
@ -3082,7 +3082,7 @@ start_gssrequest(dns_name_t *primary) {
}
/* Windows doesn't recognize name compression in the key name. */
keyname->attributes |= DNS_NAMEATTR_NOCOMPRESS;
keyname->attributes.nocompress = true;
rmsg = NULL;
dns_message_create(gmctx, DNS_MESSAGE_INTENTRENDER, &rmsg);

View file

@ -401,7 +401,8 @@ dns_compress_add(dns_compress_t *cctx, const dns_name_t *name,
node->name.length = node->r.length;
node->name.ndata = node->r.base;
node->name.labels = tname.labels;
node->name.attributes = DNS_NAMEATTR_ABSOLUTE;
node->name.attributes =
(struct dns_name_attrs){ .absolute = true };
node->next = cctx->table[i];
cctx->table[i] = node;
start++;

View file

@ -106,7 +106,22 @@ struct dns_name {
unsigned char *ndata;
unsigned int length;
unsigned int labels;
unsigned int attributes;
struct dns_name_attrs {
bool absolute : 1; /*%< Used by name.c */
bool readonly : 1; /*%< Used by name.c */
bool dynamic : 1; /*%< Used by name.c */
bool dynoffsets : 1; /*%< Used by name.c */
bool nocompress : 1; /*%< Used by name.c */
bool cache : 1; /*%< Used by resolver. */
bool answer : 1; /*%< Used by resolver. */
bool ncache : 1; /*%< Used by resolver. */
bool chaining : 1; /*%< Used by resolver. */
bool chase : 1; /*%< Used by resolver. */
bool wildcard : 1; /*%< Used by server. */
bool prerequisite : 1; /*%< Used by client. */
bool update : 1; /*%< Used by client. */
bool hasupdaterec : 1; /*%< Used by client. */
} attributes;
unsigned char *offsets;
isc_buffer_t *buffer;
ISC_LINK(dns_name_t) link;
@ -115,24 +130,6 @@ struct dns_name {
#define DNS_NAME_MAGIC ISC_MAGIC('D', 'N', 'S', 'n')
#define DNS_NAMEATTR_ABSOLUTE 0x00000001
#define DNS_NAMEATTR_READONLY 0x00000002
#define DNS_NAMEATTR_DYNAMIC 0x00000004
#define DNS_NAMEATTR_DYNOFFSETS 0x00000008
#define DNS_NAMEATTR_NOCOMPRESS 0x00000010
/*
* Attributes below 0x0100 reserved for name.c usage.
*/
#define DNS_NAMEATTR_CACHE 0x00000100 /*%< Used by resolver. */
#define DNS_NAMEATTR_ANSWER 0x00000200 /*%< Used by resolver. */
#define DNS_NAMEATTR_NCACHE 0x00000400 /*%< Used by resolver. */
#define DNS_NAMEATTR_CHAINING 0x00000800 /*%< Used by resolver. */
#define DNS_NAMEATTR_CHASE 0x00001000 /*%< Used by resolver. */
#define DNS_NAMEATTR_WILDCARD 0x00002000 /*%< Used by server. */
#define DNS_NAMEATTR_PREREQUISITE 0x00004000 /*%< Used by client. */
#define DNS_NAMEATTR_UPDATE 0x00008000 /*%< Used by client. */
#define DNS_NAMEATTR_HASUPDATEREC 0x00010000 /*%< Used by client. */
/*
* Various flags.
*/
@ -169,27 +166,27 @@ extern const dns_name_t *dns_wildcardname;
#define DNS_NAME_INITNONABSOLUTE(A, B) \
{ \
DNS_NAME_MAGIC, A, (sizeof(A) - 1), sizeof(B), \
DNS_NAMEATTR_READONLY, B, NULL, \
{ .readonly = true }, B, NULL, \
{ (void *)-1, (void *)-1 }, { \
NULL, NULL \
} \
}
#define DNS_NAME_INITABSOLUTE(A, B) \
{ \
DNS_NAME_MAGIC, A, sizeof(A), sizeof(B), \
DNS_NAMEATTR_READONLY | DNS_NAMEATTR_ABSOLUTE, B, \
NULL, { (void *)-1, (void *)-1 }, { \
NULL, NULL \
} \
#define DNS_NAME_INITABSOLUTE(A, B) \
{ \
DNS_NAME_MAGIC, A, sizeof(A), sizeof(B), \
{ .readonly = true, .absolute = true }, B, NULL, \
{ (void *)-1, (void *)-1 }, { \
NULL, NULL \
} \
}
#define DNS_NAME_INITEMPTY \
{ \
DNS_NAME_MAGIC, NULL, 0, 0, 0, NULL, NULL, \
{ (void *)-1, (void *)-1 }, { \
NULL, NULL \
} \
#define DNS_NAME_INITEMPTY \
{ \
DNS_NAME_MAGIC, NULL, 0, 0, {}, NULL, NULL, \
{ (void *)-1, (void *)-1 }, { \
NULL, NULL \
} \
}
/*%
@ -244,7 +241,7 @@ dns_name_reset(dns_name_t *name);
* is retained but the buffer itself is cleared.
*
* \li + Of the attributes associated with 'name', all are retained except
* DNS_NAMEATTR_ABSOLUTE.
* the absolute flag.
*
* Requires:
* \li 'name' is a valid name.
@ -1319,36 +1316,33 @@ ISC_LANG_ENDDECLS
* WARNING: No assertion checking is done for these macros.
*/
#define DNS_NAME_INIT(n, o) \
do { \
dns_name_t *_n = (n); \
/* memset(_n, 0, sizeof(*_n)); */ \
_n->magic = DNS_NAME_MAGIC; \
_n->ndata = NULL; \
_n->length = 0; \
_n->labels = 0; \
_n->attributes = 0; \
_n->offsets = (o); \
_n->buffer = NULL; \
ISC_LINK_INIT(_n, link); \
ISC_LIST_INIT(_n->list); \
#define DNS_NAME_INIT(n, o) \
do { \
dns_name_t *_n = (n); \
/* memset(_n, 0, sizeof(*_n)); */ \
_n->magic = DNS_NAME_MAGIC; \
_n->ndata = NULL; \
_n->length = 0; \
_n->labels = 0; \
_n->attributes = (struct dns_name_attrs){}; \
_n->offsets = (o); \
_n->buffer = NULL; \
ISC_LINK_INIT(_n, link); \
ISC_LIST_INIT(_n->list); \
} while (0)
#define DNS_NAME_RESET(n) \
do { \
(n)->ndata = NULL; \
(n)->length = 0; \
(n)->labels = 0; \
(n)->attributes &= ~DNS_NAMEATTR_ABSOLUTE; \
if ((n)->buffer != NULL) \
isc_buffer_clear((n)->buffer); \
#define DNS_NAME_RESET(n) \
do { \
(n)->ndata = NULL; \
(n)->length = 0; \
(n)->labels = 0; \
(n)->attributes.absolute = false; \
if ((n)->buffer != NULL) \
isc_buffer_clear((n)->buffer); \
} while (0)
#define DNS_NAME_SETBUFFER(n, b) (n)->buffer = (b)
#define DNS_NAME_ISABSOLUTE(n) \
(((n)->attributes & DNS_NAMEATTR_ABSOLUTE) != 0 ? true : false)
#define DNS_NAME_COUNTLABELS(n) ((n)->labels)
#define DNS_NAME_TOREGION(n, r) \
@ -1376,7 +1370,7 @@ ISC_LANG_ENDDECLS
#define dns_name_reset(n) DNS_NAME_RESET(n)
#define dns_name_setbuffer(n, b) DNS_NAME_SETBUFFER(n, b)
#define dns_name_countlabels(n) DNS_NAME_COUNTLABELS(n)
#define dns_name_isabsolute(n) DNS_NAME_ISABSOLUTE(n)
#define dns_name_isabsolute(n) ((n)->attributes.absolute)
#define dns_name_toregion(n, r) DNS_NAME_TOREGION(n, r)
#define dns_name_split(n, l, p, s) DNS_NAME_SPLIT(n, l, p, s)

View file

@ -71,9 +71,7 @@ struct dns_rbtnode {
/*@{*/
/*!
* The following bitfields add up to a total bitwidth of 32.
* The range of values necessary for each item is indicated,
* but in the case of "attributes" the field is wider to accommodate
* possible future expansion.
* The range of values necessary for each item is indicated.
*
* In each case below the "range" indicated is what's _necessary_ for
* the bitfield to hold, not what it actually _can_ hold.
@ -92,7 +90,7 @@ struct dns_rbtnode {
unsigned int is_root : 1; /*%< range is 0..1 */
unsigned int color : 1; /*%< range is 0..1 */
unsigned int find_callback : 1; /*%< range is 0..1 */
unsigned int attributes : 3; /*%< range is 0..2 */
bool absolute : 1; /*%< node with absolute DNS name */
unsigned int nsec : 2; /*%< range is 0..3 */
unsigned int namelen : 8; /*%< range is 1..255 */
unsigned int offsetlen : 8; /*%< range is 1..128 */
@ -605,7 +603,7 @@ dns_rbt_namefromnode(dns_rbtnode_t *node, dns_name_t *name);
* \li name->offsets == NULL
*
* Ensures:
* \li 'name' is DNS_NAMEATTR_READONLY.
* \li 'name' is readonly.
*
* \li 'name' will point directly to the labels stored after the
* dns_rbtnode_t struct.

View file

@ -1576,7 +1576,7 @@ getsection(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t dctx,
/*
* Windows doesn't like TSIG names to be compressed.
*/
msg->tsigname->attributes |= DNS_NAMEATTR_NOCOMPRESS;
msg->tsigname->attributes.nocompress = true;
rdataset = NULL;
free_rdataset = false;
free_name = false;

View file

@ -67,21 +67,19 @@ typedef enum { fw_start = 0, fw_ordinary, fw_newcurrent } fw_state;
* Note: If additional attributes are added that should not be set for
* empty names, MAKE_EMPTY() must be changed so it clears them.
*/
#define MAKE_EMPTY(name) \
do { \
name->ndata = NULL; \
name->length = 0; \
name->labels = 0; \
name->attributes &= ~DNS_NAMEATTR_ABSOLUTE; \
#define MAKE_EMPTY(name) \
do { \
name->ndata = NULL; \
name->length = 0; \
name->labels = 0; \
name->attributes.absolute = false; \
} while (0);
/*%
* A name is "bindable" if it can be set to point to a new value, i.e.
* name->ndata and name->length may be changed.
*/
#define BINDABLE(name) \
((name->attributes & \
(DNS_NAMEATTR_READONLY | DNS_NAMEATTR_DYNAMIC)) == 0)
#define BINDABLE(name) (!name->attributes.readonly && !name->attributes.dynamic)
/*%
* Note that the name data must be a char array, not a string
@ -139,7 +137,7 @@ dns_name_invalidate(dns_name_t *name) {
name->ndata = NULL;
name->length = 0;
name->labels = 0;
name->attributes = 0;
name->attributes = (struct dns_name_attrs){};
name->offsets = NULL;
name->buffer = NULL;
ISC_LINK_INIT(name, link);
@ -227,10 +225,7 @@ dns_name_isabsolute(const dns_name_t *name) {
REQUIRE(VALID_NAME(name));
if ((name->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) {
return (true);
}
return (false);
return name->attributes.absolute;
}
#define hyphenchar(c) ((c) == 0x2d)
@ -250,7 +245,7 @@ dns_name_ismailbox(const dns_name_t *name) {
REQUIRE(VALID_NAME(name));
REQUIRE(name->labels > 0);
REQUIRE(name->attributes & DNS_NAMEATTR_ABSOLUTE);
REQUIRE(name->attributes.absolute);
/*
* Root label.
@ -305,7 +300,7 @@ dns_name_ishostname(const dns_name_t *name, bool wildcard) {
REQUIRE(VALID_NAME(name));
REQUIRE(name->labels > 0);
REQUIRE(name->attributes & DNS_NAMEATTR_ABSOLUTE);
REQUIRE(name->attributes.absolute);
/*
* Root label.
@ -466,8 +461,7 @@ dns_name_fullcompare(const dns_name_t *name1, const dns_name_t *name2,
/*
* Either name1 is absolute and name2 is absolute, or neither is.
*/
REQUIRE((name1->attributes & DNS_NAMEATTR_ABSOLUTE) ==
(name2->attributes & DNS_NAMEATTR_ABSOLUTE));
REQUIRE((name1->attributes.absolute) == (name2->attributes.absolute));
if (name1 == name2) {
*orderp = 0;
@ -578,8 +572,7 @@ dns_name_equal(const dns_name_t *name1, const dns_name_t *name2) {
/*
* Either name1 is absolute and name2 is absolute, or neither is.
*/
REQUIRE((name1->attributes & DNS_NAMEATTR_ABSOLUTE) ==
(name2->attributes & DNS_NAMEATTR_ABSOLUTE));
REQUIRE((name1->attributes.absolute) == (name2->attributes.absolute));
if (name1 == name2) {
return (true);
@ -610,8 +603,7 @@ dns_name_caseequal(const dns_name_t *name1, const dns_name_t *name2) {
/*
* Either name1 is absolute and name2 is absolute, or neither is.
*/
REQUIRE((name1->attributes & DNS_NAMEATTR_ABSOLUTE) ==
(name2->attributes & DNS_NAMEATTR_ABSOLUTE));
REQUIRE((name1->attributes.absolute) == (name2->attributes.absolute));
if (name1->length != name2->length) {
return (false);
@ -632,10 +624,10 @@ dns_name_rdatacompare(const dns_name_t *name1, const dns_name_t *name2) {
REQUIRE(VALID_NAME(name1));
REQUIRE(name1->labels > 0);
REQUIRE((name1->attributes & DNS_NAMEATTR_ABSOLUTE) != 0);
REQUIRE(name1->attributes.absolute);
REQUIRE(VALID_NAME(name2));
REQUIRE(name2->labels > 0);
REQUIRE((name2->attributes & DNS_NAMEATTR_ABSOLUTE) != 0);
REQUIRE(name2->attributes.absolute);
/* label lengths are < 64 so tolower() does not affect them */
return (isc_ascii_lowercmp(name1->ndata, name2->ndata,
@ -768,12 +760,11 @@ dns_name_getlabelsequence(const dns_name_t *source, unsigned int first,
target->ndata = &source->ndata[firstoffset];
target->length = endoffset - firstoffset;
if (first + n == source->labels && n > 0 &&
(source->attributes & DNS_NAMEATTR_ABSOLUTE) != 0)
if (first + n == source->labels && n > 0 && source->attributes.absolute)
{
target->attributes |= DNS_NAMEATTR_ABSOLUTE;
target->attributes.absolute = true;
} else {
target->attributes &= ~DNS_NAMEATTR_ABSOLUTE;
target->attributes.absolute = false;
}
target->labels = n;
@ -801,10 +792,10 @@ dns_name_clone(const dns_name_t *source, dns_name_t *target) {
target->ndata = source->ndata;
target->length = source->length;
target->labels = source->labels;
target->attributes = source->attributes &
(unsigned int)~(DNS_NAMEATTR_READONLY |
DNS_NAMEATTR_DYNAMIC |
DNS_NAMEATTR_DYNOFFSETS);
target->attributes = source->attributes;
target->attributes.readonly = false;
target->attributes.dynamic = false;
target->attributes.dynoffsets = false;
if (target->offsets != NULL && source->labels > 0) {
if (source->offsets != NULL) {
memmove(target->offsets, source->offsets,
@ -855,7 +846,7 @@ dns_name_fromregion(dns_name_t *name, const isc_region_t *r) {
set_offsets(name, offsets, name);
} else {
name->labels = 0;
name->attributes &= ~DNS_NAMEATTR_ABSOLUTE;
name->attributes.absolute = false;
}
if (name->buffer != NULL) {
@ -1117,12 +1108,12 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
offsets[labels] = nused;
}
}
if ((origin->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) {
name->attributes |= DNS_NAMEATTR_ABSOLUTE;
if (origin->attributes.absolute) {
name->attributes.absolute = true;
}
}
} else {
name->attributes |= DNS_NAMEATTR_ABSOLUTE;
name->attributes.absolute = true;
}
name->ndata = (unsigned char *)target->base + target->used;
@ -1341,7 +1332,7 @@ dns_name_tofilenametext(const dns_name_t *name, bool omit_final_dot,
* wire format.
*/
REQUIRE(VALID_NAME(name));
REQUIRE((name->attributes & DNS_NAMEATTR_ABSOLUTE) != 0);
REQUIRE(name->attributes.absolute);
REQUIRE(ISC_BUFFER_VALID(target));
ndata = name->ndata;
@ -1455,7 +1446,7 @@ dns_name_downcase(const dns_name_t *source, dns_name_t *name,
REQUIRE(VALID_NAME(source));
REQUIRE(VALID_NAME(name));
if (source == name) {
REQUIRE((name->attributes & DNS_NAMEATTR_READONLY) == 0);
REQUIRE(!name->attributes.readonly);
isc_buffer_init(&buffer, source->ndata, source->length);
target = &buffer;
ndata = source->ndata;
@ -1482,11 +1473,9 @@ dns_name_downcase(const dns_name_t *source, dns_name_t *name,
if (source != name) {
name->labels = source->labels;
name->length = source->length;
if ((source->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) {
name->attributes = DNS_NAMEATTR_ABSOLUTE;
} else {
name->attributes = 0;
}
name->attributes = (struct dns_name_attrs){
.absolute = source->attributes.absolute
};
if (name->labels > 0 && name->offsets != NULL) {
set_offsets(name, name->offsets, NULL);
}
@ -1527,11 +1516,7 @@ set_offsets(const dns_name_t *name, unsigned char *offsets,
set_name->labels = nlabels;
set_name->length = offset;
if (absolute) {
set_name->attributes |= DNS_NAMEATTR_ABSOLUTE;
} else {
set_name->attributes &= ~DNS_NAMEATTR_ABSOLUTE;
}
set_name->attributes.absolute = absolute;
}
INSIST(nlabels == name->labels);
INSIST(offset == name->length);
@ -1687,7 +1672,7 @@ dns_name_fromwire(dns_name_t *name, isc_buffer_t *source, dns_decompress_t dctx,
name->ndata = (unsigned char *)target->base + target->used;
name->labels = labels;
name->length = nused;
name->attributes |= DNS_NAMEATTR_ABSOLUTE;
name->attributes.absolute = true;
isc_buffer_forward(source, cused);
isc_buffer_add(target, name->length);
@ -1736,7 +1721,7 @@ dns_name_towire2(const dns_name_t *name, dns_compress_t *cctx,
REQUIRE(cctx != NULL);
REQUIRE(ISC_BUFFER_VALID(target));
compress = (name->attributes & DNS_NAMEATTR_NOCOMPRESS) == 0 &&
compress = !name->attributes.nocompress &&
dns_compress_getpermitted(cctx);
/*
@ -1869,7 +1854,7 @@ dns_name_concatenate(const dns_name_t *prefix, const dns_name_t *suffix,
if (suffix == NULL || suffix->labels == 0) {
copy_suffix = false;
}
if (copy_prefix && (prefix->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) {
if (copy_prefix && prefix->attributes.absolute) {
absolute = true;
REQUIRE(!copy_suffix);
}
@ -1915,7 +1900,7 @@ dns_name_concatenate(const dns_name_t *prefix, const dns_name_t *suffix,
}
if (copy_suffix) {
if ((suffix->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) {
if (suffix->attributes.absolute) {
absolute = true;
}
memmove(ndata + prefix_length, suffix->ndata, suffix->length);
@ -1933,11 +1918,7 @@ dns_name_concatenate(const dns_name_t *prefix, const dns_name_t *suffix,
name->ndata = ndata;
name->labels = labels;
name->length = length;
if (absolute) {
name->attributes = DNS_NAMEATTR_ABSOLUTE;
} else {
name->attributes = 0;
}
name->attributes.absolute = absolute;
if (name->labels > 0 && name->offsets != NULL) {
INIT_OFFSETS(name, offsets, odata);
@ -1999,10 +1980,8 @@ dns_name_dup(const dns_name_t *source, isc_mem_t *mctx, dns_name_t *target) {
target->length = source->length;
target->labels = source->labels;
target->attributes = DNS_NAMEATTR_DYNAMIC;
if ((source->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) {
target->attributes |= DNS_NAMEATTR_ABSOLUTE;
}
target->attributes = (struct dns_name_attrs){ .dynamic = true };
target->attributes.absolute = source->attributes.absolute;
if (target->offsets != NULL) {
if (source->offsets != NULL) {
memmove(target->offsets, source->offsets,
@ -2038,11 +2017,10 @@ dns_name_dupwithoffsets(const dns_name_t *source, isc_mem_t *mctx,
target->length = source->length;
target->labels = source->labels;
target->attributes = DNS_NAMEATTR_DYNAMIC | DNS_NAMEATTR_DYNOFFSETS |
DNS_NAMEATTR_READONLY;
if ((source->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) {
target->attributes |= DNS_NAMEATTR_ABSOLUTE;
}
target->attributes = (struct dns_name_attrs){ .dynamic = true,
.dynoffsets = true,
.readonly = true };
target->attributes.absolute = source->attributes.absolute;
target->offsets = target->ndata + source->length;
if (source->offsets != NULL) {
memmove(target->offsets, source->offsets, source->labels);
@ -2062,10 +2040,10 @@ dns_name_free(dns_name_t *name, isc_mem_t *mctx) {
*/
REQUIRE(VALID_NAME(name));
REQUIRE((name->attributes & DNS_NAMEATTR_DYNAMIC) != 0);
REQUIRE(name->attributes.dynamic);
size = name->length;
if ((name->attributes & DNS_NAMEATTR_DYNOFFSETS) != 0) {
if (name->attributes.dynoffsets) {
size += name->labels;
}
isc_mem_put(mctx, name->ndata, size);
@ -2109,7 +2087,7 @@ dns_name_dynamic(const dns_name_t *name) {
* Returns whether there is dynamic memory associated with this name.
*/
return ((name->attributes & DNS_NAMEATTR_DYNAMIC) != 0 ? true : false);
return (name->attributes.dynamic);
}
isc_result_t
@ -2270,11 +2248,7 @@ dns_name_copy(const dns_name_t *source, dns_name_t *dest) {
dest->ndata = ndata;
dest->labels = source->labels;
dest->length = source->length;
if ((source->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) {
dest->attributes = DNS_NAMEATTR_ABSOLUTE;
} else {
dest->attributes = 0;
}
dest->attributes.absolute = source->attributes.absolute;
if (dest->labels > 0 && dest->offsets != NULL) {
if (source->offsets != NULL && source->labels != 0) {

View file

@ -166,7 +166,7 @@ addoptout(dns_message_t *message, dns_db_t *cache, dns_dbnode_t *node,
while (result == ISC_R_SUCCESS) {
name = NULL;
dns_message_currentname(message, DNS_SECTION_AUTHORITY, &name);
if ((name->attributes & DNS_NAMEATTR_NCACHE) != 0) {
if (name->attributes.ncache) {
for (rdataset = ISC_LIST_HEAD(name->list);
rdataset != NULL;
rdataset = ISC_LIST_NEXT(rdataset, link))

View file

@ -13,6 +13,8 @@
/*! \file */
#define DNS_NAME_USEINLINE 1
#include <inttypes.h>
#include <stdbool.h>
#include <sys/stat.h>
@ -33,8 +35,6 @@
* This define is so dns/name.h (included by dns/fixedname.h) uses more
* efficient macro calls instead of functions for a few operations.
*/
#define DNS_NAME_USEINLINE 1
#include <unistd.h>
#include <isc/result.h>
@ -130,8 +130,8 @@ node_name(dns_rbtnode_t *node, dns_name_t *name) {
name->labels = node->offsetlen;
name->ndata = NAME(node);
name->offsets = OFFSETS(node);
name->attributes = node->attributes;
name->attributes |= DNS_NAMEATTR_READONLY;
name->attributes = (struct dns_name_attrs){ .absolute = node->absolute,
.readonly = true };
}
#ifdef DEBUG
@ -627,7 +627,7 @@ dns_rbt_addnode(dns_rbt_t *rbt, const dns_name_t *name, dns_rbtnode_t **nodep) {
/*
* Set up the new root of the next level.
* By definition it will not be the top
* level tree, so clear DNS_NAMEATTR_ABSOLUTE.
* level tree, so clear the absolute flag.
*/
current->is_root = 1;
current->parent = new_current;
@ -644,7 +644,7 @@ dns_rbt_addnode(dns_rbt_t *rbt, const dns_name_t *name, dns_rbtnode_t **nodep) {
current->right = NULL;
current->color = BLACK;
current->attributes &= ~DNS_NAMEATTR_ABSOLUTE;
current->absolute = false;
rbt->nodecount++;
dns_name_getlabelsequence(name,
@ -1543,7 +1543,7 @@ create_node(isc_mem_t *mctx, const dns_name_t *name, dns_rbtnode_t **nodep) {
*/
node->oldnamelen = node->namelen = region.length;
OLDOFFSETLEN(node) = node->offsetlen = labels;
node->attributes = name->attributes;
node->absolute = name->attributes.absolute;
memmove(NAME(node), region.base, region.length);
memmove(OFFSETS(node), name->offsets, labels);
@ -2589,7 +2589,7 @@ dns_rbtnodechain_current(dns_rbtnodechain_t *chain, dns_name_t *name,
*/
name->labels--;
name->length--;
name->attributes &= ~DNS_NAMEATTR_ABSOLUTE;
name->attributes.absolute = false;
}
}

View file

@ -4292,7 +4292,7 @@ found:
}
}
if (wild) {
foundname->attributes |= DNS_NAMEATTR_WILDCARD;
foundname->attributes.wildcard = true;
}
goto node_exit;
}
@ -4378,7 +4378,7 @@ found:
}
if (wild) {
foundname->attributes |= DNS_NAMEATTR_WILDCARD;
foundname->attributes.wildcard = true;
}
node_exit:

View file

@ -445,7 +445,7 @@ towiresorted(dns_rdataset_t *rdataset, const dns_name_t *owner_name,
dns_rdataset_getownercase(rdataset, name);
offset = 0xffff;
name->attributes |= owner_name->attributes & DNS_NAMEATTR_NOCOMPRESS;
name->attributes.nocompress |= owner_name->attributes.nocompress;
do {
/*

View file

@ -6089,8 +6089,7 @@ cache_name(fetchctx_t *fctx, dns_name_t *name, dns_message_t *message,
need_validation = secure_domain;
}
if (((name->attributes & DNS_NAMEATTR_ANSWER) != 0) &&
(!need_validation)) {
if (name->attributes.answer && !need_validation) {
have_answer = true;
event = ISC_LIST_HEAD(fctx->events);
@ -6110,7 +6109,7 @@ cache_name(fetchctx_t *fctx, dns_name_t *name, dns_message_t *message,
if ((fctx->type != dns_rdatatype_any &&
fctx->type != dns_rdatatype_rrsig &&
fctx->type != dns_rdatatype_sig) ||
(name->attributes & DNS_NAMEATTR_CHAINING) != 0)
name->attributes.chaining)
{
ardataset = event->rdataset;
asigrdataset = event->sigrdataset;
@ -6532,7 +6531,7 @@ cache_message(fetchctx_t *fctx, dns_message_t *message,
while (result == ISC_R_SUCCESS) {
name = NULL;
dns_message_currentname(message, section, &name);
if ((name->attributes & DNS_NAMEATTR_CACHE) != 0) {
if (name->attributes.cache) {
result = cache_name(fctx, name, message,
addrinfo, now);
if (result != ISC_R_SUCCESS) {
@ -6772,7 +6771,7 @@ unlock:
static void
mark_related(dns_name_t *name, dns_rdataset_t *rdataset, bool external,
bool gluing) {
name->attributes |= DNS_NAMEATTR_CACHE;
name->attributes.cache = true;
if (gluing) {
rdataset->trust = dns_trust_glue;
/*
@ -6789,7 +6788,7 @@ mark_related(dns_name_t *name, dns_rdataset_t *rdataset, bool external,
* Avoid infinite loops by only marking new rdatasets.
*/
if (!CACHE(rdataset)) {
name->attributes |= DNS_NAMEATTR_CHASE;
name->attributes.chase = true;
rdataset->attributes |= DNS_RDATASETATTR_CHASE;
}
rdataset->attributes |= DNS_RDATASETATTR_CACHE;
@ -8738,8 +8737,8 @@ rctx_answer_any(respctx_t *rctx) {
return (ISC_R_COMPLETE);
}
rctx->aname->attributes |= DNS_NAMEATTR_CACHE;
rctx->aname->attributes |= DNS_NAMEATTR_ANSWER;
rctx->aname->attributes.cache = true;
rctx->aname->attributes.answer = true;
rdataset->attributes |= DNS_RDATASETATTR_ANSWER;
rdataset->attributes |= DNS_RDATASETATTR_CACHE;
rdataset->trust = rctx->trust;
@ -8787,8 +8786,8 @@ rctx_answer_match(respctx_t *rctx) {
return (ISC_R_COMPLETE);
}
rctx->aname->attributes |= DNS_NAMEATTR_CACHE;
rctx->aname->attributes |= DNS_NAMEATTR_ANSWER;
rctx->aname->attributes.cache = true;
rctx->aname->attributes.answer = true;
rctx->ardataset->attributes |= DNS_RDATASETATTR_ANSWER;
rctx->ardataset->attributes |= DNS_RDATASETATTR_CACHE;
rctx->ardataset->trust = rctx->trust;
@ -8851,9 +8850,9 @@ rctx_answer_cname(respctx_t *rctx) {
return (ISC_R_COMPLETE);
}
rctx->cname->attributes |= DNS_NAMEATTR_CACHE;
rctx->cname->attributes |= DNS_NAMEATTR_ANSWER;
rctx->cname->attributes |= DNS_NAMEATTR_CHAINING;
rctx->cname->attributes.cache = true;
rctx->cname->attributes.answer = true;
rctx->cname->attributes.chaining = true;
rctx->crdataset->attributes |= DNS_RDATASETATTR_ANSWER;
rctx->crdataset->attributes |= DNS_RDATASETATTR_CACHE;
rctx->crdataset->attributes |= DNS_RDATASETATTR_CHAINING;
@ -8905,9 +8904,9 @@ rctx_answer_dname(respctx_t *rctx) {
return (ISC_R_COMPLETE);
}
rctx->dname->attributes |= DNS_NAMEATTR_CACHE;
rctx->dname->attributes |= DNS_NAMEATTR_ANSWER;
rctx->dname->attributes |= DNS_NAMEATTR_CHAINING;
rctx->dname->attributes.cache = true;
rctx->dname->attributes.answer = true;
rctx->dname->attributes.chaining = true;
rctx->drdataset->attributes |= DNS_RDATASETATTR_ANSWER;
rctx->drdataset->attributes |= DNS_RDATASETATTR_CACHE;
rctx->drdataset->attributes |= DNS_RDATASETATTR_CHAINING;
@ -8977,7 +8976,7 @@ rctx_authority_positive(respctx_t *rctx) {
(rdataset->type == dns_rdatatype_rrsig &&
rdataset->covers == dns_rdatatype_ns))
{
name->attributes |= DNS_NAMEATTR_CACHE;
name->attributes.cache = true;
rdataset->attributes |=
DNS_RDATASETATTR_CACHE;
@ -9142,7 +9141,7 @@ rctx_answer_none(respctx_t *rctx) {
* NS RRs we may have found.
*/
if (rctx->ns_name != NULL) {
rctx->ns_name->attributes &= ~DNS_NAMEATTR_CACHE;
rctx->ns_name->attributes.cache = false;
}
if (rctx->negative) {
@ -9237,7 +9236,7 @@ rctx_authority_negative(respctx_t *rctx) {
rctx->ns_name = name;
rctx->ns_rdataset = rdataset;
}
name->attributes |= DNS_NAMEATTR_CACHE;
name->attributes.cache = true;
rdataset->attributes |= DNS_RDATASETATTR_CACHE;
rdataset->trust = dns_trust_glue;
break;
@ -9260,7 +9259,7 @@ rctx_authority_negative(respctx_t *rctx) {
}
rctx->soa_name = name;
}
name->attributes |= DNS_NAMEATTR_NCACHE;
name->attributes.ncache = true;
rdataset->attributes |= DNS_RDATASETATTR_NCACHE;
if (rctx->aa) {
rdataset->trust =
@ -9373,11 +9372,11 @@ rctx_authority_dnssec(respctx_t *rctx) {
case dns_rdatatype_nsec:
case dns_rdatatype_nsec3:
if (rctx->negative) {
name->attributes |= DNS_NAMEATTR_NCACHE;
name->attributes.ncache = true;
rdataset->attributes |=
DNS_RDATASETATTR_NCACHE;
} else if (type == dns_rdatatype_nsec) {
name->attributes |= DNS_NAMEATTR_CACHE;
name->attributes.cache = true;
rdataset->attributes |=
DNS_RDATASETATTR_CACHE;
}
@ -9423,7 +9422,7 @@ rctx_authority_dnssec(respctx_t *rctx) {
rctx->ds_name = name;
}
name->attributes |= DNS_NAMEATTR_CACHE;
name->attributes.cache = true;
rdataset->attributes |= DNS_RDATASETATTR_CACHE;
if ((fctx->options & DNS_FETCHOPT_NONTA) != 0) {
@ -9614,10 +9613,10 @@ again:
dns_rdataset_t *rdataset;
dns_message_currentname(rctx->query->rmessage,
DNS_SECTION_ADDITIONAL, &name);
if ((name->attributes & DNS_NAMEATTR_CHASE) == 0) {
if (!name->attributes.chase) {
continue;
}
name->attributes &= ~DNS_NAMEATTR_CHASE;
name->attributes.chase = false;
for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL;
rdataset = ISC_LIST_NEXT(rdataset, link))
{

View file

@ -436,8 +436,8 @@ make_key(const dns_rrl_t *rrl, dns_rrl_key_t *key,
if (qname != NULL && qname->labels != 0) {
dns_name_t *origin = NULL;
if ((qname->attributes & DNS_NAMEATTR_WILDCARD) != 0 &&
zone != NULL && (origin = dns_zone_getorigin(zone)) != NULL)
if (qname->attributes.wildcard && zone != NULL &&
(origin = dns_zone_getorigin(zone)) != NULL)
{
dns_fixedname_t fixed;
dns_name_t *wild;

View file

@ -1030,7 +1030,7 @@ dns_tsig_sign(dns_message_t *msg) {
msg->tsigname = owner;
/* Windows does not like the tsig name being compressed. */
msg->tsigname->attributes |= DNS_NAMEATTR_NOCOMPRESS;
msg->tsigname->attributes.nocompress = true;
return (ISC_R_SUCCESS);

View file

@ -1594,7 +1594,7 @@ xfrin_destroy(dns_xfrin_ctx_t *xfr) {
dst_context_destroy(&xfr->tsigctx);
}
if ((xfr->name.attributes & DNS_NAMEATTR_DYNAMIC) != 0) {
if (xfr->name.attributes.dynamic) {
dns_name_free(&xfr->name, xfr->mctx);
}

View file

@ -9220,7 +9220,7 @@ query_sign_nodata(query_ctx_t *qctx) {
}
if (!dns_rdataset_isassociated(qctx->rdataset) &&
WANTDNSSEC(qctx->client)) {
if ((qctx->fname->attributes & DNS_NAMEATTR_WILDCARD) == 0) {
if (!qctx->fname->attributes.wildcard) {
dns_name_t *found;
dns_name_t *qname;
dns_fixedname_t fixed;
@ -9342,7 +9342,7 @@ query_addnxrrsetnsec(query_ctx_t *qctx) {
INSIST(qctx->fname != NULL);
if ((qctx->fname->attributes & DNS_NAMEATTR_WILDCARD) == 0) {
if (!qctx->fname->attributes.wildcard) {
query_addrrset(qctx, &qctx->fname, &qctx->rdataset,
&qctx->sigrdataset, NULL, DNS_SECTION_AUTHORITY);
return;
@ -10328,9 +10328,7 @@ query_cname(query_ctx_t *qctx) {
sigrdatasetp = &qctx->sigrdataset;
}
if (WANTDNSSEC(qctx->client) &&
(qctx->fname->attributes & DNS_NAMEATTR_WILDCARD) != 0)
{
if (WANTDNSSEC(qctx->client) && qctx->fname->attributes.wildcard) {
dns_fixedname_init(&qctx->wildcardname);
dns_name_copy(qctx->fname,
dns_fixedname_name(&qctx->wildcardname));
@ -10436,9 +10434,7 @@ query_dname(query_ctx_t *qctx) {
sigrdatasetp = &qctx->sigrdataset;
}
if (WANTDNSSEC(qctx->client) &&
(qctx->fname->attributes & DNS_NAMEATTR_WILDCARD) != 0)
{
if (WANTDNSSEC(qctx->client) && qctx->fname->attributes.wildcard) {
dns_fixedname_init(&qctx->wildcardname);
dns_name_copy(qctx->fname,
dns_fixedname_name(&qctx->wildcardname));
@ -10606,9 +10602,7 @@ query_prepresponse(query_ctx_t *qctx) {
CALL_HOOK(NS_QUERY_PREP_RESPONSE_BEGIN, qctx);
if (WANTDNSSEC(qctx->client) &&
(qctx->fname->attributes & DNS_NAMEATTR_WILDCARD) != 0)
{
if (WANTDNSSEC(qctx->client) && qctx->fname->attributes.wildcard) {
dns_fixedname_init(&qctx->wildcardname);
dns_name_copy(qctx->fname,
dns_fixedname_name(&qctx->wildcardname));

View file

@ -406,6 +406,7 @@ ISC_RUN_TEST_IMPL(istat) {
ISC_RUN_TEST_IMPL(init) {
dns_name_t name;
unsigned char offsets[1];
struct dns_name_attrs zeroes = {};
UNUSED(state);
@ -414,7 +415,7 @@ ISC_RUN_TEST_IMPL(init) {
assert_null(name.ndata);
assert_int_equal(name.length, 0);
assert_int_equal(name.labels, 0);
assert_int_equal(name.attributes, 0);
assert_memory_equal(&name.attributes, &zeroes, sizeof(zeroes));
assert_ptr_equal(name.offsets, offsets);
assert_null(name.buffer);
}
@ -423,6 +424,7 @@ ISC_RUN_TEST_IMPL(init) {
ISC_RUN_TEST_IMPL(invalidate) {
dns_name_t name;
unsigned char offsets[1];
struct dns_name_attrs zeroes = {};
UNUSED(state);
@ -432,7 +434,7 @@ ISC_RUN_TEST_IMPL(invalidate) {
assert_null(name.ndata);
assert_int_equal(name.length, 0);
assert_int_equal(name.labels, 0);
assert_int_equal(name.attributes, 0);
assert_memory_equal(&name.attributes, &zeroes, sizeof(zeroes));
assert_null(name.offsets);
assert_null(name.buffer);
}