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 11/12] udp: Fold udp_splice_prepare and udp_splice_send into udp_sock_to_sock
Date: Mon, 7 Apr 2025 23:49:31 +0200	[thread overview]
Message-ID: <20250407234931.2cca7fae@elisabeth> (raw)
In-Reply-To: <20250404101542.3729316-12-david@gibson.dropbear.id.au>

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

> udp_splice() prepare and udp_splice_send() are both quite simple functions
> that now have only one caller: udp_sock_to_sock().  Fold them both into
> that caller.
> 
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> ---
>  udp.c | 53 +++++++++++++----------------------------------------
>  1 file changed, 13 insertions(+), 40 deletions(-)
> 
> diff --git a/udp.c b/udp.c
> index 22e74b48..7c8b7a2c 100644
> --- a/udp.c
> +++ b/udp.c
> @@ -250,43 +250,6 @@ static void udp_iov_init(const struct ctx *c)
>  		udp_iov_init_one(c, i);
>  }
>  
> -/**
> - * udp_splice_prepare() - Prepare one datagram for splicing
> - * @mmh:	Receiving mmsghdr array
> - * @idx:	Index of the datagram to prepare
> - */
> -static void udp_splice_prepare(struct mmsghdr *mmh, unsigned idx)
> -{
> -	udp_mh_splice[idx].msg_hdr.msg_iov->iov_len = mmh[idx].msg_len;
> -}
> -
> -/**
> - * udp_splice_send() - Send a batch of datagrams from socket to socket
> - * @c:		Execution context
> - * @start:	Index of batch's first datagram in udp[46]_l2_buf
> - * @n:		Number of datagrams in batch
> - * @src:	Source port for datagram (target side)
> - * @dst:	Destination port for datagrams (target side)
> - * @ref:	epoll reference for origin socket
> - * @now:	Timestamp
> - *
> - * #syscalls sendmmsg

In theory this should have been moved to udp_sock_to_sock(), even though
we already enable sendmmsg() in the comment of udp_tap_handler(), so
this is not strictly needed, but... added back on merge.

> - */
> -static void udp_splice_send(const struct ctx *c, size_t start, size_t n,
> -			    flow_sidx_t tosidx)
> -{
> -	const struct flowside *toside = flowside_at_sidx(tosidx);
> -	const struct udp_flow *uflow = udp_at_sidx(tosidx);
> -	uint8_t topif = pif_at_sidx(tosidx);
> -	int s = uflow->s[tosidx.sidei];
> -	socklen_t sl;
> -
> -	pif_sockaddr(c, &udp_splice_to, &sl, topif,
> -		     &toside->eaddr, toside->eport);
> -
> -	sendmmsg(s, udp_mh_splice + start, n, MSG_NOSIGNAL);
> -}
> -
>  /**
>   * udp_update_hdr4() - Update headers for one IPv4 datagram
>   * @ip4h:		Pre-filled IPv4 header (except for tot_len and saddr)
> @@ -683,15 +646,25 @@ static int udp_sock_recv(const struct ctx *c, int s, struct mmsghdr *mmh, int n)
>  static void udp_sock_to_sock(const struct ctx *c, int from_s, int n,
>  			     flow_sidx_t tosidx)
>  {
> +	const struct flowside *toside = flowside_at_sidx(tosidx);
> +	const struct udp_flow *uflow = udp_at_sidx(tosidx);
> +	uint8_t topif = pif_at_sidx(tosidx);
> +	int to_s = uflow->s[tosidx.sidei];
> +	socklen_t sl;
>  	int i;
>  
>  	if ((n = udp_sock_recv(c, from_s, udp_mh_recv, n)) <= 0)
>  		return;
>  
> -	for (i = 0; i < n; i++)
> -		udp_splice_prepare(udp_mh_recv, i);
> +	for (i = 0; i < n; i++) {
> +		udp_mh_splice[i].msg_hdr.msg_iov->iov_len
> +			= udp_mh_recv[i].msg_len;
> +	}
> +
> +	pif_sockaddr(c, &udp_splice_to, &sl, topif,
> +		     &toside->eaddr, toside->eport);
>  
> -	udp_splice_send(c, 0, n, tosidx);
> +	sendmmsg(to_s, udp_mh_splice, n, MSG_NOSIGNAL);
>  }
>  
>  /**

-- 
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
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 [this message]
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=20250407234931.2cca7fae@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).