From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server-vie001.gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,URIBL_DBL_BLOCKED_OPENDNS, URIBL_ZEN_BLOCKED_OPENDNS autolearn=ham autolearn_force=no version=3.4.6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=new2025; t=1754399119; bh=GtUZ6b3K96qGj/eEbfBJLUqzF78vS4O4WfMquSaGQFk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding:Message-ID:Date:From: Reply-To:Subject:To:Cc:In-Reply-To:References:Resent-Date: Resent-From:Resent-To:Resent-Cc:User-Agent:Content-Type: Content-Transfer-Encoding; b=O86ecr+MhDFO007Ri+FlCszJ5Qb47YQnZSkkdewxMvZx2R3449xtsqmkEJLLh2NQJ qaBP6GFWhxeEBCa9Z06cLSV9Zj1kbT6DYeaBl+U54CEBMpbTj3pM1bSTqPxcUuFUVn cG2jRxFlahLu4xxVy7BaWqhhJfQ/fnJZ190NjNL4xvW56Pj6MJCOmBz+zbfRT7DMVR pfa4BNqSd3S7Ah2WglOezeBK1EQz8Hi5lcadEP2rU4x4nXvyFglKvOjzQ8r6svq8TJ idQuyT+6zRTKD0ajwz8UC5Jrgitu5Zjd2Naoc6BgRzipF14RlErI/EWBVW5LeoBrsY GtVJ5z61mdhcQ== Received: from zero (unknown [182.253.151.158]) by server-vie001.gnuweeb.org (Postfix) with ESMTPSA id 63BF4312805D; Tue, 5 Aug 2025 13:05:18 +0000 (UTC) From: Ahmad Gani To: Ammar Faizi Cc: Ahmad Gani , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH gwproxy v3 5/6] dnsparser: Transaction id creation is delegated to caller Date: Tue, 5 Aug 2025 20:04:47 +0700 Message-ID: <20250805130451.146549-6-reyuki@gnuweeb.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250805130451.146549-1-reyuki@gnuweeb.org> References: <20250805130451.146549-1-reyuki@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 --- 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