Kea 3.1.1
radius_access.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 RADIUS_ACCESS_H
8#define RADIUS_ACCESS_H
9
10#include <hooks/hooks.h>
11#include <dhcp/pkt4.h>
12#include <dhcp/pkt6.h>
13#include <radius_service.h>
14#include <radius_request.h>
15#include <map>
16#include <mutex>
17
18namespace isc {
19namespace radius {
20
24template <class PktPtrType>
26public:
27
31 RadiusAuthPendingRequest(PktPtrType query) : query_(query) { }
32
34 PktPtrType query_;
35};
36
40template <class PktPtrType>
42 boost::shared_ptr<RadiusAuthPendingRequest<PktPtrType>>;
43
47template <class PktPtrType>
49public:
50
54 size_t size() const {
55 return (map_.size());
56 }
57
59 void clear() {
60 map_.clear();
61 }
62
68 get(const std::vector<uint8_t>& id) const {
69 auto const& it = map_.find(id);
70 if (it != map_.end()) {
71 return (it->second);
72 } else {
74 }
75 }
76
83 void set(const std::vector<uint8_t>& id, PktPtrType query) {
86 }
87
91 void remove(const std::vector<uint8_t>& id) {
92 static_cast<void>(map_.erase(id));
93 }
94
95private:
97 std::map<std::vector<uint8_t>, RadiusAuthPendingRequestPtr<PktPtrType>> map_;
98
99public:
103 std::mutex mutex_;
104};
105
111public:
112
118 RadiusAuthEnv(uint32_t subnet_id,
119 const std::vector<uint8_t>& id,
120 AttributesPtr send_attrs);
121
123 uint32_t subnet_id_;
124
126 const std::vector<uint8_t> id_;
127
130};
131
137public:
138
143 RadiusAuthHandler(RadiusAuthEnv env, const CallbackAuth& callback);
144
146 virtual ~RadiusAuthHandler() = default;
147
149 void start();
150
153
154protected:
155
158};
159
161typedef boost::shared_ptr<RadiusAuthHandler> RadiusAuthHandlerPtr;
162
165public:
166
168 RadiusAccess();
169
171 virtual ~RadiusAccess() = default;
172
179 bool getIdentifier(dhcp::Pkt4& query, std::vector<uint8_t>& id,
180 std::string& text);
181
188 bool getIdentifier(dhcp::Pkt6& query, std::vector<uint8_t>& id,
189 std::string& text);
190
198 RadiusAuthHandlerPtr buildAuth(dhcp::Pkt4& query, uint32_t subnet_id,
199 const std::vector<uint8_t>& id,
200 const std::string& text);
201
209 RadiusAuthHandlerPtr buildAuth(dhcp::Pkt6& query, uint32_t subnet_id,
210 const std::vector<uint8_t>& id,
211 const std::string& text);
212
227 static bool reselectSubnet(const dhcp::Pkt4Ptr& query, uint32_t& subnet_id,
228 bool& both_global, const std::string& cclass);
229
244 static bool reselectSubnet(const dhcp::Pkt6Ptr& query, uint32_t& subnet_id,
245 bool& both_global, const std::string& cclass);
246
260 static bool reselectSubnet(const isc::dhcp::Pkt4Ptr& query,
261 uint32_t& subnet_id,
262 bool& both_global,
263 const asiolink::IOAddress& address);
264
278 static bool reselectSubnet(const isc::dhcp::Pkt6Ptr& query,
279 uint32_t& subnet_id,
280 bool& both_global,
281 const asiolink::IOAddress& address);
282
290 static void terminate4(RadiusAuthEnv env, int result,
291 AttributesPtr recv_attrs);
292
300 static void terminate6(RadiusAuthEnv env, int result,
301 AttributesPtr recv_attrs);
302
310 static void terminate4Internal(RadiusAuthEnv& env, int result,
311 AttributesPtr recv_attrs,
312 dhcp::Pkt4Ptr& query, bool& drop);
313
321 static void terminate6Internal(RadiusAuthEnv& env, int result,
322 AttributesPtr recv_attrs,
323 dhcp::Pkt6Ptr& query, bool& drop);
324
327
330
331};
332
333} // end of namespace isc::radius
334} // end of namespace isc
335
336#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.
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< RadiusAuthPendingRequest< PktPtrType > > RadiusAuthPendingRequestPtr
Pointer to a pending Radius access request.
boost::shared_ptr< Attributes > AttributesPtr
Shared pointers to attribute collection.
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.