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=gSrxu6Es; 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 4BBE75A0272 for ; Tue, 30 Sep 2025 23:29:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1759267770; 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=nAFBMGZNr/4EPFSSX921dx16qzz9kly6XuxkUbTTQZw=; b=gSrxu6EskPcB5BYuEu6iFsKyBM0XYYN8UAipAIbwJx0/9kddwnzVoCCV7eXfPz2CGSjsrx lhZiVi2e6mQ4kh734Obm2IbR+RmNfEseOeJ6HAiavdIinrInzbKHn7M3Sf48S6HnFNjJl+ hd+wVKdpTVd3zLSy8AI3VCXOa6lPPyM= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-101-4oAfLmYqPSWEt9GFhenWCg-1; Tue, 30 Sep 2025 17:29:28 -0400 X-MC-Unique: 4oAfLmYqPSWEt9GFhenWCg-1 X-Mimecast-MFC-AGG-ID: 4oAfLmYqPSWEt9GFhenWCg_1759267768 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3f030846a41so4139495f8f.2 for ; Tue, 30 Sep 2025 14:29:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759267767; x=1759872567; 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=nAFBMGZNr/4EPFSSX921dx16qzz9kly6XuxkUbTTQZw=; b=nLtn4ScL7JUPJFoJvu27PSdAPMHw2nfoN7E84rj3sw4J6oxH8sb04z7ku7O+eyp8/o EIMu7VFlhZWso7C2uca5inTE9vqbNhY3I3S2Q8hCRy5mwDuXY82p4GPj8YWZBG4AFtnQ IcmWz4XNCS9EpJxtw9DbTNmfPNTrz+IMAZviKBsLEstNUSX+gAcnLFdo3ZqoS76ir4mi HrmRT/VjmcY5piqBOrIAfDTaGq4A3bwZCrQvQtX/CnnlQhJ4OUGOU71pL+QLB/wYxFFc ww4LM4RS7MrTzNF87uqMLXHNY5KPOgvljYBrsHVfzsQj49orylSE8W4q2jj3iuQeJhba 7DOg== X-Forwarded-Encrypted: i=1; AJvYcCV4am9t+zOCeXw9AuVwE7kMa+YyKDTty3buCZpv/fHjSzFRX2iWxz+qHImtUA37r0qbJDdh1KOAZD8=@passt.top X-Gm-Message-State: AOJu0YzdHAuFUjW+qqwIpEhcvTReKloBcwNXU1wE41CKQdXcXsztdj4k bhjfxO29HLk3Uu7MMBuNRtSaIMhN7rrpiVZDBuavMkOzfGTTMLBsXa1C8gYWcSPm2aVGs9wbRoR ZvtTAnUX6NcUte1F5dRInWUIscO/OoMidglVpu3xjcWK2S1LVIxw9hg== X-Gm-Gg: ASbGncuTzUsAFuTH1eWfeer5bzuJfHTQQdiSAcktr20foE7z8VSV3mNLoTNmX/H2T8F g9dmEbA99yuMXmoIaeJtqBGC/lPG5eOSs89l8IjMejISHNpGivLFy+WdwP8oE61Kj9lrURo5XS+ FseKoMGotlkEq+QcQ2RJXfWRNqm7aomyfMd10kczoSoBW7Ql/itwn9xojo/pyMMHXwrIiLh8qSU liWfh2p/iEO5vRbuF3dkV8qnRhVGytixjYdF0NWEI0HcXjeSv+HcI5gpphGaCbq7gzdvzUDYxv3 zvsUL0Jus4OX4Fy1aKPFyVvnYOV3Z0jhSjJ3xYDJxOvs260GNGZgZYqRy9zOiofjkG+e3nxfWw= = X-Received: by 2002:a05:6000:2dc1:b0:3ec:ea73:a94d with SMTP id ffacd0b85a97d-4255780b44fmr729973f8f.37.1759267767479; Tue, 30 Sep 2025 14:29:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF6x/95a1XLe1kGoKfhiWb7FQvhatbox0LmRUMOO06l+CHqXTJ8/KkV+d5p9UOvuOFqAdYMKw== X-Received: by 2002:a05:6000:2dc1:b0:3ec:ea73:a94d with SMTP id ffacd0b85a97d-4255780b44fmr729960f8f.37.1759267766885; Tue, 30 Sep 2025 14:29:26 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-46e619a6f8dsm9477785e9.11.2025.09.30.14.29.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Sep 2025 14:29:26 -0700 (PDT) Date: Tue, 30 Sep 2025 23:29:24 +0200 From: Stefano Brivio To: Jon Maloy Subject: Re: [PATCH v11 4/9] arp/ndp: respond with true MAC address of LAN local remote hosts Message-ID: <20250930232924.200e4dfd@elisabeth> In-Reply-To: <20250927192522.3024554-5-jmaloy@redhat.com> References: <20250927192522.3024554-1-jmaloy@redhat.com> <20250927192522.3024554-5-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: xHgOEqYUvi_b7qj4M1g6Add84Crsp_n37UifcrZehvc_1759267768 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: PY424KKDLSFUXTY7PVDRGD6YHRCXBUIB X-Message-ID-Hash: PY424KKDLSFUXTY7PVDRGD6YHRCXBUIB 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: Two nits only: On Sat, 27 Sep 2025 15:25:17 -0400 Jon Maloy wrote: > When we receive an ARP request or NDP neigbor solicitation over neighbour (it doesn't matter so much but I actually grep through commit messages from time to time...) > the tap interface for a host on the local network segment attached > to the template interface, we respond with that host's real MAC > address. > > Signed-off-by: Jon Maloy > Reviewed-by: David Gibson > > --- > v3: - Added helper function to find out if a remote ip address is subject > to NAT. This filters out local host addresses which should be > presented with the passt/pasta local MAC address 9a:55:9a:55:9a:55 even > though it is on the local segment. > - Adapted to the change in nl_mac_get() function, so that we now consider > only the template interface when checking the ARP/NDP table. > v4: - Moved NAT check into the function nat_outbound() to obtain more > precise criteria for when NAT is used. We may in theory > have NAT even if original and translated addresses are equal, and > we want to catch this case. > - I chose to keep the wrapper funtion inany_nat(), but moved it to > fwd.h/fwd.c and renamed it to fwd_inany_nat(). > v5: - Simplified criteria for when we do ARP/NDP lookup. Now, we > just try with the potentially translated address after an > attempted NAT check. > - Using the new ARP/NDP cache table instead of using netlink > directly. > v6: - Fixes after feedback from David: > - Renamed nat_outbound() to fwd_nat_outbound() > - Eliminated unnecessary temporary variable in arp.c::arp() > --- > arp.c | 9 +++++++-- > fwd.c | 8 ++++---- > fwd.h | 2 ++ > inany.c | 1 + > ndp.c | 8 ++++++++ > 5 files changed, 22 insertions(+), 6 deletions(-) > > diff --git a/arp.c b/arp.c > index 57e7b59..4f6b7df 100644 > --- a/arp.c > +++ b/arp.c > @@ -69,6 +69,7 @@ static bool ignore_arp(const struct ctx *c, > */ > int arp(const struct ctx *c, struct iov_tail *data) > { > + union inany_addr tgt, tgt_nat; > struct { > struct ethhdr eh; > struct arphdr ah; > @@ -102,8 +103,12 @@ int arp(const struct ctx *c, struct iov_tail *data) > resp.ah.ar_hln = ah->ar_hln; > resp.ah.ar_pln = ah->ar_pln; > > - /* ARP message */ > - memcpy(resp.am.sha, c->our_tap_mac, sizeof(resp.am.sha)); > + /* MAC address to return in ARP message */ > + inany_from_af(&tgt, AF_INET, am->tip); > + fwd_nat_outbound(c, &tgt, &tgt_nat); > + fwd_neigh_mac_get(c, &tgt_nat, resp.am.sha); > + > + /* Rest of ARP message */ > memcpy(resp.am.sip, am->tip, sizeof(resp.am.sip)); > memcpy(resp.am.tha, am->sha, sizeof(resp.am.tha)); > memcpy(resp.am.tip, am->sip, sizeof(resp.am.tip)); > diff --git a/fwd.c b/fwd.c > index 7f38b40..fef9d3d 100644 > --- a/fwd.c > +++ b/fwd.c > @@ -496,7 +496,7 @@ static bool fwd_guest_accessible(const struct ctx *c, > } > > /** > - * nat_outbound() - Apply address translation for outbound (TAP to HOST) > + * fwd_nat_outbound() - Apply address translation for outbound (TAP to HOST) > * @c: Execution context > * @addr: Input address (as seen on TAP interface) > * @translated: Output address (as seen on HOST interface) > @@ -504,8 +504,8 @@ static bool fwd_guest_accessible(const struct ctx *c, > * Only handles translations that depend *only* on the address. Anything > * related to specific ports or flows is handled elsewhere. > */ > -static void nat_outbound(const struct ctx *c, const union inany_addr *addr, > - union inany_addr *translated) > +void fwd_nat_outbound(const struct ctx *c, const union inany_addr *addr, > + union inany_addr *translated) > { > if (inany_equals4(addr, &c->ip4.map_host_loopback)) > *translated = inany_loopback4; > @@ -539,7 +539,7 @@ uint8_t fwd_nat_from_tap(const struct ctx *c, uint8_t proto, > inany_equals6(&ini->oaddr, &c->ip6.dns_match)) > tgt->eaddr.a6 = c->ip6.dns_host; > else > - nat_outbound(c, &ini->oaddr, &tgt->eaddr); > + fwd_nat_outbound(c, &ini->oaddr, &tgt->eaddr); > > tgt->eport = ini->oport; > > diff --git a/fwd.h b/fwd.h > index 5464349..241f527 100644 > --- a/fwd.h > +++ b/fwd.h > @@ -50,6 +50,8 @@ void fwd_scan_ports_init(struct ctx *c); > > bool nat_inbound(const struct ctx *c, const union inany_addr *addr, > union inany_addr *translated); > +void fwd_nat_outbound(const struct ctx *c, const union inany_addr *addr, > + union inany_addr *translated); > uint8_t fwd_nat_from_tap(const struct ctx *c, uint8_t proto, > const struct flowside *ini, struct flowside *tgt); > uint8_t fwd_nat_from_splice(const struct ctx *c, uint8_t proto, > diff --git a/inany.c b/inany.c > index 65a39f9..7680439 100644 > --- a/inany.c > +++ b/inany.c > @@ -16,6 +16,7 @@ > #include "ip.h" > #include "siphash.h" > #include "inany.h" > +#include "fwd.h" > > const union inany_addr inany_loopback4 = INANY_INIT4(IN4ADDR_LOOPBACK_INIT); > const union inany_addr inany_any4 = INANY_INIT4(IN4ADDR_ANY_INIT); > diff --git a/ndp.c b/ndp.c > index d7f64a3..610a06c 100644 > --- a/ndp.c > +++ b/ndp.c > @@ -196,6 +196,7 @@ static void ndp_send(const struct ctx *c, const struct in6_addr *dst, > static void ndp_na(const struct ctx *c, const struct in6_addr *dst, > const struct in6_addr *addr) > { > + union inany_addr tgt, tgt_nat; > struct ndp_na na = { > .ih = { > .icmp6_type = NA, > @@ -215,6 +216,13 @@ static void ndp_na(const struct ctx *c, const struct in6_addr *dst, > > memcpy(na.target_l2_addr.mac, c->our_tap_mac, ETH_ALEN); > > + /* Respond with true MAC address if remote host's address or Maybe s/true/recorded/? Outside of the context of this series, otherwise, it's pretty hard to figure out what you mean with "true" here. > + * NAT translated address can be found in NDP table. > + */ > + inany_from_af(&tgt, AF_INET6, addr); > + fwd_nat_outbound(c, &tgt, &tgt_nat); > + fwd_neigh_mac_get(c, &tgt_nat, na.target_l2_addr.mac); > + > ndp_send(c, dst, &na, sizeof(na)); > } -- Stefano