Lines Matching refs:sk
26 static u32 tcp_clamp_rto_to_user_timeout(const struct sock *sk) in tcp_clamp_rto_to_user_timeout() argument
28 struct inet_connection_sock *icsk = inet_csk(sk); in tcp_clamp_rto_to_user_timeout()
32 start_ts = tcp_sk(sk)->retrans_stamp; in tcp_clamp_rto_to_user_timeout()
35 elapsed = tcp_time_stamp(tcp_sk(sk)) - start_ts; in tcp_clamp_rto_to_user_timeout()
43 u32 tcp_clamp_probe0_to_user_timeout(const struct sock *sk, u32 when) in tcp_clamp_probe0_to_user_timeout() argument
45 struct inet_connection_sock *icsk = inet_csk(sk); in tcp_clamp_probe0_to_user_timeout()
68 static void tcp_write_err(struct sock *sk) in tcp_write_err() argument
70 sk->sk_err = sk->sk_err_soft ? : ETIMEDOUT; in tcp_write_err()
71 sk_error_report(sk); in tcp_write_err()
73 tcp_write_queue_purge(sk); in tcp_write_err()
74 tcp_done(sk); in tcp_write_err()
75 __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONTIMEOUT); in tcp_write_err()
102 static int tcp_out_of_resources(struct sock *sk, bool do_reset) in tcp_out_of_resources() argument
104 struct tcp_sock *tp = tcp_sk(sk); in tcp_out_of_resources()
113 if (sk->sk_err_soft) in tcp_out_of_resources()
116 if (tcp_check_oom(sk, shift)) { in tcp_out_of_resources()
124 tcp_send_active_reset(sk, GFP_ATOMIC); in tcp_out_of_resources()
125 tcp_done(sk); in tcp_out_of_resources()
126 __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONMEMORY); in tcp_out_of_resources()
130 if (!check_net(sock_net(sk))) { in tcp_out_of_resources()
132 tcp_done(sk); in tcp_out_of_resources()
144 static int tcp_orphan_retries(struct sock *sk, bool alive) in tcp_orphan_retries() argument
146 int retries = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_orphan_retries); /* May be zero. */ in tcp_orphan_retries()
149 if (sk->sk_err_soft && !alive) in tcp_orphan_retries()
160 static void tcp_mtu_probing(struct inet_connection_sock *icsk, struct sock *sk) in tcp_mtu_probing() argument
162 const struct net *net = sock_net(sk); in tcp_mtu_probing()
173 mss = tcp_mtu_to_mss(sk, icsk->icsk_mtup.search_low) >> 1; in tcp_mtu_probing()
177 icsk->icsk_mtup.search_low = tcp_mss_to_mtu(sk, mss); in tcp_mtu_probing()
179 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie); in tcp_mtu_probing()
182 static unsigned int tcp_model_timeout(struct sock *sk, in tcp_model_timeout() argument
209 static bool retransmits_timed_out(struct sock *sk, in retransmits_timed_out() argument
215 if (!inet_csk(sk)->icsk_retransmits) in retransmits_timed_out()
218 start_ts = tcp_sk(sk)->retrans_stamp; in retransmits_timed_out()
222 if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) in retransmits_timed_out()
223 rto_base = tcp_timeout_init(sk); in retransmits_timed_out()
224 timeout = tcp_model_timeout(sk, boundary, rto_base); in retransmits_timed_out()
227 return (s32)(tcp_time_stamp(tcp_sk(sk)) - start_ts - timeout) >= 0; in retransmits_timed_out()
231 static int tcp_write_timeout(struct sock *sk) in tcp_write_timeout() argument
233 struct inet_connection_sock *icsk = inet_csk(sk); in tcp_write_timeout()
234 struct tcp_sock *tp = tcp_sk(sk); in tcp_write_timeout()
235 struct net *net = sock_net(sk); in tcp_write_timeout()
239 if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) { in tcp_write_timeout()
241 __dst_negative_advice(sk); in tcp_write_timeout()
246 if (retransmits_timed_out(sk, READ_ONCE(net->ipv4.sysctl_tcp_retries1), 0)) { in tcp_write_timeout()
248 tcp_mtu_probing(icsk, sk); in tcp_write_timeout()
250 __dst_negative_advice(sk); in tcp_write_timeout()
254 if (sock_flag(sk, SOCK_DEAD)) { in tcp_write_timeout()
257 retry_until = tcp_orphan_retries(sk, alive); in tcp_write_timeout()
259 !retransmits_timed_out(sk, retry_until, 0); in tcp_write_timeout()
261 if (tcp_out_of_resources(sk, do_reset)) in tcp_write_timeout()
266 expired = retransmits_timed_out(sk, retry_until, in tcp_write_timeout()
268 tcp_fastopen_active_detect_blackhole(sk, expired); in tcp_write_timeout()
271 tcp_call_bpf_3arg(sk, BPF_SOCK_OPS_RTO_CB, in tcp_write_timeout()
277 tcp_write_err(sk); in tcp_write_timeout()
281 if (sk_rethink_txhash(sk)) { in tcp_write_timeout()
283 __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPTIMEOUTREHASH); in tcp_write_timeout()
290 void tcp_delack_timer_handler(struct sock *sk) in tcp_delack_timer_handler() argument
292 struct inet_connection_sock *icsk = inet_csk(sk); in tcp_delack_timer_handler()
294 if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) || in tcp_delack_timer_handler()
299 sk_reset_timer(sk, &icsk->icsk_delack_timer, icsk->icsk_ack.timeout); in tcp_delack_timer_handler()
304 if (inet_csk_ack_scheduled(sk)) { in tcp_delack_timer_handler()
305 if (!inet_csk_in_pingpong_mode(sk)) { in tcp_delack_timer_handler()
312 inet_csk_exit_pingpong_mode(sk); in tcp_delack_timer_handler()
315 tcp_mstamp_refresh(tcp_sk(sk)); in tcp_delack_timer_handler()
316 tcp_send_ack(sk); in tcp_delack_timer_handler()
317 __NET_INC_STATS(sock_net(sk), LINUX_MIB_DELAYEDACKS); in tcp_delack_timer_handler()
335 struct sock *sk = &icsk->icsk_inet.sk; in tcp_delack_timer() local
337 bh_lock_sock(sk); in tcp_delack_timer()
338 if (!sock_owned_by_user(sk)) { in tcp_delack_timer()
339 tcp_delack_timer_handler(sk); in tcp_delack_timer()
341 __NET_INC_STATS(sock_net(sk), LINUX_MIB_DELAYEDACKLOCKED); in tcp_delack_timer()
343 if (!test_and_set_bit(TCP_DELACK_TIMER_DEFERRED, &sk->sk_tsq_flags)) in tcp_delack_timer()
344 sock_hold(sk); in tcp_delack_timer()
346 bh_unlock_sock(sk); in tcp_delack_timer()
347 sock_put(sk); in tcp_delack_timer()
350 static void tcp_probe_timer(struct sock *sk) in tcp_probe_timer() argument
352 struct inet_connection_sock *icsk = inet_csk(sk); in tcp_probe_timer()
353 struct sk_buff *skb = tcp_send_head(sk); in tcp_probe_timer()
354 struct tcp_sock *tp = tcp_sk(sk); in tcp_probe_timer()
378 max_probes = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_retries2); in tcp_probe_timer()
379 if (sock_flag(sk, SOCK_DEAD)) { in tcp_probe_timer()
382 max_probes = tcp_orphan_retries(sk, alive); in tcp_probe_timer()
385 if (tcp_out_of_resources(sk, true)) in tcp_probe_timer()
390 abort: tcp_write_err(sk); in tcp_probe_timer()
393 tcp_send_probe0(sk); in tcp_probe_timer()
401 static void tcp_fastopen_synack_timer(struct sock *sk, struct request_sock *req) in tcp_fastopen_synack_timer() argument
403 struct inet_connection_sock *icsk = inet_csk(sk); in tcp_fastopen_synack_timer()
404 struct tcp_sock *tp = tcp_sk(sk); in tcp_fastopen_synack_timer()
411 READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_synack_retries) + 1; in tcp_fastopen_synack_timer()
414 tcp_write_err(sk); in tcp_fastopen_synack_timer()
419 tcp_enter_loss(sk); in tcp_fastopen_synack_timer()
425 inet_rtx_syn_ack(sk, req); in tcp_fastopen_synack_timer()
430 inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, in tcp_fastopen_synack_timer()
446 void tcp_retransmit_timer(struct sock *sk) in tcp_retransmit_timer() argument
448 struct tcp_sock *tp = tcp_sk(sk); in tcp_retransmit_timer()
449 struct net *net = sock_net(sk); in tcp_retransmit_timer()
450 struct inet_connection_sock *icsk = inet_csk(sk); in tcp_retransmit_timer()
455 lockdep_sock_is_held(sk)); in tcp_retransmit_timer()
457 WARN_ON_ONCE(sk->sk_state != TCP_SYN_RECV && in tcp_retransmit_timer()
458 sk->sk_state != TCP_FIN_WAIT1); in tcp_retransmit_timer()
459 tcp_fastopen_synack_timer(sk, req); in tcp_retransmit_timer()
469 skb = tcp_rtx_queue_head(sk); in tcp_retransmit_timer()
475 if (!tp->snd_wnd && !sock_flag(sk, SOCK_DEAD) && in tcp_retransmit_timer()
476 !((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV))) { in tcp_retransmit_timer()
482 struct inet_sock *inet = inet_sk(sk); in tcp_retransmit_timer()
483 if (sk->sk_family == AF_INET) { in tcp_retransmit_timer()
491 else if (sk->sk_family == AF_INET6) { in tcp_retransmit_timer()
493 &sk->sk_v6_daddr, in tcp_retransmit_timer()
500 tcp_write_err(sk); in tcp_retransmit_timer()
503 tcp_enter_loss(sk); in tcp_retransmit_timer()
504 tcp_retransmit_skb(sk, skb, 1); in tcp_retransmit_timer()
505 __sk_dst_reset(sk); in tcp_retransmit_timer()
509 __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPTIMEOUTS); in tcp_retransmit_timer()
510 if (tcp_write_timeout(sk)) in tcp_retransmit_timer()
531 __NET_INC_STATS(sock_net(sk), mib_idx); in tcp_retransmit_timer()
534 tcp_enter_loss(sk); in tcp_retransmit_timer()
537 if (tcp_retransmit_skb(sk, tcp_rtx_queue_head(sk), 1) > 0) { in tcp_retransmit_timer()
541 inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, in tcp_retransmit_timer()
574 if (sk->sk_state == TCP_ESTABLISHED && in tcp_retransmit_timer()
584 inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, in tcp_retransmit_timer()
585 tcp_clamp_rto_to_user_timeout(sk), TCP_RTO_MAX); in tcp_retransmit_timer()
586 if (retransmits_timed_out(sk, READ_ONCE(net->ipv4.sysctl_tcp_retries1) + 1, 0)) in tcp_retransmit_timer()
587 __sk_dst_reset(sk); in tcp_retransmit_timer()
594 void tcp_write_timer_handler(struct sock *sk) in tcp_write_timer_handler() argument
596 struct inet_connection_sock *icsk = inet_csk(sk); in tcp_write_timer_handler()
599 if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) || in tcp_write_timer_handler()
604 sk_reset_timer(sk, &icsk->icsk_retransmit_timer, icsk->icsk_timeout); in tcp_write_timer_handler()
608 tcp_mstamp_refresh(tcp_sk(sk)); in tcp_write_timer_handler()
613 tcp_rack_reo_timeout(sk); in tcp_write_timer_handler()
616 tcp_send_loss_probe(sk); in tcp_write_timer_handler()
620 tcp_retransmit_timer(sk); in tcp_write_timer_handler()
624 tcp_probe_timer(sk); in tcp_write_timer_handler()
633 struct sock *sk = &icsk->icsk_inet.sk; in tcp_write_timer() local
635 bh_lock_sock(sk); in tcp_write_timer()
636 if (!sock_owned_by_user(sk)) { in tcp_write_timer()
637 tcp_write_timer_handler(sk); in tcp_write_timer()
640 if (!test_and_set_bit(TCP_WRITE_TIMER_DEFERRED, &sk->sk_tsq_flags)) in tcp_write_timer()
641 sock_hold(sk); in tcp_write_timer()
643 bh_unlock_sock(sk); in tcp_write_timer()
644 sock_put(sk); in tcp_write_timer()
655 void tcp_set_keepalive(struct sock *sk, int val) in tcp_set_keepalive() argument
657 if ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) in tcp_set_keepalive()
660 if (val && !sock_flag(sk, SOCK_KEEPOPEN)) in tcp_set_keepalive()
661 inet_csk_reset_keepalive_timer(sk, keepalive_time_when(tcp_sk(sk))); in tcp_set_keepalive()
663 inet_csk_delete_keepalive_timer(sk); in tcp_set_keepalive()
670 struct sock *sk = from_timer(sk, t, sk_timer); in tcp_keepalive_timer() local
671 struct inet_connection_sock *icsk = inet_csk(sk); in tcp_keepalive_timer()
672 struct tcp_sock *tp = tcp_sk(sk); in tcp_keepalive_timer()
676 bh_lock_sock(sk); in tcp_keepalive_timer()
677 if (sock_owned_by_user(sk)) { in tcp_keepalive_timer()
679 inet_csk_reset_keepalive_timer (sk, HZ/20); in tcp_keepalive_timer()
683 if (sk->sk_state == TCP_LISTEN) { in tcp_keepalive_timer()
689 if (sk->sk_state == TCP_FIN_WAIT2 && sock_flag(sk, SOCK_DEAD)) { in tcp_keepalive_timer()
691 const int tmo = tcp_fin_time(sk) - TCP_TIMEWAIT_LEN; in tcp_keepalive_timer()
694 tcp_time_wait(sk, TCP_FIN_WAIT2, tmo); in tcp_keepalive_timer()
698 tcp_send_active_reset(sk, GFP_ATOMIC); in tcp_keepalive_timer()
702 if (!sock_flag(sk, SOCK_KEEPOPEN) || in tcp_keepalive_timer()
703 ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_SYN_SENT))) in tcp_keepalive_timer()
709 if (tp->packets_out || !tcp_write_queue_empty(sk)) in tcp_keepalive_timer()
723 tcp_send_active_reset(sk, GFP_ATOMIC); in tcp_keepalive_timer()
724 tcp_write_err(sk); in tcp_keepalive_timer()
727 if (tcp_write_wakeup(sk, LINUX_MIB_TCPKEEPALIVE) <= 0) { in tcp_keepalive_timer()
742 inet_csk_reset_keepalive_timer (sk, elapsed); in tcp_keepalive_timer()
746 tcp_done(sk); in tcp_keepalive_timer()
749 bh_unlock_sock(sk); in tcp_keepalive_timer()
750 sock_put(sk); in tcp_keepalive_timer()
756 struct sock *sk = (struct sock *)tp; in tcp_compressed_ack_kick() local
758 bh_lock_sock(sk); in tcp_compressed_ack_kick()
759 if (!sock_owned_by_user(sk)) { in tcp_compressed_ack_kick()
766 tcp_send_ack(sk); in tcp_compressed_ack_kick()
770 &sk->sk_tsq_flags)) in tcp_compressed_ack_kick()
771 sock_hold(sk); in tcp_compressed_ack_kick()
773 bh_unlock_sock(sk); in tcp_compressed_ack_kick()
775 sock_put(sk); in tcp_compressed_ack_kick()
780 void tcp_init_xmit_timers(struct sock *sk) in tcp_init_xmit_timers() argument
782 inet_csk_init_xmit_timers(sk, &tcp_write_timer, &tcp_delack_timer, in tcp_init_xmit_timers()
784 hrtimer_init(&tcp_sk(sk)->pacing_timer, CLOCK_MONOTONIC, in tcp_init_xmit_timers()
786 tcp_sk(sk)->pacing_timer.function = tcp_pace_kick; in tcp_init_xmit_timers()
788 hrtimer_init(&tcp_sk(sk)->compressed_ack_timer, CLOCK_MONOTONIC, in tcp_init_xmit_timers()
790 tcp_sk(sk)->compressed_ack_timer.function = tcp_compressed_ack_kick; in tcp_init_xmit_timers()