]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2078] Added TSIG context factory
authorFrancis Dupont <fdupont@isc.org>
Mon, 6 Sep 2021 18:07:14 +0000 (20:07 +0200)
committerRazvan Becheriu <razvan@isc.org>
Tue, 7 Sep 2021 09:45:43 +0000 (12:45 +0300)
src/bin/d2/dns_client.cc
src/bin/d2/dns_client.h

index 5aaddd6474cf0e8f4827da7e10908b2e6fa64b53..dd80e7b2b24678bed632244fbcd8cbd80eaea21a 100644 (file)
@@ -207,7 +207,7 @@ DNSClientImpl::doUpdate(asiolink::IOService& io_service,
     // pointer.  Message marshalling uses non-null context is the indicator
     // that TSIG should be used.
     if (tsig_key) {
-        tsig_context_.reset(new TSIGContext(*tsig_key));
+        tsig_context_ = DNSClient::factory(tsig_key);
         tsig_key_name_ = tsig_key->getKeyName().toText();
     } else {
         tsig_context_.reset();
@@ -262,6 +262,14 @@ DNSClientImpl::incrStats(const std::string& stat, bool update_key) {
     }
 }
 
+TSIGContextPtr
+DNSClient::defaultFactory(const D2TsigKeyPtr& tsig_key) {
+    return (TSIGContextPtr(new TSIGContext(*tsig_key)));
+}
+
+DNSClient::TSIGContextFactory
+DNSClient::factory = &DNSClient::defaultFactory;
+
 DNSClient::DNSClient(D2UpdateMessagePtr& response_placeholder,
                      Callback* callback, const DNSClient::Protocol proto)
     : impl_(new DNSClientImpl(response_placeholder, callback, proto)) {
index fb2412523d78eb8705b62fec08e80c815d2b56cd..68544ba6bf084053109a2d5994db09eeac962440 100644 (file)
 
 #include <asiodns/io_fetch.h>
 #include <d2srv/d2_tsig_key.h>
+#include <dns/tsig.h>
 
 namespace isc {
 namespace d2 {
 
+/// @brief Forward declaration of DNSclient class.
 class DNSClient;
 typedef boost::shared_ptr<DNSClient> DNSClientPtr;
 
@@ -83,6 +85,18 @@ public:
         virtual void operator()(DNSClient::Status status) = 0;
     };
 
+    /// @brief TSIGContext factory type.
+    typedef dns::TSIGContextPtr (*TSIGContextFactory)(const D2TsigKeyPtr&);
+
+    /// @brief Pointer to the TSIGContext factory.
+    static TSIGContextFactory factory;
+
+    /// @brief Default TSIGContext factory.
+    ///
+    /// @param tsig_key a D2 TSIG key.
+    /// @return a pointer to a TSIG context.
+    static dns::TSIGContextPtr defaultFactory(const D2TsigKeyPtr& tsig_key);
+
     /// @brief Constructor.
     ///
     /// @param response_placeholder Message object pointer which will be updated