BIND 10 trac493, updated. e9cd09d4a41cfb46af3a89e57f7d3184c602dc06 [trac493] Add message utility functions and fix some coding style problems
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Mar 3 08:37:43 UTC 2011
The branch, trac493 has been updated
via e9cd09d4a41cfb46af3a89e57f7d3184c602dc06 (commit)
from 8c136625d1e2556c7c8280917a1f18370794ce76 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit e9cd09d4a41cfb46af3a89e57f7d3184c602dc06
Author: Ocean Wang <wanghaidong at cnnic.cn>
Date: Thu Mar 3 16:36:49 2011 +0800
[trac493] Add message utility functions and fix some coding style
problems
-----------------------------------------------------------------------
Summary of changes:
src/lib/cache/message_cache.cc | 12 +++++--
src/lib/cache/message_entry.cc | 7 ++--
src/lib/cache/message_utility.cc | 63 ++++++++++++++++++++++++++++++++++++++
src/lib/cache/message_utility.h | 51 ++++++++++++++++++++++++++++++
src/lib/cache/resolver_cache.cc | 3 +-
src/lib/cache/resolver_cache.h | 5 +++
6 files changed, 133 insertions(+), 8 deletions(-)
create mode 100644 src/lib/cache/message_utility.cc
create mode 100644 src/lib/cache/message_utility.h
-----------------------------------------------------------------------
diff --git a/src/lib/cache/message_cache.cc b/src/lib/cache/message_cache.cc
index bcca66d..80346ad 100644
--- a/src/lib/cache/message_cache.cc
+++ b/src/lib/cache/message_cache.cc
@@ -32,7 +32,8 @@ using namespace std;
using namespace MessageUtility;
MessageCache::MessageCache(boost::shared_ptr<RRsetCache> rrset_cache,
- uint32_t cache_size, uint16_t message_class, boost::shared_ptr<RRsetCache> negative_soa_cache):
+ uint32_t cache_size, uint16_t message_class,
+ boost::shared_ptr<RRsetCache> negative_soa_cache):
message_class_(message_class),
rrset_cache_(rrset_cache),
negative_soa_cache_(negative_soa_cache),
@@ -62,12 +63,14 @@ bool
MessageCache::update(const Message& msg) {
// If the message is a negative response, but no SOA record is found in
// the authority section, the message cannot be cached
- if (isNegativeResponse(msg) && !hasTheRecordInAuthoritySection(msg, RRType::SOA())){
+ if (isNegativeResponse(msg) &&
+ !hasTheRecordInAuthoritySection(msg, RRType::SOA())){
return (false);
}
QuestionIterator iter = msg.beginQuestion();
- std::string entry_name = genCacheEntryName((*iter)->getName(), (*iter)->getType());
+ std::string entry_name = genCacheEntryName((*iter)->getName(),
+ (*iter)->getType());
HashKey entry_key = HashKey(entry_name, RRClass(message_class_));
// The simplest way to update is removing the old message entry directly.
@@ -80,7 +83,8 @@ MessageCache::update(const Message& msg) {
message_lru_.remove(old_msg_entry);
}
- MessageEntryPtr msg_entry(new MessageEntry(msg, rrset_cache_, negative_soa_cache_));
+ MessageEntryPtr msg_entry(new MessageEntry(msg, rrset_cache_,
+ negative_soa_cache_));
message_lru_.add(msg_entry);
return (message_table_.add(msg_entry, entry_key, true));
}
diff --git a/src/lib/cache/message_entry.cc b/src/lib/cache/message_entry.cc
index 400caf6..2db6dc3 100644
--- a/src/lib/cache/message_entry.cc
+++ b/src/lib/cache/message_entry.cc
@@ -83,7 +83,8 @@ MessageEntry::addRRset(isc::dns::Message& message,
}
for (uint16_t index = start_index; index < end_index; ++index) {
- message.addRRset(section, rrset_entry_vec[index]->getRRset(), dnssec_need);
+ message.addRRset(section, rrset_entry_vec[index]->getRRset(),
+ dnssec_need);
}
}
@@ -214,7 +215,8 @@ MessageEntry::parseSection(const isc::dns::Message& msg,
RRsetPtr rrset_ptr = *iter;
RRsetTrustLevel level = getRRsetTrustLevel(msg, rrset_ptr, section);
RRsetEntryPtr rrset_entry = rrset_cache_->update(*rrset_ptr, level);
- rrsets_.push_back(RRsetRef(rrset_ptr->getName(), rrset_ptr->getType(), rrset_cache_));
+ rrsets_.push_back(RRsetRef(rrset_ptr->getName(), rrset_ptr->getType(),
+ rrset_cache_));
uint32_t rrset_ttl = rrset_entry->getTTL();
if (smaller_ttl > rrset_ttl) {
@@ -232,7 +234,6 @@ MessageEntry::parseNegativeResponseAuthoritySection(const isc::dns::Message& msg
uint32_t& min_ttl,
uint16_t& rrset_count)
{
- // We found the SOA record, so we can cache the message and RRsets in the cache
uint16_t count = 0;
for (RRsetIterator iter = msg.beginSection(Message::SECTION_AUTHORITY);
iter != msg.endSection(Message::SECTION_AUTHORITY);
diff --git a/src/lib/cache/message_utility.cc b/src/lib/cache/message_utility.cc
new file mode 100644
index 0000000..a662ae6
--- /dev/null
+++ b/src/lib/cache/message_utility.cc
@@ -0,0 +1,63 @@
+// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC 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.
+
+// $Id$
+
+#include "message_utility.h"
+#include <dns/rcode.h>
+
+using namespace isc::dns;
+
+namespace isc {
+namespace cache {
+namespace MessageUtility{
+
+bool
+hasTheRecordInAuthoritySection(const isc::dns::Message& msg, const isc::dns::RRType& type)
+{
+ for (RRsetIterator iter = msg.beginSection(Message::SECTION_AUTHORITY);
+ iter != msg.endSection(Message::SECTION_AUTHORITY);
+ ++iter) {
+ RRsetPtr rrset_ptr = *iter;
+ if (rrset_ptr->getType() == type) {
+ return (true);
+ }
+ }
+ return (false);
+}
+
+bool
+isNegativeResponse(const isc::dns::Message& msg)
+{
+ if (msg.getRcode() == Rcode::NXDOMAIN()) {
+ return (true);
+ } else if (msg.getRcode() == Rcode::NOERROR()) {
+ // no data in the answer section
+ if (msg.getRRCount(Message::SECTION_ANSWER) == 0) {
+ // NODATA type 1/ type 2 (ref sec2.2 of RFC2308)
+ if (hasTheRecordInAuthoritySection(msg, RRType::SOA())) {
+ return (true);
+ } else if (!hasTheRecordInAuthoritySection(msg, RRType::NS())) {
+ // NODATA type 3 (sec2.2 of RFC2308)
+ return (true);
+ }
+ }
+ }
+
+ return (false);
+}
+
+} // namespace MessageUtility
+} // namespace cache
+} // namespace isc
diff --git a/src/lib/cache/message_utility.h b/src/lib/cache/message_utility.h
new file mode 100644
index 0000000..58b366f
--- /dev/null
+++ b/src/lib/cache/message_utility.h
@@ -0,0 +1,51 @@
+// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC 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.
+
+// $Id$
+
+#ifndef __MESSAGE_UTILITY_H
+#define __MESSAGE_UTILITY_H
+
+#include <dns/message.h>
+
+namespace isc {
+namespace cache {
+
+/// \brief Some utility functions to extract info from message
+///
+/// We need to check the message before cache it, for example, if no SOA
+/// record is found in the Authority section of NXDOMAIN response, the
+/// message cannot be cached
+namespace MessageUtility{
+
+/// \brief Check whether there is some type of record in
+/// Authority section
+///
+/// \param msg The response message to be checked
+/// \param type The RR type that need to check
+bool hasTheRecordInAuthoritySection(const isc::dns::Message& msg,
+ const isc::dns::RRType& type);
+
+/// \brief Check whetehr the message is a negative response
+/// (NXDOMAIN or NOERROR_NODATA)
+///
+/// \param msg The response message
+bool isNegativeResponse(const isc::dns::Message& msg);
+
+} // namespace MessageUtility
+} // namespace cache
+} // namespace isc
+
+
+#endif//__MESSAGE_UTILITY_H
diff --git a/src/lib/cache/resolver_cache.cc b/src/lib/cache/resolver_cache.cc
index 2e54a93..e347781 100644
--- a/src/lib/cache/resolver_cache.cc
+++ b/src/lib/cache/resolver_cache.cc
@@ -40,7 +40,8 @@ ResolverClassCache::ResolverClassCache(const RRClass& cache_class) :
messages_cache_ = MessageCachePtr(new MessageCache(rrsets_cache_,
MESSAGE_CACHE_DEFAULT_SIZE,
- cache_class_.getCode(), negative_soa_cache_));
+ cache_class_.getCode(),
+ negative_soa_cache_));
}
ResolverClassCache::ResolverClassCache(CacheSizeInfo cache_info) :
diff --git a/src/lib/cache/resolver_cache.h b/src/lib/cache/resolver_cache.h
index 32214b6..f62e485 100644
--- a/src/lib/cache/resolver_cache.h
+++ b/src/lib/cache/resolver_cache.h
@@ -135,6 +135,11 @@ public:
/// \note the function doesn't do any message validation check,
/// the user should make sure the message is valid, and of
/// the right class
+ /// TODO: Share the NXDOMAIN info between different type queries
+ /// current implementation can only cache for the type that
+ /// user quired, for example, if user query A record of
+ /// a.example. and the server replied with NXDOMAIN, this
+ /// should be cached for all the types queries of a.example.
bool update(const isc::dns::Message& msg);
/// \brief Update the rrset in the cache with the new one.
More information about the bind10-changes
mailing list