Kea 3.3.4
cb_parsers.h
Go to the documentation of this file.
1// Copyright (C) 2026 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#ifndef CB_PARSERS_H
8#define CB_PARSERS_H
9
10#include <cc/stamped_value.h>
11#include <cc/server_tag.h>
13#include <database/server.h>
20#include <boost/make_shared.hpp>
21#include <boost/shared_ptr.hpp>
22
28
29namespace isc {
30namespace cb {
31
36public:
41 : keywords_(keywords) {
42 }
43
51 std::string parse(data::ConstElementPtr global_parameter);
52
53private:
56 const data::SimpleKeywords& keywords_;
57};
58
61public:
67 const data::SimpleKeywords& list_keywords)
68 : keywords_(keywords), list_keywords_(list_keywords) {
69 }
70
81 parse(const data::ConstElementPtr& global_parameter_data);
82
83private:
86 const data::SimpleKeywords& keywords_;
87
90 const data::SimpleKeywords& list_keywords_;
91};
92
95public:
99 CBOptionDefParser(const uint16_t address_family)
100 : address_family_(address_family) {
101 }
102
111
112private:
114 uint16_t address_family_;
115};
116
121private:
123 static data::SimpleRequiredKeywords OPTION_REQUIRED;
124
127 static data::SimpleKeywords OPTION_KEYWORDS;
128
129public:
133 CBOptionPairParser(const uint16_t address_family)
134 : address_family_(address_family) {
135 }
136
139
155 std::pair<uint16_t, std::string> parse(data::ConstElementPtr option,
156 bool skip_keywords = false);
157
158private:
160 uint16_t address_family_;
161};
162
165typedef std::tuple<uint16_t, std::string, bool> CBOptionDefDelete;
166
168typedef std::tuple<uint16_t, std::string, ClientClassesPtr> CBOptionTuple;
169
174public:
178 CBOptionTupleParser(const uint16_t address_family)
179 : CBOptionPairParser(address_family) {
180 }
181
197};
198
203public:
207 CBOptionDefDeleteParser(const uint16_t address_family)
208 : CBOptionPairParser(address_family) {
209 }
210
226};
227
233public:
234
244 CBOptionDataParser(const uint16_t address_family,
245 dhcp::CfgOptionDefPtr cfg_option_def,
246 db::BackendSelector& backend_selector,
247 db::ServerSelector& server_selector);
248
249protected:
250
288 findOptionDefinition(const std::string& option_space,
289 const util::Optional<uint32_t>& option_code,
290 const util::Optional<std::string>& option_name) const;
291
295
299};
300
306public:
307
317 CBOptionDataListParser(const uint16_t address_family,
318 CfgOptionDefPtr cfg_option_def,
319 db::BackendSelector& backend_selector,
320 db::ServerSelector& server_selector);
321
322protected:
323
328 virtual boost::shared_ptr<OptionDataParser>
330
334
338};
339
344private:
346 static data::SimpleRequiredKeywords POOL_REQUIRED;
347
349 static data::SimpleKeywords POOL_KEYWORDS;
350
351public:
355 CBPoolRangeParser(const uint16_t address_family)
356 : address_family_(address_family) {
357 }
358
366 std::pair<asiolink::IOAddress, asiolink::IOAddress>
368
369private:
371 uint16_t address_family_;
372};
373
379template<typename PoolParser>
380class CBPoolParser : public PoolParser {
381public:
382
390 db::ServerSelector& server_selector)
391 : PoolParser(), backend_selector_(backend_selector),
392 server_selector_(server_selector) {
393 }
394
395protected:
396
406 virtual boost::shared_ptr<OptionDataListParser>
407 createOptionDataListParser(const uint16_t address_family) const {
408 auto parser = boost::make_shared<CBOptionDataListParser>(address_family,
412 return (parser);
413 }
414
418
422};
423
426
429
437template<typename PoolsListParser, typename PoolParser>
439public:
440
448 db::ServerSelector& server_selector)
449 : backend_selector_(backend_selector), server_selector_(server_selector) {
450 }
451
452protected:
453
461 virtual boost::shared_ptr<dhcp::PoolParser> createPoolConfigParser() const {
462 auto parser = boost::make_shared<PoolParser>(backend_selector_, server_selector_);
463 return (parser);
464 }
465
469
473};
474
477
480
484public:
485
492 CBPdPoolParser(db::BackendSelector& backend_selector,
493 db::ServerSelector& server_selector);
494
495protected:
496
501 virtual boost::shared_ptr<OptionDataListParser>
503
507
511};
512
516public:
517
525 db::ServerSelector& server_selector);
526
527protected:
528
533 virtual boost::shared_ptr<PdPoolParser>
535
539
543};
544
549private:
551 static data::SimpleRequiredKeywords PD_POOL_REQUIRED;
552
555 static data::SimpleKeywords PD_POOL_KEYWORDS;
556
557public:
562 std::pair<asiolink::IOAddress, uint8_t>
564};
565
570private:
572 static data::SimpleRequiredKeywords SUBNET_ID_REQUIRED;
573
575 static data::SimpleKeywords SUBNET_ID_KEYWORDS;
576
577public:
590};
591
596private:
598 static data::SimpleRequiredKeywords SUBNET_PREFIX_REQUIRED;
599
601 static data::SimpleKeywords SUBNET_PREFIX_KEYWORDS;
602
603public:
607 CBSubnetPrefixParser(const uint16_t address_family)
608 : address_family_(address_family) {
609 }
610
623 std::string parse(data::ConstElementPtr subnet);
624
625private:
627 uint16_t address_family_;
628};
629
635public:
645 db::ServerSelector& server_selector);
646
658
659protected:
660
665 virtual boost::shared_ptr<OptionDataListParser>
667
671 virtual boost::shared_ptr<dhcp::PoolsListParser>
672 createPoolsListParser() const;
673
677
681};
682
688public:
698 db::ServerSelector& server_selector);
699
711
712protected:
713
718 virtual boost::shared_ptr<OptionDataListParser>
720
724 virtual boost::shared_ptr<dhcp::PoolsListParser>
725 createPoolsListParser() const;
726
730 virtual boost::shared_ptr<dhcp::PdPoolsListParser>
732
736
740};
741
747public:
748
756 db::ServerSelector& server_selector);
757
758protected:
759
764 virtual boost::shared_ptr<Subnet4ConfigParser>
766
770
774};
775
781public:
782
790 db::ServerSelector& server_selector);
791
792protected:
793
798 virtual boost::shared_ptr<Subnet6ConfigParser>
800
804
808};
809
814private:
816 static data::SimpleRequiredKeywords SHARED_NETWORK_REQUIRED;
817
819 static data::SimpleKeywords SHARED_NETWORK_KEYWORDS;
820
821public:
833 std::string parse(data::ConstElementPtr shared_network);
834};
835
841public:
851 db::ServerSelector& server_selector);
852
862
863protected:
864
869 virtual boost::shared_ptr<OptionDataListParser>
871
876 virtual boost::shared_ptr<Subnets4ListConfigParser>
878
882
886};
887
893public:
898 db::ServerSelector& server_selector);
899
909
910protected:
911
916 virtual boost::shared_ptr<OptionDataListParser>
918
923 virtual boost::shared_ptr<Subnets6ListConfigParser>
925
929
933};
934
939public:
940
948 db::ServerSelector& server_selector);
949
956 virtual boost::shared_ptr<OptionDataListParser>
957 createOptionDataListParser(const uint16_t address_family,
958 CfgOptionDefPtr cfg_option_def) const;
959
960protected:
961
965
969};
970
977public:
978
988 CBClientClassParser(uint16_t family,
989 CfgOptionDefPtr cfg_option_def,
990 db::BackendSelector& backend_selector,
991 db::ServerSelector& server_selector);
992
1002 std::pair<dhcp::ClientClassDefPtr, std::string>
1003 parse(data::ConstElementPtr client_class);
1004
1005private:
1006
1008 uint16_t family_;
1009
1012 CfgOptionDefPtr cfg_option_def_;
1013
1016 db::BackendSelector& backend_selector_;
1017
1020 db::ServerSelector& server_selector_;
1021};
1022
1027private:
1029 static data::SimpleRequiredKeywords CLIENT_CLASS_REQUIRED;
1030
1032 static data::SimpleKeywords CLIENT_CLASS_KEYWORDS;
1033
1034public:
1046 std::string parse(data::ConstElementPtr client_class);
1047};
1048
1053private:
1055 static data::SimpleRequiredKeywords SERVER_TAG_REQUIRED;
1056
1058 static data::SimpleKeywords SERVER_TAG_KEYWORDS;
1059
1060public:
1069};
1070
1075private:
1077 static data::SimpleRequiredKeywords SERVER_CONFIG_REQUIRED;
1078
1081 static data::SimpleKeywords SERVER_CONFIG_KEYWORDS;
1082
1083public:
1090};
1091
1092} // end of namespace cb
1093} // end of namespace isc
1094
1095#endif // CB_PARSER_H
virtual boost::shared_ptr< OptionDataListParser > createOptionDataListParser(const uint16_t address_family, CfgOptionDefPtr cfg_option_def) const
Returns an instance of the CBOptionDataListParser.
db::BackendSelector & backend_selector_
Backend selector used to fetch option definitions during option data parsing.
Definition cb_parsers.h:964
CBClientClassDefParser(db::BackendSelector &backend_selector, db::ServerSelector &server_selector)
Constructor.
db::ServerSelector & server_selector_
Server selector used to fetch option definitions during option data parsing.
Definition cb_parsers.h:968
Implements a parser for a client class name.
std::string parse(data::ConstElementPtr client_class)
Parses a client class name.
CBClientClassParser(uint16_t family, CfgOptionDefPtr cfg_option_def, db::BackendSelector &backend_selector, db::ServerSelector &server_selector)
Constructor.
std::pair< dhcp::ClientClassDefPtr, std::string > parse(data::ConstElementPtr client_class)
Parses a client class.
virtual boost::shared_ptr< OptionDataParser > createOptionDataParser() const
Returns an instance of the CBOptionDataListParser to be used in parsing options.
CBOptionDataListParser(const uint16_t address_family, CfgOptionDefPtr cfg_option_def, db::BackendSelector &backend_selector, db::ServerSelector &server_selector)
Constructor.
db::BackendSelector & backend_selector_
Backend selector used to fetch option definitions during option data parsing.
Definition cb_parsers.h:333
db::ServerSelector & server_selector_
Server selector used to fetch option definitions during option data parsing.
Definition cb_parsers.h:337
virtual dhcp::OptionDefinitionPtr findOptionDefinition(const std::string &option_space, const util::Optional< uint32_t > &option_code, const util::Optional< std::string > &option_name) const
Finds an option definition within an option space.
db::BackendSelector & backend_selector_
Backend selector to be used to fetch option definitions during option data parsing.
Definition cb_parsers.h:294
db::ServerSelector & server_selector_
Server selector to be used to fetch option definitions during option data parsing.
Definition cb_parsers.h:298
CBOptionDataParser(const uint16_t address_family, dhcp::CfgOptionDefPtr cfg_option_def, db::BackendSelector &backend_selector, db::ServerSelector &server_selector)
Constructor.
CBOptionDefDeleteParser(const uint16_t address_family)
Constructor.
Definition cb_parsers.h:207
CBOptionDefDelete parse(data::ConstElementPtr option)
Parses an option into code + space pair.
CBOptionDefParser(const uint16_t address_family)
Constructor.
Definition cb_parsers.h:99
dhcp::OptionDefinitionPtr parse(data::ConstElementPtr option_def)
Parses an option definition.
virtual ~CBOptionPairParser()
Destructor.
Definition cb_parsers.h:138
CBOptionPairParser(const uint16_t address_family)
Constructor.
Definition cb_parsers.h:133
std::pair< uint16_t, std::string > parse(data::ConstElementPtr option, bool skip_keywords=false)
Parses an option into code + space pair.
CBOptionTuple parse(data::ConstElementPtr option)
Parses an option into code + space pair.
CBOptionTupleParser(const uint16_t address_family)
Constructor.
Definition cb_parsers.h:178
CBPdPoolParser(db::BackendSelector &backend_selector, db::ServerSelector &server_selector)
Constructor.
virtual boost::shared_ptr< OptionDataListParser > createOptionDataListParser() const
Returns an instance of the CBOptionDataListParser to be used in parsing the option-data structure.
db::ServerSelector & server_selector_
Server selector used to fetch option definitions during option data parsing.
Definition cb_parsers.h:510
db::BackendSelector & backend_selector_
Backend selector used to fetch option definitions during option data parsing.
Definition cb_parsers.h:506
Implements a parser for a prefix delegation pool prefix.
Definition cb_parsers.h:548
std::pair< asiolink::IOAddress, uint8_t > parse(data::ConstElementPtr pd_pool)
Parses a prefix delegation pool prefix.
virtual boost::shared_ptr< PdPoolParser > createPdPoolConfigParser() const
Returns an instance of the CBPdPoolParser to be used in parsing the prefix delegation pools.
db::BackendSelector & backend_selector_
Backend selector used to fetch option definitions during option data parsing.
Definition cb_parsers.h:538
CBPdPoolsListParser(db::BackendSelector &backend_selector, db::ServerSelector &server_selector)
Constructor.
db::ServerSelector & server_selector_
Server selector used to fetch option definitions during option data parsing.
Definition cb_parsers.h:542
Overrides the default address pool parsers to use CB specific option data parsers.
Definition cb_parsers.h:380
CBPoolParser(db::BackendSelector &backend_selector, db::ServerSelector &server_selector)
Constructor.
Definition cb_parsers.h:389
virtual boost::shared_ptr< OptionDataListParser > createOptionDataListParser(const uint16_t address_family) const
Returns an instance of the OptionDataListParser to be used in parsing the option-data structure.
Definition cb_parsers.h:407
CBPoolRangeParser(const uint16_t address_family)
Constructor.
Definition cb_parsers.h:355
std::pair< asiolink::IOAddress, asiolink::IOAddress > parse(data::ConstElementPtr pool)
Parses an address pool range.
Overrides the default address pool list parsers to use CB specific option data parsers.
Definition cb_parsers.h:438
virtual boost::shared_ptr< dhcp::PoolParser > createPoolConfigParser() const
Returns an instance of the CBPool4Parser to be used in parsing the address pools.
Definition cb_parsers.h:461
CBPoolsListParser(db::BackendSelector &backend_selector, db::ServerSelector &server_selector)
Constructor.
Definition cb_parsers.h:447
db::ServerSelector & server_selector_
Server selector used to fetch option definitions during option data parsing.
Definition cb_parsers.h:885
CBSharedNetwork4Parser(db::BackendSelector &backend_selector, db::ServerSelector &server_selector)
Constructor.
db::BackendSelector & backend_selector_
Backend selector used to fetch option definitions during option data parsing.
Definition cb_parsers.h:881
dhcp::SharedNetwork4Ptr parse(data::ConstElementPtr shared_network)
Parses a single IPv4 shared network configuration.
virtual boost::shared_ptr< OptionDataListParser > createOptionDataListParser() const
Returns an instance of the CBOptionDataListParser to be used in parsing the option-data structure.
virtual boost::shared_ptr< Subnets4ListConfigParser > createSubnetsListParser() const
Returns an instance of the CBSubnets4ListConfigParser to be used for parsing the subnets within the s...
db::BackendSelector & backend_selector_
Backend selector used to fetch option definitions during option data parsing.
Definition cb_parsers.h:928
virtual boost::shared_ptr< OptionDataListParser > createOptionDataListParser() const
Returns an instance of the CBOptionDataListParser to be used in parsing the option-data structure.
db::ServerSelector & server_selector_
Server selector used to fetch option definitions during option data parsing.
Definition cb_parsers.h:932
CBSharedNetwork6Parser(db::BackendSelector &backend_selector, db::ServerSelector &server_selector)
Constructor.
dhcp::SharedNetwork6Ptr parse(data::ConstElementPtr shared_network)
Parses a single IPv6 shared network configuration.
virtual boost::shared_ptr< Subnets6ListConfigParser > createSubnetsListParser() const
Returns an instance of the CBSubnets6ListConfigParser to be used for parsing the subnets within the s...
Implements a parser for a shared network name.
Definition cb_parsers.h:813
std::string parse(data::ConstElementPtr shared_network)
Parses a shared network name.
dhcp::Subnet4Ptr parse(data::ConstElementPtr subnet)
Parses a single subnet configuration.
db::BackendSelector & backend_selector_
Backend selector used for fetching option definitions during option data parsing.
Definition cb_parsers.h:676
virtual boost::shared_ptr< OptionDataListParser > createOptionDataListParser() const
Returns an instance of the CBOptionDataListParser to be used in parsing the option-data structure.
virtual boost::shared_ptr< dhcp::PoolsListParser > createPoolsListParser() const
Returns an instance of the CBPools4ListParser.
db::ServerSelector & server_selector_
Server selector used for fetching option definitions during option data parsing.
Definition cb_parsers.h:680
CBSubnet4ConfigParser(db::BackendSelector &backend_selector, db::ServerSelector &server_selector)
Constructor.
dhcp::Subnet6Ptr parse(data::ConstElementPtr subnet)
Parses a single subnet configuration.
virtual boost::shared_ptr< OptionDataListParser > createOptionDataListParser() const
Returns an instance of the CBOptionDataListParser to be used in parsing the option-data structure.
virtual boost::shared_ptr< dhcp::PoolsListParser > createPoolsListParser() const
Returns an instance of the CBPools6ListParser.
CBSubnet6ConfigParser(db::BackendSelector &backend_selector, db::ServerSelector &server_selector)
Constructor.
db::ServerSelector & server_selector_
Server selector used for fetching option definitions during option data parsing.
Definition cb_parsers.h:739
db::BackendSelector & backend_selector_
Backend selector used for fetching option definitions during option data parsing.
Definition cb_parsers.h:735
virtual boost::shared_ptr< dhcp::PdPoolsListParser > createPdPoolsListParser() const
Returns an instance of the CBPdPoolsListParser.
Implements a parser for a subnet id.
Definition cb_parsers.h:569
dhcp::SubnetID parse(data::ConstElementPtr subnet)
Parses a subnet id.
CBSubnetPrefixParser(const uint16_t address_family)
Constructor.
Definition cb_parsers.h:607
std::string parse(data::ConstElementPtr subnet)
Parses a subnet prefix.
db::BackendSelector & backend_selector_
Backend selector used to fetch option definitions during option data parsing.
Definition cb_parsers.h:769
CBSubnets4ListConfigParser(db::BackendSelector &backend_selector, db::ServerSelector &server_selector)
Constructor.
db::ServerSelector & server_selector_
Server selector used to fetch option definitions during option data parsing.
Definition cb_parsers.h:773
virtual boost::shared_ptr< Subnet4ConfigParser > createSubnetConfigParser() const
Returns an instance of the CBSubnet4ConfigParser to be used in parsing the subnets.
db::ServerSelector & server_selector_
Server selector used to fetch option definitions during option data parsing.
Definition cb_parsers.h:807
db::BackendSelector & backend_selector_
Backend selector used to fetch option definitions during option data parsing.
Definition cb_parsers.h:803
virtual boost::shared_ptr< Subnet6ConfigParser > createSubnetConfigParser() const
Returns an instance of the CBSubnet6ConfigParser to be used in parsing the subnets.
CBSubnets6ListConfigParser(db::BackendSelector &backend_selector, db::ServerSelector &server_selector)
Constructor.
GlobalParameterNameParser(const data::SimpleKeywords &keywords)
Constructor.
Definition cb_parsers.h:40
std::string parse(data::ConstElementPtr global_parameter)
Parses global parameter name.
Definition cb_parsers.cc:39
GlobalParameterParser(const data::SimpleKeywords &keywords, const data::SimpleKeywords &list_keywords)
Constructor.
Definition cb_parsers.h:66
data::StampedValueCollection parse(const data::ConstElementPtr &global_parameter_data)
Parses global parameters information.
Definition cb_parsers.cc:57
Implements parser for a server configuration.
db::ServerPtr parse(data::ConstElementPtr server)
Parses a single server configuration.
Implements parser for a server tag.
data::ServerTag parse(data::ConstElementPtr server)
Parses server tag.
Represents a server tag.
Definition server_tag.h:25
Config Backend selector.
Server selector for associating objects in a database with specific servers.
Parser for a single client class definition.
Parser for option data values within a subnet.
Parser for option data value.
Parser for a list of prefix delegation pools.
parser for a single pool definition
Parser for a list of pools.
Implements parser for IPv4 shared networks.
Implements parser for IPv6 shared networks.
Subnet4ConfigParser(bool check_iface=true)
Constructor.
Subnet6ConfigParser(bool check_iface=true)
Constructor.
this class parses list of DHCP4 subnets
this class parses a list of DHCP6 subnets
A template representing an optional value.
Definition optional.h:37
Defines classes for storing client class definitions.
Parsers for client class definitions.
CBPoolParser< dhcp::Pool4Parser > CBPool4Parser
Specialization of the CBPoolParser class for DHCPv4.
Definition cb_parsers.h:425
CBPoolParser< dhcp::Pool6Parser > CBPool6Parser
Specialization of the CBPoolParser class for DHCPv6.
Definition cb_parsers.h:428
std::tuple< uint16_t, std::string, ClientClassesPtr > CBOptionTuple
Defines a tuple for the three values that may be used as a key for an option.
Definition cb_parsers.h:168
CBPoolsListParser< dhcp::Pools4ListParser, CBPool4Parser > CBPools4ListParser
Specialization of the CBPoolsListParser class for DHCPv4.
Definition cb_parsers.h:476
std::tuple< uint16_t, std::string, bool > CBOptionDefDelete
Defines a tuple of values for deleting an option definition: the option code, option space,...
Definition cb_parsers.h:165
CBPoolsListParser< dhcp::Pools6ListParser, CBPool6Parser > CBPools6ListParser
Specialization of the CBPoolsListParser class for DHCPv6.
Definition cb_parsers.h:479
std::vector< std::string > SimpleRequiredKeywords
This specifies all required keywords.
boost::multi_index_container< StampedValuePtr, boost::multi_index::indexed_by< boost::multi_index::hashed_non_unique< boost::multi_index::tag< StampedValueNameIndexTag >, boost::multi_index::const_mem_fun< StampedValue, std::string, &StampedValue::getName > >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< StampedValueModificationTimeIndexTag >, boost::multi_index::const_mem_fun< BaseStampedElement, boost::posix_time::ptime, &BaseStampedElement::getModificationTime > > > > StampedValueCollection
Multi index container for StampedValue.
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:30
std::map< std::string, isc::data::Element::types > SimpleKeywords
This specifies all accepted keywords with their types.
boost::shared_ptr< Server > ServerPtr
Shared pointer to the Server class.
Definition server.h:22
boost::shared_ptr< Subnet4 > Subnet4Ptr
A pointer to a Subnet4 object.
Definition subnet.h:458
boost::shared_ptr< CfgOptionDef > CfgOptionDefPtr
Non-const pointer.
boost::shared_ptr< Subnet6 > Subnet6Ptr
A pointer to a Subnet6 object.
Definition subnet.h:623
boost::shared_ptr< OptionDefinition > OptionDefinitionPtr
Pointer to option definition object.
boost::shared_ptr< SharedNetwork6 > SharedNetwork6Ptr
Pointer to SharedNetwork6 object.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
Definition subnet_id.h:25
boost::shared_ptr< SharedNetwork4 > SharedNetwork4Ptr
Pointer to SharedNetwork4 object.
Defines the logger used by the top-level component of kea-lfc.