From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 1238E5A0270 for ; Tue, 8 Nov 2022 02:02:16 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4N5qZB202Gz4xx4; Tue, 8 Nov 2022 12:02:10 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1667869330; bh=ABRtbENUwrUpfgZrstliJ5cx699Yb+1WdeLr6pzOwXo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lgxwQUbnpA/OggF2xLhHHraHV85uua60nitf12tRcCkpaQrzrPN/7TLte9QjOAHek I4cqqWOIPX9wh9Fhbjh67F4rEZ53vrEZEV/irVHjDlAv998b96yvTKPM2frjLxovvW rs4r0oWHLhJ66AnOIwQZQV41ZEdHsEVNaPYS3aFc= Date: Tue, 8 Nov 2022 11:51:55 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 03/10] tcp: Partially unify IPv4 and IPv6 paths in tcp_hash_match() Message-ID: References: <20221104084333.3761760-1-david@gibson.dropbear.id.au> <20221104084333.3761760-4-david@gibson.dropbear.id.au> <20221107190827.11099cfa@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="PVlvfha1GGbh+xCy" Content-Disposition: inline In-Reply-To: <20221107190827.11099cfa@elisabeth> Message-ID-Hash: J4VFHPPJQAMWQL7QWVLJ3GZEYVVLU3XG X-Message-ID-Hash: J4VFHPPJQAMWQL7QWVLJ3GZEYVVLU3XG 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: --PVlvfha1GGbh+xCy Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Nov 07, 2022 at 07:08:27PM +0100, Stefano Brivio wrote: > On Fri, 4 Nov 2022 19:43:26 +1100 > David Gibson wrote: >=20 > > When given an IPv4 address tcp_hash_match() checks if the connection > > stores an IPv4-mapped IPv6 address, and if so compares the mapped part = of > > that address to the given address. This is equivalent to converting a > > given IPv4 address to an IPv4-mapped IPv6 address then comparing it to = the > > connection address using the existing IPv6 logic. > >=20 > > Convert to this slightly simpler form, which will also allow some furth= er > > simplifications in future. > >=20 > > Signed-off-by: David Gibson > > --- > > tcp.c | 13 +++++++------ > > 1 file changed, 7 insertions(+), 6 deletions(-) > >=20 > > diff --git a/tcp.c b/tcp.c > > index 26dd268..508d6e9 100644 > > --- a/tcp.c > > +++ b/tcp.c > > @@ -1285,13 +1285,14 @@ static int tcp_opt_get(const char *opts, size_t= len, uint8_t type_find, > > static int tcp_hash_match(const struct tcp_conn *conn, int af, const v= oid *addr, > > in_port_t tap_port, in_port_t sock_port) > > { > > - if (af =3D=3D AF_INET && CONN_V4(conn) && > > - !memcmp(&conn->a.a4.a, addr, sizeof(conn->a.a4.a)) && > > - conn->tap_port =3D=3D tap_port && conn->sock_port =3D=3D sock_por= t) > > - return 1; > > + struct in6_addr v4mapped; > > + > > + if (af =3D=3D AF_INET) { > > + encode_ip4mapped_ip6(&v4mapped, addr); > > + addr =3D &v4mapped; > > + } >=20 > It's probably worth the simplification, just mind that this replaces a > 32-bit comparison with 128 bits of writes. I'm aware, however this is mitigated later in the series. Once I make tcp_hash_match() take a (possibly v4mapped) v6 address only it's just a 128-bit comparison, which we already effectively do split between CONN_V4() and the v4 specific path. Obviously that means constructing the v4mapped address in the caller, but we were already doing that in at least one of the cases. >=20 > > =20 > > - if (af =3D=3D AF_INET6 && > > - IN6_ARE_ADDR_EQUAL(&conn->a.a6, addr) && > > + if (IN6_ARE_ADDR_EQUAL(&conn->a.a6, addr) && > > conn->tap_port =3D=3D tap_port && conn->sock_port =3D=3D sock_por= t) > > return 1; > > =20 >=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 --PVlvfha1GGbh+xCy Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEoULxWu4/Ws0dB+XtgypY4gEwYSIFAmNpqCUACgkQgypY4gEw YSLuIhAA0IX+Ns2uIQDS5TiPFLYdaV4iZjNQ3NsAmR27iTzGJbcGn0l990GQ9cAF 9+esE8NiSLZpts6eoVUyR925G1NGvFeSqBzHX87OxDulKqU0/TNEqU8kTW1WUsZO CjBRkRHWW2zMWoHYOD86YqMTWJY9MdNsK5ozdCSEKRQT5cCUuxD2RI1ZlWCKLwKb mmtwj9VMIkKXzQdT2Tb84IUubTX25dQxyF7V3p4B5kk+qT/ajWMdWvUYEQv00uyW jqdUPm0Gjar7NlyRAwkxfIo+98XvJ6tJbPlvv5ogzXJVVgJGahE0Ioz6ykakUuVi 5LvR0MwP9rY7D2R/FL6is9fskv547OHD9ARIGTT0pMUXqznrG+XBn3rHNyfWYVw9 MxZHmBAw0GP4u45ktpn60RoGFy6cWT4S83Y6FNLsQezovk+bjvR/uaqhJi3KROdZ Tbl6AqZrXtQMiYBXsYXEOsUdRoIvWZFIpLleUZsd4swMLtzp9rwgVGbjqF5fKgC/ J7X9eymNwFef0PFhsoWqAE216YqBUvNYeRXUUAoqiP92zpeLLH1ZidQqjffP0EWE MZsdH3sUX934adVMRrS7RGpoNYF6HmDmMYxM02lgp3t9Yh854YXAPFXFCGNhO6Ex MrZgQY3z/zBpDu954EUcUKMp12GByP8XvaBRVPiN532tMNKmwv4= =mSRO -----END PGP SIGNATURE----- --PVlvfha1GGbh+xCy--