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 v3 12/16] udp: Make UDP_SPLICE_FRAMES and UDP_TAP_FRAMES_MEM the same thing
Date: Fri, 25 Nov 2022 18:29:12 +1100 [thread overview]
Message-ID: <20221125072916.3060938-13-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20221125072916.3060938-1-david@gibson.dropbear.id.au>
These two constants have the same value, and there's not a lot of reason
they'd ever need to be different. Future changes will further integrate
the spliced and "tap" paths so that these need to be the same. So, merge
them into UDP_MAX_FRAMES.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
udp.c | 55 +++++++++++++++++++++++++++----------------------------
1 file changed, 27 insertions(+), 28 deletions(-)
diff --git a/udp.c b/udp.c
index 25a37c6..c7e05c8 100644
--- a/udp.c
+++ b/udp.c
@@ -118,9 +118,8 @@
#include "log.h"
#define UDP_CONN_TIMEOUT 180 /* s, timeout for ephemeral or local bind */
-#define UDP_SPLICE_FRAMES 32
-#define UDP_TAP_FRAMES_MEM 32
-#define UDP_TAP_FRAMES (c->mode == MODE_PASST ? UDP_TAP_FRAMES_MEM : 1)
+#define UDP_MAX_FRAMES 32 /* max # of frames to receive at once */
+#define UDP_TAP_FRAMES (c->mode == MODE_PASST ? UDP_MAX_FRAMES : 1)
/**
* struct udp_tap_port - Port tracking based on tap-facing source port
@@ -188,7 +187,7 @@ static struct udp4_l2_buf_t {
uint8_t data[USHRT_MAX -
(sizeof(struct iphdr) + sizeof(struct udphdr))];
} __attribute__ ((packed, aligned(__alignof__(unsigned int))))
-udp4_l2_buf[UDP_TAP_FRAMES_MEM];
+udp4_l2_buf[UDP_MAX_FRAMES];
/**
* udp6_l2_buf_t - Pre-cooked IPv6 packet buffers for tap connections
@@ -218,30 +217,30 @@ struct udp6_l2_buf_t {
#else
} __attribute__ ((packed, aligned(__alignof__(unsigned int))))
#endif
-udp6_l2_buf[UDP_TAP_FRAMES_MEM];
+udp6_l2_buf[UDP_MAX_FRAMES];
static struct sockaddr_storage udp_splice_namebuf;
-static uint8_t udp_splice_buf[UDP_SPLICE_FRAMES][USHRT_MAX];
+static uint8_t udp_splice_buf[UDP_MAX_FRAMES][USHRT_MAX];
/* recvmmsg()/sendmmsg() data for tap */
-static struct iovec udp4_l2_iov_sock [UDP_TAP_FRAMES_MEM];
-static struct iovec udp6_l2_iov_sock [UDP_TAP_FRAMES_MEM];
+static struct iovec udp4_l2_iov_sock [UDP_MAX_FRAMES];
+static struct iovec udp6_l2_iov_sock [UDP_MAX_FRAMES];
-static struct iovec udp4_l2_iov_tap [UDP_TAP_FRAMES_MEM];
-static struct iovec udp6_l2_iov_tap [UDP_TAP_FRAMES_MEM];
+static struct iovec udp4_l2_iov_tap [UDP_MAX_FRAMES];
+static struct iovec udp6_l2_iov_tap [UDP_MAX_FRAMES];
-static struct mmsghdr udp4_l2_mh_sock [UDP_TAP_FRAMES_MEM];
-static struct mmsghdr udp6_l2_mh_sock [UDP_TAP_FRAMES_MEM];
+static struct mmsghdr udp4_l2_mh_sock [UDP_MAX_FRAMES];
+static struct mmsghdr udp6_l2_mh_sock [UDP_MAX_FRAMES];
-static struct mmsghdr udp4_l2_mh_tap [UDP_TAP_FRAMES_MEM];
-static struct mmsghdr udp6_l2_mh_tap [UDP_TAP_FRAMES_MEM];
+static struct mmsghdr udp4_l2_mh_tap [UDP_MAX_FRAMES];
+static struct mmsghdr udp6_l2_mh_tap [UDP_MAX_FRAMES];
/* recvmmsg()/sendmmsg() data for "spliced" connections */
-static struct iovec udp_iov_recv [UDP_SPLICE_FRAMES];
-static struct mmsghdr udp_mmh_recv [UDP_SPLICE_FRAMES];
+static struct iovec udp_iov_recv [UDP_MAX_FRAMES];
+static struct mmsghdr udp_mmh_recv [UDP_MAX_FRAMES];
-static struct iovec udp_iov_sendto [UDP_SPLICE_FRAMES];
-static struct mmsghdr udp_mmh_sendto [UDP_SPLICE_FRAMES];
+static struct iovec udp_iov_sendto [UDP_MAX_FRAMES];
+static struct mmsghdr udp_mmh_sendto [UDP_MAX_FRAMES];
/**
* udp_invert_portmap() - Compute reverse port translations for return packets
@@ -286,7 +285,7 @@ void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s,
{
int i;
- for (i = 0; i < UDP_TAP_FRAMES_MEM; i++) {
+ for (i = 0; i < UDP_MAX_FRAMES; i++) {
struct udp4_l2_buf_t *b4 = &udp4_l2_buf[i];
struct udp6_l2_buf_t *b6 = &udp6_l2_buf[i];
@@ -330,7 +329,7 @@ static void udp_sock4_iov_init(void)
};
}
- for (i = 0, h = udp4_l2_mh_sock; i < UDP_TAP_FRAMES_MEM; i++, h++) {
+ for (i = 0, h = udp4_l2_mh_sock; i < UDP_MAX_FRAMES; i++, h++) {
struct msghdr *mh = &h->msg_hdr;
mh->msg_name = &udp4_l2_buf[i].s_in;
@@ -342,7 +341,7 @@ static void udp_sock4_iov_init(void)
mh->msg_iovlen = 1;
}
- for (i = 0, h = udp4_l2_mh_tap; i < UDP_TAP_FRAMES_MEM; i++, h++) {
+ for (i = 0, h = udp4_l2_mh_tap; i < UDP_MAX_FRAMES; i++, h++) {
struct msghdr *mh = &h->msg_hdr;
udp4_l2_iov_tap[i].iov_base = &udp4_l2_buf[i].vnet_len;
@@ -370,7 +369,7 @@ static void udp_sock6_iov_init(void)
};
}
- for (i = 0, h = udp6_l2_mh_sock; i < UDP_TAP_FRAMES_MEM; i++, h++) {
+ for (i = 0, h = udp6_l2_mh_sock; i < UDP_MAX_FRAMES; i++, h++) {
struct msghdr *mh = &h->msg_hdr;
mh->msg_name = &udp6_l2_buf[i].s_in6;
@@ -382,7 +381,7 @@ static void udp_sock6_iov_init(void)
mh->msg_iovlen = 1;
}
- for (i = 0, h = udp6_l2_mh_tap; i < UDP_TAP_FRAMES_MEM; i++, h++) {
+ for (i = 0, h = udp6_l2_mh_tap; i < UDP_MAX_FRAMES; i++, h++) {
struct msghdr *mh = &h->msg_hdr;
udp6_l2_iov_tap[i].iov_base = &udp6_l2_buf[i].vnet_len;
@@ -516,7 +515,7 @@ static void udp_sock_handler_splice(const struct ctx *c, union epoll_ref ref,
if (!(events & EPOLLIN))
return;
- n = recvmmsg(ref.r.s, udp_mmh_recv, UDP_SPLICE_FRAMES, 0, NULL);
+ n = recvmmsg(ref.r.s, udp_mmh_recv, UDP_MAX_FRAMES, 0, NULL);
if (n <= 0)
return;
@@ -1166,7 +1165,7 @@ static void udp_splice_iov_init(void)
struct iovec *iov;
int i;
- for (i = 0, h = udp_mmh_recv; i < UDP_SPLICE_FRAMES; i++, h++) {
+ for (i = 0, h = udp_mmh_recv; i < UDP_MAX_FRAMES; i++, h++) {
struct msghdr *mh = &h->msg_hdr;
if (!i) {
@@ -1177,12 +1176,12 @@ static void udp_splice_iov_init(void)
mh->msg_iov = &udp_iov_recv[i];
mh->msg_iovlen = 1;
}
- for (i = 0, iov = udp_iov_recv; i < UDP_SPLICE_FRAMES; i++, iov++) {
+ for (i = 0, iov = udp_iov_recv; i < UDP_MAX_FRAMES; i++, iov++) {
iov->iov_base = udp_splice_buf[i];
iov->iov_len = sizeof(udp_splice_buf[i]);
}
- for (i = 0, h = udp_mmh_sendto; i < UDP_SPLICE_FRAMES; i++, h++) {
+ for (i = 0, h = udp_mmh_sendto; i < UDP_MAX_FRAMES; i++, h++) {
struct msghdr *mh = &h->msg_hdr;
mh->msg_name = &udp_splice_namebuf;
@@ -1191,7 +1190,7 @@ static void udp_splice_iov_init(void)
mh->msg_iov = &udp_iov_sendto[i];
mh->msg_iovlen = 1;
}
- for (i = 0, iov = udp_iov_sendto; i < UDP_SPLICE_FRAMES; i++, iov++)
+ for (i = 0, iov = udp_iov_sendto; i < UDP_MAX_FRAMES; i++, iov++)
iov->iov_base = udp_splice_buf[i];
}
--
@@ -118,9 +118,8 @@
#include "log.h"
#define UDP_CONN_TIMEOUT 180 /* s, timeout for ephemeral or local bind */
-#define UDP_SPLICE_FRAMES 32
-#define UDP_TAP_FRAMES_MEM 32
-#define UDP_TAP_FRAMES (c->mode == MODE_PASST ? UDP_TAP_FRAMES_MEM : 1)
+#define UDP_MAX_FRAMES 32 /* max # of frames to receive at once */
+#define UDP_TAP_FRAMES (c->mode == MODE_PASST ? UDP_MAX_FRAMES : 1)
/**
* struct udp_tap_port - Port tracking based on tap-facing source port
@@ -188,7 +187,7 @@ static struct udp4_l2_buf_t {
uint8_t data[USHRT_MAX -
(sizeof(struct iphdr) + sizeof(struct udphdr))];
} __attribute__ ((packed, aligned(__alignof__(unsigned int))))
-udp4_l2_buf[UDP_TAP_FRAMES_MEM];
+udp4_l2_buf[UDP_MAX_FRAMES];
/**
* udp6_l2_buf_t - Pre-cooked IPv6 packet buffers for tap connections
@@ -218,30 +217,30 @@ struct udp6_l2_buf_t {
#else
} __attribute__ ((packed, aligned(__alignof__(unsigned int))))
#endif
-udp6_l2_buf[UDP_TAP_FRAMES_MEM];
+udp6_l2_buf[UDP_MAX_FRAMES];
static struct sockaddr_storage udp_splice_namebuf;
-static uint8_t udp_splice_buf[UDP_SPLICE_FRAMES][USHRT_MAX];
+static uint8_t udp_splice_buf[UDP_MAX_FRAMES][USHRT_MAX];
/* recvmmsg()/sendmmsg() data for tap */
-static struct iovec udp4_l2_iov_sock [UDP_TAP_FRAMES_MEM];
-static struct iovec udp6_l2_iov_sock [UDP_TAP_FRAMES_MEM];
+static struct iovec udp4_l2_iov_sock [UDP_MAX_FRAMES];
+static struct iovec udp6_l2_iov_sock [UDP_MAX_FRAMES];
-static struct iovec udp4_l2_iov_tap [UDP_TAP_FRAMES_MEM];
-static struct iovec udp6_l2_iov_tap [UDP_TAP_FRAMES_MEM];
+static struct iovec udp4_l2_iov_tap [UDP_MAX_FRAMES];
+static struct iovec udp6_l2_iov_tap [UDP_MAX_FRAMES];
-static struct mmsghdr udp4_l2_mh_sock [UDP_TAP_FRAMES_MEM];
-static struct mmsghdr udp6_l2_mh_sock [UDP_TAP_FRAMES_MEM];
+static struct mmsghdr udp4_l2_mh_sock [UDP_MAX_FRAMES];
+static struct mmsghdr udp6_l2_mh_sock [UDP_MAX_FRAMES];
-static struct mmsghdr udp4_l2_mh_tap [UDP_TAP_FRAMES_MEM];
-static struct mmsghdr udp6_l2_mh_tap [UDP_TAP_FRAMES_MEM];
+static struct mmsghdr udp4_l2_mh_tap [UDP_MAX_FRAMES];
+static struct mmsghdr udp6_l2_mh_tap [UDP_MAX_FRAMES];
/* recvmmsg()/sendmmsg() data for "spliced" connections */
-static struct iovec udp_iov_recv [UDP_SPLICE_FRAMES];
-static struct mmsghdr udp_mmh_recv [UDP_SPLICE_FRAMES];
+static struct iovec udp_iov_recv [UDP_MAX_FRAMES];
+static struct mmsghdr udp_mmh_recv [UDP_MAX_FRAMES];
-static struct iovec udp_iov_sendto [UDP_SPLICE_FRAMES];
-static struct mmsghdr udp_mmh_sendto [UDP_SPLICE_FRAMES];
+static struct iovec udp_iov_sendto [UDP_MAX_FRAMES];
+static struct mmsghdr udp_mmh_sendto [UDP_MAX_FRAMES];
/**
* udp_invert_portmap() - Compute reverse port translations for return packets
@@ -286,7 +285,7 @@ void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s,
{
int i;
- for (i = 0; i < UDP_TAP_FRAMES_MEM; i++) {
+ for (i = 0; i < UDP_MAX_FRAMES; i++) {
struct udp4_l2_buf_t *b4 = &udp4_l2_buf[i];
struct udp6_l2_buf_t *b6 = &udp6_l2_buf[i];
@@ -330,7 +329,7 @@ static void udp_sock4_iov_init(void)
};
}
- for (i = 0, h = udp4_l2_mh_sock; i < UDP_TAP_FRAMES_MEM; i++, h++) {
+ for (i = 0, h = udp4_l2_mh_sock; i < UDP_MAX_FRAMES; i++, h++) {
struct msghdr *mh = &h->msg_hdr;
mh->msg_name = &udp4_l2_buf[i].s_in;
@@ -342,7 +341,7 @@ static void udp_sock4_iov_init(void)
mh->msg_iovlen = 1;
}
- for (i = 0, h = udp4_l2_mh_tap; i < UDP_TAP_FRAMES_MEM; i++, h++) {
+ for (i = 0, h = udp4_l2_mh_tap; i < UDP_MAX_FRAMES; i++, h++) {
struct msghdr *mh = &h->msg_hdr;
udp4_l2_iov_tap[i].iov_base = &udp4_l2_buf[i].vnet_len;
@@ -370,7 +369,7 @@ static void udp_sock6_iov_init(void)
};
}
- for (i = 0, h = udp6_l2_mh_sock; i < UDP_TAP_FRAMES_MEM; i++, h++) {
+ for (i = 0, h = udp6_l2_mh_sock; i < UDP_MAX_FRAMES; i++, h++) {
struct msghdr *mh = &h->msg_hdr;
mh->msg_name = &udp6_l2_buf[i].s_in6;
@@ -382,7 +381,7 @@ static void udp_sock6_iov_init(void)
mh->msg_iovlen = 1;
}
- for (i = 0, h = udp6_l2_mh_tap; i < UDP_TAP_FRAMES_MEM; i++, h++) {
+ for (i = 0, h = udp6_l2_mh_tap; i < UDP_MAX_FRAMES; i++, h++) {
struct msghdr *mh = &h->msg_hdr;
udp6_l2_iov_tap[i].iov_base = &udp6_l2_buf[i].vnet_len;
@@ -516,7 +515,7 @@ static void udp_sock_handler_splice(const struct ctx *c, union epoll_ref ref,
if (!(events & EPOLLIN))
return;
- n = recvmmsg(ref.r.s, udp_mmh_recv, UDP_SPLICE_FRAMES, 0, NULL);
+ n = recvmmsg(ref.r.s, udp_mmh_recv, UDP_MAX_FRAMES, 0, NULL);
if (n <= 0)
return;
@@ -1166,7 +1165,7 @@ static void udp_splice_iov_init(void)
struct iovec *iov;
int i;
- for (i = 0, h = udp_mmh_recv; i < UDP_SPLICE_FRAMES; i++, h++) {
+ for (i = 0, h = udp_mmh_recv; i < UDP_MAX_FRAMES; i++, h++) {
struct msghdr *mh = &h->msg_hdr;
if (!i) {
@@ -1177,12 +1176,12 @@ static void udp_splice_iov_init(void)
mh->msg_iov = &udp_iov_recv[i];
mh->msg_iovlen = 1;
}
- for (i = 0, iov = udp_iov_recv; i < UDP_SPLICE_FRAMES; i++, iov++) {
+ for (i = 0, iov = udp_iov_recv; i < UDP_MAX_FRAMES; i++, iov++) {
iov->iov_base = udp_splice_buf[i];
iov->iov_len = sizeof(udp_splice_buf[i]);
}
- for (i = 0, h = udp_mmh_sendto; i < UDP_SPLICE_FRAMES; i++, h++) {
+ for (i = 0, h = udp_mmh_sendto; i < UDP_MAX_FRAMES; i++, h++) {
struct msghdr *mh = &h->msg_hdr;
mh->msg_name = &udp_splice_namebuf;
@@ -1191,7 +1190,7 @@ static void udp_splice_iov_init(void)
mh->msg_iov = &udp_iov_sendto[i];
mh->msg_iovlen = 1;
}
- for (i = 0, iov = udp_iov_sendto; i < UDP_SPLICE_FRAMES; i++, iov++)
+ for (i = 0, iov = udp_iov_sendto; i < UDP_MAX_FRAMES; i++, iov++)
iov->iov_base = udp_splice_buf[i];
}
--
2.38.1
next prev parent reply other threads:[~2022-11-25 7:29 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-25 7:29 [PATCH v3 00/16] Simplify and correct handling of "spliced" UDP forwarding David Gibson
2022-11-25 7:29 ` [PATCH v3 01/16] udp: Also bind() connected ports for "splice" forwarding David Gibson
2022-11-25 7:29 ` [PATCH v3 02/16] udp: Separate tracking of inbound and outbound packet flows David Gibson
2022-11-25 7:29 ` [PATCH v3 03/16] udp: Always use sendto() rather than send() for forwarding spliced packets David Gibson
2022-11-25 7:29 ` [PATCH v3 04/16] udp: Don't connect "forward" sockets for spliced flows David Gibson
2022-11-25 7:29 ` [PATCH v3 05/16] udp: Remove the @bound field from union udp_epoll_ref David Gibson
2022-11-25 7:29 ` [PATCH v3 06/16] udp: Split splice field in udp_epoll_ref into (mostly) independent bits David Gibson
2022-11-25 7:29 ` [PATCH v3 07/16] udp: Don't create double sockets for -U port David Gibson
2022-11-25 7:29 ` [PATCH v3 08/16] udp: Re-use fixed bound sockets for packet forwarding when possible David Gibson
2022-11-25 7:29 ` [PATCH v3 09/16] udp: Don't explicitly track originating socket for spliced "connections" David Gibson
2022-11-25 7:29 ` [PATCH v3 10/16] udp: Update UDP "connection" timestamps in both directions David Gibson
2022-11-25 7:29 ` [PATCH v3 11/16] udp: Simplify udp_sock_handler_splice David Gibson
2022-11-25 7:29 ` David Gibson [this message]
2022-11-25 7:29 ` [PATCH v3 13/16] udp: Add helper to extract port from a sockaddr_in or sockaddr_in6 David Gibson
2022-11-25 7:29 ` [PATCH v3 14/16] udp: Unify buffers for tap and splice paths David Gibson
2022-11-25 7:29 ` [PATCH v3 15/16] udp: Split send half of udp_sock_handler_splice() from the receive half David Gibson
2022-11-25 7:29 ` [PATCH v3 16/16] udp: Correct splice forwarding when receiving from multiple sources David Gibson
2022-11-29 5:59 ` 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=20221125072916.3060938-13-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).