ncache.c revision 29d52c001ff976561669375cf0c866b815a90c49
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer/*
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington * Copyright (C) 2004, 2005, 2007, 2008, 2010-2015 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Copyright (C) 1999-2003 Internet Software Consortium.
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer *
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer * Permission to use, copy, modify, and/or distribute this software for any
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer * purpose with or without fee is hereby granted, provided that the above
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * copyright notice and this permission notice appear in all copies.
15a44745412679c30a6d022733925af70a38b715David Lawrence *
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
15a44745412679c30a6d022733925af70a38b715David Lawrence * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15a44745412679c30a6d022733925af70a38b715David Lawrence * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
15a44745412679c30a6d022733925af70a38b715David Lawrence * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15a44745412679c30a6d022733925af70a38b715David Lawrence * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15a44745412679c30a6d022733925af70a38b715David Lawrence * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15a44745412679c30a6d022733925af70a38b715David Lawrence * PERFORMANCE OF THIS SOFTWARE.
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer */
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
066cb385cd8f801dd3757db2922c9b1f343e65edAndreas Gustafsson/* $Id$ */
47058d17266420179fa294de6b82d8fb5b918df4Michael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer/*! \file */
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer#include <config.h>
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer#include <isc/buffer.h>
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer#include <isc/util.h>
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer#include <dns/db.h>
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer#include <dns/message.h>
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington#include <dns/ncache.h>
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer#include <dns/rdata.h>
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer#include <dns/rdatalist.h>
c9defbf4b968e8a61f391246431ac63d0d6a39abMichael Sawyer#include <dns/rdataset.h>
1893b56ef9f5f2bc2a0fbe80d3c6b69df1bdc7c2Michael Sawyer#include <dns/rdatastruct.h>
55bf97a1b4b7f78b669b1179df1422cb9789c484Michael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer#define DNS_NCACHE_RDATA 20U
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer/*
55bf97a1b4b7f78b669b1179df1422cb9789c484Michael Sawyer * The format of an ncache rdata is a sequence of zero or more records of
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer * the following format:
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer *
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer * owner name
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson * type
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer * trust
55bf97a1b4b7f78b669b1179df1422cb9789c484Michael Sawyer * rdata count
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer * rdata length These two occur 'rdata count'
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer * rdata times.
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer *
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer */
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerstatic isc_result_t
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyeraddoptout(dns_message_t *message, dns_db_t *cache, dns_dbnode_t *node,
056aaae3e2399b2c1df8f82be52d9bd43ceda50cMichael Sawyer dns_rdatatype_t covers, isc_stdtime_t now, dns_ttl_t maxttl,
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer isc_boolean_t optout, isc_boolean_t secure,
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer dns_rdataset_t *addedrdataset);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerstatic inline isc_result_t
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyercopy_rdataset(dns_rdataset_t *rdataset, isc_buffer_t *buffer) {
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer isc_result_t result;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer unsigned int count;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer isc_region_t ar, r;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer dns_rdata_t rdata = DNS_RDATA_INIT;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer /*
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer * Copy the rdataset count to the buffer.
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer */
1893b56ef9f5f2bc2a0fbe80d3c6b69df1bdc7c2Michael Sawyer isc_buffer_availableregion(buffer, &ar);
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington if (ar.length < 2)
38cf6e52ce4b33795713388824b69d78e430b115Michael Sawyer return (ISC_R_NOSPACE);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer count = dns_rdataset_count(rdataset);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer INSIST(count <= 65535);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_putuint16(buffer, (isc_uint16_t)count);
6c6a62933dda281cb9193de1d54d4c9e74515f5aMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer result = dns_rdataset_first(rdataset);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer while (result == ISC_R_SUCCESS) {
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer dns_rdataset_current(rdataset, &rdata);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer dns_rdata_toregion(&rdata, &r);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer INSIST(r.length <= 65535);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer isc_buffer_availableregion(buffer, &ar);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer if (ar.length < 2)
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer return (ISC_R_NOSPACE);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer /*
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer * Copy the rdata length to the buffer.
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_putuint16(buffer, (isc_uint16_t)r.length);
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington /*
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer * Copy the rdata to the buffer.
a5ed46c9fd270775c39770bfd0250a52d374ebf2Michael Sawyer */
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer result = isc_buffer_copyregion(buffer, &r);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer if (result != ISC_R_SUCCESS)
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer return (result);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer dns_rdata_reset(&rdata);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer result = dns_rdataset_next(rdataset);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer }
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer if (result != ISC_R_NOMORE)
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer return (result);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer return (ISC_R_SUCCESS);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer}
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerisc_result_t
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerdns_ncache_add(dns_message_t *message, dns_db_t *cache, dns_dbnode_t *node,
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer dns_rdatatype_t covers, isc_stdtime_t now, dns_ttl_t maxttl,
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer dns_rdataset_t *addedrdataset)
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer{
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer return (addoptout(message, cache, node, covers, now, maxttl,
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer ISC_FALSE, ISC_FALSE, addedrdataset));
a5ed46c9fd270775c39770bfd0250a52d374ebf2Michael Sawyer}
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerisc_result_t
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerdns_ncache_addoptout(dns_message_t *message, dns_db_t *cache,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_dbnode_t *node, dns_rdatatype_t covers,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_stdtime_t now, dns_ttl_t maxttl,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_boolean_t optout, dns_rdataset_t *addedrdataset)
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington{
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington return (addoptout(message, cache, node, covers, now, maxttl,
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington optout, ISC_TRUE, addedrdataset));
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington}
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerstatic isc_result_t
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyeraddoptout(dns_message_t *message, dns_db_t *cache, dns_dbnode_t *node,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_rdatatype_t covers, isc_stdtime_t now, dns_ttl_t maxttl,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_boolean_t optout, isc_boolean_t secure,
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington dns_rdataset_t *addedrdataset)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer{
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_result_t result;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_t buffer;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_region_t r;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_rdataset_t *rdataset;
e32394a2ac3466a2235f79ee32c247a11be42a8dAndreas Gustafsson dns_rdatatype_t type;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_name_t *name;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_ttl_t ttl;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_trust_t trust;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_rdata_t rdata[DNS_NCACHE_RDATA];
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington dns_rdataset_t ncrdataset;
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington dns_rdatalist_t ncrdatalist;
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington unsigned char data[4096];
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington unsigned int next = 0;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer /*
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer * Convert the authority data from 'message' into a negative cache
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington * rdataset, and store it in 'cache' at 'node'.
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer REQUIRE(message != NULL);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer /*
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer * We assume that all data in the authority section has been
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington * validated by the caller.
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
066cb385cd8f801dd3757db2922c9b1f343e65edAndreas Gustafsson /*
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer * Initialize the list.
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington */
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington dns_rdatalist_init(&ncrdatalist);
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington ncrdatalist.rdclass = dns_db_class(cache);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer ncrdatalist.covers = covers;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ncrdatalist.ttl = maxttl;
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington /*
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington * Build an ncache rdatas into buffer.
cc48bb397fa6ba889f25157840492e68114dec8fBrian Wellington */
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington ttl = maxttl;
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington trust = 0xffff;
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington isc_buffer_init(&buffer, data, sizeof(data));
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington if (message->counts[DNS_SECTION_AUTHORITY])
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington result = dns_message_firstname(message, DNS_SECTION_AUTHORITY);
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington else
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington result = ISC_R_NOMORE;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer while (result == ISC_R_SUCCESS) {
cc48bb397fa6ba889f25157840492e68114dec8fBrian Wellington name = NULL;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer dns_message_currentname(message, DNS_SECTION_AUTHORITY,
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer &name);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson if ((name->attributes & DNS_NAMEATTR_NCACHE) != 0) {
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson for (rdataset = ISC_LIST_HEAD(name->list);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson rdataset != NULL;
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson rdataset = ISC_LIST_NEXT(rdataset, link)) {
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer if ((rdataset->attributes &
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer DNS_RDATASETATTR_NCACHE) == 0)
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer continue;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer type = rdataset->type;
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson if (type == dns_rdatatype_rrsig)
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson type = rdataset->covers;
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson if (type == dns_rdatatype_soa ||
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer type == dns_rdatatype_nsec ||
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer type == dns_rdatatype_nsec3) {
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer if (ttl > rdataset->ttl)
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer ttl = rdataset->ttl;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (trust > rdataset->trust)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer trust = rdataset->trust;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer /*
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer * Copy the owner name to the buffer.
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_name_toregion(name, &r);
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews result = isc_buffer_copyregion(&buffer,
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson &r);
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson if (result != ISC_R_SUCCESS)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer return (result);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson /*
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson * Copy the type to the buffer.
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_availableregion(&buffer,
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer &r);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (r.length < 3)
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer return (ISC_R_NOSPACE);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer isc_buffer_putuint16(&buffer,
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer rdataset->type);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer isc_buffer_putuint8(&buffer,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer (unsigned char)rdataset->trust);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer /*
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer * Copy the rdataset into the buffer.
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence result = copy_rdataset(rdataset,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer &buffer);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer if (result != ISC_R_SUCCESS)
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer return (result);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (next >= DNS_NCACHE_RDATA)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer return (ISC_R_NOSPACE);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson dns_rdata_init(&rdata[next]);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson isc_buffer_remainingregion(&buffer, &r);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer rdata[next].data = r.base;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer rdata[next].length = r.length;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer rdata[next].rdclass =
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson ncrdatalist.rdclass;
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson rdata[next].type = 0;
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson rdata[next].flags = 0;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ISC_LIST_APPEND(ncrdatalist.rdata,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer &rdata[next], link);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_forward(&buffer, r.length);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer next++;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer result = dns_message_nextname(message, DNS_SECTION_AUTHORITY);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer }
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (result != ISC_R_NOMORE)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer return (result);
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson if (trust == 0xffff) {
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson if ((message->flags & DNS_MESSAGEFLAG_AA) != 0 &&
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson message->counts[DNS_SECTION_ANSWER] == 0) {
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson /*
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson * The response has aa set and we haven't followed
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer * any CNAME or DNAME chains.
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson */
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson trust = dns_trust_authauthority;
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson } else
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson trust = dns_trust_additional;
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson ttl = 0;
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson }
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson INSIST(trust != 0xffff);
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson ncrdatalist.ttl = ttl;
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson dns_rdataset_init(&ncrdataset);
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson RUNTIME_CHECK(dns_rdatalist_tordataset(&ncrdatalist, &ncrdataset)
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson == ISC_R_SUCCESS);
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson if (!secure && trust > dns_trust_answer)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer trust = dns_trust_answer;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ncrdataset.trust = trust;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer ncrdataset.attributes |= DNS_RDATASETATTR_NEGATIVE;
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson if (message->rcode == dns_rcode_nxdomain)
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson ncrdataset.attributes |= DNS_RDATASETATTR_NXDOMAIN;
066cb385cd8f801dd3757db2922c9b1f343e65edAndreas Gustafsson if (optout)
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson ncrdataset.attributes |= DNS_RDATASETATTR_OPTOUT;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer return (dns_db_addrdataset(cache, node, NULL, now, &ncrdataset,
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson 0, addedrdataset));
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson}
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerisc_result_t
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrencedns_ncache_towire(dns_rdataset_t *rdataset, dns_compress_t *cctx,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_t *target, unsigned int options,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer unsigned int *countp)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer{
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_rdata_t rdata = DNS_RDATA_INIT;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_result_t result;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_region_t remaining, tavailable;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence isc_buffer_t source, savedbuffer, rdlen;
368b37b616234fce3d23099eb180f1dd38e1fb62Mark Andrews dns_name_t name;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_rdatatype_t type;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer unsigned int i, rcount, count;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer /*
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer * Convert the negative caching rdataset 'rdataset' to wire format,
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer * compressing names as specified in 'cctx', and storing the result in
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer * 'target'.
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer */
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer REQUIRE(rdataset != NULL);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer REQUIRE(rdataset->type == 0);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer REQUIRE((rdataset->attributes & DNS_RDATASETATTR_NEGATIVE) != 0);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer savedbuffer = *target;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer count = 0;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer result = dns_rdataset_first(rdataset);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer while (result == ISC_R_SUCCESS) {
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer dns_rdataset_current(rdataset, &rdata);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_buffer_init(&source, rdata.data, rdata.length);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_buffer_add(&source, rdata.length);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer dns_name_init(&name, NULL);
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews isc_buffer_remainingregion(&source, &remaining);
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson dns_name_fromregion(&name, &remaining);
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson INSIST(remaining.length >= name.length);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_buffer_forward(&source, name.length);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson remaining.length -= name.length;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
38cf6e52ce4b33795713388824b69d78e430b115Michael Sawyer INSIST(remaining.length >= 5);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer type = isc_buffer_getuint16(&source);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_buffer_forward(&source, 1);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer rcount = isc_buffer_getuint16(&source);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson for (i = 0; i < rcount; i++) {
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer /*
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer * Get the length of this rdata and set up an
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson * rdata structure for it.
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer */
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_buffer_remainingregion(&source, &remaining);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson INSIST(remaining.length >= 2);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer dns_rdata_reset(&rdata);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer rdata.length = isc_buffer_getuint16(&source);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson isc_buffer_remainingregion(&source, &remaining);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer rdata.data = remaining.base;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer rdata.type = type;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer rdata.rdclass = rdataset->rdclass;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer INSIST(remaining.length >= rdata.length);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_buffer_forward(&source, rdata.length);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if ((options & DNS_NCACHETOWIRE_OMITDNSSEC) != 0 &&
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer dns_rdatatype_isdnssec(type))
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer continue;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer /*
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer * Write the name.
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer result = dns_name_towire(&name, cctx, target);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (result != ISC_R_SUCCESS)
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer goto rollback;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer /*
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson * See if we have space for type, class, ttl, and
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson * rdata length. Write the type, class, and ttl.
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson */
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer isc_buffer_availableregion(target, &tavailable);
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson if (tavailable.length < 10) {
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson result = ISC_R_NOSPACE;
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson goto rollback;
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer }
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson isc_buffer_putuint16(target, type);
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson isc_buffer_putuint16(target, rdataset->rdclass);
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson isc_buffer_putuint32(target, rdataset->ttl);
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer /*
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer * Save space for rdata length.
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer */
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson rdlen = *target;
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson isc_buffer_add(target, 2);
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson /*
93988fb202645e5d06b337b8e3e20765a467149dAndreas Gustafsson * Write the rdata.
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer */
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer result = dns_rdata_towire(&rdata, cctx, target);
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson if (result != ISC_R_SUCCESS)
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson goto rollback;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson /*
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson * Set the rdata length field to the compressed
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson * length.
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson */
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson INSIST((target->used >= rdlen.used + 2) &&
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson (target->used - rdlen.used - 2 < 65536));
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson isc_buffer_putuint16(&rdlen,
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson (isc_uint16_t)(target->used -
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson rdlen.used - 2));
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson count++;
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson }
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson INSIST(isc_buffer_remaininglength(&source) == 0);
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson result = dns_rdataset_next(rdataset);
7ddb4c86a95ab721a70d406821352ce7b730a1bdAndreas Gustafsson dns_rdata_reset(&rdata);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer }
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (result != ISC_R_NOMORE)
066cb385cd8f801dd3757db2922c9b1f343e65edAndreas Gustafsson goto rollback;
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer *countp = count;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson return (ISC_R_SUCCESS);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer rollback:
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence INSIST(savedbuffer.used < 65536);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer dns_compress_rollback(cctx, (isc_uint16_t)savedbuffer.used);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer *countp = 0;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer *target = savedbuffer;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer return (result);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer}
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
368b37b616234fce3d23099eb180f1dd38e1fb62Mark Andrewsstatic void
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyerrdataset_disassociate(dns_rdataset_t *rdataset) {
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer UNUSED(rdataset);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer}
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyerstatic isc_result_t
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyerrdataset_first(dns_rdataset_t *rdataset) {
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer unsigned char *raw = rdataset->private3;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer unsigned int count;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer count = raw[0] * 256 + raw[1];
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer if (count == 0) {
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer rdataset->private5 = NULL;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer return (ISC_R_NOMORE);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer }
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer raw += 2;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer /*
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer * The privateuint4 field is the number of rdata beyond the cursor
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer * position, so we decrement the total count by one before storing
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer * it.
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer */
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer count--;
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson rdataset->privateuint4 = count;
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer rdataset->private5 = raw;
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer return (ISC_R_SUCCESS);
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer}
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyerstatic isc_result_t
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyerrdataset_next(dns_rdataset_t *rdataset) {
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer unsigned int count;
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer unsigned int length;
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer unsigned char *raw;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer count = rdataset->privateuint4;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (count == 0)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer return (ISC_R_NOMORE);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer count--;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer rdataset->privateuint4 = count;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer raw = rdataset->private5;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer length = raw[0] * 256 + raw[1];
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer raw += length + 2;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer rdataset->private5 = raw;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer return (ISC_R_SUCCESS);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson}
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyerstatic void
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyerrdataset_current(dns_rdataset_t *rdataset, dns_rdata_t *rdata) {
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson unsigned char *raw = rdataset->private5;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer isc_region_t r;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer REQUIRE(raw != NULL);
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer r.length = raw[0] * 256 + raw[1];
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson raw += 2;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer r.base = raw;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence dns_rdata_fromregion(rdata, rdataset->rdclass, rdataset->type, &r);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer}
7804502532d6e2eee80083431a22eb5d957f52a0Michael Sawyer
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyerstatic void
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyerrdataset_clone(dns_rdataset_t *source, dns_rdataset_t *target) {
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer *target = *source;
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer /*
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Reset iterator state.
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer */
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer target->privateuint4 = 0;
7804502532d6e2eee80083431a22eb5d957f52a0Michael Sawyer target->private5 = NULL;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer}
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyerstatic unsigned int
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyerrdataset_count(dns_rdataset_t *rdataset) {
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer unsigned char *raw = rdataset->private3;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer unsigned int count;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer count = raw[0] * 256 + raw[1];
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
f900be21902d02418c2c71ffed754fb3f9f54cffMichael Sawyer return (count);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer}
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyerstatic void
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyerrdataset_settrust(dns_rdataset_t *rdataset, dns_trust_t trust) {
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer unsigned char *raw = rdataset->private3;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer raw[-1] = (unsigned char)trust;
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer}
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyerstatic dns_rdatasetmethods_t rdataset_methods = {
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer rdataset_disassociate,
53e7d12ab53e74650c00ea4c0d6568bf675d8b17Michael Sawyer rdataset_first,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer rdataset_next,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer rdataset_current,
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson rdataset_clone,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer rdataset_count,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer NULL,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer NULL,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer NULL,
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer NULL,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer NULL,
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer NULL,
f900be21902d02418c2c71ffed754fb3f9f54cffMichael Sawyer NULL,
f900be21902d02418c2c71ffed754fb3f9f54cffMichael Sawyer rdataset_settrust,
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson NULL,
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson NULL,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer NULL,
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer NULL
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson};
844eaa56d6d647b38b2a5cf08f7ea5ab7b752690Michael Sawyer
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyerisc_result_t
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyerdns_ncache_getrdataset(dns_rdataset_t *ncacherdataset, dns_name_t *name,
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson dns_rdatatype_t type, dns_rdataset_t *rdataset)
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer{
32e783c745299f838dd7cf8ffe2032775a80f1d0Andreas Gustafsson isc_result_t result;
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer dns_rdata_t rdata = DNS_RDATA_INIT;
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer isc_region_t remaining;
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer isc_buffer_t source;
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer dns_name_t tname;
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer dns_rdatatype_t ttype;
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer dns_trust_t trust = dns_trust_none;
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer dns_rdataset_t clone;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer REQUIRE(ncacherdataset != NULL);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer REQUIRE(ncacherdataset->type == 0);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer REQUIRE((ncacherdataset->attributes & DNS_RDATASETATTR_NEGATIVE) != 0);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer REQUIRE(name != NULL);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer REQUIRE(!dns_rdataset_isassociated(rdataset));
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer REQUIRE(type != dns_rdatatype_rrsig);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer dns_rdataset_init(&clone);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer dns_rdataset_clone(ncacherdataset, &clone);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer result = dns_rdataset_first(&clone);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer while (result == ISC_R_SUCCESS) {
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer dns_rdataset_current(&clone, &rdata);
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer isc_buffer_init(&source, rdata.data, rdata.length);
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer isc_buffer_add(&source, rdata.length);
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer dns_name_init(&tname, NULL);
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer isc_buffer_remainingregion(&source, &remaining);
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer dns_name_fromregion(&tname, &remaining);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer INSIST(remaining.length >= tname.length);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer isc_buffer_forward(&source, tname.length);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer remaining.length -= tname.length;
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer INSIST(remaining.length >= 3);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer ttype = isc_buffer_getuint16(&source);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer if (ttype == type && dns_name_equal(&tname, name)) {
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer trust = isc_buffer_getuint8(&source);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer INSIST(trust <= dns_trust_ultimate);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer isc_buffer_remainingregion(&source, &remaining);
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer break;
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer }
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer result = dns_rdataset_next(&clone);
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer dns_rdata_reset(&rdata);
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer }
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer dns_rdataset_disassociate(&clone);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer if (result == ISC_R_NOMORE)
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer return (ISC_R_NOTFOUND);
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer if (result != ISC_R_SUCCESS)
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer return (result);
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer INSIST(remaining.length != 0);
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer rdataset->methods = &rdataset_methods;
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer rdataset->rdclass = ncacherdataset->rdclass;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer rdataset->type = type;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer rdataset->covers = 0;
32e783c745299f838dd7cf8ffe2032775a80f1d0Andreas Gustafsson rdataset->ttl = ncacherdataset->ttl;
f900be21902d02418c2c71ffed754fb3f9f54cffMichael Sawyer rdataset->trust = trust;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer rdataset->private1 = NULL;
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer rdataset->private2 = NULL;
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer rdataset->private3 = remaining.base;
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer /*
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer * Reset iterator state.
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer */
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer rdataset->privateuint4 = 0;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer rdataset->private5 = NULL;
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer rdataset->private6 = NULL;
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer return (ISC_R_SUCCESS);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer}
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyerisc_result_t
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerdns_ncache_getsigrdataset(dns_rdataset_t *ncacherdataset, dns_name_t *name,
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer dns_rdatatype_t covers, dns_rdataset_t *rdataset)
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer{
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_name_t tname;
e42c402595802edceafbd3e5338dda011fbbcdb6Michael Sawyer dns_rdata_rrsig_t rrsig;
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer dns_rdata_t rdata = DNS_RDATA_INIT;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_rdataset_t clone;
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer dns_rdatatype_t type;
8e61de2efdc23d1248cff0abf4cadec3325a929cMichael Sawyer dns_trust_t trust = dns_trust_none;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_t source;
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer isc_region_t remaining, sigregion;
8e61de2efdc23d1248cff0abf4cadec3325a929cMichael Sawyer isc_result_t result;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer unsigned char *raw;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer unsigned int count;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer REQUIRE(ncacherdataset != NULL);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer REQUIRE(ncacherdataset->type == 0);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer REQUIRE((ncacherdataset->attributes & DNS_RDATASETATTR_NEGATIVE) != 0);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer REQUIRE(name != NULL);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer REQUIRE(!dns_rdataset_isassociated(rdataset));
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer dns_rdataset_init(&clone);
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer dns_rdataset_clone(ncacherdataset, &clone);
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer result = dns_rdataset_first(&clone);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer while (result == ISC_R_SUCCESS) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_rdataset_current(&clone, &rdata);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_init(&source, rdata.data, rdata.length);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_add(&source, rdata.length);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_name_init(&tname, NULL);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_remainingregion(&source, &remaining);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_name_fromregion(&tname, &remaining);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer INSIST(remaining.length >= tname.length);
8e61de2efdc23d1248cff0abf4cadec3325a929cMichael Sawyer isc_buffer_forward(&source, tname.length);
8e61de2efdc23d1248cff0abf4cadec3325a929cMichael Sawyer remaining.length -= tname.length;
8e61de2efdc23d1248cff0abf4cadec3325a929cMichael Sawyer remaining.base += tname.length;
8e61de2efdc23d1248cff0abf4cadec3325a929cMichael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer INSIST(remaining.length >= 2);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer type = isc_buffer_getuint16(&source);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer remaining.length -= 2;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer remaining.base += 2;
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer if (type != dns_rdatatype_rrsig ||
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer !dns_name_equal(&tname, name)) {
d821f1cd7e97552401296e880e7518c98c9ebea1Michael Sawyer result = dns_rdataset_next(&clone);
aa2c453d3c6e416b56b29247bedd9a0af2721e93Mark Andrews dns_rdata_reset(&rdata);
aa2c453d3c6e416b56b29247bedd9a0af2721e93Mark Andrews continue;
aa2c453d3c6e416b56b29247bedd9a0af2721e93Mark Andrews }
aa2c453d3c6e416b56b29247bedd9a0af2721e93Mark Andrews
f8fec75ee8f429821137aee090f56ab678404a56Michael Sawyer INSIST(remaining.length >= 1);
6c6a62933dda281cb9193de1d54d4c9e74515f5aMichael Sawyer trust = isc_buffer_getuint8(&source);
48674819ebf9176b5d5582ae851e485c324c1159Michael Sawyer INSIST(trust <= dns_trust_ultimate);
1416cae3f614faf4067e8b5a6b4732e132958bbaAndreas Gustafsson remaining.length -= 1;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer remaining.base += 1;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer raw = remaining.base;
869f65bea49f8d65ab9bb14c4551215529bd7419David Lawrence count = raw[0] * 256 + raw[1];
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer INSIST(count > 0);
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer raw += 2;
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer sigregion.length = raw[0] * 256 + raw[1];
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer raw += 2;
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer sigregion.base = raw;
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer dns_rdata_reset(&rdata);
5d20773abcdf9ff3afe14a349413174f94594188Michael Sawyer dns_rdata_fromregion(&rdata, rdataset->rdclass,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_rdatatype_rrsig, &sigregion);
37e6e0ca1337351642798b1a6aa24ae40bf86399Andreas Gustafsson (void)dns_rdata_tostruct(&rdata, &rrsig, NULL);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer if (rrsig.covered == covers) {
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer isc_buffer_remainingregion(&source, &remaining);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer break;
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer }
32e783c745299f838dd7cf8ffe2032775a80f1d0Andreas Gustafsson
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer result = dns_rdataset_next(&clone);
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer dns_rdata_reset(&rdata);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer }
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer dns_rdataset_disassociate(&clone);
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer if (result == ISC_R_NOMORE)
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer return (ISC_R_NOTFOUND);
32e783c745299f838dd7cf8ffe2032775a80f1d0Andreas Gustafsson if (result != ISC_R_SUCCESS)
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer return (result);
3291587f23b940c986f41cf37b2e531f618ec2bdMichael Sawyer
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer INSIST(remaining.length != 0);
5d20773abcdf9ff3afe14a349413174f94594188Michael Sawyer
5d20773abcdf9ff3afe14a349413174f94594188Michael Sawyer rdataset->methods = &rdataset_methods;
55bf97a1b4b7f78b669b1179df1422cb9789c484Michael Sawyer rdataset->rdclass = ncacherdataset->rdclass;
cc7732e1299042bff430dfdfbc2624fb340047b2Michael Sawyer rdataset->type = dns_rdatatype_rrsig;
55bf97a1b4b7f78b669b1179df1422cb9789c484Michael Sawyer rdataset->covers = covers;
5d20773abcdf9ff3afe14a349413174f94594188Michael Sawyer rdataset->ttl = ncacherdataset->ttl;
55bf97a1b4b7f78b669b1179df1422cb9789c484Michael Sawyer rdataset->trust = trust;
cc7732e1299042bff430dfdfbc2624fb340047b2Michael Sawyer rdataset->private1 = NULL;
55bf97a1b4b7f78b669b1179df1422cb9789c484Michael Sawyer rdataset->private2 = NULL;
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer
cc7732e1299042bff430dfdfbc2624fb340047b2Michael Sawyer rdataset->private3 = remaining.base;
cd720113a2fc8a781d4e33350b8a2b62857b31d8David Lawrence
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer /*
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer * Reset iterator state.
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer */
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer rdataset->privateuint4 = 0;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer rdataset->private5 = NULL;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer rdataset->private6 = NULL;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer return (ISC_R_SUCCESS);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer}
9fe3676b8490319aa65182f2072cbf5086097979Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyervoid
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyerdns_ncache_current(dns_rdataset_t *ncacherdataset, dns_name_t *found,
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_rdataset_t *rdataset)
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer{
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_rdata_t rdata = DNS_RDATA_INIT;
17747cd5ee98901b435cd2b3019c52937955a981Michael Sawyer dns_trust_t trust;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer isc_region_t remaining, sigregion;
8e61de2efdc23d1248cff0abf4cadec3325a929cMichael Sawyer isc_buffer_t source;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer dns_name_t tname;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer dns_rdatatype_t type;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer unsigned int count;
38cf6e52ce4b33795713388824b69d78e430b115Michael Sawyer dns_rdata_rrsig_t rrsig;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer unsigned char *raw;
cefd68008fbba3488a077052ae62aa12b6de502bMichael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer REQUIRE(ncacherdataset != NULL);
cd720113a2fc8a781d4e33350b8a2b62857b31d8David Lawrence REQUIRE(ncacherdataset->type == 0);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer REQUIRE((ncacherdataset->attributes & DNS_RDATASETATTR_NEGATIVE) != 0);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer REQUIRE(found != NULL);
b266f8fc42702debc6bd89365273223fa89cd8ddBrian Wellington REQUIRE(!dns_rdataset_isassociated(rdataset));
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_rdataset_current(ncacherdataset, &rdata);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_init(&source, rdata.data, rdata.length);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_add(&source, rdata.length);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_name_init(&tname, NULL);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_remainingregion(&source, &remaining);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_name_fromregion(found, &remaining);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer INSIST(remaining.length >= found->length);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence isc_buffer_forward(&source, found->length);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer remaining.length -= found->length;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer INSIST(remaining.length >= 5);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer type = isc_buffer_getuint16(&source);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer trust = isc_buffer_getuint8(&source);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer INSIST(trust <= dns_trust_ultimate);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer isc_buffer_remainingregion(&source, &remaining);
f900be21902d02418c2c71ffed754fb3f9f54cffMichael Sawyer
f900be21902d02418c2c71ffed754fb3f9f54cffMichael Sawyer rdataset->methods = &rdataset_methods;
f900be21902d02418c2c71ffed754fb3f9f54cffMichael Sawyer rdataset->rdclass = ncacherdataset->rdclass;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer rdataset->type = type;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer if (type == dns_rdatatype_rrsig) {
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer /*
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer * Extract covers from RRSIG.
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer */
6fda1577669dca9e0d8e4832e407bac34cc12de6Mark Andrews raw = remaining.base;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer count = raw[0] * 256 + raw[1];
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer INSIST(count > 0);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer raw += 2;
cd720113a2fc8a781d4e33350b8a2b62857b31d8David Lawrence sigregion.length = raw[0] * 256 + raw[1];
07a926724c0a91d85b85a94441938d0094e88cffMark Andrews raw += 2;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer sigregion.base = raw;
07a926724c0a91d85b85a94441938d0094e88cffMark Andrews dns_rdata_reset(&rdata);
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer dns_rdata_fromregion(&rdata, rdataset->rdclass,
07a926724c0a91d85b85a94441938d0094e88cffMark Andrews rdataset->type, &sigregion);
07a926724c0a91d85b85a94441938d0094e88cffMark Andrews (void)dns_rdata_tostruct(&rdata, &rrsig, NULL);
07a926724c0a91d85b85a94441938d0094e88cffMark Andrews rdataset->covers = rrsig.covered;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer } else
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer rdataset->covers = 0;
07a926724c0a91d85b85a94441938d0094e88cffMark Andrews rdataset->ttl = ncacherdataset->ttl;
d7a2e0511222811b96f2e8757272ee383ec7b5e6Michael Sawyer rdataset->trust = trust;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer rdataset->private1 = NULL;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer rdataset->private2 = NULL;
07a926724c0a91d85b85a94441938d0094e88cffMark Andrews
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer rdataset->private3 = remaining.base;
07a926724c0a91d85b85a94441938d0094e88cffMark Andrews
e412ae947df6de858883564b8676a9650df70d9aMark Andrews /*
5f01e77fc23fe9665fa2b8acd0a0c5bfbf61d61dBrian Wellington * Reset iterator state.
07a926724c0a91d85b85a94441938d0094e88cffMark Andrews */
e412ae947df6de858883564b8676a9650df70d9aMark Andrews rdataset->privateuint4 = 0;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer rdataset->private5 = NULL;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer rdataset->private6 = NULL;
6fe03d6c83ec02d4494edc870f5e892d419b6885Michael Sawyer}
f900be21902d02418c2c71ffed754fb3f9f54cffMichael Sawyer