aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2022-11-17 16:59:04 +1100
committerStefano Brivio <sbrivio@redhat.com>2022-11-25 01:35:53 +0100
commit023213facd95d19117308b09db6308684e8c5bbf (patch)
treea4ca5017de90a41b116de33f2ed09455acf8bde0
parentbb6bb5649d382ccb4cce82eb2fbc97c2708f9c0f (diff)
downloadpasst-023213facd95d19117308b09db6308684e8c5bbf.tar
passt-023213facd95d19117308b09db6308684e8c5bbf.tar.gz
passt-023213facd95d19117308b09db6308684e8c5bbf.tar.bz2
passt-023213facd95d19117308b09db6308684e8c5bbf.tar.lz
passt-023213facd95d19117308b09db6308684e8c5bbf.tar.xz
passt-023213facd95d19117308b09db6308684e8c5bbf.tar.zst
passt-023213facd95d19117308b09db6308684e8c5bbf.zip
tcp_splice: Allow splicing of connections from IPv4-mapped loopback
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 <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--tcp_splice.c19
1 files 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)))