From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 5FB5F5A0283 for ; Wed, 28 Feb 2024 12:25:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1709119522; bh=n91vLOQgaHPWYcLc/0oyd4/BD1gK4aVZf3R2I9sOwcw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dpafWWvi0gIjBIa0qnUN8q0I95wkApglzM+G9S8wwIGKSO/SimYdrR0nrA4iPyfA6 MpmRnF1PQiVGcaO4Gmt/doukfMCy8kii5aaAwqnh0vbrxHQv8yWgwSxm+Ivc5ugTYq oiXw/h1iLrIbAaY1cIsVTK41K74oI3AHG3LELI/hPuBSIfdExvOiRySmDVnQhGcrJ0 gJvhlLifTpyvUZUzT585oy5+fEt5VItI5NP3Z5DCJaEBC4n4QmZBA5scODiLEoMjUu /lrXY81zhmZuO5XXLvE/VMZWukDlHB4TVAmbzklHhDGe+nb/dDINLCXItmOmYS0Cvl Gw580PVSV2siQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4TlBq65yN6z4wyp; Wed, 28 Feb 2024 22:25:22 +1100 (AEDT) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v3 13/20] tcp_splice: Make tcp_splice_connect() create its own sockets Date: Wed, 28 Feb 2024 22:25:13 +1100 Message-ID: <20240228112520.2078220-14-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228112520.2078220-1-david@gibson.dropbear.id.au> References: <20240228112520.2078220-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: IM3U5QWEWDXQCWLSUMDHRM7L5ZEW3GFU X-Message-ID-Hash: IM3U5QWEWDXQCWLSUMDHRM7L5ZEW3GFU X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- tcp_splice.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/tcp_splice.c b/tcp_splice.c index 269265e8..0e5b6524 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; -- 2.43.2