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=AAmM36WJ; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 61AD35A0279 for ; Thu, 21 Aug 2025 04:03:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202508; t=1755741833; bh=eQbFS8aG0Z7s5rrEQ1+wLsTQhK0533e8nAR1TOswXNU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=AAmM36WJPOoF1Sb3wq+FUaCicGMS1L0arwLwducBH+oa+v+HLR87iF9V2VYLWEACG rxH5eRHLJd+2oVr3cY+NaM5mJSc18oOcJnygWWgWCgWdBPzfFGQFGi+YKSSjp2eRHN sA6Rc8hB1QYs4+zx+imxdhyYBNjhJERb0bx2gBqJH6vUdNRQ/8g6xlp59GkcbGYf+H 6zpbJujWm3/4jkA5yhI9gRkEZizl3Vo17S1LtWQ8CNkrKwzIP5GvDTSwiAQ8mccLmH Sbtal5T6hJ9fmsa5ssfMWmo+KqjUhZEDmC0uMaX7dx1O2r673Hy5yWeGbHIpedV9Td hgCgTkeBStm5Q== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4c6mp12D5nz4xQ1; Thu, 21 Aug 2025 12:03:53 +1000 (AEST) Date: Thu, 21 Aug 2025 11:39:19 +1000 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v4 6/9] tap: change signature of function tap_push_l2h() Message-ID: References: <20250820031005.2725591-1-jmaloy@redhat.com> <20250820031005.2725591-7-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="cYqqLJu6kjCfB6Zk" Content-Disposition: inline In-Reply-To: <20250820031005.2725591-7-jmaloy@redhat.com> Message-ID-Hash: G4LRFHAGOXBUZ5NWQ6LQCDYY2RMUZXTS X-Message-ID-Hash: G4LRFHAGOXBUZ5NWQ6LQCDYY2RMUZXTS 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: --cYqqLJu6kjCfB6Zk Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Aug 19, 2025 at 11:10:02PM -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 > --- > tap.c | 15 +++++++++------ > tap.h | 3 ++- > tcp.c | 4 ++-- > 3 files changed, 13 insertions(+), 9 deletions(-) >=20 > diff --git a/tap.c b/tap.c > index a5de8b7..0349835 100644 > --- a/tap.c > +++ b/tap.c > @@ -171,17 +171,20 @@ 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 */ > + > 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); This assumes that src_mac is non-NULL... > eh->h_proto =3D ntohs(proto); > return eh + 1; > } > @@ -261,7 +264,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); =2E.. but then you pass NULL. > 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 +284,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 +370,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 +392,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 936ae93..6ec171d 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 1dd2e24..bdcd477 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 --cYqqLJu6kjCfB6Zk Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmimeMYACgkQzQJF27ox 2GdTpRAAkagSz3GWSUVUgK/fihT06lqypmgCFgT1Jb2UikzOIsmwVgjJ4U+IMTVL hBp1ayltppO5l0EpX6dXYeEzgspg/JyTAhUL+WEOeCqWASWyvOLIYr7CXrpbunjk 8s32HFNvxDaD9d5KWgFzwfWN0740hTwdwvs1C4xD/4ehErjvuPDqGAXfQvA5yAb+ GfomhIvoiWyNz1CPpBmh2XXhdaZ8VCdvq8//M/fArF8L2CtPMRIPRDT2ynsfhu4q LvtpPDUa2ZvwvzLBRvwPMLQSZU/SC+S2DXWDXxQzX5fSmA2Sz+yDjSM0MfL37tpG KDQZ3JNh9jD67EQrDf0bhtdxBBiekhfeFgRHO9KnOb/GWgZkLmkgr2sfQsHkaUpz zhHohz7AipW40IvNVaJkve1rE5tAr6iIzoQEt0Nou4fAaaHes5spkzFvlFXd/j75 q8klabbP+hMun1iLw6M78JPNYqGn+Xy9WIWB4dLo0rJMoAzWyBQhqbc80gVQ6gku 9lmoxf0mMgpOdiH+ZNYoIpcV+SIqehE1PJsPDxGlyErq/3fOtpOG4dUHamYgHOkG MhMhcV64/3TiLOqrNtLbRDbR5TJLHICW5AGv4H4bK+Fb0j3LeG1OytcAII9CJVZD vvoS5U4WWyryHhF/VCubXC8Xw6ZqQzkrcNWyjOiQqhrivEgOICw= =xv+N -----END PGP SIGNATURE----- --cYqqLJu6kjCfB6Zk--