From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>, passt-dev@passt.top
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 05/11] udp: Unify udp[46]_mh_splice
Date: Thu, 4 Jul 2024 14:58:29 +1000 [thread overview]
Message-ID: <20240704045835.1149746-6-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20240704045835.1149746-1-david@gibson.dropbear.id.au>
We have separate mmsghdr arrays for splicing IPv4 and IPv6 packets, where
the only difference is that they point to different sockaddr buffers for
the destination address.
Unify these by having the common array point at a sockaddr_inany as the
address. This does mean slightly more work when we're about to splice,
because we need to write the whole socket address, rather than just the
port. However it removes 32 mmsghdr structures and we're going to need
more flexibility constructing that target address for the flow table.
Because future changes might mean that the address isn't always loopback,
change the name of the common address from *_localname to udp_splicename.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
udp.c | 47 ++++++++++++++++++++---------------------------
1 file changed, 20 insertions(+), 27 deletions(-)
diff --git a/udp.c b/udp.c
index 663a2dce..b4ea2b35 100644
--- a/udp.c
+++ b/udp.c
@@ -235,18 +235,10 @@ static struct mmsghdr udp4_mh_recv [UDP_MAX_FRAMES];
static struct mmsghdr udp6_mh_recv [UDP_MAX_FRAMES];
/* IOVs and msghdr arrays for sending "spliced" datagrams to sockets */
-static struct sockaddr_in udp4_spliceto = {
- .sin_family = AF_INET,
- .sin_addr = IN4ADDR_LOOPBACK_INIT,
-};
-static struct sockaddr_in6 udp6_spliceto = {
- .sin6_family = AF_INET6,
- .sin6_addr = IN6ADDR_LOOPBACK_INIT,
-};
+static union sockaddr_inany udp_spliceto;
static struct iovec udp_iov_splice [UDP_MAX_FRAMES];
-static struct mmsghdr udp4_mh_splice [UDP_MAX_FRAMES];
-static struct mmsghdr udp6_mh_splice [UDP_MAX_FRAMES];
+static struct mmsghdr udp_mh_splice [UDP_MAX_FRAMES];
/* IOVs for L2 frames */
static struct iovec udp4_l2_iov [UDP_MAX_FRAMES][UDP_NUM_IOVS];
@@ -523,7 +515,7 @@ static unsigned udp_splice_send(const struct ctx *c, size_t start, size_t n,
const struct timespec *now)
{
in_port_t src = udp_meta[start].splicesrc;
- struct mmsghdr *mmh_recv, *mmh_send;
+ struct mmsghdr *mmh_recv;
unsigned int i = start;
int s;
@@ -532,16 +524,22 @@ static unsigned udp_splice_send(const struct ctx *c, size_t start, size_t n,
if (ref.udp.v6) {
mmh_recv = udp6_mh_recv;
- mmh_send = udp6_mh_splice;
- udp6_spliceto.sin6_port = htons(dst);
+ udp_spliceto.sa6 = (struct sockaddr_in6) {
+ .sin6_family = AF_INET6,
+ .sin6_addr = in6addr_loopback,
+ .sin6_port = htons(dst),
+ };
} else {
mmh_recv = udp4_mh_recv;
- mmh_send = udp4_mh_splice;
- udp4_spliceto.sin_port = htons(dst);
+ udp_spliceto.sa4 = (struct sockaddr_in) {
+ .sin_family = AF_INET,
+ .sin_addr = in4addr_loopback,
+ .sin_port = htons(dst),
+ };
}
do {
- mmh_send[i].msg_hdr.msg_iov->iov_len = mmh_recv[i].msg_len;
+ udp_mh_splice[i].msg_hdr.msg_iov->iov_len = mmh_recv[i].msg_len;
if (++i >= n)
break;
@@ -579,7 +577,7 @@ static unsigned udp_splice_send(const struct ctx *c, size_t start, size_t n,
udp_splice_ns[ref.udp.v6][src].ts = now->tv_sec;
}
- sendmmsg(s, mmh_send + start, i - start, MSG_NOSIGNAL);
+ sendmmsg(s, udp_mh_splice + start, i - start, MSG_NOSIGNAL);
out:
return i - start;
}
@@ -1094,20 +1092,15 @@ static void udp_splice_iov_init(void)
int i;
for (i = 0; i < UDP_MAX_FRAMES; i++) {
- struct msghdr *mh4 = &udp4_mh_splice[i].msg_hdr;
- struct msghdr *mh6 = &udp6_mh_splice[i].msg_hdr;
-
- mh4->msg_name = &udp4_spliceto;
- mh4->msg_namelen = sizeof(udp4_spliceto);
+ struct msghdr *mh = &udp_mh_splice[i].msg_hdr;
- mh6->msg_name = &udp6_spliceto;
- mh6->msg_namelen = sizeof(udp6_spliceto);
+ mh->msg_name = &udp_spliceto;
+ mh->msg_namelen = sizeof(udp_spliceto);
udp_iov_splice[i].iov_base = udp_payload[i].data;
- mh4->msg_iov = &udp_iov_splice[i];
- mh6->msg_iov = &udp_iov_splice[i];
- mh4->msg_iovlen = mh6->msg_iovlen = 1;
+ mh->msg_iov = &udp_iov_splice[i];
+ mh->msg_iovlen = 1;
}
}
--
@@ -235,18 +235,10 @@ static struct mmsghdr udp4_mh_recv [UDP_MAX_FRAMES];
static struct mmsghdr udp6_mh_recv [UDP_MAX_FRAMES];
/* IOVs and msghdr arrays for sending "spliced" datagrams to sockets */
-static struct sockaddr_in udp4_spliceto = {
- .sin_family = AF_INET,
- .sin_addr = IN4ADDR_LOOPBACK_INIT,
-};
-static struct sockaddr_in6 udp6_spliceto = {
- .sin6_family = AF_INET6,
- .sin6_addr = IN6ADDR_LOOPBACK_INIT,
-};
+static union sockaddr_inany udp_spliceto;
static struct iovec udp_iov_splice [UDP_MAX_FRAMES];
-static struct mmsghdr udp4_mh_splice [UDP_MAX_FRAMES];
-static struct mmsghdr udp6_mh_splice [UDP_MAX_FRAMES];
+static struct mmsghdr udp_mh_splice [UDP_MAX_FRAMES];
/* IOVs for L2 frames */
static struct iovec udp4_l2_iov [UDP_MAX_FRAMES][UDP_NUM_IOVS];
@@ -523,7 +515,7 @@ static unsigned udp_splice_send(const struct ctx *c, size_t start, size_t n,
const struct timespec *now)
{
in_port_t src = udp_meta[start].splicesrc;
- struct mmsghdr *mmh_recv, *mmh_send;
+ struct mmsghdr *mmh_recv;
unsigned int i = start;
int s;
@@ -532,16 +524,22 @@ static unsigned udp_splice_send(const struct ctx *c, size_t start, size_t n,
if (ref.udp.v6) {
mmh_recv = udp6_mh_recv;
- mmh_send = udp6_mh_splice;
- udp6_spliceto.sin6_port = htons(dst);
+ udp_spliceto.sa6 = (struct sockaddr_in6) {
+ .sin6_family = AF_INET6,
+ .sin6_addr = in6addr_loopback,
+ .sin6_port = htons(dst),
+ };
} else {
mmh_recv = udp4_mh_recv;
- mmh_send = udp4_mh_splice;
- udp4_spliceto.sin_port = htons(dst);
+ udp_spliceto.sa4 = (struct sockaddr_in) {
+ .sin_family = AF_INET,
+ .sin_addr = in4addr_loopback,
+ .sin_port = htons(dst),
+ };
}
do {
- mmh_send[i].msg_hdr.msg_iov->iov_len = mmh_recv[i].msg_len;
+ udp_mh_splice[i].msg_hdr.msg_iov->iov_len = mmh_recv[i].msg_len;
if (++i >= n)
break;
@@ -579,7 +577,7 @@ static unsigned udp_splice_send(const struct ctx *c, size_t start, size_t n,
udp_splice_ns[ref.udp.v6][src].ts = now->tv_sec;
}
- sendmmsg(s, mmh_send + start, i - start, MSG_NOSIGNAL);
+ sendmmsg(s, udp_mh_splice + start, i - start, MSG_NOSIGNAL);
out:
return i - start;
}
@@ -1094,20 +1092,15 @@ static void udp_splice_iov_init(void)
int i;
for (i = 0; i < UDP_MAX_FRAMES; i++) {
- struct msghdr *mh4 = &udp4_mh_splice[i].msg_hdr;
- struct msghdr *mh6 = &udp6_mh_splice[i].msg_hdr;
-
- mh4->msg_name = &udp4_spliceto;
- mh4->msg_namelen = sizeof(udp4_spliceto);
+ struct msghdr *mh = &udp_mh_splice[i].msg_hdr;
- mh6->msg_name = &udp6_spliceto;
- mh6->msg_namelen = sizeof(udp6_spliceto);
+ mh->msg_name = &udp_spliceto;
+ mh->msg_namelen = sizeof(udp_spliceto);
udp_iov_splice[i].iov_base = udp_payload[i].data;
- mh4->msg_iov = &udp_iov_splice[i];
- mh6->msg_iov = &udp_iov_splice[i];
- mh4->msg_iovlen = mh6->msg_iovlen = 1;
+ mh->msg_iov = &udp_iov_splice[i];
+ mh->msg_iovlen = 1;
}
}
--
2.45.2
next prev parent reply other threads:[~2024-07-04 4:58 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-04 4:58 [PATCH 00/11] Preliminaries for UDP flow support David Gibson
2024-07-04 4:58 ` [PATCH 01/11] util: sock_l4() determine protocol from epoll type rather than the reverse David Gibson
2024-07-04 21:19 ` Stefano Brivio
2024-07-04 23:51 ` David Gibson
2024-07-04 4:58 ` [PATCH 02/11] flow: Add flow_sidx_valid() helper David Gibson
2024-07-04 4:58 ` [PATCH 03/11] udp: Pass full epoll reference through more of sock handler path David Gibson
2024-07-04 21:20 ` Stefano Brivio
2024-07-04 23:54 ` David Gibson
2024-07-04 4:58 ` [PATCH 04/11] udp: Rename IOV and mmsghdr arrays David Gibson
2024-07-04 21:20 ` Stefano Brivio
2024-07-05 0:00 ` David Gibson
2024-07-04 4:58 ` David Gibson [this message]
2024-07-04 4:58 ` [PATCH 06/11] udp: Unify udp[46]_l2_iov David Gibson
2024-07-04 4:58 ` [PATCH 07/11] udp: Don't repeatedly initialise udp[46]_eth_hdr David Gibson
2024-07-04 4:58 ` [PATCH 08/11] udp: Move some more of sock_handler tasks into sub-functions David Gibson
2024-07-04 4:58 ` [PATCH 09/11] udp: Consolidate datagram batching David Gibson
2024-07-05 9:10 ` Stefano Brivio
2024-07-05 9:36 ` David Gibson
2024-07-04 4:58 ` [PATCH 10/11] contrib: Add program to document and test assumptions about SO_REUSEADDR David Gibson
2024-07-04 21:21 ` Stefano Brivio
2024-07-05 0:06 ` David Gibson
2024-07-05 8:33 ` Stefano Brivio
2024-07-05 9:49 ` David Gibson
2024-07-04 4:58 ` [PATCH 11/11] contrib: Test behaviour of zero length datagram recv()s 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=20240704045835.1149746-6-david@gibson.dropbear.id.au \
--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).