Kea 2.2.0
rrcollator.cc
Go to the documentation of this file.
1// Copyright (C) 2012-2020 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8
10
11// include this first to check the header is self-contained.
12#include <dns/rrcollator.h>
13
14#include <dns/name.h>
15#include <dns/rdataclass.h>
16#include <dns/rrclass.h>
17#include <dns/rrtype.h>
18#include <dns/rrttl.h>
19#include <dns/rdata.h>
20#include <dns/rrset.h>
21
22#include <algorithm>
23#include <functional>
24
25using namespace isc::dns::rdata;
26namespace ph = std::placeholders;
27
28namespace isc {
29namespace dns {
30
32public:
33 Impl(const AddRRsetCallback& callback) : callback_(callback) {}
34
35 void addRR(const Name& name, const RRClass& rrclass,
36 const RRType& rrtype, const RRTTL& rrttl,
37 const RdataPtr& rdata);
38
41};
42
43namespace {
44inline bool
45isSameType(RRType type1, const ConstRdataPtr& rdata1,
46 const ConstRRsetPtr& rrset)
47{
48 if (type1 != rrset->getType()) {
49 return (false);
50 }
51 if (type1 == RRType::RRSIG()) {
52 RdataIteratorPtr rit = rrset->getRdataIterator();
53 return (dynamic_cast<const generic::RRSIG&>(*rdata1).typeCovered()
54 == dynamic_cast<const generic::RRSIG&>(
55 rit->getCurrent()).typeCovered());
56 }
57 return (true);
58}
59}
60
61void
62RRCollator::Impl::addRR(const Name& name, const RRClass& rrclass,
63 const RRType& rrtype, const RRTTL& rrttl,
64 const RdataPtr& rdata)
65{
66 if (current_rrset_ && (!isSameType(rrtype, rdata, current_rrset_) ||
67 current_rrset_->getClass() != rrclass ||
68 current_rrset_->getName() != name)) {
70 current_rrset_.reset();
71 }
72
73 if (!current_rrset_) {
74 current_rrset_ = RRsetPtr(new RRset(name, rrclass, rrtype, rrttl));
75 } else if (current_rrset_->getTTL() != rrttl) {
76 // RRs with different TTLs are given. Smaller TTL should win.
77 current_rrset_->setTTL(std::min(current_rrset_->getTTL(), rrttl));
78 }
79 current_rrset_->addRdata(rdata);
80}
81
83 impl_(new Impl(callback))
84{}
85
87 delete impl_;
88}
89
92 return (std::bind(&RRCollator::Impl::addRR, this->impl_,
93 ph::_1, ph::_2, ph::_3, ph::_4, ph::_5));
94}
95
96void
98 if (impl_->current_rrset_) {
99 impl_->callback_(impl_->current_rrset_);
100 impl_->current_rrset_.reset();
101 }
102}
103
104} // end namespace dns
105} // end namespace isc
The Name class encapsulates DNS names.
Definition: name.h:223
The RRClass class encapsulates DNS resource record classes.
Definition: rrclass.h:98
void addRR(const Name &name, const RRClass &rrclass, const RRType &rrtype, const RRTTL &rrttl, const RdataPtr &rdata)
Definition: rrcollator.cc:62
const AddRRsetCallback callback_
Definition: rrcollator.cc:40
Impl(const AddRRsetCallback &callback)
Definition: rrcollator.cc:33
~RRCollator()
Destructor.
Definition: rrcollator.cc:86
AddRRCallback getCallback()
Return MasterLoader compatible callback.
Definition: rrcollator.cc:91
void flush()
Call the callback on the remaining RRset, if any.
Definition: rrcollator.cc:97
std::function< void(const RRsetPtr &rrset)> AddRRsetCallback
Callback functor type for RRCollator.
Definition: rrcollator.h:54
RRCollator(const AddRRsetCallback &callback)
Constructor.
Definition: rrcollator.cc:82
The RRTTL class encapsulates TTLs used in DNS resource records.
Definition: rrttl.h:55
The RRType class encapsulates DNS resource record types.
Definition: rrtype.h:106
static const RRType & RRSIG()
Definition: rrtype.h:455
The RRset class is a concrete derived class of BasicRRset which contains a pointer to an additional R...
Definition: rrset.h:847
rdata::RRSIG class represents the RRSIG RDATA as defined in RFC4034.
Definition: rdataclass.h:1784
const RRType & typeCovered() const
boost::shared_ptr< const Rdata > ConstRdataPtr
Definition: rdata.h:72
boost::shared_ptr< Rdata > RdataPtr
The RdataPtr type is a pointer-like type, pointing to an object of some concrete derived class of Rda...
boost::shared_ptr< AbstractRRset > RRsetPtr
A pointer-like type pointing to an RRset object.
Definition: rrset.h:47
boost::shared_ptr< RdataIterator > RdataIteratorPtr
A pointer-like type point to an RdataIterator object.
Definition: rrset.h:63
std::function< void(const Name &name, const RRClass &rrclass, const RRType &rrtype, const RRTTL &rrttl, const rdata::RdataPtr &rdata)> AddRRCallback
Type of callback to add a RR.
boost::shared_ptr< const AbstractRRset > ConstRRsetPtr
A pointer-like type pointing to an (immutable) RRset object.
Definition: rrset.h:60
Defines the logger used by the top-level component of kea-lfc.