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=RJ8xayuP; 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 695815A061B for ; Fri, 11 Apr 2025 15:10:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744377048; 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=+iz/u6NePoivDIxkVD3n+O8QcDc2NR89Mk1OCEyl7nk=; b=RJ8xayuPkFmGKL0ZYABkGHzD+ymzuanWwBamvcd6tTYldp20XNS3ll3S2GuEh7iY7L4vCy vtuE1zM3FWIjYowS2liYQJW0+KJ4ss853EPpMOHDmQxwYgGb4n79llCNparExyATu3H+wk JX8jLRim5iqNG4oirLSk3fF7+ReAcQA= 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-523-pKy5MfIkPWWA7EXYCNMerQ-1; Fri, 11 Apr 2025 09:10:46 -0400 X-MC-Unique: pKy5MfIkPWWA7EXYCNMerQ-1 X-Mimecast-MFC-AGG-ID: pKy5MfIkPWWA7EXYCNMerQ_1744377046 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 0ECC81800EC5 for ; Fri, 11 Apr 2025 13:10:46 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.44.32.165]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F07B019560AD; Fri, 11 Apr 2025 13:10:44 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH v2 06/20] packet: Add packet_base() Date: Fri, 11 Apr 2025 15:10:16 +0200 Message-ID: <20250411131031.1398006-7-lvivier@redhat.com> In-Reply-To: <20250411131031.1398006-1-lvivier@redhat.com> References: <20250411131031.1398006-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: e-osh-unnwRW7y2aLQanTSqLldHIIIqxlQ4onWUa4-c_1744377046 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: CFTJFQO3LLPKALATSXKZH5CZMWLJUEWK X-Message-ID-Hash: CFTJFQO3LLPKALATSXKZH5CZMWLJUEWK 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_base() 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..c3f329d53507 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_base_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: true if @data contains valid data, false otherwise + */ +/* cppcheck-suppress unusedFunction */ +bool packet_base_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); + } + + return true; +} + /** * pool_flush() - Flush a packet pool * @p: Pointer to packet pool diff --git a/packet.h b/packet.h index af40b39b5251..ee7a5304a034 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_base_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_base(p, idx, data) \ + packet_base_do(p, idx, data, __func__, __LINE__) #define PACKET_POOL_DECL(_name, _size, _buf) \ struct _name ## _t { \ -- 2.49.0