]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: dns: fix ring offset calculation in dns_resolve_send()
authorAurelien DARRAGON <adarragon@haproxy.com>
Tue, 7 Mar 2023 17:01:34 +0000 (18:01 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 8 Mar 2023 07:57:13 +0000 (08:57 +0100)
With 737d10f ("BUG/MEDIUM: dns: ensure ring offset is properly reajusted
to head") relative offset calculation was fixed in dns_session_io_handler()
and dns_process_req() functions.

But if we compare with the changes performed in the patch that introduced
the bug: d9c7188 ("MEDIUM: ring: make the offset relative to the head/tail
instead of absolute"), we can see that dns_resolve_send() is missing from
the patch.

Applying both 737d10f + ("BUG/MINOR: dns: fix ring offset calculation on
first read") to dns_resolve_send() function.
With this last commit, we should be back at pre d9c7188 behavior.

No backport needed.

src/dns.c

index 5d7e1d940103d99b3a6b4805659558bb98aba221..839c41f82c53727fcd2521d0591d03e1f85ee198 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
@@ -317,7 +317,6 @@ static void dns_resolve_send(struct dgram_conn *dgram)
        buf = &ring->buf;
 
        HA_RWLOCK_RDLOCK(DNS_LOCK, &ring->lock);
-       ofs = ns->dgram->ofs_req;
 
        /* explanation for the initialization below: it would be better to do
         * this in the parsing function but this would occasionally result in
@@ -327,14 +326,17 @@ static void dns_resolve_send(struct dgram_conn *dgram)
         * existing messages before grabbing a reference to a location. This
         * value cannot be produced after initialization.
         */
-       if (unlikely(ofs == ~0)) {
-               ofs = 0;
-               HA_ATOMIC_INC(b_peek(buf, ofs));
+       if (unlikely(ns->dgram->ofs_req == ~0)) {
+               ns->dgram->ofs_req = b_peek_ofs(buf, 0);
+               HA_ATOMIC_INC(b_orig(buf) + ns->dgram->ofs_req);
        }
 
        /* we were already there, adjust the offset to be relative to
         * the buffer's head and remove us from the counter.
         */
+       ofs = ns->dgram->ofs_req - b_head_ofs(buf);
+       if (ns->dgram->ofs_req < b_head_ofs(buf))
+               ofs += b_size(buf);
        BUG_ON(ofs >= buf->size);
        HA_ATOMIC_DEC(b_peek(buf, ofs));
 
@@ -376,12 +378,10 @@ static void dns_resolve_send(struct dgram_conn *dgram)
        fd_stop_send(fd);
 
 out:
-
        HA_ATOMIC_INC(b_peek(buf, ofs));
-       ns->dgram->ofs_req = ofs;
+       ns->dgram->ofs_req = b_peek_ofs(buf, ofs);
        HA_RWLOCK_RDUNLOCK(DNS_LOCK, &ring->lock);
        HA_SPIN_UNLOCK(DNS_LOCK, &dgram->lock);
-
 }
 
 /* proto_udp callback functions for a DNS resolution */