diff options
| -rw-r--r-- | usr.bin/dig/lib/dns/compress.c | 16 | ||||
| -rw-r--r-- | usr.bin/dig/lib/dns/include/dns/name.h | 78 | ||||
| -rw-r--r-- | usr.bin/dig/lib/dns/name.c | 31 |
3 files changed, 27 insertions, 98 deletions
diff --git a/usr.bin/dig/lib/dns/compress.c b/usr.bin/dig/lib/dns/compress.c index f5d9535243f..f184567916b 100644 --- a/usr.bin/dig/lib/dns/compress.c +++ b/usr.bin/dig/lib/dns/compress.c @@ -14,13 +14,10 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: compress.c,v 1.3 2020/02/12 13:05:03 jsg Exp $ */ +/* $Id: compress.c,v 1.4 2020/02/13 10:12:49 florian Exp $ */ /*! \file */ -#define DNS_NAME_USEINLINE 1 - - #include <stdlib.h> #include <isc/util.h> @@ -156,13 +153,6 @@ dns_compress_findglobal(dns_compress_t *cctx, const dns_name_t *name, return (ISC_TRUE); } -static inline unsigned int -name_length(const dns_name_t *name) { - isc_region_t r; - dns_name_toregion(name, &r); - return (r.length); -} - void dns_compress_add(dns_compress_t *cctx, const dns_name_t *name, const dns_name_t *prefix, uint16_t offset) @@ -187,14 +177,14 @@ dns_compress_add(dns_compress_t *cctx, const dns_name_t *name, if (dns_name_isabsolute(prefix)) count--; start = 0; - length = name_length(name); + length = name->length; while (count > 0) { if (offset >= 0x4000) break; dns_name_getlabelsequence(name, start, n, &tname); hash = dns_name_hash(&tname, ISC_FALSE) % DNS_COMPRESS_TABLESIZE; - tlength = name_length(&tname); + tlength = tname.length; toffset = (uint16_t)(offset + (length - tlength)); /* * Create a new node and add it. diff --git a/usr.bin/dig/lib/dns/include/dns/name.h b/usr.bin/dig/lib/dns/include/dns/name.h index c7817317b65..b521eed2ba6 100644 --- a/usr.bin/dig/lib/dns/include/dns/name.h +++ b/usr.bin/dig/lib/dns/include/dns/name.h @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: name.h,v 1.2 2020/02/12 13:05:03 jsg Exp $ */ +/* $Id: name.h,v 1.3 2020/02/13 10:12:49 florian Exp $ */ #ifndef DNS_NAME_H #define DNS_NAME_H 1 @@ -1107,80 +1107,4 @@ dns_name_isdnssd(const dns_name_t *owner); 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 = 0; \ - _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); \ -} while (0) - -#define DNS_NAME_SETBUFFER(n, b) \ - (n)->buffer = (b) - -#define DNS_NAME_ISABSOLUTE(n) \ - (((n)->attributes & DNS_NAMEATTR_ABSOLUTE) != 0 ? ISC_TRUE : ISC_FALSE) - -#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) DNS_NAME_ISABSOLUTE(n) -#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 */ - #endif /* DNS_NAME_H */ diff --git a/usr.bin/dig/lib/dns/name.c b/usr.bin/dig/lib/dns/name.c index 358bf8a469b..e92b113e46f 100644 --- a/usr.bin/dig/lib/dns/name.c +++ b/usr.bin/dig/lib/dns/name.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: name.c,v 1.3 2020/02/13 08:16:01 florian Exp $ */ +/* $Id: name.c,v 1.4 2020/02/13 10:12:49 florian Exp $ */ /*! \file */ #include <ctype.h> @@ -185,7 +185,16 @@ dns_name_init(dns_name_t *name, unsigned char *offsets) { /* * Initialize 'name'. */ - DNS_NAME_INIT(name, offsets); + name->magic = DNS_NAME_MAGIC; + name->ndata = NULL; + name->length = 0; + name->labels = 0; + name->attributes = 0; + name->offsets = offsets; + name->buffer = NULL; + ISC_LINK_INIT(name, link); + ISC_LIST_INIT(name->list); + } void @@ -193,7 +202,12 @@ dns_name_reset(dns_name_t *name) { REQUIRE(VALID_NAME(name)); REQUIRE(BINDABLE(name)); - DNS_NAME_RESET(name); + name->ndata = NULL; + name->length = 0; + name->labels = 0; + name->attributes &= ~DNS_NAMEATTR_ABSOLUTE; + if (name->buffer != NULL) + isc_buffer_clear(name->buffer); } void @@ -873,7 +887,8 @@ dns_name_toregion(dns_name_t *name, isc_region_t *r) { REQUIRE(VALID_NAME(name)); REQUIRE(r != NULL); - DNS_NAME_TOREGION(name, r); + r->base = name->ndata; + r->length = name->length; } isc_result_t @@ -1607,11 +1622,11 @@ dns_name_towire(const dns_name_t *name, dns_compress_t *cctx, * has one. */ if (name->offsets == NULL) { - DNS_NAME_INIT(&clname, clo); + dns_name_init(&clname, clo); dns_name_clone(name, &clname); name = &clname; } - DNS_NAME_INIT(&gp, NULL); + dns_name_init(&gp, NULL); offset = target->used; /*XXX*/ @@ -1696,7 +1711,7 @@ dns_name_concatenate(dns_name_t *prefix, dns_name_t *suffix, dns_name_t *name, REQUIRE(!copy_suffix); } if (name == NULL) { - DNS_NAME_INIT(&tmp_name, odata); + dns_name_init(&tmp_name, odata); name = &tmp_name; } if (target == NULL) { @@ -1911,7 +1926,7 @@ dns_name_digest(dns_name_t *name, dns_digestfunc_t digest, void *arg) { REQUIRE(VALID_NAME(name)); REQUIRE(digest != NULL); - DNS_NAME_INIT(&downname, NULL); + dns_name_init(&downname, NULL); isc_buffer_init(&buffer, data, sizeof(data)); |
