]> 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)
committerMark Andrews <marka@isc.org>
Mon, 21 Apr 2025 23:24:18 +0000 (09:24 +1000)
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.

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

index 249c9989d483f221ed71f91fe4aabe5fe93091ba..52e15e1b90fa58a13d51093f33d135fc046f0234 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 8673dc71211b12d6a53908a9e6743fe8c1189fcd..96f487469e1dc32748e4d9888637eed21fb5b82d 100644 (file)
@@ -3387,39 +3387,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;
 }
 
@@ -3700,7 +3742,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;
                                        }
@@ -4097,7 +4140,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;
                                        }