]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1548] kea-dhcp6 now supports ddns6_update hook point
authorThomas Markwalder <tmark@isc.org>
Thu, 7 Apr 2022 13:42:19 +0000 (09:42 -0400)
committerThomas Markwalder <tmark@isc.org>
Thu, 21 Apr 2022 14:19:20 +0000 (10:19 -0400)
src/bin/dhcp6/dhcp6_messages.cc b/src/bin/dhcp6/dhcp6_messages.*
    added DHCP6_HOOK_DDNS_UPDATE log message

src/bin/dhcp6/dhcp6_srv.cc
    Dhcpv6Srv::processClientFqdn() - added ddns6_update() hook point

src/bin/dhcp6/dhcp6_messages.cc
src/bin/dhcp6/dhcp6_messages.h
src/bin/dhcp6/dhcp6_messages.mes
src/bin/dhcp6/dhcp6_srv.cc

index e634e27b7d76cbbe78b6297683c3d24cb3c47021..4249c7f6e1c127052aa24af0b7cadd8b194598b3 100644 (file)
@@ -68,6 +68,7 @@ extern const isc::log::MessageID DHCP6_HOOKS_LIBS_RELOAD_FAIL = "DHCP6_HOOKS_LIB
 extern const isc::log::MessageID DHCP6_HOOK_BUFFER_RCVD_DROP = "DHCP6_HOOK_BUFFER_RCVD_DROP";
 extern const isc::log::MessageID DHCP6_HOOK_BUFFER_RCVD_SKIP = "DHCP6_HOOK_BUFFER_RCVD_SKIP";
 extern const isc::log::MessageID DHCP6_HOOK_BUFFER_SEND_SKIP = "DHCP6_HOOK_BUFFER_SEND_SKIP";
+extern const isc::log::MessageID DHCP6_HOOK_DDNS_UPDATE = "DHCP6_HOOK_DDNS_UPDATE";
 extern const isc::log::MessageID DHCP6_HOOK_DECLINE_DROP = "DHCP6_HOOK_DECLINE_DROP";
 extern const isc::log::MessageID DHCP6_HOOK_DECLINE_SKIP = "DHCP6_HOOK_DECLINE_SKIP";
 extern const isc::log::MessageID DHCP6_HOOK_LEASE6_RELEASE_NA_SKIP = "DHCP6_HOOK_LEASE6_RELEASE_NA_SKIP";
@@ -230,6 +231,7 @@ const char* values[] = {
     "DHCP6_HOOK_BUFFER_RCVD_DROP", "received buffer from %1 to %2 over interface %3 was dropped because a callout set the drop flag",
     "DHCP6_HOOK_BUFFER_RCVD_SKIP", "received buffer from %1 to %2 over interface %3 is not parsed because a callout set the next step to SKIP",
     "DHCP6_HOOK_BUFFER_SEND_SKIP", "%1: prepared DHCPv6 response was dropped because a callout set the next step to SKIP",
+    "DHCP6_HOOK_DDNS_UPDATE", "A hook has updated the DDNS parameters: hostname %1=>%2, forward update %3=>%4, reverse update %5=>%6",
     "DHCP6_HOOK_DECLINE_DROP", "During Decline processing (client=%1, interface=%2, addr=%3) hook callout set next step to DROP, dropping packet.",
     "DHCP6_HOOK_DECLINE_SKIP", "During Decline processing (client=%1, interface=%2, addr=%3) hook callout set status to SKIP, skipping decline.",
     "DHCP6_HOOK_LEASE6_RELEASE_NA_SKIP", "%1: DHCPv6 address lease was not released because a callout set the next step to SKIP",
index e2f664f3b2024f8956de16a55cb0dae99ff6a11c..7e88e99a5bbd6d842da28fc4556cbff1935b0918 100644 (file)
@@ -69,6 +69,7 @@ extern const isc::log::MessageID DHCP6_HOOKS_LIBS_RELOAD_FAIL;
 extern const isc::log::MessageID DHCP6_HOOK_BUFFER_RCVD_DROP;
 extern const isc::log::MessageID DHCP6_HOOK_BUFFER_RCVD_SKIP;
 extern const isc::log::MessageID DHCP6_HOOK_BUFFER_SEND_SKIP;
+extern const isc::log::MessageID DHCP6_HOOK_DDNS_UPDATE;
 extern const isc::log::MessageID DHCP6_HOOK_DECLINE_DROP;
 extern const isc::log::MessageID DHCP6_HOOK_DECLINE_SKIP;
 extern const isc::log::MessageID DHCP6_HOOK_LEASE6_RELEASE_NA_SKIP;
index aeb8a4e568728cf33514af1093b940ce7ec59f4f..41f1dc737aec0e50f7b29953461403cc31ddd39d 100644 (file)
@@ -444,6 +444,11 @@ not build the wire data (pack) because it was already done by the
 book. The argument specifies the client and transaction identification
 information.
 
+% DHCP6_HOOK_DDNS_UPDATE A hook has updated the DDNS parameters: hostname %1=>%2, forward update %3=>%4, reverse update %5=>%6
+This message indicates that there was a hook called on ddns_update hook point
+and that hook updated the DDNS update parameters: hostname, or whether to
+conduct forward (A record) or reverse (PTR record) DDNS updates.
+
 % DHCP6_HOOK_SUBNET6_SELECT_DROP %1: packet was dropped because a callout set the drop flag
 This debug message is printed when a callout installed on the
 subnet6_select hook point set the drop flag. For this particular hook
index 96bdd4ea701387a6e97692e4e87c9c52e9ff4cf8..4145e7fbe043541498d79ffc626425912d3ffe97 100644 (file)
@@ -103,6 +103,7 @@ struct Dhcp6Hooks {
     int hook_index_buffer6_send_;     ///< index for "buffer6_send" hook point
     int hook_index_lease6_decline_;   ///< index for "lease6_decline" hook point
     int hook_index_host6_identifier_; ///< index for "host6_identifier" hook point
+    int hook_index_ddns6_update_;     ///< index for "ddns6_update" hook point
 
     /// Constructor that registers hook points for DHCPv6 engine
     Dhcp6Hooks() {
@@ -115,6 +116,7 @@ struct Dhcp6Hooks {
         hook_index_buffer6_send_      = HooksManager::registerHook("buffer6_send");
         hook_index_lease6_decline_    = HooksManager::registerHook("lease6_decline");
         hook_index_host6_identifier_  = HooksManager::registerHook("host6_identifier");
+        hook_index_ddns6_update_      = HooksManager::registerHook("ddns6_update");
     }
 };
 
@@ -1937,6 +1939,45 @@ Dhcpv6Srv::processClientFqdn(const Pkt6Ptr& question, const Pkt6Ptr& answer,
         .arg(question->getLabel())
         .arg(fqdn_resp->toText());
     answer->addOption(fqdn_resp);
+
+    // Optionally, call a hook that may override the decisions made
+    // earlier.
+    if (HooksManager::calloutsPresent(Hooks.hook_index_ddns6_update_)) {
+        CalloutHandlePtr callout_handle = getCalloutHandle(question);
+        Subnet6Ptr subnet = ctx.subnet_;
+
+        // Setup the callout arguments.
+        callout_handle->setArgument("query6", question);
+        callout_handle->setArgument("response6", answer);
+        callout_handle->setArgument("subnet6", subnet);
+        callout_handle->setArgument("hostname", ctx.hostname_);
+        callout_handle->setArgument("fwd-update", ctx.fwd_dns_update_);
+        callout_handle->setArgument("rev-update", ctx.rev_dns_update_);
+        callout_handle->setArgument("ddns-params", ddns_params);
+
+        // Call callouts
+        HooksManager::callCallouts(Hooks.hook_index_ddns6_update_, *callout_handle);
+
+        // Let's get the parameters returned by hook.
+        string hook_hostname;
+        bool hook_fwd_dns_update;
+        bool hook_rev_dns_update;
+        callout_handle->getArgument("hostname", hook_hostname);
+        callout_handle->getArgument("fwd-update", hook_fwd_dns_update);
+        callout_handle->getArgument("rev-update", hook_rev_dns_update);
+
+        // If there's anything changed by the hook, log it and then update the parameters
+        if ((ctx.hostname_ != hook_hostname) || (ctx.fwd_dns_update_!= hook_fwd_dns_update) ||
+            (ctx.rev_dns_update_ != hook_rev_dns_update)) {
+            LOG_DEBUG(hooks_logger, DBGLVL_PKT_HANDLING, DHCP6_HOOK_DDNS_UPDATE)
+                      .arg(ctx.hostname_).arg(hook_hostname).arg(ctx.fwd_dns_update_).arg(hook_fwd_dns_update)
+                      .arg(ctx.rev_dns_update_).arg(hook_rev_dns_update);
+            ctx.hostname_ = hook_hostname;
+            ctx.fwd_dns_update_ = hook_fwd_dns_update;
+            ctx.rev_dns_update_ = hook_rev_dns_update;
+        }
+    }
+
 }
 
 void
@@ -2023,6 +2064,8 @@ Dhcpv6Srv::createNameChangeRequests(const Pkt6Ptr& answer,
                      (*l)->fqdn_fwd_ == do_fwd && (*l)->fqdn_rev_ == do_rev)) {
                     extended_only = true;
                 } else {
+                    std::cout << __LINE__ << "**** doing remove - l.hostname: " << (*l)->hostname_
+                              << ", opt-fqdn: " << opt_fqdn->getDomainName() << std::endl;
                     // Queue a CHG_REMOVE of the old data.
                     // NCR will only be created if the lease hostname is not
                     // empty and at least one of the direction flags is true