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=YBiYsrm0; 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 615F65A0280 for ; Mon, 26 May 2025 16:19:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748269140; 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=nBFI3TttFOW2JBPgV7YSqjYnqJ4g9cmmJoHrLyxuX/I=; b=YBiYsrm0kCBIO775BuFdYLgn4B7FE4qq/tnJb9aItEHNwMTsuV/FJar6sXzvkwpC24f3xO Z/gghDTh9DcOQ7lOxwJNwEbLKTZo8wDat/wseMPXlQjYdqaoqN/CfFCXsYOJRrTNL4swYd KkLZwnLCjFsbMVyPvMVSUFIg69Ma5DI= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-357-RHBONHO2Msuiv78mvxT6Ng-1; Mon, 26 May 2025 10:18:58 -0400 X-MC-Unique: RHBONHO2Msuiv78mvxT6Ng-1 X-Mimecast-MFC-AGG-ID: RHBONHO2Msuiv78mvxT6Ng_1748269138 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3a3683aa00eso1095908f8f.1 for ; Mon, 26 May 2025 07:18:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748269138; x=1748873938; 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=nBFI3TttFOW2JBPgV7YSqjYnqJ4g9cmmJoHrLyxuX/I=; b=APZYbyz4zFUr/IIJlUM83YUNKYij92E6tDCIIhdbuZqAF46dhzHMFmF86ksPuAF1PN hNqxVYWrJfCvz3DPwZnAL3A1doTSYZFduPm1Eq68tb2TAjTPnZUsSocgHgVMNCS7UGKn 5s/kplUexSRVPnFIUitJPBWVBnSCBCXr9nZGXe+wHgQ9yFutbnSppfw3ZwObZYrcb5tv 4WlXXsFSD5QTzcaEQqFSNhjhMksX/r/bURgDXXYi9pfb3zABZNHbScIHJjlaB7dRGgvm ck9w0d5MoIQ8uIQO1psomMUM5H6mlFoQQYLSs6Ypq/B8ivYK3wq9o7H920Xx9ETcLlON 7bGQ== X-Gm-Message-State: AOJu0YxxDIt9wCutN3zjE/VrMF7pBf7BmJFwXFGjcLo8mMF6d1u5JcHa d3sG+JEFrj+SCahBhQ1hu5EpasnnDnhFPXy3Ww+QlSXs/YB6mtqUT608YLav6RyBVdEr5BD3cOE lmIW8pDSPugmhkJNQFZlHsmgoF09Z3Rw6QISCMgiCbO5aWLkTxcNQ/g== X-Gm-Gg: ASbGncuLbEsCGEGtjPHEVck4c4616n1kyLFYV6qC5+YRDGnu9+RGHQCqfm4kuVIi0Un Mo2TGyQmJ6Wm7tD+zK5q1Ws8TW1IDodJKIQhWM8ZIEITaFlh1lO9Zxob9FkAt8q/sK6b7my4vAx m9Tatn41J/CrEAJj2v30OdfBbcWWMMfRmEgphlx11j2LIUwFTeUEjw551sX/guuAk7VCUum5wPQ IdmLlW8zyQy5TB6BVlKI2Ep9B9ehQ1Oj7ggdcXzAlRmC0YzOR/5xrcgmyvF30r8yqEpmBd/DNx5 RuAi5cVRe0Y2HWYl7UF4W4UZqn1IUryaTclJn9gz X-Received: by 2002:a5d:588e:0:b0:3a3:64b9:773 with SMTP id ffacd0b85a97d-3a4ca12d2afmr7608371f8f.10.1748269137740; Mon, 26 May 2025 07:18:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGntjb0kJK5h1GLRrQszmhVeMi46uHzJqyg2iVW7L5GxZj3+Le1jtegTiieB8oa70rEMCoQgA== X-Received: by 2002:a5d:588e:0:b0:3a3:64b9:773 with SMTP id ffacd0b85a97d-3a4ca12d2afmr7608349f8f.10.1748269137313; Mon, 26 May 2025 07:18:57 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a4cc932836sm7851825f8f.39.2025.05.26.07.18.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 07:18:57 -0700 (PDT) Date: Mon, 26 May 2025 16:18:55 +0200 From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH v5 01/29] arp: Don't mix incoming and outgoing buffers Message-ID: <20250526161846.658537f4@elisabeth> In-Reply-To: <20250417165136.2688884-2-lvivier@redhat.com> References: <20250417165136.2688884-1-lvivier@redhat.com> <20250417165136.2688884-2-lvivier@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: q5bKKSXh1ky2yz4Udqg5aoroNWeHVg1i6-SbHcfzJnU_1748269138 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: TDYNHR4XQQBKAFIGHXNGP5KUNVOU2QSH X-Message-ID-Hash: TDYNHR4XQQBKAFIGHXNGP5KUNVOU2QSH 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: passt-dev@passt.top, David Gibson 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: Here's my review, finally. Apologies for the very substantial delay. On Thu, 17 Apr 2025 18:51:08 +0200 Laurent Vivier wrote: > Don't use the memory of the incoming packet to build the outgoing buffer > as it can be memory of the TX queue in the case of vhost-user. > > Moreover with vhost-user, the packet can be splitted accross several > iovec and it's easier to rebuild it in a buffer than updating an > existing iovec array. > > Signed-off-by: Laurent Vivier > Reviewed-by: David Gibson > --- > arp.c | 84 ++++++++++++++++++++++++++++++++++++++--------------------- > 1 file changed, 55 insertions(+), 29 deletions(-) > > diff --git a/arp.c b/arp.c > index fc482bbd9938..9d68d7c3b602 100644 > --- a/arp.c > +++ b/arp.c > @@ -31,56 +31,82 @@ > #include "tap.h" > > /** > - * arp() - Check if this is a supported ARP message, reply as needed > + * ignore_arp() - Check if this is a supported ARP message > * @c: Execution context > - * @p: Packet pool, single packet with Ethernet buffer > + * @ah: ARP header > + * @am: ARP message > * > - * Return: 1 if handled, -1 on failure > + * Return: true if the message is supported, false otherwise. I find this, in combination with the name, a bit confusing. You now have ignore_arp() returning true if the ARP message should *not* be ignored. As this function is essentially a filter, rather than reversing the return value, I'd rather reverse the name, say: * accept_arp() - Check if we should accept this ARP message > */ > -int arp(const struct ctx *c, const struct pool *p) > +static bool ignore_arp(const struct ctx *c, > + const struct arphdr *ah, const struct arpmsg *am) > { > - unsigned char swap[4]; > - struct ethhdr *eh; > - struct arphdr *ah; > - struct arpmsg *am; > - size_t l2len; > - > - eh = packet_get(p, 0, 0, sizeof(*eh), NULL); > - ah = packet_get(p, 0, sizeof(*eh), sizeof(*ah), NULL); > - am = packet_get(p, 0, sizeof(*eh) + sizeof(*ah), sizeof(*am), NULL); > - > - if (!eh || !ah || !am) > - return -1; > - > if (ah->ar_hrd != htons(ARPHRD_ETHER) || > ah->ar_pro != htons(ETH_P_IP) || > ah->ar_hln != ETH_ALEN || > ah->ar_pln != 4 || > ah->ar_op != htons(ARPOP_REQUEST)) > - return 1; > + return true; > > /* Discard announcements, but not 0.0.0.0 "probes" */ > if (memcmp(am->sip, &in4addr_any, sizeof(am->sip)) && > !memcmp(am->sip, am->tip, sizeof(am->sip))) > - return 1; > + return true; > > /* Don't resolve the guest's assigned address, either. */ > if (!memcmp(am->tip, &c->ip4.addr, sizeof(am->tip))) > + return true; > + > + return false; > +} > + > +/** > + * arp() - Check if this is a supported ARP message, reply as needed > + * @c: Execution context > + * @p: Packet pool, single packet with Ethernet buffer > + * > + * Return: 1 if handled, -1 on failure > + */ > +int arp(const struct ctx *c, const struct pool *p) > +{ > + struct { > + struct ethhdr eh; > + struct arphdr ah; > + struct arpmsg am; > + } __attribute__((__packed__)) resp; > + const struct ethhdr *eh; > + const struct arphdr *ah; > + const struct arpmsg *am; > + > + eh = packet_get(p, 0, 0, sizeof(*eh), NULL); > + ah = packet_get(p, 0, sizeof(*eh), sizeof(*ah), NULL); > + am = packet_get(p, 0, sizeof(*eh) + sizeof(*ah), sizeof(*am), NULL); > + > + if (!eh || !ah || !am) > + return -1; > + > + if (ignore_arp(c, ah, am)) > return 1; > > - ah->ar_op = htons(ARPOP_REPLY); > - memcpy(am->tha, am->sha, sizeof(am->tha)); > - memcpy(am->sha, c->our_tap_mac, sizeof(am->sha)); > + /* ethernet header */ Nit: Ethernet > + resp.eh.h_proto = htons(ETH_P_ARP); > + memcpy(resp.eh.h_dest, eh->h_source, sizeof(resp.eh.h_dest)); > + memcpy(resp.eh.h_source, c->our_tap_mac, sizeof(resp.eh.h_source)); > > - memcpy(swap, am->tip, sizeof(am->tip)); > - memcpy(am->tip, am->sip, sizeof(am->tip)); > - memcpy(am->sip, swap, sizeof(am->sip)); > + /* ARP header */ > + resp.ah.ar_op = htons(ARPOP_REPLY); > + resp.ah.ar_hrd = ah->ar_hrd; > + resp.ah.ar_pro = ah->ar_pro; > + resp.ah.ar_hln = ah->ar_hln; > + resp.ah.ar_pln = ah->ar_pln; > > - l2len = sizeof(*eh) + sizeof(*ah) + sizeof(*am); > - memcpy(eh->h_dest, eh->h_source, sizeof(eh->h_dest)); > - memcpy(eh->h_source, c->our_tap_mac, sizeof(eh->h_source)); > + /* ARP message */ > + memcpy(resp.am.sha, c->our_tap_mac, sizeof(resp.am.sha)); > + memcpy(resp.am.sip, am->tip, sizeof(resp.am.sip)); > + memcpy(resp.am.tha, am->sha, sizeof(resp.am.tha)); > + memcpy(resp.am.tip, am->sip, sizeof(resp.am.tip)); > > - tap_send_single(c, eh, l2len); > + tap_send_single(c, &resp, sizeof(resp)); > > return 1; > } -- Stefano