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=fvywjPkj; 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 8B4B05A028D for ; Wed, 04 Jun 2025 15:08:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749042532; 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=lnt8ZegyyENSFq6MJrxPK5RQhmIwcCxMz555uFqa3wU=; b=fvywjPkjocmlfL6wxa3Dv5KXR68gZIsb6zgdJVJ5nvaVyu9RA+21p/ze0io1QNL3mMsFQf ovs6pYmHGbHPJCjUv24LdpFMpH1GXJzBuUPOFHFJPGnQG4gHxHJ6Ea6yrLzMj7xy1VGwGE 2/pmqYAz4RQJrkORBP4LgBNWZPpdhS0= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-553-Z6TIzhFSOt-yBOQ-n9fPtg-1; Wed, 04 Jun 2025 09:08:50 -0400 X-MC-Unique: Z6TIzhFSOt-yBOQ-n9fPtg-1 X-Mimecast-MFC-AGG-ID: Z6TIzhFSOt-yBOQ-n9fPtg_1749042529 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 37E071801BCE for ; Wed, 4 Jun 2025 13:08:49 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.45.225.52]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 06A371955D8E; Wed, 4 Jun 2025 13:08:47 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH v6 06/30] packet: Add packet_data() Date: Wed, 4 Jun 2025 15:08:10 +0200 Message-ID: <20250604130834.3868010-7-lvivier@redhat.com> In-Reply-To: <20250604130834.3868010-1-lvivier@redhat.com> References: <20250604130834.3868010-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: GBqNx2M5kjxlxeLepHWIfCSiHMRkpF465GNMCG41hUI_1749042529 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: DO552WAUIJBUFRVU4S46BU623QJNYY6X X-Message-ID-Hash: DO552WAUIJBUFRVU4S46BU623QJNYY6X X-MailFrom: lvivier@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: Laurent Vivier 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: 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 | 42 ++++++++++++++++++++++++++++++++++++++++++ packet.h | 5 +++++ 2 files changed, 47 insertions(+) diff --git a/packet.c b/packet.c index 98ded4e27aae..82adc9fd1a39 100644 --- a/packet.c +++ b/packet.c @@ -190,6 +190,48 @@ 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 + * @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: false if packet index is invalid, true otherwise. + * If something wrong with @data, don't return at all (assert). + */ +/* 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, + "Corrupted 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); + } + + 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 { \ -- 2.49.0