From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH 3/4] flow: Safer errno handling in flowside_connect() callers
Date: Wed, 17 Jun 2026 12:25:22 +1000 [thread overview]
Message-ID: <ajIFktu5UVJopzIC@zatzit> (raw)
In-Reply-To: <20260617010918.12f447a5@elisabeth>
[-- Attachment #1: Type: text/plain, Size: 3917 bytes --]
On Wed, Jun 17, 2026 at 01:09:18AM +0200, Stefano Brivio wrote:
> On Tue, 9 Jun 2026 12:32:25 +1000
> David Gibson <david@gibson.dropbear.id.au> wrote:
>
> > flowside_connect() behaves much like connect(2) itself, returning -1 on
> > error with errno set to the error code. One of the callers, in
> > udp_flow_sock(), uses the errno code with flow_dbg_perror() *after* it's
> > called epoll_del() and close() either of which could clobber errno.
> >
> > Change flowside_connect() to use the more regular convention for internal
> > functions: return a negative errno code on error, rather than just -1.
> > Save it in the callers and use that rather than raw errno to print the
> > message.
> >
> > Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> > ---
> > flow.c | 6 ++++--
> > tcp.c | 4 ++--
> > udp_flow.c | 7 +++----
> > 3 files changed, 9 insertions(+), 8 deletions(-)
> >
> > diff --git a/flow.c b/flow.c
> > index dd92bad7..98828430 100644
> > --- a/flow.c
> > +++ b/flow.c
> > @@ -259,7 +259,7 @@ int flowside_sock_l4(const struct ctx *c, enum epoll_type type, uint8_t pif,
> > *
> > * Connect @s to the endpoint address and port from @tgt.
> > *
> > - * Return: 0 on success, negative on error
> > + * Return: 0 on success, negative error code on error
> > */
> > int flowside_connect(const struct ctx *c, int s,
> > uint8_t pif, const struct flowside *tgt)
> > @@ -267,7 +267,9 @@ int flowside_connect(const struct ctx *c, int s,
> > union sockaddr_inany sa;
> >
> > pif_sockaddr(c, &sa, pif, &tgt->eaddr, tgt->eport);
> > - return connect(s, &sa.sa, socklen_inany(&sa));
> > + if (connect(s, &sa.sa, socklen_inany(&sa)) < 0)
> > + return -errno;
> > + return 0;
>
> This looks like a good idea nevertheless, but:
>
> > }
> >
> > /** flow_log__ - Log flow-related message, internal helper
> > diff --git a/tcp.c b/tcp.c
> > index 6fba865f..81813643 100644
> > --- a/tcp.c
> > +++ b/tcp.c
> > @@ -3744,8 +3744,8 @@ static int tcp_flow_repair_connect(const struct ctx *c,
> >
> > rc = flowside_connect(c, conn->sock, PIF_HOST, tgt);
> > if (rc) {
> > - rc = -errno;
> > - flow_perror(conn, "Failed to connect migrated socket");
> > + flow_err(conn, "Failed to connect migrated socket: %s",
> > + strerror_(-rc));
>
> ...wouldn't it be more convenient to establish that flowside_connect()
> behaves like connect() also by setting errno (by updating the comment
> to flowside_connect() accordingly) and use that fact here to keep
> calling flow_perror(), so that we don't need to open code the
> strerror_() call?
I was working on the basis that returning an error code is a more
common convention for internal functions than setting errno. But..
>
> > return rc;
> > }
> >
> > diff --git a/udp_flow.c b/udp_flow.c
> > index 35417bc4..6edfa65a 100644
> > --- a/udp_flow.c
> > +++ b/udp_flow.c
> > @@ -88,13 +88,12 @@ static int udp_flow_sock(const struct ctx *c,
> > return rc;
> > }
> >
> > - if (flowside_connect(c, s, pif, side) < 0) {
> > - rc = -errno;
> > -
> > + if ((rc = flowside_connect(c, s, pif, side)) < 0) {
> > epoll_del(flow_epollfd(&uflow->f), s);
> > close(s);
> >
> > - flow_dbg_perror(uflow, "Couldn't connect flow socket");
> > + flow_dbg(uflow, "Couldn't connect flow socket: %s",
> > + strerror_(-rc));
>
> For the same reason, couldn't we just move the existing
> flow_dbg_perror() call before epoll_del() instead?
..duh. That's a much easier way of solving the problem. I'll do that
instead.
>
> > return rc;
> > }
> > uflow->s[sidei] = s;
>
> --
> Stefano
>
--
David Gibson (he or they) | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you, not the other way
| around.
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2026-06-17 3:08 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-09 2:32 [PATCH 0/4] RFC: Improvements to flow specific logging David Gibson
2026-06-09 2:32 ` [PATCH 1/4] flow: Regularise flow specific logging helpers David Gibson
2026-06-16 23:09 ` Stefano Brivio
2026-06-17 2:03 ` David Gibson
2026-06-09 2:32 ` [PATCH 2/4] flow: Include flow details with higher priority log messages David Gibson
2026-06-16 23:09 ` Stefano Brivio
2026-06-17 2:15 ` David Gibson
2026-06-17 5:22 ` Stefano Brivio
2026-06-09 2:32 ` [PATCH 3/4] flow: Safer errno handling in flowside_connect() callers David Gibson
2026-06-16 23:09 ` Stefano Brivio
2026-06-17 2:25 ` David Gibson [this message]
2026-06-09 2:32 ` [PATCH 4/4] flow, treewide: Promote priority of selected flow-linked messages David Gibson
2026-06-16 23:09 ` Stefano Brivio
2026-06-17 3:08 ` David Gibson
2026-06-16 23:08 ` [PATCH 0/4] RFC: Improvements to flow specific logging Stefano Brivio
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=ajIFktu5UVJopzIC@zatzit \
--to=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.com \
/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.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).