aboutgitcodebugslistschat
path: root/tcp_splice.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2023-11-07 13:42:47 +1100
committerStefano Brivio <sbrivio@redhat.com>2023-11-07 09:54:13 +0100
commit1b762571475476cbbee09f7dc3bce3f1a4c09f49 (patch)
treeaf32b8c644f6b3eb869f530e38521a2b60276e4c /tcp_splice.c
parent8545058fbe7e927f5183ea200b32a849977f0de7 (diff)
downloadpasst-1b762571475476cbbee09f7dc3bce3f1a4c09f49.tar
passt-1b762571475476cbbee09f7dc3bce3f1a4c09f49.tar.gz
passt-1b762571475476cbbee09f7dc3bce3f1a4c09f49.tar.bz2
passt-1b762571475476cbbee09f7dc3bce3f1a4c09f49.tar.lz
passt-1b762571475476cbbee09f7dc3bce3f1a4c09f49.tar.xz
passt-1b762571475476cbbee09f7dc3bce3f1a4c09f49.tar.zst
passt-1b762571475476cbbee09f7dc3bce3f1a4c09f49.zip
tcp_splice: Exploit side symmetry in tcp_splice_timer()
tcp_splice_timer() has two very similar blocks one after another that handle the SO_RCVLOWAT flags for the two sides of the connection. We can deduplicate this with a loop across the two sides. 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.c27
1 files changed, 11 insertions, 16 deletions
diff --git a/tcp_splice.c b/tcp_splice.c
index f405184..cadad32 100644
--- a/tcp_splice.c
+++ b/tcp_splice.c
@@ -835,30 +835,25 @@ void tcp_splice_init(struct ctx *c)
void tcp_splice_timer(struct ctx *c, union tcp_conn *conn_union)
{
struct tcp_splice_conn *conn = &conn_union->splice;
+ int side;
if (conn->flags & CLOSING) {
tcp_splice_destroy(c, conn_union);
return;
}
- if ( (conn->flags & RCVLOWAT_SET_0) &&
- !(conn->flags & RCVLOWAT_ACT_0)) {
- if (setsockopt(conn->s[0], SOL_SOCKET, SO_RCVLOWAT,
- &((int){ 1 }), sizeof(int))) {
- trace("TCP (spliced): can't set SO_RCVLOWAT on "
- "%i", conn->s[0]);
- }
- conn_flag(c, conn, ~RCVLOWAT_SET_0);
- }
+ for (side = 0; side < SIDES; side++) {
+ uint8_t set = side == 0 ? RCVLOWAT_SET_0 : RCVLOWAT_SET_1;
+ uint8_t act = side == 0 ? RCVLOWAT_ACT_0 : RCVLOWAT_ACT_1;
- if ( (conn->flags & RCVLOWAT_SET_1) &&
- !(conn->flags & RCVLOWAT_ACT_1)) {
- if (setsockopt(conn->s[1], SOL_SOCKET, SO_RCVLOWAT,
- &((int){ 1 }), sizeof(int))) {
- trace("TCP (spliced): can't set SO_RCVLOWAT on "
- "%i", conn->s[1]);
+ if ((conn->flags & set) && !(conn->flags & act)) {
+ if (setsockopt(conn->s[side], SOL_SOCKET, SO_RCVLOWAT,
+ &((int){ 1 }), sizeof(int))) {
+ trace("TCP (spliced): can't set SO_RCVLOWAT on "
+ "%i", conn->s[side]);
+ }
+ conn_flag(c, conn, ~set);
}
- conn_flag(c, conn, ~RCVLOWAT_SET_1);
}
conn_flag(c, conn, ~RCVLOWAT_ACT_0);