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=202508 header.b=VEKwDm3e; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 88A725A0271 for ; Wed, 06 Aug 2025 04:23:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202508; t=1754447034; bh=VnA3rn1EJhyqIrwBFPSQxxC+NvXiUHYi0NnEac27USk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VEKwDm3ezGLgp56R86kCILHgCbhdbJ7AH9IKWbDoBNamQ0kUP86ogrWE2o3p23HSP qmU69KrXHTaw5leioZYMqNL1fUtUTTK7+UyLtIpF2rVH+YGtQUtw7nQnI6sX9OysOx sv7kRNdSxPcf5yrr6+6iAUaUENNHEJfKJRhnbuyv6WOWjn4oev9FkyZsKKCzvm+mN/ 19w+r243ighYshWi9To/BwU0v8yureNKNgk7BRIJOw4odaZdXkMSm4kcpFCXtDvZSi o0nnmz3Su8QrEhPdJSzeh+6M/Zennny+IlzbBjoaHEBruRLMurA8LiX5lZd+O7F+eY q6bt3v7iod9LA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4bxYy23ws7z4xcZ; Wed, 6 Aug 2025 12:23:54 +1000 (AEST) Date: Wed, 6 Aug 2025 12:20:58 +1000 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v8 09/30] icmp: Convert to iov_tail Message-ID: References: <20250805154628.301343-1-lvivier@redhat.com> <20250805154628.301343-10-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="CmPA5+uMCqhG5gB4" Content-Disposition: inline In-Reply-To: <20250805154628.301343-10-lvivier@redhat.com> Message-ID-Hash: OO6WGXD2INQ3UB3776VWVZV2CNNC4GYF X-Message-ID-Hash: OO6WGXD2INQ3UB3776VWVZV2CNNC4GYF 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: --CmPA5+uMCqhG5gB4 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Aug 05, 2025 at 05:46:07PM +0200, Laurent Vivier wrote: > Use packet_data() and extract headers using IOV_PEEK_HEADER() > rather than packet_get(). >=20 > Introduce iov_tail_msghdr() to convert iov_tail to msghdr >=20 > Signed-off-by: Laurent Vivier > --- > icmp.c | 25 ++++++++++++++----------- > iov.c | 23 +++++++++++++++++++++++ > iov.h | 2 ++ > 3 files changed, 39 insertions(+), 11 deletions(-) >=20 > diff --git a/icmp.c b/icmp.c > index 95f38c1e2a3a..fdfc857b5ae8 100644 > --- a/icmp.c > +++ b/icmp.c > @@ -241,25 +241,27 @@ int icmp_tap_handler(const struct ctx *c, uint8_t p= if, sa_family_t af, > struct icmp_ping_flow *pingf; > const struct flowside *tgt; > union sockaddr_inany sa; > - size_t dlen, l4len; > + struct iov_tail data; > + struct msghdr msh; > uint16_t id, seq; > union flow *flow; > uint8_t proto; > socklen_t sl; > - void *pkt; > =20 > (void)saddr; > ASSERT(pif =3D=3D PIF_TAP); > =20 > + if (!packet_data(p, 0, &data)) > + return -1; > + > if (af =3D=3D AF_INET) { > + struct icmphdr ih_storage; > const struct icmphdr *ih; > =20 > - if (!(pkt =3D packet_get(p, 0, 0, sizeof(*ih), &dlen))) > + ih =3D IOV_PEEK_HEADER(&data, ih_storage); > + if (!ih) > return 1; > =20 > - ih =3D (struct icmphdr *)pkt; > - l4len =3D dlen + sizeof(*ih); > - > if (ih->type !=3D ICMP_ECHO) > return 1; > =20 > @@ -267,14 +269,13 @@ int icmp_tap_handler(const struct ctx *c, uint8_t p= if, sa_family_t af, > id =3D ntohs(ih->un.echo.id); > seq =3D ntohs(ih->un.echo.sequence); > } else if (af =3D=3D AF_INET6) { > + struct icmp6hdr ih_storage; > const struct icmp6hdr *ih; > =20 > - if (!(pkt =3D packet_get(p, 0, 0, sizeof(*ih), &dlen))) > + ih =3D IOV_PEEK_HEADER(&data, ih_storage); > + if (!ih) > return 1; > =20 > - ih =3D (struct icmp6hdr *)pkt; > - l4len =3D dlen + sizeof(*ih); > - > if (ih->icmp6_type !=3D ICMPV6_ECHO_REQUEST) > return 1; > =20 > @@ -298,8 +299,10 @@ int icmp_tap_handler(const struct ctx *c, uint8_t pi= f, sa_family_t af, > ASSERT(flow_proto[pingf->f.type] =3D=3D proto); > pingf->ts =3D now->tv_sec; > =20 > + Bogus extra blank line. > pif_sockaddr(c, &sa, &sl, PIF_HOST, &tgt->eaddr, 0); > - if (sendto(pingf->sock, pkt, l4len, MSG_NOSIGNAL, &sa.sa, sl) < 0) { > + iov_tail_msghdr(&msh, &data, &sa, sl); > + if (sendmsg(pingf->sock, &msh, MSG_NOSIGNAL) < 0) { > flow_dbg_perror(pingf, "failed to relay request to socket"); > } else { > flow_dbg(pingf, > diff --git a/iov.c b/iov.c > index 97e4ea733540..9d99beb32532 100644 > --- a/iov.c > +++ b/iov.c > @@ -158,6 +158,29 @@ size_t iov_size(const struct iovec *iov, size_t iov_= cnt) > return len; > } > =20 > +/** > + * iov_tail_msghdr - Initialize a msghdr from an IOV tail structure > + * @msh: msghdr to initialize > + * @tail: iov_tail to use to set msg_iov and msg_iovlen > + * @msg_name: Pointer to set to msg_name > + * @msg_namelen: Size of @msg_name > + */ > +void iov_tail_msghdr(struct msghdr *msh, struct iov_tail *tail, > + void *msg_name, socklen_t msg_namelen) > +{ > + iov_tail_prune(tail); > + > + ASSERT(tail->off =3D=3D 0); Oof, this is a pretty nasty non-obvious constraint on calling this function. The whole point of iov_tails is the offset, but this function won't work in that case. > + msh->msg_name =3D msg_name; > + msh->msg_namelen =3D msg_namelen; > + msh->msg_iov =3D (struct iovec *)tail->iov; > + msh->msg_iovlen =3D tail->cnt; > + msh->msg_control =3D NULL; > + msh->msg_controllen =3D 0; > + msh->msg_flags =3D 0; > +} > + > /** > * iov_tail_prune() - Remove any unneeded buffers from an IOV tail > * @tail: IO vector tail (modified) > diff --git a/iov.h b/iov.h > index ccdb690ef3f1..75c3b07a87e3 100644 > --- a/iov.h > +++ b/iov.h > @@ -82,6 +82,8 @@ struct iov_tail { > 1, \ > (off_)) > =20 > +void iov_tail_msghdr(struct msghdr *msh, struct iov_tail *tail, > + void *msg_name, socklen_t msg_namelen); > bool iov_tail_prune(struct iov_tail *tail); > size_t iov_tail_size(struct iov_tail *tail); > bool iov_tail_drop(struct iov_tail *tail, size_t len); --=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 --CmPA5+uMCqhG5gB4 Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmiSu/4ACgkQzQJF27ox 2GfrvhAAmoRqVdHUO2Gktva4K0kdBmWo9a6r5Q/OUonvk20nV1RHZIw1hkL2Lxz2 XP8BTogV5GzORzABY6H+58WqapcDxAWbTKBNXfk152gQ2bzO1ZZQbwJ0LdNEtE1J JVRNe6bmWq9tZ2rZKqZB6ZLU0Fvdnd104q+PngU6G+tSP6gyUrHxdQlm4Y4b2JCd 5eC7RnpNNheCiaX1zZdnwly7G16jgUUFAqIdCLFJhjbo3488hnrQlqOP522Ta1P3 e7xvACXlGfVf9asWsxspWdqMtyfmnHpYHU6QHGIo10EeATcWUrs6On4HTzN451r4 Nl72ojwKWSWVLJ1jL4l4C+96NHKOLgRshG/mVW+8d9RjdaDrI/QJZ9vFcH5mTSp2 YV/p1I19pMsh72NeIDA2EYgweEeqvCWOHymqOvgFPDwUh5aqCrNkyA6/YI5/9+Hs ktyVtZNPwjPgiWeEOyJjIJxeP8vZ4sZy09UUwqmiwlpauRGrKonPBV+nPZZu37w+ hwBYoUnX/0eSmMKBcV9C+8tBuXMRbsJpA00UeBuER7bRwE6AQXFafQGQ+KtISnwT aPPb0dav2YccUNrP0GT8dj35NhYiibHDz2Q8LaRTV/j9jnM+oVAhsUFTg2OcINO3 tLm2BJW/sAQEhE7itVTZNCJQitb/nZuuday4J2oFer+CauX9FR8= =VEjL -----END PGP SIGNATURE----- --CmPA5+uMCqhG5gB4--