| Kea 3.0.2-git

lease_query_impl6.h
Go to the documentation of this file.
1// Copyright (C) 2020-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 LEASE_QUERY_IMPL6_H
8#define LEASE_QUERY_IMPL6_H
9
10#include <config.h>
11
12#include <asiolink/io_address.h>
13#include <dhcp/dhcp6.h>
14#include <dhcp/option6_iaaddr.h>
15#include <dhcp/option6_status_code.h>
16#include <dhcp/option_custom.h>
17#include <dhcp/pkt6.h>
18#include <dhcpsrv/lease.h>
19#include <dhcpsrv/cfgmgr.h>
20#include <lease_query_impl.h>
21
22 namespace isc {
23 namespace lease_query {
24
26 typedef boost::shared_ptr<dhcp::Pkt6::RelayInfo> RelayInfoPtr;
27
28
30 typedef std::set<uint8_t> PrefixLengthList;
31
33 class LeaseQueryImpl6 : public LeaseQueryImpl {
34 public:
38 LeaseQueryImpl6(const data::ConstElementPtr config);
39
41 virtual ~LeaseQueryImpl6(){};
42
54 virtual void processQuery(dhcp::PktPtr base_query) const;
55
75 static dhcp::Option6StatusCodePtr
76 queryByIpAddress(const asiolink::IOAddress& iaaddr,
77 dhcp::Lease6Collection& leases,
78 const PrefixLengthList& prefix_lengths = PrefixLengthList());
79
95 static dhcp::Option6StatusCodePtr
96 queryByClientId(const dhcp::DuidPtr& client_id,
97 const asiolink::IOAddress& link_addr,
98 dhcp::Lease6Collection& leases);
99
117 static dhcp::Option6StatusCodePtr
118 queryByRelayIdStart(const dhcp::DuidPtr& relay_id,
119 asiolink::IOAddress& start_addr,
120 const size_t page_size,
121 const asiolink::IOAddress& link_addr,
122 dhcp::SubnetIDSet& links,
123 dhcp::Lease6Collection& leases);
124
142 static void queryByRelayIdNext(const dhcp::DuidPtr& relay_id,
143 asiolink::IOAddress& start_addr,
144 const size_t page_size,
145 const dhcp::SubnetIDSet& links,
146 dhcp::Lease6Collection& leases);
147
165 static dhcp::Option6StatusCodePtr
166 queryByRemoteIdStart(const dhcp::OptionBuffer& remote_id,
167 asiolink::IOAddress& start_addr,
168 const size_t page_size,
169 const asiolink::IOAddress& link_addr,
170 dhcp::SubnetIDSet& links,
171 dhcp::Lease6Collection& leases);
172
190 static void queryByRemoteIdNext(const dhcp::OptionBuffer& remote_id,
191 asiolink::IOAddress& start_addr,
192 const size_t page_size,
193 const dhcp::SubnetIDSet& links,
194 dhcp::Lease6Collection& leases);
195
211 static dhcp::Option6StatusCodePtr
212 queryByLinkStart(asiolink::IOAddress& start_addr,
213 const size_t page_size,
214 const asiolink::IOAddress& link_addr,
215 dhcp::SubnetIDSet& links,
216 dhcp::Lease6Collection& leases);
217
233 static void queryByLinkNext(asiolink::IOAddress& start_addr,
234 const size_t page_size,
235 dhcp::SubnetIDSet& links,
236 dhcp::Lease6Collection& leases);
237
250 static dhcp::Pkt6Ptr buildReply(const dhcp::Option6StatusCodePtr& status,
251 const dhcp::Pkt6Ptr& query,
252 dhcp::Lease6Collection& leases);
253
264 static dhcp::Pkt6Ptr initReply(const dhcp::Pkt6Ptr& query);
265
273 static dhcp::Pkt6Ptr initData(const dhcp::Pkt6Ptr& query);
274
282 static dhcp::Pkt6Ptr initDone(const dhcp::Pkt6Ptr& query);
283
294 // or
310 static dhcp::OptionPtr makeClientOption(dhcp::Lease6Collection& leases);
311
323 static dhcp::OptionPtr makeClientOption(dhcp::Lease6Ptr lease);
324
349 static dhcp::OptionPtr makeRelayOption(const dhcp::Lease6& lease);
350
360 static uint16_t getRelayOverhead(const dhcp::Pkt6::RelayInfo& relay, bool innermost);
361
369 static void parseRelayInfoList(data::ConstElementPtr relays,
370 std::vector<RelayInfoPtr>& relay_infos);
371
379 static RelayInfoPtr parseRelayInfo(data::ConstElementPtr relay);
380
393 static void testServerId(const dhcp::Pkt6Ptr& query);
394
401 static dhcp::Option6StatusCodePtr makeStatusOption(const DHCPv6StatusCode&
402 status_code,
403 const std::string message = "");
404
411 void sendResponse(const dhcp::Pkt6Ptr& response) const;
412
420 virtual void send(const dhcp::Pkt6Ptr& response) const;
421
427 static std::string leaseQueryLabel(const dhcp::Pkt6Ptr& packet);
428
436 static int upgradeHandler(hooks::CalloutHandle& handle);
437
444 static asiolink::IOAddress getPrefixFromAddress(const asiolink::IOAddress& address,
445 const uint8_t prefix_length);
446
451 void addPrefixLength(uint8_t prefix_len) {
452 if (prefix_len > 0 && prefix_len <= 128) {
453 prefix_lens_.insert(prefix_len);
454 }
455 }
456
458 void clearPrefixLengthList() {
459 prefix_lens_.clear();
460 }
461
465 const PrefixLengthList& getPrefixLengthList() const {
466 return (prefix_lens_);
467 }
468
476 void populatePrefixLengthList(dhcp::SrvConfigPtr cfg);
477
485 static std::string dumpPrefixLengthList(const PrefixLengthList& prefix_lengths);
486
490 mutable PrefixLengthList prefix_lens_;
491
495 bool build_prefix_lens_;
496};
497
499 typedef boost::shared_ptr<LeaseQueryImpl6> LeaseQueryImpl6Ptr;
500
501} // end of namespace isc::lease_query
502} // end of namespace isc
503
504#endif // LEASE_QUERY_IMPL6_H
cfgmgr.h
isc::asiolink::IOAddress
The IOAddress class represents an IP addresses (version agnostic).
Definition io_address.h:45
isc::hooks::CalloutHandle
Per-packet callout handle.
Definition callout_handle.h:78
isc::lease_query::LeaseQueryImpl6::testServerId
static void testServerId(const dhcp::Pkt6Ptr &query)
Validates the server-id of a received DHCPV6_LEASEQUERY.
Definition lease_query_impl6.cc:1049
isc::lease_query::LeaseQueryImpl6::parseRelayInfo
static RelayInfoPtr parseRelayInfo(data::ConstElementPtr relay)
Converts an Element::map into an Pkt6::RelayInfo instance.
Definition lease_query_impl6.cc:985
isc::lease_query::LeaseQueryImpl6::queryByRelayIdNext
static void queryByRelayIdNext(const dhcp::DuidPtr &relay_id, asiolink::IOAddress &start_addr, const size_t page_size, const dhcp::SubnetIDSet &links, dhcp::Lease6Collection &leases)
Subsequent query for active leases matching a relay id (i.e.
Definition lease_query_impl6.cc:363
isc::lease_query::LeaseQueryImpl6::getRelayOverhead
static uint16_t getRelayOverhead(const dhcp::Pkt6::RelayInfo &relay, bool innermost)
Calculates the packed size (in octets) of a given RelayInfo.
Definition lease_query_impl6.cc:957
isc::lease_query::LeaseQueryImpl6::getPrefixFromAddress
static asiolink::IOAddress getPrefixFromAddress(const asiolink::IOAddress &address, const uint8_t prefix_length)
Creates a prefix of a given length from an address.
Definition lease_query_impl6.cc:190
isc::lease_query::LeaseQueryImpl6::addPrefixLength
void addPrefixLength(uint8_t prefix_len)
Add a prefix to the list of prefix lengths.
Definition lease_query_impl6.h:451
isc::lease_query::LeaseQueryImpl6::initDone
static dhcp::Pkt6Ptr initDone(const dhcp::Pkt6Ptr &query)
Creates the final query done response.
Definition lease_query_impl6.cc:702
isc::lease_query::LeaseQueryImpl6::dumpPrefixLengthList
static std::string dumpPrefixLengthList(const PrefixLengthList &prefix_lengths)
Dump the given list of prefix lengths to a string.
Definition lease_query_impl6.cc:1185
isc::lease_query::LeaseQueryImpl6::queryByRemoteIdStart
static dhcp::Option6StatusCodePtr queryByRemoteIdStart(const dhcp::OptionBuffer &remote_id, asiolink::IOAddress &start_addr, const size_t page_size, const asiolink::IOAddress &link_addr, dhcp::SubnetIDSet &links, dhcp::Lease6Collection &leases)
Initial query for active leases matching a remote id.
Definition lease_query_impl6.cc:401
isc::lease_query::LeaseQueryImpl6::LeaseQueryImpl6
LeaseQueryImpl6(const data::ConstElementPtr config)
Constructor.
Definition lease_query_impl6.cc:53
isc::lease_query::LeaseQueryImpl6::sendResponse
void sendResponse(const dhcp::Pkt6Ptr &response) const
Sends a response to the requester.
Definition lease_query_impl6.cc:1074
isc::lease_query::LeaseQueryImpl6::queryByRelayIdStart
static dhcp::Option6StatusCodePtr queryByRelayIdStart(const dhcp::DuidPtr &relay_id, asiolink::IOAddress &start_addr, const size_t page_size, const asiolink::IOAddress &link_addr, dhcp::SubnetIDSet &links, dhcp::Lease6Collection &leases)
Initial query for active leases matching a relay id (i.e.
Definition lease_query_impl6.cc:312
isc::lease_query::LeaseQueryImpl6::prefix_lens_
PrefixLengthList prefix_lens_
List of PD prefix lengths to use when searching for leases by address.
Definition lease_query_impl6.h:490
isc::lease_query::LeaseQueryImpl6::processQuery
virtual void processQuery(dhcp::PktPtr base_query) const
Processes a single DHCPv6 client Lease Query.
Definition lease_query_impl6.cc:93
isc::lease_query::LeaseQueryImpl6::makeStatusOption
static dhcp::Option6StatusCodePtr makeStatusOption(const DHCPv6StatusCode &status_code, const std::string message="")
Constructs a D6O_STATUS_CODE option.
Definition lease_query_impl6.cc:1110
isc::lease_query::LeaseQueryImpl6::queryByLinkStart
static dhcp::Option6StatusCodePtr queryByLinkStart(asiolink::IOAddress &start_addr, const size_t page_size, const asiolink::IOAddress &link_addr, dhcp::SubnetIDSet &links, dhcp::Lease6Collection &leases)
Initial query for active leases of a given link.
Definition lease_query_impl6.cc:490
isc::lease_query::LeaseQueryImpl6::makeClientOption
static dhcp::OptionPtr makeClientOption(dhcp::Lease6Collection &leases)
Constructs a client option based on a collection of leases.
Definition lease_query_impl6.cc:712
isc::lease_query::LeaseQueryImpl6::getPrefixLengthList
const PrefixLengthList & getPrefixLengthList() const
Fetch the prefix length list.
Definition lease_query_impl6.h:465
isc::lease_query::LeaseQueryImpl6::~LeaseQueryImpl6
virtual ~LeaseQueryImpl6()
Destructor.
Definition lease_query_impl6.h:41
isc::lease_query::LeaseQueryImpl6::clearPrefixLengthList
void clearPrefixLengthList()
Empty the prefix length list.
Definition lease_query_impl6.h:458
isc::lease_query::LeaseQueryImpl6::makeRelayOption
static dhcp::OptionPtr makeRelayOption(const dhcp::Lease6 &lease)
Constructs a D6O_LQ_RELAY_DATA option from a lease user-context.
Definition lease_query_impl6.cc:858
isc::lease_query::LeaseQueryImpl6::leaseQueryLabel
static std::string leaseQueryLabel(const dhcp::Pkt6Ptr &packet)
Convenience method for generating per packet logging info.
Definition lease_query_impl6.cc:1117
isc::lease_query::LeaseQueryImpl6::queryByIpAddress
static dhcp::Option6StatusCodePtr queryByIpAddress(const asiolink::IOAddress &iaaddr, dhcp::Lease6Collection &leases, const PrefixLengthList &prefix_lengths=PrefixLengthList())
Queries for an active lease matching an ip address.
Definition lease_query_impl6.cc:221
isc::lease_query::LeaseQueryImpl6::send
virtual void send(const dhcp::Pkt6Ptr &response) const
Wrapper around the call to IfaceMgr::send().
Definition lease_query_impl6.cc:1105
isc::lease_query::LeaseQueryImpl6::buildReply
static dhcp::Pkt6Ptr buildReply(const dhcp::Option6StatusCodePtr &status, const dhcp::Pkt6Ptr &query, dhcp::Lease6Collection &leases)
Creates a lease query reply packet.
Definition lease_query_impl6.cc:601
isc::lease_query::LeaseQueryImpl6::queryByLinkNext
static void queryByLinkNext(asiolink::IOAddress &start_addr, const size_t page_size, dhcp::SubnetIDSet &links, dhcp::Lease6Collection &leases)
Subsequent query for active leases of a given link.
Definition lease_query_impl6.cc:548
isc::lease_query::LeaseQueryImpl6::initReply
static dhcp::Pkt6Ptr initReply(const dhcp::Pkt6Ptr &query)
Creates the initial query reply.
Definition lease_query_impl6.cc:661
isc::lease_query::LeaseQueryImpl6::populatePrefixLengthList
void populatePrefixLengthList(dhcp::SrvConfigPtr cfg)
Populates the prefix length list from the given configuration.
Definition lease_query_impl6.cc:1164
isc::lease_query::LeaseQueryImpl6::queryByClientId
static dhcp::Option6StatusCodePtr queryByClientId(const dhcp::DuidPtr &client_id, const asiolink::IOAddress &link_addr, dhcp::Lease6Collection &leases)
Queries for active leases matching a client id (i.e.
Definition lease_query_impl6.cc:268
isc::lease_query::LeaseQueryImpl6::parseRelayInfoList
static void parseRelayInfoList(data::ConstElementPtr relays, std::vector< RelayInfoPtr > &relay_infos)
Converts an Element::list into a list of Pkt6::RelayInfo instances.
Definition lease_query_impl6.cc:972
isc::lease_query::LeaseQueryImpl6::queryByRemoteIdNext
static void queryByRemoteIdNext(const dhcp::OptionBuffer &remote_id, asiolink::IOAddress &start_addr, const size_t page_size, const dhcp::SubnetIDSet &links, dhcp::Lease6Collection &leases)
Subsequent query for active leases matching a remote id.
Definition lease_query_impl6.cc:452
isc::lease_query::LeaseQueryImpl6::build_prefix_lens_
bool build_prefix_lens_
True if the prefix length should be gleaned from configured pools.
Definition lease_query_impl6.h:495
isc::lease_query::LeaseQueryImpl6::upgradeHandler
static int upgradeHandler(hooks::CalloutHandle &handle)
Upgrade extended information.
Definition lease_query_impl6.cc:1136
isc::lease_query::LeaseQueryImpl6::initData
static dhcp::Pkt6Ptr initData(const dhcp::Pkt6Ptr &query)
Creates the query data response.
Definition lease_query_impl6.cc:692
isc::lease_query::LeaseQueryImpl::LeaseQueryImpl
LeaseQueryImpl(uint16_t family, const isc::data::ConstElementPtr config)
Constructor.
Definition lease_query_impl.cc:49
dhcp6.h
DHCPv6StatusCode
DHCPv6StatusCode
Definition dhcp6.h:175
io_address.h
lease.h
lease_query_impl.h
isc::config
Definition command_interpreter.cc:23
isc::data::ConstElementPtr
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
isc::dhcp::PktPtr
boost::shared_ptr< isc::dhcp::Pkt > PktPtr
A pointer to either Pkt4 or Pkt6 packet.
Definition pkt.h:998
isc::dhcp::SubnetIDSet
std::set< dhcp::SubnetID > SubnetIDSet
Ordered list aka set of subnetIDs.
Definition subnet_id.h:43
isc::dhcp::DuidPtr
boost::shared_ptr< DUID > DuidPtr
Definition duid.h:136
isc::dhcp::Lease6Ptr
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
Definition lease.h:528
isc::dhcp::Lease6Collection
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
Definition lease.h:693
isc::dhcp::SrvConfigPtr
boost::shared_ptr< SrvConfig > SrvConfigPtr
Non-const pointer to the SrvConfig.
Definition srv_config.h:1136
isc::dhcp::Option6StatusCodePtr
boost::shared_ptr< Option6StatusCode > Option6StatusCodePtr
Pointer to the isc::dhcp::Option6StatusCode.
Definition option6_status_code.h:21
isc::dhcp::Pkt6Ptr
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
Definition pkt6.h:31
isc::dhcp::OptionBuffer
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
Definition option.h:24
isc::dhcp::OptionPtr
boost::shared_ptr< Option > OptionPtr
Definition option.h:37
isc::lease_query
Definition blq_msg.h:15
isc::lease_query::LeaseQueryImpl6Ptr
boost::shared_ptr< LeaseQueryImpl6 > LeaseQueryImpl6Ptr
Defines a smart pointer to LeaseQueryImpl6 instance.
Definition lease_query_impl6.h:499
isc::lease_query::PrefixLengthList
std::set< uint8_t > PrefixLengthList
Defines an ordered list of prefix lengths.
Definition lease_query_impl6.h:30
isc::lease_query::RelayInfoPtr
boost::shared_ptr< dhcp::Pkt6::RelayInfo > RelayInfoPtr
Defines a shared pointer to a Pkt6::RelayInfo.
Definition lease_query_impl6.h:26
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148
option6_iaaddr.h
option6_status_code.h
option_custom.h
pkt6.h
isc::dhcp::Lease6
Structure that holds a lease for IPv6 address and/or prefix.
Definition lease.h:536
isc::dhcp::Pkt6::RelayInfo
structure that describes a single relay information
Definition pkt6.h:85