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=202502 header.b=WJ0GCDPx; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id DC9D65A0274 for ; Thu, 20 Feb 2025 02:11:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202502; t=1740013719; bh=XSp4ZddUJRBDHsRemO3SKAIw0ara1fvT7l+kQxo1BcY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=WJ0GCDPxSOOVizYTSNcgLlVrMxBH4rBNOGw6fJbRluSz613+OwBPFKGQRO0rp3B6+ mMuLYSMTIBHBto5OrpxQnPptguqk8DcuxOi73B6WEHtoMnFim3pXtR6lBOgDkA/EDc X6eaB1LZY12Q92PdEbMbdEOsF2H1tih8zKFx+TWhnc1LYvzPEBoxAjsiaRoJKoNbva B/we2LU7NF1/c1SWrtWR/jKFrXEkfoDbOhtA4nh8m/CGr44j/bqNVkX0A/4fB1/7Fz 8r/D5M3LG5ZVBELELW6aZFoVDC+cS3trNZaGebaZdYSTmUppl03oZmWSTgaH/bi0j/ aqS6SXrURp6Qw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4YywBH60n7z4wyw; Thu, 20 Feb 2025 12:08:39 +1100 (AEDT) Date: Thu, 20 Feb 2025 12:08:02 +1100 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v3 1/2] tap: break out building of udp header from tap_udp4_send function Message-ID: References: <20250219193007.2336670-1-jmaloy@redhat.com> <20250219193007.2336670-2-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="wgDW2vhYQR9nlmHW" Content-Disposition: inline In-Reply-To: <20250219193007.2336670-2-jmaloy@redhat.com> Message-ID-Hash: HYTWMDHXJKQ4DLB6MDQJWYWVEOJCANZB X-Message-ID-Hash: HYTWMDHXJKQ4DLB6MDQJWYWVEOJCANZB 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, sbrivio@redhat.com, lvivier@redhat.com, dgibson@redhat.com 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: --wgDW2vhYQR9nlmHW Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Feb 19, 2025 at 02:30:06PM -0500, Jon Maloy wrote: > We will need to build the UDP header at other locations than in function > tap_udp4_send(), so we break that part out to a separate function. >=20 > Signed-off-by: Jon Maloy Reviewed-by: David Gibson > --- > tap.c | 32 +++++++++++++++++++++++++------- > tap.h | 6 +++++- > 2 files changed, 30 insertions(+), 8 deletions(-) >=20 > diff --git a/tap.c b/tap.c > index dfe6dcf..95d64bf 100644 > --- a/tap.c > +++ b/tap.c > @@ -162,7 +162,7 @@ static void *tap_push_ip4h(struct iphdr *ip4h, struct= in_addr src, > } > =20 > /** > - * tap_udp4_send() - Send UDP over IPv4 packet > + * tap_push_uh4() - Build UDPv4 header with checksum > * @c: Execution context > * @src: IPv4 source address > * @sport: UDP source port > @@ -171,15 +171,11 @@ static void *tap_push_ip4h(struct iphdr *ip4h, stru= ct in_addr src, > * @in: UDP payload contents (not including UDP header) > * @dlen: UDP payload length (not including UDP header) > */ > -void tap_udp4_send(const struct ctx *c, struct in_addr src, in_port_t sp= ort, > +void *tap_push_uh4(struct udphdr *uh, struct in_addr src, in_port_t spor= t, > struct in_addr dst, in_port_t dport, > const void *in, size_t dlen) > { > size_t l4len =3D dlen + sizeof(struct udphdr); > - char buf[USHRT_MAX]; > - struct iphdr *ip4h =3D tap_push_l2h(c, buf, ETH_P_IP); > - struct udphdr *uh =3D tap_push_ip4h(ip4h, src, dst, l4len, IPPROTO_UDP); > - char *data =3D (char *)(uh + 1); > const struct iovec iov =3D { > .iov_base =3D (void *)in, > .iov_len =3D dlen > @@ -190,8 +186,30 @@ void tap_udp4_send(const struct ctx *c, struct in_ad= dr src, in_port_t sport, > uh->dest =3D htons(dport); > uh->len =3D htons(l4len); > csum_udp4(uh, src, dst, &payload); > - memcpy(data, in, dlen); > + return uh + 1; > +} > + > +/** > + * tap_udp4_send() - Send UDP over IPv4 packet > + * @c: Execution context > + * @src: IPv4 source address > + * @sport: UDP source port > + * @dst: IPv4 destination address > + * @dport: UDP destination port > + * @in: UDP payload contents (not including UDP header) > + * @dlen: UDP payload length (not including UDP header) > + */ > +void tap_udp4_send(const struct ctx *c, struct in_addr src, in_port_t sp= ort, > + struct in_addr dst, in_port_t dport, > + const void *in, size_t dlen) > +{ > + size_t l4len =3D dlen + sizeof(struct udphdr); > + char buf[USHRT_MAX]; > + struct iphdr *ip4h =3D tap_push_l2h(c, buf, ETH_P_IP); > + struct udphdr *uh =3D tap_push_ip4h(ip4h, src, dst, l4len, IPPROTO_UDP); > + char *data =3D tap_push_uh4(uh, src, sport, dst, dport, in, dlen); > =20 > + memcpy(data, in, dlen); > tap_send_single(c, buf, dlen + (data - buf)); > } > =20 > diff --git a/tap.h b/tap.h > index dfbd8b9..3451343 100644 > --- a/tap.h > +++ b/tap.h > @@ -8,6 +8,8 @@ > =20 > #define ETH_HDR_INIT(proto) { .h_proto =3D htons_constant(proto) } > =20 > +struct udphdr; > + > /** > * struct tap_hdr - tap backend specific headers > * @vnet_len: Frame length (for qemu socket transport) > @@ -43,7 +45,9 @@ static inline void tap_hdr_update(struct tap_hdr *thdr,= size_t l2len) > if (thdr) > thdr->vnet_len =3D htonl(l2len); > } > - > +void *tap_push_uh4(struct udphdr *uh, struct in_addr src, in_port_t spor= t, > + struct in_addr dst, in_port_t dport, > + const void *in, size_t dlen); > void tap_udp4_send(const struct ctx *c, struct in_addr src, in_port_t sp= ort, > struct in_addr dst, in_port_t dport, > const void *in, size_t dlen); --=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 --wgDW2vhYQR9nlmHW Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAme2gGIACgkQzQJF27ox 2GcJpg//eRox3gGvL9sVI9R7peeLP9et6CmZK+QGuFGqmiO/Ovwz2GWQm9anKOuu pDZUMmMDEJ/6FGf3ORjL2/ylx93TomshA5ZZMYI0uqlzdigYdWjQEt4KIrB4vvxs ibDtBZfEmTZsQFrcuOnzOfzPFP7b7QpQEW2Sy1V7tYhrq98PzUw0uz1sEduj68BV etE0Ynr1T5WiY41L9xlORVyoPO6vhR2db3TjXBkkl+wVAXq1evYDEXa9Cw5s4t/c cnRKhwTscUICQzrk5mt5J55TOKL6e4V0HHcHttotuYpDLSGohY1ycRi0dQ2JUgN0 x2FvmETLNJC2IUPxi8PoyA9If0AnF2tnMzol04wkyKeVrX3I1TPKbTCfjnFmIW7y VCFknsbPGfrNe9i5D3yyQ2HfxuWqDMK3C7FXqm0JTfDqMHa7J2nLvTSfTACsYy2E 25MOGS76XMFjkl6kZ6PQxRFW3MAAyjt4tcsEq61fu8Nl98kp7RXKoTQIjJnaU1mk Ok7zMG+yRuWY0kcNiBss0ZXgxfpEtncZYJ7f5GOJLZ7dnHZcrGJ/bgSlJXgYIcoR MB4q99gIyrGeZBTtLKYIW8JOoY5rsxSm3TkxGqVEhp1ZzTFU+J9Xh9XxuGudnsAs Ub/l53IPVYd00oUA8INs1QrEDZrRJFAWoqP0pzvrWTVvdHzoKF4= =ZcZI -----END PGP SIGNATURE----- --wgDW2vhYQR9nlmHW--