From 2edefbad4a99a2e2a234c2c692a6204547154e7c Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Fri, 21 Feb 2025 18:14:55 -0800 Subject: [PATCH] remove the 'name_coff' parameter in dns_name_towire() this parameter was added as a (minor) optimization for cases where dns_name_towire() is run repeatedly with the same compression context, as when rendering all of the rdatas in an rdataset. it is currently only used in one place. we now simplify the interface by removing the extra parameter. the compression offset value is now part of the compression context, and can be activated when needed by calling dns_compress_setmultiuse(). multiuse mode is automatically deactivated by any subsequent call to dns_compress_permitted(). --- lib/dns/compress.c | 19 +++++++++++++++++++ lib/dns/include/dns/compress.h | 29 ++++++++++++++++++++++++++++- lib/dns/include/dns/name.h | 2 +- lib/dns/name.c | 17 +++++++++-------- lib/dns/ncache.c | 2 +- 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/cname_5.c | 2 +- lib/dns/rdata/generic/dname_39.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 | 4 ++-- 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/ptr_12.c | 2 +- lib/dns/rdata/generic/rp_17.c | 4 ++-- 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 | 4 ++-- lib/dns/rdata/generic/talink_58.c | 4 ++-- lib/dns/rdata/generic/tkey_249.c | 2 +- lib/dns/rdata/in_1/a6_38.c | 2 +- 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 | 4 ++-- lib/dns/rdata/in_1/srv_33.c | 2 +- lib/dns/rdata/in_1/svcb_64.c | 2 +- lib/dns/rdataset.c | 8 +++----- lib/dns/resolver.c | 4 ++-- lib/ns/client.c | 2 +- tests/bench/compress.c | 2 +- tests/dns/dnstap_test.c | 2 +- tests/dns/name_test.c | 25 +++++++++++++------------ 41 files changed, 114 insertions(+), 68 deletions(-) diff --git a/lib/dns/compress.c b/lib/dns/compress.c index 9490d2a7f7..9fc067a469 100644 --- a/lib/dns/compress.c +++ b/lib/dns/compress.c @@ -57,6 +57,7 @@ dns_compress_init(dns_compress_t *cctx, isc_mem_t *mctx, .mctx = mctx, .mask = mask, .set = set, + .coff = 0xffff, }; } @@ -69,6 +70,23 @@ dns_compress_invalidate(dns_compress_t *cctx) { *cctx = (dns_compress_t){ 0 }; } +void +dns_compress_setmultiuse(dns_compress_t *cctx, bool multi) { + REQUIRE(CCTX_VALID(cctx)); + if (multi) { + cctx->flags |= DNS_COMPRESS_MULTIUSE; + } else { + cctx->flags &= ~DNS_COMPRESS_MULTIUSE; + } + cctx->coff = 0xffff; +} + +bool +dns_compress_getmultiuse(dns_compress_t *cctx) { + REQUIRE(CCTX_VALID(cctx)); + return (cctx->flags & DNS_COMPRESS_MULTIUSE) != 0; +} + void dns_compress_setpermitted(dns_compress_t *cctx, bool permitted) { REQUIRE(CCTX_VALID(cctx)); @@ -77,6 +95,7 @@ dns_compress_setpermitted(dns_compress_t *cctx, bool permitted) { } else { cctx->flags &= ~DNS_COMPRESS_PERMITTED; } + dns_compress_setmultiuse(cctx, false); } bool diff --git a/lib/dns/include/dns/compress.h b/lib/dns/include/dns/compress.h index 1e3fb84527..9ca1b98327 100644 --- a/lib/dns/include/dns/compress.h +++ b/lib/dns/include/dns/compress.h @@ -75,6 +75,7 @@ enum dns_compress_flags { DNS_COMPRESS_LARGE = 0x00000004U, /* can toggle while rendering a message */ DNS_COMPRESS_PERMITTED = 0x00000008U, + DNS_COMPRESS_MULTIUSE = 0x00000010U, }; /* @@ -91,6 +92,7 @@ struct dns_compress { dns_compress_flags_t flags; uint16_t mask; uint16_t count; + uint16_t coff; isc_mem_t *mctx; dns_compress_slot_t *set; dns_compress_slot_t smallset[1 << DNS_COMPRESS_SMALLBITS]; @@ -140,11 +142,36 @@ dns_compress_invalidate(dns_compress_t *cctx); */ void +dns_compress_setmultiuse(dns_compress_t *cctx, bool multi); +/*%< + * Indicates this compression context is to be used for + * multiple calls to dns_name_towire(), for example when + * rendering the rdata in an rdataset. This causes the + * compression offset to be reusable across calls. + * + * Requires: + *\li 'cctx' is not NULL. + */ + +bool +dns_compress_getmultiuse(dns_compress_t *cctx); + +/*%< + * Find out whether multiuse is enabled. + * + * Requires: + *\li 'cctx' to be initialized. + * + * Returns: + *\li allowed compression bitmap. + */ +void dns_compress_setpermitted(dns_compress_t *cctx, bool permitted); /*%< * Sets whether compression is allowed, according to RFC 3597. - * This can vary depending on the rdata type. + * This can vary depending on the rdata type. This will also + * reset multiuse to false. * * Requires: *\li 'cctx' to be initialized. diff --git a/lib/dns/include/dns/name.h b/lib/dns/include/dns/name.h index 24340b2e4b..2760e5bf89 100644 --- a/lib/dns/include/dns/name.h +++ b/lib/dns/include/dns/name.h @@ -768,7 +768,7 @@ dns_name_fromwire(dns_name_t *name, isc_buffer_t *source, dns_decompress_t dctx, isc_result_t dns_name_towire(const dns_name_t *name, dns_compress_t *cctx, - isc_buffer_t *target, uint16_t *comp_offsetp); + isc_buffer_t *target); /*%< * Convert 'name' into wire format, compressing it as specified by the * compression context 'cctx', and storing the result in 'target'. diff --git a/lib/dns/name.c b/lib/dns/name.c index 12201c05d8..138848937d 100644 --- a/lib/dns/name.c +++ b/lib/dns/name.c @@ -1436,8 +1436,8 @@ root_label:; isc_result_t dns_name_towire(const dns_name_t *name, dns_compress_t *cctx, - isc_buffer_t *target, uint16_t *name_coff) { - bool compress; + isc_buffer_t *target) { + bool compress, multi; unsigned int here; unsigned int prefix_length; unsigned int suffix_coff; @@ -1453,16 +1453,17 @@ dns_name_towire(const dns_name_t *name, dns_compress_t *cctx, compress = !name->attributes.nocompress && dns_compress_getpermitted(cctx); + multi = compress && dns_compress_getmultiuse(cctx); /* * Write a compression pointer directly if the caller passed us * a pointer to this name's offset that we saved previously. */ - if (compress && name_coff != NULL && *name_coff < 0x4000) { + if (multi && cctx->coff < 0x4000) { if (isc_buffer_availablelength(target) < 2) { return ISC_R_NOSPACE; } - isc_buffer_putuint16(target, *name_coff | 0xc000); + isc_buffer_putuint16(target, cctx->coff | 0xc000); return ISC_R_SUCCESS; } @@ -1483,8 +1484,8 @@ dns_name_towire(const dns_name_t *name, dns_compress_t *cctx, * it isn't too short for compression to help (i.e. it's the root) */ here = isc_buffer_usedlength(target); - if (name_coff != NULL && here < 0x4000 && prefix_length > 1) { - *name_coff = (uint16_t)here; + if (multi && here < 0x4000 && prefix_length > 1) { + cctx->coff = (uint16_t)here; } if (prefix_length > 0) { @@ -1496,8 +1497,8 @@ dns_name_towire(const dns_name_t *name, dns_compress_t *cctx, } if (suffix_coff > 0) { - if (name_coff != NULL && prefix_length == 0) { - *name_coff = suffix_coff; + if (multi && prefix_length == 0) { + cctx->coff = suffix_coff; } if (isc_buffer_availablelength(target) < 2) { return ISC_R_NOSPACE; diff --git a/lib/dns/ncache.c b/lib/dns/ncache.c index edf8bbe816..bd9c43288b 100644 --- a/lib/dns/ncache.c +++ b/lib/dns/ncache.c @@ -360,7 +360,7 @@ dns_ncache_towire(dns_rdataset_t *rdataset, dns_compress_t *cctx, * Write the name. */ dns_compress_setpermitted(cctx, true); - result = dns_name_towire(&name, cctx, target, NULL); + 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 f568665981..e356840d93 100644 --- a/lib/dns/rdata/any_255/tsig_250.c +++ b/lib/dns/rdata/any_255/tsig_250.c @@ -335,7 +335,7 @@ towire_any_tsig(ARGS_TOWIRE) { dns_rdata_toregion(rdata, &sr); dns_name_init(&name); dns_name_fromregion(&name, &sr); - RETERR(dns_name_towire(&name, cctx, target, NULL)); + RETERR(dns_name_towire(&name, cctx, target)); isc_region_consume(&sr, name_length(&name)); return mem_tobuffer(target, sr.base, sr.length); } diff --git a/lib/dns/rdata/ch_3/a_1.c b/lib/dns/rdata/ch_3/a_1.c index af7ee1e8e1..99c9334c40 100644 --- a/lib/dns/rdata/ch_3/a_1.c +++ b/lib/dns/rdata/ch_3/a_1.c @@ -146,7 +146,7 @@ towire_ch_a(ARGS_TOWIRE) { dns_name_fromregion(&name, &sregion); isc_region_consume(&sregion, name_length(&name)); - RETERR(dns_name_towire(&name, cctx, target, NULL)); + RETERR(dns_name_towire(&name, cctx, target)); isc_buffer_availableregion(target, &tregion); if (tregion.length < 2) { diff --git a/lib/dns/rdata/generic/afsdb_18.c b/lib/dns/rdata/generic/afsdb_18.c index 9a8ed8ff44..25bd2e0b69 100644 --- a/lib/dns/rdata/generic/afsdb_18.c +++ b/lib/dns/rdata/generic/afsdb_18.c @@ -141,7 +141,7 @@ towire_afsdb(ARGS_TOWIRE) { dns_name_init(&name); dns_name_fromregion(&name, &sr); - return dns_name_towire(&name, cctx, target, NULL); + return dns_name_towire(&name, cctx, target); } static int diff --git a/lib/dns/rdata/generic/cname_5.c b/lib/dns/rdata/generic/cname_5.c index a66c719b33..a946097be6 100644 --- a/lib/dns/rdata/generic/cname_5.c +++ b/lib/dns/rdata/generic/cname_5.c @@ -91,7 +91,7 @@ towire_cname(ARGS_TOWIRE) { dns_rdata_toregion(rdata, ®ion); dns_name_fromregion(&name, ®ion); - return dns_name_towire(&name, cctx, target, NULL); + return dns_name_towire(&name, cctx, target); } static int diff --git a/lib/dns/rdata/generic/dname_39.c b/lib/dns/rdata/generic/dname_39.c index 7fa31a471d..ce87676a1e 100644 --- a/lib/dns/rdata/generic/dname_39.c +++ b/lib/dns/rdata/generic/dname_39.c @@ -91,7 +91,7 @@ towire_dname(ARGS_TOWIRE) { dns_rdata_toregion(rdata, ®ion); dns_name_fromregion(&name, ®ion); - return dns_name_towire(&name, cctx, target, NULL); + return dns_name_towire(&name, cctx, target); } static int diff --git a/lib/dns/rdata/generic/mb_7.c b/lib/dns/rdata/generic/mb_7.c index 767d5b5c51..ab6ab42b0c 100644 --- a/lib/dns/rdata/generic/mb_7.c +++ b/lib/dns/rdata/generic/mb_7.c @@ -90,7 +90,7 @@ towire_mb(ARGS_TOWIRE) { dns_rdata_toregion(rdata, ®ion); dns_name_fromregion(&name, ®ion); - return dns_name_towire(&name, cctx, target, NULL); + return dns_name_towire(&name, cctx, target); } static int diff --git a/lib/dns/rdata/generic/md_3.c b/lib/dns/rdata/generic/md_3.c index 70d6006e65..702b60c185 100644 --- a/lib/dns/rdata/generic/md_3.c +++ b/lib/dns/rdata/generic/md_3.c @@ -90,7 +90,7 @@ towire_md(ARGS_TOWIRE) { dns_rdata_toregion(rdata, ®ion); dns_name_fromregion(&name, ®ion); - return dns_name_towire(&name, cctx, target, NULL); + return dns_name_towire(&name, cctx, target); } static int diff --git a/lib/dns/rdata/generic/mf_4.c b/lib/dns/rdata/generic/mf_4.c index ad14f8fa40..0142c12478 100644 --- a/lib/dns/rdata/generic/mf_4.c +++ b/lib/dns/rdata/generic/mf_4.c @@ -90,7 +90,7 @@ towire_mf(ARGS_TOWIRE) { dns_rdata_toregion(rdata, ®ion); dns_name_fromregion(&name, ®ion); - return dns_name_towire(&name, cctx, target, NULL); + return dns_name_towire(&name, cctx, target); } static int diff --git a/lib/dns/rdata/generic/mg_8.c b/lib/dns/rdata/generic/mg_8.c index f426c299a5..0c8fae21c9 100644 --- a/lib/dns/rdata/generic/mg_8.c +++ b/lib/dns/rdata/generic/mg_8.c @@ -90,7 +90,7 @@ towire_mg(ARGS_TOWIRE) { dns_rdata_toregion(rdata, ®ion); dns_name_fromregion(&name, ®ion); - return dns_name_towire(&name, cctx, target, NULL); + return dns_name_towire(&name, cctx, target); } static int diff --git a/lib/dns/rdata/generic/minfo_14.c b/lib/dns/rdata/generic/minfo_14.c index aef31a4dc3..7ea92d7c99 100644 --- a/lib/dns/rdata/generic/minfo_14.c +++ b/lib/dns/rdata/generic/minfo_14.c @@ -129,12 +129,12 @@ towire_minfo(ARGS_TOWIRE) { dns_name_fromregion(&rmail, ®ion); isc_region_consume(®ion, name_length(&rmail)); - RETERR(dns_name_towire(&rmail, cctx, target, NULL)); + RETERR(dns_name_towire(&rmail, cctx, target)); dns_name_fromregion(&rmail, ®ion); isc_region_consume(®ion, rmail.length); - return dns_name_towire(&rmail, cctx, target, NULL); + return dns_name_towire(&rmail, cctx, target); } static int diff --git a/lib/dns/rdata/generic/mr_9.c b/lib/dns/rdata/generic/mr_9.c index a63b37a947..4e62678852 100644 --- a/lib/dns/rdata/generic/mr_9.c +++ b/lib/dns/rdata/generic/mr_9.c @@ -90,7 +90,7 @@ towire_mr(ARGS_TOWIRE) { dns_rdata_toregion(rdata, ®ion); dns_name_fromregion(&name, ®ion); - return dns_name_towire(&name, cctx, target, NULL); + return dns_name_towire(&name, cctx, target); } static int diff --git a/lib/dns/rdata/generic/mx_15.c b/lib/dns/rdata/generic/mx_15.c index 50464d71b6..20510dda98 100644 --- a/lib/dns/rdata/generic/mx_15.c +++ b/lib/dns/rdata/generic/mx_15.c @@ -165,7 +165,7 @@ towire_mx(ARGS_TOWIRE) { dns_name_init(&name); dns_name_fromregion(&name, ®ion); - return dns_name_towire(&name, cctx, target, NULL); + return dns_name_towire(&name, cctx, target); } static int diff --git a/lib/dns/rdata/generic/naptr_35.c b/lib/dns/rdata/generic/naptr_35.c index d66b6934a7..3715bbcbe3 100644 --- a/lib/dns/rdata/generic/naptr_35.c +++ b/lib/dns/rdata/generic/naptr_35.c @@ -388,7 +388,7 @@ towire_naptr(ARGS_TOWIRE) { */ dns_name_init(&name); dns_name_fromregion(&name, &sr); - return dns_name_towire(&name, cctx, target, NULL); + return dns_name_towire(&name, cctx, target); } static int diff --git a/lib/dns/rdata/generic/ns_2.c b/lib/dns/rdata/generic/ns_2.c index 73e9b7c6e6..b6b38f4388 100644 --- a/lib/dns/rdata/generic/ns_2.c +++ b/lib/dns/rdata/generic/ns_2.c @@ -101,7 +101,7 @@ towire_ns(ARGS_TOWIRE) { dns_rdata_toregion(rdata, ®ion); dns_name_fromregion(&name, ®ion); - return dns_name_towire(&name, cctx, target, NULL); + return dns_name_towire(&name, cctx, target); } static int diff --git a/lib/dns/rdata/generic/nsec_47.c b/lib/dns/rdata/generic/nsec_47.c index 59db69d256..28fea07c82 100644 --- a/lib/dns/rdata/generic/nsec_47.c +++ b/lib/dns/rdata/generic/nsec_47.c @@ -110,7 +110,7 @@ towire_nsec(ARGS_TOWIRE) { dns_rdata_toregion(rdata, &sr); dns_name_fromregion(&name, &sr); isc_region_consume(&sr, name_length(&name)); - RETERR(dns_name_towire(&name, cctx, target, NULL)); + RETERR(dns_name_towire(&name, cctx, target)); return mem_tobuffer(target, sr.base, sr.length); } diff --git a/lib/dns/rdata/generic/nxt_30.c b/lib/dns/rdata/generic/nxt_30.c index 1a828933b2..a552276292 100644 --- a/lib/dns/rdata/generic/nxt_30.c +++ b/lib/dns/rdata/generic/nxt_30.c @@ -173,7 +173,7 @@ towire_nxt(ARGS_TOWIRE) { dns_rdata_toregion(rdata, &sr); dns_name_fromregion(&name, &sr); isc_region_consume(&sr, name_length(&name)); - RETERR(dns_name_towire(&name, cctx, target, NULL)); + RETERR(dns_name_towire(&name, cctx, target)); return mem_tobuffer(target, sr.base, sr.length); } diff --git a/lib/dns/rdata/generic/ptr_12.c b/lib/dns/rdata/generic/ptr_12.c index b24178c967..24d975a0b9 100644 --- a/lib/dns/rdata/generic/ptr_12.c +++ b/lib/dns/rdata/generic/ptr_12.c @@ -103,7 +103,7 @@ towire_ptr(ARGS_TOWIRE) { dns_rdata_toregion(rdata, ®ion); dns_name_fromregion(&name, ®ion); - return dns_name_towire(&name, cctx, target, NULL); + return dns_name_towire(&name, cctx, target); } static int diff --git a/lib/dns/rdata/generic/rp_17.c b/lib/dns/rdata/generic/rp_17.c index f652aa2c2c..33c8192fac 100644 --- a/lib/dns/rdata/generic/rp_17.c +++ b/lib/dns/rdata/generic/rp_17.c @@ -130,12 +130,12 @@ towire_rp(ARGS_TOWIRE) { dns_name_fromregion(&rmail, ®ion); isc_region_consume(®ion, rmail.length); - RETERR(dns_name_towire(&rmail, cctx, target, NULL)); + RETERR(dns_name_towire(&rmail, cctx, target)); dns_name_fromregion(&rmail, ®ion); isc_region_consume(®ion, rmail.length); - return dns_name_towire(&rmail, cctx, target, NULL); + return dns_name_towire(&rmail, cctx, target); } static int diff --git a/lib/dns/rdata/generic/rrsig_46.c b/lib/dns/rdata/generic/rrsig_46.c index 7cad4b65ae..bcfac4a666 100644 --- a/lib/dns/rdata/generic/rrsig_46.c +++ b/lib/dns/rdata/generic/rrsig_46.c @@ -377,7 +377,7 @@ towire_rrsig(ARGS_TOWIRE) { dns_name_init(&name); dns_name_fromregion(&name, &sr); isc_region_consume(&sr, name_length(&name)); - RETERR(dns_name_towire(&name, cctx, target, NULL)); + RETERR(dns_name_towire(&name, cctx, target)); /* * Signature. diff --git a/lib/dns/rdata/generic/rt_21.c b/lib/dns/rdata/generic/rt_21.c index 7402a14acd..41c0df41f3 100644 --- a/lib/dns/rdata/generic/rt_21.c +++ b/lib/dns/rdata/generic/rt_21.c @@ -138,7 +138,7 @@ towire_rt(ARGS_TOWIRE) { dns_name_init(&name); dns_name_fromregion(&name, ®ion); - return dns_name_towire(&name, cctx, target, NULL); + return dns_name_towire(&name, cctx, target); } static int diff --git a/lib/dns/rdata/generic/sig_24.c b/lib/dns/rdata/generic/sig_24.c index beeb366571..c5d3ed3ef7 100644 --- a/lib/dns/rdata/generic/sig_24.c +++ b/lib/dns/rdata/generic/sig_24.c @@ -341,7 +341,7 @@ towire_sig(ARGS_TOWIRE) { dns_name_init(&name); dns_name_fromregion(&name, &sr); isc_region_consume(&sr, name_length(&name)); - RETERR(dns_name_towire(&name, cctx, target, NULL)); + RETERR(dns_name_towire(&name, cctx, target)); /* * Signature. diff --git a/lib/dns/rdata/generic/soa_6.c b/lib/dns/rdata/generic/soa_6.c index 14575c3002..782da3c1a8 100644 --- a/lib/dns/rdata/generic/soa_6.c +++ b/lib/dns/rdata/generic/soa_6.c @@ -213,11 +213,11 @@ towire_soa(ARGS_TOWIRE) { dns_name_fromregion(&mname, &sregion); isc_region_consume(&sregion, name_length(&mname)); - RETERR(dns_name_towire(&mname, cctx, target, NULL)); + RETERR(dns_name_towire(&mname, cctx, target)); dns_name_fromregion(&rname, &sregion); isc_region_consume(&sregion, name_length(&rname)); - RETERR(dns_name_towire(&rname, cctx, target, NULL)); + RETERR(dns_name_towire(&rname, cctx, target)); isc_buffer_availableregion(target, &tregion); if (tregion.length < 20) { diff --git a/lib/dns/rdata/generic/talink_58.c b/lib/dns/rdata/generic/talink_58.c index 68328dc65a..148a11569c 100644 --- a/lib/dns/rdata/generic/talink_58.c +++ b/lib/dns/rdata/generic/talink_58.c @@ -117,11 +117,11 @@ towire_talink(ARGS_TOWIRE) { dns_name_fromregion(&prev, &sregion); isc_region_consume(&sregion, name_length(&prev)); - RETERR(dns_name_towire(&prev, cctx, target, NULL)); + RETERR(dns_name_towire(&prev, cctx, target)); dns_name_fromregion(&next, &sregion); isc_region_consume(&sregion, name_length(&next)); - return dns_name_towire(&next, cctx, target, NULL); + return dns_name_towire(&next, cctx, target); } static int diff --git a/lib/dns/rdata/generic/tkey_249.c b/lib/dns/rdata/generic/tkey_249.c index e700ab4987..dbea25a1da 100644 --- a/lib/dns/rdata/generic/tkey_249.c +++ b/lib/dns/rdata/generic/tkey_249.c @@ -320,7 +320,7 @@ towire_tkey(ARGS_TOWIRE) { dns_rdata_toregion(rdata, &sr); dns_name_init(&name); dns_name_fromregion(&name, &sr); - RETERR(dns_name_towire(&name, cctx, target, NULL)); + RETERR(dns_name_towire(&name, cctx, target)); isc_region_consume(&sr, name_length(&name)); return mem_tobuffer(target, sr.base, sr.length); diff --git a/lib/dns/rdata/in_1/a6_38.c b/lib/dns/rdata/in_1/a6_38.c index da76a50f5d..b70a65343f 100644 --- a/lib/dns/rdata/in_1/a6_38.c +++ b/lib/dns/rdata/in_1/a6_38.c @@ -226,7 +226,7 @@ towire_in_a6(ARGS_TOWIRE) { dns_name_init(&name); dns_name_fromregion(&name, &sr); - return dns_name_towire(&name, cctx, target, NULL); + return dns_name_towire(&name, cctx, target); } static int diff --git a/lib/dns/rdata/in_1/kx_36.c b/lib/dns/rdata/in_1/kx_36.c index 8bc548913f..aebc7292a5 100644 --- a/lib/dns/rdata/in_1/kx_36.c +++ b/lib/dns/rdata/in_1/kx_36.c @@ -120,7 +120,7 @@ towire_in_kx(ARGS_TOWIRE) { dns_name_init(&name); dns_name_fromregion(&name, ®ion); - return dns_name_towire(&name, cctx, target, NULL); + return dns_name_towire(&name, cctx, target); } static int diff --git a/lib/dns/rdata/in_1/nsap-ptr_23.c b/lib/dns/rdata/in_1/nsap-ptr_23.c index 1afb6a5ef0..55167cebee 100644 --- a/lib/dns/rdata/in_1/nsap-ptr_23.c +++ b/lib/dns/rdata/in_1/nsap-ptr_23.c @@ -95,7 +95,7 @@ towire_in_nsap_ptr(ARGS_TOWIRE) { dns_rdata_toregion(rdata, ®ion); dns_name_fromregion(&name, ®ion); - return dns_name_towire(&name, cctx, target, NULL); + return dns_name_towire(&name, cctx, target); } static int diff --git a/lib/dns/rdata/in_1/px_26.c b/lib/dns/rdata/in_1/px_26.c index 07b555750d..1301767596 100644 --- a/lib/dns/rdata/in_1/px_26.c +++ b/lib/dns/rdata/in_1/px_26.c @@ -168,7 +168,7 @@ towire_in_px(ARGS_TOWIRE) { */ dns_name_init(&name); dns_name_fromregion(&name, ®ion); - RETERR(dns_name_towire(&name, cctx, target, NULL)); + RETERR(dns_name_towire(&name, cctx, target)); isc_region_consume(®ion, name_length(&name)); /* @@ -176,7 +176,7 @@ towire_in_px(ARGS_TOWIRE) { */ dns_name_init(&name); dns_name_fromregion(&name, ®ion); - return dns_name_towire(&name, cctx, target, NULL); + return dns_name_towire(&name, cctx, target); } static int diff --git a/lib/dns/rdata/in_1/srv_33.c b/lib/dns/rdata/in_1/srv_33.c index d8693a5113..d488b94193 100644 --- a/lib/dns/rdata/in_1/srv_33.c +++ b/lib/dns/rdata/in_1/srv_33.c @@ -191,7 +191,7 @@ towire_in_srv(ARGS_TOWIRE) { */ dns_name_init(&name); dns_name_fromregion(&name, &sr); - return dns_name_towire(&name, cctx, target, NULL); + return dns_name_towire(&name, cctx, target); } static int diff --git a/lib/dns/rdata/in_1/svcb_64.c b/lib/dns/rdata/in_1/svcb_64.c index ce7a297ec0..b2f239ef99 100644 --- a/lib/dns/rdata/in_1/svcb_64.c +++ b/lib/dns/rdata/in_1/svcb_64.c @@ -940,7 +940,7 @@ generic_towire_in_svcb(ARGS_TOWIRE) { */ dns_name_init(&name); dns_name_fromregion(&name, ®ion); - RETERR(dns_name_towire(&name, cctx, target, NULL)); + RETERR(dns_name_towire(&name, cctx, target)); isc_region_consume(®ion, name_length(&name)); /* diff --git a/lib/dns/rdataset.c b/lib/dns/rdataset.c index d0962fe95e..28659b4867 100644 --- a/lib/dns/rdataset.c +++ b/lib/dns/rdataset.c @@ -247,7 +247,6 @@ towire(dns_rdataset_t *rdataset, const dns_name_t *owner_name, struct towire_sort *out = out_fixed; dns_fixedname_t fixed; dns_name_t *name = NULL; - uint16_t offset; /* * Convert 'rdataset' to wire format, compressing names as specified @@ -357,7 +356,7 @@ towire(dns_rdataset_t *rdataset, const dns_name_t *owner_name, name = dns_fixedname_initname(&fixed); dns_name_copy(owner_name, name); dns_rdataset_getownercase(rdataset, name); - offset = 0xffff; + dns_compress_setmultiuse(cctx, true); name->attributes.nocompress |= owner_name->attributes.nocompress; @@ -368,15 +367,14 @@ towire(dns_rdataset_t *rdataset, const dns_name_t *owner_name, rrbuffer = *target; dns_compress_setpermitted(cctx, true); - result = dns_name_towire(name, cctx, target, &offset); + result = dns_name_towire(name, cctx, target); if (result != ISC_R_SUCCESS) { goto rollback; } headlen = sizeof(dns_rdataclass_t) + sizeof(dns_rdatatype_t); if (!question) { headlen += sizeof(dns_ttl_t) + 2; - } /* XXX 2 for rdata len - */ + } /* XXX 2 for rdata len */ isc_buffer_availableregion(target, &r); if (r.length < headlen) { result = ISC_R_NOSPACE; diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index 962b79109b..e2601548fe 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -2703,7 +2703,7 @@ resquery_send(resquery_t *query) { memset(&zr, 0, sizeof(zr)); isc_buffer_init(&zb, zone, sizeof(zone)); dns_compress_setpermitted(&cctx, false); - result = dns_name_towire(fctx->domain, &cctx, &zb, NULL); + result = dns_name_towire(fctx->domain, &cctx, &zb); if (result == ISC_R_SUCCESS) { isc_buffer_usedregion(&zb, &zr); } @@ -9730,7 +9730,7 @@ rctx_logpacket(respctx_t *rctx) { dns_compress_init(&cctx, fctx->mctx, 0); dns_compress_setpermitted(&cctx, false); isc_buffer_init(&zb, zone, sizeof(zone)); - result = dns_name_towire(fctx->domain, &cctx, &zb, NULL); + 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 6a3d40f446..222a4f4f50 100644 --- a/lib/ns/client.c +++ b/lib/ns/client.c @@ -699,7 +699,7 @@ renderend: isc_buffer_init(&b, zone, sizeof(zone)); dns_compress_setpermitted(&cctx, false); - eresult = dns_name_towire(zo, &cctx, &b, NULL); + eresult = dns_name_towire(zo, &cctx, &b); if (eresult == ISC_R_SUCCESS) { isc_buffer_usedregion(&b, &zr); } diff --git a/tests/bench/compress.c b/tests/bench/compress.c index 0660785ddc..31e73f5be1 100644 --- a/tests/bench/compress.c +++ b/tests/bench/compress.c @@ -80,7 +80,7 @@ main(void) { for (unsigned int i = 0; i < count; i++) { dns_name_t *name = dns_fixedname_name(&fixedname[i]); - result = dns_name_towire(name, &cctx, &buf, NULL); + result = dns_name_towire(name, &cctx, &buf); if (result == ISC_R_NOSPACE) { dns_compress_invalidate(&cctx); dns_compress_init(&cctx, mctx, 0); diff --git a/tests/dns/dnstap_test.c b/tests/dns/dnstap_test.c index a7156b7ba9..a7b1aaf5b0 100644 --- a/tests/dns/dnstap_test.c +++ b/tests/dns/dnstap_test.c @@ -187,7 +187,7 @@ ISC_LOOP_TEST_IMPL(dns_dt_send) { isc_buffer_init(&zb, zone, sizeof(zone)); dns_compress_init(&cctx, mctx, 0); dns_compress_setpermitted(&cctx, false); - result = dns_name_towire(zname, &cctx, &zb, NULL); + result = dns_name_towire(zname, &cctx, &zb); assert_int_equal(result, ISC_R_SUCCESS); dns_compress_invalidate(&cctx); isc_buffer_usedregion(&zb, &zr); diff --git a/tests/dns/name_test.c b/tests/dns/name_test.c index 47369761a4..a786299a02 100644 --- a/tests/dns/name_test.c +++ b/tests/dns/name_test.c @@ -148,28 +148,28 @@ compress_test(const dns_name_t *name1, const dns_name_t *name2, if (rdata) { /* RDATA compression */ - assert_int_equal(dns_name_towire(name1, cctx, &source, NULL), + assert_int_equal(dns_name_towire(name1, cctx, &source), ISC_R_SUCCESS); - assert_int_equal(dns_name_towire(name2, cctx, &source, NULL), + assert_int_equal(dns_name_towire(name2, cctx, &source), ISC_R_SUCCESS); - assert_int_equal(dns_name_towire(name2, cctx, &source, NULL), + assert_int_equal(dns_name_towire(name2, cctx, &source), ISC_R_SUCCESS); - assert_int_equal(dns_name_towire(name3, cctx, &source, NULL), + assert_int_equal(dns_name_towire(name3, cctx, &source), ISC_R_SUCCESS); } else { /* Owner name compression */ - uint16_t offset = 0xffff; - assert_int_equal(dns_name_towire(name1, cctx, &source, &offset), + dns_compress_setmultiuse(cctx, true); + assert_int_equal(dns_name_towire(name1, cctx, &source), ISC_R_SUCCESS); - offset = 0xffff; - assert_int_equal(dns_name_towire(name2, cctx, &source, &offset), + dns_compress_setmultiuse(cctx, true); + assert_int_equal(dns_name_towire(name2, cctx, &source), ISC_R_SUCCESS); - assert_int_equal(dns_name_towire(name2, cctx, &source, &offset), + assert_int_equal(dns_name_towire(name2, cctx, &source), ISC_R_SUCCESS); - offset = 0xffff; - assert_int_equal(dns_name_towire(name3, cctx, &source, &offset), + dns_compress_setmultiuse(cctx, true); + assert_int_equal(dns_name_towire(name3, cctx, &source), ISC_R_SUCCESS); } assert_int_equal(source.used, compressed_length); @@ -433,7 +433,8 @@ ISC_RUN_TEST_IMPL(collision) { } dns_compress_rollback(&cctx, coff); - result = dns_name_towire(&name, &cctx, &message, NULL); + dns_compress_setmultiuse(&cctx, true); + result = dns_name_towire(&name, &cctx, &message); assert_int_equal(result, ISC_R_SUCCESS); /* we must be able to find the name we just added */