2 * Copyright (C) 2004-2009 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: rdataslab.c,v 1.43.128.4 2009/01/19 23:47:02 tbox Exp $ */
27 #include <isc/region.h>
28 #include <isc/string.h> /* Required for HP/UX (and others?) */
31 #include <dns/result.h>
32 #include <dns/rdata.h>
33 #include <dns/rdataset.h>
34 #include <dns/rdataslab.h>
37 * The rdataslab structure allows iteration to occur in both load order
38 * and DNSSEC order. The structure is as follows:
40 * header (reservelen bytes)
41 * record count (2 bytes)
42 * offset table (4 x record count bytes in load order)
44 * data length (2 bytes)
46 * data (data length bytes)
48 * If DNS_RDATASET_FIXED is defined to be zero (0) the format of a
49 * rdataslab is as follows:
51 * header (reservelen bytes)
52 * record count (2 bytes)
54 * data length (2 bytes)
55 * data (data length bytes)
57 * Offsets are from the end of the header.
59 * Load order traversal is performed by walking the offset table to find
60 * the start of the record (DNS_RDATASET_FIXED = 1).
62 * DNSSEC order traversal is performed by walking the data records.
64 * The order is stored with record to allow for efficient reconstruction
65 * of the offset table following a merge or subtraction.
67 * The iterator methods here currently only support DNSSEC order iteration.
69 * The iterator methods in rbtdb support both load order and DNSSEC order
73 * rbtdb.c directly interacts with the slab's raw structures. If the
74 * structure changes then rbtdb.c also needs to be updated to reflect
75 * the changes. See the areas tagged with "RDATASLAB".
83 /*% Note: the "const void *" are just to make qsort happy. */
85 compare_rdata(const void *p1, const void *p2) {
86 const struct xrdata *x1 = p1;
87 const struct xrdata *x2 = p2;
88 return (dns_rdata_compare(&x1->rdata, &x2->rdata));
91 #if DNS_RDATASET_FIXED
93 fillin_offsets(unsigned char *offsetbase, unsigned int *offsettable,
99 for (i = 0, j = 0; i < length; i++) {
101 if (offsettable[i] == 0)
105 * Fill in offset table.
107 raw = &offsetbase[j*4 + 2];
108 *raw++ = (offsettable[i] & 0xff000000) >> 24;
109 *raw++ = (offsettable[i] & 0xff0000) >> 16;
110 *raw++ = (offsettable[i] & 0xff00) >> 8;
111 *raw = offsettable[i] & 0xff;
114 * Fill in table index.
116 raw = offsetbase + offsettable[i] + 2;
117 *raw++ = (j & 0xff00) >> 8;
124 dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx,
125 isc_region_t *region, unsigned int reservelen)
128 unsigned char *rawbuf;
129 #if DNS_RDATASET_FIXED
130 unsigned char *offsetbase;
137 #if DNS_RDATASET_FIXED
138 unsigned int *offsettable;
141 buflen = reservelen + 2;
143 nalloc = dns_rdataset_count(rdataset);
146 return (ISC_R_FAILURE);
149 return (ISC_R_NOSPACE);
151 x = isc_mem_get(mctx, nalloc * sizeof(struct xrdata));
153 return (ISC_R_NOMEMORY);
156 * Save all of the rdata members into an array.
158 result = dns_rdataset_first(rdataset);
159 if (result != ISC_R_SUCCESS)
161 for (i = 0; i < nalloc && result == ISC_R_SUCCESS; i++) {
162 INSIST(result == ISC_R_SUCCESS);
163 dns_rdata_init(&x[i].rdata);
164 dns_rdataset_current(rdataset, &x[i].rdata);
165 #if DNS_RDATASET_FIXED
168 result = dns_rdataset_next(rdataset);
170 if (result != ISC_R_NOMORE)
174 * Somehow we iterated over fewer rdatas than
175 * dns_rdataset_count() said there were!
177 result = ISC_R_FAILURE;
182 * Put into DNSSEC order.
184 qsort(x, nalloc, sizeof(struct xrdata), compare_rdata);
187 * Remove duplicates and compute the total storage required.
189 * If an rdata is not a duplicate, accumulate the storage size
190 * required for the rdata. We do not store the class, type, etc,
191 * just the rdata, so our overhead is 2 bytes for the number of
192 * records, and 8 for each rdata, (length(2), offset(4) and order(2))
193 * and then the rdata itself.
195 for (i = 1; i < nalloc; i++) {
196 if (compare_rdata(&x[i-1].rdata, &x[i].rdata) == 0) {
197 x[i-1].rdata.data = NULL;
198 x[i-1].rdata.length = 0;
199 #if DNS_RDATASET_FIXED
201 * Preserve the least order so A, B, A -> A, B
202 * after duplicate removal.
204 if (x[i-1].order < x[i].order)
205 x[i].order = x[i-1].order;
209 #if DNS_RDATASET_FIXED
210 buflen += (8 + x[i-1].rdata.length);
212 buflen += (2 + x[i-1].rdata.length);
216 * Don't forget the last item!
218 #if DNS_RDATASET_FIXED
219 buflen += (8 + x[i-1].rdata.length);
221 buflen += (2 + x[i-1].rdata.length);
225 * Ensure that singleton types are actually singletons.
227 if (nitems > 1 && dns_rdatatype_issingleton(rdataset->type)) {
229 * We have a singleton type, but there's more than one
230 * RR in the rdataset.
232 result = DNS_R_SINGLETON;
237 * Allocate the memory, set up a buffer, start copying in
240 rawbuf = isc_mem_get(mctx, buflen);
241 if (rawbuf == NULL) {
242 result = ISC_R_NOMEMORY;
246 #if DNS_RDATASET_FIXED
247 /* Allocate temporary offset table. */
248 offsettable = isc_mem_get(mctx, nalloc * sizeof(unsigned int));
249 if (offsettable == NULL) {
250 isc_mem_put(mctx, rawbuf, buflen);
251 result = ISC_R_NOMEMORY;
254 memset(offsettable, 0, nalloc * sizeof(unsigned int));
257 region->base = rawbuf;
258 region->length = buflen;
260 rawbuf += reservelen;
261 #if DNS_RDATASET_FIXED
265 *rawbuf++ = (nitems & 0xff00) >> 8;
266 *rawbuf++ = (nitems & 0x00ff);
268 #if DNS_RDATASET_FIXED
269 /* Skip load order table. Filled in later. */
270 rawbuf += nitems * 4;
273 for (i = 0; i < nalloc; i++) {
274 if (x[i].rdata.data == NULL)
276 #if DNS_RDATASET_FIXED
277 offsettable[x[i].order] = rawbuf - offsetbase;
279 *rawbuf++ = (x[i].rdata.length & 0xff00) >> 8;
280 *rawbuf++ = (x[i].rdata.length & 0x00ff);
281 #if DNS_RDATASET_FIXED
282 rawbuf += 2; /* filled in later */
284 memcpy(rawbuf, x[i].rdata.data, x[i].rdata.length);
285 rawbuf += x[i].rdata.length;
288 #if DNS_RDATASET_FIXED
289 fillin_offsets(offsetbase, offsettable, nalloc);
290 isc_mem_put(mctx, offsettable, nalloc * sizeof(unsigned int));
293 result = ISC_R_SUCCESS;
296 isc_mem_put(mctx, x, nalloc * sizeof(struct xrdata));
301 rdataset_disassociate(dns_rdataset_t *rdataset) {
306 rdataset_first(dns_rdataset_t *rdataset) {
307 unsigned char *raw = rdataset->private3;
310 count = raw[0] * 256 + raw[1];
312 rdataset->private5 = NULL;
313 return (ISC_R_NOMORE);
315 #if DNS_RDATASET_FIXED
316 raw += 2 + (4 * count);
321 * The privateuint4 field is the number of rdata beyond the cursor
322 * position, so we decrement the total count by one before storing
326 rdataset->privateuint4 = count;
327 rdataset->private5 = raw;
329 return (ISC_R_SUCCESS);
333 rdataset_next(dns_rdataset_t *rdataset) {
338 count = rdataset->privateuint4;
340 return (ISC_R_NOMORE);
342 rdataset->privateuint4 = count;
343 raw = rdataset->private5;
344 length = raw[0] * 256 + raw[1];
345 #if DNS_RDATASET_FIXED
350 rdataset->private5 = raw;
352 return (ISC_R_SUCCESS);
356 rdataset_current(dns_rdataset_t *rdataset, dns_rdata_t *rdata) {
357 unsigned char *raw = rdataset->private5;
360 REQUIRE(raw != NULL);
362 r.length = raw[0] * 256 + raw[1];
363 #if DNS_RDATASET_FIXED
369 dns_rdata_fromregion(rdata, rdataset->rdclass, rdataset->type, &r);
373 rdataset_clone(dns_rdataset_t *source, dns_rdataset_t *target) {
377 * Reset iterator state.
379 target->privateuint4 = 0;
380 target->private5 = NULL;
384 rdataset_count(dns_rdataset_t *rdataset) {
385 unsigned char *raw = rdataset->private3;
388 count = raw[0] * 256 + raw[1];
393 static dns_rdatasetmethods_t rdataset_methods = {
394 rdataset_disassociate,
408 dns_rdataslab_tordataset(unsigned char *slab, unsigned int reservelen,
409 dns_rdataclass_t rdclass, dns_rdatatype_t rdtype,
410 dns_rdatatype_t covers, dns_ttl_t ttl,
411 dns_rdataset_t *rdataset)
413 REQUIRE(slab != NULL);
414 REQUIRE(!dns_rdataset_isassociated(rdataset));
416 rdataset->methods = &rdataset_methods;
417 rdataset->rdclass = rdclass;
418 rdataset->type = rdtype;
419 rdataset->covers = covers;
422 rdataset->private1 = NULL;
423 rdataset->private2 = NULL;
424 rdataset->private3 = slab + reservelen;
427 * Reset iterator state.
429 rdataset->privateuint4 = 0;
430 rdataset->private5 = NULL;
434 dns_rdataslab_size(unsigned char *slab, unsigned int reservelen) {
435 unsigned int count, length;
436 unsigned char *current;
438 REQUIRE(slab != NULL);
440 current = slab + reservelen;
441 count = *current++ * 256;
443 #if DNS_RDATASET_FIXED
444 current += (4 * count);
448 length = *current++ * 256;
449 length += *current++;
450 #if DNS_RDATASET_FIXED
451 current += length + 2;
457 return ((unsigned int)(current - slab));
461 * Make the dns_rdata_t 'rdata' refer to the slab item
462 * beginning at '*current', which is part of a slab of type
463 * 'type' and class 'rdclass', and advance '*current' to
464 * point to the next item in the slab.
467 rdata_from_slab(unsigned char **current,
468 dns_rdataclass_t rdclass, dns_rdatatype_t type,
471 unsigned char *tcurrent = *current;
474 region.length = *tcurrent++ * 256;
475 region.length += *tcurrent++;
476 #if DNS_RDATASET_FIXED
479 region.base = tcurrent;
480 tcurrent += region.length;
481 dns_rdata_fromregion(rdata, rdclass, type, ®ion);
486 * Return true iff 'slab' (slab data of type 'type' and class 'rdclass')
487 * contains an rdata identical to 'rdata'. This does case insensitive
488 * comparisons per DNSSEC.
490 static inline isc_boolean_t
491 rdata_in_slab(unsigned char *slab, unsigned int reservelen,
492 dns_rdataclass_t rdclass, dns_rdatatype_t type,
495 unsigned int count, i;
496 unsigned char *current;
497 dns_rdata_t trdata = DNS_RDATA_INIT;
500 current = slab + reservelen;
501 count = *current++ * 256;
504 #if DNS_RDATASET_FIXED
505 current += (4 * count);
508 for (i = 0; i < count; i++) {
509 rdata_from_slab(¤t, rdclass, type, &trdata);
511 n = dns_rdata_compare(&trdata, rdata);
514 if (n > 0) /* In DNSSEC order. */
516 dns_rdata_reset(&trdata);
522 dns_rdataslab_merge(unsigned char *oslab, unsigned char *nslab,
523 unsigned int reservelen, isc_mem_t *mctx,
524 dns_rdataclass_t rdclass, dns_rdatatype_t type,
525 unsigned int flags, unsigned char **tslabp)
527 unsigned char *ocurrent, *ostart, *ncurrent, *tstart, *tcurrent;
528 unsigned int ocount, ncount, count, olength, tlength, tcount, length;
529 isc_region_t nregion;
530 dns_rdata_t ordata = DNS_RDATA_INIT;
531 dns_rdata_t nrdata = DNS_RDATA_INIT;
532 isc_boolean_t added_something = ISC_FALSE;
533 unsigned int oadded = 0;
534 unsigned int nadded = 0;
535 unsigned int nncount = 0;
536 #if DNS_RDATASET_FIXED
537 unsigned int oncount;
538 unsigned int norder = 0;
539 unsigned int oorder = 0;
540 unsigned char *offsetbase;
541 unsigned int *offsettable;
545 * XXX Need parameter to allow "delete rdatasets in nslab" merge,
546 * or perhaps another merge routine for this purpose.
549 REQUIRE(tslabp != NULL && *tslabp == NULL);
550 REQUIRE(oslab != NULL && nslab != NULL);
552 ocurrent = oslab + reservelen;
553 ocount = *ocurrent++ * 256;
554 ocount += *ocurrent++;
555 #if DNS_RDATASET_FIXED
556 ocurrent += (4 * ocount);
559 ncurrent = nslab + reservelen;
560 ncount = *ncurrent++ * 256;
561 ncount += *ncurrent++;
562 #if DNS_RDATASET_FIXED
563 ncurrent += (4 * ncount);
565 INSIST(ocount > 0 && ncount > 0);
567 #if DNS_RDATASET_FIXED
572 * Yes, this is inefficient!
576 * Figure out the length of the old slab's data.
579 for (count = 0; count < ocount; count++) {
580 length = *ocurrent++ * 256;
581 length += *ocurrent++;
582 #if DNS_RDATASET_FIXED
583 olength += length + 8;
584 ocurrent += length + 2;
586 olength += length + 2;
592 * Start figuring out the target length and count.
594 tlength = reservelen + 2 + olength;
598 * Add in the length of rdata in the new slab that aren't in
602 nregion.length = *ncurrent++ * 256;
603 nregion.length += *ncurrent++;
604 #if DNS_RDATASET_FIXED
605 ncurrent += 2; /* Skip order. */
607 nregion.base = ncurrent;
608 dns_rdata_init(&nrdata);
609 dns_rdata_fromregion(&nrdata, rdclass, type, &nregion);
610 if (!rdata_in_slab(oslab, reservelen, rdclass, type, &nrdata))
613 * This rdata isn't in the old slab.
615 #if DNS_RDATASET_FIXED
616 tlength += nregion.length + 8;
618 tlength += nregion.length + 2;
622 added_something = ISC_TRUE;
624 ncurrent += nregion.length;
626 } while (ncount > 0);
629 if (((flags & DNS_RDATASLAB_EXACT) != 0) &&
630 (tcount != ncount + ocount))
631 return (DNS_R_NOTEXACT);
633 if (!added_something && (flags & DNS_RDATASLAB_FORCE) == 0)
634 return (DNS_R_UNCHANGED);
637 * Ensure that singleton types are actually singletons.
639 if (tcount > 1 && dns_rdatatype_issingleton(type)) {
641 * We have a singleton type, but there's more than one
642 * RR in the rdataset.
644 return (DNS_R_SINGLETON);
648 return (ISC_R_NOSPACE);
651 * Copy the reserved area from the new slab.
653 tstart = isc_mem_get(mctx, tlength);
655 return (ISC_R_NOMEMORY);
656 memcpy(tstart, nslab, reservelen);
657 tcurrent = tstart + reservelen;
658 #if DNS_RDATASET_FIXED
659 offsetbase = tcurrent;
663 * Write the new count.
665 *tcurrent++ = (tcount & 0xff00) >> 8;
666 *tcurrent++ = (tcount & 0x00ff);
668 #if DNS_RDATASET_FIXED
672 tcurrent += (tcount * 4);
674 offsettable = isc_mem_get(mctx,
675 (ocount + oncount) * sizeof(unsigned int));
676 if (offsettable == NULL) {
677 isc_mem_put(mctx, tstart, tlength);
678 return (ISC_R_NOMEMORY);
680 memset(offsettable, 0, (ocount + oncount) * sizeof(unsigned int));
684 * Merge the two slabs.
688 #if DNS_RDATASET_FIXED
689 oorder = ocurrent[2] * 256 + ocurrent[3];
690 INSIST(oorder < ocount);
692 rdata_from_slab(&ocurrent, rdclass, type, &ordata);
694 ncurrent = nslab + reservelen + 2;
695 #if DNS_RDATASET_FIXED
696 ncurrent += (4 * oncount);
701 dns_rdata_reset(&nrdata);
702 #if DNS_RDATASET_FIXED
703 norder = ncurrent[2] * 256 + ncurrent[3];
705 INSIST(norder < oncount);
707 rdata_from_slab(&ncurrent, rdclass, type, &nrdata);
708 } while (rdata_in_slab(oslab, reservelen, rdclass,
712 while (oadded < ocount || nadded < ncount) {
713 isc_boolean_t fromold;
714 if (oadded == ocount)
716 else if (nadded == ncount)
719 fromold = ISC_TF(compare_rdata(&ordata, &nrdata) < 0);
721 #if DNS_RDATASET_FIXED
722 offsettable[oorder] = tcurrent - offsetbase;
724 length = ordata.length;
725 *tcurrent++ = (length & 0xff00) >> 8;
726 *tcurrent++ = (length & 0x00ff);
727 #if DNS_RDATASET_FIXED
728 tcurrent += 2; /* fill in later */
730 memcpy(tcurrent, ordata.data, length);
733 if (oadded < ocount) {
734 dns_rdata_reset(&ordata);
735 #if DNS_RDATASET_FIXED
736 oorder = ocurrent[2] * 256 + ocurrent[3];
737 INSIST(oorder < ocount);
739 rdata_from_slab(&ocurrent, rdclass, type,
743 #if DNS_RDATASET_FIXED
744 offsettable[ocount + norder] = tcurrent - offsetbase;
746 length = nrdata.length;
747 *tcurrent++ = (length & 0xff00) >> 8;
748 *tcurrent++ = (length & 0x00ff);
749 #if DNS_RDATASET_FIXED
750 tcurrent += 2; /* fill in later */
752 memcpy(tcurrent, nrdata.data, length);
755 if (nadded < ncount) {
757 dns_rdata_reset(&nrdata);
758 #if DNS_RDATASET_FIXED
759 norder = ncurrent[2] * 256 + ncurrent[3];
760 INSIST(norder < oncount);
762 rdata_from_slab(&ncurrent, rdclass,
764 } while (rdata_in_slab(oslab, reservelen,
771 #if DNS_RDATASET_FIXED
772 fillin_offsets(offsetbase, offsettable, ocount + oncount);
774 isc_mem_put(mctx, offsettable,
775 (ocount + oncount) * sizeof(unsigned int));
778 INSIST(tcurrent == tstart + tlength);
782 return (ISC_R_SUCCESS);
786 dns_rdataslab_subtract(unsigned char *mslab, unsigned char *sslab,
787 unsigned int reservelen, isc_mem_t *mctx,
788 dns_rdataclass_t rdclass, dns_rdatatype_t type,
789 unsigned int flags, unsigned char **tslabp)
791 unsigned char *mcurrent, *sstart, *scurrent, *tstart, *tcurrent;
792 unsigned int mcount, scount, rcount ,count, tlength, tcount, i;
793 dns_rdata_t srdata = DNS_RDATA_INIT;
794 dns_rdata_t mrdata = DNS_RDATA_INIT;
795 #if DNS_RDATASET_FIXED
796 unsigned char *offsetbase;
797 unsigned int *offsettable;
801 REQUIRE(tslabp != NULL && *tslabp == NULL);
802 REQUIRE(mslab != NULL && sslab != NULL);
804 mcurrent = mslab + reservelen;
805 mcount = *mcurrent++ * 256;
806 mcount += *mcurrent++;
807 scurrent = sslab + reservelen;
808 scount = *scurrent++ * 256;
809 scount += *scurrent++;
810 INSIST(mcount > 0 && scount > 0);
813 * Yes, this is inefficient!
817 * Start figuring out the target length and count.
819 tlength = reservelen + 2;
823 #if DNS_RDATASET_FIXED
824 mcurrent += 4 * mcount;
825 scurrent += 4 * scount;
830 * Add in the length of rdata in the mslab that aren't in
833 for (i = 0; i < mcount; i++) {
834 unsigned char *mrdatabegin = mcurrent;
835 rdata_from_slab(&mcurrent, rdclass, type, &mrdata);
837 for (count = 0; count < scount; count++) {
838 dns_rdata_reset(&srdata);
839 rdata_from_slab(&scurrent, rdclass, type, &srdata);
840 if (dns_rdata_compare(&mrdata, &srdata) == 0)
843 if (count == scount) {
845 * This rdata isn't in the sslab, and thus isn't
848 tlength += mcurrent - mrdatabegin;
852 dns_rdata_reset(&mrdata);
855 #if DNS_RDATASET_FIXED
856 tlength += (4 * tcount);
860 * Check that all the records originally existed. The numeric
861 * check only works as rdataslabs do not contain duplicates.
863 if (((flags & DNS_RDATASLAB_EXACT) != 0) && (rcount != scount))
864 return (DNS_R_NOTEXACT);
867 * Don't continue if the new rdataslab would be empty.
870 return (DNS_R_NXRRSET);
873 * If nothing is going to change, we can stop.
876 return (DNS_R_UNCHANGED);
879 * Copy the reserved area from the mslab.
881 tstart = isc_mem_get(mctx, tlength);
883 return (ISC_R_NOMEMORY);
884 memcpy(tstart, mslab, reservelen);
885 tcurrent = tstart + reservelen;
886 #if DNS_RDATASET_FIXED
887 offsetbase = tcurrent;
889 offsettable = isc_mem_get(mctx, mcount * sizeof(unsigned int));
890 if (offsettable == NULL) {
891 isc_mem_put(mctx, tstart, tlength);
892 return (ISC_R_NOMEMORY);
894 memset(offsettable, 0, mcount * sizeof(unsigned int));
898 * Write the new count.
900 *tcurrent++ = (tcount & 0xff00) >> 8;
901 *tcurrent++ = (tcount & 0x00ff);
903 #if DNS_RDATASET_FIXED
904 tcurrent += (4 * tcount);
908 * Copy the parts of mslab not in sslab.
910 mcurrent = mslab + reservelen;
911 mcount = *mcurrent++ * 256;
912 mcount += *mcurrent++;
913 #if DNS_RDATASET_FIXED
914 mcurrent += (4 * mcount);
916 for (i = 0; i < mcount; i++) {
917 unsigned char *mrdatabegin = mcurrent;
918 #if DNS_RDATASET_FIXED
919 order = mcurrent[2] * 256 + mcurrent[3];
920 INSIST(order < mcount);
922 rdata_from_slab(&mcurrent, rdclass, type, &mrdata);
924 for (count = 0; count < scount; count++) {
925 dns_rdata_reset(&srdata);
926 rdata_from_slab(&scurrent, rdclass, type, &srdata);
927 if (dns_rdata_compare(&mrdata, &srdata) == 0)
930 if (count == scount) {
932 * This rdata isn't in the sslab, and thus should be
933 * copied to the tslab.
935 unsigned int length = mcurrent - mrdatabegin;
936 #if DNS_RDATASET_FIXED
937 offsettable[order] = tcurrent - offsetbase;
939 memcpy(tcurrent, mrdatabegin, length);
942 dns_rdata_reset(&mrdata);
945 #if DNS_RDATASET_FIXED
946 fillin_offsets(offsetbase, offsettable, mcount);
948 isc_mem_put(mctx, offsettable, mcount * sizeof(unsigned int));
951 INSIST(tcurrent == tstart + tlength);
955 return (ISC_R_SUCCESS);
959 dns_rdataslab_equal(unsigned char *slab1, unsigned char *slab2,
960 unsigned int reservelen)
962 unsigned char *current1, *current2;
963 unsigned int count1, count2;
964 unsigned int length1, length2;
966 current1 = slab1 + reservelen;
967 count1 = *current1++ * 256;
968 count1 += *current1++;
970 current2 = slab2 + reservelen;
971 count2 = *current2++ * 256;
972 count2 += *current2++;
974 if (count1 != count2)
977 #if DNS_RDATASET_FIXED
978 current1 += (4 * count1);
979 current2 += (4 * count2);
983 length1 = *current1++ * 256;
984 length1 += *current1++;
986 length2 = *current2++ * 256;
987 length2 += *current2++;
989 #if DNS_RDATASET_FIXED
994 if (length1 != length2 ||
995 memcmp(current1, current2, length1) != 0)
1007 dns_rdataslab_equalx(unsigned char *slab1, unsigned char *slab2,
1008 unsigned int reservelen, dns_rdataclass_t rdclass,
1009 dns_rdatatype_t type)
1011 unsigned char *current1, *current2;
1012 unsigned int count1, count2;
1013 dns_rdata_t rdata1 = DNS_RDATA_INIT;
1014 dns_rdata_t rdata2 = DNS_RDATA_INIT;
1016 current1 = slab1 + reservelen;
1017 count1 = *current1++ * 256;
1018 count1 += *current1++;
1020 current2 = slab2 + reservelen;
1021 count2 = *current2++ * 256;
1022 count2 += *current2++;
1024 if (count1 != count2)
1027 #if DNS_RDATASET_FIXED
1028 current1 += (4 * count1);
1029 current2 += (4 * count2);
1032 while (count1-- > 0) {
1033 rdata_from_slab(¤t1, rdclass, type, &rdata1);
1034 rdata_from_slab(¤t2, rdclass, type, &rdata2);
1035 if (dns_rdata_compare(&rdata1, &rdata2) != 0)
1037 dns_rdata_reset(&rdata1);
1038 dns_rdata_reset(&rdata2);