Kea 3.1.1
client_server.h
Go to the documentation of this file.
1// Copyright (C) 2023-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_CLIENT_SERVER_H
8#define RADIUS_CLIENT_SERVER_H
9
10#include <client_attribute.h>
11#include <client_message.h>
14#include <asiolink/io_address.h>
15#include <asiolink/io_service.h>
16#include <asiolink/udp_socket.h>
17#include <cc/cfg_to_element.h>
18#include <cc/data.h>
20#include <boost/enable_shared_from_this.hpp>
21#include <boost/scoped_ptr.hpp>
22#include <boost/shared_ptr.hpp>
23#include <chrono>
24#include <functional>
25#include <list>
26#include <mutex>
27#include <string>
28#include <vector>
29
30namespace isc {
31namespace radius {
32
34static constexpr uint16_t PW_AUTH_UDP_PORT = 1812;
35
37static constexpr uint16_t PW_ACCT_UDP_PORT = 1813;
38
40class Server : public data::CfgToElement {
41public:
46 static asiolink::IOAddress getAddress(const std::string& name);
47
54
63 Server(const asiolink::IOAddress& peer_addr, const uint16_t peer_port,
64 const asiolink::IOAddress& local_addr, const std::string& secret,
65 const unsigned timeout, const unsigned deadtime = 0)
66 : peer_addr_(peer_addr), peer_port_(peer_port),
67 local_addr_(local_addr), secret_(secret), timeout_(timeout),
68 deadtime_(deadtime), deadtime_end_(std::chrono::steady_clock::now()),
69 mutex_(new std::mutex) {
70
71 // Extra checks.
72 setLocalAddress(local_addr);
73 setSecret(secret);
74 setTimeout(timeout);
75 }
76
78 virtual ~Server();
79
84 return (peer_addr_);
85 }
86
90 uint16_t getPeerPort() const {
91 return (peer_port_);
92 }
93
97 void setPeerPort(const uint16_t peer_port) {
98 peer_port_ = peer_port;
99 }
100
105 return (local_addr_);
106 }
107
111 std::string getSecret() const {
112 return (secret_);
113 }
114
118 void setSecret(const std::string& secret);
119
123 void setLocalAddress(const asiolink::IOAddress& local_addr);
124
128 unsigned getTimeout() const {
129 return (timeout_);
130 }
131
135 void setTimeout(const unsigned timeout);
136
140 unsigned getDeadtime() const {
141 return (deadtime_);
142 }
143
145 void setDeadtime(const unsigned deadtime) {
146 if (deadtime == 0) {
147 deadtime_end_ = std::chrono::steady_clock::now();
148 }
149 deadtime_ = deadtime;
150
151 }
152
156 std::chrono::steady_clock::time_point getDeadtimeEnd() const;
157
161 void setDeadtimeEnd(const std::chrono::steady_clock::time_point& deadtime_end);
162
166 data::ElementPtr toElement() const override;
167
168protected:
171
173 uint16_t peer_port_;
174
177
179 std::string secret_;
180
182 unsigned timeout_;
183
185 unsigned deadtime_;
186
190 std::chrono::steady_clock::time_point deadtime_end_;
191
193 boost::scoped_ptr<std::mutex> mutex_;
194};
195
197typedef boost::shared_ptr<Server> ServerPtr;
198
200typedef std::vector<ServerPtr> Servers;
201
202} // end of namespace isc::radius
203} // end of namespace isc
204
205#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.
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.
Server(const asiolink::IOAddress &peer_addr, const uint16_t peer_port, const asiolink::IOAddress &local_addr, const std::string &secret, const unsigned timeout, const unsigned deadtime=0)
Constructor.
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.
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.
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
std::vector< ServerPtr > Servers
Type of RADIUS server collection.
boost::shared_ptr< Server > ServerPtr
Type of shared pointers to a RADIUS server object.
Defines the logger used by the top-level component of kea-lfc.
Abstract class for configuration Cfg_* classes.