All of lore.kernel.org
 help / color / mirror / Atom feed
From: Samuel Thibault <samuel.thibault@gnu.org>
To: Viktor Kurilko <murlockkinght@gmail.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH v4] Add a feature for mapping a host unix socket to a guest tcp socket
Date: Fri, 8 Aug 2025 01:56:18 +0200	[thread overview]
Message-ID: <aJU9IgWHfCpUEoi5@begin> (raw)
In-Reply-To: <20250805145543.580526-1-murlockkinght@gmail.com>

We're almost there :)

Viktor Kurilko, le mar. 05 août 2025 21:52:50 +0700, a ecrit:
> @@ -824,30 +827,81 @@ static int slirp_hostfwd(SlirpState *s, const char *redir_str, Error **errp)
>          is_udp = 0;
>      } else if (!strcmp(buf, "udp")) {
>          is_udp = 1;
> -    } else {
> -        fail_reason = "Bad protocol name";
> -        goto fail_syntax;
>      }
> -
> -    if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
> -        fail_reason = "Missing : separator";
> -        goto fail_syntax;
> +#if !defined(WIN32) && SLIRP_CHECK_VERSION(4, 7, 0)
> +    else if (!strcmp(buf, "unix")) {
> +        is_unix = 1;
>      }
> -    if (buf[0] != '\0' && !inet_aton(buf, &host_addr.sin_addr)) {
> -        fail_reason = "Bad host address";
> +#endif
> +    else {
> +        fail_reason = "Bad protocol name";
>          goto fail_syntax;
>      }
>  
> -    if (get_str_sep(buf, sizeof(buf), &p, '-') < 0) {
> -        fail_reason = "Bad host port separator";
> +    if (get_str_sep(buf, sizeof(buf), &p, is_unix ? '-' : ':') < 0) {

This factorization looks odd. I don't think it's actually more readable
to try to factorize some separator parsing. I'd say rather have an if
(unix) part and else (ip) part, which both make their own get_str_sep
calls, and factorize just the parsing of the guest part.

> +#endif
> +    {
> +        if (buf[0] != '\0' && !inet_aton(buf, &host_addr.in.sin_addr)) {
> +            fail_reason = "Bad host address";
> +            goto fail_syntax;
> +        }
> +
> +        if (get_str_sep(buf, sizeof(buf), &p, '-') < 0) {
> +            fail_reason = "Bad host port separator";
> +            goto fail_syntax;
> +        }
> +
> +        err = qemu_strtoi(buf, &end, 0, &host_port);
> +        if (err || host_port < 0 || host_port > 65535) {
> +            fail_reason = "Bad host port";
> +            goto fail_syntax;
> +        }
> +        host_addr.in.sin_family = AF_INET;
> +        host_addr.in.sin_addr.s_addr = INADDR_ANY;

This is overwriting the inet_aton call above?

> +        host_addr.in.sin_port = htons(host_port);
> +        host_addr_size = sizeof(host_addr.in);
>      }
> -    host_addr.sin_port = htons(host_port);
>  
>      if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
>          fail_reason = "Missing guest address";

Samuel


      reply	other threads:[~2025-08-07 23:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-05 14:52 [PATCH v4] Add a feature for mapping a host unix socket to a guest tcp socket Viktor Kurilko
2025-08-07 23:56 ` Samuel Thibault [this message]

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=aJU9IgWHfCpUEoi5@begin \
    --to=samuel.thibault@gnu.org \
    --cc=murlockkinght@gmail.com \
    --cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.