diff --git a/CHANGES b/CHANGES
index 13c70dce7b..cc6be576ed 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+3895. [func] Add the ability to set the DSCP code point to dig.
+ [RT #36546]
+
3894. [bug] Buffers in isc_print_vsnprintf were not properly
initialized leading to potential overflows when
printing out quad values. [RT #36505]
diff --git a/bin/dig/dig.c b/bin/dig/dig.c
index 6aea48d971..1158c483ab 100644
--- a/bin/dig/dig.c
+++ b/bin/dig/dig.c
@@ -243,6 +243,7 @@ help(void) {
" +[no]multiline (Print records in an expanded format)\n"
" +[no]onesoa (AXFR prints only one soa record)\n"
" +[no]keepopen (Keep the TCP socket open between queries)\n"
+" +[no]dscp[=###] (Set the DSCP value to ### [0..63])\n"
" global d-opts and servers (before host name) affect all queries.\n"
" local d-opts and servers (after host name) affect only that lookup.\n"
" -h (print help and exit)\n"
@@ -920,6 +921,19 @@ plus_option(char *option, isc_boolean_t is_batchfile,
strncpy(domainopt, value, sizeof(domainopt));
domainopt[sizeof(domainopt)-1] = '\0';
break;
+ case 's': /* dscp */
+ FULLCHECK("dscp");
+ if (!state) {
+ lookup->dscp = -1;
+ break;
+ }
+ if (value == NULL)
+ goto need_value;
+ result = parse_uint(&num, value, 0x3f, "DSCP");
+ if (result != ISC_R_SUCCESS)
+ fatal("Couldn't parse DSCP value");
+ lookup->dscp = num;
+ break;
default:
goto invalid_option;
}
diff --git a/bin/dig/dig.docbook b/bin/dig/dig.docbook
index 0a299dbccd..6b2b7850a8 100644
--- a/bin/dig/dig.docbook
+++ b/bin/dig/dig.docbook
@@ -555,6 +555,16 @@
+
+
+
+ Set the DSCP code point to be used when sending the
+ query. Valid DSCP code points are in the range
+ [0..63]. By default no code point is explictly set.
+
+
+
+
diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c
index d4a13d737a..9ef4a8806a 100644
--- a/bin/dig/dighost.c
+++ b/bin/dig/dighost.c
@@ -813,6 +813,7 @@ make_empty_lookup(void) {
#endif
looknew->ednsopts = NULL;
looknew->ednsoptscnt = 0;
+ looknew->dscp = -1;
dns_fixedname_init(&looknew->fdomain);
ISC_LINK_INIT(looknew, link);
ISC_LIST_INIT(looknew->q);
@@ -898,6 +899,7 @@ clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers) {
looknew->tsigctx = NULL;
looknew->need_search = lookold->need_search;
looknew->done_as_is = lookold->done_as_is;
+ looknew->dscp = lookold->dscp;
if (lookold->ecs_addr != NULL) {
size_t len = sizeof(isc_sockaddr_t);
@@ -2781,6 +2783,8 @@ send_tcp_connect(dig_query_t *query) {
check_result(result, "isc_socket_create");
sockcount++;
debug("sockcount=%d", sockcount);
+ if (query->lookup->dscp != -1)
+ isc_socket_dscp(query->sock, query->lookup->dscp);
if (specified_source)
result = isc_socket_bind(query->sock, &bind_address,
ISC_SOCKET_REUSEADDRESS);
@@ -2857,6 +2861,8 @@ send_udp(dig_query_t *query) {
check_result(result, "isc_socket_create");
sockcount++;
debug("sockcount=%d", sockcount);
+ if (query->lookup->dscp != -1)
+ isc_socket_dscp(query->sock, query->lookup->dscp);
if (specified_source) {
result = isc_socket_bind(query->sock, &bind_address,
ISC_SOCKET_REUSEADDRESS);
diff --git a/bin/dig/include/dig/dig.h b/bin/dig/include/dig/dig.h
index aeab0e5dfa..c978eefddf 100644
--- a/bin/dig/include/dig/dig.h
+++ b/bin/dig/include/dig/dig.h
@@ -195,6 +195,7 @@ isc_boolean_t sigchase;
#endif
dns_ednsopt_t *ednsopts;
unsigned int ednsoptscnt;
+ isc_dscp_t dscp;
};
/*% The dig_query structure */