aboutgitcodebugslistschat
path: root/passt.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2021-04-30 14:52:18 +0200
committerStefano Brivio <sbrivio@redhat.com>2021-04-30 14:52:18 +0200
commite07f539ae0aa3ad623c4e8afcaca26906fd1eb17 (patch)
tree869fc954471b65f6659ca87d9068fd9143e87674 /passt.c
parent605af213c5e0fa047f6d8caef5bcef61a0987c8d (diff)
downloadpasst-e07f539ae0aa3ad623c4e8afcaca26906fd1eb17.tar
passt-e07f539ae0aa3ad623c4e8afcaca26906fd1eb17.tar.gz
passt-e07f539ae0aa3ad623c4e8afcaca26906fd1eb17.tar.bz2
passt-e07f539ae0aa3ad623c4e8afcaca26906fd1eb17.tar.lz
passt-e07f539ae0aa3ad623c4e8afcaca26906fd1eb17.tar.xz
passt-e07f539ae0aa3ad623c4e8afcaca26906fd1eb17.tar.zst
passt-e07f539ae0aa3ad623c4e8afcaca26906fd1eb17.zip
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 <sbrivio@redhat.com>
Diffstat (limited to 'passt.c')
-rw-r--r--passt.c15
1 files changed, 8 insertions, 7 deletions
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);
}
/**