aboutgitcodebugslistschat
path: root/tcp_splice.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2024-07-17 14:52:18 +1000
committerStefano Brivio <sbrivio@redhat.com>2024-07-17 15:27:27 +0200
commit9b125e7776333326b91adfc4cfd54298737004cd (patch)
tree39ce4a14dacb89248652fdb7f0e7f1bfc7446a25 /tcp_splice.c
parent2fa91ee391b7bbed960bf404a405573c64d836aa (diff)
downloadpasst-9b125e7776333326b91adfc4cfd54298737004cd.tar
passt-9b125e7776333326b91adfc4cfd54298737004cd.tar.gz
passt-9b125e7776333326b91adfc4cfd54298737004cd.tar.bz2
passt-9b125e7776333326b91adfc4cfd54298737004cd.tar.lz
passt-9b125e7776333326b91adfc4cfd54298737004cd.tar.xz
passt-9b125e7776333326b91adfc4cfd54298737004cd.tar.zst
passt-9b125e7776333326b91adfc4cfd54298737004cd.zip
flow, icmp, tcp: Clean up helpers for getting flow from index
TCP (both regular and spliced) and ICMP both have macros to retrieve the relevant protcol specific flow structure from a flow index. In most cases what we actually want is to get the specific flow from a sidx. Replace those simple macros with a more precise inline, which also asserts that the flow is of the type we expect. While we're they're also add a pif_at_sidx() helper to get the interface of a specific flow & side, which is useful in some places. Finally, fix some minor style issues in the comments on some of the existing sidx related helpers. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'tcp_splice.c')
-rw-r--r--tcp_splice.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/tcp_splice.c b/tcp_splice.c
index f2d4fc6..9fc5656 100644
--- a/tcp_splice.c
+++ b/tcp_splice.c
@@ -76,7 +76,6 @@ static int splice_pipe_pool [TCP_SPLICE_PIPE_POOL_SIZE][2];
#define CONN_V6(x) ((x)->flags & SPLICE_V6)
#define CONN_V4(x) (!CONN_V6(x))
#define CONN_HAS(conn, set) (((conn)->events & (set)) == (set))
-#define CONN(idx) (&FLOW(idx)->tcp_splice)
/* Display strings for connection events */
static const char *tcp_splice_event_str[] __attribute((__unused__)) = {
@@ -95,6 +94,24 @@ static int tcp_sock_refill_ns(void *arg);
static int tcp_conn_sock_ns(const struct ctx *c, sa_family_t af);
/**
+ * conn_at_sidx() - Get spliced TCP connection specific flow at given sidx
+ * @sidx: Flow and side to retrieve
+ *
+ * Return: Spliced TCP connection at @sidx, or NULL of @sidx is invalid.
+ * Asserts if the flow at @sidx is not FLOW_TCP_SPLICE.
+ */
+static struct tcp_splice_conn *conn_at_sidx(flow_sidx_t sidx)
+{
+ union flow *flow = flow_at_sidx(sidx);
+
+ if (!flow)
+ return NULL;
+
+ ASSERT(flow->f.type == FLOW_TCP_SPLICE);
+ return &flow->tcp_splice;
+}
+
+/**
* tcp_splice_conn_epoll_events() - epoll events masks for given state
* @events: Connection event flags
* @ev: Events to fill in, 0 is accepted socket, 1 is connecting socket
@@ -502,7 +519,7 @@ bool tcp_splice_conn_from_sock(const struct ctx *c,
void tcp_splice_sock_handler(struct ctx *c, union epoll_ref ref,
uint32_t events)
{
- struct tcp_splice_conn *conn = CONN(ref.flowside.flow);
+ struct tcp_splice_conn *conn = conn_at_sidx(ref.flowside);
unsigned side = ref.flowside.side, fromside;
uint8_t lowat_set_flag, lowat_act_flag;
int eof, never_read;