From bce0c0c37afb55715c9593da0cad0dc2f0c843f8 Mon Sep 17 00:00:00 2001 From: Aurelien DARRAGON Date: Tue, 7 Mar 2023 18:01:34 +0100 Subject: [PATCH] BUG/MINOR: dns: fix ring offset calculation in dns_resolve_send() 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 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/dns.c b/src/dns.c index 5d7e1d940..839c41f82 100644 --- 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 */