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=WgSbc3gV; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 215EA5A0284 for ; Tue, 22 Jul 2025 04:44:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202506; t=1753152124; bh=jPgw6Z1qiuyTnoSwNdxipy3wMNu/izPhmHnP5O6cMDs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=WgSbc3gVlRyepZZRQjy/VRpA5iHjH4Lh6TA3cMrYHYh9vR6c+bHjCotjT9oihD+w4 mQYgMmzIwUXbMLhp5GhTbxI6f20sKsvx46yGaiKnOAAmCy+OKCzdhSDe354lacgZcw x8sBwyABMHtt0ZS2BfFmQ6PYRxigzfiJ+oaGY//7Dk5Lpn3Qu0uPt3msT59BY0tJ6R rTfqzVKDYmmdbRwSdfK3elk+WaoSPERZcvE5ks6h2yknxU6uw2NtZ8MlFJvgl+vqky DXrV2X5UYwj85xZkFEgR6ZlNCWvsNwbb1mI/d2/mR2kiu4oszDrvnoIHShVbap0Ti5 8e6mIau94SeAw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4bmM3w3PDKz4x3p; Tue, 22 Jul 2025 12:42:04 +1000 (AEST) Date: Tue, 22 Jul 2025 12:36:53 +1000 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v3 6/8] tap: change signature of function tap_push_l2h() Message-ID: References: <20250629171348.86323-1-jmaloy@redhat.com> <20250629171348.86323-7-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="C74bsKotOGq/55qL" Content-Disposition: inline In-Reply-To: <20250629171348.86323-7-jmaloy@redhat.com> Message-ID-Hash: AR5YDT7VVAA6VDEFYDN5BUGWPUCDLFOM X-Message-ID-Hash: AR5YDT7VVAA6VDEFYDN5BUGWPUCDLFOM 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: --C74bsKotOGq/55qL Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Jun 29, 2025 at 01:13:45PM -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 >=20 > --- > v3: Improved comment for src_mac argument, as suggested by Stefano. > --- > tap.c | 18 +++++++++++------- > tap.h | 3 ++- > tcp.c | 4 ++-- > 3 files changed, 15 insertions(+), 10 deletions(-) >=20 > diff --git a/tap.c b/tap.c > index 6db5d88..ceb9d9f 100644 > --- a/tap.c > +++ b/tap.c > @@ -171,17 +171,21 @@ 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. NULL means de= fault > * @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 */ I think the comment should stay. To my understanding this was never talking about this ARP lookup of the peer, but about sending ARPs to the guest to get its MAC, rather than just knowing it from other channels. > memcpy(eh->h_dest, c->guest_mac, ETH_ALEN); > - memcpy(eh->h_source, c->our_tap_mac, ETH_ALEN); > + if (src_mac) > + memcpy(eh->h_source, src_mac, ETH_ALEN); I'm not sure this NULL handling adds much. The callers can pass &c->our_tap_mac explicitly if that's what they want, with not much loss of brevity. > + else > + memcpy(eh->h_source, c->our_tap_mac, ETH_ALEN); > eh->h_proto =3D ntohs(proto); > return eh + 1; > } > @@ -261,7 +265,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, NULL, 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 +285,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, NULL, ETH_P_IP); > struct icmphdr *icmp4h =3D tap_push_ip4h(ip4h, src, dst, > l4len, IPPROTO_ICMP); > =20 > @@ -367,7 +371,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, NULL, ETH_P_IPV6); > 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 +393,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, NULL, ETH_P_IPV6); > struct icmp6hdr *icmp6h =3D tap_push_ip6h(ip6h, src, dst, l4len, > IPPROTO_ICMPV6, 0); > =20 > diff --git a/tap.h b/tap.h > index 6fe3d15..e640d95 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 057ee93..3ecf9e8 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -1898,7 +1898,7 @@ 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, NULL, ETH_P_IP); > const struct in_addr *rst_src =3D daddr; > const struct in_addr *rst_dst =3D saddr; > =20 > @@ -1908,7 +1908,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, NULL, ETH_P_IPV6); > const struct in6_addr *rst_src =3D daddr; > const struct in6_addr *rst_dst =3D saddr; > =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 --C74bsKotOGq/55qL Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmh++UQACgkQzQJF27ox 2Ge3Cw/+PaPyCEJUAsBdeuY8PvlzRHIrX3z6GRQu4WAd43a8e7JG+4rYA15a6fet p3i7W5WVAKUb4ghhqc/eCAFwS6morU0eDxUUntGlgybMo36qczsHbE2Q6HLWiQnW oMuiKeU8WHiZAb1O3DCvN4S2CRMCnvLH7pfIo3b4ARWCIF4WgVjMCZr9PN3TOiNR D5hSM9P+ki91yD+OCpkvKKUoRQerGlDNaIHE48IJlAbaLpMWwzHf9E8qZgBYMpFz JlxWbgs1wJeguTl34QWdR8/zAKqa5tYybcgnBzZem/DN+DhG6F5pKcsKgRa5A9Ox WuBbj9nObTcwgMntsDokCVdLMedQq358U6SqH9Wqy3lCIyXCso/Xf75ancUFcKwQ n53kY0lm3v5kmnO4VFprRs0MsARAyYFwDEPM9lDJHVIc1yVJtpQzYTriYjyOtpSv QCkGyil0B6fCUeYDlpTnHC2MoZqJ8zsMFgg/ngbdFDRCCTQqeGhq7BngHp+Zn9qs iO9rCDJgLM1gEJpvFQsGUqEcUokNYLFntjfpBzVGrAY5rSwntd7WHV/2zD60b0VY v0/nPSEEyviiN4HpXtOF2VgmREtik5/UJSIbrApnld+g0ewMKxG2nwig5ZEXBbDo u10pvrADh1tPIzjWhYeWeotLH5oMECAcEkVMsrtbWhk38fhPvsQ= =fCTS -----END PGP SIGNATURE----- --C74bsKotOGq/55qL--