• Home
  • Raw
  • Download

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()
50 static void tcp_write_err(struct sock *sk) in tcp_write_err() argument
52 sk->sk_err = sk->sk_err_soft ? : ETIMEDOUT; in tcp_write_err()
53 sk->sk_error_report(sk); in tcp_write_err()
55 tcp_write_queue_purge(sk); in tcp_write_err()
56 tcp_done(sk); in tcp_write_err()
57 __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONTIMEOUT); in tcp_write_err()
84 static int tcp_out_of_resources(struct sock *sk, bool do_reset) in tcp_out_of_resources() argument
86 struct tcp_sock *tp = tcp_sk(sk); in tcp_out_of_resources()
95 if (sk->sk_err_soft) in tcp_out_of_resources()
98 if (tcp_check_oom(sk, shift)) { in tcp_out_of_resources()
106 tcp_send_active_reset(sk, GFP_ATOMIC); in tcp_out_of_resources()
107 tcp_done(sk); in tcp_out_of_resources()
108 __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTONMEMORY); in tcp_out_of_resources()
112 if (!check_net(sock_net(sk))) { in tcp_out_of_resources()
114 tcp_done(sk); in tcp_out_of_resources()
126 static int tcp_orphan_retries(struct sock *sk, bool alive) in tcp_orphan_retries() argument
128 int retries = sock_net(sk)->ipv4.sysctl_tcp_orphan_retries; /* May be zero. */ in tcp_orphan_retries()
131 if (sk->sk_err_soft && !alive) in tcp_orphan_retries()
142 static void tcp_mtu_probing(struct inet_connection_sock *icsk, struct sock *sk) in tcp_mtu_probing() argument
144 const struct net *net = sock_net(sk); in tcp_mtu_probing()
155 mss = tcp_mtu_to_mss(sk, icsk->icsk_mtup.search_low) >> 1; in tcp_mtu_probing()
159 icsk->icsk_mtup.search_low = tcp_mss_to_mtu(sk, mss); in tcp_mtu_probing()
161 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie); in tcp_mtu_probing()
164 static unsigned int tcp_model_timeout(struct sock *sk, in tcp_model_timeout() argument
191 static bool retransmits_timed_out(struct sock *sk, in retransmits_timed_out() argument
197 if (!inet_csk(sk)->icsk_retransmits) in retransmits_timed_out()
200 start_ts = tcp_sk(sk)->retrans_stamp; in retransmits_timed_out()
204 if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) in retransmits_timed_out()
205 rto_base = tcp_timeout_init(sk); in retransmits_timed_out()
206 timeout = tcp_model_timeout(sk, boundary, rto_base); in retransmits_timed_out()
209 return (s32)(tcp_time_stamp(tcp_sk(sk)) - start_ts - timeout) >= 0; in retransmits_timed_out()
213 static int tcp_write_timeout(struct sock *sk) in tcp_write_timeout() argument
215 struct inet_connection_sock *icsk = inet_csk(sk); in tcp_write_timeout()
216 struct tcp_sock *tp = tcp_sk(sk); in tcp_write_timeout()
217 struct net *net = sock_net(sk); in tcp_write_timeout()
221 if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) { in tcp_write_timeout()
223 dst_negative_advice(sk); in tcp_write_timeout()
225 sk_rethink_txhash(sk); in tcp_write_timeout()
230 if (retransmits_timed_out(sk, net->ipv4.sysctl_tcp_retries1, 0)) { in tcp_write_timeout()
232 tcp_mtu_probing(icsk, sk); in tcp_write_timeout()
234 dst_negative_advice(sk); in tcp_write_timeout()
236 sk_rethink_txhash(sk); in tcp_write_timeout()
240 if (sock_flag(sk, SOCK_DEAD)) { in tcp_write_timeout()
243 retry_until = tcp_orphan_retries(sk, alive); in tcp_write_timeout()
245 !retransmits_timed_out(sk, retry_until, 0); in tcp_write_timeout()
247 if (tcp_out_of_resources(sk, do_reset)) in tcp_write_timeout()
252 expired = retransmits_timed_out(sk, retry_until, in tcp_write_timeout()
254 tcp_fastopen_active_detect_blackhole(sk, expired); in tcp_write_timeout()
257 tcp_call_bpf_3arg(sk, BPF_SOCK_OPS_RTO_CB, in tcp_write_timeout()
263 tcp_write_err(sk); in tcp_write_timeout()
271 void tcp_delack_timer_handler(struct sock *sk) in tcp_delack_timer_handler() argument
273 struct inet_connection_sock *icsk = inet_csk(sk); in tcp_delack_timer_handler()
275 sk_mem_reclaim_partial(sk); in tcp_delack_timer_handler()
277 if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) || in tcp_delack_timer_handler()
282 sk_reset_timer(sk, &icsk->icsk_delack_timer, icsk->icsk_ack.timeout); in tcp_delack_timer_handler()
287 if (inet_csk_ack_scheduled(sk)) { in tcp_delack_timer_handler()
288 if (!inet_csk_in_pingpong_mode(sk)) { in tcp_delack_timer_handler()
295 inet_csk_exit_pingpong_mode(sk); in tcp_delack_timer_handler()
298 tcp_mstamp_refresh(tcp_sk(sk)); in tcp_delack_timer_handler()
299 tcp_send_ack(sk); in tcp_delack_timer_handler()
300 __NET_INC_STATS(sock_net(sk), LINUX_MIB_DELAYEDACKS); in tcp_delack_timer_handler()
304 if (tcp_under_memory_pressure(sk)) in tcp_delack_timer_handler()
305 sk_mem_reclaim(sk); in tcp_delack_timer_handler()
322 struct sock *sk = &icsk->icsk_inet.sk; in tcp_delack_timer() local
324 bh_lock_sock(sk); in tcp_delack_timer()
325 if (!sock_owned_by_user(sk)) { in tcp_delack_timer()
326 tcp_delack_timer_handler(sk); in tcp_delack_timer()
329 __NET_INC_STATS(sock_net(sk), LINUX_MIB_DELAYEDACKLOCKED); in tcp_delack_timer()
331 if (!test_and_set_bit(TCP_DELACK_TIMER_DEFERRED, &sk->sk_tsq_flags)) in tcp_delack_timer()
332 sock_hold(sk); in tcp_delack_timer()
334 bh_unlock_sock(sk); in tcp_delack_timer()
335 sock_put(sk); in tcp_delack_timer()
338 static void tcp_probe_timer(struct sock *sk) in tcp_probe_timer() argument
340 struct inet_connection_sock *icsk = inet_csk(sk); in tcp_probe_timer()
341 struct sk_buff *skb = tcp_send_head(sk); in tcp_probe_timer()
342 struct tcp_sock *tp = tcp_sk(sk); in tcp_probe_timer()
359 u32 elapsed = tcp_model_timeout(sk, icsk->icsk_probes_out, in tcp_probe_timer()
360 tcp_probe0_base(sk)); in tcp_probe_timer()
366 max_probes = sock_net(sk)->ipv4.sysctl_tcp_retries2; in tcp_probe_timer()
367 if (sock_flag(sk, SOCK_DEAD)) { in tcp_probe_timer()
370 max_probes = tcp_orphan_retries(sk, alive); in tcp_probe_timer()
373 if (tcp_out_of_resources(sk, true)) in tcp_probe_timer()
378 abort: tcp_write_err(sk); in tcp_probe_timer()
381 tcp_send_probe0(sk); in tcp_probe_timer()
389 static void tcp_fastopen_synack_timer(struct sock *sk, struct request_sock *req) in tcp_fastopen_synack_timer() argument
391 struct inet_connection_sock *icsk = inet_csk(sk); in tcp_fastopen_synack_timer()
393 sock_net(sk)->ipv4.sysctl_tcp_synack_retries + 1; /* add one more retry for fastopen */ in tcp_fastopen_synack_timer()
394 struct tcp_sock *tp = tcp_sk(sk); in tcp_fastopen_synack_timer()
399 tcp_write_err(sk); in tcp_fastopen_synack_timer()
404 tcp_enter_loss(sk); in tcp_fastopen_synack_timer()
410 inet_rtx_syn_ack(sk, req); in tcp_fastopen_synack_timer()
415 inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, in tcp_fastopen_synack_timer()
431 void tcp_retransmit_timer(struct sock *sk) in tcp_retransmit_timer() argument
433 struct tcp_sock *tp = tcp_sk(sk); in tcp_retransmit_timer()
434 struct net *net = sock_net(sk); in tcp_retransmit_timer()
435 struct inet_connection_sock *icsk = inet_csk(sk); in tcp_retransmit_timer()
439 lockdep_sock_is_held(sk)); in tcp_retransmit_timer()
441 WARN_ON_ONCE(sk->sk_state != TCP_SYN_RECV && in tcp_retransmit_timer()
442 sk->sk_state != TCP_FIN_WAIT1); in tcp_retransmit_timer()
443 tcp_fastopen_synack_timer(sk, req); in tcp_retransmit_timer()
449 if (!tp->packets_out || WARN_ON_ONCE(tcp_rtx_queue_empty(sk))) in tcp_retransmit_timer()
454 if (!tp->snd_wnd && !sock_flag(sk, SOCK_DEAD) && in tcp_retransmit_timer()
455 !((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV))) { in tcp_retransmit_timer()
461 struct inet_sock *inet = inet_sk(sk); in tcp_retransmit_timer()
462 if (sk->sk_family == AF_INET) { in tcp_retransmit_timer()
470 else if (sk->sk_family == AF_INET6) { in tcp_retransmit_timer()
472 &sk->sk_v6_daddr, in tcp_retransmit_timer()
479 tcp_write_err(sk); in tcp_retransmit_timer()
482 tcp_enter_loss(sk); in tcp_retransmit_timer()
483 tcp_retransmit_skb(sk, tcp_rtx_queue_head(sk), 1); in tcp_retransmit_timer()
484 __sk_dst_reset(sk); in tcp_retransmit_timer()
488 __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPTIMEOUTS); in tcp_retransmit_timer()
489 if (tcp_write_timeout(sk)) in tcp_retransmit_timer()
510 __NET_INC_STATS(sock_net(sk), mib_idx); in tcp_retransmit_timer()
513 tcp_enter_loss(sk); in tcp_retransmit_timer()
516 if (tcp_retransmit_skb(sk, tcp_rtx_queue_head(sk), 1) > 0) { in tcp_retransmit_timer()
520 inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, in tcp_retransmit_timer()
553 if (sk->sk_state == TCP_ESTABLISHED && in tcp_retransmit_timer()
563 inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, in tcp_retransmit_timer()
564 tcp_clamp_rto_to_user_timeout(sk), TCP_RTO_MAX); in tcp_retransmit_timer()
565 if (retransmits_timed_out(sk, net->ipv4.sysctl_tcp_retries1 + 1, 0)) in tcp_retransmit_timer()
566 __sk_dst_reset(sk); in tcp_retransmit_timer()
573 void tcp_write_timer_handler(struct sock *sk) in tcp_write_timer_handler() argument
575 struct inet_connection_sock *icsk = inet_csk(sk); in tcp_write_timer_handler()
578 if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) || in tcp_write_timer_handler()
583 sk_reset_timer(sk, &icsk->icsk_retransmit_timer, icsk->icsk_timeout); in tcp_write_timer_handler()
587 tcp_mstamp_refresh(tcp_sk(sk)); in tcp_write_timer_handler()
592 tcp_rack_reo_timeout(sk); in tcp_write_timer_handler()
595 tcp_send_loss_probe(sk); in tcp_write_timer_handler()
599 tcp_retransmit_timer(sk); in tcp_write_timer_handler()
603 tcp_probe_timer(sk); in tcp_write_timer_handler()
608 sk_mem_reclaim(sk); in tcp_write_timer_handler()
615 struct sock *sk = &icsk->icsk_inet.sk; in tcp_write_timer() local
617 bh_lock_sock(sk); in tcp_write_timer()
618 if (!sock_owned_by_user(sk)) { in tcp_write_timer()
619 tcp_write_timer_handler(sk); in tcp_write_timer()
622 if (!test_and_set_bit(TCP_WRITE_TIMER_DEFERRED, &sk->sk_tsq_flags)) in tcp_write_timer()
623 sock_hold(sk); in tcp_write_timer()
625 bh_unlock_sock(sk); in tcp_write_timer()
626 sock_put(sk); in tcp_write_timer()
637 void tcp_set_keepalive(struct sock *sk, int val) in tcp_set_keepalive() argument
639 if ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) in tcp_set_keepalive()
642 if (val && !sock_flag(sk, SOCK_KEEPOPEN)) in tcp_set_keepalive()
643 inet_csk_reset_keepalive_timer(sk, keepalive_time_when(tcp_sk(sk))); in tcp_set_keepalive()
645 inet_csk_delete_keepalive_timer(sk); in tcp_set_keepalive()
652 struct sock *sk = from_timer(sk, t, sk_timer); in tcp_keepalive_timer() local
653 struct inet_connection_sock *icsk = inet_csk(sk); in tcp_keepalive_timer()
654 struct tcp_sock *tp = tcp_sk(sk); in tcp_keepalive_timer()
658 bh_lock_sock(sk); in tcp_keepalive_timer()
659 if (sock_owned_by_user(sk)) { in tcp_keepalive_timer()
661 inet_csk_reset_keepalive_timer (sk, HZ/20); in tcp_keepalive_timer()
665 if (sk->sk_state == TCP_LISTEN) { in tcp_keepalive_timer()
671 if (sk->sk_state == TCP_FIN_WAIT2 && sock_flag(sk, SOCK_DEAD)) { in tcp_keepalive_timer()
673 const int tmo = tcp_fin_time(sk) - TCP_TIMEWAIT_LEN; in tcp_keepalive_timer()
676 tcp_time_wait(sk, TCP_FIN_WAIT2, tmo); in tcp_keepalive_timer()
680 tcp_send_active_reset(sk, GFP_ATOMIC); in tcp_keepalive_timer()
684 if (!sock_flag(sk, SOCK_KEEPOPEN) || in tcp_keepalive_timer()
685 ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_SYN_SENT))) in tcp_keepalive_timer()
691 if (tp->packets_out || !tcp_write_queue_empty(sk)) in tcp_keepalive_timer()
705 tcp_send_active_reset(sk, GFP_ATOMIC); in tcp_keepalive_timer()
706 tcp_write_err(sk); in tcp_keepalive_timer()
709 if (tcp_write_wakeup(sk, LINUX_MIB_TCPKEEPALIVE) <= 0) { in tcp_keepalive_timer()
723 sk_mem_reclaim(sk); in tcp_keepalive_timer()
726 inet_csk_reset_keepalive_timer (sk, elapsed); in tcp_keepalive_timer()
730 tcp_done(sk); in tcp_keepalive_timer()
733 bh_unlock_sock(sk); in tcp_keepalive_timer()
734 sock_put(sk); in tcp_keepalive_timer()
740 struct sock *sk = (struct sock *)tp; in tcp_compressed_ack_kick() local
742 bh_lock_sock(sk); in tcp_compressed_ack_kick()
743 if (!sock_owned_by_user(sk)) { in tcp_compressed_ack_kick()
745 tcp_send_ack(sk); in tcp_compressed_ack_kick()
748 &sk->sk_tsq_flags)) in tcp_compressed_ack_kick()
749 sock_hold(sk); in tcp_compressed_ack_kick()
751 bh_unlock_sock(sk); in tcp_compressed_ack_kick()
753 sock_put(sk); in tcp_compressed_ack_kick()
758 void tcp_init_xmit_timers(struct sock *sk) in tcp_init_xmit_timers() argument
760 inet_csk_init_xmit_timers(sk, &tcp_write_timer, &tcp_delack_timer, in tcp_init_xmit_timers()
762 hrtimer_init(&tcp_sk(sk)->pacing_timer, CLOCK_MONOTONIC, in tcp_init_xmit_timers()
764 tcp_sk(sk)->pacing_timer.function = tcp_pace_kick; in tcp_init_xmit_timers()
766 hrtimer_init(&tcp_sk(sk)->compressed_ack_timer, CLOCK_MONOTONIC, in tcp_init_xmit_timers()
768 tcp_sk(sk)->compressed_ack_timer.function = tcp_compressed_ack_kick; in tcp_init_xmit_timers()