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=202506 header.b=mf2Bg43w; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id E606A5A0284 for ; Tue, 22 Jul 2025 04:21:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202506; t=1753150713; bh=DfAzLwsqdQ33znG+nt4Sa3oP0PwIYUHVtbM2arJdqWA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mf2Bg43wCjW8hSYj0UqnG+SoWTHSpGhjynAlm2cUu6FGDOP07fG93PEjGPHUWXNCY x2k1sIfw7pAAuiIcYw80ZVE1+t34/h44hjcn7ByOpmr6rG7BwR/TgeBeWZ+kWhUubo nQGTvzlLACn72mHLf3wST9h9N7+9tm2hOm8xj5w7qYf7Hy2shGuQWPYEgfP/rjKCJE bpa2Haj4zXjgv4vr7q7w/5zmzFvlF7GDtwy+6bs+/FP3kLX97dyZSRzQIozW4Io0KD m7c1L/Rncz1fm6xxZ8fSGuDakPFpLs1sjDm2mh1D1PhVKrcpyJbRUYt9EzLHUpjasl JB8zaKmDAXnew== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4bmLXn2dSKz4x3p; Tue, 22 Jul 2025 12:18:33 +1000 (AEST) Date: Tue, 22 Jul 2025 12:19:53 +1000 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v3 4/8] udp: forward external source MAC address through tap interface Message-ID: References: <20250629171348.86323-1-jmaloy@redhat.com> <20250629171348.86323-5-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="cladUhWawX+08kfm" Content-Disposition: inline In-Reply-To: <20250629171348.86323-5-jmaloy@redhat.com> Message-ID-Hash: Q3XM5KHIS5ICX5X7Y4RFUQK5Z7G2OVL7 X-Message-ID-Hash: Q3XM5KHIS5ICX5X7Y4RFUQK5Z7G2OVL7 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: sbrivio@redhat.com, dgibson@redhat.com, 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: --cladUhWawX+08kfm Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Jun 29, 2025 at 01:13:43PM -0400, Jon Maloy wrote: > We forward the incoming MAC address through the tap interface when > receiving incoming packets from network local hosts. Packets from > the own host are excepted from this rule, and are still forwarded > with the default PASST/PASTA MAC address as source. >=20 > This is a part of the solution to bug > https://bugs.passt.top/show_bug.cgi?id=3D120 >=20 > Signed-off-by: Jon Maloy >=20 > --- > v3: - Adapted to the move of external MAC address from struct flowside > to struct flow_common > --- > udp.c | 37 +++++++++++++++++++------------------ > 1 file changed, 19 insertions(+), 18 deletions(-) >=20 > diff --git a/udp.c b/udp.c > index 65a52e0..5942088 100644 > --- a/udp.c > +++ b/udp.c > @@ -133,11 +133,8 @@ static int udp_splice_init[IP_VERSIONS][NUM_PORTS]; > /* UDP header and data for inbound messages */ > static struct udp_payload_t udp_payload[UDP_MAX_FRAMES]; > =20 > -/* Ethernet header for IPv4 frames */ > -static struct ethhdr udp4_eth_hdr; > - > -/* Ethernet header for IPv6 frames */ > -static struct ethhdr udp6_eth_hdr; > +/* Ethernet headers for IPv4 and IPv6 frames */ > +static struct ethhdr udp_eth_hdr[UDP_MAX_FRAMES]; Now that the ethernet header has a per-frame buffer, it probably makes sense to fold the ethernet header into struct tap_hdr. That way tap_hdr handles everything below the IP level. That could be a follow up change, though. > =20 > /** > * struct udp_meta_t - Pre-cooked headers for UDP packets > @@ -214,8 +211,10 @@ void udp_portmap_clear(void) > */ > void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *= eth_s) > { > - eth_update_mac(&udp4_eth_hdr, eth_d, eth_s); > - eth_update_mac(&udp6_eth_hdr, eth_d, eth_s); > + int i; > + > + for (i =3D 0; i < UDP_MAX_FRAMES; i++) > + eth_update_mac(&udp_eth_hdr[i], eth_d, eth_s); > } > =20 > /** > @@ -238,6 +237,7 @@ static void udp_iov_init_one(const struct ctx *c, siz= e_t i) > =20 > *siov =3D IOV_OF_LVALUE(payload->data); > =20 > + tiov[UDP_IOV_ETH] =3D IOV_OF_LVALUE(udp_eth_hdr[i]); > tiov[UDP_IOV_TAP] =3D tap_hdr_iov(c, &meta->taph); > tiov[UDP_IOV_PAYLOAD].iov_base =3D payload; > =20 > @@ -253,9 +253,6 @@ static void udp_iov_init(const struct ctx *c) > { > size_t i; > =20 > - udp4_eth_hdr.h_proto =3D htons_constant(ETH_P_IP); > - udp6_eth_hdr.h_proto =3D htons_constant(ETH_P_IPV6); > - > for (i =3D 0; i < UDP_MAX_FRAMES; i++) > udp_iov_init_one(c, i); > } > @@ -352,31 +349,34 @@ size_t udp_update_hdr6(struct ipv6hdr *ip6h, struct= udp_payload_t *bp, > * udp_tap_prepare() - Convert one datagram into a tap frame > * @mmh: Receiving mmsghdr array > * @idx: Index of the datagram to prepare > + * @uflow: UDP flow > * @toside: Flowside for destination side > * @no_udp_csum: Do not set UDP checksum > */ > static void udp_tap_prepare(const struct mmsghdr *mmh, > - unsigned idx, const struct flowside *toside, > + unsigned int idx, > + const struct udp_flow *uflow, I'd be inclined to pass the MAC address specifically, rather than the entire flow. > + const struct flowside *toside, > bool no_udp_csum) > { > struct iovec (*tap_iov)[UDP_NUM_IOVS] =3D &udp_l2_iov[idx]; > struct udp_payload_t *bp =3D &udp_payload[idx]; > struct udp_meta_t *bm =3D &udp_meta[idx]; > + struct ethhdr *eh =3D (*tap_iov)[UDP_IOV_ETH].iov_base; > size_t l4len; > =20 > + eth_update_mac(eh, 0, uflow->f.omac); > if (!inany_v4(&toside->eaddr) || !inany_v4(&toside->oaddr)) { > l4len =3D udp_update_hdr6(&bm->ip6h, bp, toside, > mmh[idx].msg_len, no_udp_csum); > - tap_hdr_update(&bm->taph, l4len + sizeof(bm->ip6h) + > - sizeof(udp6_eth_hdr)); > - (*tap_iov)[UDP_IOV_ETH] =3D IOV_OF_LVALUE(udp6_eth_hdr); > + tap_hdr_update(&bm->taph, l4len + sizeof(bm->ip6h) + ETH_HLEN); > + eh->h_proto =3D htons_constant(ETH_P_IPV6); > (*tap_iov)[UDP_IOV_IP] =3D IOV_OF_LVALUE(bm->ip6h); > } else { > l4len =3D udp_update_hdr4(&bm->ip4h, bp, toside, > mmh[idx].msg_len, no_udp_csum); > - tap_hdr_update(&bm->taph, l4len + sizeof(bm->ip4h) + > - sizeof(udp4_eth_hdr)); > - (*tap_iov)[UDP_IOV_ETH] =3D IOV_OF_LVALUE(udp4_eth_hdr); > + tap_hdr_update(&bm->taph, l4len + sizeof(bm->ip4h) + ETH_HLEN); > + eh->h_proto =3D htons_constant(ETH_P_IP); > (*tap_iov)[UDP_IOV_IP] =3D IOV_OF_LVALUE(bm->ip4h); > } > (*tap_iov)[UDP_IOV_PAYLOAD].iov_len =3D l4len; > @@ -801,13 +801,14 @@ static void udp_buf_sock_to_tap(const struct ctx *c= , int s, int n, > flow_sidx_t tosidx) > { > const struct flowside *toside =3D flowside_at_sidx(tosidx); > + const struct udp_flow *uflow =3D udp_at_sidx(tosidx); > int i; > =20 > if ((n =3D udp_sock_recv(c, s, udp_mh_recv, n)) <=3D 0) > return; > =20 > for (i =3D 0; i < n; i++) > - udp_tap_prepare(udp_mh_recv, i, toside, false); > + udp_tap_prepare(udp_mh_recv, i, uflow, toside, false); > =20 > tap_send_frames(c, &udp_l2_iov[0][0], UDP_NUM_IOVS, n); > } --=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 --cladUhWawX+08kfm Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmh+9UgACgkQzQJF27ox 2GfFYg/+PrRNcZwVndTzzoNPgQHhpi//urzq3IdOxJNfBvu4vzEyE3LyIUFLDnyL Ji0s3g9IEVs7Tx1HnWknj1M7hkYkVJPluOOeX7Ut/Xf4EtrWX6gUU/W/azC3wi22 WSvSe75i1oMTCpjHxau3oQ0bDCoKDWI6mKTYwF77FG3VUI9xKF6GYGt+U6QIOA8l AscAmEvRNLKEEYQ35vxU3esX3yJCxLAslhIZLItpqgtqFYmWfuNo3W3E8v+7cW/f NCTZvcPd7DReuZ0UDY6CQE9y73rjQ/61l3241XvB6rBVRoqsUFz3mkV2pVLezIN+ kCnTXkyBQPRcI66Tvsvgz3FUWHj687zTqmNW6uqaEuAAfzf39N0b4QW7cEtRFBNF SR75mvPA6BIPsa7xVDA7WNXiO3JiqqlFP+/IFdBNsKVV3dy7QxyqNtxFvv3li53E ex4RUmKE2NrmVEGxH63+nzo9enzbZ3ooWHn3HwaoLYnUVOBk4WZBVyoKJGplORpv wLnsDwmYPmZ8aGqyQgXJrPOy14AhEgnKezjKPKjMWQ3otZ6E0xQ9aGJzCs1fsPDS ePsFNc6S+1t9ZRP3UioBWaCaRZdYzVt0cWrQMg5WT8T3imf3Q+X3U2tvO3W+gRiq JPoZ0gyjLMOxV3hWNWPPgFfAKBE78LR/dIpuY52PhDevjjzM/2k= =Gx/Z -----END PGP SIGNATURE----- --cladUhWawX+08kfm--