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/2] tcp: Rename and small cleanup to tcp_clamp_window()
Date: Thu, 9 Nov 2023 20:53:59 +1100 [thread overview]
Message-ID: <20231109095400.507679-2-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20231109095400.507679-1-david@gibson.dropbear.id.au>
tcp_clamp_window() is _mostly_ about using TCP_WINDOW_CLAMP to control the
sock side advertised window, but it is also responsible for actually
updating the conn->wnd_from_tap value.
Rename to tcp_tap_window_update() to reflect that broader purpose, and pull
the logic that's not TCP_WINDOW_CLAMP related out to the front.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
tcp.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/tcp.c b/tcp.c
index 19d16a6..13e82ca 100644
--- a/tcp.c
+++ b/tcp.c
@@ -1789,19 +1789,19 @@ static void tcp_get_tap_ws(struct tcp_tap_conn *conn,
}
/**
- * tcp_clamp_window() - Set new window for connection, clamp on socket
+ * tcp_tap_window_update() - Process an updated window from tap side
* @c: Execution context
* @conn: Connection pointer
* @window: Window value, host order, unscaled
*/
-static void tcp_clamp_window(const struct ctx *c, struct tcp_tap_conn *conn,
- unsigned wnd)
+static void tcp_tap_window_update(const struct ctx *c,
+ struct tcp_tap_conn *conn, unsigned wnd)
{
uint32_t prev_scaled = conn->wnd_from_tap << conn->ws_from_tap;
int s = conn->sock;
- wnd <<= conn->ws_from_tap;
- wnd = MIN(MAX_WINDOW, wnd);
+ wnd = MIN(MAX_WINDOW, wnd << conn->ws_from_tap);
+ conn->wnd_from_tap = MIN(wnd >> conn->ws_from_tap, USHRT_MAX);
/* TODO: With (at least) Linux kernel versions 6.1 to 6.5, if we end up
* with a zero-sized window on a TCP socket, dropping data (once
@@ -1838,7 +1838,6 @@ static void tcp_clamp_window(const struct ctx *c, struct tcp_tap_conn *conn,
return;
}
- conn->wnd_from_tap = MIN(wnd >> conn->ws_from_tap, USHRT_MAX);
if (setsockopt(s, SOL_TCP, TCP_WINDOW_CLAMP, &wnd, sizeof(wnd)))
trace("TCP: failed to set TCP_WINDOW_CLAMP on socket %i", s);
@@ -2453,7 +2452,7 @@ static int tcp_data_from_tap(struct ctx *c, struct tcp_tap_conn *conn,
if (ack && !tcp_sock_consume(conn, max_ack_seq))
tcp_update_seqack_from_tap(c, conn, max_ack_seq);
- tcp_clamp_window(c, conn, max_ack_seq_wnd);
+ tcp_tap_window_update(c, conn, max_ack_seq_wnd);
if (retr) {
trace("TCP: fast re-transmit, ACK: %u, previous sequence: %u",
@@ -2538,7 +2537,7 @@ static void tcp_conn_from_sock_finish(struct ctx *c, struct tcp_tap_conn *conn,
const struct tcphdr *th,
const char *opts, size_t optlen)
{
- tcp_clamp_window(c, conn, ntohs(th->window));
+ tcp_tap_window_update(c, conn, ntohs(th->window));
tcp_get_tap_ws(conn, opts, optlen);
/* First value is not scaled */
@@ -2646,7 +2645,7 @@ int tcp_tap_handler(struct ctx *c, uint8_t pif, int af,
if (!th->ack)
goto reset;
- tcp_clamp_window(c, conn, ntohs(th->window));
+ tcp_tap_window_update(c, conn, ntohs(th->window));
tcp_data_from_sock(c, conn);
@@ -2670,8 +2669,8 @@ int tcp_tap_handler(struct ctx *c, uint8_t pif, int af,
if (count == -1)
goto reset;
- /* Note: STALLED matters for tcp_clamp_window(): unset it only after
- * processing data (and window) from the tap side
+ /* Note: STALLED matters for tcp_tap_window_update(): unset it only
+ * after processing data (and window) from the tap side
*/
conn_flag(c, conn, ~STALLED);
--
@@ -1789,19 +1789,19 @@ static void tcp_get_tap_ws(struct tcp_tap_conn *conn,
}
/**
- * tcp_clamp_window() - Set new window for connection, clamp on socket
+ * tcp_tap_window_update() - Process an updated window from tap side
* @c: Execution context
* @conn: Connection pointer
* @window: Window value, host order, unscaled
*/
-static void tcp_clamp_window(const struct ctx *c, struct tcp_tap_conn *conn,
- unsigned wnd)
+static void tcp_tap_window_update(const struct ctx *c,
+ struct tcp_tap_conn *conn, unsigned wnd)
{
uint32_t prev_scaled = conn->wnd_from_tap << conn->ws_from_tap;
int s = conn->sock;
- wnd <<= conn->ws_from_tap;
- wnd = MIN(MAX_WINDOW, wnd);
+ wnd = MIN(MAX_WINDOW, wnd << conn->ws_from_tap);
+ conn->wnd_from_tap = MIN(wnd >> conn->ws_from_tap, USHRT_MAX);
/* TODO: With (at least) Linux kernel versions 6.1 to 6.5, if we end up
* with a zero-sized window on a TCP socket, dropping data (once
@@ -1838,7 +1838,6 @@ static void tcp_clamp_window(const struct ctx *c, struct tcp_tap_conn *conn,
return;
}
- conn->wnd_from_tap = MIN(wnd >> conn->ws_from_tap, USHRT_MAX);
if (setsockopt(s, SOL_TCP, TCP_WINDOW_CLAMP, &wnd, sizeof(wnd)))
trace("TCP: failed to set TCP_WINDOW_CLAMP on socket %i", s);
@@ -2453,7 +2452,7 @@ static int tcp_data_from_tap(struct ctx *c, struct tcp_tap_conn *conn,
if (ack && !tcp_sock_consume(conn, max_ack_seq))
tcp_update_seqack_from_tap(c, conn, max_ack_seq);
- tcp_clamp_window(c, conn, max_ack_seq_wnd);
+ tcp_tap_window_update(c, conn, max_ack_seq_wnd);
if (retr) {
trace("TCP: fast re-transmit, ACK: %u, previous sequence: %u",
@@ -2538,7 +2537,7 @@ static void tcp_conn_from_sock_finish(struct ctx *c, struct tcp_tap_conn *conn,
const struct tcphdr *th,
const char *opts, size_t optlen)
{
- tcp_clamp_window(c, conn, ntohs(th->window));
+ tcp_tap_window_update(c, conn, ntohs(th->window));
tcp_get_tap_ws(conn, opts, optlen);
/* First value is not scaled */
@@ -2646,7 +2645,7 @@ int tcp_tap_handler(struct ctx *c, uint8_t pif, int af,
if (!th->ack)
goto reset;
- tcp_clamp_window(c, conn, ntohs(th->window));
+ tcp_tap_window_update(c, conn, ntohs(th->window));
tcp_data_from_sock(c, conn);
@@ -2670,8 +2669,8 @@ int tcp_tap_handler(struct ctx *c, uint8_t pif, int af,
if (count == -1)
goto reset;
- /* Note: STALLED matters for tcp_clamp_window(): unset it only after
- * processing data (and window) from the tap side
+ /* Note: STALLED matters for tcp_tap_window_update(): unset it only
+ * after processing data (and window) from the tap side
*/
conn_flag(c, conn, ~STALLED);
--
2.41.0
next prev parent reply other threads:[~2023-11-09 9:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-09 9:53 [PATCH 0/2] Avoid bugs related to TCP_WINDOW_CLAMP David Gibson
2023-11-09 9:53 ` David Gibson [this message]
2023-11-09 9:54 ` [PATCH 2/2] tcp: Don't use TCP_WINDOW_CLAMP David Gibson
2023-11-09 14:51 ` Stefano Brivio
2023-11-10 0:23 ` David Gibson
2023-11-10 5:20 ` Stefano Brivio
2023-11-10 17:06 ` [PATCH 0/2] Avoid bugs related to TCP_WINDOW_CLAMP Stefano Brivio
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=20231109095400.507679-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).