Kea 3.3.4
cb_cmds_impl.cc
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#include <config.h>
8
10#include <cc/data.h>
11#include <cc/stamped_value.h>
13#include <dhcpsrv/cfgmgr.h>
17#include <hooks/hooks.h>
18
19#include <set>
20
22#include <cb_cmds/cb_parsers.h>
23
24using namespace isc::config;
25using namespace isc::data;
26using namespace isc::dhcp;
27using namespace isc::db;
28using namespace isc::hooks;
29
30namespace isc {
31namespace cb {
32
33BackendSelector
35 auto remote = args->get("remote");
36 if (!remote) {
37 return (BackendSelector());
38 }
39
40 return (BackendSelector(remote));
41}
42
45 ServerTagsParse tags_parse) const {
46 auto server_tags = args->get("server-tags");
47 if (server_tags) {
48 if (tags_parse == ServerTagsParse::TAGS_FORBIDDEN) {
49 isc_throw(BadValue, "'server-tags' parameter is forbidden");
50 }
51
52 if (server_tags->getType() != Element::list) {
53 isc_throw(BadValue, "'server-tags' parameter must be a list");
54 }
55
56 auto server_tags_list = server_tags->listValue();
57
58 // Always expecting at least one server tag.
59 if (server_tags_list.empty()) {
60 isc_throw(BadValue, "'server-tags' list must not be empty");
61 }
62
63 // Special [ null ] value for UNASSIGNED.
64 if ((server_tags_list[0]->getType() == Element::null) &&
65 (server_tags_list.size() == 1)) {
67 }
68
69 std::set<std::string> server_tags_set;
70 for (auto const& tag : server_tags_list) {
71 if (tag->getType() != Element::string) {
72 isc_throw(BadValue, "when the 'server-tags' list contains "
73 "multiple elements all these elements must "
74 "have the string type");
75 }
76 ServerTag server_tag(tag->stringValue());
77 server_tags_set.insert(server_tag.get());
78 }
79
80 if (server_tags_set.size() == 1) {
81 return (ServerSelector::ONE(*server_tags_set.begin()));
82
83 } else {
84 return (ServerSelector::MULTIPLE(server_tags_set));
85 }
86 } else if (tags_parse == ServerTagsParse::TAGS_REQUIRED) {
87 isc_throw(BadValue, "'server-tags' parameter is mandatory");
88 }
89 return (ServerSelector::ANY());
90}
91
94 auto action = args->get("subnets-action");
95 if (!action) {
97 }
98 if (action->getType() != Element::string) {
99 isc_throw(BadValue, "'subnets-action' parameter must be a string");
100 }
101 std::string action_txt = action->stringValue();
102 if (action_txt == "keep") {
104 } else if (action_txt == "delete") {
106 } else {
107 isc_throw(BadValue, "unknown 'subnets-action' parameter value: '"
108 << action_txt << "', possible vales are 'keep' (default)"
109 << " and 'delete'");
110 }
111}
112
115 auto do_include = args->get("subnets-include");
116 if (!do_include) {
118 }
119 if (do_include->getType() != Element::string) {
120 isc_throw(BadValue, "'subnets-include' parameter must be a string");
121 }
122 std::string include_txt = do_include->stringValue();
123 if (include_txt == "no") {
125 } else if (include_txt == "full") {
127 } else {
128 isc_throw(BadValue, "unknown 'subnets-include' parameter value: '"
129 << include_txt << "', possible values are 'no' (default)"
130 << " and 'full'");
131 }
132}
133
136
137} // end of namespace isc::cb
138} // end of namespace isc
Parsers for a subset of an object specification, e.g.
@ null
Definition data.h:156
@ list
Definition data.h:159
@ string
Definition data.h:157
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
ConfigCmdsImpl()
Constructor.
boost::shared_ptr< ConfigCmdsParser > parser_
Shared pointer to the commands parser.
This parser class contains the common logic for various callouts to parse and validate the contents o...
ServerTagsParse
Server selector parsing.
@ TAGS_REQUIRED
server-tags is required
@ TAGS_FORBIDDEN
server-tags is not allowed
SubnetsInclude
Subnets actions for shared network get command.
db::ServerSelector getServerSelector(const data::ConstElementPtr &args, ServerTagsParse tags_parse) const
Creates server selector from the command's arguments.
SubnetsAction
Subnets actions for shared network delete.
@ ACTION_KEEP
keep subnets (default)
@ ACTION_DELETE
delete subnets
SubnetsAction getSubnetsAction(const data::ConstElementPtr &args) const
Creates subnets action from the command's arguments.
SubnetsInclude getSubnetsInclude(const data::ConstElementPtr &args) const
Creates SubnetsInclude from the command's arguments.
db::BackendSelector getBackendSelector(const data::ConstElementPtr &args) const
Creates backend selector from the command's arguments.
Represents a server tag.
Definition server_tag.h:25
std::string get() const
Returns server tag as string.
Definition server_tag.h:51
Config Backend selector.
Server selector for associating objects in a database with specific servers.
static ServerSelector MULTIPLE(const std::set< std::string > &server_tags)
Factory returning "multiple servers" selector.
static ServerSelector ANY()
Factory returning "any server" selector.
static ServerSelector ONE(const std::string &server_tag)
Factory returning selector of one server.
static ServerSelector UNASSIGNED()
Factory returning "unassigned" server selector.
This file contains several functions and constants that are used for handling commands and responses ...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:30
Defines the logger used by the top-level component of kea-lfc.