Skip to content

Commit 29f0895

Browse files
jukkarnashif
authored andcommitted
net: tcp2: Adjust the send window according to avail bufs
We should have a max value for sending window so that application is not able to use all our net_bufs for queueing packets. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent b00adf6 commit 29f0895

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

subsys/net/ip/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,16 @@ config NET_TCP_RETRY_COUNT
377377
Should a retransmission timeout occur, the receive callback is
378378
called with -ECONNRESET error code and the context is dereferenced.
379379

380+
config NET_TCP_MAX_SEND_WINDOW_SIZE
381+
int "Maximum sending window size to use"
382+
depends on NET_TCP2
383+
default 0
384+
range 0 65535
385+
help
386+
This value affects how the TCP selects the maximum sending window
387+
size. The default value 0 lets the TCP stack select the value
388+
according to amount of network buffers configured in the system.
389+
380390
choice
381391
prompt "Select TCP stack"
382392
depends on NET_TCP

subsys/net/ip/tcp2.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,30 @@ static void tcp_in(struct tcp *conn, struct net_pkt *pkt)
11521152
}
11531153

11541154
if (th) {
1155+
size_t max_win;
1156+
11551157
conn->send_win = ntohs(th->th_win);
1158+
1159+
#if IS_ENABLED(CONFIG_NET_TCP_MAX_SEND_WINDOW_SIZE)
1160+
if (CONFIG_NET_TCP_MAX_SEND_WINDOW_SIZE) {
1161+
max_win = CONFIG_NET_TCP_MAX_SEND_WINDOW_SIZE;
1162+
} else
1163+
#endif
1164+
{
1165+
/* Adjust the window so that we do not run out of bufs
1166+
* while waiting acks.
1167+
*/
1168+
max_win = (CONFIG_NET_BUF_TX_COUNT *
1169+
CONFIG_NET_BUF_DATA_SIZE) / 3;
1170+
}
1171+
1172+
max_win = MAX(max_win, NET_IPV6_MTU);
1173+
if ((size_t)conn->send_win > max_win) {
1174+
NET_DBG("Lowering send window from %zd to %zd",
1175+
(size_t)conn->send_win, max_win);
1176+
1177+
conn->send_win = max_win;
1178+
}
11561179
}
11571180

11581181
if (FL(&fl, &, RST)) {

0 commit comments

Comments
 (0)