@@ -969,6 +969,7 @@ struct proto {
int *sysctl_rmem;
int max_header;
bool no_autobind;
+ int min_sndbuf;
struct kmem_cache *slab;
unsigned int obj_size;
@@ -818,6 +818,7 @@ static struct proto raw_proto __read_mostly = {
.owner = THIS_MODULE,
.obj_size = sizeof(struct raw_sock),
.init = raw_init,
+ .min_sndbuf = SKB_TRUESIZE(sizeof(struct can_frame) + sizeof(struct can_skb_priv)),
};
static const struct can_proto raw_can_proto = {
@@ -625,7 +625,7 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
char __user *optval, unsigned int optlen)
{
struct sock *sk = sock->sk;
- int val;
+ int val, min;
int valbool;
struct linger ling;
int ret = 0;
@@ -681,7 +681,9 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
val = min_t(u32, val, sysctl_wmem_max);
set_sndbuf:
sk->sk_userlocks |= SOCK_SNDBUF_LOCK;
- sk->sk_sndbuf = max_t(u32, val * 2, SOCK_MIN_SNDBUF);
+ min = sk->sk_prot->min_sndbuf ?
+ sk->sk_prot->min_sndbuf : SOCK_MIN_SNDBUF;
+ sk->sk_sndbuf = max_t(u32, val * 2, min);
/* Wake up sending tasks if we upped the value. */
sk->sk_write_space(sk);
break;
For CAN bus it is desired to have the per-socket send queue limit much smaller than for Ethernet-based protocols (see the previous patch). This patch makes the lower limit of accepted setsockopt(SO_SNDBUF) values smaller for PF_CAN sockets. The value of SOCK_MIN_SNDBUF is kept unchanged, because it is only used in two functions (sk_stream_moderate_sndbuf, tcp_out_of_memory) that seem to be called for TCP/IP related protocols only and the change from a constant to sk->sk_prot->min_sndbuf could have negative performance impact. Changes since v1: - SOCK_MIN_SNDBUF changed back to a constant. Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz> --- include/net/sock.h | 1 + net/can/raw.c | 1 + net/core/sock.c | 6 ++++-- 3 files changed, 6 insertions(+), 2 deletions(-)