mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-05 19:31:57 -04:00
BACKPORT: tcp: add tcp_sock_set_keepidle
Add a helper to directly set the TCP_KEEP_IDLE sockopt from kernel space without going through a fake uaccess. Change-Id: I57286ea8efb618476bac4d8d74f16e01b17e12aa Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
55cc20722d
commit
259e678a87
4 changed files with 38 additions and 21 deletions
|
|
@ -503,4 +503,6 @@ static inline u16 tcp_mss_clamp(const struct tcp_sock *tp, u16 mss)
|
|||
int tcp_skb_shift(struct sk_buff *to, struct sk_buff *from, int pcount,
|
||||
int shiftlen);
|
||||
|
||||
int tcp_sock_set_keepidle(struct sock *sk, int val);
|
||||
|
||||
#endif /* _LINUX_TCP_H */
|
||||
|
|
|
|||
|
|
@ -2837,6 +2837,39 @@ static void tcp_enable_tx_delay(void)
|
|||
}
|
||||
}
|
||||
|
||||
static int __tcp_sock_set_keepidle(struct sock *sk, int val)
|
||||
{
|
||||
struct tcp_sock *tp = tcp_sk(sk);
|
||||
|
||||
if (val < 1 || val > MAX_TCP_KEEPIDLE)
|
||||
return -EINVAL;
|
||||
|
||||
tp->keepalive_time = val * HZ;
|
||||
if (sock_flag(sk, SOCK_KEEPOPEN) &&
|
||||
!((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN))) {
|
||||
u32 elapsed = keepalive_time_elapsed(tp);
|
||||
|
||||
if (tp->keepalive_time > elapsed)
|
||||
elapsed = tp->keepalive_time - elapsed;
|
||||
else
|
||||
elapsed = 0;
|
||||
inet_csk_reset_keepalive_timer(sk, elapsed);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tcp_sock_set_keepidle(struct sock *sk, int val)
|
||||
{
|
||||
int err;
|
||||
|
||||
lock_sock(sk);
|
||||
err = __tcp_sock_set_keepidle(sk, val);
|
||||
release_sock(sk);
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL(tcp_sock_set_keepidle);
|
||||
|
||||
/*
|
||||
* Socket option code for TCP.
|
||||
*/
|
||||
|
|
@ -3044,21 +3077,7 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
|
|||
break;
|
||||
|
||||
case TCP_KEEPIDLE:
|
||||
if (val < 1 || val > MAX_TCP_KEEPIDLE)
|
||||
err = -EINVAL;
|
||||
else {
|
||||
tp->keepalive_time = val * HZ;
|
||||
if (sock_flag(sk, SOCK_KEEPOPEN) &&
|
||||
!((1 << sk->sk_state) &
|
||||
(TCPF_CLOSE | TCPF_LISTEN))) {
|
||||
u32 elapsed = keepalive_time_elapsed(tp);
|
||||
if (tp->keepalive_time > elapsed)
|
||||
elapsed = tp->keepalive_time - elapsed;
|
||||
else
|
||||
elapsed = 0;
|
||||
inet_csk_reset_keepalive_timer(sk, elapsed);
|
||||
}
|
||||
}
|
||||
err = __tcp_sock_set_keepidle(sk, val);
|
||||
break;
|
||||
case TCP_KEEPINTVL:
|
||||
if (val < 1 || val > MAX_TCP_KEEPINTVL)
|
||||
|
|
|
|||
|
|
@ -56,10 +56,7 @@ int rds_tcp_keepalive(struct socket *sock)
|
|||
if (ret < 0)
|
||||
goto bail;
|
||||
|
||||
ret = kernel_setsockopt(sock, IPPROTO_TCP, TCP_KEEPIDLE,
|
||||
(char *)&keepidle, sizeof(keepidle));
|
||||
if (ret < 0)
|
||||
goto bail;
|
||||
tcp_sock_set_keepidle(sock->sk, keepidle);
|
||||
|
||||
/* KEEPINTVL is the interval between successive probes. We follow
|
||||
* the model in xs_tcp_finish_connecting() and re-use keepidle.
|
||||
|
|
|
|||
|
|
@ -2256,8 +2256,7 @@ static void xs_tcp_set_socket_timeouts(struct rpc_xprt *xprt,
|
|||
/* TCP Keepalive options */
|
||||
kernel_setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE,
|
||||
(char *)&opt_on, sizeof(opt_on));
|
||||
kernel_setsockopt(sock, SOL_TCP, TCP_KEEPIDLE,
|
||||
(char *)&keepidle, sizeof(keepidle));
|
||||
tcp_sock_set_keepidle(sock->sk, keepidle);
|
||||
kernel_setsockopt(sock, SOL_TCP, TCP_KEEPINTVL,
|
||||
(char *)&keepidle, sizeof(keepidle));
|
||||
kernel_setsockopt(sock, SOL_TCP, TCP_KEEPCNT,
|
||||
|
|
|
|||
Loading…
Reference in a new issue