Kea 3.1.5
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
56 virtual void processQuery(isc::dhcp::PktPtr base_query,
57 bool& invalid) const;
58
81 const PrefixLengthList& prefix_lengths = PrefixLengthList());
82
99 queryByClientId(const dhcp::DuidPtr& client_id,
100 const asiolink::IOAddress& link_addr,
101 dhcp::Lease6Collection& leases);
102
121 queryByRelayIdStart(const dhcp::DuidPtr& relay_id,
122 asiolink::IOAddress& start_addr,
123 const size_t page_size,
124 const asiolink::IOAddress& link_addr,
125 dhcp::SubnetIDSet& links,
126 dhcp::Lease6Collection& leases);
127
145 static void queryByRelayIdNext(const dhcp::DuidPtr& relay_id,
146 asiolink::IOAddress& start_addr,
147 const size_t page_size,
148 const dhcp::SubnetIDSet& links,
149 dhcp::Lease6Collection& leases);
150
170 asiolink::IOAddress& start_addr,
171 const size_t page_size,
172 const asiolink::IOAddress& link_addr,
173 dhcp::SubnetIDSet& links,
174 dhcp::Lease6Collection& leases);
175
193 static void queryByRemoteIdNext(const dhcp::OptionBuffer& remote_id,
194 asiolink::IOAddress& start_addr,
195 const size_t page_size,
196 const dhcp::SubnetIDSet& links,
197 dhcp::Lease6Collection& leases);
198
216 const size_t page_size,
217 const asiolink::IOAddress& link_addr,
218 dhcp::SubnetIDSet& links,
219 dhcp::Lease6Collection& leases);
220
236 static void queryByLinkNext(asiolink::IOAddress& start_addr,
237 const size_t page_size,
238 dhcp::SubnetIDSet& links,
239 dhcp::Lease6Collection& leases);
240
254 const dhcp::Pkt6Ptr& query,
255 dhcp::Lease6Collection& leases);
256
267 static dhcp::Pkt6Ptr initReply(const dhcp::Pkt6Ptr& query);
268
276 static dhcp::Pkt6Ptr initData(const dhcp::Pkt6Ptr& query);
277
285 static dhcp::Pkt6Ptr initDone(const dhcp::Pkt6Ptr& query);
286
297 // or
314
327
352 static dhcp::OptionPtr makeRelayOption(const dhcp::Lease6& lease);
353
363 static uint16_t getRelayOverhead(const dhcp::Pkt6::RelayInfo& relay, bool innermost);
364
372 static void parseRelayInfoList(data::ConstElementPtr relays,
373 std::vector<RelayInfoPtr>& relay_infos);
374
383
396 static void testServerId(const dhcp::Pkt6Ptr& query);
397
405 status_code,
406 const std::string message = "");
407
414 void sendResponse(const dhcp::Pkt6Ptr& response) const;
415
423 virtual void send(const dhcp::Pkt6Ptr& response) const;
424
430 static std::string leaseQueryLabel(const dhcp::Pkt6Ptr& packet);
431
439 static int upgradeHandler(hooks::CalloutHandle& handle);
440
448 const uint8_t prefix_length);
449
454 void addPrefixLength(uint8_t prefix_len) {
455 if (prefix_len > 0 && prefix_len <= 128) {
456 prefix_lens_.insert(prefix_len);
457 }
458 }
459
462 prefix_lens_.clear();
463 }
464
469 return (prefix_lens_);
470 }
471
480
488 static std::string dumpPrefixLengthList(const PrefixLengthList& prefix_lengths);
489
494
499};
500
502typedef boost::shared_ptr<LeaseQueryImpl6> LeaseQueryImpl6Ptr;
503
504} // end of namespace isc::lease_query
505} // end of namespace isc
506
507#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.
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.
virtual void processQuery(isc::dhcp::PktPtr base_query, bool &invalid) const
Processes a single DHCPv6 client Lease Query.
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