rdataset.c revision 8af4b7042d84e0699f7c1de306526098030b74a9
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Copyright (C) 1999-2001 Internet Software Consortium.
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 * 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.
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington/* $Id: rdataset.c,v 1.57 2001/06/05 09:17:21 marka Exp $ */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_rdataset_init(dns_rdataset_t *rdataset) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington * Make 'rdataset' a valid, disassociated rdataset.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_rdataset_invalidate(dns_rdataset_t *rdataset) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Invalidate 'rdataset'.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondns_rdataset_disassociate(dns_rdataset_t *rdataset) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * Disassociate 'rdataset' from its rdata, allowing it to be reused.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (rdataset->methods->disassociate)(rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_rdataset_isassociated(dns_rdataset_t *rdataset) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Is 'rdataset' associated?
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonquestion_disassociate(dns_rdataset_t *rdataset) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonquestion_current(dns_rdataset_t *rdataset, dns_rdata_t *rdata) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * This routine should never be called.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonquestion_clone(dns_rdataset_t *source, dns_rdataset_t *target) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic unsigned int
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * This routine should never be called.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic dns_rdatasetmethods_t question_methods = {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_rdataset_makequestion(dns_rdataset_t *rdataset, dns_rdataclass_t rdclass,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Make 'rdataset' a valid, associated, question rdataset, with a
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * question class of 'rdclass' and type 'type'.
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington rdataset->attributes |= DNS_RDATASETATTR_QUESTION;
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellingtondns_rdataset_count(dns_rdataset_t *rdataset) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Return the number of records in 'rdataset'.
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington return ((rdataset->methods->count)(rdataset));
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtondns_rdataset_clone(dns_rdataset_t *source, dns_rdataset_t *target) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington * Make 'target' refer to the same rdataset as 'source'.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_rdataset_first(dns_rdataset_t *rdataset) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington * Move the rdata cursor to the first rdata in the rdataset (if any).
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington return ((rdataset->methods->first)(rdataset));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_rdataset_next(dns_rdataset_t *rdataset) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Move the rdata cursor to the next rdata in the rdataset (if any).
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return ((rdataset->methods->next)(rdataset));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_rdataset_current(dns_rdataset_t *rdataset, dns_rdata_t *rdata) {
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington * Make 'rdata' refer to the current rdata.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (rdataset->methods->current)(rdataset, rdata);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define WANT_FIXED(r) (((r)->attributes & DNS_RDATASETATTR_FIXEDORDER) != 0)
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 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,
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington * Convert 'rdataset' to wire format, compressing names as specified
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington * in cctx, and storing the result in 'target'.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE((order == NULL) == (order_arg == NULL));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if ((rdataset->attributes & DNS_RDATASETATTR_QUESTION) != 0) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * This is a negative caching rdataset.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (dns_ncache_towire(rdataset, cctx, target, countp));
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington count = (rdataset->methods->count)(rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * We'll only shuffle if we've got enough slots in our
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * There's no point to shuffling SIGs.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * First we get handles to all of the rdata.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_current(rdataset, &shuffled[i]);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * Now we shuffle.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * Sorted order.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington for (i = 0; i < count; i++) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * "Cyclic" order.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington unsigned int j = (((unsigned int)rand()) >> 3) % count;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington for (i = 0; i < count; i++) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington j = 0; /* Wrap around. */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * Copy out the name, type, class, ttl.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = dns_name_towire(owner_name, cctx, target);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington headlen = sizeof(dns_rdataclass_t) + sizeof(dns_rdatatype_t);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_buffer_putuint16(target, rdataset->type);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_buffer_putuint16(target, rdataset->rdclass);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_buffer_putuint32(target, rdataset->ttl);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Save space for rdlen.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Copy out the rdata
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdata_towire(&rdata, cctx, target);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_compress_rollback(cctx, (isc_uint16_t)rrbuffer.used);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_compress_rollback(cctx, (isc_uint16_t)savedbuffer.used);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_rdataset_towiresorted(dns_rdataset_t *rdataset,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int *countp)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (towiresorted(rdataset, owner_name, cctx, target,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington order, order_arg, ISC_FALSE, countp, NULL));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_rdataset_towirepartial(dns_rdataset_t *rdataset,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int *countp,
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 Wellingtondns_rdataset_towire(dns_rdataset_t *rdataset,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int *countp)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (towiresorted(rdataset, owner_name, cctx, target,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_rdataset_additionaldata(dns_rdataset_t *rdataset,
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 REQUIRE((rdataset->attributes & DNS_RDATASETATTR_QUESTION) == 0);