Commit 480aeb96 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by David S. Miller

tcp: add tcp_sock_set_keepcnt

Add a helper to directly set the TCP_KEEPCNT sockopt from kernel space
without going through a fake uaccess.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d41ecaac
...@@ -498,6 +498,7 @@ int tcp_skb_shift(struct sk_buff *to, struct sk_buff *from, int pcount, ...@@ -498,6 +498,7 @@ int tcp_skb_shift(struct sk_buff *to, struct sk_buff *from, int pcount,
int shiftlen); int shiftlen);
void tcp_sock_set_cork(struct sock *sk, bool on); void tcp_sock_set_cork(struct sock *sk, bool on);
int tcp_sock_set_keepcnt(struct sock *sk, int val);
int tcp_sock_set_keepidle(struct sock *sk, int val); int tcp_sock_set_keepidle(struct sock *sk, int val);
int tcp_sock_set_keepintvl(struct sock *sk, int val); int tcp_sock_set_keepintvl(struct sock *sk, int val);
void tcp_sock_set_nodelay(struct sock *sk); void tcp_sock_set_nodelay(struct sock *sk);
......
...@@ -2946,6 +2946,18 @@ int tcp_sock_set_keepintvl(struct sock *sk, int val) ...@@ -2946,6 +2946,18 @@ int tcp_sock_set_keepintvl(struct sock *sk, int val)
} }
EXPORT_SYMBOL(tcp_sock_set_keepintvl); EXPORT_SYMBOL(tcp_sock_set_keepintvl);
int tcp_sock_set_keepcnt(struct sock *sk, int val)
{
if (val < 1 || val > MAX_TCP_KEEPCNT)
return -EINVAL;
lock_sock(sk);
tcp_sk(sk)->keepalive_probes = val;
release_sock(sk);
return 0;
}
EXPORT_SYMBOL(tcp_sock_set_keepcnt);
/* /*
* Socket option code for TCP. * Socket option code for TCP.
*/ */
......
...@@ -70,7 +70,7 @@ struct socket *rds_tcp_listen_init(struct net *net, bool isv6); ...@@ -70,7 +70,7 @@ struct socket *rds_tcp_listen_init(struct net *net, bool isv6);
void rds_tcp_listen_stop(struct socket *sock, struct work_struct *acceptor); void rds_tcp_listen_stop(struct socket *sock, struct work_struct *acceptor);
void rds_tcp_listen_data_ready(struct sock *sk); void rds_tcp_listen_data_ready(struct sock *sk);
int rds_tcp_accept_one(struct socket *sock); int rds_tcp_accept_one(struct socket *sock);
int rds_tcp_keepalive(struct socket *sock); void rds_tcp_keepalive(struct socket *sock);
void *rds_tcp_listen_sock_def_readable(struct net *net); void *rds_tcp_listen_sock_def_readable(struct net *net);
/* tcp_recv.c */ /* tcp_recv.c */
......
...@@ -38,27 +38,19 @@ ...@@ -38,27 +38,19 @@
#include "rds.h" #include "rds.h"
#include "tcp.h" #include "tcp.h"
int rds_tcp_keepalive(struct socket *sock) void rds_tcp_keepalive(struct socket *sock)
{ {
/* values below based on xs_udp_default_timeout */ /* values below based on xs_udp_default_timeout */
int keepidle = 5; /* send a probe 'keepidle' secs after last data */ int keepidle = 5; /* send a probe 'keepidle' secs after last data */
int keepcnt = 5; /* number of unack'ed probes before declaring dead */ int keepcnt = 5; /* number of unack'ed probes before declaring dead */
int ret = 0;
sock_set_keepalive(sock->sk); sock_set_keepalive(sock->sk);
tcp_sock_set_keepcnt(sock->sk, keepcnt);
ret = kernel_setsockopt(sock, IPPROTO_TCP, TCP_KEEPCNT,
(char *)&keepcnt, sizeof(keepcnt));
if (ret < 0)
goto bail;
tcp_sock_set_keepidle(sock->sk, keepidle); tcp_sock_set_keepidle(sock->sk, keepidle);
/* KEEPINTVL is the interval between successive probes. We follow /* KEEPINTVL is the interval between successive probes. We follow
* the model in xs_tcp_finish_connecting() and re-use keepidle. * the model in xs_tcp_finish_connecting() and re-use keepidle.
*/ */
tcp_sock_set_keepintvl(sock->sk, keepidle); tcp_sock_set_keepintvl(sock->sk, keepidle);
bail:
return ret;
} }
/* rds_tcp_accept_one_path(): if accepting on cp_index > 0, make sure the /* rds_tcp_accept_one_path(): if accepting on cp_index > 0, make sure the
...@@ -140,10 +132,7 @@ int rds_tcp_accept_one(struct socket *sock) ...@@ -140,10 +132,7 @@ int rds_tcp_accept_one(struct socket *sock)
new_sock->ops = sock->ops; new_sock->ops = sock->ops;
__module_get(new_sock->ops->owner); __module_get(new_sock->ops->owner);
ret = rds_tcp_keepalive(new_sock); rds_tcp_keepalive(new_sock);
if (ret < 0)
goto out;
rds_tcp_tune(new_sock); rds_tcp_tune(new_sock);
inet = inet_sk(new_sock->sk); inet = inet_sk(new_sock->sk);
......
...@@ -2109,8 +2109,7 @@ static void xs_tcp_set_socket_timeouts(struct rpc_xprt *xprt, ...@@ -2109,8 +2109,7 @@ static void xs_tcp_set_socket_timeouts(struct rpc_xprt *xprt,
sock_set_keepalive(sock->sk); sock_set_keepalive(sock->sk);
tcp_sock_set_keepidle(sock->sk, keepidle); tcp_sock_set_keepidle(sock->sk, keepidle);
tcp_sock_set_keepintvl(sock->sk, keepidle); tcp_sock_set_keepintvl(sock->sk, keepidle);
kernel_setsockopt(sock, SOL_TCP, TCP_KEEPCNT, tcp_sock_set_keepcnt(sock->sk, keepcnt);
(char *)&keepcnt, sizeof(keepcnt));
/* TCP user timeout (see RFC5482) */ /* TCP user timeout (see RFC5482) */
tcp_sock_set_user_timeout(sock->sk, timeo); tcp_sock_set_user_timeout(sock->sk, timeo);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment