rdataset.c revision 8af4b7042d84e0699f7c1de306526098030b74a9
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington/*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Copyright (C) 1999-2001 Internet Software Consortium.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Permission to use, copy, modify, and distribute this software for any
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * purpose with or without fee is hereby granted, provided that the above
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * copyright notice and this permission notice appear in all copies.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington/* $Id: rdataset.c,v 1.57 2001/06/05 09:17:21 marka Exp $ */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <config.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
f4b4e7c16211137332e50bcad3fef0d15639a4f1Brian Wellington#include <stdlib.h>
f4b4e7c16211137332e50bcad3fef0d15639a4f1Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/buffer.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <isc/util.h>
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/name.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/ncache.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/rdata.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/rdataset.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/compress.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonvoid
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_rdataset_init(dns_rdataset_t *rdataset) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington * Make 'rdataset' a valid, disassociated rdataset.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(rdataset != NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->magic = DNS_RDATASET_MAGIC;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->methods = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LINK_INIT(rdataset, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->rdclass = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->type = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->ttl = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->trust = 0;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington rdataset->covers = 0;
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington rdataset->attributes = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->private1 = NULL;
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington rdataset->private2 = NULL;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington rdataset->private3 = NULL;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington rdataset->private4 = NULL;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington rdataset->private5 = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonvoid
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_rdataset_invalidate(dns_rdataset_t *rdataset) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Invalidate 'rdataset'.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(DNS_RDATASET_VALID(rdataset));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(rdataset->methods == NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->magic = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LINK_INIT(rdataset, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->rdclass = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->type = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->ttl = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->trust = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->covers = 0;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington rdataset->attributes = 0;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington rdataset->private1 = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->private2 = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->private3 = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->private4 = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->private5 = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonvoid
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondns_rdataset_disassociate(dns_rdataset_t *rdataset) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington /*
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * Disassociate 'rdataset' from its rdata, allowing it to be reused.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington REQUIRE(DNS_RDATASET_VALID(rdataset));
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington REQUIRE(rdataset->methods != NULL);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (rdataset->methods->disassociate)(rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->methods = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LINK_INIT(rdataset, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->rdclass = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->type = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->ttl = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->trust = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->covers = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->attributes = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->private1 = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->private2 = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->private3 = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->private4 = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->private5 = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonisc_boolean_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_rdataset_isassociated(dns_rdataset_t *rdataset) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Is 'rdataset' associated?
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(DNS_RDATASET_VALID(rdataset));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington if (rdataset->methods != NULL)
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington return (ISC_TRUE);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington return (ISC_FALSE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonquestion_disassociate(dns_rdataset_t *rdataset) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington UNUSED(rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic isc_result_t
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonquestion_cursor(dns_rdataset_t *rdataset) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington UNUSED(rdataset);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOMORE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonquestion_current(dns_rdataset_t *rdataset, dns_rdata_t *rdata) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * This routine should never be called.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington UNUSED(rdataset);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington UNUSED(rdata);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington REQUIRE(0);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic void
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonquestion_clone(dns_rdataset_t *source, dns_rdataset_t *target) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington *target = *source;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic unsigned int
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonquestion_count(dns_rdataset_t *rdataset) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington /*
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * This routine should never be called.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington UNUSED(rdataset);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington REQUIRE(0);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (0);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic dns_rdatasetmethods_t question_methods = {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington question_disassociate,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington question_cursor,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington question_cursor,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington question_current,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington question_clone,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington question_count
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington};
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonvoid
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_rdataset_makequestion(dns_rdataset_t *rdataset, dns_rdataclass_t rdclass,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatatype_t type)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Make 'rdataset' a valid, associated, question rdataset, with a
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * question class of 'rdclass' and type 'type'.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(DNS_RDATASET_VALID(rdataset));
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington REQUIRE(rdataset->methods == NULL);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington rdataset->methods = &question_methods;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->rdclass = rdclass;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington rdataset->type = type;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington rdataset->attributes |= DNS_RDATASETATTR_QUESTION;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellingtonunsigned int
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellingtondns_rdataset_count(dns_rdataset_t *rdataset) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Return the number of records in 'rdataset'.
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington */
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington REQUIRE(DNS_RDATASET_VALID(rdataset));
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington REQUIRE(rdataset->methods != NULL);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington return ((rdataset->methods->count)(rdataset));
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington}
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonvoid
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtondns_rdataset_clone(dns_rdataset_t *source, dns_rdataset_t *target) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington /*
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington * Make 'target' refer to the same rdataset as 'source'.
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington REQUIRE(DNS_RDATASET_VALID(source));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(source->methods != NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(DNS_RDATASET_VALID(target));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(target->methods == NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (source->methods->clone)(source, target);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington}
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonisc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_rdataset_first(dns_rdataset_t *rdataset) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington /*
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington * Move the rdata cursor to the first rdata in the rdataset (if any).
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington */
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington REQUIRE(DNS_RDATASET_VALID(rdataset));
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington REQUIRE(rdataset->methods != NULL);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington return ((rdataset->methods->first)(rdataset));
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonisc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_rdataset_next(dns_rdataset_t *rdataset) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Move the rdata cursor to the next rdata in the rdataset (if any).
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(DNS_RDATASET_VALID(rdataset));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(rdataset->methods != NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return ((rdataset->methods->next)(rdataset));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonvoid
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_rdataset_current(dns_rdataset_t *rdataset, dns_rdata_t *rdata) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington /*
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington * Make 'rdata' refer to the current rdata.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(DNS_RDATASET_VALID(rdataset));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(rdataset->methods != NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (rdataset->methods->current)(rdataset, rdata);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define MAX_SHUFFLE 32
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define WANT_FIXED(r) (((r)->attributes & DNS_RDATASETATTR_FIXEDORDER) != 0)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstruct towire_sort {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington int key;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_t *rdata;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington};
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic int
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtontowire_compare(const void *av, const void *bv) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington const struct towire_sort *a = (const struct towire_sort *) av;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington const struct towire_sort *b = (const struct towire_sort *) bv;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (a->key - b->key);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtontowiresorted(dns_rdataset_t *rdataset, dns_name_t *owner_name,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_compress_t *cctx, isc_buffer_t *target,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatasetorderfunc_t order, void *order_arg,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_boolean_t partial, unsigned int *countp,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington void **state)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_t rdata = DNS_RDATA_INIT;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_region_t r;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_result_t result;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int i, count, added;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_t savedbuffer, rdlen, rrbuffer;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int headlen;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_boolean_t question = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_boolean_t shuffle = ISC_FALSE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_t shuffled[MAX_SHUFFLE];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington struct towire_sort sorted[MAX_SHUFFLE];
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington UNUSED(state);
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington /*
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington * Convert 'rdataset' to wire format, compressing names as specified
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington * in cctx, and storing the result in 'target'.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(DNS_RDATASET_VALID(rdataset));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(countp != NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE((order == NULL) == (order_arg == NULL));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington count = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if ((rdataset->attributes & DNS_RDATASETATTR_QUESTION) != 0) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington question = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington count = 1;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdataset_first(rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(result == ISC_R_NOMORE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington } else if (rdataset->type == 0) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * This is a negative caching rdataset.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (dns_ncache_towire(rdataset, cctx, target, countp));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington } else {
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington count = (rdataset->methods->count)(rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdataset_first(rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result == ISC_R_NOMORE)
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington return (ISC_R_SUCCESS);
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington if (result != ISC_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * We'll only shuffle if we've got enough slots in our
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * deck.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * There's no point to shuffling SIGs.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (!question &&
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington count > 1 &&
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington !WANT_FIXED(rdataset) &&
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington count <= MAX_SHUFFLE &&
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->type != dns_rdatatype_sig)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington shuffle = ISC_TRUE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * First we get handles to all of the rdata.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington i = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington do {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(i < count);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_init(&shuffled[i]);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_current(rdataset, &shuffled[i]);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington i++;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdataset_next(rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington } while (result == ISC_R_SUCCESS);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (result != ISC_R_NOMORE)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (result);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington INSIST(i == count);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington /*
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * Now we shuffle.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (order != NULL) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington /*
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * Sorted order.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington for (i = 0; i < count; i++) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sorted[i].key = (*order)(&shuffled[i],
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington order_arg);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sorted[i].rdata = &shuffled[i];
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington qsort(sorted, count, sizeof(sorted[0]),
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington towire_compare);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington } else {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington /*
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * "Cyclic" order.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington unsigned int j = (((unsigned int)rand()) >> 3) % count;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington for (i = 0; i < count; i++) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sorted[j].key = 0; /* Unused */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sorted[j].rdata = &shuffled[i];
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington j++;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (j == count)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington j = 0; /* Wrap around. */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington savedbuffer = *target;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington i = 0;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington added = 0;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington do {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington /*
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * Copy out the name, type, class, ttl.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington rrbuffer = *target;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = dns_name_towire(owner_name, cctx, target);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (result != ISC_R_SUCCESS)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington goto rollback;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington headlen = sizeof(dns_rdataclass_t) + sizeof(dns_rdatatype_t);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (!question)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington headlen += sizeof(dns_ttl_t)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington + 2; /* XXX 2 for rdata len */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_buffer_availableregion(target, &r);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (r.length < headlen) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = ISC_R_NOSPACE;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington goto rollback;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_buffer_putuint16(target, rdataset->type);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_buffer_putuint16(target, rdataset->rdclass);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (!question) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_buffer_putuint32(target, rdataset->ttl);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Save space for rdlen.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdlen = *target;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_add(target, 2);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Copy out the rdata
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (shuffle)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdata = *(sorted[i].rdata);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington else {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_reset(&rdata);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_current(rdataset, &rdata);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdata_towire(&rdata, cctx, target);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto rollback;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST((target->used >= rdlen.used + 2) &&
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (target->used - rdlen.used - 2 < 65536));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_putuint16(&rdlen,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (isc_uint16_t)(target->used -
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdlen.used - 2));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington added++;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (shuffle) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington i++;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (i == count)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = ISC_R_NOMORE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington else
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = ISC_R_SUCCESS;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington } else {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdataset_next(rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington } while (result == ISC_R_SUCCESS);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_NOMORE)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington goto rollback;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington *countp += count;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_SUCCESS);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington rollback:
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington if (partial && result == ISC_R_NOSPACE) {
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington INSIST(rrbuffer.used < 65536);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_compress_rollback(cctx, (isc_uint16_t)rrbuffer.used);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *countp += added;
5e387b9ce6bafdfadedb5b34e4c33a4404e5d589Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(savedbuffer.used < 65536);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_compress_rollback(cctx, (isc_uint16_t)savedbuffer.used);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *countp = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *target = savedbuffer;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonisc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_rdataset_towiresorted(dns_rdataset_t *rdataset,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_t *owner_name,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_compress_t *cctx,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_t *target,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatasetorderfunc_t order,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington void *order_arg,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int *countp)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (towiresorted(rdataset, owner_name, cctx, target,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington order, order_arg, ISC_FALSE, countp, NULL));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonisc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_rdataset_towirepartial(dns_rdataset_t *rdataset,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_t *owner_name,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_compress_t *cctx,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_t *target,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatasetorderfunc_t order,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington void *order_arg,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int *countp,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington void **state)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(state == NULL); /* XXX remove when implemented */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (towiresorted(rdataset, owner_name, cctx, target,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington order, order_arg, ISC_TRUE, countp, state));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonisc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_rdataset_towire(dns_rdataset_t *rdataset,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_t *owner_name,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_compress_t *cctx,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_t *target,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int *countp)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (towiresorted(rdataset, owner_name, cctx, target,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington NULL, NULL, ISC_FALSE, countp, NULL));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonisc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_rdataset_additionaldata(dns_rdataset_t *rdataset,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_additionaldatafunc_t add, void *arg)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_t rdata = DNS_RDATA_INIT;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_result_t result;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * For each rdata in rdataset, call 'add' for each name and type in the
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * rdata which is subject to additional section processing.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(DNS_RDATASET_VALID(rdataset));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE((rdataset->attributes & DNS_RDATASETATTR_QUESTION) == 0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdataset_first(rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington do {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_current(rdataset, &rdata);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdata_additionaldata(&rdata, add, arg);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result == ISC_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdataset_next(rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_reset(&rdata);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington } while (result == ISC_R_SUCCESS);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_NOMORE)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_SUCCESS);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington