From dded5a2612d6d3fb22267866ce8665174037ae2e Mon Sep 17 00:00:00 2001 From: Tony Finch Date: Wed, 4 May 2022 09:38:54 +0100 Subject: [PATCH 1/6] Remove obsolete notes on name compression These notes describe the initial compression design for BIND 9 in 1998/1999, when the IETF had some over-optimistic plans for using EDNS to change the wire format of domain names. (Another example was bitstring labels for IPv6 reverse DNS.) By the end of 2000 the EDNS name compression schemes had been abandoned, and BIND 9's compression code was rewritten to use a hash table. There is nothing left of the implementation described here, and the API functions are better described in `compress.h`, so these notes are more misleading than helpful. Those who are interested in the past can look at the version control history. --- doc/design/compression | 159 --------------------------------------- doc/design/decompression | 107 -------------------------- 2 files changed, 266 deletions(-) delete mode 100644 doc/design/compression delete mode 100644 doc/design/decompression diff --git a/doc/design/compression b/doc/design/compression deleted file mode 100644 index 3929f26c4d..0000000000 --- a/doc/design/compression +++ /dev/null @@ -1,159 +0,0 @@ - - - Name Compression - -Overview. - - BIND 4.x and BIND 8.x only had one methods of compression to deal - with 14 bit compression. BIND 9 has 3 methods of compression - to deal with 14 bit, 16 bit and local compression (14 and 16 bit). - - In addition to this the allowed compression methods vary across - types and across client revisions thanks to EDNS. - - To be able to compress a domain name you need to some or all of - the following pieces of information. - - 1. where the message starts. - 2. where the current rdata starts in the message (local compression). - 3. what the current owner name is (local compression). - 4. existing global 14 bit compression targets. - 5. existing global 16 bit compression targets. - 6. existing local compression targets. - 7. the current domain name. - 8. what are allowable compression methods, these are not constant - across a message. - - BIND 4.x and BIND 8.x used a table of existing 14 bit compression - targets. - - The implicit assumption is that we will use compression whenever - possible and when ever there are multiple alternatives available - we will choose the one that minimises the size of the message. - - We will need functions that determine the allowable compression - methods, find the "best" match among the available compression - targets, add new compression targets. - - We need to be able to back out any changes made to the compression - targets if we are unable to add a complete RR (RRset?). This is - only a problem for the global compression targets. - -Implementation: - - We will maintain two RBT, one for local compression targets and - one for global compression targets. The data for these RBT will - be the offset values. The local compression RBT only needs to - be maintained when local compression is possible. The global - compression RBT is maintained regardless. Unless there is a - perfect match (or the name is ".") we will add the name to the - compression RBTs provide the offset would not be too large for - the valid compression methods of the RBT. All nodes of the RBT - will have an offset excluding the root node. - - The local compression RBT will be initialised with the owner name - and the start of the rdata will be recorded. - - We will use deepest partial match to find the potential - compression targets. - - We only need to maintain one global RBT as 16 bit compression - pointers are either valid or invalid for the whole message. - - dns_rdata_towire() will set the allowed methods based on the - edns version. - -Functions: - - dns_result_t - dns_compress_init(dns_compress_t *cctx, int edns, isc_mem_t *mctx); - - Initialises cctx to empty and sets whether 16 bit global - compression targets are to be added to the global RBT based on the - edns value. - - dns_result_t - dns_compress_localinit(dns_compress_t *cctx, dns_name_t *owner, - isc_buffer_t *target); - - Initialise a RBT for local compression, freeing and existing RBT. - Record current offset. - - dns_compress_invalidate(dns_compress_t *cctx); - - Free any RBT's and make empty. - - dns_compress_localinvalidate(dns_compress_t *cctx); - - Free the local RBT. - - void - dns_compress_setmethods(dns_compress_t *cctx, unsigned int allowed); - - unsigned int - dns_compress_getmethods(dns_compress_t *cctx); - - int - dns_compress_getedns(dns_compress_t *cctx); - - dns_result_t - dns_name_towire(dns_name_t *name, dns_compress_t *cctx, - isc_buffer_t *target); - - 'name' contains the current name to be added to the message 'target'. - 'target' is assumed to only contain the message. - 'cctx' contains the compression context and has to hold all the - information required that cannot be obtained from 'name' or 'target'. - - struct dns_compress { - unsigned int allowed; /* Allowed methods. */ - unsigned int rdata; /* Start of local rdata */ - bool global16; /* 16 bit offsets allowed */ - dns_rbt_t *local; /* Local RBT */ - dns_rbt_t *global; /* Global RBT */ - isc_mem_t *mctx; /* Required by RBT */ - }; - - sets allowed based on the value of edns. - - bool - dns_compress_findglobal(dns_compress_t *cctx, dns_name_t *name, - dns_name_t *prefix, dns_name_t *suffix, - uint16_t *offset, isc_buffer_t *workspace); - - bool - dns_compress_findlocal(dns_compress_t *cctx, dns_name_t *name, - dns_name_t *prefix, dns_name_t *suffix, - uint16_t *offset, isc_buffer_t *workspace); - - Find the best best match in the global / local RBT. Returns prefix, - suffix and offset of the bestmatch. Findglobal(), findlocal() - requires as workspace as it may be necessary to spit a bit stream - label. The result prefix will be such that it can be added to the - wire format followed by a compression pointer pointing to offset. - Suffix is returned so that it is possible to add the compression - pointers via dns_compress_add(). - - void - dns_compress_add(dns_compress_t *cctx, dns_name_t *prefix, - dns_name_t *suffix, uint16_t offset); - - Add compression pointers pointing to lebels (if any) in prefix. - The offset to the first label is passed in offset. - -Dependency: - - Requires RBT deepest match. - Requires the ability to walk the RBT and remove any node which - meets the removal condition. diff --git a/doc/design/decompression b/doc/design/decompression deleted file mode 100644 index 1898b6f759..0000000000 --- a/doc/design/decompression +++ /dev/null @@ -1,107 +0,0 @@ - - - Name Decompression - -Overview. - - There are 4 type of compression: global 14 bit, global 16 bit, - local 14 bit and local 16 bit. - - In general the resolver / nameserver should accept any compression - method at any time regardless of whether it was legal to - send it. This fits with the principle of being liberal with - what you accept and strict with what you send. - - There are a few cases where it does not make sense to accept - compression pointers of a given type. i.e. the first domain name - in a message, local compression pointers in the ownername of a RR - or in a question. - - When performing regression testing however we should be as strict - as possible. Hence we need to be able modify the behaviour of the - decompression routines. - - To be able to decompress a domain name we need some or all of the - following pieces of information. - - 1. where the message starts. - 2. where the current rdata starts in the message (local compression). - 3. what the current owner name is (local compression). - 4. where the domainname we are decompressing starts. - 5. what are allowable decompression method. These vary across type - and edn version. - -Implementation: - - dns_rdata_fromwire will set the allowed decompression methods allowed - by looking at edns, strict and the type values. - -Types: - struct dns_decompress { - unsigned int magic; - unsigned int allowed; - int edns; - dns_name_t owner_name; - unsigned int rdata; - bool strict; - } - -Functions: - - void - dns_decompress_init(dns_decompress_t *dctx, int edns, - bool strict); - initialise dctx - dctx->ownername is invalidated - - void - dns_decompress_localinit(dns_decompress_t *dctx, dns_name_t *name, - isc_buffer_t *source); - initialise dctx->ownername - record source->current to dctx->rdata - - void - dns_decompress_invalidate(dns_decompress_t *dctx); - - invalidate dctx - - void - dns_decompress_localinvalidate(dns_decompress_t *dctx); - - invalidate dctx->ownername - - void - dns_decompress_setmethods(dns_decompress_t *dctx, unsigned int allowed); - - sets dctx->allowed - - unsigned int - dns_decompress_getmethods(dns_decompress_t *dctx); - - returns dctx->allowed - - int - dns_decompress_edns(dns_decompress_t *dctx); - - returns dctx->edns - - bool - dns_decompress_strict(dns_decompress_t *dctx); - - returns dctx->strict - - dns_result_t - dns_name_fromwire(dns_name_t *name, isc_buffer_t *source, - dns_decompress_t *dctx, bool downcase, - isc_buffer_t *target) From e37b782c1a51b4c3b01bbe8d6333f65954918333 Mon Sep 17 00:00:00 2001 From: Tony Finch Date: Wed, 4 May 2022 17:35:39 +0100 Subject: [PATCH 2/6] DNS name compression does not depend on the EDNS version There was a proposal in the late 1990s that it might, but it turned out to be unworkable. See RFC 6891, Extension Mechanisms for DNS (EDNS(0)), section 5, Extended Label Types. The remnants of the code that supported this in BIND are redundant. --- bin/dig/dighost.c | 6 +++-- bin/tests/wire_test.c | 2 +- bin/tools/dnstap-read.c | 2 +- doc/dev/rdata.md | 21 +++++++----------- fuzz/dns_message_parse.c | 2 +- fuzz/dns_rdata_fromwire_text.c | 4 ++-- lib/dns/client.c | 2 +- lib/dns/compress.c | 29 ++---------------------- lib/dns/include/dns/compress.h | 40 ++-------------------------------- lib/dns/journal.c | 2 +- lib/dns/master.c | 2 +- lib/dns/message.c | 6 +---- lib/dns/nsec3.c | 2 +- lib/dns/rdata.c | 4 ++-- lib/dns/request.c | 2 +- lib/dns/resolver.c | 4 ++-- lib/dns/xfrin.c | 2 +- lib/ns/client.c | 2 +- lib/ns/xfrout.c | 2 +- tests/dns/dnstap_test.c | 2 +- tests/dns/name_test.c | 26 +++++++++++----------- tests/dns/rdata_test.c | 4 ++-- tests/dns/tsig_test.c | 4 ++-- tests/libtest/ns.c | 2 +- 24 files changed, 53 insertions(+), 121 deletions(-) diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index 528098a077..4a2e88fecf 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -2442,7 +2442,7 @@ setup_lookup(dig_lookup_t *lookup) { lookup->sendspace = isc_mem_get(mctx, COMMSIZE); - result = dns_compress_init(&cctx, -1, mctx); + result = dns_compress_init(&cctx, mctx); check_result(result, "dns_compress_init"); debug("starting to render the message"); @@ -3053,7 +3053,9 @@ failure_tls: } else { next = NULL; } - query_detach(&connectquery); + if (connectquery != NULL) { + query_detach(&connectquery); + } query_detach(&query); if (next == NULL) { clear_current_lookup(); diff --git a/bin/tests/wire_test.c b/bin/tests/wire_test.c index 5dcc0951f7..d4224d68f6 100644 --- a/bin/tests/wire_test.c +++ b/bin/tests/wire_test.c @@ -303,7 +303,7 @@ process_message(isc_buffer_t *source) { message->counts[i] = 0; /* Another hack XXX */ } - result = dns_compress_init(&cctx, -1, mctx); + result = dns_compress_init(&cctx, mctx); CHECKRESULT(result, "dns_compress_init() failed"); result = dns_message_renderbegin(message, &cctx, &buffer); diff --git a/bin/tools/dnstap-read.c b/bin/tools/dnstap-read.c index dc7ae919ff..fe215715e4 100644 --- a/bin/tools/dnstap-read.c +++ b/bin/tools/dnstap-read.c @@ -298,7 +298,7 @@ print_yaml(dns_dtdata_t *dt) { isc_buffer_init(&b, m->query_zone.data, m->query_zone.len); isc_buffer_add(&b, m->query_zone.len); - dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_NONE); + dns_decompress_init(&dctx, DNS_DECOMPRESS_NONE); result = dns_name_fromwire(name, &b, &dctx, 0, NULL); if (result == ISC_R_SUCCESS) { printf(" query_zone: "); diff --git a/doc/dev/rdata.md b/doc/dev/rdata.md index 511ada9697..90d140df5f 100644 --- a/doc/dev/rdata.md +++ b/doc/dev/rdata.md @@ -208,13 +208,11 @@ security area and must be paranoid about its input. bool downcase, isc_buffer_t *target); -`fromwire_classname_typename()` is required to set the valid -decompression methods if there is a domain name in the rdata. +`fromwire_classname_typename()` is required to set whether +name compression is allowed, according to RFC 3597. - if (dns_decompress_edns(dctx) >= # || !dns_decompress_strict(dctx)) - dns_decompress_setmethods(dctx, DNS_COMPRESS_ALL); - else - dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14); + dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14); + /* or DNS_COMPRESS_NONE */ |Parameter|Description | |---------|-----------------------| @@ -245,14 +243,11 @@ will return `DNS_R_EXTRADATA`. dns_compress_t *cctx, isc_buffer_t *target); -`towire_classname_typename()` is required to set the -allowed name compression methods based on the EDNS version, if there -is a domain name in the rdata. +`towire_classname_typename()` is required to set whether +name compression is allowed, according to RFC 3597. - if (dns_compress_getedns(cctx) >= #) - dns_compress_setmethods(cctx, DNS_COMPRESS_ALL); - else - dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14); + dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14); + /* or DNS_COMPRESS_NONE */ |Parameter|Description | |---------|-----------------------| diff --git a/fuzz/dns_message_parse.c b/fuzz/dns_message_parse.c index 02006a86ec..d0caa245ee 100644 --- a/fuzz/dns_message_parse.c +++ b/fuzz/dns_message_parse.c @@ -112,7 +112,7 @@ render_message(dns_message_t **messagep) { message->counts[i] = 0; } - result = dns_compress_init(&cctx, -1, mctx); + result = dns_compress_init(&cctx, mctx); if (result != ISC_R_SUCCESS) { return (result); } diff --git a/fuzz/dns_rdata_fromwire_text.c b/fuzz/dns_rdata_fromwire_text.c index f05ddd4be5..3f71538b5f 100644 --- a/fuzz/dns_rdata_fromwire_text.c +++ b/fuzz/dns_rdata_fromwire_text.c @@ -136,7 +136,7 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { callbacks.warn = callbacks.error = nullmsg; /* Disallow decompression as we are reading a packet */ - dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_NONE); + dns_decompress_init(&dctx, DNS_DECOMPRESS_NONE); isc_buffer_constinit(&source, data, size); isc_buffer_add(&source, size); @@ -206,7 +206,7 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { /* * Convert rdata back to wire. */ - CHECK(dns_compress_init(&cctx, -1, mctx)); + CHECK(dns_compress_init(&cctx, mctx)); dns_compress_disable(&cctx); isc_buffer_init(&target, towire, sizeof(towire)); result = dns_rdata_towire(&rdata1, &cctx, &target); diff --git a/lib/dns/client.c b/lib/dns/client.c index 675b78c8b3..cbe70337cc 100644 --- a/lib/dns/client.c +++ b/lib/dns/client.c @@ -1285,7 +1285,7 @@ dns_client_addtrustedkey(dns_client_t *client, dns_rdataclass_t rdclass, } isc_buffer_init(&b, rdatabuf, sizeof(rdatabuf)); - dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_NONE); + dns_decompress_init(&dctx, DNS_DECOMPRESS_NONE); dns_rdata_init(&rdata); isc_buffer_setactive(databuf, isc_buffer_usedlength(databuf)); CHECK(dns_rdata_fromwire(&rdata, rdclass, rdtype, databuf, &dctx, 0, diff --git a/lib/dns/compress.c b/lib/dns/compress.c index 583a0eab68..7a06d4fa1e 100644 --- a/lib/dns/compress.c +++ b/lib/dns/compress.c @@ -123,11 +123,10 @@ static unsigned char tableindex[256] = { ***/ isc_result_t -dns_compress_init(dns_compress_t *cctx, int edns, isc_mem_t *mctx) { +dns_compress_init(dns_compress_t *cctx, isc_mem_t *mctx) { REQUIRE(cctx != NULL); REQUIRE(mctx != NULL); /* See: rdataset.c:towiresorted(). */ - cctx->edns = edns; cctx->mctx = mctx; cctx->count = 0; cctx->allowed = DNS_COMPRESS_ENABLED; @@ -164,7 +163,6 @@ dns_compress_invalidate(dns_compress_t *cctx) { cctx->magic = 0; cctx->allowed = 0; - cctx->edns = -1; } void @@ -205,12 +203,6 @@ dns_compress_getsensitive(dns_compress_t *cctx) { return (cctx->allowed & DNS_COMPRESS_CASESENSITIVE); } -int -dns_compress_getedns(dns_compress_t *cctx) { - REQUIRE(VALID_CCTX(cctx)); - return (cctx->edns); -} - /* * Find the longest match of name in the table. * If match is found return true. prefix, suffix and offset are updated. @@ -521,13 +513,10 @@ dns_compress_rollback(dns_compress_t *cctx, uint16_t offset) { ***/ void -dns_decompress_init(dns_decompress_t *dctx, int edns, - dns_decompresstype_t type) { +dns_decompress_init(dns_decompress_t *dctx, dns_decompresstype_t type) { REQUIRE(dctx != NULL); - REQUIRE(edns >= -1 && edns <= 255); dctx->allowed = DNS_COMPRESS_NONE; - dctx->edns = edns; dctx->type = type; dctx->magic = DCTX_MAGIC; } @@ -562,17 +551,3 @@ dns_decompress_getmethods(dns_decompress_t *dctx) { return (dctx->allowed); } - -int -dns_decompress_edns(dns_decompress_t *dctx) { - REQUIRE(VALID_DCTX(dctx)); - - return (dctx->edns); -} - -dns_decompresstype_t -dns_decompress_type(dns_decompress_t *dctx) { - REQUIRE(VALID_DCTX(dctx)); - - return (dctx->type); -} diff --git a/lib/dns/include/dns/compress.h b/lib/dns/include/dns/compress.h index 5476dd92a9..6f497f639c 100644 --- a/lib/dns/include/dns/compress.h +++ b/lib/dns/include/dns/compress.h @@ -68,7 +68,6 @@ struct dns_compressnode { struct dns_compress { unsigned int magic; /*%< Magic number. */ unsigned int allowed; /*%< Allowed methods. */ - int edns; /*%< Edns version or -1. */ /*% Global compression table. */ dns_compressnode_t *table[DNS_COMPRESS_TABLESIZE]; /*% Preallocated arena for names. */ @@ -89,12 +88,11 @@ typedef enum { struct dns_decompress { unsigned int magic; /*%< Magic number. */ unsigned int allowed; /*%< Allowed methods. */ - int edns; /*%< Edns version or -1. */ dns_decompresstype_t type; /*%< Strict checking */ }; isc_result_t -dns_compress_init(dns_compress_t *cctx, int edns, isc_mem_t *mctx); +dns_compress_init(dns_compress_t *cctx, isc_mem_t *mctx); /*%< * Initialise the compression context structure pointed to by * 'cctx'. A freshly initialized context has name compression @@ -175,19 +173,6 @@ dns_compress_getsensitive(dns_compress_t *cctx); * 'cctx' to be initialized. */ -int -dns_compress_getedns(dns_compress_t *cctx); - -/*%< - * Gets edns value. - * - * Requires: - *\li 'cctx' to be initialized. - * - * Returns: - *\li -1 .. 255 - */ - bool dns_compress_findglobal(dns_compress_t *cctx, const dns_name_t *name, dns_name_t *prefix, uint16_t *offset); @@ -235,8 +220,7 @@ dns_compress_rollback(dns_compress_t *cctx, uint16_t offset); */ void -dns_decompress_init(dns_decompress_t *dctx, int edns, - dns_decompresstype_t type); +dns_decompress_init(dns_decompress_t *dctx, dns_decompresstype_t type); /*%< * Initializes 'dctx'. @@ -276,24 +260,4 @@ dns_decompress_getmethods(dns_decompress_t *dctx); *\li 'dctx' to be initialized */ -int -dns_decompress_edns(dns_decompress_t *dctx); - -/*%< - * Returns 'dctx->edns' - * - * Requires: - *\li 'dctx' to be initialized - */ - -dns_decompresstype_t -dns_decompress_type(dns_decompress_t *dctx); - -/*%< - * Returns 'dctx->type' - * - * Requires: - *\li 'dctx' to be initialized - */ - ISC_LANG_ENDDECLS diff --git a/lib/dns/journal.c b/lib/dns/journal.c index 23534115ed..9732682d03 100644 --- a/lib/dns/journal.c +++ b/lib/dns/journal.c @@ -738,7 +738,7 @@ journal_open(isc_mem_t *mctx, const char *filename, bool writable, bool create, */ isc_buffer_init(&j->it.source, NULL, 0); isc_buffer_init(&j->it.target, NULL, 0); - dns_decompress_init(&j->it.dctx, -1, DNS_DECOMPRESS_NONE); + dns_decompress_init(&j->it.dctx, DNS_DECOMPRESS_NONE); j->state = writable ? JOURNAL_STATE_WRITE : JOURNAL_STATE_READ; diff --git a/lib/dns/master.c b/lib/dns/master.c index 7399729161..ccedc1af84 100644 --- a/lib/dns/master.c +++ b/lib/dns/master.c @@ -2342,7 +2342,7 @@ load_raw(dns_loadctx_t *lctx) { dns_decompress_t dctx; callbacks = lctx->callbacks; - dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_NONE); + dns_decompress_init(&dctx, DNS_DECOMPRESS_NONE); if (lctx->first) { result = load_header(lctx); diff --git a/lib/dns/message.c b/lib/dns/message.c index d89c4f8301..ac23ebab7a 100644 --- a/lib/dns/message.c +++ b/lib/dns/message.c @@ -1681,11 +1681,7 @@ dns_message_parse(dns_message_t *msg, isc_buffer_t *source, msg->header_ok = 1; msg->state = DNS_SECTION_QUESTION; - /* - * -1 means no EDNS. - */ - dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_ANY); - + dns_decompress_init(&dctx, DNS_DECOMPRESS_ANY); dns_decompress_setmethods(&dctx, DNS_COMPRESS_GLOBAL14); ret = getquestions(source, msg, &dctx, options); diff --git a/lib/dns/nsec3.c b/lib/dns/nsec3.c index c553cdaf1e..5644f1e9e7 100644 --- a/lib/dns/nsec3.c +++ b/lib/dns/nsec3.c @@ -988,7 +988,7 @@ dns_nsec3param_fromprivate(dns_rdata_t *src, dns_rdata_t *target, isc_buffer_add(&buf1, src->length - 1); isc_buffer_setactive(&buf1, src->length - 1); isc_buffer_init(&buf2, buf, (unsigned int)buflen); - dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_NONE); + dns_decompress_init(&dctx, DNS_DECOMPRESS_NONE); result = dns_rdata_fromwire(target, src->rdclass, dns_rdatatype_nsec3param, &buf1, &dctx, 0, &buf2); diff --git a/lib/dns/rdata.c b/lib/dns/rdata.c index 76e25955f7..44e3030723 100644 --- a/lib/dns/rdata.c +++ b/lib/dns/rdata.c @@ -613,7 +613,7 @@ check_private(isc_buffer_t *source, dns_secalg_t alg) { dns_fixedname_t fixed; dns_decompress_t dctx; - dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT); + dns_decompress_init(&dctx, DNS_DECOMPRESS_STRICT); RETERR(dns_name_fromwire(dns_fixedname_initname(&fixed), source, &dctx, 0, NULL)); /* @@ -927,7 +927,7 @@ rdata_validate(isc_buffer_t *src, isc_buffer_t *dest, dns_rdataclass_t rdclass, dns_decompress_t dctx; isc_result_t result; - dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_NONE); + dns_decompress_init(&dctx, DNS_DECOMPRESS_NONE); isc_buffer_setactive(src, isc_buffer_usedlength(src)); result = dns_rdata_fromwire(NULL, rdclass, type, src, &dctx, 0, dest); dns_decompress_invalidate(&dctx); diff --git a/lib/dns/request.c b/lib/dns/request.c index 54db330833..729ae6417e 100644 --- a/lib/dns/request.c +++ b/lib/dns/request.c @@ -764,7 +764,7 @@ req_render(dns_message_t *message, isc_buffer_t **bufferp, unsigned int options, */ isc_buffer_allocate(mctx, &buf1, 65535); - result = dns_compress_init(&cctx, -1, mctx); + result = dns_compress_init(&cctx, mctx); if (result != ISC_R_SUCCESS) { return (result); } diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index 08498c368d..901da4b353 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -2530,7 +2530,7 @@ resquery_send(resquery_t *query) { /* * Convert the question to wire format. */ - result = dns_compress_init(&cctx, -1, fctx->res->mctx); + result = dns_compress_init(&cctx, fctx->res->mctx); if (result != ISC_R_SUCCESS) { goto cleanup_message; } @@ -9822,7 +9822,7 @@ rctx_logpacket(respctx_t *rctx) { * Log the response via dnstap. */ memset(&zr, 0, sizeof(zr)); - result = dns_compress_init(&cctx, -1, fctx->res->mctx); + result = dns_compress_init(&cctx, fctx->res->mctx); if (result == ISC_R_SUCCESS) { isc_buffer_init(&zb, zone, sizeof(zone)); dns_compress_setmethods(&cctx, DNS_COMPRESS_NONE); diff --git a/lib/dns/xfrin.c b/lib/dns/xfrin.c index 4f3afd216e..aae27c2fc3 100644 --- a/lib/dns/xfrin.c +++ b/lib/dns/xfrin.c @@ -1192,7 +1192,7 @@ render(dns_message_t *msg, isc_mem_t *mctx, isc_buffer_t *buf) { bool cleanup_cctx = false; isc_result_t result; - CHECK(dns_compress_init(&cctx, -1, mctx)); + CHECK(dns_compress_init(&cctx, mctx)); cleanup_cctx = true; CHECK(dns_message_renderbegin(msg, &cctx, buf)); CHECK(dns_message_rendersection(msg, DNS_SECTION_QUESTION, 0)); diff --git a/lib/ns/client.c b/lib/ns/client.c index 7596bb62e5..b620483d8b 100644 --- a/lib/ns/client.c +++ b/lib/ns/client.c @@ -537,7 +537,7 @@ ns_client_send(ns_client_t *client) { client_allocsendbuf(client, &buffer, &data); - result = dns_compress_init(&cctx, -1, client->manager->mctx); + result = dns_compress_init(&cctx, client->manager->mctx); if (result != ISC_R_SUCCESS) { goto cleanup; } diff --git a/lib/ns/xfrout.c b/lib/ns/xfrout.c index 8d71c3c572..e3290b0b1e 100644 --- a/lib/ns/xfrout.c +++ b/lib/ns/xfrout.c @@ -1526,7 +1526,7 @@ sendstream(xfrout_ctx_t *xfr) { if (is_tcp) { isc_region_t used; - CHECK(dns_compress_init(&cctx, -1, xfr->mctx)); + CHECK(dns_compress_init(&cctx, xfr->mctx)); dns_compress_setsensitive(&cctx, true); cleanup_cctx = true; CHECK(dns_message_renderbegin(msg, &cctx, &xfr->txbuf)); diff --git a/tests/dns/dnstap_test.c b/tests/dns/dnstap_test.c index 8fdb952a38..ed0ccaab25 100644 --- a/tests/dns/dnstap_test.c +++ b/tests/dns/dnstap_test.c @@ -171,7 +171,7 @@ ISC_RUN_TEST_IMPL(dns_dt_send) { memset(&zr, 0, sizeof(zr)); isc_buffer_init(&zb, zone, sizeof(zone)); - result = dns_compress_init(&cctx, -1, mctx); + result = dns_compress_init(&cctx, mctx); assert_int_equal(result, ISC_R_SUCCESS); dns_compress_setmethods(&cctx, DNS_COMPRESS_NONE); result = dns_name_towire(zname, &cctx, &zb); diff --git a/tests/dns/name_test.c b/tests/dns/name_test.c index 511ee3c8b3..f1852194d0 100644 --- a/tests/dns/name_test.c +++ b/tests/dns/name_test.c @@ -191,9 +191,9 @@ ISC_RUN_TEST_IMPL(compression) { /* Test 1: NONE */ allowed = DNS_COMPRESS_NONE; - assert_int_equal(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS); + assert_int_equal(dns_compress_init(&cctx, mctx), ISC_R_SUCCESS); dns_compress_setmethods(&cctx, allowed); - dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT); + dns_decompress_init(&dctx, DNS_DECOMPRESS_STRICT); dns_decompress_setmethods(&dctx, allowed); compress_test(&name1, &name2, &name3, plain, sizeof(plain), &cctx, @@ -204,9 +204,9 @@ ISC_RUN_TEST_IMPL(compression) { /* Test2: GLOBAL14 */ allowed = DNS_COMPRESS_GLOBAL14; - assert_int_equal(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS); + assert_int_equal(dns_compress_init(&cctx, mctx), ISC_R_SUCCESS); dns_compress_setmethods(&cctx, allowed); - dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT); + dns_decompress_init(&dctx, DNS_DECOMPRESS_STRICT); dns_decompress_setmethods(&dctx, allowed); compress_test(&name1, &name2, &name3, plain, sizeof(plain), &cctx, @@ -217,9 +217,9 @@ ISC_RUN_TEST_IMPL(compression) { /* Test3: ALL */ allowed = DNS_COMPRESS_ALL; - assert_int_equal(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS); + assert_int_equal(dns_compress_init(&cctx, mctx), ISC_R_SUCCESS); dns_compress_setmethods(&cctx, allowed); - dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT); + dns_decompress_init(&dctx, DNS_DECOMPRESS_STRICT); dns_decompress_setmethods(&dctx, allowed); compress_test(&name1, &name2, &name3, plain, sizeof(plain), &cctx, @@ -230,10 +230,10 @@ ISC_RUN_TEST_IMPL(compression) { /* Test4: NONE disabled */ allowed = DNS_COMPRESS_NONE; - assert_int_equal(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS); + assert_int_equal(dns_compress_init(&cctx, mctx), ISC_R_SUCCESS); dns_compress_setmethods(&cctx, allowed); dns_compress_disable(&cctx); - dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT); + dns_decompress_init(&dctx, DNS_DECOMPRESS_STRICT); dns_decompress_setmethods(&dctx, allowed); compress_test(&name1, &name2, &name3, plain, sizeof(plain), &cctx, @@ -244,10 +244,10 @@ ISC_RUN_TEST_IMPL(compression) { /* Test5: GLOBAL14 disabled */ allowed = DNS_COMPRESS_GLOBAL14; - assert_int_equal(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS); + assert_int_equal(dns_compress_init(&cctx, mctx), ISC_R_SUCCESS); dns_compress_setmethods(&cctx, allowed); dns_compress_disable(&cctx); - dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT); + dns_decompress_init(&dctx, DNS_DECOMPRESS_STRICT); dns_decompress_setmethods(&dctx, allowed); compress_test(&name1, &name2, &name3, plain, sizeof(plain), &cctx, @@ -258,10 +258,10 @@ ISC_RUN_TEST_IMPL(compression) { /* Test6: ALL disabled */ allowed = DNS_COMPRESS_ALL; - assert_int_equal(dns_compress_init(&cctx, -1, mctx), ISC_R_SUCCESS); + assert_int_equal(dns_compress_init(&cctx, mctx), ISC_R_SUCCESS); dns_compress_setmethods(&cctx, allowed); dns_compress_disable(&cctx); - dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT); + dns_decompress_init(&dctx, DNS_DECOMPRESS_STRICT); dns_decompress_setmethods(&dctx, allowed); compress_test(&name1, &name2, &name3, plain, sizeof(plain), &cctx, @@ -650,7 +650,7 @@ ISC_RUN_TEST_IMPL(fromwire_thread(void *arg) { UNUSED(arg); - dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT); + dns_decompress_init(&dctx, DNS_DECOMPRESS_STRICT); dns_decompress_setmethods(&dctx, DNS_COMPRESS_NONE); isc_buffer_init(&source, data, sizeof(data)); diff --git a/tests/dns/rdata_test.c b/tests/dns/rdata_test.c index 71149eafaf..8549cc528b 100644 --- a/tests/dns/rdata_test.c +++ b/tests/dns/rdata_test.c @@ -150,7 +150,7 @@ wire_to_rdata(const unsigned char *src, size_t srclen, dns_rdataclass_t rdclass, /* * Try converting input data into uncompressed wire form. */ - dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_ANY); + dns_decompress_init(&dctx, DNS_DECOMPRESS_ANY); result = dns_rdata_fromwire(rdata, rdclass, type, &source, &dctx, 0, &target); dns_decompress_invalidate(&dctx); @@ -176,7 +176,7 @@ rdata_towire(dns_rdata_t *rdata, unsigned char *dst, size_t dstlen, /* * Try converting input data into uncompressed wire form. */ - dns_compress_init(&cctx, -1, mctx); + dns_compress_init(&cctx, mctx); result = dns_rdata_towire(rdata, &cctx, &target); dns_compress_invalidate(&cctx); diff --git a/tests/dns/tsig_test.c b/tests/dns/tsig_test.c index f94a0fa016..b1fe184972 100644 --- a/tests/dns/tsig_test.c +++ b/tests/dns/tsig_test.c @@ -105,7 +105,7 @@ add_tsig(dst_context_t *tsigctx, dns_tsigkey_t *key, isc_buffer_t *target) { memset(&tsig, 0, sizeof(tsig)); - CHECK(dns_compress_init(&cctx, -1, mctx)); + CHECK(dns_compress_init(&cctx, mctx)); invalidate_ctx = true; tsig.common.rdclass = dns_rdataclass_any; @@ -232,7 +232,7 @@ render(isc_buffer_t *buf, unsigned flags, dns_tsigkey_t *key, assert_int_equal(result, ISC_R_SUCCESS); } - result = dns_compress_init(&cctx, -1, mctx); + result = dns_compress_init(&cctx, mctx); assert_int_equal(result, ISC_R_SUCCESS); result = dns_message_renderbegin(msg, &cctx, buf); diff --git a/tests/libtest/ns.c b/tests/libtest/ns.c index 6de395b6ab..b85a215401 100644 --- a/tests/libtest/ns.c +++ b/tests/libtest/ns.c @@ -336,7 +336,7 @@ attach_query_msg_to_client(ns_client_t *client, const char *qnamestr, /* * Render the query. */ - dns_compress_init(&cctx, -1, mctx); + dns_compress_init(&cctx, mctx); isc_buffer_init(&querybuf, query, sizeof(query)); result = dns_message_renderbegin(message, &cctx, &querybuf); if (result != ISC_R_SUCCESS) { From 129a522d887f03bb058c0e57259cea247830d619 Mon Sep 17 00:00:00 2001 From: Tony Finch Date: Thu, 5 May 2022 14:52:44 +0100 Subject: [PATCH 3/6] There can no longer be multiple compression methods The aim is to get rid of the obsolete term "GLOBAL14" and instead just refer to DNS name compression. This is mostly mechanically renaming from dns_(de)compress_(get|set)methods() to dns_(de)compress_(get|set)permitted() and replacing the related enum by a simple flag, because compression is either on or off. --- doc/dev/rdata.md | 6 +-- lib/dns/compress.c | 65 ++++++++++++++-------------- lib/dns/include/dns/compress.h | 49 +++++++++------------ lib/dns/message.c | 2 +- lib/dns/name.c | 27 ++++-------- lib/dns/ncache.c | 2 +- lib/dns/rdata/any_255/tsig_250.c | 4 +- lib/dns/rdata/ch_3/a_1.c | 4 +- lib/dns/rdata/generic/afsdb_18.c | 4 +- lib/dns/rdata/generic/amtrelay_260.c | 2 +- lib/dns/rdata/generic/cname_5.c | 4 +- lib/dns/rdata/generic/dname_39.c | 4 +- lib/dns/rdata/generic/hip_55.c | 2 +- lib/dns/rdata/generic/ipseckey_45.c | 2 +- lib/dns/rdata/generic/lp_107.c | 2 +- lib/dns/rdata/generic/mb_7.c | 4 +- lib/dns/rdata/generic/md_3.c | 4 +- lib/dns/rdata/generic/mf_4.c | 4 +- lib/dns/rdata/generic/mg_8.c | 4 +- lib/dns/rdata/generic/minfo_14.c | 4 +- lib/dns/rdata/generic/mr_9.c | 4 +- lib/dns/rdata/generic/mx_15.c | 4 +- lib/dns/rdata/generic/naptr_35.c | 4 +- lib/dns/rdata/generic/ns_2.c | 4 +- lib/dns/rdata/generic/nsec_47.c | 4 +- lib/dns/rdata/generic/nxt_30.c | 4 +- lib/dns/rdata/generic/proforma.c | 8 ++-- lib/dns/rdata/generic/ptr_12.c | 4 +- lib/dns/rdata/generic/rp_17.c | 4 +- lib/dns/rdata/generic/rrsig_46.c | 4 +- lib/dns/rdata/generic/rt_21.c | 4 +- lib/dns/rdata/generic/sig_24.c | 4 +- lib/dns/rdata/generic/soa_6.c | 4 +- lib/dns/rdata/generic/talink_58.c | 4 +- lib/dns/rdata/generic/tkey_249.c | 4 +- lib/dns/rdata/in_1/a6_38.c | 4 +- lib/dns/rdata/in_1/kx_36.c | 4 +- lib/dns/rdata/in_1/nsap-ptr_23.c | 4 +- lib/dns/rdata/in_1/px_26.c | 4 +- lib/dns/rdata/in_1/srv_33.c | 4 +- lib/dns/rdata/in_1/svcb_64.c | 4 +- lib/dns/rdataset.c | 2 +- lib/dns/resolver.c | 4 +- lib/ns/client.c | 2 +- tests/dns/dnstap_test.c | 2 +- tests/dns/name_test.c | 61 ++++++++------------------ 46 files changed, 155 insertions(+), 203 deletions(-) diff --git a/doc/dev/rdata.md b/doc/dev/rdata.md index 90d140df5f..7c67650179 100644 --- a/doc/dev/rdata.md +++ b/doc/dev/rdata.md @@ -211,8 +211,7 @@ security area and must be paranoid about its input. `fromwire_classname_typename()` is required to set whether name compression is allowed, according to RFC 3597. - dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14); - /* or DNS_COMPRESS_NONE */ + dns_decompress_setpermitted(dctx, true); /* or false */ |Parameter|Description | |---------|-----------------------| @@ -246,8 +245,7 @@ will return `DNS_R_EXTRADATA`. `towire_classname_typename()` is required to set whether name compression is allowed, according to RFC 3597. - dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14); - /* or DNS_COMPRESS_NONE */ + dns_compress_setpermitted(cctx, true); /* or false */ |Parameter|Description | |---------|-----------------------| diff --git a/lib/dns/compress.c b/lib/dns/compress.c index 7a06d4fa1e..8e49f9bbce 100644 --- a/lib/dns/compress.c +++ b/lib/dns/compress.c @@ -127,9 +127,14 @@ dns_compress_init(dns_compress_t *cctx, isc_mem_t *mctx) { REQUIRE(cctx != NULL); REQUIRE(mctx != NULL); /* See: rdataset.c:towiresorted(). */ + /* + * not using a structure literal here to avoid large memset()s + */ cctx->mctx = mctx; cctx->count = 0; - cctx->allowed = DNS_COMPRESS_ENABLED; + cctx->permitted = true; + cctx->disabled = false; + cctx->sensitive = false; cctx->arena_off = 0; memset(&cctx->table[0], 0, sizeof(cctx->table)); @@ -162,45 +167,39 @@ dns_compress_invalidate(dns_compress_t *cctx) { } cctx->magic = 0; - cctx->allowed = 0; + cctx->permitted = false; + cctx->disabled = false; + cctx->sensitive = false; } void -dns_compress_setmethods(dns_compress_t *cctx, unsigned int allowed) { +dns_compress_setpermitted(dns_compress_t *cctx, bool permitted) { REQUIRE(VALID_CCTX(cctx)); - - cctx->allowed &= ~DNS_COMPRESS_ALL; - cctx->allowed |= (allowed & DNS_COMPRESS_ALL); + cctx->permitted = permitted; } -unsigned int -dns_compress_getmethods(dns_compress_t *cctx) { +bool +dns_compress_getpermitted(dns_compress_t *cctx) { REQUIRE(VALID_CCTX(cctx)); - return (cctx->allowed & DNS_COMPRESS_ALL); + return (cctx->permitted); } void dns_compress_disable(dns_compress_t *cctx) { REQUIRE(VALID_CCTX(cctx)); - cctx->allowed &= ~DNS_COMPRESS_ENABLED; + cctx->disabled = true; } void dns_compress_setsensitive(dns_compress_t *cctx, bool sensitive) { REQUIRE(VALID_CCTX(cctx)); - - if (sensitive) { - cctx->allowed |= DNS_COMPRESS_CASESENSITIVE; - } else { - cctx->allowed &= ~DNS_COMPRESS_CASESENSITIVE; - } + cctx->sensitive = sensitive; } bool dns_compress_getsensitive(dns_compress_t *cctx) { REQUIRE(VALID_CCTX(cctx)); - - return (cctx->allowed & DNS_COMPRESS_CASESENSITIVE); + return (cctx->sensitive); } /* @@ -221,7 +220,7 @@ dns_compress_findglobal(dns_compress_t *cctx, const dns_name_t *name, REQUIRE(dns_name_isabsolute(name)); REQUIRE(offset != NULL); - if ((cctx->allowed & DNS_COMPRESS_ENABLED) == 0) { + if (cctx->disabled) { return (false); } @@ -250,7 +249,7 @@ dns_compress_findglobal(dns_compress_t *cctx, const dns_name_t *name, */ ch = p[1]; i = tableindex[ch]; - if ((cctx->allowed & DNS_COMPRESS_CASESENSITIVE) != 0) { + if (cctx->sensitive) { for (node = cctx->table[i]; node != NULL; node = node->next) { if (node->name.length != length) { @@ -380,7 +379,7 @@ dns_compress_add(dns_compress_t *cctx, const dns_name_t *name, REQUIRE(VALID_CCTX(cctx)); REQUIRE(dns_name_isabsolute(name)); - if ((cctx->allowed & DNS_COMPRESS_ENABLED) == 0) { + if (cctx->disabled) { return; } @@ -481,7 +480,7 @@ dns_compress_rollback(dns_compress_t *cctx, uint16_t offset) { REQUIRE(VALID_CCTX(cctx)); - if ((cctx->allowed & DNS_COMPRESS_ENABLED) == 0) { + if (cctx->disabled) { return; } @@ -516,38 +515,38 @@ void dns_decompress_init(dns_decompress_t *dctx, dns_decompresstype_t type) { REQUIRE(dctx != NULL); - dctx->allowed = DNS_COMPRESS_NONE; - dctx->type = type; - dctx->magic = DCTX_MAGIC; + *dctx = (dns_decompress_t){ + .magic = DCTX_MAGIC, + .type = type, + }; } void dns_decompress_invalidate(dns_decompress_t *dctx) { REQUIRE(VALID_DCTX(dctx)); - dctx->magic = 0; } void -dns_decompress_setmethods(dns_decompress_t *dctx, unsigned int allowed) { +dns_decompress_setpermitted(dns_decompress_t *dctx, bool permitted) { REQUIRE(VALID_DCTX(dctx)); switch (dctx->type) { case DNS_DECOMPRESS_ANY: - dctx->allowed = DNS_COMPRESS_ALL; + dctx->permitted = true; break; case DNS_DECOMPRESS_NONE: - dctx->allowed = DNS_COMPRESS_NONE; + dctx->permitted = false; break; case DNS_DECOMPRESS_STRICT: - dctx->allowed = allowed; + dctx->permitted = permitted; break; } } -unsigned int -dns_decompress_getmethods(dns_decompress_t *dctx) { +bool +dns_decompress_getpermitted(dns_decompress_t *dctx) { REQUIRE(VALID_DCTX(dctx)); - return (dctx->allowed); + return (dctx->permitted); } diff --git a/lib/dns/include/dns/compress.h b/lib/dns/include/dns/compress.h index 6f497f639c..f3c6a7e12d 100644 --- a/lib/dns/include/dns/compress.h +++ b/lib/dns/include/dns/compress.h @@ -27,24 +27,15 @@ ISC_LANG_BEGINDECLS /*! \file dns/compress.h * Direct manipulation of the structures is strongly discouraged. * - * A name compression context handles compression of multiple DNS names - * in relation to a single DNS message. The context can be used to - * selectively turn on/off compression for specific names (depending on - * the RR type) by using \c dns_compress_setmethods(). Alternately, - * compression can be disabled completely using \c - * dns_compress_disable(). + * A name compression context handles compression of multiple DNS names in + * relation to a single DNS message. The context can be used to selectively + * turn on/off compression for specific names (depending on the RR type, + * according to RFC 3597) by using \c dns_compress_setpermitted(). * - * \c dns_compress_setmethods() is intended for use by RDATA towire() - * implementations, whereas \c dns_compress_disable() is intended to be - * used by a nameserver's configuration manager. + * The nameserver can be configured not to use compression at all using + * \c dns_compress_disable(). */ -#define DNS_COMPRESS_NONE 0x00 /*%< no compression */ -#define DNS_COMPRESS_GLOBAL14 0x01 /*%< "normal" compression. */ -#define DNS_COMPRESS_ALL 0x01 /*%< all compression. */ -#define DNS_COMPRESS_CASESENSITIVE 0x02 /*%< case sensitive compression. */ -#define DNS_COMPRESS_ENABLED 0x04 - /* * DNS_COMPRESS_TABLESIZE must be a power of 2. The compress code * utilizes this assumption. @@ -66,8 +57,10 @@ struct dns_compressnode { }; struct dns_compress { - unsigned int magic; /*%< Magic number. */ - unsigned int allowed; /*%< Allowed methods. */ + unsigned int magic; /*%< Magic number. */ + bool permitted; + bool disabled; + bool sensitive; /*% Global compression table. */ dns_compressnode_t *table[DNS_COMPRESS_TABLESIZE]; /*% Preallocated arena for names. */ @@ -87,8 +80,8 @@ typedef enum { struct dns_decompress { unsigned int magic; /*%< Magic number. */ - unsigned int allowed; /*%< Allowed methods. */ dns_decompresstype_t type; /*%< Strict checking */ + bool permitted; }; isc_result_t @@ -120,17 +113,17 @@ dns_compress_invalidate(dns_compress_t *cctx); */ void -dns_compress_setmethods(dns_compress_t *cctx, unsigned int allowed); +dns_compress_setpermitted(dns_compress_t *cctx, bool permitted); /*%< - * Sets allowed compression methods. + * Sets whether compression is allowed, according to RFC 3597 * * Requires: *\li 'cctx' to be initialized. */ -unsigned int -dns_compress_getmethods(dns_compress_t *cctx); +bool +dns_compress_getpermitted(dns_compress_t *cctx); /*%< * Gets allowed compression methods. @@ -186,7 +179,7 @@ dns_compress_findglobal(dns_compress_t *cctx, const dns_name_t *name, *\li 'offset' to point to an uint16_t. * * Ensures: - *\li 'prefix' and 'offset' are valid if true is returned. + *\li 'prefix' and 'offset' are valid if true is returned. * * Returns: *\li #true / #false @@ -241,20 +234,20 @@ dns_decompress_invalidate(dns_decompress_t *dctx); */ void -dns_decompress_setmethods(dns_decompress_t *dctx, unsigned int allowed); +dns_decompress_setpermitted(dns_decompress_t *dctx, bool permitted); /*%< - * Sets 'dctx->allowed' to 'allowed'. + * Sets whether decompression is allowed, according to RFC 3597 * * Requires: *\li 'dctx' to be initialized */ -unsigned int -dns_decompress_getmethods(dns_decompress_t *dctx); +bool +dns_decompress_getpermitted(dns_decompress_t *dctx); /*%< - * Returns 'dctx->allowed' + * Returns whether decompression is allowed here * * Requires: *\li 'dctx' to be initialized diff --git a/lib/dns/message.c b/lib/dns/message.c index ac23ebab7a..e567202eb9 100644 --- a/lib/dns/message.c +++ b/lib/dns/message.c @@ -1682,7 +1682,7 @@ dns_message_parse(dns_message_t *msg, isc_buffer_t *source, msg->state = DNS_SECTION_QUESTION; dns_decompress_init(&dctx, DNS_DECOMPRESS_ANY); - dns_decompress_setmethods(&dctx, DNS_COMPRESS_GLOBAL14); + dns_decompress_setpermitted(&dctx, true); ret = getquestions(source, msg, &dctx, options); if (ret == ISC_R_UNEXPECTEDEND && ignore_tc) { diff --git a/lib/dns/name.c b/lib/dns/name.c index 58cdc100a5..76dd6b4470 100644 --- a/lib/dns/name.c +++ b/lib/dns/name.c @@ -1839,19 +1839,11 @@ dns_name_fromwire(dns_name_t *name, isc_buffer_t *source, } n = c; state = fw_ordinary; - } else if (c >= 128 && c < 192) { - /* - * 14 bit local compression pointer. - * Local compression is no longer an - * IETF draft. - */ - return (DNS_R_BADLABELTYPE); } else if (c >= 192) { /* - * Ordinary 14-bit pointer. + * 14-bit compression pointer */ - if ((dctx->allowed & DNS_COMPRESS_GLOBAL14) == - 0) { + if (!dctx->permitted) { return (DNS_R_DISALLOWED); } new_current = c & 0x3F; @@ -1928,7 +1920,7 @@ dns_name_towire(const dns_name_t *name, dns_compress_t *cctx, isc_result_t dns_name_towire2(const dns_name_t *name, dns_compress_t *cctx, isc_buffer_t *target, uint16_t *comp_offsetp) { - unsigned int methods; + bool compress; uint16_t offset; dns_name_t gp; /* Global compression prefix */ bool gf; /* Global compression target found */ @@ -1945,16 +1937,15 @@ 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 && + dns_compress_getpermitted(cctx); + /* * If this exact name was already rendered before, and the * offset of the previously rendered name is passed to us, write * a compression pointer directly. */ - methods = dns_compress_getmethods(cctx); - if (comp_offsetp != NULL && *comp_offsetp < 0x4000 && - (name->attributes & DNS_NAMEATTR_NOCOMPRESS) == 0 && - (methods & DNS_COMPRESS_GLOBAL14) != 0) - { + if (comp_offsetp != NULL && *comp_offsetp < 0x4000 && compress) { if (target->length - target->used < 2) { return (ISC_R_NOSPACE); } @@ -1977,9 +1968,7 @@ dns_name_towire2(const dns_name_t *name, dns_compress_t *cctx, offset = target->used; /*XXX*/ - if ((name->attributes & DNS_NAMEATTR_NOCOMPRESS) == 0 && - (methods & DNS_COMPRESS_GLOBAL14) != 0) - { + if (compress) { gf = dns_compress_findglobal(cctx, name, &gp, &go); } else { gf = false; diff --git a/lib/dns/ncache.c b/lib/dns/ncache.c index 7bea3d376c..466af525f4 100644 --- a/lib/dns/ncache.c +++ b/lib/dns/ncache.c @@ -351,7 +351,7 @@ dns_ncache_towire(dns_rdataset_t *rdataset, dns_compress_t *cctx, /* * Write the name. */ - dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14); + dns_compress_setpermitted(cctx, true); result = dns_name_towire(&name, cctx, target); if (result != ISC_R_SUCCESS) { goto rollback; diff --git a/lib/dns/rdata/any_255/tsig_250.c b/lib/dns/rdata/any_255/tsig_250.c index c8bcd3e007..f6829c67c2 100644 --- a/lib/dns/rdata/any_255/tsig_250.c +++ b/lib/dns/rdata/any_255/tsig_250.c @@ -263,7 +263,7 @@ fromwire_any_tsig(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); + dns_decompress_setpermitted(dctx, false); /* * Algorithm Name. @@ -330,7 +330,7 @@ towire_any_tsig(ARGS_TOWIRE) { REQUIRE(rdata->rdclass == dns_rdataclass_any); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_NONE); + dns_compress_setpermitted(cctx, false); dns_rdata_toregion(rdata, &sr); dns_name_init(&name, offsets); dns_name_fromregion(&name, &sr); diff --git a/lib/dns/rdata/ch_3/a_1.c b/lib/dns/rdata/ch_3/a_1.c index a3303a88e4..b5514c1659 100644 --- a/lib/dns/rdata/ch_3/a_1.c +++ b/lib/dns/rdata/ch_3/a_1.c @@ -105,7 +105,7 @@ fromwire_ch_a(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14); + dns_decompress_setpermitted(dctx, true); dns_name_init(&name, NULL); @@ -138,7 +138,7 @@ towire_ch_a(ARGS_TOWIRE) { REQUIRE(rdata->rdclass == dns_rdataclass_ch); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14); + dns_compress_setpermitted(cctx, true); dns_name_init(&name, offsets); diff --git a/lib/dns/rdata/generic/afsdb_18.c b/lib/dns/rdata/generic/afsdb_18.c index 077e0acc55..63b3149cd6 100644 --- a/lib/dns/rdata/generic/afsdb_18.c +++ b/lib/dns/rdata/generic/afsdb_18.c @@ -101,7 +101,7 @@ fromwire_afsdb(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); + dns_decompress_setpermitted(dctx, false); dns_name_init(&name, NULL); @@ -129,7 +129,7 @@ towire_afsdb(ARGS_TOWIRE) { REQUIRE(rdata->type == dns_rdatatype_afsdb); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_NONE); + dns_compress_setpermitted(cctx, false); isc_buffer_availableregion(target, &tr); dns_rdata_toregion(rdata, &sr); if (tr.length < 2) { diff --git a/lib/dns/rdata/generic/amtrelay_260.c b/lib/dns/rdata/generic/amtrelay_260.c index 69b6f190c2..13b707cf82 100644 --- a/lib/dns/rdata/generic/amtrelay_260.c +++ b/lib/dns/rdata/generic/amtrelay_260.c @@ -192,7 +192,7 @@ fromwire_amtrelay(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); + dns_decompress_setpermitted(dctx, false); isc_buffer_activeregion(source, ®ion); if (region.length < 2) { diff --git a/lib/dns/rdata/generic/cname_5.c b/lib/dns/rdata/generic/cname_5.c index f3f9378b29..61b2e9f278 100644 --- a/lib/dns/rdata/generic/cname_5.c +++ b/lib/dns/rdata/generic/cname_5.c @@ -71,7 +71,7 @@ fromwire_cname(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14); + dns_decompress_setpermitted(dctx, true); dns_name_init(&name, NULL); return (dns_name_fromwire(&name, source, dctx, options, target)); @@ -86,7 +86,7 @@ towire_cname(ARGS_TOWIRE) { REQUIRE(rdata->type == dns_rdatatype_cname); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14); + dns_compress_setpermitted(cctx, true); dns_name_init(&name, offsets); dns_rdata_toregion(rdata, ®ion); diff --git a/lib/dns/rdata/generic/dname_39.c b/lib/dns/rdata/generic/dname_39.c index 2eb1dc840a..cd7a0d8f75 100644 --- a/lib/dns/rdata/generic/dname_39.c +++ b/lib/dns/rdata/generic/dname_39.c @@ -72,7 +72,7 @@ fromwire_dname(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); + dns_decompress_setpermitted(dctx, false); dns_name_init(&name, NULL); return (dns_name_fromwire(&name, source, dctx, options, target)); @@ -87,7 +87,7 @@ towire_dname(ARGS_TOWIRE) { REQUIRE(rdata->type == dns_rdatatype_dname); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_NONE); + dns_compress_setpermitted(cctx, false); dns_name_init(&name, offsets); dns_rdata_toregion(rdata, ®ion); dns_name_fromregion(&name, ®ion); diff --git a/lib/dns/rdata/generic/hip_55.c b/lib/dns/rdata/generic/hip_55.c index a224a83134..34d7940faa 100644 --- a/lib/dns/rdata/generic/hip_55.c +++ b/lib/dns/rdata/generic/hip_55.c @@ -226,7 +226,7 @@ fromwire_hip(ARGS_FROMWIRE) { RETERR(mem_tobuffer(target, rr.base, 4 + len)); isc_buffer_forward(source, 4 + len); - dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); + dns_decompress_setpermitted(dctx, false); while (isc_buffer_activelength(source) > 0) { dns_name_init(&name, NULL); RETERR(dns_name_fromwire(&name, source, dctx, options, target)); diff --git a/lib/dns/rdata/generic/ipseckey_45.c b/lib/dns/rdata/generic/ipseckey_45.c index fe7d8094da..5122ebe1d2 100644 --- a/lib/dns/rdata/generic/ipseckey_45.c +++ b/lib/dns/rdata/generic/ipseckey_45.c @@ -221,7 +221,7 @@ fromwire_ipseckey(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); + dns_decompress_setpermitted(dctx, false); dns_name_init(&name, NULL); diff --git a/lib/dns/rdata/generic/lp_107.c b/lib/dns/rdata/generic/lp_107.c index c4342c06c1..91658938ce 100644 --- a/lib/dns/rdata/generic/lp_107.c +++ b/lib/dns/rdata/generic/lp_107.c @@ -88,7 +88,7 @@ fromwire_lp(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14); + dns_decompress_setpermitted(dctx, true); dns_name_init(&name, NULL); diff --git a/lib/dns/rdata/generic/mb_7.c b/lib/dns/rdata/generic/mb_7.c index 23e9e09eab..4d417ded87 100644 --- a/lib/dns/rdata/generic/mb_7.c +++ b/lib/dns/rdata/generic/mb_7.c @@ -70,7 +70,7 @@ fromwire_mb(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14); + dns_decompress_setpermitted(dctx, true); dns_name_init(&name, NULL); return (dns_name_fromwire(&name, source, dctx, options, target)); @@ -85,7 +85,7 @@ towire_mb(ARGS_TOWIRE) { REQUIRE(rdata->type == dns_rdatatype_mb); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14); + dns_compress_setpermitted(cctx, true); dns_name_init(&name, offsets); dns_rdata_toregion(rdata, ®ion); diff --git a/lib/dns/rdata/generic/md_3.c b/lib/dns/rdata/generic/md_3.c index 38d48d32ad..7711eac084 100644 --- a/lib/dns/rdata/generic/md_3.c +++ b/lib/dns/rdata/generic/md_3.c @@ -70,7 +70,7 @@ fromwire_md(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14); + dns_decompress_setpermitted(dctx, true); dns_name_init(&name, NULL); return (dns_name_fromwire(&name, source, dctx, options, target)); @@ -85,7 +85,7 @@ towire_md(ARGS_TOWIRE) { REQUIRE(rdata->type == dns_rdatatype_md); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14); + dns_compress_setpermitted(cctx, true); dns_name_init(&name, offsets); dns_rdata_toregion(rdata, ®ion); diff --git a/lib/dns/rdata/generic/mf_4.c b/lib/dns/rdata/generic/mf_4.c index 3590767dea..5130e5006a 100644 --- a/lib/dns/rdata/generic/mf_4.c +++ b/lib/dns/rdata/generic/mf_4.c @@ -70,7 +70,7 @@ fromwire_mf(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14); + dns_decompress_setpermitted(dctx, true); dns_name_init(&name, NULL); return (dns_name_fromwire(&name, source, dctx, options, target)); @@ -85,7 +85,7 @@ towire_mf(ARGS_TOWIRE) { REQUIRE(rdata->type == dns_rdatatype_mf); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14); + dns_compress_setpermitted(cctx, true); dns_name_init(&name, offsets); dns_rdata_toregion(rdata, ®ion); diff --git a/lib/dns/rdata/generic/mg_8.c b/lib/dns/rdata/generic/mg_8.c index 201a295c60..7285c5cb36 100644 --- a/lib/dns/rdata/generic/mg_8.c +++ b/lib/dns/rdata/generic/mg_8.c @@ -70,7 +70,7 @@ fromwire_mg(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14); + dns_decompress_setpermitted(dctx, true); dns_name_init(&name, NULL); return (dns_name_fromwire(&name, source, dctx, options, target)); @@ -85,7 +85,7 @@ towire_mg(ARGS_TOWIRE) { REQUIRE(rdata->type == dns_rdatatype_mg); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14); + dns_compress_setpermitted(cctx, true); dns_name_init(&name, offsets); dns_rdata_toregion(rdata, ®ion); diff --git a/lib/dns/rdata/generic/minfo_14.c b/lib/dns/rdata/generic/minfo_14.c index 38ff8bdef4..03200ba9d9 100644 --- a/lib/dns/rdata/generic/minfo_14.c +++ b/lib/dns/rdata/generic/minfo_14.c @@ -98,7 +98,7 @@ fromwire_minfo(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14); + dns_decompress_setpermitted(dctx, true); dns_name_init(&rmail, NULL); dns_name_init(&email, NULL); @@ -118,7 +118,7 @@ towire_minfo(ARGS_TOWIRE) { REQUIRE(rdata->type == dns_rdatatype_minfo); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14); + dns_compress_setpermitted(cctx, true); dns_name_init(&rmail, roffsets); dns_name_init(&email, eoffsets); diff --git a/lib/dns/rdata/generic/mr_9.c b/lib/dns/rdata/generic/mr_9.c index 4ea279b2a0..60f59cacf6 100644 --- a/lib/dns/rdata/generic/mr_9.c +++ b/lib/dns/rdata/generic/mr_9.c @@ -70,7 +70,7 @@ fromwire_mr(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14); + dns_decompress_setpermitted(dctx, true); dns_name_init(&name, NULL); return (dns_name_fromwire(&name, source, dctx, options, target)); @@ -85,7 +85,7 @@ towire_mr(ARGS_TOWIRE) { REQUIRE(rdata->type == dns_rdatatype_mr); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14); + dns_compress_setpermitted(cctx, true); dns_name_init(&name, offsets); dns_rdata_toregion(rdata, ®ion); diff --git a/lib/dns/rdata/generic/mx_15.c b/lib/dns/rdata/generic/mx_15.c index 9356f0d3c6..4614c95ac5 100644 --- a/lib/dns/rdata/generic/mx_15.c +++ b/lib/dns/rdata/generic/mx_15.c @@ -134,7 +134,7 @@ fromwire_mx(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14); + dns_decompress_setpermitted(dctx, true); dns_name_init(&name, NULL); @@ -156,7 +156,7 @@ towire_mx(ARGS_TOWIRE) { REQUIRE(rdata->type == dns_rdatatype_mx); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14); + dns_compress_setpermitted(cctx, true); dns_rdata_toregion(rdata, ®ion); RETERR(mem_tobuffer(target, region.base, 2)); diff --git a/lib/dns/rdata/generic/naptr_35.c b/lib/dns/rdata/generic/naptr_35.c index 9ab8343f2b..afa1a5d4b8 100644 --- a/lib/dns/rdata/generic/naptr_35.c +++ b/lib/dns/rdata/generic/naptr_35.c @@ -311,7 +311,7 @@ fromwire_naptr(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); + dns_decompress_setpermitted(dctx, false); dns_name_init(&name, NULL); @@ -357,7 +357,7 @@ towire_naptr(ARGS_TOWIRE) { REQUIRE(rdata->type == dns_rdatatype_naptr); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_NONE); + dns_compress_setpermitted(cctx, false); /* * Order, preference. */ diff --git a/lib/dns/rdata/generic/ns_2.c b/lib/dns/rdata/generic/ns_2.c index 9fa8dba0a3..ce9f44a112 100644 --- a/lib/dns/rdata/generic/ns_2.c +++ b/lib/dns/rdata/generic/ns_2.c @@ -81,7 +81,7 @@ fromwire_ns(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14); + dns_decompress_setpermitted(dctx, true); dns_name_init(&name, NULL); return (dns_name_fromwire(&name, source, dctx, options, target)); @@ -96,7 +96,7 @@ towire_ns(ARGS_TOWIRE) { REQUIRE(rdata->type == dns_rdatatype_ns); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14); + dns_compress_setpermitted(cctx, true); dns_name_init(&name, offsets); dns_rdata_toregion(rdata, ®ion); diff --git a/lib/dns/rdata/generic/nsec_47.c b/lib/dns/rdata/generic/nsec_47.c index add8deae00..571a0ce37b 100644 --- a/lib/dns/rdata/generic/nsec_47.c +++ b/lib/dns/rdata/generic/nsec_47.c @@ -85,7 +85,7 @@ fromwire_nsec(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); + dns_decompress_setpermitted(dctx, false); dns_name_init(&name, NULL); RETERR(dns_name_fromwire(&name, source, dctx, options, target)); @@ -106,7 +106,7 @@ towire_nsec(ARGS_TOWIRE) { REQUIRE(rdata->type == dns_rdatatype_nsec); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_NONE); + dns_compress_setpermitted(cctx, false); dns_name_init(&name, offsets); dns_rdata_toregion(rdata, &sr); dns_name_fromregion(&name, &sr); diff --git a/lib/dns/rdata/generic/nxt_30.c b/lib/dns/rdata/generic/nxt_30.c index 6ca056001c..5dce8a03fc 100644 --- a/lib/dns/rdata/generic/nxt_30.c +++ b/lib/dns/rdata/generic/nxt_30.c @@ -144,7 +144,7 @@ fromwire_nxt(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); + dns_decompress_setpermitted(dctx, false); dns_name_init(&name, NULL); RETERR(dns_name_fromwire(&name, source, dctx, options, target)); @@ -169,7 +169,7 @@ towire_nxt(ARGS_TOWIRE) { REQUIRE(rdata->type == dns_rdatatype_nxt); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_NONE); + dns_compress_setpermitted(cctx, false); dns_name_init(&name, offsets); dns_rdata_toregion(rdata, &sr); dns_name_fromregion(&name, &sr); diff --git a/lib/dns/rdata/generic/proforma.c b/lib/dns/rdata/generic/proforma.c index 6315a6f147..2c286227b0 100644 --- a/lib/dns/rdata/generic/proforma.c +++ b/lib/dns/rdata/generic/proforma.c @@ -40,8 +40,8 @@ static isc_result_t fromwire_ #(ARGS_FROMWIRE) { REQUIRE(type == dns_rdatatype_proforma.c #); REQUIRE(rdclass == #); - /* NONE or GLOBAL14 */ - dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); + /* see RFC 3597 */ + dns_decompress_setpermitted(dctx, false); return (ISC_R_NOTIMPLEMENTED); } @@ -51,8 +51,8 @@ static isc_result_t towire_ #(ARGS_TOWIRE) { REQUIRE(rdata->rdclass == #); REQUIRE(rdata->length != 0); /* XXX */ - /* NONE or GLOBAL14 */ - dns_compress_setmethods(cctx, DNS_COMPRESS_NONE); + /* see RFC 3597 */ + dns_compress_setpermitted(cctx, false); return (ISC_R_NOTIMPLEMENTED); } diff --git a/lib/dns/rdata/generic/ptr_12.c b/lib/dns/rdata/generic/ptr_12.c index 41e2e8e64b..f584b7a80e 100644 --- a/lib/dns/rdata/generic/ptr_12.c +++ b/lib/dns/rdata/generic/ptr_12.c @@ -83,7 +83,7 @@ fromwire_ptr(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14); + dns_decompress_setpermitted(dctx, true); dns_name_init(&name, NULL); return (dns_name_fromwire(&name, source, dctx, options, target)); @@ -98,7 +98,7 @@ towire_ptr(ARGS_TOWIRE) { REQUIRE(rdata->type == dns_rdatatype_ptr); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14); + dns_compress_setpermitted(cctx, true); dns_name_init(&name, offsets); dns_rdata_toregion(rdata, ®ion); diff --git a/lib/dns/rdata/generic/rp_17.c b/lib/dns/rdata/generic/rp_17.c index 62080c666f..6e1800d7cd 100644 --- a/lib/dns/rdata/generic/rp_17.c +++ b/lib/dns/rdata/generic/rp_17.c @@ -99,7 +99,7 @@ fromwire_rp(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); + dns_decompress_setpermitted(dctx, false); dns_name_init(&rmail, NULL); dns_name_init(&email, NULL); @@ -119,7 +119,7 @@ towire_rp(ARGS_TOWIRE) { REQUIRE(rdata->type == dns_rdatatype_rp); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_NONE); + dns_compress_setpermitted(cctx, false); dns_name_init(&rmail, roffsets); dns_name_init(&email, eoffsets); diff --git a/lib/dns/rdata/generic/rrsig_46.c b/lib/dns/rdata/generic/rrsig_46.c index bb9190431d..d457160b04 100644 --- a/lib/dns/rdata/generic/rrsig_46.c +++ b/lib/dns/rdata/generic/rrsig_46.c @@ -303,7 +303,7 @@ fromwire_rrsig(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); + dns_decompress_setpermitted(dctx, false); isc_buffer_activeregion(source, &sr); /* @@ -357,7 +357,7 @@ towire_rrsig(ARGS_TOWIRE) { REQUIRE(rdata->type == dns_rdatatype_rrsig); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_NONE); + dns_compress_setpermitted(cctx, false); dns_rdata_toregion(rdata, &sr); /* * type covered: 2 diff --git a/lib/dns/rdata/generic/rt_21.c b/lib/dns/rdata/generic/rt_21.c index 10a003f5c0..f36836f3ab 100644 --- a/lib/dns/rdata/generic/rt_21.c +++ b/lib/dns/rdata/generic/rt_21.c @@ -97,7 +97,7 @@ fromwire_rt(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); + dns_decompress_setpermitted(dctx, false); dns_name_init(&name, NULL); @@ -125,7 +125,7 @@ towire_rt(ARGS_TOWIRE) { REQUIRE(rdata->type == dns_rdatatype_rt); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_NONE); + dns_compress_setpermitted(cctx, false); isc_buffer_availableregion(target, &tr); dns_rdata_toregion(rdata, ®ion); if (tr.length < 2) { diff --git a/lib/dns/rdata/generic/sig_24.c b/lib/dns/rdata/generic/sig_24.c index 7cfec7bfed..f6a10f7a44 100644 --- a/lib/dns/rdata/generic/sig_24.c +++ b/lib/dns/rdata/generic/sig_24.c @@ -266,7 +266,7 @@ fromwire_sig(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); + dns_decompress_setpermitted(dctx, false); isc_buffer_activeregion(source, &sr); /* @@ -320,7 +320,7 @@ towire_sig(ARGS_TOWIRE) { REQUIRE(rdata->type == dns_rdatatype_sig); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_NONE); + dns_compress_setpermitted(cctx, false); dns_rdata_toregion(rdata, &sr); /* * type covered: 2 diff --git a/lib/dns/rdata/generic/soa_6.c b/lib/dns/rdata/generic/soa_6.c index 24b52784a3..2cba492c77 100644 --- a/lib/dns/rdata/generic/soa_6.c +++ b/lib/dns/rdata/generic/soa_6.c @@ -165,7 +165,7 @@ fromwire_soa(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14); + dns_decompress_setpermitted(dctx, true); dns_name_init(&mname, NULL); dns_name_init(&rname, NULL); @@ -202,7 +202,7 @@ towire_soa(ARGS_TOWIRE) { REQUIRE(rdata->type == dns_rdatatype_soa); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14); + dns_compress_setpermitted(cctx, true); dns_name_init(&mname, moffsets); dns_name_init(&rname, roffsets); diff --git a/lib/dns/rdata/generic/talink_58.c b/lib/dns/rdata/generic/talink_58.c index 49ad8df49b..b47220f0b9 100644 --- a/lib/dns/rdata/generic/talink_58.c +++ b/lib/dns/rdata/generic/talink_58.c @@ -88,7 +88,7 @@ fromwire_talink(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); + dns_decompress_setpermitted(dctx, false); dns_name_init(&prev, NULL); dns_name_init(&next, NULL); @@ -108,7 +108,7 @@ towire_talink(ARGS_TOWIRE) { REQUIRE(rdata->type == dns_rdatatype_talink); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_NONE); + dns_compress_setpermitted(cctx, false); dns_name_init(&prev, moffsets); dns_name_init(&next, roffsets); diff --git a/lib/dns/rdata/generic/tkey_249.c b/lib/dns/rdata/generic/tkey_249.c index 1744a54de3..34189cf082 100644 --- a/lib/dns/rdata/generic/tkey_249.c +++ b/lib/dns/rdata/generic/tkey_249.c @@ -253,7 +253,7 @@ fromwire_tkey(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); + dns_decompress_setpermitted(dctx, false); /* * Algorithm. @@ -312,7 +312,7 @@ towire_tkey(ARGS_TOWIRE) { REQUIRE(rdata->type == dns_rdatatype_tkey); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_NONE); + dns_compress_setpermitted(cctx, false); /* * Algorithm. */ diff --git a/lib/dns/rdata/in_1/a6_38.c b/lib/dns/rdata/in_1/a6_38.c index 80941d650b..ea2f13fe9b 100644 --- a/lib/dns/rdata/in_1/a6_38.c +++ b/lib/dns/rdata/in_1/a6_38.c @@ -158,7 +158,7 @@ fromwire_in_a6(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); + dns_decompress_setpermitted(dctx, false); isc_buffer_activeregion(source, &sr); /* @@ -211,7 +211,7 @@ towire_in_a6(ARGS_TOWIRE) { REQUIRE(rdata->rdclass == dns_rdataclass_in); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_NONE); + dns_compress_setpermitted(cctx, false); dns_rdata_toregion(rdata, &sr); prefixlen = sr.base[0]; INSIST(prefixlen <= 128); diff --git a/lib/dns/rdata/in_1/kx_36.c b/lib/dns/rdata/in_1/kx_36.c index ce48db1238..355734332d 100644 --- a/lib/dns/rdata/in_1/kx_36.c +++ b/lib/dns/rdata/in_1/kx_36.c @@ -89,7 +89,7 @@ fromwire_in_kx(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); + dns_decompress_setpermitted(dctx, false); dns_name_init(&name, NULL); @@ -112,7 +112,7 @@ towire_in_kx(ARGS_TOWIRE) { REQUIRE(rdata->rdclass == dns_rdataclass_in); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_NONE); + dns_compress_setpermitted(cctx, false); dns_rdata_toregion(rdata, ®ion); RETERR(mem_tobuffer(target, region.base, 2)); isc_region_consume(®ion, 2); diff --git a/lib/dns/rdata/in_1/nsap-ptr_23.c b/lib/dns/rdata/in_1/nsap-ptr_23.c index 9620fed71c..3345aa82c9 100644 --- a/lib/dns/rdata/in_1/nsap-ptr_23.c +++ b/lib/dns/rdata/in_1/nsap-ptr_23.c @@ -75,7 +75,7 @@ fromwire_in_nsap_ptr(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); + dns_decompress_setpermitted(dctx, false); dns_name_init(&name, NULL); return (dns_name_fromwire(&name, source, dctx, options, target)); @@ -91,7 +91,7 @@ towire_in_nsap_ptr(ARGS_TOWIRE) { REQUIRE(rdata->rdclass == dns_rdataclass_in); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_NONE); + dns_compress_setpermitted(cctx, false); dns_name_init(&name, offsets); dns_rdata_toregion(rdata, ®ion); dns_name_fromregion(&name, ®ion); diff --git a/lib/dns/rdata/in_1/px_26.c b/lib/dns/rdata/in_1/px_26.c index 441c3c413c..1223664153 100644 --- a/lib/dns/rdata/in_1/px_26.c +++ b/lib/dns/rdata/in_1/px_26.c @@ -119,7 +119,7 @@ fromwire_in_px(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); + dns_decompress_setpermitted(dctx, false); dns_name_init(&name, NULL); @@ -154,7 +154,7 @@ towire_in_px(ARGS_TOWIRE) { REQUIRE(rdata->rdclass == dns_rdataclass_in); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_NONE); + dns_compress_setpermitted(cctx, false); /* * Preference. */ diff --git a/lib/dns/rdata/in_1/srv_33.c b/lib/dns/rdata/in_1/srv_33.c index 6818b0395c..df10c819d8 100644 --- a/lib/dns/rdata/in_1/srv_33.c +++ b/lib/dns/rdata/in_1/srv_33.c @@ -149,7 +149,7 @@ fromwire_in_srv(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); + dns_decompress_setpermitted(dctx, false); dns_name_init(&name, NULL); @@ -178,7 +178,7 @@ towire_in_srv(ARGS_TOWIRE) { REQUIRE(rdata->type == dns_rdatatype_srv); REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_NONE); + dns_compress_setpermitted(cctx, false); /* * Priority, weight, port. */ diff --git a/lib/dns/rdata/in_1/svcb_64.c b/lib/dns/rdata/in_1/svcb_64.c index f4881c8508..00fdf24b25 100644 --- a/lib/dns/rdata/in_1/svcb_64.c +++ b/lib/dns/rdata/in_1/svcb_64.c @@ -756,7 +756,7 @@ generic_fromwire_in_svcb(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); + dns_decompress_setpermitted(dctx, false); dns_name_init(&name, NULL); @@ -904,7 +904,7 @@ generic_towire_in_svcb(ARGS_TOWIRE) { REQUIRE(rdata->length != 0); - dns_compress_setmethods(cctx, DNS_COMPRESS_NONE); + dns_compress_setpermitted(cctx, false); /* * SvcPriority. diff --git a/lib/dns/rdataset.c b/lib/dns/rdataset.c index 5271d3c36c..a547e0ba1f 100644 --- a/lib/dns/rdataset.c +++ b/lib/dns/rdataset.c @@ -453,7 +453,7 @@ towiresorted(dns_rdataset_t *rdataset, const dns_name_t *owner_name, */ rrbuffer = *target; - dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14); + dns_compress_setpermitted(cctx, true); result = dns_name_towire2(name, cctx, target, &offset); if (result != ISC_R_SUCCESS) { goto rollback; diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index 901da4b353..f8d5d12f72 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -2798,7 +2798,7 @@ resquery_send(resquery_t *query) { #ifdef HAVE_DNSTAP memset(&zr, 0, sizeof(zr)); isc_buffer_init(&zb, zone, sizeof(zone)); - dns_compress_setmethods(&cctx, DNS_COMPRESS_NONE); + dns_compress_setpermitted(&cctx, false); result = dns_name_towire(fctx->domain, &cctx, &zb); if (result == ISC_R_SUCCESS) { isc_buffer_usedregion(&zb, &zr); @@ -9825,7 +9825,7 @@ rctx_logpacket(respctx_t *rctx) { result = dns_compress_init(&cctx, fctx->res->mctx); if (result == ISC_R_SUCCESS) { isc_buffer_init(&zb, zone, sizeof(zone)); - dns_compress_setmethods(&cctx, DNS_COMPRESS_NONE); + dns_compress_setpermitted(&cctx, false); result = dns_name_towire(fctx->domain, &cctx, &zb); if (result == ISC_R_SUCCESS) { isc_buffer_usedregion(&zb, &zr); diff --git a/lib/ns/client.c b/lib/ns/client.c index b620483d8b..627dfeb14f 100644 --- a/lib/ns/client.c +++ b/lib/ns/client.c @@ -633,7 +633,7 @@ renderend: dns_name_t *zo = dns_zone_getorigin(client->query.authzone); isc_buffer_init(&b, zone, sizeof(zone)); - dns_compress_setmethods(&cctx, DNS_COMPRESS_NONE); + dns_compress_setpermitted(&cctx, false); eresult = dns_name_towire(zo, &cctx, &b); if (eresult == ISC_R_SUCCESS) { isc_buffer_usedregion(&b, &zr); diff --git a/tests/dns/dnstap_test.c b/tests/dns/dnstap_test.c index ed0ccaab25..b338ecbcc9 100644 --- a/tests/dns/dnstap_test.c +++ b/tests/dns/dnstap_test.c @@ -173,7 +173,7 @@ ISC_RUN_TEST_IMPL(dns_dt_send) { isc_buffer_init(&zb, zone, sizeof(zone)); result = dns_compress_init(&cctx, mctx); assert_int_equal(result, ISC_R_SUCCESS); - dns_compress_setmethods(&cctx, DNS_COMPRESS_NONE); + dns_compress_setpermitted(&cctx, false); result = dns_name_towire(zname, &cctx, &zb); assert_int_equal(result, ISC_R_SUCCESS); dns_compress_invalidate(&cctx); diff --git a/tests/dns/name_test.c b/tests/dns/name_test.c index f1852194d0..4bb4655914 100644 --- a/tests/dns/name_test.c +++ b/tests/dns/name_test.c @@ -159,7 +159,7 @@ compress_test(dns_name_t *name1, dns_name_t *name2, dns_name_t *name3, /* name compression test */ ISC_RUN_TEST_IMPL(compression) { - unsigned int allowed; + bool permitted; dns_compress_t cctx; dns_decompress_t dctx; dns_name_t name1; @@ -189,12 +189,12 @@ ISC_RUN_TEST_IMPL(compression) { r.length = sizeof(plain3); dns_name_fromregion(&name3, &r); - /* Test 1: NONE */ - allowed = DNS_COMPRESS_NONE; + /* Test 1: off */ + permitted = false; assert_int_equal(dns_compress_init(&cctx, mctx), ISC_R_SUCCESS); - dns_compress_setmethods(&cctx, allowed); + dns_compress_setpermitted(&cctx, permitted); dns_decompress_init(&dctx, DNS_DECOMPRESS_STRICT); - dns_decompress_setmethods(&dctx, allowed); + dns_decompress_setpermitted(&dctx, permitted); compress_test(&name1, &name2, &name3, plain, sizeof(plain), &cctx, &dctx); @@ -202,12 +202,12 @@ ISC_RUN_TEST_IMPL(compression) { dns_compress_rollback(&cctx, 0); dns_compress_invalidate(&cctx); - /* Test2: GLOBAL14 */ - allowed = DNS_COMPRESS_GLOBAL14; + /* Test2: on */ + permitted = true; assert_int_equal(dns_compress_init(&cctx, mctx), ISC_R_SUCCESS); - dns_compress_setmethods(&cctx, allowed); + dns_compress_setpermitted(&cctx, permitted); dns_decompress_init(&dctx, DNS_DECOMPRESS_STRICT); - dns_decompress_setmethods(&dctx, allowed); + dns_decompress_setpermitted(&dctx, permitted); compress_test(&name1, &name2, &name3, plain, sizeof(plain), &cctx, &dctx); @@ -215,26 +215,13 @@ ISC_RUN_TEST_IMPL(compression) { dns_compress_rollback(&cctx, 0); dns_compress_invalidate(&cctx); - /* Test3: ALL */ - allowed = DNS_COMPRESS_ALL; + /* Test3: off, disabled */ + permitted = false; assert_int_equal(dns_compress_init(&cctx, mctx), ISC_R_SUCCESS); - dns_compress_setmethods(&cctx, allowed); - dns_decompress_init(&dctx, DNS_DECOMPRESS_STRICT); - dns_decompress_setmethods(&dctx, allowed); - - compress_test(&name1, &name2, &name3, plain, sizeof(plain), &cctx, - &dctx); - - dns_compress_rollback(&cctx, 0); - dns_compress_invalidate(&cctx); - - /* Test4: NONE disabled */ - allowed = DNS_COMPRESS_NONE; - assert_int_equal(dns_compress_init(&cctx, mctx), ISC_R_SUCCESS); - dns_compress_setmethods(&cctx, allowed); + dns_compress_setpermitted(&cctx, permitted); dns_compress_disable(&cctx); dns_decompress_init(&dctx, DNS_DECOMPRESS_STRICT); - dns_decompress_setmethods(&dctx, allowed); + dns_decompress_setpermitted(&dctx, permitted); compress_test(&name1, &name2, &name3, plain, sizeof(plain), &cctx, &dctx); @@ -242,27 +229,13 @@ ISC_RUN_TEST_IMPL(compression) { dns_compress_rollback(&cctx, 0); dns_compress_invalidate(&cctx); - /* Test5: GLOBAL14 disabled */ - allowed = DNS_COMPRESS_GLOBAL14; + /* Test4: on, disabled */ + permitted = true; assert_int_equal(dns_compress_init(&cctx, mctx), ISC_R_SUCCESS); - dns_compress_setmethods(&cctx, allowed); + dns_compress_setpermitted(&cctx, permitted); dns_compress_disable(&cctx); dns_decompress_init(&dctx, DNS_DECOMPRESS_STRICT); - dns_decompress_setmethods(&dctx, allowed); - - compress_test(&name1, &name2, &name3, plain, sizeof(plain), &cctx, - &dctx); - - dns_compress_rollback(&cctx, 0); - dns_compress_invalidate(&cctx); - - /* Test6: ALL disabled */ - allowed = DNS_COMPRESS_ALL; - assert_int_equal(dns_compress_init(&cctx, mctx), ISC_R_SUCCESS); - dns_compress_setmethods(&cctx, allowed); - dns_compress_disable(&cctx); - dns_decompress_init(&dctx, DNS_DECOMPRESS_STRICT); - dns_decompress_setmethods(&dctx, allowed); + dns_decompress_setpermitted(&dctx, permitted); compress_test(&name1, &name2, &name3, plain, sizeof(plain), &cctx, &dctx); From 1d807d84f1961e5250956e59e1fb8a833caa9968 Mon Sep 17 00:00:00 2001 From: Tony Finch Date: Thu, 5 May 2022 16:36:52 +0100 Subject: [PATCH 4/6] Shrink decompression contexts It's wasteful to use 20 bytes and a pointer indirection to represent two bits of information, so turn the struct into an enum. And change the names of the enumeration constants to make the intent more clear. This change introduces some inline functions into another header, which confuses `gcovr` when it is trying to collect code coverage statistics. So, in the CI job, copy more header files into a directory where `gcovr` looks for them. --- .gitlab-ci.yml | 6 ++- bin/tools/dnstap-read.c | 5 +- doc/dev/rdata.md | 6 +-- fuzz/dns_rdata_fromwire_text.c | 11 ++--- lib/dns/client.c | 7 +-- lib/dns/compress.c | 47 ------------------- lib/dns/include/dns/compress.h | 70 +++++++++------------------- lib/dns/include/dns/name.h | 5 +- lib/dns/include/dns/rdata.h | 2 +- lib/dns/include/dns/types.h | 2 +- lib/dns/journal.c | 7 ++- lib/dns/master.c | 6 +-- lib/dns/message.c | 19 ++++---- lib/dns/name.c | 8 ++-- lib/dns/nsec3.c | 7 +-- lib/dns/rdata.c | 15 ++---- lib/dns/rdata/any_255/tsig_250.c | 2 +- lib/dns/rdata/ch_3/a_1.c | 2 +- lib/dns/rdata/generic/afsdb_18.c | 2 +- lib/dns/rdata/generic/amtrelay_260.c | 2 +- lib/dns/rdata/generic/cname_5.c | 2 +- lib/dns/rdata/generic/dname_39.c | 2 +- lib/dns/rdata/generic/hip_55.c | 2 +- lib/dns/rdata/generic/ipseckey_45.c | 2 +- lib/dns/rdata/generic/lp_107.c | 2 +- lib/dns/rdata/generic/mb_7.c | 2 +- lib/dns/rdata/generic/md_3.c | 2 +- lib/dns/rdata/generic/mf_4.c | 2 +- lib/dns/rdata/generic/mg_8.c | 2 +- lib/dns/rdata/generic/minfo_14.c | 2 +- lib/dns/rdata/generic/mr_9.c | 2 +- lib/dns/rdata/generic/mx_15.c | 2 +- lib/dns/rdata/generic/naptr_35.c | 2 +- lib/dns/rdata/generic/ns_2.c | 2 +- lib/dns/rdata/generic/nsec_47.c | 2 +- lib/dns/rdata/generic/nxt_30.c | 2 +- lib/dns/rdata/generic/proforma.c | 2 +- lib/dns/rdata/generic/ptr_12.c | 2 +- lib/dns/rdata/generic/rp_17.c | 2 +- lib/dns/rdata/generic/rrsig_46.c | 2 +- lib/dns/rdata/generic/rt_21.c | 2 +- lib/dns/rdata/generic/sig_24.c | 2 +- lib/dns/rdata/generic/soa_6.c | 2 +- lib/dns/rdata/generic/talink_58.c | 2 +- lib/dns/rdata/generic/tkey_249.c | 2 +- lib/dns/rdata/in_1/a6_38.c | 2 +- lib/dns/rdata/in_1/apl_42.c | 3 +- lib/dns/rdata/in_1/kx_36.c | 2 +- lib/dns/rdata/in_1/nsap-ptr_23.c | 2 +- lib/dns/rdata/in_1/px_26.c | 2 +- lib/dns/rdata/in_1/srv_33.c | 2 +- lib/dns/rdata/in_1/svcb_64.c | 2 +- tests/dns/name_test.c | 23 ++++----- tests/dns/rdata_test.c | 7 +-- 54 files changed, 115 insertions(+), 211 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b6d7ad9d43..db8f85bb1e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1415,8 +1415,10 @@ gcov: # Help gcovr process the nasty tricks in lib/dns/code.h, where we include C # source files from lib/dns/rdata/*/, using an even nastier trick. - find lib/dns/rdata/* -name "*.c" -execdir cp -f "{}" ../../ \; - # Help gcovr process inline function in the isc/hash.h - - cp -f lib/isc/include/isc/hash.h lib/dns/hash.h + # Help gcovr process inline functions in headers + - cp -f lib/isc/include/isc/*.h lib/dns/ + - cp -f lib/dns/include/dns/*.h lib/dns/ + - cp -f lib/dns/include/dns/*.h lib/ns/ # Generate XML file in the Cobertura XML format suitable for use by GitLab # for the purpose of displaying code coverage information in the diff view # of a given merge request. diff --git a/bin/tools/dnstap-read.c b/bin/tools/dnstap-read.c index fe215715e4..78b95a76fb 100644 --- a/bin/tools/dnstap-read.c +++ b/bin/tools/dnstap-read.c @@ -291,15 +291,14 @@ print_yaml(dns_dtdata_t *dt) { dns_fixedname_t fn; dns_name_t *name; isc_buffer_t b; - dns_decompress_t dctx; name = dns_fixedname_initname(&fn); isc_buffer_init(&b, m->query_zone.data, m->query_zone.len); isc_buffer_add(&b, m->query_zone.len); - dns_decompress_init(&dctx, DNS_DECOMPRESS_NONE); - result = dns_name_fromwire(name, &b, &dctx, 0, NULL); + result = dns_name_fromwire(name, &b, DNS_DECOMPRESS_NEVER, 0, + NULL); if (result == ISC_R_SUCCESS) { printf(" query_zone: "); dns_name_print(name, stdout); diff --git a/doc/dev/rdata.md b/doc/dev/rdata.md index 7c67650179..f68b0b2ffe 100644 --- a/doc/dev/rdata.md +++ b/doc/dev/rdata.md @@ -196,7 +196,7 @@ security area and must be paranoid about its input. fromwire_typename(dns_rdataclass_t class, dns_rdatatype_t type, isc_buffer_t *source, - dns_decompress_t *dctx, + dns_decompress_t dctx, bool downcase, isc_buffer_t *target); @@ -204,14 +204,14 @@ security area and must be paranoid about its input. fromwire_classname_typename(dns_rdataclass_t class, dns_rdatatype_t type, isc_buffer_t *source, - dns_decompress_t *dctx, + dns_decompress_t dctx, bool downcase, isc_buffer_t *target); `fromwire_classname_typename()` is required to set whether name compression is allowed, according to RFC 3597. - dns_decompress_setpermitted(dctx, true); /* or false */ + dctx = dns_decompress_setpermitted(dctx, true); /* or false */ |Parameter|Description | |---------|-----------------------| diff --git a/fuzz/dns_rdata_fromwire_text.c b/fuzz/dns_rdata_fromwire_text.c index 3f71538b5f..5a970e3dfa 100644 --- a/fuzz/dns_rdata_fromwire_text.c +++ b/fuzz/dns_rdata_fromwire_text.c @@ -78,7 +78,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { char totext[64 * 1044 * 4]; dns_compress_t cctx; - dns_decompress_t dctx; dns_rdatatype_t rdtype; dns_rdataclass_t rdclass; dns_rdatatype_t typelist[256] = { 1000 }; /* unknown */ @@ -135,9 +134,6 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { dns_rdatacallbacks_init(&callbacks); callbacks.warn = callbacks.error = nullmsg; - /* Disallow decompression as we are reading a packet */ - dns_decompress_init(&dctx, DNS_DECOMPRESS_NONE); - isc_buffer_constinit(&source, data, size); isc_buffer_add(&source, size); isc_buffer_setactive(&source, size); @@ -145,10 +141,11 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { isc_buffer_init(&target, fromwire, sizeof(fromwire)); /* - * Reject invalid rdata. + * Reject invalid rdata. (Disallow decompression as we are + * reading a packet) */ - CHECK(dns_rdata_fromwire(&rdata1, rdclass, rdtype, &source, &dctx, 0, - &target)); + CHECK(dns_rdata_fromwire(&rdata1, rdclass, rdtype, &source, + DNS_DECOMPRESS_NEVER, 0, &target)); assert(rdata1.length == size); /* diff --git a/lib/dns/client.c b/lib/dns/client.c index cbe70337cc..a5bbaebe97 100644 --- a/lib/dns/client.c +++ b/lib/dns/client.c @@ -1263,7 +1263,6 @@ dns_client_addtrustedkey(dns_client_t *client, dns_rdataclass_t rdclass, char rdatabuf[DST_KEY_MAXSIZE]; unsigned char digest[ISC_MAX_MD_SIZE]; dns_rdata_ds_t ds; - dns_decompress_t dctx; dns_rdata_t rdata; isc_buffer_t b; @@ -1285,12 +1284,10 @@ dns_client_addtrustedkey(dns_client_t *client, dns_rdataclass_t rdclass, } isc_buffer_init(&b, rdatabuf, sizeof(rdatabuf)); - dns_decompress_init(&dctx, DNS_DECOMPRESS_NONE); dns_rdata_init(&rdata); isc_buffer_setactive(databuf, isc_buffer_usedlength(databuf)); - CHECK(dns_rdata_fromwire(&rdata, rdclass, rdtype, databuf, &dctx, 0, - &b)); - dns_decompress_invalidate(&dctx); + CHECK(dns_rdata_fromwire(&rdata, rdclass, rdtype, databuf, + DNS_DECOMPRESS_NEVER, 0, &b)); if (rdtype == dns_rdatatype_ds) { CHECK(dns_rdata_tostruct(&rdata, &ds, NULL)); diff --git a/lib/dns/compress.c b/lib/dns/compress.c index 8e49f9bbce..f195e98b06 100644 --- a/lib/dns/compress.c +++ b/lib/dns/compress.c @@ -30,9 +30,6 @@ #define CCTX_MAGIC ISC_MAGIC('C', 'C', 'T', 'X') #define VALID_CCTX(x) ISC_MAGIC_VALID(x, CCTX_MAGIC) -#define DCTX_MAGIC ISC_MAGIC('D', 'C', 'T', 'X') -#define VALID_DCTX(x) ISC_MAGIC_VALID(x, DCTX_MAGIC) - static unsigned char maptolower[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, @@ -506,47 +503,3 @@ dns_compress_rollback(dns_compress_t *cctx, uint16_t offset) { } } } - -/*** - *** Decompression - ***/ - -void -dns_decompress_init(dns_decompress_t *dctx, dns_decompresstype_t type) { - REQUIRE(dctx != NULL); - - *dctx = (dns_decompress_t){ - .magic = DCTX_MAGIC, - .type = type, - }; -} - -void -dns_decompress_invalidate(dns_decompress_t *dctx) { - REQUIRE(VALID_DCTX(dctx)); - dctx->magic = 0; -} - -void -dns_decompress_setpermitted(dns_decompress_t *dctx, bool permitted) { - REQUIRE(VALID_DCTX(dctx)); - - switch (dctx->type) { - case DNS_DECOMPRESS_ANY: - dctx->permitted = true; - break; - case DNS_DECOMPRESS_NONE: - dctx->permitted = false; - break; - case DNS_DECOMPRESS_STRICT: - dctx->permitted = permitted; - break; - } -} - -bool -dns_decompress_getpermitted(dns_decompress_t *dctx) { - REQUIRE(VALID_DCTX(dctx)); - - return (dctx->permitted); -} diff --git a/lib/dns/include/dns/compress.h b/lib/dns/include/dns/compress.h index f3c6a7e12d..151a860fbe 100644 --- a/lib/dns/include/dns/compress.h +++ b/lib/dns/include/dns/compress.h @@ -72,16 +72,11 @@ struct dns_compress { isc_mem_t *mctx; /*%< Memory context. */ }; -typedef enum { - DNS_DECOMPRESS_ANY, /*%< Any compression */ - DNS_DECOMPRESS_STRICT, /*%< Allowed compression */ - DNS_DECOMPRESS_NONE /*%< No compression */ -} dns_decompresstype_t; - -struct dns_decompress { - unsigned int magic; /*%< Magic number. */ - dns_decompresstype_t type; /*%< Strict checking */ - bool permitted; +enum dns_decompress { + DNS_DECOMPRESS_DEFAULT, + DNS_DECOMPRESS_PERMITTED, + DNS_DECOMPRESS_NEVER, + DNS_DECOMPRESS_ALWAYS, }; isc_result_t @@ -204,7 +199,6 @@ dns_compress_add(dns_compress_t *cctx, const dns_name_t *name, void dns_compress_rollback(dns_compress_t *cctx, uint16_t offset); - /*%< * Remove any compression pointers from global table >= offset. * @@ -212,45 +206,27 @@ dns_compress_rollback(dns_compress_t *cctx, uint16_t offset); *\li 'cctx' is initialized. */ -void -dns_decompress_init(dns_decompress_t *dctx, dns_decompresstype_t type); - -/*%< - * Initializes 'dctx'. - * Records 'edns' and 'type' into the structure. - * - * Requires: - *\li 'dctx' to be a valid pointer. +/*% + * Set whether decompression is allowed, according to RFC 3597 */ +static inline dns_decompress_t /* inline to suppress code generation */ +dns_decompress_setpermitted(dns_decompress_t dctx, bool permitted) { + if (dctx == DNS_DECOMPRESS_NEVER || dctx == DNS_DECOMPRESS_ALWAYS) { + return (dctx); + } else if (permitted) { + return (DNS_DECOMPRESS_PERMITTED); + } else { + return (DNS_DECOMPRESS_DEFAULT); + } +} -void -dns_decompress_invalidate(dns_decompress_t *dctx); - -/*%< - * Invalidates 'dctx'. - * - * Requires: - *\li 'dctx' to be initialized - */ - -void -dns_decompress_setpermitted(dns_decompress_t *dctx, bool permitted); - -/*%< - * Sets whether decompression is allowed, according to RFC 3597 - * - * Requires: - *\li 'dctx' to be initialized - */ - -bool -dns_decompress_getpermitted(dns_decompress_t *dctx); - -/*%< +/*% * Returns whether decompression is allowed here - * - * Requires: - *\li 'dctx' to be initialized */ +static inline bool /* inline to suppress code generation */ +dns_decompress_getpermitted(dns_decompress_t dctx) { + return (dctx == DNS_DECOMPRESS_ALWAYS || + dctx == DNS_DECOMPRESS_PERMITTED); +} ISC_LANG_ENDDECLS diff --git a/lib/dns/include/dns/name.h b/lib/dns/include/dns/name.h index 8063799490..e294b9068b 100644 --- a/lib/dns/include/dns/name.h +++ b/lib/dns/include/dns/name.h @@ -691,9 +691,8 @@ dns_name_toregion(const dns_name_t *name, isc_region_t *r); */ isc_result_t -dns_name_fromwire(dns_name_t *name, isc_buffer_t *source, - dns_decompress_t *dctx, unsigned int options, - isc_buffer_t *target); +dns_name_fromwire(dns_name_t *name, isc_buffer_t *source, dns_decompress_t dctx, + unsigned int options, isc_buffer_t *target); /*%< * Copy the possibly-compressed name at source (active region) into target, * decompressing it. diff --git a/lib/dns/include/dns/rdata.h b/lib/dns/include/dns/rdata.h index 03298c7c71..029685a6ef 100644 --- a/lib/dns/include/dns/rdata.h +++ b/lib/dns/include/dns/rdata.h @@ -281,7 +281,7 @@ dns_rdata_toregion(const dns_rdata_t *rdata, isc_region_t *r); isc_result_t dns_rdata_fromwire(dns_rdata_t *rdata, dns_rdataclass_t rdclass, dns_rdatatype_t type, isc_buffer_t *source, - dns_decompress_t *dctx, unsigned int options, + dns_decompress_t dctx, unsigned int options, isc_buffer_t *target); /*%< * Copy the possibly-compressed rdata at source into the target region. diff --git a/lib/dns/include/dns/types.h b/lib/dns/include/dns/types.h index eece8448d3..4d69639f13 100644 --- a/lib/dns/include/dns/types.h +++ b/lib/dns/include/dns/types.h @@ -65,7 +65,7 @@ typedef struct dns_dlzdb dns_dlzdb_t; typedef ISC_LIST(dns_dlzdb_t) dns_dlzdblist_t; typedef struct dns_dyndbctx dns_dyndbctx_t; typedef struct dns_sdlzimplementation dns_sdlzimplementation_t; -typedef struct dns_decompress dns_decompress_t; +typedef enum dns_decompress dns_decompress_t; typedef struct dns_dispatch dns_dispatch_t; typedef struct dns_dispatchlist dns_dispatchlist_t; typedef struct dns_dispatchset dns_dispatchset_t; diff --git a/lib/dns/journal.c b/lib/dns/journal.c index 9732682d03..664ef23269 100644 --- a/lib/dns/journal.c +++ b/lib/dns/journal.c @@ -738,7 +738,7 @@ journal_open(isc_mem_t *mctx, const char *filename, bool writable, bool create, */ isc_buffer_init(&j->it.source, NULL, 0); isc_buffer_init(&j->it.target, NULL, 0); - dns_decompress_init(&j->it.dctx, DNS_DECOMPRESS_NONE); + j->it.dctx = DNS_DECOMPRESS_NEVER; j->state = writable ? JOURNAL_STATE_WRITE : JOURNAL_STATE_READ; @@ -1438,7 +1438,6 @@ dns_journal_destroy(dns_journal_t **journalp) { j->it.result = ISC_R_FAILURE; dns_name_invalidate(&j->it.name); - dns_decompress_invalidate(&j->it.dctx); if (j->rawindex != NULL) { isc_mem_put(j->mctx, j->rawindex, j->header.index_size * sizeof(journal_rawpos_t)); @@ -2029,7 +2028,7 @@ read_one_rr(dns_journal_t *j) { */ isc_buffer_setactive(&j->it.source, j->it.source.used - j->it.source.current); - CHECK(dns_name_fromwire(&j->it.name, &j->it.source, &j->it.dctx, 0, + CHECK(dns_name_fromwire(&j->it.name, &j->it.source, j->it.dctx, 0, &j->it.target)); /* @@ -2061,7 +2060,7 @@ read_one_rr(dns_journal_t *j) { isc_buffer_setactive(&j->it.source, rdlen); dns_rdata_reset(&j->it.rdata); CHECK(dns_rdata_fromwire(&j->it.rdata, rdclass, rdtype, &j->it.source, - &j->it.dctx, 0, &j->it.target)); + j->it.dctx, 0, &j->it.target)); j->it.ttl = ttl; j->it.xpos += sizeof(journal_rawrrhdr_t) + rrhdr.size; diff --git a/lib/dns/master.c b/lib/dns/master.c index ccedc1af84..598bde02de 100644 --- a/lib/dns/master.c +++ b/lib/dns/master.c @@ -2342,7 +2342,7 @@ load_raw(dns_loadctx_t *lctx) { dns_decompress_t dctx; callbacks = lctx->callbacks; - dns_decompress_init(&dctx, DNS_DECOMPRESS_NONE); + dctx = DNS_DECOMPRESS_NEVER; if (lctx->first) { result = load_header(lctx); @@ -2475,7 +2475,7 @@ load_raw(dns_loadctx_t *lctx) { } isc_buffer_setactive(&target, (unsigned int)namelen); - result = dns_name_fromwire(name, &target, &dctx, 0, NULL); + result = dns_name_fromwire(name, &target, dctx, 0, NULL); if (result != ISC_R_SUCCESS) { goto cleanup; } @@ -2564,7 +2564,7 @@ load_raw(dns_loadctx_t *lctx) { (unsigned int)rdlen); result = dns_rdata_fromwire( &rdata[i], rdatalist.rdclass, rdatalist.type, - &target, &dctx, 0, &buf); + &target, dctx, 0, &buf); if (result != ISC_R_SUCCESS) { goto cleanup; } diff --git a/lib/dns/message.c b/lib/dns/message.c index e567202eb9..da101eeadc 100644 --- a/lib/dns/message.c +++ b/lib/dns/message.c @@ -862,7 +862,7 @@ dns_message_findtype(const dns_name_t *name, dns_rdatatype_t type, */ static isc_result_t getname(dns_name_t *name, isc_buffer_t *source, dns_message_t *msg, - dns_decompress_t *dctx) { + dns_decompress_t dctx) { isc_buffer_t *scratch; isc_result_t result; unsigned int tries; @@ -896,7 +896,7 @@ getname(dns_name_t *name, isc_buffer_t *source, dns_message_t *msg, } static isc_result_t -getrdata(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx, +getrdata(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t dctx, dns_rdataclass_t rdclass, dns_rdatatype_t rdtype, unsigned int rdatalen, dns_rdata_t *rdata) { isc_buffer_t *scratch; @@ -960,7 +960,7 @@ getrdata(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx, } while (0) static isc_result_t -getquestions(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx, +getquestions(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t dctx, unsigned int options) { isc_region_t r; unsigned int count; @@ -1175,7 +1175,7 @@ auth_signed(dns_namelist_t *section) { } static isc_result_t -getsection(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx, +getsection(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t dctx, dns_section_t sectionid, unsigned int options) { isc_region_t r; unsigned int count, rdatalen; @@ -1681,10 +1681,9 @@ dns_message_parse(dns_message_t *msg, isc_buffer_t *source, msg->header_ok = 1; msg->state = DNS_SECTION_QUESTION; - dns_decompress_init(&dctx, DNS_DECOMPRESS_ANY); - dns_decompress_setpermitted(&dctx, true); + dctx = DNS_DECOMPRESS_ALWAYS; - ret = getquestions(source, msg, &dctx, options); + ret = getquestions(source, msg, dctx, options); if (ret == ISC_R_UNEXPECTEDEND && ignore_tc) { goto truncated; } @@ -1697,7 +1696,7 @@ dns_message_parse(dns_message_t *msg, isc_buffer_t *source, } msg->question_ok = 1; - ret = getsection(source, msg, &dctx, DNS_SECTION_ANSWER, options); + ret = getsection(source, msg, dctx, DNS_SECTION_ANSWER, options); if (ret == ISC_R_UNEXPECTEDEND && ignore_tc) { goto truncated; } @@ -1709,7 +1708,7 @@ dns_message_parse(dns_message_t *msg, isc_buffer_t *source, return (ret); } - ret = getsection(source, msg, &dctx, DNS_SECTION_AUTHORITY, options); + ret = getsection(source, msg, dctx, DNS_SECTION_AUTHORITY, options); if (ret == ISC_R_UNEXPECTEDEND && ignore_tc) { goto truncated; } @@ -1721,7 +1720,7 @@ dns_message_parse(dns_message_t *msg, isc_buffer_t *source, return (ret); } - ret = getsection(source, msg, &dctx, DNS_SECTION_ADDITIONAL, options); + ret = getsection(source, msg, dctx, DNS_SECTION_ADDITIONAL, options); if (ret == ISC_R_UNEXPECTEDEND && ignore_tc) { goto truncated; } diff --git a/lib/dns/name.c b/lib/dns/name.c index 76dd6b4470..26114fde30 100644 --- a/lib/dns/name.c +++ b/lib/dns/name.c @@ -1737,9 +1737,8 @@ set_offsets(const dns_name_t *name, unsigned char *offsets, } isc_result_t -dns_name_fromwire(dns_name_t *name, isc_buffer_t *source, - dns_decompress_t *dctx, unsigned int options, - isc_buffer_t *target) { +dns_name_fromwire(dns_name_t *name, isc_buffer_t *source, dns_decompress_t dctx, + unsigned int options, isc_buffer_t *target) { unsigned char *cdata, *ndata; unsigned int cused; /* Bytes of compressed name data used */ unsigned int nused, labels, n, nmax; @@ -1769,7 +1768,6 @@ dns_name_fromwire(dns_name_t *name, isc_buffer_t *source, isc_buffer_clear(target); } - REQUIRE(dctx != NULL); REQUIRE(BINDABLE(name)); INIT_OFFSETS(name, offsets, odata); @@ -1843,7 +1841,7 @@ dns_name_fromwire(dns_name_t *name, isc_buffer_t *source, /* * 14-bit compression pointer */ - if (!dctx->permitted) { + if (!dns_decompress_getpermitted(dctx)) { return (DNS_R_DISALLOWED); } new_current = c & 0x3F; diff --git a/lib/dns/nsec3.c b/lib/dns/nsec3.c index 5644f1e9e7..fca6459343 100644 --- a/lib/dns/nsec3.c +++ b/lib/dns/nsec3.c @@ -971,7 +971,6 @@ failure: bool dns_nsec3param_fromprivate(dns_rdata_t *src, dns_rdata_t *target, unsigned char *buf, size_t buflen) { - dns_decompress_t dctx; isc_result_t result; isc_buffer_t buf1; isc_buffer_t buf2; @@ -988,11 +987,9 @@ dns_nsec3param_fromprivate(dns_rdata_t *src, dns_rdata_t *target, isc_buffer_add(&buf1, src->length - 1); isc_buffer_setactive(&buf1, src->length - 1); isc_buffer_init(&buf2, buf, (unsigned int)buflen); - dns_decompress_init(&dctx, DNS_DECOMPRESS_NONE); result = dns_rdata_fromwire(target, src->rdclass, - dns_rdatatype_nsec3param, &buf1, &dctx, 0, - &buf2); - dns_decompress_invalidate(&dctx); + dns_rdatatype_nsec3param, &buf1, + DNS_DECOMPRESS_NEVER, 0, &buf2); return (result == ISC_R_SUCCESS); } diff --git a/lib/dns/rdata.c b/lib/dns/rdata.c index 44e3030723..23c863edbb 100644 --- a/lib/dns/rdata.c +++ b/lib/dns/rdata.c @@ -97,7 +97,7 @@ #define ARGS_FROMWIRE \ int rdclass, dns_rdatatype_t type, isc_buffer_t *source, \ - dns_decompress_t *dctx, unsigned int options, \ + dns_decompress_t dctx, unsigned int options, \ isc_buffer_t *target #define CALL_FROMWIRE rdclass, type, source, dctx, options, target @@ -611,11 +611,9 @@ check_private(isc_buffer_t *source, dns_secalg_t alg) { isc_region_t sr; if (alg == DNS_KEYALG_PRIVATEDNS) { dns_fixedname_t fixed; - dns_decompress_t dctx; - dns_decompress_init(&dctx, DNS_DECOMPRESS_STRICT); RETERR(dns_name_fromwire(dns_fixedname_initname(&fixed), source, - &dctx, 0, NULL)); + DNS_DECOMPRESS_DEFAULT, 0, NULL)); /* * There should be a public key or signature after the key name. */ @@ -806,7 +804,7 @@ dns_rdata_toregion(const dns_rdata_t *rdata, isc_region_t *r) { isc_result_t dns_rdata_fromwire(dns_rdata_t *rdata, dns_rdataclass_t rdclass, dns_rdatatype_t type, isc_buffer_t *source, - dns_decompress_t *dctx, unsigned int options, + dns_decompress_t dctx, unsigned int options, isc_buffer_t *target) { isc_result_t result = ISC_R_NOTIMPLEMENTED; isc_region_t region; @@ -816,7 +814,6 @@ dns_rdata_fromwire(dns_rdata_t *rdata, dns_rdataclass_t rdclass, uint32_t activelength; unsigned int length; - REQUIRE(dctx != NULL); if (rdata != NULL) { REQUIRE(DNS_RDATA_INITIALIZED(rdata)); REQUIRE(DNS_RDATA_VALIDFLAGS(rdata)); @@ -924,13 +921,11 @@ dns_rdata_towire(dns_rdata_t *rdata, dns_compress_t *cctx, static isc_result_t rdata_validate(isc_buffer_t *src, isc_buffer_t *dest, dns_rdataclass_t rdclass, dns_rdatatype_t type) { - dns_decompress_t dctx; isc_result_t result; - dns_decompress_init(&dctx, DNS_DECOMPRESS_NONE); isc_buffer_setactive(src, isc_buffer_usedlength(src)); - result = dns_rdata_fromwire(NULL, rdclass, type, src, &dctx, 0, dest); - dns_decompress_invalidate(&dctx); + result = dns_rdata_fromwire(NULL, rdclass, type, src, + DNS_DECOMPRESS_NEVER, 0, dest); return (result); } diff --git a/lib/dns/rdata/any_255/tsig_250.c b/lib/dns/rdata/any_255/tsig_250.c index f6829c67c2..3dbd73349b 100644 --- a/lib/dns/rdata/any_255/tsig_250.c +++ b/lib/dns/rdata/any_255/tsig_250.c @@ -263,7 +263,7 @@ fromwire_any_tsig(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, false); + dctx = dns_decompress_setpermitted(dctx, false); /* * Algorithm Name. diff --git a/lib/dns/rdata/ch_3/a_1.c b/lib/dns/rdata/ch_3/a_1.c index b5514c1659..09051af0cc 100644 --- a/lib/dns/rdata/ch_3/a_1.c +++ b/lib/dns/rdata/ch_3/a_1.c @@ -105,7 +105,7 @@ fromwire_ch_a(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, true); + dctx = dns_decompress_setpermitted(dctx, true); dns_name_init(&name, NULL); diff --git a/lib/dns/rdata/generic/afsdb_18.c b/lib/dns/rdata/generic/afsdb_18.c index 63b3149cd6..3b24048479 100644 --- a/lib/dns/rdata/generic/afsdb_18.c +++ b/lib/dns/rdata/generic/afsdb_18.c @@ -101,7 +101,7 @@ fromwire_afsdb(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, false); + dctx = dns_decompress_setpermitted(dctx, false); dns_name_init(&name, NULL); diff --git a/lib/dns/rdata/generic/amtrelay_260.c b/lib/dns/rdata/generic/amtrelay_260.c index 13b707cf82..616c6ff2a6 100644 --- a/lib/dns/rdata/generic/amtrelay_260.c +++ b/lib/dns/rdata/generic/amtrelay_260.c @@ -192,7 +192,7 @@ fromwire_amtrelay(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, false); + dctx = dns_decompress_setpermitted(dctx, false); isc_buffer_activeregion(source, ®ion); if (region.length < 2) { diff --git a/lib/dns/rdata/generic/cname_5.c b/lib/dns/rdata/generic/cname_5.c index 61b2e9f278..3cc6918c52 100644 --- a/lib/dns/rdata/generic/cname_5.c +++ b/lib/dns/rdata/generic/cname_5.c @@ -71,7 +71,7 @@ fromwire_cname(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, true); + dctx = dns_decompress_setpermitted(dctx, true); dns_name_init(&name, NULL); return (dns_name_fromwire(&name, source, dctx, options, target)); diff --git a/lib/dns/rdata/generic/dname_39.c b/lib/dns/rdata/generic/dname_39.c index cd7a0d8f75..b061ccb13a 100644 --- a/lib/dns/rdata/generic/dname_39.c +++ b/lib/dns/rdata/generic/dname_39.c @@ -72,7 +72,7 @@ fromwire_dname(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, false); + dctx = dns_decompress_setpermitted(dctx, false); dns_name_init(&name, NULL); return (dns_name_fromwire(&name, source, dctx, options, target)); diff --git a/lib/dns/rdata/generic/hip_55.c b/lib/dns/rdata/generic/hip_55.c index 34d7940faa..041f561d3e 100644 --- a/lib/dns/rdata/generic/hip_55.c +++ b/lib/dns/rdata/generic/hip_55.c @@ -226,7 +226,7 @@ fromwire_hip(ARGS_FROMWIRE) { RETERR(mem_tobuffer(target, rr.base, 4 + len)); isc_buffer_forward(source, 4 + len); - dns_decompress_setpermitted(dctx, false); + dctx = dns_decompress_setpermitted(dctx, false); while (isc_buffer_activelength(source) > 0) { dns_name_init(&name, NULL); RETERR(dns_name_fromwire(&name, source, dctx, options, target)); diff --git a/lib/dns/rdata/generic/ipseckey_45.c b/lib/dns/rdata/generic/ipseckey_45.c index 5122ebe1d2..c69280d79f 100644 --- a/lib/dns/rdata/generic/ipseckey_45.c +++ b/lib/dns/rdata/generic/ipseckey_45.c @@ -221,7 +221,7 @@ fromwire_ipseckey(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, false); + dctx = dns_decompress_setpermitted(dctx, false); dns_name_init(&name, NULL); diff --git a/lib/dns/rdata/generic/lp_107.c b/lib/dns/rdata/generic/lp_107.c index 91658938ce..d02e4aa00d 100644 --- a/lib/dns/rdata/generic/lp_107.c +++ b/lib/dns/rdata/generic/lp_107.c @@ -88,7 +88,7 @@ fromwire_lp(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, true); + dctx = dns_decompress_setpermitted(dctx, true); dns_name_init(&name, NULL); diff --git a/lib/dns/rdata/generic/mb_7.c b/lib/dns/rdata/generic/mb_7.c index 4d417ded87..64e3ed3236 100644 --- a/lib/dns/rdata/generic/mb_7.c +++ b/lib/dns/rdata/generic/mb_7.c @@ -70,7 +70,7 @@ fromwire_mb(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, true); + dctx = dns_decompress_setpermitted(dctx, true); dns_name_init(&name, NULL); return (dns_name_fromwire(&name, source, dctx, options, target)); diff --git a/lib/dns/rdata/generic/md_3.c b/lib/dns/rdata/generic/md_3.c index 7711eac084..e817ac0338 100644 --- a/lib/dns/rdata/generic/md_3.c +++ b/lib/dns/rdata/generic/md_3.c @@ -70,7 +70,7 @@ fromwire_md(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, true); + dctx = dns_decompress_setpermitted(dctx, true); dns_name_init(&name, NULL); return (dns_name_fromwire(&name, source, dctx, options, target)); diff --git a/lib/dns/rdata/generic/mf_4.c b/lib/dns/rdata/generic/mf_4.c index 5130e5006a..e28878f334 100644 --- a/lib/dns/rdata/generic/mf_4.c +++ b/lib/dns/rdata/generic/mf_4.c @@ -70,7 +70,7 @@ fromwire_mf(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, true); + dctx = dns_decompress_setpermitted(dctx, true); dns_name_init(&name, NULL); return (dns_name_fromwire(&name, source, dctx, options, target)); diff --git a/lib/dns/rdata/generic/mg_8.c b/lib/dns/rdata/generic/mg_8.c index 7285c5cb36..60c85c3ba8 100644 --- a/lib/dns/rdata/generic/mg_8.c +++ b/lib/dns/rdata/generic/mg_8.c @@ -70,7 +70,7 @@ fromwire_mg(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, true); + dctx = dns_decompress_setpermitted(dctx, true); dns_name_init(&name, NULL); return (dns_name_fromwire(&name, source, dctx, options, target)); diff --git a/lib/dns/rdata/generic/minfo_14.c b/lib/dns/rdata/generic/minfo_14.c index 03200ba9d9..3ccf77a099 100644 --- a/lib/dns/rdata/generic/minfo_14.c +++ b/lib/dns/rdata/generic/minfo_14.c @@ -98,7 +98,7 @@ fromwire_minfo(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, true); + dctx = dns_decompress_setpermitted(dctx, true); dns_name_init(&rmail, NULL); dns_name_init(&email, NULL); diff --git a/lib/dns/rdata/generic/mr_9.c b/lib/dns/rdata/generic/mr_9.c index 60f59cacf6..5fc77963d4 100644 --- a/lib/dns/rdata/generic/mr_9.c +++ b/lib/dns/rdata/generic/mr_9.c @@ -70,7 +70,7 @@ fromwire_mr(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, true); + dctx = dns_decompress_setpermitted(dctx, true); dns_name_init(&name, NULL); return (dns_name_fromwire(&name, source, dctx, options, target)); diff --git a/lib/dns/rdata/generic/mx_15.c b/lib/dns/rdata/generic/mx_15.c index 4614c95ac5..a914540ccc 100644 --- a/lib/dns/rdata/generic/mx_15.c +++ b/lib/dns/rdata/generic/mx_15.c @@ -134,7 +134,7 @@ fromwire_mx(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, true); + dctx = dns_decompress_setpermitted(dctx, true); dns_name_init(&name, NULL); diff --git a/lib/dns/rdata/generic/naptr_35.c b/lib/dns/rdata/generic/naptr_35.c index afa1a5d4b8..5babd31b93 100644 --- a/lib/dns/rdata/generic/naptr_35.c +++ b/lib/dns/rdata/generic/naptr_35.c @@ -311,7 +311,7 @@ fromwire_naptr(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, false); + dctx = dns_decompress_setpermitted(dctx, false); dns_name_init(&name, NULL); diff --git a/lib/dns/rdata/generic/ns_2.c b/lib/dns/rdata/generic/ns_2.c index ce9f44a112..32b5430656 100644 --- a/lib/dns/rdata/generic/ns_2.c +++ b/lib/dns/rdata/generic/ns_2.c @@ -81,7 +81,7 @@ fromwire_ns(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, true); + dctx = dns_decompress_setpermitted(dctx, true); dns_name_init(&name, NULL); return (dns_name_fromwire(&name, source, dctx, options, target)); diff --git a/lib/dns/rdata/generic/nsec_47.c b/lib/dns/rdata/generic/nsec_47.c index 571a0ce37b..e36ff65552 100644 --- a/lib/dns/rdata/generic/nsec_47.c +++ b/lib/dns/rdata/generic/nsec_47.c @@ -85,7 +85,7 @@ fromwire_nsec(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, false); + dctx = dns_decompress_setpermitted(dctx, false); dns_name_init(&name, NULL); RETERR(dns_name_fromwire(&name, source, dctx, options, target)); diff --git a/lib/dns/rdata/generic/nxt_30.c b/lib/dns/rdata/generic/nxt_30.c index 5dce8a03fc..7d62c56a74 100644 --- a/lib/dns/rdata/generic/nxt_30.c +++ b/lib/dns/rdata/generic/nxt_30.c @@ -144,7 +144,7 @@ fromwire_nxt(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, false); + dctx = dns_decompress_setpermitted(dctx, false); dns_name_init(&name, NULL); RETERR(dns_name_fromwire(&name, source, dctx, options, target)); diff --git a/lib/dns/rdata/generic/proforma.c b/lib/dns/rdata/generic/proforma.c index 2c286227b0..fa7982fb7a 100644 --- a/lib/dns/rdata/generic/proforma.c +++ b/lib/dns/rdata/generic/proforma.c @@ -41,7 +41,7 @@ static isc_result_t fromwire_ #(ARGS_FROMWIRE) { REQUIRE(rdclass == #); /* see RFC 3597 */ - dns_decompress_setpermitted(dctx, false); + dctx = dns_decompress_setpermitted(dctx, false); return (ISC_R_NOTIMPLEMENTED); } diff --git a/lib/dns/rdata/generic/ptr_12.c b/lib/dns/rdata/generic/ptr_12.c index f584b7a80e..8acffe797e 100644 --- a/lib/dns/rdata/generic/ptr_12.c +++ b/lib/dns/rdata/generic/ptr_12.c @@ -83,7 +83,7 @@ fromwire_ptr(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, true); + dctx = dns_decompress_setpermitted(dctx, true); dns_name_init(&name, NULL); return (dns_name_fromwire(&name, source, dctx, options, target)); diff --git a/lib/dns/rdata/generic/rp_17.c b/lib/dns/rdata/generic/rp_17.c index 6e1800d7cd..dfba5feca9 100644 --- a/lib/dns/rdata/generic/rp_17.c +++ b/lib/dns/rdata/generic/rp_17.c @@ -99,7 +99,7 @@ fromwire_rp(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, false); + dctx = dns_decompress_setpermitted(dctx, false); dns_name_init(&rmail, NULL); dns_name_init(&email, NULL); diff --git a/lib/dns/rdata/generic/rrsig_46.c b/lib/dns/rdata/generic/rrsig_46.c index d457160b04..0aba846913 100644 --- a/lib/dns/rdata/generic/rrsig_46.c +++ b/lib/dns/rdata/generic/rrsig_46.c @@ -303,7 +303,7 @@ fromwire_rrsig(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, false); + dctx = dns_decompress_setpermitted(dctx, false); isc_buffer_activeregion(source, &sr); /* diff --git a/lib/dns/rdata/generic/rt_21.c b/lib/dns/rdata/generic/rt_21.c index f36836f3ab..a22ff600d7 100644 --- a/lib/dns/rdata/generic/rt_21.c +++ b/lib/dns/rdata/generic/rt_21.c @@ -97,7 +97,7 @@ fromwire_rt(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, false); + dctx = dns_decompress_setpermitted(dctx, false); dns_name_init(&name, NULL); diff --git a/lib/dns/rdata/generic/sig_24.c b/lib/dns/rdata/generic/sig_24.c index f6a10f7a44..1d4b6f7bc0 100644 --- a/lib/dns/rdata/generic/sig_24.c +++ b/lib/dns/rdata/generic/sig_24.c @@ -266,7 +266,7 @@ fromwire_sig(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, false); + dctx = dns_decompress_setpermitted(dctx, false); isc_buffer_activeregion(source, &sr); /* diff --git a/lib/dns/rdata/generic/soa_6.c b/lib/dns/rdata/generic/soa_6.c index 2cba492c77..e72ff5cc40 100644 --- a/lib/dns/rdata/generic/soa_6.c +++ b/lib/dns/rdata/generic/soa_6.c @@ -165,7 +165,7 @@ fromwire_soa(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, true); + dctx = dns_decompress_setpermitted(dctx, true); dns_name_init(&mname, NULL); dns_name_init(&rname, NULL); diff --git a/lib/dns/rdata/generic/talink_58.c b/lib/dns/rdata/generic/talink_58.c index b47220f0b9..710efb5a98 100644 --- a/lib/dns/rdata/generic/talink_58.c +++ b/lib/dns/rdata/generic/talink_58.c @@ -88,7 +88,7 @@ fromwire_talink(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, false); + dctx = dns_decompress_setpermitted(dctx, false); dns_name_init(&prev, NULL); dns_name_init(&next, NULL); diff --git a/lib/dns/rdata/generic/tkey_249.c b/lib/dns/rdata/generic/tkey_249.c index 34189cf082..a77054da11 100644 --- a/lib/dns/rdata/generic/tkey_249.c +++ b/lib/dns/rdata/generic/tkey_249.c @@ -253,7 +253,7 @@ fromwire_tkey(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, false); + dctx = dns_decompress_setpermitted(dctx, false); /* * Algorithm. diff --git a/lib/dns/rdata/in_1/a6_38.c b/lib/dns/rdata/in_1/a6_38.c index ea2f13fe9b..83716952aa 100644 --- a/lib/dns/rdata/in_1/a6_38.c +++ b/lib/dns/rdata/in_1/a6_38.c @@ -158,7 +158,7 @@ fromwire_in_a6(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, false); + dctx = dns_decompress_setpermitted(dctx, false); isc_buffer_activeregion(source, &sr); /* diff --git a/lib/dns/rdata/in_1/apl_42.c b/lib/dns/rdata/in_1/apl_42.c index c2862d3f1c..d7f12f962f 100644 --- a/lib/dns/rdata/in_1/apl_42.c +++ b/lib/dns/rdata/in_1/apl_42.c @@ -276,7 +276,8 @@ fromstruct_in_apl(ARGS_FROMSTRUCT) { isc_buffer_init(&b, apl->apl, apl->apl_len); isc_buffer_add(&b, apl->apl_len); isc_buffer_setactive(&b, apl->apl_len); - return (fromwire_in_apl(rdclass, type, &b, NULL, false, target)); + return (fromwire_in_apl(rdclass, type, &b, DNS_DECOMPRESS_DEFAULT, + false, target)); } static isc_result_t diff --git a/lib/dns/rdata/in_1/kx_36.c b/lib/dns/rdata/in_1/kx_36.c index 355734332d..9a271b9c70 100644 --- a/lib/dns/rdata/in_1/kx_36.c +++ b/lib/dns/rdata/in_1/kx_36.c @@ -89,7 +89,7 @@ fromwire_in_kx(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, false); + dctx = dns_decompress_setpermitted(dctx, false); dns_name_init(&name, NULL); diff --git a/lib/dns/rdata/in_1/nsap-ptr_23.c b/lib/dns/rdata/in_1/nsap-ptr_23.c index 3345aa82c9..a3cb908ca7 100644 --- a/lib/dns/rdata/in_1/nsap-ptr_23.c +++ b/lib/dns/rdata/in_1/nsap-ptr_23.c @@ -75,7 +75,7 @@ fromwire_in_nsap_ptr(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, false); + dctx = dns_decompress_setpermitted(dctx, false); dns_name_init(&name, NULL); return (dns_name_fromwire(&name, source, dctx, options, target)); diff --git a/lib/dns/rdata/in_1/px_26.c b/lib/dns/rdata/in_1/px_26.c index 1223664153..8f5af8783a 100644 --- a/lib/dns/rdata/in_1/px_26.c +++ b/lib/dns/rdata/in_1/px_26.c @@ -119,7 +119,7 @@ fromwire_in_px(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, false); + dctx = dns_decompress_setpermitted(dctx, false); dns_name_init(&name, NULL); diff --git a/lib/dns/rdata/in_1/srv_33.c b/lib/dns/rdata/in_1/srv_33.c index df10c819d8..da07c95986 100644 --- a/lib/dns/rdata/in_1/srv_33.c +++ b/lib/dns/rdata/in_1/srv_33.c @@ -149,7 +149,7 @@ fromwire_in_srv(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, false); + dctx = dns_decompress_setpermitted(dctx, false); dns_name_init(&name, NULL); diff --git a/lib/dns/rdata/in_1/svcb_64.c b/lib/dns/rdata/in_1/svcb_64.c index 00fdf24b25..ed9d2d6537 100644 --- a/lib/dns/rdata/in_1/svcb_64.c +++ b/lib/dns/rdata/in_1/svcb_64.c @@ -756,7 +756,7 @@ generic_fromwire_in_svcb(ARGS_FROMWIRE) { UNUSED(type); UNUSED(rdclass); - dns_decompress_setpermitted(dctx, false); + dctx = dns_decompress_setpermitted(dctx, false); dns_name_init(&name, NULL); diff --git a/tests/dns/name_test.c b/tests/dns/name_test.c index 4bb4655914..2eeaa4bf69 100644 --- a/tests/dns/name_test.c +++ b/tests/dns/name_test.c @@ -124,7 +124,7 @@ ISC_RUN_TEST_IMPL(fullcompare) { static void compress_test(dns_name_t *name1, dns_name_t *name2, dns_name_t *name3, unsigned char *expected, unsigned int length, - dns_compress_t *cctx, dns_decompress_t *dctx) { + dns_compress_t *cctx, dns_decompress_t dctx) { isc_buffer_t source; isc_buffer_t target; dns_name_t name; @@ -151,7 +151,6 @@ compress_test(dns_name_t *name1, dns_name_t *name2, dns_name_t *name3, ISC_R_SUCCESS); RUNTIME_CHECK(dns_name_fromwire(&name, &source, dctx, 0, &target) == ISC_R_SUCCESS); - dns_decompress_invalidate(dctx); assert_int_equal(target.used, length); assert_true(memcmp(target.base, expected, target.used) == 0); @@ -193,11 +192,10 @@ ISC_RUN_TEST_IMPL(compression) { permitted = false; assert_int_equal(dns_compress_init(&cctx, mctx), ISC_R_SUCCESS); dns_compress_setpermitted(&cctx, permitted); - dns_decompress_init(&dctx, DNS_DECOMPRESS_STRICT); - dns_decompress_setpermitted(&dctx, permitted); + dctx = dns_decompress_setpermitted(DNS_DECOMPRESS_DEFAULT, permitted); compress_test(&name1, &name2, &name3, plain, sizeof(plain), &cctx, - &dctx); + dctx); dns_compress_rollback(&cctx, 0); dns_compress_invalidate(&cctx); @@ -206,11 +204,10 @@ ISC_RUN_TEST_IMPL(compression) { permitted = true; assert_int_equal(dns_compress_init(&cctx, mctx), ISC_R_SUCCESS); dns_compress_setpermitted(&cctx, permitted); - dns_decompress_init(&dctx, DNS_DECOMPRESS_STRICT); - dns_decompress_setpermitted(&dctx, permitted); + dctx = dns_decompress_setpermitted(DNS_DECOMPRESS_DEFAULT, permitted); compress_test(&name1, &name2, &name3, plain, sizeof(plain), &cctx, - &dctx); + dctx); dns_compress_rollback(&cctx, 0); dns_compress_invalidate(&cctx); @@ -220,11 +217,10 @@ ISC_RUN_TEST_IMPL(compression) { assert_int_equal(dns_compress_init(&cctx, mctx), ISC_R_SUCCESS); dns_compress_setpermitted(&cctx, permitted); dns_compress_disable(&cctx); - dns_decompress_init(&dctx, DNS_DECOMPRESS_STRICT); - dns_decompress_setpermitted(&dctx, permitted); + dctx = dns_decompress_setpermitted(DNS_DECOMPRESS_DEFAULT, permitted); compress_test(&name1, &name2, &name3, plain, sizeof(plain), &cctx, - &dctx); + dctx); dns_compress_rollback(&cctx, 0); dns_compress_invalidate(&cctx); @@ -234,11 +230,10 @@ ISC_RUN_TEST_IMPL(compression) { assert_int_equal(dns_compress_init(&cctx, mctx), ISC_R_SUCCESS); dns_compress_setpermitted(&cctx, permitted); dns_compress_disable(&cctx); - dns_decompress_init(&dctx, DNS_DECOMPRESS_STRICT); - dns_decompress_setpermitted(&dctx, permitted); + dctx = dns_decompress_setpermitted(DNS_DECOMPRESS_DEFAULT, permitted); compress_test(&name1, &name2, &name3, plain, sizeof(plain), &cctx, - &dctx); + dctx); dns_compress_rollback(&cctx, 0); dns_compress_invalidate(&cctx); diff --git a/tests/dns/rdata_test.c b/tests/dns/rdata_test.c index 8549cc528b..0b6c6d73f7 100644 --- a/tests/dns/rdata_test.c +++ b/tests/dns/rdata_test.c @@ -132,7 +132,6 @@ wire_to_rdata(const unsigned char *src, size_t srclen, dns_rdataclass_t rdclass, dns_rdatatype_t type, unsigned char *dst, size_t dstlen, dns_rdata_t *rdata) { isc_buffer_t source, target; - dns_decompress_t dctx; isc_result_t result; /* @@ -150,10 +149,8 @@ wire_to_rdata(const unsigned char *src, size_t srclen, dns_rdataclass_t rdclass, /* * Try converting input data into uncompressed wire form. */ - dns_decompress_init(&dctx, DNS_DECOMPRESS_ANY); - result = dns_rdata_fromwire(rdata, rdclass, type, &source, &dctx, 0, - &target); - dns_decompress_invalidate(&dctx); + result = dns_rdata_fromwire(rdata, rdclass, type, &source, + DNS_DECOMPRESS_ALWAYS, 0, &target); return (result); } From 64e801243e0781ef98a2c2aff98e99682f63ae8d Mon Sep 17 00:00:00 2001 From: Tony Finch Date: Thu, 5 May 2022 18:36:48 +0100 Subject: [PATCH 5/6] Clean up remaining references to global compression It is simply called "compression" now, without any qualifiers. Also, improve some variable names in dns_name_towire2() so they are not two letter abbreviations for global something. --- lib/dns/compress.c | 4 +-- lib/dns/include/dns/compress.h | 15 +++++---- lib/dns/include/dns/name.h | 6 ++-- lib/dns/include/dns/rdata.h | 6 ++-- lib/dns/name.c | 59 +++++++++++++++++----------------- 5 files changed, 43 insertions(+), 47 deletions(-) diff --git a/lib/dns/compress.c b/lib/dns/compress.c index f195e98b06..607c7c273a 100644 --- a/lib/dns/compress.c +++ b/lib/dns/compress.c @@ -205,8 +205,8 @@ dns_compress_getsensitive(dns_compress_t *cctx) { * If no match is found return false. */ bool -dns_compress_findglobal(dns_compress_t *cctx, const dns_name_t *name, - dns_name_t *prefix, uint16_t *offset) { +dns_compress_find(dns_compress_t *cctx, const dns_name_t *name, + dns_name_t *prefix, uint16_t *offset) { dns_name_t tname; dns_compressnode_t *node = NULL; unsigned int labels, i, n; diff --git a/lib/dns/include/dns/compress.h b/lib/dns/include/dns/compress.h index 151a860fbe..81e70f9e76 100644 --- a/lib/dns/include/dns/compress.h +++ b/lib/dns/include/dns/compress.h @@ -61,7 +61,7 @@ struct dns_compress { bool permitted; bool disabled; bool sensitive; - /*% Global compression table. */ + /*% Compression pointer table. */ dns_compressnode_t *table[DNS_COMPRESS_TABLESIZE]; /*% Preallocated arena for names. */ unsigned char arena[DNS_COMPRESS_ARENA_SIZE]; @@ -91,7 +91,8 @@ dns_compress_init(dns_compress_t *cctx, isc_mem_t *mctx); * \li 'cctx' is a valid dns_compress_t structure. * \li 'mctx' is an initialized memory context. * Ensures: - * \li cctx->global is initialized. + * \li 'cctx' is initialized. + * \li 'cctx->permitted' is true. * * Returns: * \li #ISC_R_SUCCESS @@ -162,10 +163,10 @@ dns_compress_getsensitive(dns_compress_t *cctx); */ bool -dns_compress_findglobal(dns_compress_t *cctx, const dns_name_t *name, - dns_name_t *prefix, uint16_t *offset); +dns_compress_find(dns_compress_t *cctx, const dns_name_t *name, + dns_name_t *prefix, uint16_t *offset); /*%< - * Finds longest possible match of 'name' in the global compression table. + * Finds longest possible match of 'name' in the compression table. * * Requires: *\li 'cctx' to be initialized. @@ -194,13 +195,13 @@ dns_compress_add(dns_compress_t *cctx, const dns_name_t *name, * valid until the message compression is complete. * *\li 'prefix' must be a prefix returned by - * dns_compress_findglobal(), or the same as 'name'. + * dns_compress_find(), or the same as 'name'. */ void dns_compress_rollback(dns_compress_t *cctx, uint16_t offset); /*%< - * Remove any compression pointers from global table >= offset. + * Remove any compression pointers from the table that are >= offset. * * Requires: *\li 'cctx' is initialized. diff --git a/lib/dns/include/dns/name.h b/lib/dns/include/dns/name.h index e294b9068b..0f140876c8 100644 --- a/lib/dns/include/dns/name.h +++ b/lib/dns/include/dns/name.h @@ -757,8 +757,7 @@ dns_name_towire2(const dns_name_t *name, dns_compress_t *cctx, * compression context 'cctx', and storing the result in 'target'. * * Notes: - * \li If the compression context allows global compression, then the - * global compression table may be updated. + * \li If compression is permitted, then the cctx table may be updated. * * Requires: * \li 'name' is a valid name @@ -769,8 +768,7 @@ dns_name_towire2(const dns_name_t *name, dns_compress_t *cctx, * * \li target is a valid buffer. * - * \li Any offsets specified in a global compression table are valid - * for buffer. + * \li Any offsets in the compression table are valid for buffer. * * Ensures: * diff --git a/lib/dns/include/dns/rdata.h b/lib/dns/include/dns/rdata.h index 029685a6ef..8603fa81b9 100644 --- a/lib/dns/include/dns/rdata.h +++ b/lib/dns/include/dns/rdata.h @@ -328,16 +328,14 @@ dns_rdata_towire(dns_rdata_t *rdata, dns_compress_t *cctx, * compression context 'cctx', and storing the result in 'target'. * * Notes: - *\li If the compression context allows global compression, then the - * global compression table may be updated. + *\li If compression is permitted, then the cctx table may be updated. * * Requires: *\li 'rdata' is a valid, non-empty rdata * *\li target is a valid buffer * - *\li Any offsets specified in a global compression table are valid - * for target. + *\li Any offsets in the compression table are valid for target. * * Ensures, * if the result is success: diff --git a/lib/dns/name.c b/lib/dns/name.c index 26114fde30..cde940e826 100644 --- a/lib/dns/name.c +++ b/lib/dns/name.c @@ -1919,10 +1919,10 @@ isc_result_t dns_name_towire2(const dns_name_t *name, dns_compress_t *cctx, isc_buffer_t *target, uint16_t *comp_offsetp) { bool compress; - uint16_t offset; - dns_name_t gp; /* Global compression prefix */ - bool gf; /* Global compression target found */ - uint16_t go; /* Global compression offset */ + bool found; + uint16_t here; /* start of the name we are adding to the message */ + uint16_t there; /* target of the compression pointer */ + dns_name_t prefix; dns_offsets_t clo; dns_name_t clname; @@ -1947,9 +1947,8 @@ dns_name_towire2(const dns_name_t *name, dns_compress_t *cctx, if (target->length - target->used < 2) { return (ISC_R_NOSPACE); } - offset = *comp_offsetp; - offset |= 0xc000; - isc_buffer_putuint16(target, offset); + here = *comp_offsetp; + isc_buffer_putuint16(target, here | 0xc000); return (ISC_R_SUCCESS); } @@ -1962,52 +1961,52 @@ dns_name_towire2(const dns_name_t *name, dns_compress_t *cctx, dns_name_clone(name, &clname); name = &clname; } - DNS_NAME_INIT(&gp, NULL); + DNS_NAME_INIT(&prefix, NULL); - offset = target->used; /*XXX*/ + here = target->used; /*XXX*/ if (compress) { - gf = dns_compress_findglobal(cctx, name, &gp, &go); + found = dns_compress_find(cctx, name, &prefix, &there); } else { - gf = false; + found = false; } /* - * If the offset is too high for 14 bit global compression, we're - * out of luck. + * If the offset does not fit in a 14 bit compression pointer, + * we're out of luck. */ - if (gf && go >= 0x4000) { - gf = false; + if (found && there >= 0x4000) { + found = false; } /* * Will the compression pointer reduce the message size? */ - if (gf && (gp.length + 2) >= name->length) { - gf = false; + if (found && (prefix.length + 2) >= name->length) { + found = false; } - if (gf) { - if (target->length - target->used < gp.length) { + if (found) { + if (target->length - target->used < prefix.length) { return (ISC_R_NOSPACE); } - if (gp.length != 0) { + if (prefix.length != 0) { unsigned char *base = target->base; - (void)memmove(base + target->used, gp.ndata, - (size_t)gp.length); + (void)memmove(base + target->used, prefix.ndata, + (size_t)prefix.length); } - isc_buffer_add(target, gp.length); + isc_buffer_add(target, prefix.length); if (target->length - target->used < 2) { return (ISC_R_NOSPACE); } - isc_buffer_putuint16(target, go | 0xc000); - if (gp.length != 0) { - dns_compress_add(cctx, name, &gp, offset); + isc_buffer_putuint16(target, there | 0xc000); + if (prefix.length != 0) { + dns_compress_add(cctx, name, &prefix, here); if (comp_offsetp != NULL) { - *comp_offsetp = offset; + *comp_offsetp = here; } } else if (comp_offsetp != NULL) { - *comp_offsetp = go; + *comp_offsetp = there; } } else { if (target->length - target->used < name->length) { @@ -2019,9 +2018,9 @@ dns_name_towire2(const dns_name_t *name, dns_compress_t *cctx, (size_t)name->length); } isc_buffer_add(target, name->length); - dns_compress_add(cctx, name, name, offset); + dns_compress_add(cctx, name, name, here); if (comp_offsetp != NULL) { - *comp_offsetp = offset; + *comp_offsetp = here; } } From 1d1114fe0a427391279baa7b6a4b7c5732b705b1 Mon Sep 17 00:00:00 2001 From: Tony Finch Date: Fri, 6 May 2022 08:19:54 +0100 Subject: [PATCH 6/6] CHANGES note for [GL !6270] [cleanup] Simplify BIND's internal DNS name compression API. As RFC 6891 explains, it isn't practical to deploy new label types or compression methods, so it isn't necessary to have an API designed to support them. Remove compression terminology that refers to Internet Drafts that expired in the 1990s. --- CHANGES | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGES b/CHANGES index 508810b2f4..ff445f22fb 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,10 @@ +5898. [cleanup] Simplify BIND's internal DNS name compression API. As + RFC 6891 explains, it isn't practical to deploy new + label types or compression methods, so it isn't + necessary to have an API designed to support them. + Remove compression terminology that refers to Internet + Drafts that expired in the 1990s. [GL !6270] + 5897. [bug] Views that weren't configured to use RFC 5011 key management would still set up an empty managed-keys zone. This has been fixed. [GL #3349]