Kea 3.3.3
radius_access.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 RADIUS_ACCESS_H
8#define RADIUS_ACCESS_H
9
10#include <dhcp/pkt4.h>
11#include <dhcp/pkt6.h>
12#include <hooks/hooks.h>
15
16#include <map>
17#include <mutex>
18
19namespace isc {
20namespace radius {
21
25template <class PktPtrType>
27public:
28
32 RadiusAuthPendingRequest(PktPtrType query) : query_(query) { }
33
35 PktPtrType query_;
36};
37
41template <class PktPtrType>
43 boost::shared_ptr<RadiusAuthPendingRequest<PktPtrType>>;
44
48template <class PktPtrType>
50public:
51
55 size_t size() const {
56 return (map_.size());
57 }
58
60 void clear() {
61 map_.clear();
62 }
63
69 get(const std::vector<uint8_t>& id) const {
70 auto const& it = map_.find(id);
71 if (it != map_.end()) {
72 return (it->second);
73 } else {
75 }
76 }
77
84 void set(const std::vector<uint8_t>& id, PktPtrType query) {
87 }
88
92 void remove(const std::vector<uint8_t>& id) {
93 static_cast<void>(map_.erase(id));
94 }
95
96private:
98 std::map<std::vector<uint8_t>, RadiusAuthPendingRequestPtr<PktPtrType>> map_;
99
100public:
104 std::mutex mutex_;
105};
106
112public:
113
119 RadiusAuthEnv(uint32_t subnet_id,
120 const std::vector<uint8_t>& id,
121 AttributesPtr send_attrs);
122
124 uint32_t subnet_id_;
125
127 const std::vector<uint8_t> id_;
128
131};
132
138public:
139
144 RadiusAuthHandler(RadiusAuthEnv env, const CallbackAuth& callback);
145
147 virtual ~RadiusAuthHandler() = default;
148
150 void start();
151
154
155protected:
156
159};
160
162typedef boost::shared_ptr<RadiusAuthHandler> RadiusAuthHandlerPtr;
163
166public:
167
169 RadiusAccess();
170
172 virtual ~RadiusAccess() = default;
173
180 bool getIdentifier(dhcp::Pkt4& query, std::vector<uint8_t>& id,
181 std::string& text);
182
189 bool getIdentifier(dhcp::Pkt6& query, std::vector<uint8_t>& id,
190 std::string& text);
191
199 RadiusAuthHandlerPtr buildAuth(dhcp::Pkt4& query, uint32_t subnet_id,
200 const std::vector<uint8_t>& id,
201 const std::string& text);
202
210 RadiusAuthHandlerPtr buildAuth(dhcp::Pkt6& query, uint32_t subnet_id,
211 const std::vector<uint8_t>& id,
212 const std::string& text);
213
228 static bool reselectSubnet(const dhcp::Pkt4Ptr& query, uint32_t& subnet_id,
229 bool& both_global, const std::string& cclass);
230
245 static bool reselectSubnet(const dhcp::Pkt6Ptr& query, uint32_t& subnet_id,
246 bool& both_global, const std::string& cclass);
247
261 static bool reselectSubnet(const isc::dhcp::Pkt4Ptr& query,
262 uint32_t& subnet_id,
263 bool& both_global,
264 const asiolink::IOAddress& address);
265
279 static bool reselectSubnet(const isc::dhcp::Pkt6Ptr& query,
280 uint32_t& subnet_id,
281 bool& both_global,
282 const asiolink::IOAddress& address);
283
291 static void terminate4(RadiusAuthEnv env, int result,
292 AttributesPtr recv_attrs);
293
301 static void terminate6(RadiusAuthEnv env, int result,
302 AttributesPtr recv_attrs);
303
311 static void terminate4Internal(RadiusAuthEnv& env, int result,
312 AttributesPtr recv_attrs,
313 dhcp::Pkt4Ptr& query, bool& drop);
314
322 static void terminate6Internal(RadiusAuthEnv& env, int result,
323 AttributesPtr recv_attrs,
324 dhcp::Pkt6Ptr& query, bool& drop);
325
328
331
335 void setIdleTimer();
336
338 static void IdleTimerCallback();
339};
340
341} // end of namespace isc::radius
342} // end of namespace isc
343
344#endif
Represents DHCPv4 packet.
Definition pkt4.h:37
Represents a DHCPv6 packet.
Definition pkt6.h:44
static void terminate6Internal(RadiusAuthEnv &env, int result, AttributesPtr recv_attrs, dhcp::Pkt6Ptr &query, bool &drop)
Termination callback body - IPv6.
static void terminate4Internal(RadiusAuthEnv &env, int result, AttributesPtr recv_attrs, dhcp::Pkt4Ptr &query, bool &drop)
Termination callback body - IPv4.
RadiusAuthPendingRequests< dhcp::Pkt6Ptr > requests6_
Pending RADIUS access requests - IPv6.
static void terminate4(RadiusAuthEnv env, int result, AttributesPtr recv_attrs)
Termination callback - IPv4.
static bool reselectSubnet(const dhcp::Pkt4Ptr &query, uint32_t &subnet_id, bool &both_global, const std::string &cclass)
Subnet reselect - class/pool IPv4.
static void terminate6(RadiusAuthEnv env, int result, AttributesPtr recv_attrs)
Termination callback - IPv6.
virtual ~RadiusAccess()=default
Destructor.
bool getIdentifier(dhcp::Pkt4 &query, std::vector< uint8_t > &id, std::string &text)
Get Identifier – IPv4.
void setIdleTimer()
Set idle timer.
static void IdleTimerCallback()
Idle timer callback.
RadiusAuthPendingRequests< dhcp::Pkt4Ptr > requests4_
Pending RADIUS access requests - IPv4.
RadiusAuthHandlerPtr buildAuth(dhcp::Pkt4 &query, uint32_t subnet_id, const std::vector< uint8_t > &id, const std::string &text)
Build RadiusAuth handler for Access-Request - IPv4.
Class of Radius access environments.
RadiusAuthEnv(uint32_t subnet_id, const std::vector< uint8_t > &id, AttributesPtr send_attrs)
Constructor.
const std::vector< uint8_t > id_
Identifier.
uint32_t subnet_id_
Subnet Id (aka client/NAS port).
AttributesPtr send_attrs_
Attributes to send.
RadiusAuthHandler(RadiusAuthEnv env, const CallbackAuth &callback)
Constructor.
virtual ~RadiusAuthHandler()=default
Destructor.
RadiusAuthEnv env_
Environment.
void start()
Start communication.
RadiusAsyncAuthPtr auth_
Pointer to the communication class.
Class of pending Radius access request.
PktPtrType query_
The query which triggered the access request.
RadiusAuthPendingRequest(PktPtrType query)
Constructor.
Class of pending Radius access requests.
RadiusAuthPendingRequestPtr< PktPtrType > get(const std::vector< uint8_t > &id) const
Get a pending access request from the map.
void set(const std::vector< uint8_t > &id, PktPtrType query)
Set a pending access request into the map.
size_t size() const
Size of the map.
void remove(const std::vector< uint8_t > &id)
Remove a pending access request from the map.
RadiusService(const std::string &name)
Constructor.
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
Definition pkt4.h:556
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
Definition pkt6.h:31
boost::shared_ptr< Attributes > AttributesPtr
Shared pointers to attribute collection.
boost::shared_ptr< RadiusAuthPendingRequest< PktPtrType > > RadiusAuthPendingRequestPtr
Pointer to a pending Radius access request.
boost::shared_ptr< RadiusAsyncAuth > RadiusAsyncAuthPtr
Pointer to asynchronous authentication.
std::function< void(int, AttributesPtr)> CallbackAuth
Type of callback for authentication termination.
boost::shared_ptr< RadiusAuthHandler > RadiusAuthHandlerPtr
Type of pointers to Radius access communication handler.
Defines the logger used by the top-level component of kea-lfc.