From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id EEB995A0082 for ; Thu, 17 Nov 2022 01:15:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668644115; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hNmyA85VxVVOpvkomoq1DT9TD6r5hBv+q+fJnkbimMU=; b=XN2O/q1RAuIiv+QgKrx4A4WwTVvO29uPBQxrzS6LAXzEKVg9RlW0F2ILeUVJEa9n7ZZLPS afI6zQBDa9j1CGf/ynvR44gypIfaXDF+M8SX2R+bcWt6+PZzIgoCTja+M1ko0mZ/EcsMER rFQu0Db266GLrAEj+RwwEVbW5AgaAvE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-447-1pT-VawBNdmy9ikdQPu6Mg-1; Wed, 16 Nov 2022 19:15:14 -0500 X-MC-Unique: 1pT-VawBNdmy9ikdQPu6Mg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 77C28811E87; Thu, 17 Nov 2022 00:15:14 +0000 (UTC) Received: from maya.cloud.tilaa.com (ovpn-208-8.brq.redhat.com [10.40.208.8]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1035E2027064; Thu, 17 Nov 2022 00:15:13 +0000 (UTC) Date: Thu, 17 Nov 2022 01:15:11 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 26/32] tcp: Remove v6 flag from tcp_epoll_ref Message-ID: <20221117011511.56447333@elisabeth> In-Reply-To: <20221116044212.3876516-27-david@gibson.dropbear.id.au> References: <20221116044212.3876516-1-david@gibson.dropbear.id.au> <20221116044212.3876516-27-david@gibson.dropbear.id.au> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: AG6K2CV3BU4VU5Z4HUY7HYMOOJR7VT7H X-Message-ID-Hash: AG6K2CV3BU4VU5Z4HUY7HYMOOJR7VT7H X-MailFrom: sbrivio@redhat.com 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: passt-dev@passt.top 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: On Wed, 16 Nov 2022 15:42:06 +1100 David Gibson wrote: > This bit in the TCP specific epoll reference indicates whether the > connection is IPv6 or IPv4. However the sites which refer to it are > already calling accept() which (optionally) returns an address for the > remote end of the connection. We can use the sa_family field in that > address to determine the connection type independent of the epoll > reference. > > This does have a cost: for the spliced case, it means we now need to get > that address from accept() which introduces an extran copy_to_user(). > However, in future we want to allow handling IPv4 connectons through IPv6 > sockets, which means we won't be able to determine the IP version at the > time we create the listening socket and epoll reference. So, at some point > we'll have to pay this cost anyway. > > Signed-off-by: David Gibson > --- > tcp.c | 10 ++++------ > tcp.h | 2 -- > tcp_splice.c | 9 ++++----- > 3 files changed, 8 insertions(+), 13 deletions(-) > > diff --git a/tcp.c b/tcp.c > index 0513b3b..b05ed6c 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -662,8 +662,7 @@ static int tcp_epoll_ctl(const struct ctx *c, struct tcp_tap_conn *conn) > { > int m = conn->c.in_epoll ? EPOLL_CTL_MOD : EPOLL_CTL_ADD; > union epoll_ref ref = { .r.proto = IPPROTO_TCP, .r.s = conn->sock, > - .r.p.tcp.tcp.index = CONN_IDX(conn), > - .r.p.tcp.tcp.v6 = CONN_V6(conn) }; > + .r.p.tcp.tcp.index = CONN_IDX(conn) }; > struct epoll_event ev = { .data.u64 = ref.u64 }; > > if (conn->events == CLOSED) { > @@ -2745,7 +2744,7 @@ static void tcp_tap_conn_from_sock(struct ctx *c, union epoll_ref ref, > conn->ws_to_tap = conn->ws_from_tap = 0; > conn_event(c, conn, SOCK_ACCEPTED); > > - if (ref.r.p.tcp.tcp.v6) { > + if (sa->sa_family == AF_INET6) { > struct sockaddr_in6 sa6; > > memcpy(&sa6, sa, sizeof(sa6)); > @@ -3019,8 +3018,7 @@ static void tcp_sock_init6(const struct ctx *c, > in_port_t port) > { > in_port_t idx = port + c->tcp.fwd_in.delta[port]; > - union tcp_epoll_ref tref = { .tcp.listen = 1, .tcp.v6 = 1, > - .tcp.index = idx }; > + union tcp_epoll_ref tref = { .tcp.listen = 1, .tcp.index = idx }; Excess whitespace (from earlier patch). > int s; > > s = sock_l4(c, AF_INET6, IPPROTO_TCP, addr, ifname, port, tref.u32); > @@ -3084,7 +3082,7 @@ static void tcp_ns_sock_init6(const struct ctx *c, in_port_t port) > { > in_port_t idx = port + c->tcp.fwd_out.delta[port]; > union tcp_epoll_ref tref = { .tcp.listen = 1, .tcp.outbound = 1, > - .tcp.v6 = 1, .tcp.index = idx}; > + .tcp.index = idx}; Missing whitespace (from earlier patch). > int s; > > assert(c->mode == MODE_PASTA); > diff --git a/tcp.h b/tcp.h > index a940682..739b451 100644 > --- a/tcp.h > +++ b/tcp.h > @@ -33,7 +33,6 @@ void tcp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s, > * union tcp_epoll_ref - epoll reference portion for TCP connections > * @listen: Set if this file descriptor is a listening socket > * @outbound: Listening socket maps to outbound, spliced connection > - * @v6: Set for IPv6 sockets or connections > * @timer: Reference is a timerfd descriptor for connection > * @index: Index of connection in table, or port for bound sockets > * @u32: Opaque u32 value of reference > @@ -42,7 +41,6 @@ union tcp_epoll_ref { > struct { > uint32_t listen:1, > outbound:1, > - v6:1, > timer:1, > index:20; > } tcp; > diff --git a/tcp_splice.c b/tcp_splice.c > index 30ab0eb..7c2f667 100644 > --- a/tcp_splice.c > +++ b/tcp_splice.c > @@ -167,11 +167,9 @@ static int tcp_splice_epoll_ctl(const struct ctx *c, > { > int m = conn->c.in_epoll ? EPOLL_CTL_MOD : EPOLL_CTL_ADD; > union epoll_ref ref_a = { .r.proto = IPPROTO_TCP, .r.s = conn->a, > - .r.p.tcp.tcp.index = CONN_IDX(conn), > - .r.p.tcp.tcp.v6 = CONN_V6(conn) }; > + .r.p.tcp.tcp.index = CONN_IDX(conn) }; > union epoll_ref ref_b = { .r.proto = IPPROTO_TCP, .r.s = conn->b, > - .r.p.tcp.tcp.index = CONN_IDX(conn), > - .r.p.tcp.tcp.v6 = CONN_V6(conn) }; > + .r.p.tcp.tcp.index = CONN_IDX(conn) }; > struct epoll_event ev_a = { .data.u64 = ref_a.u64 }; > struct epoll_event ev_b = { .data.u64 = ref_b.u64 }; > uint32_t events_a, events_b; > @@ -504,6 +502,7 @@ static void tcp_splice_dir(struct tcp_splice_conn *conn, int ref_sock, > * tcp_splice_conn_from_sock() - Attempt to init state for a spliced connection > * @c: Execution context > * @ref: epoll reference of listening socket > + * @ipv6: Should this be an IPv6 connection? Left-over from previous idea I guess. > * @conn: connection structure to initialize > * @s: Accepted socket > * @sa: Peer address of connection > @@ -517,7 +516,7 @@ bool tcp_splice_conn_from_sock(struct ctx *c, union epoll_ref ref, > { > assert(c->mode == MODE_PASTA); > > - if (ref.r.p.tcp.tcp.v6) { > + if (sa->sa_family == AF_INET6) { > const struct sockaddr_in6 *sa6 > = (const struct sockaddr_in6 *)sa; > if (!IN6_IS_ADDR_LOOPBACK(&sa6->sin6_addr)) -- Stefano