public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>, passt-dev@passt.top
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 1/6] flow: Properly type callbacks to protocol specific handlers
Date: Tue, 21 May 2024 15:57:03 +1000	[thread overview]
Message-ID: <20240521055708.1150050-2-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20240521055708.1150050-1-david@gibson.dropbear.id.au>

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>
---
 flow.c       |  8 ++++----
 icmp.c       |  6 ++----
 icmp_flow.h  |  2 +-
 tcp.c        | 10 ++++------
 tcp_conn.h   |  6 +++---
 tcp_splice.c | 12 +++++-------
 6 files changed, 19 insertions(+), 25 deletions(-)

diff --git a/flow.c b/flow.c
index 80dd269e..e257f890 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 1c5cf84b..eb559c18 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 5a2eed9c..c9847eae 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 21d0af06..a8ba5858 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 d280b222..52bd8156 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 4c36b721..fb00bc22 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));
-- 
@@ -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));
-- 
2.45.1



  reply	other threads:[~2024-05-21  5:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-21  5:57 [PATCH 0/6] Final flow table preliminaries David Gibson
2024-05-21  5:57 ` David Gibson [this message]
2024-05-21  5:57 ` [PATCH 2/6] inany: Better helpers for using inany and specific family addrs together David Gibson
2024-05-21  5:57 ` [PATCH 3/6] flow: Clarify and enforce flow state transitions David Gibson
2024-05-21  5:57 ` [PATCH 4/6] flow: Make side 0 always be the initiating side David Gibson
2024-05-21  5:57 ` [PATCH 5/6] flow: Record the pifs for each side of each flow David Gibson
2024-05-21  5:57 ` [PATCH 6/6] tcp: Remove interim 'tapside' field from connection David Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240521055708.1150050-2-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    --cc=sbrivio@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).