076f82
commit 62a321b12d0e397af88fa422db65079332f971dc
076f82
Author: Florian Weimer <fweimer@redhat.com>
076f82
Date:   Fri Jun 24 18:16:41 2022 +0200
076f82
076f82
    support: Change non-address output format of support_format_dns_packet
076f82
    
076f82
    It makes sense to include the owner name (LHS) and record type in the
076f82
    output, so that they can be checked for correctness.
076f82
    
076f82
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>
076f82
076f82
diff --git a/support/support_format_dns_packet.c b/support/support_format_dns_packet.c
076f82
index 1f8e9ca172a06f4f..c3dff0e019801904 100644
076f82
--- a/support/support_format_dns_packet.c
076f82
+++ b/support/support_format_dns_packet.c
076f82
@@ -101,6 +101,17 @@ extract_name (struct in_buffer full, struct in_buffer *in, struct dname *value)
076f82
   return true;
076f82
 }
076f82
 
076f82
+static void
076f82
+extract_name_data (struct in_buffer full, struct in_buffer *rdata,
076f82
+                   const struct dname *owner, const char *typename, FILE *out)
076f82
+{
076f82
+  struct dname name;
076f82
+  if (extract_name (full, rdata, &name))
076f82
+    fprintf (out, "data: %s %s %s\n", owner->name, typename, name.name);
076f82
+  else
076f82
+    fprintf (out, "error: malformed CNAME/PTR record\n");
076f82
+}
076f82
+
076f82
 char *
076f82
 support_format_dns_packet (const unsigned char *buffer, size_t length)
076f82
 {
076f82
@@ -206,14 +217,11 @@ support_format_dns_packet (const unsigned char *buffer, size_t length)
076f82
           }
076f82
           break;
076f82
         case T_CNAME:
076f82
+          extract_name_data (full, &rdata, &rname, "CNAME", mem.out);
076f82
+          break;
076f82
         case T_PTR:
076f82
-          {
076f82
-            struct dname name;
076f82
-            if (extract_name (full, &rdata, &name))
076f82
-              fprintf (mem.out, "name: %s\n", name.name);
076f82
-            else
076f82
-              fprintf (mem.out, "error: malformed CNAME/PTR record\n");
076f82
-          }
076f82
+          extract_name_data (full, &rdata, &rname, "PTR", mem.out);
076f82
+          break;
076f82
         }
076f82
     }
076f82
 
076f82
diff --git a/support/tst-support_format_dns_packet.c b/support/tst-support_format_dns_packet.c
076f82
index 03ff59457e3bdde8..5596db1785009557 100644
076f82
--- a/support/tst-support_format_dns_packet.c
076f82
+++ b/support/tst-support_format_dns_packet.c
076f82
@@ -85,8 +85,8 @@ test_multiple_cnames (void)
076f82
     "\xc0\x00\x02\x01";
076f82
   check_packet (packet, sizeof (packet) - 1, __func__,
076f82
                 "name: www.example\n"
076f82
-                "name: www1.example\n"
076f82
-                "name: www2.example\n"
076f82
+                "data: www.example CNAME www1.example\n"
076f82
+                "data: www1.example CNAME www2.example\n"
076f82
                 "address: 192.0.2.1\n");
076f82
 }
076f82