1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
| | /* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright (c) 2022 Red Hat GmbH
* Author: Stefano Brivio <sbrivio@redhat.com>
*/
#ifndef PACKET_H
#define PACKET_H
/**
* struct pool - Generic pool of packets stored in nmemory
* @size: Number of usable descriptors for the pool
* @count: Number of used descriptors for the pool
* @pkt: Descriptors: see macros below
*/
struct pool {
size_t size;
size_t count;
struct iovec pkt[];
};
void packet_add_do(struct pool *p, size_t len, const char *start,
const char *func, int line);
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);
void pool_flush(struct pool *p);
#define packet_add(p, len, start) \
packet_add_do(p, len, start, __func__, __LINE__)
#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_POOL_DECL(_name, _size) \
struct _name ## _t { \
size_t size; \
size_t count; \
struct iovec pkt[_size]; \
}
#define PACKET_POOL_INIT_NOCAST(_size) \
{ \
.size = _size, \
}
#define PACKET_POOL(name, size) \
PACKET_POOL_DECL(name, size) name = \
PACKET_POOL_INIT_NOCAST(size)
#define PACKET_INIT(name, size) \
(struct name ## _t) PACKET_POOL_INIT_NOCAST(size)
#define PACKET_POOL_P(name, size) \
PACKET_POOL(name ## _storage, size); \
struct pool *name = (struct pool *)&name ## _storage
#endif /* PACKET_H */
|