Kea  1.9.9-git
cfgmgr.h
Go to the documentation of this file.
1 // Copyright (C) 2012-2019 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 #ifndef CFGMGR_H
8 #define CFGMGR_H
9 
10 #include <asiolink/io_address.h>
11 #include <dhcp/option.h>
12 #include <dhcp/option_space.h>
13 #include <dhcp/classify.h>
14 #include <dhcpsrv/d2_client_mgr.h>
15 #include <dhcpsrv/pool.h>
16 #include <dhcpsrv/srv_config.h>
17 #include <util/buffer.h>
18 #include <util/optional.h>
19 
20 #include <boost/shared_ptr.hpp>
21 #include <boost/noncopyable.hpp>
22 
23 #include <map>
24 #include <string>
25 #include <vector>
26 #include <list>
27 
28 namespace isc {
29 namespace dhcp {
30 
36 public:
37  DuplicateListeningIface(const char* file, size_t line, const char* what) :
38  isc::Exception(file, line, what) { };
39 };
40 
70 class CfgMgr : public boost::noncopyable {
71 public:
72 
76  static const size_t CONFIG_LIST_SIZE;
77 
82  static CfgMgr& instance();
83 
90 
95  void setDataDir(const std::string& datadir, bool unspecified = true);
96 
108  void setD2ClientConfig(D2ClientConfigPtr& new_config);
109 
113  bool ddnsEnabled();
114 
118  const D2ClientConfigPtr& getD2ClientConfig() const;
119 
124 
139 
140 
148  void clear();
149 
158  void commit();
159 
169  void rollback();
170 
195  void revert(const size_t index);
196 
221 
235 
247 
258  void mergeIntoStagingCfg(const uint32_t seq);
259 
270  void mergeIntoCurrentCfg(const uint32_t seq);
271 
273 
275  void setFamily(uint16_t family) {
276  family_ = family == AF_INET ? AF_INET : AF_INET6;
277  }
278 
280  uint16_t getFamily() const {
281  return (family_);
282  }
283 
285 
286 protected:
287 
294  CfgMgr();
295 
297  virtual ~CfgMgr();
298 
299 private:
300 
306  void ensureCurrentAllocated();
307 
308 
315  void mergeIntoCfg(const SrvConfigPtr& taget_config, const uint32_t seq);
316 
319 
321  D2ClientMgr d2_client_mgr_;
322 
327  SrvConfigPtr configuration_;
328 
331 
332  typedef std::list<SrvConfigPtr> SrvConfigList;
334 
336  SrvConfigList configs_;
338 
341 
342  typedef std::map<uint32_t, SrvConfigPtr> SrvConfigMap;
344 
347  SrvConfigMap external_configs_;
349 
351  uint16_t family_;
352 };
353 
354 } // namespace isc::dhcp
355 } // namespace isc
356 
357 #endif // CFGMGR_H
static const size_t CONFIG_LIST_SIZE
A number of configurations held by CfgMgr.
Definition: cfgmgr.h:76
void revert(const size_t index)
Reverts to one of the previous configurations.
Definition: cfgmgr.cc:128
void mergeIntoStagingCfg(const uint32_t seq)
Merges external configuration with the given sequence number into the staging configuration.
Definition: cfgmgr.cc:190
void rollback()
Removes staging configuration.
Definition: cfgmgr.cc:120
void setDataDir(const std::string &datadir, bool unspecified=true)
Sets new data directory.
Definition: cfgmgr.cc:36
void commit()
Commits the staging configuration.
Definition: cfgmgr.cc:90
static CfgMgr & instance()
returns a single instance of Configuration Manager
Definition: cfgmgr.cc:25
Defines elements for storing the names of client classes.
boost::shared_ptr< SrvConfig > SrvConfigPtr
Non-const pointer to the SrvConfig.
Definition: srv_config.h:1036
Exception thrown when the same interface has been specified twice.
Definition: cfgmgr.h:35
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
Definition: cfgmgr.cc:161
DuplicateListeningIface(const char *file, size_t line, const char *what)
Definition: cfgmgr.h:37
void setFamily(uint16_t family)
Sets address family (AF_INET or AF_INET6)
Definition: cfgmgr.h:275
void clear()
Removes current, staging and all previous configurations.
Definition: cfgmgr.cc:79
util::Optional< std::string > getDataDir() const
returns path do the data directory
Definition: cfgmgr.cc:31
uint16_t getFamily() const
Returns address family.
Definition: cfgmgr.h:280
void mergeIntoCurrentCfg(const uint32_t seq)
Merges external configuration with the given sequence number into the current configuration.
Definition: cfgmgr.cc:195
virtual ~CfgMgr()
virtual destructor
Definition: cfgmgr.cc:229
void setD2ClientConfig(D2ClientConfigPtr &new_config)
Updates the DHCP-DDNS client configuration to the given value.
Definition: cfgmgr.cc:41
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
D2ClientMgr isolates Kea from the details of being a D2 client.
Definition: d2_client_mgr.h:79
bool ddnsEnabled()
Convenience method for checking if DHCP-DDNS updates are enabled.
Definition: cfgmgr.cc:56
D2ClientMgr & getD2ClientMgr()
Fetches the DHCP-DDNS manager.
Definition: cfgmgr.cc:66
SrvConfigPtr createExternalCfg()
Creates an external configuration and returns pointer to it.
Definition: cfgmgr.cc:177
boost::shared_ptr< D2ClientConfig > D2ClientConfigPtr
Defines a pointer for D2ClientConfig instances.
Defines the D2ClientMgr class.
const D2ClientConfigPtr & getD2ClientConfig() const
Fetches the DHCP-DDNS configuration pointer.
Definition: cfgmgr.cc:61
Configuration Manager.
Definition: cfgmgr.h:70
CfgMgr()
Protected constructor.
Definition: cfgmgr.cc:222
SrvConfigPtr getStagingCfg()
Returns a pointer to the staging configuration.
Definition: cfgmgr.cc:167