aboutgitcodebugslistschat
path: root/tcp.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2024-02-28 22:25:10 +1100
committerStefano Brivio <sbrivio@redhat.com>2024-02-29 09:48:01 +0100
commit0f938c3b9a9dbc854c1d2e33fab5af41b4a660c8 (patch)
tree787aef747d60b8aacb3e1d472aeac8b69994ad8c /tcp.c
parentd0550f97cd2f38c74806c10904341584f0c0a2ad (diff)
downloadpasst-0f938c3b9a9dbc854c1d2e33fab5af41b4a660c8.tar
passt-0f938c3b9a9dbc854c1d2e33fab5af41b4a660c8.tar.gz
passt-0f938c3b9a9dbc854c1d2e33fab5af41b4a660c8.tar.bz2
passt-0f938c3b9a9dbc854c1d2e33fab5af41b4a660c8.tar.lz
passt-0f938c3b9a9dbc854c1d2e33fab5af41b4a660c8.tar.xz
passt-0f938c3b9a9dbc854c1d2e33fab5af41b4a660c8.tar.zst
passt-0f938c3b9a9dbc854c1d2e33fab5af41b4a660c8.zip
flow: Clarify flow entry life cycle, introduce uniform logging
Our allocation scheme for flow entries means there are some non-obvious constraints on when what things can be done with an entry. Add a big doc comment explaining the life cycle. In addition, make a FLOW_START() macro to mark one of the important transitions. This encourages correct usage, by making it natural to only access the flow type specific structure after calling it. It also logs that a new flow has been created, which is useful for debugging. We also add logging when a flow's lifecycle ends. This doesn't need a new helper, because it can only happen either from flow_alloc_cancel() or from the flow deferred handler. 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.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/tcp.c b/tcp.c
index e8f4da4..91163b8 100644
--- a/tcp.c
+++ b/tcp.c
@@ -1976,8 +1976,7 @@ static void tcp_conn_from_tap(struct ctx *c, sa_family_t af,
goto cancel;
}
- conn = &flow->tcp;
- conn->f.type = FLOW_TCP;
+ conn = FLOW_START(flow, FLOW_TCP, tcp, TAPSIDE);
conn->sock = s;
conn->timer = -1;
conn_event(c, conn, TAP_SYN_RCVD);
@@ -2681,18 +2680,19 @@ static void tcp_snat_inbound(const struct ctx *c, union inany_addr *addr)
* tcp_tap_conn_from_sock() - Initialize state for non-spliced connection
* @c: Execution context
* @ref: epoll reference of listening socket
- * @conn: connection structure to initialize
+ * @flow: flow to initialise
* @s: Accepted socket
* @sa: Peer socket address (from accept())
* @now: Current timestamp
*/
static void tcp_tap_conn_from_sock(struct ctx *c,
union tcp_listen_epoll_ref ref,
- struct tcp_tap_conn *conn, int s,
+ union flow *flow, int s,
const union sockaddr_inany *sa,
const struct timespec *now)
{
- conn->f.type = FLOW_TCP;
+ struct tcp_tap_conn *conn = FLOW_START(flow, FLOW_TCP, tcp, SOCKSIDE);
+
conn->sock = s;
conn->timer = -1;
conn->ws_to_tap = conn->ws_from_tap = 0;
@@ -2738,11 +2738,10 @@ void tcp_listen_handler(struct ctx *c, union epoll_ref ref,
goto cancel;
if (c->mode == MODE_PASTA &&
- tcp_splice_conn_from_sock(c, ref.tcp_listen, &flow->tcp_splice,
- s, &sa))
+ tcp_splice_conn_from_sock(c, ref.tcp_listen, flow, s, &sa))
return;
- tcp_tap_conn_from_sock(c, ref.tcp_listen, &flow->tcp, s, &sa, now);
+ tcp_tap_conn_from_sock(c, ref.tcp_listen, flow, s, &sa, now);
return;
cancel: