Kea 3.1.1
cfg_option.cc
Go to the documentation of this file.
1// Copyright (C) 2014-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#include <config.h>
8
9#include <dhcp/libdhcp++.h>
10#include <dhcpsrv/cfg_option.h>
11#include <dhcp/dhcp6.h>
12#include <dhcp/option_space.h>
13#include <util/encode/encode.h>
14#include <boost/algorithm/string/split.hpp>
15#include <boost/algorithm/string/classification.hpp>
16#include <boost/make_shared.hpp>
17#include <string>
18#include <sstream>
19#include <vector>
20
21using namespace isc::data;
22
23namespace isc {
24namespace dhcp {
25
27OptionDescriptor::create(const OptionPtr& opt, bool persist, bool cancel,
28 const std::string& formatted_value,
29 ConstElementPtr user_context) {
30 return (boost::make_shared<OptionDescriptor>(opt, persist, cancel,
31 formatted_value,
32 user_context));
33}
34
36OptionDescriptor::create(bool persist, bool cancel) {
37 return (boost::make_shared<OptionDescriptor>(persist, cancel));
38}
39
42 return (boost::make_shared<OptionDescriptor>(desc));
43}
44
45bool
47 return ((persistent_ == other.persistent_) &&
48 (cancelled_ == other.cancelled_) &&
50 (space_name_ == other.space_name_) &&
51 ((option_ && other.option_) &&
52 option_->equals(other.option_)) &&
54}
55
56void
57OptionDescriptor::addClientClass(const std::string& class_name) {
58 std::string trimmed = util::str::trim(class_name);
59 if (!trimmed.empty()) {
60 client_classes_.insert(ClientClass(trimmed));
61 }
62}
63
68
69bool
71 if (client_classes_.empty()) {
72 return (true);
73 }
74
75 return (client_classes_.intersects(cclasses));
76}
77
79 : encapsulated_(false) {
80}
81
82bool
84 return (options_.empty() && vendor_options_.empty());
85}
86
87bool
88CfgOption::equals(const CfgOption& other) const {
89 return (options_.equals(other.options_) &&
90 vendor_options_.equals(other.vendor_options_));
91}
92
93void
95 const bool persistent,
96 const bool cancelled,
97 const std::string& option_space,
98 const uint64_t id) {
99 OptionDescriptor desc(option, persistent, cancelled);
100 if (id > 0) {
101 desc.setId(id);
102 }
103 add(desc, option_space);
104}
105
106void
107CfgOption::add(const OptionDescriptor& desc, const std::string& option_space) {
108 if (!desc.option_) {
109 isc_throw(isc::BadValue, "option being configured must not be NULL");
110
111 } else if (!OptionSpace::validateName(option_space)) {
112 isc_throw(isc::BadValue, "invalid option space name: '"
113 << option_space << "'");
114 }
115
116 const uint32_t vendor_id = LibDHCP::optionSpaceToVendorId(option_space);
117 if (vendor_id) {
118 vendor_options_.addItem(desc, vendor_id);
119 } else {
120 options_.addItem(desc, option_space);
121 }
122}
123
124void
125CfgOption::replace(const OptionDescriptor& desc, const std::string& option_space) {
126 if (!desc.option_) {
127 isc_throw(isc::BadValue, "option being replaced must not be NULL");
128 }
129
130 // Check for presence of options.
131 OptionContainerPtr options = getAll(option_space);
132 if (!options) {
133 isc_throw(isc::BadValue, "option space " << option_space
134 << " does not exist");
135 }
136
137 // Find the option we want to replace.
138 auto& idx6 = options->get<6>();
139 auto const& od_itr = idx6.find(boost::make_tuple(desc.option_->getType(), desc.client_classes_));
140 if (od_itr == idx6.end()) {
141 isc_throw(isc::BadValue, "cannot replace option: "
142 << option_space << ":" << desc.option_->getType()
143 << ", client-classes: " << desc.client_classes_.toText()
144 << ", it does not exist");
145 }
146
147 idx6.replace(od_itr, desc);
148}
149
150std::list<std::string>
152 std::list<uint32_t> ids = getVendorIds();
153 std::list<std::string> names;
154 for (auto const& id : ids) {
155 std::ostringstream s;
156 // Vendor space name is constructed as "vendor-XYZ" where XYZ is an
157 // uint32_t value, without leading zeros.
158 s << "vendor-" << id;
159 names.push_back(s.str());
160 }
161 return (names);
162}
163
164void
166 // First we merge our options into other.
167 // This adds my options that are not
168 // in other, to other (i.e we skip over
169 // duplicates).
170 mergeTo(other);
171
172 // Create option instances based on the given definitions.
173 other.createOptions(cfg_def);
174
175 // Next we copy "other" on top of ourself.
176 other.copyTo(*this);
177
178 // If we copied new options we may need to populate the
179 // sub-options into the upper level options. The server
180 // expects that the top-level options have suitable
181 // suboptions appended.
182 encapsulate();
183}
184
185void
187 // Iterate over all the option descriptors in
188 // all the spaces and instantiate the options
189 // based on the given definitions.
190 for (auto const& space : getOptionSpaceNames()) {
191 for (auto opt_desc : *(getAll(space))) {
192 if (createDescriptorOption(cfg_def, space, opt_desc)) {
193 // Option was recreated, let's replace the descriptor.
194 replace(opt_desc, space);
195 }
196 }
197 }
198}
199
200bool
201CfgOption::createDescriptorOption(CfgOptionDefPtr cfg_def, const std::string& space,
202 OptionDescriptor& opt_desc) {
203 if (!opt_desc.option_) {
205 "validateCreateOption: descriptor has no option instance");
206 }
207
208 Option::Universe universe = opt_desc.option_->getUniverse();
209 uint16_t code = opt_desc.option_->getType();
210
211 // Find the option's defintion, if it has one.
212 // First, check for a standard definition.
214
215 // If there is no standard definition but the option is vendor specific,
216 // we should search the definition within the vendor option space.
217 if (!def && (space != DHCP4_OPTION_SPACE) && (space != DHCP6_OPTION_SPACE)) {
218 uint32_t vendor_id = LibDHCP::optionSpaceToVendorId(space);
219 if (vendor_id > 0) {
220 def = LibDHCP::getVendorOptionDef(universe, vendor_id, code);
221 }
222 }
223
224 // Still haven't found the definition, so look for custom
225 // definition in the given set of configured definitions
226 if (!def) {
227 def = cfg_def->get(space, code);
228 }
229
230 // Finish with a last resort option definition.
231 if (!def) {
232 def = LibDHCP::getLastResortOptionDef(space, code);
233 }
234
235 std::string& formatted_value = opt_desc.formatted_value_;
236 if (!def) {
237 if (!formatted_value.empty()) {
238 isc_throw(InvalidOperation, "option: " << space << "." << code
239 << " has a formatted value: '" << formatted_value
240 << "' but no option definition");
241 }
242
243 // If there's no definition and no formatted string, we'll
244 // settle for the generic option already in the descriptor.
245 // Indicate no-change by returning false.
246 return (false);
247 }
248
249 try {
250 // Definition found. Let's replace the generic option in
251 // the descriptor with one created based on definition's factory.
252 if (formatted_value.empty()) {
253 // No formatted value, use data stored in the generic option.
254 opt_desc.option_ = def->optionFactory(universe, code, opt_desc.option_->getData());
255 } else {
256 // Spit the value specified in comma separated values format.
257 std::vector<std::string> split_vec;
258 boost::split(split_vec, formatted_value, boost::is_any_of(","));
259 opt_desc.option_ = def->optionFactory(universe, code, split_vec);
260 }
261 } catch (const std::exception& ex) {
262 isc_throw(InvalidOperation, "could not create option: " << space << "." << code
263 << " from data specified, reason: " << ex.what());
264 }
265
266 // Indicate we replaced the definition.
267 return (true);
268}
269
270void
272 // Merge non-vendor options.
273 mergeInternal(options_, other.options_);
274 // Merge vendor options.
275 mergeInternal(vendor_options_, other.vendor_options_);
276}
277
278void
280 // Remove any existing data in the destination.
281 other.options_.clearItems();
282 other.vendor_options_.clearItems();
283 mergeTo(other);
284 other.encapsulated_ = isEncapsulated();
285}
286
287void
289 // Append sub-options to the top level "dhcp4" option space.
290 encapsulateInternal(DHCP4_OPTION_SPACE);
291 // Append sub-options to the top level "dhcp6" option space.
292 encapsulateInternal(DHCP6_OPTION_SPACE);
293 encapsulated_ = true;
294}
295
296void
297CfgOption::encapsulateInternal(const std::string& option_space) {
298 // Get all options for the particular option space.
299 OptionContainerPtr options = getAll(option_space);
300 // For each option in the option space we will append sub-options
301 // from the option spaces they encapsulate.
302 for (auto const& opt : *options) {
303 encapsulateInternal(opt.option_);
304 }
305
306 for (auto const& vendor : getVendorIds()) {
307 OptionContainerPtr vendor_options = getAll(vendor);
308 // For each option in the option space we will append sub-options
309 // from the option spaces they encapsulate.
310 for (auto const& opt : *vendor_options) {
311 encapsulateInternal(opt.option_);
312 }
313 }
314}
315
316void
317CfgOption::encapsulateInternal(const OptionPtr& option) {
318 // Get encapsulated option space for the option.
319 const std::string& encap_space = option->getEncapsulatedSpace();
320 // Empty value means that no option space is encapsulated.
321 if (!encap_space.empty()) {
322 if (encap_space == DHCP4_OPTION_SPACE || encap_space == DHCP6_OPTION_SPACE) {
323 return;
324 }
325 // Retrieve all options from the encapsulated option space.
326 OptionContainerPtr encap_options = getAll(encap_space);
327 for (auto const& encap_opt : *encap_options) {
328 if (option.get() == encap_opt.option_.get()) {
329 // Avoid recursion by not adding options to themselves.
330 continue;
331 }
332
333 // Add sub-option if there isn't one added already.
334 if (!option->getOption(encap_opt.option_->getType())) {
335 option->addOption(encap_opt.option_);
336 }
337 encapsulateInternal(encap_opt.option_);
338 }
339 }
340}
341
342template <typename Selector>
343void
344CfgOption::mergeInternal(const OptionSpaceContainer<OptionContainer,
345 OptionDescriptor, Selector>& src_container,
347 OptionDescriptor, Selector>& dest_container) const {
348 // Get all option spaces used in source container.
349 std::list<Selector> selectors = src_container.getOptionSpaceNames();
350
351 // For each space in the source container retrieve the actual options and
352 // match them with the options held in the destination container under
353 // the same space.
354 for (auto const& it : selectors) {
355 // Get all options in the destination container for the particular
356 // option space.
357 OptionContainerPtr dest_all = dest_container.getItems(it);
358 OptionContainerPtr src_all = src_container.getItems(it);
359 // For each option under this option space check if there is a
360 // corresponding option in the destination container. If not,
361 // add one.
362 for (auto const& src_opt : *src_all) {
363 const OptionContainerTypeIndex& idx = dest_all->get<1>();
364 const OptionContainerTypeRange& range =
365 idx.equal_range(src_opt.option_->getType());
366 // If there is no such option in the destination container,
367 // add one.
368 if (std::distance(range.first, range.second) == 0) {
369 dest_container.addItem(OptionDescriptor(src_opt), it);
370 }
371 }
372 }
373}
374
376CfgOption::getAll(const std::string& option_space) const {
377 return (options_.getItems(option_space));
378}
379
381CfgOption::getAll(const uint32_t vendor_id) const {
382 return (vendor_options_.getItems(vendor_id));
383}
384
386CfgOption::getAllCombined(const std::string& option_space) const {
387 auto vendor_id = LibDHCP::optionSpaceToVendorId(option_space);
388 if (vendor_id > 0) {
389 return (getAll(vendor_id));
390 }
391 return (getAll(option_space));
392}
393
394size_t
395CfgOption::del(const std::string& option_space, const uint16_t option_code) {
396 // Check for presence of options.
397 OptionContainerPtr options = getAll(option_space);
398 if (!options || options->empty()) {
399 // There are no options, so there is nothing to do.
400 return (0);
401 }
402
403 // If this is not top level option we may also need to delete the
404 // option instance from options encapsulating the particular option
405 // space.
406 if ((option_space != DHCP4_OPTION_SPACE) &&
407 (option_space != DHCP6_OPTION_SPACE)) {
408 // For each option space name iterate over the existing options.
409 auto option_space_names = getOptionSpaceNames();
410 for (auto const& option_space_from_list : option_space_names) {
411 // Get all options within the particular option space.
412 auto const& options_in_space = getAll(option_space_from_list);
413 for (auto const& option_it : *options_in_space) {
414
415 // Check if the option encapsulates our option space and
416 // it does, try to delete our option.
417 if (option_it.option_ &&
418 (option_it.option_->getEncapsulatedSpace() == option_space)) {
419 option_it.option_->delOption(option_code);
420 }
421 }
422 }
423 }
424
425 auto& idx = options->get<1>();
426 return (idx.erase(option_code));
427}
428
429size_t
430CfgOption::del(const std::string& option_space, const uint16_t option_code,
431 const ClientClasses& client_classes) {
432 // Check for presence of options.
433 OptionContainerPtr options = getAll(option_space);
434 if (!options || options->empty()) {
435 // There are no options, so there is nothing to do.
436 return (0);
437 }
438
439 // If this is not top level option we may also need to delete the
440 // option instance from options encapsulating the particular option
441 // space.
442 if ((option_space != DHCP4_OPTION_SPACE) &&
443 (option_space != DHCP6_OPTION_SPACE)) {
444 // For each option space name iterate over the existing options.
445 auto option_space_names = getOptionSpaceNames();
446 for (auto const& option_space_from_list : option_space_names) {
447 // Get all options within the particular option space.
448 auto const& options_in_space = getAll(option_space_from_list);
449 for (auto const& option_it : *options_in_space) {
450
451 // Check if the option encapsulates our option space and
452 // if it does, try to delete our option.
453 if (option_it.option_ &&
454 (option_it.option_->getEncapsulatedSpace() == option_space)) {
455 option_it.option_->delOption(option_code);
456 }
457 }
458 }
459 }
460
461 auto& idx6 = options->get<6>();
462 auto range = idx6.equal_range(boost::make_tuple(option_code, client_classes));
463 auto count = std::distance(range.first, range.second);
464 if (count) {
465 idx6.erase(range.first, range.second);
466 }
467
468 return (count);
469}
470
471size_t
472CfgOption::del(const uint32_t vendor_id, const uint16_t option_code) {
473 // Check for presence of options.
474 OptionContainerPtr vendor_options = getAll(vendor_id);
475 if (!vendor_options || vendor_options->empty()) {
476 // There are no options, so there is nothing to do.
477 return (0);
478 }
479
480 auto& idx = vendor_options->get<1>();
481 return (idx.erase(option_code));
482}
483
484size_t
485CfgOption::del(const uint64_t id) {
486 // Hierarchical nature of the options configuration requires that
487 // we go over all options and decapsulate them before removing
488 // any of them. Let's walk over the existing option spaces.
489 for (auto const& space_name : getOptionSpaceNames()) {
490 // Get all options for the option space.
491 auto const& options = getAll(space_name);
492 for (auto const& option_it : *options) {
493 if (!option_it.option_) {
494 continue;
495 }
496
497 // For each option within the option space we need to dereference
498 // any existing sub options.
499 auto sub_options = option_it.option_->getOptions();
500 for (auto const& sub : sub_options) {
501 // Dereference sub option.
502 option_it.option_->delOption(sub.second->getType());
503 }
504 }
505 }
506
507 // Now that we got rid of dependencies between the instances of the options
508 // we can delete all options having a specified id.
509 size_t num_deleted = options_.deleteItems(id) + vendor_options_.deleteItems(id);
510
511 // Let's encapsulate those options that remain in the configuration.
512 encapsulate();
513
514 // Return the number of deleted options.
515 return (num_deleted);
516}
517
520 return (toElementWithMetadata(false));
521}
522
525 return (toElementWithMetadata(false, cfg_option_def));
526}
527
529CfgOption::toElementWithMetadata(const bool include_metadata,
530 CfgOptionDefPtr cfg_option_def) const {
531 // option-data value is a list of maps
533 // Iterate first on options using space names
534 const std::list<std::string>& names = options_.getOptionSpaceNames();
535 for (auto const& name : names) {
536 OptionContainerPtr opts = getAll(name);
537 for (auto const& opt : *opts) {
538 // Get and fill the map for this option
540 // Set user context
541 opt.contextToElement(map);
542 // Set space from parent iterator
543 map->set("space", Element::create(name));
544 // Set the code
545 uint16_t code = opt.option_->getType();
546 map->set("code", Element::create(code));
547 // Set the name (always for standard options else when asked for)
549 if (cfg_option_def) {
550 def = cfg_option_def->get(name, code);
551 }
552 if (!def) {
553 def = LibDHCP::getOptionDef(name, code);
554 }
555 if (!def) {
556 def = LibDHCP::getRuntimeOptionDef(name, code);
557 }
558 if (!def) {
559 def = LibDHCP::getLastResortOptionDef(name, code);
560 }
561 if (def) {
562 map->set("name", Element::create(def->getName()));
563 }
564 // Set the data item
565 if (!opt.formatted_value_.empty()) {
566 map->set("csv-format", Element::create(true));
567 if (def && def->getType() == OPT_EMPTY_TYPE) {
568 map->set("data", Element::create(""));
569 } else {
570 map->set("data", Element::create(opt.formatted_value_));
571 }
572 } else {
573 std::vector<uint8_t> bin = opt.option_->toBinary();
574 if (!opt.cancelled_ || !bin.empty()) {
575 map->set("csv-format", Element::create(false));
576 if (def && def->getType() == OPT_EMPTY_TYPE) {
577 map->set("data", Element::create(""));
578 } else {
579 std::string repr = util::encode::encodeHex(bin);
580 map->set("data", Element::create(repr));
581 }
582 }
583 }
584 // Set the persistency flag
585 map->set("always-send", Element::create(opt.persistent_));
586 // Set the cancelled flag.
587 map->set("never-send", Element::create(opt.cancelled_));
588 // Include metadata if requested.
589 if (include_metadata) {
590 map->set("metadata", opt.getMetadata());
591 }
592
593 // Include client-classes if not empty.
594 if (!opt.client_classes_.empty()) {
595 map->set("client-classes", opt.client_classes_.toElement());
596 }
597
598 // Push on the list
599 result->add(map);
600 }
601 }
602 // Iterate first on vendor_options using vendor ids
603 const std::list<uint32_t>& ids = vendor_options_.getOptionSpaceNames();
604 for (auto const& id : ids) {
605 OptionContainerPtr opts = getAll(id);
606 for (auto const& opt : *opts) {
607 // Get and fill the map for this option
609 // Set user context
610 opt.contextToElement(map);
611 // Set space from parent iterator
612 std::ostringstream oss;
613 oss << "vendor-" << id;
614 map->set("space", Element::create(oss.str()));
615 // Set the code
616 uint16_t code = opt.option_->getType();
617 map->set("code", Element::create(code));
618 // Set the name
619 Option::Universe universe = opt.option_->getUniverse();
621 LibDHCP::getVendorOptionDef(universe, id, code);
622 if (!def) {
623 // vendor-XXX space is in oss
624 def = LibDHCP::getRuntimeOptionDef(oss.str(), code);
625 }
626 if (def) {
627 map->set("name", Element::create(def->getName()));
628 }
629 // Set the data item
630 if (!opt.formatted_value_.empty()) {
631 map->set("csv-format", Element::create(true));
632 if (def && def->getType() == OPT_EMPTY_TYPE) {
633 map->set("data", Element::create(""));
634 } else {
635 map->set("data", Element::create(opt.formatted_value_));
636 }
637 } else {
638 std::vector<uint8_t> bin = opt.option_->toBinary();
639 if (!opt.cancelled_ || !bin.empty()) {
640 map->set("csv-format", Element::create(false));
641 if (def && def->getType() == OPT_EMPTY_TYPE) {
642 map->set("data", Element::create(""));
643 } else {
644 std::string repr = util::encode::encodeHex(bin);
645 map->set("data", Element::create(repr));
646 }
647 }
648 }
649 // Set the persistency flag
650 map->set("always-send", Element::create(opt.persistent_));
651 // Set the cancellation flag
652 map->set("never-send", Element::create(opt.cancelled_));
653
654 // Include client-classes if not empty.
655 if (!opt.client_classes_.empty()) {
656 map->set("client-classes", opt.client_classes_.toElement());
657 }
658
659 // Push on the list
660 result->add(map);
661 }
662 }
663
664 return (result);
665}
666
667} // namespace dhcp
668} // namespace isc
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown if a function is called in a prohibited way.
void setId(const uint64_t id)
Sets element's database identifier.
static ElementPtr create(const Position &pos=ZERO_POSITION())
Definition data.cc:249
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition data.cc:304
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
Definition data.cc:299
bool isEncapsulated() const
Checks if options have been encapsulated.
Definition cfg_option.h:602
OptionContainerPtr getAllCombined(const std::string &option_space) const
Returns all non-vendor or vendor options for the specified option space.
void encapsulate()
Appends encapsulated options to top-level options.
void replace(const OptionDescriptor &desc, const std::string &option_space)
Replaces the instance of an option within this collection.
static bool createDescriptorOption(CfgOptionDefPtr cfg_def, const std::string &space, OptionDescriptor &opt_desc)
Creates an option descriptor's option based on a set of option defs.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
void createOptions(CfgOptionDefPtr cfg_def)
Re-create the option in each descriptor based on given definitions.
isc::data::ElementPtr toElementWithMetadata(const bool include_metadata, CfgOptionDefPtr cfg_option_def=CfgOptionDefPtr()) const
Unparse a configuration object with optionally including the metadata.
size_t del(const std::string &option_space, const uint16_t option_code)
Deletes option for the specified option space and option code.
std::list< std::string > getOptionSpaceNames() const
Returns a list of configured option space names.
Definition cfg_option.h:868
bool empty() const
Indicates the object is empty.
Definition cfg_option.cc:83
void mergeTo(CfgOption &other) const
Merges this configuration to another configuration.
void copyTo(CfgOption &other) const
Copies this configuration to another configuration.
CfgOption()
default constructor
Definition cfg_option.cc:78
std::list< std::string > getVendorIdsSpaceNames() const
Returns a list of option space names for configured vendor ids.
OptionContainerPtr getAll(const std::string &option_space) const
Returns all options for the specified option space.
void merge(CfgOptionDefPtr cfg_def, CfgOption &other)
Merges another option configuration into this one.
bool equals(const CfgOption &other) const
Check if configuration is equal to other configuration.
Definition cfg_option.cc:88
void add(const OptionPtr &option, const bool persistent, const bool cancelled, const std::string &option_space, const uint64_t id=0)
Adds instance of the option to the configuration.
Definition cfg_option.cc:94
std::list< uint32_t > getVendorIds() const
Returns a list of all configured vendor identifiers.
Definition cfg_option.h:873
Container for storing client class names.
Definition classify.h:110
std::string toText(const std::string &separator=", ") const
Returns all class names as text.
Definition classify.cc:80
static OptionDefinitionPtr getOptionDef(const std::string &space, const uint16_t code)
Return the first option definition matching a particular option code.
Definition libdhcp++.cc:132
static OptionDefinitionPtr getVendorOptionDef(const Option::Universe u, const uint32_t vendor_id, const uint16_t code)
Returns vendor option definition for a given vendor-id and code.
Definition libdhcp++.cc:174
static uint32_t optionSpaceToVendorId(const std::string &option_space)
Converts option space name to vendor id.
static OptionDefinitionPtr getRuntimeOptionDef(const std::string &space, const uint16_t code)
Returns runtime (non-standard) option definition by space and option code.
Definition libdhcp++.cc:195
static OptionDefinitionPtr getLastResortOptionDef(const std::string &space, const uint16_t code)
Returns last resort option definition by space and option code.
Definition libdhcp++.cc:253
Option descriptor.
Definition cfg_option.h:49
OptionPtr option_
Option instance.
Definition cfg_option.h:52
void addClientClass(const std::string &class_name)
Adds new client class for which the option is allowed.
Definition cfg_option.cc:57
std::string space_name_
Option space name.
Definition cfg_option.h:92
OptionDescriptor(const OptionPtr &opt, bool persist, bool cancel, const std::string &formatted_value="", data::ConstElementPtr user_context=data::ConstElementPtr())
Constructor.
Definition cfg_option.h:105
bool equals(const OptionDescriptor &other) const
Checks if the one descriptor is equal to another.
Definition cfg_option.cc:46
bool allowedForClientClasses(const ClientClasses &cclasses) const
Validates an OptionDescriptor's client-classes against a list of classes.
Definition cfg_option.cc:70
ClientClassesPtr copyClientClasses() const
Get a copy of client classes.
Definition cfg_option.cc:65
bool cancelled_
Cancelled flag.
Definition cfg_option.h:66
std::string formatted_value_
Option value in textual (CSV) format.
Definition cfg_option.h:81
static OptionDescriptorPtr create(const OptionPtr &opt, bool persist, bool cancel, const std::string &formatted_value="", data::ConstElementPtr user_context=data::ConstElementPtr())
Factory function creating an instance of the OptionDescriptor.
Definition cfg_option.cc:27
ClientClasses client_classes_
Collection of classes for the which option is allowed.
Definition cfg_option.h:96
bool persistent_
Persistence flag.
Definition cfg_option.h:58
Simple container for option spaces holding various items.
void clearItems()
Remove all items from the container.
static bool validateName(const std::string &name)
Checks that the provided option space name is valid.
Universe
defines option universe DHCPv4 or DHCPv6
Definition option.h:90
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
std::string ClientClass
Defines a single class name.
Definition classify.h:44
boost::multi_index_container< OptionDescriptor, boost::multi_index::indexed_by< boost::multi_index::sequenced<>, boost::multi_index::hashed_non_unique< KeyFromKeyExtractor< boost::multi_index::const_mem_fun< Option, uint16_t, &Option::getType >, boost::multi_index::member< OptionDescriptor, OptionPtr, &OptionDescriptor::option_ > > >, boost::multi_index::hashed_non_unique< boost::multi_index::member< OptionDescriptor, bool, &OptionDescriptor::persistent_ > >, boost::multi_index::ordered_non_unique< boost::multi_index::const_mem_fun< data::BaseStampedElement, boost::posix_time::ptime, &data::BaseStampedElement::getModificationTime > >, boost::multi_index::hashed_non_unique< boost::multi_index::tag< OptionIdIndexTag >, boost::multi_index::const_mem_fun< data::BaseStampedElement, uint64_t, &data::BaseStampedElement::getId > >, boost::multi_index::hashed_non_unique< boost::multi_index::member< OptionDescriptor, bool, &OptionDescriptor::cancelled_ > >, boost::multi_index::hashed_non_unique< boost::multi_index::composite_key< OptionDescriptor, KeyFromKeyExtractor< boost::multi_index::const_mem_fun< Option, uint16_t, &Option::getType >, boost::multi_index::member< OptionDescriptor, OptionPtr, &OptionDescriptor::option_ > >, boost::multi_index::member< OptionDescriptor, ClientClasses, &OptionDescriptor::client_classes_ > > > > > OptionContainer
Multi index container for DHCP option descriptors.
Definition cfg_option.h:347
std::pair< OptionContainerTypeIndex::const_iterator, OptionContainerTypeIndex::const_iterator > OptionContainerTypeRange
Pair of iterators to represent the range of options having the same option type value.
Definition cfg_option.h:357
OptionContainer::nth_index< 1 >::type OptionContainerTypeIndex
Type of the index #1 - option type.
Definition cfg_option.h:352
boost::shared_ptr< CfgOptionDef > CfgOptionDefPtr
Non-const pointer.
boost::shared_ptr< ClientClasses > ClientClassesPtr
Smart pointer to ClientClasses object.
Definition classify.h:281
boost::shared_ptr< OptionDefinition > OptionDefinitionPtr
Pointer to option definition object.
boost::shared_ptr< OptionDescriptor > OptionDescriptorPtr
A pointer to option descriptor.
Definition cfg_option.h:38
boost::shared_ptr< OptionContainer > OptionContainerPtr
Pointer to the OptionContainer object.
Definition cfg_option.h:350
boost::shared_ptr< Option > OptionPtr
Definition option.h:37
string encodeHex(const vector< uint8_t > &binary)
Encode binary data in the base16 format.
Definition encode.cc:361
string trim(const string &input)
Trim leading and trailing spaces.
Definition str.cc:32
Defines the logger used by the top-level component of kea-lfc.
#define DHCP4_OPTION_SPACE
global std option spaces
#define DHCP6_OPTION_SPACE