rdataslab.c revision d76ed813a51465e5c47d521ab09ea20c06f1428d
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Hunt * Copyright (C) 1999-2003 Internet Software Consortium.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Permission to use, copy, modify, and distribute this software for any
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * purpose with or without fee is hereby granted, provided that the above
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Hunt * copyright notice and this permission notice appear in all copies.
6715db6593ce9a271ac3131cd7a886feaa386a2eEvan Hunt * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Hunt * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt * PERFORMANCE OF THIS SOFTWARE.
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Hunt/* $Id: rdataslab.c,v 1.39 2006/03/03 00:43:35 marka Exp $ */
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Hunt#include <isc/string.h> /* Required for HP/UX (and others?) */
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Hunt * The rdataslab structure allows iteration to occur in both load order
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Hunt * and DNSSEC order. The structure is as follows:
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Hunt * header (reservelen bytes)
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Hunt * record count (2 bytes)
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt * offset table (4 x record count bytes in load order)
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Hunt * data records
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt * data length (2 bytes)
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt * order (2 bytes)
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Hunt * data (data length bytes)
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Hunt * Offsets are from the end of the header.
30eec077db2bdcb6f2a0dc388a3cdde2ede75ec1Mark Andrews * Load order traversal is performed by walking the offset table to find
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Hunt * the start of the record.
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Hunt * DNSSEC order traversal is performed by walking the data records.
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Hunt * The order is stored with record to allow for efficient reconstuction of
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Hunt * of the offset table following a merge or subtraction.
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Hunt * The iterator methods here currently only support DNSSEC order iteration.
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Hunt * The iterator methods in rbtdb support both load order and DNSSEC order
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Hunt * iteration.
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Hunt * rbtdb.c directly interacts with the slab's raw structures. If the
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Hunt * structure changes then rbtdb.c also needs to be updated to reflect
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Hunt * the changes. See the areas tagged with "RDATASLAB".
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Hunt unsigned int order;
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt/*% Note: the "const void *" are just to make qsort happy. */
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Hunt return (dns_rdata_compare(&x1->rdata, &x2->rdata));
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Huntfillin_offsets(unsigned char *offsetbase, unsigned int *offsettable,
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt unsigned int i, j;
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Hunt unsigned char *raw;
30eec077db2bdcb6f2a0dc388a3cdde2ede75ec1Mark Andrews for (i = 0, j = 0; i < length; i++) {
0f66aced2640d964aeb6db41210711ba0640d7f2Evan Hunt * Fill in offset table.
struct xrdata *x;
unsigned char *rawbuf;
unsigned char *offsetbase;
unsigned int buflen;
unsigned int nitems;
unsigned int nalloc;
unsigned int *offsettable;
if (nitems == 0)
return (ISC_R_FAILURE);
return (ISC_R_NOSPACE);
if (x == NULL)
return (ISC_R_NOMEMORY);
goto free_rdatas;
x[i].order = i;
goto free_rdatas;
if (i != nalloc) {
goto free_rdatas;
nitems--;
goto free_rdatas;
goto free_rdatas;
goto free_rdatas;
for (i = 0; i < nalloc; i++) {
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 count;
return (count);
NULL,
NULL,
NULL,
NULL,
unsigned char *current;
while (count > 0) {
count--;
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;
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) {
oadded++;
&ordata);
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);