From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from imap.gmail.com [173.194.76.109] by localhost with POP3 (fetchmail-6.3.26) for (single-drop); Tue, 21 May 2024 07:57:38 +0200 (CEST) Received: by 2002:a05:6a10:9148:b0:55f:c3c0:ed08 with SMTP id n8csp851873pxb; Mon, 20 May 2024 22:57:19 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUASOs7mcFtBQjxIzYCjUIYVe8D4UzdwUuTyqzcgNyKsPzTNPOlniisNyryaTH/plfWzczc3SmtfiGYFC64ArhnQWWSBGMisvQ= X-Google-Smtp-Source: AGHT+IFPY1gP5+CVkkNUcgbN7ZYjdZm3C4JB8ryUBl77OcFxK1HIP3882aT++Vpqgtru0libjbWQ X-Received: by 2002:a05:620a:20d3:b0:792:c3c4:1082 with SMTP id af79cd13be357-792c75f35demr3324883985a.54.1716271039408; Mon, 20 May 2024 22:57:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1716271039; cv=none; d=google.com; s=arc-20160816; b=OMUjannsQwYV1g+JTbWM3MdnDQAQXW7u0duguUkuFeEnmcK/OjMG07nOcPObnfppDx J9bUp0UKhHQnr0wM2Ym3csZTD7cXDJ+xddOAk/LDaXhkM9fftZEU27pNU1Vly6VdrKl9 YD7DTMStrk9l1QkliBLCrW8wiGRM7FVLrwb+okP+8mLWGD8qi8l3W+ATbJ98RqkziwdG CjtQOWCNCrxuTwbwH1SZYFGe562nSlupEbFa+59d83tx8nMRFl5DD5dMxIOv4hKdrLh0 9Q6vMG5B9LDTqTy7s2kLpPg2Q7jxEGk9QWo+eKJSSPZgJ07BnTy305dPQB7eY4I7OQWf eMEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:delivered-to; bh=AxOxpEbdC9nKV5LkfDBtyWZvrnkKOBYYhoZm0JGuszM=; fh=OvZxoe0l5OQEr5hiks2YsWDyoZfSCuw/Wl/AnSjLRjU=; b=DjdWiJbBJkUCJjtcPBqK5HzPjCsa9Xr6e6kbFT7Wnq6SgaX+DkMvf/i4HfLNgUaPz4 9TW4OU8R21DAPZ9QaxXkWvnDialMzcnZW+xDVU/93UdUGYdJ0J/Akqu6n/ciQGKTK1Fq lp0A/tpwsDSUnGDU+Olfdu5CMaOWfg6iCLPkziaGRaxCQNDrAPWw84sHdlPUJiRyEy0e q9HJKSRt1wNyBCiq0F/iUPoletx6n1ekhZyB+DhKJbh9kpbwkGAsdJF3M4PptLTgy2vD lly5c7Bt+AIcgdpFXykAYU9GQ8XErQtwEF8tmHhJl+tSvPx3Zc/S2Ng3uz+zDmTW/Qrg 1rzQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dgibson@gandalf.ozlabs.org designates 150.107.74.76 as permitted sender) smtp.mailfrom=dgibson@gandalf.ozlabs.org Return-Path: Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com. [170.10.128.131]) by mx.google.com with ESMTPS id af79cd13be357-792ed012732si640536485a.677.2024.05.20.22.57.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 22:57:19 -0700 (PDT) Received-SPF: pass (google.com: domain of dgibson@gandalf.ozlabs.org designates 150.107.74.76 as permitted sender) client-ip=150.107.74.76; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dgibson@gandalf.ozlabs.org designates 150.107.74.76 as permitted sender) smtp.mailfrom=dgibson@gandalf.ozlabs.org Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-443-lyJ0ztp_MPeoEWlIB3dzwQ-1; Tue, 21 May 2024 01:57:17 -0400 X-MC-Unique: lyJ0ztp_MPeoEWlIB3dzwQ-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 85F09195608B for ; Tue, 21 May 2024 05:57:16 +0000 (UTC) Received: by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) id 75D1B1955D7C; Tue, 21 May 2024 05:57:16 +0000 (UTC) Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.46]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 737F31955D7D for ; Tue, 21 May 2024 05:57:16 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 22F4A19560A2 for ; Tue, 21 May 2024 05:57:16 +0000 (UTC) Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-172-1vtocdS8Om-ja59Z07kEcA-1; Tue, 21 May 2024 01:57:13 -0400 X-MC-Unique: 1vtocdS8Om-ja59Z07kEcA-1 Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Vk3c55s9Vz4wxf; Tue, 21 May 2024 15:57:09 +1000 (AEST) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Cc: David Gibson Subject: [PATCH 1/6] flow: Properly type callbacks to protocol specific handlers Date: Tue, 21 May 2024 15:57:03 +1000 Message-ID: <20240521055708.1150050-2-david@gibson.dropbear.id.au> In-Reply-To: <20240521055708.1150050-1-david@gibson.dropbear.id.au> References: <20240521055708.1150050-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition;Similar Internal Domain=false;Similar Monitored External Domain=false;Custom External Domain=false;Mimecast External Domain=false;Newly Observed Domain=false;Internal User Name=false;Custom Display Name List=false;Reply-to Address Mismatch=false;Targeted Threat Dictionary=false;Mimecast Threat Dictionary=false;Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: gibson.dropbear.id.au Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="US-ASCII"; x-default=true List-Id: 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 --- 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 st= ruct timespec *now) =09=09=09ASSERT(false); =09=09=09break; =09=09case FLOW_TCP: -=09=09=09closed =3D tcp_flow_defer(flow); +=09=09=09closed =3D tcp_flow_defer(&flow->tcp); =09=09=09break; =09=09case FLOW_TCP_SPLICE: -=09=09=09closed =3D tcp_splice_flow_defer(flow); +=09=09=09closed =3D tcp_splice_flow_defer(&flow->tcp_splice); =09=09=09if (!closed && timer) -=09=09=09=09tcp_splice_timer(c, flow); +=09=09=09=09tcp_splice_timer(c, &flow->tcp_splice); =09=09=09break; =09=09case FLOW_PING4: =09=09case FLOW_PING6: =09=09=09if (timer) -=09=09=09=09closed =3D icmp_ping_timer(c, flow, now); +=09=09=09=09closed =3D icmp_ping_timer(c, &flow->ping, now); =09=09=09break; =09=09default: =09=09=09/* 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:=09=09Execution context - * @flow:=09flow table entry to check for timeout + * @pingf:=09Ping flow to check for timeout * @now:=09Current 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 *pin= gf, =09=09 const struct timespec *now) { -=09const struct icmp_ping_flow *pingf =3D &flow->ping; - =09if (now->tv_sec - pingf->ts <=3D ICMP_ECHO_TIMEOUT) =09=09return false; =20 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 { =09uint16_t id; }; =20 -bool icmp_ping_timer(const struct ctx *c, union flow *flow, +bool icmp_ping_timer(const struct ctx *c, const struct icmp_ping_flow *pin= gf, =09=09 const struct timespec *now); =20 #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 s= truct ctx *c, =20 /** * tcp_flow_defer() - Deferred per-flow handling (clean up closed connecti= ons) - * @flow:=09Flow table entry for this connection + * @conn:=09Connection 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) { -=09const struct tcp_tap_conn *conn =3D &flow->tcp; - -=09if (flow->tcp.events !=3D CLOSED) +=09if (conn->events !=3D CLOSED) =09=09return false; =20 =09close(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=09[TCP_SOCK_POOL_SIZE]; extern int init_sock_pool6=09[TCP_SOCK_POOL_SIZE]; =20 -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, =20 /** * tcp_splice_flow_defer() - Deferred per-flow handling (clean up closed) - * @flow:=09Flow table entry for this connection + * @conn:=09Connection 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) { -=09struct tcp_splice_conn *conn =3D &flow->tcp_splice; =09unsigned side; =20 -=09if (!(flow->tcp_splice.flags & CLOSING)) +=09if (!(conn->flags & CLOSING)) =09=09return false; =20 =09for (side =3D 0; side < SIDES; side++) { @@ -786,11 +785,10 @@ void tcp_splice_init(struct ctx *c) /** * tcp_splice_timer() - Timer for spliced connections * @c:=09=09Execution context - * @flow:=09Flow table entry + * @conn:=09Connection 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) { -=09struct tcp_splice_conn *conn =3D &flow->tcp_splice; =09int side; =20 =09ASSERT(!(conn->flags & CLOSING)); --=20 2.45.1