]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#562] template adapters to existing qualified names
authorAndrei Pavel <andrei@isc.org>
Fri, 6 May 2022 05:55:54 +0000 (08:55 +0300)
committerAndrei Pavel <andrei@isc.org>
Fri, 20 May 2022 17:38:56 +0000 (20:38 +0300)
src/hooks/dhcp/mysql_cb/mysql_cb_impl.h
src/lib/dhcp/Makefile.am
src/lib/dhcp/option_int.h
src/lib/dhcp/option_int_array.h
src/lib/dhcp/pkt_template.h [new file with mode: 0644]
src/lib/dhcpsrv/subnet.h
src/lib/hooks/callout_handle.cc
src/lib/hooks/callout_handle.h
src/lib/util/Makefile.am
src/lib/util/dhcp_space.cc [new file with mode: 0644]
src/lib/util/dhcp_space.h [new file with mode: 0644]

index 3894ced649e5da4c35ffecf00b5017dc585fdbe7..2422a601c7b36efa954f94b9e7832332a4983788 100644 (file)
@@ -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
index 413db74eacad33621c29216df6753b05d5db61cb..4734d8c170ab83feb72242d22b551a81a9096f21 100644 (file)
@@ -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
index caed70aa55c498a478a4b130d5cc27b01b134709..6ccae3ec58230c604e0e1fb9ea549cb95b1b19fa 100644 (file)
@@ -44,7 +44,7 @@ typedef boost::shared_ptr<OptionUint32> OptionUint32Ptr;
 /// - int16_t,
 /// - int32_t.
 ///
-/// @param T data field type (see above).
+/// @tparam T data field type (see above).
 template<typename T>
 class OptionInt: public Option {
 private:
index ec6fc2be8d89dd8b9c729abd75416d9561d3fb55..92dc19830626e2ae673cef5e1b89730c6b0bf02c 100644 (file)
@@ -51,7 +51,7 @@ typedef boost::shared_ptr<OptionUint32Array> 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<typename T>
 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 (file)
index 0000000..a018cf6
--- /dev/null
@@ -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 <dhcp/pkt4.h>
+#include <dhcp/pkt6.h>
+#include <util/dhcp_space.h>
+
+namespace isc {
+
+namespace dhcp {
+
+/// @brief adapters for linking templates to qualified names
+/// @{
+namespace {
+
+template <isc::util::DhcpSpace D>
+struct adapter_Pkt {};
+
+template <>
+struct adapter_Pkt<isc::util::DHCPv4> {
+    using type = Pkt4;
+};
+
+template <>
+struct adapter_Pkt<isc::util::DHCPv6> {
+    using type = Pkt6;
+};
+
+}  // namespace
+
+template <isc::util::DhcpSpace D>
+using PktT = typename adapter_Pkt<D>::type;
+
+template <isc::util::DhcpSpace D>
+using PktTPtr = boost::shared_ptr<PktT<D>>;
+/// @}
+
+}  // namespace dhcp
+}  // namespace isc
+
+#endif  // ISC_PKT_TEMPLATE_H
index 6fe9f13e404563cfc4054dd762ee021d5e5bbc41..4dfad6f3a750344da0475ec8ad0a12224f0f3e6a 100644 (file)
@@ -15,7 +15,9 @@
 #include <dhcpsrv/network.h>
 #include <dhcpsrv/pool.h>
 #include <dhcpsrv/subnet_id.h>
+#include <util/dhcp_space.h>
 #include <util/triplet.h>
+
 #include <boost/multi_index/mem_fun.hpp>
 #include <boost/multi_index/indexed_by.hpp>
 #include <boost/multi_index/ordered_index.hpp>
@@ -25,6 +27,7 @@
 #include <boost/pointer_cast.hpp>
 #include <boost/scoped_ptr.hpp>
 #include <boost/shared_ptr.hpp>
+
 #include <cstdint>
 #include <map>
 #include <mutex>
@@ -995,9 +998,33 @@ using SubnetFetcher4 = SubnetFetcher<Subnet4Ptr, Subnet4Collection>;
 
 /// @brief Type of the @c SubnetFetcher used for IPv6.
 using SubnetFetcher6 = SubnetFetcher<Subnet6Ptr, Subnet6Collection>;
+//@}
 
+/// @brief adapters for linking templates to qualified names
+/// @{
+namespace {
 
-//@}
+template <isc::util::DhcpSpace D>
+struct adapter_Subnet {};
+
+template <>
+struct adapter_Subnet<isc::util::DHCPv4> {
+    using type = Subnet4;
+};
+
+template <>
+struct adapter_Subnet<isc::util::DHCPv6> {
+    using type = Subnet6;
+};
+
+}  // namespace
+
+template <isc::util::DhcpSpace D>
+using SubnetT = typename adapter_Subnet<D>::type;
+
+template <isc::util::DhcpSpace D>
+using SubnetTPtr = boost::shared_ptr<SubnetT<D>>;
+/// @}
 
 } // end of isc::dhcp namespace
 } // end of isc namespace
index e80760ac922aa9420aac4cc520897a7528e5601c..89eae865dbdc5adffaea0e7eba7b8c41a1715d52 100644 (file)
@@ -159,5 +159,25 @@ ScopedCalloutHandleState::resetState() {
     callout_handle_->setStatus(CalloutHandle::NEXT_STEP_CONTINUE);
 }
 
+template <>
+char const* queryArgument<isc::util::DHCPv4>() {
+    return "query4";
+}
+
+template <>
+char const* queryArgument<isc::util::DHCPv6>() {
+    return "query6";
+}
+
+template <>
+char const* subnetArgument<isc::util::DHCPv4>() {
+    return "subnet4";
+}
+
+template <>
+char const* subnetArgument<isc::util::DHCPv6>() {
+    return "subnet6";
+}
+
 } // namespace hooks
 } // namespace isc
index b9e018b7c026ed34c364d1d3b0789ac533bd93a5..017ebe67acf68e4b5f7a64f926bd4667d2e8ff68 100644 (file)
@@ -10,6 +10,7 @@
 #include <exceptions/exceptions.h>
 #include <hooks/library_handle.h>
 #include <hooks/parking_lots.h>
+#include <util/dhcp_space.h>
 
 #include <boost/any.hpp>
 #include <boost/shared_ptr.hpp>
@@ -501,6 +502,12 @@ private:
     CalloutHandlePtr callout_handle_;
 };
 
+template <isc::util::DhcpSpace D>
+char const* queryArgument();
+
+template <isc::util::DhcpSpace D>
+char const* subnetArgument();
+
 } // namespace hooks
 } // namespace isc
 
index cf1f2d6c85dc8786a0f3ca444df6dd5925c3a5b1..e7895ae9ed5af4eadf8208e7fd571b3cc10f0d7c 100644 (file)
@@ -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 (file)
index 0000000..c6bbe31
--- /dev/null
@@ -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 <config.h>
+
+#include <util/dhcp_space.h>
+
+namespace isc {
+namespace util {
+
+template <>
+uint16_t integerDhcpSpace<DHCPv4>() {
+    return 4;
+}
+
+template <>
+uint16_t integerDhcpSpace<DHCPv6>() {
+    return 6;
+}
+
+template <>
+char const* cStringDhcpSpace<DHCPv4>() {
+    return "4";
+}
+
+template <>
+char const* cStringDhcpSpace<DHCPv6>() {
+    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 (file)
index 0000000..2945eef
--- /dev/null
@@ -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 <cstdint>
+
+namespace isc {
+namespace util {
+
+enum DhcpSpace {
+    DHCPv4,
+    DHCPv6,
+};
+
+template <DhcpSpace D>
+constexpr uint16_t integerDhcpSpace();
+
+template <DhcpSpace D>
+constexpr char const* cStringDhcpSpace();
+
+}  // namespace util
+}  // namespace isc
+
+#endif  // ISC_DHCP_SPACE_H