From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202504 header.b=TLjG4hCH; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 1C72E5A0271 for ; Mon, 14 Apr 2025 05:59:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202504; t=1744603136; bh=u3D2DyF+SaiTa7VEH83qCHzPh8zl8G3BVVgBFEJ6/Hw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TLjG4hCHbI4a6itiMg0A6pc9lRkdDJJbrlWwVeQR79HpbLEz6bNZEH8s6LvjYQcNM 5DziPAa7Y7s0D/wWWhJki0HekkZGXxJh1ubese7TLCz6RK6ZKAhbbpQL2Ruddp0j0C PWgow099szhf4iDoX/TRu01hZskVAoGcOM2bBxcPzrM0ibcGaEkgKAsYIOVN+7f9fY lbRh2o7sZrkgTeibla/TJbDCShC9BBu4FLM0JLnxQ+ulqx2nC/eT8Xpvqo0xvfymt1 gbbHs7Aseh/uX9ppjQMEKC3OMSOxkirZsKvufY/s3oItZnNoARp+8+1R5XzAH637Rk cf84XMZUv/kWw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4ZbYSJ10qBz4wcd; Mon, 14 Apr 2025 13:58:56 +1000 (AEST) Date: Mon, 14 Apr 2025 13:28:06 +1000 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v2 12/20] tcp: Convert tcp_data_from_tap() to use iov_tail Message-ID: References: <20250411131031.1398006-1-lvivier@redhat.com> <20250411131031.1398006-13-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="fwjUZqoWF9U1b0m4" Content-Disposition: inline In-Reply-To: <20250411131031.1398006-13-lvivier@redhat.com> Message-ID-Hash: 74JRQV4RH2AOARTRBDNWQU5WLMGFYSYM X-Message-ID-Hash: 74JRQV4RH2AOARTRBDNWQU5WLMGFYSYM 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.8 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: --fwjUZqoWF9U1b0m4 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Apr 11, 2025 at 03:10:22PM +0200, Laurent Vivier wrote: > Use packet_base() and extract headers using IOV_PEEK_HEADER() > rather than packet_get(). >=20 > Signed-off-by: Laurent Vivier > --- > tcp.c | 30 +++++++++++++++++++----------- > 1 file changed, 19 insertions(+), 11 deletions(-) >=20 > diff --git a/tcp.c b/tcp.c > index 1838b73cf766..bebbb01b39f5 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -1651,15 +1651,21 @@ static int tcp_data_from_tap(const struct ctx *c,= struct tcp_tap_conn *conn, > for (i =3D idx, iov_i =3D 0; i < (int)p->count; i++) { > uint32_t seq, seq_offset, ack_seq; > const struct tcphdr *th; > - char *data; > - size_t off; > + struct iov_tail data; > + struct tcphdr thc; > + size_t off, size; > + int count; > =20 > - th =3D packet_get(p, i, 0, sizeof(*th), &len); > + if (!packet_base(p, i, &data)) > + return -1; > + > + th =3D IOV_PEEK_HEADER(&data, thc); > if (!th) > return -1; > - len +=3D sizeof(*th); > + len =3D iov_tail_size(&data); > =20 > off =3D th->doff * 4UL; > + > if (off < sizeof(*th) || off > len) > return -1; > =20 > @@ -1669,9 +1675,7 @@ static int tcp_data_from_tap(const struct ctx *c, s= truct tcp_tap_conn *conn, > } > =20 > len -=3D off; > - data =3D packet_get(p, i, off, len, NULL); > - if (!data) > - continue; > + iov_tail_drop(&data, off); > =20 > seq =3D ntohl(th->seq); > if (SEQ_LT(seq, conn->seq_from_tap) && len <=3D 1) { > @@ -1745,10 +1749,14 @@ static int tcp_data_from_tap(const struct ctx *c,= struct tcp_tap_conn *conn, > continue; > } > =20 > - tcp_iov[iov_i].iov_base =3D data + seq_offset; > - tcp_iov[iov_i].iov_len =3D len - seq_offset; > - seq_from_tap +=3D tcp_iov[iov_i].iov_len; > - iov_i++; > + size =3D len - seq_offset; > + count =3D iov_slice(&tcp_iov[iov_i], UIO_MAXIOV - iov_i, > + &data.iov[0], data.cnt, data.off + seq_offset, > + &size); Here's another use case for that iov_slice() wrapper > + if (count < 0) > + break; > + seq_from_tap +=3D size; > + iov_i +=3D count; > =20 > if (keep =3D=3D i) > keep =3D -1; --=20 David Gibson (he or they) | 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 --fwjUZqoWF9U1b0m4 Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmf8gMUACgkQzQJF27ox 2GdovA/+MKemcA8LWkiDCvinRAAs2u9JDslLCz2ofrOjebS4ahzaqS8ebe1M74o9 kxRRE6hG6R+FLBKUsGsJ3lH2QkHBBmDB4bBdXHV8Swof5RsBqG69vtiQPayZybkw a/3AHXAJB9us3A7X3c6YH0PPQUVCeFncxq1DmRFRJjuN6MXOVccF7eR/ds7mFNEU 33iWWS2X+bv1JwhnDT6RzXm1NzKspqPKukO4ZLcju0+HXnFK4glpUH6h4LQHyGqV BbgrZWYqKXoQJ1oEV+mxotqNRcGwTsXHUfzy2Kd1bn9+ELW+MbkcTStCabutkJkw B87INLpOMCbIapZRq4XzvB+1d74zZwzGayTb/WUkNq7lGU4a+Fhj7rpS9L7nlV7C o5/4q/WbT96RRuMAh5MROh9+MzZIYKo9/oQRjSnDoZu74MoOsmqCmRmMWkFEBgzQ sCZZK/DSGMLkYSTTrCQXAH4QZa481fSuxtbftrVuPpr+ycYQnyECgTHOhQGYlVGF jzxBmTLk5v8y2aVRxLyG6+IDUlmjtgHanZg2Flg/XUtzItO7Cu8JaVRRAiK3UXvu 8YLNKp90OE9kw+WalT29wfvRLtQXB6X2ZSUmcVkkIR/xn/lI1j3TMHs9+SFcyz3s 4gWuY82PFSEj7sqqo/Xee8y5P4MWwMwxra5Mr68w7itzYF9GxQQ= =vzSl -----END PGP SIGNATURE----- --fwjUZqoWF9U1b0m4--