Commit 6c37e5de456987f5bc80879afde05aa120784095
Committed by
David S. Miller
1 parent
dcdca2c49b
Exists in
master
and in
7 other branches
TCP: avoid to send keepalive probes if receiving data
RFC 1122 says the following: ... Keep-alive packets MUST only be sent when no data or acknowledgement packets have been received for the connection within an interval. ... The acknowledgement packet is reseting the keepalive timer but the data packet isn't. This patch fixes it by checking the timestamp of the last received data packet too when the keepalive timer expires. Signed-off-by: Flavio Leitner <fleitner@redhat.com> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Acked-by: Ilpo Järvinen <ilpo.jarvinen@helsinki.fi> Signed-off-by: David S. Miller <davem@davemloft.net>
Showing 3 changed files with 11 additions and 3 deletions Side-by-side Diff
include/net/tcp.h
... | ... | @@ -1033,6 +1033,14 @@ |
1033 | 1033 | return tp->keepalive_probes ? : sysctl_tcp_keepalive_probes; |
1034 | 1034 | } |
1035 | 1035 | |
1036 | +static inline u32 keepalive_time_elapsed(const struct tcp_sock *tp) | |
1037 | +{ | |
1038 | + const struct inet_connection_sock *icsk = &tp->inet_conn; | |
1039 | + | |
1040 | + return min_t(u32, tcp_time_stamp - icsk->icsk_ack.lrcvtime, | |
1041 | + tcp_time_stamp - tp->rcv_tstamp); | |
1042 | +} | |
1043 | + | |
1036 | 1044 | static inline int tcp_fin_time(const struct sock *sk) |
1037 | 1045 | { |
1038 | 1046 | int fin_timeout = tcp_sk(sk)->linger2 ? : sysctl_tcp_fin_timeout; |
net/ipv4/tcp.c
... | ... | @@ -2298,7 +2298,7 @@ |
2298 | 2298 | if (sock_flag(sk, SOCK_KEEPOPEN) && |
2299 | 2299 | !((1 << sk->sk_state) & |
2300 | 2300 | (TCPF_CLOSE | TCPF_LISTEN))) { |
2301 | - __u32 elapsed = tcp_time_stamp - tp->rcv_tstamp; | |
2301 | + u32 elapsed = keepalive_time_elapsed(tp); | |
2302 | 2302 | if (tp->keepalive_time > elapsed) |
2303 | 2303 | elapsed = tp->keepalive_time - elapsed; |
2304 | 2304 | else |
net/ipv4/tcp_timer.c
... | ... | @@ -517,7 +517,7 @@ |
517 | 517 | struct sock *sk = (struct sock *) data; |
518 | 518 | struct inet_connection_sock *icsk = inet_csk(sk); |
519 | 519 | struct tcp_sock *tp = tcp_sk(sk); |
520 | - __u32 elapsed; | |
520 | + u32 elapsed; | |
521 | 521 | |
522 | 522 | /* Only process if socket is not in use. */ |
523 | 523 | bh_lock_sock(sk); |
... | ... | @@ -554,7 +554,7 @@ |
554 | 554 | if (tp->packets_out || tcp_send_head(sk)) |
555 | 555 | goto resched; |
556 | 556 | |
557 | - elapsed = tcp_time_stamp - tp->rcv_tstamp; | |
557 | + elapsed = keepalive_time_elapsed(tp); | |
558 | 558 | |
559 | 559 | if (elapsed >= keepalive_time_when(tp)) { |
560 | 560 | if (icsk->icsk_probes_out >= keepalive_probes(tp)) { |