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=202510 header.b=motAPhm7; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id B40295A0619 for ; Tue, 14 Oct 2025 07:04:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202510; t=1760418288; bh=wtjz/NMUcx638QHesGPy7OvY2Infr7Gs3RfTOfVVbvg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=motAPhm77qzfwJSaUafhdMf9+7BQ11sXDyFN0i4E9LjM3pHx9hjmyyzlgD6Ji9umy D+KJKpUg0pDc6TuciOD4J5pFPFyKQuDxcrmunMCC2DtZ8+EHVR4zFeojjAhv0UGf2t G+dPlLg0zE4UhVmD2MJPkrfOZRV3X41nS1/vaCWIZ3vZyKXT+xQIOpQfmrPbhSUqmK tZ2OgnhUZvzxLpP1HANSEGynwz5Y5FictGmWQoOtwsbnBziEo3JeZbbjt7qvmnhUvg U/y+vrHXPOePzbK4DLANScgPCocFRb8FMmImtDtk4ArNJKvbZ3XUtT64CK/ViSLDkU ggVguZb5s653A== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4cm2Fr1Qh1z4wCf; Tue, 14 Oct 2025 16:04:48 +1100 (AEDT) Date: Tue, 14 Oct 2025 16:01:06 +1100 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v13 05/10] arp/ndp: send ARP announcement / unsolicited NA when neigbour entry added Message-ID: References: <20251012193337.616835-1-jmaloy@redhat.com> <20251012193337.616835-6-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="ULlF2pSc4nl/EriI" Content-Disposition: inline In-Reply-To: <20251012193337.616835-6-jmaloy@redhat.com> Message-ID-Hash: 7N23P676BIYGXTI3NUUGYSCORQDDUBZR X-Message-ID-Hash: 7N23P676BIYGXTI3NUUGYSCORQDDUBZR 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: --ULlF2pSc4nl/EriI Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Oct 12, 2025 at 03:33:32PM -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. >=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 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. >=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. > 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() > --- > arp.c | 42 ++++++++++++++++++++++++++++++++++++++++++ > arp.h | 2 ++ > fwd.c | 10 ++++++++++ > ndp.c | 10 ++++++++++ > ndp.h | 1 + > 5 files changed, 65 insertions(+) >=20 > diff --git a/arp.c b/arp.c > index b4a686f..18fe1c7 100644 > --- a/arp.c > +++ b/arp.c > @@ -150,3 +150,45 @@ 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__)) 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_ZERO, sizeof(annc.am.tha)); > + memcpy(annc.am.tip, ip, sizeof(annc.am.tip)); It seems weird to have sip =3D=3D tip, but sha !=3D tha. Is this the way to do this suggested in the RFCs? If so, might be worth quoting chapter and verse in a comment. > + inet_ntop(AF_INET, ip, ip_str, sizeof(ip_str)); > + eth_ntop(mac, mac_str, sizeof(mac_str)); > + debug("Announcing ARP for %s / %s", ip_str, mac_str); > + > + tap_send_single(c, &annc, sizeof(annc)); > +} > diff --git a/arp.h b/arp.h > index d5ad0e1..4862e90 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_announce(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 d062ebc..3a61901 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" > =20 > /* Empheral port range: values from RFC 6335 */ > static in_port_t fwd_ephemeral_min =3D (1 << 15) + (1 << 14); > @@ -145,6 +147,14 @@ void fwd_neigh_table_update(const struct ctx *c, con= st union inany_addr *addr, > memcpy(&e->addr, &daddr, sizeof(daddr)); > memcpy(e->mac, mac, ETH_ALEN); > e->permanent =3D permanent; > + > + if (!memcmp(mac, c->our_tap_mac, ETH_ALEN)) > + return; > + > + if (inany_v4(&daddr)) > + arp_announce(c, inany_v4(&daddr), e->mac); > + else > + ndp_unsolicited_na(c, &daddr.a6); > } > =20 > /** > diff --git a/ndp.c b/ndp.c > index 7cc6e48..1e41933 100644 > --- a/ndp.c > +++ b/ndp.c > @@ -222,6 +222,16 @@ static void ndp_na(const struct ctx *c, const struct= in6_addr *dst, > ndp_send(c, dst, &na, sizeof(na)); > } > =20 > +/** > + * 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 *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_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 --ULlF2pSc4nl/EriI Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmjt2RIACgkQzQJF27ox 2Gf3qRAAimTt155q5dOmEFWfPJwEQc/lDt1+iHwyjedgBPKcDiygHEtJlWkj4How 1kROW9Vufhwiq0X7Uq8cpdwESNQoqCOG4p+1FFmpGrmlyjGw3ob5RzoNvQj7T9cO nCtkCJae8k4cJvPbc7WycHTTrgGImPPIz+B6lsGWEWFfHRu4ZwmYq/xznrkriflv DQNYDmIiAYtV7asO9nRLCw21i/VgKBkePqLbYHomsJuaaghUnhPLySx+vAXRaXlR FiCjKkxeXwBZHm/acBp12Mxk7MCQLdLQDLh2rOEJPv8QW/IrsXn8t1ucQZliHzfa 8cY/PNfe5JSTC19ztOkZujYJVr6wgSVsUkjrESLWUwlllwfuU3pHcRBStLhpiK+k wtJgbWUluiezJMPbdPsYJAAxslWbCZ/Xhzx7jDZrSIno6wUSMtcN/HNewVAUQHmr k1BiQaxxjV1reU5WPAK3Fji5YOVP0tbQmBL+yZNG8OJpyFLev/jNHmVOs0gxa/Yw unijuTu0Jman9QMFeDGalez1XLHSbWUQaRyKwXJp28rwhgmN6zg3Uh1yPhDtC/oH wHLUH6rSnwZzf+0Vmtajqn6sJadoQRxFO5muWuNwZ8f6Fc2OLtnKBrJ/UXskKRIt BcO1ldeV87qezrQX+s1sxasoR+SS9JEmYDd6mlKquuBXUyeg99s= =kljI -----END PGP SIGNATURE----- --ULlF2pSc4nl/EriI--