1999-01-27 08:44:10 +00:00
|
|
|
/*
|
2000-02-03 23:50:32 +00:00
|
|
|
* Copyright (C) 1999, 2000 Internet Software Consortium.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
1999-01-27 08:44:10 +00:00
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2000-07-27 09:55:03 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
|
|
|
|
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
|
|
|
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
|
|
|
|
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
1999-01-27 08:44:10 +00:00
|
|
|
*/
|
|
|
|
|
2000-11-30 23:59:08 +00:00
|
|
|
/* $Id: rdataslab.c,v 1.26 2000/11/30 23:59:08 marka Exp $ */
|
1999-01-27 08:44:10 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2000-09-01 01:35:21 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <isc/mem.h>
|
1999-01-27 08:44:10 +00:00
|
|
|
#include <isc/region.h>
|
2000-05-08 19:23:32 +00:00
|
|
|
#include <isc/string.h> /* Required for HP/UX (and others?) */
|
2000-04-28 01:12:23 +00:00
|
|
|
#include <isc/util.h>
|
1999-01-27 08:44:10 +00:00
|
|
|
|
|
|
|
#include <dns/result.h>
|
|
|
|
#include <dns/rdata.h>
|
|
|
|
#include <dns/rdataset.h>
|
|
|
|
#include <dns/rdataslab.h>
|
|
|
|
|
2000-09-01 01:35:21 +00:00
|
|
|
/* Note: the "const void *" are just to make qsort happy. */
|
|
|
|
static int
|
|
|
|
compare_rdata(const void *p1, const void *p2) {
|
|
|
|
const dns_rdata_t *rdata1 = p1;
|
|
|
|
const dns_rdata_t *rdata2 = p2;
|
2000-09-23 01:05:03 +00:00
|
|
|
return (dns_rdata_compare(rdata1, rdata2));
|
2000-09-01 01:35:21 +00:00
|
|
|
}
|
|
|
|
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t
|
1999-01-27 08:44:10 +00:00
|
|
|
dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx,
|
|
|
|
isc_region_t *region, unsigned int reservelen)
|
|
|
|
{
|
2000-09-01 01:35:21 +00:00
|
|
|
dns_rdata_t *rdatas;
|
1999-01-27 08:44:10 +00:00
|
|
|
unsigned char *rawbuf;
|
|
|
|
unsigned int buflen;
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t result;
|
1999-01-27 08:44:10 +00:00
|
|
|
unsigned int nitems;
|
2000-09-01 01:35:21 +00:00
|
|
|
unsigned int nalloc;
|
|
|
|
unsigned int i;
|
1999-01-27 08:44:10 +00:00
|
|
|
|
|
|
|
buflen = reservelen + 2;
|
2000-09-01 01:35:21 +00:00
|
|
|
|
|
|
|
nalloc = dns_rdataset_count(rdataset);
|
|
|
|
nitems = nalloc;
|
2000-11-22 00:18:34 +00:00
|
|
|
if (nitems == 0)
|
|
|
|
return (ISC_R_FAILURE);
|
2000-09-01 01:35:21 +00:00
|
|
|
|
|
|
|
rdatas = isc_mem_get(mctx, nalloc * sizeof(dns_rdata_t));
|
|
|
|
if (rdatas == NULL)
|
|
|
|
return (ISC_R_NOMEMORY);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Save all of the rdata members into an array.
|
|
|
|
*/
|
2000-09-01 16:37:30 +00:00
|
|
|
result = dns_rdataset_first(rdataset);
|
2000-11-22 00:18:34 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto free_rdatas;
|
|
|
|
for (i = 0; i < nalloc && result == ISC_R_SUCCESS; i++) {
|
2000-09-01 01:35:21 +00:00
|
|
|
INSIST(result == ISC_R_SUCCESS);
|
2000-10-25 04:26:57 +00:00
|
|
|
dns_rdata_init(&rdatas[i]);
|
2000-09-01 01:35:21 +00:00
|
|
|
dns_rdataset_current(rdataset, &rdatas[i]);
|
|
|
|
result = dns_rdataset_next(rdataset);
|
|
|
|
}
|
2000-11-22 00:18:34 +00:00
|
|
|
if (result != ISC_R_NOMORE)
|
|
|
|
goto free_rdatas;
|
|
|
|
if (i != nalloc) {
|
|
|
|
/*
|
|
|
|
* Somehow we iterated over fewer rdatas than
|
|
|
|
* dns_rdataset_count() said there were!
|
|
|
|
*/
|
|
|
|
result = ISC_R_FAILURE;
|
|
|
|
goto free_rdatas;
|
|
|
|
}
|
2000-09-01 01:35:21 +00:00
|
|
|
|
|
|
|
qsort(rdatas, nalloc, sizeof(dns_rdata_t), compare_rdata);
|
|
|
|
|
|
|
|
/*
|
2000-11-22 00:18:34 +00:00
|
|
|
* Remove duplicates and compute the total storage required.
|
|
|
|
*
|
|
|
|
* If an rdata is not a duplicate, accumulate the storage size
|
|
|
|
* required for the rdata. We do not store the class, type, etc,
|
|
|
|
* just the rdata, so our overhead is 2 bytes for the number of
|
|
|
|
* records, and 2 for each rdata length, and then the rdata itself.
|
2000-09-01 01:35:21 +00:00
|
|
|
*/
|
|
|
|
for (i = 1; i < nalloc; i++) {
|
|
|
|
if (compare_rdata(&rdatas[i-1], &rdatas[i]) == 0) {
|
|
|
|
rdatas[i-1].data = NULL;
|
|
|
|
rdatas[i-1].length = 0;
|
|
|
|
nitems--;
|
2000-11-22 00:18:34 +00:00
|
|
|
} else
|
|
|
|
buflen += (2 + rdatas[i-1].length);
|
2000-09-01 01:35:21 +00:00
|
|
|
}
|
1999-01-27 08:44:10 +00:00
|
|
|
/*
|
2000-11-22 00:18:34 +00:00
|
|
|
* Don't forget the last item!
|
1999-01-27 08:44:10 +00:00
|
|
|
*/
|
2000-11-22 00:18:34 +00:00
|
|
|
buflen += (2 + rdatas[i-1].length);
|
1999-01-27 08:44:10 +00:00
|
|
|
|
2000-11-22 00:18:34 +00:00
|
|
|
/*
|
2000-11-22 01:55:38 +00:00
|
|
|
* Ensure that singleton types are actually singletons.
|
2000-11-22 00:18:34 +00:00
|
|
|
*/
|
|
|
|
if (nitems > 1 && dns_rdatatype_issingleton(rdataset->type)) {
|
|
|
|
/*
|
|
|
|
* We have a singleton type, but there's more than one
|
|
|
|
* RR in the rdataset.
|
|
|
|
*/
|
|
|
|
result = DNS_R_SINGLETON;
|
|
|
|
goto free_rdatas;
|
2000-09-01 01:35:21 +00:00
|
|
|
}
|
1999-01-27 08:44:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate the memory, set up a buffer, start copying in
|
|
|
|
* data.
|
|
|
|
*/
|
|
|
|
rawbuf = isc_mem_get(mctx, buflen);
|
2000-09-01 01:35:21 +00:00
|
|
|
if (rawbuf == NULL) {
|
2000-09-01 19:59:35 +00:00
|
|
|
result = ISC_R_NOMEMORY;
|
|
|
|
goto free_rdatas;
|
2000-09-01 01:35:21 +00:00
|
|
|
}
|
1999-01-27 08:44:10 +00:00
|
|
|
|
|
|
|
region->base = rawbuf;
|
|
|
|
region->length = buflen;
|
|
|
|
|
|
|
|
rawbuf += reservelen;
|
|
|
|
|
|
|
|
*rawbuf++ = (nitems & 0xff00) >> 8;
|
|
|
|
*rawbuf++ = (nitems & 0x00ff);
|
2000-09-01 01:35:21 +00:00
|
|
|
for (i = 0; i < nalloc; i++) {
|
|
|
|
if (rdatas[i].data == NULL)
|
|
|
|
continue;
|
|
|
|
*rawbuf++ = (rdatas[i].length & 0xff00) >> 8;
|
|
|
|
*rawbuf++ = (rdatas[i].length & 0x00ff);
|
|
|
|
memcpy(rawbuf, rdatas[i].data, rdatas[i].length);
|
|
|
|
rawbuf += rdatas[i].length;
|
1999-01-27 08:44:10 +00:00
|
|
|
}
|
2000-09-01 19:59:35 +00:00
|
|
|
result = ISC_R_SUCCESS;
|
1999-01-27 08:44:10 +00:00
|
|
|
|
2000-09-01 19:59:35 +00:00
|
|
|
free_rdatas:
|
2000-09-01 01:35:21 +00:00
|
|
|
isc_mem_put(mctx, rdatas, nalloc * sizeof(dns_rdata_t));
|
2000-09-01 19:59:35 +00:00
|
|
|
return (result);
|
1999-01-27 08:44:10 +00:00
|
|
|
}
|
|
|
|
|
1999-02-06 00:07:09 +00:00
|
|
|
unsigned int
|
|
|
|
dns_rdataslab_size(unsigned char *slab, unsigned int reservelen) {
|
|
|
|
unsigned int count, length;
|
|
|
|
unsigned char *current;
|
|
|
|
|
|
|
|
REQUIRE(slab != NULL);
|
|
|
|
|
|
|
|
current = slab + reservelen;
|
|
|
|
count = *current++ * 256;
|
|
|
|
count += *current++;
|
|
|
|
while (count > 0) {
|
|
|
|
count--;
|
|
|
|
length = *current++ * 256;
|
|
|
|
length += *current++;
|
|
|
|
current += length;
|
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-02-06 00:07:09 +00:00
|
|
|
return ((unsigned int)(current - slab));
|
1999-01-27 08:44:10 +00:00
|
|
|
}
|
1999-04-01 04:00:39 +00:00
|
|
|
|
2000-09-01 19:59:35 +00:00
|
|
|
/*
|
|
|
|
* Make the dns_rdata_t 'rdata' refer to the slab item
|
|
|
|
* beginning at '*current', which is part of a slab of type
|
|
|
|
* 'type' and class 'rdclass', and advance '*current' to
|
|
|
|
* point to the next item in the slab.
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
rdata_from_slab(unsigned char **current,
|
|
|
|
dns_rdataclass_t rdclass, dns_rdatatype_t type,
|
|
|
|
dns_rdata_t *rdata)
|
|
|
|
{
|
|
|
|
unsigned char *tcurrent = *current;
|
|
|
|
isc_region_t region;
|
|
|
|
|
|
|
|
region.length = *tcurrent++ * 256;
|
|
|
|
region.length += *tcurrent++;
|
|
|
|
region.base = tcurrent;
|
|
|
|
tcurrent += region.length;
|
|
|
|
dns_rdata_fromregion(rdata, rdclass, type, ®ion);
|
|
|
|
*current = tcurrent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return true iff 'slab' (slab data of type 'type' and class 'rdclass')
|
|
|
|
* contains an rdata identical to 'rdata'. This does case insensitive
|
|
|
|
* comparisons per DNSSEC.
|
|
|
|
*/
|
2000-09-01 01:35:21 +00:00
|
|
|
static inline isc_boolean_t
|
|
|
|
rdata_in_slab(unsigned char *slab, unsigned int reservelen,
|
|
|
|
dns_rdataclass_t rdclass, dns_rdatatype_t type,
|
|
|
|
dns_rdata_t *rdata)
|
|
|
|
{
|
|
|
|
unsigned int count, i;
|
|
|
|
unsigned char *current;
|
2000-10-25 04:26:57 +00:00
|
|
|
dns_rdata_t trdata = DNS_RDATA_INIT;
|
2000-09-01 01:35:21 +00:00
|
|
|
|
|
|
|
current = slab + reservelen;
|
|
|
|
count = *current++ * 256;
|
|
|
|
count += *current++;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
2000-09-01 19:59:35 +00:00
|
|
|
rdata_from_slab(¤t, rdclass, type, &trdata);
|
2000-09-01 01:35:21 +00:00
|
|
|
if (dns_rdata_compare(&trdata, rdata) == 0)
|
|
|
|
return (ISC_TRUE);
|
2000-10-31 03:22:05 +00:00
|
|
|
dns_rdata_reset(&trdata);
|
2000-09-01 01:35:21 +00:00
|
|
|
}
|
|
|
|
return (ISC_FALSE);
|
|
|
|
}
|
|
|
|
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t
|
1999-04-01 04:00:39 +00:00
|
|
|
dns_rdataslab_merge(unsigned char *oslab, unsigned char *nslab,
|
|
|
|
unsigned int reservelen, isc_mem_t *mctx,
|
|
|
|
dns_rdataclass_t rdclass, dns_rdatatype_t type,
|
2000-11-30 23:59:08 +00:00
|
|
|
unsigned int flags, unsigned char **tslabp)
|
1999-04-01 04:00:39 +00:00
|
|
|
{
|
|
|
|
unsigned char *ocurrent, *ostart, *ncurrent, *tstart, *tcurrent;
|
|
|
|
unsigned int ocount, ncount, count, olength, tlength, tcount, length;
|
2000-09-01 01:35:21 +00:00
|
|
|
isc_region_t nregion;
|
2000-10-25 04:26:57 +00:00
|
|
|
dns_rdata_t ordata = DNS_RDATA_INIT;
|
|
|
|
dns_rdata_t nrdata = DNS_RDATA_INIT;
|
1999-06-16 21:03:07 +00:00
|
|
|
isc_boolean_t added_something = ISC_FALSE;
|
2000-09-01 01:35:21 +00:00
|
|
|
unsigned int oadded = 0;
|
|
|
|
unsigned int nadded = 0;
|
|
|
|
unsigned int nncount = 0;
|
1999-04-01 04:00:39 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX Need parameter to allow "delete rdatasets in nslab" merge,
|
|
|
|
* or perhaps another merge routine for this purpose.
|
|
|
|
*/
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-04-01 04:00:39 +00:00
|
|
|
REQUIRE(tslabp != NULL && *tslabp == NULL);
|
|
|
|
REQUIRE(oslab != NULL && nslab != NULL);
|
2000-11-30 23:59:08 +00:00
|
|
|
REQUIRE((flags & (DNS_RDATASLAB_FORCE|DNS_RDATASLAB_EXACT)) !=
|
|
|
|
(DNS_RDATASLAB_FORCE|DNS_RDATASLAB_EXACT));
|
1999-04-01 04:00:39 +00:00
|
|
|
|
|
|
|
ocurrent = oslab + reservelen;
|
|
|
|
ocount = *ocurrent++ * 256;
|
|
|
|
ocount += *ocurrent++;
|
|
|
|
ostart = ocurrent;
|
|
|
|
ncurrent = nslab + reservelen;
|
|
|
|
ncount = *ncurrent++ * 256;
|
|
|
|
ncount += *ncurrent++;
|
|
|
|
INSIST(ocount > 0 && ncount > 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Yes, this is inefficient!
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Figure out the length of the old slab's data.
|
|
|
|
*/
|
|
|
|
olength = 0;
|
|
|
|
for (count = 0; count < ocount; count++) {
|
|
|
|
length = *ocurrent++ * 256;
|
|
|
|
length += *ocurrent++;
|
|
|
|
olength += length + 2;
|
|
|
|
ocurrent += length;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start figuring out the target length and count.
|
|
|
|
*/
|
|
|
|
tlength = reservelen + 2 + olength;
|
|
|
|
tcount = ocount;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add in the length of rdata in the new slab that aren't in
|
|
|
|
* the old slab.
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
nregion.length = *ncurrent++ * 256;
|
|
|
|
nregion.length += *ncurrent++;
|
|
|
|
nregion.base = ncurrent;
|
2000-10-25 04:26:57 +00:00
|
|
|
dns_rdata_init(&nrdata);
|
1999-04-01 04:00:39 +00:00
|
|
|
dns_rdata_fromregion(&nrdata, rdclass, type, &nregion);
|
2000-09-01 01:35:21 +00:00
|
|
|
if (!rdata_in_slab(oslab, reservelen, rdclass, type, &nrdata))
|
|
|
|
{
|
1999-04-01 04:00:39 +00:00
|
|
|
/*
|
|
|
|
* This rdata isn't in the old slab.
|
|
|
|
*/
|
|
|
|
tlength += nregion.length + 2;
|
|
|
|
tcount++;
|
2000-09-01 01:35:21 +00:00
|
|
|
nncount++;
|
1999-06-16 21:03:07 +00:00
|
|
|
added_something = ISC_TRUE;
|
1999-04-01 04:00:39 +00:00
|
|
|
}
|
|
|
|
ncurrent += nregion.length;
|
|
|
|
ncount--;
|
|
|
|
} while (ncount > 0);
|
2000-09-01 01:35:21 +00:00
|
|
|
ncount = nncount;
|
1999-04-01 04:00:39 +00:00
|
|
|
|
2000-11-30 23:59:08 +00:00
|
|
|
if ((flags & DNS_RDATASLAB_EXACT) != 0 &&
|
|
|
|
tcount != ncount + ocount)
|
|
|
|
return (DNS_R_NOTEXACT);
|
|
|
|
|
|
|
|
if (!added_something && (flags & DNS_RDATASLAB_FORCE) == 0)
|
1999-06-16 21:03:07 +00:00
|
|
|
return (DNS_R_UNCHANGED);
|
|
|
|
|
2000-11-22 01:55:38 +00:00
|
|
|
/*
|
|
|
|
* Ensure that singleton types are actually singletons.
|
|
|
|
*/
|
|
|
|
if (tcount > 1 && dns_rdatatype_issingleton(type)) {
|
|
|
|
/*
|
|
|
|
* We have a singleton type, but there's more than one
|
|
|
|
* RR in the rdataset.
|
|
|
|
*/
|
|
|
|
return (DNS_R_SINGLETON);
|
|
|
|
}
|
|
|
|
|
1999-04-01 04:00:39 +00:00
|
|
|
/*
|
|
|
|
* Copy the reserved area from the new slab.
|
|
|
|
*/
|
|
|
|
tstart = isc_mem_get(mctx, tlength);
|
|
|
|
if (tstart == NULL)
|
2000-04-06 22:03:35 +00:00
|
|
|
return (ISC_R_NOMEMORY);
|
1999-04-01 04:00:39 +00:00
|
|
|
memcpy(tstart, nslab, reservelen);
|
|
|
|
tcurrent = tstart + reservelen;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-04-01 04:00:39 +00:00
|
|
|
/*
|
|
|
|
* Write the new count.
|
|
|
|
*/
|
|
|
|
*tcurrent++ = (tcount & 0xff00) >> 8;
|
|
|
|
*tcurrent++ = (tcount & 0x00ff);
|
|
|
|
|
|
|
|
/*
|
2000-09-01 01:35:21 +00:00
|
|
|
* Merge the two slabs.
|
1999-04-01 04:00:39 +00:00
|
|
|
*/
|
2000-09-01 01:35:21 +00:00
|
|
|
ocurrent = ostart;
|
2000-09-01 19:59:35 +00:00
|
|
|
INSIST(ocount != 0);
|
|
|
|
rdata_from_slab(&ocurrent, rdclass, type, &ordata);
|
2000-09-01 01:35:21 +00:00
|
|
|
|
|
|
|
ncurrent = nslab + reservelen + 2;
|
|
|
|
if (ncount > 0) {
|
|
|
|
do {
|
2000-10-31 03:22:05 +00:00
|
|
|
dns_rdata_reset(&nrdata);
|
2000-09-01 01:35:21 +00:00
|
|
|
rdata_from_slab(&ncurrent, rdclass, type, &nrdata);
|
|
|
|
} while (rdata_in_slab(oslab, reservelen, rdclass,
|
|
|
|
type, &nrdata));
|
|
|
|
}
|
1999-04-01 04:00:39 +00:00
|
|
|
|
2000-09-01 01:35:21 +00:00
|
|
|
while (oadded < ocount || nadded < ncount) {
|
|
|
|
isc_boolean_t fromold;
|
|
|
|
if (oadded == ocount)
|
|
|
|
fromold = ISC_FALSE;
|
|
|
|
else if (nadded == ncount)
|
|
|
|
fromold = ISC_TRUE;
|
|
|
|
else
|
|
|
|
fromold = ISC_TF(compare_rdata(&ordata, &nrdata) < 0);
|
|
|
|
if (fromold) {
|
|
|
|
length = ordata.length;
|
|
|
|
*tcurrent++ = (length & 0xff00) >> 8;
|
|
|
|
*tcurrent++ = (length & 0x00ff);
|
|
|
|
memcpy(tcurrent, ordata.data, length);
|
|
|
|
tcurrent += length;
|
|
|
|
oadded++;
|
|
|
|
if (oadded < ocount) {
|
2000-10-31 03:22:05 +00:00
|
|
|
dns_rdata_reset(&ordata);
|
2000-09-01 01:35:21 +00:00
|
|
|
rdata_from_slab(&ocurrent, rdclass, type,
|
|
|
|
&ordata);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
length = nrdata.length;
|
|
|
|
*tcurrent++ = (length & 0xff00) >> 8;
|
|
|
|
*tcurrent++ = (length & 0x00ff);
|
|
|
|
memcpy(tcurrent, nrdata.data, length);
|
|
|
|
tcurrent += length;
|
|
|
|
nadded++;
|
|
|
|
if (nadded < ncount) {
|
|
|
|
do {
|
2000-10-31 03:22:05 +00:00
|
|
|
dns_rdata_reset(&nrdata);
|
2000-09-01 01:35:21 +00:00
|
|
|
rdata_from_slab(&ncurrent, rdclass,
|
|
|
|
type, &nrdata);
|
|
|
|
} while (rdata_in_slab(oslab, reservelen,
|
|
|
|
rdclass, type,
|
|
|
|
&nrdata));
|
|
|
|
}
|
1999-04-01 04:00:39 +00:00
|
|
|
}
|
2000-09-01 01:35:21 +00:00
|
|
|
}
|
1999-04-01 04:00:39 +00:00
|
|
|
|
2000-09-01 19:59:35 +00:00
|
|
|
INSIST(tcurrent == tstart + tlength);
|
|
|
|
|
1999-04-01 04:00:39 +00:00
|
|
|
*tslabp = tstart;
|
|
|
|
|
2000-04-06 22:03:35 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-04-01 04:00:39 +00:00
|
|
|
}
|
1999-06-16 21:03:07 +00:00
|
|
|
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t
|
1999-06-16 21:03:07 +00:00
|
|
|
dns_rdataslab_subtract(unsigned char *mslab, unsigned char *sslab,
|
|
|
|
unsigned int reservelen, isc_mem_t *mctx,
|
|
|
|
dns_rdataclass_t rdclass, dns_rdatatype_t type,
|
2000-10-18 23:53:31 +00:00
|
|
|
isc_boolean_t exact, unsigned char **tslabp)
|
1999-06-16 21:03:07 +00:00
|
|
|
{
|
|
|
|
unsigned char *mcurrent, *sstart, *scurrent, *tstart, *tcurrent;
|
2000-10-18 23:53:31 +00:00
|
|
|
unsigned int mcount, scount, rcount ,count, tlength, tcount;
|
2000-10-25 04:26:57 +00:00
|
|
|
dns_rdata_t srdata = DNS_RDATA_INIT;
|
|
|
|
dns_rdata_t mrdata = DNS_RDATA_INIT;
|
1999-06-16 21:03:07 +00:00
|
|
|
|
|
|
|
REQUIRE(tslabp != NULL && *tslabp == NULL);
|
|
|
|
REQUIRE(mslab != NULL && sslab != NULL);
|
|
|
|
|
|
|
|
mcurrent = mslab + reservelen;
|
|
|
|
mcount = *mcurrent++ * 256;
|
|
|
|
mcount += *mcurrent++;
|
|
|
|
scurrent = sslab + reservelen;
|
|
|
|
scount = *scurrent++ * 256;
|
|
|
|
scount += *scurrent++;
|
|
|
|
sstart = scurrent;
|
1999-06-24 19:15:55 +00:00
|
|
|
INSIST(mcount > 0 && scount > 0);
|
1999-06-16 21:03:07 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Yes, this is inefficient!
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start figuring out the target length and count.
|
|
|
|
*/
|
|
|
|
tlength = reservelen + 2;
|
|
|
|
tcount = 0;
|
2000-10-18 23:53:31 +00:00
|
|
|
rcount = 0;
|
1999-06-16 21:03:07 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Add in the length of rdata in the mslab that aren't in
|
|
|
|
* the sslab.
|
|
|
|
*/
|
|
|
|
do {
|
2000-09-01 19:59:35 +00:00
|
|
|
unsigned char *mrdatabegin = mcurrent;
|
|
|
|
rdata_from_slab(&mcurrent, rdclass, type, &mrdata);
|
1999-06-16 21:03:07 +00:00
|
|
|
scurrent = sstart;
|
|
|
|
for (count = 0; count < scount; count++) {
|
2000-10-31 03:22:05 +00:00
|
|
|
dns_rdata_reset(&srdata);
|
2000-09-01 19:59:35 +00:00
|
|
|
rdata_from_slab(&scurrent, rdclass, type, &srdata);
|
1999-06-16 21:03:07 +00:00
|
|
|
if (dns_rdata_compare(&mrdata, &srdata) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (count == scount) {
|
|
|
|
/*
|
|
|
|
* This rdata isn't in the sslab, and thus isn't
|
|
|
|
* being subtracted.
|
|
|
|
*/
|
2000-09-01 19:59:35 +00:00
|
|
|
tlength += mcurrent - mrdatabegin;
|
1999-06-16 21:03:07 +00:00
|
|
|
tcount++;
|
1999-06-17 00:31:32 +00:00
|
|
|
} else
|
2000-10-18 23:53:31 +00:00
|
|
|
rcount++;
|
1999-06-16 21:03:07 +00:00
|
|
|
mcount--;
|
2000-10-31 03:22:05 +00:00
|
|
|
dns_rdata_reset(&mrdata);
|
1999-06-16 21:03:07 +00:00
|
|
|
} while (mcount > 0);
|
|
|
|
|
2000-10-18 23:53:31 +00:00
|
|
|
/*
|
|
|
|
* Check that all the records originally existed. The numeric
|
|
|
|
* check only works as rdataslabs do not contain duplicates.
|
|
|
|
*/
|
|
|
|
if (exact && (rcount != scount))
|
|
|
|
return (DNS_R_NOTEXACT);
|
|
|
|
|
1999-06-16 21:03:07 +00:00
|
|
|
/*
|
|
|
|
* Don't continue if the new rdataslab would be empty.
|
|
|
|
*/
|
|
|
|
if (tcount == 0)
|
2000-04-06 22:03:35 +00:00
|
|
|
return (DNS_R_NXRRSET);
|
1999-06-16 21:03:07 +00:00
|
|
|
|
1999-06-17 00:31:32 +00:00
|
|
|
/*
|
|
|
|
* If nothing is going to change, we can stop.
|
|
|
|
*/
|
2000-10-18 23:53:31 +00:00
|
|
|
if (rcount == 0)
|
1999-06-17 00:31:32 +00:00
|
|
|
return (DNS_R_UNCHANGED);
|
|
|
|
|
1999-06-16 21:03:07 +00:00
|
|
|
/*
|
|
|
|
* Copy the reserved area from the mslab.
|
|
|
|
*/
|
|
|
|
tstart = isc_mem_get(mctx, tlength);
|
|
|
|
if (tstart == NULL)
|
2000-04-06 22:03:35 +00:00
|
|
|
return (ISC_R_NOMEMORY);
|
1999-06-16 21:03:07 +00:00
|
|
|
memcpy(tstart, mslab, reservelen);
|
|
|
|
tcurrent = tstart + reservelen;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-06-16 21:03:07 +00:00
|
|
|
/*
|
|
|
|
* Write the new count.
|
|
|
|
*/
|
|
|
|
*tcurrent++ = (tcount & 0xff00) >> 8;
|
|
|
|
*tcurrent++ = (tcount & 0x00ff);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy the parts of mslab not in sslab.
|
|
|
|
*/
|
1999-06-24 19:15:55 +00:00
|
|
|
mcurrent = mslab + reservelen;
|
1999-06-16 21:03:07 +00:00
|
|
|
mcount = *mcurrent++ * 256;
|
|
|
|
mcount += *mcurrent++;
|
|
|
|
do {
|
2000-09-01 19:59:35 +00:00
|
|
|
unsigned char *mrdatabegin = mcurrent;
|
|
|
|
rdata_from_slab(&mcurrent, rdclass, type, &mrdata);
|
1999-06-16 21:03:07 +00:00
|
|
|
scurrent = sstart;
|
|
|
|
for (count = 0; count < scount; count++) {
|
2000-10-31 03:22:05 +00:00
|
|
|
dns_rdata_reset(&srdata);
|
2000-09-01 19:59:35 +00:00
|
|
|
rdata_from_slab(&scurrent, rdclass, type, &srdata);
|
1999-06-16 21:03:07 +00:00
|
|
|
if (dns_rdata_compare(&mrdata, &srdata) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (count == scount) {
|
|
|
|
/*
|
|
|
|
* This rdata isn't in the sslab, and thus should be
|
|
|
|
* copied to the tslab.
|
|
|
|
*/
|
2000-09-01 19:59:35 +00:00
|
|
|
unsigned int length = mcurrent - mrdatabegin;
|
|
|
|
memcpy(tcurrent, mrdatabegin, length);
|
|
|
|
tcurrent += length;
|
1999-06-16 21:03:07 +00:00
|
|
|
}
|
2000-10-31 03:22:05 +00:00
|
|
|
dns_rdata_reset(&mrdata);
|
1999-06-16 21:03:07 +00:00
|
|
|
mcount--;
|
|
|
|
} while (mcount > 0);
|
|
|
|
|
2000-09-01 19:59:35 +00:00
|
|
|
INSIST(tcurrent == tstart + tlength);
|
|
|
|
|
1999-06-16 21:03:07 +00:00
|
|
|
*tslabp = tstart;
|
|
|
|
|
2000-04-06 22:03:35 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-06-16 21:03:07 +00:00
|
|
|
}
|
2000-09-01 01:35:21 +00:00
|
|
|
|
|
|
|
isc_boolean_t
|
|
|
|
dns_rdataslab_equal(unsigned char *slab1, unsigned char *slab2,
|
|
|
|
unsigned int reservelen)
|
|
|
|
{
|
|
|
|
unsigned char *current1, *current2;
|
|
|
|
unsigned int count1, count2;
|
|
|
|
unsigned int length1, length2;
|
|
|
|
|
|
|
|
current1 = slab1 + reservelen;
|
|
|
|
count1 = *current1++ * 256;
|
|
|
|
count1 += *current1++;
|
|
|
|
|
|
|
|
current2 = slab2 + reservelen;
|
|
|
|
count2 = *current2++ * 256;
|
|
|
|
count2 += *current2++;
|
|
|
|
|
|
|
|
if (count1 != count2)
|
|
|
|
return (ISC_FALSE);
|
|
|
|
|
|
|
|
while (count1 > 0) {
|
|
|
|
length1 = *current1++ * 256;
|
|
|
|
length1 += *current1++;
|
|
|
|
|
|
|
|
length2 = *current2++ * 256;
|
|
|
|
length2 += *current2++;
|
|
|
|
|
|
|
|
if (length1 != length2 ||
|
|
|
|
memcmp(current1, current2, length1) != 0)
|
|
|
|
return (ISC_FALSE);
|
|
|
|
|
|
|
|
current1 += length1;
|
|
|
|
current2 += length1;
|
|
|
|
|
|
|
|
count1--;
|
|
|
|
}
|
|
|
|
return (ISC_TRUE);
|
|
|
|
}
|