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=1754013304; bh=nowYVtzE5Tw//AGLl1rfQMMs0NPJyAfnC9DurK0edRc=; h=From:To:Cc:Subject:Date:Message-ID: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=UEVvy/NBQV1fBmqLpWAbfzNEjyxvrS9S7NZkpWj3Cb88iGX/Wglt0ZS2rCLO0E8x3 fRi02pF5K+d1dsLVAzIxKLOkuoE5wyfLEIfCnYhTX76sVVYAosaKd+jpjg2LH6p93B scKiN+e3s++vyPUxgk+Emir2kdKm0jRxg8QAlJidrdmAEp+yJR4+k9QEATgMY4xSzn Zc5MD6K7pkNCmjxFI1jf8X2fUWiP2g0vyo4uJUcljQROaRMGPtbdSYcSh8//nLykTv wBsnA9hKy0DTUPQQ22GHSecxf0cl4tecBNDBX3R0uULfoD9BsylJsOGpb8jx/ruFAW rWkzyWDEVPYlg== Received: from zero (unknown [182.253.151.159]) by server-vie001.gnuweeb.org (Postfix) with ESMTPSA id 799B03126F06; Fri, 1 Aug 2025 01:55:03 +0000 (UTC) From: Ahmad Gani To: Ammar Faizi Cc: Ahmad Gani , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH gwproxy v2 0/3] Initial work for DNS lookup implementation Date: Fri, 1 Aug 2025 08:54:21 +0700 Message-ID: <20250801015427.439511-1-reyuki@gnuweeb.org> X-Mailer: git-send-email 2.50.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Hi Chief, This is initial work of dns lookup feature, The patches aren't final, but it's enough to get a grasp of what the interface looks like. I've provided a temporary entry point main function to test it. There are 3 patches in this series: - create net.h and net.c to store network related functionality. - allow only port string number in service parameter of gwp_dns_queue - initial work for implementation of C-ares-like getaddrinfo function On Thu, 31 Jul 2025 21:01:02 +0700, Ammar Faizi wrote: >> On Thu, Jul 31, 2025 at 10:07:44AM +0700, Ahmad Gani wrote: >> +int init_addr(const char *addr, struct gwp_sockaddr *addr_st, uint16_t port) > This is a no-no. We don't need it. Sorry, I didn't know the existence of convert_str_to_ssaddr, the init_addr is now replaced with convert_str_to_ssaddr. > In gwproxy.c, there is convert_str_to_ssaddr(). It's also better than > your version because with it you can have: > > ./gwproxy --target google.com:80 --bind localhost:1111 > Not restricted to IP address format, but domain name is also ok. Looking at the example, I guess I need to add logic to handle Special-use domain name [1] and an ability to detect local name server in the system to fully replace glibc's getaddrinfo, but since it's mentioned somewhere in the mail threads [2] that we can use glibc's getaddrinfo for just bootstrapping purpose I guess I don't need to fully replace it then. I also bring back __cold attribute on convert_ssaddr_to_str function to inform the compiler that function is unlikely to be executed and thus change optiomization priority for size first rather than speed. ## Changelog v1 -> v2: - use existing convert_str_to_ssaddr instead of init_addr - fix memory leak when init_addr (now it's replaced) failed - modify convert_str_to_ssaddr to support default port - bring back __cold attribute on convert_ssaddr_to_str - don't fill a dangling pointer as Sir Alviro said [3] - for now it's blocking, attempt_retry label is not needed [1]: - https://en.wikipedia.org/wiki/Special-use_domain_name [2]: - https://lore.gnuweeb.org/gwml/aIu7m+NE8Iny+YQN@linux.gnuweeb.org [3]: - https://lore.gnuweeb.org/gwml/CAOG64qMPmFL-+7OrVv4psmyOt8G-3OZJGa=bQ1a_wuV06WTyng@mail.gmail.com/ Signed-off-by: Ahmad Gani --- Ahmad Gani (3): dnslookup: split common functionality and struct into net.c dnslookup: Allow only port string number dnslookup: Initial work for implementation of C-ares-like getaddrinfo function Makefile | 1 + man/gwp_dns_queue.3 | 2 +- src/gwproxy/dns.h | 12 +- src/gwproxy/dnslookup.c | 289 ++++++++++++++++++++++++++++++++ src/gwproxy/dnslookup.h | 118 +++++++++++++ src/gwproxy/dnsparser.c | 357 ++++++++++++++++++++++++++++++++++++++++ src/gwproxy/dnsparser.h | 191 +++++++++++++++++++++ src/gwproxy/gwproxy.c | 93 +---------- src/gwproxy/net.c | 103 ++++++++++++ src/gwproxy/net.h | 35 ++++ 10 files changed, 1099 insertions(+), 102 deletions(-) create mode 100644 src/gwproxy/dnslookup.c create mode 100644 src/gwproxy/dnslookup.h create mode 100644 src/gwproxy/dnsparser.c create mode 100644 src/gwproxy/dnsparser.h create mode 100644 src/gwproxy/net.c create mode 100644 src/gwproxy/net.h base-commit: 0753f2d766e85fcbffc1f83dfd4e67d6206591cb -- Ahmad Gani