Kea  2.3.6-git
d2_tsig_key.cc
Go to the documentation of this file.
1 // Copyright (C) 2021 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 
8 
9 #include <config.h>
10 
11 #include <d2srv/d2_stats.h>
12 #include <d2srv/d2_tsig_key.h>
13 #include <stats/stats_mgr.h>
14 
15 using namespace isc::dns;
16 using namespace isc::stats;
17 using namespace std;
18 
19 namespace isc {
20 namespace d2 {
21 
22 D2TsigKey::D2TsigKey(const std::string& key_spec) : TSIGKey(key_spec) {
23  initStats();
24 }
25 
26 D2TsigKey::D2TsigKey(const Name& key_name, const Name& algorithm_name,
27  const void* secret, size_t secret_len, size_t digestbits)
28  : TSIGKey(key_name, algorithm_name, secret, secret_len, digestbits) {
29  initStats();
30 }
31 
33  removeStats();
34 }
35 
36 void
37 D2TsigKey::initStats() {
38  StatsMgr& stats_mgr = StatsMgr::instance();
39  const string& kname = getKeyName().toText();
40  for (const auto& name : D2Stats::key) {
41  const string& sname = StatsMgr::generateName("key", kname, name);
42  stats_mgr.setValue(sname, static_cast<int64_t>(0));
43  }
44 }
45 
46 void
47 D2TsigKey::removeStats() {
48  StatsMgr& stats_mgr = StatsMgr::instance();
49  const string& kname = getKeyName().toText();
50  for (const auto& name : D2Stats::key) {
51  string sname = StatsMgr::generateName("key", kname, name);
52  stats_mgr.del(sname);
53  }
54 }
55 
56 void
58  StatsMgr& stats_mgr = StatsMgr::instance();
59  const string& kname = getKeyName().toText();
60  for (const auto& name : D2Stats::key) {
61  string sname = StatsMgr::generateName("key", kname, name);
62  stats_mgr.reset(sname);
63  }
64 }
65 
68  return (TSIGContextPtr(new TSIGContext(*this)));
69 }
70 
71 } // namespace d2
72 } // namespace isc
The Name class encapsulates DNS names.
Definition: name.h:223
TSIG session context.
Definition: tsig.h:171
virtual dns::TSIGContextPtr createContext()
Create TSIG context.
Definition: d2_tsig_key.cc:67
TSIG key.
Definition: tsigkey.h:56
const Name & getKeyName() const
Return the key name.
Definition: tsigkey.cc:213
STL namespace.
static const std::list< std::string > key
Key DNS update statistics names.
Definition: d2_stats.h:42
virtual ~D2TsigKey()
Destructor.
Definition: d2_tsig_key.cc:32
static StatsMgr & instance()
Statistics Manager accessor method.
Statistics Manager class.
virtual void resetStats()
Reset statistics.
Definition: d2_tsig_key.cc:57
bool del(const std::string &name)
Removes specified statistic.
std::string toText(bool omit_final_dot=false) const
Convert the Name to a string.
Definition: name.cc:507
static std::string generateName(const std::string &context, Type index, const std::string &stat_name)
Generates statistic name in a given context.
D2TsigKey(const std::string &key_spec)
Constructor.
Definition: d2_tsig_key.cc:22
Defines the logger used by the top-level component of kea-lfc.
bool reset(const std::string &name)
Resets specified statistic.
boost::shared_ptr< TSIGContext > TSIGContextPtr
Definition: tsig.h:435
void setValue(const std::string &name, const int64_t value)
Records absolute integer observation.