From 09caa3186463c16876fa1df376931076c9cefc78 Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Tue, 4 Oct 2022 11:34:56 +0200 Subject: [PATCH 1/6] [#2584] Added extended info containers --- src/lib/dhcpsrv/lease.cc | 4 +- src/lib/dhcpsrv/lease.h | 7 +- src/lib/dhcpsrv/memfile_lease_storage.h | 230 +++++++++++++++++++++++- 3 files changed, 234 insertions(+), 7 deletions(-) diff --git a/src/lib/dhcpsrv/lease.cc b/src/lib/dhcpsrv/lease.cc index e9a2c3d11b..fd77922e76 100644 --- a/src/lib/dhcpsrv/lease.cc +++ b/src/lib/dhcpsrv/lease.cc @@ -333,7 +333,7 @@ Lease4::Lease4(const isc::asiolink::IOAddress& address, : Lease(address, valid_lifetime, subnet_id, cltt, fqdn_fwd, fqdn_rev, hostname, hw_address), - client_id_(client_id) { + client_id_(client_id), remote_id_(), relay_id_() { } std::string @@ -343,7 +343,7 @@ Lease4::statesToText(const uint32_t state) { const std::vector& Lease4::getClientIdVector() const { - if(!client_id_) { + if (!client_id_) { static std::vector empty_vec; return (empty_vec); } diff --git a/src/lib/dhcpsrv/lease.h b/src/lib/dhcpsrv/lease.h index b603ebeee2..a0b3010b97 100644 --- a/src/lib/dhcpsrv/lease.h +++ b/src/lib/dhcpsrv/lease.h @@ -492,6 +492,12 @@ struct Lease4 : public Lease { static Lease4Ptr fromElement(const data::ConstElementPtr& element); /// @todo: Add DHCPv4 failover related fields here + + /// @brief Remote identifier for Bulk Lease Query + std::vector remote_id_; + + /// @brief Relay identifier for Bulk Lease Query + std::vector relay_id_; }; /// @brief A collection of IPv4 leases. @@ -660,7 +666,6 @@ typedef boost::shared_ptr ConstLease6Ptr; /// @brief A collection of IPv6 leases. typedef std::vector Lease6Collection; - /// @brief A shared pointer to the collection of IPv6 leases. typedef boost::shared_ptr Lease6CollectionPtr; diff --git a/src/lib/dhcpsrv/memfile_lease_storage.h b/src/lib/dhcpsrv/memfile_lease_storage.h index 0fe2a70546..6dfe01480c 100644 --- a/src/lib/dhcpsrv/memfile_lease_storage.h +++ b/src/lib/dhcpsrv/memfile_lease_storage.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -47,6 +48,12 @@ struct DuidIndexTag { }; /// @brief Tag for index using hostname. struct HostnameIndexTag { }; +/// @brief Tag for index using remote-id. +struct RemoteIdIndexTag { }; + +/// @brief Tag for index using relay-id. +struct RelayIdIndexTag { }; + /// @name Multi index containers holding DHCPv4 and DHCPv6 leases. /// //@{ @@ -58,6 +65,8 @@ struct HostnameIndexTag { }; /// - using a composite index: DUID, IAID and lease type. /// - using a composite index: boolean flag indicating if the state is /// "expired-reclaimed" and expiration time. +/// - using subnet ID. +/// - using hostname. /// /// Indexes can be accessed using the index number (from 0 to 5) or a /// name tag. It is recommended to use the tags to access indexes as @@ -139,11 +148,15 @@ typedef boost::multi_index_container< /// @brief A multi index container holding DHCPv4 leases. /// /// The leases in the container may be accessed using different indexes: -/// - IPv6 address, -/// - composite index: HW address and subnet id, +/// - IPv4 address, +/// - composite index: hardware address and subnet id, /// - composite index: client id and subnet id, /// - using a composite index: boolean flag indicating if the state is /// "expired-reclaimed" and expiration time. +/// - using subnet id. +/// - using hostname. +/// - using remote id. +/// - using a composite index: /// /// Indexes can be accessed using the index number (from 0 to 5) or a /// name tag. It is recommended to use the tags to access indexes as @@ -225,11 +238,39 @@ typedef boost::multi_index_container< boost::multi_index::member >, - // Specification of the seventh index starts here + // Specification of the sixth index starts here. // This index is used to retrieve leases for matching hostname. - boost::multi_index::ordered_non_unique< + boost::multi_index::hashed_non_unique< boost::multi_index::tag, boost::multi_index::member + >, + + // Specification of the seventh index starts here. + // This index is used to retrieve leases for matching remote id + // for Bulk Lease Query. + boost::multi_index::hashed_non_unique< + boost::multi_index::tag, + boost::multi_index::member, + &Lease4::remote_id_> + >, + + // Specification of the eighth index starts here. + // This index is used to retrieve leases for matching relay id + // for Bulk Lease Query. + boost::multi_index::ordered_non_unique< + boost::multi_index::tag, + boost::multi_index::composite_key< + Lease4, + // Relay id. + boost::multi_index::member, + &Lease4::relay_id_>, + // Address. + boost::multi_index::member + > > > > Lease4Storage; // Specify the type name for this container. @@ -278,7 +319,188 @@ typedef Lease4Storage::index::type Lease4StorageSubnetIdIndex; /// @brief DHCPv4 lease storage index by hostname. typedef Lease4Storage::index::type Lease4StorageHostnameIndex; +/// @brief DHCPv4 lease storage index by remote identifier. +typedef Lease4Storage::index::type Lease4StorageRemoteIdIndex; + +/// @brief DHCPv4 lease storage index by relay identifier. +typedef Lease4Storage::index::type Lease4StorageRelayIdIndex; + +//@} + +/// @name Multi index containers holding DHCPv6 lease extended informations +/// for Bulk Lease Query. +//@{ + +/// @brief Lease6 extended informations for Bulk Lease Query. +class Lease6ExtendedInfo { +public: + /// @brief Lease address. + isc::asiolink::IOAddress lease_addr_; + + /// @brief Link address. + isc::asiolink::IOAddress link_addr_; + + /// @brief Remote or relay opaque identifier. + std::vector id_; +}; + +/// @brief Pointer to a Lease6ExtendedInfo object. +typedef boost::shared_ptr Lease6ExtendedInfoPtr; + +/// @brief Tag for indexes by lease address. +struct LeaseAddressIndexTag { }; + +/// @brief Tag for indexes by relay id and link address. +struct RelayIdLinkAddressIndexTag { }; + +/// @brief Tag for indexes by remote id and link address. +struct RemoteIdLinkAddressIndexTag { }; + +/// @brief Tag for indexes by link address. +struct LinkAddressIndexTag { }; + +/// @brief A multi index container holding lease6 extended info for by relay id. +/// +/// The lease6 extended info may be accessed using different indexes: +/// - using a composite index: relay id and link address. +/// - using relay id. +/// - using lease address. +/// +/// The choice of binary trees was governed by the fact a large number of +/// clients can be behind a relay. +/// +/// Indexes can be accessed using the index number (from 0 to 5) or a +/// name tag. It is recommended to use the tags to access indexes as +/// they do not depend on the order of indexes in the container. +typedef boost::multi_index_container< + // It holds pointers to lease6 extended info. + Lease6ExtendedInfoPtr, + boost::multi_index::indexed_by< + // First index is by relay id and link address. + boost::multi_index::ordered_non_unique< + boost::multi_index::tag, + boost::multi_index::composite_key< + Lease6ExtendedInfo, + boost::multi_index::member, + &Lease6ExtendedInfo::id_>, + boost::multi_index::member + > + >, + + // Second index is by relay id. + boost::multi_index::ordered_non_unique< + boost::multi_index::tag, + boost::multi_index::member, + &Lease6ExtendedInfo::id_> + >, + + // Last index is by lease address. + boost::multi_index::hashed_non_unique< + boost::multi_index::tag, + boost::multi_index::member + > + > +> Lease6ExtendedInfoRelayIdTable; + +/// @brief A multi index container holding lease6 extended info for by remote id. +/// +/// The lease6 extended info may be accessed using different indexes: +/// - using a composite index: remote id and link address. +/// - using remote id. +/// - using lease address. +/// +/// The internal layout of remote id is not used. The choice of hash tables +/// was governed by the fact a small number of clients should share the same +/// remote id. +/// +/// Indexes can be accessed using the index number (from 0 to 5) or a +/// name tag. It is recommended to use the tags to access indexes as +/// they do not depend on the order of indexes in the container. +typedef boost::multi_index_container< + // It holds pointers to lease6 extended info. + Lease6ExtendedInfoPtr, + boost::multi_index::indexed_by< + // First index is by remote id and link address. + boost::multi_index::hashed_non_unique< + boost::multi_index::tag, + boost::multi_index::composite_key< + Lease6ExtendedInfo, + boost::multi_index::member, + &Lease6ExtendedInfo::id_>, + boost::multi_index::member + > + >, + + // Second index is by remote id. + boost::multi_index::hashed_non_unique< + boost::multi_index::tag, + boost::multi_index::member, + &Lease6ExtendedInfo::id_> + >, + + // Last index is by lease address. + boost::multi_index::hashed_non_unique< + boost::multi_index::tag, + boost::multi_index::member + > + > +> Lease6ExtendedInfoRemoteIdTable; + +/// @brief A multi index container holding lease6 extended info +/// for by link address. +/// +/// The lease6 extended info may be accessed using different indexes: +/// - using a composite index: link and lease addresses. +/// - using lease address. +/// +/// The choice of a binary tree was governed by the fact no hypothesis can +/// be done on the number of clients. +/// +/// Indexes can be accessed using the index number (from 0 to 5) or a +/// name tag. It is recommended to use the tags to access indexes as +/// they do not depend on the order of indexes in the container. +typedef boost::multi_index_container< + // It holds pointers to lease6 extended info. + Lease6ExtendedInfoPtr, + boost::multi_index::indexed_by< + // First index is by link and lease addresses. + boost::multi_index::ordered_non_unique< + boost::multi_index::tag, + boost::multi_index::composite_key< + Lease6ExtendedInfo, + boost::multi_index::member, + boost::multi_index::member + > + >, + + // Last index is by lease address. + boost::multi_index::hashed_non_unique< + boost::multi_index::tag, + boost::multi_index::member + > + > +> Lease6ExtendedInfoLinkAddrTable; + //@} + } // end of isc::dhcp namespace } // end of isc namespace -- GitLab From c5c5627df765187202c91ff22303a91e98672cf1 Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Tue, 4 Oct 2022 13:12:08 +0200 Subject: [PATCH 2/6] [#2584] Reverted hostname index to ordered --- src/lib/dhcpsrv/memfile_lease_storage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/dhcpsrv/memfile_lease_storage.h b/src/lib/dhcpsrv/memfile_lease_storage.h index 6dfe01480c..8aa5f1e783 100644 --- a/src/lib/dhcpsrv/memfile_lease_storage.h +++ b/src/lib/dhcpsrv/memfile_lease_storage.h @@ -240,7 +240,7 @@ typedef boost::multi_index_container< // Specification of the sixth index starts here. // This index is used to retrieve leases for matching hostname. - boost::multi_index::hashed_non_unique< + boost::multi_index::ordered_non_unique< boost::multi_index::tag, boost::multi_index::member >, -- GitLab From 911c48b7e64d2eccf1c41da4724c293b76be10b9 Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Tue, 4 Oct 2022 16:39:44 +0200 Subject: [PATCH 3/6] [#2584] Removed v4 code --- src/lib/dhcpsrv/lease.cc | 2 +- src/lib/dhcpsrv/lease.h | 6 --- src/lib/dhcpsrv/memfile_lease_storage.h | 52 ++----------------------- 3 files changed, 4 insertions(+), 56 deletions(-) diff --git a/src/lib/dhcpsrv/lease.cc b/src/lib/dhcpsrv/lease.cc index fd77922e76..d14c53b273 100644 --- a/src/lib/dhcpsrv/lease.cc +++ b/src/lib/dhcpsrv/lease.cc @@ -333,7 +333,7 @@ Lease4::Lease4(const isc::asiolink::IOAddress& address, : Lease(address, valid_lifetime, subnet_id, cltt, fqdn_fwd, fqdn_rev, hostname, hw_address), - client_id_(client_id), remote_id_(), relay_id_() { + client_id_(client_id) { } std::string diff --git a/src/lib/dhcpsrv/lease.h b/src/lib/dhcpsrv/lease.h index a0b3010b97..0c2c791903 100644 --- a/src/lib/dhcpsrv/lease.h +++ b/src/lib/dhcpsrv/lease.h @@ -492,12 +492,6 @@ struct Lease4 : public Lease { static Lease4Ptr fromElement(const data::ConstElementPtr& element); /// @todo: Add DHCPv4 failover related fields here - - /// @brief Remote identifier for Bulk Lease Query - std::vector remote_id_; - - /// @brief Relay identifier for Bulk Lease Query - std::vector relay_id_; }; /// @brief A collection of IPv4 leases. diff --git a/src/lib/dhcpsrv/memfile_lease_storage.h b/src/lib/dhcpsrv/memfile_lease_storage.h index 8aa5f1e783..6828018424 100644 --- a/src/lib/dhcpsrv/memfile_lease_storage.h +++ b/src/lib/dhcpsrv/memfile_lease_storage.h @@ -48,12 +48,6 @@ struct DuidIndexTag { }; /// @brief Tag for index using hostname. struct HostnameIndexTag { }; -/// @brief Tag for index using remote-id. -struct RemoteIdIndexTag { }; - -/// @brief Tag for index using relay-id. -struct RelayIdIndexTag { }; - /// @name Multi index containers holding DHCPv4 and DHCPv6 leases. /// //@{ @@ -65,8 +59,6 @@ struct RelayIdIndexTag { }; /// - using a composite index: DUID, IAID and lease type. /// - using a composite index: boolean flag indicating if the state is /// "expired-reclaimed" and expiration time. -/// - using subnet ID. -/// - using hostname. /// /// Indexes can be accessed using the index number (from 0 to 5) or a /// name tag. It is recommended to use the tags to access indexes as @@ -148,15 +140,11 @@ typedef boost::multi_index_container< /// @brief A multi index container holding DHCPv4 leases. /// /// The leases in the container may be accessed using different indexes: -/// - IPv4 address, -/// - composite index: hardware address and subnet id, +/// - IPv6 address, +/// - composite index: HW address and subnet id, /// - composite index: client id and subnet id, /// - using a composite index: boolean flag indicating if the state is /// "expired-reclaimed" and expiration time. -/// - using subnet id. -/// - using hostname. -/// - using remote id. -/// - using a composite index: /// /// Indexes can be accessed using the index number (from 0 to 5) or a /// name tag. It is recommended to use the tags to access indexes as @@ -238,39 +226,11 @@ typedef boost::multi_index_container< boost::multi_index::member >, - // Specification of the sixth index starts here. + // Specification of the seventh index starts here // This index is used to retrieve leases for matching hostname. boost::multi_index::ordered_non_unique< boost::multi_index::tag, boost::multi_index::member - >, - - // Specification of the seventh index starts here. - // This index is used to retrieve leases for matching remote id - // for Bulk Lease Query. - boost::multi_index::hashed_non_unique< - boost::multi_index::tag, - boost::multi_index::member, - &Lease4::remote_id_> - >, - - // Specification of the eighth index starts here. - // This index is used to retrieve leases for matching relay id - // for Bulk Lease Query. - boost::multi_index::ordered_non_unique< - boost::multi_index::tag, - boost::multi_index::composite_key< - Lease4, - // Relay id. - boost::multi_index::member, - &Lease4::relay_id_>, - // Address. - boost::multi_index::member - > > > > Lease4Storage; // Specify the type name for this container. @@ -319,12 +279,6 @@ typedef Lease4Storage::index::type Lease4StorageSubnetIdIndex; /// @brief DHCPv4 lease storage index by hostname. typedef Lease4Storage::index::type Lease4StorageHostnameIndex; -/// @brief DHCPv4 lease storage index by remote identifier. -typedef Lease4Storage::index::type Lease4StorageRemoteIdIndex; - -/// @brief DHCPv4 lease storage index by relay identifier. -typedef Lease4Storage::index::type Lease4StorageRelayIdIndex; - //@} /// @name Multi index containers holding DHCPv6 lease extended informations -- GitLab From df4f6ff5bf22ff29c3ee4016a38a2b32a1291084 Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Tue, 4 Oct 2022 16:42:35 +0200 Subject: [PATCH 4/6] [#2584] Reverted shared v4/v6 code --- src/lib/dhcpsrv/memfile_lease_storage.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib/dhcpsrv/memfile_lease_storage.h b/src/lib/dhcpsrv/memfile_lease_storage.h index 6828018424..ba3f2e2154 100644 --- a/src/lib/dhcpsrv/memfile_lease_storage.h +++ b/src/lib/dhcpsrv/memfile_lease_storage.h @@ -307,9 +307,15 @@ struct LeaseAddressIndexTag { }; /// @brief Tag for indexes by relay id and link address. struct RelayIdLinkAddressIndexTag { }; +/// @brief Tag for index using relay id. +struct RelayIdIndexTag { }; + /// @brief Tag for indexes by remote id and link address. struct RemoteIdLinkAddressIndexTag { }; +/// @brief Tag for index using remote id. +struct RemoteIdIndexTag { }; + /// @brief Tag for indexes by link address. struct LinkAddressIndexTag { }; -- GitLab From 40075f2c050ad237f5ba79ac786ee9e267530ef2 Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Tue, 4 Oct 2022 16:53:25 +0200 Subject: [PATCH 5/6] [#2584] Added constructors --- src/lib/dhcpsrv/memfile_lease_storage.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/lib/dhcpsrv/memfile_lease_storage.h b/src/lib/dhcpsrv/memfile_lease_storage.h index ba3f2e2154..96643c5139 100644 --- a/src/lib/dhcpsrv/memfile_lease_storage.h +++ b/src/lib/dhcpsrv/memfile_lease_storage.h @@ -288,6 +288,26 @@ typedef Lease4Storage::index::type Lease4StorageHostnameIndex; /// @brief Lease6 extended informations for Bulk Lease Query. class Lease6ExtendedInfo { public: + /// @brief Constructor. + /// + /// @param lease_addr Lease address. + /// @param link_addr Link address. + /// @param id Identifier. + Lease6ExtendedInfo(const isc::asiolink::IOAddress& lease_addr, + const isc::asiolink::IOAddress& link_addr, + const std::vector& id) + : lease_addr_(lease_addr), link_addr_(link_addr), id_(id) { + } + + /// @brief Constructor without id (for the by-link-addr table). + /// + /// @param lease_addr Lease address. + /// @param link_addr Link address. + Lease6ExtendedInfo(const isc::asiolink::IOAddress& lease_addr, + const isc::asiolink::IOAddress& link_addr) + : lease_addr_(lease_addr), link_addr_(link_addr), id_() { + } + /// @brief Lease address. isc::asiolink::IOAddress lease_addr_; -- GitLab From 999e35e30c956bb703df2383bd0cd43b92959b6d Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Tue, 4 Oct 2022 17:09:05 +0200 Subject: [PATCH 6/6] [#2584] Split lease6 extended info class --- src/lib/dhcpsrv/memfile_lease_storage.h | 56 +++++++++++++++---------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/src/lib/dhcpsrv/memfile_lease_storage.h b/src/lib/dhcpsrv/memfile_lease_storage.h index 96643c5139..33380b0a6d 100644 --- a/src/lib/dhcpsrv/memfile_lease_storage.h +++ b/src/lib/dhcpsrv/memfile_lease_storage.h @@ -299,15 +299,6 @@ public: : lease_addr_(lease_addr), link_addr_(link_addr), id_(id) { } - /// @brief Constructor without id (for the by-link-addr table). - /// - /// @param lease_addr Lease address. - /// @param link_addr Link address. - Lease6ExtendedInfo(const isc::asiolink::IOAddress& lease_addr, - const isc::asiolink::IOAddress& link_addr) - : lease_addr_(lease_addr), link_addr_(link_addr), id_() { - } - /// @brief Lease address. isc::asiolink::IOAddress lease_addr_; @@ -336,9 +327,6 @@ struct RemoteIdLinkAddressIndexTag { }; /// @brief Tag for index using remote id. struct RemoteIdIndexTag { }; -/// @brief Tag for indexes by link address. -struct LinkAddressIndexTag { }; - /// @brief A multi index container holding lease6 extended info for by relay id. /// /// The lease6 extended info may be accessed using different indexes: @@ -438,6 +426,32 @@ typedef boost::multi_index_container< > > Lease6ExtendedInfoRemoteIdTable; +/// @brief Lease6 extended informations for Bulk Lease Query, +/// simpler version (2 fields vs 3) for by link address table. +class Lease6SimpleExtendedInfo { +public: + /// @brief Constructor. + /// + /// @param lease_addr Lease address. + /// @param link_addr Link address. + Lease6SimpleExtendedInfo(const isc::asiolink::IOAddress& lease_addr, + const isc::asiolink::IOAddress& link_addr) + : lease_addr_(lease_addr), link_addr_(link_addr) { + } + + /// @brief Lease address. + isc::asiolink::IOAddress lease_addr_; + + /// @brief Link address. + isc::asiolink::IOAddress link_addr_; +}; + +/// @brief Pointer to a Lease6SimpleExtendedInfo object. +typedef boost::shared_ptr Lease6SimpleExtendedInfoPtr; + +/// @brief Tag for indexes by link address. +struct LinkAddressIndexTag { }; + /// @brief A multi index container holding lease6 extended info /// for by link address. /// @@ -453,31 +467,31 @@ typedef boost::multi_index_container< /// they do not depend on the order of indexes in the container. typedef boost::multi_index_container< // It holds pointers to lease6 extended info. - Lease6ExtendedInfoPtr, + Lease6SimpleExtendedInfoPtr, boost::multi_index::indexed_by< // First index is by link and lease addresses. boost::multi_index::ordered_non_unique< boost::multi_index::tag, boost::multi_index::composite_key< - Lease6ExtendedInfo, - boost::multi_index::member, - boost::multi_index::member, + boost::multi_index::member + &Lease6SimpleExtendedInfo::lease_addr_> > >, // Last index is by lease address. boost::multi_index::hashed_non_unique< boost::multi_index::tag, - boost::multi_index::member + &Lease6SimpleExtendedInfo::lease_addr_> > > -> Lease6ExtendedInfoLinkAddrTable; +> Lease6SimpleExtendedInfoLinkAddrTable; //@} -- GitLab