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 09/11] test: revert DNS test-case
Date: Thu, 28 Aug 2025 21:34:31 +0700 [thread overview]
Message-ID: <20250828143444.540247-10-reyuki@gnuweeb.org> (raw)
In-Reply-To: <20250828143444.540247-1-reyuki@gnuweeb.org>
The raw DNS test case will be added later once we've solved the known problem.
Signed-off-by: Ahmad Gani <reyuki@gnuweeb.org>
---
src/gwproxy/ev/epoll.c | 1 -
src/gwproxy/tests/dns.c | 110 +++++++++++++++++++++++-----------------
2 files changed, 63 insertions(+), 48 deletions(-)
diff --git a/src/gwproxy/ev/epoll.c b/src/gwproxy/ev/epoll.c
index a4ea80359236..cd8fd8752473 100644
--- a/src/gwproxy/ev/epoll.c
+++ b/src/gwproxy/ev/epoll.c
@@ -847,7 +847,6 @@ static int handle_ev_dns_query(struct gwp_wrk *w, struct gwp_conn_pair *gcp)
int r, ct = gcp->conn_state;
assert(gde);
- assert(gde->ev_fd >= 0);
assert(ct == CONN_STATE_SOCKS5_DNS_QUERY ||
ct == CONN_STATE_HTTP_DNS_QUERY);
diff --git a/src/gwproxy/tests/dns.c b/src/gwproxy/tests/dns.c
index 130ccfec59b6..7735d24afdd2 100644
--- a/src/gwproxy/tests/dns.c
+++ b/src/gwproxy/tests/dns.c
@@ -20,30 +20,25 @@ struct req_template {
const char *domain, *service;
};
-struct poll_map {
- struct gwp_dns_entry *e;
- int fd;
-};
-
static const struct req_template req_template[] = {
+ { "localhost", "80" },
{ "facebook.com", "80" },
+ { "google.com", "443" },
+ { "github.com", "443" },
+ { "example.com", "80" },
+ { "twitter.com", "443" },
+ { "reddit.com", "80" },
+ { "youtube.com", "443" },
+ { "wikipedia.org", "80" },
+ { "stackoverflow.com", "443" },
+ { "amazon.com", "80" },
+ { "microsoft.com", "443" },
+ { "apple.com", "80" },
+ { "linkedin.com", "443" },
+ { "bing.com", "80" },
};
-static struct gwp_dns_entry *find_item(struct poll_map *map, int n, int fd)
-{
- struct gwp_dns_entry *e;
- int i;
-
- e = NULL;
- for (i = 0; i < n; i++) {
- if (map[i].fd == fd)
- e = map[i].e;
- }
-
- return e;
-}
-
-static int poll_all_in(struct gwp_dns_ctx *ctx, struct poll_map *map, struct pollfd *pfd, int n, int timeout)
+static int poll_all_in(struct pollfd *pfd, int n, int timeout)
{
int ret, i, t = 0;
@@ -59,12 +54,7 @@ static int poll_all_in(struct gwp_dns_ctx *ctx, struct poll_map *map, struct pol
}
for (i = 0; i < n; i++) {
- struct gwp_dns_entry *e;
- if (pfd[i].revents & POLLIN) {
- e = find_item(map, n, pfd[i].fd);
- assert(e);
- ret = gwp_dns_process(ctx, e);
- assert(!ret);
+ if (pfd[i].revents & (POLLIN | POLLERR | POLLHUP)) {
pfd[i].events = 0;
t++;
}
@@ -77,14 +67,12 @@ static int poll_all_in(struct gwp_dns_ctx *ctx, struct poll_map *map, struct pol
static void test_basic_dns_multiple_requests(void)
{
- struct gwp_dns_cfg cfg = { .nr_workers = 1, .ns_addr_str = "1.1.1.1" };
- struct poll_map pollfd_map[ARRAY_SIZE(req_template)];
+ struct gwp_dns_cfg cfg = { .nr_workers = 1 };
+ struct gwp_dns_entry *earr[ARRAY_SIZE(req_template)];
struct pollfd pfd[ARRAY_SIZE(req_template)];
- struct gwp_sockaddr addr;
struct gwp_dns_ctx *ctx;
- uint8_t addrlen;
- ssize_t r;
int i, n;
+ int r;
r = gwp_dns_ctx_init(&ctx, &cfg);
assert(!r);
@@ -93,37 +81,65 @@ static void test_basic_dns_multiple_requests(void)
n = (int)ARRAY_SIZE(req_template);
for (i = 0; i < n; i++) {
const struct req_template *rt = &req_template[i];
- struct gwp_dns_entry *e;
- e = gwp_dns_queue(ctx, rt->domain, rt->service);
- assert(e);
- assert(e->udp_fd >= 0);
- pfd[i].fd = e->udp_fd;
+ earr[i] = gwp_dns_queue(ctx, rt->domain, rt->service);
+ assert(earr[i]);
+ assert(earr[i]->ev_fd >= 0);
+ pfd[i].fd = earr[i]->ev_fd;
pfd[i].events = POLLIN;
- cp_nsaddr(ctx, &addr, &addrlen);
- r = __sys_sendto(
- e->udp_fd, e->payload, e->payloadlen, MSG_NOSIGNAL,
- &addr.sa, addrlen
- );
- assert(r > 0);
- pollfd_map[i].fd = e->udp_fd;
- pollfd_map[i].e = e;
}
- r = poll_all_in(ctx, pollfd_map, pfd, n, 5000);
+ r = poll_all_in(pfd, n, 5000);
assert(!r);
for (i = 0; i < n; i++) {
- assert(pollfd_map[i].e->res == 0);
- r = pollfd_map[i].e->addr.sa.sa_family;
+ assert(earr[i]->res == 0);
+ r = earr[i]->addr.sa.sa_family;
assert(r == AF_INET || r == AF_INET6);
}
+ for (i = 0; i < n; i++)
+ gwp_dns_entry_put(earr[i]);
+ gwp_dns_ctx_free(ctx);
+}
+
+static void test_dns_cache(void)
+{
+ struct gwp_dns_cfg cfg = { .nr_workers = 1, .cache_expiry = 10 };
+ struct gwp_sockaddr addr;
+ struct gwp_dns_ctx *ctx;
+ struct gwp_dns_entry *e;
+ struct pollfd pfd;
+ int r;
+
+ r = gwp_dns_ctx_init(&ctx, &cfg);
+ assert(!r);
+ assert(ctx != NULL);
+
+ e = gwp_dns_queue(ctx, "localhost", "80");
+ assert(e != NULL);
+ assert(e->ev_fd >= 0);
+ pfd.fd = e->ev_fd;
+ pfd.events = POLLIN;
+ r = poll_all_in(&pfd, 1, 5000);
+ assert(r == 0);
+ assert(e->res == 0);
+ r = e->addr.sa.sa_family;
+ assert(r == AF_INET || r == AF_INET6);
+ gwp_dns_entry_put(e);
+
+ r = gwp_dns_cache_lookup(ctx, "localhost", "80", &addr);
+ assert(!r);
+ r = addr.sa.sa_family;
+ assert(r == AF_INET || r == AF_INET6);
+ r = gwp_dns_cache_lookup(ctx, "aaaa.com", "80", &addr);
+ assert(r == -ENOENT);
gwp_dns_ctx_free(ctx);
}
int main(void)
{
test_basic_dns_multiple_requests();
+ test_dns_cache();
printf("All tests passed.\n");
return 0;
}
--
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 ` [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 ` Ahmad Gani [this message]
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-10-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