aboutgitcodebugslistschat
path: root/tcp_splice.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2023-11-07 13:42:49 +1100
committerStefano Brivio <sbrivio@redhat.com>2023-11-07 09:54:19 +0100
commit7486cd13af311a5fd429a69ea5fe04f43cd78b49 (patch)
tree39c37e49e4596b85f450280e946e0bda070909a8 /tcp_splice.c
parent69db3b3b2943ab791786dccc2f35a0284e0a531d (diff)
downloadpasst-7486cd13af311a5fd429a69ea5fe04f43cd78b49.tar
passt-7486cd13af311a5fd429a69ea5fe04f43cd78b49.tar.gz
passt-7486cd13af311a5fd429a69ea5fe04f43cd78b49.tar.bz2
passt-7486cd13af311a5fd429a69ea5fe04f43cd78b49.tar.lz
passt-7486cd13af311a5fd429a69ea5fe04f43cd78b49.tar.xz
passt-7486cd13af311a5fd429a69ea5fe04f43cd78b49.tar.zst
passt-7486cd13af311a5fd429a69ea5fe04f43cd78b49.zip
tcp_splice: Exploit side symmetry in tcp_splice_destroy()
tcp_splice_destroy() has some close-to-duplicated logic handling closing of the socket and pipes for each side of the connection. We can use a loop across the sides to reduce the duplication. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'tcp_splice.c')
-rw-r--r--tcp_splice.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/tcp_splice.c b/tcp_splice.c
index 214bf22..9f84d4f 100644
--- a/tcp_splice.c
+++ b/tcp_splice.c
@@ -258,30 +258,26 @@ void tcp_splice_conn_update(const struct ctx *c, struct tcp_splice_conn *new)
void tcp_splice_destroy(struct ctx *c, union tcp_conn *conn_union)
{
struct tcp_splice_conn *conn = &conn_union->splice;
+ int side;
- if (conn->events & SPLICE_ESTABLISHED) {
- /* Flushing might need to block: don't recycle them. */
- if (conn->pipe[0][0] != -1) {
- close(conn->pipe[0][0]);
- close(conn->pipe[0][1]);
- conn->pipe[0][0] = conn->pipe[0][1] = -1;
+ for (side = 0; side < SIDES; side++) {
+ if (conn->events & SPLICE_ESTABLISHED) {
+ /* Flushing might need to block: don't recycle them. */
+ if (conn->pipe[side][0] != -1) {
+ close(conn->pipe[side][0]);
+ close(conn->pipe[side][1]);
+ conn->pipe[side][0] = conn->pipe[side][1] = -1;
+ }
}
- if (conn->pipe[1][0] != -1) {
- close(conn->pipe[1][0]);
- close(conn->pipe[1][1]);
- conn->pipe[1][0] = conn->pipe[1][1] = -1;
+
+ if (side == 0 || conn->events & SPLICE_CONNECT) {
+ close(conn->s[side]);
+ conn->s[side] = -1;
}
- }
- if (conn->events & SPLICE_CONNECT) {
- close(conn->s[1]);
- conn->s[1] = -1;
+ conn->read[side] = conn->written[side] = 0;
}
- close(conn->s[0]);
- conn->s[0] = -1;
- conn->read[0] = conn->written[0] = conn->read[1] = conn->written[1] = 0;
-
conn->events = SPLICE_CLOSED;
conn->flags = 0;
debug("TCP (spliced): index %li, CLOSED", CONN_IDX(conn));