From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202508 header.b=WU5ZzFe9; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 748A75A0272 for ; Mon, 29 Sep 2025 08:04:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202508; t=1759125849; bh=suyHveYBtSQ0Pub+4u6xQlbey2Ed6nCuPxk1jvci/pA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=WU5ZzFe9/CoBxZ4rOfqqE3pUVurzpkeaOSmkx2P/LRsSpSgiftV33bUwwLXs5/3se 87JBk+MB9nC1FBMw6kEOM4FyPwe60SkvwlI/aSB/+jqwwmsZYc1fQTek+WUAKtKED2 Ac7K0P4iVGkTtZTNAU4lOHo5bRY/BvxwAJsxjSjuT3o9Me0Gh3jkW9IgGbN/qs/II9 05LAgzMQEU+YXyhRelUhuZe9/4UKe4dGBIn3weZQCU5J2MmPRuD5iotoHg6AAvDoHa xoriW2ESvTVYMm41KUFZmpHeD1dVIv8qYNYl6Z8WeuLAq6zNNIaKnfAMu4Pbci67jr CV9G+/yxkJxeg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4cZrHF0rqQz4wB9; Mon, 29 Sep 2025 16:04:09 +1000 (AEST) Date: Mon, 29 Sep 2025 16:03:39 +1000 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v11 3/9] arp/ndp: send gratuitous ARP / unsolicitated NA when MAC cache entry added Message-ID: References: <20250927192522.3024554-1-jmaloy@redhat.com> <20250927192522.3024554-4-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="k9AiwARL/vYHbIX/" Content-Disposition: inline In-Reply-To: <20250927192522.3024554-4-jmaloy@redhat.com> Message-ID-Hash: ZUXXMT7BE5GZXFN7EIDPGXOZUELNIAD3 X-Message-ID-Hash: ZUXXMT7BE5GZXFN7EIDPGXOZUELNIAD3 X-MailFrom: dgibson@gandalf.ozlabs.org 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: sbrivio@redhat.com, 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: --k9AiwARL/vYHbIX/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Sep 27, 2025 at 03:25:16PM -0400, Jon Maloy wrote: > Gratuitious ARP and unsolicitated NA should be handled with caution s/unsolicitated/unsolicited/ Given the confusing history that RFC 5227 mentions, I feel like we should avoid the term "gratuitous ARP" as confusing. > because of the risk of malignant users emitting them to disturb > network communication. >=20 > 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. >=20 > When sending this type of messages, we notice that the guest accepts > the update, but also asks for a confirmation in the form of a regular > ARP/NS request. Is this still true with the announcement-by-request method? > This is responded to with the new value, and we have > exactly the effect we wanted. >=20 > This commit adds this functionality. >=20 > Signed-off-by: Jon Maloy >=20 > --- > v10: -Made small changes based of feedback from David G. > v11: -Moved from 'Gratuitous ARP reply' model to 'ARP Announcement' > model. > --- > arp.c | 41 +++++++++++++++++++++++++++++++++++++++++ > arp.h | 2 ++ > fwd.c | 8 ++++++++ > ndp.c | 10 ++++++++++ > ndp.h | 1 + > 5 files changed, 62 insertions(+) >=20 > diff --git a/arp.c b/arp.c > index ad088b1..57e7b59 100644 > --- a/arp.c > +++ b/arp.c > @@ -146,3 +146,44 @@ 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_send_gratuitous() - Send a gratuitous ARP announcement for an IPv= 4 host arp_announce() maybe? > + * @c: Execution context > + * @ip: IPv4 address we announce as owned by @mac > + * @mac: MAC address to advertise for @ip > + */ > +void arp_send_gratuitous(const struct ctx *c, struct in_addr *ip, > + const unsigned char *mac) > +{ > + char ip_str[INET_ADDRSTRLEN]; > + struct { > + struct ethhdr eh; > + struct arphdr ah; > + struct arpmsg am; > + } __attribute__((__packed__)) annc; > + > + /* Ethernet header */ > + annc.eh.h_proto =3D htons(ETH_P_ARP); > + memcpy(annc.eh.h_dest, MAC_BROADCAST, sizeof(annc.eh.h_dest)); > + memcpy(annc.eh.h_source, mac, sizeof(annc.eh.h_source)); > + > + /* ARP header */ > + annc.ah.ar_op =3D htons(ARPOP_REQUEST); > + annc.ah.ar_hrd =3D htons(ARPHRD_ETHER); > + annc.ah.ar_pro =3D htons(ETH_P_IP); > + annc.ah.ar_hln =3D ETH_ALEN; > + annc.ah.ar_pln =3D 4; > + > + /* ARP message */ > + memcpy(annc.am.sha, mac, sizeof(annc.am.sha)); > + memcpy(annc.am.sip, ip, sizeof(annc.am.sip)); > + memcpy(annc.am.tha, MAC_BROADCAST, sizeof(annc.am.tha)); > + memcpy(annc.am.tip, ip, sizeof(annc.am.tip)); Does using tip =3D=3D sip make sense? Or should tip be 255.255.255.255? > + inet_ntop(AF_INET, ip, ip_str, sizeof(ip_str)); > + debug("Sending ARP announcement for %s", ip_str); Maybe include the MAC address too? > + > + tap_send_single(c, &annc, sizeof(annc)); > +} > + > diff --git a/arp.h b/arp.h > index d5ad0e1..2cf1326 100644 > --- a/arp.h > +++ b/arp.h > @@ -22,5 +22,7 @@ struct arpmsg { > =20 > int arp(const struct ctx *c, struct iov_tail *data); > void arp_send_init_req(const struct ctx *c); > +void arp_send_gratuitous(const struct ctx *c, struct in_addr *ip, > + const unsigned char *mac); > =20 > #endif /* ARP_H */ > diff --git a/fwd.c b/fwd.c > index 2fd6cee..7f38b40 100644 > --- a/fwd.c > +++ b/fwd.c > @@ -26,6 +26,8 @@ > #include "passt.h" > #include "lineread.h" > #include "flow_table.h" > +#include "arp.h" > +#include "ndp.h" > =20 > /* Empheral port range: values from RFC 6335 */ > static in_port_t fwd_ephemeral_min =3D (1 << 15) + (1 << 14); > @@ -131,6 +133,12 @@ void fwd_neigh_table_update(const struct ctx *c, > =20 > memcpy(&e->addr, addr, sizeof(*addr)); > memcpy(e->mac, mac, ETH_ALEN); > + > + /* Send gratuitous ARP / unsolicited NA for the new mapping */ > + if (inany_v4(addr)) > + arp_send_gratuitous(c, inany_v4(addr), e->mac); > + else > + ndp_send_unsolicited_na(c, &addr->a6); > } > =20 > /** > diff --git a/ndp.c b/ndp.c > index 588b48f..d7f64a3 100644 > --- a/ndp.c > +++ b/ndp.c > @@ -218,6 +218,16 @@ static void ndp_na(const struct ctx *c, const struct= in6_addr *dst, > ndp_send(c, dst, &na, sizeof(na)); > } > =20 > +/** > + * ndp_send_unsolicited_na() - Send unsolicited NA > + * @c: Execution context > + * @addr: IPv6 address to advertise > + */ > +void ndp_send_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..320009c 100644 > --- a/ndp.h > +++ b/ndp.h > @@ -12,5 +12,6 @@ int ndp(const struct ctx *c, const struct in6_addr *sad= dr, > 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_send_unsolicited_na(const struct ctx *c, const struct in6_addr = *addr); > =20 > #endif /* NDP_H */ > --=20 > 2.50.1 >=20 --=20 David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson --k9AiwARL/vYHbIX/ Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmjaIToACgkQzQJF27ox 2GeDmQ/+NmXywXY0EodCSexEIU/cHl/kq0sJQhD9+zbWlyj6kTd3ixHkTDPOTcow SgsC0YOwxN9OM5Soe8cTfARc2Ybb69lkgBc6nV6p572haD4oEpdXjpo715aSmfiR kGq2DXyOAYAlmm01+uJ1N25UNVzMb5hwhPPDlcfYV1ni8KXzSEH+9LyR9THk71dN yaNUumarjJn2z3Llx//aN6JQ9jJT7vTM7AtPCh3fyWqX+pxZ6WF7uRchtOfziCEU ZNR9G6BeBKpewe2DsRhJmU6KjXnr1+BOlcpyqkyheq85IbyZDICBIVx3ExheKxjh QQvxg40TdAZEgO3YhwyUUSIwt+nDZFZAE2gC+DK41b9ydT65W8evdoXTogPKBDwW +6c0krfbDkHj92fe4wKRLJjRFGmj6Di8EXLVs1rk3mQzjI7ws66hcwhMu6wGCaLj O23b9E2D8mo9YQkt6FeMPUvQ+0x3XOBwBrdccTxYBnCNPRIqDWn7I0GArBerNvWU VubyXPnASs+jrSaDe9gRmCOuDKPr66gON4jHdHUFT5jamENmWz1XOCaUYIqy9rMs nw4DbNGKkOsXYxFCelS1Eb1TjfhaNXBX1HVXxmjdVpR1yHIcZyBch71/zLfdi/u5 0FV6J6aOoXNKpJjVS/HcnPJ3GNe7TJsdbPmrZAUlLiLQ6nobiQY= =E7vm -----END PGP SIGNATURE----- --k9AiwARL/vYHbIX/--