Kea 3.1.1
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>
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
22namespace isc {
23namespace lease_query {
24
26typedef boost::shared_ptr<dhcp::Pkt6::RelayInfo> RelayInfoPtr;
27
28
30typedef std::set<uint8_t> PrefixLengthList;
31
34public:
39
41 virtual ~LeaseQueryImpl6(){};
42
54 virtual void processQuery(dhcp::PktPtr base_query) const;
55
78 const PrefixLengthList& prefix_lengths = PrefixLengthList());
79
96 queryByClientId(const dhcp::DuidPtr& client_id,
97 const asiolink::IOAddress& link_addr,
99
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
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
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
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
311
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
380
393 static void testServerId(const dhcp::Pkt6Ptr& query);
394
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
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
459 prefix_lens_.clear();
460 }
461
466 return (prefix_lens_);
467 }
468
477
485 static std::string dumpPrefixLengthList(const PrefixLengthList& prefix_lengths);
486
491
496};
497
499typedef 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
Per-packet callout handle.
static void testServerId(const dhcp::Pkt6Ptr &query)
Validates the server-id of a received DHCPV6_LEASEQUERY.
static RelayInfoPtr parseRelayInfo(data::ConstElementPtr relay)
Converts an Element::map into an Pkt6::RelayInfo instance.
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.
static uint16_t getRelayOverhead(const dhcp::Pkt6::RelayInfo &relay, bool innermost)
Calculates the packed size (in octets) of a given RelayInfo.
static asiolink::IOAddress getPrefixFromAddress(const asiolink::IOAddress &address, const uint8_t prefix_length)
Creates a prefix of a given length from an address.
void addPrefixLength(uint8_t prefix_len)
Add a prefix to the list of prefix lengths.
static dhcp::Pkt6Ptr initDone(const dhcp::Pkt6Ptr &query)
Creates the final query done response.
static std::string dumpPrefixLengthList(const PrefixLengthList &prefix_lengths)
Dump the given list of prefix lengths to a string.
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.
LeaseQueryImpl6(const data::ConstElementPtr config)
Constructor.
void sendResponse(const dhcp::Pkt6Ptr &response) const
Sends a response to the requester.
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.
PrefixLengthList prefix_lens_
List of PD prefix lengths to use when searching for leases by address.
virtual void processQuery(dhcp::PktPtr base_query) const
Processes a single DHCPv6 client Lease Query.
static dhcp::Option6StatusCodePtr makeStatusOption(const DHCPv6StatusCode &status_code, const std::string message="")
Constructs a D6O_STATUS_CODE option.
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.
static dhcp::OptionPtr makeClientOption(dhcp::Lease6Collection &leases)
Constructs a client option based on a collection of leases.
const PrefixLengthList & getPrefixLengthList() const
Fetch the prefix length list.
void clearPrefixLengthList()
Empty the prefix length list.
static dhcp::OptionPtr makeRelayOption(const dhcp::Lease6 &lease)
Constructs a D6O_LQ_RELAY_DATA option from a lease user-context.
static std::string leaseQueryLabel(const dhcp::Pkt6Ptr &packet)
Convenience method for generating per packet logging info.
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.
virtual void send(const dhcp::Pkt6Ptr &response) const
Wrapper around the call to IfaceMgr::send().
static dhcp::Pkt6Ptr buildReply(const dhcp::Option6StatusCodePtr &status, const dhcp::Pkt6Ptr &query, dhcp::Lease6Collection &leases)
Creates a lease query reply packet.
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.
static dhcp::Pkt6Ptr initReply(const dhcp::Pkt6Ptr &query)
Creates the initial query reply.
void populatePrefixLengthList(dhcp::SrvConfigPtr cfg)
Populates the prefix length list from the given configuration.
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.
static void parseRelayInfoList(data::ConstElementPtr relays, std::vector< RelayInfoPtr > &relay_infos)
Converts an Element::list into a list of Pkt6::RelayInfo instances.
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.
bool build_prefix_lens_
True if the prefix length should be gleaned from configured pools.
static int upgradeHandler(hooks::CalloutHandle &handle)
Upgrade extended information.
static dhcp::Pkt6Ptr initData(const dhcp::Pkt6Ptr &query)
Creates the query data response.
LeaseQueryImpl(uint16_t family, const isc::data::ConstElementPtr config)
Constructor.
DHCPv6StatusCode
Definition dhcp6.h:175
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
boost::shared_ptr< isc::dhcp::Pkt > PktPtr
A pointer to either Pkt4 or Pkt6 packet.
Definition pkt.h:999
std::set< dhcp::SubnetID > SubnetIDSet
Ordered list aka set of subnetIDs.
Definition subnet_id.h:43
boost::shared_ptr< DUID > DuidPtr
Definition duid.h:136
boost::shared_ptr< Lease6 > Lease6Ptr
Pointer to a Lease6 structure.
Definition lease.h:528
std::vector< Lease6Ptr > Lease6Collection
A collection of IPv6 leases.
Definition lease.h:693
boost::shared_ptr< SrvConfig > SrvConfigPtr
Non-const pointer to the SrvConfig.
boost::shared_ptr< Option6StatusCode > Option6StatusCodePtr
Pointer to the isc::dhcp::Option6StatusCode.
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
Definition pkt6.h:31
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
Definition option.h:24
boost::shared_ptr< Option > OptionPtr
Definition option.h:37
boost::shared_ptr< LeaseQueryImpl6 > LeaseQueryImpl6Ptr
Defines a smart pointer to LeaseQueryImpl6 instance.
std::set< uint8_t > PrefixLengthList
Defines an ordered list of prefix lengths.
boost::shared_ptr< dhcp::Pkt6::RelayInfo > RelayInfoPtr
Defines a shared pointer to a Pkt6::RelayInfo.
Defines the logger used by the top-level component of kea-lfc.
Structure that holds a lease for IPv6 address and/or prefix.
Definition lease.h:536
structure that describes a single relay information
Definition pkt6.h:85