public inbox for gwml@vger.gnuweeb.org
 help / color / mirror / Atom feed
From: Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>
To: Ahmad Gani <reyuki@gnuweeb.org>
Cc: Ammar Faizi <ammarfaizi2@gnuweeb.org>,
	"GNU/Weeb Mailing List" <gwml@vger.gnuweeb.org>
Subject: Re: [PATCH gwproxy v8 2/2] gwproxy: refactor code base to add experimental raw DNS backend
Date: Fri, 5 Sep 2025 23:26:01 +0700	[thread overview]
Message-ID: <CAOG64qN+BXH0S5YTzBrgY4JAJPd-TSDpiOd8YSirU=BA0hUy2Q@mail.gmail.com> (raw)
In-Reply-To: <20250829075557.598176-3-reyuki@gnuweeb.org>

Having #ifdef CONFIG_RAW_DNS all over the place is horrible. Please do
something else to reduce them. CTRL + F, "def CONFIG_RAW_DNS", 24
matches. We're not taking this.

On Fri, Aug 29, 2025 at 2:56 PM Ahmad Gani wrote:
> +void cp_nsaddr(struct gwp_dns_ctx *ctx, struct gwp_sockaddr *addr, uint8_t *addrlen)
> +{
> +       *addr = ctx->ns_addr;
> +       *addrlen = ctx->ns_addrlen;
> +}

Why is this exposed globally? I don't think it's worth a function
call. Better be inlined.

> +int gwp_dns_process(struct gwp_dns_ctx *ctx, struct gwp_dns_entry *e)
> +{
> +       struct gwdns_addrinfo_node *ai;
> +       uint8_t buff[UDP_MSG_LIMIT];
> +       ssize_t r;
> +
> +       r = __sys_recvfrom(
> +               e->udp_fd, buff, sizeof(buff), 0,
> +               &ctx->ns_addr.sa, (socklen_t *)&ctx->ns_addrlen
> +       );
> +       if (r <= 0)
> +               return (int)r;

The subsequent code calls gwdns_parse_query(), and you noted that a
return value of 0 indicates success, and by the end of
gwp_dns_process(), it returns what was returned by
gwdns_parse_query(). That's it. It means, if successful, it returns 0.
What happens if __sys_recvfrom() returns 0? Doesn't that mean it's
also considered successful? If so, why?

> +       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_destroy_mutex;
> +       ctx->ns_addrlen = ctx->ns_addr.sa.sa_family == AF_INET
> +                       ? sizeof(ctx->ns_addr.i4)
> +                       : sizeof(ctx->ns_addr.i6);
> +       ctx->entry_cap = DEFAULT_ENTRIES_CAP;
> +       ctx->entries = malloc(ctx->entry_cap * sizeof(*ctx->entries));
> +       if (!ctx->entries)
> +               goto out_destroy_mutex;
> +#endif
> +       } else {

Bad indentation. Apart from bad indentation, if the malloc() call
fails, r still contains 0, and you goto out_destroy_mutex, returning 0
on failure. Shouldn't you set -ENOMEM instead?

>  void gwp_dns_ctx_free(struct gwp_dns_ctx *ctx)
>  {
> -       free_workers(ctx);
> +       if (ctx->cfg.use_raw_dns) {
> +#ifdef CONFIG_RAW_DNS
> +       free_all_queued_entries(ctx);
> +#endif
> +       } else {

Bad indentation.

> +               txid = (uint16_t)rand();

Why do you use a random number for the txid? I don't think rand()
guarantees uniqueness. Also, I don't find the srand() call anywhere.
That's equivalent to having srand(1).

What about using a simple incrementing counter instead (which
guarantees the uniqueness)?
It will indeed reset after 65535, but that should give enough room to
complete prior DNS requests first. With a simple counter, the reuse of
an ID will always be 65535 queries away.

>  struct gwp_dns_entry {
> +#ifdef CONFIG_RAW_DNS
> +       uint32_t                idx;
> +       int                     udp_fd;

AFAIU, when using the raw DNS feature you bring. ev_fd is not used,
instead you use udp_fd. So I think it is not worth adding extra unused
space. Better be an anonymous union if the name needs to be different.
No?

> +#ifdef CONFIG_RAW_DNS
> +static int arm_poll_for_raw_dns_query(struct gwp_wrk *w,
> +                                       struct gwp_conn_pair *gcp)
> +{
> +       struct gwp_dns_entry *gde = gcp->gde;
> +       struct gwp_dns_ctx *dctx;
> +       struct gwp_sockaddr addr;
> +       uint8_t addrlen;
> +       ssize_t r;
> +
> +       dctx = w->ctx->dns;
> +       cp_nsaddr(dctx, &addr, &addrlen);
> +       r = __sys_sendto(
> +               gde->udp_fd, gde->payload, gde->payloadlen, MSG_NOSIGNAL,
> +               &addr.sa, addrlen
> +       );
> +
> +       return (int)r;
> +}
> +#endif

Why is this function named arm_poll_for_raw_dns_query()? There is no
poll-arming here. You're simply calling __sys_sendto(). Please write a
function name based on what it does. It's confusing.

> +       if (w->ctx->cfg.use_raw_dns) {
> +#ifdef CONFIG_RAW_DNS
> +       arm_poll_for_raw_dns_query(w, gcp);
> +
> +       r = __sys_epoll_ctl(w->ep_fd, EPOLL_CTL_ADD, gde->udp_fd, &ev);
>         if (unlikely(r))
> -               return r;
> +               return (int)r;
> +#endif
> +       } else {

Bad indentation.

> -       gwp_dns_entry_put(gde);
> +       if (w->ctx->cfg.use_raw_dns) {
> +#ifdef CONFIG_RAW_DNS
> +       gwp_dns_raw_entry_free(w->ctx->dns, gde);
> +#endif

Bad indentation. Why are there many of those?

> +       if (gcp->gde) {
> +               if (w->ctx->cfg.use_raw_dns) {
> +#ifdef CONFIG_RAW_DNS
> +               gwp_dns_raw_entry_free(w->ctx->dns, gcp->gde);
> +#endif
> +               } else {

Bad indentation.

  reply	other threads:[~2025-09-05 16:26 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-29  7:55 [PATCH gwproxy v8 0/2] Initial work on integration of DNS parser lib in gwproxy Ahmad Gani
2025-08-29  7:55 ` [PATCH gwproxy v8 1/2] dnsparser: Add dns parser code Ahmad Gani
2025-08-29  7:55 ` [PATCH gwproxy v8 2/2] gwproxy: refactor code base to add experimental raw DNS backend Ahmad Gani
2025-09-05 16:26   ` Alviro Iskandar Setiawan [this message]
2025-09-06  4:32     ` Ahmad Gani
2025-09-06  5:16       ` Ahmad Gani
2025-09-06  6:17       ` Ahmad Gani
2025-09-06  6:48         ` Ahmad Gani
2025-09-06  7:02           ` Alviro Iskandar Setiawan
2025-09-06  6:47       ` Alviro Iskandar Setiawan
2025-09-09  2:38         ` reyuki
2025-09-06 11:27       ` Ahmad Gani
2025-09-06 12:01         ` Alviro Iskandar Setiawan
2025-09-06 12:58         ` Ahmad Gani
2025-09-06 13:30           ` Alviro Iskandar Setiawan
2025-09-06 13:44             ` Alviro Iskandar Setiawan
2025-09-06 14:26             ` Ahmad Gani
2025-09-06 14:30               ` Alviro Iskandar Setiawan
2025-09-07  4:22             ` Ammar Faizi
2025-09-07  5:57               ` Ammar Faizi
2025-09-07  6:39               ` Ahmad Gani
2025-09-07  6:40                 ` Ahmad Gani
2025-09-07  6:43                   ` Ammar Faizi
2025-09-07  7:06                 ` Ammar Faizi
2025-09-07  7:17                   ` Ahmad Gani
2025-09-07  9:52               ` Ahmad Gani
2025-09-07 10:19                 ` Ammar Faizi
2025-09-07 10:36                   ` Ahmad Gani
2025-09-06  7:14     ` Alviro Iskandar Setiawan
2025-09-06  7:21       ` Ahmad Gani
2025-09-06  7:47   ` Alviro Iskandar Setiawan
2025-09-06 11:01     ` Ahmad Gani
2025-09-05  9:18 ` [PATCH gwproxy v8 0/2] Initial work on integration of DNS parser lib in gwproxy Ammar Faizi
2025-09-05  9:34   ` Alviro Iskandar Setiawan

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='CAOG64qN+BXH0S5YTzBrgY4JAJPd-TSDpiOd8YSirU=BA0hUy2Q@mail.gmail.com' \
    --to=alviro.iskandar@gnuweeb.org \
    --cc=ammarfaizi2@gnuweeb.org \
    --cc=gwml@vger.gnuweeb.org \
    --cc=reyuki@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