1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298 | // Copyright (C) 2012-2024 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#ifndef CFGMGR_H
#define CFGMGR_H
#include <asiolink/io_address.h>
#include <dhcp/option.h>
#include <dhcp/option_space.h>
#include <dhcp/classify.h>
#include <dhcpsrv/d2_client_mgr.h>
#include <dhcpsrv/pool.h>
#include <dhcpsrv/srv_config.h>
#include <util/buffer.h>
#include <util/optional.h>
#include <boost/shared_ptr.hpp><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <boost/noncopyable.hpp><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <map><--- Include file:
#include <string><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <vector><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <list><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
namespace isc {
namespace dhcp {
/// @brief Exception thrown when the same interface has been specified twice.
///
/// In particular, this exception is thrown when adding interface to the set
/// of interfaces on which server is supposed to listen.
class DuplicateListeningIface : public Exception {
public:
DuplicateListeningIface(const char* file, size_t line, const char* what) :
isc::Exception(file, line, what) { }
};
/// @brief Configuration Manager
///
/// This singleton class holds the whole configuration for DHCPv4 and DHCPv6
/// servers.
///
/// Below is a sketch of configuration inheritance.
/// Let's investigate the following configuration:
///
/// @code
/// preferred-lifetime 500;
/// valid-lifetime 1000;
/// subnet6 2001:db8:1::/48 {
/// pool6 2001::db8:1::1 - 2001::db8:1::ff;
/// };
/// subnet6 2001:db8:2::/48 {
/// valid-lifetime 2000;
/// pool6 2001::db8:2::1 - 2001::db8:2::ff;
/// };
/// @endcode
///
/// Parameters defined in a global scope are applicable to everything until
/// they are overwritten in a smaller scope, in this case subnet6.
/// In the example above, the first subnet6 has preferred lifetime of 500s
/// and a valid lifetime of 1000s. The second subnet has preferred lifetime
/// of 500s, but valid lifetime of 2000s.
///
/// Parameter inheritance is implemented in dedicated classes. See
/// @ref isc::dhcp::SimpleParser4::deriveParameters and
/// @ref isc::dhcp::SimpleParser6::deriveParameters.
class CfgMgr : public boost::noncopyable {
public:
/// @brief returns a single instance of Configuration Manager
///
/// CfgMgr is a singleton and this method is the only way of
/// accessing it.
static CfgMgr& instance();
/// @brief returns path do the data directory
///
/// This method returns a path to writable directory that DHCP servers
/// can store data in.
/// @return data directory
util::Optional<std::string> getDataDir() const;<--- Function 'getDataDir()' should return member 'datadir_' by const reference.
/// @brief Sets new data directory.
///
/// @param datadir New data directory.
/// @param unspecified Initial state. Default is "unspecified".
void setDataDir(const std::string& datadir, bool unspecified = true);
/// @brief Updates the DHCP-DDNS client configuration to the given value.
///
/// Passes the new configuration to the D2ClientMgr instance,
/// d2_client_mgr_, which will attempt to apply the new configuration
/// by shutting down its sender and opening a new connection per the new
/// configuration (see @c D2ClientMgr::setD2ClientConfig()).
///
/// @param new_config pointer to the new client configuration.
///
/// @throw Underlying method(s) will throw D2ClientError if given an empty
/// pointer.
void setD2ClientConfig(D2ClientConfigPtr& new_config);
/// @brief Convenience method for checking if DHCP-DDNS updates are enabled.
///
/// @return True if the D2 configuration is enabled.
bool ddnsEnabled();
/// @brief Fetches the DHCP-DDNS configuration pointer.
///
/// @return a reference to the current configuration pointer.
const D2ClientConfigPtr& getD2ClientConfig() const;
/// @brief Fetches the DHCP-DDNS manager.
///
/// @return a reference to the DHCP-DDNS manager.
D2ClientMgr& getD2ClientMgr();
/// @name Methods managing the collection of configurations.
///
/// The following methods manage the process of preparing a configuration
/// without affecting a currently used configuration and then committing
/// the configuration to replace current configuration atomically.
///
/// @todo Migrate all configuration parameters to use the model supported
/// by these functions.
///
//@{
/// @brief Remove current, staging, and external configurations.
///
/// This function removes all configurations, including current,
/// staging and external configurations. It creates a new current
/// configuration with default settings.
///
/// This function is exception safe.
void clear();
/// @brief Remove staging configuration.
///
/// This function is exception safe.
void clearStagingConfiguration();
/// @brief Commits the staging configuration.
///
/// The staging configuration becomes current configuration when this
/// function is called.
///
/// This function is exception safe.
void commit();
/// @brief Returns a pointer to the current configuration.
///
/// This function returns pointer to the current configuration. If the
/// current configuration is not set it will create a default configuration
/// and return it.
///
/// In the previous Kea releases this method used to return a const pointer
/// to the current configuration to ensure that it is not accidentally
/// modified while the server is running. This has been changed in Kea 1.3
/// release and now this function returns a non-const pointer. The reason
/// is that there are certain use cases when current configuration must
/// be modified without going through a full cycle of server
/// reconfiguration, e.g. add a subnet to the current configuration as
/// a result of receiving a command over control API. In such case the
/// performance of processing such command is critical and rebuilding the
/// whole configuration just for this small configuration change is out
/// of question.
///
/// Nevertheless, such configuration updates should always be made with
/// caution and one has to make sure that the configuration data integrity
/// is preserved.
///
/// @return Non-null pointer to the current configuration.
SrvConfigPtr getCurrentCfg();
/// @brief Returns a pointer to the staging configuration.
///
/// The staging configuration is used by the configuration parsers to
/// create new configuration. The staging configuration doesn't affect the
/// server's operation until it is committed. The staging configuration
/// is a non-const object which can be modified by the caller.
///
/// Multiple consecutive calls to this function return the same object
/// which can be modified from various places of the code (e.g. various
/// configuration parsers).
///
/// @return non-null pointer to the staging configuration.
SrvConfigPtr getStagingCfg();
/// @brief Creates an external configuration and returns pointer to it.
///
/// External configurations are those that come from other sources than
/// from the configuration file, e.g. a database or a command. They
/// are created aside and merged into the staging or current configuration.
/// External configurations are accessed by their sequence numbers. The
/// sequence numbers are autogenerated when the external configuration
/// instance is created.
///
/// @return non-null pointer to created external configuration.
SrvConfigPtr createExternalCfg();
/// @brief Merges external configuration with the given sequence number
/// into the staging configuration.
///
/// After the merge, the source configuration is discarded from the
/// @c CfgMgr as it should not be used anymore.
///
/// @param seq Source configuration sequence number.
///
/// @throw BadValue if the external configuration with the given sequence
/// number doesn't exist.
void mergeIntoStagingCfg(const uint32_t seq);
/// @brief Merges external configuration with the given sequence number
/// into the current configuration.
///
/// After the merge, the source configuration is discarded from the
/// @c CfgMgr as it should not be used anymore.
///
/// @param seq Source configuration sequence number.
///
/// @throw BadValue if the external configuration with the given sequence
/// number doesn't exist.
void mergeIntoCurrentCfg(const uint32_t seq);
//@}
/// @brief Sets address family (AF_INET or AF_INET6)
void setFamily(uint16_t family) {
family_ = family == AF_INET ? AF_INET : AF_INET6;
}
/// @brief Returns address family.
uint16_t getFamily() const {
return (family_);
}
//@}
protected:
/// @brief Protected constructor.
///
/// This constructor is protected for 2 reasons. First, it forbids any
/// instantiations of this class (CfgMgr is a singleton). Second, it
/// allows derived class to instantiate it. That is useful for testing
/// purposes.
CfgMgr();
/// @brief virtual destructor
virtual ~CfgMgr() = default;
private:
/// @brief Merges external configuration with the given sequence number
/// into the specified configuration.
///
/// @param target_config Pointer to the configuration into which the
/// external configuration should be merged.
/// @param seq Source configuration sequence number.
void mergeIntoCfg(const SrvConfigPtr& taget_config, const uint32_t seq);
/// @brief directory where data files (e.g. server-id) are stored
util::Optional<std::string> datadir_;
/// @brief Manages the DHCP-DDNS client and its configuration.
D2ClientMgrPtr d2_client_mgr_;
/// @brief Current server configuration
///
/// This is a structure that will hold all configuration.
/// @todo: migrate all other parameters to that structure.
SrvConfigPtr configuration_;
/// @brief Staging server configuration
///
/// This is a structure that holds configuration until it is applied.
SrvConfigPtr staging_configuration_;
/// @name Map of external configurations.
///
//@{
/// @brief Server configuration map type.
typedef std::map<uint32_t, SrvConfigPtr> SrvConfigMap;
/// @brief Map of external configurations with sequence numbers used
/// as keys.
SrvConfigMap external_configs_;
//@}
/// @brief Address family.
uint16_t family_;
};
} // namespace isc::dhcp
} // namespace isc
#endif // CFGMGR_H
|