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=VnDxJ64J; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id B0EFA5A027C for ; Wed, 13 Aug 2025 05:27:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202508; t=1755055626; bh=TwE65hj6bCS3tQh699D0HCp2tGW0HoUlcIll27O/Ifc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VnDxJ64JIVPinVFrdjOIf/c1KrBA8L/Pcc1rPitYBF1NA0R/h+lDrUmM+PjSNPq1O V4UcWi2vcBGqvdWywHHRdhIS3uzIpR4YO5ID2IJdgEIM5XPOd95HY+IuVmrswelQ84 Ea3jmbgOWYfcJeu/hCe+UzgX+OYTBq8t9gUQlT+ygPee7CVHN/r6D9EJQn/AsX3eTL Oux+aGBvRYCf959ghvt9jkO6oEEYSl2WpHHY2uBiGpbNxVwj10QSEuFB5Ye7vI56XV daqoMRFq1cUjVqZ4JjjgNQW0HjlhxByLRs3BGTJ81rI9CRaUxwns6xZONoTmKrgDSy g3s1+GcdATgbQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4c1v1k4ZJRz4x6n; Wed, 13 Aug 2025 13:27:06 +1000 (AEST) Date: Wed, 13 Aug 2025 13:09:49 +1000 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v9 09/30] icmp: Convert to iov_tail Message-ID: References: <20250808140142.3404325-1-lvivier@redhat.com> <20250808140142.3404325-10-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="+bQ7SrG+Y5RnOX4R" Content-Disposition: inline In-Reply-To: <20250808140142.3404325-10-lvivier@redhat.com> Message-ID-Hash: IHW5IVQLOBFNFIQ5YZQNKH3FPY2BY25X X-Message-ID-Hash: IHW5IVQLOBFNFIQ5YZQNKH3FPY2BY25X 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: --+bQ7SrG+Y5RnOX4R Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Aug 08, 2025 at 04:01:21PM +0200, Laurent Vivier wrote: > Use packet_data() and extract headers using IOV_PEEK_HEADER() > rather than packet_get(). >=20 > Signed-off-by: Laurent Vivier Reviewed-by: David Gibson > --- > icmp.c | 40 +++++++++++++++++++++++++++------------- > iov.c | 1 - > 2 files changed, 27 insertions(+), 14 deletions(-) >=20 > diff --git a/icmp.c b/icmp.c > index 95f38c1e2a3a..7791e88733d7 100644 > --- a/icmp.c > +++ b/icmp.c > @@ -44,6 +44,7 @@ > =20 > #define ICMP_ECHO_TIMEOUT 60 /* s, timeout for ICMP socket activity */ > #define ICMP_NUM_IDS (1U << 16) > +#define MAX_IOV_ICMP 16 /* Arbitrary, should be enough */ > =20 > /** > * ping_at_sidx() - Get ping specific flow at given sidx > @@ -238,28 +239,31 @@ int icmp_tap_handler(const struct ctx *c, uint8_t p= if, sa_family_t af, > const void *saddr, const void *daddr, > const struct pool *p, const struct timespec *now) > { > + struct iovec iov[MAX_IOV_ICMP]; > 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; > + int cnt; > =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 +271,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 > @@ -285,6 +288,10 @@ int icmp_tap_handler(const struct ctx *c, uint8_t pi= f, sa_family_t af, > ASSERT(0); > } > =20 > + cnt =3D iov_tail_clone(&iov[0], MAX_IOV_ICMP, &data); > + if (cnt < 0) > + return 1; > + > flow =3D flow_at_sidx(flow_lookup_af(c, proto, PIF_TAP, > af, saddr, daddr, id, id)); > =20 > @@ -298,8 +305,15 @@ 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 > - pif_sockaddr(c, &sa, &sl, PIF_HOST, &tgt->eaddr, 0); > - if (sendto(pingf->sock, pkt, l4len, MSG_NOSIGNAL, &sa.sa, sl) < 0) { > + pif_sockaddr(c, &sa, &msh.msg_namelen, PIF_HOST, &tgt->eaddr, 0); > + msh.msg_name =3D &sa; > + msh.msg_iov =3D iov; > + msh.msg_iovlen =3D cnt; > + msh.msg_control =3D NULL; > + msh.msg_controllen =3D 0; > + msh.msg_flags =3D 0; > + > + 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..9d423d0f521e 100644 > --- a/iov.c > +++ b/iov.c > @@ -311,7 +311,6 @@ void *iov_remove_header_(struct iov_tail *tail, void = *v, size_t len, size_t alig > * iov array, a negative value if there is not enough room in the > * destination iov array > */ > -/* cppcheck-suppress unusedFunction */ > ssize_t iov_tail_clone(struct iovec *dst_iov, size_t dst_iov_cnt, > struct iov_tail *tail) > { --=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 --+bQ7SrG+Y5RnOX4R Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmicAf0ACgkQzQJF27ox 2GfOTQ/+I1kOFFXDyye6np3Eq+cOEdVlUteWQ6ZPSFV3jsKdBe9oJBAhr7kp8NUm DC5OWsXDnnfSxToqoIyEyemA3zQJ/3SA/qdqj2uCNwJSvvlMkAAa50FcBRiNabpa oIJ8MLvbNJKq2/z3bGnd9ZgEdrb2R/napQY9Mzqv6Tbeft7vkIBlhhzGPD42pxFz oaM/4bCXX8R/V34MAueeVdIxBqyzN8/sBkxSniJeG661kOSbgOscWM0BCvyTjjmG sEyA9RfnayJK7sTM330Dhubd+LOc8IvlLVbPr5esoC8/e+zOKmp7TS1m911qbO2t xPFm3d+TPQlEiRx8ohXROoTn8tIZx5Atlof2JpSxqdA0gs/qwopOm27kmtzvNnqK FuVeMUUFxiUXKFjRUyMYC6Nt/0jVnj3HfAzFzAiOei4SJBRx4TfrElRBLWrI47oR CoBus4dDuFsQ6Qf4xa3Sky5lCcD0rhT2TpZLFKMXVqA/1kIb/Pfpu0KhLVma6NBm f12OLnnrUlw2UZSMiYsEFLyrUzE8QE6Wx5d7PrFRpVpg52kSkmWuwRfDbA8Myapa EpqieN1VQntm7i9SQrizupicAXP3f5oCVzaXyC3xmxwNGHyLPTmbeSye13jfUVAx QgE20U31EjSmPttGQIrx8E917z75pkFON2FI9GOXjVj5GS6wZW0= =6b0e -----END PGP SIGNATURE----- --+bQ7SrG+Y5RnOX4R--