aboutgitcodebugslistschat
path: root/tcp.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2022-11-17 16:58:53 +1100
committerStefano Brivio <sbrivio@redhat.com>2022-11-25 01:35:25 +0100
commit233b95e90f8e9391d93d2187f682eaf51b6f3dd1 (patch)
tree85d80d8cf394f7f905b7354cd29a2eb24ef1523c /tcp.c
parentd909fda1e81979da12ed4ab8b2f2a18fba756a07 (diff)
downloadpasst-233b95e90f8e9391d93d2187f682eaf51b6f3dd1.tar
passt-233b95e90f8e9391d93d2187f682eaf51b6f3dd1.tar.gz
passt-233b95e90f8e9391d93d2187f682eaf51b6f3dd1.tar.bz2
passt-233b95e90f8e9391d93d2187f682eaf51b6f3dd1.tar.lz
passt-233b95e90f8e9391d93d2187f682eaf51b6f3dd1.tar.xz
passt-233b95e90f8e9391d93d2187f682eaf51b6f3dd1.tar.zst
passt-233b95e90f8e9391d93d2187f682eaf51b6f3dd1.zip
tcp: Remove splice from tcp_epoll_ref
Currently the epoll reference for tcp sockets includes a bit indicating whether the socket maps to a spliced connection. However, the reference also has the index of the connection structure which also indicates whether it is spliced. We can therefore avoid the splice bit in the epoll_ref by unifying the first part of the non-spliced and spliced handlers where we look up the connection state. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'tcp.c')
-rw-r--r--tcp.c60
1 files changed, 34 insertions, 26 deletions
diff --git a/tcp.c b/tcp.c
index 7df3c09..b11ce6e 100644
--- a/tcp.c
+++ b/tcp.c
@@ -2851,7 +2851,6 @@ static void tcp_conn_from_sock(struct ctx *c, union epoll_ref ref,
int s;
assert(ref.r.p.tcp.tcp.listen);
- assert(!ref.r.p.tcp.tcp.splice);
if (c->tcp.conn_count >= TCP_MAX_CONNS)
return;
@@ -2940,35 +2939,14 @@ static void tcp_timer_handler(struct ctx *c, union epoll_ref ref)
}
/**
- * tcp_sock_handler() - Handle new data from socket, or timerfd event
+ * tcp_tap_sock_handler() - Handle new data from non-spliced socket
* @c: Execution context
- * @ref: epoll reference
+ * @conn: Connection state
* @events: epoll events bitmap
- * @now: Current timestamp
*/
-void tcp_sock_handler(struct ctx *c, union epoll_ref ref, uint32_t events,
- const struct timespec *now)
+static void tcp_tap_sock_handler(struct ctx *c, struct tcp_tap_conn *conn,
+ uint32_t events)
{
- struct tcp_tap_conn *conn;
-
- if (ref.r.p.tcp.tcp.timer) {
- tcp_timer_handler(c, ref);
- return;
- }
-
- if (ref.r.p.tcp.tcp.listen) {
- tcp_conn_from_sock(c, ref, now);
- return;
- }
-
- if (ref.r.p.tcp.tcp.splice) {
- tcp_sock_handler_splice(c, ref, events);
- return;
- }
-
- if (!(conn = conn_at_idx(ref.r.p.tcp.tcp.index)))
- return;
-
if (conn->events == CLOSED)
return;
@@ -3016,6 +2994,36 @@ void tcp_sock_handler(struct ctx *c, union epoll_ref ref, uint32_t events,
}
/**
+ * tcp_sock_handler() - Handle new data from socket, or timerfd event
+ * @c: Execution context
+ * @ref: epoll reference
+ * @events: epoll events bitmap
+ * @now: Current timestamp
+ */
+void tcp_sock_handler(struct ctx *c, union epoll_ref ref, uint32_t events,
+ const struct timespec *now)
+{
+ union tcp_conn *conn;
+
+ if (ref.r.p.tcp.tcp.timer) {
+ tcp_timer_handler(c, ref);
+ return;
+ }
+
+ if (ref.r.p.tcp.tcp.listen) {
+ tcp_conn_from_sock(c, ref, now);
+ return;
+ }
+
+ conn = tc + ref.r.p.tcp.tcp.index;
+
+ if (conn->c.spliced)
+ tcp_splice_sock_handler(c, &conn->splice, ref.r.s, events);
+ else
+ tcp_tap_sock_handler(c, &conn->tap, events);
+}
+
+/**
* tcp_sock_init4() - Initialise listening sockets for a given IPv4 port
* @c: Execution context
* @addr: Pointer to address for binding, NULL if not configured