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.
This commit is contained in:
Mark Andrews
2023-11-07 02:10:45 +11:00
parent a8390e8ded
commit 1b6f70076a
2 changed files with 8 additions and 3 deletions

View File

@@ -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:
*

View File

@@ -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;