Kea 2.2.0
adaptor_option.cc
Go to the documentation of this file.
1// Copyright (C) 2018-2022 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
12
13using namespace std;
14using namespace isc::data;
15using namespace isc::dhcp;
16
17namespace isc {
18namespace yang {
19
21}
22
24}
25
26void
27AdaptorOption::setSpace(ElementPtr option, const string& space) {
28 if (!option->contains("space")) {
29 option->set("space", Element::create(space));
30 }
31}
32
33void
35 if (!option->contains("type")) {
36 isc_throw(MissingKey, "missing type in option definition "
37 << option->str());
38 }
39}
40
41void
43 if (!option->contains("code")) {
44 isc_throw(MissingKey, "missing code in option " << option->str());
45 }
46}
47
48void
50 ConstElementPtr name = option->get("name");
51 if (name) {
52 ConstElementPtr space = option->get("space");
53 ConstElementPtr code = option->get("code");
54 string index = space->stringValue() + "@" + name->stringValue();
55 uint16_t val = static_cast<uint16_t>(code->intValue());
56 codes.insert(std::pair<string, uint16_t>(index, val));
57 }
58}
59
60void
62 ConstElementPtr code = option->get("code");
63 if (!code) {
64 ConstElementPtr name = option->get("name");
65 if (!name) {
66 isc_throw(MissingKey, "missing name and code in option "
67 << option->str());
68 }
69 ConstElementPtr space = option->get("space");
70 string index = space->stringValue() + "@" + name->stringValue();
71 OptionCodes::const_iterator it = codes.find(index);
72 if (it == codes.end()) {
73 isc_throw(MissingKey, "can't get code from option "
74 << option->str());
75 }
76 option->set("code", Element::create(static_cast<int>(it->second)));
77 }
78}
79
80void
81AdaptorOption::initCodes(OptionCodes& codes, const string& space) {
82 if (space == DHCP4_OPTION_SPACE) {
83 initCodesInternal(codes, space, STANDARD_V4_OPTION_DEFINITIONS,
84 STANDARD_V4_OPTION_DEFINITIONS_SIZE);
85 initCodesInternal(codes, space, LAST_RESORT_V4_OPTION_DEFINITIONS,
86 LAST_RESORT_V4_OPTION_DEFINITIONS_SIZE);
87 initCodesInternal(codes, "vendor-4491",
90 } else if (space == DHCP6_OPTION_SPACE) {
91 initCodesInternal(codes, space, STANDARD_V6_OPTION_DEFINITIONS,
92 STANDARD_V6_OPTION_DEFINITIONS_SIZE);
93 initCodesInternal(codes, "vendor-4491",
97 MAPE_V6_OPTION_DEFINITIONS,
98 MAPE_V6_OPTION_DEFINITIONS_SIZE);
100 MAPT_V6_OPTION_DEFINITIONS,
101 MAPT_V6_OPTION_DEFINITIONS_SIZE);
103 LW_V6_OPTION_DEFINITIONS,
104 LW_V6_OPTION_DEFINITIONS_SIZE);
106 V4V6_RULE_OPTION_DEFINITIONS,
107 V4V6_RULE_OPTION_DEFINITIONS_SIZE);
109 V4V6_BIND_OPTION_DEFINITIONS,
110 V4V6_BIND_OPTION_DEFINITIONS_SIZE);
111 initCodesInternal(codes, "vendor-2495",
112 ISC_V6_OPTION_DEFINITIONS,
113 ISC_V6_OPTION_DEFINITIONS_SIZE);
114 }
115}
116
117void
119 const OptionDefParams* params,
120 size_t params_size) {
121 for (size_t i = 0; i < params_size; ++i) {
122 string index = space + "@" + params[i].name;
123 codes.insert(std::pair<string, uint16_t>(index, params[i].code));
124 }
125}
126
127} // end of namespace isc::yang
128} // end of namespace isc
static void setCode(isc::data::ElementPtr option, const OptionCodes &codes)
Set code from name and definitions.
static void initCodes(OptionCodes &codes, const std::string &space)
Initialize code map.
static void setSpace(isc::data::ElementPtr option, const std::string &space)
Set space.
static void checkType(isc::data::ConstElementPtr option)
Checks if type is specified in option definition.
static void initCodesInternal(OptionCodes &codes, const std::string &space, const isc::dhcp::OptionDefParams *params, size_t params_size)
Initialize code map from option definition parameters.
virtual ~AdaptorOption()
Destructor.
static void collect(isc::data::ConstElementPtr option, OptionCodes &codes)
Collect definition.
static void checkCode(isc::data::ConstElementPtr option)
Check if code is specified in option defintion.
Missing key error.
Definition: adaptor.h:17
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
const OptionDefParams DOCSIS3_V4_OPTION_DEFINITIONS[]
Definitions of standard DHCPv4 options.
const int DOCSIS3_V6_OPTION_DEFINITIONS_SIZE
Number of option definitions defined.
const int DOCSIS3_V4_OPTION_DEFINITIONS_SIZE
Number of option definitions defined.
const OptionDefParams DOCSIS3_V6_OPTION_DEFINITIONS[]
Definitions of standard DHCPv6 options.
std::map< std::string, uint16_t > OptionCodes
Map for DHCP option definitions handling code and an index built from space and name.
Defines the logger used by the top-level component of kea-lfc.
#define V4V6_BIND_OPTION_SPACE
#define DHCP4_OPTION_SPACE
global std option spaces
#define V4V6_RULE_OPTION_SPACE
#define MAPE_V6_OPTION_SPACE
#define LW_V6_OPTION_SPACE
#define DHCP6_OPTION_SPACE
#define MAPT_V6_OPTION_SPACE
Parameters being used to make up an option definition.