]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Split EDNS COOKIE YAML into separate parts
authorMark Andrews <marka@isc.org>
Wed, 30 Oct 2024 03:37:32 +0000 (14:37 +1100)
committerMark Andrews <marka@isc.org>
Mon, 21 Apr 2025 23:24:18 +0000 (09:24 +1000)
Split the YAML display of the EDNS COOKIE option into CLIENT and SERVER
parts.  The STATUS of the EDNS COOKIE in the reply is now a YAML element
rather than a comment.

lib/dns/message.c

index f1e7079aae6bfb7bcb3b5e8f47fc6be59abc22f7..17e3e83e3aef9f2f5cf90565fcb141d54a0c1613 100644 (file)
@@ -3917,6 +3917,68 @@ dns_message_pseudosectiontoyaml(dns_message_t *msg, dns_pseudosection_t section,
                                        continue;
                                }
                                break;
+                       case DNS_OPT_COOKIE:
+                               if (optlen == 8 ||
+                                   (optlen >= 16 && optlen < 40))
+                               {
+                                       size_t i;
+
+                                       msg->indent.count++;
+                                       optdata = isc_buffer_current(&optbuf);
+
+                                       ADD_STRING(target, "\n");
+                                       INDENT(style);
+                                       ADD_STRING(target, "CLIENT: ");
+                                       for (i = 0; i < 8; i++) {
+                                               snprintf(buf, sizeof(buf),
+                                                        "%02x", optdata[i]);
+                                               ADD_STRING(target, buf);
+                                       }
+                                       ADD_STRING(target, "\n");
+
+                                       if (optlen >= 16) {
+                                               INDENT(style);
+                                               ADD_STRING(target, "SERVER: ");
+                                               for (; i < optlen; i++) {
+                                                       snprintf(buf,
+                                                                sizeof(buf),
+                                                                "%02x",
+                                                                optdata[i]);
+                                                       ADD_STRING(target, buf);
+                                               }
+                                               ADD_STRING(target, "\n");
+                                       }
+
+                                       /*
+                                        * Valid server cookie?
+                                        */
+                                       if (msg->cc_ok && optlen >= 16) {
+                                               INDENT(style);
+                                               ADD_STRING(target,
+                                                          "STATUS: good\n");
+                                       }
+                                       /*
+                                        * Server cookie is not valid but
+                                        * we had our cookie echoed back.
+                                        */
+                                       if (msg->cc_ok && optlen < 16) {
+                                               INDENT(style);
+                                               ADD_STRING(target,
+                                                          "STATUS: echoed\n");
+                                       }
+                                       /*
+                                        * We didn't get our cookie echoed
+                                        * back.
+                                        */
+                                       if (msg->cc_bad) {
+                                               INDENT(style);
+                                               ADD_STRING(target,
+                                                          "STATUS: bad\n)");
+                                       }
+                                       isc_buffer_forward(&optbuf, optlen);
+                                       continue;
+                               }
+                               break;
                        default:
                                break;
                        }
@@ -3952,32 +4014,9 @@ dns_message_pseudosectiontoyaml(dns_message_t *msg, dns_pseudosection_t section,
 
                                isc_buffer_forward(&optbuf, optlen);
 
-                               if (optcode == DNS_OPT_COOKIE) {
-                                       /*
-                                        * Valid server cookie?
-                                        */
-                                       if (msg->cc_ok && optlen >= 16) {
-                                               ADD_STRING(target, " (good)");
-                                       }
-                                       /*
-                                        * Server cookie is not valid but
-                                        * we had our cookie echoed back.
-                                        */
-                                       if (msg->cc_ok && optlen < 16) {
-                                               ADD_STRING(target, " (echoed)");
-                                       }
-                                       /*
-                                        * We didn't get our cookie echoed
-                                        * back.
-                                        */
-                                       if (msg->cc_bad) {
-                                               ADD_STRING(target, " (bad)");
-                                       }
-                                       ADD_STRING(target, "\n");
-                                       continue;
-                               }
-
-                               if (optcode == DNS_OPT_CLIENT_SUBNET) {
+                               if (optcode == DNS_OPT_COOKIE ||
+                                   optcode == DNS_OPT_CLIENT_SUBNET)
+                               {
                                        ADD_STRING(target, "\n");
                                        continue;
                                }