Kea 3.1.9
client_server.h
Go to the documentation of this file.
1// Copyright (C) 2023-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_CLIENT_SERVER_H
8#define RADIUS_CLIENT_SERVER_H
9
10#include <client_attribute.h>
11#include <client_message.h>
13#include <asiolink/crypto_tls.h>
15#include <asiolink/io_address.h>
16#include <asiolink/io_service.h>
17#include <asiolink/udp_socket.h>
18#include <cc/cfg_to_element.h>
19#include <cc/data.h>
21#include <boost/enable_shared_from_this.hpp>
22#include <boost/scoped_ptr.hpp>
23#include <boost/shared_ptr.hpp>
24#include <chrono>
25#include <functional>
26#include <list>
27#include <mutex>
28#include <string>
29#include <vector>
30
31namespace isc {
32namespace radius {
33
35static constexpr uint16_t PW_AUTH_PORT = 1812;
36
38static constexpr uint16_t PW_ACCT_PORT = 1813;
39
41static constexpr uint16_t PW_TLS_PORT = 2083;
42
49
51std::string protocolToText(const int proto);
52
54class Server : public data::CfgToElement {
55public:
60 static asiolink::IOAddress getAddress(const std::string& name);
61
68
78 Server(const asiolink::IOAddress& peer_addr, const uint16_t peer_port,
79 const asiolink::IOAddress& local_addr,
80 const asiolink::TlsContextPtr& tls_context,
81 const std::string& secret, const unsigned timeout,
82 const unsigned deadtime = 0)
83 : peer_addr_(peer_addr), peer_port_(peer_port),
84 local_addr_(local_addr), tls_context_(tls_context), secret_(secret),
85 timeout_(timeout), deadtime_(deadtime),
86 deadtime_end_(std::chrono::steady_clock::now()),
87 mutex_(new std::mutex) {
88
89 // Extra checks.
90 setLocalAddress(local_addr);
91 setSecret(secret);
92 setTimeout(timeout);
93 }
94
96 virtual ~Server();
97
102 return (peer_addr_);
103 }
104
108 uint16_t getPeerPort() const {
109 return (peer_port_);
110 }
111
115 void setPeerPort(const uint16_t peer_port) {
116 peer_port_ = peer_port;
117 }
118
123 return (local_addr_);
124 }
125
132
136 std::string getSecret() const {
137 return (secret_);
138 }
139
143 void setSecret(const std::string& secret);
144
148 void setLocalAddress(const asiolink::IOAddress& local_addr);
149
153 unsigned getTimeout() const {
154 return (timeout_);
155 }
156
160 void setTimeout(const unsigned timeout);
161
165 unsigned getDeadtime() const {
166 return (deadtime_);
167 }
168
170 void setDeadtime(const unsigned deadtime) {
171 if (deadtime == 0) {
172 deadtime_end_ = std::chrono::steady_clock::now();
173 }
174 deadtime_ = deadtime;
175
176 }
177
181 std::chrono::steady_clock::time_point getDeadtimeEnd() const;
182
186 void setDeadtimeEnd(const std::chrono::steady_clock::time_point& deadtime_end);
187
191 data::ElementPtr toElement() const override;
192
193protected:
196
198 uint16_t peer_port_;
199
202
205
207 std::string secret_;
208
210 unsigned timeout_;
211
213 unsigned deadtime_;
214
218 std::chrono::steady_clock::time_point deadtime_end_;
219
221 boost::scoped_ptr<std::mutex> mutex_;
222};
223
225typedef boost::shared_ptr<Server> ServerPtr;
226
228typedef std::vector<ServerPtr> Servers;
229
230} // end of namespace isc::radius
231} // end of namespace isc
232
233#endif
void setPeerPort(const uint16_t peer_port)
Set peer port.
void setTimeout(const unsigned timeout)
Set timeout.
asiolink::IOAddress local_addr_
Local address.
boost::scoped_ptr< std::mutex > mutex_
Mutex to protect the state.
void setSecret(const std::string &secret)
Set secret.
asiolink::IOAddress getLocalAddress() const
Get local address.
asiolink::TlsContextPtr getTlsContext() const
Get TLS context.
Server(const asiolink::IOAddress &peer_addr, const uint16_t peer_port, const asiolink::IOAddress &local_addr, const asiolink::TlsContextPtr &tls_context, const std::string &secret, const unsigned timeout, const unsigned deadtime=0)
Constructor.
void setLocalAddress(const asiolink::IOAddress &local_addr)
Set local address.
const asiolink::IOAddress peer_addr_
Peer address.
data::ElementPtr toElement() const override
Unparse server.
unsigned deadtime_
Deadtime i.e. hold-down delay.
virtual ~Server()
Destructor.
unsigned getTimeout() const
Get timeout.
static asiolink::IOAddress getSrcAddress(const asiolink::IOAddress &dest)
Get the source address from a destination address.
unsigned getDeadtime() const
Get deadtime.
std::chrono::steady_clock::time_point deadtime_end_
Deadtime end i.e.
void setDeadtime(const unsigned deadtime)
Set deadtime.
std::chrono::steady_clock::time_point getDeadtimeEnd() const
Get deadtime end.
static asiolink::IOAddress getAddress(const std::string &name)
Get an address from a name.
uint16_t getPeerPort() const
Get peer port.
unsigned timeout_
Timeout.
asiolink::TlsContextPtr tls_context_
TLS context.
void setDeadtimeEnd(const std::chrono::steady_clock::time_point &deadtime_end)
Set deadtime end.
std::string secret_
Secret.
uint16_t peer_port_
Peer port.
std::string getSecret() const
Get secret.
asiolink::IOAddress getPeerAddress() const
Get peer address.
TLS API.
boost::shared_ptr< Element > ElementPtr
Definition data.h:29
RadiusProtocol
Transport protocols.
std::vector< ServerPtr > Servers
Type of RADIUS server collection.
boost::shared_ptr< Server > ServerPtr
Type of shared pointers to a RADIUS server object.
string protocolToText(const int proto)
Transport protocol to text.
Defines the logger used by the top-level component of kea-lfc.
Abstract class for configuration Cfg_* classes.