net: Limit max value for Send/Recv bufsize
There're some apps trying to set too large SO_SNDBUF and SO_RCVBUF, which may use all IOBs in one socket and block all other network traffic. Note: Linux silently limits SO_SNDBUF to be less than `sysctl_wmem_max`, so we can also do this limit without returning any error. Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
This commit is contained in:
parent
67ec447513
commit
1072b5b564
20
net/Kconfig
20
net/Kconfig
@ -128,18 +128,34 @@ config NET_LL_GUARDSIZE
|
|||||||
to L3 network layer protocol transparent transmission and forwarding
|
to L3 network layer protocol transparent transmission and forwarding
|
||||||
|
|
||||||
config NET_RECV_BUFSIZE
|
config NET_RECV_BUFSIZE
|
||||||
int "Net Receive buffer size"
|
int "Net Default Receive buffer size"
|
||||||
default 0
|
default 0
|
||||||
---help---
|
---help---
|
||||||
This is the default value for receive buffer size.
|
This is the default value for receive buffer size.
|
||||||
|
|
||||||
|
config NET_MAX_RECV_BUFSIZE
|
||||||
|
int "Net Max Receive buffer size"
|
||||||
|
depends on NET_RECV_BUFSIZE > 0
|
||||||
|
default 0
|
||||||
|
---help---
|
||||||
|
Limit the max value for receive buffer size to avoid overconsumption.
|
||||||
|
Zero means no limit.
|
||||||
|
|
||||||
config NET_SEND_BUFSIZE
|
config NET_SEND_BUFSIZE
|
||||||
int "Net Send buffer size"
|
int "Net Default Send buffer size"
|
||||||
depends on NET_TCP_WRITE_BUFFERS || NET_UDP_WRITE_BUFFERS
|
depends on NET_TCP_WRITE_BUFFERS || NET_UDP_WRITE_BUFFERS
|
||||||
default 0
|
default 0
|
||||||
---help---
|
---help---
|
||||||
This is the default value for send buffer size.
|
This is the default value for send buffer size.
|
||||||
|
|
||||||
|
config NET_MAX_SEND_BUFSIZE
|
||||||
|
int "Net Max Send buffer size"
|
||||||
|
depends on NET_SEND_BUFSIZE > 0
|
||||||
|
default 0
|
||||||
|
---help---
|
||||||
|
Limit the max value for send buffer size to avoid overconsumption.
|
||||||
|
Zero means no limit.
|
||||||
|
|
||||||
endmenu # Driver buffer configuration
|
endmenu # Driver buffer configuration
|
||||||
|
|
||||||
menu "Link layer support"
|
menu "Link layer support"
|
||||||
|
@ -929,6 +929,10 @@ static int inet_set_socketlevel_option(FAR struct socket *psock, int option,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CONFIG_NET_MAX_RECV_BUFSIZE > 0
|
||||||
|
buffersize = MIN(buffersize, CONFIG_NET_MAX_RECV_BUFSIZE);
|
||||||
|
#endif
|
||||||
|
|
||||||
net_lock();
|
net_lock();
|
||||||
|
|
||||||
#ifdef NET_TCP_HAVE_STACK
|
#ifdef NET_TCP_HAVE_STACK
|
||||||
@ -986,6 +990,10 @@ static int inet_set_socketlevel_option(FAR struct socket *psock, int option,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CONFIG_NET_MAX_SEND_BUFSIZE > 0
|
||||||
|
buffersize = MIN(buffersize, CONFIG_NET_MAX_SEND_BUFSIZE);
|
||||||
|
#endif
|
||||||
|
|
||||||
net_lock();
|
net_lock();
|
||||||
|
|
||||||
#ifdef NET_TCP_HAVE_STACK
|
#ifdef NET_TCP_HAVE_STACK
|
||||||
|
Loading…
Reference in New Issue
Block a user