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=Y5n3repn; 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 566815A0289 for ; Sat, 07 Jun 2025 03:12:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749258720; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9SK2Ff+CjTlVlIYyepfMcWYzfnvuOfYIDHpc5wz6dFI=; b=Y5n3repnvYn+vIz6T7482MSl0urd+FxFT/jkgQKoQnplfTk9oFXg4BPAAdvSM5Zg1PAeWn aFdZ55IZfUz679zWuIzsA1uZYPdEwWJ8xdacNbX88uy9Q5yA0JdvaSQyWUVvJBCv9KwvIJ zNzoR4mcjGKeSVMTN+unw2ifBcTYlrE= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-221-4MVJ2tQBOgagkFX1WssQ8g-1; Fri, 06 Jun 2025 21:11:58 -0400 X-MC-Unique: 4MVJ2tQBOgagkFX1WssQ8g-1 X-Mimecast-MFC-AGG-ID: 4MVJ2tQBOgagkFX1WssQ8g_1749258718 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DAFD7195608B for ; Sat, 7 Jun 2025 01:11:57 +0000 (UTC) Received: from jmaloy-thinkpadp16vgen1.rmtcaqc.csb (unknown [10.22.80.87]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E770718002BA; Sat, 7 Jun 2025 01:11:55 +0000 (UTC) From: Jon Maloy To: sbrivio@redhat.com, dgibson@redhat.com, jmaloy@redhat.com, passt-dev@passt.top Subject: [2/4] arp: respond with true mac address of LAN local remote hosts Date: Fri, 6 Jun 2025 21:11:49 -0400 Message-ID: <20250607011151.3290866-3-jmaloy@redhat.com> In-Reply-To: <20250607011151.3290866-1-jmaloy@redhat.com> References: <20250607011151.3290866-1-jmaloy@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: yJNHYkPFd-VsHcMEGL7TUKpt-dbhipotLRfYE8e9rB0_1749258718 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: N2A5ICRI6VRZ3IMQ2ZPQI5LLVXQXXFTH X-Message-ID-Hash: N2A5ICRI6VRZ3IMQ2ZPQI5LLVXQXXFTH X-MailFrom: jmaloy@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 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: When we receive an ARP or NTP request over the tap interface for a host on the local network, we respond with that host's real mac address. The local host, which is acting as a proxy for the default gateway, is still exempted from this rule. Signed-off-by: Jon Maloy --- arp.c | 9 +++++++++ fwd.c | 2 +- fwd.h | 3 ++- ndp.c | 11 +++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/arp.c b/arp.c index fc482bb..fbd8219 100644 --- a/arp.c +++ b/arp.c @@ -29,6 +29,7 @@ #include "dhcp.h" #include "passt.h" #include "tap.h" +#include "netlink.h" /** * arp() - Check if this is a supported ARP message, reply as needed @@ -39,6 +40,8 @@ */ int arp(const struct ctx *c, const struct pool *p) { + union inany_addr translated; + union inany_addr addr; unsigned char swap[4]; struct ethhdr *eh; struct arphdr *ah; @@ -72,6 +75,12 @@ int arp(const struct ctx *c, const struct pool *p) memcpy(am->tha, am->sha, sizeof(am->tha)); memcpy(am->sha, c->our_tap_mac, sizeof(am->sha)); + /* If remote host on local network - respond with its mac address */ + inany_from_af(&addr, AF_INET, am->tip); + nat_outbound(c, &addr, &translated); + if (!memcmp(&addr, &translated, sizeof(addr))) + nl_mac_get(nl_sock, &addr, am->sha); + memcpy(swap, am->tip, sizeof(am->tip)); memcpy(am->tip, am->sip, sizeof(am->tip)); memcpy(am->sip, swap, sizeof(am->sip)); diff --git a/fwd.c b/fwd.c index 250cf56..02ebc9d 100644 --- a/fwd.c +++ b/fwd.c @@ -332,7 +332,7 @@ 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, +void nat_outbound(const struct ctx *c, const union inany_addr *addr, union inany_addr *translated) { if (inany_equals4(addr, &c->ip4.map_host_loopback)) diff --git a/fwd.h b/fwd.h index 0458a3c..61632f2 100644 --- a/fwd.h +++ b/fwd.h @@ -56,5 +56,6 @@ uint8_t fwd_nat_from_splice(const struct ctx *c, uint8_t proto, const struct flowside *ini, struct flowside *tgt); uint8_t fwd_nat_from_host(const struct ctx *c, uint8_t proto, const struct flowside *ini, struct flowside *tgt); - +void nat_outbound(const struct ctx *c, const union inany_addr *addr, + union inany_addr *translated); #endif /* FWD_H */ diff --git a/ndp.c b/ndp.c index 3e15494..d702f37 100644 --- a/ndp.c +++ b/ndp.c @@ -32,6 +32,7 @@ #include "passt.h" #include "tap.h" #include "log.h" +#include "netlink.h" #define RT_LIFETIME 65535 @@ -196,6 +197,9 @@ 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 translated; + union inany_addr addr_any; + struct ndp_na na = { .ih = { .icmp6_type = NA, @@ -215,6 +219,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); + /* If remote host on local network - respond with its mac address */ + inany_from_af(&addr_any, AF_INET6, addr); + nat_outbound(c, &addr_any, &translated); + + if (!memcmp(&addr_any, &translated, sizeof(addr_any))) + nl_mac_get(nl_sock, &addr_any, na.target_l2_addr.mac); + ndp_send(c, dst, &na, sizeof(na)); } -- 2.48.1