From 4e142a5bccd2944174ad9ae58d86cf03e170054d Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Tue, 21 Sep 1999 20:41:20 +0000 Subject: [PATCH] start of ncache support --- lib/dns/Makefile.in | 20 ++-- lib/dns/include/dns/Makefile.in | 2 +- lib/dns/include/dns/ncache.h | 55 +++++++++ lib/dns/ncache.c | 201 ++++++++++++++++++++++++++++++++ 4 files changed, 267 insertions(+), 11 deletions(-) create mode 100644 lib/dns/include/dns/ncache.h create mode 100644 lib/dns/ncache.c diff --git a/lib/dns/Makefile.in b/lib/dns/Makefile.in index eb8edd91f7..dbea5641d1 100644 --- a/lib/dns/Makefile.in +++ b/lib/dns/Makefile.in @@ -117,20 +117,20 @@ DNSSAFEOBJS = sec/dnssafe/ahchdig.@O@ sec/dnssafe/ahchencr.@O@ \ OBJS = a6.@O@ callbacks.@O@ compress.@O@ db.@O@ dbiterator.@O@ \ dbtable.@O@ dispatch.@O@ dnssec.@O@ lib.@O@ master.@O@ \ - message.@O@ name.@O@ rbt.@O@ rbtdb.@O@ rbtdb64.@O@ rdata.@O@ \ - rdatalist.@O@ rdataset.@O@ rdatasetiter.@O@ rdataslab.@O@ \ - resolver.@O@ result.@O@ version.@O@ masterdump.@O@ time.@O@ \ - ttl.@O@ tcpmsg.@O@ tsig.@O@ view.@O@ journal.@O@ zone.@O@ \ - nxt.@O@ \ + message.@O@ name.@O@ ncache.@O@ rbt.@O@ rbtdb.@O@ \ + rbtdb64.@O@ rdata.@O@ rdatalist.@O@ rdataset.@O@ \ + rdatasetiter.@O@ rdataslab.@O@ resolver.@O@ result.@O@ \ + version.@O@ masterdump.@O@ time.@O@ ttl.@O@ tcpmsg.@O@ \ + tsig.@O@ view.@O@ journal.@O@ zone.@O@ nxt.@O@ \ ${DSTOBJS} ${OPENSSLOBJS} ${DNSSAFEOBJS} ${CONFOBJS} SRCS = a6.c callbacks.c compress.c db.c dbiterator.c \ dbtable.c dispatch.c dnssec.c lib.c master.c \ - message.c name.c rbt.c rbtdb.c rbtdb64.c rdata.c \ - rdatalist.c rdataset.c rdatasetiter.c rdataslab.c \ - resolver.c result.c version.c masterdump.c time.c \ - ttl.c tcpmsg.c tsig.c view.c journal.c zone.c \ - nxt.c + message.c name.c ncache.c rbt.c rbtdb.c \ + rbtdb64.c rdata.c rdatalist.c rdataset.c \ + rdatasetiter.c rdataslab.c resolver.c result.c \ + version.c masterdump.c time.c ttl.c tcpmsg.c \ + tsig.c view.c journal.c zone.c nxt.c SUBDIRS = include sec config TARGETS = include/dns/enumtype.h include/dns/enumclass.h \ diff --git a/lib/dns/include/dns/Makefile.in b/lib/dns/include/dns/Makefile.in index ca7c5957a1..282ecdcf12 100644 --- a/lib/dns/include/dns/Makefile.in +++ b/lib/dns/include/dns/Makefile.in @@ -21,7 +21,7 @@ top_srcdir = @top_srcdir@ HEADERS = callbacks.h cert.h compress.h db.h dbiterator.h dbtable.h \ events.h dispatch.h events.h fixedname.h keyvalues.h \ - lib.h master.h masterdump.h message.h name.h rbt.h \ + lib.h master.h masterdump.h message.h name.h ncache.h rbt.h \ rcode.h rdata.h rdataclass.h rdatalist.h rdataset.h \ rdatasetiter.h rdataslab.h rdatatype.h result.h \ secalg.h tcpmsg.h time.h ttl.h types.h view.h \ diff --git a/lib/dns/include/dns/ncache.h b/lib/dns/include/dns/ncache.h new file mode 100644 index 0000000000..5aa9f23f41 --- /dev/null +++ b/lib/dns/include/dns/ncache.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 1999 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#ifndef DNS_NCACHE_H +#define DNS_NCACHE_H 1 + +/***** + ***** Module Info + *****/ + +/* + * DNS Ncache + * + * XXX XXX + * + * MP: + * The caller must ensure any required synchronization. + * + * Reliability: + * No anticipated impact. + * + * Resources: + * + * + * Security: + * No anticipated impact. + * + * Standards: + * RFC 2308 + */ + +#include + +#include +#include + +ISC_LANG_BEGINDECLS + +ISC_LANG_ENDDECLS + +#endif /* DNS_NCACHE_H */ diff --git a/lib/dns/ncache.c b/lib/dns/ncache.c new file mode 100644 index 0000000000..f5e769bd82 --- /dev/null +++ b/lib/dns/ncache.c @@ -0,0 +1,201 @@ +/* + * Copyright (C) 1999 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * The format of an ncache rdata is a sequence of one or more records of + * the following format: + * + * owner name + * type + * rdata count + * rdata length These two occur 'rdata count' + * rdata times. + * + */ + +static inline isc_result_t +copy_rdataset(dns_rdataset_t *rdataset, isc_buffer_t *buffer) { + isc_result_t result; + unsigned int count; + isc_region_t ar, r; + dns_rdata_t rdata; + + /* + * Copy the rdataset count to the buffer. + */ + isc_buffer_available(buffer, &ar); + if (ar.length < 2) + return (ISC_R_NOSPACE); + count = dns_rdataset_count(rdataset); + INSIST(count <= 65535); + isc_buffer_putuint16(buffer, (isc_uint16_t)count); + + result = dns_rdataset_first(rdataset); + while (result == ISC_R_SUCCESS) { + dns_rdataset_current(rdataset, &rdata); + dns_rdata_toregion(&rdata, &r); + INSIST(r.length <= 65535); + isc_buffer_available(buffer, &ar); + if (ar.length < 2) + return (ISC_R_NOSPACE); + /* + * Copy the rdata length to the buffer. + */ + isc_buffer_putuint16(buffer, (isc_uint16_t)r.length); + /* + * Copy the rdata to the buffer. + */ + result = isc_buffer_copyregion(buffer, &r); + if (result != ISC_R_SUCCESS) + return (result); + result = dns_rdataset_next(rdataset); + } + if (result != ISC_R_NOMORE) + return (result); + + return (ISC_R_SUCCESS); +} + +isc_result_t +dns_ncache_add(dns_message_t *message, dns_db_t *cache, dns_dbnode_t *node, + dns_rdatatype_t covers, isc_stdtime_t now, + dns_rdataset_t *addedrdataset) +{ + isc_result_t result; + isc_buffer_t buffer; + isc_region_t r; + dns_rdataset_t *rdataset; + dns_rdata_t rdata; + dns_rdataset_t ncrdataset; + dns_rdatalist_t ncrdatalist; + dns_rdatatype_t type; + dns_name_t *name; + dns_ttl_t ttl; + char *data[4096]; + + /* + * We assume that all data in the authority section has been + * validated by the caller. + */ + + /* + * First, build an ncache rdata in buffer. + */ + ttl = 0xffffffff; + isc_buffer_init(&buffer, data, sizeof data, ISC_BUFFERTYPE_BINARY); + result = dns_message_firstname(message, DNS_SECTION_AUTHORITY); + while (result == ISC_R_SUCCESS) { + name = NULL; + dns_message_currentname(message, DNS_SECTION_AUTHORITY, + &name); + for (rdataset = ISC_LIST_HEAD(name->list); + rdataset != NULL; + rdataset = ISC_LIST_NEXT(rdataset, link)) { + /* + * XXXRTH check for ignore bit here? + */ + type = rdataset->type; + if (type == dns_rdatatype_sig) + type = rdataset->covers; + if (type == dns_rdatatype_soa || + type == dns_rdatatype_nxt) { + if (ttl > rdataset->ttl) + ttl = rdataset->ttl; + /* + * Copy the owner name to the buffer. + */ + dns_name_toregion(name, &r); + result = isc_buffer_copyregion(&buffer, + &r); + if (result != ISC_R_SUCCESS) + return (result); + /* + * Copy the type to the buffer. + */ + isc_buffer_available(&buffer, &r); + if (r.length < 2) + return (ISC_R_NOSPACE); + isc_buffer_putuint16(&buffer, type); + /* + * Copy the rdataset into the buffer. + */ + result = copy_rdataset(rdataset, &buffer); + if (result != ISC_R_SUCCESS) + return (result); + } + } + result = dns_message_nextname(message, DNS_SECTION_AUTHORITY); + } + if (result != ISC_R_NOMORE) + return (result); + + /* + * Now, turn 'buffer' into an ncache rdataset and add it to + * the cache. + */ + + dns_rdata_init(&rdata); + isc_buffer_available(&buffer, &r); + rdata.data = r.base; + rdata.length = r.length; + rdata.rdclass = dns_db_class(cache); + rdata.type = 0; + + ncrdatalist.rdclass = rdata.rdclass; + ncrdatalist.type = 0; + ncrdatalist.covers = covers; + ncrdatalist.ttl = ttl; + ISC_LIST_INIT(ncrdatalist.rdata); + ISC_LINK_INIT(&ncrdatalist, link); + + ISC_LIST_APPEND(ncrdatalist.rdata, &rdata, link); + + dns_rdataset_init(&ncrdataset); + dns_rdatalist_tordataset(&ncrdatalist, &ncrdataset); + + result = dns_db_addrdataset(cache, node, NULL, now, &ncrdataset, + ISC_FALSE, addedrdataset); + + return (result); +} + +isc_result_t +dns_ncache_towire(dns_rdataset_t *rdataset, dns_compress_t *cctx, + isc_buffer_t *target, unsigned int *countp) +{ + REQUIRE(rdataset->type == 0); + + + + return (ISC_R_NOTIMPLEMENTED); +}