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=1754376642; 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=BGF5JPTXMb/hH/QzXOpgwedTnijrHHEuumt69CYsnUcrEP5GopWZQJT0DDgnNhQ5W ZgMX0UX0ygUUNMv3ZCksEYJbsGDo5H9E0ur8+1v28IGWPYsUCKrDgQpfj/Tyk7VthR GP+ff89MErAm9NG7qL8nY71CCW8Q4G6IiMJRbvtBBEIJUfLcBmmTR35+rpeorZsj5V VfW9Qc3fEtiFL88eE/zyRrUVc8fNiDSnkpCVl0cnn7UTavz49NRrUAsenZz7c32gv4 J5iAnRk70/Q+5i9dFy1EdS+ajaHhtXoxmHNUO0vAGKWnLzlw1RgayRGaThjWxWCJdS jjHyHe1ratmfA== Received: from zero (unknown [182.253.151.158]) by server-vie001.gnuweeb.org (Postfix) with ESMTPSA id E51DE312801F; Tue, 5 Aug 2025 06:50:40 +0000 (UTC) From: Ahmad Gani To: Ammar Faizi Cc: Ahmad Gani , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH gwproxy v3 7/9] dnsparser: Transaction id creation is delegated to caller Date: Tue, 5 Aug 2025 13:49:27 +0700 Message-ID: <20250805064933.109080-8-reyuki@gnuweeb.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250805064933.109080-1-reyuki@gnuweeb.org> References: <20250805064933.109080-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