1
0
mirror of https://passt.top/passt synced 2024-12-22 13:45:32 +00:00

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>
This commit is contained in:
David Gibson 2024-05-21 15:57:03 +10:00 committed by Stefano Brivio
parent 1a20370b36
commit 7a832a8a0e
6 changed files with 19 additions and 25 deletions

8
flow.c
View File

@ -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 */

6
icmp.c
View File

@ -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;

View File

@ -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 */

10
tcp.c
View File

@ -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);

View File

@ -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);

View File

@ -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));