rdataset.c revision 732e0731dec1922747bb3b3147cf2c3d16b22eaa
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff/*
ca41b452ede6feaa9d8739ec3cae19389a7b0d03Bob Halley * Copyright (C) 1999 Internet Software Consortium.
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff *
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * Permission to use, copy, modify, and distribute this software for any
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * purpose with or without fee is hereby granted, provided that the above
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * copyright notice and this permission notice appear in all copies.
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff *
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * SOFTWARE.
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff */
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff#include <config.h>
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff#include <stddef.h>
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff#include <string.h>
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff#include <isc/assertions.h>
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff#include <dns/rdata.h>
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff#include <dns/rdataclass.h>
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff#include <dns/rdatatype.h>
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff#include <dns/rdataset.h>
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff#include <dns/compress.h>
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graffvoid
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graffdns_rdataset_init(dns_rdataset_t *rdataset) {
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff /*
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff * Make 'rdataset' a valid, disassociated rdataset.
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff */
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff REQUIRE(rdataset != NULL);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->magic = DNS_RDATASET_MAGIC;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->methods = NULL;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff ISC_LINK_INIT(rdataset, link);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->rdclass = 0;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->type = 0;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->ttl = 0;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->trust = 0;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->covers = 0;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->attributes = 0;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->private1 = NULL;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->private2 = NULL;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->private3 = NULL;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->private4 = NULL;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->private5 = NULL;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff}
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graffvoid
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graffdns_rdataset_invalidate(dns_rdataset_t *rdataset) {
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff /*
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff * Invalidate 'rdataset'.
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff */
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff REQUIRE(DNS_RDATASET_VALID(rdataset));
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff REQUIRE(rdataset->methods == NULL);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->magic = 0;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff ISC_LINK_INIT(rdataset, link);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->rdclass = 0;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->type = 0;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->ttl = 0;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->trust = 0;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->covers = 0;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->attributes = 0;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->private1 = NULL;
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff rdataset->private2 = NULL;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->private3 = NULL;
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff rdataset->private4 = NULL;
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff rdataset->private5 = NULL;
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff}
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graffvoid
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graffdns_rdataset_disassociate(dns_rdataset_t *rdataset) {
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff /*
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff * Disassociate 'rdataset' from its rdata, allowing it to be reused.
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff */
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff REQUIRE(DNS_RDATASET_VALID(rdataset));
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff REQUIRE(rdataset->methods != NULL);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff (rdataset->methods->disassociate)(rdataset);
62e4837585f2d48ce9ef3ad6880d8fb75a578e58Andreas Gustafsson rdataset->methods = NULL;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff ISC_LINK_INIT(rdataset, link);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->rdclass = 0;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->type = 0;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->ttl = 0;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->trust = 0;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->covers = 0;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->attributes = 0;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->private1 = NULL;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->private2 = NULL;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->private3 = NULL;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->private4 = NULL;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff rdataset->private5 = NULL;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff}
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graffisc_boolean_t
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graffdns_rdataset_isassociated(dns_rdataset_t *rdataset) {
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff /*
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff * Is 'rdataset' associated?
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff */
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff REQUIRE(DNS_RDATASET_VALID(rdataset));
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff if (rdataset->methods != NULL)
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff return (ISC_TRUE);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff return (ISC_FALSE);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff}
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graffstatic void
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graffquestion_disassociate(dns_rdataset_t *rdataset) {
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff (void)rdataset;
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff}
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graffstatic dns_result_t
62e4837585f2d48ce9ef3ad6880d8fb75a578e58Andreas Gustafssonquestion_cursor(dns_rdataset_t *rdataset) {
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff (void)rdataset;
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff return (DNS_R_NOMORE);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff}
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graffstatic void
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graffquestion_current(dns_rdataset_t *rdataset, dns_rdata_t *rdata) {
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff /*
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff * This routine should never be called.
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff */
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff (void)rdataset;
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff (void)rdata;
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff REQUIRE(0);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff}
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graffstatic void
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graffquestion_clone(dns_rdataset_t *source, dns_rdataset_t *target) {
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff *target = *source;
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff}
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graffstatic dns_rdatasetmethods_t question_methods = {
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff question_disassociate,
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff question_cursor,
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff question_cursor,
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff question_current,
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff question_clone,
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff};
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graffvoid
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graffdns_rdataset_makequestion(dns_rdataset_t *rdataset, dns_rdataclass_t rdclass,
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff dns_rdatatype_t type)
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff{
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff /*
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff * Make 'rdataset' a valid, associated, question rdataset, with a
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff * question class of 'rdclass' and type 'type'.
e24f605ad64182532640dc6721070456b13112d5Michael Graff */
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff REQUIRE(DNS_RDATASET_VALID(rdataset));
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff REQUIRE(rdataset->methods == NULL);
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff rdataset->methods = &question_methods;
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff rdataset->rdclass = rdclass;
4e675038a097065ff13944232cd7c89ac5961984Michael Graff rdataset->type = type;
4e675038a097065ff13944232cd7c89ac5961984Michael Graff rdataset->attributes |= DNS_RDATASETATTR_QUESTION;
4e675038a097065ff13944232cd7c89ac5961984Michael Graff}
4e675038a097065ff13944232cd7c89ac5961984Michael Graff
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graffvoid
4e675038a097065ff13944232cd7c89ac5961984Michael Graffdns_rdataset_clone(dns_rdataset_t *source, dns_rdataset_t *target) {
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff /*
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff * Make 'target' refer to the same rdataset as 'source'.
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff */
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff REQUIRE(DNS_RDATASET_VALID(source));
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff REQUIRE(source->methods != NULL);
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff REQUIRE(DNS_RDATASET_VALID(target));
e24f605ad64182532640dc6721070456b13112d5Michael Graff REQUIRE(target->methods == NULL);
e24f605ad64182532640dc6721070456b13112d5Michael Graff
e24f605ad64182532640dc6721070456b13112d5Michael Graff (source->methods->clone)(source, target);
e24f605ad64182532640dc6721070456b13112d5Michael Graff}
e24f605ad64182532640dc6721070456b13112d5Michael Graff
e24f605ad64182532640dc6721070456b13112d5Michael Graffdns_result_t
e24f605ad64182532640dc6721070456b13112d5Michael Graffdns_rdataset_first(dns_rdataset_t *rdataset) {
e24f605ad64182532640dc6721070456b13112d5Michael Graff
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff /*
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff * Move the rdata cursor to the first rdata in the rdataset (if any).
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff */
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff REQUIRE(DNS_RDATASET_VALID(rdataset));
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff REQUIRE(rdataset->methods != NULL);
e24f605ad64182532640dc6721070456b13112d5Michael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff return ((rdataset->methods->first)(rdataset));
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff}
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graffdns_result_t
e24f605ad64182532640dc6721070456b13112d5Michael Graffdns_rdataset_next(dns_rdataset_t *rdataset) {
e24f605ad64182532640dc6721070456b13112d5Michael Graff
e24f605ad64182532640dc6721070456b13112d5Michael Graff /*
e24f605ad64182532640dc6721070456b13112d5Michael Graff * Move the rdata cursor to the next rdata in the rdataset (if any).
e24f605ad64182532640dc6721070456b13112d5Michael Graff */
e24f605ad64182532640dc6721070456b13112d5Michael Graff
e24f605ad64182532640dc6721070456b13112d5Michael Graff REQUIRE(DNS_RDATASET_VALID(rdataset));
e24f605ad64182532640dc6721070456b13112d5Michael Graff REQUIRE(rdataset->methods != NULL);
e24f605ad64182532640dc6721070456b13112d5Michael Graff
e24f605ad64182532640dc6721070456b13112d5Michael Graff return ((rdataset->methods->next)(rdataset));
e24f605ad64182532640dc6721070456b13112d5Michael Graff}
e24f605ad64182532640dc6721070456b13112d5Michael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graffvoid
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graffdns_rdataset_current(dns_rdataset_t *rdataset, dns_rdata_t *rdata) {
e24f605ad64182532640dc6721070456b13112d5Michael Graff
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff /*
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff * Make 'rdata' refer to the current rdata.
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff */
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff REQUIRE(DNS_RDATASET_VALID(rdataset));
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff REQUIRE(rdataset->methods != NULL);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff (rdataset->methods->current)(rdataset, rdata);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff}
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graffdns_result_t
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graffdns_rdataset_towire(dns_rdataset_t *rdataset,
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff dns_name_t *owner_name,
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff dns_compress_t *cctx,
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff isc_buffer_t *target,
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff unsigned int *countp)
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff{
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff dns_rdata_t rdata;
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff isc_region_t r;
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff dns_result_t result;
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff unsigned int count;
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff isc_buffer_t st;
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff isc_buffer_t rdlen;
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff unsigned int headlen;
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff isc_boolean_t question = ISC_FALSE;
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff /*
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff * Convert 'rdataset' to wire format, compressing names as specified
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff * in cctx, and storing the result in 'target'.
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff */
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff REQUIRE(DNS_RDATASET_VALID(rdataset));
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff REQUIRE(countp != NULL);
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff if ((rdataset->attributes & DNS_RDATASETATTR_QUESTION) != 0) {
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff question = ISC_TRUE;
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff result = dns_rdataset_first(rdataset);
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff INSIST(result == DNS_R_NOMORE);
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff } else {
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff result = dns_rdataset_first(rdataset);
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff if (result == DNS_R_NOMORE)
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff return (DNS_R_SUCCESS);
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff if (result != DNS_R_SUCCESS)
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff return (result);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff }
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff count = 0;
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff do {
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff /*
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff * copy out the name, type, class, ttl.
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff */
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff if (dns_compress_getedns(cctx) >= 1)
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL);
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff else
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff st = *target;
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff result = dns_name_towire(owner_name, cctx, target);
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff if (result != DNS_R_SUCCESS) {
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff dns_compress_rollback(cctx, st.used);
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff *countp += count;
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff *target = st;
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff return (result);
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff }
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff headlen = sizeof(dns_rdataclass_t) + sizeof(dns_rdatatype_t);
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff if (!question)
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff headlen += sizeof(dns_ttl_t)
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff + 2; /* XXX 2 for rdata len */
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff isc_buffer_available(target, &r);
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff if (r.length < headlen) {
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff dns_compress_rollback(cctx, st.used);
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff *countp += count;
e24f605ad64182532640dc6721070456b13112d5Michael Graff *target = st;
4e675038a097065ff13944232cd7c89ac5961984Michael Graff return (DNS_R_NOSPACE);
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff }
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff isc_buffer_putuint16(target, rdataset->type);
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff isc_buffer_putuint16(target, rdataset->rdclass);
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff if (!question) {
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff isc_buffer_putuint32(target, rdataset->ttl);
e24f605ad64182532640dc6721070456b13112d5Michael Graff
e24f605ad64182532640dc6721070456b13112d5Michael Graff /*
e24f605ad64182532640dc6721070456b13112d5Michael Graff * Save space for rdlen.
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff */
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff rdlen = *target;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff isc_buffer_add(target, 2);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff /*
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff * copy out the rdata
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff */
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff dns_rdataset_current(rdataset, &rdata);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff result = dns_compress_localinit(cctx, owner_name,
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff target);
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff if (result != DNS_R_SUCCESS) {
dns_compress_rollback(cctx, st.used);
*countp += count;
*target = st;
return (result);
}
result = dns_rdata_towire(&rdata, cctx, target);
dns_compress_localinvalidate(cctx);
if (result != DNS_R_SUCCESS) {
dns_compress_rollback(cctx, st.used);
*countp += count;
*target = st;
return (result);
}
isc_buffer_putuint16(&rdlen,
target->used - rdlen.used - 2);
}
count++;
result = dns_rdataset_next(rdataset);
} while (result == DNS_R_SUCCESS);
if (result != DNS_R_NOMORE)
return (result);
*countp += count;
return (DNS_R_SUCCESS);
}
dns_result_t
dns_rdataset_additionaldata(dns_rdataset_t *rdataset,
dns_additionaldatafunc_t add, void *arg)
{
dns_rdata_t rdata;
dns_result_t result;
/*
* For each rdata in rdataset, call 'add' for each name and type in the
* rdata which is subject to additional section processing.
*/
REQUIRE(DNS_RDATASET_VALID(rdataset));
REQUIRE((rdataset->attributes & DNS_RDATASETATTR_QUESTION) == 0);
result = dns_rdataset_first(rdataset);
if (result != DNS_R_SUCCESS)
return (result);
do {
dns_rdataset_current(rdataset, &rdata);
result = dns_rdata_additionaldata(&rdata, add, arg);
if (result == DNS_R_SUCCESS)
result = dns_rdataset_next(rdataset);
} while (result == DNS_R_SUCCESS);
if (result != DNS_R_NOMORE)
return (result);
return (DNS_R_SUCCESS);
}