From: Andrei Pavel Date: Fri, 6 May 2022 05:55:54 +0000 (+0300) Subject: [#562] template adapters to existing qualified names X-Git-Tag: Kea-2.1.6~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8781fbf1bab361bbf21160e1df1b3ff85e7574a8;p=thirdparty%2Fkea.git [#562] template adapters to existing qualified names --- diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h index 3894ced649..2422a601c7 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h @@ -644,7 +644,7 @@ public: /// @brief Creates input binding for user context parameter. /// - /// @param T Type of the configuration element to which context belongs. + /// @tparam T Type of the configuration element to which context belongs. /// @param network Pointer to a shared network, subnet or other configuration /// element for which binding should be created. /// @return Pointer to the binding (possibly null binding if context is diff --git a/src/lib/dhcp/Makefile.am b/src/lib/dhcp/Makefile.am index 413db74eac..4734d8c170 100644 --- a/src/lib/dhcp/Makefile.am +++ b/src/lib/dhcp/Makefile.am @@ -56,6 +56,7 @@ libkea_dhcp___la_SOURCES += pkt_filter.h pkt_filter.cc libkea_dhcp___la_SOURCES += pkt_filter6.h pkt_filter6.cc libkea_dhcp___la_SOURCES += pkt_filter_inet.cc pkt_filter_inet.h libkea_dhcp___la_SOURCES += pkt_filter_inet6.cc pkt_filter_inet6.h +libkea_dhcp___la_SOURCES += pkt_template.h libkea_dhcp___la_SOURCES += socket_info.h # Utilize Linux Packet Filtering on Linux. @@ -138,6 +139,7 @@ libkea_dhcp___include_HEADERS = \ pkt_filter6.h \ pkt_filter_inet.h \ pkt_filter_inet6.h \ + pkt_template.h \ protocol_util.h \ socket_info.h \ std_option_defs.h diff --git a/src/lib/dhcp/option_int.h b/src/lib/dhcp/option_int.h index caed70aa55..6ccae3ec58 100644 --- a/src/lib/dhcp/option_int.h +++ b/src/lib/dhcp/option_int.h @@ -44,7 +44,7 @@ typedef boost::shared_ptr OptionUint32Ptr; /// - int16_t, /// - int32_t. /// -/// @param T data field type (see above). +/// @tparam T data field type (see above). template class OptionInt: public Option { private: diff --git a/src/lib/dhcp/option_int_array.h b/src/lib/dhcp/option_int_array.h index ec6fc2be8d..92dc198306 100644 --- a/src/lib/dhcp/option_int_array.h +++ b/src/lib/dhcp/option_int_array.h @@ -51,7 +51,7 @@ typedef boost::shared_ptr OptionUint32ArrayPtr; /// allow addition of sub-options but they will be ignored during /// packing and unpacking option data. /// -/// @param T data field type (see above). +/// @tparam T data field type (see above). template class OptionIntArray : public Option { private: diff --git a/src/lib/dhcp/pkt_template.h b/src/lib/dhcp/pkt_template.h new file mode 100644 index 0000000000..a018cf6164 --- /dev/null +++ b/src/lib/dhcp/pkt_template.h @@ -0,0 +1,47 @@ +// Copyright (C) 2022 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef ISC_PKT_TEMPLATE_H +#define ISC_PKT_TEMPLATE_H + +#include +#include +#include + +namespace isc { + +namespace dhcp { + +/// @brief adapters for linking templates to qualified names +/// @{ +namespace { + +template +struct adapter_Pkt {}; + +template <> +struct adapter_Pkt { + using type = Pkt4; +}; + +template <> +struct adapter_Pkt { + using type = Pkt6; +}; + +} // namespace + +template +using PktT = typename adapter_Pkt::type; + +template +using PktTPtr = boost::shared_ptr>; +/// @} + +} // namespace dhcp +} // namespace isc + +#endif // ISC_PKT_TEMPLATE_H diff --git a/src/lib/dhcpsrv/subnet.h b/src/lib/dhcpsrv/subnet.h index 6fe9f13e40..4dfad6f3a7 100644 --- a/src/lib/dhcpsrv/subnet.h +++ b/src/lib/dhcpsrv/subnet.h @@ -15,7 +15,9 @@ #include #include #include +#include #include + #include #include #include @@ -25,6 +27,7 @@ #include #include #include + #include #include #include @@ -995,9 +998,33 @@ using SubnetFetcher4 = SubnetFetcher; /// @brief Type of the @c SubnetFetcher used for IPv6. using SubnetFetcher6 = SubnetFetcher; +//@} +/// @brief adapters for linking templates to qualified names +/// @{ +namespace { -//@} +template +struct adapter_Subnet {}; + +template <> +struct adapter_Subnet { + using type = Subnet4; +}; + +template <> +struct adapter_Subnet { + using type = Subnet6; +}; + +} // namespace + +template +using SubnetT = typename adapter_Subnet::type; + +template +using SubnetTPtr = boost::shared_ptr>; +/// @} } // end of isc::dhcp namespace } // end of isc namespace diff --git a/src/lib/hooks/callout_handle.cc b/src/lib/hooks/callout_handle.cc index e80760ac92..89eae865db 100644 --- a/src/lib/hooks/callout_handle.cc +++ b/src/lib/hooks/callout_handle.cc @@ -159,5 +159,25 @@ ScopedCalloutHandleState::resetState() { callout_handle_->setStatus(CalloutHandle::NEXT_STEP_CONTINUE); } +template <> +char const* queryArgument() { + return "query4"; +} + +template <> +char const* queryArgument() { + return "query6"; +} + +template <> +char const* subnetArgument() { + return "subnet4"; +} + +template <> +char const* subnetArgument() { + return "subnet6"; +} + } // namespace hooks } // namespace isc diff --git a/src/lib/hooks/callout_handle.h b/src/lib/hooks/callout_handle.h index b9e018b7c0..017ebe67ac 100644 --- a/src/lib/hooks/callout_handle.h +++ b/src/lib/hooks/callout_handle.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -501,6 +502,12 @@ private: CalloutHandlePtr callout_handle_; }; +template +char const* queryArgument(); + +template +char const* subnetArgument(); + } // namespace hooks } // namespace isc diff --git a/src/lib/util/Makefile.am b/src/lib/util/Makefile.am index cf1f2d6c85..e7895ae9ed 100644 --- a/src/lib/util/Makefile.am +++ b/src/lib/util/Makefile.am @@ -11,6 +11,7 @@ libkea_util_la_SOURCES = boost_time_utils.h boost_time_utils.cc libkea_util_la_SOURCES += buffer.h io_utilities.h libkea_util_la_SOURCES += chrono_time_utils.h chrono_time_utils.cc libkea_util_la_SOURCES += csv_file.h csv_file.cc +libkea_util_la_SOURCES += dhcp_space.cc dhcp_space.h libkea_util_la_SOURCES += doubles.h libkea_util_la_SOURCES += file_utilities.h file_utilities.cc libkea_util_la_SOURCES += filename.h filename.cc @@ -59,6 +60,7 @@ libkea_util_include_HEADERS = \ boost_time_utils.h \ buffer.h \ csv_file.h \ + dhcp_space.h \ doubles.h \ file_utilities.h \ filename.h \ diff --git a/src/lib/util/dhcp_space.cc b/src/lib/util/dhcp_space.cc new file mode 100644 index 0000000000..c6bbe31754 --- /dev/null +++ b/src/lib/util/dhcp_space.cc @@ -0,0 +1,35 @@ +// Copyright (C) 2022 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include + +#include + +namespace isc { +namespace util { + +template <> +uint16_t integerDhcpSpace() { + return 4; +} + +template <> +uint16_t integerDhcpSpace() { + return 6; +} + +template <> +char const* cStringDhcpSpace() { + return "4"; +} + +template <> +char const* cStringDhcpSpace() { + return "6"; +} + +} // namespace util +} // namespace isc diff --git a/src/lib/util/dhcp_space.h b/src/lib/util/dhcp_space.h new file mode 100644 index 0000000000..2945eefef8 --- /dev/null +++ b/src/lib/util/dhcp_space.h @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef ISC_DHCP_SPACE_H +#define ISC_DHCP_SPACE_H 1 + +#include + +namespace isc { +namespace util { + +enum DhcpSpace { + DHCPv4, + DHCPv6, +}; + +template +constexpr uint16_t integerDhcpSpace(); + +template +constexpr char const* cStringDhcpSpace(); + +} // namespace util +} // namespace isc + +#endif // ISC_DHCP_SPACE_H