ncache.c revision fbe2cff19f5cddc67b967764ad95038dfcafc85a
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington/*
1b5a34533410ff4eaff0e5b5b110221a97e29cfcAutomatic Updater * Copyright (C) 2004, 2005, 2007, 2008, 2010, 2011 Internet Systems Consortium, Inc. ("ISC")
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * Copyright (C) 1999-2003 Internet Software Consortium.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * Permission to use, copy, modify, and/or 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 *
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PERFORMANCE OF THIS SOFTWARE.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
557bcc2092642b2d4668c9b08872c9f2bb88bddbMark Andrews/* $Id: ncache.c,v 1.53 2011/05/26 23:11:15 each Exp $ */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*! \file */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <config.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
f4b4e7c16211137332e50bcad3fef0d15639a4f1Brian Wellington#include <isc/buffer.h>
f4b4e7c16211137332e50bcad3fef0d15639a4f1Brian Wellington#include <isc/util.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/db.h>
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington#include <dns/message.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/ncache.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/rdata.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/rdatalist.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/rdataset.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#include <dns/rdatastruct.h>
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define DNS_NCACHE_RDATA 20U
229ce407c359b0b641759ba1fc4a5fa2054a44daBrian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington/*
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * The format of an ncache rdata is a sequence of zero or more records of
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * the following format:
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington *
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * owner name
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * type
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * trust
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * rdata count
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * rdata length These two occur 'rdata count'
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * rdata times.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic inline isc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtoncopy_rdataset(dns_rdataset_t *rdataset, isc_buffer_t *buffer) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_result_t result;
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington unsigned int count;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_region_t ar, r;
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington dns_rdata_t rdata = DNS_RDATA_INIT;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington /*
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington * Copy the rdataset count to the buffer.
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_availableregion(buffer, &ar);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (ar.length < 2)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOSPACE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington count = dns_rdataset_count(rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(count <= 65535);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_buffer_putuint16(buffer, (isc_uint16_t)count);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdataset_first(rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington while (result == ISC_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_current(rdataset, &rdata);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_toregion(&rdata, &r);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(r.length <= 65535);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_availableregion(buffer, &ar);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (ar.length < 2)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOSPACE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Copy the rdata length to the buffer.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_buffer_putuint16(buffer, (isc_uint16_t)r.length);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Copy the rdata to the buffer.
229ce407c359b0b641759ba1fc4a5fa2054a44daBrian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = isc_buffer_copyregion(buffer, &r);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_reset(&rdata);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = dns_rdataset_next(rdataset);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington }
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (result != ISC_R_NOMORE)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (result);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (ISC_R_SUCCESS);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonisc_result_t
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtondns_ncache_add(dns_message_t *message, dns_db_t *cache, dns_dbnode_t *node,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_rdatatype_t covers, isc_stdtime_t now, dns_ttl_t maxttl,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_t *addedrdataset)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (dns_ncache_addoptout(message, cache, node, covers, now, maxttl,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_FALSE, addedrdataset));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
92ef1a9b9dbd48ecb507b42ac62c15afefdaf838David Lawrence
571688b02f955f6304649866e768b1f81739cbedBrian Wellingtonisc_result_t
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeindns_ncache_addoptout(dns_message_t *message, dns_db_t *cache,
571688b02f955f6304649866e768b1f81739cbedBrian Wellington dns_dbnode_t *node, dns_rdatatype_t covers,
571688b02f955f6304649866e768b1f81739cbedBrian Wellington isc_stdtime_t now, dns_ttl_t maxttl,
571688b02f955f6304649866e768b1f81739cbedBrian Wellington isc_boolean_t optout, dns_rdataset_t *addedrdataset)
571688b02f955f6304649866e768b1f81739cbedBrian Wellington{
571688b02f955f6304649866e768b1f81739cbedBrian Wellington isc_result_t result;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_t buffer;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_region_t r;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_t *rdataset;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatatype_t type;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_t *name;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein dns_ttl_t ttl;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_trust_t trust;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_t rdata[DNS_NCACHE_RDATA];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_t ncrdataset;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatalist_t ncrdatalist;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned char data[4096];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int next = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
557bcc2092642b2d4668c9b08872c9f2bb88bddbMark Andrews * Convert the authority data from 'message' into a negative cache
557bcc2092642b2d4668c9b08872c9f2bb88bddbMark Andrews * rdataset, and store it in 'cache' at 'node'.
557bcc2092642b2d4668c9b08872c9f2bb88bddbMark Andrews */
557bcc2092642b2d4668c9b08872c9f2bb88bddbMark Andrews
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington REQUIRE(message != NULL);
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington /*
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington * We assume that all data in the authority section has been
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington * validated by the caller.
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington */
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington /*
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington * Initialize the list.
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington */
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington ncrdatalist.rdclass = dns_db_class(cache);
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington ncrdatalist.type = 0;
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington ncrdatalist.covers = covers;
557bcc2092642b2d4668c9b08872c9f2bb88bddbMark Andrews ncrdatalist.ttl = maxttl;
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington ISC_LIST_INIT(ncrdatalist.rdata);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LINK_INIT(&ncrdatalist, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington /*
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington * Build an ncache rdatas into buffer.
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington */
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington ttl = maxttl;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington trust = 0xffff;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_init(&buffer, data, sizeof(data));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (message->counts[DNS_SECTION_AUTHORITY])
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_message_firstname(message, DNS_SECTION_AUTHORITY);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington else
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = ISC_R_NOMORE;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington while (result == ISC_R_SUCCESS) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington name = NULL;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_message_currentname(message, DNS_SECTION_AUTHORITY,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington &name);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if ((name->attributes & DNS_NAMEATTR_NCACHE) != 0) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington for (rdataset = ISC_LIST_HEAD(name->list);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset != NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset = ISC_LIST_NEXT(rdataset, link)) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if ((rdataset->attributes &
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington DNS_RDATASETATTR_NCACHE) == 0)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington continue;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington type = rdataset->type;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (type == dns_rdatatype_rrsig)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington type = rdataset->covers;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (type == dns_rdatatype_soa ||
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington type == dns_rdatatype_nsec ||
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington type == dns_rdatatype_nsec3) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (ttl > rdataset->ttl)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington ttl = rdataset->ttl;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (trust > rdataset->trust)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington trust = rdataset->trust;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington /*
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * Copy the owner name to the buffer.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_name_toregion(name, &r);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = isc_buffer_copyregion(&buffer,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington &r);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (result != ISC_R_SUCCESS)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (result);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington /*
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * Copy the type to the buffer.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_buffer_availableregion(&buffer,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington &r);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (r.length < 3)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (ISC_R_NOSPACE);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_buffer_putuint16(&buffer,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->type);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_buffer_putuint8(&buffer,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington (unsigned char)rdataset->trust);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington /*
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * Copy the rdataset into the buffer.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = copy_rdataset(rdataset,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington &buffer);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (next >= DNS_NCACHE_RDATA)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOSPACE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_init(&rdata[next]);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_remainingregion(&buffer, &r);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdata[next].data = r.base;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdata[next].length = r.length;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdata[next].rdclass =
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington ncrdatalist.rdclass;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington rdata[next].type = 0;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington rdata[next].flags = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_APPEND(ncrdatalist.rdata,
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington &rdata[next], link);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_buffer_forward(&buffer, r.length);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington next++;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington }
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington }
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington result = dns_message_nextname(message, DNS_SECTION_AUTHORITY);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington }
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington if (result != ISC_R_NOMORE)
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington return (result);
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (trust == 0xffff) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington if ((message->flags & DNS_MESSAGEFLAG_AA) != 0 &&
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington message->counts[DNS_SECTION_ANSWER] == 0) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington /*
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington * The response has aa set and we haven't followed
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington * any CNAME or DNAME chains.
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington */
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington trust = dns_trust_authauthority;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington } else
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington trust = dns_trust_additional;
18d0b5e54be891a1aa938c165b6d439859121ec8Mark Andrews ttl = 0;
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington }
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington INSIST(trust != 0xffff);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington ncrdatalist.ttl = ttl;
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington dns_rdataset_init(&ncrdataset);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington RUNTIME_CHECK(dns_rdatalist_tordataset(&ncrdatalist, &ncrdataset)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington == ISC_R_SUCCESS);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ncrdataset.trust = trust;
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington if (message->rcode == dns_rcode_nxdomain)
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington ncrdataset.attributes |= DNS_RDATASETATTR_NXDOMAIN;
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington if (optout)
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington ncrdataset.attributes |= DNS_RDATASETATTR_OPTOUT;
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington return (dns_db_addrdataset(cache, node, NULL, now, &ncrdataset,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington 0, addedrdataset));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonisc_result_t
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtondns_ncache_towire(dns_rdataset_t *rdataset, dns_compress_t *cctx,
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_buffer_t *target, unsigned int options,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int *countp)
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington{
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dns_rdata_t rdata = DNS_RDATA_INIT;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_result_t result;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_region_t remaining, tavailable;
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington isc_buffer_t source, savedbuffer, rdlen;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dns_name_t name;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dns_rdatatype_t type;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington unsigned int i, rcount, count;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington /*
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington * Convert the negative caching rdataset 'rdataset' to wire format,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * compressing names as specified in 'cctx', and storing the result in
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * 'target'.
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellington */
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
de32cbd34e78bdd276e69cff239846760d4ee16eBrian Wellington REQUIRE(rdataset != NULL);
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews REQUIRE(rdataset->type == 0);
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellington savedbuffer = *target;
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellington count = 0;
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellington result = dns_rdataset_first(rdataset);
d2aebe24c477c70e79dc33ea0507e8886eb7d626Brian Wellington while (result == ISC_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_current(rdataset, &rdata);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_init(&source, rdata.data, rdata.length);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_add(&source, rdata.length);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_init(&name, NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_remainingregion(&source, &remaining);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_fromregion(&name, &remaining);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson INSIST(remaining.length >= name.length);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_forward(&source, name.length);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington remaining.length -= name.length;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(remaining.length >= 5);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington type = isc_buffer_getuint16(&source);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_forward(&source, 1);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rcount = isc_buffer_getuint16(&source);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington for (i = 0; i < rcount; i++) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Get the length of this rdata and set up an
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * rdata structure for it.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_remainingregion(&source, &remaining);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(remaining.length >= 2);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_reset(&rdata);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdata.length = isc_buffer_getuint16(&source);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_remainingregion(&source, &remaining);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdata.data = remaining.base;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdata.type = type;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdata.rdclass = rdataset->rdclass;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(remaining.length >= rdata.length);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_forward(&source, rdata.length);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if ((options & DNS_NCACHETOWIRE_OMITDNSSEC) != 0 &&
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatatype_isdnssec(type))
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington continue;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Write the name.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = dns_name_towire(&name, cctx, target);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (result != ISC_R_SUCCESS)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson goto rollback;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson /*
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson * See if we have space for type, class, ttl, and
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson * rdata length. Write the type, class, and ttl.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_availableregion(target, &tavailable);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (tavailable.length < 10) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = ISC_R_NOSPACE;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson goto rollback;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson }
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_putuint16(target, type);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_putuint16(target, rdataset->rdclass);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_putuint32(target, rdataset->ttl);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson /*
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson * Save space for rdata length.
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson */
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson rdlen = *target;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_add(target, 2);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson /*
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson * Write the rdata.
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson */
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = dns_rdata_towire(&rdata, cctx, target);
daa73eae708d568d453e6082e0890d35886a9e0fMark Andrews if (result != ISC_R_SUCCESS)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson goto rollback;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson /*
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson * Set the rdata length field to the compressed
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson * length.
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson */
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson INSIST((target->used >= rdlen.used + 2) &&
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson (target->used - rdlen.used - 2 < 65536));
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_putuint16(&rdlen,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson (isc_uint16_t)(target->used -
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson rdlen.used - 2));
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson count++;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson }
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson INSIST(isc_buffer_remaininglength(&source) == 0);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = dns_rdataset_next(rdataset);
daa73eae708d568d453e6082e0890d35886a9e0fMark Andrews dns_rdata_reset(&rdata);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson }
daa73eae708d568d453e6082e0890d35886a9e0fMark Andrews if (result != ISC_R_NOMORE)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson goto rollback;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *countp = count;
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington return (ISC_R_SUCCESS);
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington rollback:
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington INSIST(savedbuffer.used < 65536);
a4c351fcef77fb332e3cb20253fb96556a414a17Brian Wellington dns_compress_rollback(cctx, (isc_uint16_t)savedbuffer.used);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *countp = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *target = savedbuffer;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson}
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssonstatic void
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssonrdataset_disassociate(dns_rdataset_t *rdataset) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson UNUSED(rdataset);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic isc_result_t
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonrdataset_first(dns_rdataset_t *rdataset) {
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews unsigned char *raw = rdataset->private3;
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews unsigned int count;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson count = raw[0] * 256 + raw[1];
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (count == 0) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->private5 = NULL;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson return (ISC_R_NOMORE);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson }
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson raw += 2;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson /*
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson * The privateuint4 field is the number of rdata beyond the cursor
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews * position, so we decrement the total count by one before storing
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson * it.
229ce407c359b0b641759ba1fc4a5fa2054a44daBrian Wellington */
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson count--;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson rdataset->privateuint4 = count;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson rdataset->private5 = raw;
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews return (ISC_R_SUCCESS);
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews}
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrews
6b79e960e6ba2991aeb02a6c39af255ab7f06d99Mark Andrewsstatic isc_result_t
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssonrdataset_next(dns_rdataset_t *rdataset) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson unsigned int count;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int length;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned char *raw;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington count = rdataset->privateuint4;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (count == 0)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOMORE);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson count--;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson rdataset->privateuint4 = count;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson raw = rdataset->private5;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington length = raw[0] * 256 + raw[1];
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson raw += length + 2;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson rdataset->private5 = raw;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_SUCCESS);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic void
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonrdataset_current(dns_rdataset_t *rdataset, dns_rdata_t *rdata) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson unsigned char *raw = rdataset->private5;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_region_t r;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington REQUIRE(raw != NULL);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington r.length = raw[0] * 256 + raw[1];
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington raw += 2;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington r.base = raw;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_rdata_fromregion(rdata, rdataset->rdclass, rdataset->type, &r);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic void
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonrdataset_clone(dns_rdataset_t *source, dns_rdataset_t *target) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington *target = *source;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington /*
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * Reset iterator state.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington */
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington target->privateuint4 = 0;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington target->private5 = NULL;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic unsigned int
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonrdataset_count(dns_rdataset_t *rdataset) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington unsigned char *raw = rdataset->private3;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington unsigned int count;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington count = raw[0] * 256 + raw[1];
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington return (count);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic void
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonrdataset_settrust(dns_rdataset_t *rdataset, dns_trust_t trust) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington unsigned char *raw = rdataset->private3;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington raw[-1] = (unsigned char)trust;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington}
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic dns_rdatasetmethods_t rdataset_methods = {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington rdataset_disassociate,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington rdataset_first,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington rdataset_next,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington rdataset_current,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington rdataset_clone,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington rdataset_count,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington NULL,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington NULL,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington NULL,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington NULL,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington NULL,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington NULL,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington NULL,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington rdataset_settrust,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson NULL
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson};
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssonisc_result_t
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssondns_ncache_getrdataset(dns_rdataset_t *ncacherdataset, dns_name_t *name,
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_rdatatype_t type, dns_rdataset_t *rdataset)
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson{
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_result_t result;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_rdata_t rdata = DNS_RDATA_INIT;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_region_t remaining;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson isc_buffer_t source;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_name_t tname;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_rdatatype_t ttype;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington dns_trust_t trust = dns_trust_none;
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_rdataset_t clone;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson REQUIRE(ncacherdataset != NULL);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson REQUIRE(ncacherdataset->type == 0);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson REQUIRE(name != NULL);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson REQUIRE(!dns_rdataset_isassociated(rdataset));
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson REQUIRE(type != dns_rdatatype_rrsig);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_rdataset_init(&clone);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_rdataset_clone(ncacherdataset, &clone);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = dns_rdataset_first(&clone);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson while (result == ISC_R_SUCCESS) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_rdataset_current(&clone, &rdata);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_buffer_init(&source, rdata.data, rdata.length);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_buffer_add(&source, rdata.length);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_init(&tname, NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_remainingregion(&source, &remaining);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_fromregion(&tname, &remaining);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(remaining.length >= tname.length);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_forward(&source, tname.length);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington remaining.length -= tname.length;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(remaining.length >= 3);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ttype = isc_buffer_getuint16(&source);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson if (ttype == type && dns_name_equal(&tname, name)) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington trust = isc_buffer_getuint8(&source);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(trust <= dns_trust_ultimate);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_remainingregion(&source, &remaining);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdataset_next(&clone);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_reset(&rdata);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_disassociate(&clone);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result == ISC_R_NOMORE)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOTFOUND);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(remaining.length != 0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->methods = &rdataset_methods;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->rdclass = ncacherdataset->rdclass;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->type = type;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->covers = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->ttl = ncacherdataset->ttl;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->trust = trust;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->private1 = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->private2 = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->private3 = remaining.base;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Reset iterator state.
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->privateuint4 = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->private5 = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->private6 = NULL;
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington return (ISC_R_SUCCESS);
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington}
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellington
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellingtonisc_result_t
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellingtondns_ncache_getsigrdataset(dns_rdataset_t *ncacherdataset, dns_name_t *name,
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington dns_rdatatype_t covers, dns_rdataset_t *rdataset)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_t tname;
5e387b9ce6bafdfadedb5b34e4c33a4404e5d589Brian Wellington dns_rdata_rrsig_t rrsig;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_t rdata = DNS_RDATA_INIT;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_t clone;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatatype_t type;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_trust_t trust = dns_trust_none;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_t source;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_region_t remaining, sigregion;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_result_t result;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned char *raw;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int count;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(ncacherdataset != NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(ncacherdataset->type == 0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(name != NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(!dns_rdataset_isassociated(rdataset));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_init(&clone);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_clone(ncacherdataset, &clone);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdataset_first(&clone);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington while (result == ISC_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_current(&clone, &rdata);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_init(&source, rdata.data, rdata.length);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_add(&source, rdata.length);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_init(&tname, NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_remainingregion(&source, &remaining);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_fromregion(&tname, &remaining);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(remaining.length >= tname.length);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_forward(&source, tname.length);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington remaining.length -= tname.length;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington remaining.base += tname.length;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(remaining.length >= 2);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington type = isc_buffer_getuint16(&source);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington remaining.length -= 2;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington remaining.base += 2;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (type != dns_rdatatype_rrsig ||
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington !dns_name_equal(&tname, name)) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdataset_next(&clone);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_reset(&rdata);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington continue;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(remaining.length >= 1);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington trust = isc_buffer_getuint8(&source);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(trust <= dns_trust_ultimate);
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews remaining.length -= 1;
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews remaining.base += 1;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington raw = remaining.base;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington count = raw[0] * 256 + raw[1];
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews INSIST(count > 0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington raw += 2;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sigregion.length = raw[0] * 256 + raw[1];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington raw += 2;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sigregion.base = raw;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_reset(&rdata);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_fromregion(&rdata, rdataset->rdclass,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatatype_rrsig, &sigregion);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (void)dns_rdata_tostruct(&rdata, &rrsig, NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (rrsig.covered == covers) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_remainingregion(&source, &remaining);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington break;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_rdataset_next(&clone);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_reset(&rdata);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington }
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_disassociate(&clone);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result == ISC_R_NOMORE)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_NOTFOUND);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (result != ISC_R_SUCCESS)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (result);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(remaining.length != 0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->methods = &rdataset_methods;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->rdclass = ncacherdataset->rdclass;
c0d2891f6e08fcf5379dfb9a1bf8fbbb63f1952aMark Andrews rdataset->type = dns_rdatatype_rrsig;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->covers = covers;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->ttl = ncacherdataset->ttl;
c0d2891f6e08fcf5379dfb9a1bf8fbbb63f1952aMark Andrews rdataset->trust = trust;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->private1 = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->private2 = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->private3 = remaining.base;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Reset iterator state.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->privateuint4 = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->private5 = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->private6 = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington return (ISC_R_SUCCESS);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonvoid
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtondns_ncache_current(dns_rdataset_t *ncacherdataset, dns_name_t *found,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_t *rdataset)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington{
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_t rdata = DNS_RDATA_INIT;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_trust_t trust;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_region_t remaining, sigregion;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_t source;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_t tname;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdatatype_t type;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned int count;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_rrsig_t rrsig;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington unsigned char *raw;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington REQUIRE(ncacherdataset != NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(ncacherdataset->type == 0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(found != NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington REQUIRE(!dns_rdataset_isassociated(rdataset));
18d0b5e54be891a1aa938c165b6d439859121ec8Mark Andrews
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdataset_current(ncacherdataset, &rdata);
229ce407c359b0b641759ba1fc4a5fa2054a44daBrian Wellington isc_buffer_init(&source, rdata.data, rdata.length);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_add(&source, rdata.length);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_init(&tname, NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_remainingregion(&source, &remaining);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_name_fromregion(found, &remaining);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(remaining.length >= found->length);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_buffer_forward(&source, found->length);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington remaining.length -= found->length;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(remaining.length >= 5);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington type = isc_buffer_getuint16(&source);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington trust = isc_buffer_getuint8(&source);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(trust <= dns_trust_ultimate);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington isc_buffer_remainingregion(&source, &remaining);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington rdataset->methods = &rdataset_methods;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington rdataset->rdclass = ncacherdataset->rdclass;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->type = type;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (type == dns_rdatatype_rrsig) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Extract covers from RRSIG.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington raw = remaining.base;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington count = raw[0] * 256 + raw[1];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington INSIST(count > 0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington raw += 2;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington sigregion.length = raw[0] * 256 + raw[1];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington raw += 2;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington sigregion.base = raw;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_reset(&rdata);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington dns_rdata_fromregion(&rdata, rdataset->rdclass,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->type, &sigregion);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (void)dns_rdata_tostruct(&rdata, &rrsig, NULL);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->covers = rrsig.covered;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington } else
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington rdataset->covers = 0;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington rdataset->ttl = ncacherdataset->ttl;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington rdataset->trust = trust;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington rdataset->private1 = NULL;
5e387b9ce6bafdfadedb5b34e4c33a4404e5d589Brian Wellington rdataset->private2 = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington rdataset->private3 = remaining.base;
daa73eae708d568d453e6082e0890d35886a9e0fMark Andrews
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /*
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Reset iterator state.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->privateuint4 = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->private5 = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington rdataset->private6 = NULL;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington}
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington