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_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=1754397670; 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=bRNq8tpzwUbLZ69cBT3xQAlrdvGCQ8XVQgvuUm5O2XN3xMCXVgRAzfYpk51U/ZiHd LfvWZfQCRFu+wjhJXrqjvv+SkKc1TTMN2OVr2sItc03vOmyoJiEXiVfglOicGpfpge Ew2WccnBuSoBmvGDeoDWD3FZrp7B+ZYh0YfI1399Pc1o2IHjrCXRGYnIcJeYg5Kpnz h4xnsJrfJPrJIHj/J4W1kPKVpOb7VuLl+Blcf/cf84UKTkMQ3WiKknJsBSP7WlthEC y49nQUuIHPkeSQ5p59ymFR28VqBQw3MMYMazn+X60VU4al1mYYzich0zkROsluSJE9 mOBnJ7x4HYbMw== Received: from zero (unknown [182.253.151.158]) by server-vie001.gnuweeb.org (Postfix) with ESMTPSA id BF198312805A; Tue, 5 Aug 2025 12:41:09 +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 19:40:39 +0700 Message-ID: <20250805124042.143673-6-reyuki@gnuweeb.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250805124042.143673-1-reyuki@gnuweeb.org> References: <20250805124042.143673-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