net: add sndbuf socket option

Introduce set/get SO_SNDBUF option using the setsockopt
function. In addition, for TCP, check the sndbuf value
before queuing data.

Signed-off-by: Mohan Kumar Kumar <mohankm@fb.com>
This commit is contained in:
Mohan Kumar Kumar 2022-04-01 12:47:25 -07:00 committed by Carles Cufí
commit f105ea6ef5
5 changed files with 96 additions and 0 deletions

View file

@ -1782,6 +1782,9 @@ static void tcp_in(struct tcp *conn, struct net_pkt *pkt)
if (th) {
size_t max_win;
int sndbuf;
size_t sndbuf_len;
conn->send_win = ntohs(th_win(th));
@ -1798,6 +1801,17 @@ static void tcp_in(struct tcp *conn, struct net_pkt *pkt)
CONFIG_NET_BUF_DATA_SIZE) / 3;
}
if (IS_ENABLED(CONFIG_NET_CONTEXT_SNDBUF) &&
conn->state != TCP_SYN_SENT &&
net_context_get_option(conn->context,
NET_OPT_SNDBUF,
&sndbuf,
&sndbuf_len) == 0) {
if (sndbuf > 0) {
max_win = sndbuf;
}
}
max_win = MAX(max_win, NET_IPV6_MTU);
if ((size_t)conn->send_win > max_win) {
NET_DBG("Lowering send window from %zd to %zd",