Kea: cb_ctl_dhcp.h Source File

| Kea 3.2.0-git

cb_ctl_dhcp.h
Go to the documentation of this file.
1// Copyright (C) 2019-2025 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 CB_CTL_DHCP_H
8#define CB_CTL_DHCP_H
9
10#include <cc/stamped_value.h>
11#include <process/cb_ctl_base.h>
12#include <dhcpsrv/srv_config.h>
13
14namespace isc {
15namespace dhcp {
16
26template<typename ConfigBackendMgrType>
27 class CBControlDHCP : public process::CBControlBase<ConfigBackendMgrType> {
28public:
29
31 CBControlDHCP()
32 : process::CBControlBase<ConfigBackendMgrType>() {
33 }
34
46 static bool translateName(std::string const& name, std::string& param_name,
47 std::string& sub_param_name) {
48 param_name = name;
49 sub_param_name = std::string();
50 auto pos = param_name.find('.');
51 if (pos != std::string::npos) {
52 sub_param_name = param_name.substr(pos + 1);
53 param_name = param_name.substr(0, pos);
54 return (true);
55 }
56 return (false);
57 }
58
59protected:
60
74 void translateAndAddGlobalsToConfig(SrvConfigPtr external_cfg,
75 data::StampedValueCollection& cb_globals,
76 data::SimpleKeywords global_lists) const {
77 auto const& index = cb_globals.get<data::StampedValueNameIndexTag>();
78 for (auto const& cb_global : index) {
79 if (cb_global->amNull()) {
80 continue;
81 }
82 data::ConstElementPtr value = cb_global->getElementValue();
83 // All ListElement parameters must be converted from StringElement
84 // (used by CB to store global list parameters).
85 data::ElementPtr mutable_value = boost::const_pointer_cast<data::Element>(value);
86 if (global_lists.count(cb_global->getName())) {
87 mutable_value = data::Element::fromJSON(value->stringValue());
88 }
89 data::ConstElementPtr global_value = boost::const_pointer_cast<data::Element>(mutable_value);
90 std::string param_name;
91 std::string sub_param_name;
92 if (translateName(cb_global->getName(), param_name, sub_param_name)) {
93 data::ElementPtr sub_param = boost::const_pointer_cast<data::Element>(external_cfg->getConfiguredGlobal(param_name));
94 if (!sub_param) {
95 sub_param = data::Element::createMap();
96 }
97 sub_param->set(sub_param_name, global_value);
98 external_cfg->addConfiguredGlobal(param_name, sub_param);
99 } else {
100 // Reuse name and value.
101 external_cfg->addConfiguredGlobal(param_name, global_value);
102 }
103 }
104 }
105};
106
107} // end of namespace isc::dhcp
108} // end of namespace isc
109
110#endif // CB_CTL_DHCP_H
cb_ctl_base.h
isc::data::Element::fromJSON
static ElementPtr fromJSON(const std::string &in, bool preproc=false)
These functions will parse the given string (JSON) representation of a compound element.
Definition data.cc:864
isc::data::Element::createMap
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition data.cc:354
isc::dhcp::CBControlDHCP::translateName
static bool translateName(std::string const &name, std::string &param_name, std::string &sub_param_name)
It translates the top level map parameters from flat naming format (e.g.
Definition cb_ctl_dhcp.h:46
isc::dhcp::CBControlDHCP::CBControlDHCP
CBControlDHCP()
Constructor.
Definition cb_ctl_dhcp.h:31
isc::dhcp::CBControlDHCP::translateAndAddGlobalsToConfig
void translateAndAddGlobalsToConfig(SrvConfigPtr external_cfg, data::StampedValueCollection &cb_globals, data::SimpleKeywords global_lists) const
It translates the top level map parameters from flat naming format (e.g.
Definition cb_ctl_dhcp.h:74
isc::process::CBControlBase
Base class for implementing server specific mechanisms to control the use of the Configuration Backen...
Definition cb_ctl_base.h:82
isc::process::CBControlBase::CBControlBase
CBControlBase()
Constructor.
Definition cb_ctl_base.h:99
isc::data::StampedValueCollection
boost::multi_index_container< StampedValuePtr, boost::multi_index::indexed_by< boost::multi_index::hashed_non_unique< boost::multi_index::tag< StampedValueNameIndexTag >, boost::multi_index::const_mem_fun< StampedValue, std::string, &StampedValue::getName > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< StampedValueModificationTimeIndexTag >, boost::multi_index::const_mem_fun< BaseStampedElement, boost::posix_time::ptime, &BaseStampedElement::getModificationTime > > > > StampedValueCollection
Multi index container for StampedValue.
Definition stamped_value.h:230
isc::data::ConstElementPtr
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:30
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition data.h:29
isc::data::SimpleKeywords
std::map< std::string, isc::data::Element::types > SimpleKeywords
This specifies all accepted keywords with their types.
Definition lib/cc/simple_parser.h:36
isc::dhcp
Definition dhcp4/client_handler.cc:20
isc::dhcp::SrvConfigPtr
boost::shared_ptr< SrvConfig > SrvConfigPtr
Non-const pointer to the SrvConfig.
Definition srv_config.h:1148
isc::process
Definition cb_ctl_base.h:22
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18
srv_config.h
stamped_value.h
isc::data::StampedValueNameIndexTag
Tag for the index for access by value name.
Definition stamped_value.h:201