mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-01 15:05:23 +00:00
Remove the "raw" version of the dns_slabheader API
The "raw" version of the header was used for the noqname and the closest proofs to save around 152 bytes of the dns_slabheader_t while bringing an additional complexity. Remove the raw version of the dns_slabheader API at the slight expense of having unused dns_slabheader_t data sitting in front of the proofs.
This commit is contained in:
@@ -257,7 +257,7 @@ struct dns_rdataset {
|
|||||||
#define DNS_RDATASETATTR_CHECKNAMES 0x00008000 /*%< Used by resolver. */
|
#define DNS_RDATASETATTR_CHECKNAMES 0x00008000 /*%< Used by resolver. */
|
||||||
#define DNS_RDATASETATTR_REQUIRED 0x00010000
|
#define DNS_RDATASETATTR_REQUIRED 0x00010000
|
||||||
#define DNS_RDATASETATTR_REQUIREDGLUE DNS_RDATASETATTR_REQUIRED
|
#define DNS_RDATASETATTR_REQUIREDGLUE DNS_RDATASETATTR_REQUIRED
|
||||||
#define DNS_RDATASETATTR_NOHEADER 0x00020000
|
#define DNS_RDATASETATTR_UNUSED1 0x00020000
|
||||||
#define DNS_RDATASETATTR_RESIGN 0x00040000
|
#define DNS_RDATASETATTR_RESIGN 0x00040000
|
||||||
#define DNS_RDATASETATTR_CLOSEST 0x00080000
|
#define DNS_RDATASETATTR_CLOSEST 0x00080000
|
||||||
#define DNS_RDATASETATTR_OPTOUT 0x00100000 /*%< OPTOUT proof */
|
#define DNS_RDATASETATTR_OPTOUT 0x00100000 /*%< OPTOUT proof */
|
||||||
|
@@ -174,16 +174,12 @@ extern dns_rdatasetmethods_t dns_rdataslab_rdatasetmethods;
|
|||||||
isc_result_t
|
isc_result_t
|
||||||
dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx,
|
dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx,
|
||||||
isc_region_t *region, uint32_t limit);
|
isc_region_t *region, uint32_t limit);
|
||||||
isc_result_t
|
|
||||||
dns_rdataslab_raw_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx,
|
|
||||||
isc_region_t *region, uint32_t limit);
|
|
||||||
/*%<
|
/*%<
|
||||||
* Allocate space for a slab to hold the data in rdataset, and copy the
|
* Allocate space for a slab to hold the data in rdataset, and copy the
|
||||||
* data into it. The resulting slab will be returned in 'region'.
|
* data into it. The resulting slab will be returned in 'region'.
|
||||||
*
|
*
|
||||||
* The dns_rdataslab_raw_fromrdataset() function allocates and fills only
|
* dns_rdataslab_fromrdataset() allocates space for a dns_slabheader object
|
||||||
* the memory needed for a raw slab. dns_rdataslab_fromrdataset() also
|
* and the memory needed for a raw slab, and partially initializes
|
||||||
* allocates space for a dns_slabheader object, and partially initializes
|
|
||||||
* it, setting the type, trust, and TTL fields to match rdataset->type,
|
* it, setting the type, trust, and TTL fields to match rdataset->type,
|
||||||
* rdataset->covers, rdataset->trust, and rdataset->ttl. (Note that the
|
* rdataset->covers, rdataset->trust, and rdataset->ttl. (Note that the
|
||||||
* last field needs to be overridden when used in the cache database,
|
* last field needs to be overridden when used in the cache database,
|
||||||
@@ -216,18 +212,6 @@ dns_rdataslab_size(dns_slabheader_t *header);
|
|||||||
*\li The number of bytes in the slab, plus the header.
|
*\li The number of bytes in the slab, plus the header.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsigned int
|
|
||||||
dns_rdataslab_sizeraw(unsigned char *slab);
|
|
||||||
/*%<
|
|
||||||
* Return the total size of the raw rdataslab 'slab'.
|
|
||||||
*
|
|
||||||
* Requires:
|
|
||||||
*\li 'slab' points to a raw slab.
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
*\li The number of bytes in the slab.
|
|
||||||
*/
|
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
dns_rdataslab_count(dns_slabheader_t *header);
|
dns_rdataslab_count(dns_slabheader_t *header);
|
||||||
/*%<
|
/*%<
|
||||||
|
@@ -3090,21 +3090,20 @@ addnoqname(isc_mem_t *mctx, dns_slabheader_t *newheader, uint32_t maxrrperset,
|
|||||||
result = dns_rdataset_getnoqname(rdataset, &name, &neg, &negsig);
|
result = dns_rdataset_getnoqname(rdataset, &name, &neg, &negsig);
|
||||||
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
||||||
|
|
||||||
result = dns_rdataslab_raw_fromrdataset(&neg, mctx, &r1, maxrrperset);
|
result = dns_rdataslab_fromrdataset(&neg, mctx, &r1, maxrrperset);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = dns_rdataslab_raw_fromrdataset(&negsig, mctx, &r2,
|
result = dns_rdataslab_fromrdataset(&negsig, mctx, &r2, maxrrperset);
|
||||||
maxrrperset);
|
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
noqname = isc_mem_get(mctx, sizeof(*noqname));
|
noqname = isc_mem_get(mctx, sizeof(*noqname));
|
||||||
*noqname = (dns_slabheader_proof_t){
|
*noqname = (dns_slabheader_proof_t){
|
||||||
.neg = r1.base,
|
.neg = dns_slabheader_raw((dns_slabheader_t *)r1.base),
|
||||||
.negsig = r2.base,
|
.negsig = dns_slabheader_raw((dns_slabheader_t *)r2.base),
|
||||||
.type = neg.type,
|
.type = neg.type,
|
||||||
.name = DNS_NAME_INITEMPTY,
|
.name = DNS_NAME_INITEMPTY,
|
||||||
};
|
};
|
||||||
@@ -3130,21 +3129,20 @@ addclosest(isc_mem_t *mctx, dns_slabheader_t *newheader, uint32_t maxrrperset,
|
|||||||
result = dns_rdataset_getclosest(rdataset, &name, &neg, &negsig);
|
result = dns_rdataset_getclosest(rdataset, &name, &neg, &negsig);
|
||||||
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
||||||
|
|
||||||
result = dns_rdataslab_raw_fromrdataset(&neg, mctx, &r1, maxrrperset);
|
result = dns_rdataslab_fromrdataset(&neg, mctx, &r1, maxrrperset);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = dns_rdataslab_raw_fromrdataset(&negsig, mctx, &r2,
|
result = dns_rdataslab_fromrdataset(&negsig, mctx, &r2, maxrrperset);
|
||||||
maxrrperset);
|
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
closest = isc_mem_get(mctx, sizeof(*closest));
|
closest = isc_mem_get(mctx, sizeof(*closest));
|
||||||
*closest = (dns_slabheader_proof_t){
|
*closest = (dns_slabheader_proof_t){
|
||||||
.neg = r1.base,
|
.neg = dns_slabheader_raw((dns_slabheader_t *)r1.base),
|
||||||
.negsig = r2.base,
|
.negsig = dns_slabheader_raw((dns_slabheader_t *)r2.base),
|
||||||
.name = DNS_NAME_INITEMPTY,
|
.name = DNS_NAME_INITEMPTY,
|
||||||
.type = neg.type,
|
.type = neg.type,
|
||||||
};
|
};
|
||||||
|
@@ -653,9 +653,7 @@ dns_slabheader_t *
|
|||||||
dns_rdataset_getheader(const dns_rdataset_t *rdataset) {
|
dns_rdataset_getheader(const dns_rdataset_t *rdataset) {
|
||||||
REQUIRE(DNS_RDATASET_VALID(rdataset));
|
REQUIRE(DNS_RDATASET_VALID(rdataset));
|
||||||
|
|
||||||
if (rdataset->methods->getheader != NULL &&
|
if (rdataset->methods->getheader != NULL) {
|
||||||
(rdataset->attributes & DNS_RDATASETATTR_NOHEADER) == 0)
|
|
||||||
{
|
|
||||||
return (rdataset->methods->getheader)(rdataset);
|
return (rdataset->methods->getheader)(rdataset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -124,7 +124,7 @@ compare_rdata(const void *p1, const void *p2) {
|
|||||||
|
|
||||||
static isc_result_t
|
static isc_result_t
|
||||||
makeslab(dns_rdataset_t *rdataset, isc_mem_t *mctx, isc_region_t *region,
|
makeslab(dns_rdataset_t *rdataset, isc_mem_t *mctx, isc_region_t *region,
|
||||||
uint32_t maxrrperset, bool raw) {
|
uint32_t maxrrperset) {
|
||||||
/*
|
/*
|
||||||
* Use &removed as a sentinel pointer for duplicate
|
* Use &removed as a sentinel pointer for duplicate
|
||||||
* rdata as rdata.data == NULL is valid.
|
* rdata as rdata.data == NULL is valid.
|
||||||
@@ -132,13 +132,14 @@ makeslab(dns_rdataset_t *rdataset, isc_mem_t *mctx, isc_region_t *region,
|
|||||||
static unsigned char removed;
|
static unsigned char removed;
|
||||||
dns_rdata_t *rdata = NULL;
|
dns_rdata_t *rdata = NULL;
|
||||||
unsigned char *rawbuf = NULL;
|
unsigned char *rawbuf = NULL;
|
||||||
unsigned int headerlen = raw ? 0 : sizeof(dns_slabheader_t);
|
unsigned int headerlen = sizeof(dns_slabheader_t);
|
||||||
unsigned int buflen;
|
unsigned int buflen;
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
unsigned int nitems;
|
unsigned int nitems;
|
||||||
unsigned int nalloc;
|
unsigned int nalloc;
|
||||||
unsigned int length;
|
unsigned int length;
|
||||||
unsigned int i;
|
size_t i;
|
||||||
|
size_t rdatasize;
|
||||||
|
|
||||||
buflen = headerlen + 2;
|
buflen = headerlen + 2;
|
||||||
|
|
||||||
@@ -173,7 +174,9 @@ makeslab(dns_rdataset_t *rdataset, isc_mem_t *mctx, isc_region_t *region,
|
|||||||
* Remember the original number of items.
|
* Remember the original number of items.
|
||||||
*/
|
*/
|
||||||
nalloc = nitems;
|
nalloc = nitems;
|
||||||
rdata = isc_mem_cget(mctx, nalloc, sizeof(rdata[0]));
|
|
||||||
|
RUNTIME_CHECK(!ISC_OVERFLOW_MUL(nalloc, sizeof(rdata[0]), &rdatasize));
|
||||||
|
rdata = isc_mem_get(mctx, rdatasize);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Save all of the rdata members into an array.
|
* Save all of the rdata members into an array.
|
||||||
@@ -259,7 +262,7 @@ makeslab(dns_rdataset_t *rdataset, isc_mem_t *mctx, isc_region_t *region,
|
|||||||
* Allocate the memory, set up a buffer, start copying in
|
* Allocate the memory, set up a buffer, start copying in
|
||||||
* data.
|
* data.
|
||||||
*/
|
*/
|
||||||
rawbuf = isc_mem_cget(mctx, 1, buflen);
|
rawbuf = isc_mem_get(mctx, buflen);
|
||||||
|
|
||||||
region->base = rawbuf;
|
region->base = rawbuf;
|
||||||
region->length = buflen;
|
region->length = buflen;
|
||||||
@@ -297,7 +300,7 @@ makeslab(dns_rdataset_t *rdataset, isc_mem_t *mctx, isc_region_t *region,
|
|||||||
result = ISC_R_SUCCESS;
|
result = ISC_R_SUCCESS;
|
||||||
|
|
||||||
free_rdatas:
|
free_rdatas:
|
||||||
isc_mem_cput(mctx, rdata, nalloc, sizeof(rdata[0]));
|
isc_mem_put(mctx, rdata, rdatasize);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,7 +309,7 @@ dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx,
|
|||||||
isc_region_t *region, uint32_t maxrrperset) {
|
isc_region_t *region, uint32_t maxrrperset) {
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
|
|
||||||
result = makeslab(rdataset, mctx, region, maxrrperset, false);
|
result = makeslab(rdataset, mctx, region, maxrrperset);
|
||||||
if (result == ISC_R_SUCCESS) {
|
if (result == ISC_R_SUCCESS) {
|
||||||
dns_slabheader_t *new = (dns_slabheader_t *)region->base;
|
dns_slabheader_t *new = (dns_slabheader_t *)region->base;
|
||||||
|
|
||||||
@@ -322,15 +325,13 @@ dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
isc_result_t
|
|
||||||
dns_rdataslab_raw_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx,
|
|
||||||
isc_region_t *region, uint32_t maxrrperset) {
|
|
||||||
return makeslab(rdataset, mctx, region, maxrrperset, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
dns_rdataslab_sizeraw(unsigned char *slab) {
|
dns_rdataslab_size(dns_slabheader_t *header) {
|
||||||
REQUIRE(slab != NULL);
|
REQUIRE(header != NULL);
|
||||||
|
|
||||||
|
unsigned char *slab = (unsigned char *)header +
|
||||||
|
sizeof(dns_slabheader_t);
|
||||||
|
INSIST(slab != NULL);
|
||||||
|
|
||||||
unsigned char *current = slab;
|
unsigned char *current = slab;
|
||||||
uint16_t count = get_uint16(current);
|
uint16_t count = get_uint16(current);
|
||||||
@@ -340,15 +341,7 @@ dns_rdataslab_sizeraw(unsigned char *slab) {
|
|||||||
current += length;
|
current += length;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (unsigned int)(current - slab);
|
return (unsigned int)(current - slab) + sizeof(dns_slabheader_t);
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int
|
|
||||||
dns_rdataslab_size(dns_slabheader_t *header) {
|
|
||||||
REQUIRE(header != NULL);
|
|
||||||
|
|
||||||
unsigned char *s = (unsigned char *)header + sizeof(dns_slabheader_t);
|
|
||||||
return dns_rdataslab_sizeraw(s) + sizeof(dns_slabheader_t);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
@@ -882,20 +875,30 @@ dns_slabheader_destroy(dns_slabheader_t **headerp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dns_slabheader_freeproof(isc_mem_t *mctx, dns_slabheader_proof_t **proof) {
|
dns_slabheader_freeproof(isc_mem_t *mctx, dns_slabheader_proof_t **proofp) {
|
||||||
if (dns_name_dynamic(&(*proof)->name)) {
|
unsigned int buflen;
|
||||||
dns_name_free(&(*proof)->name, mctx);
|
uint8_t *rawbuf;
|
||||||
|
dns_slabheader_proof_t *proof = *proofp;
|
||||||
|
*proofp = NULL;
|
||||||
|
|
||||||
|
if (dns_name_dynamic(&proof->name)) {
|
||||||
|
dns_name_free(&proof->name, mctx);
|
||||||
}
|
}
|
||||||
if ((*proof)->neg != NULL) {
|
if (proof->neg != NULL) {
|
||||||
isc_mem_put(mctx, (*proof)->neg,
|
rawbuf = proof->neg;
|
||||||
dns_rdataslab_sizeraw((*proof)->neg));
|
rawbuf -= sizeof(dns_slabheader_t);
|
||||||
|
buflen = dns_rdataslab_size((dns_slabheader_t *)rawbuf);
|
||||||
|
|
||||||
|
isc_mem_put(mctx, rawbuf, buflen);
|
||||||
}
|
}
|
||||||
if ((*proof)->negsig != NULL) {
|
if (proof->negsig != NULL) {
|
||||||
isc_mem_put(mctx, (*proof)->negsig,
|
rawbuf = proof->negsig;
|
||||||
dns_rdataslab_sizeraw((*proof)->negsig));
|
rawbuf -= sizeof(dns_slabheader_t);
|
||||||
|
buflen = dns_rdataslab_size((dns_slabheader_t *)rawbuf);
|
||||||
|
|
||||||
|
isc_mem_put(mctx, rawbuf, buflen);
|
||||||
}
|
}
|
||||||
isc_mem_put(mctx, *proof, sizeof(**proof));
|
isc_mem_put(mctx, proof, sizeof(*proof));
|
||||||
*proof = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dns_slabheader_t *
|
dns_slabheader_t *
|
||||||
@@ -1063,13 +1066,9 @@ rdataset_getnoqname(dns_rdataset_t *rdataset, dns_name_t *name,
|
|||||||
const dns_slabheader_proof_t *noqname = rdataset->slab.noqname;
|
const dns_slabheader_proof_t *noqname = rdataset->slab.noqname;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Usually, rdataset->slab.raw refers the data following a
|
* The _KEEPCASE attribute is set to prevent setownercase and
|
||||||
* dns_slabheader, but in this case it points to a bare
|
* getownercase methods from affecting the case of NSEC/NSEC3
|
||||||
* rdataslab belonging to the dns_slabheader's `noqname` field.
|
* owner names.
|
||||||
* The DNS_RDATASETATTR_NOHEADER attribute is set so that
|
|
||||||
* dns_rdataset_getheader() will return NULL, and the _KEEPCASE
|
|
||||||
* attribute is set to prevent setownercase and getownercase
|
|
||||||
* methods from affecting the case of NSEC/NSEC3 owner names.
|
|
||||||
*/
|
*/
|
||||||
dns__db_attachnode(db, node,
|
dns__db_attachnode(db, node,
|
||||||
&(dns_dbnode_t *){ NULL } DNS__DB_FLARG_PASS);
|
&(dns_dbnode_t *){ NULL } DNS__DB_FLARG_PASS);
|
||||||
@@ -1084,8 +1083,7 @@ rdataset_getnoqname(dns_rdataset_t *rdataset, dns_name_t *name,
|
|||||||
.slab.raw = noqname->neg,
|
.slab.raw = noqname->neg,
|
||||||
.link = nsec->link,
|
.link = nsec->link,
|
||||||
.count = nsec->count,
|
.count = nsec->count,
|
||||||
.attributes = nsec->attributes | DNS_RDATASETATTR_KEEPCASE |
|
.attributes = nsec->attributes | DNS_RDATASETATTR_KEEPCASE,
|
||||||
DNS_RDATASETATTR_NOHEADER,
|
|
||||||
.magic = nsec->magic,
|
.magic = nsec->magic,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1103,8 +1101,7 @@ rdataset_getnoqname(dns_rdataset_t *rdataset, dns_name_t *name,
|
|||||||
.slab.raw = noqname->negsig,
|
.slab.raw = noqname->negsig,
|
||||||
.link = nsecsig->link,
|
.link = nsecsig->link,
|
||||||
.count = nsecsig->count,
|
.count = nsecsig->count,
|
||||||
.attributes = nsecsig->attributes | DNS_RDATASETATTR_KEEPCASE |
|
.attributes = nsecsig->attributes | DNS_RDATASETATTR_KEEPCASE,
|
||||||
DNS_RDATASETATTR_NOHEADER,
|
|
||||||
.magic = nsecsig->magic,
|
.magic = nsecsig->magic,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1139,8 +1136,7 @@ rdataset_getclosest(dns_rdataset_t *rdataset, dns_name_t *name,
|
|||||||
.slab.raw = closest->neg,
|
.slab.raw = closest->neg,
|
||||||
.link = nsec->link,
|
.link = nsec->link,
|
||||||
.count = nsec->count,
|
.count = nsec->count,
|
||||||
.attributes = nsec->attributes | DNS_RDATASETATTR_KEEPCASE |
|
.attributes = nsec->attributes | DNS_RDATASETATTR_KEEPCASE,
|
||||||
DNS_RDATASETATTR_NOHEADER,
|
|
||||||
.magic = nsec->magic,
|
.magic = nsec->magic,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1158,8 +1154,7 @@ rdataset_getclosest(dns_rdataset_t *rdataset, dns_name_t *name,
|
|||||||
.slab.raw = closest->negsig,
|
.slab.raw = closest->negsig,
|
||||||
.link = nsecsig->link,
|
.link = nsecsig->link,
|
||||||
.count = nsecsig->count,
|
.count = nsecsig->count,
|
||||||
.attributes = nsecsig->attributes | DNS_RDATASETATTR_KEEPCASE |
|
.attributes = nsecsig->attributes | DNS_RDATASETATTR_KEEPCASE,
|
||||||
DNS_RDATASETATTR_NOHEADER,
|
|
||||||
.magic = nsecsig->magic,
|
.magic = nsecsig->magic,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user