From: Ahmad Gani <reyuki@gnuweeb.org>
To: Ammar Faizi <ammarfaizi2@gnuweeb.org>
Cc: Ahmad Gani <reyuki@gnuweeb.org>,
Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>,
GNU/Weeb Mailing List <gwml@vger.gnuweeb.org>
Subject: [PATCH gwproxy v4 5/6] dnsparser: Transaction id creation is delegated to caller
Date: Wed, 6 Aug 2025 10:57:23 +0700 [thread overview]
Message-ID: <20250806035727.216702-6-reyuki@gnuweeb.org> (raw)
In-Reply-To: <20250806035727.216702-1-reyuki@gnuweeb.org>
It gives the caller more flexibility in handling DNS requests.
A single domain name lookup can have two responses: one for IPv4 and one
for IPv6. With this change, the caller may use the same txid for both queries,
making it easier to group related DNS responses.
Signed-off-by: Ahmad Gani <reyuki@gnuweeb.org>
---
src/gwproxy/dnsparser.c | 7 +++++--
src/gwproxy/dnsparser.h | 1 +
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/gwproxy/dnsparser.c b/src/gwproxy/dnsparser.c
index 744dc61581ef..2d8af1da2893 100644
--- a/src/gwproxy/dnsparser.c
+++ b/src/gwproxy/dnsparser.c
@@ -65,9 +65,9 @@ static ssize_t calculate_question_len(uint8_t *in, size_t in_len)
int serialize_answ(uint16_t txid, uint8_t *in, size_t in_len, gwdns_answ_data *out)
{
- size_t idx;
gwdns_header_pkt *hdr;
uint16_t raw_flags;
+ size_t idx;
int ret;
idx = sizeof(*hdr);
@@ -244,7 +244,10 @@ ssize_t construct_question(gwdns_question_part *question)
* the memset implicitly set opcode to OPCODE_QUERY
*/
memset(hdr, 0, sizeof(*hdr));
- hdr->id = htons((uint16_t)rand());
+ /*
+ * no need to htons, so no ntohs for comparison in serialize_answ.
+ */
+ hdr->id = question->txid;
DNS_SET_RD(hdr->flags, true);
hdr->flags = htons(hdr->flags);
hdr->qdcount = htons(1);
diff --git a/src/gwproxy/dnsparser.h b/src/gwproxy/dnsparser.h
index 41048568240b..502281ad9d57 100644
--- a/src/gwproxy/dnsparser.h
+++ b/src/gwproxy/dnsparser.h
@@ -116,6 +116,7 @@ typedef struct {
typedef struct {
uint8_t *dst_buffer;
+ uint16_t txid;
uint16_t type;
size_t dst_len;
const char *domain;
--
Ahmad Gani
next prev parent reply other threads:[~2025-08-06 3:57 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-06 3:57 [PATCH gwproxy v4 0/6] Initial work for DNS lookup implementation Ahmad Gani
2025-08-06 3:57 ` [PATCH gwproxy v4 1/6] dnslookup: Split common functionality and struct into net.h and net.c Ahmad Gani
2025-08-06 6:18 ` Alviro Iskandar Setiawan
2025-08-06 3:57 ` [PATCH gwproxy v4 2/6] dnslookup: Add a new parameter default_port Ahmad Gani
2025-08-06 6:20 ` Alviro Iskandar Setiawan
2025-08-06 3:57 ` [PATCH gwproxy v4 3/6] dnslookup: Allow only port string number Ahmad Gani
2025-08-06 3:57 ` [PATCH gwproxy v4 4/6] dnslookup: Initial work for implementation of C-ares-like getaddrinfo function Ahmad Gani
2025-08-06 6:40 ` Alviro Iskandar Setiawan
2025-08-06 6:51 ` Alviro Iskandar Setiawan
2025-08-06 8:43 ` Ahmad Gani
2025-08-06 8:40 ` Ahmad Gani
2025-08-06 11:09 ` Alviro Iskandar Setiawan
2025-08-06 11:20 ` Alviro Iskandar Setiawan
2025-08-06 11:39 ` Ammar Faizi
2025-08-06 12:30 ` Ahmad Gani
2025-08-06 20:54 ` Ammar Faizi
2025-08-06 12:30 ` Ahmad Gani
2025-08-06 21:33 ` Ammar Faizi
2025-08-14 4:54 ` Ahmad Gani
2025-08-06 3:57 ` Ahmad Gani [this message]
2025-08-06 6:28 ` [PATCH gwproxy v4 5/6] dnsparser: Transaction id creation is delegated to caller Alviro Iskandar Setiawan
2025-08-06 10:20 ` Ahmad Gani
2025-08-06 10:51 ` Alviro Iskandar Setiawan
2025-08-06 12:29 ` Ahmad Gani
2025-08-06 3:57 ` [PATCH gwproxy v4 6/6] dnslookup: Make gw_ares_getaddrinfo asynchronous Ahmad Gani
2025-08-06 6:22 ` Alviro Iskandar Setiawan
2025-08-06 8:42 ` Ahmad Gani
2025-08-06 7:03 ` [PATCH gwproxy v4 0/6] Initial work for DNS lookup implementation Ammar Faizi
2025-08-06 7:08 ` Ammar Faizi
2025-08-06 8:37 ` Ahmad Gani
2025-08-06 8:58 ` Ammar Faizi
2025-08-06 9:47 ` Ammar Faizi
2025-08-06 20:50 ` Ammar Faizi
2025-08-06 22:14 ` Ammar Faizi
2025-08-06 7:08 ` (subset) " Ammar Faizi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250806035727.216702-6-reyuki@gnuweeb.org \
--to=reyuki@gnuweeb.org \
--cc=alviro.iskandar@gnuweeb.org \
--cc=ammarfaizi2@gnuweeb.org \
--cc=gwml@vger.gnuweeb.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox