From: Stefano Brivio <sbrivio@redhat.com>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: passt-dev@passt.top, Jon Maloy <jmaloy@redhat.com>
Subject: Re: [PATCH 5/7] udp: Add udp_pktinfo() helper
Date: Tue, 15 Apr 2025 20:54:00 +0200 [thread overview]
Message-ID: <20250415205400.68c7c1d2@elisabeth> (raw)
In-Reply-To: <20250415071624.2618589-6-david@gibson.dropbear.id.au>
I took the liberty of applying this with two minor changes:
On Tue, 15 Apr 2025 17:16:22 +1000
David Gibson <david@gibson.dropbear.id.au> wrote:
> Currently we open code parsing the control message for IP_PKTINFO in
> udp_peek_addr(). We have an upcoming case where we want to parse PKTINFO
> in another place, so split this out into a helper function.
>
> While we're there, make the parsing a bit more robust: scan all cmsgs to
> look for the one we want, rather than assuming there's only one.
>
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> udp.c | 52 ++++++++++++++++++++++++++++++++++++----------------
> 1 file changed, 36 insertions(+), 16 deletions(-)
>
> diff --git a/udp.c b/udp.c
> index 0bec499d..352ab83b 100644
> --- a/udp.c
> +++ b/udp.c
> @@ -464,6 +464,41 @@ static void udp_send_tap_icmp6(const struct ctx *c,
> tap_icmp6_send(c, saddr, eaddr, &msg, msglen);
> }
>
> +/**
> + * udp_pktinfo() - Retreive packet destination address from cmsg
Nit: "Retrieve", and:
> + * @msg: msghdr into which message has been received
> + * @dst: (Local) destination address of message in @mh (output)
> + *
> + * Return: 0 on success, -1 if the information was missing (@dst is set to
> + * inany_any6).
> + */
> +static int udp_pktinfo(struct msghdr *msg, union inany_addr *dst)
> +{
> + struct cmsghdr *hdr;
> +
> + for (hdr = CMSG_FIRSTHDR(msg); hdr; hdr = CMSG_NXTHDR(msg, hdr)) {
> + if (hdr->cmsg_level == IPPROTO_IP &&
> + hdr->cmsg_type == IP_PKTINFO) {
> + const struct in_pktinfo *i4 = (void *)CMSG_DATA(hdr);
> +
> + *dst = inany_from_v4(i4->ipi_addr);
> + return 0;
> + }
> +
> + if (hdr->cmsg_level == IPPROTO_IPV6 &&
> + hdr->cmsg_type == IPV6_PKTINFO) {
> + const struct in6_pktinfo *i6 = (void *)CMSG_DATA(hdr);
> +
> + dst->a6 = i6->ipi6_addr;
> + return 0;
> + }
> + }
> +
> + err("Missing PKTINFO cmsg on datagram");
...from a quick glance at the matching kernel path, this looks a bit
too likely for err(), so I got a bit scared, and turned it to debug().
I think warn() is actually more correct than debug() (I think it
shouldn't really be err() though because we can keep using this flow),
but I would feel a lot more confident about it once we have
rate-limited versions of those.
Of course, I'll change this back to err() or warn() if you have a
compelling reason.
Similar reasoning in 7/7 where this is called.
By the way, two messages (here and in caller) look redundant to me,
regardless of their severity, but I'm not sure if you have further
changes in mind where these separate prints would make sense.
--
Stefano
next prev parent reply other threads:[~2025-04-15 18:54 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-15 7:16 [PATCH 0/7] Assorted fixes for UDP socket and error handling problems David Gibson
2025-04-15 7:16 ` [PATCH 1/7] udp: Fix breakage of UDP error handling by PKTINFO support David Gibson
2025-04-15 7:16 ` [PATCH 2/7] udp: Be quieter about errors on UDP receive David Gibson
2025-04-15 7:16 ` [PATCH 3/7] udp: Pass socket & flow information direction to error handling functions David Gibson
2025-04-15 7:16 ` [PATCH 4/7] udp: Deal with errors as we go in udp_sock_fwd() David Gibson
2025-04-15 7:16 ` [PATCH 5/7] udp: Add udp_pktinfo() helper David Gibson
2025-04-15 18:54 ` Stefano Brivio [this message]
2025-04-16 0:37 ` David Gibson
2025-04-15 7:16 ` [PATCH 6/7] udp: Minor re-organisation of udp_sock_recverr() David Gibson
2025-04-15 7:16 ` [PATCH 7/7] udp: Propagate errors on listening and brand new sockets David Gibson
2025-04-15 18:54 ` Stefano Brivio
2025-04-16 0:38 ` David Gibson
2025-04-15 19:10 ` [PATCH 0/7] Assorted fixes for UDP socket and error handling problems 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=20250415205400.68c7c1d2@elisabeth \
--to=sbrivio@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=jmaloy@redhat.com \
--cc=passt-dev@passt.top \
/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).