rdataslab.c revision 4a4066453f45c869fc9f91d9807b7b8b25b004a0
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * Copyright (C) 2004-2011 Internet Systems Consortium, Inc. ("ISC")
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * Copyright (C) 1999-2003 Internet Software Consortium.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * Permission to use, copy, modify, and/or distribute this software for any
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * purpose with or without fee is hereby granted, provided that the above
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * copyright notice and this permission notice appear in all copies.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * PERFORMANCE OF THIS SOFTWARE.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy/* $Id: rdataslab.c,v 1.55 2011/12/20 00:55:01 marka Exp $ */
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#include <isc/string.h> /* Required for HP/UX (and others?) */
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * The rdataslab structure allows iteration to occur in both load order
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * and DNSSEC order. The structure is as follows:
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * header (reservelen bytes)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * record count (2 bytes)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * offset table (4 x record count bytes in load order)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * data records
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * data length (2 bytes)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * order (2 bytes)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * meta data (1 byte for RRSIG's)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * data (data length bytes)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * If DNS_RDATASET_FIXED is defined to be zero (0) the format of a
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * rdataslab is as follows:
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * header (reservelen bytes)
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy * record count (2 bytes)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * data records
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * data length (2 bytes)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * meta data (1 byte for RRSIG's)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * data (data length bytes)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * Offsets are from the end of the header.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * Load order traversal is performed by walking the offset table to find
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy * the start of the record (DNS_RDATASET_FIXED = 1).
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * DNSSEC order traversal is performed by walking the data records.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * The order is stored with record to allow for efficient reconstruction
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy * of the offset table following a merge or subtraction.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy * The iterator methods here currently only support DNSSEC order iteration.
* rbtdb.c directly interacts with the slab's raw structures. If the
* structure changes then rbtdb.c also needs to be updated to reflect
struct xrdata {
unsigned int order;
unsigned length)
unsigned char *raw;
for (i = 0, j = 0; i < length; i++) {
if (offsettable[i] == 0)
struct xrdata *x;
unsigned char *rawbuf;
unsigned char *offsetbase;
unsigned int buflen;
unsigned int nitems;
unsigned int nalloc;
unsigned int *offsettable;
unsigned int length;
return (ISC_R_FAILURE);
return (ISC_R_NOSPACE);
if (nalloc != 0) {
if (x == NULL)
return (ISC_R_NOMEMORY);
x = NULL;
goto free_rdatas;
x[i].order = i;
goto free_rdatas;
if (i != nalloc) {
goto free_rdatas;
nitems--;
buflen++;
if (nalloc != 0) {
buflen++;
goto free_rdatas;
goto free_rdatas;
goto free_rdatas;
for (i = 0; i < nalloc; i++) {
length++;
if (x != NULL)
return (result);
static isc_result_t
unsigned int count;
if (count == 0) {
return (ISC_R_NOMORE);
count--;
return (ISC_R_SUCCESS);
static isc_result_t
unsigned int count;
unsigned int length;
unsigned char *raw;
if (count == 0)
return (ISC_R_NOMORE);
count--;
return (ISC_R_SUCCESS);
isc_region_t r;
unsigned int length;
unsigned int flags = 0;
length--;
raw++;
unsigned int count;
return (count);
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
unsigned char *current;
while (count > 0) {
count--;
unsigned int length;
length--;
tcurrent++;
if (offline)
static inline isc_boolean_t
unsigned int count, i;
unsigned char *current;
for (i = 0; i < count; i++) {
return (ISC_TRUE);
return (ISC_FALSE);
unsigned int oadded = 0;
unsigned int nadded = 0;
unsigned int nncount = 0;
unsigned int oncount;
unsigned int norder = 0;
unsigned int oorder = 0;
unsigned char *offsetbase;
unsigned int *offsettable;
olength = 0;
tlength++;
tcount++;
nncount++;
ncount--;
} while (ncount > 0);
return (DNS_R_NOTEXACT);
return (DNS_R_UNCHANGED);
return (DNS_R_SINGLETON);
return (ISC_R_NOSPACE);
return (ISC_R_NOMEMORY);
return (ISC_R_NOMEMORY);
if (ncount > 0) {
if (fromold) {
length++;
data--;
oadded++;
&ordata);
length++;
data--;
nadded++;
&nrdata));
return (ISC_R_SUCCESS);
unsigned char *offsetbase;
unsigned int *offsettable;
unsigned int order;
tcount = 0;
rcount = 0;
for (i = 0; i < mcount; i++) {
tcount++;
rcount++;
return (DNS_R_NOTEXACT);
if (tcount == 0)
return (DNS_R_NXRRSET);
if (rcount == 0)
return (DNS_R_UNCHANGED);
return (ISC_R_NOMEMORY);
return (ISC_R_NOMEMORY);
for (i = 0; i < mcount; i++) {
return (ISC_R_SUCCESS);
unsigned int reservelen)
return (ISC_FALSE);
while (count1 > 0) {
return (ISC_FALSE);
count1--;
return (ISC_TRUE);
return (ISC_FALSE);
while (count1-- > 0) {
return (ISC_FALSE);
return (ISC_TRUE);