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=JIlctPcP; 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 F1B965A026F for ; Wed, 29 Oct 2025 13:30:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761741011; 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=CFFnj51WBlJlguxYrzwXh5sBZvkEJB7LQN3VJ4UwuoE=; b=JIlctPcPksYm7FNQ7gH0QYOahxWZIY7/FYyntiOjKVyGk76+mlxTO9ep+a71cP4dFZQQq+ hVdnz1uk3V2fktpXXbP5ZTKs1MNCExA681jbXvX2VjBZjtGtWx/08sykmC18MkJCvM4rbs 8rlX1LmooFvdGyQuTJPpUY0iBDyQ75o= 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-551-7aahwQhjP3epN6SXRD1fDA-1; Wed, 29 Oct 2025 08:30:10 -0400 X-MC-Unique: 7aahwQhjP3epN6SXRD1fDA-1 X-Mimecast-MFC-AGG-ID: 7aahwQhjP3epN6SXRD1fDA_1761741009 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4710d174c31so64783355e9.0 for ; Wed, 29 Oct 2025 05:30:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761741009; x=1762345809; 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=CFFnj51WBlJlguxYrzwXh5sBZvkEJB7LQN3VJ4UwuoE=; b=Xg3g2MNhIbesIHus0GWfXVFVbJKIVQvOv2B8W8GJDBveT9xObs1nm8JhGIofmD8TTL AZB/0fAurpTbEDy8a7Y87Bw6tteL77k8K5AmlMDl1GhHMqp2aPtV8rOgKfUNyEq6wdnw 5MQaOSVShmKJnB73Hw4RrY0RvYy7zKpYRqco7f5JxeDuuw6eAp00zOtNIndfkdgbRr9o 2q1ehiuLz+KVDltSADOz5OF8T/UQFax8ncCsqZhcNyD7j4E3cpNhFVT84nzdRaxsC0IE 3mUFfPgnVgKKssrXwnVdXqhIjUI4tmIRMkrr28rdnC4DQ39Qy7Osoe3v5sOeX3xmTi3P 3iPw== X-Forwarded-Encrypted: i=1; AJvYcCVxM0NsiJ/qMZs+HBomJWIO5V4CnT3TBfHp3LsS91ZaZH7vW2+SnIJxAHXYzEFYWXsslTqiWIO5hFw=@passt.top X-Gm-Message-State: AOJu0YxHhdglXAi3uugfigImPdky4jniE4LeegUQpI5/nHFrrQAMEoSb I0jzUo5K3hii7zGl2DKTmvW3tkURqFHEAHFs9xgHiWADqBAMsTmbNywGfU07wuuAhOUg0A7jBHW DK4fYBrh2OYK58Qc5cKQtBiE6hbvFiSn+oaB4+IBxUg1yJkwlUAmogQ== X-Gm-Gg: ASbGncsEUGV/NOCQgY942GxmkKiInsT8LVx5jYzDGXovF9frr5FjP8v9yRtBuUGKAEz C/OpUgcGJ6V6e8BOQfb3HZYdTfFqOlIpCWIpGbLNNGycVo3kjxB2FgrZSSKejNJcu2dn7tO0eAH Nc3TCrAJMEzbCFIBK/iYUpGigKfJFN5UrgX1ZUyl5wL2DMffL/HpCp+3HulIixW5M9jv4foJe+n gbi/ALNXI2qFH8CVOx/uzactnJj1GMxWz0lu8qXSzeOyDkmjpafg4pf+9auInRvTfF1Cv8PV6bG 8tXnTtdwdeB5xm6AlUJ5u+dMl0H3O/fSUNiCaW+n1dDOjDuzAMMlJ6HaHs7vIUKfBmeYzrjeSJw VM1mXTw9lHg== X-Received: by 2002:a05:600c:190d:b0:477:fcb:2256 with SMTP id 5b1f17b1804b1-4771e18f602mr26288885e9.17.1761741008667; Wed, 29 Oct 2025 05:30:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFKvYtKnFhW198FbKj10VmYjms+DtpHfmZ83s9csMzpHKiyah3phBVIZ7VpOiA2DTd/cyfahA== X-Received: by 2002:a05:600c:190d:b0:477:fcb:2256 with SMTP id 5b1f17b1804b1-4771e18f602mr26288605e9.17.1761741008149; Wed, 29 Oct 2025 05:30:08 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4771e372a2asm47531195e9.1.2025.10.29.05.30.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Oct 2025 05:30:07 -0700 (PDT) Date: Wed, 29 Oct 2025 13:30:06 +0100 From: Stefano Brivio To: Jon Maloy Subject: Re: [PATCH v15 4/9] arp/ndp: send ARP announcement / unsolicited NA when neigbour entry added Message-ID: <20251029133006.4a21fd62@elisabeth> In-Reply-To: <20251024012933.1933642-5-jmaloy@redhat.com> References: <20251024012933.1933642-1-jmaloy@redhat.com> <20251024012933.1933642-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: 1Jelf9vR5teB0GJRzDAhW4dQSPsr6lZV-RDC-8VNGDA_1761741009 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: SNDC7NRNQU3CM2OBCIL7VYUHGFCSJ3FM X-Message-ID-Hash: SNDC7NRNQU3CM2OBCIL7VYUHGFCSJ3FM 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: On Thu, 23 Oct 2025 21:29:28 -0400 Jon Maloy wrote: > ARP announcements and unsolicited NAs should be handled with caution > because of the risk of malignant users emitting them to disturb > network communication. > > There is however one case we where we know it is legitimate > and safe for us to send out such messages: The one time we switch > from using ctx->own_tap_mac to a MAC address received via the > recently added neigbour subscription function. Later changes to > the MAC address of a host in an existing entry cannot be fully > trusted, so we abstain from doing it in such cases. > > When sending this type of messages, we notice that the guest accepts > the update, but shortly later asks for a confirmation in the form of > a regular ARP/NS request. This is responded to with the new value, > and we have exactly the effect we wanted. > > This commit adds this functionality. > > Signed-off-by: Jon Maloy > > --- > v10: -Made small changes based of feedback from David G. > v11: -Moved from 'Gratuitous ARP reply' model to 'ARP Announcement' > model. > v12: -Excluding loopback and default GW addresses from the ARP/NA > announcement to be sent to the guest > v13: -Filtering out all announcements of our_tap_mac instead of > explicitly comparing a set of IP addresses. > -Changed annc.am.tha in arp_announce() to MAC_ZERO, which is > 'unknown' according to RFC826. > -Renamed ndp_send_unsolicited_na() to ndp_unsolicited_na() > v14: -Added quotes from RFC5227 to explain the format of ARP > announce messages, as suggested by David. > v15: -A couple of minor changes based on feedback from Stefano > --- > arp.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ > arp.h | 2 ++ > fwd.c | 10 ++++++++++ > ndp.c | 10 ++++++++++ > ndp.h | 1 + > 5 files changed, 74 insertions(+) > > diff --git a/arp.c b/arp.c > index b4a686f..b0d2fc3 100644 > --- a/arp.c > +++ b/arp.c > @@ -150,3 +150,54 @@ void arp_send_init_req(const struct ctx *c) > debug("Sending initial ARP request for guest MAC address"); > tap_send_single(c, &req, sizeof(req)); > } > + > +/** > + * arp_announce() - Send an ARP announcement for an IPv4 host > + * @c: Execution context > + * @ip: IPv4 address we announce as owned by @mac > + * @mac: MAC address to advertise for @ip > + */ > +void arp_announce(const struct ctx *c, struct in_addr *ip, > + const unsigned char *mac) > +{ > + char ip_str[INET_ADDRSTRLEN]; > + char mac_str[ETH_ADDRSTRLEN]; > + struct { > + struct ethhdr eh; > + struct arphdr ah; > + struct arpmsg am; > + } __attribute__((__packed__)) msg; > + > + /* Ethernet header */ > + msg.eh.h_proto = htons(ETH_P_ARP); > + memcpy(msg.eh.h_dest, MAC_BROADCAST, sizeof(msg.eh.h_dest)); > + memcpy(msg.eh.h_source, mac, sizeof(msg.eh.h_source)); > + > + /* ARP header */ > + msg.ah.ar_op = htons(ARPOP_REQUEST); > + msg.ah.ar_hrd = htons(ARPHRD_ETHER); > + msg.ah.ar_pro = htons(ETH_P_IP); > + msg.ah.ar_hln = ETH_ALEN; > + msg.ah.ar_pln = 4; > + > + /* RFC5227, section 2.1.1, about Probe messages: "The client MUST fill > + * in the 'sender hardware address' field of the ARP Request with the > + * hardware address of the interface through which it is sending the > + * packet. [...] The 'target hardware address' field is ignored and > + * SHOULD be set to all zeroes." > + * > + * RFC5227, section 2.3: "An ARP Announcement is identical to the ARP > + * Probe described above, except that now the sender and target IP > + * addresses are both set to the host's newly selected IPv4 address." > + */ > + memcpy(msg.am.sha, mac, sizeof(msg.am.sha)); > + memcpy(msg.am.sip, ip, sizeof(msg.am.sip)); > + memcpy(msg.am.tha, MAC_ZERO, sizeof(msg.am.tha)); > + memcpy(msg.am.tip, ip, sizeof(msg.am.tip)); > + > + inet_ntop(AF_INET, ip, ip_str, sizeof(ip_str)); > + eth_ntop(mac, mac_str, sizeof(mac_str)); > + debug("ARP announcment for %s / %s", ip_str, mac_str); Nit: announcement. I'll fix this on merge if there's nothing else that needs changes. > + > + tap_send_single(c, &msg, sizeof(msg)); > +} > diff --git a/arp.h b/arp.h > index d5ad0e1..4862e90 100644 > --- a/arp.h > +++ b/arp.h > @@ -22,5 +22,7 @@ struct arpmsg { > > int arp(const struct ctx *c, struct iov_tail *data); > void arp_send_init_req(const struct ctx *c); > +void arp_announce(const struct ctx *c, struct in_addr *ip, > + const unsigned char *mac); > > #endif /* ARP_H */ > diff --git a/fwd.c b/fwd.c > index 93d83e3..c1de4b8 100644 > --- a/fwd.c > +++ b/fwd.c > @@ -27,6 +27,8 @@ > #include "lineread.h" > #include "flow_table.h" > #include "netlink.h" > +#include "arp.h" > +#include "ndp.h" > > /* Empheral port range: values from RFC 6335 */ > static in_port_t fwd_ephemeral_min = (1 << 15) + (1 << 14); > @@ -140,6 +142,14 @@ void fwd_neigh_table_update(const struct ctx *c, const union inany_addr *addr, > memcpy(&e->addr, addr, sizeof(*addr)); > memcpy(e->mac, mac, ETH_ALEN); > e->permanent = permanent; > + > + if (!memcmp(mac, c->our_tap_mac, ETH_ALEN)) > + return; > + > + if (inany_v4(addr)) > + arp_announce(c, inany_v4(addr), e->mac); > + else > + ndp_unsolicited_na(c, &addr->a6); > } > > /** > diff --git a/ndp.c b/ndp.c > index 7e2ae2a..430d420 100644 > --- a/ndp.c > +++ b/ndp.c > @@ -220,6 +220,16 @@ static void ndp_na(const struct ctx *c, const struct in6_addr *dst, > ndp_send(c, dst, &na, sizeof(na)); > } > > +/** > + * ndp_unsolicited_na() - Send unsolicited NA > + * @c: Execution context > + * @addr: IPv6 address to advertise > + */ > +void ndp_unsolicited_na(const struct ctx *c, const struct in6_addr *addr) > +{ > + ndp_na(c, &in6addr_ll_all_nodes, addr); > +} > + > /** > * ndp_ra() - Send an NDP Router Advertisement (RA) message > * @c: Execution context > diff --git a/ndp.h b/ndp.h > index 781ea86..56b756d 100644 > --- a/ndp.h > +++ b/ndp.h > @@ -12,5 +12,6 @@ int ndp(const struct ctx *c, const struct in6_addr *saddr, > struct iov_tail *data); > void ndp_timer(const struct ctx *c, const struct timespec *now); > void ndp_send_init_req(const struct ctx *c); > +void ndp_unsolicited_na(const struct ctx *c, const struct in6_addr *addr); > > #endif /* NDP_H */ -- Stefano