5619558151f1aa4249b3ead979e76876e29278b6Bob Halley/*
4269c3690697323b4c258ea279fbbe406dc356b3Tinderbox User * Copyright (C) 1999-2012, 2014-2017 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley */
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*! \file */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
110d1702731f42dd620879c1d765ebe91f3920ceMichael Graff#include <config.h>
110d1702731f42dd620879c1d765ebe91f3920ceMichael Graff
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley#include <stdlib.h>
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/buffer.h>
c569a0e4d518bf30be1b2ba9cc3592fe470e9822Mark Andrews#include <isc/mem.h>
def8e47c688e2480a4539d69c3d1a0a28a7c0550Mark Andrews#include <isc/random.h>
e7857b5ee05414961bb11f9e57f654163fae6acbckb#include <isc/serial.h>
364a82f7c25b62967678027043425201a5e5171aBob Halley#include <isc/util.h>
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews#include <dns/compress.h>
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews#include <dns/fixedname.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <dns/name.h>
8dfa9caeec8e68db0c937e347a3d6629e7627d54Bob Halley#include <dns/ncache.h>
54f959d12b5a1f9315fbf6a776c6d349316e9686Bob Halley#include <dns/rdata.h>
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley#include <dns/rdataset.h>
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
4100ae5109c69d8269a8fa626f217a15a633cd7fMark Andrewsstatic const char *trustnames[] = {
4100ae5109c69d8269a8fa626f217a15a633cd7fMark Andrews "none",
4100ae5109c69d8269a8fa626f217a15a633cd7fMark Andrews "pending-additional",
4100ae5109c69d8269a8fa626f217a15a633cd7fMark Andrews "pending-answer",
4100ae5109c69d8269a8fa626f217a15a633cd7fMark Andrews "additional",
4100ae5109c69d8269a8fa626f217a15a633cd7fMark Andrews "glue",
4100ae5109c69d8269a8fa626f217a15a633cd7fMark Andrews "answer",
4100ae5109c69d8269a8fa626f217a15a633cd7fMark Andrews "authauthority",
4100ae5109c69d8269a8fa626f217a15a633cd7fMark Andrews "authanswer",
4100ae5109c69d8269a8fa626f217a15a633cd7fMark Andrews "secure",
4100ae5109c69d8269a8fa626f217a15a633cd7fMark Andrews "local" /* aka ultimate */
4100ae5109c69d8269a8fa626f217a15a633cd7fMark Andrews};
4100ae5109c69d8269a8fa626f217a15a633cd7fMark Andrews
4100ae5109c69d8269a8fa626f217a15a633cd7fMark Andrewsconst char *
4100ae5109c69d8269a8fa626f217a15a633cd7fMark Andrewsdns_trust_totext(dns_trust_t trust) {
4100ae5109c69d8269a8fa626f217a15a633cd7fMark Andrews if (trust >= sizeof(trustnames)/sizeof(*trustnames))
4100ae5109c69d8269a8fa626f217a15a633cd7fMark Andrews return ("bad");
4100ae5109c69d8269a8fa626f217a15a633cd7fMark Andrews return (trustnames[trust]);
4100ae5109c69d8269a8fa626f217a15a633cd7fMark Andrews}
4100ae5109c69d8269a8fa626f217a15a633cd7fMark Andrews
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleyvoid
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleydns_rdataset_init(dns_rdataset_t *rdataset) {
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley /*
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley * Make 'rdataset' a valid, disassociated rdataset.
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley */
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley REQUIRE(rdataset != NULL);
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
078d49b63324f01d98301ee21671abee0c41fcdeBob Halley rdataset->magic = DNS_RDATASET_MAGIC;
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley rdataset->methods = NULL;
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley ISC_LINK_INIT(rdataset, link);
904a5734375869ffb504ed8cde6b68cafadb6d64Bob Halley rdataset->rdclass = 0;
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley rdataset->type = 0;
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley rdataset->ttl = 0;
ca67883a666bdf314d3da958d5195e7215b1f797Bob Halley rdataset->trust = 0;
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley rdataset->covers = 0;
b12f0228b32775ee688ed21ddbf3a116c1adfb43Michael Graff rdataset->attributes = 0;
61fb42c4ef45d88e115bd769c30c4f36b461870bMark Andrews rdataset->count = ISC_UINT32_MAX;
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley rdataset->private1 = NULL;
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley rdataset->private2 = NULL;
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley rdataset->private3 = NULL;
80b782f356f0692c11b4e52e8dd46ec41704e5a2Mark Andrews rdataset->privateuint4 = 0;
e496615043400500492fa7b891c515c8e7cb7d08Bob Halley rdataset->private5 = NULL;
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews rdataset->private6 = NULL;
ca77632f65c939d844f54b9bd48c17b77b817681Mark Andrews rdataset->private7 = NULL;
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews rdataset->resign = 0;
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley}
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleyvoid
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleydns_rdataset_invalidate(dns_rdataset_t *rdataset) {
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley /*
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley * Invalidate 'rdataset'.
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley */
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
078d49b63324f01d98301ee21671abee0c41fcdeBob Halley REQUIRE(DNS_RDATASET_VALID(rdataset));
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley REQUIRE(rdataset->methods == NULL);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley rdataset->magic = 0;
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley ISC_LINK_INIT(rdataset, link);
904a5734375869ffb504ed8cde6b68cafadb6d64Bob Halley rdataset->rdclass = 0;
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley rdataset->type = 0;
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley rdataset->ttl = 0;
ca67883a666bdf314d3da958d5195e7215b1f797Bob Halley rdataset->trust = 0;
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley rdataset->covers = 0;
b12f0228b32775ee688ed21ddbf3a116c1adfb43Michael Graff rdataset->attributes = 0;
61fb42c4ef45d88e115bd769c30c4f36b461870bMark Andrews rdataset->count = ISC_UINT32_MAX;
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley rdataset->private1 = NULL;
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley rdataset->private2 = NULL;
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley rdataset->private3 = NULL;
80b782f356f0692c11b4e52e8dd46ec41704e5a2Mark Andrews rdataset->privateuint4 = 0;
e496615043400500492fa7b891c515c8e7cb7d08Bob Halley rdataset->private5 = NULL;
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley}
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleyvoid
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleydns_rdataset_disassociate(dns_rdataset_t *rdataset) {
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley /*
2cd0c38115b1efb043ed3104c0d08e51ceade0d7Bob Halley * Disassociate 'rdataset' from its rdata, allowing it to be reused.
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley */
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
078d49b63324f01d98301ee21671abee0c41fcdeBob Halley REQUIRE(DNS_RDATASET_VALID(rdataset));
0180ccf72c79b98eb8ee5abbb7331aec6951dd9fBob Halley REQUIRE(rdataset->methods != NULL);
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley (rdataset->methods->disassociate)(rdataset);
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley rdataset->methods = NULL;
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley ISC_LINK_INIT(rdataset, link);
904a5734375869ffb504ed8cde6b68cafadb6d64Bob Halley rdataset->rdclass = 0;
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley rdataset->type = 0;
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley rdataset->ttl = 0;
ca67883a666bdf314d3da958d5195e7215b1f797Bob Halley rdataset->trust = 0;
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley rdataset->covers = 0;
b12f0228b32775ee688ed21ddbf3a116c1adfb43Michael Graff rdataset->attributes = 0;
61fb42c4ef45d88e115bd769c30c4f36b461870bMark Andrews rdataset->count = ISC_UINT32_MAX;
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley rdataset->private1 = NULL;
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley rdataset->private2 = NULL;
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley rdataset->private3 = NULL;
80b782f356f0692c11b4e52e8dd46ec41704e5a2Mark Andrews rdataset->privateuint4 = 0;
e496615043400500492fa7b891c515c8e7cb7d08Bob Halley rdataset->private5 = NULL;
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews rdataset->private6 = NULL;
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley}
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
28640d1da26d561f4137122fe64e9e8cc08bf11eBob Halleyisc_boolean_t
28640d1da26d561f4137122fe64e9e8cc08bf11eBob Halleydns_rdataset_isassociated(dns_rdataset_t *rdataset) {
28640d1da26d561f4137122fe64e9e8cc08bf11eBob Halley /*
28640d1da26d561f4137122fe64e9e8cc08bf11eBob Halley * Is 'rdataset' associated?
28640d1da26d561f4137122fe64e9e8cc08bf11eBob Halley */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
28640d1da26d561f4137122fe64e9e8cc08bf11eBob Halley REQUIRE(DNS_RDATASET_VALID(rdataset));
28640d1da26d561f4137122fe64e9e8cc08bf11eBob Halley
28640d1da26d561f4137122fe64e9e8cc08bf11eBob Halley if (rdataset->methods != NULL)
28640d1da26d561f4137122fe64e9e8cc08bf11eBob Halley return (ISC_TRUE);
28640d1da26d561f4137122fe64e9e8cc08bf11eBob Halley
28640d1da26d561f4137122fe64e9e8cc08bf11eBob Halley return (ISC_FALSE);
28640d1da26d561f4137122fe64e9e8cc08bf11eBob Halley}
28640d1da26d561f4137122fe64e9e8cc08bf11eBob Halley
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halleystatic void
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halleyquestion_disassociate(dns_rdataset_t *rdataset) {
e02884167b7c969b56413f76c48c3802c4dca14dAndreas Gustafsson UNUSED(rdataset);
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley}
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic isc_result_t
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halleyquestion_cursor(dns_rdataset_t *rdataset) {
e02884167b7c969b56413f76c48c3802c4dca14dAndreas Gustafsson UNUSED(rdataset);
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOMORE);
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley}
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halleystatic void
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halleyquestion_current(dns_rdataset_t *rdataset, dns_rdata_t *rdata) {
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley /*
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley * This routine should never be called.
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley */
e02884167b7c969b56413f76c48c3802c4dca14dAndreas Gustafsson UNUSED(rdataset);
e02884167b7c969b56413f76c48c3802c4dca14dAndreas Gustafsson UNUSED(rdata);
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley REQUIRE(0);
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley}
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halleystatic void
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halleyquestion_clone(dns_rdataset_t *source, dns_rdataset_t *target) {
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley *target = *source;
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley}
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halleystatic unsigned int
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halleyquestion_count(dns_rdataset_t *rdataset) {
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley /*
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley * This routine should never be called.
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley */
e02884167b7c969b56413f76c48c3802c4dca14dAndreas Gustafsson UNUSED(rdataset);
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley REQUIRE(0);
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley return (0);
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley}
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halleystatic dns_rdatasetmethods_t question_methods = {
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley question_disassociate,
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley question_cursor,
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley question_cursor,
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley question_current,
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley question_clone,
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews question_count,
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews NULL,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 NULL,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 NULL,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 NULL,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews NULL,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews NULL,
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews NULL,
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews NULL,
092d3b76db6b93b8029bd7d083e74fc80fb41858Mark Andrews NULL,
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews NULL,
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews NULL,
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews NULL
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley};
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halleyvoid
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halleydns_rdataset_makequestion(dns_rdataset_t *rdataset, dns_rdataclass_t rdclass,
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley dns_rdatatype_t type)
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley{
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley /*
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley * Make 'rdataset' a valid, associated, question rdataset, with a
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley * question class of 'rdclass' and type 'type'.
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley */
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley REQUIRE(DNS_RDATASET_VALID(rdataset));
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley REQUIRE(rdataset->methods == NULL);
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley rdataset->methods = &question_methods;
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley rdataset->rdclass = rdclass;
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley rdataset->type = type;
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley rdataset->attributes |= DNS_RDATASETATTR_QUESTION;
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley}
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halleyunsigned int
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halleydns_rdataset_count(dns_rdataset_t *rdataset) {
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley /*
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley * Return the number of records in 'rdataset'.
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley */
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley REQUIRE(DNS_RDATASET_VALID(rdataset));
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley REQUIRE(rdataset->methods != NULL);
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley return ((rdataset->methods->count)(rdataset));
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley}
7837d146219db7a85a4b444a9cdf6602254a4f75Bob Halley
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halleyvoid
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halleydns_rdataset_clone(dns_rdataset_t *source, dns_rdataset_t *target) {
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley /*
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley * Make 'target' refer to the same rdataset as 'source'.
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley */
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley REQUIRE(DNS_RDATASET_VALID(source));
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley REQUIRE(source->methods != NULL);
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley REQUIRE(DNS_RDATASET_VALID(target));
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley REQUIRE(target->methods == NULL);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley (source->methods->clone)(source, target);
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley}
1c724c986de1449e3b2f1eeae4c724dc0d97603cBob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleydns_rdataset_first(dns_rdataset_t *rdataset) {
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley /*
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley * Move the rdata cursor to the first rdata in the rdataset (if any).
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley */
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
078d49b63324f01d98301ee21671abee0c41fcdeBob Halley REQUIRE(DNS_RDATASET_VALID(rdataset));
0180ccf72c79b98eb8ee5abbb7331aec6951dd9fBob Halley REQUIRE(rdataset->methods != NULL);
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley return ((rdataset->methods->first)(rdataset));
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley}
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleydns_rdataset_next(dns_rdataset_t *rdataset) {
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley /*
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley * Move the rdata cursor to the next rdata in the rdataset (if any).
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley */
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
078d49b63324f01d98301ee21671abee0c41fcdeBob Halley REQUIRE(DNS_RDATASET_VALID(rdataset));
0180ccf72c79b98eb8ee5abbb7331aec6951dd9fBob Halley REQUIRE(rdataset->methods != NULL);
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley return ((rdataset->methods->next)(rdataset));
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley}
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleyvoid
5619558151f1aa4249b3ead979e76876e29278b6Bob Halleydns_rdataset_current(dns_rdataset_t *rdataset, dns_rdata_t *rdata) {
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley /*
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley * Make 'rdata' refer to the current rdata.
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley */
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
078d49b63324f01d98301ee21671abee0c41fcdeBob Halley REQUIRE(DNS_RDATASET_VALID(rdataset));
0180ccf72c79b98eb8ee5abbb7331aec6951dd9fBob Halley REQUIRE(rdataset->methods != NULL);
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley (rdataset->methods->current)(rdataset, rdata);
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley}
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley#define MAX_SHUFFLE 32
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley#define WANT_FIXED(r) (((r)->attributes & DNS_RDATASETATTR_FIXEDORDER) != 0)
2dd99c098ca162f985b7ef3c8142a964ad8281aeMark Andrews#define WANT_RANDOM(r) (((r)->attributes & DNS_RDATASETATTR_RANDOMIZE) != 0)
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafssonstruct towire_sort {
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson int key;
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson dns_rdata_t *rdata;
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson};
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafssonstatic int
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafssontowire_compare(const void *av, const void *bv) {
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson const struct towire_sort *a = (const struct towire_sort *) av;
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson const struct towire_sort *b = (const struct towire_sort *) bv;
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson return (a->key - b->key);
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson}
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrewsstatic isc_result_t
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrewstowiresorted(dns_rdataset_t *rdataset, const dns_name_t *owner_name,
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews dns_compress_t *cctx, isc_buffer_t *target,
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews dns_rdatasetorderfunc_t order, const void *order_arg,
84185d19c7a9ef1ac23cc6236c8773697d4efeb1Brian Wellington isc_boolean_t partial, unsigned int options,
84185d19c7a9ef1ac23cc6236c8773697d4efeb1Brian Wellington unsigned int *countp, void **state)
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley{
88a6fef4944a00d8350ffd8b64ef58c694b8335eMark Andrews dns_rdata_t rdata = DNS_RDATA_INIT;
76883e8cee593f45c65b0936e5d6e8f778d6e3efMichael Graff isc_region_t r;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_result_t result;
0874abad14e3e9ecfc3dc1a1a2b9969f2f027724Mark Andrews unsigned int i, count = 0, added, choice;
8af4b7042d84e0699f7c1de306526098030b74a9Mark Andrews isc_buffer_t savedbuffer, rdlen, rrbuffer;
69be7837c920fac5c71a73e8fad586f9a2711e96Michael Graff unsigned int headlen;
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley isc_boolean_t question = ISC_FALSE;
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley isc_boolean_t shuffle = ISC_FALSE;
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews dns_rdata_t *in = NULL, in_fixed[MAX_SHUFFLE];
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews struct towire_sort *out = NULL, out_fixed[MAX_SHUFFLE];
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews dns_fixedname_t fixed;
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews dns_name_t *name;
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews UNUSED(state);
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley /*
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley * Convert 'rdataset' to wire format, compressing names as specified
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley * in cctx, and storing the result in 'target'.
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley */
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley
54f959d12b5a1f9315fbf6a776c6d349316e9686Bob Halley REQUIRE(DNS_RDATASET_VALID(rdataset));
c2c386119e2cfe0831c3804d3691324ddcf5561cMark Andrews REQUIRE(rdataset->methods != NULL);
ccbfddc70ef38263daca312d29bb8c5077e24785Bob Halley REQUIRE(countp != NULL);
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson REQUIRE((order == NULL) == (order_arg == NULL));
c569a0e4d518bf30be1b2ba9cc3592fe470e9822Mark Andrews REQUIRE(cctx != NULL && cctx->mctx != NULL);
54f959d12b5a1f9315fbf6a776c6d349316e9686Bob Halley
89d8adb6663b13435ff9ae1eb53e45da7fa79275Bob Halley if ((rdataset->attributes & DNS_RDATASETATTR_QUESTION) != 0) {
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley question = ISC_TRUE;
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley count = 1;
89d8adb6663b13435ff9ae1eb53e45da7fa79275Bob Halley result = dns_rdataset_first(rdataset);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff INSIST(result == ISC_R_NOMORE);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt } else if ((rdataset->attributes & DNS_RDATASETATTR_NEGATIVE) != 0) {
8dfa9caeec8e68db0c937e347a3d6629e7627d54Bob Halley /*
8dfa9caeec8e68db0c937e347a3d6629e7627d54Bob Halley * This is a negative caching rdataset.
8dfa9caeec8e68db0c937e347a3d6629e7627d54Bob Halley */
b2ca6fd3a8293440b4d263723525396059cf2400Brian Wellington unsigned int ncache_opts = 0;
b2ca6fd3a8293440b4d263723525396059cf2400Brian Wellington if ((options & DNS_RDATASETTOWIRE_OMITDNSSEC) != 0)
b2ca6fd3a8293440b4d263723525396059cf2400Brian Wellington ncache_opts |= DNS_NCACHETOWIRE_OMITDNSSEC;
b2ca6fd3a8293440b4d263723525396059cf2400Brian Wellington return (dns_ncache_towire(rdataset, cctx, target, ncache_opts,
84185d19c7a9ef1ac23cc6236c8773697d4efeb1Brian Wellington countp));
89d8adb6663b13435ff9ae1eb53e45da7fa79275Bob Halley } else {
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley count = (rdataset->methods->count)(rdataset);
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley result = dns_rdataset_first(rdataset);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result == ISC_R_NOMORE)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS)
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley return (result);
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley }
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson /*
bdfaef63f576f810fab27f64395faccf2fcd9434Francis Dupont * Do we want to shuffle this answer?
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson */
c569a0e4d518bf30be1b2ba9cc3592fe470e9822Mark Andrews if (!question && count > 1 &&
2dd99c098ca162f985b7ef3c8142a964ad8281aeMark Andrews (!WANT_FIXED(rdataset) || order != NULL) &&
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews rdataset->type != dns_rdatatype_rrsig)
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson shuffle = ISC_TRUE;
c569a0e4d518bf30be1b2ba9cc3592fe470e9822Mark Andrews
c569a0e4d518bf30be1b2ba9cc3592fe470e9822Mark Andrews if (shuffle && count > MAX_SHUFFLE) {
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews in = isc_mem_get(cctx->mctx, count * sizeof(*in));
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews out = isc_mem_get(cctx->mctx, count * sizeof(*out));
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews if (in == NULL || out == NULL)
c569a0e4d518bf30be1b2ba9cc3592fe470e9822Mark Andrews shuffle = ISC_FALSE;
c569a0e4d518bf30be1b2ba9cc3592fe470e9822Mark Andrews } else {
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews in = in_fixed;
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews out = out_fixed;
c569a0e4d518bf30be1b2ba9cc3592fe470e9822Mark Andrews }
c569a0e4d518bf30be1b2ba9cc3592fe470e9822Mark Andrews
c569a0e4d518bf30be1b2ba9cc3592fe470e9822Mark Andrews if (shuffle) {
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson /*
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson * First we get handles to all of the rdata.
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson */
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson i = 0;
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson do {
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson INSIST(i < count);
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews dns_rdata_init(&in[i]);
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews dns_rdataset_current(rdataset, &in[i]);
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson i++;
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson result = dns_rdataset_next(rdataset);
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson } while (result == ISC_R_SUCCESS);
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson if (result != ISC_R_NOMORE)
c569a0e4d518bf30be1b2ba9cc3592fe470e9822Mark Andrews goto cleanup;
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson INSIST(i == count);
2dd99c098ca162f985b7ef3c8142a964ad8281aeMark Andrews
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley /*
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson * Now we shuffle.
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley */
2dd99c098ca162f985b7ef3c8142a964ad8281aeMark Andrews if (WANT_FIXED(rdataset)) {
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley /*
2dd99c098ca162f985b7ef3c8142a964ad8281aeMark Andrews * 'Fixed' order.
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley */
2dd99c098ca162f985b7ef3c8142a964ad8281aeMark Andrews INSIST(order != NULL);
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson for (i = 0; i < count; i++) {
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews out[i].key = (*order)(&in[i], order_arg);
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews out[i].rdata = &in[i];
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson }
2dd99c098ca162f985b7ef3c8142a964ad8281aeMark Andrews } else if (WANT_RANDOM(rdataset)) {
2dd99c098ca162f985b7ef3c8142a964ad8281aeMark Andrews /*
2dd99c098ca162f985b7ef3c8142a964ad8281aeMark Andrews * 'Random' order.
2dd99c098ca162f985b7ef3c8142a964ad8281aeMark Andrews */
2dd99c098ca162f985b7ef3c8142a964ad8281aeMark Andrews for (i = 0; i < count; i++) {
def8e47c688e2480a4539d69c3d1a0a28a7c0550Mark Andrews isc_uint32_t val;
def8e47c688e2480a4539d69c3d1a0a28a7c0550Mark Andrews
def8e47c688e2480a4539d69c3d1a0a28a7c0550Mark Andrews isc_random_get(&val);
def8e47c688e2480a4539d69c3d1a0a28a7c0550Mark Andrews choice = i + (val % (count - i));
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews rdata = in[i];
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews in[i] = in[choice];
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews in[choice] = rdata;
2dd99c098ca162f985b7ef3c8142a964ad8281aeMark Andrews if (order != NULL)
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews out[i].key = (*order)(&in[i],
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews order_arg);
2dd99c098ca162f985b7ef3c8142a964ad8281aeMark Andrews else
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews out[i].key = 0; /* Unused */
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews out[i].rdata = &in[i];
2dd99c098ca162f985b7ef3c8142a964ad8281aeMark Andrews }
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson } else {
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley /*
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson * "Cyclic" order.
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley */
def8e47c688e2480a4539d69c3d1a0a28a7c0550Mark Andrews isc_uint32_t val;
def8e47c688e2480a4539d69c3d1a0a28a7c0550Mark Andrews unsigned int j;
def8e47c688e2480a4539d69c3d1a0a28a7c0550Mark Andrews
61fb42c4ef45d88e115bd769c30c4f36b461870bMark Andrews val = rdataset->count;
61fb42c4ef45d88e115bd769c30c4f36b461870bMark Andrews if (val == ISC_UINT32_MAX)
61fb42c4ef45d88e115bd769c30c4f36b461870bMark Andrews isc_random_get(&val);
def8e47c688e2480a4539d69c3d1a0a28a7c0550Mark Andrews j = val % count;
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson for (i = 0; i < count; i++) {
2dd99c098ca162f985b7ef3c8142a964ad8281aeMark Andrews if (order != NULL)
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews out[i].key = (*order)(&in[j],
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews order_arg);
2dd99c098ca162f985b7ef3c8142a964ad8281aeMark Andrews else
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews out[i].key = 0; /* Unused */
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews out[i].rdata = &in[j];
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson j++;
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson if (j == count)
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson j = 0; /* Wrap around. */
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley }
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley }
2dd99c098ca162f985b7ef3c8142a964ad8281aeMark Andrews
2dd99c098ca162f985b7ef3c8142a964ad8281aeMark Andrews /*
2dd99c098ca162f985b7ef3c8142a964ad8281aeMark Andrews * Sorted order.
2dd99c098ca162f985b7ef3c8142a964ad8281aeMark Andrews */
2dd99c098ca162f985b7ef3c8142a964ad8281aeMark Andrews if (order != NULL)
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews qsort(out, count, sizeof(out[0]), towire_compare);
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley }
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley
8dfa9caeec8e68db0c937e347a3d6629e7627d54Bob Halley savedbuffer = *target;
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson i = 0;
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews added = 0;
8dfa9caeec8e68db0c937e347a3d6629e7627d54Bob Halley
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews dns_fixedname_init(&fixed);
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews name = dns_fixedname_name(&fixed);
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews dns_name_copy(owner_name, name, NULL);
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews dns_rdataset_getownercase(rdataset, name);
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews
836601ccc5e38b8104831f629f11fdb8e9d7238bMukund Sivaraman name->attributes |= owner_name->attributes &
836601ccc5e38b8104831f629f11fdb8e9d7238bMukund Sivaraman DNS_NAMEATTR_NOCOMPRESS;
b301c4293c082fcce4ec26218e6fad346976eb9eMark Andrews
76883e8cee593f45c65b0936e5d6e8f778d6e3efMichael Graff do {
76883e8cee593f45c65b0936e5d6e8f778d6e3efMichael Graff /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Copy out the name, type, class, ttl.
76883e8cee593f45c65b0936e5d6e8f778d6e3efMichael Graff */
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater
8af4b7042d84e0699f7c1de306526098030b74a9Mark Andrews rrbuffer = *target;
94a08e09db3dc844b6ee4841c368a2d7074a9c3fAndreas Gustafsson dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews result = dns_name_towire(name, cctx, target);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS)
8dfa9caeec8e68db0c937e347a3d6629e7627d54Bob Halley goto rollback;
69be7837c920fac5c71a73e8fad586f9a2711e96Michael Graff headlen = sizeof(dns_rdataclass_t) + sizeof(dns_rdatatype_t);
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley if (!question)
69be7837c920fac5c71a73e8fad586f9a2711e96Michael Graff headlen += sizeof(dns_ttl_t)
69be7837c920fac5c71a73e8fad586f9a2711e96Michael Graff + 2; /* XXX 2 for rdata len */
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_availableregion(target, &r);
69be7837c920fac5c71a73e8fad586f9a2711e96Michael Graff if (r.length < headlen) {
8dfa9caeec8e68db0c937e347a3d6629e7627d54Bob Halley result = ISC_R_NOSPACE;
8dfa9caeec8e68db0c937e347a3d6629e7627d54Bob Halley goto rollback;
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews }
22f735acbce7ffe95af20bb58bb8929b6f1d674fMichael Graff isc_buffer_putuint16(target, rdataset->type);
904a5734375869ffb504ed8cde6b68cafadb6d64Bob Halley isc_buffer_putuint16(target, rdataset->rdclass);
bf345589ce0b0b64533d4566e4992a0e63aac6f5Bob Halley if (!question) {
69be7837c920fac5c71a73e8fad586f9a2711e96Michael Graff isc_buffer_putuint32(target, rdataset->ttl);
69be7837c920fac5c71a73e8fad586f9a2711e96Michael Graff
69be7837c920fac5c71a73e8fad586f9a2711e96Michael Graff /*
69be7837c920fac5c71a73e8fad586f9a2711e96Michael Graff * Save space for rdlen.
69be7837c920fac5c71a73e8fad586f9a2711e96Michael Graff */
69be7837c920fac5c71a73e8fad586f9a2711e96Michael Graff rdlen = *target;
69be7837c920fac5c71a73e8fad586f9a2711e96Michael Graff isc_buffer_add(target, 2);
69be7837c920fac5c71a73e8fad586f9a2711e96Michael Graff
69be7837c920fac5c71a73e8fad586f9a2711e96Michael Graff /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Copy out the rdata
69be7837c920fac5c71a73e8fad586f9a2711e96Michael Graff */
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley if (shuffle)
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews rdata = *(out[i].rdata);
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews else {
43b8fb75704f290a48fc96461140b42b2488348dMark Andrews dns_rdata_reset(&rdata);
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley dns_rdataset_current(rdataset, &rdata);
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews }
69be7837c920fac5c71a73e8fad586f9a2711e96Michael Graff result = dns_rdata_towire(&rdata, cctx, target);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS)
8dfa9caeec8e68db0c937e347a3d6629e7627d54Bob Halley goto rollback;
13eaef2df27683658868c3828c18880d7419a16aDavid Lawrence INSIST((target->used >= rdlen.used + 2) &&
13eaef2df27683658868c3828c18880d7419a16aDavid Lawrence (target->used - rdlen.used - 2 < 65536));
69be7837c920fac5c71a73e8fad586f9a2711e96Michael Graff isc_buffer_putuint16(&rdlen,
13eaef2df27683658868c3828c18880d7419a16aDavid Lawrence (isc_uint16_t)(target->used -
13eaef2df27683658868c3828c18880d7419a16aDavid Lawrence rdlen.used - 2));
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews added++;
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews }
76883e8cee593f45c65b0936e5d6e8f778d6e3efMichael Graff
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley if (shuffle) {
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley i++;
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley if (i == count)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff result = ISC_R_NOMORE;
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley else
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley result = ISC_R_SUCCESS;
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson } else {
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley result = dns_rdataset_next(rdataset);
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson }
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff } while (result == ISC_R_SUCCESS);
76883e8cee593f45c65b0936e5d6e8f778d6e3efMichael Graff
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_NOMORE)
c3b708aaf1bb0a118e0e11befa1b732acfb1d079Bob Halley goto rollback;
76883e8cee593f45c65b0936e5d6e8f778d6e3efMichael Graff
ccbfddc70ef38263daca312d29bb8c5077e24785Bob Halley *countp += count;
ccbfddc70ef38263daca312d29bb8c5077e24785Bob Halley
c569a0e4d518bf30be1b2ba9cc3592fe470e9822Mark Andrews result = ISC_R_SUCCESS;
c569a0e4d518bf30be1b2ba9cc3592fe470e9822Mark Andrews goto cleanup;
8dfa9caeec8e68db0c937e347a3d6629e7627d54Bob Halley
8dfa9caeec8e68db0c937e347a3d6629e7627d54Bob Halley rollback:
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews if (partial && result == ISC_R_NOSPACE) {
8af4b7042d84e0699f7c1de306526098030b74a9Mark Andrews INSIST(rrbuffer.used < 65536);
8af4b7042d84e0699f7c1de306526098030b74a9Mark Andrews dns_compress_rollback(cctx, (isc_uint16_t)rrbuffer.used);
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews *countp += added;
92296c744ef9ef36de499eb10b3e27800d8b24a5Mark Andrews *target = rrbuffer;
c569a0e4d518bf30be1b2ba9cc3592fe470e9822Mark Andrews goto cleanup;
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews }
13eaef2df27683658868c3828c18880d7419a16aDavid Lawrence INSIST(savedbuffer.used < 65536);
13eaef2df27683658868c3828c18880d7419a16aDavid Lawrence dns_compress_rollback(cctx, (isc_uint16_t)savedbuffer.used);
8dfa9caeec8e68db0c937e347a3d6629e7627d54Bob Halley *countp = 0;
8dfa9caeec8e68db0c937e347a3d6629e7627d54Bob Halley *target = savedbuffer;
8dfa9caeec8e68db0c937e347a3d6629e7627d54Bob Halley
c569a0e4d518bf30be1b2ba9cc3592fe470e9822Mark Andrews cleanup:
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews if (out != NULL && out != out_fixed)
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews isc_mem_put(cctx->mctx, out, count * sizeof(*out));
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews if (in != NULL && in != in_fixed)
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews isc_mem_put(cctx->mctx, in, count * sizeof(*in));
8dfa9caeec8e68db0c937e347a3d6629e7627d54Bob Halley return (result);
5619558151f1aa4249b3ead979e76876e29278b6Bob Halley}
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrewsisc_result_t
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrewsdns_rdataset_towiresorted(dns_rdataset_t *rdataset,
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews const dns_name_t *owner_name,
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews dns_compress_t *cctx,
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews isc_buffer_t *target,
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews dns_rdatasetorderfunc_t order,
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews const void *order_arg,
84185d19c7a9ef1ac23cc6236c8773697d4efeb1Brian Wellington unsigned int options,
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews unsigned int *countp)
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews{
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews return (towiresorted(rdataset, owner_name, cctx, target,
84185d19c7a9ef1ac23cc6236c8773697d4efeb1Brian Wellington order, order_arg, ISC_FALSE, options,
84185d19c7a9ef1ac23cc6236c8773697d4efeb1Brian Wellington countp, NULL));
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews}
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrewsisc_result_t
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrewsdns_rdataset_towirepartial(dns_rdataset_t *rdataset,
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews const dns_name_t *owner_name,
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews dns_compress_t *cctx,
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews isc_buffer_t *target,
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews dns_rdatasetorderfunc_t order,
45e1bd63587102c3bb361eaca42ee7b714fb3542Mark Andrews const void *order_arg,
84185d19c7a9ef1ac23cc6236c8773697d4efeb1Brian Wellington unsigned int options,
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews unsigned int *countp,
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews void **state)
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews{
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews REQUIRE(state == NULL); /* XXX remove when implemented */
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews return (towiresorted(rdataset, owner_name, cctx, target,
84185d19c7a9ef1ac23cc6236c8773697d4efeb1Brian Wellington order, order_arg, ISC_TRUE, options,
84185d19c7a9ef1ac23cc6236c8773697d4efeb1Brian Wellington countp, state));
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews}
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafssonisc_result_t
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafssondns_rdataset_towire(dns_rdataset_t *rdataset,
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson dns_name_t *owner_name,
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson dns_compress_t *cctx,
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson isc_buffer_t *target,
84185d19c7a9ef1ac23cc6236c8773697d4efeb1Brian Wellington unsigned int options,
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson unsigned int *countp)
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson{
03f91269f5453bcbd924910ef85a8f8496cf2661Mark Andrews return (towiresorted(rdataset, owner_name, cctx, target,
84185d19c7a9ef1ac23cc6236c8773697d4efeb1Brian Wellington NULL, NULL, ISC_FALSE, options, countp, NULL));
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson}
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
d981ca645597116d227a48bf37cc5edc061c854dBob Halleydns_rdataset_additionaldata(dns_rdataset_t *rdataset,
d981ca645597116d227a48bf37cc5edc061c854dBob Halley dns_additionaldatafunc_t add, void *arg)
d981ca645597116d227a48bf37cc5edc061c854dBob Halley{
88a6fef4944a00d8350ffd8b64ef58c694b8335eMark Andrews dns_rdata_t rdata = DNS_RDATA_INIT;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_result_t result;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
d981ca645597116d227a48bf37cc5edc061c854dBob Halley /*
d981ca645597116d227a48bf37cc5edc061c854dBob Halley * For each rdata in rdataset, call 'add' for each name and type in the
d981ca645597116d227a48bf37cc5edc061c854dBob Halley * rdata which is subject to additional section processing.
d981ca645597116d227a48bf37cc5edc061c854dBob Halley */
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
d981ca645597116d227a48bf37cc5edc061c854dBob Halley REQUIRE(DNS_RDATASET_VALID(rdataset));
d981ca645597116d227a48bf37cc5edc061c854dBob Halley REQUIRE((rdataset->attributes & DNS_RDATASETATTR_QUESTION) == 0);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
d981ca645597116d227a48bf37cc5edc061c854dBob Halley result = dns_rdataset_first(rdataset);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS)
d981ca645597116d227a48bf37cc5edc061c854dBob Halley return (result);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
d981ca645597116d227a48bf37cc5edc061c854dBob Halley do {
d981ca645597116d227a48bf37cc5edc061c854dBob Halley dns_rdataset_current(rdataset, &rdata);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley result = dns_rdata_additionaldata(&rdata, add, arg);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result == ISC_R_SUCCESS)
d981ca645597116d227a48bf37cc5edc061c854dBob Halley result = dns_rdataset_next(rdataset);
43b8fb75704f290a48fc96461140b42b2488348dMark Andrews dns_rdata_reset(&rdata);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff } while (result == ISC_R_SUCCESS);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_NOMORE)
d981ca645597116d227a48bf37cc5edc061c854dBob Halley return (result);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley}
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrewsisc_result_t
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrewsdns_rdataset_addnoqname(dns_rdataset_t *rdataset, dns_name_t *name) {
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews REQUIRE(DNS_RDATASET_VALID(rdataset));
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews REQUIRE(rdataset->methods != NULL);
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews if (rdataset->methods->addnoqname == NULL)
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews return (ISC_R_NOTIMPLEMENTED);
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews return((rdataset->methods->addnoqname)(rdataset, name));
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews}
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrewsisc_result_t
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrewsdns_rdataset_getnoqname(dns_rdataset_t *rdataset, dns_name_t *name,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_rdataset_t *neg, dns_rdataset_t *negsig)
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews{
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews REQUIRE(DNS_RDATASET_VALID(rdataset));
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews REQUIRE(rdataset->methods != NULL);
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews if (rdataset->methods->getnoqname == NULL)
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews return (ISC_R_NOTIMPLEMENTED);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews return((rdataset->methods->getnoqname)(rdataset, name, neg, negsig));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews}
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsisc_result_t
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsdns_rdataset_addclosest(dns_rdataset_t *rdataset, dns_name_t *name) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews REQUIRE(DNS_RDATASET_VALID(rdataset));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews REQUIRE(rdataset->methods != NULL);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (rdataset->methods->addclosest == NULL)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews return (ISC_R_NOTIMPLEMENTED);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews return((rdataset->methods->addclosest)(rdataset, name));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews}
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsisc_result_t
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsdns_rdataset_getclosest(dns_rdataset_t *rdataset, dns_name_t *name,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_rdataset_t *neg, dns_rdataset_t *negsig)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews{
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews REQUIRE(DNS_RDATASET_VALID(rdataset));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews REQUIRE(rdataset->methods != NULL);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (rdataset->methods->getclosest == NULL)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews return (ISC_R_NOTIMPLEMENTED);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews return((rdataset->methods->getclosest)(rdataset, name, neg, negsig));
35541328a8c18ba1f984300dfe30ec8713c90031Mark Andrews}
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉/*
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 * Additional cache stuff
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 */
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉isc_result_t
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉dns_rdataset_getadditional(dns_rdataset_t *rdataset,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_rdatasetadditional_t type,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_rdatatype_t qtype,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_acache_t *acache,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_zone_t **zonep,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_db_t **dbp,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_dbversion_t **versionp,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_dbnode_t **nodep,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_name_t *fname,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_message_t *msg,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 isc_stdtime_t now)
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉{
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 REQUIRE(DNS_RDATASET_VALID(rdataset));
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 REQUIRE(rdataset->methods != NULL);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 REQUIRE(zonep == NULL || *zonep == NULL);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 REQUIRE(dbp != NULL && *dbp == NULL);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 REQUIRE(versionp != NULL && *versionp == NULL);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 REQUIRE(nodep != NULL && *nodep == NULL);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 REQUIRE(fname != NULL);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 REQUIRE(msg != NULL);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 if (acache != NULL && rdataset->methods->getadditional != NULL) {
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 return ((rdataset->methods->getadditional)(rdataset, type,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 qtype, acache,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 zonep, dbp,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 versionp, nodep,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 fname, msg, now));
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 }
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 return (ISC_R_FAILURE);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉}
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉isc_result_t
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉dns_rdataset_setadditional(dns_rdataset_t *rdataset,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_rdatasetadditional_t type,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_rdatatype_t qtype,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_acache_t *acache,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_zone_t *zone,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_db_t *db,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_dbversion_t *version,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_dbnode_t *node,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_name_t *fname)
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉{
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 REQUIRE(DNS_RDATASET_VALID(rdataset));
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 REQUIRE(rdataset->methods != NULL);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 if (acache != NULL && rdataset->methods->setadditional != NULL) {
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 return ((rdataset->methods->setadditional)(rdataset, type,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 qtype, acache, zone,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 db, version,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 node, fname));
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 }
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 return (ISC_R_FAILURE);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉}
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉isc_result_t
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉dns_rdataset_putadditional(dns_acache_t *acache,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_rdataset_t *rdataset,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_rdatasetadditional_t type,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 dns_rdatatype_t qtype)
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉{
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 REQUIRE(DNS_RDATASET_VALID(rdataset));
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 REQUIRE(rdataset->methods != NULL);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 if (acache != NULL && rdataset->methods->putadditional != NULL) {
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 return ((rdataset->methods->putadditional)(acache, rdataset,
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 type, qtype));
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 }
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 return (ISC_R_FAILURE);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉}
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉
0cae66577c69c89086cd065bb297690072b471b4Mark Andrewsvoid
0cae66577c69c89086cd065bb297690072b471b4Mark Andrewsdns_rdataset_settrust(dns_rdataset_t *rdataset, dns_trust_t trust) {
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews REQUIRE(DNS_RDATASET_VALID(rdataset));
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews REQUIRE(rdataset->methods != NULL);
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews if (rdataset->methods->settrust != NULL)
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews (rdataset->methods->settrust)(rdataset, trust);
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews else
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews rdataset->trust = trust;
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews}
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews
0cae66577c69c89086cd065bb297690072b471b4Mark Andrewsvoid
0cae66577c69c89086cd065bb297690072b471b4Mark Andrewsdns_rdataset_expire(dns_rdataset_t *rdataset) {
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews REQUIRE(DNS_RDATASET_VALID(rdataset));
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews REQUIRE(rdataset->methods != NULL);
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews if (rdataset->methods->expire != NULL)
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews (rdataset->methods->expire)(rdataset);
0cae66577c69c89086cd065bb297690072b471b4Mark Andrews}
e7857b5ee05414961bb11f9e57f654163fae6acbckb
092d3b76db6b93b8029bd7d083e74fc80fb41858Mark Andrewsvoid
092d3b76db6b93b8029bd7d083e74fc80fb41858Mark Andrewsdns_rdataset_clearprefetch(dns_rdataset_t *rdataset) {
092d3b76db6b93b8029bd7d083e74fc80fb41858Mark Andrews REQUIRE(DNS_RDATASET_VALID(rdataset));
092d3b76db6b93b8029bd7d083e74fc80fb41858Mark Andrews REQUIRE(rdataset->methods != NULL);
092d3b76db6b93b8029bd7d083e74fc80fb41858Mark Andrews
092d3b76db6b93b8029bd7d083e74fc80fb41858Mark Andrews if (rdataset->methods->clearprefetch != NULL)
092d3b76db6b93b8029bd7d083e74fc80fb41858Mark Andrews (rdataset->methods->clearprefetch)(rdataset);
092d3b76db6b93b8029bd7d083e74fc80fb41858Mark Andrews}
092d3b76db6b93b8029bd7d083e74fc80fb41858Mark Andrews
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrewsvoid
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrewsdns_rdataset_setownercase(dns_rdataset_t *rdataset, const dns_name_t *name) {
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews REQUIRE(DNS_RDATASET_VALID(rdataset));
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews REQUIRE(rdataset->methods != NULL);
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews if (rdataset->methods->setownercase != NULL)
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews (rdataset->methods->setownercase)(rdataset, name);
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews}
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrewsvoid
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrewsdns_rdataset_getownercase(const dns_rdataset_t *rdataset, dns_name_t *name) {
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews REQUIRE(DNS_RDATASET_VALID(rdataset));
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews REQUIRE(rdataset->methods != NULL);
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews if (rdataset->methods->getownercase != NULL)
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews (rdataset->methods->getownercase)(rdataset, name);
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews}
a8da00ef95ba37b9d071c2b8db1a0c967e060106Mark Andrews
e7857b5ee05414961bb11f9e57f654163fae6acbckbvoid
e7857b5ee05414961bb11f9e57f654163fae6acbckbdns_rdataset_trimttl(dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset,
e7857b5ee05414961bb11f9e57f654163fae6acbckb dns_rdata_rrsig_t *rrsig, isc_stdtime_t now,
e7857b5ee05414961bb11f9e57f654163fae6acbckb isc_boolean_t acceptexpired)
e7857b5ee05414961bb11f9e57f654163fae6acbckb{
e7857b5ee05414961bb11f9e57f654163fae6acbckb isc_uint32_t ttl = 0;
e7857b5ee05414961bb11f9e57f654163fae6acbckb
e7857b5ee05414961bb11f9e57f654163fae6acbckb REQUIRE(DNS_RDATASET_VALID(rdataset));
e7857b5ee05414961bb11f9e57f654163fae6acbckb REQUIRE(DNS_RDATASET_VALID(sigrdataset));
e7857b5ee05414961bb11f9e57f654163fae6acbckb REQUIRE(rrsig != NULL);
e7857b5ee05414961bb11f9e57f654163fae6acbckb
e7857b5ee05414961bb11f9e57f654163fae6acbckb /*
e7857b5ee05414961bb11f9e57f654163fae6acbckb * If we accept expired RRsets keep them for no more than 120 seconds.
e7857b5ee05414961bb11f9e57f654163fae6acbckb */
953692fa1e307b7325e383302d82b711d164a9d5Tinderbox User if (acceptexpired &&
953692fa1e307b7325e383302d82b711d164a9d5Tinderbox User (isc_serial_le(rrsig->timeexpire, ((now + 120) & 0xffffffff)) ||
953692fa1e307b7325e383302d82b711d164a9d5Tinderbox User isc_serial_le(rrsig->timeexpire, now)))
953692fa1e307b7325e383302d82b711d164a9d5Tinderbox User ttl = 120;
953692fa1e307b7325e383302d82b711d164a9d5Tinderbox User else if (isc_serial_ge(rrsig->timeexpire, now))
953692fa1e307b7325e383302d82b711d164a9d5Tinderbox User ttl = rrsig->timeexpire - now;
953692fa1e307b7325e383302d82b711d164a9d5Tinderbox User
953692fa1e307b7325e383302d82b711d164a9d5Tinderbox User ttl = ISC_MIN(ISC_MIN(rdataset->ttl, sigrdataset->ttl),
953692fa1e307b7325e383302d82b711d164a9d5Tinderbox User ISC_MIN(rrsig->originalttl, ttl));
953692fa1e307b7325e383302d82b711d164a9d5Tinderbox User rdataset->ttl = ttl;
953692fa1e307b7325e383302d82b711d164a9d5Tinderbox User sigrdataset->ttl = ttl;
e7857b5ee05414961bb11f9e57f654163fae6acbckb}