Kea 1.5.0
simple_parser4.cc
Go to the documentation of this file.
1// Copyright (C) 2016-2018 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>
11#include <boost/foreach.hpp>
12#include <iostream>
13
14using namespace isc::data;
15
16namespace isc {
17namespace dhcp {
32
38 { "record-types", Element::string, ""},
39 { "space", Element::string, "dhcp4"},
40 { "array", Element::boolean, "false"},
41 { "encapsulate", Element::string, "" }
42};
43
50 { "space", Element::string, "dhcp4"},
51 { "csv-format", Element::boolean, "true"},
52 { "always-send", Element::boolean, "false"}
53};
54
61 { "valid-lifetime", Element::integer, "7200" },
62 { "decline-probation-period", Element::integer, "86400" }, // 24h
63 { "dhcp4o6-port", Element::integer, "0" },
64 { "echo-client-id", Element::boolean, "true" },
65 { "match-client-id", Element::boolean, "true" },
66 { "authoritative", Element::boolean, "false" },
67 { "next-server", Element::string, "0.0.0.0" },
68 { "server-hostname", Element::string, "" },
69 { "boot-file-name", Element::string, "" },
70 { "server-tag", Element::string, "" },
71 { "reservation-mode", Element::string, "all" }
72};
73
82 { "id", Element::integer, "0" }, // 0 means autogenerate
83 { "interface", Element::string, "" },
84 { "client-class", Element::string, "" },
85 { "4o6-interface", Element::string, "" },
86 { "4o6-interface-id", Element::string, "" },
87 { "4o6-subnet", Element::string, "" },
88};
89
97 { "id", Element::integer, "0" }, // 0 means autogenerate
98 { "4o6-interface", Element::string, "" },
99 { "4o6-interface-id", Element::string, "" },
100 { "4o6-subnet", Element::string, "" },
101};
102
105 { "client-class", Element::string, "" },
106 { "interface", Element::string, "" }
107};
108
111 { "re-detect", Element::boolean, "true" }
112};
113
124 "boot-file-name",
125 "client-class",
126 "interface",
127 "match-client-id",
128 "authoritative",
129 "next-server",
130 "rebind-timer",
131 "relay",
132 "renew-timer",
133 "reservation-mode",
134 "server-hostname",
135 "valid-lifetime"
136};
137
140 { "enable-queue", Element::boolean, "false"},
141 { "queue-type", Element::string, "kea-ring4"},
142 { "capacity", Element::integer, "500"}
143};
144
145
147
151
153 size_t cnt = 0;
154
155 // Set global defaults first.
156 cnt = setDefaults(global, GLOBAL4_DEFAULTS);
157
158 // Now set option definition defaults for each specified option definition
159 ConstElementPtr option_defs = global->get("option-def");
160 if (option_defs) {
161 BOOST_FOREACH(ElementPtr option_def, option_defs->listValue()) {
163 }
164 }
165
166 // Set the defaults for option data
167 ConstElementPtr options = global->get("option-data");
168 if (options) {
169 cnt += setListDefaults(options, OPTION4_DEFAULTS);
170 }
171
172 // Now set the defaults for defined subnets
173 ConstElementPtr subnets = global->get("subnet4");
174 if (subnets) {
175 cnt += setListDefaults(subnets, SUBNET4_DEFAULTS);
176 }
177
178 // Set the defaults for interfaces config
179 ConstElementPtr ifaces_cfg = global->get("interfaces-config");
180 if (ifaces_cfg) {
181 ElementPtr mutable_cfg = boost::const_pointer_cast<Element>(ifaces_cfg);
182 cnt += setDefaults(mutable_cfg, IFACE4_DEFAULTS);
183 }
184
185 // Set defaults for shared networks
186 ConstElementPtr shared = global->get("shared-networks");
187 if (shared) {
188 BOOST_FOREACH(ElementPtr net, shared->listValue()) {
189
191
192 ConstElementPtr subs = net->get("subnet4");
193 if (subs) {
195 }
196 }
197 }
198
199 // Set the defaults for dhcp-queue-control. If the element isn't
200 // there we'll add it.
201 ConstElementPtr queue_control = global->get("dhcp-queue-control");
202 ElementPtr mutable_cfg;
203 if (queue_control) {
204 mutable_cfg = boost::const_pointer_cast<Element>(queue_control);
205 } else {
206 mutable_cfg = Element::createMap();
207 global->set("dhcp-queue-control", mutable_cfg);
208 }
209
210 cnt += setDefaults(mutable_cfg, DHCP_QUEUE_CONTROL4_DEFAULTS);
211
212 return (cnt);
213}
214
216 size_t cnt = 0;
217
218 // Now derive global parameters into subnets.
219 ConstElementPtr subnets = global->get("subnet4");
220 if (subnets) {
221 BOOST_FOREACH(ElementPtr single_subnet, subnets->listValue()) {
222 cnt += SimpleParser::deriveParams(global, single_subnet,
224 }
225 }
226
227 // Deriving parameters for shared networks is a bit more involved.
228 // First, the shared-network level derives from global, and then
229 // subnets within derive from it.
230 ConstElementPtr shared = global->get("shared-networks");
231 if (shared) {
232 BOOST_FOREACH(ElementPtr net, shared->listValue()) {
233 // First try to inherit the parameters from shared network,
234 // if defined there.
235 // Then try to inherit them from global.
236 cnt += SimpleParser::deriveParams(global, net,
238
239 // Now we need to go thrugh all the subnets in this net.
240 subnets = net->get("subnet4");
241 if (subnets) {
242 BOOST_FOREACH(ElementPtr single_subnet, subnets->listValue()) {
243 cnt += SimpleParser::deriveParams(net, single_subnet,
245 }
246 }
247
248 }
249 }
250
251 return (cnt);
252}
253
254};
255};
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition: data.cc:268
static size_t setListDefaults(isc::data::ConstElementPtr list, const SimpleDefaults &default_values)
Sets the default values for all entries in a list.
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.
static const isc::data::SimpleDefaults SUBNET4_DEFAULTS
This table defines default values for each IPv4 subnet.
static const isc::data::SimpleDefaults GLOBAL4_DEFAULTS
This table defines default global values for DHCPv4.
static const isc::data::ParamsList INHERIT_TO_SUBNET4
List of parameters that can be inherited to subnet4 scope.
static const isc::data::SimpleDefaults IFACE4_DEFAULTS
This table defines default values for interfaces for DHCPv4.
static const isc::data::SimpleDefaults SHARED_NETWORK4_DEFAULTS
This table defines default values for each IPv4 shared network.
static size_t deriveParameters(isc::data::ElementPtr global)
Derives (inherits) all parameters from global to more specific scopes.
static size_t setAllDefaults(isc::data::ElementPtr global)
Sets all defaults for DHCPv4 configuration.
static const isc::data::SimpleDefaults SHARED_SUBNET4_DEFAULTS
This table defines default values for each IPv4 subnet that is part of a shared network.
static const isc::data::SimpleDefaults OPTION4_DEFAULTS
This table defines default values for options in DHCPv4.
static const isc::data::SimpleDefaults DHCP_QUEUE_CONTROL4_DEFAULTS
This table defines default values for dhcp-queue-control in DHCPv4.
static const isc::data::SimpleDefaults OPTION4_DEF_DEFAULTS
This table defines default values for option definitions in DHCPv4.
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:23
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:22
Defines the logger used by the top-level component of kea-dhcp-ddns.