public inbox for gwml@vger.gnuweeb.org
 help / color / mirror / Atom feed
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 v6 10/11] gwproxy: Add DNS server option
Date: Thu, 28 Aug 2025 21:34:32 +0700	[thread overview]
Message-ID: <20250828143444.540247-11-reyuki@gnuweeb.org> (raw)
In-Reply-To: <20250828143444.540247-1-reyuki@gnuweeb.org>

Introduce --dns-server gwproxy' cmdline option instead of hard-coded
value.

Signed-off-by: Ahmad Gani <reyuki@gnuweeb.org>
---
 src/gwproxy/dns.c     |  3 +--
 src/gwproxy/gwproxy.c | 18 +++++++++++++++++-
 src/gwproxy/gwproxy.h |  3 +++
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/gwproxy/dns.c b/src/gwproxy/dns.c
index 9bc67b083b03..1eb0d9a67229 100644
--- a/src/gwproxy/dns.c
+++ b/src/gwproxy/dns.c
@@ -815,8 +815,7 @@ int gwp_dns_ctx_init(struct gwp_dns_ctx **ctx_p, const struct gwp_dns_cfg *cfg)
 
 	if (cfg->use_raw_dns) {
 #ifdef CONFIG_RAW_DNS
-	// r = convert_str_to_ssaddr(cfg->ns_addr_str, &ctx->ns_addr, 53);
-	r = convert_str_to_ssaddr("1.1.1.1", &ctx->ns_addr, 53);
+	r = convert_str_to_ssaddr(cfg->ns_addr_str, &ctx->ns_addr, 53);
 	if (r)
 		goto out_destroy_mutex;
 	ctx->ns_addrlen = ctx->ns_addr.sa.sa_family == AF_INET
diff --git a/src/gwproxy/gwproxy.c b/src/gwproxy/gwproxy.c
index 11efc21f4c5c..36305e65c4cb 100644
--- a/src/gwproxy/gwproxy.c
+++ b/src/gwproxy/gwproxy.c
@@ -45,6 +45,9 @@
 static const struct option long_opts[] = {
 	{ "help",		no_argument,		NULL,	'h' },
 	{ "raw-dns",		required_argument,	NULL,	'r' },
+#ifdef CONFIG_RAW_DNS
+	{ "dns-server",		required_argument,	NULL,	'j' },
+#endif
 	{ "event-loop",		required_argument,	NULL,	'e' },
 	{ "bind",		required_argument,	NULL,	'b' },
 	{ "target",		required_argument,	NULL,	't' },
@@ -94,6 +97,9 @@ static const struct gwp_cfg default_opts = {
 	.log_level		= 3,
 	.log_file		= "/dev/stdout",
 	.pid_file		= NULL,
+#ifdef CONFIG_RAW_DNS
+	.ns_addr_str		= "1.1.1.1"
+#endif
 };
 
 __cold
@@ -105,6 +111,9 @@ static void show_help(const char *app)
 	printf("  -e, --event-loop=name           Specify the event loop to use (default: %s)\n", default_opts.event_loop);
 	printf("                                  Available values: epoll, io_uring\n");
 	printf("  -r, --raw-dns=0|1               Use experimental raw DNS as the backend (default: %d)\n", default_opts.use_raw_dns);
+#ifdef CONFIG_RAW_DNS
+	printf("  -j, --dns-server=addr           DNS server address (default: %s)\n", default_opts.ns_addr_str);
+#endif
 	printf("  -b, --bind=addr:port            Bind to the specified address (default: %s)\n", default_opts.bind);
 	printf("  -t, --target=addr_port          Target address to connect to\n");
 	printf("  -S, --as-socks5=0|1             Run as a SOCKS5 proxy (default: %d)\n", default_opts.as_socks5);
@@ -228,6 +237,11 @@ static int parse_options(int argc, char *argv[], struct gwp_cfg *cfg)
 		case 'p':
 			cfg->pid_file = optarg;
 			break;
+#ifdef CONFIG_RAW_DNS
+		case 'j':
+			cfg->ns_addr_str = optarg;
+			break;
+#endif
 		default:
 			fprintf(stderr, "Unknown option: %c\n", c);
 			show_help(argv[0]);
@@ -693,7 +707,9 @@ static int gwp_ctx_init_dns(struct gwp_ctx *ctx)
 		.cache_expiry = cfg->socks5_dns_cache_secs,
 		.restyp = cfg->socks5_prefer_ipv6 ? GWP_DNS_RESTYP_PREFER_IPV6 : 0,
 		.nr_workers = 1,
-		// .ns_addr_str = "1.1.1.1"
+#ifdef CONFIG_RAW_DNS
+		.ns_addr_str = cfg->ns_addr_str
+#endif
 	};
 	int r;
 
diff --git a/src/gwproxy/gwproxy.h b/src/gwproxy/gwproxy.h
index 7f276d329e78..cdc5adf88ad6 100644
--- a/src/gwproxy/gwproxy.h
+++ b/src/gwproxy/gwproxy.h
@@ -44,6 +44,9 @@ struct gwp_cfg {
 	int		log_level;
 	const char	*log_file;
 	const char	*pid_file;
+#ifdef CONFIG_RAW_DNS
+	const char	*ns_addr_str;
+#endif
 };
 
 struct gwp_ctx;
-- 
Ahmad Gani


  parent reply	other threads:[~2025-08-28 14:37 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-28 14:34 [PATCH gwproxy v6 00/11] Initial work on integration of DNS parser lib in gwproxy Ahmad Gani
2025-08-28 14:34 ` [PATCH gwproxy v6 01/11] gwproxy: Fix syntax error inside assertion Ahmad Gani
2025-08-28 14:34 ` [PATCH gwproxy v6 02/11] gwproxy: Fix socks5 failure on debug mode Ahmad Gani
2025-08-28 14:34 ` [PATCH gwproxy v6 03/11] dnsparser: Add dns parser code Ahmad Gani
2025-08-28 14:34 ` [PATCH gwproxy v6 04/11] dnsparser: remove unused constant Ahmad Gani
2025-08-28 14:34 ` [PATCH gwproxy v6 05/11] dnsparser: Ignore CNAME if any Ahmad Gani
2025-08-28 14:34 ` [PATCH gwproxy v6 06/11] dns: Remove code block related to the usage of glibc's getaddrinfo_a function Ahmad Gani
2025-08-28 14:34 ` [PATCH gwproxy v6 07/11] dns: refactor dns.c to integrate the dns parser Ahmad Gani
2025-08-28 14:34 ` [PATCH gwproxy v6 08/11] dns: revert removed DNS code and disable raw DNS by default Ahmad Gani
2025-08-28 14:34 ` [PATCH gwproxy v6 09/11] test: revert DNS test-case Ahmad Gani
2025-08-28 14:34 ` Ahmad Gani [this message]
2025-08-28 14:34 ` [PATCH gwproxy v6 11/11] dns: Add fallback mechanism for raw DNS Ahmad Gani
2025-08-28 21:52 ` [PATCH gwproxy v6 00/11] Initial work on integration of DNS parser lib in gwproxy Ammar Faizi
2025-08-28 22:23 ` Ammar Faizi
2025-08-29  0:54   ` Ahmad Gani
2025-08-29  1:59     ` 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=20250828143444.540247-11-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