aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2024-05-21 15:57:03 +1000
committerStefano Brivio <sbrivio@redhat.com>2024-05-22 23:20:52 +0200
commit7a832a8a0edbdd5a705c1fe03fca0790a535ab11 (patch)
tree408f32fadc34b75ea9e7e166a5ba91880a4a1d73
parent1a20370b364ada675882e6a70d05b6e81418d64f (diff)
downloadpasst-7a832a8a0edbdd5a705c1fe03fca0790a535ab11.tar
passt-7a832a8a0edbdd5a705c1fe03fca0790a535ab11.tar.gz
passt-7a832a8a0edbdd5a705c1fe03fca0790a535ab11.tar.bz2
passt-7a832a8a0edbdd5a705c1fe03fca0790a535ab11.tar.lz
passt-7a832a8a0edbdd5a705c1fe03fca0790a535ab11.tar.xz
passt-7a832a8a0edbdd5a705c1fe03fca0790a535ab11.tar.zst
passt-7a832a8a0edbdd5a705c1fe03fca0790a535ab11.zip
flow: Properly type callbacks to protocol specific handlers
The flow dispatches deferred and timer handling for flows centrally, but needs to call into protocol specific code for the handling of individual flows. Currently this passes a general union flow *. It makes more sense to pass the specific relevant flow type structure. That brings the check on the flow type adjacent to casting to the union variant which it tags. Arguably, this is a slight abstraction violation since it involves the generic flow code using protocol specific types. It's already calling into protocol specific functions, so I don't think this really makes any difference. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--flow.c8
-rw-r--r--icmp.c6
-rw-r--r--icmp_flow.h2
-rw-r--r--tcp.c10
-rw-r--r--tcp_conn.h6
-rw-r--r--tcp_splice.c12
6 files changed, 19 insertions, 25 deletions
diff --git a/flow.c b/flow.c
index 80dd269..e257f89 100644
--- a/flow.c
+++ b/flow.c
@@ -292,17 +292,17 @@ void flow_defer_handler(const struct ctx *c, const struct timespec *now)
ASSERT(false);
break;
case FLOW_TCP:
- closed = tcp_flow_defer(flow);
+ closed = tcp_flow_defer(&flow->tcp);
break;
case FLOW_TCP_SPLICE:
- closed = tcp_splice_flow_defer(flow);
+ closed = tcp_splice_flow_defer(&flow->tcp_splice);
if (!closed && timer)
- tcp_splice_timer(c, flow);
+ tcp_splice_timer(c, &flow->tcp_splice);
break;
case FLOW_PING4:
case FLOW_PING6:
if (timer)
- closed = icmp_ping_timer(c, flow, now);
+ closed = icmp_ping_timer(c, &flow->ping, now);
break;
default:
/* Assume other flow types don't need any handling */
diff --git a/icmp.c b/icmp.c
index 1c5cf84..eb559c1 100644
--- a/icmp.c
+++ b/icmp.c
@@ -289,16 +289,14 @@ int icmp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
/**
* icmp_ping_timer() - Handler for timed events related to a given flow
* @c: Execution context
- * @flow: flow table entry to check for timeout
+ * @pingf: Ping flow to check for timeout
* @now: Current timestamp
*
* Return: true if the flow is ready to free, false otherwise
*/
-bool icmp_ping_timer(const struct ctx *c, union flow *flow,
+bool icmp_ping_timer(const struct ctx *c, const struct icmp_ping_flow *pingf,
const struct timespec *now)
{
- const struct icmp_ping_flow *pingf = &flow->ping;
-
if (now->tv_sec - pingf->ts <= ICMP_ECHO_TIMEOUT)
return false;
diff --git a/icmp_flow.h b/icmp_flow.h
index 5a2eed9..c9847ea 100644
--- a/icmp_flow.h
+++ b/icmp_flow.h
@@ -25,7 +25,7 @@ struct icmp_ping_flow {
uint16_t id;
};
-bool icmp_ping_timer(const struct ctx *c, union flow *flow,
+bool icmp_ping_timer(const struct ctx *c, const struct icmp_ping_flow *pingf,
const struct timespec *now);
#endif /* ICMP_FLOW_H */
diff --git a/tcp.c b/tcp.c
index efbbc1c..109d443 100644
--- a/tcp.c
+++ b/tcp.c
@@ -1221,15 +1221,13 @@ static struct tcp_tap_conn *tcp_hash_lookup(const struct ctx *c,
/**
* tcp_flow_defer() - Deferred per-flow handling (clean up closed connections)
- * @flow: Flow table entry for this connection
+ * @conn: Connection to handle
*
- * Return: true if the flow is ready to free, false otherwise
+ * Return: true if the connection is ready to free, false otherwise
*/
-bool tcp_flow_defer(union flow *flow)
+bool tcp_flow_defer(const struct tcp_tap_conn *conn)
{
- const struct tcp_tap_conn *conn = &flow->tcp;
-
- if (flow->tcp.events != CLOSED)
+ if (conn->events != CLOSED)
return false;
close(conn->sock);
diff --git a/tcp_conn.h b/tcp_conn.h
index d280b22..52bd815 100644
--- a/tcp_conn.h
+++ b/tcp_conn.h
@@ -155,9 +155,9 @@ struct tcp_splice_conn {
extern int init_sock_pool4 [TCP_SOCK_POOL_SIZE];
extern int init_sock_pool6 [TCP_SOCK_POOL_SIZE];
-bool tcp_flow_defer(union flow *flow);
-bool tcp_splice_flow_defer(union flow *flow);
-void tcp_splice_timer(const struct ctx *c, union flow *flow);
+bool tcp_flow_defer(const struct tcp_tap_conn *conn);
+bool tcp_splice_flow_defer(struct tcp_splice_conn *conn);
+void tcp_splice_timer(const struct ctx *c, struct tcp_splice_conn *conn);
int tcp_conn_pool_sock(int pool[]);
int tcp_conn_sock(const struct ctx *c, sa_family_t af);
int tcp_sock_refill_pool(const struct ctx *c, int pool[], sa_family_t af);
diff --git a/tcp_splice.c b/tcp_splice.c
index 4c36b72..fb00bc2 100644
--- a/tcp_splice.c
+++ b/tcp_splice.c
@@ -235,16 +235,15 @@ static void conn_event_do(const struct ctx *c, struct tcp_splice_conn *conn,
/**
* tcp_splice_flow_defer() - Deferred per-flow handling (clean up closed)
- * @flow: Flow table entry for this connection
+ * @conn: Connection entry to handle
*
* Return: true if the flow is ready to free, false otherwise
*/
-bool tcp_splice_flow_defer(union flow *flow)
+bool tcp_splice_flow_defer(struct tcp_splice_conn *conn)
{
- struct tcp_splice_conn *conn = &flow->tcp_splice;
unsigned side;
- if (!(flow->tcp_splice.flags & CLOSING))
+ if (!(conn->flags & CLOSING))
return false;
for (side = 0; side < SIDES; side++) {
@@ -786,11 +785,10 @@ void tcp_splice_init(struct ctx *c)
/**
* tcp_splice_timer() - Timer for spliced connections
* @c: Execution context
- * @flow: Flow table entry
+ * @conn: Connection to handle
*/
-void tcp_splice_timer(const struct ctx *c, union flow *flow)
+void tcp_splice_timer(const struct ctx *c, struct tcp_splice_conn *conn)
{
- struct tcp_splice_conn *conn = &flow->tcp_splice;
int side;
ASSERT(!(conn->flags & CLOSING));