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=1757826599; bh=FgmYxgHFOcIH+O+YpjN4d09Tfb0PJmoHCIwWta9YuQM=; 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=haQMUEWT4X+lLJfk6pxPTHZVUjJUHEV8BBdU43egzdTVb9SebDPUTumcWzcrCgxIP /5rvhqOux6BsDvl61hJ6XI/f5ldPwaskgDNSV3z5693/DgBO1Zgde55xJs4z+2edmU X/rJpkLK+ql44G+kFSyIlu0q00x6GHBaoDCPfI7rdc3zS31VZ7gJR/JReCjKjh0POZ BruZLQDPy+qO1XlyJJeEkhDDdeVoJrVEj+UxekfOPT5T/uGtGbBXMHR4ka3QInfthD Pwfl/CmTrQWJvwv6AK6pljqmhf7JIbd9JPS3lC6aj/xGbLzQUf8i9a+xp7WqVJr0Ne y46eEbSBjH+xg== Received: from zero (unknown [182.253.228.107]) by server-vie001.gnuweeb.org (Postfix) with ESMTPSA id 60A6831279CA; Sun, 14 Sep 2025 05:09:58 +0000 (UTC) From: Ahmad Gani To: Ammar Faizi Cc: Ahmad Gani , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH gwproxy v11 6/6] gwproxy: Reduce #ifdef CONFIG_RAW_DNS Date: Sun, 14 Sep 2025 12:09:40 +0700 Message-ID: <20250914050943.184934-7-reyuki@gnuweeb.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250914050943.184934-1-reyuki@gnuweeb.org> References: <20250914050943.184934-1-reyuki@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: No need to wrap struct members in #ifdef, adding a couple of bytes isn't a big deal. Signed-off-by: Ahmad Gani --- src/gwproxy/dns.c | 2 -- src/gwproxy/dns.h | 8 +------- src/gwproxy/ev/epoll.c | 4 +--- src/gwproxy/gwproxy.c | 10 ---------- src/gwproxy/gwproxy.h | 6 +----- 5 files changed, 3 insertions(+), 27 deletions(-) diff --git a/src/gwproxy/dns.c b/src/gwproxy/dns.c index c881b034611f..cd43c7c2f698 100644 --- a/src/gwproxy/dns.c +++ b/src/gwproxy/dns.c @@ -868,7 +868,6 @@ int gwp_dns_ctx_init(struct gwp_dns_ctx **ctx_p, const struct gwp_dns_cfg *cfg) ctx->cfg = *cfg; if (cfg->use_raw_dns) { -#ifdef CONFIG_RAW_DNS r = convert_str_to_ssaddr(cfg->ns_addr_str, &ctx->ns_addr, 53); if (r) goto out_free_ctx; @@ -882,7 +881,6 @@ int gwp_dns_ctx_init(struct gwp_dns_ctx **ctx_p, const struct gwp_dns_cfg *cfg) r = -ENOMEM; goto out_free_ctx; } -#endif } else { r = pthread_mutex_init(&ctx->lock, NULL); if (r) { diff --git a/src/gwproxy/dns.h b/src/gwproxy/dns.h index 049505997e37..30658090f130 100644 --- a/src/gwproxy/dns.h +++ b/src/gwproxy/dns.h @@ -15,14 +15,12 @@ #include struct gwp_dns_entry { -#ifdef CONFIG_RAW_DNS uint32_t idx; int payloadlen; union { uint16_t txid; uint8_t payload[UDP_MSG_LIMIT]; }; -#endif char *name; char *service; _Atomic(int) refcnt; @@ -47,18 +45,14 @@ struct gwp_dns_cfg { uint32_t nr_workers; uint32_t restyp; bool use_raw_dns; -#ifdef CONFIG_RAW_DNS const char *ns_addr_str; -#endif }; struct gwp_dns_ctx { -#ifdef CONFIG_RAW_DNS uint32_t entry_cap; struct gwp_dns_entry **entries; struct gwp_sockaddr ns_addr; socklen_t ns_addrlen; -#endif volatile bool should_stop; pthread_mutex_t lock; pthread_cond_t cond; @@ -137,7 +131,7 @@ static inline struct gwp_dns_entry *gwp_raw_dns_queue(__maybe_unused uint16_t tx static inline void gwp_dns_raw_entry_free(__maybe_unused struct gwp_dns_ctx *ctx, __maybe_unused struct gwp_dns_entry *e) { } -#endif +#endif /* #ifdef CONFIG_RAW_DNS */ /** * Lookup a DNS entry in the cache. If the entry is found, it fills the diff --git a/src/gwproxy/ev/epoll.c b/src/gwproxy/ev/epoll.c index 5926bb5e090a..7c2ff111cefe 100644 --- a/src/gwproxy/ev/epoll.c +++ b/src/gwproxy/ev/epoll.c @@ -40,13 +40,11 @@ int gwp_ctx_init_thread_epoll(struct gwp_wrk *w) } if (w->ctx->cfg.use_raw_dns) { -#ifdef CONFIG_RAW_DNS ev.events = EPOLLIN; ev.data.u64 = EV_BIT_DNS_QUERY; r = __sys_epoll_ctl(ep_fd, EPOLL_CTL_ADD, w->dns_resolver.udp_fd, &ev); if (unlikely(r)) return (int)r; -#endif } w->evsz = 512; @@ -869,7 +867,7 @@ static int read_raw_dns_answer(__maybe_unused struct gwp_wrk *w, { return 0; } -#endif +#endif /* #ifdef CONFIG_RAW_DNS */ static int arm_poll_for_dns_query(struct gwp_wrk *w, struct gwp_conn_pair *gcp) diff --git a/src/gwproxy/gwproxy.c b/src/gwproxy/gwproxy.c index e14780f23945..5afc2f0105ba 100644 --- a/src/gwproxy/gwproxy.c +++ b/src/gwproxy/gwproxy.c @@ -45,10 +45,8 @@ 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' }, { "session-map-cap", required_argument, NULL, 's' }, -#endif { "event-loop", required_argument, NULL, 'e' }, { "bind", required_argument, NULL, 'b' }, { "target", required_argument, NULL, 't' }, @@ -100,10 +98,8 @@ 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", .sess_map_cap = 16 -#endif }; __cold @@ -115,9 +111,7 @@ 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); @@ -245,14 +239,12 @@ 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; case 's': cfg->sess_map_cap = atoi(optarg); break; -#endif default: fprintf(stderr, "Unknown option: %c\n", c); show_help(argv[0]); @@ -858,9 +850,7 @@ 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 = cfg->nr_dns_workers, -#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 9930934b893e..527447cb8dcc 100644 --- a/src/gwproxy/gwproxy.h +++ b/src/gwproxy/gwproxy.h @@ -46,10 +46,8 @@ struct gwp_cfg { int log_level; const char *log_file; const char *pid_file; -#ifdef CONFIG_RAW_DNS const char *ns_addr_str; int sess_map_cap; -#endif }; struct gwp_ctx; @@ -215,10 +213,8 @@ struct dns_resolver { struct gwp_wrk { int tcp_fd; -#ifdef CONFIG_RAW_DNS /* For mapping DNS queries to the corresponding proxy session */ struct dns_resolver dns_resolver; -#endif struct gwp_conn_slot conn_slot; union { @@ -337,7 +333,7 @@ static inline int return_txid(__maybe_unused struct gwp_wrk *w, __maybe_unused s { return 0; } -#endif +#endif /* #ifdef CONFIG_RAW_DNS */ static inline void gwp_conn_buf_advance(struct gwp_conn *conn, size_t len) { -- Ahmad Gani