summaryrefslogtreecommitdiffstats
path: root/src/lib/yang/adaptor_option.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 12:15:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 12:15:43 +0000
commitf5f56e1a1c4d9e9496fcb9d81131066a964ccd23 (patch)
tree49e44c6f87febed37efb953ab5485aa49f6481a7 /src/lib/yang/adaptor_option.cc
parentInitial commit. (diff)
downloadisc-kea-f5f56e1a1c4d9e9496fcb9d81131066a964ccd23.tar.xz
isc-kea-f5f56e1a1c4d9e9496fcb9d81131066a964ccd23.zip
Adding upstream version 2.4.1.upstream/2.4.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/lib/yang/adaptor_option.cc')
-rw-r--r--src/lib/yang/adaptor_option.cc123
1 files changed, 123 insertions, 0 deletions
diff --git a/src/lib/yang/adaptor_option.cc b/src/lib/yang/adaptor_option.cc
new file mode 100644
index 0000000..e0405c1
--- /dev/null
+++ b/src/lib/yang/adaptor_option.cc
@@ -0,0 +1,123 @@
+// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <dhcp/docsis3_option_defs.h>
+#include <dhcp/std_option_defs.h>
+#include <yang/adaptor_option.h>
+#include <yang/netconf_error.h>
+
+using namespace std;
+using namespace isc::data;
+using namespace isc::dhcp;
+
+namespace isc {
+namespace yang {
+
+void
+AdaptorOption::setSpace(ElementPtr option, const string& space) {
+ if (!option->contains("space")) {
+ option->set("space", Element::create(space));
+ }
+}
+
+void
+AdaptorOption::checkType(ConstElementPtr option) {
+ if (!option->contains("type")) {
+ isc_throw(MissingKey, "missing type in option definition "
+ << option->str());
+ }
+}
+
+void
+AdaptorOption::checkCode(ConstElementPtr option) {
+ if (!option->contains("code")) {
+ isc_throw(MissingKey, "missing code in option " << option->str());
+ }
+}
+
+void
+AdaptorOption::collect(ConstElementPtr option, OptionCodes& codes) {
+ ConstElementPtr name = option->get("name");
+ if (name) {
+ ConstElementPtr space = option->get("space");
+ ConstElementPtr code = option->get("code");
+ string index = space->stringValue() + "@" + name->stringValue();
+ uint16_t val = static_cast<uint16_t>(code->intValue());
+ codes.insert(pair<string, uint16_t>(index, val));
+ }
+}
+
+void
+AdaptorOption::setCode(ElementPtr option, const OptionCodes& codes) {
+ ConstElementPtr code = option->get("code");
+ if (!code) {
+ ConstElementPtr name = option->get("name");
+ if (!name) {
+ isc_throw(MissingKey, "missing name and code in option "
+ << option->str());
+ }
+ ConstElementPtr space = option->get("space");
+ string index = space->stringValue() + "@" + name->stringValue();
+ OptionCodes::const_iterator it = codes.find(index);
+ if (it == codes.end()) {
+ isc_throw(MissingKey, "can't get code from option "
+ << option->str());
+ }
+ option->set("code", Element::create(static_cast<int>(it->second)));
+ }
+}
+
+void
+AdaptorOption::initCodes(OptionCodes& codes, const string& space) {
+ if (space == DHCP4_OPTION_SPACE) {
+ initCodesInternal(codes, space, STANDARD_V4_OPTION_DEFINITIONS,
+ STANDARD_V4_OPTION_DEFINITIONS_SIZE);
+ initCodesInternal(codes, space, LAST_RESORT_V4_OPTION_DEFINITIONS,
+ LAST_RESORT_V4_OPTION_DEFINITIONS_SIZE);
+ initCodesInternal(codes, "vendor-4491",
+ DOCSIS3_V4_OPTION_DEFINITIONS,
+ DOCSIS3_V4_OPTION_DEFINITIONS_SIZE);
+ } else if (space == DHCP6_OPTION_SPACE) {
+ initCodesInternal(codes, space, STANDARD_V6_OPTION_DEFINITIONS,
+ STANDARD_V6_OPTION_DEFINITIONS_SIZE);
+ initCodesInternal(codes, "vendor-4491",
+ DOCSIS3_V6_OPTION_DEFINITIONS,
+ DOCSIS3_V6_OPTION_DEFINITIONS_SIZE);
+ initCodesInternal(codes, MAPE_V6_OPTION_SPACE,
+ MAPE_V6_OPTION_DEFINITIONS,
+ MAPE_V6_OPTION_DEFINITIONS_SIZE);
+ initCodesInternal(codes, MAPT_V6_OPTION_SPACE,
+ MAPT_V6_OPTION_DEFINITIONS,
+ MAPT_V6_OPTION_DEFINITIONS_SIZE);
+ initCodesInternal(codes, LW_V6_OPTION_SPACE,
+ LW_V6_OPTION_DEFINITIONS,
+ LW_V6_OPTION_DEFINITIONS_SIZE);
+ initCodesInternal(codes, V4V6_RULE_OPTION_SPACE,
+ V4V6_RULE_OPTION_DEFINITIONS,
+ V4V6_RULE_OPTION_DEFINITIONS_SIZE);
+ initCodesInternal(codes, V4V6_BIND_OPTION_SPACE,
+ V4V6_BIND_OPTION_DEFINITIONS,
+ V4V6_BIND_OPTION_DEFINITIONS_SIZE);
+ initCodesInternal(codes, "vendor-2495",
+ ISC_V6_OPTION_DEFINITIONS,
+ ISC_V6_OPTION_DEFINITIONS_SIZE);
+ }
+}
+
+void
+AdaptorOption::initCodesInternal(OptionCodes& codes, const string& space,
+ const OptionDefParams* params,
+ size_t params_size) {
+ for (size_t i = 0; i < params_size; ++i) {
+ string index = space + "@" + params[i].name;
+ codes.insert(pair<string, uint16_t>(index, params[i].code));
+ }
+}
+
+} // namespace yang
+} // namespace isc