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 38D4D5A028E for ; Thu, 17 Nov 2022 06:59:22 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4NCTkl53kXz4xyT; Thu, 17 Nov 2022 16:59:11 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1668664751; bh=rGiLb7gRpwdpRwYn+0fJWP6ExZOenISel3lPG/3nKUM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fpgNkBqQkEoCAPIcUxItlrvTYSwTOy/JWEt8fSet1aZ260Tqk8sAIIE3z7d4w+n74 0xqUYvFr3SeuPXfg9O4PrOTbjul0Tebq0XfzgbxS4Q4SznA64Wwyt2cuzDRhdIDnw8 GPgYGBZXBCUq5WcDWFAjhls6lzT3pKuDymKPZqLY= From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v2 28/32] tcp_splice: Allow splicing of connections from IPv4-mapped loopback Date: Thu, 17 Nov 2022 16:59:04 +1100 Message-Id: <20221117055908.2782981-29-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221117055908.2782981-1-david@gibson.dropbear.id.au> References: <20221117055908.2782981-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 2QJ2J2DOXIDXXSKTLNCG2GLLZQAFKTCA X-Message-ID-Hash: 2QJ2J2DOXIDXXSKTLNCG2GLLZQAFKTCA 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.3 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: For non-spliced connections we now treat IPv4-mapped IPv6 addresses the same as the corresponding IPv4 addresses. However currently we won't splice a connection from ::ffff:127.0.0.1 the way we would one from 127.0.0.1. Correct this so that we can splice connections from IPv4 localhost that have been received on an IPv6 dual stack socket. Signed-off-by: David Gibson --- tcp_splice.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tcp_splice.c b/tcp_splice.c index 1bbd085..e2f0ce1 100644 --- a/tcp_splice.c +++ b/tcp_splice.c @@ -513,20 +513,23 @@ bool tcp_splice_conn_from_sock(struct ctx *c, union epoll_ref ref, struct tcp_splice_conn *conn, int s, const struct sockaddr *sa) { + const struct in_addr *a4; + union inany_addr aany; + in_port_t port; + assert(c->mode == MODE_PASTA); - if (sa->sa_family == AF_INET6) { - const struct sockaddr_in6 *sa6; + inany_from_sockaddr(&aany, &port, sa); + a4 = inany_v4(&aany); - sa6 = (const struct sockaddr_in6 *)sa; - if (!IN6_IS_ADDR_LOOPBACK(&sa6->sin6_addr)) + if (a4) { + if (!IN4_IS_ADDR_LOOPBACK(a4)) return false; - conn->flags = SPLICE_V6; + conn->flags = 0; } else { - const struct sockaddr_in *sa4 = (const struct sockaddr_in *)sa; - if (!IN4_IS_ADDR_LOOPBACK(&sa4->sin_addr)) + if (!IN6_IS_ADDR_LOOPBACK(&aany.a6)) return false; - conn->flags = 0; + conn->flags = SPLICE_V6; } if (setsockopt(s, SOL_TCP, TCP_QUICKACK, &((int){ 1 }), sizeof(int))) -- 2.38.1