aboutgitcodebugslistschat
path: root/tcp.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.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.c')
-rw-r--r--tcp.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/tcp.c b/tcp.c
index 05a430b..c5431f1 100644
--- a/tcp.c
+++ b/tcp.c
@@ -379,8 +379,6 @@ bool peek_offset_cap;
/* sendmsg() to socket */
static struct iovec tcp_iov [UIO_MAXIOV];
-#define CONN(idx) (&(FLOW(idx)->tcp))
-
/* Table for lookup from remote address, local port, remote port */
static flow_sidx_t tc_hash[TCP_HASH_TABLE_SIZE];
@@ -392,6 +390,24 @@ int init_sock_pool4 [TCP_SOCK_POOL_SIZE];
int init_sock_pool6 [TCP_SOCK_POOL_SIZE];
/**
+ * conn_at_sidx() - Get TCP connection specific flow at given sidx
+ * @sidx: Flow and side to retrieve
+ *
+ * Return: TCP connection at @sidx, or NULL of @sidx is invalid. Asserts if the
+ * flow at @sidx is not FLOW_TCP.
+ */
+static struct tcp_tap_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);
+ return &flow->tcp;
+}
+
+/**
* tcp_set_peek_offset() - Set SO_PEEK_OFF offset on a socket if supported
* @s: Socket to update
* @offset: Offset in bytes
@@ -2379,9 +2395,10 @@ cancel:
void tcp_timer_handler(struct ctx *c, union epoll_ref ref)
{
struct itimerspec check_armed = { { 0 }, { 0 } };
- struct tcp_tap_conn *conn = CONN(ref.flow);
+ struct tcp_tap_conn *conn = &FLOW(ref.flow)->tcp;
ASSERT(!c->no_tcp);
+ ASSERT(conn->f.type == FLOW_TCP);
/* We don't reset timers on ~ACK_FROM_TAP_DUE, ~ACK_TO_TAP_DUE. If the
* timer is currently armed, this event came from a previous setting,
@@ -2441,11 +2458,10 @@ void tcp_timer_handler(struct ctx *c, union epoll_ref ref)
*/
void tcp_sock_handler(struct ctx *c, union epoll_ref ref, uint32_t events)
{
- struct tcp_tap_conn *conn = CONN(ref.flowside.flow);
+ struct tcp_tap_conn *conn = conn_at_sidx(ref.flowside);
ASSERT(!c->no_tcp);
- ASSERT(conn->f.type == FLOW_TCP);
- ASSERT(conn->f.pif[ref.flowside.side] != PIF_TAP);
+ ASSERT(pif_at_sidx(ref.flowside) != PIF_TAP);
if (conn->events == CLOSED)
return;