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.
This commit is contained in:
Mark Andrews 2024-10-29 14:06:57 +11:00
parent 27e8732c17
commit 81334113c3
2 changed files with 76 additions and 8 deletions

View 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

View 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;
}