aboutgitcodebugslistschat
path: root/tcp_splice.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2024-02-28 22:25:13 +1100
committerStefano Brivio <sbrivio@redhat.com>2024-02-29 09:48:09 +0100
commitf0e2a6b8c984f7633f38d4ab2e46666c6d969962 (patch)
tree7793516da6d46d9c2265c8796104b9d192d862e9 /tcp_splice.c
parentf4e5d73684d6e92eeadfe2a84d92a06d20312a76 (diff)
downloadpasst-f0e2a6b8c984f7633f38d4ab2e46666c6d969962.tar
passt-f0e2a6b8c984f7633f38d4ab2e46666c6d969962.tar.gz
passt-f0e2a6b8c984f7633f38d4ab2e46666c6d969962.tar.bz2
passt-f0e2a6b8c984f7633f38d4ab2e46666c6d969962.tar.lz
passt-f0e2a6b8c984f7633f38d4ab2e46666c6d969962.tar.xz
passt-f0e2a6b8c984f7633f38d4ab2e46666c6d969962.tar.zst
passt-f0e2a6b8c984f7633f38d4ab2e46666c6d969962.zip
tcp_splice: Make tcp_splice_connect() create its own sockets
Currently creating the connected socket for a splice is split between tcp_splice_conn_from_sock(), which opens the socket, and tcp_splice_connect() which connects it. Alter tcp_splice_connect() to open its own socket based on an address family and pif we pass it. This does require a second conditional on pif, but makes for a more logical split of functionality: tcp_splice_conn_from_sock() picks the target, tcp_splice_connect() creates the connection. While we're there improve reporting of errors 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.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/tcp_splice.c b/tcp_splice.c
index 269265e..0e5b652 100644
--- a/tcp_splice.c
+++ b/tcp_splice.c
@@ -91,6 +91,7 @@ static const char *tcp_splice_flag_str[] __attribute((__unused__)) = {
/* Forward declaration */
static int tcp_sock_refill_ns(void *arg);
+static int tcp_conn_sock_ns(const struct ctx *c, sa_family_t af);
/**
* tcp_splice_conn_epoll_events() - epoll events masks for given state
@@ -319,13 +320,14 @@ static int tcp_splice_connect_finish(const struct ctx *c,
* tcp_splice_connect() - Create and connect socket for new spliced connection
* @c: Execution context
* @conn: Connection pointer
- * @s: Accepted socket
+ * @af: Address family
+ * @pif: pif on which to create socket
* @port: Destination port, host order
*
* Return: 0 for connect() succeeded or in progress, negative value on error
*/
static int tcp_splice_connect(const struct ctx *c, struct tcp_splice_conn *conn,
- int sock_conn, in_port_t port)
+ sa_family_t af, uint8_t pif, in_port_t port)
{
struct sockaddr_in6 addr6 = {
.sin6_family = AF_INET6,
@@ -340,7 +342,15 @@ static int tcp_splice_connect(const struct ctx *c, struct tcp_splice_conn *conn,
const struct sockaddr *sa;
socklen_t sl;
- conn->s[1] = sock_conn;
+ if (pif == PIF_HOST)
+ conn->s[1] = tcp_conn_sock(c, af);
+ else if (pif == PIF_SPLICE)
+ conn->s[1] = tcp_conn_sock_ns(c, af);
+ else
+ ASSERT(0);
+
+ if (conn->s[1] < 0)
+ return -1;
if (setsockopt(conn->s[1], SOL_TCP, TCP_QUICKACK,
&((int){ 1 }), sizeof(int))) {
@@ -416,7 +426,7 @@ bool tcp_splice_conn_from_sock(const struct ctx *c,
struct tcp_splice_conn *conn;
union inany_addr src;
sa_family_t af;
- int s1;
+ uint8_t pif1;
ASSERT(c->mode == MODE_PASTA);
@@ -438,23 +448,16 @@ bool tcp_splice_conn_from_sock(const struct ctx *c,
flow_trace(conn, "failed to set TCP_QUICKACK on %i", s0);
if (ref.pif == PIF_SPLICE) {
+ pif1 = PIF_HOST;
dstport += c->tcp.fwd_out.delta[dstport];
-
- s1 = tcp_conn_sock(c, af);
} else {
ASSERT(ref.pif == PIF_HOST);
+ pif1 = PIF_SPLICE;
dstport += c->tcp.fwd_in.delta[dstport];
-
- s1 = tcp_conn_sock_ns(c, af);
- }
-
- if (s1 < 0) {
- conn_flag(c, conn, CLOSING);
- return true;
}
- if (tcp_splice_connect(c, conn, s1, dstport))
+ if (tcp_splice_connect(c, conn, af, pif1, dstport))
conn_flag(c, conn, CLOSING);
return true;