]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#35,!517] Added getDdnsParams() to AllocEngine::ClientContext4/6
authorThomas Markwalder <tmark@isc.org>
Thu, 3 Oct 2019 18:19:33 +0000 (14:19 -0400)
committerThomas Markwalder <tmark@isc.org>
Thu, 10 Oct 2019 12:32:44 +0000 (08:32 -0400)
src/lib/dhcpsrv/alloc_engine.*
    AllocEngine::ClientContext6::getDdnsParams()
    AllocEngine::ClientContext4::getDdnsParams() - new
    methods which return a DdnsParams instance scoped by
    currently selected subnet

    Replaced direct references to context::ddns_params_ with
    new getter methods.

src/lib/dhcpsrv/parsers/simple_parser4.cc
src/lib/dhcpsrv/parsers/simple_parser6.cc
    Removed global defaults for hostname-char-set/replacement

src/lib/dhcpsrv/alloc_engine.cc
src/lib/dhcpsrv/alloc_engine.h
src/lib/dhcpsrv/parsers/simple_parser4.cc
src/lib/dhcpsrv/parsers/simple_parser6.cc
src/lib/dhcpsrv/srv_config.cc

index 35849386528af7bd1af7c9e8dcd7d9f7c230040d..5be2a1d9be93f2481d3e725655cb5e2187ab1f25 100644 (file)
@@ -446,7 +446,7 @@ AllocEngine::ClientContext6::ClientContext6(const Subnet6Ptr& subnet,
       duid_(duid), hwaddr_(), host_identifiers_(), hosts_(),
       fwd_dns_update_(fwd_dns), rev_dns_update_(rev_dns), hostname_(hostname),
       callout_handle_(callout_handle), allocated_resources_(), new_leases_(),
-      ias_(), ddns_params_(new DdnsParams()) {
+      ias_(), ddns_params_() {
 
     // Initialize host identifiers.
     if (duid) {
@@ -538,6 +538,26 @@ AllocEngine::ClientContext6::hasGlobalReservation(const IPv6Resrv& resv) const {
     return (ghost && ghost->hasReservation(resv));
 }
 
+DdnsParamsPtr
+AllocEngine::ClientContext6::getDdnsParams() {
+    // We already have it, return it.
+    if (ddns_params_) {
+        return (ddns_params_);
+    }
+
+    // Haven't created it, so this is the first time we've needed it
+    // since being given a subnet.
+    if (subnet_) {
+        ddns_params_ = CfgMgr::instance().getCurrentCfg()->getDdnsParams(*subnet_);
+        return (ddns_params_);
+    }
+
+    // Asked for it without a subnet? This case really shouldn't occur but
+    // for now let's an instance with default values.
+    std::cout << "ClientContext6, Hey we're accessing this without a subnet!" << std::endl;
+    return (DdnsParamsPtr(new DdnsParams()));
+}
+
 void AllocEngine::findReservation(ClientContext6& ctx) {
     ctx.hosts_.clear();
 
@@ -1157,7 +1177,7 @@ AllocEngine::allocateReservedLeases6(ClientContext6& ctx,
                             // the hostname as it is specified for the reservation.
                             OptionPtr fqdn = ctx.query_->getOption(D6O_CLIENT_FQDN);
                             ctx.hostname_ = CfgMgr::instance().getD2ClientMgr().
-                                qualifyName(host->getHostname(), *ctx.ddns_params_,
+                                qualifyName(host->getHostname(), *ctx.getDdnsParams(),
                                             static_cast<bool>(fqdn));
                         }
                     }
@@ -1230,7 +1250,7 @@ AllocEngine::allocateReservedLeases6(ClientContext6& ctx,
                         // the hostname as it is specified for the reservation.
                         OptionPtr fqdn = ctx.query_->getOption(D6O_CLIENT_FQDN);
                         ctx.hostname_ = CfgMgr::instance().getD2ClientMgr().
-                            qualifyName(host->getHostname(), *ctx.ddns_params_,
+                            qualifyName(host->getHostname(), *ctx.getDdnsParams(),
                                         static_cast<bool>(fqdn));
                     }
                 }
@@ -1306,7 +1326,7 @@ AllocEngine::allocateGlobalReservedLeases6(ClientContext6& ctx,
                     // the hostname as it is specified for the reservation.
                     OptionPtr fqdn = ctx.query_->getOption(D6O_CLIENT_FQDN);
                     ctx.hostname_ = CfgMgr::instance().getD2ClientMgr().
-                                    qualifyName(ghost->getHostname(), *ctx.ddns_params_,
+                                    qualifyName(ghost->getHostname(), *ctx.getDdnsParams(),
                                                 static_cast<bool>(fqdn));
             }
 
@@ -1357,7 +1377,7 @@ AllocEngine::allocateGlobalReservedLeases6(ClientContext6& ctx,
                 // the hostname as it is specified for the reservation.
                 OptionPtr fqdn = ctx.query_->getOption(D6O_CLIENT_FQDN);
                 ctx.hostname_ = CfgMgr::instance().getD2ClientMgr().
-                                qualifyName(ghost->getHostname(), *ctx.ddns_params_,
+                                qualifyName(ghost->getHostname(), *ctx.getDdnsParams(),
                                             static_cast<bool>(fqdn));
             }
 
@@ -3008,7 +3028,7 @@ AllocEngine::ClientContext4::ClientContext4()
       hostname_(""), callout_handle_(), fake_allocation_(false),
       old_lease_(), new_lease_(), hosts_(), conflicting_lease_(),
       query_(), host_identifiers_(),
-      ddns_params_(new DdnsParams()) {
+      ddns_params_() {
 }
 
 AllocEngine::ClientContext4::ClientContext4(const Subnet4Ptr& subnet,
@@ -3047,6 +3067,26 @@ AllocEngine::ClientContext4::currentHost() const {
     return (ConstHostPtr());
 }
 
+DdnsParamsPtr
+AllocEngine::ClientContext4::getDdnsParams() {
+    // We already have it, return it.
+    if (ddns_params_) {
+        return (ddns_params_);
+    }
+
+    // Haven't created it, so this is the first time we've needed it
+    // since being given a subnet.
+    if (subnet_) {
+        ddns_params_ = CfgMgr::instance().getCurrentCfg()->getDdnsParams(*subnet_);
+        return (ddns_params_);
+    }
+
+    // Asked for it without a subnet? This case really shouldn't occur but
+    // for now let's an instance with default values.
+    std::cout << "ClientContext4, Hey we're accessing this without a subnet!" << std::endl;
+    return (DdnsParamsPtr(new DdnsParams()));
+}
+
 Lease4Ptr
 AllocEngine::allocateLease4(ClientContext4& ctx) {
     // The NULL pointer indicates that the old lease didn't exist. It may
index 89e5765ab0b79e016aba9ebd9329659a9904c4a3..3d55fa25ebe73e3f238efb76269b7b64fbb78900 100644 (file)
@@ -553,8 +553,14 @@ public:
         /// @brief Container holding IA specific contexts.
         std::vector<IAContext> ias_;
 
-        /// @brief Holds scoped DDNS behavioral parameters
-        DdnsParamsPtr ddns_params_;
+        /// @brief Returns the set of DDNS behavioral parameters based on
+        /// the selected subnet.
+        ///
+        /// If there is no selected subnet (i.e. subnet_ is empty), the
+        /// returned set will cotain default values.
+        ///
+        /// @return pointer to a DdnsParams instance
+        DdnsParamsPtr getDdnsParams();
 
         /// @brief Convenience method adding allocated prefix or address.
         ///
@@ -652,6 +658,12 @@ public:
                        const Pkt6Ptr& query,
                        const hooks::CalloutHandlePtr& callout_handle =
                        hooks::CalloutHandlePtr());
+
+        private:
+            /// @brief Contains a pointer to the DDNS parameters for selected
+            /// subnet.  Set by the first call to getDdnsParams() made when
+            /// the context has a selected subnet (i.e. subnet_ is not empty).
+            DdnsParamsPtr ddns_params_;
     };
 
     /// @brief Allocates IPv6 leases for a given IA container
@@ -1323,8 +1335,14 @@ public:
         /// received by the server.
         IdentifierList host_identifiers_;
 
-        /// @brief Holds scoped DDNS behavioral parameters
-        DdnsParamsPtr ddns_params_;
+        /// @brief Returns the set of DDNS behavioral parameters based on
+        /// the selected subnet.
+        ///
+        /// If there is no selected subnet (i.e. subnet_ is empty), the
+        /// returned set will cotain default values.
+        ///
+        /// @return pointer to a DdnsParams instance
+        DdnsParamsPtr getDdnsParams();
 
         /// @brief Convenience function adding host identifier into
         /// @ref host_identifiers_ list.
@@ -1364,6 +1382,11 @@ public:
                        const bool fwd_dns_update, const bool rev_dns_update,
                        const std::string& hostname, const bool fake_allocation);
 
+        private:
+            /// @brief Contains a pointer to the DDNS parameters for selected
+            /// subnet.  Set by the first call to getDdnsParams() made when
+            /// the context has a selected subnet (i.e. subnet_ is not empty).
+            DdnsParamsPtr ddns_params_;
     };
 
     /// @brief Pointer to the @c ClientContext4.
index 7f52460d9c0ceee1bc10acd0f63b4508ac75fa72..0224fc159167896331593f5e8f5839420e09ccb3 100644 (file)
@@ -111,9 +111,7 @@ const SimpleDefaults SimpleParser4::GLOBAL4_DEFAULTS = {
     { "ddns-replace-client-name",       Element::string, "never" },
     { "ddns-generated-prefix",          Element::string, "myhost" },
     // TKM should this still be true? qualifying-suffix has no default ??
-    { "ddns-qualifying-suffix",         Element::string, "" },
-    { "hostname-char-set",              Element::string, "" },
-    { "hostname-char-replacement",      Element::string, "" }
+    { "ddns-qualifying-suffix",         Element::string, "" }
 };
 
 /// @brief This table defines all option definition parameters.
index a3d62e084b14b15c75b78f1cb8430e16c7a28066..9bba170a8d4e1174731b8db7b4a1da87b9848321 100644 (file)
@@ -106,9 +106,7 @@ const SimpleDefaults SimpleParser6::GLOBAL6_DEFAULTS = {
     { "ddns-replace-client-name",       Element::string, "never" },
     { "ddns-generated-prefix",          Element::string, "myhost" },
     // TKM should this still be true? qualifying-suffix has no default ??
-    { "ddns-qualifying-suffix",         Element::string, "" },
-    { "hostname-char-set",              Element::string, "" },
-    { "hostname-char-replacement",      Element::string, "" }
+    { "ddns-qualifying-suffix",         Element::string, "" }
 };
 
 /// @brief This table defines all option definition parameters.
index 6052aeadd51132dc6e84847c6fca6732d65d1c10..213ef0263f687fada64f03e0ba5b4a9c4dc4e899 100644 (file)
@@ -594,7 +594,7 @@ SrvConfig::getDdnsParams(const Subnet& subnet) const {
     DdnsParamsPtr params(new DdnsParams());
 
     params->enable_updates_ = (getD2ClientConfig()->getEnableUpdates() &&
-                                  subnet.getDdnsSendUpdates().get());
+                               subnet.getDdnsSendUpdates().get());
 
     params->override_no_update_ = subnet.getDdnsOverrideNoUpdate().get();
     params->override_client_update_ = subnet.getDdnsOverrideClientUpdate().get();