Kea 2.7.5
bin/netconf/simple_parser.cc
Go to the documentation of this file.
1// Copyright (C) 2018-2024 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#include <config.h>
8
10#include <cc/data.h>
12#include <hooks/hooks_manager.h>
13#include <hooks/hooks_parser.h>
16
17using namespace isc::data;
18using namespace isc::asiolink;
19
20namespace isc {
21namespace netconf {
36
41 { "boot-update", Element::boolean, "true" },
42 { "subscribe-changes", Element::boolean, "true" },
43 { "validate-changes", Element::boolean, "true" }
44};
45
48 { "socket-type", Element::string, "stdout" },
49 { "socket-name", Element::string, "" },
50 { "socket-url" , Element::string, "http://127.0.0.1:8000/" }
51};
52
55 { "model", Element::string, "kea-dhcp4-server" }
56};
57
60 { "model", Element::string, "kea-dhcp6-server" }
61};
62
65 { "model", Element::string, "kea-dhcp-ddns" }
66};
67
70 { "model", Element::string, "kea-ctrl-agent" }
71};
72
80 "boot-update",
81 "subscribe-changes",
82 "validate-changes"
83};
84
86
90
92 size_t cnt = 0;
93
94 // Set global defaults first.
95 cnt = setDefaults(global, NETCONF_DEFAULTS);
96
97 ConstElementPtr servers = global->get("managed-servers");
98 if (servers) {
99 ElementPtr mutable_servers(copy(servers, 0));
100 for (auto const& it : mutable_servers->mapValue()) {
101 ElementPtr server(copy(it.second, 0));
102 cnt += setServerDefaults(it.first, server);
103 mutable_servers->set(it.first, server);
104 }
105 global->set("managed-servers", mutable_servers);
106 }
107
108 return (cnt);
109}
110
112 size_t cnt = 0;
113
114 // Now derive global parameters into managed-servers.
115 ConstElementPtr servers = global->get("managed-servers");
116 if (servers) {
117 ElementPtr mutable_servers(copy(servers, 0));
118 for (auto const& it : mutable_servers->mapValue()) {
119 ElementPtr mutable_server = copy(it.second, 0);
120 cnt += SimpleParser::deriveParams(global,
121 mutable_server,
123 mutable_servers->set(it.first, mutable_server);
124 }
125 global->set("managed-servers", mutable_servers);
126 }
127
128 return (cnt);
129}
130
131size_t
133 ElementPtr server) {
134 size_t cnt = 0;
135
136 if (name == "dhcp4") {
137 cnt += setDefaults(server, DHCP4_DEFAULTS);
138 } else if (name == "dhcp6") {
139 cnt += setDefaults(server, DHCP6_DEFAULTS);
140 } else if (name == "d2") {
141 cnt += setDefaults(server, D2_DEFAULTS);
142 } else if (name == "ca") {
143 cnt += setDefaults(server, CA_DEFAULTS);
144 }
145
146 ConstElementPtr ctrl_sock = server->get("control-socket");
147 if (!ctrl_sock) {
148 return (cnt);
149 }
150 ElementPtr mutable_ctrl_sock(copy(ctrl_sock, 0));
151 cnt += setDefaults(mutable_ctrl_sock, CTRL_SOCK_DEFAULTS);
152 server->set("control-socket", mutable_ctrl_sock);
153
154 return (cnt);
155}
156
157void
159 const ElementPtr& config,
160 bool check_only) {
161
162 // User context can be done at anytime.
163 ConstElementPtr user_context = config->get("user-context");
164 if (user_context) {
165 ctx->setContext(user_context);
166 }
167
168 // get managed servers.
169 ConstElementPtr servers = config->get("managed-servers");
170 if (servers) {
171 for (auto const& it : servers->mapValue()) {
172 ServerConfigParser server_parser;
173 CfgServerPtr server = server_parser.parse(it.second);
174 ctx->getCfgServersMap()->insert(make_pair(it.first, server));
175 }
176 }
177
178 // Finally, let's get the hook libs!
179 using namespace isc::hooks;
180 HooksConfig& libraries = ctx->getHooksConfig();
181 ConstElementPtr hooks = config->get("hooks-libraries");
182 if (hooks) {
183 HooksLibrariesParser hooks_parser;
184 hooks_parser.parse(libraries, hooks);
185 libraries.verifyLibraries(hooks->getPosition(), false);
186 }
187
188 if (!check_only) {
189 // This occurs last as if it succeeds, there is no easy way
190 // revert it. As a result, the failure to commit a subsequent
191 // change causes problems when trying to roll back.
192 HooksManager::prepareUnloadLibraries();
193 static_cast<void>(HooksManager::unloadLibraries());
194 IOServiceMgr::instance().clearIOServices();
195 libraries.loadLibraries(false);
196 }
197}
198
199} // namespace netconf
200} // namespace isc
static size_t deriveParams(isc::data::ConstElementPtr parent, isc::data::ElementPtr child, const ParamsList &params)
Derives (inherits) parameters from parent scope to a child.
static size_t setDefaults(isc::data::ElementPtr scope, const SimpleDefaults &default_values)
Sets the default values.
Wrapper class that holds hooks libraries configuration.
const isc::hooks::HookLibsCollection & get() const
Provides access to the configured hooks libraries.
Parser for hooks library list.
void parse(HooksConfig &libraries, isc::data::ConstElementPtr value)
Parses parameters value.
static const isc::data::SimpleDefaults NETCONF_DEFAULTS
This table defines default values for global options.
static const isc::data::SimpleDefaults DHCP6_DEFAULTS
Supplies defaults for dhcp6 managed server.
static const isc::data::SimpleDefaults DHCP4_DEFAULTS
Supplies defaults for dhcp4 managed server.
static size_t setAllDefaults(const isc::data::ElementPtr &global)
Sets all defaults for Netconf configuration.
static size_t deriveParameters(isc::data::ElementPtr global)
Derives (inherits) all parameters from global to more specific scopes.
static const isc::data::SimpleDefaults CA_DEFAULTS
Supplies defaults for ca managed server.
static const isc::data::ParamsList INHERIT_TO_SERVERS
List of parameters that can be inherited to managed-servers scope.
void parse(const NetconfConfigPtr &ctx, const isc::data::ElementPtr &config, bool check_only)
Parses the netconf configuration.
static const isc::data::SimpleDefaults CTRL_SOCK_DEFAULTS
Supplies defaults for control-socket elements.
static const isc::data::SimpleDefaults D2_DEFAULTS
Supplies defaults for d2 managed server.
static size_t setServerDefaults(const std::string name, isc::data::ElementPtr server)
Adds default values to a Managed server entry.
CfgServerPtr parse(data::ConstElementPtr server_config)
Performs the actual parsing of the given value from the "managed-servers" map.
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
Definition data.cc:1420
std::vector< std::string > ParamsList
This defines a list of all parameters that are derived (or inherited) between contexts.
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
std::vector< SimpleDefault > SimpleDefaults
This specifies all default values in a given scope (e.g. a subnet).
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
boost::shared_ptr< NetconfConfig > NetconfConfigPtr
Pointer to a configuration context.
std::shared_ptr< CfgServer > CfgServerPtr
Defines a pointer for CfgServer instances.
Defines the logger used by the top-level component of kea-lfc.
A collection of classes for housing and parsing the application configuration necessary for the Netco...