Kea: client_handler.h Source File

| Kea 3.2.0-git

dhcp4/client_handler.h
Go to the documentation of this file.
1// Copyright (C) 2020-2023 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 CLIENT_HANDLER_H
8#define CLIENT_HANDLER_H
9
10#include <dhcp/pkt4.h>
11#include <boost/noncopyable.hpp>
12#include <boost/multi_index_container.hpp>
13#include <boost/multi_index/composite_key.hpp>
14#include <boost/multi_index/hashed_index.hpp>
15#include <boost/multi_index/member.hpp>
16#include <boost/shared_ptr.hpp>
17#include <functional>
18#include <mutex>
19#include <thread>
20
21namespace isc {
22namespace dhcp {
23
25 typedef std::function<void()> Continuation;
26
28 typedef boost::shared_ptr<Continuation> ContinuationPtr;
29
33 inline ContinuationPtr makeContinuation(Continuation&& cont) {
34 return (boost::make_shared<Continuation>(cont));
35}
36
38 class ClientHandler : public boost::noncopyable {
39private:
40
42
44 struct Client {
45
52 Client(Pkt4Ptr query, ClientIdPtr client_id, HWAddrPtr hwaddr);
53
55 Pkt4Ptr query_;
56
58 std::vector<uint8_t> client_id_;
59
61 uint16_t htype_;
62
64 std::vector<uint8_t> hwaddr_;
65
67 std::thread::id thread_;
68
73 Pkt4Ptr next_query_;
74
79 ContinuationPtr cont_;
80 };
81
83 typedef boost::shared_ptr<Client> ClientPtr;
84
86 typedef boost::multi_index_container<
87
88 // This container stores pointers to client-by-id objects.
89 ClientPtr,
90
91 // Start specification of indexes here.
92 boost::multi_index::indexed_by<
93
94 // First index is used to search by Duid.
95 boost::multi_index::hashed_unique<
96
97 // Client ID binary content as a member of the Client object.
98 boost::multi_index::member<
99 Client, std::vector<uint8_t>, &Client::client_id_
100 >
101 >
102 >
103 > ClientByIdContainer;
104
106 typedef boost::multi_index_container<
107
108 // This container stores pointers to client-by-hwaddr objects.
109 ClientPtr,
110
111 // Start specification of indexes here.
112 boost::multi_index::indexed_by<
113
114 // First index is used to search by HWAddr.
115 boost::multi_index::hashed_unique<
116
117 // This is a composite index for type and binary components.
118 boost::multi_index::composite_key<
119 Client,
120 boost::multi_index::member<
121 Client, uint16_t, &Client::htype_
122 >,
123 boost::multi_index::member<
124 Client, std::vector<uint8_t>, &Client::hwaddr_
125 >
126 >
127 >
128 >
129 > ClientByHWAddrContainer;
130
137 static ClientPtr lookup(const ClientIdPtr& client_id);
138
145 static ClientPtr lookup(const HWAddrPtr& hwaddr);
146
152 static void addById(const ClientPtr& client);
153
159 static void addByHWAddr(const ClientPtr& client);
160
166 static void del(const ClientIdPtr& client_id);
167
173 static void del(const HWAddrPtr& hwaddr);
174
178 static std::mutex mutex_;
179
181 static ClientByIdContainer clients_client_id_;
182
184 static ClientByHWAddrContainer clients_hwaddr_;
185
186public:
187
189
191 ClientHandler();
192
196 virtual ~ClientHandler();
197
209 bool tryLock(Pkt4Ptr query, ContinuationPtr cont = ContinuationPtr());
210
211private:
212
214
218 void lockById();
219
223 void lockByHWAddr();
224
228 void unLockById();
229
233 void unLockByHWAddr();
234
236 ClientPtr client_;
237
239 ClientIdPtr locked_client_id_;
240
242 HWAddrPtr locked_hwaddr_;
243};
244
245} // namespace isc
246} // namespace dhcp
247
248#endif // CLIENT_HANDLER_H
isc::dhcp::ClientHandler::~ClientHandler
virtual ~ClientHandler()
Destructor.
Definition dhcp4/client_handler.cc:139
isc::dhcp::ClientHandler::tryLock
bool tryLock(Pkt4Ptr query, ContinuationPtr cont=ContinuationPtr())
Tries to acquires a client.
Definition dhcp4/client_handler.cc:164
isc::dhcp::ClientHandler::ClientHandler
ClientHandler()
Public interface.
Definition dhcp4/client_handler.cc:135
isc::dhcp
Definition dhcp4/client_handler.cc:20
isc::dhcp::Continuation
std::function< void()> Continuation
Define the type of packet processing continuation.
Definition dhcp4/client_handler.h:25
isc::dhcp::Pkt4Ptr
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
Definition pkt4.h:556
isc::dhcp::makeContinuation
ContinuationPtr makeContinuation(Continuation &&cont)
Continuation factory.
Definition dhcp4/client_handler.h:33
isc::dhcp::HWAddrPtr
boost::shared_ptr< HWAddr > HWAddrPtr
Shared pointer to a hardware address structure.
Definition hwaddr.h:154
isc::dhcp::ClientIdPtr
boost::shared_ptr< ClientId > ClientIdPtr
Shared pointer to a Client ID.
Definition duid.h:216
isc::dhcp::ContinuationPtr
boost::shared_ptr< Continuation > ContinuationPtr
Define the type of shared pointers to continuations.
Definition dhcp4/client_handler.h:28
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18
pkt4.h