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=vv74Ff+0; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 71B3C5A0280 for ; Tue, 22 Jul 2025 04:29:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202506; t=1753151232; bh=QSUbBxbwCi2MJeNP7WA1+fGHplOGSB9kbRUAaZyZLBY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=vv74Ff+0Bb72eTIxuEpZ+hjev8BUCHsMRfS8b5Lvz0tP3xSr+hDAF7lDmS3+eeNfL ZEIpFcOfUtiP4c6HNlqfyGAMttpk67781W0LWIApYHxEevslBUPQimXun4E+Ld13Wz YsdLyfME5kVongbNNqQA5O/+lGXDsSCOqW0Mxu93vXe6GD/iD2oi9mnfAm+u97EvHI 3hvnW5Kf7pB+99cokjXdOjyX5DAf28Qipai+x2piBNSzkicVwZ+tYwuzxbGhl8NYf6 vH46G7hHAkNWUIG0/9me+dTaGOQCtMLfmU+JdUIytDHEtDzNBswutfKJMsabcIm4mq RpfovnsTSGQgA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4bmLkm233dz4x4w; Tue, 22 Jul 2025 12:27:12 +1000 (AEST) Date: Tue, 22 Jul 2025 12:29:29 +1000 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v3 5/8] tcp: forward external source MAC address through tap interface Message-ID: References: <20250629171348.86323-1-jmaloy@redhat.com> <20250629171348.86323-6-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="6rCeBbLPFI4oqNMN" Content-Disposition: inline In-Reply-To: <20250629171348.86323-6-jmaloy@redhat.com> Message-ID-Hash: LFFHTSRJDLWJIXGETLK3DOX2KVFG2PJO X-Message-ID-Hash: LFFHTSRJDLWJIXGETLK3DOX2KVFG2PJO 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: --6rCeBbLPFI4oqNMN Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Jun 29, 2025 at 01:13:44PM -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 > --- > tcp.c | 5 ++++- > tcp_buf.c | 27 +++++++++++++-------------- > tcp_internal.h | 2 +- > tcp_vu.c | 5 ++--- > 4 files changed, 20 insertions(+), 19 deletions(-) >=20 > diff --git a/tcp.c b/tcp.c > index f43c1e2..057ee93 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -920,7 +920,7 @@ static void tcp_fill_header(struct tcphdr *th, > * @no_tcp_csum: Do not set TCP checksum > */ > void tcp_fill_headers(const struct tcp_tap_conn *conn, > - struct tap_hdr *taph, > + struct tap_hdr *taph, struct ethhdr *eh, > struct iphdr *ip4h, struct ipv6hdr *ip6h, > struct tcphdr *th, struct iov_tail *payload, > const uint16_t *ip4_check, uint32_t seq, bool no_tcp_csum) > @@ -952,6 +952,7 @@ void tcp_fill_headers(const struct tcp_tap_conn *conn, > psum =3D proto_ipv4_header_psum(l4len, IPPROTO_TCP, > *src4, *dst4); > } > + eh->h_proto =3D htons_constant(ETH_P_IP); > } > =20 > if (ip6h) { > @@ -972,7 +973,9 @@ void tcp_fill_headers(const struct tcp_tap_conn *conn, > &ip6h->saddr, > &ip6h->daddr); > } > + eh->h_proto =3D htons_constant(ETH_P_IPV6); > } > + eth_update_mac(eh, 0, conn->f.omac); s/0/NULL/ please. > tcp_fill_header(th, conn, seq); > =20 > diff --git a/tcp_buf.c b/tcp_buf.c > index d1fca67..85df5c7 100644 > --- a/tcp_buf.c > +++ b/tcp_buf.c > @@ -40,8 +40,7 @@ > /* Static buffers */ > =20 > /* Ethernet header for IPv4 and IPv6 frames */ > -static struct ethhdr tcp4_eth_src; > -static struct ethhdr tcp6_eth_src; > +static struct ethhdr tcp_eth_hdr[TCP_FRAMES_MEM]; As with UDP, I think this should be folded into tap_hdr, but that could be a follow up. > static struct tap_hdr tcp_payload_tap_hdr[TCP_FRAMES_MEM]; > =20 > @@ -71,8 +70,10 @@ static struct iovec tcp_l2_iov[TCP_FRAMES_MEM][TCP_NUM= _IOVS]; > */ > void tcp_update_l2_buf(const unsigned char *eth_d, const unsigned char *= eth_s) > { > - eth_update_mac(&tcp4_eth_src, eth_d, eth_s); > - eth_update_mac(&tcp6_eth_src, eth_d, eth_s); > + int i; > + > + for (i =3D 0; i < TCP_FRAMES_MEM; i++) > + eth_update_mac(&tcp_eth_hdr[i], eth_d, eth_s); I don't think eth_s is relevant here any more - you're setting it on every frame. > } > =20 > /** > @@ -85,8 +86,8 @@ void tcp_sock_iov_init(const struct ctx *c) > struct iphdr iph =3D L2_BUF_IP4_INIT(IPPROTO_TCP); > int i; > =20 > - tcp6_eth_src.h_proto =3D htons_constant(ETH_P_IPV6); > - tcp4_eth_src.h_proto =3D htons_constant(ETH_P_IP); > + for (i =3D 0; i < TCP_FRAMES_MEM; i++) > + eth_update_mac(&tcp_eth_hdr[i], NULL, c->our_tap_mac); Likewise here, AFAICT this will always be overwritten on each frame. > for (i =3D 0; i < ARRAY_SIZE(tcp_payload); i++) { > tcp6_payload_ip[i] =3D ip6; > @@ -164,6 +165,7 @@ static void tcp_l2_buf_fill_headers(const struct tcp_= tap_conn *conn, > struct tap_hdr *taph =3D iov[TCP_IOV_TAP].iov_base; > const struct flowside *tapside =3D TAPFLOW(conn); > const struct in_addr *a4 =3D inany_v4(&tapside->oaddr); > + struct ethhdr *eh =3D iov[TCP_IOV_ETH].iov_base; > struct ipv6hdr *ip6h =3D NULL; > struct iphdr *ip4h =3D NULL; > =20 > @@ -172,7 +174,7 @@ static void tcp_l2_buf_fill_headers(const struct tcp_= tap_conn *conn, > else > ip6h =3D iov[TCP_IOV_IP].iov_base; > =20 > - tcp_fill_headers(conn, taph, ip4h, ip6h, th, &tail, > + tcp_fill_headers(conn, taph, eh, ip4h, ip6h, th, &tail, > check, seq, no_tcp_csum); > } > =20 > @@ -194,14 +196,12 @@ int tcp_buf_send_flag(const struct ctx *c, struct t= cp_tap_conn *conn, int flags) > int ret; > =20 > iov =3D tcp_l2_iov[tcp_payload_used]; > - if (CONN_V4(conn)) { > + if (CONN_V4(conn)) > iov[TCP_IOV_IP] =3D IOV_OF_LVALUE(tcp4_payload_ip[tcp_payload_used]); > - iov[TCP_IOV_ETH].iov_base =3D &tcp4_eth_src; > - } else { > + else > iov[TCP_IOV_IP] =3D IOV_OF_LVALUE(tcp6_payload_ip[tcp_payload_used]); > - iov[TCP_IOV_ETH].iov_base =3D &tcp6_eth_src; > - } > =20 > + iov[TCP_IOV_ETH] =3D IOV_OF_LVALUE(tcp_eth_hdr[tcp_payload_used]); > payload =3D iov[TCP_IOV_PAYLOAD].iov_base; > seq =3D conn->seq_to_tap; > ret =3D tcp_prepare_flags(c, conn, flags, &payload->th, > @@ -259,11 +259,10 @@ static void tcp_data_to_tap(const struct ctx *c, st= ruct tcp_tap_conn *conn, > check =3D &iph->check; > } > iov[TCP_IOV_IP] =3D IOV_OF_LVALUE(tcp4_payload_ip[tcp_payload_used]); > - iov[TCP_IOV_ETH].iov_base =3D &tcp4_eth_src; > } else if (CONN_V6(conn)) { > iov[TCP_IOV_IP] =3D IOV_OF_LVALUE(tcp6_payload_ip[tcp_payload_used]); > - iov[TCP_IOV_ETH].iov_base =3D &tcp6_eth_src; > } > + iov[TCP_IOV_ETH].iov_base =3D &tcp_eth_hdr[tcp_payload_used]; > payload =3D iov[TCP_IOV_PAYLOAD].iov_base; > payload->th.th_off =3D sizeof(struct tcphdr) / 4; > payload->th.th_x2 =3D 0; > diff --git a/tcp_internal.h b/tcp_internal.h > index 36c6533..6c2d1ef 100644 > --- a/tcp_internal.h > +++ b/tcp_internal.h > @@ -167,7 +167,7 @@ void tcp_rst_do(const struct ctx *c, struct tcp_tap_c= onn *conn); > struct tcp_info_linux; > =20 > void tcp_fill_headers(const struct tcp_tap_conn *conn, > - struct tap_hdr *taph, > + struct tap_hdr *taph, struct ethhdr *eh, > struct iphdr *ip4h, struct ipv6hdr *ip6h, > struct tcphdr *th, struct iov_tail *payload, > const uint16_t *ip4_check, uint32_t seq, bool no_tcp_csum); > diff --git a/tcp_vu.c b/tcp_vu.c > index f3914c7..da1fb37 100644 > --- a/tcp_vu.c > +++ b/tcp_vu.c > @@ -135,7 +135,7 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_= tap_conn *conn, int flags) > flags_elem[0].in_sg[0].iov_len =3D hdrlen + optlen; > payload =3D IOV_TAIL(flags_elem[0].in_sg, 1, hdrlen); > =20 > - tcp_fill_headers(conn, NULL, ip4h, ip6h, th, &payload, > + tcp_fill_headers(conn, NULL, eh, ip4h, ip6h, th, &payload, > NULL, seq, !*c->pcap); > =20 > if (*c->pcap) { > @@ -315,7 +315,6 @@ static void tcp_vu_prepare(const struct ctx *c, struc= t tcp_tap_conn *conn, > eh =3D vu_eth(base); > =20 > memcpy(eh->h_dest, c->guest_mac, sizeof(eh->h_dest)); > - memcpy(eh->h_source, c->our_tap_mac, sizeof(eh->h_source)); > =20 > /* initialize header */ > =20 > @@ -339,7 +338,7 @@ static void tcp_vu_prepare(const struct ctx *c, struc= t tcp_tap_conn *conn, > th->ack =3D 1; > th->psh =3D push; > =20 > - tcp_fill_headers(conn, NULL, ip4h, ip6h, th, &payload, > + tcp_fill_headers(conn, NULL, eh, ip4h, ip6h, th, &payload, > *check, conn->seq_to_tap, no_tcp_csum); > if (ip4h) > *check =3D &ip4h->check; --=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 --6rCeBbLPFI4oqNMN Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmh+94gACgkQzQJF27ox 2GcE1w/+Kl2tnnx7sGbkfrsLLOyyxgmoVAUBCJgkb1u2gCdogY29OXaxcZBoIuSG m8DoTH+XBw13HMRvqNgUdSuE9TogBuF7LMubgW7YWzVMpCI5B2ZwbofReuei3Uh1 jDiQo1r8I14Pb5Tes+bx5T20kiBoC8Fs+dbyxAc8Q9GQgGmroll/jHWwLc/OpkhX 5nQMoWtWlUbFySeUOSlZRhw48zu8SQuJFzs3gcP4L8TUSRHQqFoll+kpGpTDeldL tm1yytJYa66xaXre1RS/Twn7JDc9A5zYOAYiXyDBtEUQw2GTtyCHwDOxbMwknbkG Tn8lSy2mPJNDZgxVXyrzH5U2/dLkVLHpJ8z6EbtFXVd/wZml7GDkHJ2iLv/cIAsS YN5iliImo5UKebn5gJAGKeg7deb0qBFx/pjuY1FVxg3B6YFVILxH4aoAMnAp70xd OKXoROtmqFTNibW7XzH80rLKEUG7HBIklpcXD4PBhSCxAFgW4Nd/2PT48rz4lhuv gpyVx+t1jAAUsXIMjl4CptWUrig+0VCGZBtY6AZ43JoYoepwzjoo7rQIl9Tw3SbI dc7CjO3a6n+v7mk2U/M7iMhFU2YLh+9xFQLJWrBtQYE0XYiubfh5qM//+A6zIDEB ko0slfQ4s214ybRxFFvzpDeilcLIT/bFWtDzCt5zXLv2wl8eAsQ= =ICnO -----END PGP SIGNATURE----- --6rCeBbLPFI4oqNMN--