]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix EDNS LLQ option YAML output
authorMark Andrews <marka@isc.org>
Tue, 29 Oct 2024 03:06:57 +0000 (14:06 +1100)
committerEvan Hunt <each@isc.org>
Wed, 7 May 2025 07:00:10 +0000 (00:00 -0700)
The EDNS LLQ option was not being emitted as valid YAML. Correct
the output to be valid YAML with each field of the LLQ being
individually selectable.

(cherry picked from commit 81334113c39d419528e540dcf94f0046544f6edb)

bin/tests/system/digdelv/tests.sh
lib/dns/message.c

index 5af9f2ff7e6ada608e67955558014371aff2a2a9..51e699241691beabdc196b58a252d122ff1a2246 100644 (file)
@@ -618,6 +618,30 @@ if [ -x "$DIG" ]; then
   if [ $ret -ne 0 ]; then echo_i "failed"; fi
   status=$((status + ret))
 
+  if [ $HAS_PYYAML -ne 0 ]; then
+    n=$((n + 1))
+    echo_i "checking ednsopt LLQ prints as expected +yaml ($n)"
+    ret=0
+    dig_with_opts @10.53.0.3 +yaml +ednsopt=llq:0001000200001234567812345678fefefefe +qr a.example >dig.out.test$n 2>&1 || ret=1
+    $PYTHON yamlget.py dig.out.test$n 0 message query_message_data OPT_PSEUDOSECTION EDNS LLQ LLQ-VERSION >yamlget.out.test$n 2>&1 || ret=1
+    read -r value <yamlget.out.test$n
+    [ "$value" = "1" ] || ret=1
+    $PYTHON yamlget.py dig.out.test$n 0 message query_message_data OPT_PSEUDOSECTION EDNS LLQ LLQ-OPCODE >yamlget.out.test$n 2>&1 || ret=1
+    read -r value <yamlget.out.test$n
+    [ "$value" = "2" ] || ret=1
+    $PYTHON yamlget.py dig.out.test$n 0 message query_message_data OPT_PSEUDOSECTION EDNS LLQ LLQ-ERROR >yamlget.out.test$n 2>&1 || ret=1
+    read -r value <yamlget.out.test$n
+    [ "$value" = "0" ] || ret=1
+    $PYTHON yamlget.py dig.out.test$n 0 message query_message_data OPT_PSEUDOSECTION EDNS LLQ LLQ-ID >yamlget.out.test$n 2>&1 || ret=1
+    read -r value <yamlget.out.test$n
+    [ "$value" = "1311768465173141112" ] || ret=1
+    $PYTHON yamlget.py dig.out.test$n 0 message query_message_data OPT_PSEUDOSECTION EDNS LLQ LLQ-LEASE >yamlget.out.test$n 2>&1 || ret=1
+    read -r value <yamlget.out.test$n
+    [ "$value" = "4278124286" ] || ret=1
+    if [ $ret -ne 0 ]; then echo_i "failed"; fi
+    status=$((status + ret))
+  fi
+
   n=$((n + 1))
   echo_i "checking that dig warns about .local queries ($n)"
   ret=0
index f519bcd20120b9d3937727df4a3605628bb35752..1c9b6dca3d2caad934d7f92792ff007d3f52f433 100644 (file)
@@ -3528,39 +3528,81 @@ cleanup:
 }
 
 static isc_result_t
-render_llq(isc_buffer_t *optbuf, isc_buffer_t *target) {
+render_llq(isc_buffer_t *optbuf, dns_message_t *msg,
+          const dns_master_style_t *style, isc_buffer_t *target) {
        char buf[sizeof("18446744073709551615")]; /* 2^64-1 */
        isc_result_t result = ISC_R_SUCCESS;
        uint32_t u;
        uint64_t q;
+       const char *sep1 = " ", *sep2 = ", ";
+       size_t count = msg->indent.count;
+       bool yaml = false;
+
+       if ((dns_master_styleflags(style) & DNS_STYLEFLAG_YAML) != 0) {
+               sep1 = sep2 = "\n";
+               msg->indent.count++;
+               yaml = true;
+       }
 
        u = isc_buffer_getuint16(optbuf);
-       ADD_STRING(target, " Version: ");
+       ADD_STRING(target, sep1);
+       INDENT(style);
+       if (yaml) {
+               ADD_STRING(target, "LLQ-VERSION: ");
+       } else {
+               ADD_STRING(target, "Version: ");
+       }
        snprintf(buf, sizeof(buf), "%u", u);
        ADD_STRING(target, buf);
 
        u = isc_buffer_getuint16(optbuf);
-       ADD_STRING(target, ", Opcode: ");
+       ADD_STRING(target, sep2);
+       INDENT(style);
+       if (yaml) {
+               ADD_STRING(target, "LLQ-OPCODE: ");
+       } else {
+               ADD_STRING(target, "Opcode: ");
+       }
        snprintf(buf, sizeof(buf), "%u", u);
        ADD_STRING(target, buf);
 
        u = isc_buffer_getuint16(optbuf);
-       ADD_STRING(target, ", Error: ");
+       ADD_STRING(target, sep2);
+       INDENT(style);
+       if (yaml) {
+               ADD_STRING(target, "LLQ-ERROR: ");
+       } else {
+               ADD_STRING(target, "Error: ");
+       }
        snprintf(buf, sizeof(buf), "%u", u);
        ADD_STRING(target, buf);
 
        q = isc_buffer_getuint32(optbuf);
        q <<= 32;
        q |= isc_buffer_getuint32(optbuf);
-       ADD_STRING(target, ", Identifier: ");
+       ADD_STRING(target, sep2);
+       INDENT(style);
+       if (yaml) {
+               ADD_STRING(target, "LLQ-ID: ");
+       } else {
+               ADD_STRING(target, "Identifier: ");
+       }
        snprintf(buf, sizeof(buf), "%" PRIu64, q);
        ADD_STRING(target, buf);
 
        u = isc_buffer_getuint32(optbuf);
-       ADD_STRING(target, ", Lifetime: ");
+       ADD_STRING(target, sep2);
+       INDENT(style);
+       if (yaml) {
+               ADD_STRING(target, "LLQ-LEASE: ");
+       } else {
+               ADD_STRING(target, "Lifetime: ");
+       }
        snprintf(buf, sizeof(buf), "%u", u);
        ADD_STRING(target, buf);
+
 cleanup:
+       msg->indent.count = count;
        return result;
 }
 
@@ -3743,7 +3785,8 @@ dns_message_pseudosectiontoyaml(dns_message_t *msg, dns_pseudosection_t section,
                        switch (optcode) {
                        case DNS_OPT_LLQ:
                                if (optlen == 18U) {
-                                       result = render_llq(&optbuf, target);
+                                       result = render_llq(&optbuf, msg, style,
+                                                           target);
                                        if (result != ISC_R_SUCCESS) {
                                                goto cleanup;
                                        }
@@ -4126,7 +4169,8 @@ dns_message_pseudosectiontotext(dns_message_t *msg, dns_pseudosection_t section,
                        switch (optcode) {
                        case DNS_OPT_LLQ:
                                if (optlen == 18U) {
-                                       result = render_llq(&optbuf, target);
+                                       result = render_llq(&optbuf, msg, style,
+                                                           target);
                                        if (result != ISC_R_SUCCESS) {
                                                return result;
                                        }