public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Ammar Yasser <aerosound161@gmail.com>
To: passt-dev@passt.top
Cc: eperezma@redhat.com, Ammar Yasser <aerosound161@gmail.com>
Subject: [RFC v3 2/8] udp,tcp: Make protocol specific buffers public
Date: Sun,  2 Aug 2026 13:21:49 +0000	[thread overview]
Message-ID: <20260802132155.870796-3-aerosound161@gmail.com> (raw)
In-Reply-To: <20260802132155.870796-1-aerosound161@gmail.com>

Move the buffers used to split tcp and udp packets coming from the host
from being static definitions in tcp_buf.c and udp.c to structs exported
through extern on the their respective header files.

Also move the udp_meta_t definition to the public udp.h file instead of
it living in udp_internal.h

Signed-off-by: Ammar Yasser <aerosound161@gmail.com>
---
 tcp_buf.c      | 14 +++++---------
 tcp_buf.h      | 16 +++++++++++++++-
 udp.c          | 40 ++++++++++++----------------------------
 udp.h          | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 udp_internal.h | 13 -------------
 5 files changed, 81 insertions(+), 51 deletions(-)

diff --git a/tcp_buf.c b/tcp_buf.c
index 72c4541..4452337 100644
--- a/tcp_buf.c
+++ b/tcp_buf.c
@@ -33,23 +33,19 @@
 #include "tcp_internal.h"
 #include "tcp_buf.h"
 
-#define TCP_FRAMES_MEM			128
-#define TCP_FRAMES							   \
-	(c->mode == MODE_PASTA ? 1 : TCP_FRAMES_MEM)
-
 /* Static buffers */
 
 /* Ethernet header for IPv4 and IPv6 frames */
-static struct ethhdr		tcp_eth_hdr[TCP_FRAMES_MEM];
+struct ethhdr		tcp_eth_hdr[TCP_FRAMES_MEM];
 
-static struct tap_hdr		tcp_payload_tap_hdr[TCP_FRAMES_MEM];
+struct tap_hdr tcp_payload_tap_hdr[TCP_FRAMES_MEM];
 
 /* IP headers for IPv4 and IPv6 */
-static struct iphdr		tcp4_payload_ip[TCP_FRAMES_MEM];
-static struct ipv6hdr		tcp6_payload_ip[TCP_FRAMES_MEM];
+struct iphdr		tcp4_payload_ip[TCP_FRAMES_MEM];
+struct ipv6hdr		tcp6_payload_ip[TCP_FRAMES_MEM];
 
 /* TCP segments with payload for IPv4 and IPv6 frames */
-static struct tcp_payload_t	tcp_payload[TCP_FRAMES_MEM];
+struct tcp_payload_t	tcp_payload[TCP_FRAMES_MEM];
 
 static_assert(MSS4 <= sizeof(tcp_payload[0].data), "MSS4 is greater than 65516");
 static_assert(MSS6 <= sizeof(tcp_payload[0].data), "MSS6 is greater than 65516");
diff --git a/tcp_buf.h b/tcp_buf.h
index 5d31cea..c749038 100644
--- a/tcp_buf.h
+++ b/tcp_buf.h
@@ -6,11 +6,25 @@
 #ifndef TCP_BUF_H
 #define TCP_BUF_H
 
-void tcp_sock_iov_init(const struct ctx *c);
+#include "tcp_conn.h"
+#include "tcp_internal.h"
+
+void tcp_sock_iov_init();
 void tcp_payload_flush(const struct ctx *c, const struct timespec *now);
 int tcp_buf_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn,
 			   uint32_t already_sent, const struct timespec *now);
 int tcp_buf_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags,
 		      const struct timespec *now);
 
+#define TCP_FRAMES_MEM			128
+#define TCP_FRAMES							   \
+(c->mode == MODE_PASTA ? 1 : TCP_FRAMES_MEM)
+
+extern struct tap_hdr tcp_payload_tap_hdr[TCP_FRAMES_MEM];
+extern struct ethhdr		tcp_eth_hdr[TCP_FRAMES_MEM];
+extern struct tcp_payload_t	tcp_payload[TCP_FRAMES_MEM];
+
+extern struct iphdr		tcp4_payload_ip[TCP_FRAMES_MEM];
+extern struct ipv6hdr		tcp6_payload_ip[TCP_FRAMES_MEM];
+
 #endif  /*TCP_BUF_H */
diff --git a/udp.c b/udp.c
index 505e554..d05ee66 100644
--- a/udp.c
+++ b/udp.c
@@ -119,7 +119,6 @@
 #include "udp_vu.h"
 #include "epoll_ctl.h"
 
-#define UDP_MAX_FRAMES		32  /* max # of frames to receive at once */
 
 #define UDP_TIMEOUT	"/proc/sys/net/netfilter/nf_conntrack_udp_timeout"
 #define UDP_TIMEOUT_STREAM	\
@@ -134,30 +133,6 @@
 			- sizeof(struct udphdr)	\
 			- sizeof(struct ipv6hdr))
 
-/* Static buffers */
-
-/* UDP header and data for inbound messages */
-static struct udp_payload_t udp_payload[UDP_MAX_FRAMES];
-
-/* Ethernet headers for IPv4 and IPv6 frames */
-static struct ethhdr udp_eth_hdr[UDP_MAX_FRAMES];
-
-/**
- * struct udp_meta_t - Pre-cooked headers for UDP packets
- * @ip6h:	Pre-filled IPv6 header (except for payload_len and addresses)
- * @ip4h:	Pre-filled IPv4 header (except for tot_len and saddr)
- * @taph:	Tap backend specific header
- */
-static struct udp_meta_t {
-	struct ipv6hdr ip6h;
-	struct iphdr ip4h;
-	struct tap_hdr taph;
-}
-#ifdef __AVX2__
-__attribute__ ((aligned(32)))
-#endif
-udp_meta[UDP_MAX_FRAMES];
-
 #define PKTINFO_SPACE					\
 	MAX(CMSG_SPACE(sizeof(struct in_pktinfo)),	\
 	    CMSG_SPACE(sizeof(struct in6_pktinfo)))
@@ -186,9 +161,6 @@ enum udp_iov_idx {
 	UDP_NUM_IOVS,
 };
 
-/* IOVs and msghdr arrays for receiving datagrams from sockets */
-static struct iovec	udp_iov_recv		[UDP_MAX_FRAMES];
-static struct mmsghdr	udp_mh_recv		[UDP_MAX_FRAMES];
 
 /* IOVs and msghdr arrays for sending "spliced" datagrams to sockets */
 static union sockaddr_inany udp_splice_to;
@@ -199,6 +171,18 @@ static struct mmsghdr	udp_mh_splice		[UDP_MAX_FRAMES];
 /* IOVs for L2 frames */
 static struct iovec	udp_l2_iov		[UDP_MAX_FRAMES][UDP_NUM_IOVS];
 
+struct udp_payload_t udp_payload[UDP_MAX_FRAMES];
+
+/* Ethernet headers for IPv4 and IPv6 frames */
+struct ethhdr udp_eth_hdr[UDP_MAX_FRAMES];
+
+/* IOVs and msghdr arrays for receiving datagrams from sockets */
+struct iovec  udp_iov_recv            [UDP_MAX_FRAMES];
+struct mmsghdr        udp_mh_recv             [UDP_MAX_FRAMES];
+
+/* Pre-cooked headers for UDP packets */
+struct udp_meta_t udp_meta[UDP_MAX_FRAMES];
+
 /**
  * udp_update_l2_buf() - Update L2 buffers with Ethernet and IPv4 addresses
  * @eth_d:	Ethernet destination address, NULL if unchanged
diff --git a/udp.h b/udp.h
index b50283e..b7a367c 100644
--- a/udp.h
+++ b/udp.h
@@ -8,9 +8,58 @@
 
 #include <stdint.h>
 #include <netinet/in.h>
+#include <netinet/udp.h>
 
+#include "tap_hdr.h"
 #include "fwd.h"
 
+/**
+ * struct udp_payload_t - UDP header and data for inbound messages
+ * @uh:		UDP header
+ * @data:	UDP data
+ */
+struct udp_payload_t {
+	struct udphdr uh;
+	char data[USHRT_MAX - sizeof(struct udphdr)];
+#ifdef __AVX2__
+} __attribute__ ((packed, aligned(32)));
+#else
+} __attribute__ ((packed, aligned(__alignof__(unsigned int))));
+#endif
+
+#define UDP_MAX_FRAMES		32  /* max # of frames to receive at once */
+
+/* UDP header and data for inbound messages */
+extern struct udp_payload_t udp_payload[UDP_MAX_FRAMES];
+
+/* Ethernet headers for IPv4 and IPv6 frames */
+extern struct ethhdr udp_eth_hdr[UDP_MAX_FRAMES];
+
+/* IOVs and msghdr arrays for receiving datagrams from sockets */
+extern struct iovec	udp_iov_recv		[UDP_MAX_FRAMES];
+extern struct mmsghdr	udp_mh_recv		[UDP_MAX_FRAMES];
+
+
+/**
+ * struct udp_meta_t - Pre-cooked headers for UDP packets
+ * @ip6h:	Pre-filled IPv6 header (except for payload_len and addresses)
+ * @ip4h:	Pre-filled IPv4 header (except for tot_len and saddr)
+ * @taph:	Tap backend specific header
+ */
+struct udp_meta_t {
+	struct ipv6hdr ip6h;
+	struct iphdr ip4h;
+	struct tap_hdr taph;
+#ifdef __AVX2__
+} __attribute__((aligned(32)));
+#else
+};
+#endif
+
+/* Pre-cooked headers for UDP packets */
+extern struct udp_meta_t udp_meta[UDP_MAX_FRAMES];
+
+
 void udp_listen_sock_handler(const struct ctx *c, union epoll_ref ref,
 			     uint32_t events, const struct timespec *now);
 void udp_sock_handler(const struct ctx *c, union epoll_ref ref,
diff --git a/udp_internal.h b/udp_internal.h
index 361cc74..6804843 100644
--- a/udp_internal.h
+++ b/udp_internal.h
@@ -11,19 +11,6 @@
 
 #include "tap.h" /* needed by udp_meta_t */
 
-/**
- * struct udp_payload_t - UDP header and data for inbound messages
- * @uh:		UDP header
- * @data:	UDP data
- */
-struct udp_payload_t {
-	struct udphdr uh;
-	char data[USHRT_MAX - sizeof(struct udphdr)];
-#ifdef __AVX2__
-} __attribute__ ((packed, aligned(32)));
-#else
-} __attribute__ ((packed, aligned(__alignof__(unsigned int))));
-#endif
 
 size_t udp_update_hdr4(struct iphdr *ip4h, struct udphdr *uh,
 		       struct iov_tail *payload,
-- 
2.34.1


  parent reply	other threads:[~2026-08-02 13:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-02 13:21 [RFC v3 0/8] Add vhost-net kernel support to pasta Ammar Yasser
2026-08-02 13:21 ` [RFC v3 1/8] tap: Move the tap_hdr file to a separate file Ammar Yasser
2026-08-02 13:21 ` Ammar Yasser [this message]
2026-08-02 13:21 ` [RFC v3 3/8] conf: Add context fields, epoll types and the --vhost flag to pasta Ammar Yasser
2026-08-02 13:21 ` [RFC v3 4/8] virtio: Define the pasta vhost interface Ammar Yasser
2026-08-02 13:21 ` [RFC v3 5/8] virtio: Implement the pasta vhost functions Ammar Yasser
2026-08-02 13:21 ` [RFC v3 6/8] virtio: Implement pasta vhost acceleration guest->pasta path Ammar Yasser
2026-08-02 13:21 ` [RFC v3 7/8] pasta: Implement pasta vhost TX (pasta->guest) prerequisites Ammar Yasser
2026-08-02 13:21 ` [RFC v3 8/8] tap: Implement pasta vhost TX Ammar Yasser

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=20260802132155.870796-3-aerosound161@gmail.com \
    --to=aerosound161@gmail.com \
    --cc=eperezma@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).