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
---
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
#include
+#include
+#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