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=vT/Ou1Z2; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 7F1285A027A for ; Wed, 10 Sep 2025 04:57:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202508; t=1757473034; bh=a8m/WzQXSHW/0sMo9uohDEkW0Jo28l21hkt4BH2MR50=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=vT/Ou1Z2+NYrWW+GD64Zu4P7vLRlZ21sSGi/TYsoHYbhiohHKIPaHlG11VHSHmwp6 3AHeEKQbj+2MH13JtSf1IS6/PEoX8L0dyzjykvyJvvWo8CH6S7KGil68S+uU+T6njp 4CHEbTPn1/pRvz3Su19nutjPG30wvO3YFPAtPeU9BHIv/1WL8scjOPaYSZ4h4Gzr+C w2Wizr4AcHu8vrvk2OLVNyuObXwllrkpGhV1IwL1YYnqLqvkqnWWj7TU/T5Jh12s59 GbKK8PuXvlpAJ4E72PoQ7KtBIVdZ2OGtTMLvL2ZN4GX9bh1rQVOIPD5ahKX6pY9PLR AwgYk530NpudQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4cM52L30pQz4wC3; Wed, 10 Sep 2025 12:57:14 +1000 (AEST) Date: Wed, 10 Sep 2025 12:54:24 +1000 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v6 7/8] tap: change signature of function tap_push_l2h() Message-ID: References: <20250910015919.173414-1-jmaloy@redhat.com> <20250910015919.173414-8-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="9f19dOmCsVnDrHZD" Content-Disposition: inline In-Reply-To: <20250910015919.173414-8-jmaloy@redhat.com> Message-ID-Hash: 3ZGZ7ILQM453ESZRVFH72Q2E5KW5MKNR X-Message-ID-Hash: 3ZGZ7ILQM453ESZRVFH72Q2E5KW5MKNR 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: --9f19dOmCsVnDrHZD Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Sep 09, 2025 at 09:59:18PM -0400, Jon Maloy wrote: > In the following commits it must be possible for the callers of > function tap_push_l2h() to specify which source MAC address should > be added to the ethernet header sent over the tap interface. As > a preparation, we now add a new argument to that function, still > without actually using it. >=20 > Signed-off-by: Jon Maloy Reviewed-by: David Gibson >=20 > --- > v3: -Improved comment for src_mac argument, as suggested by Stefano. > v4: -Re-added comment in tap.c and remove redundant argument check > in tap_push_l2() > v5: -Ensured that MAC argument to tap_push_l2h() never is NULL. > v6: -Clarification of comment about ARP lookup > --- > tap.c | 16 +++++++++------- > tap.h | 3 ++- > tcp.c | 5 +++-- > 3 files changed, 14 insertions(+), 10 deletions(-) >=20 > diff --git a/tap.c b/tap.c > index 74557e1..a390be8 100644 > --- a/tap.c > +++ b/tap.c > @@ -171,17 +171,19 @@ const struct in6_addr *tap_ip6_daddr(const struct c= tx *c, > * tap_push_l2h() - Build an L2 header for an inbound packet > * @c: Execution context > * @buf: Buffer address at which to generate header > + * @src_mac: MAC address to be used as source for message. > * @proto: Ethernet protocol number for L3 > * > * Return: pointer at which to write the packet's payload > */ > -void *tap_push_l2h(const struct ctx *c, void *buf, uint16_t proto) > +void *tap_push_l2h(const struct ctx *c, void *buf, > + const void *src_mac, uint16_t proto) > { > struct ethhdr *eh =3D (struct ethhdr *)buf; > =20 > - /* TODO: ARP table lookup */ > + /* TODO: ARP lookup on tap side */ > memcpy(eh->h_dest, c->guest_mac, ETH_ALEN); > - memcpy(eh->h_source, c->our_tap_mac, ETH_ALEN); > + memcpy(eh->h_source, src_mac, ETH_ALEN); > eh->h_proto =3D ntohs(proto); > return eh + 1; > } > @@ -261,7 +263,7 @@ void tap_udp4_send(const struct ctx *c, struct in_add= r src, in_port_t sport, > { > 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 iphdr *ip4h =3D tap_push_l2h(c, buf, c->our_tap_mac, 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 > @@ -281,7 +283,7 @@ void tap_icmp4_send(const struct ctx *c, struct in_ad= dr src, struct in_addr dst, > const void *in, size_t l4len) > { > char buf[USHRT_MAX]; > - struct iphdr *ip4h =3D tap_push_l2h(c, buf, ETH_P_IP); > + struct iphdr *ip4h =3D tap_push_l2h(c, buf, c->our_tap_mac, ETH_P_IP); > struct icmphdr *icmp4h =3D tap_push_ip4h(ip4h, src, dst, > l4len, IPPROTO_ICMP); > =20 > @@ -367,7 +369,7 @@ void tap_udp6_send(const struct ctx *c, > { > size_t l4len =3D dlen + sizeof(struct udphdr); > char buf[USHRT_MAX]; > - struct ipv6hdr *ip6h =3D tap_push_l2h(c, buf, ETH_P_IPV6); > + struct ipv6hdr *ip6h =3D tap_push_l2h(c, buf, c->our_tap_mac, ETH_P_IPV= 6); > struct udphdr *uh =3D tap_push_ip6h(ip6h, src, dst, > l4len, IPPROTO_UDP, flow); > char *data =3D tap_push_uh6(uh, src, sport, dst, dport, in, dlen); > @@ -389,7 +391,7 @@ void tap_icmp6_send(const struct ctx *c, > const void *in, size_t l4len) > { > char buf[USHRT_MAX]; > - struct ipv6hdr *ip6h =3D tap_push_l2h(c, buf, ETH_P_IPV6); > + struct ipv6hdr *ip6h =3D tap_push_l2h(c, buf, c->our_tap_mac, ETH_P_IPV= 6); > struct icmp6hdr *icmp6h =3D tap_push_ip6h(ip6h, src, dst, l4len, > IPPROTO_ICMPV6, 0); > =20 > diff --git a/tap.h b/tap.h > index 21db4d2..02f7761 100644 > --- a/tap.h > +++ b/tap.h > @@ -70,7 +70,8 @@ static inline void tap_hdr_update(struct tap_hdr *thdr,= size_t l2len) > } > =20 > unsigned long tap_l2_max_len(const struct ctx *c); > -void *tap_push_l2h(const struct ctx *c, void *buf, uint16_t proto); > +void *tap_push_l2h(const struct ctx *c, void *buf, > + const void *src_mac, uint16_t proto); > void *tap_push_ip4h(struct iphdr *ip4h, struct in_addr src, > struct in_addr dst, size_t l4len, uint8_t proto); > void *tap_push_uh4(struct udphdr *uh, struct in_addr src, in_port_t spor= t, > diff --git a/tcp.c b/tcp.c > index 76fc0e4..b44fa62 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -1922,7 +1922,8 @@ static void tcp_rst_no_conn(const struct ctx *c, in= t af, > return; > =20 > if (af =3D=3D AF_INET) { > - struct iphdr *ip4h =3D tap_push_l2h(c, buf, ETH_P_IP); > + struct iphdr *ip4h =3D tap_push_l2h(c, buf, c->our_tap_mac, > + ETH_P_IP); > const struct in_addr *rst_src =3D daddr; > const struct in_addr *rst_dst =3D saddr; > =20 > @@ -1932,7 +1933,7 @@ static void tcp_rst_no_conn(const struct ctx *c, in= t af, > *rst_src, *rst_dst); > =20 > } else { > - struct ipv6hdr *ip6h =3D tap_push_l2h(c, buf, ETH_P_IPV6); > + struct ipv6hdr *ip6h =3D tap_push_l2h(c, buf, c->our_tap_mac, ETH_P_IP= V6); > const struct in6_addr *rst_src =3D daddr; > const struct in6_addr *rst_dst =3D saddr; > =20 > --=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 --9f19dOmCsVnDrHZD Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmjA6F8ACgkQzQJF27ox 2Gfdfw/+IId6qvKRiuPX0IGtQDYUVC3RTRsoEYUNgvN+Reso5o6eCwwIrgQe6U3p WsO9iB95PPeNWkSOr6VI6UblPFcL+irqQ3uOaU4O83iZKquQsgdLRKlyjrfl12ll R3MT3uXU452sx8I/ctaeA+CMFJ55LErpIdY5GTRWiXSmyK+wHI1EKLHvgQMfZze6 FobNUux+UcsuaI3w2bXS9DzJLthkS6Ve8iRXtZne5bgHDc/FtndCJXeLWHdh0Cu1 9gLeuVZqAHi2V1oM7iIq7vIUrjbZFLK1jiwUS23/fELcWbMylHF2Pl6Z4as6PWB0 +TrGmDU5Kaq5drJVQuM46s8P8dtuHWnGHJ42SdK8xX5TZRmF/Ud2m6cFRHC2L0IG GkBKoWITWWS5QgHlwM1KAnR4q4571ADGXCiHgGui2ITZQXZsR9CVa6WV80DiNdIr 4sErV42jD+yWd13QzwZ4bgqkKXKyJP9KxCngoqVRYBpMFwmYC+XzXWs6blL0Enz2 hRVgOHHoef+Zc+7vtNAYO+v3LSDDKjvrHFMcAfQZW5k8Pk/cIyr/Rx911R/gEyu9 m85+irjZnVv4ZvMPNGDPItdfPOp+OKITc0nr+8zvcxuP5Jq1GO+nFXvFt2S/Q9CN zlTShr8Qll0vzjek/XWQJ4g3pDsobOpOcW3xQ+/6YDGfdQ4MsWA= =wTR7 -----END PGP SIGNATURE----- --9f19dOmCsVnDrHZD--