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=WZufrviN; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id EAE295A0271 for ; Mon, 08 Sep 2025 05:14:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202508; t=1757301250; bh=EGyaGZYZKh24xcAetj8BRkk3SvfkNuGqvFuKIDoS4y0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=WZufrviNjhuG3yoAjLnTHcpijmOG3tD6jZ3ydjbvaXguHyLXH4jqsVnkoc0MmlvKB gHtwRhD6TSoNiOyApWDTg07pVJtbmC/Ur5ck23RdFmlIL6w+knURre8ok35OI2k0Hp DMQSNsm8f+/RWowITr+yJapv7xpx8Qur+mTlf3PuX2RPBAGM0qFNBEPJHXJF/oEU0V aMe+7sr3yxYE6gimdMClZiABRYmZ+hTJZ+ICG3mzMloT2ousSKbY92nt47Ejkxsj6B dtiuxKuUgmWA+hNKAq3y5tqx4TP+To8kZpVgy2vGR6ERPU9swl8B4YU+wLLwT8iONc 4oN73ek6ZpSGQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4cKsVp5cb0z4w9v; Mon, 8 Sep 2025 13:14:10 +1000 (AEST) Date: Mon, 8 Sep 2025 13:13:35 +1000 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v5 06/10] udp: forward external source MAC address through tap interface Message-ID: References: <20250906021154.2760611-1-jmaloy@redhat.com> <20250906021154.2760611-7-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="yM4qZ6aukrAS9EgJ" Content-Disposition: inline In-Reply-To: <20250906021154.2760611-7-jmaloy@redhat.com> Message-ID-Hash: N6PWZWCRQEB5XKEHLTJ5BPAMREGXUSZN X-Message-ID-Hash: N6PWZWCRQEB5XKEHLTJ5BPAMREGXUSZN 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: --yM4qZ6aukrAS9EgJ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Sep 05, 2025 at 10:11:50PM -0400, Jon Maloy wrote: > We forward the incoming MAC address through the tap interface when > receiving incoming packets from network local hosts. >=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 Reviewed-by: David Gibson Modulo any changes that are needed because of changes in the earlier patches. > --- > v3: - Adapted to the move of external MAC address from struct flowside > to struct flow_common > v4: - Changed signature of udp_tap_prepare() to take a MAC address > instead of a flow. > - Eliminated initialization of MAC source address in all frames, > since those now are set per send occasion anyway. > v5: - Added lookup in ARP/NDP table on incoming messages in > case flow->tap_omac wasn't initialized at flow creation, > i.e., the flow was initiated from the guest. > --- > passt.c | 2 +- > udp.c | 45 +++++++++++++++++++++++++-------------------- > udp.h | 2 +- > 3 files changed, 27 insertions(+), 22 deletions(-) >=20 > diff --git a/passt.c b/passt.c > index a4ec115..2a28e20 100644 > --- a/passt.c > +++ b/passt.c > @@ -154,7 +154,7 @@ static void timer_init(struct ctx *c, const struct ti= mespec *now) > void proto_update_l2_buf(const unsigned char *eth_d, const unsigned char= *eth_s) > { > tcp_update_l2_buf(eth_d, eth_s); > - udp_update_l2_buf(eth_d, eth_s); > + udp_update_l2_buf(eth_d); > } > =20 > /** > diff --git a/udp.c b/udp.c > index 86585b7..7d98845 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]; > =20 > /** > * struct udp_meta_t - Pre-cooked headers for UDP packets > @@ -210,12 +207,13 @@ void udp_portmap_clear(void) > /** > * udp_update_l2_buf() - Update L2 buffers with Ethernet and IPv4 addres= ses > * @eth_d: Ethernet destination address, NULL if unchanged > - * @eth_s: Ethernet source address, NULL if unchanged > */ > -void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *= eth_s) > +void udp_update_l2_buf(const unsigned char *eth_d) > { > - 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, NULL); > } > =20 > /** > @@ -238,6 +236,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 +252,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 +348,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 > + * @tap_omac: MAC address of remote endpoint as seen from the guest > * @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 uint8_t *tap_omac, > + 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, NULL, tap_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 +800,19 @@ 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); > + struct udp_flow *uflow =3D udp_at_sidx(tosidx); > + uint8_t *omac =3D uflow->f.tap_omac; > int i; > =20 > if ((n =3D udp_sock_recv(c, s, udp_mh_recv, n)) <=3D 0) > return; > =20 > + /* Make one attempt to find true MAC address in ARP/NDP table */ > + if (mac_undefined(omac)) > + fwd_neigh_mac_get(c, &toside->oaddr, omac); > + > for (i =3D 0; i < n; i++) > - udp_tap_prepare(udp_mh_recv, i, toside, false); > + udp_tap_prepare(udp_mh_recv, i, omac, toside, false); > =20 > tap_send_frames(c, &udp_l2_iov[0][0], UDP_NUM_IOVS, n); > } > diff --git a/udp.h b/udp.h > index 8f8531a..dd6e5ad 100644 > --- a/udp.h > +++ b/udp.h > @@ -21,7 +21,7 @@ int udp_sock_init(const struct ctx *c, int ns, const un= ion inany_addr *addr, > const char *ifname, in_port_t port); > int udp_init(struct ctx *c); > void udp_timer(struct ctx *c, const struct timespec *now); > -void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *= eth_s); > +void udp_update_l2_buf(const unsigned char *eth_d); > =20 > /** > * union udp_listen_epoll_ref - epoll reference for "listening" UDP sock= ets > --=20 > 2.50.1 >=20 --=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 --yM4qZ6aukrAS9EgJ Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmi+Sd4ACgkQzQJF27ox 2GedCQ/9E8Q0B4Y1kX+TsfZnCG13C2hNeBqLxepVDOwWg+mJxHIojl1/oHCtNl28 hTBGNh3p5nGyIXaVvSI9itR6tcP1m3SJmfg19aXofEI2NvGBhO5S+At058NCKKlw l0yV49MxSRWRRBxEzlacBobIj0wsKMgphhS9xRZfBgyZ/B/mMbbalEritI90e+05 A10PadrirjPT4+6yt5T5veagPrBm7eh1awCLZHTNnIwu7e6SL2FV16b3JA+x1QGm eCa6a8l53NSNVMlUK1wZQcObtH1vzUPm4DrKq0d4gA6y5QPnVXtv8f9UC5sOJvMB bKg/jOa7G5vi/RqzpzlcexVnyMAT/opjPQX4VGp7OTboa8Q7EVQAqLO0+ZHYtRtQ TshnXI8VSZKF3n4FIIXqXy9Y6jo08FNlDgfjr/V0IQUVLXKl2hNQV3m1s2Njmvzd gsXidi0d/Y7DXdI6Lmk6+PmBhjzWdQJvvrh6QrmjJFaNseZbYly4Ycr2Wc0DX+NV Sn00ynckteEA/D6hHeHgatiapImNWgIGAmAfkA1Q/vc/BHCj2QIqNdow7NuRJ639 qcOvSUjMjqGUoGgEIsi8ZgYhV9iy4q3VMxJyyRgwumLcBwzOqgvomEMhCvfgSEeA lrNDxCrGV8Xk96DqfjwguuzuLhfSy1m2zLpdx+KlUE6IlefCybk= =Vamd -----END PGP SIGNATURE----- --yM4qZ6aukrAS9EgJ--