Kea: simple_parser6.cc Source File

| Kea 1.5.0

simple_parser6.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
9 #include <cc/data.h>
10 #include <dhcpsrv/parsers/simple_parser6.h>
11 #include <boost/foreach.hpp>
12
13 using namespace isc::data;
14
15 namespace isc {
16 namespace dhcp {
31
36 const SimpleDefaults SimpleParser6::OPTION6_DEF_DEFAULTS = {
37 { "record-types", Element::string, ""},
38 { "space", Element::string, "dhcp6"},
39 { "array", Element::boolean, "false"},
40 { "encapsulate", Element::string, "" }
41 };
42
48 const SimpleDefaults SimpleParser6::OPTION6_DEFAULTS = {
49 { "space", Element::string, "dhcp6"},
50 { "csv-format", Element::boolean, "true"},
51 { "always-send", Element::boolean, "false"}
52 };
53
59 const SimpleDefaults SimpleParser6::GLOBAL6_DEFAULTS = {
60 { "renew-timer", Element::integer, "900" },
61 { "rebind-timer", Element::integer, "1800" },
62 { "preferred-lifetime", Element::integer, "3600" },
63 { "valid-lifetime", Element::integer, "7200" },
64 { "decline-probation-period", Element::integer, "86400" }, // 24h
65 { "dhcp4o6-port", Element::integer, "0" },
66 { "server-tag", Element::string, "" },
67 { "reservation-mode", Element::string, "all" }
68 };
69
71 const SimpleDefaults SimpleParser6::SUBNET6_DEFAULTS = {
72 { "id", Element::integer, "0" }, // 0 means autogenerate
73 { "interface", Element::string, "" },
74 { "client-class", Element::string, "" },
75 { "rapid-commit", Element::boolean, "false" }, // rapid-commit disabled by default
76 { "interface-id", Element::string, "" }
77 };
78
80 const SimpleDefaults SimpleParser6::SHARED_SUBNET6_DEFAULTS = {
81 { "id", Element::integer, "0" } // 0 means autogenerate
82 };
83
85 const SimpleDefaults SimpleParser6::SHARED_NETWORK6_DEFAULTS = {
86 { "client-class", Element::string, "" },
87 { "interface", Element::string, "" },
88 { "interface-id", Element::string, "" },
89 { "rapid-commit", Element::boolean, "false" } // rapid-commit disabled by default
90 };
91
92
94 const SimpleDefaults SimpleParser6::IFACE6_DEFAULTS = {
95 { "re-detect", Element::boolean, "true" }
96 };
97
107 const ParamsList SimpleParser6::INHERIT_TO_SUBNET6 = {
108 "client-class",
109 "interface",
110 "interface-id",
111 "preferred-lifetime",
112 "rapid-commit",
113 "rebind-timer",
114 "relay",
115 "renew-timer",
116 "reservation-mode",
117 "valid-lifetime"
118 };
119
121 const SimpleDefaults SimpleParser6::DHCP_QUEUE_CONTROL6_DEFAULTS = {
122 { "enable-queue", Element::boolean, "false"},
123 { "queue-type", Element::string, "kea-ring6"},
124 { "capacity", Element::integer, "500"}
125 };
126
127
129
133
134 size_t SimpleParser6::setAllDefaults(isc::data::ElementPtr global) {
135 size_t cnt = 0;
136
137 // Set global defaults first.
138 cnt = setDefaults(global, GLOBAL6_DEFAULTS);
139
140 // Now set the defaults for each specified option definition
141 ConstElementPtr option_defs = global->get("option-def");
142 if (option_defs) {
143 BOOST_FOREACH(ElementPtr option_def, option_defs->listValue()) {
144 cnt += SimpleParser::setDefaults(option_def, OPTION6_DEF_DEFAULTS);
145 }
146 }
147
148 // Set the defaults for option data
149 ConstElementPtr options = global->get("option-data");
150 if (options) {
151 BOOST_FOREACH(ElementPtr single_option, options->listValue()) {
152 cnt += SimpleParser::setDefaults(single_option, OPTION6_DEFAULTS);
153 }
154 }
155
156 // Now set the defaults for defined subnets
157 ConstElementPtr subnets = global->get("subnet6");
158 if (subnets) {
159 cnt += setListDefaults(subnets, SUBNET6_DEFAULTS);
160 }
161
162 // Set the defaults for interfaces config
163 ConstElementPtr ifaces_cfg = global->get("interfaces-config");
164 if (ifaces_cfg) {
165 ElementPtr mutable_cfg = boost::const_pointer_cast<Element>(ifaces_cfg);
166 cnt += setDefaults(mutable_cfg, IFACE6_DEFAULTS);
167 }
168
169 // Set defaults for shared networks
170 ConstElementPtr shared = global->get("shared-networks");
171 if (shared) {
172 BOOST_FOREACH(ElementPtr net, shared->listValue()) {
173
174 cnt += setDefaults(net, SHARED_NETWORK6_DEFAULTS);
175
176 ConstElementPtr subs = net->get("subnet6");
177 if (subs) {
178 cnt += setListDefaults(subs, SHARED_SUBNET6_DEFAULTS);
179 }
180 }
181 }
182
183 // Set the defaults for dhcp-queue-control. If the element isn't there
184 // we'll add it.
185 ConstElementPtr queue_control = global->get("dhcp-queue-control");
186 ElementPtr mutable_cfg;
187 if (queue_control) {
188 mutable_cfg = boost::const_pointer_cast<Element>(queue_control);
189 } else {
190 mutable_cfg = Element::createMap();
191 global->set("dhcp-queue-control", mutable_cfg);
192 }
193
194 cnt += setDefaults(mutable_cfg, DHCP_QUEUE_CONTROL6_DEFAULTS);
195
196 return (cnt);
197 }
198
199 size_t SimpleParser6::deriveParameters(isc::data::ElementPtr global) {
200 size_t cnt = 0;
201 // Now derive global parameters into subnets.
202 ConstElementPtr subnets = global->get("subnet6");
203 if (subnets) {
204 BOOST_FOREACH(ElementPtr single_subnet, subnets->listValue()) {
205 cnt += SimpleParser::deriveParams(global, single_subnet,
206 INHERIT_TO_SUBNET6);
207 }
208 }
209
210 // Deriving parameters for shared networks is a bit more involved.
211 // First, the shared-network level derives from global, and then
212 // subnets within derive from it.
213 ConstElementPtr shared = global->get("shared-networks");
214 if (shared) {
215 BOOST_FOREACH(ElementPtr net, shared->listValue()) {
216 // First try to inherit the parameters from shared network,
217 // if defined there.
218 // Then try to inherit them from global.
219 cnt += SimpleParser::deriveParams(global, net,
220 INHERIT_TO_SUBNET6);
221
222 // Now we need to go thrugh all the subnets in this net.
223 subnets = net->get("subnet6");
224 if (subnets) {
225 BOOST_FOREACH(ElementPtr single_subnet, subnets->listValue()) {
226 cnt += SimpleParser::deriveParams(net, single_subnet,
227 INHERIT_TO_SUBNET6);
228 }
229 }
230 }
231 }
232
233 return (cnt);
234 }
235
236 };
237 };
simple_parser6.h
isc::data::SimpleDefaults
std::vector< SimpleDefault > SimpleDefaults
This specifies all default values in a given scope (e.g. a subnet)
Definition: lib/cc/simple_parser.h:31
isc::data
Definition: cfg_to_element.h:25
isc::data::Element::createMap
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition: data.cc:268
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::data::ParamsList
std::vector< std::string > ParamsList
This defines a list of all parameters that are derived (or inherited) between contexts.
Definition: lib/cc/simple_parser.h:35
isc::data::SimpleParser::deriveParams
static size_t deriveParams(isc::data::ConstElementPtr parent, isc::data::ElementPtr child, const ParamsList &params)
Derives (inherits) parameters from parent scope to a child.
Definition: lib/cc/simple_parser.cc:183
isc::data::Element::boolean
@ boolean
Definition: data.h:151
isc::data::Element::string
@ string
Definition: data.h:151
data.h
isc::data::Element::integer
@ integer
Definition: data.h:151
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
isc::data::ConstElementPtr
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:23
isc::data::SimpleParser::setDefaults
static size_t setDefaults(isc::data::ElementPtr scope, const SimpleDefaults &default_values)
Sets the default values.
Definition: lib/cc/simple_parser.cc:99