* [PATCH] flow: Handle NULL (unknown) flows in flow logging functions
@ 2026-11-15 22:37 Stefano Brivio
2026-11-16 3:12 ` David Gibson
0 siblings, 1 reply; 2+ messages in thread
From: Stefano Brivio @ 2026-11-15 22:37 UTC (permalink / raw)
To: passt-dev; +Cc: Doug Baggett, David Gibson
Starting from commit edeb2a26c663 ("udp: Improve messages for errors
getting errors"), we might call flow logging functions with a NULL
flow, for example via udp_sock_fwd() -> udp_sock_errs().
As reported by Doug, that will make us dereference a NULL flow in
flow_dbg(). This happens occasionally with a specific pattern in
outbound UDP traffic, where we contact a large number of endpoints
that might be occasionally unreachable.
We want to print socket errors even if we couldn't find an associated
flow. For simplicity, instead of adding conditionals in all the
possible callers, just handle NULL flows in flow logging functions,
and tell the user that we couldn't find a flow for the error.
Reported-by: Doug Baggett <doug.baggett@gmail.com>
Link: https://bugzilla.redhat.com/show_bug.cgi?id=2529245
Fixes: edeb2a26c663 ("udp: Improve messages for errors getting errors")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
flow.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/flow.c b/flow.c
index 71918b7..27a24a4 100644
--- a/flow.c
+++ b/flow.c
@@ -295,14 +295,19 @@ void flow_log__(const struct flow_common *f, int pri, bool perror, bool details,
(void)vsnprintf(msg, sizeof(msg), fmt, args);
va_end(args);
- /* Show type if it's set, otherwise the state */
- if (f->state < FLOW_STATE_TYPED)
- type_or_state = FLOW_STATE(f);
- else
- type_or_state = FLOW_TYPE(f);
+ if (!f) {
+ logmsg(!perror, false, pri, "Flow: not found, error: %s", msg);
+ details = false;
+ } else {
+ /* Show type if it's set, otherwise the state */
+ if (f->state < FLOW_STATE_TYPED)
+ type_or_state = FLOW_STATE(f);
+ else
+ type_or_state = FLOW_TYPE(f);
- logmsg(!perror, false, pri,
- "Flow %u (%s): %s", flow_idx(f), type_or_state, msg);
+ logmsg(!perror, false, pri,
+ "Flow %u (%s): %s", flow_idx(f), type_or_state, msg);
+ }
if (perror)
logmsg(true, true, pri, ": %s", strerror_(errno_));
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] flow: Handle NULL (unknown) flows in flow logging functions
2026-11-15 22:37 [PATCH] flow: Handle NULL (unknown) flows in flow logging functions Stefano Brivio
@ 2026-11-16 3:12 ` David Gibson
0 siblings, 0 replies; 2+ messages in thread
From: David Gibson @ 2026-11-16 3:12 UTC (permalink / raw)
To: Stefano Brivio; +Cc: passt-dev, Doug Baggett
[-- Attachment #1: Type: text/plain, Size: 2478 bytes --]
On Sun, Nov 15, 2026 at 11:37:28PM +0100, Stefano Brivio wrote:
> Starting from commit edeb2a26c663 ("udp: Improve messages for errors
> getting errors"), we might call flow logging functions with a NULL
> flow, for example via udp_sock_fwd() -> udp_sock_errs().
>
> As reported by Doug, that will make us dereference a NULL flow in
> flow_dbg(). This happens occasionally with a specific pattern in
> outbound UDP traffic, where we contact a large number of endpoints
> that might be occasionally unreachable.
>
> We want to print socket errors even if we couldn't find an associated
> flow. For simplicity, instead of adding conditionals in all the
> possible callers, just handle NULL flows in flow logging functions,
> and tell the user that we couldn't find a flow for the error.
>
> Reported-by: Doug Baggett <doug.baggett@gmail.com>
> Link: https://bugzilla.redhat.com/show_bug.cgi?id=2529245
> Fixes: edeb2a26c663 ("udp: Improve messages for errors getting errors")
> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> flow.c | 19 ++++++++++++-------
> 1 file changed, 12 insertions(+), 7 deletions(-)
>
> diff --git a/flow.c b/flow.c
> index 71918b7..27a24a4 100644
> --- a/flow.c
> +++ b/flow.c
> @@ -295,14 +295,19 @@ void flow_log__(const struct flow_common *f, int pri, bool perror, bool details,
> (void)vsnprintf(msg, sizeof(msg), fmt, args);
> va_end(args);
>
> - /* Show type if it's set, otherwise the state */
> - if (f->state < FLOW_STATE_TYPED)
> - type_or_state = FLOW_STATE(f);
> - else
> - type_or_state = FLOW_TYPE(f);
> + if (!f) {
> + logmsg(!perror, false, pri, "Flow: not found, error: %s", msg);
> + details = false;
> + } else {
> + /* Show type if it's set, otherwise the state */
> + if (f->state < FLOW_STATE_TYPED)
> + type_or_state = FLOW_STATE(f);
> + else
> + type_or_state = FLOW_TYPE(f);
>
> - logmsg(!perror, false, pri,
> - "Flow %u (%s): %s", flow_idx(f), type_or_state, msg);
> + logmsg(!perror, false, pri,
> + "Flow %u (%s): %s", flow_idx(f), type_or_state, msg);
> + }
>
> if (perror)
> logmsg(true, true, pri, ": %s", strerror_(errno_));
> --
> 2.43.0
>
--
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 --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-16 4:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-15 22:37 [PATCH] flow: Handle NULL (unknown) flows in flow logging functions Stefano Brivio
2026-11-16 3:12 ` David Gibson
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).