remove dns_name_towire2()

we don't need two versions of dns_name_towire(), we can just add NULL
to the calls that don't need to specify a compression offset.
This commit is contained in:
Evan Hunt 2023-08-15 17:55:13 -07:00
parent a290ed5bd0
commit 62d70966f2
39 changed files with 57 additions and 70 deletions

View file

@ -720,10 +720,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);
isc_result_t
dns_name_towire2(const dns_name_t *name, dns_compress_t *cctx,
isc_buffer_t *target, uint16_t *comp_offsetp);
isc_buffer_t *target, uint16_t *comp_offsetp);
/*%<
* Convert 'name' into wire format, compressing it as specified by the
* compression context 'cctx', and storing the result in 'target'.

View file

@ -1663,13 +1663,7 @@ root_label:;
isc_result_t
dns_name_towire(const dns_name_t *name, dns_compress_t *cctx,
isc_buffer_t *target) {
return (dns_name_towire2(name, cctx, target, NULL));
}
isc_result_t
dns_name_towire2(const dns_name_t *name, dns_compress_t *cctx,
isc_buffer_t *target, uint16_t *name_coff) {
isc_buffer_t *target, uint16_t *name_coff) {
bool compress;
dns_offsets_t clo;
dns_name_t clname;

View file

@ -352,7 +352,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);
result = dns_name_towire(&name, cctx, target, NULL);
if (result != ISC_R_SUCCESS) {
goto rollback;
}

View file

@ -335,7 +335,7 @@ towire_any_tsig(ARGS_TOWIRE) {
dns_rdata_toregion(rdata, &sr);
dns_name_init(&name, offsets);
dns_name_fromregion(&name, &sr);
RETERR(dns_name_towire(&name, cctx, target));
RETERR(dns_name_towire(&name, cctx, target, NULL));
isc_region_consume(&sr, name_length(&name));
return (mem_tobuffer(target, sr.base, sr.length));
}

View file

@ -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));
RETERR(dns_name_towire(&name, cctx, target, NULL));
isc_buffer_availableregion(target, &tregion);
if (tregion.length < 2) {

View file

@ -142,7 +142,7 @@ towire_afsdb(ARGS_TOWIRE) {
dns_name_init(&name, offsets);
dns_name_fromregion(&name, &sr);
return (dns_name_towire(&name, cctx, target));
return (dns_name_towire(&name, cctx, target, NULL));
}
static int

View file

@ -92,7 +92,7 @@ towire_cname(ARGS_TOWIRE) {
dns_rdata_toregion(rdata, &region);
dns_name_fromregion(&name, &region);
return (dns_name_towire(&name, cctx, target));
return (dns_name_towire(&name, cctx, target, NULL));
}
static int

View file

@ -92,7 +92,7 @@ towire_dname(ARGS_TOWIRE) {
dns_rdata_toregion(rdata, &region);
dns_name_fromregion(&name, &region);
return (dns_name_towire(&name, cctx, target));
return (dns_name_towire(&name, cctx, target, NULL));
}
static int

View file

@ -91,7 +91,7 @@ towire_mb(ARGS_TOWIRE) {
dns_rdata_toregion(rdata, &region);
dns_name_fromregion(&name, &region);
return (dns_name_towire(&name, cctx, target));
return (dns_name_towire(&name, cctx, target, NULL));
}
static int

View file

@ -91,7 +91,7 @@ towire_md(ARGS_TOWIRE) {
dns_rdata_toregion(rdata, &region);
dns_name_fromregion(&name, &region);
return (dns_name_towire(&name, cctx, target));
return (dns_name_towire(&name, cctx, target, NULL));
}
static int

View file

@ -91,7 +91,7 @@ towire_mf(ARGS_TOWIRE) {
dns_rdata_toregion(rdata, &region);
dns_name_fromregion(&name, &region);
return (dns_name_towire(&name, cctx, target));
return (dns_name_towire(&name, cctx, target, NULL));
}
static int

View file

@ -91,7 +91,7 @@ towire_mg(ARGS_TOWIRE) {
dns_rdata_toregion(rdata, &region);
dns_name_fromregion(&name, &region);
return (dns_name_towire(&name, cctx, target));
return (dns_name_towire(&name, cctx, target, NULL));
}
static int

View file

@ -128,12 +128,12 @@ towire_minfo(ARGS_TOWIRE) {
dns_name_fromregion(&rmail, &region);
isc_region_consume(&region, name_length(&rmail));
RETERR(dns_name_towire(&rmail, cctx, target));
RETERR(dns_name_towire(&rmail, cctx, target, NULL));
dns_name_fromregion(&rmail, &region);
isc_region_consume(&region, rmail.length);
return (dns_name_towire(&rmail, cctx, target));
return (dns_name_towire(&rmail, cctx, target, NULL));
}
static int

View file

@ -91,7 +91,7 @@ towire_mr(ARGS_TOWIRE) {
dns_rdata_toregion(rdata, &region);
dns_name_fromregion(&name, &region);
return (dns_name_towire(&name, cctx, target));
return (dns_name_towire(&name, cctx, target, NULL));
}
static int

View file

@ -165,7 +165,7 @@ towire_mx(ARGS_TOWIRE) {
dns_name_init(&name, offsets);
dns_name_fromregion(&name, &region);
return (dns_name_towire(&name, cctx, target));
return (dns_name_towire(&name, cctx, target, NULL));
}
static int

View file

@ -388,7 +388,7 @@ towire_naptr(ARGS_TOWIRE) {
*/
dns_name_init(&name, offsets);
dns_name_fromregion(&name, &sr);
return (dns_name_towire(&name, cctx, target));
return (dns_name_towire(&name, cctx, target, NULL));
}
static int

View file

@ -102,7 +102,7 @@ towire_ns(ARGS_TOWIRE) {
dns_rdata_toregion(rdata, &region);
dns_name_fromregion(&name, &region);
return (dns_name_towire(&name, cctx, target));
return (dns_name_towire(&name, cctx, target, NULL));
}
static int

View file

@ -111,7 +111,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));
RETERR(dns_name_towire(&name, cctx, target, NULL));
return (mem_tobuffer(target, sr.base, sr.length));
}

View file

@ -174,7 +174,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));
RETERR(dns_name_towire(&name, cctx, target, NULL));
return (mem_tobuffer(target, sr.base, sr.length));
}

View file

@ -104,7 +104,7 @@ towire_ptr(ARGS_TOWIRE) {
dns_rdata_toregion(rdata, &region);
dns_name_fromregion(&name, &region);
return (dns_name_towire(&name, cctx, target));
return (dns_name_towire(&name, cctx, target, NULL));
}
static int

View file

@ -128,12 +128,12 @@ towire_rp(ARGS_TOWIRE) {
dns_name_fromregion(&rmail, &region);
isc_region_consume(&region, rmail.length);
RETERR(dns_name_towire(&rmail, cctx, target));
RETERR(dns_name_towire(&rmail, cctx, target, NULL));
dns_name_fromregion(&rmail, &region);
isc_region_consume(&region, rmail.length);
return (dns_name_towire(&rmail, cctx, target));
return (dns_name_towire(&rmail, cctx, target, NULL));
}
static int

View file

@ -378,7 +378,7 @@ towire_rrsig(ARGS_TOWIRE) {
dns_name_init(&name, offsets);
dns_name_fromregion(&name, &sr);
isc_region_consume(&sr, name_length(&name));
RETERR(dns_name_towire(&name, cctx, target));
RETERR(dns_name_towire(&name, cctx, target, NULL));
/*
* Signature.

View file

@ -138,7 +138,7 @@ towire_rt(ARGS_TOWIRE) {
dns_name_init(&name, offsets);
dns_name_fromregion(&name, &region);
return (dns_name_towire(&name, cctx, target));
return (dns_name_towire(&name, cctx, target, NULL));
}
static int

View file

@ -341,7 +341,7 @@ towire_sig(ARGS_TOWIRE) {
dns_name_init(&name, offsets);
dns_name_fromregion(&name, &sr);
isc_region_consume(&sr, name_length(&name));
RETERR(dns_name_towire(&name, cctx, target));
RETERR(dns_name_towire(&name, cctx, target, NULL));
/*
* Signature.

View file

@ -211,11 +211,11 @@ towire_soa(ARGS_TOWIRE) {
dns_name_fromregion(&mname, &sregion);
isc_region_consume(&sregion, name_length(&mname));
RETERR(dns_name_towire(&mname, cctx, target));
RETERR(dns_name_towire(&mname, cctx, target, NULL));
dns_name_fromregion(&rname, &sregion);
isc_region_consume(&sregion, name_length(&rname));
RETERR(dns_name_towire(&rname, cctx, target));
RETERR(dns_name_towire(&rname, cctx, target, NULL));
isc_buffer_availableregion(target, &tregion);
if (tregion.length < 20) {

View file

@ -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));
RETERR(dns_name_towire(&prev, cctx, target, NULL));
dns_name_fromregion(&next, &sregion);
isc_region_consume(&sregion, name_length(&next));
return (dns_name_towire(&next, cctx, target));
return (dns_name_towire(&next, cctx, target, NULL));
}
static int

View file

@ -320,7 +320,7 @@ towire_tkey(ARGS_TOWIRE) {
dns_rdata_toregion(rdata, &sr);
dns_name_init(&name, offsets);
dns_name_fromregion(&name, &sr);
RETERR(dns_name_towire(&name, cctx, target));
RETERR(dns_name_towire(&name, cctx, target, NULL));
isc_region_consume(&sr, name_length(&name));
return (mem_tobuffer(target, sr.base, sr.length));

View file

@ -226,7 +226,7 @@ towire_in_a6(ARGS_TOWIRE) {
dns_name_init(&name, offsets);
dns_name_fromregion(&name, &sr);
return (dns_name_towire(&name, cctx, target));
return (dns_name_towire(&name, cctx, target, NULL));
}
static int

View file

@ -120,7 +120,7 @@ towire_in_kx(ARGS_TOWIRE) {
dns_name_init(&name, offsets);
dns_name_fromregion(&name, &region);
return (dns_name_towire(&name, cctx, target));
return (dns_name_towire(&name, cctx, target, NULL));
}
static int

View file

@ -96,7 +96,7 @@ towire_in_nsap_ptr(ARGS_TOWIRE) {
dns_rdata_toregion(rdata, &region);
dns_name_fromregion(&name, &region);
return (dns_name_towire(&name, cctx, target));
return (dns_name_towire(&name, cctx, target, NULL));
}
static int

View file

@ -167,7 +167,7 @@ towire_in_px(ARGS_TOWIRE) {
*/
dns_name_init(&name, offsets);
dns_name_fromregion(&name, &region);
RETERR(dns_name_towire(&name, cctx, target));
RETERR(dns_name_towire(&name, cctx, target, NULL));
isc_region_consume(&region, name_length(&name));
/*
@ -175,7 +175,7 @@ towire_in_px(ARGS_TOWIRE) {
*/
dns_name_init(&name, offsets);
dns_name_fromregion(&name, &region);
return (dns_name_towire(&name, cctx, target));
return (dns_name_towire(&name, cctx, target, NULL));
}
static int

View file

@ -191,7 +191,7 @@ towire_in_srv(ARGS_TOWIRE) {
*/
dns_name_init(&name, offsets);
dns_name_fromregion(&name, &sr);
return (dns_name_towire(&name, cctx, target));
return (dns_name_towire(&name, cctx, target, NULL));
}
static int

View file

@ -966,7 +966,7 @@ generic_towire_in_svcb(ARGS_TOWIRE) {
*/
dns_name_init(&name, offsets);
dns_name_fromregion(&name, &region);
RETERR(dns_name_towire(&name, cctx, target));
RETERR(dns_name_towire(&name, cctx, target, NULL));
isc_region_consume(&region, name_length(&name));
/*

View file

@ -385,7 +385,7 @@ towiresorted(dns_rdataset_t *rdataset, const dns_name_t *owner_name,
rrbuffer = *target;
dns_compress_setpermitted(cctx, true);
result = dns_name_towire2(name, cctx, target, &offset);
result = dns_name_towire(name, cctx, target, &offset);
if (result != ISC_R_SUCCESS) {
goto rollback;
}

View file

@ -2676,7 +2676,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);
result = dns_name_towire(fctx->domain, &cctx, &zb, NULL);
if (result == ISC_R_SUCCESS) {
isc_buffer_usedregion(&zb, &zr);
}
@ -9627,7 +9627,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);
result = dns_name_towire(fctx->domain, &cctx, &zb, NULL);
if (result == ISC_R_SUCCESS) {
isc_buffer_usedregion(&zb, &zr);
}

View file

@ -626,7 +626,7 @@ renderend:
isc_buffer_init(&b, zone, sizeof(zone));
dns_compress_setpermitted(&cctx, false);
eresult = dns_name_towire(zo, &cctx, &b);
eresult = dns_name_towire(zo, &cctx, &b, NULL);
if (eresult == ISC_R_SUCCESS) {
isc_buffer_usedregion(&b, &zr);
}

View file

@ -78,7 +78,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);
result = dns_name_towire(name, &cctx, &buf, NULL);
if (result == ISC_R_NOSPACE) {
dns_compress_invalidate(&cctx);
dns_compress_init(&cctx, mctx, 0);

View file

@ -173,7 +173,7 @@ ISC_RUN_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);
result = dns_name_towire(zname, &cctx, &zb, NULL);
assert_int_equal(result, ISC_R_SUCCESS);
dns_compress_invalidate(&cctx);
isc_buffer_usedregion(&zb, &zr);

View file

@ -144,33 +144,29 @@ 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),
assert_int_equal(dns_name_towire(name1, cctx, &source, NULL),
ISC_R_SUCCESS);
assert_int_equal(dns_name_towire(name2, cctx, &source),
assert_int_equal(dns_name_towire(name2, cctx, &source, NULL),
ISC_R_SUCCESS);
assert_int_equal(dns_name_towire(name2, cctx, &source),
assert_int_equal(dns_name_towire(name2, cctx, &source, NULL),
ISC_R_SUCCESS);
assert_int_equal(dns_name_towire(name3, cctx, &source),
assert_int_equal(dns_name_towire(name3, cctx, &source, NULL),
ISC_R_SUCCESS);
} else {
/* Owner name compression */
uint16_t offset = 0xffff;
assert_int_equal(
dns_name_towire2(name1, cctx, &source, &offset),
ISC_R_SUCCESS);
assert_int_equal(dns_name_towire(name1, cctx, &source, &offset),
ISC_R_SUCCESS);
offset = 0xffff;
assert_int_equal(
dns_name_towire2(name2, cctx, &source, &offset),
ISC_R_SUCCESS);
assert_int_equal(
dns_name_towire2(name2, cctx, &source, &offset),
ISC_R_SUCCESS);
assert_int_equal(dns_name_towire(name2, cctx, &source, &offset),
ISC_R_SUCCESS);
assert_int_equal(dns_name_towire(name2, cctx, &source, &offset),
ISC_R_SUCCESS);
offset = 0xffff;
assert_int_equal(
dns_name_towire2(name3, cctx, &source, &offset),
ISC_R_SUCCESS);
assert_int_equal(dns_name_towire(name3, cctx, &source, &offset),
ISC_R_SUCCESS);
}
assert_int_equal(source.used, compressed_length);
assert_true(memcmp(source.base, compressed, source.used) == 0);
@ -434,7 +430,7 @@ ISC_RUN_TEST_IMPL(collision) {
}
dns_compress_rollback(&cctx, coff);
result = dns_name_towire(&name, &cctx, &message);
result = dns_name_towire(&name, &cctx, &message, NULL);
assert_int_equal(result, ISC_R_SUCCESS);
/* we must be able to find the name we just added */