23namespace ph = std::placeholders;
35 const long idle_timeout,
36 const uint16_t family,
37 const size_t max_concurrent_queries,
38 const size_t read_max)
82 bool stop_now =
false;
107 boost::dynamic_pointer_cast<TcpStreamRequest>(request);
114 stream_req->unpack();
115 auto length = stream_req->getRequestSize();
124 const uint8_t*
data = stream_req->getRequest();
134 }
catch (
const std::exception& ex) {
150 .arg(query->getQuery()->toText());
155 .arg(query->getXid());
175 bool deferred_stop =
false;
184 deferred_stop =
true;
205 .arg(do_send->getResponse()->toText());
206 }
catch (
const std::exception& ex) {
221 isc_throw(
BadValue,
"LeaseQueryConnection::makeTcpResponse blq_response cannot be empty");
225 blq_response->getResponse()->pack();
226 auto buffer = blq_response->getResponse()->getBuffer();
227 const uint8_t*
data = buffer.getData();
228 auto length = buffer.getLength();
232 tcp_response->setResponseData(
data, length);
235 tcp_response->pack();
236 return (tcp_response);
254 pkt->updateTimestamp();
256 pkt->setRemoteAddr(
IOAddress(endpoint.address()));
257 pkt->setRemotePort(endpoint.port());
262 .arg(pkt->getName());
272 pkt->updateTimestamp();
274 pkt->setRemoteAddr(
IOAddress(endpoint.address()));
275 pkt->setRemotePort(endpoint.port());
280 .arg(pkt->getName());
298 boost::static_pointer_cast<LeaseQueryConnection>(shared_from_this());
318 }
catch (
const std::exception& ex) {
330 if (bulk_lease_query->isProcessed()) {
387 boost::static_pointer_cast<LeaseQueryConnection>(shared_from_this());
405 }
catch (
const std::exception& ex) {
436 return (endpoint.address());
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown when an unexpected error condition occurs.
The IOAddress class represents an IP addresses (version agnostic)
static const IOAddress & IPV4_ZERO_ADDRESS()
Returns an address set to all zeros.
static const IOAddress & IPV6_ZERO_ADDRESS()
Returns an IPv6 zero address.
Represents DHCPv4 packet.
Represents a DHCPv6 packet.
Holds a bulk lease query query packet.
Provides control flow for processing a bulk query.
static std::string leaseQueryLabel(const BlqMsgPtr &msg)
Convenience method for generating per packet logging info.
Provides control flow for processing a bulk query.
static std::string leaseQueryLabel(const BlqMsgPtr &msg)
Convenience method for generating per packet logging info.
static void processStart(BulkLeaseQueryPtr ptr)
Class/static start processing.
LeaseQueryConnection(const asiolink::IOServicePtr &io_service, const tcp::TcpConnectionAcceptorPtr &acceptor, const asiolink::TlsContextPtr &tls_context, tcp::TcpConnectionPool &connection_pool, const tcp::TcpConnectionAcceptorCallback &acceptor_callback, const tcp::TcpConnectionFilterCallback &filter_callback, const long idle_timeout, const uint16_t family, const size_t max_concurrent_queries, const size_t read_max=32768)
Constructor.
size_t max_concurrent_queries_
Maximum number of concurrent queries allowed.
size_t getNumResponses() const
Returns the number of responses in the response queue.
virtual bool responseSent(tcp::TcpResponsePtr response)
Processes a response once it has been sent.
bool stopping_
Stopping flag.
bool findQuery(const Xid &xid) const
Find queries based on Xid in the query list and queue.
virtual tcp::TcpRequestPtr createRequest()
Creates a new empty request ready to receive data.
size_t getNumRunningQueries() const
Returns the number of queries in the in-progress list.
virtual void processNextQuery()
Process next waiting query.
bool noPendingQuery() const
Returns True if the queue of waiting queries is empty.
virtual void requestReceived(tcp::TcpRequestPtr request)
Processes a completely received request.
virtual void sendNextResponse()
Sends the next response in the response queue.
BlqQueryPtr unpackQuery6(const uint8_t *buffer, size_t length) const
Unpacks a DHCPv6 packet from a data buffer.
XidQueue< BlqMsg > pending_queries_
Queue of queries waiting to enter processing.
virtual void close()
Closes the socket.
BlqResponseList responses_
List of responses waiting to be sent.
static bool doPushToSend(LeaseQueryConnectionWPtr wptr, BlqResponsePtr response)
Class/static version of pushToSend.
uint16_t family_
Protocol family AF_INET or AF_INET6.
BlqQueryPtr popPendingQuery()
Pops a query from the queue of waiting queries.
XidQueue< BulkLeaseQuery > running_queries_
List of in-process queries.
virtual void stopThisConnection()
Stops current connection.
virtual void shutdown()
Shutdown the socket.
std::string getRemoteEndpointAddressAsText() const
Export getRemoteEndpointAddressAsText.
tcp::TcpResponsePtr makeTcpResponse(BlqResponsePtr blq_response) const
Constructs a ready to send TcpResponse from and BlqResponse.
std::mutex responses_mutex_
Mutex used to lock during responses access.
BlqResponsePtr response_to_send_
Tracks the response currently being sent.
void removeRunningQuery(const Xid &xid)
Removes a query from the in-progress query list.
static void doSendNextResponse(LeaseQueryConnectionWPtr wptr)
Class/static version of sendNextResponse.
void addPendingQuery(BlqQueryPtr query)
Queues a query to the end of the queue of waiting queries.
void startQuery(BlqQueryPtr query_msg)
Start query processing.
asiolink::IOServicePtr io_service_
IOService that drives the connection events.
bool can_send_
Can send flag.
virtual void queryComplete(const Xid &xid)
Finishes up when a query has been completed (e.g.
virtual void post(const BlqPostCbArg &callback)
Posts an event callback to the connection's IOService.
static void doPost(LeaseQueryConnectionWPtr wptr, const BlqPostCbArg &callback)
Class/static version of post.
BlqQueryPtr unpackQuery4(const uint8_t *buffer, size_t length) const
Unpacks a DHCPv4 packet from a data buffer.
asiolink::IOAddress getRequesterAddress() const
Returns the requester's ip address.
static void doQueryComplete(LeaseQueryConnectionWPtr wptr, const Xid &xid)
Class/static version of queryComplete.
void addRunningQuery(BulkLeaseQueryPtr query)
Adds a query to the end of the list of in-progress queries.
virtual bool pushToSend(BlqResponsePtr response)
Adds a response to the connection's outbound queue of responses.
Thrown on hook termination.
Pool of active TCP connections.
virtual void shutdown()
Shutdown the socket.
virtual void stopThisConnection()
Stops current connection.
virtual void close()
Closes the socket.
void asyncSendResponse(TcpResponsePtr response)
Sends TCP response asynchronously.
const boost::asio::ip::tcp::endpoint getRemoteEndpoint() const
Fetches the remote endpoint for the connection's socket.
static const boost::asio::ip::tcp::endpoint & NO_ENDPOINT()
Returns an empty end point.
TcpConnection(const asiolink::IOServicePtr &io_service, const TcpConnectionAcceptorPtr &acceptor, const asiolink::TlsContextPtr &tls_context, TcpConnectionPool &connection_pool, const TcpConnectionAcceptorCallback &acceptor_callback, const TcpConnectionFilterCallback &connection_filter, const long idle_timeout, const size_t read_max=32768)
Constructor.
Implement a simple length:data input stream message.
Implements a simple length:data output stream message.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
boost::shared_ptr< TlsContext > TlsContextPtr
The type of shared pointers to TlsContext objects.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
const isc::log::MessageID BULK_LEASE_QUERY6_UNSUPPORTED_MSG_TYPE
const isc::log::MessageID BULK_LEASE_QUERY_DUPLICATE_XID
const isc::log::MessageID BULK_LEASE_QUERY_INVALID_REQUEST
const isc::log::MessageID BULK_LEASE_QUERY_RESPONSE_SENT
boost::shared_ptr< BlqResponse > BlqResponsePtr
Defines a shared pointer to an BlqResponse.
std::function< void(const BlqPostCbArg &)> BlqPostCb
Type of BLQ post callback.
std::function< void(Xid)> BlqQueryCompleteCb
Type of BLQ queryComplete callback.
std::function< void()> BlqPostCbArg
Type of BLQ post callback argument..
uint32_t Xid
Defines a Bulk LeaseQuery transaction id.
boost::weak_ptr< LeaseQueryConnection > LeaseQueryConnectionWPtr
Defines a weak pointer to a LeaseQueryConnection.
const isc::log::MessageID BULK_LEASE_QUERY_QUERY_RECEIVED
const isc::log::MessageID BULK_LEASE_QUERY_EMPTY_REQUEST
const isc::log::MessageID BULK_LEASE_QUERY_AT_MAX_CONCURRENT_QUERIES
const isc::log::MessageID BULK_LEASE_QUERY_RESPONSE_SEND_ERROR
boost::shared_ptr< BlqQuery > BlqQueryPtr
Defines a shared pointer to an BlqQuery.
const isc::log::MessageID BULK_LEASE_QUERY4_UNSUPPORTED_MSG_TYPE
const isc::log::MessageID BULK_LEASE_QUERY_DEQUEUED
boost::shared_ptr< BulkLeaseQuery > BulkLeaseQueryPtr
Defines a shared pointer to a BulkLeaseQuery object.
isc::log::Logger lease_query_logger("lease-query-hooks")
const isc::log::MessageID BULK_LEASE_QUERY_UNPACK_ERROR
std::function< bool(BlqResponsePtr)> BlqPushToSendCb
Type of BLQ pushToSend callback.
const isc::log::MessageID BULK_LEASE_QUERY_PROCESSING_UNEXPECTED_FAILURE
const int DBGLVL_TRACE_BASIC
Trace basic operations.
std::function< bool(const boost::asio::ip::tcp::endpoint &)> TcpConnectionFilterCallback
Type of the callback for filtering new connections by ip address.
boost::shared_ptr< TcpConnectionAcceptor > TcpConnectionAcceptorPtr
Type of shared pointer to TCP acceptors.
boost::shared_ptr< TcpRequest > TcpRequestPtr
Defines a smart pointer to a TcpRequest.
boost::shared_ptr< TcpResponse > TcpResponsePtr
boost::shared_ptr< TcpStreamResponse > TcpStreamResponsePtr
Pointer to a TcpStreamResponse.
boost::shared_ptr< TcpStreamRequest > TcpStreamRequestPtr
Pointer to a TcpStreamRequest.
std::function< void(const boost::system::error_code &)> TcpConnectionAcceptorCallback
Type of the callback for the TCP acceptor used in this library.
Defines the logger used by the top-level component of kea-lfc.