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 0416A5A0270 for ; Thu, 17 Nov 2022 03:08:57 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4NCNcx2l3Xz4xZl; Thu, 17 Nov 2022 13:08:49 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1668650929; bh=ao2mg2gN7k4Z+Igem7qU9aaubMXiqXEPCjapO+xx1no=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=M5iHgeQecK0rug+yvqQL2zXOpSAFWtiR+roes84mMsGon8d8jQcW+WMTZlHe9wpiR qjrmAug7X3Zr3c0PH0XytKL5AQF7jUTFAR8GaOOKzmYUaYlC6D4arzc6b6xMTkaqdn wsPKC1Xu1NQkah2j+V2dHP7XzCuKr77UEbAjlMyQ= Date: Thu, 17 Nov 2022 12:50:10 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 26/32] tcp: Remove v6 flag from tcp_epoll_ref Message-ID: References: <20221116044212.3876516-1-david@gibson.dropbear.id.au> <20221116044212.3876516-27-david@gibson.dropbear.id.au> <20221117011511.56447333@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="Dnw96DVGRXl7HQsi" Content-Disposition: inline In-Reply-To: <20221117011511.56447333@elisabeth> Message-ID-Hash: VFH4C7E3INTHDQ6WM3C5OOLFLV2XZP66 X-Message-ID-Hash: VFH4C7E3INTHDQ6WM3C5OOLFLV2XZP66 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: 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: --Dnw96DVGRXl7HQsi Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Nov 17, 2022 at 01:15:11AM +0100, Stefano Brivio wrote: > On Wed, 16 Nov 2022 15:42:06 +1100 > David Gibson wrote: >=20 > > 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. > >=20 > > 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 IP= v6 > > 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 p= oint > > we'll have to pay this cost anyway. > >=20 > > Signed-off-by: David Gibson > > --- > > tcp.c | 10 ++++------ > > tcp.h | 2 -- > > tcp_splice.c | 9 ++++----- > > 3 files changed, 8 insertions(+), 13 deletions(-) > >=20 > > 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, struc= t tcp_tap_conn *conn) > > { > > int m =3D conn->c.in_epoll ? EPOLL_CTL_MOD : EPOLL_CTL_ADD; > > union epoll_ref ref =3D { .r.proto =3D IPPROTO_TCP, .r.s =3D conn->so= ck, > > - .r.p.tcp.tcp.index =3D CONN_IDX(conn), > > - .r.p.tcp.tcp.v6 =3D CONN_V6(conn) }; > > + .r.p.tcp.tcp.index =3D CONN_IDX(conn) }; > > struct epoll_event ev =3D { .data.u64 =3D ref.u64 }; > > =20 > > if (conn->events =3D=3D CLOSED) { > > @@ -2745,7 +2744,7 @@ static void tcp_tap_conn_from_sock(struct ctx *c,= union epoll_ref ref, > > conn->ws_to_tap =3D conn->ws_from_tap =3D 0; > > conn_event(c, conn, SOCK_ACCEPTED); > > =20 > > - if (ref.r.p.tcp.tcp.v6) { > > + if (sa->sa_family =3D=3D AF_INET6) { > > struct sockaddr_in6 sa6; > > =20 > > 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 =3D port + c->tcp.fwd_in.delta[port]; > > - union tcp_epoll_ref tref =3D { .tcp.listen =3D 1, .tcp.v6 =3D 1, > > - .tcp.index =3D idx }; > > + union tcp_epoll_ref tref =3D { .tcp.listen =3D 1, .tcp.index =3D idx = }; >=20 > Excess whitespace (from earlier patch). Fixed > > int s; > > =20 > > s =3D 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 =3D port + c->tcp.fwd_out.delta[port]; > > union tcp_epoll_ref tref =3D { .tcp.listen =3D 1, .tcp.outbound =3D 1, > > - .tcp.v6 =3D 1, .tcp.index =3D idx}; > > + .tcp.index =3D idx}; >=20 > Missing whitespace (from earlier patch). Fixed. > > int s; > > =20 > > assert(c->mode =3D=3D 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, co= nst 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 =3D conn->c.in_epoll ? EPOLL_CTL_MOD : EPOLL_CTL_ADD; > > union epoll_ref ref_a =3D { .r.proto =3D IPPROTO_TCP, .r.s =3D conn->= a, > > - .r.p.tcp.tcp.index =3D CONN_IDX(conn), > > - .r.p.tcp.tcp.v6 =3D CONN_V6(conn) }; > > + .r.p.tcp.tcp.index =3D CONN_IDX(conn) }; > > union epoll_ref ref_b =3D { .r.proto =3D IPPROTO_TCP, .r.s =3D conn->= b, > > - .r.p.tcp.tcp.index =3D CONN_IDX(conn), > > - .r.p.tcp.tcp.v6 =3D CONN_V6(conn) }; > > + .r.p.tcp.tcp.index =3D CONN_IDX(conn) }; > > struct epoll_event ev_a =3D { .data.u64 =3D ref_a.u64 }; > > struct epoll_event ev_b =3D { .data.u64 =3D 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 c= onnection > > * @c: Execution context > > * @ref: epoll reference of listening socket > > + * @ipv6: Should this be an IPv6 connection? >=20 > Left-over from previous idea I guess. Yes indeed, fixed. > > * @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 =3D=3D MODE_PASTA); > > =20 > > - if (ref.r.p.tcp.tcp.v6) { > > + if (sa->sa_family =3D=3D AF_INET6) { > > const struct sockaddr_in6 *sa6 > > =3D (const struct sockaddr_in6 *)sa; > > if (!IN6_IS_ADDR_LOOPBACK(&sa6->sin6_addr)) >=20 --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --Dnw96DVGRXl7HQsi Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEoULxWu4/Ws0dB+XtgypY4gEwYSIFAmN1k0wACgkQgypY4gEw YSLCZxAAkcq3R5qA125E/eIwXk8mTzZMudZJmfKFiXpI/UxdmislrRta0y6SRGKl uYIJ8uAH/FsBdbbZVfu5xVCjTPLSv6YRdYh5hzsP4XK/Ns1DbmNnNJK5+HTj9kni fEkTKoKiwH0kQ8SEETTcaCAHdC2O0AaSG0sHyxBU18vJP5wXJ1Eg6vXIza9uNgvy B9nsiDXdFncvTVEh75kj2ahnSlyteCObPwsRvYjf3ARgDDR5A27BfEdwsa2VLz48 1c/cNH2tlQ2Yd/aPsLrsus+LzdylIN3NQhtnONRmI8WgIDnS4l/AbqiEW162zmIN bJjdRZJwdBc+U7Bpacms0b6/ov9eA7o8Eg8fz0y5VAmCXkILgfpaYfWACFVA0vFv K7vwOaRijSOqsLS5swtWEbx8yubS1mOepSO3RxYi4sxA+kiCSPguuWZy0QwdvgZy bJq0ku+7G8S/50NpxCDOh0CVzPNTQExSzpDCS7e6z1gMMiUuR9NE7pYHOVcTWUpc 8Nzt6S29jraY4osD3ekJAyk1sTZSp0Kq31VZTMkknGQpUaY79ZnmO3MEl46qpJkt G4uUKJpPzS+I+MySuIDp6R1GIWw/GDbPLcrh5ub3jkIdVyVEPPInMIkrgITjqIvy nfpkW5irl1Sk2hZ/PZYkfj2pGjpvDTCsVSDlUYODvIty0xamUEc= =F7ii -----END PGP SIGNATURE----- --Dnw96DVGRXl7HQsi--