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 06/11] dns: Remove code block related to the usage of glibc's getaddrinfo_a function
Date: Thu, 28 Aug 2025 21:34:28 +0700 [thread overview]
Message-ID: <20250828143444.540247-7-reyuki@gnuweeb.org> (raw)
In-Reply-To: <20250828143444.540247-1-reyuki@gnuweeb.org>
This change is required for preparation in migration to no dedicated DNS
threads alternative.
Signed-off-by: Ahmad Gani <reyuki@gnuweeb.org>
---
configure | 20 -----
src/gwproxy/dns.c | 220 ----------------------------------------------
2 files changed, 240 deletions(-)
diff --git a/configure b/configure
index cef07b1cb652..19baa1585237 100755
--- a/configure
+++ b/configure
@@ -355,26 +355,6 @@ else
CXXFLAGS="${CXXFLAGS} -DNDEBUG";
fi;
-# ------ Check for getaddrinfo_a() ------
-cat > $tmp_c << EOF
-#include <netdb.h>
-int main(void)
-{
- struct sigevent ev;
- struct gaicb *gc = (void *)0;
- getaddrinfo_a(GAI_NOWAIT, &gc, 1, &ev);
- return 0;
-}
-EOF
-l="Do we have getaddrinfo_a()?";
-if compile_cc "" "-lanl" "getaddrinfo_a()"; then
- add_config "CONFIG_HAVE_GETADDRINFO_A";
- print_supp "yes" "${l}";
- LIB_LDFLAGS="${LIB_LDFLAGS} -lanl";
-else
- print_supp "no" "${l}";
-fi;
-
add_make_var "CC" "${cc}";
add_make_var "CXX" "${cxx}";
add_make_var "CFLAGS" "$(echo "${CFLAGS} ${USER_CFLAGS}" | awk '{$1=$1};1')";
diff --git a/src/gwproxy/dns.c b/src/gwproxy/dns.c
index cdc62a5bcf78..1e271a388493 100644
--- a/src/gwproxy/dns.c
+++ b/src/gwproxy/dns.c
@@ -234,204 +234,6 @@ static void wait_for_queue_entry(struct gwp_dns_ctx *ctx)
cond_scan_cache(ctx);
}
-#ifdef CONFIG_HAVE_GETADDRINFO_A
-/*
- * Must be called with ctx->lock held.
- */
-static struct gwp_dns_entry *unplug_queue_list(struct gwp_dns_ctx *ctx)
-{
- struct gwp_dns_entry *head = ctx->head;
-
- ctx->head = ctx->tail = NULL;
- ctx->nr_entries = 0;
- return head;
-}
-
-struct dbq_entry {
- struct gwp_dns_entry *e;
- struct gaicb cb;
-};
-
-struct dns_batch_query {
- struct dbq_entry *entries;
- struct gaicb **reqs;
- struct addrinfo hints;
- uint32_t nr_entries;
- uint32_t cap;
-};
-
-static void dbq_free(struct dns_batch_query *dbq)
-{
- uint32_t i;
-
- if (!dbq)
- return;
-
- if (dbq->reqs) {
- for (i = 0; i < dbq->nr_entries; i++) {
- if (dbq->reqs[i]->ar_result)
- freeaddrinfo(dbq->reqs[i]->ar_result);
- }
- }
-
- free(dbq->entries);
- free(dbq->reqs);
- free(dbq);
-}
-
-static int dbq_add_entry(struct dns_batch_query *dbq, struct gwp_dns_entry *e)
-{
- struct dbq_entry *de;
-
- if (dbq->nr_entries >= dbq->cap) {
- uint32_t new_cap = dbq->cap ? dbq->cap * 2 : 16;
- struct dbq_entry *nentries;
-
- nentries = realloc(dbq->entries, new_cap * sizeof(*nentries));
- if (!nentries)
- return -ENOMEM;
- dbq->entries = nentries;
- dbq->cap = new_cap;
- }
-
- de = &dbq->entries[dbq->nr_entries];
- de->e = e;
- memset(&de->cb, 0, sizeof(de->cb));
- de->cb.ar_name = e->name;
- de->cb.ar_service = e->service;
- de->cb.ar_request = &dbq->hints;
- de->cb.ar_result = NULL;
- dbq->nr_entries++;
-
- return 0;
-}
-
-static int collect_active_queries(struct gwp_dns_ctx *ctx,
- struct gwp_dns_entry **head_p,
- struct dns_batch_query **dbq_p)
-{
- struct gwp_dns_entry *e, *next, *prev = NULL, *head = *head_p;
- struct dns_batch_query *dbq;
-
- dbq = calloc(1, sizeof(*dbq));
- if (!dbq)
- return -ENOMEM;
-
- assert(head);
- prep_hints(&dbq->hints, ctx->cfg.restyp);
- for (e = head; e; e = next) {
- int x = atomic_load(&e->refcnt);
- next = e->next;
- if (x > 1) {
-
- if (dbq_add_entry(dbq, e)) {
- dbq_free(dbq);
- return -ENOMEM;
- }
-
- prev = e;
- continue;
- }
-
- assert(x == 1);
- /*
- * If the refcnt is 1, it means we are the last reference
- * to this entry. The client no longer cares about the
- * result. We can free it immediately. No need to resolve
- * the query nor to signal the eventfd.
- */
- if (prev)
- prev->next = next;
- else
- head = next;
-
- gwp_dns_entry_free(e);
- }
-
- *head_p = head;
- *dbq_p = dbq;
- return 0;
-}
-
-static void dispatch_batch_result(int r, struct gwp_dns_ctx *ctx,
- struct dns_batch_query *dbq,
- uint32_t restyp)
-{
- struct gwp_dns_entry *e;
- struct addrinfo *ai;
- uint32_t i;
-
- for (i = 0; i < dbq->nr_entries; i++) {
- e = dbq->entries[i].e;
- ai = dbq->reqs[i]->ar_result;
-
- if (!r) {
- e->res = gai_error(dbq->reqs[i]);
- if (!e->res) {
- if (!iterate_addr_list(ai, &e->addr, restyp))
- e->res = -EHOSTUNREACH;
- }
- } else {
- e->res = r;
- }
-
- eventfd_write(e->ev_fd, 1);
- if (!e->res)
- try_pass_result_to_cache(ctx, e->name, ai);
- }
-}
-
-/*
- * Filling dbq->reqs[n] cannot be done in dbq_add_entry() because
- * the reallocation of dbq->entries may change the address of
- * dbq->entries[n].cb.
- */
-static int prep_reqs(struct dns_batch_query *dbq)
-{
- uint32_t i;
-
- dbq->reqs = malloc(dbq->nr_entries * sizeof(*dbq->reqs));
- if (!dbq->reqs)
- return -ENOMEM;
-
- for (i = 0; i < dbq->nr_entries; i++)
- dbq->reqs[i] = &dbq->entries[i].cb;
-
- return 0;
-}
-
-/*
- * Must be called with ctx->lock held. May release the lock, but
- * it will reacquire it before returning.
- */
-static void process_queue_entry_batch(struct gwp_dns_ctx *ctx)
-{
- struct gwp_dns_entry *head = unplug_queue_list(ctx);
- struct dns_batch_query *dbq = NULL;
-
- if (!head)
- return;
-
- pthread_mutex_unlock(&ctx->lock);
-
- if (!collect_active_queries(ctx, &head, &dbq)) {
- if (!prep_reqs(dbq)) {
- struct sigevent ev;
- int r;
-
- memset(&ev, 0, sizeof(ev));
- ev.sigev_notify = SIGEV_NONE;
- r = getaddrinfo_a(GAI_WAIT, dbq->reqs, dbq->nr_entries, &ev);
- dispatch_batch_result(r, ctx, dbq, ctx->cfg.restyp);
- }
- }
-
- dbq_free(dbq);
- put_all_entries(head);
- pthread_mutex_lock(&ctx->lock);
-}
-#endif /* #ifdef CONFIG_HAVE_GETADDRINFO_A */
-
/*
* Must be called with ctx->lock held. May release the lock, but
* it will reacquire it before returning.
@@ -477,28 +279,6 @@ out:
*/
static void process_queue_entry(struct gwp_dns_ctx *ctx)
{
- /*
- * There are two cases here:
- *
- * 1. All of the DNS threads are busy, and there are still a lot
- * of queued entries. Process them in batch via getaddrinfo_a().
- *
- * 2. The number of threads is sufficient to handle the queued
- * entries, so process them one by one.
- *
- * Why not always getaddrinfo_a()? Because getaddrinfo_a() has
- * a higher overhead than processing entries individually as it
- * will spawn a new thread for each query. Don't bother invoking
- * clone() for each entry if we can process them in the current
- * thread.
- */
-#ifdef CONFIG_HAVE_GETADDRINFO_A
- if (ctx->nr_entries > (ctx->nr_sleeping + 16)) {
- process_queue_entry_batch(ctx);
- return;
- }
-#endif
-
process_queue_entry_single(ctx);
}
--
Ahmad Gani
next prev 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 ` Ahmad Gani [this message]
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 ` [PATCH gwproxy v6 10/11] gwproxy: Add DNS server option Ahmad Gani
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-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