}
static void
-print_yaml(dns_dtdata_t *d) {
- Dnstap__Dnstap *frame = d->frame;
+print_dtdata(dns_dtdata_t *dt) {
+ isc_result_t result;
+ isc_buffer_t *b = NULL;
+
+ isc_buffer_allocate(mctx, &b, 2048);
+ if (b == NULL)
+ fatal("out of memory");
+
+ CHECKM(dns_dt_datatotext(dt, &b), "dns_dt_datatotext");
+ printf("%.*s\n", (int) isc_buffer_usedlength(b),
+ (char *) isc_buffer_base(b));
+
+ cleanup:
+ if (b != NULL)
+ isc_buffer_free(&b);
+}
+
+static void
+print_packet(dns_dtdata_t *dt, const dns_master_style_t *style) {
+ isc_buffer_t *b = NULL;
+ isc_result_t result;
+
+ if (dt->msg != NULL) {
+ size_t textlen = 2048;
+
+ isc_buffer_allocate(mctx, &b, textlen);
+ if (b == NULL)
+ fatal("out of memory");
+
+ for (;;) {
+ isc_buffer_reserve(&b, textlen);
+ if (b == NULL)
+ fatal("out of memory");
+
+ result = dns_message_totext(dt->msg, style, 0, b);
+ if (result == ISC_R_NOSPACE) {
+ textlen *= 2;
+ continue;
+ } else if (result == ISC_R_SUCCESS) {
+ printf("%.*s",
+ (int) isc_buffer_usedlength(b),
+ (char *) isc_buffer_base(b));
+ isc_buffer_free(&b);
+ } else {
+ isc_buffer_free(&b);
+ CHECKM(result, "dns_message_totext");
+ }
+ break;
+ }
+ }
+
+ cleanup:
+ if (b != NULL)
+ isc_buffer_free(&b);
+}
+
+static void
+print_yaml(dns_dtdata_t *dt) {
+ Dnstap__Dnstap *frame = dt->frame;
Dnstap__Message *m = frame->message;
const ProtobufCEnumValue *ftype, *mtype;
+ static isc_boolean_t first = ISC_TRUE;
ftype = protobuf_c_enum_descriptor_get_value(
&dnstap__dnstap__type__descriptor,
if (ftype == NULL)
return;
+ if (!first)
+ printf("---\n");
+ else
+ first = ISC_FALSE;
+
printf("type: %s\n", ftype->name);
if (frame->has_identity)
printf(" type: %s\n", mtype->name);
- if (!isc_time_isepoch(&d->qtime)) {
+ if (!isc_time_isepoch(&dt->qtime)) {
char buf[100];
- isc_time_formatISO8601(&d->qtime, buf, sizeof(buf));
+ isc_time_formatISO8601(&dt->qtime, buf, sizeof(buf));
printf(" query_time: !!timestamp %s\n", buf);
}
- if (!isc_time_isepoch(&d->rtime)) {
+ if (!isc_time_isepoch(&dt->rtime)) {
char buf[100];
- isc_time_formatISO8601(&d->rtime, buf, sizeof(buf));
+ isc_time_formatISO8601(&dt->rtime, buf, sizeof(buf));
printf(" response_time: !!timestamp %s\n", buf);
}
+ if (dt->msgdata.base != NULL) {
+ printf(" message_size: %zdb\n", (size_t) dt->msgdata.length);
+ } else
+ printf(" message_size: 0b\n");
+
if (m->has_socket_family) {
const ProtobufCEnumValue *type =
protobuf_c_enum_descriptor_get_value(
printf(" socket_family: %s\n", type->name);
}
- printf(" socket_protocol: %s\n", d->tcp ? "TCP" : "UDP");
+ printf(" socket_protocol: %s\n", dt->tcp ? "TCP" : "UDP");
if (m->has_query_address) {
ProtobufCBinaryData *ip = &m->query_address;
}
}
- if (d->msg != NULL)
- printf(" %s: |\n", ((d->type & DNS_DTTYPE_QUERY) != 0)
- ? "query_message" : "response_message");
+ if (dt->msg != NULL) {
+ printf(" %s:\n", ((dt->type & DNS_DTTYPE_QUERY) != 0)
+ ? "query_message_data"
+ : "response_message_data");
+
+ print_packet(dt, &dns_master_style_yaml);
+
+ printf(" %s: |\n", ((dt->type & DNS_DTTYPE_QUERY) != 0)
+ ? "query_message"
+ : "response_message");
+ print_packet(dt, &dns_master_style_indent);
+ }
};
int
dns_message_t *message = NULL;
isc_buffer_t *b = NULL;
dns_dtdata_t *dt = NULL;
- const dns_master_style_t *style = &dns_master_style_debug;
dns_dthandle_t *handle = NULL;
int rv = 0, ch;
break;
case 'y':
yaml = ISC_TRUE;
- style = &dns_master_style_indent;
- dns_master_indentstr = " ";
- printmessage = ISC_TRUE;
+ dns_master_indentstr = " ";
+ dns_master_indent = 2;
break;
default:
usage();
continue;
}
- if (yaml)
+ if (yaml) {
print_yaml(dt);
- else {
- CHECKM(dns_dt_datatotext(dt, &b), "dns_dt_datatotext");
- printf("%.*s\n", (int) isc_buffer_usedlength(b),
- (char *) isc_buffer_base(b));
+ } else if (printmessage) {
+ print_dtdata(dt);
+ print_packet(dt, &dns_master_style_debug);
+ } else {
+ print_dtdata(dt);
}
- if (printmessage && dt->msg != NULL) {
- size_t textlen = 2048;
-
- isc_buffer_clear(b);
-
- for (;;) {
- isc_buffer_reserve(&b, textlen);
- if (b == NULL)
- fatal("out of memory");
- result = dns_message_totext(dt->msg, style,
- 0, b);
- if (result == ISC_R_NOSPACE) {
- textlen *= 2;
- continue;
- } else if (result == ISC_R_SUCCESS) {
- printf("%.*s",
- (int) isc_buffer_usedlength(b),
- (char *) isc_buffer_base(b));
- isc_buffer_free(&b);
- } else {
- isc_buffer_free(&b);
- CHECKM(result, "dns_message_totext");
- }
- break;
- }
- }
-
- if (yaml)
- printf("---\n");
-
dns_dtdata_free(&dt);
}
#include <stdlib.h>
+#include <isc/buffer.h>
#include <isc/event.h>
#include <isc/file.h>
#include <isc/magic.h>
24, 32, 40, 48, 80, 8, UINT_MAX
};
+/*%
+ * YAML style
+ */
+LIBDNS_EXTERNAL_DATA const dns_master_style_t
+dns_master_style_yaml = {
+ DNS_STYLEFLAG_YAML |
+ DNS_STYLEFLAG_REL_OWNER |
+ DNS_STYLEFLAG_INDENT,
+ 24, 32, 40, 48, 80, 8, UINT_MAX
+};
/*%
* Default indent string.
*/
LIBDNS_EXTERNAL_DATA const char *dns_master_indentstr = "\t";
+LIBDNS_EXTERNAL_DATA unsigned int dns_master_indent = 1;
#define N_SPACES 10
static char spaces[N_SPACES+1] = " ";
r.base[0] = '\n';
isc_buffer_add(&buf, 1);
- if ((ctx->style.flags & DNS_STYLEFLAG_INDENT) != 0) {
- unsigned int ilen = strlen(dns_master_indentstr);
- isc_buffer_availableregion(&buf, &r);
- if (r.length < ilen)
- return (DNS_R_TEXTTOOLONG);
- isc_buffer_putmem(&buf,
- (const isc_uint8_t *) dns_master_indentstr,
- (unsigned int)ilen);
+ if ((ctx->style.flags & DNS_STYLEFLAG_INDENT) != 0 ||
+ (ctx->style.flags & DNS_STYLEFLAG_YAML) != 0)
+ {
+ unsigned int i, len = strlen(dns_master_indentstr);
+ for (i = 0; i < dns_master_indent; i++) {
+ if (isc_buffer_availablelength(&buf) < len)
+ return (DNS_R_TEXTTOOLONG);
+ isc_buffer_putstr(&buf, dns_master_indentstr);
+ }
}
if ((ctx->style.flags & DNS_STYLEFLAG_COMMENTDATA) != 0) {
#define INDENT_TO(col) \
do { \
- if ((result = indent(&column, ctx->style.col, \
+ if ((ctx->style.flags & DNS_STYLEFLAG_YAML) != 0) { \
+ if ((result = str_totext(" ", target)) \
+ != ISC_R_SUCCESS) \
+ return (result); \
+ } else if ((result = indent(&column, ctx->style.col, \
ctx->style.tab_width, target)) \
!= ISC_R_SUCCESS) \
return (result); \
unsigned int type_start;
dns_fixedname_t fixed;
dns_name_t *name = NULL;
+ unsigned int i;
REQUIRE(DNS_RDATASET_VALID(rdataset));
/*
* Indent?
*/
- if ((ctx->style.flags & DNS_STYLEFLAG_INDENT) != 0)
- RETERR(str_totext(dns_master_indentstr, target));
+ if ((ctx->style.flags & DNS_STYLEFLAG_INDENT) != 0 ||
+ (ctx->style.flags & DNS_STYLEFLAG_YAML) != 0)
+ for (i = 0; i < dns_master_indent; i++)
+ RETERR(str_totext(dns_master_indentstr,
+ target));
+
+ /*
+ * YAML enumerator?
+ */
+ if ((ctx->style.flags & DNS_STYLEFLAG_YAML) != 0) {
+ RETERR(str_totext("- ", target));
+ }
/*
* Comment?
*/
INDENT_TO(rdata_column);
if ((rdataset->attributes & DNS_RDATASETATTR_NEGATIVE) != 0) {
- if ((ctx->style.flags & DNS_STYLEFLAG_INDENT) != 0)
- RETERR(str_totext(dns_master_indentstr,
- target));
+ if ((ctx->style.flags & DNS_STYLEFLAG_INDENT) != 0 ||
+ (ctx->style.flags & DNS_STYLEFLAG_YAML) != 0)
+ {
+ for (i = 0; i < dns_master_indent; i++)
+ RETERR(str_totext(dns_master_indentstr,
+ target));
+ }
if (NXDOMAIN(rdataset))
RETERR(str_totext(";-$NXDOMAIN\n", target));
else
for (i = 0; i < n; i++) {
dns_rdataset_t *rds = sorted[i];
- if (ctx->style.flags & DNS_STYLEFLAG_TRUST)
- fprintf(f, "%s; %s\n",
- (ctx->style.flags & DNS_STYLEFLAG_INDENT)
- ? dns_master_indentstr : "",
- dns_trust_totext(rds->trust));
+ if (ctx->style.flags & DNS_STYLEFLAG_TRUST) {
+ if ((ctx->style.flags & DNS_STYLEFLAG_INDENT) != 0 ||
+ (ctx->style.flags & DNS_STYLEFLAG_YAML) != 0)
+ {
+ unsigned int j;
+ for (j = 0; j < dns_master_indent; j++)
+ fprintf(f, "%s", dns_master_indentstr);
+ }
+ fprintf(f, "; %s\n", dns_trust_totext(rds->trust));
+ }
if (((rds->attributes & DNS_RDATASETATTR_NEGATIVE) != 0) &&
(ctx->style.flags & DNS_STYLEFLAG_NCACHE) == 0) {
/* Omit negative cache entries */
memset(buf, 0, sizeof(buf));
isc_buffer_init(&b, buf, sizeof(buf) - 1);
dns_time64_totext((isc_uint64_t)rds->resign, &b);
- fprintf(f, "%s; resign=%s\n",
- (ctx->style.flags & DNS_STYLEFLAG_INDENT)
- ? dns_master_indentstr : "",
- buf);
+ if ((ctx->style.flags & DNS_STYLEFLAG_INDENT) != 0 ||
+ (ctx->style.flags & DNS_STYLEFLAG_YAML) != 0)
+ {
+ unsigned int j;
+ for (j = 0; j < dns_master_indent; j++)
+ fprintf(f, "%s", dns_master_indentstr);
+ }
+ fprintf(f, "; resign=%s\n", buf);
}
dns_rdataset_disassociate(rds);
}
style->line_length = line_length;
style->tab_width = tab_width;
style->split_width = split_width;
-
*stylep = style;
return (ISC_R_SUCCESS);
}
#define VALID_SECTION(s) (((s) >= DNS_SECTION_ANY) \
&& ((s) < DNS_SECTION_MAX))
#define ADD_STRING(b, s) {if (strlen(s) >= \
- isc_buffer_availablelength(b)) \
- return(ISC_R_NOSPACE); else \
+ isc_buffer_availablelength(b)) { \
+ result = ISC_R_NOSPACE; \
+ goto cleanup; \
+ } else \
isc_buffer_putstr(b, s);}
#define VALID_PSEUDOSECTION(s) (((s) >= DNS_PSEUDOSECTION_ANY) \
&& ((s) < DNS_PSEUDOSECTION_MAX))
}
}
+#define INDENT(sp) \
+ do { \
+ unsigned int __i, __flags = dns_master_styleflags(sp); \
+ if ((__flags & DNS_STYLEFLAG_INDENT) == 0 && \
+ (__flags & DNS_STYLEFLAG_YAML) == 0) \
+ break; \
+ for (__i = 0; __i < dns_master_indent; __i++) { \
+ ADD_STRING(target, dns_master_indentstr); \
+ } \
+ } while (0)
+
isc_result_t
dns_message_sectiontotext(dns_message_t *msg, dns_section_t section,
const dns_master_style_t *style,
isc_buffer_t *target) {
dns_name_t *name, empty_name;
dns_rdataset_t *rdataset;
- isc_result_t result;
+ isc_result_t result = ISC_R_SUCCESS;
isc_boolean_t seensoa = ISC_FALSE;
- unsigned int sflags = dns_master_styleflags(style);
+ unsigned int sflags, saveindent;
REQUIRE(DNS_MESSAGE_VALID(msg));
REQUIRE(target != NULL);
REQUIRE(VALID_SECTION(section));
+ saveindent = dns_master_indent;
+ sflags = dns_master_styleflags(style);
if (ISC_LIST_EMPTY(msg->sections[section]))
- return (ISC_R_SUCCESS);
+ goto cleanup;
+
- if ((flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0) {
- if ((sflags & DNS_STYLEFLAG_INDENT) != 0)
- ADD_STRING(target, dns_master_indentstr);
+ INDENT(style);
+ if ((sflags & DNS_STYLEFLAG_YAML) != 0) {
+ if (msg->opcode != dns_opcode_update) {
+ ADD_STRING(target, sectiontext[section]);
+ } else {
+ ADD_STRING(target, updsectiontext[section]);
+ }
+ ADD_STRING(target, "_SECTION:\n");
+ } else if ((flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0) {
ADD_STRING(target, ";; ");
if (msg->opcode != dns_opcode_update) {
ADD_STRING(target, sectiontext[section]);
dns_name_init(&empty_name, NULL);
result = dns_message_firstname(msg, section);
if (result != ISC_R_SUCCESS) {
- return (result);
+ goto cleanup;
+ }
+ if ((sflags & DNS_STYLEFLAG_YAML) != 0) {
+ dns_master_indent++;
}
do {
name = NULL;
seensoa = ISC_TRUE;
}
if (section == DNS_SECTION_QUESTION) {
- if ((sflags & DNS_STYLEFLAG_INDENT) != 0)
- ADD_STRING(target,
- dns_master_indentstr);
- ADD_STRING(target, ";");
+ INDENT(style);
+ if ((sflags & DNS_STYLEFLAG_YAML) != 0) {
+ ADD_STRING(target, "- ");
+ } else {
+ ADD_STRING(target, ";");
+ }
result = dns_master_questiontotext(name,
rdataset,
style,
target);
}
if (result != ISC_R_SUCCESS)
- return (result);
+ goto cleanup;
}
result = dns_message_nextname(msg, section);
} while (result == ISC_R_SUCCESS);
+ if ((sflags & DNS_STYLEFLAG_YAML) != 0) {
+ dns_master_indent--;
+ }
if ((flags & DNS_MESSAGETEXTFLAG_NOHEADERS) == 0 &&
- (flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0) {
- if ((sflags & DNS_STYLEFLAG_INDENT) != 0)
- ADD_STRING(target, dns_master_indentstr);
+ (flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0 &&
+ (sflags & DNS_STYLEFLAG_YAML) == 0)
+ {
+ INDENT(style);
ADD_STRING(target, "\n");
}
if (result == ISC_R_NOMORE)
result = ISC_R_SUCCESS;
+
+ cleanup:
+ dns_master_indent = saveindent;
return (result);
}
char addr[16], addr_text[64];
isc_uint16_t family;
isc_uint8_t addrlen, addrbytes, scopelen;
+ isc_result_t result;
/*
* Note: This routine needs to handle malformed ECS options.
ADD_STRING(target, addr_text);
snprintf(addr_text, sizeof(addr_text), "/%d/%d", addrlen, scopelen);
ADD_STRING(target, addr_text);
- return (ISC_R_SUCCESS);
+
+ result = ISC_R_SUCCESS;
+
+ cleanup:
+ return (result);
+}
+
+
+static isc_result_t
+dns_message_pseudosectiontoyaml(dns_message_t *msg,
+ dns_pseudosection_t section,
+ const dns_master_style_t *style,
+ dns_messagetextflag_t flags,
+ isc_buffer_t *target)
+{
+ dns_rdataset_t *ps = NULL;
+ dns_name_t *name = NULL;
+ isc_result_t result = ISC_R_SUCCESS;
+ char buf[sizeof("1234567890")];
+ isc_uint32_t mbz;
+ dns_rdata_t rdata;
+ isc_buffer_t optbuf;
+ isc_uint16_t optcode, optlen;
+ unsigned char *optdata;
+ unsigned int saveindent = dns_master_indent;
+
+ REQUIRE(DNS_MESSAGE_VALID(msg));
+ REQUIRE(target != NULL);
+ REQUIRE(VALID_PSEUDOSECTION(section));
+
+ switch (section) {
+ case DNS_PSEUDOSECTION_OPT:
+ ps = dns_message_getopt(msg);
+ if (ps == NULL) {
+ goto cleanup;
+ }
+
+ INDENT(style);
+ ADD_STRING(target, "OPT_PSEUDOSECTION:\n");
+ dns_master_indent++;
+
+ INDENT(style);
+ ADD_STRING(target, "EDNS:\n");
+ dns_master_indent++;
+
+ INDENT(style);
+ ADD_STRING(target, "version: ");
+ snprintf(buf, sizeof(buf), "%u",
+ (unsigned int)((ps->ttl & 0x00ff0000) >> 16));
+ ADD_STRING(target, buf);
+ ADD_STRING(target, "\n");
+ INDENT(style);
+ ADD_STRING(target, "flags:");
+ if ((ps->ttl & DNS_MESSAGEEXTFLAG_DO) != 0)
+ ADD_STRING(target, " do");
+ ADD_STRING(target, "\n");
+ mbz = ps->ttl & 0xffff;
+ mbz &= ~DNS_MESSAGEEXTFLAG_DO; /* Known Flags. */
+ if (mbz != 0) {
+ INDENT(style);
+ ADD_STRING(target, "MBZ: ");
+ snprintf(buf, sizeof(buf), "0x%.4x", mbz);
+ ADD_STRING(target, buf);
+ ADD_STRING(target, "\n");
+ }
+ INDENT(style);
+ ADD_STRING(target, "udp: ");
+ snprintf(buf, sizeof(buf), "%u\n", (unsigned int)ps->rdclass);
+ ADD_STRING(target, buf);
+ result = dns_rdataset_first(ps);
+ if (result != ISC_R_SUCCESS) {
+ result = ISC_R_SUCCESS;
+ goto cleanup;
+ }
+
+ /*
+ * Print EDNS info, if any.
+ *
+ * WARNING: The option contents may be malformed as
+ * dig +ednsopt=value:<content> does not validity
+ * checking.
+ */
+ dns_rdata_init(&rdata);
+ dns_rdataset_current(ps, &rdata);
+
+ isc_buffer_init(&optbuf, rdata.data, rdata.length);
+ isc_buffer_add(&optbuf, rdata.length);
+ while (isc_buffer_remaininglength(&optbuf) != 0) {
+ INSIST(isc_buffer_remaininglength(&optbuf) >= 4U);
+ optcode = isc_buffer_getuint16(&optbuf);
+ optlen = isc_buffer_getuint16(&optbuf);
+ INSIST(isc_buffer_remaininglength(&optbuf) >= optlen);
+
+ if (optcode == DNS_OPT_NSID) {
+ INDENT(style);
+ ADD_STRING(target, "NSID");
+ } else if (optcode == DNS_OPT_COOKIE) {
+ INDENT(style);
+ ADD_STRING(target, "COOKIE");
+ } else if (optcode == DNS_OPT_CLIENT_SUBNET) {
+ isc_buffer_t ecsbuf;
+ INDENT(style);
+ ADD_STRING(target, "CLIENT-SUBNET");
+ isc_buffer_init(&ecsbuf,
+ isc_buffer_current(&optbuf),
+ optlen);
+ isc_buffer_add(&ecsbuf, optlen);
+ result = render_ecs(&ecsbuf, target);
+ if (result == ISC_R_NOSPACE)
+ goto cleanup;
+ if (result == ISC_R_SUCCESS) {
+ isc_buffer_forward(&optbuf, optlen);
+ ADD_STRING(target, "\n");
+ continue;
+ }
+ ADD_STRING(target, "\n");
+ } else if (optcode == DNS_OPT_EXPIRE) {
+ if (optlen == 4) {
+ isc_uint32_t secs;
+ secs = isc_buffer_getuint32(&optbuf);
+ INDENT(style);
+ ADD_STRING(target, "EXPIRE: ");
+ snprintf(buf, sizeof(buf), "%u", secs);
+ ADD_STRING(target, buf);
+ ADD_STRING(target, " (");
+ result = dns_ttl_totext(secs,
+ ISC_TRUE,
+ target);
+ if (result != ISC_R_SUCCESS)
+ goto cleanup;
+ ADD_STRING(target, ")\n");
+ continue;
+ }
+ INDENT(style);
+ ADD_STRING(target, "EXPIRE");
+ } else if (optcode == DNS_OPT_PAD) {
+ INDENT(style);
+ ADD_STRING(target, "PAD");
+ } else {
+ INDENT(style);
+ ADD_STRING(target, "OPT: ");
+ snprintf(buf, sizeof(buf), "%u", optcode);
+ ADD_STRING(target, buf);
+ ADD_STRING(target, "\n");
+ }
+
+ if (optlen != 0) {
+ int i;
+ ADD_STRING(target, ": ");
+
+ optdata = isc_buffer_current(&optbuf);
+ for (i = 0; i < optlen; i++) {
+ const char *sep;
+ switch (optcode) {
+ case DNS_OPT_COOKIE:
+ sep = "";
+ break;
+ default:
+ sep = " ";
+ break;
+ }
+ snprintf(buf, sizeof(buf), "%02x%s",
+ optdata[i], sep);
+ ADD_STRING(target, buf);
+ }
+
+ 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) {
+ ADD_STRING(target, "\n");
+ continue;
+ }
+
+ /*
+ * For non-COOKIE options, add a printable
+ * version
+ */
+ ADD_STRING(target, "(\"");
+ if (isc_buffer_availablelength(target) < optlen)
+ {
+ result = ISC_R_NOSPACE;
+ goto cleanup;
+ }
+ for (i = 0; i < optlen; i++) {
+ if (isprint(optdata[i]))
+ isc_buffer_putmem(target,
+ &optdata[i],
+ 1);
+ else
+ isc_buffer_putstr(target, ".");
+ }
+ ADD_STRING(target, "\")");
+ }
+ ADD_STRING(target, "\n");
+ }
+ result = ISC_R_SUCCESS;
+ goto cleanup;
+ case DNS_PSEUDOSECTION_TSIG:
+ ps = dns_message_gettsig(msg, &name);
+ if (ps == NULL) {
+ result = ISC_R_SUCCESS;
+ goto cleanup;
+ }
+ INDENT(style);
+ ADD_STRING(target, "TSIG_PSEUDOSECTION:\n");
+ result = dns_master_rdatasettotext(name, ps, style, target);
+ ADD_STRING(target, "\n");
+ goto cleanup;
+ case DNS_PSEUDOSECTION_SIG0:
+ ps = dns_message_getsig0(msg, &name);
+ if (ps == NULL) {
+ result = ISC_R_SUCCESS;
+ goto cleanup;
+ }
+ INDENT(style);
+ ADD_STRING(target, "SIG0_PSEUDOSECTION:\n");
+ result = dns_master_rdatasettotext(name, ps, style, target);
+ if ((flags & DNS_MESSAGETEXTFLAG_NOHEADERS) == 0 &&
+ (flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0)
+ ADD_STRING(target, "\n");
+ goto cleanup;
+ }
+
+ result = ISC_R_UNEXPECTED;
+
+ cleanup:
+ dns_master_indent = saveindent;
+ return (result);
}
isc_result_t
isc_buffer_t optbuf;
isc_uint16_t optcode, optlen;
unsigned char *optdata;
- unsigned int sflags = dns_master_styleflags(style);
REQUIRE(DNS_MESSAGE_VALID(msg));
REQUIRE(target != NULL);
REQUIRE(VALID_PSEUDOSECTION(section));
+ if ((dns_master_styleflags(style) & DNS_STYLEFLAG_YAML) != 0)
+ return (dns_message_pseudosectiontoyaml(msg, section, style,
+ flags, target));
switch (section) {
case DNS_PSEUDOSECTION_OPT:
ps = dns_message_getopt(msg);
if (ps == NULL)
return (ISC_R_SUCCESS);
if ((flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0) {
- if ((sflags & DNS_STYLEFLAG_INDENT) != 0)
- ADD_STRING(target, dns_master_indentstr);
+ INDENT(style);
ADD_STRING(target, ";; OPT PSEUDOSECTION:\n");
}
- if ((sflags & DNS_STYLEFLAG_INDENT) != 0)
- ADD_STRING(target, dns_master_indentstr);
+ INDENT(style);
ADD_STRING(target, "; EDNS: version: ");
snprintf(buf, sizeof(buf), "%u",
(unsigned int)((ps->ttl & 0x00ff0000) >> 16));
optlen = isc_buffer_getuint16(&optbuf);
INSIST(isc_buffer_remaininglength(&optbuf) >= optlen);
- if ((sflags & DNS_STYLEFLAG_INDENT) != 0)
- ADD_STRING(target, dns_master_indentstr);
+ INDENT(style);
if (optcode == DNS_OPT_NSID) {
ADD_STRING(target, "; NSID");
ps = dns_message_gettsig(msg, &name);
if (ps == NULL)
return (ISC_R_SUCCESS);
- if ((sflags & DNS_STYLEFLAG_INDENT) != 0)
- ADD_STRING(target, dns_master_indentstr);
+ INDENT(style);
if ((flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0)
ADD_STRING(target, ";; TSIG PSEUDOSECTION:\n");
result = dns_master_rdatasettotext(name, ps, style, target);
ps = dns_message_getsig0(msg, &name);
if (ps == NULL)
return (ISC_R_SUCCESS);
- if ((sflags & DNS_STYLEFLAG_INDENT) != 0)
- ADD_STRING(target, dns_master_indentstr);
+ INDENT(style);
if ((flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0)
ADD_STRING(target, ";; SIG0 PSEUDOSECTION:\n");
result = dns_master_rdatasettotext(name, ps, style, target);
ADD_STRING(target, "\n");
return (result);
}
- return (ISC_R_UNEXPECTED);
+ result = ISC_R_UNEXPECTED;
+ cleanup:
+ return (result);
}
isc_result_t
dns_message_totext(dns_message_t *msg, const dns_master_style_t *style,
dns_messagetextflag_t flags, isc_buffer_t *target)
{
- unsigned int sflags = dns_master_styleflags(style);
char buf[sizeof("1234567890")];
isc_result_t result;
REQUIRE(DNS_MESSAGE_VALID(msg));
REQUIRE(target != NULL);
- if ((flags & DNS_MESSAGETEXTFLAG_NOHEADERS) == 0) {
- if ((sflags & DNS_STYLEFLAG_INDENT) != 0)
- ADD_STRING(target, dns_master_indentstr);
+ if (((flags & DNS_MESSAGETEXTFLAG_NOHEADERS) == 0) &&
+ (dns_master_styleflags(style) & DNS_STYLEFLAG_YAML))
+ {
+ INDENT(style);
+ ADD_STRING(target, "opcode: ");
+ ADD_STRING(target, opcodetext[msg->opcode]);
+ ADD_STRING(target, "\n");
+ INDENT(style);
+ ADD_STRING(target, "status: ");
+ result = dns_rcode_totext(msg->rcode, target);
+ if (result != ISC_R_SUCCESS)
+ return (result);
+ ADD_STRING(target, "\n");
+ INDENT(style);
+ ADD_STRING(target, "id: ");
+ snprintf(buf, sizeof(buf), "%6u", msg->id);
+ ADD_STRING(target, buf);
+ ADD_STRING(target, "\n");
+ INDENT(style);
+ ADD_STRING(target, "flags:");
+ if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0)
+ ADD_STRING(target, " qr");
+ if ((msg->flags & DNS_MESSAGEFLAG_AA) != 0)
+ ADD_STRING(target, " aa");
+ if ((msg->flags & DNS_MESSAGEFLAG_TC) != 0)
+ ADD_STRING(target, " tc");
+ if ((msg->flags & DNS_MESSAGEFLAG_RD) != 0)
+ ADD_STRING(target, " rd");
+ if ((msg->flags & DNS_MESSAGEFLAG_RA) != 0)
+ ADD_STRING(target, " ra");
+ if ((msg->flags & DNS_MESSAGEFLAG_AD) != 0)
+ ADD_STRING(target, " ad");
+ if ((msg->flags & DNS_MESSAGEFLAG_CD) != 0)
+ ADD_STRING(target, " cd");
+ ADD_STRING(target, "\n");
+ /*
+ * The final unnamed flag must be zero.
+ */
+ if ((msg->flags & 0x0040U) != 0) {
+ INDENT(style);
+ ADD_STRING(target, "MBZ: 0x4");
+ ADD_STRING(target, "\n");
+ }
+ if (msg->opcode != dns_opcode_update) {
+ INDENT(style);
+ ADD_STRING(target, "QUESTION: ");
+ } else {
+ ADD_STRING(target, "ZONE: ");
+ }
+ snprintf(buf, sizeof(buf), "%1u",
+ msg->counts[DNS_SECTION_QUESTION]);
+ ADD_STRING(target, buf);
+ ADD_STRING(target, "\n");
+ if (msg->opcode != dns_opcode_update) {
+ INDENT(style);
+ ADD_STRING(target, "ANSWER: ");
+ } else {
+ INDENT(style);
+ ADD_STRING(target, "PREREQ: ");
+ }
+ snprintf(buf, sizeof(buf), "%1u",
+ msg->counts[DNS_SECTION_ANSWER]);
+ ADD_STRING(target, buf);
+ ADD_STRING(target, "\n");
+ if (msg->opcode != dns_opcode_update) {
+ INDENT(style);
+ ADD_STRING(target, "AUTHORITY: ");
+ } else {
+ INDENT(style);
+ ADD_STRING(target, "UPDATE: ");
+ }
+ snprintf(buf, sizeof(buf), "%1u",
+ msg->counts[DNS_SECTION_AUTHORITY]);
+ ADD_STRING(target, buf);
+ ADD_STRING(target, "\n");
+ INDENT(style);
+ ADD_STRING(target, "ADDITIONAL: ");
+ snprintf(buf, sizeof(buf), "%1u",
+ msg->counts[DNS_SECTION_ADDITIONAL]);
+ ADD_STRING(target, buf);
+ ADD_STRING(target, "\n");
+ } else if ((flags & DNS_MESSAGETEXTFLAG_NOHEADERS) == 0) {
+ INDENT(style);
ADD_STRING(target, ";; ->>HEADER<<- opcode: ");
ADD_STRING(target, opcodetext[msg->opcode]);
ADD_STRING(target, ", status: ");
snprintf(buf, sizeof(buf), "%6u", msg->id);
ADD_STRING(target, buf);
ADD_STRING(target, "\n");
- if ((sflags & DNS_STYLEFLAG_INDENT) != 0)
- ADD_STRING(target, dns_master_indentstr);
+ INDENT(style);
ADD_STRING(target, ";; flags:");
if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0)
ADD_STRING(target, " qr");
* The final unnamed flag must be zero.
*/
if ((msg->flags & 0x0040U) != 0) {
- if ((sflags & DNS_STYLEFLAG_INDENT) != 0)
- ADD_STRING(target, dns_master_indentstr);
+ INDENT(style);
ADD_STRING(target, "; MBZ: 0x4");
}
if (msg->opcode != dns_opcode_update) {
- if ((sflags & DNS_STYLEFLAG_INDENT) != 0)
- ADD_STRING(target, dns_master_indentstr);
+ INDENT(style);
ADD_STRING(target, "; QUESTION: ");
} else {
- if ((sflags & DNS_STYLEFLAG_INDENT) != 0)
- ADD_STRING(target, dns_master_indentstr);
+ INDENT(style);
ADD_STRING(target, "; ZONE: ");
}
snprintf(buf, sizeof(buf), "%1u",
if (result != ISC_R_SUCCESS)
return (result);
- return (ISC_R_SUCCESS);
+ cleanup:
+ return (result);
}
isc_region_t *