From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RoaYrZbw; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 25F2B5A0272 for ; Tue, 30 Sep 2025 23:30:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1759267820; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uGoPvIbX19bAFSliY9ptG5nRkqdEi/WULiAPIPs8onE=; b=RoaYrZbwQ5PahqZP6NllgvlUWcehG9FXjsyKpn86/Cs2gAEn+uLBcPa36evI35bZAdv1jb pdsAAJoUUz3qZFXhoGBJi591K6J/y+7a5/U7AlsxAK0dCt20heJJ8ss+pvPqiJAz89zIVp 7ixkzz+iq240F8FDT1LIzCO0fPlYrgE= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-9-weetc5neNua9y82nJJjX0g-1; Tue, 30 Sep 2025 17:30:18 -0400 X-MC-Unique: weetc5neNua9y82nJJjX0g-1 X-Mimecast-MFC-AGG-ID: weetc5neNua9y82nJJjX0g_1759267817 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-41066f050a4so3171546f8f.1 for ; Tue, 30 Sep 2025 14:30:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759267817; x=1759872617; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=uGoPvIbX19bAFSliY9ptG5nRkqdEi/WULiAPIPs8onE=; b=s2X6tvIiEg9INiFSCMDN8pMRosdc0LNknLvc9NAuatXp4XoGosfH8+TZw2v/gBT/+e kP4n4/O/Ldq7IhC/Y+aTZtYg/MmHCOtQgp48VUbddBL2zWqinXs91GNbWI1mqRkBtOq8 5YvQ424sYD2ncC1QpPOBrT/5+OXKhsNPY31WpQZGGBDSRCWA1lPne9xxZMbqfbi1RNs+ bHxrwyWyYcOHe6+2T72eIBp5zsRjl3fZzA1ASAf/4iGVfwOXVTMkIkHJZ5fgUSiWRHMw BIoDI70S2xkvigoxmws58hsPq7BnTS1dYKwPB0lX2dRvq5bABduECT+4Y7Sl4peryHmx Oi0Q== X-Forwarded-Encrypted: i=1; AJvYcCVQQmPJYNRRjUcolsk3D2ePSmsGYfdLeSJ0dGrDz6QCdq7LpmWmXa7I3Ib7cKWRclZCw0xMwtm7mWk=@passt.top X-Gm-Message-State: AOJu0Yzv5DQ+YHv5atu0v5nDKRFkInxOQ6DvQQVM1v/rUlzqCoSVVk03 BX4psnBjt35jRQamWL3uimTWXIPZ7X4w0Lhf69Fc5IEmNg2/FLxJ4GYqJRvUput2r5Aq/GPMHBt 7fSFUp6KCQz1nLOogbaR9x/oME2xhemWer22dL9fpsEhhgmiireSjPQ== X-Gm-Gg: ASbGncs9iv4Ok4S6HCd69HreQdH0YUUSlXehUyQ4jO/LuzIIcWc5ooCr+rQvuadPd1e HlWyHWE2wxHUIQlCHW0zRDEwuFc1d3stkFflEiwUot7zHWuNwEn7Xof6274KYBVERXpKcsudZBR YSXhGAxAkuhlxp6yIsArOU+y8/SRC60h9u/+MKkbwNPEhmH/dOLl6KJLbKPePDHZ28DopTE1YXq SQNgdfRVNbgPhtRyh3zBwAGKUr3og6nUFReaX6R8iEzAJS/0SoaHG8j7IH/QXMgDnj8NE6FFqCj 3LA4H0tmxOQ0nuyW5yFvNPyHiBRI2sUTQB0+Xi9l29OhvtmrxNEgU4A0GepRu904ZkfIKnX72A= = X-Received: by 2002:a05:6000:186e:b0:3e9:b208:f2d2 with SMTP id ffacd0b85a97d-42557a15a22mr859669f8f.50.1759267817114; Tue, 30 Sep 2025 14:30:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFySqvy7atxR/tWuFpW/XmYZa/32IAfIjLR9SwkT+HRNRmZ4GYjbrjFuq+0fZJIj9LYW9eOxg== X-Received: by 2002:a05:6000:186e:b0:3e9:b208:f2d2 with SMTP id ffacd0b85a97d-42557a15a22mr859650f8f.50.1759267816606; Tue, 30 Sep 2025 14:30:16 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-46e6199193dsm9809345e9.1.2025.09.30.14.30.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Sep 2025 14:30:16 -0700 (PDT) Date: Tue, 30 Sep 2025 23:30:15 +0200 From: Stefano Brivio To: Jon Maloy Subject: Re: [PATCH v11 8/9] tap: change signature of function tap_push_l2h() Message-ID: <20250930233015.752d6ed5@elisabeth> In-Reply-To: <20250927192522.3024554-9-jmaloy@redhat.com> References: <20250927192522.3024554-1-jmaloy@redhat.com> <20250927192522.3024554-9-jmaloy@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.49; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: n9vfjOPSmAWSXoaL5T_qvcmJYrhu77vHjZzcmJUBtf8_1759267817 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: JF2BOMZR6VJBTGV5RE4YRLY2KFCVN5EN X-Message-ID-Hash: JF2BOMZR6VJBTGV5RE4YRLY2KFCVN5EN X-MailFrom: sbrivio@redhat.com 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: dgibson@redhat.com, david@gibson.dropbear.id.au, 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: On Sat, 27 Sep 2025 15:25:21 -0400 Jon Maloy wrote: > In the next commit 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 any logical changes. > > Signed-off-by: Jon Maloy > Reviewed-by: David Gibson > > --- > 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(-) > > diff --git a/tap.c b/tap.c > index 250a0f6..ec7e525 100644 > --- a/tap.c > +++ b/tap.c > @@ -171,17 +171,19 @@ const struct in6_addr *tap_ip6_daddr(const struct ctx *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. Trailing . which we never use. > * @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 = (struct ethhdr *)buf; > > - /* TODO: ARP table lookup */ > + /* TODO: ARP lookup on tap side */ Why? I mean, what would we do with guest-side MAC addresses, as we don't control Layer-2 host-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 = ntohs(proto); > return eh + 1; > } > @@ -261,7 +263,7 @@ void tap_udp4_send(const struct ctx *c, struct in_addr src, in_port_t sport, > { > size_t l4len = dlen + sizeof(struct udphdr); > char buf[USHRT_MAX]; > - struct iphdr *ip4h = tap_push_l2h(c, buf, ETH_P_IP); > + struct iphdr *ip4h = tap_push_l2h(c, buf, c->our_tap_mac, ETH_P_IP); > struct udphdr *uh = tap_push_ip4h(ip4h, src, dst, l4len, IPPROTO_UDP); > char *data = tap_push_uh4(uh, src, sport, dst, dport, in, dlen); > > @@ -281,7 +283,7 @@ void tap_icmp4_send(const struct ctx *c, struct in_addr src, struct in_addr dst, > const void *in, size_t l4len) > { > char buf[USHRT_MAX]; > - struct iphdr *ip4h = tap_push_l2h(c, buf, ETH_P_IP); > + struct iphdr *ip4h = tap_push_l2h(c, buf, c->our_tap_mac, ETH_P_IP); > struct icmphdr *icmp4h = tap_push_ip4h(ip4h, src, dst, > l4len, IPPROTO_ICMP); > > @@ -367,7 +369,7 @@ void tap_udp6_send(const struct ctx *c, > { > size_t l4len = dlen + sizeof(struct udphdr); > char buf[USHRT_MAX]; > - struct ipv6hdr *ip6h = tap_push_l2h(c, buf, ETH_P_IPV6); > + struct ipv6hdr *ip6h = tap_push_l2h(c, buf, c->our_tap_mac, ETH_P_IPV6); > struct udphdr *uh = tap_push_ip6h(ip6h, src, dst, > l4len, IPPROTO_UDP, flow); > char *data = 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 = tap_push_l2h(c, buf, ETH_P_IPV6); > + struct ipv6hdr *ip6h = tap_push_l2h(c, buf, c->our_tap_mac, ETH_P_IPV6); > struct icmp6hdr *icmp6h = tap_push_ip6h(ip6h, src, dst, l4len, > IPPROTO_ICMPV6, 0); > > 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) > } > > 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 sport, > diff --git a/tcp.c b/tcp.c > index af05d35..b874317 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -1978,7 +1978,8 @@ static void tcp_rst_no_conn(const struct ctx *c, int af, > return; > > if (af == AF_INET) { > - struct iphdr *ip4h = tap_push_l2h(c, buf, ETH_P_IP); > + struct iphdr *ip4h = tap_push_l2h(c, buf, c->our_tap_mac, > + ETH_P_IP); > const struct in_addr *rst_src = daddr; > const struct in_addr *rst_dst = saddr; > > @@ -1988,7 +1989,7 @@ static void tcp_rst_no_conn(const struct ctx *c, int af, > *rst_src, *rst_dst); > > } else { > - struct ipv6hdr *ip6h = tap_push_l2h(c, buf, ETH_P_IPV6); > + struct ipv6hdr *ip6h = tap_push_l2h(c, buf, c->our_tap_mac, ETH_P_IPV6); This can and should be wrapped to 80 columns. > const struct in6_addr *rst_src = daddr; > const struct in6_addr *rst_dst = saddr; > -- Stefano