14 const string DHCP4_SPACE =
"dhcp4";
15 const string DHCP6_SPACE =
"dhcp6";
21 AdaptorConfig::AdaptorConfig() {
24 AdaptorConfig::~AdaptorConfig() {
31 if (!subnets || subnets->empty()) {
42 if (!collectID(subnet, set)) {
52 const string& subsel) {
53 if (!networks || networks->empty()) {
63 for (
size_t i = 0; i < networks->size(); ++i) {
67 if (!subnets->empty()) {
70 if (!subnetsCollectID(subnets, set)) {
75 network->remove(subsel);
85 if (!subnets || subnets->empty()) {
90 for (
size_t i = 0; i < subnets->size(); ++i) {
92 assignID(subnet, set, next);
99 const string& subsel) {
100 if (!networks || networks->empty()) {
107 if (!subnets || subnets->empty()) {
111 for (
size_t i = 0; i < subnets->size(); ++i) {
113 assignID(subnet, set, next);
120 if (!pools || pools->empty()) {
127 for (
size_t i = 0; i < pools->size(); ++i) {
129 AdaptorPool::canonizePool(pool);
135 if (!subnets || subnets->empty()) {
141 sanitizePools(subnet->get(
"pools"));
147 const string& subsel) {
148 if (!networks || networks->empty()) {
154 sanitizePoolsInSubnets(network->get(subsel));
162 if (!defs || defs->empty()) {
169 for (
size_t i = 0; i < defs->size(); ++i) {
173 setSpace(def, space);
182 if (!options || options->empty()) {
189 for (
size_t i = 0; i < options->size(); ++i) {
191 setSpace(option, space);
192 setCode(option, codes);
200 if (!classes || classes->empty()) {
206 for (
size_t i = 0; i < classes->size(); ++i) {
209 if (space == DHCP4_SPACE) {
212 if (!options->empty()) {
214 sanitizeOptionDefList(options, space, codes);
217 cclass->remove(
"option-def");
225 if (!options->empty()) {
227 sanitizeOptionDataList(options, space, codes);
230 cclass->remove(
"option-data");
239 if (!pools || pools->empty()) {
244 for (
size_t i = 0; i < pools->size(); ++i) {
248 if (!options->empty()) {
249 sanitizeOptionDataList(options, space, codes);
251 pool->remove(
"option-data");
260 if (!hosts || hosts->empty()) {
265 for (
size_t i = 0; i < hosts->size(); ++i) {
269 if (!options->empty()) {
270 sanitizeOptionDataList(options, space, codes);
272 host->remove(
"option-data");
282 if (!subnets || subnets->empty()) {
287 for (
size_t i = 0; i < subnets->size(); ++i) {
293 if (!options->empty()) {
294 sanitizeOptionDataList(options, space, codes);
296 subnet->remove(
"option-data");
303 if (!pools->empty()) {
304 sanitizeOptionPools(pools, space, codes);
306 subnet->remove(
"pools");
311 if (space == DHCP6_SPACE) {
314 if (!pools->empty()) {
315 sanitizeOptionPools(pools, space, codes);
317 subnet->remove(
"pd-pools");
325 if (!hosts->empty()) {
326 sanitizeOptionHosts(hosts, space, codes);
328 subnet->remove(
"reservations");
338 if (!networks || networks->empty()) {
344 for (
size_t i = 0; i < networks->size(); ++i) {
345 ElementPtr network = networks->getNonConst(i);
350 if (!options->empty()) {
351 sanitizeOptionDataList(options, space, codes);
353 network->remove(
"option-data");
356 string subnet =
"subnet";
357 if (space == DHCP4_SPACE) {
366 if (!subnets->empty()) {
367 sanitizeOptionSubnets(subnets, space, codes);
369 network->remove(subnet);
377 if (!pools || pools->empty()) {
382 for (
size_t i = 0; i < pools->size(); ++i) {
385 if (requires && requires->empty()) {
386 pool->remove(
"require-client-classes");
393 if (!subnets || subnets->empty()) {
398 for (
size_t i = 0; i < subnets->size(); ++i) {
400 sanitizeRequireClassesPools(subnet->get(
"pools"));
401 sanitizeRequireClassesPools(subnet->get(
"pd-pools"));
403 if (requires && requires->empty()) {
404 subnet->remove(
"require-client-classes");
411 const string& subsel) {
412 if (!networks || networks->empty()) {
417 for (
size_t i = 0; i < networks->size(); ++i) {
418 ElementPtr network = networks->getNonConst(i);
419 sanitizeRequireClassesSubnets(network->get(subsel));
421 if (requires && requires->empty()) {
422 network->remove(
"require-client-classes");
430 if (!hosts || hosts->empty()) {
435 for (
size_t i = 0; i < hosts->size(); ++i) {
437 quoteIdentifier(host);
444 if (!subnets || subnets->empty()) {
450 sanitizeHostList(subnet->get(
"reservations"));
456 const string& space) {
457 if (!networks || networks->empty()) {
463 if (space == DHCP4_SPACE) {
464 sanitizeHostSubnets(network->get(
"subnet4"));
466 sanitizeHostSubnets(network->get(
"subnet6"));
473 if (!subnets || subnets->empty()) {
478 for (
size_t i = 0; i < subnets->size(); ++i) {
486 const string& subsel) {
487 if (!networks || networks->empty()) {
492 for (
size_t i = 0; i < networks->size(); ++i) {
493 ElementPtr network = networks->getNonConst(i);
494 updateRelay(network);
495 sanitizeRelaySubnets(network->get(subsel));
507 ElementPtr mutable_dhcp = boost::const_pointer_cast<Element>(dhcp);
508 mutable_dhcp->remove(
"hosts-database");
510 list->add(boost::const_pointer_cast<Element>(database));
511 mutable_dhcp->set(
"hosts-databases", list);
517 if (!options || !options->empty()) {
521 ElementPtr mutable_dhcp = boost::const_pointer_cast<Element>(dhcp);
522 mutable_dhcp->remove(
"relay-supplied-options");
526 AdaptorConfig::preProcess(
ElementPtr dhcp,
const string& subsel,
527 const string& space) {
531 bool have_ids =
true;
535 if (!subnets->empty()) {
536 if (!subnetsCollectID(subnets, set)) {
540 dhcp->remove(subsel);
545 if (!networks->empty()) {
546 if (!sharedNetworksCollectID(networks, set, subsel)) {
550 dhcp->remove(
"shared-networks");
556 subnetsAssignID(subnets, set, next);
557 sharedNetworksAssignID(networks, set, next, subsel);
561 initCodes(codes, space);;
564 if (!defs->empty()) {
565 sanitizeOptionDefList(defs, space, codes);
567 dhcp->remove(
"option-def");
572 if (!options->empty()) {
573 sanitizeOptionDataList(options, space, codes);
575 dhcp->remove(
"option-data");
580 if (!classes->empty()) {
581 sanitizeOptionClasses(classes, space, codes);
583 dhcp->remove(
"client-classes");
588 if (!hosts->empty()) {
589 sanitizeHostList(hosts);
590 sanitizeOptionHosts(hosts, space, codes);
592 dhcp->remove(
"reservations");
595 sanitizeOptionSubnets(subnets, space, codes);
596 sanitizeOptionSharedNetworks(networks, space, codes);
598 sanitizePoolsInSubnets(subnets);
599 sanitizePoolsInSharedNetworks(networks, subsel);
601 sanitizeHostSubnets(subnets);
602 SanitizeHostsInSharedNetworks(networks, space);
604 sanitizeRelaySubnets(subnets);
605 sanitizeRelayInSharedNetworks(networks, subsel);
607 sanitizeRequireClassesSubnets(subnets);
608 requireClassesSharedNetworks(networks, subsel);
610 sanitizeDatabase(dhcp);
612 if (space == DHCP6_SPACE) {
613 sanitizeRelaySuppliedOptions(dhcp);
622 if (config->getType() != Element::map) {
629 ElementPtr mutable_dhcp = boost::const_pointer_cast<Element>(dhcp);
630 preProcess(mutable_dhcp,
"subnet4", DHCP4_SPACE);
638 if (config->getType() != Element::map) {
645 ElementPtr mutable_dhcp = boost::const_pointer_cast<Element>(dhcp);
646 preProcess(mutable_dhcp,
"subnet6", DHCP6_SPACE);
std::map< std::string, uint16_t > OptionCodes
Map for DHCP option definitions handling code and an index built from space and name.
boost::shared_ptr< Element > ElementPtr
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
boost::shared_ptr< const Element > ConstElementPtr
Defines the logger used by the top-level component of kea-dhcp-ddns.
std::set< isc::dhcp::SubnetID > SubnetIDSet
Set of SubnetIDs.
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)