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=aYOy7d4Z; 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 BBAB05A028A for ; Thu, 12 Jun 2025 17:17:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749741475; 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=+JHB4IjtJNnNwdJH4yQ7J3n+xP5AXwMo+dQEf6VnsIY=; b=aYOy7d4ZPQhCVxfzdiUM4UjBR40eCRoTjmGiUx6DlrlHUn7aNqYSF24FrdDFl7RqQQNX3Y Gx8X14bJeVWZOaGhBUMRj/42eGzToA+keP6coJTQsF86D97a9Q/SL3PqXXRUSWdZzt1WNP 7kld3AcLbXA4GII5ZNw20KHrkTV7VE0= 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-118-5TqoLp5CM7ug08iZ0nfiEQ-1; Thu, 12 Jun 2025 11:17:54 -0400 X-MC-Unique: 5TqoLp5CM7ug08iZ0nfiEQ-1 X-Mimecast-MFC-AGG-ID: 5TqoLp5CM7ug08iZ0nfiEQ_1749741473 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-450cb8ff0c6so5829125e9.3 for ; Thu, 12 Jun 2025 08:17:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749741472; x=1750346272; 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=+JHB4IjtJNnNwdJH4yQ7J3n+xP5AXwMo+dQEf6VnsIY=; b=gf2JBIPPHZrLQzddymMIEmqz9Pgh/OX7YG0r285737KCKBno5FE4AuOJYlVLOtjaID wDFVsmsPF/eHvwRQzr89H2QwvtnDnY0LWjcdccstjRM8uEuMNQEsnZzTtiQWqWFSNeAN vF7ZdzT5kKmClhX/MPtnBLNk1EgRYqrLrla1x7MxE2kTMHu2WYWOZ3WF/Sig9y/rbWAR Y5BY3cFtHqBoI7hT4TcS5YF81lprD7nqmfTfgfr8SX+nGgAn7AhLXdcuRBH/qb/D1yoc vpnYT41m4zfEv4fBktWnAxzN24+XzfkZFS3cBrYXMJaGpBZHzOm0uPjfb/TiaII1XN/6 j7VQ== X-Forwarded-Encrypted: i=1; AJvYcCXXgk1sIqvbVYRmYc0b8afolZNVlhO56VE1EnTri6t52anglBpI6HnjqP4BVEpmRehd5ftTT3R5MGU=@passt.top X-Gm-Message-State: AOJu0Yx+jJHvmvFYLT67GStoPV0qCGwbLrOAlIR1QGkPVohzW9AW1xH3 RkUJfjg0L4S4jvWHo5O5SMJqzaOR/BO9GHrUiKMnkz8IaNQi1XPuTRU5oLrdApHq/Ut6hX31/p4 UVUnWJ2jYyksjrc3+oBhMQ9pJMqROiicvq+lk+ziXwNY8SMqrurBX1FN5VDtikwkHdRCY6nAOUo rgAFBkdtizZ5b6hCf+DoqbjPYm9wTwgzY+gf5s X-Gm-Gg: ASbGnctHzYqOuBdoHQU9TOP1woT/vqA1jcRxdO2E92FxR1PmurgBeuCQ3b7gPcQCmMY c0Gobhi6B3WLyGoHCumw1bPxfUgvtqo/mpjuw87J0t0syrO+2+TvdelSGXDqVf31nrIGE1fRWwn DJvUa5rnH6fSuhkCKBXpcrY3BYfnCZGxCEZH5qLKV2AOV2VZsYcNDQqkHjlDJoi7Rkn/VfaxNH+ aSXiA4NgerstBVW310MBnTJc1Ox7lASc2h74gnF/5BYZaOAKtWn4sTVs3ZnNrAUtqv4N3YhzZEC a2yHD6Z+lrnpHPgLSsXitombLRSGnHJ1vA== X-Received: by 2002:a05:600c:310f:b0:442:f8e7:25ef with SMTP id 5b1f17b1804b1-4532c49088fmr36800555e9.11.1749741472116; Thu, 12 Jun 2025 08:17:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEDcc9QFsK1OY4KRQy6OsWwIQy+onc0T+Nun8GBkegUG8xcoxBPfS5+yafnkg+YFVl42qDgjA== X-Received: by 2002:a05:600c:310f:b0:442:f8e7:25ef with SMTP id 5b1f17b1804b1-4532c49088fmr36800015e9.11.1749741471487; Thu, 12 Jun 2025 08:17:51 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4532e2618f0sm23117855e9.37.2025.06.12.08.17.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jun 2025 08:17:50 -0700 (PDT) Date: Thu, 12 Jun 2025 17:17:49 +0200 From: Stefano Brivio To: Jon Maloy Subject: Re: [PATCH v2 5/8] tcp: forward external source mac address through tap interface Message-ID: <20250612171749.6459bcaa@elisabeth> In-Reply-To: <20250612042152.695879-6-jmaloy@redhat.com> References: <20250612042152.695879-1-jmaloy@redhat.com> <20250612042152.695879-6-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: p9Lnmj9LbEXPnpz0TjdFgcWshrnY-UW2bCnoldAA2jo_1749741473 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: XRC3HAXAWPRB2ERWDIY6SQEF4GPDRB6G X-Message-ID-Hash: XRC3HAXAWPRB2ERWDIY6SQEF4GPDRB6G 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:49 -0400 Jon Maloy wrote: > We forward the incoming mac address through the tap interface when > receiving incoming packets from network local hosts. Packets from > the local host are excepted from this rule, and are still forwarded > with the default passt/pasta mac address as source. > > This is a part of the solution to bug #120 > > Signed-off-by: Jon Maloy > --- > tcp.c | 5 ++++- > tcp_buf.c | 27 +++++++++++++-------------- > tcp_internal.h | 2 +- > tcp_vu.c | 5 ++--- > 4 files changed, 20 insertions(+), 19 deletions(-) > > diff --git a/tcp.c b/tcp.c > index f43c1e2..777f345 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -920,7 +920,7 @@ static void tcp_fill_header(struct tcphdr *th, > * @no_tcp_csum: Do not set TCP checksum > */ > void tcp_fill_headers(const struct tcp_tap_conn *conn, > - struct tap_hdr *taph, > + struct tap_hdr *taph, struct ethhdr *eh, > struct iphdr *ip4h, struct ipv6hdr *ip6h, > struct tcphdr *th, struct iov_tail *payload, > const uint16_t *ip4_check, uint32_t seq, bool no_tcp_csum) > @@ -952,6 +952,7 @@ void tcp_fill_headers(const struct tcp_tap_conn *conn, > psum = proto_ipv4_header_psum(l4len, IPPROTO_TCP, > *src4, *dst4); > } > + eh->h_proto = htons_constant(ETH_P_IP); > } > > if (ip6h) { > @@ -972,7 +973,9 @@ void tcp_fill_headers(const struct tcp_tap_conn *conn, > &ip6h->saddr, > &ip6h->daddr); > } > + eh->h_proto = htons_constant(ETH_P_IPV6); > } > + eth_update_mac(eh, 0, tapside->mac); > > tcp_fill_header(th, conn, seq); > > diff --git a/tcp_buf.c b/tcp_buf.c > index d1fca67..2dbeca2 100644 > --- a/tcp_buf.c > +++ b/tcp_buf.c > @@ -40,8 +40,7 @@ > /* Static buffers */ > > /* Ethernet header for IPv4 and IPv6 frames */ > -static struct ethhdr tcp4_eth_src; > -static struct ethhdr tcp6_eth_src; > +static struct ethhdr tcp_eth_hdr[TCP_FRAMES_MEM]; Same comment as for the UDP implementation. > > static struct tap_hdr tcp_payload_tap_hdr[TCP_FRAMES_MEM]; > > @@ -71,8 +70,10 @@ static struct iovec tcp_l2_iov[TCP_FRAMES_MEM][TCP_NUM_IOVS]; > */ > void tcp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s) > { > - eth_update_mac(&tcp4_eth_src, eth_d, eth_s); > - eth_update_mac(&tcp6_eth_src, eth_d, eth_s); > + int i; > + > + for (i = 0; i < TCP_FRAMES_MEM; i ++) While 'i ++' is surely valid, it's somewhat weird and we never add that extra whitespace elsewhere. > + eth_update_mac(&tcp_eth_hdr[i], eth_d, eth_s); > } > > /** > @@ -85,8 +86,8 @@ void tcp_sock_iov_init(const struct ctx *c) > struct iphdr iph = L2_BUF_IP4_INIT(IPPROTO_TCP); > int i; > > - tcp6_eth_src.h_proto = htons_constant(ETH_P_IPV6); > - tcp4_eth_src.h_proto = htons_constant(ETH_P_IP); > + for (i = 0; i < TCP_FRAMES_MEM; i ++) Same here. > + eth_update_mac(&tcp_eth_hdr[i], NULL, c->our_tap_mac); > > for (i = 0; i < ARRAY_SIZE(tcp_payload); i++) { > tcp6_payload_ip[i] = ip6; > @@ -164,6 +165,7 @@ static void tcp_l2_buf_fill_headers(const struct tcp_tap_conn *conn, > struct tap_hdr *taph = iov[TCP_IOV_TAP].iov_base; > const struct flowside *tapside = TAPFLOW(conn); > const struct in_addr *a4 = inany_v4(&tapside->oaddr); > + struct ethhdr *eh = iov[TCP_IOV_ETH].iov_base; > struct ipv6hdr *ip6h = NULL; > struct iphdr *ip4h = NULL; > > @@ -172,7 +174,7 @@ static void tcp_l2_buf_fill_headers(const struct tcp_tap_conn *conn, > else > ip6h = iov[TCP_IOV_IP].iov_base; > > - tcp_fill_headers(conn, taph, ip4h, ip6h, th, &tail, > + tcp_fill_headers(conn, taph, eh, ip4h, ip6h, th, &tail, > check, seq, no_tcp_csum); > } > > @@ -194,14 +196,12 @@ int tcp_buf_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags) > int ret; > > iov = tcp_l2_iov[tcp_payload_used]; > - if (CONN_V4(conn)) { > + if (CONN_V4(conn)) > iov[TCP_IOV_IP] = IOV_OF_LVALUE(tcp4_payload_ip[tcp_payload_used]); > - iov[TCP_IOV_ETH].iov_base = &tcp4_eth_src; > - } else { > + else > iov[TCP_IOV_IP] = IOV_OF_LVALUE(tcp6_payload_ip[tcp_payload_used]); > - iov[TCP_IOV_ETH].iov_base = &tcp6_eth_src; > - } > > + iov[TCP_IOV_ETH] = IOV_OF_LVALUE(tcp_eth_hdr[tcp_payload_used]); > payload = iov[TCP_IOV_PAYLOAD].iov_base; > seq = conn->seq_to_tap; > ret = tcp_prepare_flags(c, conn, flags, &payload->th, > @@ -259,11 +259,10 @@ static void tcp_data_to_tap(const struct ctx *c, struct tcp_tap_conn *conn, > check = &iph->check; > } > iov[TCP_IOV_IP] = IOV_OF_LVALUE(tcp4_payload_ip[tcp_payload_used]); > - iov[TCP_IOV_ETH].iov_base = &tcp4_eth_src; > } else if (CONN_V6(conn)) { > iov[TCP_IOV_IP] = IOV_OF_LVALUE(tcp6_payload_ip[tcp_payload_used]); > - iov[TCP_IOV_ETH].iov_base = &tcp6_eth_src; > } > + iov[TCP_IOV_ETH].iov_base = &tcp_eth_hdr[tcp_payload_used]; > payload = iov[TCP_IOV_PAYLOAD].iov_base; > payload->th.th_off = sizeof(struct tcphdr) / 4; > payload->th.th_x2 = 0; > diff --git a/tcp_internal.h b/tcp_internal.h > index 36c6533..6c2d1ef 100644 > --- a/tcp_internal.h > +++ b/tcp_internal.h > @@ -167,7 +167,7 @@ void tcp_rst_do(const struct ctx *c, struct tcp_tap_conn *conn); > struct tcp_info_linux; > > void tcp_fill_headers(const struct tcp_tap_conn *conn, > - struct tap_hdr *taph, > + struct tap_hdr *taph, struct ethhdr *eh, > struct iphdr *ip4h, struct ipv6hdr *ip6h, > struct tcphdr *th, struct iov_tail *payload, > const uint16_t *ip4_check, uint32_t seq, bool no_tcp_csum); > diff --git a/tcp_vu.c b/tcp_vu.c > index f3914c7..da1fb37 100644 > --- a/tcp_vu.c > +++ b/tcp_vu.c > @@ -135,7 +135,7 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags) > flags_elem[0].in_sg[0].iov_len = hdrlen + optlen; > payload = IOV_TAIL(flags_elem[0].in_sg, 1, hdrlen); > > - tcp_fill_headers(conn, NULL, ip4h, ip6h, th, &payload, > + tcp_fill_headers(conn, NULL, eh, ip4h, ip6h, th, &payload, > NULL, seq, !*c->pcap); > > if (*c->pcap) { > @@ -315,7 +315,6 @@ static void tcp_vu_prepare(const struct ctx *c, struct tcp_tap_conn *conn, > eh = vu_eth(base); > > memcpy(eh->h_dest, c->guest_mac, sizeof(eh->h_dest)); > - memcpy(eh->h_source, c->our_tap_mac, sizeof(eh->h_source)); > > /* initialize header */ > > @@ -339,7 +338,7 @@ static void tcp_vu_prepare(const struct ctx *c, struct tcp_tap_conn *conn, > th->ack = 1; > th->psh = push; > > - tcp_fill_headers(conn, NULL, ip4h, ip6h, th, &payload, > + tcp_fill_headers(conn, NULL, eh, ip4h, ip6h, th, &payload, > *check, conn->seq_to_tap, no_tcp_csum); > if (ip4h) > *check = &ip4h->check; -- Stefano