Kea 3.3.3
cfg_attribute.h
Go to the documentation of this file.
1// Copyright (C) 2020-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 CFG_ATTRIBUTE_H
8#define CFG_ATTRIBUTE_H
9
10#include <cc/cfg_to_element.h>
11#include <cc/data.h>
12#include <dhcp/pkt.h>
13#include <eval/token.h>
16#include <util/buffer.h>
17
18#include <map>
19#include <vector>
20
21#include <boost/multi_index/composite_key.hpp>
22#include <boost/multi_index/hashed_index.hpp>
23#include <boost/multi_index/mem_fun.hpp>
24#include <boost/multi_index_container.hpp>
25#include <boost/shared_ptr.hpp>
26
27namespace isc {
28namespace radius {
29
41public:
42
46
47 // @brief Destructor.
48 virtual ~CfgAttributes() {
49 clear();
50 }
51
55 bool empty() const {
56 return (container_.empty());
57 }
58
62 size_t size() const {
63 return (container_.size());
64 }
65
72 void add(const AttrDefPtr& def,
73 const ConstAttributePtr& attr,
74 const dhcp::ExpressionPtr& expr,
75 const std::string& test);
76
81 void add(const AttrDefPtr& def, const ConstAttributePtr& attr) {
82 add(def, attr, dhcp::ExpressionPtr(), "");
83 }
84
92 bool del(const uint8_t type, const uint32_t vendor = 0);
93
95 void clear() {
96 container_.clear();
97 }
98
105 size_t count(const uint8_t type, const uint32_t vendor = 0) const {
106 return (container_.count(boost::make_tuple(vendor, type)));
107 }
108
114 AttrDefPtr getDef(const uint8_t type, const uint32_t vendor = 0) const;
115
121 ConstAttributePtr get(const uint8_t type, const uint32_t vendor = 0) const;
122
128 dhcp::ExpressionPtr getExpr(const uint8_t type,
129 const uint32_t vendor = 0) const;
130
136 std::string getTest(const uint8_t type, const uint32_t vendor = 0) const;
137
141 Attributes getAll() const;
142
152
156 data::ElementPtr toElement() const override;
157
158protected:
161 public:
169 const ConstAttributePtr& attr,
170 const dhcp::ExpressionPtr& expr,
171 const std::string& test)
172 : def_(def), attr_(attr), expr_(expr), test_(test) {
173 if (!def) {
174 isc_throw(BadValue, "no attribute definition");
175 }
176 if (expr || !test.empty()) {
177 if (attr) {
178 isc_throw(BadValue, "once of attribute or test");
179 }
180 if (!expr || test.empty()) {
181 isc_throw(BadValue, "missing expression or test");
182 }
183 } else if (!attr) {
184 isc_throw(BadValue, "no attribute and test");
185 }
186 }
187
190
193
196
198 std::string test_;
199
201 uint8_t getType() const {
202 if (!def_) {
203 isc_throw(BadValue, "no attribute definition");
204 }
205 return (def_->type_);
206 }
207
209 uint32_t getVendor() const {
210 if (!def_) {
211 isc_throw(BadValue, "no attribute definition");
212 }
213 return (def_->vendor_);
214 }
215 };
216
218 boost::multi_index_container<
219 // This container stores AttributeValue objects.
220 AttributeValue,
221 // Start specification of indexes here.
222 boost::multi_index::indexed_by<
223 // Hash index for by vendor and type.
224 boost::multi_index::hashed_non_unique<
225 boost::multi_index::composite_key<
226 AttributeValue,
227 boost::multi_index::const_mem_fun<
228 AttributeValue, uint32_t, &AttributeValue::getVendor
229 >,
230 boost::multi_index::const_mem_fun<
231 AttributeValue, uint8_t, &AttributeValue::getType
232 >
233 >
234 >
235 >
237};
238
239} // end of namespace isc::radius
240} // end of namespace isc
241
242#endif
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Base class for classes representing DHCP messages.
Definition pkt.h:162
Collection of attributes.
AttrDefPtr def_
Pointer to the attribute definition (required).
ConstAttributePtr attr_
Pointer to the attribute.
uint8_t getType() const
Return the type.
std::string test_
Original expression.
dhcp::ExpressionPtr expr_
Expression to compute the value.
uint32_t getVendor() const
Return the vendor.
AttributeValue(const AttrDefPtr &def, const ConstAttributePtr &attr, const dhcp::ExpressionPtr &expr, const std::string &test)
Constructor.
ConstAttributePtr get(const uint8_t type, const uint32_t vendor=0) const
Get instance of the attribute in the configuration.
dhcp::ExpressionPtr getExpr(const uint8_t type, const uint32_t vendor=0) const
Returns the expression of an attribute.
Attributes getAll() const
Get all attributes in the configuration.
void add(const AttrDefPtr &def, const ConstAttributePtr &attr, const dhcp::ExpressionPtr &expr, const std::string &test)
Adds instance of the attribute to the configuration.
size_t size() const
Returns the number of elements.
size_t count(const uint8_t type, const uint32_t vendor=0) const
Counts instance of the attribute in the configuration.
AttrDefPtr getDef(const uint8_t type, const uint32_t vendor=0) const
Returns the definition of an attribute.
bool empty() const
Checks if the object is empty.
bool del(const uint8_t type, const uint32_t vendor=0)
Deletes an attribute from the configuration.
void add(const AttrDefPtr &def, const ConstAttributePtr &attr)
Adds instance of the attribute to the configuration.
std::string getTest(const uint8_t type, const uint32_t vendor=0) const
Returns the text expression of an attribute.
boost::multi_index_container< AttributeValue, boost::multi_index::indexed_by< boost::multi_index::hashed_non_unique< boost::multi_index::composite_key< AttributeValue, boost::multi_index::const_mem_fun< AttributeValue, uint32_t, &AttributeValue::getVendor >, boost::multi_index::const_mem_fun< AttributeValue, uint8_t, &AttributeValue::getType > > > > > container_
The container.
void clear()
Clear the container.
Attributes getEvalAll(dhcp::Pkt &pkt)
Get all evaluated attributes in the configuration.
data::ElementPtr toElement() const override
Unparse configuration.
if(!(yy_init))
Definition d2_lexer.cc:1515
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< Element > ElementPtr
Definition data.h:29
boost::shared_ptr< Expression > ExpressionPtr
Definition token.h:33
boost::shared_ptr< const Attribute > ConstAttributePtr
boost::shared_ptr< AttrDef > AttrDefPtr
Shared pointers to Attribute definition.
Defines the logger used by the top-level component of kea-lfc.
Abstract class for configuration Cfg_* classes.