From 81334113c39d419528e540dcf94f0046544f6edb Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Tue, 29 Oct 2024 14:06:57 +1100 Subject: [PATCH] Fix EDNS LLQ option YAML output 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 | 24 +++++++++++++ lib/dns/message.c | 60 ++++++++++++++++++++++++++----- 2 files changed, 76 insertions(+), 8 deletions(-) diff --git a/bin/tests/system/digdelv/tests.sh b/bin/tests/system/digdelv/tests.sh index 249c9989d4..52e15e1b90 100644 --- a/bin/tests/system/digdelv/tests.sh +++ b/bin/tests/system/digdelv/tests.sh @@ -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 2>&1 || ret=1 + read -r value yamlget.out.test$n 2>&1 || ret=1 + read -r value yamlget.out.test$n 2>&1 || ret=1 + read -r value yamlget.out.test$n 2>&1 || ret=1 + read -r value 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; }