Kea 3.3.3
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
11#include <asiolink/crypto_tls.h>
13#include <asiolink/io_address.h>
14#include <asiolink/io_service.h>
15#include <asiolink/udp_socket.h>
16#include <cc/cfg_to_element.h>
17#include <cc/data.h>
21
22#include <chrono>
23#include <cstdint>
24#include <functional>
25#include <list>
26#include <mutex>
27#include <string>
28#include <vector>
29
30#include <boost/enable_shared_from_this.hpp>
31#include <boost/scoped_ptr.hpp>
32#include <boost/shared_ptr.hpp>
33
34namespace isc {
35namespace radius {
36
38static constexpr uint16_t PW_AUTH_PORT = 1812;
39
41static constexpr uint16_t PW_ACCT_PORT = 1813;
42
44static constexpr uint16_t PW_TLS_PORT = 2083;
45
52
54std::string protocolToText(const int proto);
55
57class Server : public data::CfgToElement {
58public:
63 static asiolink::IOAddress getAddress(const std::string& name);
64
71
81 Server(const asiolink::IOAddress& peer_addr, const uint16_t peer_port,
82 const asiolink::IOAddress& local_addr,
83 const asiolink::TlsContextPtr& tls_context,
84 const std::string& secret, const unsigned timeout,
85 const unsigned deadtime = 0)
86 : peer_addr_(peer_addr), peer_port_(peer_port),
87 local_addr_(local_addr), tls_context_(tls_context), secret_(secret),
88 timeout_(timeout), deadtime_(deadtime),
89 deadtime_end_(std::chrono::steady_clock::now()),
90 mutex_(new std::mutex) {
91
92 // Extra checks.
93 setLocalAddress(local_addr);
94 setSecret(secret);
95 setTimeout(timeout);
96 }
97
99 virtual ~Server();
100
105 return (peer_addr_);
106 }
107
111 uint16_t getPeerPort() const {
112 return (peer_port_);
113 }
114
118 void setPeerPort(const uint16_t peer_port) {
119 peer_port_ = peer_port;
120 }
121
126 return (local_addr_);
127 }
128
135
139 std::string getSecret() const {
140 return (secret_);
141 }
142
146 void setSecret(const std::string& secret);
147
151 void setLocalAddress(const asiolink::IOAddress& local_addr);
152
156 unsigned getTimeout() const {
157 return (timeout_);
158 }
159
163 void setTimeout(const unsigned timeout);
164
168 unsigned getDeadtime() const {
169 return (deadtime_);
170 }
171
173 void setDeadtime(const unsigned deadtime) {
174 if (deadtime == 0) {
175 deadtime_end_ = std::chrono::steady_clock::now();
176 }
177 deadtime_ = deadtime;
178
179 }
180
184 std::chrono::steady_clock::time_point getDeadtimeEnd() const;
185
189 void setDeadtimeEnd(const std::chrono::steady_clock::time_point& deadtime_end);
190
194 data::ElementPtr toElement() const override;
195
196protected:
199
201 uint16_t peer_port_;
202
205
208
210 std::string secret_;
211
213 unsigned timeout_;
214
216 unsigned deadtime_;
217
221 std::chrono::steady_clock::time_point deadtime_end_;
222
224 boost::scoped_ptr<std::mutex> mutex_;
225};
226
228typedef boost::shared_ptr<Server> ServerPtr;
229
231typedef std::vector<ServerPtr> Servers;
232
233} // end of namespace isc::radius
234} // end of namespace isc
235
236#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
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.
RadiusProtocol
Transport protocols.
Defines the logger used by the top-level component of kea-lfc.
Abstract class for configuration Cfg_* classes.