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=OYmB3W20; 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 06B365A0280 for ; Mon, 26 May 2025 16:19:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748269185; 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=+hvYPn8AyyeReBapArACrrA31+Tmz4X0fYiibuYyb/4=; b=OYmB3W20prdlmozXL/AmkItiJ0MrPIUCutYytwHANxE22RKlxWqXviBClNZ2Rqpm50hZZ4 BQRSAxV69YNRErW/e4Dfqeu77Lvvj8dCdpKAUktOAGznz6lDWxuXeZC7GC62w1iRnz8Zz+ 2gp3MJMudCQ5i38FU7xbLI53qQ1ce94= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-218-bPuWR_4nPauZMFkUeZZtCw-1; Mon, 26 May 2025 10:19:43 -0400 X-MC-Unique: bPuWR_4nPauZMFkUeZZtCw-1 X-Mimecast-MFC-AGG-ID: bPuWR_4nPauZMFkUeZZtCw_1748269183 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-43eea5a5d80so14663705e9.1 for ; Mon, 26 May 2025 07:19:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748269182; x=1748873982; 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=+hvYPn8AyyeReBapArACrrA31+Tmz4X0fYiibuYyb/4=; b=ee+buIVwNB59J5HbvxyPSar/A/9F5bZq/zzzhLsExKwj/ZIhp6XPO6BE7oC1uJEDTt N3FJbk9180nTI60YiU4D8LaSjXLiEe8FKjNcWe9pcdmDLA5tFX1hq2jaq8WelcxCU8hI poFRITDgW45Zk4W+b7Q2Er1EQO75B6wqqpYsU2aAU+8rvIlQ5MpGKSH56HReQ3knvq4u 50GGPcexTm7VExGJgsh+flRta1RBm5oh/MeVhyzVHJ/rcy2KkhfOd7rTiZqf5pjJFVlp QVPnLvLYwoVMTiUJMKPR39NodvrkqpDKm5Lc+M9TFXBAaB7c2ZNNNGIEEgqsN/Id75gQ ILFw== X-Gm-Message-State: AOJu0YyZoW/TZsUoAYg5wpPb2eDe9dcl9GeQDsZZ+5IyN7GTF19zCGF0 ceTOrRCCAscMrXenkOlFHcIrk923ZU3YTpiSmuKqD3PyLk9vgo0lgC/iQM6AVPNtIoIXuq5Dh82 X1KWmjZKBwhR6uyGUTQ8WKSWYvqMItuXKjEveFapJ/y861bJbwdRwr9aLAbyznvnSHdquGaEMZz KlCvq7osTOBFvlTPiZfWGDYNcLQ1lEsGFUqTYc X-Gm-Gg: ASbGncsKfU9XEhhCyJLBdnDdO7DYp7rL3KpJSjrCij59k2qvRvGvyHQllkB/kc7tHv4 TkVMubmui9/p1tOE1pBQ4eH711naqkgvWkyKTR+1zSCOVRagKudsF7PbQTYJRciaaZSF881bnPy 9+lN4UgKsqnoQspNoW+3paQugr/eQi4XUS1Sbpn+3QySccrgea3Yvhr943Qn/1mYopGDz73PFle cZftampe7CiIS+MZ5m1PO1Gw95XsAweMY9/Wqfrq+MQQPwazX7qEOBiFL1pp7lT+EUjucbcP3cA DeKMyoNu/Jr84W0baPUKmPo= X-Received: by 2002:a05:600c:4fd1:b0:43c:eeee:b70a with SMTP id 5b1f17b1804b1-44c9493e68dmr67257015e9.22.1748269182124; Mon, 26 May 2025 07:19:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEEIBejAjXGUtj9Musrl0Xk6VTXoQGnRtmXdZuJIwz4zwzrPU0JNcu2XkxMn3nHBXaRpnC14g== X-Received: by 2002:a05:600c:4fd1:b0:43c:eeee:b70a with SMTP id 5b1f17b1804b1-44c9493e68dmr67256745e9.22.1748269181631; Mon, 26 May 2025 07:19:41 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-447f7bae3b9sm235137535e9.33.2025.05.26.07.19.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 07:19:41 -0700 (PDT) Date: Mon, 26 May 2025 16:19:40 +0200 From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH v5 06/29] packet: Add packet_data() Message-ID: <20250526161940.4f502eaf@elisabeth> In-Reply-To: <20250417165136.2688884-7-lvivier@redhat.com> References: <20250417165136.2688884-1-lvivier@redhat.com> <20250417165136.2688884-7-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: 1G0AUaVZFYs-Wwb6EAQEISwPT_wZ_Y--Wv4bx7UD1fE_1748269183 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: QRHHUISPVDTWBLPOZ6SPCBO42WVOTILP X-Message-ID-Hash: QRHHUISPVDTWBLPOZ6SPCBO42WVOTILP 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 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, 17 Apr 2025 18:51:13 +0200 Laurent Vivier wrote: > packet_data() gets the data range from a packet descriptor from a > given pool. > > It uses iov_tail to return the packet memory. > > Signed-off-by: Laurent Vivier > --- > packet.c | 41 +++++++++++++++++++++++++++++++++++++++++ > packet.h | 5 +++++ > 2 files changed, 46 insertions(+) > > diff --git a/packet.c b/packet.c > index 98ded4e27aae..675bccf4d787 100644 > --- a/packet.c > +++ b/packet.c > @@ -190,6 +190,47 @@ void *packet_get_do(const struct pool *p, const size_t idx, > return r; > } > > +/** > + * packet_data_do() - Get data range from packet descriptor from given pool All the code changes here make sense to me, but the name itself, packet_data_do(), is rather cryptic, in the sense that 'data' is not a verb. Was this supposed to be a temporary name to use before removing packet_get_do() later in the series? > + * @p: Packet pool > + * @idx: Index of packet descriptor in pool > + * @data: IOV tail to store the address of the data (output) > + * @func: For tracing: name of calling function, NULL means no trace() > + * @line: For tracing: caller line of function call > + * > + * Return: true if @data contains valid data, false otherwise I think it's not so much about "valid" data (how do we define data validity here?): we return false if the packet index is invalid. If there's something wrong with @data, we don't return at all. > + */ > +/* cppcheck-suppress unusedFunction */ > +bool packet_data_do(const struct pool *p, size_t idx, > + struct iov_tail *data, > + const char *func, int line) > +{ > + size_t i; > + > + ASSERT_WITH_MSG(p->count <= p->size, > + "Corrupt pool count: %zu, size: %zu, %s:%i", > + p->count, p->size, func, line); > + > + if (idx >= p->count) { > + debug("packet %zu from pool size: %zu, count: %zu, " > + "%s:%i", idx, p->size, p->count, func, line); > + return false; > + } > + > + data->cnt = 1; > + data->off = 0; > + data->iov = &p->pkt[idx]; > + > + for (i = 0; i < data->cnt; i++) { > + ASSERT_WITH_MSG(!packet_check_range(p, data->iov[i].iov_base, > + data->iov[i].iov_len, > + func, line), > + "Corrupt packet pool, %s:%i", func, line); I think "Corrupted" is a bit more common in computing, but I guess it's correct either way. > + } > + > + return true; > +} > + > /** > * pool_flush() - Flush a packet pool > * @p: Pointer to packet pool > diff --git a/packet.h b/packet.h > index af40b39b5251..062afb978124 100644 > --- a/packet.h > +++ b/packet.h > @@ -39,6 +39,9 @@ void *packet_get_try_do(const struct pool *p, const size_t idx, > void *packet_get_do(const struct pool *p, const size_t idx, > size_t offset, size_t len, size_t *left, > const char *func, int line); > +bool packet_data_do(const struct pool *p, const size_t idx, > + struct iov_tail *data, > + const char *func, int line); > bool pool_full(const struct pool *p); > void pool_flush(struct pool *p); > > @@ -49,6 +52,8 @@ void pool_flush(struct pool *p); > packet_get_try_do(p, idx, offset, len, left, __func__, __LINE__) > #define packet_get(p, idx, offset, len, left) \ > packet_get_do(p, idx, offset, len, left, __func__, __LINE__) > +#define packet_data(p, idx, data) \ > + packet_data_do(p, idx, data, __func__, __LINE__) > > #define PACKET_POOL_DECL(_name, _size, _buf) \ > struct _name ## _t { \ -- Stefano