From e07f539ae0aa3ad623c4e8afcaca26906fd1eb17 Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Fri, 30 Apr 2021 14:52:18 +0200 Subject: udp, passt: Introduce socket packet buffer, avoid getsockname() for UDP This is in preparation for scatter-gather IO on the UDP receive path: save a getsockname() syscall by setting a flag if we get the numbering of all bound sockets in a strict sequence (expected, in practice) and repurpose the tap buffer to be also a socket receive buffer, passing it down to protocol handlers. Signed-off-by: Stefano Brivio --- passt.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'passt.c') diff --git a/passt.c b/passt.c index 765f153..4b0497c 100644 --- a/passt.c +++ b/passt.c @@ -60,6 +60,9 @@ #define TAP_BUF_FILL (TAP_BUF_BYTES - ETH_MAX_MTU - sizeof(uint32_t)) #define TAP_MSGS (TAP_BUF_BYTES / sizeof(struct ethhdr) + 1) +#define PKT_BUF_BYTES MAX(TAP_BUF_BYTES, SOCK_BUF_BYTES) +static char pkt_buf [PKT_BUF_BYTES]; + #define TIMER_INTERVAL MIN(TCP_TIMER_INTERVAL, UDP_TIMER_INTERVAL) /** @@ -530,8 +533,6 @@ static int tap6_handler(struct ctx *c, struct tap_msg *msg, size_t count, return 1; } -static char tap_buf[TAP_BUF_BYTES]; - /** * tap_handler() - Packet handler for tap file descriptor * @c: Execution context @@ -544,7 +545,7 @@ static int tap_handler(struct ctx *c, struct timespec *now) struct tap_msg msg[TAP_MSGS]; int msg_count, same, i; struct ethhdr *eh; - char *p = tap_buf; + char *p = pkt_buf; ssize_t n, rem; while ((n = recv(c->fd_unix, p, TAP_BUF_FILL, MSG_DONTWAIT)) > 0) { @@ -615,7 +616,7 @@ static int tap_handler(struct ctx *c, struct timespec *now) } } - p = tap_buf; + p = pkt_buf; } if (n >= 0 || errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) @@ -660,11 +661,11 @@ static void sock_handler(struct ctx *c, int s, uint32_t events, debug("%s: packet from socket %i", getprotobynumber(proto)->p_name, s); if (proto == IPPROTO_ICMP || proto == IPPROTO_ICMPV6) - icmp_sock_handler(c, s, events, now); + icmp_sock_handler(c, s, events, pkt_buf, now); else if (proto == IPPROTO_TCP) - tcp_sock_handler(c, s, events, now); + tcp_sock_handler( c, s, events, pkt_buf, now); else if (proto == IPPROTO_UDP) - udp_sock_handler(c, s, events, now); + udp_sock_handler( c, s, events, pkt_buf, now); } /** -- cgit v1.2.3