passt: Relicense to GPL 2.0, or any later version
In practical terms, passt doesn't benefit from the additional
protection offered by the AGPL over the GPL, because it's not
suitable to be executed over a computer network.
Further, restricting the distribution under the version 3 of the GPL
wouldn't provide any practical advantage either, as long as the passt
codebase is concerned, and might cause unnecessary compatibility
dilemmas.
Change licensing terms to the GNU General Public License Version 2,
or any later version, with written permission from all current and
past contributors, namely: myself, David Gibson, Laine Stump, Andrea
Bolognani, Paul Holzinger, Richard W.M. Jones, Chris Kuhn, Florian
Weimer, Giuseppe Scrivano, Stefan Hajnoczi, and Vasiliy Ulyanov.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2023-04-05 20:11:44 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later
|
treewide: Packet abstraction with mandatory boundary checks
Implement a packet abstraction providing boundary and size checks
based on packet descriptors: packets stored in a buffer can be queued
into a pool (without storage of its own), and data can be retrieved
referring to an index in the pool, specifying offset and length.
Checks ensure data is not read outside the boundaries of buffer and
descriptors, and that packets added to a pool are within the buffer
range with valid offset and indices.
This implies a wider rework: usage of the "queueing" part of the
abstraction mostly affects tap_handler_{passt,pasta}() functions and
their callees, while the "fetching" part affects all the guest or tap
facing implementations: TCP, UDP, ICMP, ARP, NDP, DHCP and DHCPv6
handlers.
Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2022-03-25 13:02:47 +01:00
|
|
|
* 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 a buffer
|
|
|
|
* @buf: Buffer storing packet descriptors
|
|
|
|
* @buf_size: Total size of buffer
|
|
|
|
* @size: Number of usable descriptors for the pool
|
|
|
|
* @count: Number of used descriptors for the pool
|
|
|
|
* @pkt: Descriptors: see macros below
|
|
|
|
*/
|
|
|
|
struct pool {
|
|
|
|
char *buf;
|
|
|
|
size_t buf_size;
|
|
|
|
size_t size;
|
|
|
|
size_t count;
|
2023-08-11 15:51:51 +02:00
|
|
|
struct iovec pkt[1];
|
treewide: Packet abstraction with mandatory boundary checks
Implement a packet abstraction providing boundary and size checks
based on packet descriptors: packets stored in a buffer can be queued
into a pool (without storage of its own), and data can be retrieved
referring to an index in the pool, specifying offset and length.
Checks ensure data is not read outside the boundaries of buffer and
descriptors, and that packets added to a pool are within the buffer
range with valid offset and indices.
This implies a wider rework: usage of the "queueing" part of the
abstraction mostly affects tap_handler_{passt,pasta}() functions and
their callees, while the "fetching" part affects all the guest or tap
facing implementations: TCP, UDP, ICMP, ARP, NDP, DHCP and DHCPv6
handlers.
Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2022-03-25 13:02:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void packet_add_do(struct pool *p, size_t len, const char *start,
|
2022-03-26 07:23:21 +01:00
|
|
|
const char *func, int line);
|
2023-09-21 06:49:38 +02:00
|
|
|
void *packet_get_do(const struct pool *p, const size_t idx,
|
2022-03-26 07:23:21 +01:00
|
|
|
size_t offset, size_t len, size_t *left,
|
|
|
|
const char *func, int line);
|
treewide: Packet abstraction with mandatory boundary checks
Implement a packet abstraction providing boundary and size checks
based on packet descriptors: packets stored in a buffer can be queued
into a pool (without storage of its own), and data can be retrieved
referring to an index in the pool, specifying offset and length.
Checks ensure data is not read outside the boundaries of buffer and
descriptors, and that packets added to a pool are within the buffer
range with valid offset and indices.
This implies a wider rework: usage of the "queueing" part of the
abstraction mostly affects tap_handler_{passt,pasta}() functions and
their callees, while the "fetching" part affects all the guest or tap
facing implementations: TCP, UDP, ICMP, ARP, NDP, DHCP and DHCPv6
handlers.
Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2022-03-25 13:02:47 +01:00
|
|
|
void pool_flush(struct pool *p);
|
|
|
|
|
|
|
|
#define packet_add(p, len, start) \
|
2022-06-08 11:08:29 +02:00
|
|
|
packet_add_do(p, len, start, __func__, __LINE__)
|
treewide: Packet abstraction with mandatory boundary checks
Implement a packet abstraction providing boundary and size checks
based on packet descriptors: packets stored in a buffer can be queued
into a pool (without storage of its own), and data can be retrieved
referring to an index in the pool, specifying offset and length.
Checks ensure data is not read outside the boundaries of buffer and
descriptors, and that packets added to a pool are within the buffer
range with valid offset and indices.
This implies a wider rework: usage of the "queueing" part of the
abstraction mostly affects tap_handler_{passt,pasta}() functions and
their callees, while the "fetching" part affects all the guest or tap
facing implementations: TCP, UDP, ICMP, ARP, NDP, DHCP and DHCPv6
handlers.
Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2022-03-25 13:02:47 +01:00
|
|
|
|
2023-09-21 06:49:38 +02:00
|
|
|
#define packet_get(p, idx, offset, len, left) \
|
|
|
|
packet_get_do(p, idx, offset, len, left, __func__, __LINE__)
|
treewide: Packet abstraction with mandatory boundary checks
Implement a packet abstraction providing boundary and size checks
based on packet descriptors: packets stored in a buffer can be queued
into a pool (without storage of its own), and data can be retrieved
referring to an index in the pool, specifying offset and length.
Checks ensure data is not read outside the boundaries of buffer and
descriptors, and that packets added to a pool are within the buffer
range with valid offset and indices.
This implies a wider rework: usage of the "queueing" part of the
abstraction mostly affects tap_handler_{passt,pasta}() functions and
their callees, while the "fetching" part affects all the guest or tap
facing implementations: TCP, UDP, ICMP, ARP, NDP, DHCP and DHCPv6
handlers.
Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2022-03-25 13:02:47 +01:00
|
|
|
|
2023-09-21 06:49:38 +02:00
|
|
|
#define packet_get_try(p, idx, offset, len, left) \
|
|
|
|
packet_get_do(p, idx, offset, len, left, NULL, 0)
|
treewide: Packet abstraction with mandatory boundary checks
Implement a packet abstraction providing boundary and size checks
based on packet descriptors: packets stored in a buffer can be queued
into a pool (without storage of its own), and data can be retrieved
referring to an index in the pool, specifying offset and length.
Checks ensure data is not read outside the boundaries of buffer and
descriptors, and that packets added to a pool are within the buffer
range with valid offset and indices.
This implies a wider rework: usage of the "queueing" part of the
abstraction mostly affects tap_handler_{passt,pasta}() functions and
their callees, while the "fetching" part affects all the guest or tap
facing implementations: TCP, UDP, ICMP, ARP, NDP, DHCP and DHCPv6
handlers.
Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2022-03-25 13:02:47 +01:00
|
|
|
|
|
|
|
#define PACKET_POOL_DECL(_name, _size, _buf) \
|
|
|
|
struct _name ## _t { \
|
|
|
|
char *buf; \
|
|
|
|
size_t buf_size; \
|
|
|
|
size_t size; \
|
|
|
|
size_t count; \
|
2023-08-11 15:51:51 +02:00
|
|
|
struct iovec pkt[_size]; \
|
treewide: Packet abstraction with mandatory boundary checks
Implement a packet abstraction providing boundary and size checks
based on packet descriptors: packets stored in a buffer can be queued
into a pool (without storage of its own), and data can be retrieved
referring to an index in the pool, specifying offset and length.
Checks ensure data is not read outside the boundaries of buffer and
descriptors, and that packets added to a pool are within the buffer
range with valid offset and indices.
This implies a wider rework: usage of the "queueing" part of the
abstraction mostly affects tap_handler_{passt,pasta}() functions and
their callees, while the "fetching" part affects all the guest or tap
facing implementations: TCP, UDP, ICMP, ARP, NDP, DHCP and DHCPv6
handlers.
Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2022-03-25 13:02:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#define PACKET_POOL_INIT_NOCAST(_size, _buf, _buf_size) \
|
|
|
|
{ \
|
|
|
|
.buf_size = _buf_size, \
|
|
|
|
.buf = _buf, \
|
|
|
|
.size = _size, \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PACKET_POOL(name, size, buf, buf_size) \
|
|
|
|
PACKET_POOL_DECL(name, size, buf) name = \
|
|
|
|
PACKET_POOL_INIT_NOCAST(size, buf, buf_size)
|
|
|
|
|
|
|
|
#define PACKET_INIT(name, size, buf, buf_size) \
|
|
|
|
(struct name ## _t) PACKET_POOL_INIT_NOCAST(size, buf, buf_size)
|
|
|
|
|
|
|
|
#define PACKET_POOL_NOINIT(name, size, buf) \
|
|
|
|
PACKET_POOL_DECL(name, size, buf) name ## _storage; \
|
|
|
|
static struct pool *name = (struct pool *)&name ## _storage
|
|
|
|
|
|
|
|
#define PACKET_POOL_P(name, size, buf, buf_size) \
|
|
|
|
PACKET_POOL(name ## _storage, size, buf, buf_size); \
|
|
|
|
struct pool *name = (struct pool *)&name ## _storage
|
|
|
|
|
|
|
|
#endif /* PACKET_H */
|