Skip to content

Commit d41ecaa

Browse files
Christoph Hellwigdavem330
authored andcommitted
tcp: add tcp_sock_set_keepintvl
Add a helper to directly set the TCP_KEEPINTVL sockopt from kernel space without going through a fake uaccess. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 71c48eb commit d41ecaa

4 files changed

Lines changed: 15 additions & 5 deletions

File tree

‎include/linux/tcp.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ int tcp_skb_shift(struct sk_buff *to, struct sk_buff *from, int pcount,
499499

500500
void tcp_sock_set_cork(struct sock *sk, bool on);
501501
int tcp_sock_set_keepidle(struct sock *sk, int val);
502+
int tcp_sock_set_keepintvl(struct sock *sk, int val);
502503
void tcp_sock_set_nodelay(struct sock *sk);
503504
void tcp_sock_set_quickack(struct sock *sk, int val);
504505
int tcp_sock_set_syncnt(struct sock *sk, int val);

‎net/ipv4/tcp.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2934,6 +2934,18 @@ int tcp_sock_set_keepidle(struct sock *sk, int val)
29342934
}
29352935
EXPORT_SYMBOL(tcp_sock_set_keepidle);
29362936

2937+
int tcp_sock_set_keepintvl(struct sock *sk, int val)
2938+
{
2939+
if (val < 1 || val > MAX_TCP_KEEPINTVL)
2940+
return -EINVAL;
2941+
2942+
lock_sock(sk);
2943+
tcp_sk(sk)->keepalive_intvl = val * HZ;
2944+
release_sock(sk);
2945+
return 0;
2946+
}
2947+
EXPORT_SYMBOL(tcp_sock_set_keepintvl);
2948+
29372949
/*
29382950
* Socket option code for TCP.
29392951
*/

‎net/rds/tcp_listen.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,10 @@ int rds_tcp_keepalive(struct socket *sock)
5353
goto bail;
5454

5555
tcp_sock_set_keepidle(sock->sk, keepidle);
56-
5756
/* KEEPINTVL is the interval between successive probes. We follow
5857
* the model in xs_tcp_finish_connecting() and re-use keepidle.
5958
*/
60-
ret = kernel_setsockopt(sock, IPPROTO_TCP, TCP_KEEPINTVL,
61-
(char *)&keepidle, sizeof(keepidle));
59+
tcp_sock_set_keepintvl(sock->sk, keepidle);
6260
bail:
6361
return ret;
6462
}

‎net/sunrpc/xprtsock.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,8 +2108,7 @@ static void xs_tcp_set_socket_timeouts(struct rpc_xprt *xprt,
21082108
/* TCP Keepalive options */
21092109
sock_set_keepalive(sock->sk);
21102110
tcp_sock_set_keepidle(sock->sk, keepidle);
2111-
kernel_setsockopt(sock, SOL_TCP, TCP_KEEPINTVL,
2112-
(char *)&keepidle, sizeof(keepidle));
2111+
tcp_sock_set_keepintvl(sock->sk, keepidle);
21132112
kernel_setsockopt(sock, SOL_TCP, TCP_KEEPCNT,
21142113
(char *)&keepcnt, sizeof(keepcnt));
21152114

0 commit comments

Comments
 (0)