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 v11 6/6] gwproxy: Reduce #ifdef CONFIG_RAW_DNS
Date: Sun, 14 Sep 2025 12:09:40 +0700 [thread overview]
Message-ID: <20250914050943.184934-7-reyuki@gnuweeb.org> (raw)
In-Reply-To: <20250914050943.184934-1-reyuki@gnuweeb.org>
No need to wrap struct members in #ifdef, adding a couple of bytes isn't
a big deal.
Signed-off-by: Ahmad Gani <reyuki@gnuweeb.org>
---
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 <gwproxy/syscall.h>
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
next prev parent reply other threads:[~2025-09-14 5:09 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-14 5:09 [PATCH gwproxy v11 0/6] Initial work on integration of DNS parser lib in gwproxy Ahmad Gani
2025-09-14 5:09 ` [PATCH gwproxy v11 1/6] dns: Use __sys_close instead of close Ahmad Gani
2025-09-14 5:09 ` [PATCH gwproxy v11 2/6] gwproxy: Define __maybe_unused macro Ahmad Gani
2025-09-14 5:09 ` [PATCH gwproxy v11 3/6] dnsparser: Add dns parser code Ahmad Gani
2025-09-14 5:09 ` [PATCH gwproxy v11 4/6] gwproxy: Refactor code base to add experimental raw DNS backend Ahmad Gani
2025-09-14 12:14 ` Ammar Faizi
2025-09-14 13:54 ` Alviro Iskandar Setiawan
2025-09-14 17:46 ` Ahmad Gani
2025-09-14 5:09 ` [PATCH gwproxy v11 5/6] gwproxy: Update Makefile and configure scripts Ahmad Gani
2025-09-14 12:55 ` Ammar Faizi
2025-09-14 17:45 ` Ahmad Gani
2025-09-14 5:09 ` Ahmad Gani [this message]
2025-09-14 12:16 ` [PATCH gwproxy v11 6/6] gwproxy: Reduce #ifdef CONFIG_RAW_DNS Ammar Faizi
2025-09-14 14:26 ` Alviro Iskandar Setiawan
2025-09-14 17:45 ` Ahmad Gani
2025-09-14 17:59 ` Alviro Iskandar Setiawan
2025-09-14 18:13 ` Ahmad Gani
2025-09-15 2:21 ` Alviro Iskandar Setiawan
2025-09-14 17:44 ` Ahmad Gani
2025-09-14 19:02 ` Ammar Faizi
2025-09-15 2:50 ` Alviro Iskandar Setiawan
2025-09-14 12:51 ` (subset) [PATCH gwproxy v11 0/6] Initial work on integration of DNS parser lib in gwproxy Ammar Faizi
2025-09-14 17:22 ` Alviro Iskandar Setiawan
2025-09-14 18:07 ` Ahmad Gani
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=20250914050943.184934-7-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