showsearch = false,
is_dst_up = false,
keep_open = false,
- verbose = false;
+ verbose = false,
+ yaml = false;
in_port_t port = 53;
unsigned int timeout = 0;
unsigned int extrabytes;
"isc_mutex_unlock");\
}
+static void
+default_warnerr(const char *format, ...) {
+ va_list args;
+
+ printf(";; ");
+ va_start(args, format);
+ vprintf(format, args);
+ va_end(args);
+ printf("\n");
+};
+
+static void
+default_comments(dig_lookup_t *lookup, const char *format, ...) {
+ va_list args;
+
+ if (lookup->comments) {
+ printf(";; ");
+ va_start(args, format);
+ vprintf(format, args);
+ va_end(args);
+ printf("\n");
+ }
+};
+
/* dynamic callbacks */
isc_result_t
dns_message_t *msg, bool headers);
void
-(*dighost_error)(const char *format, ...);
+(*dighost_error)(const char *format, ...) = default_warnerr;
+
+void
+(*dighost_warning)(const char *format, ...) = default_warnerr;
+
+void
+(*dighost_comments)(dig_lookup_t *lookup, const char *format, ...) = default_comments;
void
(*dighost_received)(unsigned int bytes, isc_sockaddr_t *from,
namereln = dns_name_fullcompare(name, domain,
&order, &nlabels);
if (namereln == dns_namereln_equal) {
- if (!horizontal)
- printf(";; BAD (HORIZONTAL) REFERRAL\n");
+ if (!horizontal) {
+ dighost_warning("BAD (HORIZONTAL) "
+ "REFERRAL");
+ }
horizontal = true;
} else if (namereln != dns_namereln_subdomain) {
- if (!bad)
- printf(";; BAD REFERRAL\n");
+ if (!bad) {
+ dighost_warning( "BAD REFERRAL");
+ }
bad = true;
continue;
}
isc_netaddr_fromsockaddr(&netaddr, &query->sockaddr);
isc_netaddr_format(&netaddr, buf, sizeof(buf));
- printf(";; Skipping mapped address '%s'\n", buf);
+ dighost_warning("Skipping mapped address '%s'", buf);
query->waiting_connect = false;
if (ISC_LINK_LINKED(query, link))
l = query->lookup;
clear_query(query);
if (next == NULL) {
- printf(";; No acceptable nameservers\n");
+ dighost_warning("No acceptable nameservers");
check_next_lookup(l);
return;
}
}
}
+static void
+print_query_size(dig_query_t *query) {
+ if (!yaml) {
+ printf(";; QUERY SIZE: %u\n\n",
+ isc_buffer_usedlength(&query->lookup->renderbuf));
+ }
+}
+
/*%
* Send a UDP packet to the remote nameserver, possible starting the
* recv action as well. Also make sure that the timer is running and
isc_netaddr_fromsockaddr(&netaddr, &query->sockaddr);
isc_netaddr_format(&netaddr, buf, sizeof(buf));
- printf(";; Skipping mapped address '%s'\n", buf);
-
+ dighost_warning("Skipping mapped address '%s'", buf);
next = ISC_LIST_NEXT(query, link);
l = query->lookup;
clear_query(query);
if (next == NULL) {
- printf(";; No acceptable nameservers\n");
+ dighost_warning("No acceptable nameservers");
check_next_lookup(l);
} else {
send_udp(next);
&query->lookup->renderbuf,
query->lookup->sendmsg, true);
if (query->lookup->stats) {
- printf(";; QUERY SIZE: %u\n\n",
- isc_buffer_usedlength(&query->lookup->renderbuf));
+ print_query_size(query);
}
}
}
&query->lookup->renderbuf,
query->lookup->sendmsg, true);
if (query->lookup->stats) {
- printf(";; QUERY SIZE: %u\n\n",
- isc_buffer_usedlength(
- &query->lookup->renderbuf));
+ print_query_size(query);
}
}
}
if (sevent->result == ISC_R_CANCELED) {
debug("in cancel handler");
isc_sockaddr_format(&query->sockaddr, sockstr, sizeof(sockstr));
- if (query->timedout)
- printf(";; Connection to %s(%s) for %s failed: %s.\n",
- sockstr, query->servname,
- query->lookup->textname,
- isc_result_totext(ISC_R_TIMEDOUT));
+ if (query->timedout) {
+ dighost_warning("Connection to %s(%s) for %s failed: "
+ "%s.", sockstr, query->servname,
+ query->lookup->textname,
+ isc_result_totext(ISC_R_TIMEDOUT));
+ }
isc_socket_detach(&query->sock);
INSIST(sockcount > 0);
sockcount--;
debug("unsuccessful connection: %s",
isc_result_totext(sevent->result));
isc_sockaddr_format(&query->sockaddr, sockstr, sizeof(sockstr));
- if (sevent->result != ISC_R_CANCELED)
- printf(";; Connection to %s(%s) for %s failed: "
- "%s.\n", sockstr,
- query->servname, query->lookup->textname,
- isc_result_totext(sevent->result));
+ if (sevent->result != ISC_R_CANCELED) {
+ dighost_warning("Connection to %s(%s) for %s failed: "
+ "%s.", sockstr, query->servname,
+ query->lookup->textname,
+ isc_result_totext(sevent->result));
+ }
isc_socket_detach(&query->sock);
INSIST(sockcount > 0);
sockcount--;
if (isc_safe_memequal(isc_buffer_current(optbuf), sent, 8)) {
msg->cc_ok = 1;
} else {
- printf(";; Warning: Client COOKIE mismatch\n");
+ dighost_warning("Warning: Client COOKIE mismatch");
msg->cc_bad = 1;
copy = false;
}
} else {
- printf(";; Warning: COOKIE bad token (too short)\n");
+ dighost_warning("Warning: COOKIE bad token (too short)");
msg->cc_bad = 1;
copy = false;
}
sizeof(buf1));
isc_sockaddr_format(&query->sockaddr, buf2,
sizeof(buf2));
- printf(";; reply from unexpected source: %s,"
- " expected %s\n", buf1, buf2);
+ dighost_warning("reply from unexpected source: %s,"
+ " expected %s\n", buf1, buf2);
if (!l->accept_reply_unexpected_src) {
match = false;
}
if (l->tcp_mode) {
bool fail = true;
if (result == ISC_R_SUCCESS) {
- if (!query->first_soa_rcvd ||
- query->warn_id)
- printf(";; %s: ID mismatch: "
- "expected ID %u, got %u\n",
- query->first_soa_rcvd ?
- "WARNING" : "ERROR",
- l->sendmsg->id, id);
+ if ((!query->first_soa_rcvd || query->warn_id))
+ {
+ dighost_warning("%s: ID mismatch: "
+ "expected ID %u, got "
+ "%u",
+ query->first_soa_rcvd ?
+ "WARNING" : "ERROR",
+ l->sendmsg->id, id);
+ }
if (query->first_soa_rcvd)
fail = false;
query->warn_id = false;
- } else
- printf(";; ERROR: short "
- "(< header size) message\n");
+ } else {
+ dighost_warning("ERROR: short (< header size) "
+ "message");
+ }
if (fail) {
isc_event_free(&event);
clear_query(query);
return;
}
match = true;
- } else if (result == ISC_R_SUCCESS)
- printf(";; Warning: ID mismatch: "
- "expected ID %u, got %u\n", l->sendmsg->id, id);
- else
- printf(";; Warning: short "
- "(< header size) message received\n");
+ } else if (result == ISC_R_SUCCESS) {
+ dighost_warning("Warning: ID mismatch: expected ID %u,"
+ " got %u", l->sendmsg->id, id);
+ } else {
+ dighost_warning("Warning: short (< header size) "
+ "message received");
+ }
}
- if (result == ISC_R_SUCCESS && (msgflags & DNS_MESSAGEFLAG_QR) == 0)
- printf(";; Warning: query response not set\n");
+ if (result == ISC_R_SUCCESS && (msgflags & DNS_MESSAGEFLAG_QR) == 0) {
+ dighost_warning("Warning: query response not set");
+ }
if (!match)
goto udp_mismatch;
}
result = dns_message_parse(msg, &b, parseflags);
if (result == DNS_R_RECOVERABLE) {
- printf(";; Warning: Message parser reports malformed "
- "message packet.\n");
+ dighost_warning("Warning: Message parser reports malformed "
+ "message packet.");
result = ISC_R_SUCCESS;
}
if (result != ISC_R_SUCCESS) {
- printf(";; Got bad packet: %s\n", isc_result_totext(result));
- hex_dump(&b);
+ if (!yaml) {
+ printf(";; Got bad packet: %s\n",
+ isc_result_totext(result));
+ hex_dump(&b);
+ }
query->waiting_connect = false;
dns_message_destroy(&msg);
isc_event_free(&event);
dns_rdataclass_format(rdataset->rdclass,
classbuf,
sizeof(classbuf));
- printf(";; Question section mismatch: "
- "got %s/%s/%s\n",
- namestr, typebuf, classbuf);
+ dighost_warning(";; Question section "
+ "mismatch: got "
+ "%s/%s/%s", namestr,
+ typebuf, classbuf);
match = false;
}
}
/*
* Add minimum EDNS version required checks here if needed.
*/
- if (l->comments)
- printf(";; BADVERS, retrying with EDNS version %u.\n",
- (unsigned int)newedns);
+ dighost_comments(l, "BADVERS, retrying with EDNS version %u.",
+ (unsigned int)newedns);
l->edns = newedns;
n = requeue_lookup(l, true);
if (l->trace && l->trace_root)
!l->ignore && !l->tcp_mode) {
if (l->cookie == NULL && l->sendcookie && msg->opt != NULL)
process_opt(l, msg);
- if (l->comments)
- printf(";; Truncated, retrying in TCP mode.\n");
+ dighost_comments(l, "Truncated, retrying in TCP mode.");
n = requeue_lookup(l, true);
n->tcp_mode = true;
if (l->trace && l->trace_root)
l->sendcookie && l->badcookie) {
process_opt(l, msg);
if (msg->cc_ok) {
- if (l->comments)
- printf(";; BADCOOKIE, retrying%s.\n",
- l->seenbadcookie ? " in TCP mode" : "");
+ dighost_comments(l, "BADCOOKIE, retrying%s.",
+ l->seenbadcookie ?
+ " in TCP mode" : "");
n = requeue_lookup(l, true);
if (l->seenbadcookie)
n->tcp_mode = true;
*/
if ((ISC_LIST_HEAD(l->q) != query) ||
(ISC_LIST_NEXT(query, link) != NULL)) {
- if (l->comments)
- printf(";; Got %s from %s, "
- "trying next server\n",
- msg->rcode == dns_rcode_servfail ?
- "SERVFAIL reply" :
- "recursion not available",
- query->servname);
+ dighost_comments(l, "Got %s from %s, trying next "
+ "server",
+ msg->rcode == dns_rcode_servfail ?
+ "SERVFAIL reply" :
+ "recursion not available",
+ query->servname);
clear_query(query);
check_next_lookup(l);
dns_message_destroy(&msg);
if (tsigkey != NULL) {
result = dns_tsig_verify(&b, msg, NULL, NULL);
if (result != ISC_R_SUCCESS) {
- printf(";; Couldn't verify signature: %s\n",
- isc_result_totext(result));
+ dighost_warning("Couldn't verify signature: %s",
+ isc_result_totext(result));
validated = false;
}
l->tsigctx = msg->tsigctx;
if (!done_process_opt) {
if (l->cookie != NULL) {
if (msg->opt == NULL) {
- printf(";; expected opt record in response\n");
+ dighost_warning("expected opt record in "
+ "response");
} else {
process_opt(l, msg);
}