Lines Matching +full:ideal +full:- +full:factor +full:- +full:value
1 // SPDX-License-Identifier: GPL-2.0
12 * Corey Minyard <wf-rch!minyard@relay.EU.net>
13 * Florian La Roche, <flla@stud.uni-sb.de>
62 * Pasi Sarolahti: F-RTO for dealing with spurious RTOs
98 #define FLAG_DSACKING_ACK 0x800 /* SACK blocks contained D-SACK info */
116 #define REXMIT_NEW 2 /* FRTO-style transmit of unsent/new packets */
124 icsk->icsk_clean_acked = cad; in clean_acked_data_enable()
132 icsk->icsk_clean_acked = NULL; in clean_acked_data_disable()
146 bool unknown_opt = tcp_sk(sk)->rx_opt.saw_unknown && in bpf_skops_parse_hdr()
160 switch (sk->sk_state) { in bpf_skops_parse_hdr()
212 dev = dev_get_by_index_rcu(sock_net(sk), skb->skb_iif); in tcp_gro_dev_warn()
213 if (!dev || len >= READ_ONCE(dev->mtu)) in tcp_gro_dev_warn()
215 dev ? dev->name : "Unknown driver"); in tcp_gro_dev_warn()
219 /* Adapt the MSS value used to make delayed ack decision to the
225 const unsigned int lss = icsk->icsk_ack.last_seg_size; in tcp_measure_rcv_mss()
228 icsk->icsk_ack.last_seg_size = 0; in tcp_measure_rcv_mss()
230 /* skb->len may jitter because of SACKs, even if peer in tcp_measure_rcv_mss()
231 * sends good full-sized frames. in tcp_measure_rcv_mss()
233 len = skb_shinfo(skb)->gso_size ? : skb->len; in tcp_measure_rcv_mss()
234 if (len >= icsk->icsk_ack.rcv_mss) { in tcp_measure_rcv_mss()
239 if (unlikely(len != icsk->icsk_ack.rcv_mss)) { in tcp_measure_rcv_mss()
240 u64 val = (u64)skb->len << TCP_RMEM_TO_WIN_SCALE; in tcp_measure_rcv_mss()
241 u8 old_ratio = tcp_sk(sk)->scaling_ratio; in tcp_measure_rcv_mss()
243 do_div(val, skb->truesize); in tcp_measure_rcv_mss()
244 tcp_sk(sk)->scaling_ratio = val ? val : 1; in tcp_measure_rcv_mss()
246 if (old_ratio != tcp_sk(sk)->scaling_ratio) in tcp_measure_rcv_mss()
247 WRITE_ONCE(tcp_sk(sk)->window_clamp, in tcp_measure_rcv_mss()
248 tcp_win_from_space(sk, sk->sk_rcvbuf)); in tcp_measure_rcv_mss()
250 icsk->icsk_ack.rcv_mss = min_t(unsigned int, len, in tcp_measure_rcv_mss()
251 tcp_sk(sk)->advmss); in tcp_measure_rcv_mss()
252 /* Account for possibly-removed options */ in tcp_measure_rcv_mss()
253 DO_ONCE_LITE_IF(len > icsk->icsk_ack.rcv_mss + MAX_TCP_OPTION_SPACE, in tcp_measure_rcv_mss()
258 * may be waiting for an ACK if cwnd-bound or using TX zero in tcp_measure_rcv_mss()
261 * reads all of the data and is not ping-pong. If len > MSS in tcp_measure_rcv_mss()
266 if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_PSH) in tcp_measure_rcv_mss()
267 icsk->icsk_ack.pending |= ICSK_ACK_PUSHED; in tcp_measure_rcv_mss()
274 len += skb->data - skb_transport_header(skb); in tcp_measure_rcv_mss()
279 * to handle super-low mtu links fairly. in tcp_measure_rcv_mss()
287 len -= tcp_sk(sk)->tcp_header_len; in tcp_measure_rcv_mss()
288 icsk->icsk_ack.last_seg_size = len; in tcp_measure_rcv_mss()
290 icsk->icsk_ack.rcv_mss = len; in tcp_measure_rcv_mss()
294 if (icsk->icsk_ack.pending & ICSK_ACK_PUSHED) in tcp_measure_rcv_mss()
295 icsk->icsk_ack.pending |= ICSK_ACK_PUSHED2; in tcp_measure_rcv_mss()
296 icsk->icsk_ack.pending |= ICSK_ACK_PUSHED; in tcp_measure_rcv_mss()
303 unsigned int quickacks = tcp_sk(sk)->rcv_wnd / (2 * icsk->icsk_ack.rcv_mss); in tcp_incr_quickack()
308 if (quickacks > icsk->icsk_ack.quick) in tcp_incr_quickack()
309 icsk->icsk_ack.quick = quickacks; in tcp_incr_quickack()
318 icsk->icsk_ack.ato = TCP_ATO_MIN; in tcp_enter_quickack_mode()
331 (icsk->icsk_ack.quick && !inet_csk_in_pingpong_mode(sk)); in tcp_in_quickack_mode()
336 if (tp->ecn_flags & TCP_ECN_OK) in tcp_ecn_queue_cwr()
337 tp->ecn_flags |= TCP_ECN_QUEUE_CWR; in tcp_ecn_queue_cwr()
342 if (tcp_hdr(skb)->cwr) { in tcp_ecn_accept_cwr()
343 tcp_sk(sk)->ecn_flags &= ~TCP_ECN_DEMAND_CWR; in tcp_ecn_accept_cwr()
349 if (TCP_SKB_CB(skb)->seq != TCP_SKB_CB(skb)->end_seq) in tcp_ecn_accept_cwr()
350 inet_csk(sk)->icsk_ack.pending |= ICSK_ACK_NOW; in tcp_ecn_accept_cwr()
356 tp->ecn_flags &= ~TCP_ECN_QUEUE_CWR; in tcp_ecn_withdraw_cwr()
363 switch (TCP_SKB_CB(skb)->ip_dsfield & INET_ECN_MASK) { in __tcp_ecn_check_ce()
369 if (tp->ecn_flags & TCP_ECN_SEEN) in __tcp_ecn_check_ce()
376 if (!(tp->ecn_flags & TCP_ECN_DEMAND_CWR)) { in __tcp_ecn_check_ce()
379 tp->ecn_flags |= TCP_ECN_DEMAND_CWR; in __tcp_ecn_check_ce()
381 tp->ecn_flags |= TCP_ECN_SEEN; in __tcp_ecn_check_ce()
386 tp->ecn_flags |= TCP_ECN_SEEN; in __tcp_ecn_check_ce()
393 if (tcp_sk(sk)->ecn_flags & TCP_ECN_OK) in tcp_ecn_check_ce()
399 if ((tp->ecn_flags & TCP_ECN_OK) && (!th->ece || th->cwr)) in tcp_ecn_rcv_synack()
400 tp->ecn_flags &= ~TCP_ECN_OK; in tcp_ecn_rcv_synack()
405 if ((tp->ecn_flags & TCP_ECN_OK) && (!th->ece || !th->cwr)) in tcp_ecn_rcv_syn()
406 tp->ecn_flags &= ~TCP_ECN_OK; in tcp_ecn_rcv_syn()
411 if (th->ece && !th->syn && (tp->ecn_flags & TCP_ECN_OK)) in tcp_ecn_rcv_ecn_echo()
418 * 1. Tuning sk->sk_sndbuf, when connection enters established state.
424 const struct tcp_congestion_ops *ca_ops = inet_csk(sk)->icsk_ca_ops; in tcp_sndbuf_expand()
429 * and skb->head is kmalloced using power of two area of memory in tcp_sndbuf_expand()
431 per_mss = max_t(u32, tp->rx_opt.mss_clamp, tp->mss_cache) + in tcp_sndbuf_expand()
439 nr_segs = max_t(u32, nr_segs, tp->reordering + 1); in tcp_sndbuf_expand()
442 * Cubic needs 1.7 factor, rounded to 2 to include in tcp_sndbuf_expand()
445 sndmem = ca_ops->sndbuf_expand ? ca_ops->sndbuf_expand(sk) : 2; in tcp_sndbuf_expand()
448 if (sk->sk_sndbuf < sndmem) in tcp_sndbuf_expand()
449 WRITE_ONCE(sk->sk_sndbuf, in tcp_sndbuf_expand()
450 min(sndmem, READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_wmem[2]))); in tcp_sndbuf_expand()
456 * forward and advertised in receiver window (tp->rcv_wnd) and
460 * tcp_full_space(), in this case tcp_full_space() - window_clamp
468 * - to enforce header prediction at sender, even when application
470 * - to prevent pruning of receive queue because of misprediction
485 int window = tcp_win_from_space(sk, READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_rmem[2])) >> 1; in __tcp_grow_window()
487 while (tp->rcv_ssthresh <= window) { in __tcp_grow_window()
488 if (truesize <= skb->len) in __tcp_grow_window()
489 return 2 * inet_csk(sk)->icsk_ack.rcv_mss; in __tcp_grow_window()
498 * can play nice with us, as sk_buff and skb->head might be either
501 * and if no payload was pulled in skb->head before reaching us.
505 u32 truesize = skb->truesize; in truesize_adjust()
508 truesize -= SKB_TRUESIZE(skb_end_offset(skb)); in truesize_adjust()
510 if (unlikely((int)truesize < (int)skb->len)) in truesize_adjust()
511 truesize = skb->truesize; in truesize_adjust()
522 room = min_t(int, tp->window_clamp, tcp_space(sk)) - tp->rcv_ssthresh; in tcp_grow_window()
535 if (tcp_win_from_space(sk, truesize) <= skb->len) in tcp_grow_window()
536 incr = 2 * tp->advmss; in tcp_grow_window()
541 incr = max_t(int, incr, 2 * skb->len); in tcp_grow_window()
542 tp->rcv_ssthresh += min(room, incr); in tcp_grow_window()
543 inet_csk(sk)->icsk_ack.quick |= 1; in tcp_grow_window()
558 int tcp_app_win = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_app_win); in tcp_init_buffer_space()
562 if (!(sk->sk_userlocks & SOCK_SNDBUF_LOCK)) in tcp_init_buffer_space()
566 tp->rcvq_space.time = tp->tcp_mstamp; in tcp_init_buffer_space()
567 tp->rcvq_space.seq = tp->copied_seq; in tcp_init_buffer_space()
571 if (tp->window_clamp >= maxwin) { in tcp_init_buffer_space()
572 WRITE_ONCE(tp->window_clamp, maxwin); in tcp_init_buffer_space()
574 if (tcp_app_win && maxwin > 4 * tp->advmss) in tcp_init_buffer_space()
575 WRITE_ONCE(tp->window_clamp, in tcp_init_buffer_space()
576 max(maxwin - (maxwin >> tcp_app_win), in tcp_init_buffer_space()
577 4 * tp->advmss)); in tcp_init_buffer_space()
582 tp->window_clamp > 2 * tp->advmss && in tcp_init_buffer_space()
583 tp->window_clamp + tp->advmss > maxwin) in tcp_init_buffer_space()
584 WRITE_ONCE(tp->window_clamp, in tcp_init_buffer_space()
585 max(2 * tp->advmss, maxwin - tp->advmss)); in tcp_init_buffer_space()
587 tp->rcv_ssthresh = min(tp->rcv_ssthresh, tp->window_clamp); in tcp_init_buffer_space()
588 tp->snd_cwnd_stamp = tcp_jiffies32; in tcp_init_buffer_space()
589 tp->rcvq_space.space = min3(tp->rcv_ssthresh, tp->rcv_wnd, in tcp_init_buffer_space()
590 (u32)TCP_INIT_CWND * tp->advmss); in tcp_init_buffer_space()
601 icsk->icsk_ack.quick = 0; in tcp_clamp_window()
602 rmem2 = READ_ONCE(net->ipv4.sysctl_tcp_rmem[2]); in tcp_clamp_window()
604 if (sk->sk_rcvbuf < rmem2 && in tcp_clamp_window()
605 !(sk->sk_userlocks & SOCK_RCVBUF_LOCK) && in tcp_clamp_window()
608 WRITE_ONCE(sk->sk_rcvbuf, in tcp_clamp_window()
609 min(atomic_read(&sk->sk_rmem_alloc), rmem2)); in tcp_clamp_window()
611 if (atomic_read(&sk->sk_rmem_alloc) > sk->sk_rcvbuf) in tcp_clamp_window()
612 tp->rcv_ssthresh = min(tp->window_clamp, 2U * tp->advmss); in tcp_clamp_window()
615 /* Initialize RCV_MSS value.
625 unsigned int hint = min_t(unsigned int, tp->advmss, tp->mss_cache); in tcp_initialize_rcv_mss()
627 hint = min(hint, tp->rcv_wnd / 2); in tcp_initialize_rcv_mss()
631 inet_csk(sk)->icsk_ack.rcv_mss = hint; in tcp_initialize_rcv_mss()
638 * Dynamic Right-Sizing (DRS) by Wu Feng and Mike Fisk of LANL.
648 u32 new_sample = tp->rcv_rtt_est.rtt_us; in tcp_rcv_rtt_update()
652 /* If we sample in larger samples in the non-timestamp in tcp_rcv_rtt_update()
658 * non-timestamp case, we do not smooth things out in tcp_rcv_rtt_update()
663 m -= (new_sample >> 3); in tcp_rcv_rtt_update()
675 tp->rcv_rtt_est.rtt_us = new_sample; in tcp_rcv_rtt_update()
682 if (tp->rcv_rtt_est.time == 0) in tcp_rcv_rtt_measure()
684 if (before(tp->rcv_nxt, tp->rcv_rtt_est.seq)) in tcp_rcv_rtt_measure()
686 delta_us = tcp_stamp_us_delta(tp->tcp_mstamp, tp->rcv_rtt_est.time); in tcp_rcv_rtt_measure()
692 tp->rcv_rtt_est.seq = tp->rcv_nxt + tp->rcv_wnd; in tcp_rcv_rtt_measure()
693 tp->rcv_rtt_est.time = tp->tcp_mstamp; in tcp_rcv_rtt_measure()
700 delta = tcp_time_stamp_ts(tp) - tp->rx_opt.rcv_tsecr; in tcp_rtt_tsopt_us()
701 if (tp->tcp_usec_ts) in tcp_rtt_tsopt_us()
710 return -1; in tcp_rtt_tsopt_us()
718 if (tp->rx_opt.rcv_tsecr == tp->rcv_rtt_last_tsecr) in tcp_rcv_rtt_measure_ts()
720 tp->rcv_rtt_last_tsecr = tp->rx_opt.rcv_tsecr; in tcp_rcv_rtt_measure_ts()
722 if (TCP_SKB_CB(skb)->end_seq - in tcp_rcv_rtt_measure_ts()
723 TCP_SKB_CB(skb)->seq >= inet_csk(sk)->icsk_ack.rcv_mss) { in tcp_rcv_rtt_measure_ts()
744 time = tcp_stamp_us_delta(tp->tcp_mstamp, tp->rcvq_space.time); in tcp_rcv_space_adjust()
745 if (time < (tp->rcv_rtt_est.rtt_us >> 3) || tp->rcv_rtt_est.rtt_us == 0) in tcp_rcv_space_adjust()
749 copied = tp->copied_seq - tp->rcvq_space.seq; in tcp_rcv_space_adjust()
750 if (copied <= tp->rcvq_space.space) in tcp_rcv_space_adjust()
755 * To cope with packet losses, we need a 2x factor in tcp_rcv_space_adjust()
757 * every RTT, we need a 4x factor, because the ACK we are sending in tcp_rcv_space_adjust()
762 if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_moderate_rcvbuf) && in tcp_rcv_space_adjust()
763 !(sk->sk_userlocks & SOCK_RCVBUF_LOCK)) { in tcp_rcv_space_adjust()
770 rcvwin = ((u64)copied << 1) + 16 * tp->advmss; in tcp_rcv_space_adjust()
773 grow = rcvwin * (copied - tp->rcvq_space.space); in tcp_rcv_space_adjust()
774 do_div(grow, tp->rcvq_space.space); in tcp_rcv_space_adjust()
778 READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_rmem[2])); in tcp_rcv_space_adjust()
779 if (rcvbuf > sk->sk_rcvbuf) { in tcp_rcv_space_adjust()
780 WRITE_ONCE(sk->sk_rcvbuf, rcvbuf); in tcp_rcv_space_adjust()
783 WRITE_ONCE(tp->window_clamp, in tcp_rcv_space_adjust()
787 tp->rcvq_space.space = copied; in tcp_rcv_space_adjust()
790 tp->rcvq_space.seq = tp->copied_seq; in tcp_rcv_space_adjust()
791 tp->rcvq_space.time = tp->tcp_mstamp; in tcp_rcv_space_adjust()
799 if (skb->protocol == htons(ETH_P_IPV6)) in tcp_save_lrcv_flowlabel()
800 icsk->icsk_ack.lrcv_flowlabel = ntohl(ip6_flowlabel(ipv6_hdr(skb))); in tcp_save_lrcv_flowlabel()
805 * behavior of the tp->ato delayed ack timeout interval. When a
812 * queue. -DaveM
828 if (!icsk->icsk_ack.ato) { in tcp_event_data_recv()
833 icsk->icsk_ack.ato = TCP_ATO_MIN; in tcp_event_data_recv()
835 int m = now - icsk->icsk_ack.lrcvtime; in tcp_event_data_recv()
839 icsk->icsk_ack.ato = (icsk->icsk_ack.ato >> 1) + TCP_ATO_MIN / 2; in tcp_event_data_recv()
840 } else if (m < icsk->icsk_ack.ato) { in tcp_event_data_recv()
841 icsk->icsk_ack.ato = (icsk->icsk_ack.ato >> 1) + m; in tcp_event_data_recv()
842 if (icsk->icsk_ack.ato > icsk->icsk_rto) in tcp_event_data_recv()
843 icsk->icsk_ack.ato = icsk->icsk_rto; in tcp_event_data_recv()
844 } else if (m > icsk->icsk_rto) { in tcp_event_data_recv()
851 icsk->icsk_ack.lrcvtime = now; in tcp_event_data_recv()
856 if (skb->len >= 128) in tcp_event_data_recv()
867 * it up into three procedures. -- erics
873 u32 srtt = tp->srtt_us; in tcp_rtt_estimator()
881 * On a 1990 paper the rto value is changed to: in tcp_rtt_estimator()
887 * etc. I guess in BSD RTO takes ONE value, so that it is absolutely in tcp_rtt_estimator()
892 m -= (srtt >> 3); /* m is now error in rtt est */ in tcp_rtt_estimator()
895 m = -m; /* m is now abs(error) */ in tcp_rtt_estimator()
896 m -= (tp->mdev_us >> 2); /* similar update on mdev */ in tcp_rtt_estimator()
908 m -= (tp->mdev_us >> 2); /* similar update on mdev */ in tcp_rtt_estimator()
910 tp->mdev_us += m; /* mdev = 3/4 mdev + 1/4 new */ in tcp_rtt_estimator()
911 if (tp->mdev_us > tp->mdev_max_us) { in tcp_rtt_estimator()
912 tp->mdev_max_us = tp->mdev_us; in tcp_rtt_estimator()
913 if (tp->mdev_max_us > tp->rttvar_us) in tcp_rtt_estimator()
914 tp->rttvar_us = tp->mdev_max_us; in tcp_rtt_estimator()
916 if (after(tp->snd_una, tp->rtt_seq)) { in tcp_rtt_estimator()
917 if (tp->mdev_max_us < tp->rttvar_us) in tcp_rtt_estimator()
918 tp->rttvar_us -= (tp->rttvar_us - tp->mdev_max_us) >> 2; in tcp_rtt_estimator()
919 tp->rtt_seq = tp->snd_nxt; in tcp_rtt_estimator()
920 tp->mdev_max_us = tcp_rto_min_us(sk); in tcp_rtt_estimator()
927 tp->mdev_us = m << 1; /* make sure rto = 3*rtt */ in tcp_rtt_estimator()
928 tp->rttvar_us = max(tp->mdev_us, tcp_rto_min_us(sk)); in tcp_rtt_estimator()
929 tp->mdev_max_us = tp->rttvar_us; in tcp_rtt_estimator()
930 tp->rtt_seq = tp->snd_nxt; in tcp_rtt_estimator()
934 tp->srtt_us = max(1U, srtt); in tcp_rtt_estimator()
943 rate = (u64)tp->mss_cache * ((USEC_PER_SEC / 100) << 3); in tcp_update_pacing_rate()
949 * [1] : Normal Slow Start condition is (tp->snd_cwnd < tp->snd_ssthresh) in tcp_update_pacing_rate()
950 * If snd_cwnd >= (tp->snd_ssthresh / 2), we are approaching in tcp_update_pacing_rate()
953 if (tcp_snd_cwnd(tp) < tp->snd_ssthresh / 2) in tcp_update_pacing_rate()
954 rate *= READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_pacing_ss_ratio); in tcp_update_pacing_rate()
956 rate *= READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_pacing_ca_ratio); in tcp_update_pacing_rate()
958 rate *= max(tcp_snd_cwnd(tp), tp->packets_out); in tcp_update_pacing_rate()
960 if (likely(tp->srtt_us)) in tcp_update_pacing_rate()
961 do_div(rate, tp->srtt_us); in tcp_update_pacing_rate()
967 WRITE_ONCE(sk->sk_pacing_rate, in tcp_update_pacing_rate()
968 min_t(u64, rate, READ_ONCE(sk->sk_max_pacing_rate))); in tcp_update_pacing_rate()
984 * is invisible. Actually, Linux-2.4 also generates erratic in tcp_set_rto()
987 inet_csk(sk)->icsk_rto = __tcp_set_rto(tp); in tcp_set_rto()
1007 return min_t(__u32, cwnd, tp->snd_cwnd_clamp); in tcp_init_cwnd()
1011 /* Timestamps for earliest and latest never-retransmitted segment
1024 /* Take a notice that peer is sending D-SACKs. Skip update of data delivery
1027 * - DSACKed sequence range is larger than maximum receiver's window.
1028 * - Total no. of DSACKed segments exceed the total no. of retransmitted segs.
1038 seq_len = end_seq - start_seq; in tcp_dsack_seen()
1040 if (seq_len > tp->max_window) in tcp_dsack_seen()
1042 if (seq_len > tp->mss_cache) in tcp_dsack_seen()
1043 dup_segs = DIV_ROUND_UP(seq_len, tp->mss_cache); in tcp_dsack_seen()
1044 else if (tp->tlp_high_seq && tp->tlp_high_seq == end_seq) in tcp_dsack_seen()
1045 state->flag |= FLAG_DSACK_TLP; in tcp_dsack_seen()
1047 tp->dsack_dups += dup_segs; in tcp_dsack_seen()
1049 if (tp->dsack_dups > tp->total_retrans) in tcp_dsack_seen()
1052 tp->rx_opt.sack_ok |= TCP_DSACK_SEEN; in tcp_dsack_seen()
1057 * is timer-driven, not triggered by RACK). in tcp_dsack_seen()
1059 if (tp->reord_seen && !(state->flag & FLAG_DSACK_TLP)) in tcp_dsack_seen()
1060 tp->rack.dsack_seen = 1; in tcp_dsack_seen()
1062 state->flag |= FLAG_DSACKING_ACK; in tcp_dsack_seen()
1064 state->sack_delivered += dup_segs; in tcp_dsack_seen()
1070 * some lower never-retransmitted sequence ("low_seq"). The maximum reordering
1071 * distance is approximated in full-mss packet distance ("reordering").
1077 const u32 mss = tp->mss_cache; in tcp_check_sack_reordering()
1084 metric = fack - low_seq; in tcp_check_sack_reordering()
1085 if ((metric > tp->reordering * mss) && mss) { in tcp_check_sack_reordering()
1088 tp->rx_opt.sack_ok, inet_csk(sk)->icsk_ca_state, in tcp_check_sack_reordering()
1089 tp->reordering, in tcp_check_sack_reordering()
1091 tp->sacked_out, in tcp_check_sack_reordering()
1092 tp->undo_marker ? tp->undo_retrans : 0); in tcp_check_sack_reordering()
1094 tp->reordering = min_t(u32, (metric + mss - 1) / mss, in tcp_check_sack_reordering()
1095 READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_max_reordering)); in tcp_check_sack_reordering()
1099 tp->reord_seen++; in tcp_check_sack_reordering()
1111 if ((!tp->retransmit_skb_hint && tp->retrans_out >= tp->lost_out) || in tcp_verify_retransmit_hint()
1112 (tp->retransmit_skb_hint && in tcp_verify_retransmit_hint()
1113 before(TCP_SKB_CB(skb)->seq, in tcp_verify_retransmit_hint()
1114 TCP_SKB_CB(tp->retransmit_skb_hint)->seq))) in tcp_verify_retransmit_hint()
1115 tp->retransmit_skb_hint = skb; in tcp_verify_retransmit_hint()
1123 tp->lost += tcp_skb_pcount(skb); in tcp_notify_skb_loss_event()
1128 __u8 sacked = TCP_SKB_CB(skb)->sacked; in tcp_mark_skb_lost()
1138 TCP_SKB_CB(skb)->sacked &= ~TCPCB_SACKED_RETRANS; in tcp_mark_skb_lost()
1139 tp->retrans_out -= tcp_skb_pcount(skb); in tcp_mark_skb_lost()
1145 tp->lost_out += tcp_skb_pcount(skb); in tcp_mark_skb_lost()
1146 TCP_SKB_CB(skb)->sacked |= TCPCB_LOST; in tcp_mark_skb_lost()
1155 tp->delivered += delivered; in tcp_count_delivered()
1157 tp->delivered_ce += delivered; in tcp_count_delivered()
1168 * 0 1 - orig segment is in flight.
1169 * S 0 - nothing flies, orig reached receiver.
1170 * L 0 - nothing flies, orig lost by net.
1171 * R 2 - both orig and retransmit are in flight.
1172 * L|R 1 - orig is lost, retransmit is in flight.
1173 * S|R 1 - orig reached receiver, retrans is still in flight.
1175 * but it is equivalent to plain S and code short-circuits it to S.
1176 * L|S is logically invalid, it would mean -1 packet in flight 8))
1186 * 4. D-SACK added new rule: D-SACK changes any tag to S.
1193 * --------------------
1198 * ever retransmitted -> reordering. Alas, we cannot use it
1200 * 2. The last flaw is solved with D-SACK. D-SACK arrives
1201 * for retransmitted and already SACKed segment -> reordering..
1206 * ----------------------
1221 * Implements also blockage to start_seq wrap-around. Problem lies in the
1227 * <- outs wnd -> <- wrapzone ->
1230 * |<------------+------+----- TCP seqno space --------------+---------->|
1231 * ...-- <2^31 ->| |<--------...
1232 * ...---- >2^31 ------>| |<--------...
1237 * snd_nxt wrap -> snd_una region will then become "well defined", i.e.,
1238 * equal to the ideal case (infinite seqno space without wrap caused issues).
1240 * With D-SACK the lower bound is extended to cover sequence space below
1242 * again, D-SACK block must not to go across snd_una (for the same reason as
1244 * ends, TCP might receive valid D-SACKs below that. As long as they reside
1247 * theoretical ones), the D-SACK will nicely cross that boundary due to skb
1250 * the exact amount is rather hard to quantify. However, tp->max_window can
1257 if (after(end_seq, tp->snd_nxt) || !before(start_seq, end_seq)) in tcp_is_sackblock_valid()
1260 /* Nasty start_seq wrap-around check (see comments above) */ in tcp_is_sackblock_valid()
1261 if (!before(start_seq, tp->snd_nxt)) in tcp_is_sackblock_valid()
1264 /* In outstanding window? ...This is valid exit for D-SACKs too. in tcp_is_sackblock_valid()
1265 * start_seq == snd_una is non-sensical (see comments above) in tcp_is_sackblock_valid()
1267 if (after(start_seq, tp->snd_una)) in tcp_is_sackblock_valid()
1270 if (!is_dsack || !tp->undo_marker) in tcp_is_sackblock_valid()
1273 /* ...Then it's D-SACK, and must reside below snd_una completely */ in tcp_is_sackblock_valid()
1274 if (after(end_seq, tp->snd_una)) in tcp_is_sackblock_valid()
1277 if (!before(start_seq, tp->undo_marker)) in tcp_is_sackblock_valid()
1281 if (!after(end_seq, tp->undo_marker)) in tcp_is_sackblock_valid()
1287 return !before(start_seq, end_seq - tp->max_window); in tcp_is_sackblock_valid()
1299 if (before(start_seq_0, TCP_SKB_CB(ack_skb)->ack_seq)) { in tcp_check_dsack()
1320 /* D-SACK for already forgotten data... Do dumb counting. */ in tcp_check_dsack()
1321 if (tp->undo_marker && tp->undo_retrans > 0 && in tcp_check_dsack()
1323 after(end_seq_0, tp->undo_marker)) in tcp_check_dsack()
1324 tp->undo_retrans = max_t(int, 0, tp->undo_retrans - dup_segs); in tcp_check_dsack()
1345 in_sack = !after(start_seq, TCP_SKB_CB(skb)->seq) && in tcp_match_skb_to_sack()
1346 !before(end_seq, TCP_SKB_CB(skb)->end_seq); in tcp_match_skb_to_sack()
1349 after(TCP_SKB_CB(skb)->end_seq, start_seq)) { in tcp_match_skb_to_sack()
1351 in_sack = !after(start_seq, TCP_SKB_CB(skb)->seq); in tcp_match_skb_to_sack()
1354 pkt_len = start_seq - TCP_SKB_CB(skb)->seq; in tcp_match_skb_to_sack()
1358 pkt_len = end_seq - TCP_SKB_CB(skb)->seq; in tcp_match_skb_to_sack()
1360 return -EINVAL; in tcp_match_skb_to_sack()
1373 if (pkt_len >= skb->len && !in_sack) in tcp_match_skb_to_sack()
1385 /* Mark the given newly-SACKed range as such, adjusting counters and hints. */
1394 /* Account D-SACK for retransmitted packet. */ in tcp_sacktag_one()
1396 if (tp->undo_marker && tp->undo_retrans > 0 && in tcp_sacktag_one()
1397 after(end_seq, tp->undo_marker)) in tcp_sacktag_one()
1398 tp->undo_retrans = max_t(int, 0, tp->undo_retrans - pcount); in tcp_sacktag_one()
1400 before(start_seq, state->reord)) in tcp_sacktag_one()
1401 state->reord = start_seq; in tcp_sacktag_one()
1405 if (!after(end_seq, tp->snd_una)) in tcp_sacktag_one()
1418 tp->lost_out -= pcount; in tcp_sacktag_one()
1419 tp->retrans_out -= pcount; in tcp_sacktag_one()
1428 before(start_seq, state->reord)) in tcp_sacktag_one()
1429 state->reord = start_seq; in tcp_sacktag_one()
1431 if (!after(end_seq, tp->high_seq)) in tcp_sacktag_one()
1432 state->flag |= FLAG_ORIG_SACK_ACKED; in tcp_sacktag_one()
1433 if (state->first_sackt == 0) in tcp_sacktag_one()
1434 state->first_sackt = xmit_time; in tcp_sacktag_one()
1435 state->last_sackt = xmit_time; in tcp_sacktag_one()
1440 tp->lost_out -= pcount; in tcp_sacktag_one()
1445 state->flag |= FLAG_DATA_SACKED; in tcp_sacktag_one()
1446 tp->sacked_out += pcount; in tcp_sacktag_one()
1447 /* Out-of-order packets delivered */ in tcp_sacktag_one()
1448 state->sack_delivered += pcount; in tcp_sacktag_one()
1451 if (tp->lost_skb_hint && in tcp_sacktag_one()
1452 before(start_seq, TCP_SKB_CB(tp->lost_skb_hint)->seq)) in tcp_sacktag_one()
1453 tp->lost_cnt_hint += pcount; in tcp_sacktag_one()
1456 /* D-SACK. We can detect redundant retransmission in S|R and plain R in tcp_sacktag_one()
1462 tp->retrans_out -= pcount; in tcp_sacktag_one()
1468 /* Shift newly-SACKed bytes from this skb to the immediately previous
1469 * already-SACKed sk_buff. Mark the newly-SACKed bytes as such.
1478 u32 start_seq = TCP_SKB_CB(skb)->seq; /* start of newly-SACKed */ in tcp_shifted_skb()
1479 u32 end_seq = start_seq + shifted; /* end of newly-SACKed */ in tcp_shifted_skb()
1484 * range but discard the return value since prev is already in tcp_shifted_skb()
1489 tcp_sacktag_one(sk, state, TCP_SKB_CB(skb)->sacked, in tcp_shifted_skb()
1492 tcp_rate_skb_delivered(sk, skb, state->rate); in tcp_shifted_skb()
1494 if (skb == tp->lost_skb_hint) in tcp_shifted_skb()
1495 tp->lost_cnt_hint += pcount; in tcp_shifted_skb()
1497 TCP_SKB_CB(prev)->end_seq += shifted; in tcp_shifted_skb()
1498 TCP_SKB_CB(skb)->seq += shifted; in tcp_shifted_skb()
1502 tcp_skb_pcount_add(skb, -pcount); in tcp_shifted_skb()
1509 if (!TCP_SKB_CB(prev)->tcp_gso_size) in tcp_shifted_skb()
1510 TCP_SKB_CB(prev)->tcp_gso_size = mss; in tcp_shifted_skb()
1514 TCP_SKB_CB(skb)->tcp_gso_size = 0; in tcp_shifted_skb()
1517 TCP_SKB_CB(prev)->sacked |= (TCP_SKB_CB(skb)->sacked & TCPCB_EVER_RETRANS); in tcp_shifted_skb()
1519 if (skb->len > 0) { in tcp_shifted_skb()
1525 /* Whole SKB was eaten :-) */ in tcp_shifted_skb()
1527 if (skb == tp->retransmit_skb_hint) in tcp_shifted_skb()
1528 tp->retransmit_skb_hint = prev; in tcp_shifted_skb()
1529 if (skb == tp->lost_skb_hint) { in tcp_shifted_skb()
1530 tp->lost_skb_hint = prev; in tcp_shifted_skb()
1531 tp->lost_cnt_hint -= tcp_skb_pcount(prev); in tcp_shifted_skb()
1534 TCP_SKB_CB(prev)->tcp_flags |= TCP_SKB_CB(skb)->tcp_flags; in tcp_shifted_skb()
1535 TCP_SKB_CB(prev)->eor = TCP_SKB_CB(skb)->eor; in tcp_shifted_skb()
1536 if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) in tcp_shifted_skb()
1537 TCP_SKB_CB(prev)->end_seq++; in tcp_shifted_skb()
1543 if (unlikely(TCP_SKB_CB(prev)->tx.delivered_mstamp)) in tcp_shifted_skb()
1544 TCP_SKB_CB(prev)->tx.delivered_mstamp = 0; in tcp_shifted_skb()
1554 * something-or-zero which complicates things
1558 return tcp_skb_pcount(skb) == 1 ? skb->len : tcp_skb_mss(skb); in tcp_skb_seglen()
1571 * Since TCP_SKB_CB(skb)->tcp_gso_segs is 16 bits, we need in tcp_skb_shift()
1575 if (unlikely(to->len + shiftlen >= 65535 * TCP_MIN_GSO_SIZE)) in tcp_skb_shift()
1599 (TCP_SKB_CB(skb)->sacked & (TCPCB_LOST|TCPCB_SACKED_RETRANS)) == TCPCB_SACKED_RETRANS) in tcp_shift_skb_data()
1604 if (!after(TCP_SKB_CB(skb)->end_seq, tp->snd_una)) in tcp_shift_skb_data()
1612 if ((TCP_SKB_CB(prev)->sacked & TCPCB_TAGBITS) != TCPCB_SACKED_ACKED) in tcp_shift_skb_data()
1618 in_sack = !after(start_seq, TCP_SKB_CB(skb)->seq) && in tcp_shift_skb_data()
1619 !before(end_seq, TCP_SKB_CB(skb)->end_seq); in tcp_shift_skb_data()
1622 len = skb->len; in tcp_shift_skb_data()
1632 if (!after(TCP_SKB_CB(skb)->end_seq, start_seq)) in tcp_shift_skb_data()
1634 /* CHECKME: This is non-MSS split case only?, this will in tcp_shift_skb_data()
1641 in_sack = !after(start_seq, TCP_SKB_CB(skb)->seq); in tcp_shift_skb_data()
1644 * if (!after(TCP_SKB_CB(skb)->end_seq, end_seq)), in tcp_shift_skb_data()
1648 * previously. We could try merging non-SACKed ones in tcp_shift_skb_data()
1657 len = end_seq - TCP_SKB_CB(skb)->seq; in tcp_shift_skb_data()
1659 BUG_ON(len > skb->len); in tcp_shift_skb_data()
1683 /* tcp_sacktag_one() won't SACK-tag ranges below snd_una */ in tcp_shift_skb_data()
1684 if (!after(TCP_SKB_CB(skb)->seq + len, tp->snd_una)) in tcp_shift_skb_data()
1700 ((TCP_SKB_CB(skb)->sacked & TCPCB_TAGBITS) != TCPCB_SACKED_ACKED) || in tcp_shift_skb_data()
1706 len = skb->len; in tcp_shift_skb_data()
1736 /* queue is in-order => we can short-circuit the walk early */ in tcp_sacktag_walk()
1737 if (!before(TCP_SKB_CB(skb)->seq, end_seq)) in tcp_sacktag_walk()
1741 before(TCP_SKB_CB(skb)->seq, next_dup->end_seq)) { in tcp_sacktag_walk()
1743 next_dup->start_seq, in tcp_sacktag_walk()
1744 next_dup->end_seq); in tcp_sacktag_walk()
1774 TCP_SKB_CB(skb)->sacked = in tcp_sacktag_walk()
1777 TCP_SKB_CB(skb)->sacked, in tcp_sacktag_walk()
1778 TCP_SKB_CB(skb)->seq, in tcp_sacktag_walk()
1779 TCP_SKB_CB(skb)->end_seq, in tcp_sacktag_walk()
1783 tcp_rate_skb_delivered(sk, skb, state->rate); in tcp_sacktag_walk()
1784 if (TCP_SKB_CB(skb)->sacked & TCPCB_SACKED_ACKED) in tcp_sacktag_walk()
1785 list_del_init(&skb->tcp_tsorted_anchor); in tcp_sacktag_walk()
1787 if (!before(TCP_SKB_CB(skb)->seq, in tcp_sacktag_walk()
1797 struct rb_node *parent, **p = &sk->tcp_rtx_queue.rb_node; in tcp_sacktag_bsearch()
1803 if (before(seq, TCP_SKB_CB(skb)->seq)) { in tcp_sacktag_bsearch()
1804 p = &parent->rb_left; in tcp_sacktag_bsearch()
1807 if (!before(seq, TCP_SKB_CB(skb)->end_seq)) { in tcp_sacktag_bsearch()
1808 p = &parent->rb_right; in tcp_sacktag_bsearch()
1819 if (skb && after(TCP_SKB_CB(skb)->seq, skip_to_seq)) in tcp_sacktag_skip()
1834 if (before(next_dup->start_seq, skip_to_seq)) { in tcp_maybe_skipping_dsack()
1835 skb = tcp_sacktag_skip(skb, sk, next_dup->start_seq); in tcp_maybe_skipping_dsack()
1837 next_dup->start_seq, next_dup->end_seq, in tcp_maybe_skipping_dsack()
1846 return cache < tp->recv_sack_cache + ARRAY_SIZE(tp->recv_sack_cache); in tcp_sack_cache_ok()
1855 TCP_SKB_CB(ack_skb)->sacked); in tcp_sacktag_write_queue()
1860 int num_sacks = min(TCP_NUM_SACKS, (ptr[1] - TCPOLEN_SACK_BASE) >> 3); in tcp_sacktag_write_queue()
1866 state->flag = 0; in tcp_sacktag_write_queue()
1867 state->reord = tp->snd_nxt; in tcp_sacktag_write_queue()
1869 if (!tp->sacked_out) in tcp_sacktag_write_queue()
1879 if (before(TCP_SKB_CB(ack_skb)->ack_seq, prior_snd_una - tp->max_window)) in tcp_sacktag_write_queue()
1882 if (!tp->packets_out) in tcp_sacktag_write_queue()
1899 if (!tp->undo_marker) in tcp_sacktag_write_queue()
1905 if ((TCP_SKB_CB(ack_skb)->ack_seq != tp->snd_una) && in tcp_sacktag_write_queue()
1906 !after(sp[used_sacks].end_seq, tp->snd_una)) in tcp_sacktag_write_queue()
1913 first_sack_index = -1; in tcp_sacktag_write_queue()
1920 first_sack_index = -1; in tcp_sacktag_write_queue()
1928 for (i = used_sacks - 1; i > 0; i--) { in tcp_sacktag_write_queue()
1940 state->mss_now = tcp_current_mss(sk); in tcp_sacktag_write_queue()
1944 if (!tp->sacked_out) { in tcp_sacktag_write_queue()
1946 cache = tp->recv_sack_cache + ARRAY_SIZE(tp->recv_sack_cache); in tcp_sacktag_write_queue()
1948 cache = tp->recv_sack_cache; in tcp_sacktag_write_queue()
1950 while (tcp_sack_cache_ok(tp, cache) && !cache->start_seq && in tcp_sacktag_write_queue()
1951 !cache->end_seq) in tcp_sacktag_write_queue()
1966 !before(start_seq, cache->end_seq)) in tcp_sacktag_write_queue()
1971 after(end_seq, cache->start_seq)) { in tcp_sacktag_write_queue()
1974 if (before(start_seq, cache->start_seq)) { in tcp_sacktag_write_queue()
1979 cache->start_seq, in tcp_sacktag_write_queue()
1984 if (!after(end_seq, cache->end_seq)) in tcp_sacktag_write_queue()
1989 cache->end_seq); in tcp_sacktag_write_queue()
1992 if (tcp_highest_sack_seq(tp) == cache->end_seq) { in tcp_sacktag_write_queue()
2001 skb = tcp_sacktag_skip(skb, sk, cache->end_seq); in tcp_sacktag_write_queue()
2023 for (i = 0; i < ARRAY_SIZE(tp->recv_sack_cache) - used_sacks; i++) { in tcp_sacktag_write_queue()
2024 tp->recv_sack_cache[i].start_seq = 0; in tcp_sacktag_write_queue()
2025 tp->recv_sack_cache[i].end_seq = 0; in tcp_sacktag_write_queue()
2028 tp->recv_sack_cache[i++] = sp[j]; in tcp_sacktag_write_queue()
2030 if (inet_csk(sk)->icsk_ca_state != TCP_CA_Loss || tp->undo_marker) in tcp_sacktag_write_queue()
2031 tcp_check_sack_reordering(sk, state->reord, 0); in tcp_sacktag_write_queue()
2037 WARN_ON((int)tp->sacked_out < 0); in tcp_sacktag_write_queue()
2038 WARN_ON((int)tp->lost_out < 0); in tcp_sacktag_write_queue()
2039 WARN_ON((int)tp->retrans_out < 0); in tcp_sacktag_write_queue()
2042 return state->flag; in tcp_sacktag_write_queue()
2052 holes = max(tp->lost_out, 1U); in tcp_limit_reno_sacked()
2053 holes = min(holes, tp->packets_out); in tcp_limit_reno_sacked()
2055 if ((tp->sacked_out + holes) > tp->packets_out) { in tcp_limit_reno_sacked()
2056 tp->sacked_out = tp->packets_out - holes; in tcp_limit_reno_sacked()
2073 tp->reordering = min_t(u32, tp->packets_out + addend, in tcp_check_reno_reordering()
2074 READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_max_reordering)); in tcp_check_reno_reordering()
2075 tp->reord_seen++; in tcp_check_reno_reordering()
2085 u32 prior_sacked = tp->sacked_out; in tcp_add_reno_sack()
2088 tp->sacked_out += num_dupack; in tcp_add_reno_sack()
2090 delivered = tp->sacked_out - prior_sacked; in tcp_add_reno_sack()
2105 tcp_count_delivered(tp, max_t(int, acked - tp->sacked_out, 1), in tcp_remove_reno_sacks()
2107 if (acked - 1 >= tp->sacked_out) in tcp_remove_reno_sacks()
2108 tp->sacked_out = 0; in tcp_remove_reno_sacks()
2110 tp->sacked_out -= acked - 1; in tcp_remove_reno_sacks()
2118 tp->sacked_out = 0; in tcp_reset_reno_sack()
2123 tp->retrans_out = 0; in tcp_clear_retrans()
2124 tp->lost_out = 0; in tcp_clear_retrans()
2125 tp->undo_marker = 0; in tcp_clear_retrans()
2126 tp->undo_retrans = -1; in tcp_clear_retrans()
2127 tp->sacked_out = 0; in tcp_clear_retrans()
2128 tp->rto_stamp = 0; in tcp_clear_retrans()
2129 tp->total_rto = 0; in tcp_clear_retrans()
2130 tp->total_rto_recoveries = 0; in tcp_clear_retrans()
2131 tp->total_rto_time = 0; in tcp_clear_retrans()
2136 tp->undo_marker = tp->snd_una; in tcp_init_undo()
2140 tp->undo_retrans = tp->retrans_out; in tcp_init_undo()
2142 if (tp->tlp_high_seq && tp->tlp_retrans) in tcp_init_undo()
2143 tp->undo_retrans++; in tcp_init_undo()
2145 if (!tp->undo_retrans) in tcp_init_undo()
2146 tp->undo_retrans = -1; in tcp_init_undo()
2151 return READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_recovery) & in tcp_is_rack()
2166 is_reneg = head && (TCP_SKB_CB(head)->sacked & TCPCB_SACKED_ACKED); in tcp_timeout_mark_lost()
2169 tp->sacked_out = 0; in tcp_timeout_mark_lost()
2171 tp->is_sack_reneg = 1; in tcp_timeout_mark_lost()
2179 TCP_SKB_CB(skb)->sacked &= ~TCPCB_SACKED_ACKED; in tcp_timeout_mark_lost()
2195 bool new_recovery = icsk->icsk_ca_state < TCP_CA_Recovery; in tcp_enter_loss()
2201 if (icsk->icsk_ca_state <= TCP_CA_Disorder || in tcp_enter_loss()
2202 !after(tp->high_seq, tp->snd_una) || in tcp_enter_loss()
2203 (icsk->icsk_ca_state == TCP_CA_Loss && !icsk->icsk_retransmits)) { in tcp_enter_loss()
2204 tp->prior_ssthresh = tcp_current_ssthresh(sk); in tcp_enter_loss()
2205 tp->prior_cwnd = tcp_snd_cwnd(tp); in tcp_enter_loss()
2206 tp->snd_ssthresh = icsk->icsk_ca_ops->ssthresh(sk); in tcp_enter_loss()
2211 tp->snd_cwnd_cnt = 0; in tcp_enter_loss()
2212 tp->snd_cwnd_stamp = tcp_jiffies32; in tcp_enter_loss()
2215 * suggests that the degree of reordering is over-estimated. in tcp_enter_loss()
2217 reordering = READ_ONCE(net->ipv4.sysctl_tcp_reordering); in tcp_enter_loss()
2218 if (icsk->icsk_ca_state <= TCP_CA_Disorder && in tcp_enter_loss()
2219 tp->sacked_out >= reordering) in tcp_enter_loss()
2220 tp->reordering = min_t(unsigned int, tp->reordering, in tcp_enter_loss()
2224 tp->high_seq = tp->snd_nxt; in tcp_enter_loss()
2225 tp->tlp_high_seq = 0; in tcp_enter_loss()
2228 /* F-RTO RFC5682 sec 3.1 step 1: retransmit SND.UNA if no previous in tcp_enter_loss()
2230 * the same SND.UNA (sec 3.2). Disable F-RTO on path MTU probing in tcp_enter_loss()
2232 tp->frto = READ_ONCE(net->ipv4.sysctl_tcp_frto) && in tcp_enter_loss()
2233 (new_recovery || icsk->icsk_retransmits) && in tcp_enter_loss()
2234 !inet_csk(sk)->icsk_mtup.probe_size; in tcp_enter_loss()
2252 unsigned long delay = max(usecs_to_jiffies(tp->srtt_us >> 4), in tcp_check_sack_reneging()
2270 * but when e.g. out-of-window ACKs or packet duplication occurs,
2276 return tp->sacked_out + 1; in tcp_dupack_heuristics()
2280 * --------------------------------------
2289 * "Recovery" CWND was reduced, we are fast-retransmitting.
2293 * - each incoming ACK, if state is not "Open"
2294 * - when arrived ACK is unusual, namely:
2301 * in_flight = packets_out - left_out + retrans_out
2303 * packets_out is SND.NXT-SND.UNA counted in packets.
2337 * RACK (draft-ietf-tcpm-rack-01): it is a newer algorithm
2338 * (2017-) that checks timing instead of counting DUPACKs.
2364 * timestamps and D-SACKs. When we detect that some segments were
2381 if (tp->lost_out) in tcp_time_to_recover()
2384 /* Not-A-Trick#2 : Classic rule... */ in tcp_time_to_recover()
2385 if (!tcp_is_rack(sk) && tcp_dupack_heuristics(tp) > tp->reordering) in tcp_time_to_recover()
2393 * has at least tp->reordering SACKed seqments above it; "packets" refers to
2402 const u32 loss_high = tp->snd_nxt; in tcp_mark_head_lost()
2404 WARN_ON(packets > tp->packets_out); in tcp_mark_head_lost()
2405 skb = tp->lost_skb_hint; in tcp_mark_head_lost()
2408 if (mark_head && after(TCP_SKB_CB(skb)->seq, tp->snd_una)) in tcp_mark_head_lost()
2410 cnt = tp->lost_cnt_hint; in tcp_mark_head_lost()
2419 tp->lost_skb_hint = skb; in tcp_mark_head_lost()
2420 tp->lost_cnt_hint = cnt; in tcp_mark_head_lost()
2422 if (after(TCP_SKB_CB(skb)->end_seq, loss_high)) in tcp_mark_head_lost()
2425 if (TCP_SKB_CB(skb)->sacked & TCPCB_SACKED_ACKED) in tcp_mark_head_lost()
2431 if (!(TCP_SKB_CB(skb)->sacked & TCPCB_LOST)) in tcp_mark_head_lost()
2447 int sacked_upto = tp->sacked_out - tp->reordering; in tcp_update_scoreboard()
2457 return tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr && in tcp_tsopt_ecr_before()
2458 before(tp->rx_opt.rcv_tsecr, when); in tcp_tsopt_ecr_before()
2467 return (TCP_SKB_CB(skb)->sacked & TCPCB_RETRANS) && in tcp_skb_spurious_retrans()
2468 tcp_tsopt_ecr_before(tp, tcp_skb_timestamp_ts(tp->tcp_usec_ts, skb)); in tcp_skb_spurious_retrans()
2478 if (tp->retrans_stamp && in tcp_packet_delayed()
2479 tcp_tsopt_ecr_before(tp, tp->retrans_stamp)) in tcp_packet_delayed()
2487 if (!tp->retrans_stamp && /* no record of a retransmit/SYN? */ in tcp_packet_delayed()
2488 sk->sk_state != TCP_SYN_SENT) /* not the FLAG_SYN_ACKED case? */ in tcp_packet_delayed()
2498 * tp->retrans_out, however, that kind of assumptions doesn't consider
2515 if (tp->retrans_out) in tcp_any_retrans_done()
2519 if (unlikely(skb && TCP_SKB_CB(skb)->sacked & TCPCB_EVER_RETRANS)) in tcp_any_retrans_done()
2527 * retransmits_timed_out() and timestamp-undo are using the correct value.
2532 tcp_sk(sk)->retrans_stamp = 0; in tcp_retrans_stamp_cleanup()
2541 if (sk->sk_family == AF_INET) { in DBGUNDO()
2544 &inet->inet_daddr, ntohs(inet->inet_dport), in DBGUNDO()
2546 tp->snd_ssthresh, tp->prior_ssthresh, in DBGUNDO()
2547 tp->packets_out); in DBGUNDO()
2550 else if (sk->sk_family == AF_INET6) { in DBGUNDO()
2553 &sk->sk_v6_daddr, ntohs(inet->inet_dport), in DBGUNDO()
2555 tp->snd_ssthresh, tp->prior_ssthresh, in DBGUNDO()
2556 tp->packets_out); in DBGUNDO()
2569 skb_rbtree_walk(skb, &sk->tcp_rtx_queue) { in tcp_undo_cwnd_reduction()
2570 TCP_SKB_CB(skb)->sacked &= ~TCPCB_LOST; in tcp_undo_cwnd_reduction()
2572 tp->lost_out = 0; in tcp_undo_cwnd_reduction()
2576 if (tp->prior_ssthresh) { in tcp_undo_cwnd_reduction()
2579 tcp_snd_cwnd_set(tp, icsk->icsk_ca_ops->undo_cwnd(sk)); in tcp_undo_cwnd_reduction()
2581 if (tp->prior_ssthresh > tp->snd_ssthresh) { in tcp_undo_cwnd_reduction()
2582 tp->snd_ssthresh = tp->prior_ssthresh; in tcp_undo_cwnd_reduction()
2586 tp->snd_cwnd_stamp = tcp_jiffies32; in tcp_undo_cwnd_reduction()
2587 tp->undo_marker = 0; in tcp_undo_cwnd_reduction()
2588 tp->rack.advanced = 1; /* Force RACK to re-exam losses */ in tcp_undo_cwnd_reduction()
2593 return tp->undo_marker && (!tp->undo_retrans || tcp_packet_delayed(tp)); in tcp_may_undo()
2600 if (tp->snd_una == tp->high_seq && tcp_is_reno(tp)) { in tcp_is_non_sack_preventing_reopen()
2605 tp->retrans_stamp = 0; in tcp_is_non_sack_preventing_reopen()
2622 DBGUNDO(sk, inet_csk(sk)->icsk_ca_state == TCP_CA_Loss ? "loss" : "retrans"); in tcp_try_undo_recovery()
2624 if (inet_csk(sk)->icsk_ca_state == TCP_CA_Loss) in tcp_try_undo_recovery()
2630 } else if (tp->rack.reo_wnd_persist) { in tcp_try_undo_recovery()
2631 tp->rack.reo_wnd_persist--; in tcp_try_undo_recovery()
2636 tp->is_sack_reneg = 0; in tcp_try_undo_recovery()
2640 /* Try to undo cwnd reduction, because D-SACKs acked all retransmitted data */
2645 if (tp->undo_marker && !tp->undo_retrans) { in tcp_try_undo_dsack()
2646 tp->rack.reo_wnd_persist = min(TCP_RACK_RECOVERY_THRESH, in tcp_try_undo_dsack()
2647 tp->rack.reo_wnd_persist + 1); in tcp_try_undo_dsack()
2648 DBGUNDO(sk, "D-SACK"); in tcp_try_undo_dsack()
2656 /* Undo during loss recovery after partial ACK or using F-RTO. */
2669 inet_csk(sk)->icsk_retransmits = 0; in tcp_try_undo_loss()
2674 tp->is_sack_reneg = 0; in tcp_try_undo_loss()
2694 tp->high_seq = tp->snd_nxt; in tcp_init_cwnd_reduction()
2695 tp->tlp_high_seq = 0; in tcp_init_cwnd_reduction()
2696 tp->snd_cwnd_cnt = 0; in tcp_init_cwnd_reduction()
2697 tp->prior_cwnd = tcp_snd_cwnd(tp); in tcp_init_cwnd_reduction()
2698 tp->prr_delivered = 0; in tcp_init_cwnd_reduction()
2699 tp->prr_out = 0; in tcp_init_cwnd_reduction()
2700 tp->snd_ssthresh = inet_csk(sk)->icsk_ca_ops->ssthresh(sk); in tcp_init_cwnd_reduction()
2708 int delta = tp->snd_ssthresh - tcp_packets_in_flight(tp); in tcp_cwnd_reduction()
2710 if (newly_acked_sacked <= 0 || WARN_ON_ONCE(!tp->prior_cwnd)) in tcp_cwnd_reduction()
2713 tp->prr_delivered += newly_acked_sacked; in tcp_cwnd_reduction()
2715 u64 dividend = (u64)tp->snd_ssthresh * tp->prr_delivered + in tcp_cwnd_reduction()
2716 tp->prior_cwnd - 1; in tcp_cwnd_reduction()
2717 sndcnt = div_u64(dividend, tp->prior_cwnd) - tp->prr_out; in tcp_cwnd_reduction()
2719 sndcnt = max_t(int, tp->prr_delivered - tp->prr_out, in tcp_cwnd_reduction()
2726 sndcnt = max(sndcnt, (tp->prr_out ? 0 : 1)); in tcp_cwnd_reduction()
2734 if (inet_csk(sk)->icsk_ca_ops->cong_control) in tcp_end_cwnd_reduction()
2738 if (tp->snd_ssthresh < TCP_INFINITE_SSTHRESH && in tcp_end_cwnd_reduction()
2739 (inet_csk(sk)->icsk_ca_state == TCP_CA_CWR || tp->undo_marker)) { in tcp_end_cwnd_reduction()
2740 tcp_snd_cwnd_set(tp, tp->snd_ssthresh); in tcp_end_cwnd_reduction()
2741 tp->snd_cwnd_stamp = tcp_jiffies32; in tcp_end_cwnd_reduction()
2751 tp->prior_ssthresh = 0; in tcp_enter_cwr()
2752 if (inet_csk(sk)->icsk_ca_state < TCP_CA_CWR) { in tcp_enter_cwr()
2753 tp->undo_marker = 0; in tcp_enter_cwr()
2768 if (inet_csk(sk)->icsk_ca_state != state) { in tcp_try_keep_open()
2770 tp->high_seq = tp->snd_nxt; in tcp_try_keep_open()
2781 tp->retrans_stamp = 0; in tcp_try_to_open()
2786 if (inet_csk(sk)->icsk_ca_state != TCP_CA_CWR) { in tcp_try_to_open()
2795 icsk->icsk_mtup.search_high = icsk->icsk_mtup.probe_size - 1; in tcp_mtup_probe_failed()
2796 icsk->icsk_mtup.probe_size = 0; in tcp_mtup_probe_failed()
2806 tp->prior_ssthresh = tcp_current_ssthresh(sk); in tcp_mtup_probe_success()
2808 val = (u64)tcp_snd_cwnd(tp) * tcp_mss_to_mtu(sk, tp->mss_cache); in tcp_mtup_probe_success()
2809 do_div(val, icsk->icsk_mtup.probe_size); in tcp_mtup_probe_success()
2813 tp->snd_cwnd_cnt = 0; in tcp_mtup_probe_success()
2814 tp->snd_cwnd_stamp = tcp_jiffies32; in tcp_mtup_probe_success()
2815 tp->snd_ssthresh = tcp_current_ssthresh(sk); in tcp_mtup_probe_success()
2817 icsk->icsk_mtup.search_low = icsk->icsk_mtup.probe_size; in tcp_mtup_probe_success()
2818 icsk->icsk_mtup.probe_size = 0; in tcp_mtup_probe_success()
2819 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie); in tcp_mtup_probe_success()
2827 * non-zero value (and may do so in a later calling context due to TSQ), we
2838 if (icsk->icsk_ca_state != TCP_CA_Loss) { in tcp_non_congestion_loss_retransmit()
2839 tp->high_seq = tp->snd_nxt; in tcp_non_congestion_loss_retransmit()
2840 tp->snd_ssthresh = tcp_current_ssthresh(sk); in tcp_non_congestion_loss_retransmit()
2841 tp->prior_ssthresh = 0; in tcp_non_congestion_loss_retransmit()
2842 tp->undo_marker = 0; in tcp_non_congestion_loss_retransmit()
2866 * -1 to mark all frames as lost, otherwise compute the current MSS. in tcp_simple_retransmit()
2868 if (tp->syn_data && sk->sk_state == TCP_SYN_SENT) in tcp_simple_retransmit()
2869 mss = -1; in tcp_simple_retransmit()
2873 skb_rbtree_walk(skb, &sk->tcp_rtx_queue) { in tcp_simple_retransmit()
2880 if (!tp->lost_out) in tcp_simple_retransmit()
2912 tp->prior_ssthresh = 0; in tcp_enter_recovery()
2917 tp->prior_ssthresh = tcp_current_ssthresh(sk); in tcp_enter_recovery()
2925 if (tp->rto_stamp) { in tcp_update_rto_time()
2926 tp->total_rto_time += tcp_time_stamp_ms(tp) - tp->rto_stamp; in tcp_update_rto_time()
2927 tp->rto_stamp = 0; in tcp_update_rto_time()
2938 bool recovered = !before(tp->snd_una, tp->high_seq); in tcp_process_loss()
2940 if ((flag & FLAG_SND_UNA_ADVANCED || rcu_access_pointer(tp->fastopen_rsk)) && in tcp_process_loss()
2944 if (tp->frto) { /* F-RTO RFC5682 sec 3.1 (sack enhanced version). */ in tcp_process_loss()
2946 * lost, i.e., never-retransmitted data are (s)acked. in tcp_process_loss()
2952 if (after(tp->snd_nxt, tp->high_seq)) { in tcp_process_loss()
2954 tp->frto = 0; /* Step 3.a. loss was real */ in tcp_process_loss()
2956 tp->high_seq = tp->snd_nxt; in tcp_process_loss()
2962 after(tcp_wnd_end(tp), tp->snd_nxt)) { in tcp_process_loss()
2966 tp->frto = 0; in tcp_process_loss()
2971 /* F-RTO RFC5682 sec 3.1 step 2.a and 1st part of step 3.a */ in tcp_process_loss()
2976 /* A Reno DUPACK means new data in F-RTO step 2.b above are in tcp_process_loss()
2979 if (after(tp->snd_nxt, tp->high_seq) && num_dupack) in tcp_process_loss()
2992 tp->snd_una + tp->reordering * tp->mss_cache); in tcp_force_fast_retransmit()
3001 if (tp->undo_marker && tcp_packet_delayed(tp)) { in tcp_try_undo_partial()
3012 if (tp->retrans_out) in tcp_try_undo_partial()
3016 tp->retrans_stamp = 0; in tcp_try_undo_partial()
3039 u32 prior_retrans = tp->retrans_out; in tcp_identify_packet_loss()
3043 if (prior_retrans > tp->retrans_out) in tcp_identify_packet_loss()
3048 /* Process an event, which can update packets-in-flight not trivially.
3070 if (!tp->packets_out && tp->sacked_out) in tcp_fastretrans_alert()
3071 tp->sacked_out = 0; in tcp_fastretrans_alert()
3076 tp->prior_ssthresh = 0; in tcp_fastretrans_alert()
3087 if (icsk->icsk_ca_state == TCP_CA_Open) { in tcp_fastretrans_alert()
3088 WARN_ON(tp->retrans_out != 0 && !tp->syn_data); in tcp_fastretrans_alert()
3089 tp->retrans_stamp = 0; in tcp_fastretrans_alert()
3090 } else if (!before(tp->snd_una, tp->high_seq)) { in tcp_fastretrans_alert()
3091 switch (icsk->icsk_ca_state) { in tcp_fastretrans_alert()
3095 if (tp->snd_una != tp->high_seq) { in tcp_fastretrans_alert()
3112 switch (icsk->icsk_ca_state) { in tcp_fastretrans_alert()
3124 if (icsk->icsk_ca_state != TCP_CA_Recovery) { in tcp_fastretrans_alert()
3135 if (icsk->icsk_ca_state != TCP_CA_Loss) in tcp_fastretrans_alert()
3138 if (!(icsk->icsk_ca_state == TCP_CA_Open || in tcp_fastretrans_alert()
3150 if (icsk->icsk_ca_state <= TCP_CA_Disorder) in tcp_fastretrans_alert()
3160 if (icsk->icsk_ca_state < TCP_CA_CWR && in tcp_fastretrans_alert()
3161 icsk->icsk_mtup.probe_size && in tcp_fastretrans_alert()
3162 tp->snd_una == tp->mtu_probe.probe_seq_start) { in tcp_fastretrans_alert()
3182 u32 wlen = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_min_rtt_wlen) * HZ; in tcp_update_rtt_min()
3192 minmax_running_min(&tp->rtt_min, wlen, tcp_jiffies32, in tcp_update_rtt_min()
3202 /* Prefer RTT measured from ACK's timing to TS-ECR. This is because in tcp_ack_update_rtt()
3203 * broken middle-boxes or peers may corrupt TS-ECR fields. But in tcp_ack_update_rtt()
3210 /* RTTM Rule: A TSecr value received in a segment is used to in tcp_ack_update_rtt()
3214 * See draft-ietf-tcplw-high-performance-00, section 3.3. in tcp_ack_update_rtt()
3216 if (seq_rtt_us < 0 && tp->rx_opt.saw_tstamp && in tcp_ack_update_rtt()
3217 tp->rx_opt.rcv_tsecr && flag & FLAG_ACKED) in tcp_ack_update_rtt()
3220 rs->rtt_us = ca_rtt_us; /* RTT of last (S)ACKed packet (or -1) */ in tcp_ack_update_rtt()
3225 * always taken together with ACK, SACK, or TS-opts. Any negative in tcp_ack_update_rtt()
3233 inet_csk(sk)->icsk_backoff = 0; in tcp_ack_update_rtt()
3241 long rtt_us = -1L; in tcp_synack_rtt_meas()
3243 if (req && !req->num_retrans && tcp_rsk(req)->snt_synack) in tcp_synack_rtt_meas()
3244 rtt_us = tcp_stamp_us_delta(tcp_clock_us(), tcp_rsk(req)->snt_synack); in tcp_synack_rtt_meas()
3246 tcp_ack_update_rtt(sk, FLAG_SYN_ACKED, rtt_us, -1L, rtt_us, &rs); in tcp_synack_rtt_meas()
3254 icsk->icsk_ca_ops->cong_avoid(sk, ack, acked); in tcp_cong_avoid()
3255 tcp_sk(sk)->snd_cwnd_stamp = tcp_jiffies32; in tcp_cong_avoid()
3267 * for SYN-ACK retrans purpose, stay put. in tcp_rearm_rto()
3269 if (rcu_access_pointer(tp->fastopen_rsk)) in tcp_rearm_rto()
3272 if (!tp->packets_out) { in tcp_rearm_rto()
3275 u32 rto = inet_csk(sk)->icsk_rto; in tcp_rearm_rto()
3277 if (icsk->icsk_pending == ICSK_TIME_REO_TIMEOUT || in tcp_rearm_rto()
3278 icsk->icsk_pending == ICSK_TIME_LOSS_PROBE) { in tcp_rearm_rto()
3303 BUG_ON(!after(TCP_SKB_CB(skb)->end_seq, tp->snd_una)); in tcp_tso_acked()
3306 if (tcp_trim_head(sk, skb, tp->snd_una - TCP_SKB_CB(skb)->seq)) in tcp_tso_acked()
3308 packets_acked -= tcp_skb_pcount(skb); in tcp_tso_acked()
3312 BUG_ON(!before(TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq)); in tcp_tso_acked()
3323 /* Avoid cache line misses to get skb_shinfo() and shinfo->tx_flags */ in tcp_ack_tstamp()
3324 if (likely(!TCP_SKB_CB(skb)->txstamp_ack)) in tcp_ack_tstamp()
3328 if (!before(shinfo->tskey, prior_snd_una) && in tcp_ack_tstamp()
3329 before(shinfo->tskey, tcp_sk(sk)->snd_una)) { in tcp_ack_tstamp()
3347 u32 prior_sacked = tp->sacked_out; in tcp_clean_rtx_queue()
3348 u32 reord = tp->snd_nxt; /* lowest acked un-retx un-sacked seq */ in tcp_clean_rtx_queue()
3351 long sack_rtt_us = -1L; in tcp_clean_rtx_queue()
3352 long seq_rtt_us = -1L; in tcp_clean_rtx_queue()
3353 long ca_rtt_us = -1L; in tcp_clean_rtx_queue()
3360 for (skb = skb_rb_first(&sk->tcp_rtx_queue); skb; skb = next) { in tcp_clean_rtx_queue()
3362 const u32 start_seq = scb->seq; in tcp_clean_rtx_queue()
3363 u8 sacked = scb->sacked; in tcp_clean_rtx_queue()
3367 if (after(scb->end_seq, tp->snd_una)) { in tcp_clean_rtx_queue()
3369 !after(tp->snd_una, scb->seq)) in tcp_clean_rtx_queue()
3382 tp->retrans_out -= acked_pcount; in tcp_clean_rtx_queue()
3392 if (!after(scb->end_seq, tp->high_seq)) in tcp_clean_rtx_queue()
3397 tp->sacked_out -= acked_pcount; in tcp_clean_rtx_queue()
3401 tcp_rack_advance(tp, sacked, scb->end_seq, in tcp_clean_rtx_queue()
3405 tp->lost_out -= acked_pcount; in tcp_clean_rtx_queue()
3407 tp->packets_out -= acked_pcount; in tcp_clean_rtx_queue()
3409 tcp_rate_skb_delivered(sk, skb, sack->rate); in tcp_clean_rtx_queue()
3418 if (likely(!(scb->tcp_flags & TCPHDR_SYN))) { in tcp_clean_rtx_queue()
3422 tp->retrans_stamp = 0; in tcp_clean_rtx_queue()
3431 if (unlikely(skb == tp->retransmit_skb_hint)) in tcp_clean_rtx_queue()
3432 tp->retransmit_skb_hint = NULL; in tcp_clean_rtx_queue()
3433 if (unlikely(skb == tp->lost_skb_hint)) in tcp_clean_rtx_queue()
3434 tp->lost_skb_hint = NULL; in tcp_clean_rtx_queue()
3442 if (likely(between(tp->snd_up, prior_snd_una, tp->snd_una))) in tcp_clean_rtx_queue()
3443 tp->snd_up = tp->snd_una; in tcp_clean_rtx_queue()
3447 if (TCP_SKB_CB(skb)->sacked & TCPCB_SACKED_ACKED) in tcp_clean_rtx_queue()
3452 seq_rtt_us = tcp_stamp_us_delta(tp->tcp_mstamp, first_ackt); in tcp_clean_rtx_queue()
3453 ca_rtt_us = tcp_stamp_us_delta(tp->tcp_mstamp, last_ackt); in tcp_clean_rtx_queue()
3456 (tp->snd_una - prior_snd_una) < tp->mss_cache && in tcp_clean_rtx_queue()
3457 sack->rate->prior_delivered + 1 == tp->delivered && in tcp_clean_rtx_queue()
3461 * a receiver w/o out-of-order or CE events. in tcp_clean_rtx_queue()
3466 if (sack->first_sackt) { in tcp_clean_rtx_queue()
3467 sack_rtt_us = tcp_stamp_us_delta(tp->tcp_mstamp, sack->first_sackt); in tcp_clean_rtx_queue()
3468 ca_rtt_us = tcp_stamp_us_delta(tp->tcp_mstamp, sack->last_sackt); in tcp_clean_rtx_queue()
3471 ca_rtt_us, sack->rate); in tcp_clean_rtx_queue()
3475 if (unlikely(icsk->icsk_mtup.probe_size && in tcp_clean_rtx_queue()
3476 !after(tp->mtu_probe.probe_seq_end, tp->snd_una))) { in tcp_clean_rtx_queue()
3484 * retransmitted, non-SACK case cannot confirm that in tcp_clean_rtx_queue()
3494 /* Non-retransmitted hole got filled? That's reordering */ in tcp_clean_rtx_queue()
3498 delta = prior_sacked - tp->sacked_out; in tcp_clean_rtx_queue()
3499 tp->lost_cnt_hint -= min(tp->lost_cnt_hint, delta); in tcp_clean_rtx_queue()
3502 sack_rtt_us > tcp_stamp_us_delta(tp->tcp_mstamp, in tcp_clean_rtx_queue()
3504 /* Do not re-arm RTO if the sack RTT is measured from data sent in tcp_clean_rtx_queue()
3511 if (icsk->icsk_ca_ops->pkts_acked) { in tcp_clean_rtx_queue()
3513 .rtt_us = sack->rate->rtt_us }; in tcp_clean_rtx_queue()
3515 sample.in_flight = tp->mss_cache * in tcp_clean_rtx_queue()
3516 (tp->delivered - sack->rate->prior_delivered); in tcp_clean_rtx_queue()
3517 icsk->icsk_ca_ops->pkts_acked(sk, &sample); in tcp_clean_rtx_queue()
3521 WARN_ON((int)tp->sacked_out < 0); in tcp_clean_rtx_queue()
3522 WARN_ON((int)tp->lost_out < 0); in tcp_clean_rtx_queue()
3523 WARN_ON((int)tp->retrans_out < 0); in tcp_clean_rtx_queue()
3524 if (!tp->packets_out && tcp_is_sack(tp)) { in tcp_clean_rtx_queue()
3526 if (tp->lost_out) { in tcp_clean_rtx_queue()
3528 tp->lost_out, icsk->icsk_ca_state); in tcp_clean_rtx_queue()
3529 tp->lost_out = 0; in tcp_clean_rtx_queue()
3531 if (tp->sacked_out) { in tcp_clean_rtx_queue()
3533 tp->sacked_out, icsk->icsk_ca_state); in tcp_clean_rtx_queue()
3534 tp->sacked_out = 0; in tcp_clean_rtx_queue()
3536 if (tp->retrans_out) { in tcp_clean_rtx_queue()
3538 tp->retrans_out, icsk->icsk_ca_state); in tcp_clean_rtx_queue()
3539 tp->retrans_out = 0; in tcp_clean_rtx_queue()
3555 if (!after(TCP_SKB_CB(head)->end_seq, tcp_wnd_end(tp))) { in tcp_ack_probe()
3556 icsk->icsk_backoff = 0; in tcp_ack_probe()
3557 icsk->icsk_probes_tstamp = 0; in tcp_ack_probe()
3573 inet_csk(sk)->icsk_ca_state != TCP_CA_Open; in tcp_ack_is_dubious()
3581 * and only grow cwnd on in-order delivery (RFC5681). A stretched ACK w/ in tcp_may_raise_cwnd()
3585 if (tcp_sk(sk)->reordering > in tcp_may_raise_cwnd()
3586 READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_reordering)) in tcp_may_raise_cwnd()
3602 if (icsk->icsk_ca_ops->cong_control) { in tcp_cong_control()
3603 icsk->icsk_ca_ops->cong_control(sk, ack, flag, rs); in tcp_cong_control()
3609 tcp_cwnd_reduction(sk, acked_sacked, rs->losses, flag); in tcp_cong_control()
3624 return after(ack, tp->snd_una) || in tcp_may_update_window()
3625 after(ack_seq, tp->snd_wl1) || in tcp_may_update_window()
3626 (ack_seq == tp->snd_wl1 && (nwin > tp->snd_wnd || !nwin)); in tcp_may_update_window()
3637 ao = rcu_dereference_protected(tp->ao_info, in tcp_snd_sne_update()
3639 if (ao && ack < tp->snd_una) { in tcp_snd_sne_update()
3640 ao->snd_sne++; in tcp_snd_sne_update()
3641 trace_tcp_ao_snd_sne_update((struct sock *)tp, ao->snd_sne); in tcp_snd_sne_update()
3646 /* If we update tp->snd_una, also update tp->bytes_acked */
3649 u32 delta = ack - tp->snd_una; in tcp_snd_una_update()
3652 tp->bytes_acked += delta; in tcp_snd_una_update()
3654 tp->snd_una = ack; in tcp_snd_una_update()
3665 ao = rcu_dereference_protected(tp->ao_info, in tcp_rcv_sne_update()
3667 if (ao && seq < tp->rcv_nxt) { in tcp_rcv_sne_update()
3668 ao->rcv_sne++; in tcp_rcv_sne_update()
3669 trace_tcp_ao_rcv_sne_update((struct sock *)tp, ao->rcv_sne); in tcp_rcv_sne_update()
3674 /* If we update tp->rcv_nxt, also update tp->bytes_received */
3677 u32 delta = seq - tp->rcv_nxt; in tcp_rcv_nxt_update()
3680 tp->bytes_received += delta; in tcp_rcv_nxt_update()
3682 WRITE_ONCE(tp->rcv_nxt, seq); in tcp_rcv_nxt_update()
3687 * Window update algorithm, described in RFC793/RFC1122 (used in linux-2.2
3695 u32 nwin = ntohs(tcp_hdr(skb)->window); in tcp_ack_update_window()
3697 if (likely(!tcp_hdr(skb)->syn)) in tcp_ack_update_window()
3698 nwin <<= tp->rx_opt.snd_wscale; in tcp_ack_update_window()
3704 if (tp->snd_wnd != nwin) { in tcp_ack_update_window()
3705 tp->snd_wnd = nwin; in tcp_ack_update_window()
3710 tp->pred_flags = 0; in tcp_ack_update_window()
3716 if (nwin > tp->max_window) { in tcp_ack_update_window()
3717 tp->max_window = nwin; in tcp_ack_update_window()
3718 tcp_sync_mss(sk, inet_csk(sk)->icsk_pmtu_cookie); in tcp_ack_update_window()
3735 s32 elapsed = (s32)(tcp_jiffies32 - val); in __tcp_oow_rate_limited()
3738 elapsed < READ_ONCE(net->ipv4.sysctl_tcp_invalid_ratelimit)) { in __tcp_oow_rate_limited()
3740 return true; /* rate-limited: don't send yet! */ in __tcp_oow_rate_limited()
3749 return false; /* not rate-limited: go ahead, send dupack now! */ in __tcp_oow_rate_limited()
3752 /* Return true if we're currently rate-limiting out-of-window ACKs and
3753 * thus shouldn't send a dupack right now. We rate-limit dupacks in
3754 * response to out-of-window SYNs or ACKs to mitigate ACK loops or DoS
3757 * endpoint is sending out-of-window SYNs or pure ACKs at a high rate.
3763 if ((TCP_SKB_CB(skb)->seq != TCP_SKB_CB(skb)->end_seq) && in tcp_oow_rate_limited()
3764 !tcp_hdr(skb)->syn) in tcp_oow_rate_limited()
3777 /* First check our per-socket dupack rate limit. */ in tcp_send_challenge_ack()
3780 &tp->last_oow_ack_time)) in tcp_send_challenge_ack()
3783 ack_limit = READ_ONCE(net->ipv4.sysctl_tcp_challenge_ack_limit); in tcp_send_challenge_ack()
3787 /* Then check host-wide RFC 5961 rate limit. */ in tcp_send_challenge_ack()
3789 if (now != READ_ONCE(net->ipv4.tcp_challenge_timestamp)) { in tcp_send_challenge_ack()
3792 WRITE_ONCE(net->ipv4.tcp_challenge_timestamp, now); in tcp_send_challenge_ack()
3793 WRITE_ONCE(net->ipv4.tcp_challenge_count, in tcp_send_challenge_ack()
3794 get_random_u32_inclusive(half, ack_limit + half - 1)); in tcp_send_challenge_ack()
3796 count = READ_ONCE(net->ipv4.tcp_challenge_count); in tcp_send_challenge_ack()
3798 WRITE_ONCE(net->ipv4.tcp_challenge_count, count - 1); in tcp_send_challenge_ack()
3807 tp->rx_opt.ts_recent = tp->rx_opt.rcv_tsval; in tcp_store_ts_recent()
3808 tp->rx_opt.ts_recent_stamp = ktime_get_seconds(); in tcp_store_ts_recent()
3813 if (tp->rx_opt.saw_tstamp && !after(seq, tp->rcv_wup)) { in tcp_replace_ts_recent()
3816 * for pure ACK frames. -DaveM in tcp_replace_ts_recent()
3821 if (tcp_paws_check(&tp->rx_opt, 0)) in tcp_replace_ts_recent()
3827 * resetting tlp_high_seq. Ref: TLP algorithm in draft-ietf-tcpm-rack
3833 if (before(ack, tp->tlp_high_seq)) in tcp_process_tlp_ack()
3836 if (!tp->tlp_retrans) { in tcp_process_tlp_ack()
3838 tp->tlp_high_seq = 0; in tcp_process_tlp_ack()
3841 tp->tlp_high_seq = 0; in tcp_process_tlp_ack()
3842 } else if (after(ack, tp->tlp_high_seq)) { in tcp_process_tlp_ack()
3855 tp->tlp_high_seq = 0; in tcp_process_tlp_ack()
3863 if (icsk->icsk_ca_ops->in_ack_event) in tcp_in_ack_event()
3864 icsk->icsk_ca_ops->in_ack_event(sk, flags); in tcp_in_ack_event()
3875 if (rexmit == REXMIT_NONE || sk->sk_state == TCP_SYN_SENT) in tcp_xmit_recovery()
3881 if (after(tp->snd_nxt, tp->high_seq)) in tcp_xmit_recovery()
3883 tp->frto = 0; in tcp_xmit_recovery()
3895 delivered = tp->delivered - prior_delivered; in tcp_newly_delivered()
3910 u32 prior_snd_una = tp->snd_una; in tcp_ack()
3911 bool is_sack_reneg = tp->is_sack_reneg; in tcp_ack()
3912 u32 ack_seq = TCP_SKB_CB(skb)->seq; in tcp_ack()
3913 u32 ack = TCP_SKB_CB(skb)->ack_seq; in tcp_ack()
3915 int prior_packets = tp->packets_out; in tcp_ack()
3916 u32 delivered = tp->delivered; in tcp_ack()
3917 u32 lost = tp->lost; in tcp_ack()
3926 prefetch(sk->tcp_rtx_queue.rb_node); in tcp_ack()
3935 max_window = min_t(u64, tp->max_window, tp->bytes_acked); in tcp_ack()
3937 if (before(ack, prior_snd_una - max_window)) { in tcp_ack()
3940 return -SKB_DROP_REASON_TCP_TOO_OLD_ACK; in tcp_ack()
3948 if (after(ack, tp->snd_nxt)) in tcp_ack()
3949 return -SKB_DROP_REASON_TCP_ACK_UNSENT_DATA; in tcp_ack()
3953 icsk->icsk_retransmits = 0; in tcp_ack()
3957 if (icsk->icsk_clean_acked) in tcp_ack()
3958 icsk->icsk_clean_acked(sk, ack); in tcp_ack()
3962 prior_fack = tcp_is_sack(tp) ? tcp_highest_sack_seq(tp) : tp->snd_una; in tcp_ack()
3969 tcp_replace_ts_recent(tp, TCP_SKB_CB(skb)->seq); in tcp_ack()
3987 if (ack_seq != TCP_SKB_CB(skb)->end_seq) in tcp_ack()
3994 if (TCP_SKB_CB(skb)->sacked) in tcp_ack()
4018 * with widely-deployed TCP implementations that do this. in tcp_ack()
4025 WRITE_ONCE(sk->sk_err_soft, 0); in tcp_ack()
4026 icsk->icsk_probes_out = 0; in tcp_ack()
4027 tp->rcv_tstamp = tcp_jiffies32; in tcp_ack()
4037 if (tp->tlp_high_seq) in tcp_ack()
4046 num_dupack = max_t(u16, 1, skb_shinfo(skb)->gso_segs); in tcp_ack()
4060 lost = tp->lost - lost; /* freshly marked lost */ in tcp_ack()
4080 if (tp->tlp_high_seq) in tcp_ack()
4088 if (TCP_SKB_CB(skb)->sacked) { in tcp_ack()
4104 /* Valid only in SYN or SYN-ACK with an even length. */ in tcp_parse_fastopen_option()
4110 memcpy(foc->val, cookie, len); in tcp_parse_fastopen_option()
4112 len = -1; in tcp_parse_fastopen_option()
4113 foc->len = len; in tcp_parse_fastopen_option()
4114 foc->exp = exp_opt; in tcp_parse_fastopen_option()
4124 if (th->syn && !(opsize & 1) && in smc_parse_options()
4127 opt_rx->smc_ok = 1; in smc_parse_options()
4136 * value on success.
4141 int length = (th->doff * 4) - sizeof(struct tcphdr); in tcp_parse_mss_option()
4152 length--; in tcp_parse_mss_option()
4171 ptr += opsize - 2; in tcp_parse_mss_option()
4172 length -= opsize; in tcp_parse_mss_option()
4190 int length = (th->doff * 4) - sizeof(struct tcphdr); in tcp_parse_options()
4193 opt_rx->saw_tstamp = 0; in tcp_parse_options()
4194 opt_rx->saw_unknown = 0; in tcp_parse_options()
4204 length--; in tcp_parse_options()
4216 if (opsize == TCPOLEN_MSS && th->syn && !estab) { in tcp_parse_options()
4219 if (opt_rx->user_mss && in tcp_parse_options()
4220 opt_rx->user_mss < in_mss) in tcp_parse_options()
4221 in_mss = opt_rx->user_mss; in tcp_parse_options()
4222 opt_rx->mss_clamp = in_mss; in tcp_parse_options()
4227 if (opsize == TCPOLEN_WINDOW && th->syn && in tcp_parse_options()
4228 !estab && READ_ONCE(net->ipv4.sysctl_tcp_window_scaling)) { in tcp_parse_options()
4230 opt_rx->wscale_ok = 1; in tcp_parse_options()
4232 net_info_ratelimited("%s: Illegal window scaling value %d > %u received\n", in tcp_parse_options()
4238 opt_rx->snd_wscale = snd_wscale; in tcp_parse_options()
4243 ((estab && opt_rx->tstamp_ok) || in tcp_parse_options()
4244 (!estab && READ_ONCE(net->ipv4.sysctl_tcp_timestamps)))) { in tcp_parse_options()
4245 opt_rx->saw_tstamp = 1; in tcp_parse_options()
4246 opt_rx->rcv_tsval = get_unaligned_be32(ptr); in tcp_parse_options()
4247 opt_rx->rcv_tsecr = get_unaligned_be32(ptr + 4); in tcp_parse_options()
4251 if (opsize == TCPOLEN_SACK_PERM && th->syn && in tcp_parse_options()
4252 !estab && READ_ONCE(net->ipv4.sysctl_tcp_sack)) { in tcp_parse_options()
4253 opt_rx->sack_ok = TCP_SACK_SEEN; in tcp_parse_options()
4260 !((opsize - TCPOLEN_SACK_BASE) % TCPOLEN_SACK_PERBLOCK) && in tcp_parse_options()
4261 opt_rx->sack_ok) { in tcp_parse_options()
4262 TCP_SKB_CB(skb)->sacked = (ptr - 2) - (unsigned char *)th; in tcp_parse_options()
4281 opsize - TCPOLEN_FASTOPEN_BASE, in tcp_parse_options()
4282 ptr, th->syn, foc, false); in tcp_parse_options()
4292 tcp_parse_fastopen_option(opsize - in tcp_parse_options()
4294 ptr + 2, th->syn, foc, true); in tcp_parse_options()
4301 opt_rx->saw_unknown = 1; in tcp_parse_options()
4305 opt_rx->saw_unknown = 1; in tcp_parse_options()
4307 ptr += opsize-2; in tcp_parse_options()
4308 length -= opsize; in tcp_parse_options()
4320 tp->rx_opt.saw_tstamp = 1; in tcp_parse_aligned_timestamp()
4322 tp->rx_opt.rcv_tsval = ntohl(*ptr); in tcp_parse_aligned_timestamp()
4325 tp->rx_opt.rcv_tsecr = ntohl(*ptr) - tp->tsoffset; in tcp_parse_aligned_timestamp()
4327 tp->rx_opt.rcv_tsecr = 0; in tcp_parse_aligned_timestamp()
4343 if (th->doff == (sizeof(*th) / 4)) { in tcp_fast_parse_options()
4344 tp->rx_opt.saw_tstamp = 0; in tcp_fast_parse_options()
4346 } else if (tp->rx_opt.tstamp_ok && in tcp_fast_parse_options()
4347 th->doff == ((sizeof(*th) + TCPOLEN_TSTAMP_ALIGNED) / 4)) { in tcp_fast_parse_options()
4352 tcp_parse_options(net, skb, &tp->rx_opt, 1, NULL); in tcp_fast_parse_options()
4353 if (tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr) in tcp_fast_parse_options()
4354 tp->rx_opt.rcv_tsecr -= tp->tsoffset; in tcp_fast_parse_options()
4366 int length = (th->doff << 2) - sizeof(*th); in tcp_do_parse_auth_options()
4385 length--; in tcp_do_parse_auth_options()
4390 return -EINVAL; in tcp_do_parse_auth_options()
4393 return -EINVAL; in tcp_do_parse_auth_options()
4395 return -EEXIST; in tcp_do_parse_auth_options()
4399 return -EINVAL; in tcp_do_parse_auth_options()
4401 return -EEXIST; in tcp_do_parse_auth_options()
4405 ptr += opsize - 2; in tcp_do_parse_auth_options()
4406 length -= opsize; in tcp_do_parse_auth_options()
4413 /* Sorry, PAWS as specified is broken wrt. pure-ACKs -DaveM
4444 if (tcp_sk(sk)->tcp_usec_ts) in tcp_tsval_replay()
4445 return inet_csk(sk)->icsk_rto * (USEC_PER_SEC / HZ); in tcp_tsval_replay()
4450 return inet_csk(sk)->icsk_rto * 1200 / HZ; in tcp_tsval_replay()
4457 u32 seq = TCP_SKB_CB(skb)->seq; in tcp_disordered_ack()
4458 u32 ack = TCP_SKB_CB(skb)->ack_seq; in tcp_disordered_ack()
4461 (th->ack && seq == TCP_SKB_CB(skb)->end_seq && seq == tp->rcv_nxt) && in tcp_disordered_ack()
4464 ack == tp->snd_una && in tcp_disordered_ack()
4467 !tcp_may_update_window(tp, ack, seq, ntohs(th->window) << tp->rx_opt.snd_wscale) && in tcp_disordered_ack()
4470 (s32)(tp->rx_opt.ts_recent - tp->rx_opt.rcv_tsval) <= in tcp_disordered_ack()
4479 return !tcp_paws_check(&tp->rx_opt, TCP_PAWS_WINDOW) && in tcp_paws_discard()
4499 if (before(end_seq, tp->rcv_wup)) in tcp_sequence()
4502 if (after(seq, tp->rcv_nxt + tcp_receive_window(tp))) in tcp_sequence()
4512 WRITE_ONCE(sk->sk_err, err); in tcp_done_with_error()
4531 * so just ignore the return value of mptcp_incoming_options(). in tcp_reset()
4537 switch (sk->sk_state) { in tcp_reset()
4557 * If we are ESTABLISHED, a received fin moves us to CLOSE-WAIT
4558 * (and thence onto LAST-ACK and finally, CLOSE, we never enter
4559 * TIME-WAIT)
4561 * If we are in FINWAIT-1, a received FIN indicates simultaneous
4562 * close and we go into CLOSING (and later onto TIME-WAIT)
4564 * If we are in FINWAIT-2, a received FIN moves us to TIME-WAIT.
4572 WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | RCV_SHUTDOWN); in tcp_fin()
4575 switch (sk->sk_state) { in tcp_fin()
4590 /* RFC793: Remain in the LAST-ACK state. */ in tcp_fin()
4602 /* Received a FIN -- send ACK and enter TIME_WAIT. */ in tcp_fin()
4610 pr_err("%s: Impossible, sk->sk_state=%d\n", in tcp_fin()
4611 __func__, sk->sk_state); in tcp_fin()
4615 /* It _is_ possible, that we have something out-of-order _after_ FIN. in tcp_fin()
4618 skb_rbtree_purge(&tp->out_of_order_queue); in tcp_fin()
4620 tcp_sack_reset(&tp->rx_opt); in tcp_fin()
4623 sk->sk_state_change(sk); in tcp_fin()
4626 if (sk->sk_shutdown == SHUTDOWN_MASK || in tcp_fin()
4627 sk->sk_state == TCP_CLOSE) in tcp_fin()
4637 if (!after(seq, sp->end_seq) && !after(sp->start_seq, end_seq)) { in tcp_sack_extend()
4638 if (before(seq, sp->start_seq)) in tcp_sack_extend()
4639 sp->start_seq = seq; in tcp_sack_extend()
4640 if (after(end_seq, sp->end_seq)) in tcp_sack_extend()
4641 sp->end_seq = end_seq; in tcp_sack_extend()
4651 if (tcp_is_sack(tp) && READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_dsack)) { in tcp_dsack_set()
4654 if (before(seq, tp->rcv_nxt)) in tcp_dsack_set()
4661 tp->rx_opt.dsack = 1; in tcp_dsack_set()
4662 tp->duplicate_sack[0].start_seq = seq; in tcp_dsack_set()
4663 tp->duplicate_sack[0].end_seq = end_seq; in tcp_dsack_set()
4671 if (!tp->rx_opt.dsack) in tcp_dsack_extend()
4674 tcp_sack_extend(tp->duplicate_sack, seq, end_seq); in tcp_dsack_extend()
4688 if (inet_csk(sk)->icsk_ca_state != TCP_CA_Loss && in tcp_rcv_spurious_retrans()
4689 skb->protocol == htons(ETH_P_IPV6) && in tcp_rcv_spurious_retrans()
4690 (tcp_sk(sk)->inet_conn.icsk_ack.lrcv_flowlabel != in tcp_rcv_spurious_retrans()
4704 if (TCP_SKB_CB(skb)->end_seq != TCP_SKB_CB(skb)->seq && in tcp_send_dupack()
4705 before(TCP_SKB_CB(skb)->seq, tp->rcv_nxt)) { in tcp_send_dupack()
4709 if (tcp_is_sack(tp) && READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_dsack)) { in tcp_send_dupack()
4710 u32 end_seq = TCP_SKB_CB(skb)->end_seq; in tcp_send_dupack()
4713 if (after(TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt)) in tcp_send_dupack()
4714 end_seq = tp->rcv_nxt; in tcp_send_dupack()
4715 tcp_dsack_set(sk, TCP_SKB_CB(skb)->seq, end_seq); in tcp_send_dupack()
4722 /* These routines update the SACK block as out-of-order packets arrive or
4723 * in-order packets close up the sequence space.
4728 struct tcp_sack_block *sp = &tp->selective_acks[0]; in tcp_sack_maybe_coalesce()
4734 for (this_sack = 1; this_sack < tp->rx_opt.num_sacks;) { in tcp_sack_maybe_coalesce()
4735 if (tcp_sack_extend(sp, swalk->start_seq, swalk->end_seq)) { in tcp_sack_maybe_coalesce()
4741 tp->rx_opt.num_sacks--; in tcp_sack_maybe_coalesce()
4742 for (i = this_sack; i < tp->rx_opt.num_sacks; i++) in tcp_sack_maybe_coalesce()
4755 if (!tp->compressed_ack) in tcp_sack_compress_send_ack()
4758 if (hrtimer_try_to_cancel(&tp->compressed_ack_timer) == 1) in tcp_sack_compress_send_ack()
4762 * substract one from tp->compressed_ack to keep in tcp_sack_compress_send_ack()
4766 tp->compressed_ack - 1); in tcp_sack_compress_send_ack()
4768 tp->compressed_ack = 0; in tcp_sack_compress_send_ack()
4781 struct tcp_sack_block *sp = &tp->selective_acks[0]; in tcp_sack_new_ofo_skb()
4782 int cur_sacks = tp->rx_opt.num_sacks; in tcp_sack_new_ofo_skb()
4793 for (; this_sack > 0; this_sack--, sp--) in tcp_sack_new_ofo_skb()
4794 swap(*sp, *(sp - 1)); in tcp_sack_new_ofo_skb()
4811 this_sack--; in tcp_sack_new_ofo_skb()
4812 tp->rx_opt.num_sacks--; in tcp_sack_new_ofo_skb()
4813 sp--; in tcp_sack_new_ofo_skb()
4815 for (; this_sack > 0; this_sack--, sp--) in tcp_sack_new_ofo_skb()
4816 *sp = *(sp - 1); in tcp_sack_new_ofo_skb()
4820 sp->start_seq = seq; in tcp_sack_new_ofo_skb()
4821 sp->end_seq = end_seq; in tcp_sack_new_ofo_skb()
4822 tp->rx_opt.num_sacks++; in tcp_sack_new_ofo_skb()
4829 struct tcp_sack_block *sp = &tp->selective_acks[0]; in tcp_sack_remove()
4830 int num_sacks = tp->rx_opt.num_sacks; in tcp_sack_remove()
4834 if (RB_EMPTY_ROOT(&tp->out_of_order_queue)) { in tcp_sack_remove()
4835 tp->rx_opt.num_sacks = 0; in tcp_sack_remove()
4841 if (!before(tp->rcv_nxt, sp->start_seq)) { in tcp_sack_remove()
4845 WARN_ON(before(tp->rcv_nxt, sp->end_seq)); in tcp_sack_remove()
4849 tp->selective_acks[i-1] = tp->selective_acks[i]; in tcp_sack_remove()
4850 num_sacks--; in tcp_sack_remove()
4856 tp->rx_opt.num_sacks = num_sacks; in tcp_sack_remove()
4860 * tcp_try_coalesce - try to merge skb to prior one
4882 if (TCP_SKB_CB(from)->seq != TCP_SKB_CB(to)->end_seq) in tcp_try_coalesce()
4891 atomic_add(delta, &sk->sk_rmem_alloc); in tcp_try_coalesce()
4894 TCP_SKB_CB(to)->end_seq = TCP_SKB_CB(from)->end_seq; in tcp_try_coalesce()
4895 TCP_SKB_CB(to)->ack_seq = TCP_SKB_CB(from)->ack_seq; in tcp_try_coalesce()
4896 TCP_SKB_CB(to)->tcp_flags |= TCP_SKB_CB(from)->tcp_flags; in tcp_try_coalesce()
4898 if (TCP_SKB_CB(from)->has_rxtstamp) { in tcp_try_coalesce()
4899 TCP_SKB_CB(to)->has_rxtstamp = true; in tcp_try_coalesce()
4900 to->tstamp = from->tstamp; in tcp_try_coalesce()
4901 skb_hwtstamps(to)->hwtstamp = skb_hwtstamps(from)->hwtstamp; in tcp_try_coalesce()
4914 /* In case tcp_drop_reason() is called later, update to->gso_segs */ in tcp_ooo_try_coalesce()
4916 u32 gso_segs = max_t(u16, 1, skb_shinfo(to)->gso_segs) + in tcp_ooo_try_coalesce()
4917 max_t(u16, 1, skb_shinfo(from)->gso_segs); in tcp_ooo_try_coalesce()
4919 skb_shinfo(to)->gso_segs = min_t(u32, gso_segs, 0xFFFF); in tcp_ooo_try_coalesce()
4937 __u32 dsack_high = tp->rcv_nxt; in tcp_ofo_queue()
4942 p = rb_first(&tp->out_of_order_queue); in tcp_ofo_queue()
4945 if (after(TCP_SKB_CB(skb)->seq, tp->rcv_nxt)) in tcp_ofo_queue()
4948 if (before(TCP_SKB_CB(skb)->seq, dsack_high)) { in tcp_ofo_queue()
4950 if (before(TCP_SKB_CB(skb)->end_seq, dsack_high)) in tcp_ofo_queue()
4951 dsack_high = TCP_SKB_CB(skb)->end_seq; in tcp_ofo_queue()
4952 tcp_dsack_extend(sk, TCP_SKB_CB(skb)->seq, dsack); in tcp_ofo_queue()
4955 rb_erase(&skb->rbnode, &tp->out_of_order_queue); in tcp_ofo_queue()
4957 if (unlikely(!after(TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt))) { in tcp_ofo_queue()
4962 tail = skb_peek_tail(&sk->sk_receive_queue); in tcp_ofo_queue()
4964 tcp_rcv_nxt_update(tp, TCP_SKB_CB(skb)->end_seq); in tcp_ofo_queue()
4965 fin = TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN; in tcp_ofo_queue()
4967 __skb_queue_tail(&sk->sk_receive_queue, skb); in tcp_ofo_queue()
4973 /* tcp_fin() purges tp->out_of_order_queue, in tcp_ofo_queue()
4987 if (atomic_read(&sk->sk_rmem_alloc) > sk->sk_rcvbuf || in tcp_try_rmem_schedule()
4991 return -1; in tcp_try_rmem_schedule()
4995 return -1; in tcp_try_rmem_schedule()
5012 if (unlikely(tcp_try_rmem_schedule(sk, skb, skb->truesize))) { in tcp_data_queue_ofo()
5014 sk->sk_data_ready(sk); in tcp_data_queue_ofo()
5020 tp->pred_flags = 0; in tcp_data_queue_ofo()
5023 tp->rcv_ooopack += max_t(u16, 1, skb_shinfo(skb)->gso_segs); in tcp_data_queue_ofo()
5025 seq = TCP_SKB_CB(skb)->seq; in tcp_data_queue_ofo()
5026 end_seq = TCP_SKB_CB(skb)->end_seq; in tcp_data_queue_ofo()
5028 p = &tp->out_of_order_queue.rb_node; in tcp_data_queue_ofo()
5029 if (RB_EMPTY_ROOT(&tp->out_of_order_queue)) { in tcp_data_queue_ofo()
5032 tp->rx_opt.num_sacks = 1; in tcp_data_queue_ofo()
5033 tp->selective_acks[0].start_seq = seq; in tcp_data_queue_ofo()
5034 tp->selective_acks[0].end_seq = end_seq; in tcp_data_queue_ofo()
5036 rb_link_node(&skb->rbnode, NULL, p); in tcp_data_queue_ofo()
5037 rb_insert_color(&skb->rbnode, &tp->out_of_order_queue); in tcp_data_queue_ofo()
5038 tp->ooo_last_skb = skb; in tcp_data_queue_ofo()
5045 if (tcp_ooo_try_coalesce(sk, tp->ooo_last_skb, in tcp_data_queue_ofo()
5058 if (!before(seq, TCP_SKB_CB(tp->ooo_last_skb)->end_seq)) { in tcp_data_queue_ofo()
5059 parent = &tp->ooo_last_skb->rbnode; in tcp_data_queue_ofo()
5060 p = &parent->rb_right; in tcp_data_queue_ofo()
5069 if (before(seq, TCP_SKB_CB(skb1)->seq)) { in tcp_data_queue_ofo()
5070 p = &parent->rb_left; in tcp_data_queue_ofo()
5073 if (before(seq, TCP_SKB_CB(skb1)->end_seq)) { in tcp_data_queue_ofo()
5074 if (!after(end_seq, TCP_SKB_CB(skb1)->end_seq)) { in tcp_data_queue_ofo()
5084 if (after(seq, TCP_SKB_CB(skb1)->seq)) { in tcp_data_queue_ofo()
5086 tcp_dsack_set(sk, seq, TCP_SKB_CB(skb1)->end_seq); in tcp_data_queue_ofo()
5091 rb_replace_node(&skb1->rbnode, &skb->rbnode, in tcp_data_queue_ofo()
5092 &tp->out_of_order_queue); in tcp_data_queue_ofo()
5094 TCP_SKB_CB(skb1)->seq, in tcp_data_queue_ofo()
5095 TCP_SKB_CB(skb1)->end_seq); in tcp_data_queue_ofo()
5106 p = &parent->rb_right; in tcp_data_queue_ofo()
5110 rb_link_node(&skb->rbnode, parent, p); in tcp_data_queue_ofo()
5111 rb_insert_color(&skb->rbnode, &tp->out_of_order_queue); in tcp_data_queue_ofo()
5116 if (!after(end_seq, TCP_SKB_CB(skb1)->seq)) in tcp_data_queue_ofo()
5118 if (before(end_seq, TCP_SKB_CB(skb1)->end_seq)) { in tcp_data_queue_ofo()
5119 tcp_dsack_extend(sk, TCP_SKB_CB(skb1)->seq, in tcp_data_queue_ofo()
5123 rb_erase(&skb1->rbnode, &tp->out_of_order_queue); in tcp_data_queue_ofo()
5124 tcp_dsack_extend(sk, TCP_SKB_CB(skb1)->seq, in tcp_data_queue_ofo()
5125 TCP_SKB_CB(skb1)->end_seq); in tcp_data_queue_ofo()
5131 tp->ooo_last_skb = skb; in tcp_data_queue_ofo()
5152 struct sk_buff *tail = skb_peek_tail(&sk->sk_receive_queue); in tcp_queue_rcv()
5157 tcp_rcv_nxt_update(tcp_sk(sk), TCP_SKB_CB(skb)->end_seq); in tcp_queue_rcv()
5159 __skb_queue_tail(&sk->sk_receive_queue, skb); in tcp_queue_rcv()
5168 int err = -ENOMEM; in tcp_send_rcvq()
5181 skb = alloc_skb_with_frags(size - data_len, data_len, in tcp_send_rcvq()
5183 &err, sk->sk_allocation); in tcp_send_rcvq()
5187 skb_put(skb, size - data_len); in tcp_send_rcvq()
5188 skb->data_len = data_len; in tcp_send_rcvq()
5189 skb->len = size; in tcp_send_rcvq()
5191 if (tcp_try_rmem_schedule(sk, skb, skb->truesize)) { in tcp_send_rcvq()
5196 err = skb_copy_datagram_from_iter(skb, 0, &msg->msg_iter, size); in tcp_send_rcvq()
5200 TCP_SKB_CB(skb)->seq = tcp_sk(sk)->rcv_nxt; in tcp_send_rcvq()
5201 TCP_SKB_CB(skb)->end_seq = TCP_SKB_CB(skb)->seq + size; in tcp_send_rcvq()
5202 TCP_SKB_CB(skb)->ack_seq = tcp_sk(sk)->snd_una - 1; in tcp_send_rcvq()
5219 if (tcp_epollin_ready(sk, sk->sk_rcvlowat) || sock_flag(sk, SOCK_DONE)) in tcp_data_ready()
5220 sk->sk_data_ready(sk); in tcp_data_ready()
5238 if (TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq) { in tcp_data_queue()
5243 __skb_pull(skb, tcp_hdr(skb)->doff * 4); in tcp_data_queue()
5246 tp->rx_opt.dsack = 0; in tcp_data_queue()
5252 if (TCP_SKB_CB(skb)->seq == tp->rcv_nxt) { in tcp_data_queue()
5260 if (!skb->len && in tcp_data_queue()
5261 (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN)) in tcp_data_queue()
5271 if (tcp_try_rmem_schedule(sk, skb, skb->truesize)) { in tcp_data_queue()
5273 inet_csk(sk)->icsk_ack.pending |= in tcp_data_queue()
5276 sk->sk_data_ready(sk); in tcp_data_queue()
5278 if (skb_queue_len(&sk->sk_receive_queue) && skb->len) { in tcp_data_queue()
5283 sk_forced_mem_schedule(sk, skb->truesize); in tcp_data_queue()
5287 if (skb->len) in tcp_data_queue()
5289 if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) in tcp_data_queue()
5292 if (!RB_EMPTY_ROOT(&tp->out_of_order_queue)) { in tcp_data_queue()
5298 if (RB_EMPTY_ROOT(&tp->out_of_order_queue)) in tcp_data_queue()
5299 inet_csk(sk)->icsk_ack.pending |= ICSK_ACK_NOW; in tcp_data_queue()
5302 if (tp->rx_opt.num_sacks) in tcp_data_queue()
5314 if (!after(TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt)) { in tcp_data_queue()
5319 tcp_dsack_set(sk, TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq); in tcp_data_queue()
5330 if (!before(TCP_SKB_CB(skb)->seq, in tcp_data_queue()
5331 tp->rcv_nxt + tcp_receive_window(tp))) { in tcp_data_queue()
5336 if (before(TCP_SKB_CB(skb)->seq, tp->rcv_nxt)) { in tcp_data_queue()
5338 tcp_dsack_set(sk, TCP_SKB_CB(skb)->seq, tp->rcv_nxt); in tcp_data_queue()
5341 * remembering D-SACK for its head made in previous line. in tcp_data_queue()
5357 return !skb_queue_is_last(list, skb) ? skb->next : NULL; in tcp_skb_next()
5371 rb_erase(&skb->rbnode, root); in tcp_collapse_one()
5379 /* Insert skb into rb tree, ordered by TCP_SKB_CB(skb)->seq */
5382 struct rb_node **p = &root->rb_node; in tcp_rbtree_insert()
5389 if (before(TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb1)->seq)) in tcp_rbtree_insert()
5390 p = &parent->rb_left; in tcp_rbtree_insert()
5392 p = &parent->rb_right; in tcp_rbtree_insert()
5394 rb_link_node(&skb->rbnode, parent, p); in tcp_rbtree_insert()
5395 rb_insert_color(&skb->rbnode, root); in tcp_rbtree_insert()
5425 if (!before(start, TCP_SKB_CB(skb)->end_seq)) { in tcp_collapse()
5433 * - not SYN/FIN and in tcp_collapse()
5434 * - bloated or contains data before "start" or in tcp_collapse()
5437 if (!(TCP_SKB_CB(skb)->tcp_flags & (TCPHDR_SYN | TCPHDR_FIN)) && in tcp_collapse()
5438 (tcp_win_from_space(sk, skb->truesize) > skb->len || in tcp_collapse()
5439 before(TCP_SKB_CB(skb)->seq, start))) { in tcp_collapse()
5446 TCP_SKB_CB(skb)->end_seq != TCP_SKB_CB(n)->seq) { in tcp_collapse()
5453 start = TCP_SKB_CB(skb)->end_seq; in tcp_collapse()
5456 (TCP_SKB_CB(skb)->tcp_flags & (TCPHDR_SYN | TCPHDR_FIN)) || in tcp_collapse()
5463 int copy = min_t(int, SKB_MAX_ORDER(0, 0), end - start); in tcp_collapse()
5470 memcpy(nskb->cb, skb->cb, sizeof(skb->cb)); in tcp_collapse()
5472 TCP_SKB_CB(nskb)->seq = TCP_SKB_CB(nskb)->end_seq = start; in tcp_collapse()
5482 int offset = start - TCP_SKB_CB(skb)->seq; in tcp_collapse()
5483 int size = TCP_SKB_CB(skb)->end_seq - start; in tcp_collapse()
5490 TCP_SKB_CB(nskb)->end_seq += size; in tcp_collapse()
5491 copy -= size; in tcp_collapse()
5494 if (!before(start, TCP_SKB_CB(skb)->end_seq)) { in tcp_collapse()
5499 (TCP_SKB_CB(skb)->tcp_flags & (TCPHDR_SYN | TCPHDR_FIN)) || in tcp_collapse()
5520 skb = skb_rb_first(&tp->out_of_order_queue); in tcp_collapse_ofo_queue()
5523 tp->ooo_last_skb = skb_rb_last(&tp->out_of_order_queue); in tcp_collapse_ofo_queue()
5526 start = TCP_SKB_CB(skb)->seq; in tcp_collapse_ofo_queue()
5527 end = TCP_SKB_CB(skb)->end_seq; in tcp_collapse_ofo_queue()
5528 range_truesize = skb->truesize; in tcp_collapse_ofo_queue()
5537 after(TCP_SKB_CB(skb)->seq, end) || in tcp_collapse_ofo_queue()
5538 before(TCP_SKB_CB(skb)->end_seq, start)) { in tcp_collapse_ofo_queue()
5540 if (range_truesize != head->truesize || in tcp_collapse_ofo_queue()
5541 end - start >= SKB_WITH_OVERHEAD(PAGE_SIZE)) { in tcp_collapse_ofo_queue()
5542 tcp_collapse(sk, NULL, &tp->out_of_order_queue, in tcp_collapse_ofo_queue()
5546 if (sum_tiny > sk->sk_rcvbuf >> 3) in tcp_collapse_ofo_queue()
5552 range_truesize += skb->truesize; in tcp_collapse_ofo_queue()
5553 if (unlikely(before(TCP_SKB_CB(skb)->seq, start))) in tcp_collapse_ofo_queue()
5554 start = TCP_SKB_CB(skb)->seq; in tcp_collapse_ofo_queue()
5555 if (after(TCP_SKB_CB(skb)->end_seq, end)) in tcp_collapse_ofo_queue()
5556 end = TCP_SKB_CB(skb)->end_seq; in tcp_collapse_ofo_queue()
5561 * Clean the out-of-order queue to make room.
5580 if (RB_EMPTY_ROOT(&tp->out_of_order_queue)) in tcp_prune_ofo_queue()
5583 goal = sk->sk_rcvbuf >> 3; in tcp_prune_ofo_queue()
5584 node = &tp->ooo_last_skb->rbnode; in tcp_prune_ofo_queue()
5590 if (after(TCP_SKB_CB(in_skb)->seq, TCP_SKB_CB(skb)->seq)) in tcp_prune_ofo_queue()
5594 rb_erase(node, &tp->out_of_order_queue); in tcp_prune_ofo_queue()
5595 goal -= skb->truesize; in tcp_prune_ofo_queue()
5597 tp->ooo_last_skb = rb_to_skb(prev); in tcp_prune_ofo_queue()
5599 if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf && in tcp_prune_ofo_queue()
5602 goal = sk->sk_rcvbuf >> 3; in tcp_prune_ofo_queue()
5614 if (tp->rx_opt.sack_ok) in tcp_prune_ofo_queue()
5615 tcp_sack_reset(&tp->rx_opt); in tcp_prune_ofo_queue()
5633 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) in tcp_prune_queue()
5638 if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf) in tcp_prune_queue()
5642 if (!skb_queue_empty(&sk->sk_receive_queue)) in tcp_prune_queue()
5643 tcp_collapse(sk, &sk->sk_receive_queue, NULL, in tcp_prune_queue()
5644 skb_peek(&sk->sk_receive_queue), in tcp_prune_queue()
5646 tp->copied_seq, tp->rcv_nxt); in tcp_prune_queue()
5648 if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf) in tcp_prune_queue()
5656 if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf) in tcp_prune_queue()
5666 tp->pred_flags = 0; in tcp_prune_queue()
5667 return -1; in tcp_prune_queue()
5677 if (sk->sk_userlocks & SOCK_SNDBUF_LOCK) in tcp_should_expand_sndbuf()
5689 WRITE_ONCE(sk->sk_sndbuf, unused_mem); in tcp_should_expand_sndbuf()
5711 tp->snd_cwnd_stamp = tcp_jiffies32; in tcp_new_space()
5714 INDIRECT_CALL_1(sk->sk_write_space, sk_stream_write_space, sk); in tcp_new_space()
5718 * 1) Freeing skbs in rtx queues (after tp->snd_una has advanced)
5719 * 2) Sent skbs from output queue (and thus advancing tp->snd_nxt)
5722 * 1) Space consumed in output/rtx queues is below sk->sk_sndbuf/2
5723 * 2) notsent amount (tp->write_seq - tp->snd_nxt) became
5731 if (sk->sk_socket && in tcp_check_space()
5732 test_bit(SOCK_NOSPACE, &sk->sk_socket->flags)) { in tcp_check_space()
5734 if (!test_bit(SOCK_NOSPACE, &sk->sk_socket->flags)) in tcp_check_space()
5754 if (((tp->rcv_nxt - tp->rcv_wup) > inet_csk(sk)->icsk_ack.rcv_mss && in __tcp_ack_snd_check()
5760 (tp->rcv_nxt - tp->copied_seq < sk->sk_rcvlowat || in __tcp_ack_snd_check()
5761 __tcp_select_window(sk) >= tp->rcv_wnd)) || in __tcp_ack_snd_check()
5764 /* Protocol state mandates a one-time immediate ACK */ in __tcp_ack_snd_check()
5765 inet_csk(sk)->icsk_ack.pending & ICSK_ACK_NOW) { in __tcp_ack_snd_check()
5770 READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_backlog_ack_defer)) { in __tcp_ack_snd_check()
5771 set_bit(TCP_ACK_DEFERRED, &sk->sk_tsq_flags); in __tcp_ack_snd_check()
5779 if (!ofo_possible || RB_EMPTY_ROOT(&tp->out_of_order_queue)) { in __tcp_ack_snd_check()
5785 tp->compressed_ack >= READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_comp_sack_nr)) in __tcp_ack_snd_check()
5788 if (tp->compressed_ack_rcv_nxt != tp->rcv_nxt) { in __tcp_ack_snd_check()
5789 tp->compressed_ack_rcv_nxt = tp->rcv_nxt; in __tcp_ack_snd_check()
5790 tp->dup_ack_counter = 0; in __tcp_ack_snd_check()
5792 if (tp->dup_ack_counter < TCP_FASTRETRANS_THRESH) { in __tcp_ack_snd_check()
5793 tp->dup_ack_counter++; in __tcp_ack_snd_check()
5796 tp->compressed_ack++; in __tcp_ack_snd_check()
5797 if (hrtimer_is_queued(&tp->compressed_ack_timer)) in __tcp_ack_snd_check()
5802 rtt = tp->rcv_rtt_est.rtt_us; in __tcp_ack_snd_check()
5803 if (tp->srtt_us && tp->srtt_us < rtt) in __tcp_ack_snd_check()
5804 rtt = tp->srtt_us; in __tcp_ack_snd_check()
5807 READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_comp_sack_delay_ns), in __tcp_ack_snd_check()
5810 hrtimer_start_range_ns(&tp->compressed_ack_timer, ns_to_ktime(delay), in __tcp_ack_snd_check()
5811 READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_comp_sack_slack_ns), in __tcp_ack_snd_check()
5828 * place. We handle URGent data wrong. We have to - as
5837 u32 ptr = ntohs(th->urg_ptr); in tcp_check_urg()
5839 if (ptr && !READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_stdurg)) in tcp_check_urg()
5840 ptr--; in tcp_check_urg()
5841 ptr += ntohl(th->seq); in tcp_check_urg()
5844 if (after(tp->copied_seq, ptr)) in tcp_check_urg()
5857 if (before(ptr, tp->rcv_nxt)) in tcp_check_urg()
5861 if (tp->urg_data && !after(ptr, tp->urg_seq)) in tcp_check_urg()
5869 * tp->copied_seq since we would read the last urgent byte again in tcp_check_urg()
5882 if (tp->urg_seq == tp->copied_seq && tp->urg_data && in tcp_check_urg()
5883 !sock_flag(sk, SOCK_URGINLINE) && tp->copied_seq != tp->rcv_nxt) { in tcp_check_urg()
5884 struct sk_buff *skb = skb_peek(&sk->sk_receive_queue); in tcp_check_urg()
5885 tp->copied_seq++; in tcp_check_urg()
5886 if (skb && !before(tp->copied_seq, TCP_SKB_CB(skb)->end_seq)) { in tcp_check_urg()
5887 __skb_unlink(skb, &sk->sk_receive_queue); in tcp_check_urg()
5892 WRITE_ONCE(tp->urg_data, TCP_URG_NOTYET); in tcp_check_urg()
5893 WRITE_ONCE(tp->urg_seq, ptr); in tcp_check_urg()
5896 tp->pred_flags = 0; in tcp_check_urg()
5904 /* Check if we get a new urgent pointer - normally not. */ in tcp_urg()
5905 if (unlikely(th->urg)) in tcp_urg()
5908 /* Do we wait for any urgent data? - normally not... */ in tcp_urg()
5909 if (unlikely(tp->urg_data == TCP_URG_NOTYET)) { in tcp_urg()
5910 u32 ptr = tp->urg_seq - ntohl(th->seq) + (th->doff * 4) - in tcp_urg()
5911 th->syn; in tcp_urg()
5914 if (ptr < skb->len) { in tcp_urg()
5918 WRITE_ONCE(tp->urg_data, TCP_URG_VALID | tmp); in tcp_urg()
5920 sk->sk_data_ready(sk); in tcp_urg()
5925 /* Accept RST for rcv_nxt - 1 after a FIN.
5937 return unlikely(TCP_SKB_CB(skb)->seq == (tp->rcv_nxt - 1) && in tcp_reset_check()
5938 (1 << sk->sk_state) & (TCPF_CLOSE_WAIT | TCPF_LAST_ACK | in tcp_reset_check()
5953 tp->rx_opt.saw_tstamp && in tcp_validate_incoming()
5955 if (!th->rst) { in tcp_validate_incoming()
5956 if (unlikely(th->syn)) in tcp_validate_incoming()
5961 &tp->last_oow_ack_time)) in tcp_validate_incoming()
5970 reason = tcp_sequence(tp, TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq); in tcp_validate_incoming()
5972 /* RFC793, page 37: "In all states except SYN-SENT, all reset in tcp_validate_incoming()
5973 * (RST) segments are validated by checking their SEQ-fields." in tcp_validate_incoming()
5978 if (!th->rst) { in tcp_validate_incoming()
5979 if (th->syn) in tcp_validate_incoming()
5983 &tp->last_oow_ack_time)) in tcp_validate_incoming()
5992 if (th->rst) { in tcp_validate_incoming()
5993 /* RFC 5961 3.2 (extend to match against (RCV.NXT - 1) after a in tcp_validate_incoming()
5995 * If seq num matches RCV.NXT or (RCV.NXT - 1) after a FIN, or in tcp_validate_incoming()
5996 * the right-most SACK block, in tcp_validate_incoming()
6002 if (TCP_SKB_CB(skb)->seq == tp->rcv_nxt || in tcp_validate_incoming()
6006 if (tcp_is_sack(tp) && tp->rx_opt.num_sacks > 0) { in tcp_validate_incoming()
6007 struct tcp_sack_block *sp = &tp->selective_acks[0]; in tcp_validate_incoming()
6011 for (this_sack = 1; this_sack < tp->rx_opt.num_sacks; in tcp_validate_incoming()
6018 if (TCP_SKB_CB(skb)->seq == max_sack) in tcp_validate_incoming()
6022 /* Disable TFO if RST is out-of-order in tcp_validate_incoming()
6026 if (tp->syn_fastopen && !tp->data_segs_in && in tcp_validate_incoming()
6027 sk->sk_state == TCP_ESTABLISHED) in tcp_validate_incoming()
6039 if (th->syn) { in tcp_validate_incoming()
6040 if (sk->sk_state == TCP_SYN_RECV && sk->sk_socket && th->ack && in tcp_validate_incoming()
6041 TCP_SKB_CB(skb)->seq + 1 == TCP_SKB_CB(skb)->end_seq && in tcp_validate_incoming()
6042 TCP_SKB_CB(skb)->seq + 1 == tp->rcv_nxt && in tcp_validate_incoming()
6043 TCP_SKB_CB(skb)->ack_seq == tp->snd_nxt) in tcp_validate_incoming()
6074 * - A zero window was announced from us - zero window probing
6076 * - Out of order segments arrived.
6077 * - Urgent data is expected.
6078 * - There is no buffer space left
6079 * - Unexpected TCP flags/window values/header lengths are received
6081 * - Data is sent in both directions. Fast path only supports pure senders
6083 * value must stay constant)
6084 * - Unexpected TCP option.
6095 const struct tcphdr *th = (const struct tcphdr *)skb->data; in tcp_rcv_established()
6097 unsigned int len = skb->len; in tcp_rcv_established()
6103 if (unlikely(!rcu_access_pointer(sk->sk_rx_dst))) in tcp_rcv_established()
6104 inet_csk(sk)->icsk_af_ops->sk_rx_dst_set(sk, skb); in tcp_rcv_established()
6120 tp->rx_opt.saw_tstamp = 0; in tcp_rcv_established()
6124 * 'S' will always be tp->tcp_header_len >> 2 in tcp_rcv_established()
6131 if ((tcp_flag_word(th) & TCP_HP_BITS) == tp->pred_flags && in tcp_rcv_established()
6132 TCP_SKB_CB(skb)->seq == tp->rcv_nxt && in tcp_rcv_established()
6133 !after(TCP_SKB_CB(skb)->ack_seq, tp->snd_nxt)) { in tcp_rcv_established()
6134 int tcp_header_len = tp->tcp_header_len; in tcp_rcv_established()
6137 * is automatically equal to th->doff*4 due to pred_flags in tcp_rcv_established()
6148 if ((s32)(tp->rx_opt.rcv_tsval - tp->rx_opt.ts_recent) < 0) in tcp_rcv_established()
6167 tp->rcv_nxt == tp->rcv_wup) in tcp_rcv_established()
6180 tp->rcv_rtt_last_tsecr = tp->rx_opt.rcv_tsecr; in tcp_rcv_established()
6194 if ((int)skb->truesize > sk->sk_forward_alloc) in tcp_rcv_established()
6203 tp->rcv_nxt == tp->rcv_wup) in tcp_rcv_established()
6217 if (TCP_SKB_CB(skb)->ack_seq != tp->snd_una) { in tcp_rcv_established()
6224 tcp_update_wl(tp, TCP_SKB_CB(skb)->seq); in tcp_rcv_established()
6237 if (len < (th->doff << 2) || tcp_checksum_complete(skb)) in tcp_rcv_established()
6240 if (!th->ack && !th->rst && !th->syn) { in tcp_rcv_established()
6255 reason = -reason; in tcp_rcv_established()
6287 icsk->icsk_af_ops->rebuild_header(sk); in tcp_init_transfer()
6291 * Cut cwnd down to 1 per RFC5681 if SYN or SYN-ACK has been in tcp_init_transfer()
6293 * initRTO, we only reset cwnd when more than 1 SYN/SYN-ACK in tcp_init_transfer()
6296 if (tp->total_retrans > 1 && tp->undo_marker) in tcp_init_transfer()
6300 tp->snd_cwnd_stamp = tcp_jiffies32; in tcp_init_transfer()
6304 if (!icsk->icsk_ca_initialized) in tcp_init_transfer()
6316 icsk->icsk_ack.lrcvtime = tcp_jiffies32; in tcp_finish_connect()
6319 icsk->icsk_af_ops->sk_rx_dst_set(sk, skb); in tcp_finish_connect()
6329 tp->lsndtime = tcp_jiffies32; in tcp_finish_connect()
6334 if (!tp->rx_opt.snd_wscale) in tcp_finish_connect()
6335 __tcp_fast_path_on(tp, tp->snd_wnd); in tcp_finish_connect()
6337 tp->pred_flags = 0; in tcp_finish_connect()
6344 struct sk_buff *data = tp->syn_data ? tcp_rtx_queue_head(sk) : NULL; in tcp_rcv_fastopen_synack()
6345 u16 mss = tp->rx_opt.mss_clamp, try_exp = 0; in tcp_rcv_fastopen_synack()
6348 if (mss == tp->rx_opt.user_mss) { in tcp_rcv_fastopen_synack()
6351 /* Get original SYNACK MSS value if user MSS sets mss_clamp */ in tcp_rcv_fastopen_synack()
6358 if (!tp->syn_fastopen) { in tcp_rcv_fastopen_synack()
6360 cookie->len = -1; in tcp_rcv_fastopen_synack()
6361 } else if (tp->total_retrans) { in tcp_rcv_fastopen_synack()
6362 /* SYN timed out and the SYN-ACK neither has a cookie nor in tcp_rcv_fastopen_synack()
6365 * SYN-data or the corresponding SYN-ACK was dropped. in tcp_rcv_fastopen_synack()
6367 syn_drop = (cookie->len < 0 && data); in tcp_rcv_fastopen_synack()
6368 } else if (cookie->len < 0 && !tp->syn_data) { in tcp_rcv_fastopen_synack()
6373 try_exp = tp->syn_fastopen_exp ? 2 : 1; in tcp_rcv_fastopen_synack()
6379 if (tp->total_retrans) in tcp_rcv_fastopen_synack()
6380 tp->fastopen_client_fail = TFO_SYN_RETRANSMITTED; in tcp_rcv_fastopen_synack()
6382 tp->fastopen_client_fail = TFO_DATA_NOT_ACKED; in tcp_rcv_fastopen_synack()
6390 tp->syn_data_acked = tp->syn_data; in tcp_rcv_fastopen_synack()
6391 if (tp->syn_data_acked) { in tcp_rcv_fastopen_synack()
6393 /* SYN-data is counted as two separate packets in tcp_ack() */ in tcp_rcv_fastopen_synack()
6394 if (tp->delivered > 1) in tcp_rcv_fastopen_synack()
6395 --tp->delivered; in tcp_rcv_fastopen_synack()
6407 if (tp->syn_smc && !tp->rx_opt.smc_ok) in smc_check_reset_syn()
6408 tp->syn_smc = 0; in smc_check_reset_syn()
6419 * spurious if the ACK's timestamp option echo value matches the in tcp_try_undo_spurious_syn()
6422 syn_stamp = tp->retrans_stamp; in tcp_try_undo_spurious_syn()
6423 if (tp->undo_marker && syn_stamp && tp->rx_opt.saw_tstamp && in tcp_try_undo_spurious_syn()
6424 syn_stamp == tp->rx_opt.rcv_tsecr) in tcp_try_undo_spurious_syn()
6425 tp->undo_marker = 0; in tcp_try_undo_spurious_syn()
6433 struct tcp_fastopen_cookie foc = { .len = -1 }; in tcp_rcv_synsent_state_process()
6434 int saved_clamp = tp->rx_opt.mss_clamp; in tcp_rcv_synsent_state_process()
6438 tcp_parse_options(sock_net(sk), skb, &tp->rx_opt, 0, &foc); in tcp_rcv_synsent_state_process()
6439 if (tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr) in tcp_rcv_synsent_state_process()
6440 tp->rx_opt.rcv_tsecr -= tp->tsoffset; in tcp_rcv_synsent_state_process()
6442 if (th->ack) { in tcp_rcv_synsent_state_process()
6444 * "If the state is SYN-SENT then in tcp_rcv_synsent_state_process()
6451 if (!after(TCP_SKB_CB(skb)->ack_seq, tp->snd_una) || in tcp_rcv_synsent_state_process()
6452 after(TCP_SKB_CB(skb)->ack_seq, tp->snd_nxt)) { in tcp_rcv_synsent_state_process()
6454 if (icsk->icsk_retransmits == 0) in tcp_rcv_synsent_state_process()
6462 if (tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr && in tcp_rcv_synsent_state_process()
6463 !between(tp->rx_opt.rcv_tsecr, tp->retrans_stamp, in tcp_rcv_synsent_state_process()
6479 if (th->rst) { in tcp_rcv_synsent_state_process()
6491 * --ANK(990513) in tcp_rcv_synsent_state_process()
6493 if (!th->syn) { in tcp_rcv_synsent_state_process()
6506 tcp_init_wl(tp, TCP_SKB_CB(skb)->seq); in tcp_rcv_synsent_state_process()
6513 WRITE_ONCE(tp->rcv_nxt, TCP_SKB_CB(skb)->seq + 1); in tcp_rcv_synsent_state_process()
6514 tp->rcv_wup = TCP_SKB_CB(skb)->seq + 1; in tcp_rcv_synsent_state_process()
6519 tp->snd_wnd = ntohs(th->window); in tcp_rcv_synsent_state_process()
6521 if (!tp->rx_opt.wscale_ok) { in tcp_rcv_synsent_state_process()
6522 tp->rx_opt.snd_wscale = tp->rx_opt.rcv_wscale = 0; in tcp_rcv_synsent_state_process()
6523 WRITE_ONCE(tp->window_clamp, in tcp_rcv_synsent_state_process()
6524 min(tp->window_clamp, 65535U)); in tcp_rcv_synsent_state_process()
6527 if (tp->rx_opt.saw_tstamp) { in tcp_rcv_synsent_state_process()
6528 tp->rx_opt.tstamp_ok = 1; in tcp_rcv_synsent_state_process()
6529 tp->tcp_header_len = in tcp_rcv_synsent_state_process()
6531 tp->advmss -= TCPOLEN_TSTAMP_ALIGNED; in tcp_rcv_synsent_state_process()
6534 tp->tcp_header_len = sizeof(struct tcphdr); in tcp_rcv_synsent_state_process()
6537 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie); in tcp_rcv_synsent_state_process()
6541 * Change state from SYN-SENT only after copied_seq in tcp_rcv_synsent_state_process()
6543 WRITE_ONCE(tp->copied_seq, tp->rcv_nxt); in tcp_rcv_synsent_state_process()
6551 fastopen_fail = (tp->syn_fastopen || tp->syn_data) && in tcp_rcv_synsent_state_process()
6555 sk->sk_state_change(sk); in tcp_rcv_synsent_state_process()
6559 return -1; in tcp_rcv_synsent_state_process()
6560 if (sk->sk_write_pending || in tcp_rcv_synsent_state_process()
6561 READ_ONCE(icsk->icsk_accept_queue.rskq_defer_accept) || in tcp_rcv_synsent_state_process()
6568 * to stand against the temptation 8) --ANK in tcp_rcv_synsent_state_process()
6577 return -1; in tcp_rcv_synsent_state_process()
6582 if (th->rst) { in tcp_rcv_synsent_state_process()
6593 if (tp->rx_opt.ts_recent_stamp && tp->rx_opt.saw_tstamp && in tcp_rcv_synsent_state_process()
6594 tcp_paws_reject(&tp->rx_opt, 0)) { in tcp_rcv_synsent_state_process()
6598 if (th->syn) { in tcp_rcv_synsent_state_process()
6606 ao = rcu_dereference_protected(tp->ao_info, in tcp_rcv_synsent_state_process()
6609 WRITE_ONCE(ao->risn, th->seq); in tcp_rcv_synsent_state_process()
6610 ao->rcv_sne = 0; in tcp_rcv_synsent_state_process()
6615 if (tp->rx_opt.saw_tstamp) { in tcp_rcv_synsent_state_process()
6616 tp->rx_opt.tstamp_ok = 1; in tcp_rcv_synsent_state_process()
6618 tp->tcp_header_len = in tcp_rcv_synsent_state_process()
6621 tp->tcp_header_len = sizeof(struct tcphdr); in tcp_rcv_synsent_state_process()
6624 WRITE_ONCE(tp->rcv_nxt, TCP_SKB_CB(skb)->seq + 1); in tcp_rcv_synsent_state_process()
6625 WRITE_ONCE(tp->copied_seq, tp->rcv_nxt); in tcp_rcv_synsent_state_process()
6626 tp->rcv_wup = TCP_SKB_CB(skb)->seq + 1; in tcp_rcv_synsent_state_process()
6631 tp->snd_wnd = ntohs(th->window); in tcp_rcv_synsent_state_process()
6632 tp->snd_wl1 = TCP_SKB_CB(skb)->seq; in tcp_rcv_synsent_state_process()
6633 tp->max_window = tp->snd_wnd; in tcp_rcv_synsent_state_process()
6638 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie); in tcp_rcv_synsent_state_process()
6654 return -1; in tcp_rcv_synsent_state_process()
6664 tcp_clear_options(&tp->rx_opt); in tcp_rcv_synsent_state_process()
6665 tp->rx_opt.mss_clamp = saved_clamp; in tcp_rcv_synsent_state_process()
6670 tcp_clear_options(&tp->rx_opt); in tcp_rcv_synsent_state_process()
6671 tp->rx_opt.mss_clamp = saved_clamp; in tcp_rcv_synsent_state_process()
6684 if (inet_csk(sk)->icsk_ca_state == TCP_CA_Loss && !tp->packets_out) in tcp_rcv_synrecv_state_fastopen()
6688 inet_csk(sk)->icsk_retransmits = 0; in tcp_rcv_synrecv_state_fastopen()
6702 req = rcu_dereference_protected(tp->fastopen_rsk, in tcp_rcv_synrecv_state_fastopen()
6706 /* Re-arm the timer because data may have been sent out. in tcp_rcv_synrecv_state_fastopen()
6710 * (TFO) - we could try to be more aggressive and in tcp_rcv_synrecv_state_fastopen()
6734 switch (sk->sk_state) { in tcp_rcv_state_process()
6740 if (th->ack) in tcp_rcv_state_process()
6743 if (th->rst) { in tcp_rcv_state_process()
6747 if (th->syn) { in tcp_rcv_state_process()
6748 if (th->fin) { in tcp_rcv_state_process()
6757 icsk->icsk_af_ops->conn_request(sk, skb); in tcp_rcv_state_process()
6768 tp->rx_opt.saw_tstamp = 0; in tcp_rcv_state_process()
6782 tp->rx_opt.saw_tstamp = 0; in tcp_rcv_state_process()
6783 req = rcu_dereference_protected(tp->fastopen_rsk, in tcp_rcv_state_process()
6788 WARN_ON_ONCE(sk->sk_state != TCP_SYN_RECV && in tcp_rcv_state_process()
6789 sk->sk_state != TCP_FIN_WAIT1); in tcp_rcv_state_process()
6797 if (!th->ack && !th->rst && !th->syn) { in tcp_rcv_state_process()
6810 if (sk->sk_state == TCP_SYN_RECV) { in tcp_rcv_state_process()
6814 return -reason; in tcp_rcv_state_process()
6819 reason = -reason; in tcp_rcv_state_process()
6824 switch (sk->sk_state) { in tcp_rcv_state_process()
6826 tp->delivered++; /* SYN-ACK delivery isn't tracked in tcp_ack */ in tcp_rcv_state_process()
6827 if (!tp->srtt_us) in tcp_rcv_state_process()
6834 tp->retrans_stamp = 0; in tcp_rcv_state_process()
6837 WRITE_ONCE(tp->copied_seq, tp->rcv_nxt); in tcp_rcv_state_process()
6842 sk->sk_state_change(sk); in tcp_rcv_state_process()
6846 * sk->sk_sleep == NULL and sk->sk_socket == NULL. in tcp_rcv_state_process()
6848 if (sk->sk_socket) in tcp_rcv_state_process()
6851 tp->snd_una = TCP_SKB_CB(skb)->ack_seq; in tcp_rcv_state_process()
6852 tp->snd_wnd = ntohs(th->window) << tp->rx_opt.snd_wscale; in tcp_rcv_state_process()
6853 tcp_init_wl(tp, TCP_SKB_CB(skb)->seq); in tcp_rcv_state_process()
6855 if (tp->rx_opt.tstamp_ok) in tcp_rcv_state_process()
6856 tp->advmss -= TCPOLEN_TSTAMP_ALIGNED; in tcp_rcv_state_process()
6858 if (!inet_csk(sk)->icsk_ca_ops->cong_control) in tcp_rcv_state_process()
6862 tp->lsndtime = tcp_jiffies32; in tcp_rcv_state_process()
6866 if (sk->sk_shutdown & SEND_SHUTDOWN) in tcp_rcv_state_process()
6876 if (tp->snd_una != tp->write_seq) in tcp_rcv_state_process()
6880 WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | SEND_SHUTDOWN); in tcp_rcv_state_process()
6886 sk->sk_state_change(sk); in tcp_rcv_state_process()
6890 if (READ_ONCE(tp->linger2) < 0) { in tcp_rcv_state_process()
6895 if (TCP_SKB_CB(skb)->end_seq != TCP_SKB_CB(skb)->seq && in tcp_rcv_state_process()
6896 after(TCP_SKB_CB(skb)->end_seq - th->fin, tp->rcv_nxt)) { in tcp_rcv_state_process()
6898 if (tp->syn_fastopen && th->fin) in tcp_rcv_state_process()
6907 inet_csk_reset_keepalive_timer(sk, tmo - TCP_TIMEWAIT_LEN); in tcp_rcv_state_process()
6908 } else if (th->fin || sock_owned_by_user(sk)) { in tcp_rcv_state_process()
6924 if (tp->snd_una == tp->write_seq) { in tcp_rcv_state_process()
6931 if (tp->snd_una == tp->write_seq) { in tcp_rcv_state_process()
6943 switch (sk->sk_state) { in tcp_rcv_state_process()
6947 if (!before(TCP_SKB_CB(skb)->seq, tp->rcv_nxt)) { in tcp_rcv_state_process()
6962 if (sk->sk_shutdown & RCV_SHUTDOWN) { in tcp_rcv_state_process()
6963 if (TCP_SKB_CB(skb)->end_seq != TCP_SKB_CB(skb)->seq && in tcp_rcv_state_process()
6964 after(TCP_SKB_CB(skb)->end_seq - th->fin, tp->rcv_nxt)) { in tcp_rcv_state_process()
6977 /* tcp_data could move socket to TIME-WAIT */ in tcp_rcv_state_process()
6978 if (sk->sk_state != TCP_CLOSE) { in tcp_rcv_state_process()
7001 &ireq->ir_rmt_addr, port); in pr_drop_req()
7005 &ireq->ir_v6_rmt_addr, port); in pr_drop_req()
7021 * Exception: At least one of the reserved bits of the TCP header (th->res1) is
7033 bool th_ecn = th->ece && th->cwr; in tcp_ecn_create_request()
7040 ect = !INET_ECN_is_not_ect(TCP_SKB_CB(skb)->ip_dsfield); in tcp_ecn_create_request()
7042 ecn_ok = READ_ONCE(net->ipv4.sysctl_tcp_ecn) || ecn_ok_dst; in tcp_ecn_create_request()
7044 if (((!ect || th->res1) && ecn_ok) || tcp_ca_needs_ecn(listen_sk) || in tcp_ecn_create_request()
7047 inet_rsk(req)->ecn_ok = 1; in tcp_ecn_create_request()
7056 req->rsk_rcv_wnd = 0; /* So that tcp_send_synack() knows! */ in tcp_openreq_init()
7057 tcp_rsk(req)->rcv_isn = TCP_SKB_CB(skb)->seq; in tcp_openreq_init()
7058 tcp_rsk(req)->rcv_nxt = TCP_SKB_CB(skb)->seq + 1; in tcp_openreq_init()
7059 tcp_rsk(req)->snt_synack = 0; in tcp_openreq_init()
7060 tcp_rsk(req)->last_oow_ack_time = 0; in tcp_openreq_init()
7061 req->mss = rx_opt->mss_clamp; in tcp_openreq_init()
7062 req->ts_recent = rx_opt->saw_tstamp ? rx_opt->rcv_tsval : 0; in tcp_openreq_init()
7063 ireq->tstamp_ok = rx_opt->tstamp_ok; in tcp_openreq_init()
7064 ireq->sack_ok = rx_opt->sack_ok; in tcp_openreq_init()
7065 ireq->snd_wscale = rx_opt->snd_wscale; in tcp_openreq_init()
7066 ireq->wscale_ok = rx_opt->wscale_ok; in tcp_openreq_init()
7067 ireq->acked = 0; in tcp_openreq_init()
7068 ireq->ecn_ok = 0; in tcp_openreq_init()
7069 ireq->ir_rmt_port = tcp_hdr(skb)->source; in tcp_openreq_init()
7070 ireq->ir_num = ntohs(tcp_hdr(skb)->dest); in tcp_openreq_init()
7071 ireq->ir_mark = inet_request_mark(sk, skb); in tcp_openreq_init()
7073 ireq->smc_ok = rx_opt->smc_ok && !(tcp_sk(sk)->smc_hs_congested && in tcp_openreq_init()
7074 tcp_sk(sk)->smc_hs_congested(sk)); in tcp_openreq_init()
7083 struct request_sock_queue *queue = &inet_csk(sk)->icsk_accept_queue; in tcp_syn_flood_action()
7089 syncookies = READ_ONCE(net->ipv4.sysctl_tcp_syncookies); in tcp_syn_flood_action()
7100 if (!READ_ONCE(queue->synflood_warned) && syncookies != 2 && in tcp_syn_flood_action()
7101 xchg(&queue->synflood_warned, 1) == 0) { in tcp_syn_flood_action()
7102 if (IS_ENABLED(CONFIG_IPV6) && sk->sk_family == AF_INET6) { in tcp_syn_flood_action()
7105 sk->sk_num, msg); in tcp_syn_flood_action()
7108 proto, &sk->sk_rcv_saddr, in tcp_syn_flood_action()
7109 sk->sk_num, msg); in tcp_syn_flood_action()
7120 if (tcp_sk(sk)->save_syn) { in tcp_reqsk_record_syn()
7126 if (tcp_sk(sk)->save_syn == 2) { /* Save full header. */ in tcp_reqsk_record_syn()
7138 saved_syn->mac_hdrlen = mac_hdrlen; in tcp_reqsk_record_syn()
7139 saved_syn->network_hdrlen = skb_network_header_len(skb); in tcp_reqsk_record_syn()
7140 saved_syn->tcp_hdrlen = tcp_hdrlen(skb); in tcp_reqsk_record_syn()
7141 memcpy(saved_syn->data, base, len); in tcp_reqsk_record_syn()
7142 req->saved_syn = saved_syn; in tcp_reqsk_record_syn()
7147 /* If a SYN cookie is required and supported, returns a clamped MSS value to be
7157 if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_syncookies) != 2 && in tcp_get_syncookie_mss()
7161 if (!tcp_syn_flood_action(sk, rsk_ops->slab_name)) in tcp_get_syncookie_mss()
7169 mss = tcp_parse_mss_option(th, tp->rx_opt.user_mss); in tcp_get_syncookie_mss()
7171 mss = af_ops->mss_clamp; in tcp_get_syncookie_mss()
7181 struct tcp_fastopen_cookie foc = { .len = -1 }; in tcp_conn_request()
7205 syncookies = READ_ONCE(net->ipv4.sysctl_tcp_syncookies); in tcp_conn_request()
7209 rsk_ops->slab_name); in tcp_conn_request()
7224 req->syncookie = want_cookie; in tcp_conn_request()
7225 tcp_rsk(req)->af_specific = af_ops; in tcp_conn_request()
7226 tcp_rsk(req)->ts_off = 0; in tcp_conn_request()
7227 tcp_rsk(req)->req_usec_ts = false; in tcp_conn_request()
7229 tcp_rsk(req)->is_mptcp = 0; in tcp_conn_request()
7233 tmp_opt.mss_clamp = af_ops->mss_clamp; in tcp_conn_request()
7234 tmp_opt.user_mss = tp->rx_opt.user_mss; in tcp_conn_request()
7246 inet_rsk(req)->no_srccheck = inet_test_bit(TRANSPARENT, sk); in tcp_conn_request()
7249 inet_rsk(req)->ir_iif = inet_request_bound_dev_if(sk, skb); in tcp_conn_request()
7251 dst = af_ops->route_req(sk, skb, &fl, req, isn); in tcp_conn_request()
7256 tcp_rsk(req)->req_usec_ts = dst_tcp_usec_ts(dst); in tcp_conn_request()
7257 tcp_rsk(req)->ts_off = af_ops->init_ts_off(net, skb); in tcp_conn_request()
7260 int max_syn_backlog = READ_ONCE(net->ipv4.sysctl_max_syn_backlog); in tcp_conn_request()
7264 (max_syn_backlog - inet_csk_reqsk_queue_len(sk) < in tcp_conn_request()
7274 pr_drop_req(req, ntohs(tcp_hdr(skb)->source), in tcp_conn_request()
7275 rsk_ops->family); in tcp_conn_request()
7279 isn = af_ops->init_seq(skb); in tcp_conn_request()
7285 isn = cookie_init_sequence(af_ops, sk, skb, &req->mss); in tcp_conn_request()
7287 inet_rsk(req)->ecn_ok = 0; in tcp_conn_request()
7294 tcp_rsk(req)->used_tcp_ao = true; in tcp_conn_request()
7295 tcp_rsk(req)->ao_rcv_next = aoh->keyid; in tcp_conn_request()
7296 tcp_rsk(req)->ao_keyid = aoh->rnext_keyid; in tcp_conn_request()
7299 tcp_rsk(req)->used_tcp_ao = false; in tcp_conn_request()
7302 tcp_rsk(req)->snt_isn = isn; in tcp_conn_request()
7303 tcp_rsk(req)->txhash = net_tx_rndhash(); in tcp_conn_request()
7304 tcp_rsk(req)->syn_tos = TCP_SKB_CB(skb)->ip_dsfield; in tcp_conn_request()
7312 af_ops->send_synack(fastopen_sk, dst, &fl, req, in tcp_conn_request()
7321 sk->sk_data_ready(sk); in tcp_conn_request()
7325 tcp_rsk(req)->tfo_listener = false; in tcp_conn_request()
7327 req->timeout = tcp_timeout_init((struct sock *)req); in tcp_conn_request()
7329 req->timeout))) { in tcp_conn_request()
7335 af_ops->send_synack(sk, dst, &fl, req, &foc, in tcp_conn_request()