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