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=Mpn6Byse; 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 6725B5A026F for ; Tue, 30 Sep 2025 01:59:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1759190341; 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=CQaz0BqKW5EvuQ2MX81w+Zp+bVwgo1Qc3HFYXBV3rK4=; b=Mpn6Byse9V7mybo7xNL+SCu4WoSOMZipHVhCFb7mYi5ESXQQYfo/8Pwe9U9ECzS9iiCE+w YCYOFlmcTBu8mUL8unKg5ARvlhA7Sf0v7foU1kiXl6el9hGfIthKo7dXDw+UXpyMftb/aL kd7B9afFSvF/hJP5Bojrm5FTyyBHwf0= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-66-hc-kUCYCOvusLckLXacylA-1; Mon, 29 Sep 2025 19:59:00 -0400 X-MC-Unique: hc-kUCYCOvusLckLXacylA-1 X-Mimecast-MFC-AGG-ID: hc-kUCYCOvusLckLXacylA_1759190339 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3ee1365964cso3655702f8f.2 for ; Mon, 29 Sep 2025 16:59:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759190338; x=1759795138; 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=CQaz0BqKW5EvuQ2MX81w+Zp+bVwgo1Qc3HFYXBV3rK4=; b=EbCGNz+0oMKN2TTtaUv7vXlC33Hf3g1szz8TnzovEO10D0hQ2HiY9UCMrMG+9hVuGy ihe05/vR+qRcXMI4DIUOM54qH2TMzjhzXl3HDrivinCLCVpSj4tfqwzrzpey7gZKOz1U 0Lh8to+Kmh3anLdA1IDpFZADjt2s8Q5X/e7wHyXhRNZleaWdRld05O2DwyZNwxEmBzFt x0P+xZ3ZknInk4J+UXVe1siXLwYY0GTSEhp/0JTEIICHLW5/oLY/voFVxUFGD9qDB42a Gt98qNXdZ/9QQxVUjPnmfSapp/AC+obgRFrgSuDPQVk/hiaZw1BpHuinwmvo/WSk8o2h iwUA== X-Forwarded-Encrypted: i=1; AJvYcCWNeL+gz6T0s7aPrL3R3EuelPaik23wT/4FbK459teL9HIXWWEMw/FuXweXoOAxJPmhpgVYXpvfyOw=@passt.top X-Gm-Message-State: AOJu0YxVaEnj4p795iQPPxkNeOstq3HnfqObLizP3V89WPNiCUnxWL6+ Pyj/S9Q0W69DQ+VqONCf66SXd+nqvkIpTN4q9QTvC+ZOmk8RpSVJhtIdzdShW3VUB04nO8rK+hv T0RrLula5PQv30V+08Nchnd3lSdsviGS1Jodbo8PdBPQs80YPI+ieMsiYc+kjcA== X-Gm-Gg: ASbGnctEmFROcdkfi525vJiyCL5R7xpJ6/EDoTCSsuYxdQh5fsxus122O2L7NWRNhLp OxdAeqnD2YaTCByNeAvYSC+Qutgxy09F49GPIuBvsPrjGHnWfW5Pl2AiJzCSKdkNYMfRtwW9n6v OyVNNpScEF84ZiGuXH/p5/Jz9JzRP7ugTw8ZYsgwgsMKI1FMgiWiagX+crfQTuDeYG9eH4Twm1K QbptwAcHQG66EONrdrAtB6YjVkCTPoRhnnKdLA7raN6iZwTyC7Q/W8UsRCxMp2dL+xpdSP9UksR VY58RitSYmN0/OoVM6z+QFxa1xR6g8OsZI+/4fkGqt0PfCrA4uA= X-Received: by 2002:a5d:5d11:0:b0:3f9:bc33:2fab with SMTP id ffacd0b85a97d-40e4a70ccc9mr17123845f8f.60.1759190338638; Mon, 29 Sep 2025 16:58:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFe0J5oWWJ8n0419FpcBmiTqLHevOLRaviO2osuwIcFO0jwFiaCbw9bD14VcjI2UeIMQ9ZW+Q== X-Received: by 2002:a5d:5d11:0:b0:3f9:bc33:2fab with SMTP id ffacd0b85a97d-40e4a70ccc9mr17123840f8f.60.1759190338143; Mon, 29 Sep 2025 16:58:58 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-40fc5603161sm20506078f8f.35.2025.09.29.16.58.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Sep 2025 16:58:57 -0700 (PDT) Date: Tue, 30 Sep 2025 01:58:56 +0200 From: Stefano Brivio To: Jon Maloy Subject: Re: [PATCH v11 3/9] arp/ndp: send gratuitous ARP / unsolicitated NA when MAC cache entry added Message-ID: <20250930015856.720ffe09@elisabeth> In-Reply-To: <20250927192522.3024554-4-jmaloy@redhat.com> References: <20250927192522.3024554-1-jmaloy@redhat.com> <20250927192522.3024554-4-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: OCOgSQtDbUOIe6kPGw313dDPdkkYFAIL2vAB-2caxog_1759190339 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: HNEPC2KSXUHEUJE3C5F2N7H4RKOCVEMO X-Message-ID-Hash: HNEPC2KSXUHEUJE3C5F2N7H4RKOCVEMO 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 Sat, 27 Sep 2025 15:25:16 -0400 Jon Maloy wrote: > Gratuitious ARP and unsolicitated NA 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 also 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. > --- > arp.c | 41 +++++++++++++++++++++++++++++++++++++++++ > arp.h | 2 ++ > fwd.c | 8 ++++++++ > ndp.c | 10 ++++++++++ > ndp.h | 1 + > 5 files changed, 62 insertions(+) > > 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 IPv4 host > + * @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 = 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 = htons(ARPOP_REQUEST); > + annc.ah.ar_hrd = htons(ARPHRD_ETHER); > + annc.ah.ar_pro = htons(ETH_P_IP); > + annc.ah.ar_hln = ETH_ALEN; > + annc.ah.ar_pln = 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)); > + > + inet_ntop(AF_INET, ip, ip_str, sizeof(ip_str)); > + debug("Sending ARP announcement for %s", ip_str); > + > + tap_send_single(c, &annc, sizeof(annc)); > +} > + Nit: git show / log highlights this excess newline in red, and I merely relay the pedantry. > diff --git a/arp.h b/arp.h > index d5ad0e1..2cf1326 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_send_gratuitous(const struct ctx *c, struct in_addr *ip, > + const unsigned char *mac); > > #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" > > /* Empheral port range: values from RFC 6335 */ > static in_port_t fwd_ephemeral_min = (1 << 15) + (1 << 14); > @@ -131,6 +133,12 @@ void fwd_neigh_table_update(const struct ctx *c, > > 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); > } > > /** > 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)); > } > > +/** > + * ndp_send_unsolicited_na() - Send unsolicited NA This comment, strictly speaking, should be related to the notification mechanism, but the usage here makes me wonder: do we want to announce link-layer addresses for link-local (IPv6) addresses as well? Those are not reachable from the guest. I'm not sure if we want to filter IPv6 addresses a bit, in general. I didn't really think it through. > + * @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 *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_send_unsolicited_na(const struct ctx *c, const struct in6_addr *addr); > > #endif /* NDP_H */ -- Stefano