]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
add some debugging output for use with the DDNS code. [ISC-Bugs 20916]
authorShawn Routhier <sar@isc.org>
Wed, 26 May 2010 22:34:56 +0000 (22:34 +0000)
committerShawn Routhier <sar@isc.org>
Wed, 26 May 2010 22:34:56 +0000 (22:34 +0000)
RELNOTES
common/dns.c
common/print.c
includes/dhcpd.h
includes/site.h

index 4e4054c1b901e7445b7743d10077219dd6c7f98c..0d643a1fe7ef27611234858933dc5eb4d5fef531 100644 (file)
--- a/RELNOTES
+++ b/RELNOTES
@@ -63,6 +63,8 @@ work on other platforms. Please report any problems and suggested fixes to
   allocated in shared networks also now are not offered if the client has
   moved.  [ISC-Bugs #21152]
 
+- Add some debugging output for use with the DDNS code. [ISC-Bugs #20916]
+
                        Changes since 4.2.0a2
 
 - Update the fsync code to work with the changes to the DDNS code.  It now
index 970d7cf9e321a1703fef2ef3502a38afe7f1c99b..b9d6d2ac636b58e1b3da64d6940ad8931600c13e 100644 (file)
@@ -1245,6 +1245,11 @@ void ddns_interlude(isc_task_t  *taskp,
                trace_ddns_input_write(ddns_cb, eresult);
        }
 #endif
+
+#if defined (DEBUG_DNS_UPDATES)
+       print_dns_status(DDNS_PRINT_INBOUND, ddns_cb, eresult);
+#endif
+
        /* This transaction is complete, clear the value */
        dns_client_destroyupdatetrans(&ddns_cb->transaction);
 
@@ -1469,6 +1474,10 @@ ddns_modify_fwd(dhcp_ddns_cb_t *ddns_cb)
                         "address family not supported");
        }
 
+#if defined (DEBUG_DNS_UPDATES)
+       print_dns_status(DDNS_PRINT_OUTBOUND, ddns_cb, result);
+#endif
+
  cleanup:
        if (dataspace != NULL) {
                isc_mem_put(dhcp_gbl_ctx.mctx, dataspace,
@@ -1654,6 +1663,10 @@ ddns_modify_ptr(dhcp_ddns_cb_t *ddns_cb)
                         "address family not supported");
        }
 
+#if defined (DEBUG_DNS_UPDATES)
+       print_dns_status(DDNS_PRINT_OUTBOUND, ddns_cb, result);
+#endif
+
  cleanup:
        if (dataspace != NULL) {
                isc_mem_put(dhcp_gbl_ctx.mctx, dataspace,
index 2f30c96e24b2e9fdffadae961889fb51f06df864..e5772967244afbcbe2579eabe0c1d46a81bbd4d8 100644 (file)
@@ -1209,10 +1209,178 @@ void indent_spaces (FILE *file, int indent)
 }
 
 #if defined (NSUPDATE)
+#if defined (DEBUG_DNS_UPDATES)
 /*
- * Place holder for debug information for ddns.
+ * direction outbound (messages to the dns server)
+ *           inbound  (messages from the dns server)
+ * ddns_cb is the control block associated with the message
+ * result is the result from the dns code.  For outbound calls
+ * it is from the call to pass the message to the dns library.
+ * For inbound calls it is from the event returned by the library.
  *
+ * For outbound messages we print whatever we think is interesting
+ * from the control block.
+ * For inbound messages we only print the transaction id pointer
+ * and the result and expect that the user will match them up as
+ * necessary.  Note well: the transaction information is opaque to
+ * us so we simply print the pointer to it.  This should be sufficient
+ * to match requests and replys in a short sequence but is awkward
+ * when trying to use it for longer sequences.
  */
+void
+print_dns_status (int direction,
+                 struct dhcp_ddns_cb *ddns_cb,
+                 isc_result_t result)
+{
+       char obuf[1024];
+       char *s = obuf, *end = &obuf[sizeof(obuf)-2];
+       char *en;
+       const char *result_str;
+       char ddns_address[
+               sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
+
+       if (direction == DDNS_PRINT_INBOUND) {
+               log_info("DDNS reply: id ptr %p, result: %s",
+                        ddns_cb->transaction, isc_result_totext(result));
+               return;
+       }
+
+       /* 
+        * To avoid having to figure out if any of the strings
+        * aren't NULL terminated, just 0 the whole string
+        */
+       memset(obuf, 0, 1024);
+
+       en = "DDNS request: id ptr ";
+       if (s + strlen(en) + 16 < end) {
+               sprintf(s, "%s%p", en, ddns_cb->transaction);
+               s += strlen(s);
+       } else {
+               goto bailout;
+       }
+
+       switch (ddns_cb->state) {
+       case DDNS_STATE_ADD_FW_NXDOMAIN:
+               en = " add forward ";
+               break;
+       case DDNS_STATE_ADD_FW_YXDHCID:
+               en = " modify forward ";
+               break;
+
+       case DDNS_STATE_ADD_PTR:
+               en = " add reverse ";
+               break;
+
+       case DDNS_STATE_REM_FW_YXDHCID:
+               en = " remove forward ";
+               break;
+
+       case DDNS_STATE_REM_FW_NXRR:
+               en = " remove rrset ";
+               break;
+
+       case DDNS_STATE_REM_PTR:
+               en = " remove reverse ";
+               break;
+
+       case DDNS_STATE_CLEANUP:
+               en = " cleanup ";
+               break;
+
+       default:
+               en = " unknown state ";
+               break;
+       }
+
+       switch (ddns_cb->state) {
+       case DDNS_STATE_ADD_FW_NXDOMAIN:
+       case DDNS_STATE_ADD_FW_YXDHCID:
+       case DDNS_STATE_REM_FW_YXDHCID:
+       case DDNS_STATE_REM_FW_NXRR:
+               strcpy(ddns_address, piaddr(ddns_cb->address));
+               if (s + strlen(en) + strlen(ddns_address) +
+                   ddns_cb->fwd_name.len + 5 < end) {
+                       sprintf(s, "%s%s for %.*s", en, ddns_address,
+                               ddns_cb->fwd_name.len,
+                               ddns_cb->fwd_name.data);
+                       s += strlen(s);
+               } else {
+                       goto bailout;
+               }
+               break;
+
+       case DDNS_STATE_ADD_PTR:
+       case DDNS_STATE_REM_PTR:
+               if (s + strlen(en) + ddns_cb->fwd_name.len +
+                   ddns_cb->rev_name.len + 5 < end) {
+                       sprintf(s, "%s%.*s for %.*s", en,
+                               ddns_cb->fwd_name.len,
+                               ddns_cb->fwd_name.data,
+                               ddns_cb->rev_name.len,
+                               ddns_cb->rev_name.data);
+                       s += strlen(s);
+               } else {
+                       goto bailout;
+               }
+               break;
+
+       case DDNS_STATE_CLEANUP:
+       default:
+               if (s + strlen(en) < end) {
+                       sprintf(s, "%s", en);
+                       s += strlen(s);
+               } else {
+                       goto bailout;
+               }
+               break;
+       }
+
+       en = " zone: ";
+       if (s + strlen(en) + strlen((char *)ddns_cb->zone_name) < end) {
+               sprintf(s, "%s%s", en, ddns_cb->zone_name);
+               s += strlen(s);
+       } else {
+               goto bailout;
+       }
+
+       en = " dhcid: ";
+       if (s + strlen(en) + ddns_cb->dhcid.len < end) {
+               strcpy(s, en);
+               s += strlen(s);
+               strncpy(s, (char *)ddns_cb->dhcid.data + 1,
+                       ddns_cb->dhcid.len - 1);
+               s += strlen(s);
+       } else {
+               goto bailout;
+       }
+
+       en = " ttl: ";
+       if (s + strlen(en) + 10 < end) {
+               sprintf(s, "%s%ld", en, ddns_cb->ttl);
+               s += strlen(s);
+       } else {
+               goto bailout;
+       }
+               
+       en = " result: ";
+       result_str = isc_result_totext(result);
+       if (s + strlen(en) + strlen(result_str) < end) {
+               sprintf(s, "%s%s", en, result_str);
+               s += strlen(s);
+       } else {
+               goto bailout;
+       }
+
+ bailout:
+       /*
+        * We either finished building the string or ran out
+        * of space, print whatever we have in case it is useful
+        */
+       log_info("%s", obuf);
+
+       return;
+}
+#endif
 #endif /* NSUPDATE */
 
 /* Format the given time as "A; # B", where A is the format
index 28df6c86ff9001ac6c8b4b5d4d09451c625218cb..015f22ea53a5fd5c39f2212c3aecee9219082086 100644 (file)
@@ -1538,6 +1538,12 @@ struct ipv6_pool {
 #define DDNS_STATE_REM_FW_NXRR     18
 #define DDNS_STATE_REM_PTR         19
 
+/*
+ * Flags for the dns print function
+ */
+#define DDNS_PRINT_INBOUND  1
+#define DDNS_PRINT_OUTBOUND 0
+
 struct dhcp_ddns_cb;
 
 typedef void (*ddns_action_t)(struct dhcp_ddns_cb *ddns_cb,
@@ -2308,9 +2314,7 @@ int token_print_indent (FILE *, int, int,
                        const char *, const char *, const char *);
 void indent_spaces (FILE *, int);
 #if defined (NSUPDATE)
-#if 0
-void print_dns_status (int, ns_updque *);
-#endif
+void print_dns_status (int, struct dhcp_ddns_cb *, isc_result_t);
 #endif
 const char *print_time(TIME);
 
index c77947d5de78035140fafdf8a574ad01ac38ac51..2238fe7a35d1735ad11fd61350c226d4277c4afe 100644 (file)
 
 /* #define DEBUG_DUMP_ALL_LEASES */
 
+/* Define this if you want to see the requests and replies between the
+   DHCP code and the DNS library code. */
+
+/* #define DEBUG_DNS_UPDATES */
+
 /* Define this if you want DHCP failover protocol support in the DHCP
    server. */