Kea 3.1.3
cfg_attribute.h
Go to the documentation of this file.
1// Copyright (C) 2020-2025 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 <client_attribute.h>
12#include <cc/data.h>
13#include <cc/cfg_to_element.h>
14#include <dhcp/pkt.h>
15#include <eval/token.h>
16#include <util/buffer.h>
17#include <boost/multi_index_container.hpp>
18#include <boost/multi_index/hashed_index.hpp>
19#include <boost/multi_index/mem_fun.hpp>
20#include <boost/multi_index/composite_key.hpp>
21#include <boost/shared_ptr.hpp>
22#include <vector>
23#include <map>
24
25namespace isc {
26namespace radius {
27
39public:
40
44
45 // @brief Destructor.
46 virtual ~CfgAttributes() {
47 clear();
48 }
49
53 bool empty() const {
54 return (container_.empty());
55 }
56
60 size_t size() const {
61 return (container_.size());
62 }
63
70 void add(const AttrDefPtr& def,
71 const ConstAttributePtr& attr,
72 const dhcp::ExpressionPtr& expr,
73 const std::string& test);
74
79 void add(const AttrDefPtr& def, const ConstAttributePtr& attr) {
80 add(def, attr, dhcp::ExpressionPtr(), "");
81 }
82
90 bool del(const uint8_t type, const uint32_t vendor = 0);
91
93 void clear() {
94 container_.clear();
95 }
96
103 size_t count(const uint8_t type, const uint32_t vendor = 0) const {
104 return (container_.count(boost::make_tuple(vendor, type)));
105 }
106
112 AttrDefPtr getDef(const uint8_t type, const uint32_t vendor = 0) const;
113
119 ConstAttributePtr get(const uint8_t type, const uint32_t vendor = 0) const;
120
126 dhcp::ExpressionPtr getExpr(const uint8_t type,
127 const uint32_t vendor = 0) const;
128
134 std::string getTest(const uint8_t type, const uint32_t vendor = 0) const;
135
139 Attributes getAll() const;
140
150
154 data::ElementPtr toElement() const override;
155
156protected:
159 public:
167 const ConstAttributePtr& attr,
168 const dhcp::ExpressionPtr& expr,
169 const std::string& test)
170 : def_(def), attr_(attr), expr_(expr), test_(test) {
171 if (!def) {
172 isc_throw(BadValue, "no attribute definition");
173 }
174 if (expr || !test.empty()) {
175 if (attr) {
176 isc_throw(BadValue, "once of attribute or test");
177 }
178 if (!expr || test.empty()) {
179 isc_throw(BadValue, "missing expression or test");
180 }
181 } else if (!attr) {
182 isc_throw(BadValue, "no attribute and test");
183 }
184 }
185
188
191
194
196 std::string test_;
197
199 uint8_t getType() const {
200 if (!def_) {
201 isc_throw(BadValue, "no attribute definition");
202 }
203 return (def_->type_);
204 }
205
207 uint32_t getVendor() const {
208 if (!def_) {
209 isc_throw(BadValue, "no attribute definition");
210 }
211 return (def_->vendor_);
212 }
213 };
214
216 boost::multi_index_container<
217 // This container stores AttributeValue objects.
218 AttributeValue,
219 // Start specification of indexes here.
220 boost::multi_index::indexed_by<
221 // Hash index for by vendor and type.
222 boost::multi_index::hashed_non_unique<
223 boost::multi_index::composite_key<
224 AttributeValue,
225 boost::multi_index::const_mem_fun<
226 AttributeValue, uint32_t, &AttributeValue::getVendor
227 >,
228 boost::multi_index::const_mem_fun<
229 AttributeValue, uint8_t, &AttributeValue::getType
230 >
231 >
232 >
233 >
235};
236
237} // end of namespace isc::radius
238} // end of namespace isc
239
240#endif
if(!(yy_init))
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:161
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.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
boost::shared_ptr< Expression > ExpressionPtr
Definition token.h:31
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.