]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Extend dns_message_setopt to clear the opt record
authorMark Andrews <marka@isc.org>
Mon, 6 Nov 2023 15:10:45 +0000 (02:10 +1100)
committerMark Andrews <marka@isc.org>
Mon, 22 Jan 2024 23:47:31 +0000 (10:47 +1100)
Use NULL to signal that the opt record, if any, set on the
message be removed.

lib/dns/include/dns/message.h
lib/dns/message.c

index cda53f3c8ceb80eb5de4b523d299c1116bc3e1d3..14c987f649ffcd7e2ea4ea99d9d088cd4c7d39c4 100644 (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:
  *
index e61f6b6142c62aa3129688ca6af44371bde68b26..f5fc1cad9ab296daaa591cc7ea9eead0a79346cd 100644 (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;