public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: passt-dev@passt.top
Subject: Re: [PATCH 09/12] udp_flow: Take pif and port as explicit parameters to udp_flow_from_sock()
Date: Mon, 7 Apr 2025 23:49:27 +0200	[thread overview]
Message-ID: <20250407234927.767cca47@elisabeth> (raw)
In-Reply-To: <20250404101542.3729316-10-david@gibson.dropbear.id.au>

On Fri,  4 Apr 2025 21:15:39 +1100
David Gibson <david@gibson.dropbear.id.au> wrote:

> Currently udp_flow_from_sock() is only used when receiving a datagram
> from a "listening" socket.  It takes the listening socket's epoll
> reference to get the interface and port on which the datagram arrived.
> 
> We have some upcoming cases where we want to use this in different
> contexts, so make it take the pif and port as direct parameters instead.
> 
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> ---
>  udp.c      |  4 +++-
>  udp_flow.c | 15 +++++++--------
>  udp_flow.h |  2 +-
>  3 files changed, 11 insertions(+), 10 deletions(-)
> 
> diff --git a/udp.c b/udp.c
> index f6de2924..dbb33f2a 100644
> --- a/udp.c
> +++ b/udp.c
> @@ -728,7 +728,9 @@ static void udp_listen_sock_data(const struct ctx *c, union epoll_ref ref,
>  	union sockaddr_inany src;
>  
>  	while (udp_peek_addr(ref.fd, &src) == 0) {
> -		flow_sidx_t tosidx = udp_flow_from_sock(c, ref, &src, now);
> +		flow_sidx_t tosidx = udp_flow_from_sock(c, ref.udp.pif,
> +							ref.udp.port, &src,
> +							now);
>  		uint8_t topif = pif_at_sidx(tosidx);
>  
>  		if (pif_is_socket(topif)) {
> diff --git a/udp_flow.c b/udp_flow.c
> index d50bddb2..b95c3176 100644
> --- a/udp_flow.c
> +++ b/udp_flow.c
> @@ -160,8 +160,10 @@ cancel:
>  }
>  
>  /**
> - * udp_flow_from_sock() - Find or create UDP flow for "listening" socket
> + * udp_flow_from_sock() - Find or create UDP flow for incoming datagram
>   * @c:		Execution context
> + * @pif:	Interface the datagram is arriving from
> + * @port:	Our (local) port number to which the datagram is arriving
>   * @ref:	epoll reference of the receiving socket

@ref went away. Fixed on merge.

>   * @s_in:	Source socket address, filled in by recvmmsg()
>   * @now:	Timestamp
> @@ -171,7 +173,7 @@ cancel:
>   * Return: sidx for the destination side of the flow for this packet, or
>   *         FLOW_SIDX_NONE if we couldn't find or create a flow.
>   */
> -flow_sidx_t udp_flow_from_sock(const struct ctx *c, union epoll_ref ref,
> +flow_sidx_t udp_flow_from_sock(const struct ctx *c, uint8_t pif, in_port_t port,
>  			       const union sockaddr_inany *s_in,
>  			       const struct timespec *now)
>  {
> @@ -180,9 +182,7 @@ flow_sidx_t udp_flow_from_sock(const struct ctx *c, union epoll_ref ref,
>  	union flow *flow;
>  	flow_sidx_t sidx;
>  
> -	ASSERT(ref.type == EPOLL_TYPE_UDP_LISTEN);
> -
> -	sidx = flow_lookup_sa(c, IPPROTO_UDP, ref.udp.pif, s_in, ref.udp.port);
> +	sidx = flow_lookup_sa(c, IPPROTO_UDP, pif, s_in, port);
>  	if ((uflow = udp_at_sidx(sidx))) {
>  		uflow->ts = now->tv_sec;
>  		return flow_sidx_opposite(sidx);
> @@ -192,12 +192,11 @@ flow_sidx_t udp_flow_from_sock(const struct ctx *c, union epoll_ref ref,
>  		char sastr[SOCKADDR_STRLEN];
>  
>  		debug("Couldn't allocate flow for UDP datagram from %s %s",
> -		      pif_name(ref.udp.pif),
> -		      sockaddr_ntop(s_in, sastr, sizeof(sastr)));
> +		      pif_name(pif), sockaddr_ntop(s_in, sastr, sizeof(sastr)));
>  		return FLOW_SIDX_NONE;
>  	}
>  
> -	ini = flow_initiate_sa(flow, ref.udp.pif, s_in, ref.udp.port);
> +	ini = flow_initiate_sa(flow, pif, s_in, port);
>  
>  	if (!inany_is_unicast(&ini->eaddr) ||
>  	    ini->eport == 0 || ini->oport == 0) {
> diff --git a/udp_flow.h b/udp_flow.h
> index 9a1b059c..d4e4c8b9 100644
> --- a/udp_flow.h
> +++ b/udp_flow.h
> @@ -24,7 +24,7 @@ struct udp_flow {
>  };
>  
>  struct udp_flow *udp_at_sidx(flow_sidx_t sidx);
> -flow_sidx_t udp_flow_from_sock(const struct ctx *c, union epoll_ref ref,
> +flow_sidx_t udp_flow_from_sock(const struct ctx *c, uint8_t pif, in_port_t port,
>  			       const union sockaddr_inany *s_in,
>  			       const struct timespec *now);
>  flow_sidx_t udp_flow_from_tap(const struct ctx *c,

-- 
Stefano


  reply	other threads:[~2025-04-07 21:49 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-04 10:15 [PATCH 00/12] Use connect()ed sockets for both sides of UDP flows David Gibson
2025-04-04 10:15 ` [PATCH 01/12] udp: Use connect()ed sockets for initiating side David Gibson
2025-04-04 10:15 ` [PATCH 02/12] udp: Make udp_sock_recv() take max number of frames as a parameter David Gibson
2025-04-07 21:49   ` Stefano Brivio
2025-04-04 10:15 ` [PATCH 03/12] udp: Polish udp_vu_sock_info() and remove from vu specific code David Gibson
2025-04-07 21:49   ` Stefano Brivio
2025-04-04 10:15 ` [PATCH 04/12] udp: Don't bother to batch datagrams from "listening" socket David Gibson
2025-04-04 10:15 ` [PATCH 05/12] udp: Parameterize number of datagrams handled by udp_*_reply_sock_data() David Gibson
2025-04-04 10:15 ` [PATCH 06/12] udp: Split spliced forwarding path from udp_buf_reply_sock_data() David Gibson
2025-04-07 21:49   ` Stefano Brivio
2025-04-04 10:15 ` [PATCH 07/12] udp: Merge vhost-user and "buf" listening socket paths David Gibson
2025-04-04 10:15 ` [PATCH 08/12] udp: Move UDP_MAX_FRAMES to udp.c David Gibson
2025-04-04 10:15 ` [PATCH 09/12] udp_flow: Take pif and port as explicit parameters to udp_flow_from_sock() David Gibson
2025-04-07 21:49   ` Stefano Brivio [this message]
2025-04-04 10:15 ` [PATCH 10/12] udp: Rework udp_listen_sock_data() into udp_sock_fwd() David Gibson
2025-04-04 10:15 ` [PATCH 11/12] udp: Fold udp_splice_prepare and udp_splice_send into udp_sock_to_sock David Gibson
2025-04-07 21:49   ` Stefano Brivio
2025-04-04 10:15 ` [PATCH 12/12] udp_flow: Don't discard packets that arrive between bind() and connect() David Gibson
2025-04-07 21:49   ` Stefano Brivio
2025-04-07 21:49 ` [PATCH 00/12] Use connect()ed sockets for both sides of UDP flows Stefano Brivio
2025-04-07 23:50   ` David Gibson

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=20250407234927.767cca47@elisabeth \
    --to=sbrivio@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --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).