mirror of
https://github.com/isc-projects/bind9.git
synced 2026-05-28 04:34:54 -04:00
Merge branch 'ondrej/make-dns_name-mostly-header-only' into 'main'
Cleanup the dns_name macros See merge request isc-projects/bind9!8297
This commit is contained in:
commit
9df9296b7a
4 changed files with 166 additions and 280 deletions
|
|
@ -11,8 +11,6 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
#define DNS_NAME_USEINLINE 1
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/lang.h>
|
||||
#include <isc/magic.h>
|
||||
#include <isc/region.h> /* Required for storage size of dns_label_t. */
|
||||
|
|
@ -120,7 +121,15 @@ struct dns_name {
|
|||
ISC_LIST(dns_rdataset_t) list;
|
||||
};
|
||||
|
||||
#define DNS_NAME_MAGIC ISC_MAGIC('D', 'N', 'S', 'n')
|
||||
#define DNS_NAME_MAGIC ISC_MAGIC('D', 'N', 'S', 'n')
|
||||
#define DNS_NAME_VALID(n) ISC_MAGIC_VALID(n, DNS_NAME_MAGIC)
|
||||
|
||||
/*%
|
||||
* 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 DNS_NAME_BINDABLE(name) \
|
||||
(!name->attributes.readonly && !name->attributes.dynamic)
|
||||
|
||||
/*
|
||||
* Various flags.
|
||||
|
|
@ -155,30 +164,27 @@ extern const dns_name_t *dns_wildcardname;
|
|||
* unsigned char offsets[] = { 0, 6 };
|
||||
* dns_name_t value = DNS_NAME_INITABSOLUTE(data, offsets);
|
||||
*/
|
||||
#define DNS_NAME_INITNONABSOLUTE(A, B) \
|
||||
{ \
|
||||
DNS_NAME_MAGIC, A, (sizeof(A) - 1), sizeof(B), \
|
||||
{ .readonly = true }, B, NULL, \
|
||||
{ (void *)-1, (void *)-1 }, { \
|
||||
NULL, NULL \
|
||||
} \
|
||||
#define DNS_NAME_INITNONABSOLUTE(A, B) \
|
||||
{ \
|
||||
.magic = DNS_NAME_MAGIC, .ndata = A, \
|
||||
.length = (sizeof(A) - 1), .labels = sizeof(B), \
|
||||
.attributes = { .readonly = true }, .offsets = B, \
|
||||
.link = ISC_LINK_INITIALIZER, .list = ISC_LIST_INITIALIZER, \
|
||||
}
|
||||
|
||||
#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_INITABSOLUTE(A, B) \
|
||||
{ \
|
||||
.magic = DNS_NAME_MAGIC, .ndata = A, .length = sizeof(A), \
|
||||
.labels = sizeof(B), \
|
||||
.attributes = { .readonly = true, .absolute = true }, \
|
||||
.offsets = B, .link = ISC_LINK_INITIALIZER, \
|
||||
.list = ISC_LIST_INITIALIZER, \
|
||||
}
|
||||
|
||||
#define DNS_NAME_INITEMPTY \
|
||||
{ \
|
||||
DNS_NAME_MAGIC, NULL, 0, 0, {}, NULL, NULL, \
|
||||
{ (void *)-1, (void *)-1 }, { \
|
||||
NULL, NULL \
|
||||
} \
|
||||
#define DNS_NAME_INITEMPTY \
|
||||
{ \
|
||||
.magic = DNS_NAME_MAGIC, .link = ISC_LINK_INITIALIZER, \
|
||||
.list = ISC_LIST_INITIALIZER \
|
||||
}
|
||||
|
||||
/*%
|
||||
|
|
@ -202,8 +208,15 @@ typedef isc_result_t(dns_name_totextfilter_t)(isc_buffer_t *target,
|
|||
*** Initialization
|
||||
***/
|
||||
|
||||
void
|
||||
dns_name_init(dns_name_t *name, unsigned char *offsets);
|
||||
static inline void
|
||||
dns_name_init(dns_name_t *name, unsigned char *offsets) {
|
||||
*name = (dns_name_t){
|
||||
.magic = DNS_NAME_MAGIC,
|
||||
.offsets = (offsets),
|
||||
.link = ISC_LINK_INITIALIZER,
|
||||
.list = ISC_LIST_INITIALIZER,
|
||||
};
|
||||
}
|
||||
/*%<
|
||||
* Initialize 'name'.
|
||||
*
|
||||
|
|
@ -223,8 +236,19 @@ dns_name_init(dns_name_t *name, unsigned char *offsets);
|
|||
* \li dns_name_isabsolute(name) == false
|
||||
*/
|
||||
|
||||
void
|
||||
dns_name_reset(dns_name_t *name);
|
||||
static inline void
|
||||
dns_name_reset(dns_name_t *name) {
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
REQUIRE(DNS_NAME_BINDABLE(name));
|
||||
|
||||
name->ndata = NULL;
|
||||
name->length = 0;
|
||||
name->labels = 0;
|
||||
name->attributes.absolute = false;
|
||||
if (name->buffer != NULL) {
|
||||
isc_buffer_clear(name->buffer);
|
||||
}
|
||||
}
|
||||
/*%<
|
||||
* Reinitialize 'name'.
|
||||
*
|
||||
|
|
@ -248,8 +272,19 @@ dns_name_reset(dns_name_t *name);
|
|||
* \li dns_name_isabsolute(name) == false
|
||||
*/
|
||||
|
||||
void
|
||||
dns_name_invalidate(dns_name_t *name);
|
||||
static inline void
|
||||
dns_name_invalidate(dns_name_t *name) {
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
|
||||
name->magic = 0;
|
||||
name->ndata = NULL;
|
||||
name->length = 0;
|
||||
name->labels = 0;
|
||||
name->attributes = (struct dns_name_attrs){};
|
||||
name->offsets = NULL;
|
||||
name->buffer = NULL;
|
||||
ISC_LINK_INIT(name, link);
|
||||
}
|
||||
/*%<
|
||||
* Make 'name' invalid.
|
||||
*
|
||||
|
|
@ -273,8 +308,13 @@ dns_name_isvalid(const dns_name_t *name);
|
|||
*** Dedicated Buffers
|
||||
***/
|
||||
|
||||
void
|
||||
dns_name_setbuffer(dns_name_t *name, isc_buffer_t *buffer);
|
||||
static inline void
|
||||
dns_name_setbuffer(dns_name_t *name, isc_buffer_t *buffer) {
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
REQUIRE((buffer != NULL && name->buffer == NULL) || (buffer == NULL));
|
||||
|
||||
name->buffer = buffer;
|
||||
}
|
||||
/*%<
|
||||
* Dedicate a buffer for use with 'name'.
|
||||
*
|
||||
|
|
@ -549,8 +589,13 @@ dns_name_matcheswildcard(const dns_name_t *name, const dns_name_t *wname);
|
|||
*** Labels
|
||||
***/
|
||||
|
||||
unsigned int
|
||||
dns_name_countlabels(const dns_name_t *name);
|
||||
static inline unsigned int
|
||||
dns_name_countlabels(const dns_name_t *name) {
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
REQUIRE(name->labels <= DNS_NAME_MAXLABELS);
|
||||
|
||||
return (name->labels);
|
||||
}
|
||||
/*%<
|
||||
* How many labels does 'name' have?
|
||||
*
|
||||
|
|
@ -655,8 +700,14 @@ dns_name_fromregion(dns_name_t *name, const isc_region_t *r);
|
|||
* \li The data in 'r' is a sequence of one or more type 00 labels.
|
||||
*/
|
||||
|
||||
void
|
||||
dns_name_toregion(const dns_name_t *name, isc_region_t *r);
|
||||
static inline void
|
||||
dns_name_toregion(const dns_name_t *name, isc_region_t *r) {
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
REQUIRE(r != NULL);
|
||||
|
||||
r->base = name->ndata;
|
||||
r->length = name->length;
|
||||
}
|
||||
/*%<
|
||||
* Make 'r' refer to 'name'.
|
||||
*
|
||||
|
|
@ -946,9 +997,27 @@ dns_name_concatenate(const dns_name_t *prefix, const dns_name_t *suffix,
|
|||
*\li #DNS_R_NAMETOOLONG
|
||||
*/
|
||||
|
||||
void
|
||||
static inline void
|
||||
dns_name_split(const dns_name_t *name, unsigned int suffixlabels,
|
||||
dns_name_t *prefix, dns_name_t *suffix);
|
||||
dns_name_t *prefix, dns_name_t *suffix) {
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
REQUIRE(suffixlabels > 0);
|
||||
REQUIRE(suffixlabels <= name->labels);
|
||||
REQUIRE(prefix != NULL || suffix != NULL);
|
||||
REQUIRE(prefix == NULL ||
|
||||
(DNS_NAME_VALID(prefix) && DNS_NAME_BINDABLE(prefix)));
|
||||
REQUIRE(suffix == NULL ||
|
||||
(DNS_NAME_VALID(suffix) && DNS_NAME_BINDABLE(suffix)));
|
||||
|
||||
if (prefix != NULL) {
|
||||
dns_name_getlabelsequence(name, 0, name->labels - suffixlabels,
|
||||
prefix);
|
||||
}
|
||||
if (suffix != NULL) {
|
||||
dns_name_getlabelsequence(name, name->labels - suffixlabels,
|
||||
suffixlabels, suffix);
|
||||
}
|
||||
}
|
||||
/*%<
|
||||
*
|
||||
* Split 'name' into two pieces on a label boundary.
|
||||
|
|
@ -1269,75 +1338,3 @@ dns_name_isdnssvcb(const dns_name_t *name);
|
|||
*/
|
||||
|
||||
ISC_LANG_ENDDECLS
|
||||
|
||||
/*
|
||||
*** High Performance Macros
|
||||
***/
|
||||
|
||||
/*
|
||||
* WARNING: Use of these macros by applications may require recompilation
|
||||
* of the application in some situations where calling the function
|
||||
* would not.
|
||||
*
|
||||
* 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 = (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.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_COUNTLABELS(n) ((n)->labels)
|
||||
|
||||
#define DNS_NAME_TOREGION(n, r) \
|
||||
do { \
|
||||
(r)->base = (n)->ndata; \
|
||||
(r)->length = (n)->length; \
|
||||
} while (0)
|
||||
|
||||
#define DNS_NAME_SPLIT(n, l, p, s) \
|
||||
do { \
|
||||
dns_name_t *_n = (n); \
|
||||
dns_name_t *_p = (p); \
|
||||
dns_name_t *_s = (s); \
|
||||
unsigned int _l = (l); \
|
||||
if (_p != NULL) \
|
||||
dns_name_getlabelsequence(_n, 0, _n->labels - _l, _p); \
|
||||
if (_s != NULL) \
|
||||
dns_name_getlabelsequence(_n, _n->labels - _l, _l, \
|
||||
_s); \
|
||||
} while (0)
|
||||
|
||||
#ifdef DNS_NAME_USEINLINE
|
||||
|
||||
#define dns_name_init(n, o) DNS_NAME_INIT(n, o)
|
||||
#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) ((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)
|
||||
|
||||
#endif /* DNS_NAME_USEINLINE */
|
||||
|
|
|
|||
231
lib/dns/name.c
231
lib/dns/name.c
|
|
@ -34,8 +34,6 @@
|
|||
#include <dns/fixedname.h>
|
||||
#include <dns/name.h>
|
||||
|
||||
#define VALID_NAME(n) ISC_MAGIC_VALID(n, DNS_NAME_MAGIC)
|
||||
|
||||
typedef enum {
|
||||
ft_init = 0,
|
||||
ft_start,
|
||||
|
|
@ -72,12 +70,6 @@ typedef enum {
|
|||
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.readonly && !name->attributes.dynamic)
|
||||
|
||||
/*%
|
||||
* Note that the name data must be a char array, not a string
|
||||
* literal, to avoid compiler warnings about discarding
|
||||
|
|
@ -106,46 +98,12 @@ static void
|
|||
set_offsets(const dns_name_t *name, unsigned char *offsets,
|
||||
dns_name_t *set_name);
|
||||
|
||||
void
|
||||
dns_name_init(dns_name_t *name, unsigned char *offsets) {
|
||||
/*
|
||||
* Initialize 'name'.
|
||||
*/
|
||||
DNS_NAME_INIT(name, offsets);
|
||||
}
|
||||
|
||||
void
|
||||
dns_name_reset(dns_name_t *name) {
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(BINDABLE(name));
|
||||
|
||||
DNS_NAME_RESET(name);
|
||||
}
|
||||
|
||||
void
|
||||
dns_name_invalidate(dns_name_t *name) {
|
||||
/*
|
||||
* Make 'name' invalid.
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_NAME(name));
|
||||
|
||||
name->magic = 0;
|
||||
name->ndata = NULL;
|
||||
name->length = 0;
|
||||
name->labels = 0;
|
||||
name->attributes = (struct dns_name_attrs){};
|
||||
name->offsets = NULL;
|
||||
name->buffer = NULL;
|
||||
ISC_LINK_INIT(name, link);
|
||||
}
|
||||
|
||||
bool
|
||||
dns_name_isvalid(const dns_name_t *name) {
|
||||
unsigned char *ndata, *offsets;
|
||||
unsigned int offset, count, length, nlabels;
|
||||
|
||||
if (!VALID_NAME(name)) {
|
||||
if (!DNS_NAME_VALID(name)) {
|
||||
return (false);
|
||||
}
|
||||
|
||||
|
|
@ -189,25 +147,13 @@ dns_name_isvalid(const dns_name_t *name) {
|
|||
return (true);
|
||||
}
|
||||
|
||||
void
|
||||
dns_name_setbuffer(dns_name_t *name, isc_buffer_t *buffer) {
|
||||
/*
|
||||
* Dedicate a buffer for use with 'name'.
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE((buffer != NULL && name->buffer == NULL) || (buffer == NULL));
|
||||
|
||||
name->buffer = buffer;
|
||||
}
|
||||
|
||||
bool
|
||||
dns_name_hasbuffer(const dns_name_t *name) {
|
||||
/*
|
||||
* Does 'name' have a dedicated buffer?
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
|
||||
if (name->buffer != NULL) {
|
||||
return (true);
|
||||
|
|
@ -222,7 +168,7 @@ dns_name_isabsolute(const dns_name_t *name) {
|
|||
* Does 'name' end in the root label?
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
|
||||
return name->attributes.absolute;
|
||||
}
|
||||
|
|
@ -242,7 +188,7 @@ dns_name_ismailbox(const dns_name_t *name) {
|
|||
unsigned int n;
|
||||
bool first;
|
||||
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
REQUIRE(name->labels > 0);
|
||||
REQUIRE(name->attributes.absolute);
|
||||
|
||||
|
|
@ -297,7 +243,7 @@ dns_name_ishostname(const dns_name_t *name, bool wildcard) {
|
|||
unsigned int n;
|
||||
bool first;
|
||||
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
REQUIRE(name->labels > 0);
|
||||
REQUIRE(name->attributes.absolute);
|
||||
|
||||
|
|
@ -348,7 +294,7 @@ dns_name_iswildcard(const dns_name_t *name) {
|
|||
* Is 'name' a wildcard name?
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
REQUIRE(name->labels > 0);
|
||||
|
||||
if (name->length >= 2) {
|
||||
|
|
@ -371,7 +317,7 @@ dns_name_internalwildcard(const dns_name_t *name) {
|
|||
* Does 'name' contain a internal wildcard?
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
REQUIRE(name->labels > 0);
|
||||
|
||||
/*
|
||||
|
|
@ -399,7 +345,7 @@ dns_name_internalwildcard(const dns_name_t *name) {
|
|||
|
||||
uint32_t
|
||||
dns_name_hash(const dns_name_t *name) {
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
|
||||
return (isc_hash32(name->ndata, name->length, false));
|
||||
}
|
||||
|
|
@ -425,8 +371,8 @@ dns_name_fullcompare(const dns_name_t *name1, const dns_name_t *name2,
|
|||
* same domain.
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_NAME(name1));
|
||||
REQUIRE(VALID_NAME(name2));
|
||||
REQUIRE(DNS_NAME_VALID(name1));
|
||||
REQUIRE(DNS_NAME_VALID(name2));
|
||||
REQUIRE(orderp != NULL);
|
||||
REQUIRE(nlabelsp != NULL);
|
||||
/*
|
||||
|
|
@ -538,8 +484,8 @@ dns_name_equal(const dns_name_t *name1, const dns_name_t *name2) {
|
|||
* same domain.
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_NAME(name1));
|
||||
REQUIRE(VALID_NAME(name2));
|
||||
REQUIRE(DNS_NAME_VALID(name1));
|
||||
REQUIRE(DNS_NAME_VALID(name2));
|
||||
/*
|
||||
* Either name1 is absolute and name2 is absolute, or neither is.
|
||||
*/
|
||||
|
|
@ -569,8 +515,8 @@ dns_name_caseequal(const dns_name_t *name1, const dns_name_t *name2) {
|
|||
* same domain.
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_NAME(name1));
|
||||
REQUIRE(VALID_NAME(name2));
|
||||
REQUIRE(DNS_NAME_VALID(name1));
|
||||
REQUIRE(DNS_NAME_VALID(name2));
|
||||
/*
|
||||
* Either name1 is absolute and name2 is absolute, or neither is.
|
||||
*/
|
||||
|
|
@ -593,10 +539,10 @@ dns_name_rdatacompare(const dns_name_t *name1, const dns_name_t *name2) {
|
|||
* Compare two absolute names as rdata.
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_NAME(name1));
|
||||
REQUIRE(DNS_NAME_VALID(name1));
|
||||
REQUIRE(name1->labels > 0);
|
||||
REQUIRE(name1->attributes.absolute);
|
||||
REQUIRE(VALID_NAME(name2));
|
||||
REQUIRE(DNS_NAME_VALID(name2));
|
||||
REQUIRE(name2->labels > 0);
|
||||
REQUIRE(name2->attributes.absolute);
|
||||
|
||||
|
|
@ -636,14 +582,14 @@ dns_name_matcheswildcard(const dns_name_t *name, const dns_name_t *wname) {
|
|||
unsigned int nlabels, labels;
|
||||
dns_name_t tname;
|
||||
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
REQUIRE(name->labels > 0);
|
||||
REQUIRE(VALID_NAME(wname));
|
||||
REQUIRE(DNS_NAME_VALID(wname));
|
||||
labels = wname->labels;
|
||||
REQUIRE(labels > 0);
|
||||
REQUIRE(dns_name_iswildcard(wname));
|
||||
|
||||
DNS_NAME_INIT(&tname, NULL);
|
||||
dns_name_init(&tname, NULL);
|
||||
dns_name_getlabelsequence(wname, 1, labels - 1, &tname);
|
||||
if (dns_name_fullcompare(name, &tname, &order, &nlabels) ==
|
||||
dns_namereln_subdomain)
|
||||
|
|
@ -653,19 +599,6 @@ dns_name_matcheswildcard(const dns_name_t *name, const dns_name_t *wname) {
|
|||
return (false);
|
||||
}
|
||||
|
||||
unsigned int
|
||||
dns_name_countlabels(const dns_name_t *name) {
|
||||
/*
|
||||
* How many labels does 'name' have?
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_NAME(name));
|
||||
|
||||
ENSURE(name->labels <= DNS_NAME_MAXLABELS);
|
||||
|
||||
return (name->labels);
|
||||
}
|
||||
|
||||
void
|
||||
dns_name_getlabel(const dns_name_t *name, unsigned int n, dns_label_t *label) {
|
||||
unsigned char *offsets;
|
||||
|
|
@ -675,7 +608,7 @@ dns_name_getlabel(const dns_name_t *name, unsigned int n, dns_label_t *label) {
|
|||
* Make 'label' refer to the 'n'th least significant label of 'name'.
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
REQUIRE(name->labels > 0);
|
||||
REQUIRE(n < name->labels);
|
||||
REQUIRE(label != NULL);
|
||||
|
|
@ -702,11 +635,11 @@ dns_name_getlabelsequence(const dns_name_t *source, unsigned int first,
|
|||
* 'first' in 'source'.
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_NAME(source));
|
||||
REQUIRE(VALID_NAME(target));
|
||||
REQUIRE(DNS_NAME_VALID(source));
|
||||
REQUIRE(DNS_NAME_VALID(target));
|
||||
REQUIRE(first <= source->labels);
|
||||
REQUIRE(n <= source->labels - first); /* note first+n could overflow */
|
||||
REQUIRE(BINDABLE(target));
|
||||
REQUIRE(DNS_NAME_BINDABLE(target));
|
||||
|
||||
p = source->ndata;
|
||||
if (first == source->labels) {
|
||||
|
|
@ -757,9 +690,9 @@ dns_name_clone(const dns_name_t *source, dns_name_t *target) {
|
|||
* Make 'target' refer to the same name as 'source'.
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_NAME(source));
|
||||
REQUIRE(VALID_NAME(target));
|
||||
REQUIRE(BINDABLE(target));
|
||||
REQUIRE(DNS_NAME_VALID(source));
|
||||
REQUIRE(DNS_NAME_VALID(target));
|
||||
REQUIRE(DNS_NAME_BINDABLE(target));
|
||||
|
||||
target->ndata = source->ndata;
|
||||
target->length = source->length;
|
||||
|
|
@ -789,9 +722,9 @@ dns_name_fromregion(dns_name_t *name, const isc_region_t *r) {
|
|||
* Make 'name' refer to region 'r'.
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
REQUIRE(r != NULL);
|
||||
REQUIRE(BINDABLE(name));
|
||||
REQUIRE(DNS_NAME_BINDABLE(name));
|
||||
|
||||
INIT_OFFSETS(name, offsets, odata);
|
||||
|
||||
|
|
@ -826,18 +759,6 @@ dns_name_fromregion(dns_name_t *name, const isc_region_t *r) {
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
dns_name_toregion(const dns_name_t *name, isc_region_t *r) {
|
||||
/*
|
||||
* Make 'r' refer to 'name'.
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(r != NULL);
|
||||
|
||||
DNS_NAME_TOREGION(name, r);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
|
||||
const dns_name_t *origin, unsigned int options,
|
||||
|
|
@ -864,7 +785,7 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
|
|||
* will remain relative.
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
REQUIRE(ISC_BUFFER_VALID(source));
|
||||
REQUIRE((target != NULL && ISC_BUFFER_VALID(target)) ||
|
||||
(target == NULL && ISC_BUFFER_VALID(name->buffer)));
|
||||
|
|
@ -876,7 +797,7 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source,
|
|||
isc_buffer_clear(target);
|
||||
}
|
||||
|
||||
REQUIRE(BINDABLE(name));
|
||||
REQUIRE(DNS_NAME_BINDABLE(name));
|
||||
|
||||
INIT_OFFSETS(name, offsets, odata);
|
||||
offsets[0] = 0;
|
||||
|
|
@ -1114,7 +1035,7 @@ dns_name_totext(const dns_name_t *name, unsigned int options,
|
|||
* This function assumes the name is in proper uncompressed
|
||||
* wire format.
|
||||
*/
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
REQUIRE(ISC_BUFFER_VALID(target));
|
||||
|
||||
oused = target->used;
|
||||
|
|
@ -1285,7 +1206,7 @@ dns_name_tofilenametext(const dns_name_t *name, bool omit_final_dot,
|
|||
* This function assumes the name is in proper uncompressed
|
||||
* wire format.
|
||||
*/
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
REQUIRE(name->attributes.absolute);
|
||||
REQUIRE(ISC_BUFFER_VALID(target));
|
||||
|
||||
|
|
@ -1396,15 +1317,15 @@ dns_name_downcase(const dns_name_t *source, dns_name_t *name,
|
|||
* Downcase 'source'.
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_NAME(source));
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(DNS_NAME_VALID(source));
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
if (source == name) {
|
||||
REQUIRE(!name->attributes.readonly);
|
||||
isc_buffer_init(&buffer, source->ndata, source->length);
|
||||
target = &buffer;
|
||||
ndata = source->ndata;
|
||||
} else {
|
||||
REQUIRE(BINDABLE(name));
|
||||
REQUIRE(DNS_NAME_BINDABLE(name));
|
||||
REQUIRE((target != NULL && ISC_BUFFER_VALID(target)) ||
|
||||
(target == NULL && ISC_BUFFER_VALID(name->buffer)));
|
||||
if (target == NULL) {
|
||||
|
|
@ -1529,8 +1450,8 @@ dns_name_fromwire(dns_name_t *const name, isc_buffer_t *const source,
|
|||
* correct way to set our "consumed" variable.
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(BINDABLE(name));
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
REQUIRE(DNS_NAME_BINDABLE(name));
|
||||
REQUIRE((target != NULL && ISC_BUFFER_VALID(target)) ||
|
||||
(target == NULL && ISC_BUFFER_VALID(name->buffer)));
|
||||
|
||||
|
|
@ -1659,7 +1580,7 @@ dns_name_towire(const dns_name_t *name, dns_compress_t *cctx,
|
|||
* compression context 'cctx', and storing the result in 'target'.
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
REQUIRE(cctx != NULL);
|
||||
REQUIRE(ISC_BUFFER_VALID(target));
|
||||
|
||||
|
|
@ -1679,7 +1600,7 @@ dns_name_towire(const dns_name_t *name, dns_compress_t *cctx,
|
|||
}
|
||||
|
||||
if (name->offsets == NULL) {
|
||||
DNS_NAME_INIT(&clname, clo);
|
||||
dns_name_init(&clname, clo);
|
||||
dns_name_clone(name, &clname);
|
||||
name = &clname;
|
||||
}
|
||||
|
|
@ -1741,9 +1662,9 @@ dns_name_concatenate(const dns_name_t *prefix, const dns_name_t *suffix,
|
|||
* Concatenate 'prefix' and 'suffix'.
|
||||
*/
|
||||
|
||||
REQUIRE(prefix == NULL || VALID_NAME(prefix));
|
||||
REQUIRE(suffix == NULL || VALID_NAME(suffix));
|
||||
REQUIRE(name == NULL || VALID_NAME(name));
|
||||
REQUIRE(prefix == NULL || DNS_NAME_VALID(prefix));
|
||||
REQUIRE(suffix == NULL || DNS_NAME_VALID(suffix));
|
||||
REQUIRE(name == NULL || DNS_NAME_VALID(name));
|
||||
REQUIRE((target != NULL && ISC_BUFFER_VALID(target)) ||
|
||||
(target == NULL && name != NULL &&
|
||||
ISC_BUFFER_VALID(name->buffer)));
|
||||
|
|
@ -1758,7 +1679,7 @@ dns_name_concatenate(const dns_name_t *prefix, const dns_name_t *suffix,
|
|||
REQUIRE(!copy_suffix);
|
||||
}
|
||||
if (name == NULL) {
|
||||
DNS_NAME_INIT(&tmp_name, odata);
|
||||
dns_name_init(&tmp_name, odata);
|
||||
name = &tmp_name;
|
||||
}
|
||||
if (target == NULL) {
|
||||
|
|
@ -1767,7 +1688,7 @@ dns_name_concatenate(const dns_name_t *prefix, const dns_name_t *suffix,
|
|||
isc_buffer_clear(name->buffer);
|
||||
}
|
||||
|
||||
REQUIRE(BINDABLE(name));
|
||||
REQUIRE(DNS_NAME_BINDABLE(name));
|
||||
|
||||
/*
|
||||
* Set up.
|
||||
|
|
@ -1829,44 +1750,16 @@ dns_name_concatenate(const dns_name_t *prefix, const dns_name_t *suffix,
|
|||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
void
|
||||
dns_name_split(const dns_name_t *name, unsigned int suffixlabels,
|
||||
dns_name_t *prefix, dns_name_t *suffix)
|
||||
|
||||
{
|
||||
unsigned int splitlabel;
|
||||
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(suffixlabels > 0);
|
||||
REQUIRE(suffixlabels <= name->labels);
|
||||
REQUIRE(prefix != NULL || suffix != NULL);
|
||||
REQUIRE(prefix == NULL || (VALID_NAME(prefix) && BINDABLE(prefix)));
|
||||
REQUIRE(suffix == NULL || (VALID_NAME(suffix) && BINDABLE(suffix)));
|
||||
|
||||
splitlabel = name->labels - suffixlabels;
|
||||
|
||||
if (prefix != NULL) {
|
||||
dns_name_getlabelsequence(name, 0, splitlabel, prefix);
|
||||
}
|
||||
|
||||
if (suffix != NULL) {
|
||||
dns_name_getlabelsequence(name, splitlabel, suffixlabels,
|
||||
suffix);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
dns_name_dup(const dns_name_t *source, isc_mem_t *mctx, dns_name_t *target) {
|
||||
/*
|
||||
* Make 'target' a dynamically allocated copy of 'source'.
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_NAME(source));
|
||||
REQUIRE(DNS_NAME_VALID(source));
|
||||
REQUIRE(source->length > 0);
|
||||
REQUIRE(VALID_NAME(target));
|
||||
REQUIRE(BINDABLE(target));
|
||||
REQUIRE(DNS_NAME_VALID(target));
|
||||
REQUIRE(DNS_NAME_BINDABLE(target));
|
||||
|
||||
/*
|
||||
* Make 'target' empty in case of failure.
|
||||
|
|
@ -1899,10 +1792,10 @@ dns_name_dupwithoffsets(const dns_name_t *source, isc_mem_t *mctx,
|
|||
* 'target' will also have a dynamically allocated offsets table.
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_NAME(source));
|
||||
REQUIRE(DNS_NAME_VALID(source));
|
||||
REQUIRE(source->length > 0);
|
||||
REQUIRE(VALID_NAME(target));
|
||||
REQUIRE(BINDABLE(target));
|
||||
REQUIRE(DNS_NAME_VALID(target));
|
||||
REQUIRE(DNS_NAME_BINDABLE(target));
|
||||
REQUIRE(target->offsets == NULL);
|
||||
|
||||
/*
|
||||
|
|
@ -1938,7 +1831,7 @@ dns_name_free(dns_name_t *name, isc_mem_t *mctx) {
|
|||
* Free 'name'.
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
REQUIRE(name->attributes.dynamic);
|
||||
|
||||
size = name->length;
|
||||
|
|
@ -1961,10 +1854,10 @@ dns_name_digest(const dns_name_t *name, dns_digestfunc_t digest, void *arg) {
|
|||
* Send 'name' in DNSSEC canonical form to 'digest'.
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
REQUIRE(digest != NULL);
|
||||
|
||||
DNS_NAME_INIT(&downname, NULL);
|
||||
dns_name_init(&downname, NULL);
|
||||
|
||||
isc_buffer_init(&buffer, data, sizeof(data));
|
||||
|
||||
|
|
@ -1980,7 +1873,7 @@ dns_name_digest(const dns_name_t *name, dns_digestfunc_t digest, void *arg) {
|
|||
|
||||
bool
|
||||
dns_name_dynamic(const dns_name_t *name) {
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
|
||||
/*
|
||||
* Returns whether there is dynamic memory associated with this name.
|
||||
|
|
@ -2000,7 +1893,7 @@ dns_name_print(const dns_name_t *name, FILE *stream) {
|
|||
* Print 'name' on 'stream'.
|
||||
*/
|
||||
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
|
||||
isc_buffer_init(&b, t, sizeof(t));
|
||||
result = dns_name_totext(name, 0, &b);
|
||||
|
|
@ -2063,7 +1956,7 @@ dns_name_tostring(const dns_name_t *name, char **target, isc_mem_t *mctx) {
|
|||
isc_region_t reg;
|
||||
char *p, txt[DNS_NAME_FORMATSIZE];
|
||||
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
REQUIRE(target != NULL && *target == NULL);
|
||||
|
||||
isc_buffer_init(&buf, txt, sizeof(txt));
|
||||
|
|
@ -2094,7 +1987,7 @@ dns_name_fromstring(dns_name_t *target, const char *src,
|
|||
|
||||
isc_buffer_constinit(&buf, src, strlen(src));
|
||||
isc_buffer_add(&buf, strlen(src));
|
||||
if (BINDABLE(target) && target->buffer != NULL) {
|
||||
if (DNS_NAME_BINDABLE(target) && target->buffer != NULL) {
|
||||
name = target;
|
||||
} else {
|
||||
name = dns_fixedname_initname(&fn);
|
||||
|
|
@ -2116,9 +2009,9 @@ dns_name_copy(const dns_name_t *source, dns_name_t *dest) {
|
|||
isc_buffer_t *target = NULL;
|
||||
unsigned char *ndata = NULL;
|
||||
|
||||
REQUIRE(VALID_NAME(source));
|
||||
REQUIRE(VALID_NAME(dest));
|
||||
REQUIRE(BINDABLE(dest));
|
||||
REQUIRE(DNS_NAME_VALID(source));
|
||||
REQUIRE(DNS_NAME_VALID(dest));
|
||||
REQUIRE(DNS_NAME_BINDABLE(dest));
|
||||
|
||||
target = dest->buffer;
|
||||
|
||||
|
|
@ -2273,7 +2166,7 @@ dns_name_istat(const dns_name_t *name) {
|
|||
unsigned char len;
|
||||
const unsigned char *ndata;
|
||||
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
|
||||
if (name->labels < 1) {
|
||||
return (false);
|
||||
|
|
@ -2319,7 +2212,7 @@ dns_name_isdnssvcb(const dns_name_t *name) {
|
|||
unsigned char len, len1;
|
||||
const unsigned char *ndata;
|
||||
|
||||
REQUIRE(VALID_NAME(name));
|
||||
REQUIRE(DNS_NAME_VALID(name));
|
||||
|
||||
if (name->labels < 1 || name->length < 5) {
|
||||
return (false);
|
||||
|
|
|
|||
|
|
@ -13,8 +13,6 @@
|
|||
|
||||
/*! \file */
|
||||
|
||||
#define DNS_NAME_USEINLINE 1
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/stat.h>
|
||||
|
|
|
|||
Loading…
Reference in a new issue