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=pLLm4qf2; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 1B24A5A0008 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=VlU3a00Rvd8qrGTTFoYwkRjDTWWsFIomNRurOTjMojo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=pLLm4qf2hkzuwdQHZYbbfofanUva7x+nRCr9huTnzl2DFWOegjLXTJJZo7D6Vv5P7 y6cJEBb3dT+/RpGXNMiHyxX2+1fkl1z1ijp/WUSeJZGmF5w5MY/RnN+d5SySXtivJs Y/P5gmDiBflGxj2SmoAiYm1GziqR9XdjnyDVF5MzsqkOtmZyOlmLPU+sDCbW2jsr7X g20BAkFh6Vh8Lciwe/oVrdEMrtLt6k25psimoOV7euVjPjKThhKnwsj0BbwBTUQwKS qdWxhmJQ8iprRGvm2jWu/Q+NV2Zk8KNAwZHDNUfuSLJafuqGSpRjUz6ltUy2ODC+VR gVAYb9g0B+5YQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4ZbYSJ0x7Vz4wcx; Mon, 14 Apr 2025 13:58:56 +1000 (AEST) Date: Mon, 14 Apr 2025 13:26:04 +1000 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v2 11/20] tcp: Convert tcp_tap_handler() to use iov_tail Message-ID: References: <20250411131031.1398006-1-lvivier@redhat.com> <20250411131031.1398006-12-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="4KjEQYxw9gMEDH+J" Content-Disposition: inline In-Reply-To: <20250411131031.1398006-12-lvivier@redhat.com> Message-ID-Hash: OBL6AI4RUOFBFCO6JOMFL62B35O2XZPN X-Message-ID-Hash: OBL6AI4RUOFBFCO6JOMFL62B35O2XZPN 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: --4KjEQYxw9gMEDH+J Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Apr 11, 2025 at 03:10:21PM +0200, Laurent Vivier wrote: > Use packet_base() and extract headers using IOV_REMOVE_HEADER() > and iov_peek_header_() rather than packet_get(). >=20 > Signed-off-by: Laurent Vivier > --- > tcp.c | 31 ++++++++++++++++++++++++------- > 1 file changed, 24 insertions(+), 7 deletions(-) >=20 > diff --git a/tcp.c b/tcp.c > index 35626c914c6a..1838b73cf766 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -310,6 +310,16 @@ > #include "tcp_buf.h" > #include "tcp_vu.h" > =20 > +/* > + * The size of TCP header (including options) is given by doff (Data Off= set) > + * that is a 4-bit value specifying the number of 32-bit words in the he= ader. > + * The maximum value of doff is 15 [(1 << 4) - 1]. > + * The maximum length in bytes of options is 15 minus the number of 32-b= it > + * words in the minimal TCP header (5) multiplied by the length of a 32-= bit > + * word (4). > + */ > +#define OPTLEN_MAX (((1UL << 4) - 6) * 4UL) > + > #ifndef __USE_MISC > /* From Linux UAPI, missing in netinet/tcp.h provided by musl */ > struct tcp_repair_opt { > @@ -1957,7 +1967,10 @@ int tcp_tap_handler(const struct ctx *c, uint8_t p= if, sa_family_t af, > { > struct tcp_tap_conn *conn; > const struct tcphdr *th; > - size_t optlen, len; > + char optsc[OPTLEN_MAX]; > + struct iov_tail data; > + size_t optlen, l4len; > + struct tcphdr thc; > const char *opts; > union flow *flow; > flow_sidx_t sidx; > @@ -1966,15 +1979,19 @@ int tcp_tap_handler(const struct ctx *c, uint8_t = pif, sa_family_t af, > =20 > (void)pif; > =20 > - th =3D packet_get(p, idx, 0, sizeof(*th), &len); > + if (!packet_base(p, idx, &data)) > + return 1; > + > + l4len =3D iov_tail_size(&data); > + > + th =3D IOV_REMOVE_HEADER(&data, thc); > if (!th) > return 1; > - len +=3D sizeof(*th); > =20 > optlen =3D th->doff * 4UL - sizeof(*th); > /* Static checkers might fail to see this: */ > - optlen =3D MIN(optlen, ((1UL << 4) /* from doff width */ - 6) * 4UL); > - opts =3D packet_get(p, idx, sizeof(*th), optlen, NULL); > + optlen =3D MIN(optlen, OPTLEN_MAX); > + opts =3D (char *)iov_peek_header_(&data, &optsc[0], optlen, 1); Can you use remove_header here? AFAICT it makes logical sense to move the tail on to covering just the payload at this point. > sidx =3D flow_lookup_af(c, IPPROTO_TCP, PIF_TAP, af, saddr, daddr, > ntohs(th->source), ntohs(th->dest)); > @@ -1986,7 +2003,7 @@ int tcp_tap_handler(const struct ctx *c, uint8_t pi= f, sa_family_t af, > tcp_conn_from_tap(c, af, saddr, daddr, th, > opts, optlen, now); > else > - tcp_rst_no_conn(c, af, saddr, daddr, flow_lbl, th, len); > + tcp_rst_no_conn(c, af, saddr, daddr, flow_lbl, th, l4len); > return 1; > } > =20 > @@ -1994,7 +2011,7 @@ int tcp_tap_handler(const struct ctx *c, uint8_t pi= f, sa_family_t af, > ASSERT(pif_at_sidx(sidx) =3D=3D PIF_TAP); > conn =3D &flow->tcp; > =20 > - flow_trace(conn, "packet length %zu from tap", len); > + flow_trace(conn, "packet length %zu from tap", l4len); > =20 > if (th->rst) { > conn_event(c, conn, CLOSED); --=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 --4KjEQYxw9gMEDH+J Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmf8gEsACgkQzQJF27ox 2GehKhAAjlrKe29Vo3t2x6mKKvf3G7osIk3T4WzBzj/CNUmdKGIBUS5DGPKtYzVS oJBv5flLqc+x5HcKBut3Afr9NyKrgtGSbwrwbzubaFGqaq9Hqzz5e4jnatrRpAwB s1zuErcvGkR1enYxDIefYMZyGH9Tl3Ehk8lebs2q33bXrWKd9Usvks52TLYl6BkZ qRkwKl2TqE1X4IusNZbrJ4DEQTccoLN53qA60ISUcVrIckzRYikSWZ4mxD6VI9Qw z9xzGpx/P5L5P0nzQKP3aQ7wlej1TF4e0sthmkC+YUw2j439rCgeJtCCavoxIChg lLpRny7AG9x0lNLbEvvK3UzLRIkeCAqVhRNmqsyWXk6BfhabOW68wvhpFQW7Tvxl xjgakwBJYrsRBQxyP788MdlKX5Udi0B2+ObY5kPMDMI075kkXZyQQLtMJiS0EzVc nVpzo4ciDiXUURu0Dag97yb3JzBAnJfxVXc6WGI/buUHplozF4sxnyiqXKO7Xedt r+ydTGfH5s5YVYZ3e2jr4c1sNgTYJFcPa0WPUSszgcDaSJZxsa0eTRPl4zf3RnHF 57OkhxvwCXrBst9p85OMo9vegiF8Wzn4pSvFRSti+hGfyfVpJKavR1PNTHdKZ/vZ 3SWTIStz4nmsxv+YhZkpeYtX28kmex9JSLPVW2iHCvIQ9KexapM= =JGU2 -----END PGP SIGNATURE----- --4KjEQYxw9gMEDH+J--