srv_config.h 30.7 KB
Newer Older
1
// Copyright (C) 2014-2019 Internet Systems Consortium, Inc. ("ISC")
2
//
3 4 5
// 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/.
6

7 8
#ifndef DHCPSRV_CONFIG_H
#define DHCPSRV_CONFIG_H
9

10
#include <cc/cfg_to_element.h>
11
#include <dhcpsrv/cfg_db_access.h>
12
#include <dhcpsrv/cfg_duid.h>
13
#include <dhcpsrv/cfg_expiration.h>
14
#include <dhcpsrv/cfg_host_operations.h>
15
#include <dhcpsrv/cfg_hosts.h>
16
#include <dhcpsrv/cfg_iface.h>
17
#include <dhcpsrv/cfg_option.h>
18
#include <dhcpsrv/cfg_option_def.h>
19
#include <dhcpsrv/cfg_rsoo.h>
20
#include <dhcpsrv/cfg_shared_networks.h>
21
#include <dhcpsrv/cfg_subnets4.h>
22
#include <dhcpsrv/cfg_subnets6.h>
Tomek Mrugalski's avatar
Tomek Mrugalski committed
23
#include <dhcpsrv/cfg_mac_source.h>
24
#include <dhcpsrv/cfg_consistency.h>
25
#include <dhcpsrv/client_class_def.h>
26
#include <dhcpsrv/d2_client_cfg.h>
27
#include <process/config_base.h>
28
#include <hooks/hooks_config.h>
29
#include <cc/data.h>
30
#include <cc/user_context.h>
31
#include <cc/simple_parser.h>
32
#include <boost/shared_ptr.hpp>
33 34
#include <vector>
#include <stdint.h>
35 36 37 38

namespace isc {
namespace dhcp {

39 40
class CfgMgr;

41 42 43 44

/// @brief Specifies current DHCP configuration
///
/// @todo Migrate all other configuration parameters from cfgmgr.h here
45
class SrvConfig : public process::ConfigBase {
46
public:
47 48 49
    /// @name Constants for selection of parameters returned by @c getConfigSummary
    ///
    //@{
50 51 52 53 54 55 56 57 58 59 60 61 62 63
    /// Nothing selected
    static const uint32_t CFGSEL_NONE    = 0x00000000;
    /// Number of IPv4 subnets
    static const uint32_t CFGSEL_SUBNET4 = 0x00000001;
    /// Number of IPv6 subnets
    static const uint32_t CFGSEL_SUBNET6 = 0x00000002;
    /// Number of enabled ifaces
    static const uint32_t CFGSEL_IFACE4  = 0x00000004;
    /// Number of v6 ifaces
    static const uint32_t CFGSEL_IFACE6  = 0x00000008;
    /// DDNS enabled/disabled
    static const uint32_t CFGSEL_DDNS    = 0x00000010;
    /// Number of all subnets
    static const uint32_t CFGSEL_SUBNET  = 0x00000003;
64 65
    /// Configured globals
    static const uint32_t CFGSEL_GLOBALS = 0x00000020;
66 67
    /// Config control info
    static const uint32_t CFGSEL_CFG_CTL = 0x00000040;
68
    /// IPv4 related config
69
    static const uint32_t CFGSEL_ALL4    = 0x00000035;
70
    /// IPv6 related config
71
    static const uint32_t CFGSEL_ALL6    = 0x0000003A;
72 73
    /// Whole config
    static const uint32_t CFGSEL_ALL     = 0xFFFFFFFF;
74
    //@}
75

76
    /// @brief Default constructor.
77
    ///
78
    /// This constructor sets configuration sequence number to 0.
79
    SrvConfig();
80 81 82 83

    /// @brief Constructor.
    ///
    /// Sets arbitrary configuration sequence number.
84
    SrvConfig(const uint32_t sequence);
85

86 87 88
    /// @brief Returns summary of the configuration in the textual format.
    ///
    /// This method returns the brief text describing the current configuration.
89
    /// It may be used for logging purposes, e.g. when the new configuration is
90 91 92 93 94 95
    /// committed to notify a user about the changes in configuration.
    ///
    /// @todo Currently this method uses @c CfgMgr accessors to get the
    /// configuration parameters. Once these parameters are migrated from the
    /// @c CfgMgr this method will have to be modified accordingly.
    ///
96 97 98 99
    /// @todo Implement reporting a summary of interfaces being used for
    /// receiving and sending DHCP messages. This will be implemented with
    /// ticket #3512.
    ///
100 101 102 103 104
    /// @param selection Is a bitfield which describes the parts of the
    /// configuration to be returned.
    ///
    /// @return Summary of the configuration in the textual format.
    std::string getConfigSummary(const uint32_t selection) const;
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120

    /// @brief Returns configuration sequence number.
    uint32_t getSequence() const {
        return (sequence_);
    }

    /// @brief Compares configuration sequence with other sequence.
    ///
    /// This method compares sequence numbers of two configurations for
    /// equality. The sequence numbers are meant to be unique, so if
    /// they are equal it means that they point to the same configuration.
    ///
    /// @param other Configuration which sequence number should be
    /// compared with the sequence number of this configuration.
    ///
    /// @return true if sequence numbers are equal.
121
    bool sequenceEquals(const SrvConfig& other);
122

123
    /// @brief Returns non-const pointer to interface configuration.
124
    ///
125 126
    /// This function returns a non-const pointer to the interface
    /// configuration.
127
    ///
128 129
    /// @return Object representing configuration of interfaces.
    CfgIfacePtr getCfgIface() {
130 131 132
        return (cfg_iface_);
    }

133
    /// @brief Returns const pointer to interface configuration.
134
    ///
135 136 137 138 139 140
    /// This function returns a const pointer to the interface
    /// configuration.
    ///
    /// @return Object representing configuration of interfaces.
    ConstCfgIfacePtr getCfgIface() const {
        return (cfg_iface_);
141 142
    }

143 144
    /// @brief Return pointer to non-const object representing user-defined
    /// option definitions.
145
    ///
146 147 148 149 150 151 152 153 154 155 156 157
    /// This function returns a pointer to the object which represents the
    /// user defined option definitions grouped by option space name.
    ///
    /// @return Pointer to an object holding option definitions.
    CfgOptionDefPtr getCfgOptionDef() {
        return (cfg_option_def_);
    }

    /// @brief Returns pointer to the const object representing user-defined
    /// option definitions.
    ///
    /// This function returns a pointer to the object which represents the
158 159
    /// user defined option definitions grouped by option space name.
    ///
160 161
    /// @return Pointer to an object holding option definitions.
    ConstCfgOptionDefPtr getCfgOptionDef() const {
162 163 164
        return (cfg_option_def_);
    }

165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
    /// @brief Returns pointer to the non-const object holding options.
    ///
    /// This method returns a pointer to the object which holds instances
    /// of the options to be returned to the clients belonging to any subnet.
    ///
    /// @return Pointer to the object holding options.
    CfgOptionPtr getCfgOption() {
        return (cfg_option_);
    }

    /// @brief Returns pointer to the const object holding options.
    ///
    /// This method returns a pointer to the object which holds instances
    /// of the options to be returned to the clients belonging to any subnet.
    ///
    /// @return Pointer to the object holding options.
    const ConstCfgOptionPtr getCfgOption() const {
        return (cfg_option_);
    }

185 186 187 188 189 190 191 192
    /// @brief Returns pointer to non-const object holding subnets configuration
    /// for DHCPv4.
    ///
    /// @return Pointer to the object holding subnets configuration for DHCPv4.
    CfgSubnets4Ptr getCfgSubnets4() {
        return (cfg_subnets4_);
    }

193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
    /// @brief Returns pointer to non-const object holding configuration of
    /// shared networks in DHCPv4;
    ///
    /// @return Pointer to the object holding shared networks configuration
    /// for DHCPv4.
    CfgSharedNetworks4Ptr getCfgSharedNetworks4() const {
        return (cfg_shared_networks4_);
    }

    /// @brief Returns pointer to non-const object holding configuration of
    /// shared networks in DHCPv6.
    ///
    /// @return Pointer to the object holding shared networks configuration
    /// for DHCPv6.
    CfgSharedNetworks6Ptr getCfgSharedNetworks6() const {
        return (cfg_shared_networks6_);
    }

211 212 213 214 215 216 217 218
    /// @brief Returns pointer to const object holding subnets configuration for
    /// DHCPv4.
    ///
    /// @return Pointer to the object holding subnets configuration for DHCPv4.
    ConstCfgSubnets4Ptr getCfgSubnets4() const {
        return (cfg_subnets4_);
    }

219 220 221
    /// @brief Returns pointer to non-const object holding subnets configuration
    /// for DHCPv6.
    ///
222
    /// @return Pointer to the object holding subnets configuration for DHCPv6.
223 224 225 226 227
    CfgSubnets6Ptr getCfgSubnets6() {
        return (cfg_subnets6_);
    }

    /// @brief Returns pointer to const object holding subnets configuration for
228
    /// DHCPv6.
229 230 231 232 233 234
    ///
    /// @return Pointer to the object holding subnets configuration for DHCPv6.
    ConstCfgSubnets6Ptr getCfgSubnets6() const {
        return (cfg_subnets6_);
    }

235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
    /// @brief Returns pointer to the non-const objects representing host
    /// reservations for different IPv4 and IPv6 subnets.
    ///
    /// @return Pointer to the non-const object holding host reservations.
    CfgHostsPtr getCfgHosts() {
        return (cfg_hosts_);
    }

    /// @brief Returns pointer to the const objects representing host
    /// reservations for different IPv4 and IPv6 subnets.
    ///
    /// @return Pointer to the const object holding host reservations.
    ConstCfgHostsPtr getCfgHosts() const {
        return (cfg_hosts_);
    }

251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
    /// @brief Returns pointer to the non-const object representing
    /// set of RSOO-enabled options.
    ///
    /// @return Pointer to the non-const object holding RSOO-enabled
    /// options.
    CfgRSOOPtr getCfgRSOO() {
        return (cfg_rsoo_);
    }

    /// @brief Returns pointer to the const object representing set
    /// of RSOO-enabled options.
    ///
    /// @return Pointer to the const object holding RSOO-enabled
    /// options.
    ConstCfgRSOOPtr getCfgRSOO() const {
        return (cfg_rsoo_);
    }

269 270 271 272 273 274 275 276 277 278 279 280
    /// @brief Returns pointer to the object holding configuration pertaining
    /// to processing expired leases.
    CfgExpirationPtr getCfgExpiration() {
        return (cfg_expiration_);
    }

    /// @brief Returns pointer to the const object holding configuration
    /// pertaining to processing expired leases.
    ConstCfgExpirationPtr getCfgExpiration() const {
        return (cfg_expiration_);
    }

281 282 283 284 285 286 287 288 289 290 291 292
    /// @brief Returns pointer to the object holding configuration of the
    /// server identifier.
    CfgDUIDPtr getCfgDUID() {
        return (cfg_duid_);
    }

    /// @brief Returns const pointer to the object holding configuration
    /// of the server identifier.
    ConstCfgDUIDPtr getCfgDUID() const {
        return (cfg_duid_);
    }

293
    /// @brief Returns pointer to the object holding configuration of the
294 295 296 297 298 299 300 301 302 303 304
    /// lease and host database connection parameters.
    CfgDbAccessPtr getCfgDbAccess() {
        return (cfg_db_access_);
    }

    /// @brief Returns const pointer to the object holding configuration of
    /// the lease and host database connection parameters.
    ConstCfgDbAccessPtr getCfgDbAccess() const {
        return (cfg_db_access_);
    }

305 306
    /// @brief Returns pointer to the object holding general configuration
    /// for host reservations in DHCPv4.
307 308
    CfgHostOperationsPtr getCfgHostOperations4() {
        return (cfg_host_operations4_);
309 310 311 312
    }

    /// @brief Returns const pointer to the object holding general
    /// configuration for host reservations in DHCPv4
313 314
    ConstCfgHostOperationsPtr getCfgHostOperations4() const {
        return (cfg_host_operations4_);
315 316 317 318
    }

    /// @brief Returns pointer to the object holding general configuration
    /// for host reservations in DHCPv6.
319 320
    CfgHostOperationsPtr getCfgHostOperations6() {
        return (cfg_host_operations6_);
321 322 323 324
    }

    /// @brief Returns const pointer to the object holding general
    /// configuration for host reservations in DHCPv6
325 326
    ConstCfgHostOperationsPtr getCfgHostOperations6() const {
        return (cfg_host_operations6_);
327 328
    }

329 330 331 332 333
    /// @brief Returns const pointer to object holding sanity checks flags
    CfgConsistencyPtr getConsistency() {
        return (cfg_consist_);
    }

Tomek Mrugalski's avatar
Tomek Mrugalski committed
334
    //@}
335

Tomek Mrugalski's avatar
Tomek Mrugalski committed
336 337
    /// @brief Returns non-const reference to an array that stores
    ///        MAC/hardware address sources.
338
    ///
Tomek Mrugalski's avatar
Tomek Mrugalski committed
339 340 341
    /// @return non-const reference to MAC/hardware address sources
    CfgMACSource& getMACSources() {
        return (cfg_mac_source_);
342 343
    }

Tomek Mrugalski's avatar
Tomek Mrugalski committed
344 345 346 347 348 349
    /// @brief Returns const reference to an array that stores
    ///        MAC/hardware address sources.
    ///
    /// @return const reference to MAC/hardware address sources
    const CfgMACSource& getMACSources() const {
        return (cfg_mac_source_);
350 351
    }

352 353 354 355 356 357 358 359 360 361 362 363
    /// @brief Returns information about control socket
    /// @return pointer to the Element that holds control-socket map
    const isc::data::ConstElementPtr getControlSocketInfo() const {
        return (control_socket_);
    }

    /// @brief Sets information about the control socket
    /// @param control_socket Element that holds control-socket map
    void setControlSocketInfo(const isc::data::ConstElementPtr& control_socket) {
        control_socket_ = control_socket;
    }

364 365 366 367
    /// @brief Returns DHCP queue control information
    /// @return pointer to the DHCP queue control information
    const isc::data::ConstElementPtr getDHCPQueueControl() const {
        return (dhcp_queue_control_);
368 369
    }

370
    /// @brief Sets information about the dhcp queue control
371
    /// @param dhcp_queue_control new dhcp queue control information
372 373
    void setDHCPQueueControl(const isc::data::ConstElementPtr dhcp_queue_control) {
        dhcp_queue_control_ = dhcp_queue_control;
374 375
    }

376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
    /// @brief Returns pointer to the dictionary of global client
    /// class definitions
    ClientClassDictionaryPtr getClientClassDictionary() {
        return (class_dictionary_);
    }

    /// @brief Returns pointer to const dictionary of global client
    /// class definitions
    const ClientClassDictionaryPtr getClientClassDictionary() const {
        return (class_dictionary_);
    }

    /// @brief Sets the client class dictionary
    /// @param dictionary pointer to the new class dictionary
    void setClientClassDictionary(const ClientClassDictionaryPtr& dictionary) {
        class_dictionary_ = dictionary;
    }

394 395 396 397 398 399 400 401 402 403 404 405 406 407
    /// @brief Returns non-const reference to configured hooks libraries.
    ///
    /// @return non-const reference to configured hooks libraries.
    isc::hooks::HooksConfig& getHooksConfig() {
        return (hooks_config_);
    }

    /// @brief Returns const reference to configured hooks libraries.
    ///
    /// @return const reference to configured hooks libraries.
    const isc::hooks::HooksConfig& getHooksConfig() const {
        return (hooks_config_);
    }

408
    /// @brief Fetches the DDNS parameters for a given subnet.
409 410 411 412 413 414 415 416 417 418 419 420
    ///
    /// Creates a DdnsParams structure populated with the scoped
    /// values for DDNS behaviorial parameters. The scope mode used
    /// is Network::ALL.
    ///
    /// - enable_updates_ = (DhcpDdns.enable-updates && scoped ddns-enable-updates)
    /// - override_no_update_ = scoped ddns-override-no-update
    /// - override_client_update_ = scoped ddns-override-no-update
    /// - replace_client_name_mode_  = scoped ddns-replace-client-name
    /// - generated_prefix_ =  scoped ddns-generated-prefix
    /// - qualifying_suffix_ = scoped ddns-qualifying-suffix
    ///
421
    /// @param subnet Subnet for which DDNS parameters are desired.
422 423 424
    /// @return pointer to DddnParams instance
    DdnsParamsPtr getDdnsParams(const Subnet& subnet) const;

425
    /// @brief Copies the current configuration to a new configuration.
426 427 428 429 430
    ///
    /// This method copies the parameters stored in the configuration to
    /// an object passed as parameter. The configuration sequence is not
    /// copied.
    ///
431 432 433 434 435 436
    /// @warning Some of the configuration objects are not copied at
    /// this point, e.g. subnets. This is because they contain quite complex
    /// data structures and they make use of pointers, so in many cases
    /// the default copy constructors can't be used. Implementing this
    /// requires quite a lot of time so this is left as is for now.
    /// The lack of ability to copy the entire configuration makes
Josh Soref's avatar
Josh Soref committed
437
    /// revert function of the @c CfgMgr unusable.
438
    ///
439 440
    /// @param [out] new_config An object to which the configuration will
    /// be copied.
441
    void copy(SrvConfig& new_config) const;
442

443 444 445 446 447 448 449 450 451 452 453 454
    /// @name Methods and operators used to compare configurations.
    ///
    //@{
    ///
    /// @brief Compares two objects for equality.
    ///
    /// It ignores the configuration sequence number when checking for
    /// equality of objects.
    ///
    /// @param other An object to be compared with this object.
    ///
    /// @return true if two objects are equal, false otherwise.
455
    bool equals(const SrvConfig& other) const;
456 457 458 459 460 461 462 463 464

    /// @brief Compares two objects for inequality.
    ///
    /// It ignores the configuration sequence number when checking for
    /// inequality of objects.
    ///
    /// @param other An object to be compared with this object.
    ///
    /// @return true if two objects are not equal, false otherwise.
465
    bool nequals(const SrvConfig& other) const {
466 467 468 469 470 471 472 473 474 475 476
        return (!equals(other));
    }

    /// @brief Equality operator.
    ///
    /// It ignores the configuration sequence number when checking for
    /// equality of objects.
    ///
    /// @param other An object to be compared with this object.
    ///
    /// @return true if two objects are equal, false otherwise.
477
    bool operator==(const SrvConfig& other) const {
478 479 480
        return (equals(other));
    }

481
    /// @brief other An object to be compared with this object.
482 483 484 485 486 487 488
    ///
    /// It ignores the configuration sequence number when checking for
    /// inequality of objects.
    ///
    /// @param other An object to be compared with this object.
    ///
    /// @return true if two objects are not equal, false otherwise.
489
    bool operator!=(const SrvConfig& other) const {
490 491 492 493 494
        return (nequals(other));
    }

    //@}

495 496 497 498 499
    /// @brief Merges the configuration specified as a parameter into
    /// this configuration.
    ///
    /// This method is used when two or more configurations held in the
    /// @c SrvConfig objects need to be combined into a single configuration.
500
    /// Specifically, when the configuration backend is used, then part of
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
    /// the server configuration comes from the configuration file and
    /// stored in the staging configuration. The other part of the
    /// configuration comes from the database. The configuration fetched
    /// from the database is stored in a separate @c SrvConfig instance
    /// and then merged into the staging configuration prior to commiting
    /// it.
    ///
    /// The merging strategy depends on the underlying data being merged.
    /// For example: subnets are merged using the algorithm implemented
    /// in the @c CfgSubnets4. Other data structures are merged using the
    /// algorithms implemented in their respective configuration
    /// containers.
    ///
    /// The general rule is that the configuration data from the @c other
    /// object replaces configuration data held in this object instance.
    /// The data that do not overlap between the two objects is simply
    /// inserted into this configuration.
    ///
519
    /// @warning The call to @c merge may modify the data in the @c other
520 521 522 523 524 525 526
    /// object. Therefore, the caller must not rely on the data held
    /// in the @c other object after the call to @c merge. Also, the
    /// data held in @c other must not be modified after the call to
    /// @c merge because it may affect the merged configuration.
    ///
    /// The @c other parameter must be a @c SrvConfig or its derivation.
    ///
527 528
    /// This method calls either @c merge4 or @c merge6 based on
    ///
529
    /// Currently, the following parts of the configuration are merged:
530 531 532 533 534 535
    /// - globals
    /// - option definitions
    /// - options
    /// - via @c merge4 or @c merge6 depending on @c CfgMgr::family_:
    ///     - shared networks
    ///     - subnets
536 537 538 539 540
    ///
    /// @todo Add support for merging other configuration elements.
    ///
    /// @param other An object holding the configuration to be merged
    /// into this configuration.
541
    virtual void merge(ConfigBase& other);
542

Tomek Mrugalski's avatar
Tomek Mrugalski committed
543 544 545
    /// @brief Updates statistics.
    ///
    /// This method calls appropriate methods in child objects that update
546 547
    /// related statistics. See @ref CfgSubnets4::updateStatistics and
    /// @ref CfgSubnets6::updateStatistics for details.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
548 549 550 551 552
    void updateStatistics();

    /// @brief Removes statistics.
    ///
    /// This method calls appropriate methods in child objects that remove
553 554
    /// related statistics. See @ref CfgSubnets4::removeStatistics and
    /// @ref CfgSubnets6::removeStatistics for details.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
555
    void removeStatistics();
556

557
    /// @brief Sets decline probation-period
Tomek Mrugalski's avatar
Tomek Mrugalski committed
558 559 560 561
    ///
    /// Probation-period is the timer, expressed, in seconds, that specifies how
    /// long a lease is unavailable after reported as declined.
    ///
562
    /// @param decline_timer number of seconds after declined lease is restored
Tomek Mrugalski's avatar
Tomek Mrugalski committed
563
    void setDeclinePeriod(const uint32_t decline_timer) {
564 565 566
        decline_timer_ = decline_timer;
    }

Tomek Mrugalski's avatar
Tomek Mrugalski committed
567 568 569 570
    /// @brief Returns probation-period
    ///
    /// See @ref setDeclinePeriod for brief discussion.
    /// @return value of probation-period, expressed in seconds
571 572 573 574
    uint32_t getDeclinePeriod() const {
        return (decline_timer_);
    }

575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
    /// @brief Sets whether server should send back client-id in DHCPv4
    ///
    /// This is a compatibility flag. The default (true) is compliant with
    /// RFC6842. False is for backward compatibility.
    ///
    /// @param echo should the client-id be sent or not
    void setEchoClientId(const bool echo) {
        echo_v4_client_id_ = echo;
    }

    /// @brief Returns whether server should send back client-id in DHCPv4.
    /// @return true if client-id should be returned, false otherwise.
    bool getEchoClientId() const {
        return (echo_v4_client_id_);
    }

591 592 593 594 595 596
    /// @brief Sets DHCP4o6 IPC port
    ///
    /// DHCPv4-over-DHCPv6 uses a UDP socket for interserver communication,
    /// this socket is bound and connected to this port and port + 1
    ///
    /// @param port port and port + 1 to use
597
    void setDhcp4o6Port(uint16_t port) {
598 599 600 601 602
        dhcp4o6_port_ = port;
    }

    /// @brief Returns DHCP4o6 IPC port
    ///
603
    /// See @ref setDhcp4o6Port for brief discussion.
604
    /// @return value of DHCP4o6 IPC port
605
    uint16_t getDhcp4o6Port() const {
606 607 608
        return (dhcp4o6_port_);
    }

609 610 611 612 613 614 615 616 617 618 619
    /// @brief Returns pointer to the D2 client configuration
    D2ClientConfigPtr getD2ClientConfig() {
        return (d2_client_config_);
    }

    /// @brief Returns pointer to const D2 client configuration
    const D2ClientConfigPtr getD2ClientConfig() const {
        return (d2_client_config_);
    }

    /// @brief Sets the D2 client configuration
620
    /// @param d2_client_config pointer to the new D2 client configuration
621 622 623 624
    void setD2ClientConfig(const D2ClientConfigPtr& d2_client_config) {
        d2_client_config_ = d2_client_config;
    }

625 626 627 628 629
    /// @brief Returns pointer to configured global parameters
    isc::data::ConstElementPtr getConfiguredGlobals() const {
        return (isc::data::ConstElementPtr(configured_globals_));
    }

630 631 632 633 634 635
    /// @brief Returns pointer to a given configured global parameter
    /// @param name name of the parameter to fetch
    /// @return Pointer to the parameter if it exists, otherwise an
    /// empty pointer.
    isc::data::ConstElementPtr getConfiguredGlobal(std::string name) const;

636
    /// @brief Removes all configured global parameters.
637 638 639 640
    /// @note This removes the default values too so either
    /// @c applyDefaultsConfiguredGlobals and @c mergeGlobals,
    /// or @c isc::data::SimpleParser::setDefaults and
    /// @c extractConfiguredGlobals should be called after.
641 642
    void clearConfiguredGlobals();

643 644 645 646
    /// @brief Applies defaults to global parameters.
    /// @param defaults vector of (name, type, value) defaults to apply.
    void applyDefaultsConfiguredGlobals(const isc::data::SimpleDefaults& defaults);

647 648 649 650 651 652 653 654 655 656
    /// @brief Saves scalar elements from the global scope of a configuration
    void extractConfiguredGlobals(isc::data::ConstElementPtr config);

    /// @brief Adds a parameter to the collection configured globals
    /// @param name std::string name of the global to add
    /// @param value ElementPtr containing the value of the global
    void addConfiguredGlobal(const std::string& name, isc::data::ConstElementPtr value) {
        configured_globals_->set(name, value);
    }

657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680
    /// @brief Moves deprecated parameters from dhcp-ddns element to global element
    ///
    /// Given a server configuration element map, the following parameters are moved
    /// from dhcp-ddns to top-level (i.e. global) element if they do not already
    /// exist there:
    ///
    /// @code
    /// From dhcp-ddns:            To (global):
    /// ------------------------------------------------------
    /// override-no-update         ddns-override-no-update
    /// override-client-update     ddns-override-client-update
    /// replace-client-name        ddns-replace-client-name
    /// generated-prefix           ddns-generated-prefix
    /// qualifying-suffix          ddns-qualifying-suffix
    /// hostname-char-set          hostname-char-set
    /// hostname-char-replacement  hostname-char-replacement
    /// @endcode
    ///
    /// Note that the whether or not the deprecated parameters are added
    /// to the global element, they are always removed from the dhcp-ddns
    /// element.
    ///
    /// @param srv_elem server top level map to alter
    static void moveDdnsParams(isc::data::ElementPtr srv_elem);
681

Tomek Mrugalski's avatar
Tomek Mrugalski committed
682
    /// @brief Unparse a configuration object
683 684 685 686
    ///
    /// @return a pointer to unparsed configuration
    virtual isc::data::ElementPtr toElement() const;

687 688
private:

689 690 691
    /// @brief Merges the DHCPv4 configuration specified as a parameter into
    /// this configuration.
    ///
692 693
    /// This is called by @c merge() to handle v4 specifics, such as
    /// networks and subnets.
694 695 696
    ///
    /// @param other An object holding the configuration to be merged
    /// into this configuration.
697
    void merge4(SrvConfig& other);
698

699 700 701
    /// @brief Merges the DHCPv6 configuration specified as a parameter into
    /// this configuration.
    ///
702 703
    /// This is called by @c merge() to handle v4 specifics, such as
    /// networks and subnets.
704 705 706 707
    ///
    /// @param other An object holding the configuration to be merged
    /// into this configuration.
    void merge6(SrvConfig& other);
708

709
    /// @brief Merges the globals specified in the given configuration
710 711
    /// into this configuration.
    ///
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728
    /// Configurable global values may be specified either via JSON
    /// configuration (e.g. "echo-client-id":true) or as global parameters
    /// within a configuration back end.  Regardless of the source, these
    /// values once provided, are stored in @c SrvConfig::configured_globals_.
    /// Any such value that does not have an explicit specification should be
    /// considered "unspecified" at the global scope.
    ///
    /// This function adds the configured globals from the "other" config
    /// into this config's configured globals.  If a value already exists
    /// in this config, it will be overwritten with the value from the
    /// "other" config.
    ///
    /// It then iterates over this merged list of globals, setting
    /// any of the corresponding SrvConfig members that map to a
    /// a configurable parameter (e.g. c@ SrvConfig::echo_client_id_,
    /// @c SrvConfig::server_tag_).
    ///
729 730
    /// @param other An object holding the configuration to be merged
    /// into this configuration.
731
    void mergeGlobals(SrvConfig& other);
732

733 734 735 736 737 738 739
    /// @brief Sequence number identifying the configuration.
    uint32_t sequence_;

    /// @brief Interface configuration.
    ///
    /// Used to select interfaces on which the DHCP server will listen to
    /// queries.
740
    CfgIfacePtr cfg_iface_;
741

742
    /// @brief Pointer to option definitions configuration.
743 744 745
    ///
    /// This object holds the user-defined option definitions grouped
    /// by option space name.
746
    CfgOptionDefPtr cfg_option_def_;
747

748 749 750 751 752 753
    /// @brief Pointer to options (data) configuration.
    ///
    /// This object holds the instances of the options to be sent to clients
    /// connected to any subnet.
    CfgOptionPtr cfg_option_;

754 755 756
    /// @brief Pointer to subnets configuration for IPv4.
    CfgSubnets4Ptr cfg_subnets4_;

757
    /// @brief Pointer to subnets configuration for IPv6.
758 759
    CfgSubnets6Ptr cfg_subnets6_;

760 761 762 763 764 765
    /// @brief Pointer to IPv4 shared networks configuration.
    CfgSharedNetworks4Ptr cfg_shared_networks4_;

    /// @brief Pointer to IPv4 shared networks configuration.
    CfgSharedNetworks6Ptr cfg_shared_networks6_;

766 767 768 769 770 771
    /// @brief Pointer to the configuration for hosts reservation.
    ///
    /// This object holds a list of @c Host objects representing host
    /// reservations for different IPv4 and IPv6 subnets.
    CfgHostsPtr cfg_hosts_;

772
    /// @brief A list of configured MAC sources.
Tomek Mrugalski's avatar
Tomek Mrugalski committed
773
    CfgMACSource cfg_mac_source_;
774 775 776

    /// @brief Pointer to the configuration for RSOO-enabled options.
    ///
777 778
    /// This object holds a set of RSOO-enabled options. See
    /// RFC 6422 for the definition of the RSOO-enabled option.
779
    CfgRSOOPtr cfg_rsoo_;
780

781 782 783 784
    /// @brief Pointer to the configuration pertaining to processing of
    /// expired leases.
    CfgExpirationPtr cfg_expiration_;

785 786 787
    /// @brief Pointer to the configuration of the server identifier.
    CfgDUIDPtr cfg_duid_;

788 789 790 791
    /// @brief Pointer to the configuration of the lease and host database
    /// connection parameters.
    CfgDbAccessPtr cfg_db_access_;

792 793
    /// @brief Pointer to the general configuration for host reservations in
    /// DHCPv4.
794
    CfgHostOperationsPtr cfg_host_operations4_;
795 796 797

    /// @brief Pointer to the general configuration for host reservations in
    /// DHCPv6.
798
    CfgHostOperationsPtr cfg_host_operations6_;
799

800 801
    /// @brief Pointer to the control-socket information
    isc::data::ConstElementPtr control_socket_;
802

803 804
    /// @brief Pointer to the dhcp-queue-control information
    isc::data::ConstElementPtr dhcp_queue_control_;
805

806 807 808
    /// @brief Pointer to the dictionary of global client class definitions
    ClientClassDictionaryPtr class_dictionary_;

809 810 811
    /// @brief Configured hooks libraries.
    isc::hooks::HooksConfig hooks_config_;

812
    /// @brief Decline Period time
Tomek Mrugalski's avatar
Tomek Mrugalski committed
813 814 815
    ///
    /// This timer specifies decline probation period, the time after a declined
    /// lease is recovered back to available state. Expressed in seconds.
816
    uint32_t decline_timer_;
817

818 819 820
    /// @brief Indicates whether v4 server should send back client-id
    bool echo_v4_client_id_;

821 822 823 824
    /// @brief DHCP4o6 IPC port
    ///
    /// DHCPv4-over-DHCPv6 uses a UDP socket for interserver communication,
    /// this socket is bound and connected to this port and port + 1
825
    uint16_t dhcp4o6_port_;
826

827
    /// @brief Stores D2 client configuration
828
    D2ClientConfigPtr d2_client_config_;
829 830 831

    /// @brief Stores the global parameters specified via configuration
    isc::data::ElementPtr configured_globals_;
832 833 834

    /// @brief Pointer to the configuration consistency settings
    CfgConsistencyPtr cfg_consist_;
835 836
};

837
/// @name Pointers to the @c SrvConfig object.
838 839
///
//@{
840 841
/// @brief Non-const pointer to the @c SrvConfig.
typedef boost::shared_ptr<SrvConfig> SrvConfigPtr;
842

843 844
/// @brief Const pointer to the @c SrvConfig.
typedef boost::shared_ptr<const SrvConfig> ConstSrvConfigPtr;
845 846
//@}

847 848 849
} // namespace isc::dhcp
} // namespace isc

850
#endif // DHCPSRV_CONFIG_H