From: Mark Andrews Date: Mon, 6 Nov 2023 15:10:45 +0000 (+1100) Subject: Extend dns_message_setopt to clear the opt record X-Git-Tag: v9.19.22~73^2~2 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=1b6f70076aed04526fea3f9c7a6d35ba684df876;p=thirdparty%2Fbind9.git Extend dns_message_setopt to clear the opt record Use NULL to signal that the opt record, if any, set on the message be removed. --- diff --git a/lib/dns/include/dns/message.h b/lib/dns/include/dns/message.h index cda53f3c8ce..14c987f649f 100644 --- a/lib/dns/include/dns/message.h +++ b/lib/dns/include/dns/message.h @@ -1114,14 +1114,14 @@ dns_message_getopt(dns_message_t *msg); isc_result_t dns_message_setopt(dns_message_t *msg, dns_rdataset_t *opt); /*%< - * Set the OPT record for 'msg'. + * Set/clear the OPT record for 'msg'. * * Requires: * *\li 'msg' is a valid message with rendering intent * and no sections have been rendered. * - *\li 'opt' is a valid OPT record. + *\li 'opt' is a valid OPT record or NULL. * * Ensures: * diff --git a/lib/dns/message.c b/lib/dns/message.c index e61f6b6142c..f5fc1cad9ab 100644 --- a/lib/dns/message.c +++ b/lib/dns/message.c @@ -2707,12 +2707,17 @@ dns_message_setopt(dns_message_t *msg, dns_rdataset_t *opt) { */ REQUIRE(DNS_MESSAGE_VALID(msg)); - REQUIRE(opt->type == dns_rdatatype_opt); + REQUIRE(opt == NULL || DNS_RDATASET_VALID(opt)); + REQUIRE(opt == NULL || opt->type == dns_rdatatype_opt); REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTRENDER); REQUIRE(msg->state == DNS_SECTION_ANY); msgresetopt(msg); + if (opt == NULL) { + return (ISC_R_SUCCESS); + } + result = dns_rdataset_first(opt); if (result != ISC_R_SUCCESS) { goto cleanup;