Skip to content

Commit df19a62

Browse files
Eric Dumazetdavem330
authored andcommitted
tcp: keepalive cleanups
Introduce keepalive_probes(tp) helper, and use it, like keepalive_time_when(tp) and keepalive_intvl_when(tp) Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5e9b2db commit df19a62

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

include/net/tcp.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,11 @@ static inline int keepalive_time_when(const struct tcp_sock *tp)
10071007
return tp->keepalive_time ? : sysctl_tcp_keepalive_time;
10081008
}
10091009

1010+
static inline int keepalive_probes(const struct tcp_sock *tp)
1011+
{
1012+
return tp->keepalive_probes ? : sysctl_tcp_keepalive_probes;
1013+
}
1014+
10101015
static inline int tcp_fin_time(const struct sock *sk)
10111016
{
10121017
int fin_timeout = tcp_sk(sk)->linger2 ? : sysctl_tcp_fin_timeout;

net/ipv4/tcp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2336,13 +2336,13 @@ static int do_tcp_getsockopt(struct sock *sk, int level,
23362336
val = !!(tp->nonagle&TCP_NAGLE_CORK);
23372337
break;
23382338
case TCP_KEEPIDLE:
2339-
val = (tp->keepalive_time ? : sysctl_tcp_keepalive_time) / HZ;
2339+
val = keepalive_time_when(tp) / HZ;
23402340
break;
23412341
case TCP_KEEPINTVL:
2342-
val = (tp->keepalive_intvl ? : sysctl_tcp_keepalive_intvl) / HZ;
2342+
val = keepalive_intvl_when(tp) / HZ;
23432343
break;
23442344
case TCP_KEEPCNT:
2345-
val = tp->keepalive_probes ? : sysctl_tcp_keepalive_probes;
2345+
val = keepalive_probes(tp);
23462346
break;
23472347
case TCP_SYNCNT:
23482348
val = icsk->icsk_syn_retries ? : sysctl_tcp_syn_retries;

net/ipv4/tcp_timer.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,7 @@ static void tcp_keepalive_timer (unsigned long data)
499499
elapsed = tcp_time_stamp - tp->rcv_tstamp;
500500

501501
if (elapsed >= keepalive_time_when(tp)) {
502-
if ((!tp->keepalive_probes && icsk->icsk_probes_out >= sysctl_tcp_keepalive_probes) ||
503-
(tp->keepalive_probes && icsk->icsk_probes_out >= tp->keepalive_probes)) {
502+
if (icsk->icsk_probes_out >= keepalive_probes(tp)) {
504503
tcp_send_active_reset(sk, GFP_ATOMIC);
505504
tcp_write_err(sk);
506505
goto out;

0 commit comments

Comments
 (0)