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=bBYzCaOY; 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 222875A0274 for ; Wed, 02 Apr 2025 19:23:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1743614637; 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=XAQ9+47+mtrVya3mxku+vkz9wBdbE4UGXW+OlsC/si4=; b=bBYzCaOYXRVpLGKtGvaeauBLUf4eixZDIT8diV/ZhU5A2oC7EGtipDdTg5YSDabr7oNOw8 jbAdeQdfHw8PuGInarkGVSsVok6+2fScb1CstYFykNFsDRBHTeY/nrhQyNa9PzECAhm5hn 4YlXvW86v3m5W9MjflUZoo3i+IGCoAg= 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-508-dPOYNUEiOjKq4MQamhI28Q-1; Wed, 02 Apr 2025 13:23:55 -0400 X-MC-Unique: dPOYNUEiOjKq4MQamhI28Q-1 X-Mimecast-MFC-AGG-ID: dPOYNUEiOjKq4MQamhI28Q_1743614633 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 83D3218007E1 for ; Wed, 2 Apr 2025 17:23:53 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.44.33.101]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 74A9F19560AD; Wed, 2 Apr 2025 17:23:52 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH 05/18] packet: Add packet_base() Date: Wed, 2 Apr 2025 19:23:30 +0200 Message-ID: <20250402172343.858187-6-lvivier@redhat.com> In-Reply-To: <20250402172343.858187-1-lvivier@redhat.com> References: <20250402172343.858187-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: 50WSgU_JQ0Z6U78dtCMvuN3PdvwV2I6LD4Pda2xnyB0_1743614633 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: RHBQ3YNPOUW3RQO52W6RJ76W3BKCF7JR X-Message-ID-Hash: RHBQ3YNPOUW3RQO52W6RJ76W3BKCF7JR 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: Signed-off-by: Laurent Vivier --- packet.c | 37 +++++++++++++++++++++++++++++++++++++ packet.h | 7 +++++++ 2 files changed, 44 insertions(+) diff --git a/packet.c b/packet.c index 8b11e0850ff6..25ede38b94cb 100644 --- a/packet.c +++ b/packet.c @@ -156,6 +156,43 @@ void *packet_get_do(const struct pool *p, size_t idx, size_t offset, return ptr; } +/** + * packet_base_do() - Get data range from packet descriptor from given pool + * @p: Packet pool + * @idx: Index of packet descriptor in pool + * @func: For tracing: name of calling function, NULL means no trace() + * @line: For tracing: caller line of function call + * + * Return: pointer to start of data range, NULL on invalid range or descriptor + */ +/* 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; + + if (idx >= p->size || idx >= p->count) { + if (func) { + trace("packet %zu from pool size: %zu, count: %zu, " + "%s:%i", idx, p->size, p->count, func, line); + } + return NULL; + } + + data->cnt = 1; + data->off = 0; + data->iov = &p->pkt[idx]; + + for (i = 0; i < data->cnt; i++) { + if (packet_check_range(p, data->iov[i].iov_base, + data->iov[i].iov_len, func, line)) + return false; + } + + return true; +} + /** * pool_flush() - Flush a packet pool * @p: Pointer to packet pool diff --git a/packet.h b/packet.h index f386295da203..35058e747a43 100644 --- a/packet.h +++ b/packet.h @@ -35,6 +35,9 @@ void packet_add_do(struct pool *p, struct iov_tail *data, 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); void pool_flush(struct pool *p); #define packet_add(p, data) \ @@ -43,9 +46,13 @@ void pool_flush(struct pool *p); #define packet_get(p, idx, offset, len, left) \ packet_get_do(p, idx, offset, len, left, __func__, __LINE__) + #define packet_get_try(p, idx, offset, len, left) \ packet_get_do(p, idx, offset, len, left, NULL, 0) +#define packet_base(p, idx, data) \ + packet_base_do(p, idx, data, __func__, __LINE__) + #define PACKET_POOL_DECL(_name, _size, _buf) \ struct _name ## _t { \ char *buf; \ -- 2.49.0