Kea 3.1.0
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
307void
308CfgOption::encapsulateInternal(const OptionPtr& option) {
309 // Get encapsulated option space for the option.
310 const std::string& encap_space = option->getEncapsulatedSpace();
311 // Empty value means that no option space is encapsulated.
312 if (!encap_space.empty()) {
313 if (encap_space == DHCP4_OPTION_SPACE || encap_space == DHCP6_OPTION_SPACE) {
314 return;
315 }
316 // Retrieve all options from the encapsulated option space.
317 OptionContainerPtr encap_options = getAll(encap_space);
318 for (auto const& encap_opt : *encap_options) {
319 if (option.get() == encap_opt.option_.get()) {
320 // Avoid recursion by not adding options to themselves.
321 continue;
322 }
323
324 // Add sub-option if there isn't one added already.
325 if (!option->getOption(encap_opt.option_->getType())) {
326 option->addOption(encap_opt.option_);
327 }
328 encapsulateInternal(encap_opt.option_);
329 }
330 }
331}
332
333template <typename Selector>
334void
335CfgOption::mergeInternal(const OptionSpaceContainer<OptionContainer,
336 OptionDescriptor, Selector>& src_container,
338 OptionDescriptor, Selector>& dest_container) const {
339 // Get all option spaces used in source container.
340 std::list<Selector> selectors = src_container.getOptionSpaceNames();
341
342 // For each space in the source container retrieve the actual options and
343 // match them with the options held in the destination container under
344 // the same space.
345 for (auto const& it : selectors) {
346 // Get all options in the destination container for the particular
347 // option space.
348 OptionContainerPtr dest_all = dest_container.getItems(it);
349 OptionContainerPtr src_all = src_container.getItems(it);
350 // For each option under this option space check if there is a
351 // corresponding option in the destination container. If not,
352 // add one.
353 for (auto const& src_opt : *src_all) {
354 const OptionContainerTypeIndex& idx = dest_all->get<1>();
355 const OptionContainerTypeRange& range =
356 idx.equal_range(src_opt.option_->getType());
357 // If there is no such option in the destination container,
358 // add one.
359 if (std::distance(range.first, range.second) == 0) {
360 dest_container.addItem(OptionDescriptor(src_opt), it);
361 }
362 }
363 }
364}
365
367CfgOption::getAll(const std::string& option_space) const {
368 return (options_.getItems(option_space));
369}
370
372CfgOption::getAll(const uint32_t vendor_id) const {
373 return (vendor_options_.getItems(vendor_id));
374}
375
377CfgOption::getAllCombined(const std::string& option_space) const {
378 auto vendor_id = LibDHCP::optionSpaceToVendorId(option_space);
379 if (vendor_id > 0) {
380 return (getAll(vendor_id));
381 }
382 return (getAll(option_space));
383}
384
385size_t
386CfgOption::del(const std::string& option_space, const uint16_t option_code) {
387 // Check for presence of options.
388 OptionContainerPtr options = getAll(option_space);
389 if (!options || options->empty()) {
390 // There are no options, so there is nothing to do.
391 return (0);
392 }
393
394 // If this is not top level option we may also need to delete the
395 // option instance from options encapsulating the particular option
396 // space.
397 if ((option_space != DHCP4_OPTION_SPACE) &&
398 (option_space != DHCP6_OPTION_SPACE)) {
399 // For each option space name iterate over the existing options.
400 auto option_space_names = getOptionSpaceNames();
401 for (auto const& option_space_from_list : option_space_names) {
402 // Get all options within the particular option space.
403 auto const& options_in_space = getAll(option_space_from_list);
404 for (auto const& option_it : *options_in_space) {
405
406 // Check if the option encapsulates our option space and
407 // it does, try to delete our option.
408 if (option_it.option_ &&
409 (option_it.option_->getEncapsulatedSpace() == option_space)) {
410 option_it.option_->delOption(option_code);
411 }
412 }
413 }
414 }
415
416 auto& idx = options->get<1>();
417 return (idx.erase(option_code));
418}
419
420size_t
421CfgOption::del(const std::string& option_space, const uint16_t option_code,
422 const ClientClasses& client_classes) {
423 // Check for presence of options.
424 OptionContainerPtr options = getAll(option_space);
425 if (!options || options->empty()) {
426 // There are no options, so there is nothing to do.
427 return (0);
428 }
429
430 // If this is not top level option we may also need to delete the
431 // option instance from options encapsulating the particular option
432 // space.
433 if ((option_space != DHCP4_OPTION_SPACE) &&
434 (option_space != DHCP6_OPTION_SPACE)) {
435 // For each option space name iterate over the existing options.
436 auto option_space_names = getOptionSpaceNames();
437 for (auto const& option_space_from_list : option_space_names) {
438 // Get all options within the particular option space.
439 auto const& options_in_space = getAll(option_space_from_list);
440 for (auto const& option_it : *options_in_space) {
441
442 // Check if the option encapsulates our option space and
443 // if it does, try to delete our option.
444 if (option_it.option_ &&
445 (option_it.option_->getEncapsulatedSpace() == option_space)) {
446 option_it.option_->delOption(option_code);
447 }
448 }
449 }
450 }
451
452 auto& idx6 = options->get<6>();
453 auto range = idx6.equal_range(boost::make_tuple(option_code, client_classes));
454 auto count = std::distance(range.first, range.second);
455 if (count) {
456 idx6.erase(range.first, range.second);
457 }
458
459 return (count);
460}
461
462size_t
463CfgOption::del(const uint32_t vendor_id, const uint16_t option_code) {
464 // Check for presence of options.
465 OptionContainerPtr vendor_options = getAll(vendor_id);
466 if (!vendor_options || vendor_options->empty()) {
467 // There are no options, so there is nothing to do.
468 return (0);
469 }
470
471 auto& idx = vendor_options->get<1>();
472 return (idx.erase(option_code));
473}
474
475size_t
476CfgOption::del(const uint64_t id) {
477 // Hierarchical nature of the options configuration requires that
478 // we go over all options and decapsulate them before removing
479 // any of them. Let's walk over the existing option spaces.
480 for (auto const& space_name : getOptionSpaceNames()) {
481 // Get all options for the option space.
482 auto const& options = getAll(space_name);
483 for (auto const& option_it : *options) {
484 if (!option_it.option_) {
485 continue;
486 }
487
488 // For each option within the option space we need to dereference
489 // any existing sub options.
490 auto sub_options = option_it.option_->getOptions();
491 for (auto const& sub : sub_options) {
492 // Dereference sub option.
493 option_it.option_->delOption(sub.second->getType());
494 }
495 }
496 }
497
498 // Now that we got rid of dependencies between the instances of the options
499 // we can delete all options having a specified id.
500 size_t num_deleted = options_.deleteItems(id) + vendor_options_.deleteItems(id);
501
502 // Let's encapsulate those options that remain in the configuration.
503 encapsulate();
504
505 // Return the number of deleted options.
506 return (num_deleted);
507}
508
511 return (toElementWithMetadata(false));
512}
513
516 return (toElementWithMetadata(false, cfg_option_def));
517}
518
520CfgOption::toElementWithMetadata(const bool include_metadata,
521 CfgOptionDefPtr cfg_option_def) const {
522 // option-data value is a list of maps
524 // Iterate first on options using space names
525 const std::list<std::string>& names = options_.getOptionSpaceNames();
526 for (auto const& name : names) {
527 OptionContainerPtr opts = getAll(name);
528 for (auto const& opt : *opts) {
529 // Get and fill the map for this option
531 // Set user context
532 opt.contextToElement(map);
533 // Set space from parent iterator
534 map->set("space", Element::create(name));
535 // Set the code
536 uint16_t code = opt.option_->getType();
537 map->set("code", Element::create(code));
538 // Set the name (always for standard options else when asked for)
540 if (cfg_option_def) {
541 def = cfg_option_def->get(name, code);
542 }
543 if (!def) {
544 def = LibDHCP::getOptionDef(name, code);
545 }
546 if (!def) {
547 def = LibDHCP::getRuntimeOptionDef(name, code);
548 }
549 if (!def) {
550 def = LibDHCP::getLastResortOptionDef(name, code);
551 }
552 if (def) {
553 map->set("name", Element::create(def->getName()));
554 }
555 // Set the data item
556 if (!opt.formatted_value_.empty()) {
557 map->set("csv-format", Element::create(true));
558 if (def && def->getType() == OPT_EMPTY_TYPE) {
559 map->set("data", Element::create(""));
560 } else {
561 map->set("data", Element::create(opt.formatted_value_));
562 }
563 } else {
564 std::vector<uint8_t> bin = opt.option_->toBinary();
565 if (!opt.cancelled_ || !bin.empty()) {
566 map->set("csv-format", Element::create(false));
567 if (def && def->getType() == OPT_EMPTY_TYPE) {
568 map->set("data", Element::create(""));
569 } else {
570 std::string repr = util::encode::encodeHex(bin);
571 map->set("data", Element::create(repr));
572 }
573 }
574 }
575 // Set the persistency flag
576 map->set("always-send", Element::create(opt.persistent_));
577 // Set the cancelled flag.
578 map->set("never-send", Element::create(opt.cancelled_));
579 // Include metadata if requested.
580 if (include_metadata) {
581 map->set("metadata", opt.getMetadata());
582 }
583
584 // Include client-classes if not empty.
585 if (!opt.client_classes_.empty()) {
586 map->set("client-classes", opt.client_classes_.toElement());
587 }
588
589 // Push on the list
590 result->add(map);
591 }
592 }
593 // Iterate first on vendor_options using vendor ids
594 const std::list<uint32_t>& ids = vendor_options_.getOptionSpaceNames();
595 for (auto const& id : ids) {
596 OptionContainerPtr opts = getAll(id);
597 for (auto const& opt : *opts) {
598 // Get and fill the map for this option
600 // Set user context
601 opt.contextToElement(map);
602 // Set space from parent iterator
603 std::ostringstream oss;
604 oss << "vendor-" << id;
605 map->set("space", Element::create(oss.str()));
606 // Set the code
607 uint16_t code = opt.option_->getType();
608 map->set("code", Element::create(code));
609 // Set the name
610 Option::Universe universe = opt.option_->getUniverse();
612 LibDHCP::getVendorOptionDef(universe, id, code);
613 if (!def) {
614 // vendor-XXX space is in oss
615 def = LibDHCP::getRuntimeOptionDef(oss.str(), code);
616 }
617 if (def) {
618 map->set("name", Element::create(def->getName()));
619 }
620 // Set the data item
621 if (!opt.formatted_value_.empty()) {
622 map->set("csv-format", Element::create(true));
623 if (def && def->getType() == OPT_EMPTY_TYPE) {
624 map->set("data", Element::create(""));
625 } else {
626 map->set("data", Element::create(opt.formatted_value_));
627 }
628 } else {
629 std::vector<uint8_t> bin = opt.option_->toBinary();
630 if (!opt.cancelled_ || !bin.empty()) {
631 map->set("csv-format", Element::create(false));
632 if (def && def->getType() == OPT_EMPTY_TYPE) {
633 map->set("data", Element::create(""));
634 } else {
635 std::string repr = util::encode::encodeHex(bin);
636 map->set("data", Element::create(repr));
637 }
638 }
639 }
640 // Set the persistency flag
641 map->set("always-send", Element::create(opt.persistent_));
642 // Set the cancellation flag
643 map->set("never-send", Element::create(opt.cancelled_));
644
645 // Include client-classes if not empty.
646 if (!opt.client_classes_.empty()) {
647 map->set("client-classes", opt.client_classes_.toElement());
648 }
649
650 // Push on the list
651 result->add(map);
652 }
653 }
654
655 return (result);
656}
657
658} // namespace dhcp
659} // namespace isc
boost::shared_ptr< Option > OptionPtr
Definition option.h:37
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