]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Allow EDNS to be used when making requests in xfrin
authorMark Andrews <marka@isc.org>
Thu, 29 Jun 2023 07:25:15 +0000 (17:25 +1000)
committerMark Andrews <marka@isc.org>
Thu, 31 Aug 2023 01:32:29 +0000 (11:32 +1000)
This allow for the EDNS options EXPIRE and NSID to be sent when
when making requests.  The existing controls controlling whether
EDNS is used and whether EXPIRE or NSID are sent are honoured.

Adjust the expected byte counts in the xfer system test to reflect
the EDNS overhead.  Adjust the dig call to match named's behavior
(don't set +expire as we are talking to a secondary).

bin/tests/system/ixfr/ixfr-stats-with-expire.good [moved from bin/tests/system/ixfr/ixfr-stats.good with 67% similarity]
bin/tests/system/ixfr/ixfr-stats-without-expire.good [new file with mode: 0644]
bin/tests/system/ixfr/tests.sh
bin/tests/system/xfer/axfr-stats.good
bin/tests/system/xfer/tests.sh
lib/dns/xfrin.c

similarity index 67%
rename from bin/tests/system/ixfr/ixfr-stats.good
rename to bin/tests/system/ixfr/ixfr-stats-with-expire.good
index 3d0d2dde32eb6a5bb1da0d7e945ca75a0b7d3b5d..c02992b14fcbd61ab71d387c1a2469b9b800c2b4 100644 (file)
@@ -1,3 +1,3 @@
 messages=1
 records=5
-bytes=204
+bytes=223
diff --git a/bin/tests/system/ixfr/ixfr-stats-without-expire.good b/bin/tests/system/ixfr/ixfr-stats-without-expire.good
new file mode 100644 (file)
index 0000000..0713c0b
--- /dev/null
@@ -0,0 +1,3 @@
+messages=1
+records=5
+bytes=215
index f1e3b622411cd05a2536d17bcc9da33196bfa8c3..4b61a2c9e11d4d52edaa749e1173b13b1f628f93 100644 (file)
@@ -388,9 +388,9 @@ status=$((status+ret))
 n=$((n+1))
 echo_i "checking whether dig calculates IXFR statistics correctly ($n)"
 ret=0
-$DIG $DIGOPTS +noedns +stat -b 10.53.0.4 @10.53.0.4 test. ixfr=2 > dig.out1.test$n
+$DIG $DIGOPTS +expire +nocookie +stat -b 10.53.0.4 @10.53.0.4 test. ixfr=2 > dig.out1.test$n
 get_dig_xfer_stats dig.out1.test$n > stats.dig
-diff ixfr-stats.good stats.dig > /dev/null || ret=1
+diff ixfr-stats-with-expire.good stats.dig > /dev/null || ret=1
 if [ $ret != 0 ]; then echo_i "failed"; fi
 status=$((status+ret))
 
@@ -400,20 +400,20 @@ status=$((status+ret))
 
 _wait_for_stats () {
     get_named_xfer_stats ns4/named.run "$1" test "$2" > "$3"
-    diff ixfr-stats.good "$3" > /dev/null || return 1
+    diff "$4" "$3" > /dev/null || return 1
     return 0
 }
 
 n=$((n+1))
 echo_i "checking whether named calculates incoming IXFR statistics correctly ($n)"
 ret=0
-retry_quiet 10 _wait_for_stats 10.53.0.3 "Transfer completed" stats.incoming || ret=1
+retry_quiet 10 _wait_for_stats 10.53.0.3 "Transfer completed" stats.incoming ixfr-stats-without-expire.good || ret=1
 if [ $ret != 0 ]; then echo_i "failed"; fi
 status=$((status+ret))
 
 n=$((n+1))
 echo_i "checking whether named calculates outgoing IXFR statistics correctly ($n)"
-retry_quiet 10 _wait_for_stats 10.53.0.4 "IXFR ended" stats.outgoing || ret=1
+retry_quiet 10 _wait_for_stats 10.53.0.4 "IXFR ended" stats.outgoing ixfr-stats-with-expire.good || ret=1
 if [ $ret != 0 ]; then echo_i "failed"; fi
 status=$((status+ret))
 
index 264af09705b346f23c28fd6e87d4db9be2cc5fec..616854e6466d0dad3f877ed1323410b893acac53 100644 (file)
@@ -1,3 +1,3 @@
 messages=16
 records=10003
-bytes=218227
+bytes=218403
index 33eee6ae47f83b2cd2c1f1d50114cea4e45a3dae..6595927e7eeff1cd7f226670322205fd4bd0db3d 100755 (executable)
@@ -541,7 +541,7 @@ tmp=0
 # Use -b so that we can discern between incoming and outgoing transfers in ns3
 # logs later on.
 wait_for_xfer() (
-       $DIG $DIGOPTS +noedns +stat -b 10.53.0.2 @10.53.0.3 xfer-stats. AXFR > dig.out.ns3.test$n
+       $DIG $DIGOPTS +edns +nocookie +noexpire +stat -b 10.53.0.2 @10.53.0.3 xfer-stats. AXFR > dig.out.ns3.test$n
        grep "; Transfer failed" dig.out.ns3.test$n > /dev/null || return 0
        return 1
 )
index be7a427226ac47e26ebe5c4ce2fa03d36efd500a..3961f8eb84e63c468a63e5f5ee74ca2310d08a70 100644 (file)
@@ -30,6 +30,7 @@
 #include <dns/journal.h>
 #include <dns/log.h>
 #include <dns/message.h>
+#include <dns/peer.h>
 #include <dns/rdataclass.h>
 #include <dns/rdatalist.h>
 #include <dns/rdataset.h>
@@ -1147,6 +1148,38 @@ request_type(dns_xfrin_t *xfr) {
        }
 }
 
+static isc_result_t
+add_opt(dns_message_t *message, uint16_t udpsize, bool reqnsid,
+       bool reqexpire) {
+       isc_result_t result;
+       dns_rdataset_t *rdataset = NULL;
+       dns_ednsopt_t ednsopts[DNS_EDNSOPTIONS];
+       int count = 0;
+
+       /* Set EDNS options if applicable. */
+       if (reqnsid) {
+               INSIST(count < DNS_EDNSOPTIONS);
+               ednsopts[count].code = DNS_OPT_NSID;
+               ednsopts[count].length = 0;
+               ednsopts[count].value = NULL;
+               count++;
+       }
+       if (reqexpire) {
+               INSIST(count < DNS_EDNSOPTIONS);
+               ednsopts[count].code = DNS_OPT_EXPIRE;
+               ednsopts[count].length = 0;
+               ednsopts[count].value = NULL;
+               count++;
+       }
+       result = dns_message_buildopt(message, &rdataset, 0, udpsize, 0,
+                                     ednsopts, count);
+       if (result != ISC_R_SUCCESS) {
+               return (result);
+       }
+
+       return (dns_message_setopt(message, rdataset));
+}
+
 /*
  * Build an *XFR request and send its length prefix.
  */
@@ -1160,6 +1193,10 @@ xfrin_send_request(dns_xfrin_t *xfr) {
        dns_name_t *qname = NULL;
        dns_dbversion_t *ver = NULL;
        dns_name_t *msgsoaname = NULL;
+       bool edns = true;
+       bool reqnsid = xfr->view->requestnsid;
+       bool reqexpire = dns_zone_getrequestexpire(xfr->zone);
+       uint16_t udpsize = dns_view_getudpsize(xfr->view);
 
        LIBDNS_XFRIN_RECV_SEND_REQUEST(xfr, xfr->info);
 
@@ -1198,6 +1235,24 @@ xfrin_send_request(dns_xfrin_t *xfr) {
                                          &xfr->ixfr.request_serial));
        }
 
+       if (xfr->view->peers != NULL) {
+               dns_peer_t *peer = NULL;
+               isc_netaddr_t primaryip;
+               isc_netaddr_fromsockaddr(&primaryip, &xfr->primaryaddr);
+               result = dns_peerlist_peerbyaddr(xfr->view->peers, &primaryip,
+                                                &peer);
+               if (result == ISC_R_SUCCESS) {
+                       (void)dns_peer_getsupportedns(peer, &edns);
+                       (void)dns_peer_getudpsize(peer, &udpsize);
+                       (void)dns_peer_getrequestnsid(peer, &reqnsid);
+                       (void)dns_peer_getrequestexpire(peer, &reqexpire);
+               }
+       }
+
+       if (edns) {
+               CHECK(add_opt(msg, udpsize, reqnsid, reqexpire));
+       }
+
        xfr->nmsg = 0;
        xfr->nrecs = 0;
        xfr->nbytes = 0;