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=farpigW+; 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 E0A3D5A028A for ; Thu, 12 Jun 2025 17:17:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749741443; 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=y3C1kxIJ5noMdkVmvwHZLmhGj+Lcyb5YrJJ8SlSxkTk=; b=farpigW+PAw6HlvY1Sh6u/Ehdj5USXSNvI40zKGbosdqHVjopF6HC5xKAHlJ1FNkxIibUf nWyMZs8kj12hpPXj3qcTrXKCRUEuZXk6HZQmfaRL0Ha8uWzzdY2S2QLlIA8efRXlSCFSWM 90GitKN1POCR3EdTZZ4NKtooUzR5qkQ= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-538-q_Cn5rSYPrGERGDupgTqYQ-1; Thu, 12 Jun 2025 11:17:22 -0400 X-MC-Unique: q_Cn5rSYPrGERGDupgTqYQ-1 X-Mimecast-MFC-AGG-ID: q_Cn5rSYPrGERGDupgTqYQ_1749741440 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3a4f858bc5eso832369f8f.0 for ; Thu, 12 Jun 2025 08:17:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749741439; x=1750346239; 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=y3C1kxIJ5noMdkVmvwHZLmhGj+Lcyb5YrJJ8SlSxkTk=; b=fB9eLWseyl31dIplfRFRWS62UQFVUf0VDGpg+FzJx20EjR3uYhngOEe+5mMnyEPEcZ jODIpEG0JcZ3vGfo7nZaU4Dh81QvBnFRKPj0ejZ37OlDcDRC6512mVCv/fZXOquvvaZ/ A9rlQJudKICyMdkbuhSdPKLlNY84gb9wSbbS7cL00+5JVKL9g/EnQLm/1Jmd2PyBpb+j h1/faNUPLa+Dmm8s22woN99msq41BMg7UutPGNa6ZS0u5gugJTkM7i7ZLqa30DXaTgpn 86XyrvlKjdbU2sa64iZqgD6Ejv1f/cmwN8e/xKDXpMv3JDFnJ4k2dmNT2tLy+oSimuYr YR6A== X-Forwarded-Encrypted: i=1; AJvYcCWU7khuZg4fKzW91uqN7dJ4c/2NlJ7/bzIEk2IIfydI0PtxsLblHpgF+BvbrtFVTv29QJEGO9DNxRQ=@passt.top X-Gm-Message-State: AOJu0YygX1qflZBPkUQGQxwffl4ZNZ9ZRjgREn1gaaGsSy2TGKTZP8fH rZ4yCfzSFjXlCN+hejKGuPlOj/gcKmsQW8ebwuy0s4rfSmUa/rwhMabfUXEsSDVusGlPNzGzgU9 UIyMLUExaRjaI/gGyLHSKuI869y9IPXzxRpiTFn0BTBwa6fe4/cfzEfQM/hJM1GpODi7NWs9d9o DHBvtM9rGKOVhSmAor/Lj1T9n9okfvt4IaUR7x X-Gm-Gg: ASbGncvZ910s4iknUJtxZUHp9QnNH2nWfQzVvYuU4kwX8EFYluwdN/ntXtB9JB/x+jV zcNRpBAz0yOwPzS03CH3+yRhJHtw4LEg37nHko0zxn2hTzTdY7grarPy5mjS8c6n3iXnI8NAsqR +TtZmSVd7LzSWt+jjJK3RC8R7D7ZrE+AxAYbfaGVZWg4COyM44p0F0S4nIPzD3FNYTHn6Jw+X20 hwv3hv+Msuph+9jjDYZbRbUzqoAkebojK3/9FTY9uPIkY5m+M8OpXZWYBIY1qMRfI3NbLFNS2V8 hib1jqSPQ26j1weel+l0zn+dgxfQpHao9A== X-Received: by 2002:a05:6000:4006:b0:3a4:d64a:3df6 with SMTP id ffacd0b85a97d-3a5679afb80mr340948f8f.3.1749741439216; Thu, 12 Jun 2025 08:17:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG34gqp07ag5zcvJFAUwiv2EwCphfJhg4nd8oPAPrIKUENhx1i3B8DzYYtWPflpiav9U4ZFmQ== X-Received: by 2002:a05:6000:4006:b0:3a4:d64a:3df6 with SMTP id ffacd0b85a97d-3a5679afb80mr340903f8f.3.1749741438477; Thu, 12 Jun 2025 08:17:18 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4532e169d90sm24158165e9.32.2025.06.12.08.17.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jun 2025 08:17:17 -0700 (PDT) Date: Thu, 12 Jun 2025 17:17:16 +0200 From: Stefano Brivio To: Jon Maloy Subject: Re: [PATCH v2 2/8] arp: respond with true mac address of LAN local remote hosts Message-ID: <20250612171716.11b29e93@elisabeth> In-Reply-To: <20250612042152.695879-3-jmaloy@redhat.com> References: <20250612042152.695879-1-jmaloy@redhat.com> <20250612042152.695879-3-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: WruzIxwedEtxJLsn9P5kxYXDo3cmDtjEl4-1Fmqc3VE_1749741440 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: SWYHQXB6IG3CYA4FXKA6B2DT5NR7EOSW X-Message-ID-Hash: SWYHQXB6IG3CYA4FXKA6B2DT5NR7EOSW 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:46 -0400 Jon Maloy wrote: > When we receive an ARP or NTP request over the tap interface for a Nit: NDP. > 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; Those aren't very descriptive, especially 'translated'. What about 'tgt_ipaddr' and 'tgt_ipaddr_nat'? I'm not fond of those names either but I can't come up with much better right now. Nit: that could be a single line. > 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 */ This is partially a full sentence ("If remote host [...] respond ..."), partially a schematic form of a correspondence ("Remote host [...]: respond with ..."). In general we stick to either one, not a mix. > + inany_from_af(&addr, AF_INET, am->tip); > + nat_outbound(c, &addr, &translated); > + if (!memcmp(&addr, &translated, sizeof(addr))) You can use inany_equals() here as well, for consistency, even though it's always an IPv4 address. By the way, this way of checking if the target IP address is a non-local host on the local segment is a bit convoluted, and perhaps would deserve its own helper outside of this function. I also wonder if it's correct in all cases: what happens if this is a local (non-loopback) address of a host interface? Then we'll call nl_mac_get() which should leave am->sha as it is (because the MAC address is not found), but the comment above doesn't match anymore. > + 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 */ In IPv6 terms this is typically called link-layer 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); > + Same as for arp(). > ndp_send(c, dst, &na, sizeof(na)); > } > -- Stefano