Commit 4edbb773 authored by Ondřej Surý's avatar Ondřej Surý
Browse files

Refactor the DNS_RDATASET_FIXED code to use constants instead of ifdefs

parent 87daa547
Pipeline #13532 passed with stages
in 11 minutes and 9 seconds
...@@ -754,6 +754,17 @@ hexdump(const char *desc, unsigned char *data, size_t size) { ...@@ -754,6 +754,17 @@ hexdump(const char *desc, unsigned char *data, size_t size) {
} }
#endif #endif
/* Fixed RRSet helper macros */
#define DNS_RDATASET_LENGTH 2;
#if DNS_RDATASET_FIXED
#define DNS_RDATASET_ORDER 2
#define DNS_RDATASET_COUNT (count * 4)
#else /* !DNS_RDATASET_FIXED */
#define DNS_RDATASET_ORDER 0
#define DNS_RDATASET_COUNT 0
#endif /* DNS_RDATASET_FIXED */
/* /*
* DB Routines * DB Routines
...@@ -2288,18 +2299,10 @@ setnsec3parameters(dns_db_t *db, rbtdb_version_t *version) { ...@@ -2288,18 +2299,10 @@ setnsec3parameters(dns_db_t *db, rbtdb_version_t *version) {
*/ */
raw = (unsigned char *)header + sizeof(*header); raw = (unsigned char *)header + sizeof(*header);
count = raw[0] * 256 + raw[1]; /* count */ count = raw[0] * 256 + raw[1]; /* count */
#if DNS_RDATASET_FIXED raw += DNS_RDATASET_COUNT + DNS_RDATASET_LENGTH;
raw += count * 4 + 2;
#else
raw += 2;
#endif
while (count-- > 0U) { while (count-- > 0U) {
length = raw[0] * 256 + raw[1]; length = raw[0] * 256 + raw[1];
#if DNS_RDATASET_FIXED raw += DNS_RDATASET_ORDER + DNS_RDATASET_LENGTH;
raw += 4;
#else
raw += 2;
#endif
region.base = raw; region.base = raw;
region.length = length; region.length = length;
raw += length; raw += length;
...@@ -3105,20 +3108,12 @@ valid_glue(rbtdb_search_t *search, dns_name_t *name, rbtdb_rdatatype_t type, ...@@ -3105,20 +3108,12 @@ valid_glue(rbtdb_search_t *search, dns_name_t *name, rbtdb_rdatatype_t type,
header = search->zonecut_rdataset; header = search->zonecut_rdataset;
raw = (unsigned char *)header + sizeof(*header); raw = (unsigned char *)header + sizeof(*header);
count = raw[0] * 256 + raw[1]; count = raw[0] * 256 + raw[1];
#if DNS_RDATASET_FIXED raw += DNS_RDATASET_COUNT + DNS_RDATASET_LENGTH;
raw += 2 + (4 * count);
#else
raw += 2;
#endif
while (count > 0) { while (count > 0) {
count--; count--;
size = raw[0] * 256 + raw[1]; size = raw[0] * 256 + raw[1];
#if DNS_RDATASET_FIXED raw += DNS_RDATASET_ORDER + DNS_RDATASET_LENGTH;
raw += 4;
#else
raw += 2;
#endif
region.base = raw; region.base = raw;
region.length = size; region.length = size;
raw += size; raw += size;
...@@ -3470,18 +3465,11 @@ matchparams(rdatasetheader_t *header, rbtdb_search_t *search) ...@@ -3470,18 +3465,11 @@ matchparams(rdatasetheader_t *header, rbtdb_search_t *search)
raw = (unsigned char *)header + sizeof(*header); raw = (unsigned char *)header + sizeof(*header);
count = raw[0] * 256 + raw[1]; /* count */ count = raw[0] * 256 + raw[1]; /* count */
#if DNS_RDATASET_FIXED raw += DNS_RDATASET_COUNT + DNS_RDATASET_LENGTH;
raw += count * 4 + 2;
#else
raw += 2;
#endif
while (count-- > 0) { while (count-- > 0) {
rdlen = raw[0] * 256 + raw[1]; rdlen = raw[0] * 256 + raw[1];
#if DNS_RDATASET_FIXED raw += DNS_RDATASET_ORDER + DNS_RDATASET_LENGTH;
raw += 4;
#else
raw += 2;
#endif
region.base = raw; region.base = raw;
region.length = rdlen; region.length = rdlen;
dns_rdata_fromregion(&rdata, search->rbtdb->common.rdclass, dns_rdata_fromregion(&rdata, search->rbtdb->common.rdclass,
...@@ -8435,12 +8423,11 @@ rdataset_first(dns_rdataset_t *rdataset) { ...@@ -8435,12 +8423,11 @@ rdataset_first(dns_rdataset_t *rdataset) {
return (ISC_R_NOMORE); return (ISC_R_NOMORE);
} }
#if DNS_RDATASET_FIXED if ((rdataset->attributes & DNS_RDATASETATTR_LOADORDER) == 0) {
if ((rdataset->attributes & DNS_RDATASETATTR_LOADORDER) == 0) raw += DNS_RDATASET_COUNT;
raw += 2 + (4 * count); }
else
#endif raw += DNS_RDATASET_LENGTH;
raw += 2;
/* /*
* The privateuint4 field is the number of rdata beyond the * The privateuint4 field is the number of rdata beyond the
...@@ -8475,16 +8462,14 @@ rdataset_next(dns_rdataset_t *rdataset) { ...@@ -8475,16 +8462,14 @@ rdataset_next(dns_rdataset_t *rdataset) {
*/ */
raw = rdataset->private5; raw = rdataset->private5;
#if DNS_RDATASET_FIXED #if DNS_RDATASET_FIXED
if ((rdataset->attributes & DNS_RDATASETATTR_LOADORDER) == 0) { if ((rdataset->attributes & DNS_RDATASETATTR_LOADORDER) == 0)
#endif #endif /* DNS_RDATASET_FIXED */
{
length = raw[0] * 256 + raw[1]; length = raw[0] * 256 + raw[1];
raw += length; raw += length;
#if DNS_RDATASET_FIXED
} }
rdataset->private5 = raw + 4; /* length(2) + order(2) */
#else rdataset->private5 = raw + DNS_RDATASET_ORDER + DNS_RDATASET_LENGTH;
rdataset->private5 = raw + 2; /* length(2) */
#endif
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
} }
...@@ -8492,9 +8477,6 @@ rdataset_next(dns_rdataset_t *rdataset) { ...@@ -8492,9 +8477,6 @@ rdataset_next(dns_rdataset_t *rdataset) {
static void static void
rdataset_current(dns_rdataset_t *rdataset, dns_rdata_t *rdata) { rdataset_current(dns_rdataset_t *rdataset, dns_rdata_t *rdata) {
unsigned char *raw = rdataset->private5; /* RDATASLAB */ unsigned char *raw = rdataset->private5; /* RDATASLAB */
#if DNS_RDATASET_FIXED
unsigned int offset;
#endif
unsigned int length; unsigned int length;
isc_region_t r; isc_region_t r;
unsigned int flags = 0; unsigned int flags = 0;
...@@ -8507,18 +8489,18 @@ rdataset_current(dns_rdataset_t *rdataset, dns_rdata_t *rdata) { ...@@ -8507,18 +8489,18 @@ rdataset_current(dns_rdataset_t *rdataset, dns_rdata_t *rdata) {
*/ */
#if DNS_RDATASET_FIXED #if DNS_RDATASET_FIXED
if ((rdataset->attributes & DNS_RDATASETATTR_LOADORDER) != 0) { if ((rdataset->attributes & DNS_RDATASETATTR_LOADORDER) != 0) {
unsigned int offset;
offset = (raw[0] << 24) + (raw[1] << 16) + offset = (raw[0] << 24) + (raw[1] << 16) +
(raw[2] << 8) + raw[3]; (raw[2] << 8) + raw[3];
raw = rdataset->private3; raw = rdataset->private3;
raw += offset; raw += offset;
} }
#endif #endif
length = raw[0] * 256 + raw[1]; length = raw[0] * 256 + raw[1];
#if DNS_RDATASET_FIXED
raw += 4; raw += DNS_RDATASET_ORDER + DNS_RDATASET_LENGTH;
#else
raw += 2;
#endif
if (rdataset->type == dns_rdatatype_rrsig) { if (rdataset->type == dns_rdatatype_rrsig) {
if (*raw & DNS_RDATASLAB_OFFLINE) if (*raw & DNS_RDATASLAB_OFFLINE)
flags |= DNS_RDATA_OFFLINE; flags |= DNS_RDATA_OFFLINE;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment