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.133.124]) by passt.top (Postfix) with ESMTP id 6E4595A0265 for ; Mon, 7 Nov 2022 19:08:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667844515; 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=BtoeQ/IuJ7uQd+NtT6G6AcZG5/NCcrK97EQfnrDPWak=; b=Mb8no7zTuyVTjK0s9u8y72ZlEAfMqtW71ylJHhf/ew/OQkdWTsuQrXkJckdQsixGBkgI48 mbrXd/qddftWl10yKbtEqObpeI8DFRl5nuJDJdl/VRE1LRolcolFFCSPiHqLun5bGuQyIL 1vxZOT4Vsn2nH0snxwSgYxlfWP70O5Y= 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-208-BUwHF1N3Ojm--Hmbto_3bA-1; Mon, 07 Nov 2022 13:08:31 -0500 X-MC-Unique: BUwHF1N3Ojm--Hmbto_3bA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 12105800159; Mon, 7 Nov 2022 18:08:31 +0000 (UTC) Received: from maya.cloud.tilaa.com (ovpn-208-9.brq.redhat.com [10.40.208.9]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CC2E34022DA; Mon, 7 Nov 2022 18:08:30 +0000 (UTC) Date: Mon, 7 Nov 2022 19:08:27 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 03/10] tcp: Partially unify IPv4 and IPv6 paths in tcp_hash_match() Message-ID: <20221107190827.11099cfa@elisabeth> In-Reply-To: <20221104084333.3761760-4-david@gibson.dropbear.id.au> References: <20221104084333.3761760-1-david@gibson.dropbear.id.au> <20221104084333.3761760-4-david@gibson.dropbear.id.au> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: QPQPLRBXMVU5IDGYC2HTZ22XC2PJNLL3 X-Message-ID-Hash: QPQPLRBXMVU5IDGYC2HTZ22XC2PJNLL3 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 Fri, 4 Nov 2022 19:43:26 +1100 David Gibson wrote: > 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. > > Convert to this slightly simpler form, which will also allow some further > simplifications in future. > > Signed-off-by: David Gibson > --- > tcp.c | 13 +++++++------ > 1 file changed, 7 insertions(+), 6 deletions(-) > > 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 void *addr, > in_port_t tap_port, in_port_t sock_port) > { > - if (af == AF_INET && CONN_V4(conn) && > - !memcmp(&conn->a.a4.a, addr, sizeof(conn->a.a4.a)) && > - conn->tap_port == tap_port && conn->sock_port == sock_port) > - return 1; > + struct in6_addr v4mapped; > + > + if (af == AF_INET) { > + encode_ip4mapped_ip6(&v4mapped, addr); > + addr = &v4mapped; > + } It's probably worth the simplification, just mind that this replaces a 32-bit comparison with 128 bits of writes. > > - if (af == AF_INET6 && > - IN6_ARE_ADDR_EQUAL(&conn->a.a6, addr) && > + if (IN6_ARE_ADDR_EQUAL(&conn->a.a6, addr) && > conn->tap_port == tap_port && conn->sock_port == sock_port) > return 1; > -- Stefano