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=NcFFF0sv; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id 520495A028C for ; Thu, 12 Jun 2025 17:18:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749741481; 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=K+cm8/N9saNohqtgG3xnEYT5xLCQjJQALXTupCMWNiA=; b=NcFFF0svS1SFE/h/e/u1zT8vdfhirgmRNTLtFpJDjRYGAapPNWRo/6h+imi1G2LyaYZbr3 FJDF8Wktkm7j6n8sAmp4nRbYbOPZZyTKmWAznTgFp7CFWVX6/BK0eqYC4+dFyQa69p0Xtb kNXf8o8FY7NTtoNJZ0nRq9ZMHDbJwQ4= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-124-9WYCAv7TNrK14Xwcg2QOwQ-1; Thu, 12 Jun 2025 11:18:00 -0400 X-MC-Unique: 9WYCAv7TNrK14Xwcg2QOwQ-1 X-Mimecast-MFC-AGG-ID: 9WYCAv7TNrK14Xwcg2QOwQ_1749741479 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-451ecc3be97so4879355e9.0 for ; Thu, 12 Jun 2025 08:17:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749741478; x=1750346278; 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=K+cm8/N9saNohqtgG3xnEYT5xLCQjJQALXTupCMWNiA=; b=CDjDkjuCxnUa1VMm7Kc91L98e3FzHgHeH90IAX32QCg09yBFdCnbO3PkYw5HJMoCS7 ek5FnEXg5lLEMpxa/IC14GCI3lKf7T5HOcxYRjWprosG6egz77ZsRnIYasYVS6/UJJY7 wtEVBa3ob07c9WFyR0DQ+moSH0CwDtcvrjBpdDUR4GmCzw2DPdOPIwGCbn7UI9CGhhw9 c7aRE0JesHnuQ9Sv+hzm2y2Ox+EIdW9+wClQvoRFO2/fwFZTHYjteosABl/V7PQfxEeg g+02iPffx/yQ28yJYl1ncC/3E7OZUrlUkhceKlDf9uZ3xNc4JO6urFt7mWBy6ezetBzU UaAw== X-Forwarded-Encrypted: i=1; AJvYcCUwjdWD0C+cSRCPhudCBoAe14nbRJlmxF4iYrSYy30732N0ThABGGYpQ9VqEsIO6106fABs8rsYBzQ=@passt.top X-Gm-Message-State: AOJu0YwrhPVupRXSKNeJJHJK/A+2nYsZQo+jMxYFMSABNWSi3rFukCJA uVK3klcuJU//a5nQ0877VtGQXTiEyztgzhBdqAje9tVxdEyIDoStPilh+t06lTn7HxZv7Z2oyvn wkMOJl+cy+c05JrL1EaxafC4Ko0ttqqYlVCggaJ226epKE3g6IoX1UTN37Ci2efVZA58SfLU8ZH IjCMCRt8wT6ixCqg8OvU+QVMlt2dFwEHtwi6Gk X-Gm-Gg: ASbGncstPl5NDb1OxU+VKJuHV+j/QH2jrcNa7IZijkkdBd0EW57epzA4fbvRh8ab1JN 8KP4TggDqS3jUiIHLbfZiIeDrrjLb/VE9Xj5x/22x+Q5kgrN+m6M93cr1DJhSrvRYEnkRH+LRK0 b30zQoojWKY2v8OUewt9yP+oQ3dSDe3NzRSjnd59eUbAW/4Y4aKbhNOAK18SQjqfiD/Gp4TfWDh UY8axhKSXlOTMShiMeFVSe6UF7KvCGv3KqoZtOosK9gBDIpV0i+zMPBR8H65Xx3NTlsSIpq6BEy MES2kTSOPeaP1EALOaN4ZeywkfDmMc/ghw== X-Received: by 2002:a05:600c:3496:b0:43c:fa24:8721 with SMTP id 5b1f17b1804b1-453248f984cmr82076095e9.17.1749741478232; Thu, 12 Jun 2025 08:17:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF4KBexQjDuIBz5T41DOWLwqeQLB1VJpyLuUWM168cB4BH60J3mdxV+C3dbtK2fb7w6aJAxJQ== X-Received: by 2002:a05:600c:3496:b0:43c:fa24:8721 with SMTP id 5b1f17b1804b1-453248f984cmr82075445e9.17.1749741477691; Thu, 12 Jun 2025 08:17:57 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4532de8bd0bsm23646555e9.5.2025.06.12.08.17.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jun 2025 08:17:57 -0700 (PDT) Date: Thu, 12 Jun 2025 17:17:55 +0200 From: Stefano Brivio To: Jon Maloy Subject: Re: [PATCH v2 6/8] tap: change signature of function tap_push_l2h() Message-ID: <20250612171755.47860b51@elisabeth> In-Reply-To: <20250612042152.695879-7-jmaloy@redhat.com> References: <20250612042152.695879-1-jmaloy@redhat.com> <20250612042152.695879-7-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: xNLhqr8PlysSYPwgYJ1IjyB4W9wK4MyIISUEA2KH_DY_1749741479 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: VRIWYTTHZ5H5CXPCYDPQ6UJU3SRYVUOE X-Message-ID-Hash: VRIWYTTHZ5H5CXPCYDPQ6UJU3SRYVUOE 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, 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 Thu, 12 Jun 2025 00:21:50 -0400 Jon Maloy wrote: > In the following commits it must be possible for the callers of > funtion 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. > > Signed-off-by: Jon Maloy > --- > tap.c | 18 +++++++++++------- > tap.h | 3 ++- > tcp.c | 4 ++-- > 3 files changed, 15 insertions(+), 10 deletions(-) > > diff --git a/tap.c b/tap.c > index 6db5d88..634c012 100644 > --- a/tap.c > +++ b/tap.c > @@ -171,17 +171,21 @@ 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 Maybe ", NULL means default"? > * @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 */ > 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); > + else > + memcpy(eh->h_source, c->our_tap_mac, ETH_ALEN); > eh->h_proto = ntohs(proto); > return eh + 1; > } > @@ -261,7 +265,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, NULL, 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 +285,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, NULL, ETH_P_IP); > struct icmphdr *icmp4h = tap_push_ip4h(ip4h, src, dst, > l4len, IPPROTO_ICMP); > > @@ -367,7 +371,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, NULL, 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 +393,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, NULL, 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 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) > } > > 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 777f345..1a32424 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -1898,7 +1898,7 @@ 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, NULL, ETH_P_IP); > const struct in_addr *rst_src = daddr; > const struct in_addr *rst_dst = saddr; > > @@ -1908,7 +1908,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, NULL, ETH_P_IPV6); > const struct in6_addr *rst_src = daddr; > const struct in6_addr *rst_dst = saddr; > -- Stefano