Lines Matching refs:tp
313 static void tcp_ecn_queue_cwr(struct tcp_sock *tp) in tcp_ecn_queue_cwr() argument
315 if (tp->ecn_flags & TCP_ECN_OK) in tcp_ecn_queue_cwr()
316 tp->ecn_flags |= TCP_ECN_QUEUE_CWR; in tcp_ecn_queue_cwr()
333 static void tcp_ecn_withdraw_cwr(struct tcp_sock *tp) in tcp_ecn_withdraw_cwr() argument
335 tp->ecn_flags &= ~TCP_ECN_QUEUE_CWR; in tcp_ecn_withdraw_cwr()
340 struct tcp_sock *tp = tcp_sk(sk); in __tcp_ecn_check_ce() local
348 if (tp->ecn_flags & TCP_ECN_SEEN) in __tcp_ecn_check_ce()
355 if (!(tp->ecn_flags & TCP_ECN_DEMAND_CWR)) { in __tcp_ecn_check_ce()
358 tp->ecn_flags |= TCP_ECN_DEMAND_CWR; in __tcp_ecn_check_ce()
360 tp->ecn_flags |= TCP_ECN_SEEN; in __tcp_ecn_check_ce()
365 tp->ecn_flags |= TCP_ECN_SEEN; in __tcp_ecn_check_ce()
376 static void tcp_ecn_rcv_synack(struct tcp_sock *tp, const struct tcphdr *th) in tcp_ecn_rcv_synack() argument
378 if ((tp->ecn_flags & TCP_ECN_OK) && (!th->ece || th->cwr)) in tcp_ecn_rcv_synack()
379 tp->ecn_flags &= ~TCP_ECN_OK; in tcp_ecn_rcv_synack()
382 static void tcp_ecn_rcv_syn(struct tcp_sock *tp, const struct tcphdr *th) in tcp_ecn_rcv_syn() argument
384 if ((tp->ecn_flags & TCP_ECN_OK) && (!th->ece || !th->cwr)) in tcp_ecn_rcv_syn()
385 tp->ecn_flags &= ~TCP_ECN_OK; in tcp_ecn_rcv_syn()
388 static bool tcp_ecn_rcv_ecn_echo(const struct tcp_sock *tp, const struct tcphdr *th) in tcp_ecn_rcv_ecn_echo() argument
390 if (th->ece && !th->syn && (tp->ecn_flags & TCP_ECN_OK)) in tcp_ecn_rcv_ecn_echo()
402 const struct tcp_sock *tp = tcp_sk(sk); in tcp_sndbuf_expand() local
410 per_mss = max_t(u32, tp->rx_opt.mss_clamp, tp->mss_cache) + in tcp_sndbuf_expand()
417 nr_segs = max_t(u32, TCP_INIT_CWND, tcp_snd_cwnd(tp)); in tcp_sndbuf_expand()
418 nr_segs = max_t(u32, nr_segs, tp->reordering + 1); in tcp_sndbuf_expand()
461 struct tcp_sock *tp = tcp_sk(sk); in __tcp_grow_window() local
466 while (tp->rcv_ssthresh <= window) { in __tcp_grow_window()
498 struct tcp_sock *tp = tcp_sk(sk); in tcp_grow_window() local
501 room = min_t(int, tp->window_clamp, tcp_space(sk)) - tp->rcv_ssthresh; in tcp_grow_window()
515 incr = 2 * tp->advmss; in tcp_grow_window()
521 tp->rcv_ssthresh += min(room, incr); in tcp_grow_window()
538 struct tcp_sock *tp = tcp_sk(sk); in tcp_init_buffer_space() local
544 tcp_mstamp_refresh(tp); in tcp_init_buffer_space()
545 tp->rcvq_space.time = tp->tcp_mstamp; in tcp_init_buffer_space()
546 tp->rcvq_space.seq = tp->copied_seq; in tcp_init_buffer_space()
550 if (tp->window_clamp >= maxwin) { in tcp_init_buffer_space()
551 tp->window_clamp = maxwin; in tcp_init_buffer_space()
553 if (tcp_app_win && maxwin > 4 * tp->advmss) in tcp_init_buffer_space()
554 tp->window_clamp = max(maxwin - in tcp_init_buffer_space()
556 4 * tp->advmss); in tcp_init_buffer_space()
561 tp->window_clamp > 2 * tp->advmss && in tcp_init_buffer_space()
562 tp->window_clamp + tp->advmss > maxwin) in tcp_init_buffer_space()
563 tp->window_clamp = max(2 * tp->advmss, maxwin - tp->advmss); in tcp_init_buffer_space()
565 tp->rcv_ssthresh = min(tp->rcv_ssthresh, tp->window_clamp); in tcp_init_buffer_space()
566 tp->snd_cwnd_stamp = tcp_jiffies32; in tcp_init_buffer_space()
567 tp->rcvq_space.space = min3(tp->rcv_ssthresh, tp->rcv_wnd, in tcp_init_buffer_space()
568 (u32)TCP_INIT_CWND * tp->advmss); in tcp_init_buffer_space()
574 struct tcp_sock *tp = tcp_sk(sk); in tcp_clamp_window() local
590 tp->rcv_ssthresh = min(tp->window_clamp, 2U * tp->advmss); in tcp_clamp_window()
602 const struct tcp_sock *tp = tcp_sk(sk); in tcp_initialize_rcv_mss() local
603 unsigned int hint = min_t(unsigned int, tp->advmss, tp->mss_cache); in tcp_initialize_rcv_mss()
605 hint = min(hint, tp->rcv_wnd / 2); in tcp_initialize_rcv_mss()
624 static void tcp_rcv_rtt_update(struct tcp_sock *tp, u32 sample, int win_dep) in tcp_rcv_rtt_update() argument
626 u32 new_sample = tp->rcv_rtt_est.rtt_us; in tcp_rcv_rtt_update()
653 tp->rcv_rtt_est.rtt_us = new_sample; in tcp_rcv_rtt_update()
656 static inline void tcp_rcv_rtt_measure(struct tcp_sock *tp) in tcp_rcv_rtt_measure() argument
660 if (tp->rcv_rtt_est.time == 0) in tcp_rcv_rtt_measure()
662 if (before(tp->rcv_nxt, tp->rcv_rtt_est.seq)) in tcp_rcv_rtt_measure()
664 delta_us = tcp_stamp_us_delta(tp->tcp_mstamp, tp->rcv_rtt_est.time); in tcp_rcv_rtt_measure()
667 tcp_rcv_rtt_update(tp, delta_us, 1); in tcp_rcv_rtt_measure()
670 tp->rcv_rtt_est.seq = tp->rcv_nxt + tp->rcv_wnd; in tcp_rcv_rtt_measure()
671 tp->rcv_rtt_est.time = tp->tcp_mstamp; in tcp_rcv_rtt_measure()
677 struct tcp_sock *tp = tcp_sk(sk); in tcp_rcv_rtt_measure_ts() local
679 if (tp->rx_opt.rcv_tsecr == tp->rcv_rtt_last_tsecr) in tcp_rcv_rtt_measure_ts()
681 tp->rcv_rtt_last_tsecr = tp->rx_opt.rcv_tsecr; in tcp_rcv_rtt_measure_ts()
685 u32 delta = tcp_time_stamp(tp) - tp->rx_opt.rcv_tsecr; in tcp_rcv_rtt_measure_ts()
692 tcp_rcv_rtt_update(tp, delta_us, 0); in tcp_rcv_rtt_measure_ts()
703 struct tcp_sock *tp = tcp_sk(sk); in tcp_rcv_space_adjust() local
709 tcp_mstamp_refresh(tp); in tcp_rcv_space_adjust()
710 time = tcp_stamp_us_delta(tp->tcp_mstamp, tp->rcvq_space.time); in tcp_rcv_space_adjust()
711 if (time < (tp->rcv_rtt_est.rtt_us >> 3) || tp->rcv_rtt_est.rtt_us == 0) in tcp_rcv_space_adjust()
715 copied = tp->copied_seq - tp->rcvq_space.seq; in tcp_rcv_space_adjust()
716 if (copied <= tp->rcvq_space.space) in tcp_rcv_space_adjust()
736 rcvwin = ((u64)copied << 1) + 16 * tp->advmss; in tcp_rcv_space_adjust()
739 grow = rcvwin * (copied - tp->rcvq_space.space); in tcp_rcv_space_adjust()
740 do_div(grow, tp->rcvq_space.space); in tcp_rcv_space_adjust()
743 rcvmem = SKB_TRUESIZE(tp->advmss + MAX_TCP_HEADER); in tcp_rcv_space_adjust()
744 while (tcp_win_from_space(sk, rcvmem) < tp->advmss) in tcp_rcv_space_adjust()
747 do_div(rcvwin, tp->advmss); in tcp_rcv_space_adjust()
754 tp->window_clamp = tcp_win_from_space(sk, rcvbuf); in tcp_rcv_space_adjust()
757 tp->rcvq_space.space = copied; in tcp_rcv_space_adjust()
760 tp->rcvq_space.seq = tp->copied_seq; in tcp_rcv_space_adjust()
761 tp->rcvq_space.time = tp->tcp_mstamp; in tcp_rcv_space_adjust()
776 struct tcp_sock *tp = tcp_sk(sk); in tcp_event_data_recv() local
784 tcp_rcv_rtt_measure(tp); in tcp_event_data_recv()
830 struct tcp_sock *tp = tcp_sk(sk); in tcp_rtt_estimator() local
832 u32 srtt = tp->srtt_us; in tcp_rtt_estimator()
855 m -= (tp->mdev_us >> 2); /* similar update on mdev */ in tcp_rtt_estimator()
867 m -= (tp->mdev_us >> 2); /* similar update on mdev */ in tcp_rtt_estimator()
869 tp->mdev_us += m; /* mdev = 3/4 mdev + 1/4 new */ in tcp_rtt_estimator()
870 if (tp->mdev_us > tp->mdev_max_us) { in tcp_rtt_estimator()
871 tp->mdev_max_us = tp->mdev_us; in tcp_rtt_estimator()
872 if (tp->mdev_max_us > tp->rttvar_us) in tcp_rtt_estimator()
873 tp->rttvar_us = tp->mdev_max_us; in tcp_rtt_estimator()
875 if (after(tp->snd_una, tp->rtt_seq)) { in tcp_rtt_estimator()
876 if (tp->mdev_max_us < tp->rttvar_us) in tcp_rtt_estimator()
877 tp->rttvar_us -= (tp->rttvar_us - tp->mdev_max_us) >> 2; in tcp_rtt_estimator()
878 tp->rtt_seq = tp->snd_nxt; in tcp_rtt_estimator()
879 tp->mdev_max_us = tcp_rto_min_us(sk); in tcp_rtt_estimator()
886 tp->mdev_us = m << 1; /* make sure rto = 3*rtt */ in tcp_rtt_estimator()
887 tp->rttvar_us = max(tp->mdev_us, tcp_rto_min_us(sk)); in tcp_rtt_estimator()
888 tp->mdev_max_us = tp->rttvar_us; in tcp_rtt_estimator()
889 tp->rtt_seq = tp->snd_nxt; in tcp_rtt_estimator()
893 tp->srtt_us = max(1U, srtt); in tcp_rtt_estimator()
898 const struct tcp_sock *tp = tcp_sk(sk); in tcp_update_pacing_rate() local
902 rate = (u64)tp->mss_cache * ((USEC_PER_SEC / 100) << 3); in tcp_update_pacing_rate()
912 if (tcp_snd_cwnd(tp) < tp->snd_ssthresh / 2) in tcp_update_pacing_rate()
917 rate *= max(tcp_snd_cwnd(tp), tp->packets_out); in tcp_update_pacing_rate()
919 if (likely(tp->srtt_us)) in tcp_update_pacing_rate()
920 do_div(rate, tp->srtt_us); in tcp_update_pacing_rate()
935 const struct tcp_sock *tp = tcp_sk(sk); in tcp_set_rto() local
946 inet_csk(sk)->icsk_rto = __tcp_set_rto(tp); in tcp_set_rto()
960 __u32 tcp_init_cwnd(const struct tcp_sock *tp, const struct dst_entry *dst) in tcp_init_cwnd() argument
966 return min_t(__u32, cwnd, tp->snd_cwnd_clamp); in tcp_init_cwnd()
989 static u32 tcp_dsack_seen(struct tcp_sock *tp, u32 start_seq, in tcp_dsack_seen() argument
999 if (seq_len > tp->max_window) in tcp_dsack_seen()
1001 if (seq_len > tp->mss_cache) in tcp_dsack_seen()
1002 dup_segs = DIV_ROUND_UP(seq_len, tp->mss_cache); in tcp_dsack_seen()
1003 else if (tp->tlp_high_seq && tp->tlp_high_seq == end_seq) in tcp_dsack_seen()
1006 tp->dsack_dups += dup_segs; in tcp_dsack_seen()
1008 if (tp->dsack_dups > tp->total_retrans) in tcp_dsack_seen()
1011 tp->rx_opt.sack_ok |= TCP_DSACK_SEEN; in tcp_dsack_seen()
1018 if (tp->reord_seen && !(state->flag & FLAG_DSACK_TLP)) in tcp_dsack_seen()
1019 tp->rack.dsack_seen = 1; in tcp_dsack_seen()
1035 struct tcp_sock *tp = tcp_sk(sk); in tcp_check_sack_reordering() local
1036 const u32 mss = tp->mss_cache; in tcp_check_sack_reordering()
1039 fack = tcp_highest_sack_seq(tp); in tcp_check_sack_reordering()
1044 if ((metric > tp->reordering * mss) && mss) { in tcp_check_sack_reordering()
1047 tp->rx_opt.sack_ok, inet_csk(sk)->icsk_ca_state, in tcp_check_sack_reordering()
1048 tp->reordering, in tcp_check_sack_reordering()
1050 tp->sacked_out, in tcp_check_sack_reordering()
1051 tp->undo_marker ? tp->undo_retrans : 0); in tcp_check_sack_reordering()
1053 tp->reordering = min_t(u32, (metric + mss - 1) / mss, in tcp_check_sack_reordering()
1058 tp->reord_seen++; in tcp_check_sack_reordering()
1068 static void tcp_verify_retransmit_hint(struct tcp_sock *tp, struct sk_buff *skb) in tcp_verify_retransmit_hint() argument
1070 if ((!tp->retransmit_skb_hint && tp->retrans_out >= tp->lost_out) || in tcp_verify_retransmit_hint()
1071 (tp->retransmit_skb_hint && in tcp_verify_retransmit_hint()
1073 TCP_SKB_CB(tp->retransmit_skb_hint)->seq))) in tcp_verify_retransmit_hint()
1074 tp->retransmit_skb_hint = skb; in tcp_verify_retransmit_hint()
1080 static void tcp_notify_skb_loss_event(struct tcp_sock *tp, const struct sk_buff *skb) in tcp_notify_skb_loss_event() argument
1082 tp->lost += tcp_skb_pcount(skb); in tcp_notify_skb_loss_event()
1088 struct tcp_sock *tp = tcp_sk(sk); in tcp_mark_skb_lost() local
1093 tcp_verify_retransmit_hint(tp, skb); in tcp_mark_skb_lost()
1098 tp->retrans_out -= tcp_skb_pcount(skb); in tcp_mark_skb_lost()
1101 tcp_notify_skb_loss_event(tp, skb); in tcp_mark_skb_lost()
1104 tp->lost_out += tcp_skb_pcount(skb); in tcp_mark_skb_lost()
1106 tcp_notify_skb_loss_event(tp, skb); in tcp_mark_skb_lost()
1111 static void tcp_count_delivered(struct tcp_sock *tp, u32 delivered, in tcp_count_delivered() argument
1114 tp->delivered += delivered; in tcp_count_delivered()
1116 tp->delivered_ce += delivered; in tcp_count_delivered()
1212 static bool tcp_is_sackblock_valid(struct tcp_sock *tp, bool is_dsack, in tcp_is_sackblock_valid() argument
1216 if (after(end_seq, tp->snd_nxt) || !before(start_seq, end_seq)) in tcp_is_sackblock_valid()
1220 if (!before(start_seq, tp->snd_nxt)) in tcp_is_sackblock_valid()
1226 if (after(start_seq, tp->snd_una)) in tcp_is_sackblock_valid()
1229 if (!is_dsack || !tp->undo_marker) in tcp_is_sackblock_valid()
1233 if (after(end_seq, tp->snd_una)) in tcp_is_sackblock_valid()
1236 if (!before(start_seq, tp->undo_marker)) in tcp_is_sackblock_valid()
1240 if (!after(end_seq, tp->undo_marker)) in tcp_is_sackblock_valid()
1246 return !before(start_seq, end_seq - tp->max_window); in tcp_is_sackblock_valid()
1253 struct tcp_sock *tp = tcp_sk(sk); in tcp_check_dsack() local
1271 dup_segs = tcp_dsack_seen(tp, start_seq_0, end_seq_0, state); in tcp_check_dsack()
1280 if (tp->undo_marker && tp->undo_retrans > 0 && in tcp_check_dsack()
1282 after(end_seq_0, tp->undo_marker)) in tcp_check_dsack()
1283 tp->undo_retrans = max_t(int, 0, tp->undo_retrans - dup_segs); in tcp_check_dsack()
1351 struct tcp_sock *tp = tcp_sk(sk); in tcp_sacktag_one() local
1355 if (tp->undo_marker && tp->undo_retrans > 0 && in tcp_sacktag_one()
1356 after(end_seq, tp->undo_marker)) in tcp_sacktag_one()
1357 tp->undo_retrans = max_t(int, 0, tp->undo_retrans - pcount); in tcp_sacktag_one()
1364 if (!after(end_seq, tp->snd_una)) in tcp_sacktag_one()
1368 tcp_rack_advance(tp, sacked, end_seq, xmit_time); in tcp_sacktag_one()
1377 tp->lost_out -= pcount; in tcp_sacktag_one()
1378 tp->retrans_out -= pcount; in tcp_sacktag_one()
1386 tcp_highest_sack_seq(tp)) && in tcp_sacktag_one()
1390 if (!after(end_seq, tp->high_seq)) in tcp_sacktag_one()
1399 tp->lost_out -= pcount; in tcp_sacktag_one()
1405 tp->sacked_out += pcount; in tcp_sacktag_one()
1410 if (tp->lost_skb_hint && in tcp_sacktag_one()
1411 before(start_seq, TCP_SKB_CB(tp->lost_skb_hint)->seq)) in tcp_sacktag_one()
1412 tp->lost_cnt_hint += pcount; in tcp_sacktag_one()
1421 tp->retrans_out -= pcount; in tcp_sacktag_one()
1436 struct tcp_sock *tp = tcp_sk(sk); in tcp_shifted_skb() local
1453 if (skb == tp->lost_skb_hint) in tcp_shifted_skb()
1454 tp->lost_cnt_hint += pcount; in tcp_shifted_skb()
1486 if (skb == tp->retransmit_skb_hint) in tcp_shifted_skb()
1487 tp->retransmit_skb_hint = prev; in tcp_shifted_skb()
1488 if (skb == tp->lost_skb_hint) { in tcp_shifted_skb()
1489 tp->lost_skb_hint = prev; in tcp_shifted_skb()
1490 tp->lost_cnt_hint -= tcp_skb_pcount(prev); in tcp_shifted_skb()
1549 struct tcp_sock *tp = tcp_sk(sk); in tcp_shift_skb_data() local
1563 if (!after(TCP_SKB_CB(skb)->end_seq, tp->snd_una)) in tcp_shift_skb_data()
1643 if (!after(TCP_SKB_CB(skb)->seq + len, tp->snd_una)) in tcp_shift_skb_data()
1688 struct tcp_sock *tp = tcp_sk(sk); in tcp_sacktag_walk() local
1747 tcp_highest_sack_seq(tp))) in tcp_sacktag_walk()
1803 static int tcp_sack_cache_ok(const struct tcp_sock *tp, const struct tcp_sack_block *cache) in tcp_sack_cache_ok() argument
1805 return cache < tp->recv_sack_cache + ARRAY_SIZE(tp->recv_sack_cache); in tcp_sack_cache_ok()
1812 struct tcp_sock *tp = tcp_sk(sk); in tcp_sacktag_write_queue() local
1826 state->reord = tp->snd_nxt; in tcp_sacktag_write_queue()
1828 if (!tp->sacked_out) in tcp_sacktag_write_queue()
1838 if (before(TCP_SKB_CB(ack_skb)->ack_seq, prior_snd_una - tp->max_window)) in tcp_sacktag_write_queue()
1841 if (!tp->packets_out) in tcp_sacktag_write_queue()
1852 if (!tcp_is_sackblock_valid(tp, dup_sack, in tcp_sacktag_write_queue()
1858 if (!tp->undo_marker) in tcp_sacktag_write_queue()
1864 if ((TCP_SKB_CB(ack_skb)->ack_seq != tp->snd_una) && in tcp_sacktag_write_queue()
1865 !after(sp[used_sacks].end_seq, tp->snd_una)) in tcp_sacktag_write_queue()
1903 if (!tp->sacked_out) { in tcp_sacktag_write_queue()
1905 cache = tp->recv_sack_cache + ARRAY_SIZE(tp->recv_sack_cache); in tcp_sacktag_write_queue()
1907 cache = tp->recv_sack_cache; in tcp_sacktag_write_queue()
1909 while (tcp_sack_cache_ok(tp, cache) && !cache->start_seq && in tcp_sacktag_write_queue()
1924 while (tcp_sack_cache_ok(tp, cache) && in tcp_sacktag_write_queue()
1929 if (tcp_sack_cache_ok(tp, cache) && !dup_sack && in tcp_sacktag_write_queue()
1951 if (tcp_highest_sack_seq(tp) == cache->end_seq) { in tcp_sacktag_write_queue()
1966 if (!before(start_seq, tcp_highest_sack_seq(tp))) { in tcp_sacktag_write_queue()
1982 for (i = 0; i < ARRAY_SIZE(tp->recv_sack_cache) - used_sacks; i++) { in tcp_sacktag_write_queue()
1983 tp->recv_sack_cache[i].start_seq = 0; in tcp_sacktag_write_queue()
1984 tp->recv_sack_cache[i].end_seq = 0; in tcp_sacktag_write_queue()
1987 tp->recv_sack_cache[i++] = sp[j]; in tcp_sacktag_write_queue()
1989 if (inet_csk(sk)->icsk_ca_state != TCP_CA_Loss || tp->undo_marker) in tcp_sacktag_write_queue()
1992 tcp_verify_left_out(tp); in tcp_sacktag_write_queue()
1996 WARN_ON((int)tp->sacked_out < 0); in tcp_sacktag_write_queue()
1997 WARN_ON((int)tp->lost_out < 0); in tcp_sacktag_write_queue()
1998 WARN_ON((int)tp->retrans_out < 0); in tcp_sacktag_write_queue()
1999 WARN_ON((int)tcp_packets_in_flight(tp) < 0); in tcp_sacktag_write_queue()
2007 static bool tcp_limit_reno_sacked(struct tcp_sock *tp) in tcp_limit_reno_sacked() argument
2011 holes = max(tp->lost_out, 1U); in tcp_limit_reno_sacked()
2012 holes = min(holes, tp->packets_out); in tcp_limit_reno_sacked()
2014 if ((tp->sacked_out + holes) > tp->packets_out) { in tcp_limit_reno_sacked()
2015 tp->sacked_out = tp->packets_out - holes; in tcp_limit_reno_sacked()
2027 struct tcp_sock *tp = tcp_sk(sk); in tcp_check_reno_reordering() local
2029 if (!tcp_limit_reno_sacked(tp)) in tcp_check_reno_reordering()
2032 tp->reordering = min_t(u32, tp->packets_out + addend, in tcp_check_reno_reordering()
2034 tp->reord_seen++; in tcp_check_reno_reordering()
2043 struct tcp_sock *tp = tcp_sk(sk); in tcp_add_reno_sack() local
2044 u32 prior_sacked = tp->sacked_out; in tcp_add_reno_sack()
2047 tp->sacked_out += num_dupack; in tcp_add_reno_sack()
2049 delivered = tp->sacked_out - prior_sacked; in tcp_add_reno_sack()
2051 tcp_count_delivered(tp, delivered, ece_ack); in tcp_add_reno_sack()
2052 tcp_verify_left_out(tp); in tcp_add_reno_sack()
2060 struct tcp_sock *tp = tcp_sk(sk); in tcp_remove_reno_sacks() local
2064 tcp_count_delivered(tp, max_t(int, acked - tp->sacked_out, 1), in tcp_remove_reno_sacks()
2066 if (acked - 1 >= tp->sacked_out) in tcp_remove_reno_sacks()
2067 tp->sacked_out = 0; in tcp_remove_reno_sacks()
2069 tp->sacked_out -= acked - 1; in tcp_remove_reno_sacks()
2072 tcp_verify_left_out(tp); in tcp_remove_reno_sacks()
2075 static inline void tcp_reset_reno_sack(struct tcp_sock *tp) in tcp_reset_reno_sack() argument
2077 tp->sacked_out = 0; in tcp_reset_reno_sack()
2080 void tcp_clear_retrans(struct tcp_sock *tp) in tcp_clear_retrans() argument
2082 tp->retrans_out = 0; in tcp_clear_retrans()
2083 tp->lost_out = 0; in tcp_clear_retrans()
2084 tp->undo_marker = 0; in tcp_clear_retrans()
2085 tp->undo_retrans = -1; in tcp_clear_retrans()
2086 tp->sacked_out = 0; in tcp_clear_retrans()
2089 static inline void tcp_init_undo(struct tcp_sock *tp) in tcp_init_undo() argument
2091 tp->undo_marker = tp->snd_una; in tcp_init_undo()
2093 tp->undo_retrans = tp->retrans_out ? : -1; in tcp_init_undo()
2108 struct tcp_sock *tp = tcp_sk(sk); in tcp_timeout_mark_lost() local
2116 tp->sacked_out = 0; in tcp_timeout_mark_lost()
2118 tp->is_sack_reneg = 1; in tcp_timeout_mark_lost()
2119 } else if (tcp_is_reno(tp)) { in tcp_timeout_mark_lost()
2120 tcp_reset_reno_sack(tp); in tcp_timeout_mark_lost()
2128 tcp_rack_skb_timeout(tp, skb, 0) > 0) in tcp_timeout_mark_lost()
2132 tcp_verify_left_out(tp); in tcp_timeout_mark_lost()
2133 tcp_clear_all_retrans_hints(tp); in tcp_timeout_mark_lost()
2140 struct tcp_sock *tp = tcp_sk(sk); in tcp_enter_loss() local
2149 !after(tp->high_seq, tp->snd_una) || in tcp_enter_loss()
2151 tp->prior_ssthresh = tcp_current_ssthresh(sk); in tcp_enter_loss()
2152 tp->prior_cwnd = tcp_snd_cwnd(tp); in tcp_enter_loss()
2153 tp->snd_ssthresh = icsk->icsk_ca_ops->ssthresh(sk); in tcp_enter_loss()
2155 tcp_init_undo(tp); in tcp_enter_loss()
2157 tcp_snd_cwnd_set(tp, tcp_packets_in_flight(tp) + 1); in tcp_enter_loss()
2158 tp->snd_cwnd_cnt = 0; in tcp_enter_loss()
2159 tp->snd_cwnd_stamp = tcp_jiffies32; in tcp_enter_loss()
2166 tp->sacked_out >= reordering) in tcp_enter_loss()
2167 tp->reordering = min_t(unsigned int, tp->reordering, in tcp_enter_loss()
2171 tp->high_seq = tp->snd_nxt; in tcp_enter_loss()
2172 tcp_ecn_queue_cwr(tp); in tcp_enter_loss()
2178 tp->frto = READ_ONCE(net->ipv4.sysctl_tcp_frto) && in tcp_enter_loss()
2197 struct tcp_sock *tp = tcp_sk(sk); in tcp_check_sack_reneging() local
2198 unsigned long delay = max(usecs_to_jiffies(tp->srtt_us >> 4), in tcp_check_sack_reneging()
2219 static inline int tcp_dupack_heuristics(const struct tcp_sock *tp) in tcp_dupack_heuristics() argument
2221 return tp->sacked_out + 1; in tcp_dupack_heuristics()
2323 struct tcp_sock *tp = tcp_sk(sk); in tcp_time_to_recover() local
2326 if (tp->lost_out) in tcp_time_to_recover()
2330 if (!tcp_is_rack(sk) && tcp_dupack_heuristics(tp) > tp->reordering) in tcp_time_to_recover()
2343 struct tcp_sock *tp = tcp_sk(sk); in tcp_mark_head_lost() local
2347 const u32 loss_high = tp->snd_nxt; in tcp_mark_head_lost()
2349 WARN_ON(packets > tp->packets_out); in tcp_mark_head_lost()
2350 skb = tp->lost_skb_hint; in tcp_mark_head_lost()
2353 if (mark_head && after(TCP_SKB_CB(skb)->seq, tp->snd_una)) in tcp_mark_head_lost()
2355 cnt = tp->lost_cnt_hint; in tcp_mark_head_lost()
2364 tp->lost_skb_hint = skb; in tcp_mark_head_lost()
2365 tp->lost_cnt_hint = cnt; in tcp_mark_head_lost()
2382 tcp_verify_left_out(tp); in tcp_mark_head_lost()
2389 struct tcp_sock *tp = tcp_sk(sk); in tcp_update_scoreboard() local
2391 if (tcp_is_sack(tp)) { in tcp_update_scoreboard()
2392 int sacked_upto = tp->sacked_out - tp->reordering; in tcp_update_scoreboard()
2400 static bool tcp_tsopt_ecr_before(const struct tcp_sock *tp, u32 when) in tcp_tsopt_ecr_before() argument
2402 return tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr && in tcp_tsopt_ecr_before()
2403 before(tp->rx_opt.rcv_tsecr, when); in tcp_tsopt_ecr_before()
2409 static bool tcp_skb_spurious_retrans(const struct tcp_sock *tp, in tcp_skb_spurious_retrans() argument
2413 tcp_tsopt_ecr_before(tp, tcp_skb_timestamp(skb)); in tcp_skb_spurious_retrans()
2419 static inline bool tcp_packet_delayed(const struct tcp_sock *tp) in tcp_packet_delayed() argument
2421 return tp->retrans_stamp && in tcp_packet_delayed()
2422 tcp_tsopt_ecr_before(tp, tp->retrans_stamp); in tcp_packet_delayed()
2443 const struct tcp_sock *tp = tcp_sk(sk); in tcp_any_retrans_done() local
2446 if (tp->retrans_out) in tcp_any_retrans_done()
2459 struct tcp_sock *tp = tcp_sk(sk); in DBGUNDO() local
2466 tcp_snd_cwnd(tp), tcp_left_out(tp), in DBGUNDO()
2467 tp->snd_ssthresh, tp->prior_ssthresh, in DBGUNDO()
2468 tp->packets_out); in DBGUNDO()
2475 tcp_snd_cwnd(tp), tcp_left_out(tp), in DBGUNDO()
2476 tp->snd_ssthresh, tp->prior_ssthresh, in DBGUNDO()
2477 tp->packets_out); in DBGUNDO()
2485 struct tcp_sock *tp = tcp_sk(sk); in tcp_undo_cwnd_reduction() local
2493 tp->lost_out = 0; in tcp_undo_cwnd_reduction()
2494 tcp_clear_all_retrans_hints(tp); in tcp_undo_cwnd_reduction()
2497 if (tp->prior_ssthresh) { in tcp_undo_cwnd_reduction()
2500 tcp_snd_cwnd_set(tp, icsk->icsk_ca_ops->undo_cwnd(sk)); in tcp_undo_cwnd_reduction()
2502 if (tp->prior_ssthresh > tp->snd_ssthresh) { in tcp_undo_cwnd_reduction()
2503 tp->snd_ssthresh = tp->prior_ssthresh; in tcp_undo_cwnd_reduction()
2504 tcp_ecn_withdraw_cwr(tp); in tcp_undo_cwnd_reduction()
2507 tp->snd_cwnd_stamp = tcp_jiffies32; in tcp_undo_cwnd_reduction()
2508 tp->undo_marker = 0; in tcp_undo_cwnd_reduction()
2509 tp->rack.advanced = 1; /* Force RACK to re-exam losses */ in tcp_undo_cwnd_reduction()
2512 static inline bool tcp_may_undo(const struct tcp_sock *tp) in tcp_may_undo() argument
2514 return tp->undo_marker && (!tp->undo_retrans || tcp_packet_delayed(tp)); in tcp_may_undo()
2519 struct tcp_sock *tp = tcp_sk(sk); in tcp_is_non_sack_preventing_reopen() local
2521 if (tp->snd_una == tp->high_seq && tcp_is_reno(tp)) { in tcp_is_non_sack_preventing_reopen()
2526 tp->retrans_stamp = 0; in tcp_is_non_sack_preventing_reopen()
2535 struct tcp_sock *tp = tcp_sk(sk); in tcp_try_undo_recovery() local
2537 if (tcp_may_undo(tp)) { in tcp_try_undo_recovery()
2551 } else if (tp->rack.reo_wnd_persist) { in tcp_try_undo_recovery()
2552 tp->rack.reo_wnd_persist--; in tcp_try_undo_recovery()
2557 tp->is_sack_reneg = 0; in tcp_try_undo_recovery()
2564 struct tcp_sock *tp = tcp_sk(sk); in tcp_try_undo_dsack() local
2566 if (tp->undo_marker && !tp->undo_retrans) { in tcp_try_undo_dsack()
2567 tp->rack.reo_wnd_persist = min(TCP_RACK_RECOVERY_THRESH, in tcp_try_undo_dsack()
2568 tp->rack.reo_wnd_persist + 1); in tcp_try_undo_dsack()
2580 struct tcp_sock *tp = tcp_sk(sk); in tcp_try_undo_loss() local
2582 if (frto_undo || tcp_may_undo(tp)) { in tcp_try_undo_loss()
2593 if (frto_undo || tcp_is_sack(tp)) { in tcp_try_undo_loss()
2595 tp->is_sack_reneg = 0; in tcp_try_undo_loss()
2613 struct tcp_sock *tp = tcp_sk(sk); in tcp_init_cwnd_reduction() local
2615 tp->high_seq = tp->snd_nxt; in tcp_init_cwnd_reduction()
2616 tp->tlp_high_seq = 0; in tcp_init_cwnd_reduction()
2617 tp->snd_cwnd_cnt = 0; in tcp_init_cwnd_reduction()
2618 tp->prior_cwnd = tcp_snd_cwnd(tp); in tcp_init_cwnd_reduction()
2619 tp->prr_delivered = 0; in tcp_init_cwnd_reduction()
2620 tp->prr_out = 0; in tcp_init_cwnd_reduction()
2621 tp->snd_ssthresh = inet_csk(sk)->icsk_ca_ops->ssthresh(sk); in tcp_init_cwnd_reduction()
2622 tcp_ecn_queue_cwr(tp); in tcp_init_cwnd_reduction()
2627 struct tcp_sock *tp = tcp_sk(sk); in tcp_cwnd_reduction() local
2629 int delta = tp->snd_ssthresh - tcp_packets_in_flight(tp); in tcp_cwnd_reduction()
2631 if (newly_acked_sacked <= 0 || WARN_ON_ONCE(!tp->prior_cwnd)) in tcp_cwnd_reduction()
2634 tp->prr_delivered += newly_acked_sacked; in tcp_cwnd_reduction()
2636 u64 dividend = (u64)tp->snd_ssthresh * tp->prr_delivered + in tcp_cwnd_reduction()
2637 tp->prior_cwnd - 1; in tcp_cwnd_reduction()
2638 sndcnt = div_u64(dividend, tp->prior_cwnd) - tp->prr_out; in tcp_cwnd_reduction()
2640 sndcnt = max_t(int, tp->prr_delivered - tp->prr_out, in tcp_cwnd_reduction()
2647 sndcnt = max(sndcnt, (tp->prr_out ? 0 : 1)); in tcp_cwnd_reduction()
2648 tcp_snd_cwnd_set(tp, tcp_packets_in_flight(tp) + sndcnt); in tcp_cwnd_reduction()
2653 struct tcp_sock *tp = tcp_sk(sk); in tcp_end_cwnd_reduction() local
2659 if (tp->snd_ssthresh < TCP_INFINITE_SSTHRESH && in tcp_end_cwnd_reduction()
2660 (inet_csk(sk)->icsk_ca_state == TCP_CA_CWR || tp->undo_marker)) { in tcp_end_cwnd_reduction()
2661 tcp_snd_cwnd_set(tp, tp->snd_ssthresh); in tcp_end_cwnd_reduction()
2662 tp->snd_cwnd_stamp = tcp_jiffies32; in tcp_end_cwnd_reduction()
2670 struct tcp_sock *tp = tcp_sk(sk); in tcp_enter_cwr() local
2672 tp->prior_ssthresh = 0; in tcp_enter_cwr()
2674 tp->undo_marker = 0; in tcp_enter_cwr()
2683 struct tcp_sock *tp = tcp_sk(sk); in tcp_try_keep_open() local
2686 if (tcp_left_out(tp) || tcp_any_retrans_done(sk)) in tcp_try_keep_open()
2691 tp->high_seq = tp->snd_nxt; in tcp_try_keep_open()
2697 struct tcp_sock *tp = tcp_sk(sk); in tcp_try_to_open() local
2699 tcp_verify_left_out(tp); in tcp_try_to_open()
2702 tp->retrans_stamp = 0; in tcp_try_to_open()
2723 struct tcp_sock *tp = tcp_sk(sk); in tcp_mtup_probe_success() local
2727 tp->prior_ssthresh = tcp_current_ssthresh(sk); in tcp_mtup_probe_success()
2729 val = (u64)tcp_snd_cwnd(tp) * tcp_mss_to_mtu(sk, tp->mss_cache); in tcp_mtup_probe_success()
2732 tcp_snd_cwnd_set(tp, max_t(u32, 1U, val)); in tcp_mtup_probe_success()
2734 tp->snd_cwnd_cnt = 0; in tcp_mtup_probe_success()
2735 tp->snd_cwnd_stamp = tcp_jiffies32; in tcp_mtup_probe_success()
2736 tp->snd_ssthresh = tcp_current_ssthresh(sk); in tcp_mtup_probe_success()
2751 struct tcp_sock *tp = tcp_sk(sk); in tcp_simple_retransmit() local
2765 if (tp->syn_data && sk->sk_state == TCP_SYN_SENT) in tcp_simple_retransmit()
2775 tcp_clear_retrans_hints_partial(tp); in tcp_simple_retransmit()
2777 if (!tp->lost_out) in tcp_simple_retransmit()
2780 if (tcp_is_reno(tp)) in tcp_simple_retransmit()
2781 tcp_limit_reno_sacked(tp); in tcp_simple_retransmit()
2783 tcp_verify_left_out(tp); in tcp_simple_retransmit()
2791 tp->high_seq = tp->snd_nxt; in tcp_simple_retransmit()
2792 tp->snd_ssthresh = tcp_current_ssthresh(sk); in tcp_simple_retransmit()
2793 tp->prior_ssthresh = 0; in tcp_simple_retransmit()
2794 tp->undo_marker = 0; in tcp_simple_retransmit()
2803 struct tcp_sock *tp = tcp_sk(sk); in tcp_enter_recovery() local
2806 if (tcp_is_reno(tp)) in tcp_enter_recovery()
2813 tp->prior_ssthresh = 0; in tcp_enter_recovery()
2814 tcp_init_undo(tp); in tcp_enter_recovery()
2818 tp->prior_ssthresh = tcp_current_ssthresh(sk); in tcp_enter_recovery()
2830 struct tcp_sock *tp = tcp_sk(sk); in tcp_process_loss() local
2831 bool recovered = !before(tp->snd_una, tp->high_seq); in tcp_process_loss()
2833 if ((flag & FLAG_SND_UNA_ADVANCED || rcu_access_pointer(tp->fastopen_rsk)) && in tcp_process_loss()
2837 if (tp->frto) { /* F-RTO RFC5682 sec 3.1 (sack enhanced version). */ in tcp_process_loss()
2845 if (after(tp->snd_nxt, tp->high_seq)) { in tcp_process_loss()
2847 tp->frto = 0; /* Step 3.a. loss was real */ in tcp_process_loss()
2849 tp->high_seq = tp->snd_nxt; in tcp_process_loss()
2855 after(tcp_wnd_end(tp), tp->snd_nxt)) { in tcp_process_loss()
2859 tp->frto = 0; in tcp_process_loss()
2868 if (tcp_is_reno(tp)) { in tcp_process_loss()
2872 if (after(tp->snd_nxt, tp->high_seq) && num_dupack) in tcp_process_loss()
2875 tcp_reset_reno_sack(tp); in tcp_process_loss()
2882 struct tcp_sock *tp = tcp_sk(sk); in tcp_force_fast_retransmit() local
2884 return after(tcp_highest_sack_seq(tp), in tcp_force_fast_retransmit()
2885 tp->snd_una + tp->reordering * tp->mss_cache); in tcp_force_fast_retransmit()
2892 struct tcp_sock *tp = tcp_sk(sk); in tcp_try_undo_partial() local
2894 if (tp->undo_marker && tcp_packet_delayed(tp)) { in tcp_try_undo_partial()
2905 if (tp->retrans_out) in tcp_try_undo_partial()
2909 tp->retrans_stamp = 0; in tcp_try_undo_partial()
2924 struct tcp_sock *tp = tcp_sk(sk); in tcp_identify_packet_loss() local
2929 if (unlikely(tcp_is_reno(tp))) { in tcp_identify_packet_loss()
2932 u32 prior_retrans = tp->retrans_out; in tcp_identify_packet_loss()
2936 if (prior_retrans > tp->retrans_out) in tcp_identify_packet_loss()
2957 struct tcp_sock *tp = tcp_sk(sk); in tcp_fastretrans_alert() local
2963 if (!tp->packets_out && tp->sacked_out) in tcp_fastretrans_alert()
2964 tp->sacked_out = 0; in tcp_fastretrans_alert()
2969 tp->prior_ssthresh = 0; in tcp_fastretrans_alert()
2976 tcp_verify_left_out(tp); in tcp_fastretrans_alert()
2981 WARN_ON(tp->retrans_out != 0 && !tp->syn_data); in tcp_fastretrans_alert()
2982 tp->retrans_stamp = 0; in tcp_fastretrans_alert()
2983 } else if (!before(tp->snd_una, tp->high_seq)) { in tcp_fastretrans_alert()
2988 if (tp->snd_una != tp->high_seq) { in tcp_fastretrans_alert()
2995 if (tcp_is_reno(tp)) in tcp_fastretrans_alert()
2996 tcp_reset_reno_sack(tp); in tcp_fastretrans_alert()
3008 if (tcp_is_reno(tp)) in tcp_fastretrans_alert()
3035 if (tcp_is_reno(tp)) { in tcp_fastretrans_alert()
3037 tcp_reset_reno_sack(tp); in tcp_fastretrans_alert()
3053 tp->snd_una == tp->mtu_probe.probe_seq_start) { in tcp_fastretrans_alert()
3056 tcp_snd_cwnd_set(tp, tcp_snd_cwnd(tp) + 1); in tcp_fastretrans_alert()
3074 struct tcp_sock *tp = tcp_sk(sk); in tcp_update_rtt_min() local
3076 if ((flag & FLAG_ACK_MAYBE_DELAYED) && rtt_us > tcp_min_rtt(tp)) { in tcp_update_rtt_min()
3083 minmax_running_min(&tp->rtt_min, wlen, tcp_jiffies32, in tcp_update_rtt_min()
3091 const struct tcp_sock *tp = tcp_sk(sk); in tcp_ack_update_rtt() local
3107 if (seq_rtt_us < 0 && tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr && in tcp_ack_update_rtt()
3109 u32 delta = tcp_time_stamp(tp) - tp->rx_opt.rcv_tsecr; in tcp_ack_update_rtt()
3162 struct tcp_sock *tp = tcp_sk(sk); in tcp_rearm_rto() local
3167 if (rcu_access_pointer(tp->fastopen_rsk)) in tcp_rearm_rto()
3170 if (!tp->packets_out) { in tcp_rearm_rto()
3198 struct tcp_sock *tp = tcp_sk(sk); in tcp_tso_acked() local
3201 BUG_ON(!after(TCP_SKB_CB(skb)->end_seq, tp->snd_una)); in tcp_tso_acked()
3204 if (tcp_trim_head(sk, skb, tp->snd_una - TCP_SKB_CB(skb)->seq)) in tcp_tso_acked()
3244 struct tcp_sock *tp = tcp_sk(sk); in tcp_clean_rtx_queue() local
3245 u32 prior_sacked = tp->sacked_out; in tcp_clean_rtx_queue()
3246 u32 reord = tp->snd_nxt; /* lowest acked un-retx un-sacked seq */ in tcp_clean_rtx_queue()
3265 if (after(scb->end_seq, tp->snd_una)) { in tcp_clean_rtx_queue()
3267 !after(tp->snd_una, scb->seq)) in tcp_clean_rtx_queue()
3280 tp->retrans_out -= acked_pcount; in tcp_clean_rtx_queue()
3290 if (!after(scb->end_seq, tp->high_seq)) in tcp_clean_rtx_queue()
3295 tp->sacked_out -= acked_pcount; in tcp_clean_rtx_queue()
3296 } else if (tcp_is_sack(tp)) { in tcp_clean_rtx_queue()
3297 tcp_count_delivered(tp, acked_pcount, ece_ack); in tcp_clean_rtx_queue()
3298 if (!tcp_skb_spurious_retrans(tp, skb)) in tcp_clean_rtx_queue()
3299 tcp_rack_advance(tp, sacked, scb->end_seq, in tcp_clean_rtx_queue()
3303 tp->lost_out -= acked_pcount; in tcp_clean_rtx_queue()
3305 tp->packets_out -= acked_pcount; in tcp_clean_rtx_queue()
3320 tp->retrans_stamp = 0; in tcp_clean_rtx_queue()
3329 if (unlikely(skb == tp->retransmit_skb_hint)) in tcp_clean_rtx_queue()
3330 tp->retransmit_skb_hint = NULL; in tcp_clean_rtx_queue()
3331 if (unlikely(skb == tp->lost_skb_hint)) in tcp_clean_rtx_queue()
3332 tp->lost_skb_hint = NULL; in tcp_clean_rtx_queue()
3340 if (likely(between(tp->snd_up, prior_snd_una, tp->snd_una))) in tcp_clean_rtx_queue()
3341 tp->snd_up = tp->snd_una; in tcp_clean_rtx_queue()
3350 seq_rtt_us = tcp_stamp_us_delta(tp->tcp_mstamp, first_ackt); in tcp_clean_rtx_queue()
3351 ca_rtt_us = tcp_stamp_us_delta(tp->tcp_mstamp, last_ackt); in tcp_clean_rtx_queue()
3354 (tp->snd_una - prior_snd_una) < tp->mss_cache && in tcp_clean_rtx_queue()
3355 sack->rate->prior_delivered + 1 == tp->delivered && in tcp_clean_rtx_queue()
3365 sack_rtt_us = tcp_stamp_us_delta(tp->tcp_mstamp, sack->first_sackt); in tcp_clean_rtx_queue()
3366 ca_rtt_us = tcp_stamp_us_delta(tp->tcp_mstamp, sack->last_sackt); in tcp_clean_rtx_queue()
3374 !after(tp->mtu_probe.probe_seq_end, tp->snd_una))) { in tcp_clean_rtx_queue()
3378 if (tcp_is_reno(tp)) { in tcp_clean_rtx_queue()
3396 delta = prior_sacked - tp->sacked_out; in tcp_clean_rtx_queue()
3397 tp->lost_cnt_hint -= min(tp->lost_cnt_hint, delta); in tcp_clean_rtx_queue()
3400 sack_rtt_us > tcp_stamp_us_delta(tp->tcp_mstamp, in tcp_clean_rtx_queue()
3413 sample.in_flight = tp->mss_cache * in tcp_clean_rtx_queue()
3414 (tp->delivered - sack->rate->prior_delivered); in tcp_clean_rtx_queue()
3419 WARN_ON((int)tp->sacked_out < 0); in tcp_clean_rtx_queue()
3420 WARN_ON((int)tp->lost_out < 0); in tcp_clean_rtx_queue()
3421 WARN_ON((int)tp->retrans_out < 0); in tcp_clean_rtx_queue()
3422 if (!tp->packets_out && tcp_is_sack(tp)) { in tcp_clean_rtx_queue()
3424 if (tp->lost_out) { in tcp_clean_rtx_queue()
3426 tp->lost_out, icsk->icsk_ca_state); in tcp_clean_rtx_queue()
3427 tp->lost_out = 0; in tcp_clean_rtx_queue()
3429 if (tp->sacked_out) { in tcp_clean_rtx_queue()
3431 tp->sacked_out, icsk->icsk_ca_state); in tcp_clean_rtx_queue()
3432 tp->sacked_out = 0; in tcp_clean_rtx_queue()
3434 if (tp->retrans_out) { in tcp_clean_rtx_queue()
3436 tp->retrans_out, icsk->icsk_ca_state); in tcp_clean_rtx_queue()
3437 tp->retrans_out = 0; in tcp_clean_rtx_queue()
3448 const struct tcp_sock *tp = tcp_sk(sk); in tcp_ack_probe() local
3453 if (!after(TCP_SKB_CB(head)->end_seq, tcp_wnd_end(tp))) { in tcp_ack_probe()
3518 static inline bool tcp_may_update_window(const struct tcp_sock *tp, in tcp_may_update_window() argument
3522 return after(ack, tp->snd_una) || in tcp_may_update_window()
3523 after(ack_seq, tp->snd_wl1) || in tcp_may_update_window()
3524 (ack_seq == tp->snd_wl1 && nwin > tp->snd_wnd); in tcp_may_update_window()
3528 static void tcp_snd_una_update(struct tcp_sock *tp, u32 ack) in tcp_snd_una_update() argument
3530 u32 delta = ack - tp->snd_una; in tcp_snd_una_update()
3532 sock_owned_by_me((struct sock *)tp); in tcp_snd_una_update()
3533 tp->bytes_acked += delta; in tcp_snd_una_update()
3534 tp->snd_una = ack; in tcp_snd_una_update()
3538 static void tcp_rcv_nxt_update(struct tcp_sock *tp, u32 seq) in tcp_rcv_nxt_update() argument
3540 u32 delta = seq - tp->rcv_nxt; in tcp_rcv_nxt_update()
3542 sock_owned_by_me((struct sock *)tp); in tcp_rcv_nxt_update()
3543 tp->bytes_received += delta; in tcp_rcv_nxt_update()
3544 WRITE_ONCE(tp->rcv_nxt, seq); in tcp_rcv_nxt_update()
3555 struct tcp_sock *tp = tcp_sk(sk); in tcp_ack_update_window() local
3560 nwin <<= tp->rx_opt.snd_wscale; in tcp_ack_update_window()
3562 if (tcp_may_update_window(tp, ack, ack_seq, nwin)) { in tcp_ack_update_window()
3564 tcp_update_wl(tp, ack_seq); in tcp_ack_update_window()
3566 if (tp->snd_wnd != nwin) { in tcp_ack_update_window()
3567 tp->snd_wnd = nwin; in tcp_ack_update_window()
3572 tp->pred_flags = 0; in tcp_ack_update_window()
3578 if (nwin > tp->max_window) { in tcp_ack_update_window()
3579 tp->max_window = nwin; in tcp_ack_update_window()
3585 tcp_snd_una_update(tp, ack); in tcp_ack_update_window()
3629 struct tcp_sock *tp = tcp_sk(sk); in tcp_send_challenge_ack() local
3636 &tp->last_oow_ack_time)) in tcp_send_challenge_ack()
3660 static void tcp_store_ts_recent(struct tcp_sock *tp) in tcp_store_ts_recent() argument
3662 tp->rx_opt.ts_recent = tp->rx_opt.rcv_tsval; in tcp_store_ts_recent()
3663 tp->rx_opt.ts_recent_stamp = ktime_get_seconds(); in tcp_store_ts_recent()
3666 static void tcp_replace_ts_recent(struct tcp_sock *tp, u32 seq) in tcp_replace_ts_recent() argument
3668 if (tp->rx_opt.saw_tstamp && !after(seq, tp->rcv_wup)) { in tcp_replace_ts_recent()
3676 if (tcp_paws_check(&tp->rx_opt, 0)) in tcp_replace_ts_recent()
3677 tcp_store_ts_recent(tp); in tcp_replace_ts_recent()
3686 struct tcp_sock *tp = tcp_sk(sk); in tcp_process_tlp_ack() local
3688 if (before(ack, tp->tlp_high_seq)) in tcp_process_tlp_ack()
3691 if (!tp->tlp_retrans) { in tcp_process_tlp_ack()
3693 tp->tlp_high_seq = 0; in tcp_process_tlp_ack()
3696 tp->tlp_high_seq = 0; in tcp_process_tlp_ack()
3697 } else if (after(ack, tp->tlp_high_seq)) { in tcp_process_tlp_ack()
3710 tp->tlp_high_seq = 0; in tcp_process_tlp_ack()
3728 struct tcp_sock *tp = tcp_sk(sk); in tcp_xmit_recovery() local
3736 if (after(tp->snd_nxt, tp->high_seq)) in tcp_xmit_recovery()
3738 tp->frto = 0; in tcp_xmit_recovery()
3747 struct tcp_sock *tp = tcp_sk(sk); in tcp_newly_delivered() local
3750 delivered = tp->delivered - prior_delivered; in tcp_newly_delivered()
3762 struct tcp_sock *tp = tcp_sk(sk); in tcp_ack() local
3765 u32 prior_snd_una = tp->snd_una; in tcp_ack()
3766 bool is_sack_reneg = tp->is_sack_reneg; in tcp_ack()
3770 int prior_packets = tp->packets_out; in tcp_ack()
3771 u32 delivered = tp->delivered; in tcp_ack()
3772 u32 lost = tp->lost; in tcp_ack()
3788 if (before(ack, prior_snd_una - tp->max_window)) { in tcp_ack()
3799 if (after(ack, tp->snd_nxt)) in tcp_ack()
3813 prior_fack = tcp_is_sack(tp) ? tcp_highest_sack_seq(tp) : tp->snd_una; in tcp_ack()
3814 rs.prior_in_flight = tcp_packets_in_flight(tp); in tcp_ack()
3820 tcp_replace_ts_recent(tp, TCP_SKB_CB(skb)->seq); in tcp_ack()
3828 tcp_update_wl(tp, ack_seq); in tcp_ack()
3829 tcp_snd_una_update(tp, ack); in tcp_ack()
3849 if (tcp_ecn_rcv_ecn_echo(tp, tcp_hdr(skb))) { in tcp_ack()
3855 tcp_count_delivered(tp, sack_state.sack_delivered, in tcp_ack()
3878 tp->rcv_tstamp = tcp_jiffies32; in tcp_ack()
3888 if (tp->tlp_high_seq) in tcp_ack()
3911 lost = tp->lost - lost; /* freshly marked lost */ in tcp_ack()
3931 if (tp->tlp_high_seq) in tcp_ack()
4159 static bool tcp_parse_aligned_timestamp(struct tcp_sock *tp, const struct tcphdr *th) in tcp_parse_aligned_timestamp() argument
4165 tp->rx_opt.saw_tstamp = 1; in tcp_parse_aligned_timestamp()
4167 tp->rx_opt.rcv_tsval = ntohl(*ptr); in tcp_parse_aligned_timestamp()
4170 tp->rx_opt.rcv_tsecr = ntohl(*ptr) - tp->tsoffset; in tcp_parse_aligned_timestamp()
4172 tp->rx_opt.rcv_tsecr = 0; in tcp_parse_aligned_timestamp()
4183 const struct tcphdr *th, struct tcp_sock *tp) in tcp_fast_parse_options() argument
4189 tp->rx_opt.saw_tstamp = 0; in tcp_fast_parse_options()
4191 } else if (tp->rx_opt.tstamp_ok && in tcp_fast_parse_options()
4193 if (tcp_parse_aligned_timestamp(tp, th)) in tcp_fast_parse_options()
4197 tcp_parse_options(net, skb, &tp->rx_opt, 1, NULL); in tcp_fast_parse_options()
4198 if (tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr) in tcp_fast_parse_options()
4199 tp->rx_opt.rcv_tsecr -= tp->tsoffset; in tcp_fast_parse_options()
4264 const struct tcp_sock *tp = tcp_sk(sk); in tcp_disordered_ack() local
4270 (th->ack && seq == TCP_SKB_CB(skb)->end_seq && seq == tp->rcv_nxt) && in tcp_disordered_ack()
4273 ack == tp->snd_una && in tcp_disordered_ack()
4276 !tcp_may_update_window(tp, ack, seq, ntohs(th->window) << tp->rx_opt.snd_wscale) && in tcp_disordered_ack()
4279 (s32)(tp->rx_opt.ts_recent - tp->rx_opt.rcv_tsval) <= (inet_csk(sk)->icsk_rto * 1024) / HZ); in tcp_disordered_ack()
4285 const struct tcp_sock *tp = tcp_sk(sk); in tcp_paws_discard() local
4287 return !tcp_paws_check(&tp->rx_opt, TCP_PAWS_WINDOW) && in tcp_paws_discard()
4304 static inline bool tcp_sequence(const struct tcp_sock *tp, u32 seq, u32 end_seq) in tcp_sequence() argument
4306 return !before(end_seq, tp->rcv_wup) && in tcp_sequence()
4307 !after(seq, tp->rcv_nxt + tcp_receive_window(tp)); in tcp_sequence()
4360 struct tcp_sock *tp = tcp_sk(sk); in tcp_fin() local
4410 skb_rbtree_purge(&tp->out_of_order_queue); in tcp_fin()
4411 if (tcp_is_sack(tp)) in tcp_fin()
4412 tcp_sack_reset(&tp->rx_opt); in tcp_fin()
4441 struct tcp_sock *tp = tcp_sk(sk); in tcp_dsack_set() local
4443 if (tcp_is_sack(tp) && READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_dsack)) { in tcp_dsack_set()
4446 if (before(seq, tp->rcv_nxt)) in tcp_dsack_set()
4453 tp->rx_opt.dsack = 1; in tcp_dsack_set()
4454 tp->duplicate_sack[0].start_seq = seq; in tcp_dsack_set()
4455 tp->duplicate_sack[0].end_seq = end_seq; in tcp_dsack_set()
4461 struct tcp_sock *tp = tcp_sk(sk); in tcp_dsack_extend() local
4463 if (!tp->rx_opt.dsack) in tcp_dsack_extend()
4466 tcp_sack_extend(tp->duplicate_sack, seq, end_seq); in tcp_dsack_extend()
4483 struct tcp_sock *tp = tcp_sk(sk); in tcp_send_dupack() local
4486 before(TCP_SKB_CB(skb)->seq, tp->rcv_nxt)) { in tcp_send_dupack()
4490 if (tcp_is_sack(tp) && READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_dsack)) { in tcp_send_dupack()
4494 if (after(TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt)) in tcp_send_dupack()
4495 end_seq = tp->rcv_nxt; in tcp_send_dupack()
4506 static void tcp_sack_maybe_coalesce(struct tcp_sock *tp) in tcp_sack_maybe_coalesce() argument
4509 struct tcp_sack_block *sp = &tp->selective_acks[0]; in tcp_sack_maybe_coalesce()
4515 for (this_sack = 1; this_sack < tp->rx_opt.num_sacks;) { in tcp_sack_maybe_coalesce()
4522 tp->rx_opt.num_sacks--; in tcp_sack_maybe_coalesce()
4523 for (i = this_sack; i < tp->rx_opt.num_sacks; i++) in tcp_sack_maybe_coalesce()
4534 struct tcp_sock *tp = tcp_sk(sk); in tcp_sack_compress_send_ack() local
4536 if (!tp->compressed_ack) in tcp_sack_compress_send_ack()
4539 if (hrtimer_try_to_cancel(&tp->compressed_ack_timer) == 1) in tcp_sack_compress_send_ack()
4547 tp->compressed_ack - 1); in tcp_sack_compress_send_ack()
4549 tp->compressed_ack = 0; in tcp_sack_compress_send_ack()
4561 struct tcp_sock *tp = tcp_sk(sk); in tcp_sack_new_ofo_skb() local
4562 struct tcp_sack_block *sp = &tp->selective_acks[0]; in tcp_sack_new_ofo_skb()
4563 int cur_sacks = tp->rx_opt.num_sacks; in tcp_sack_new_ofo_skb()
4577 tcp_sack_maybe_coalesce(tp); in tcp_sack_new_ofo_skb()
4593 tp->rx_opt.num_sacks--; in tcp_sack_new_ofo_skb()
4603 tp->rx_opt.num_sacks++; in tcp_sack_new_ofo_skb()
4608 static void tcp_sack_remove(struct tcp_sock *tp) in tcp_sack_remove() argument
4610 struct tcp_sack_block *sp = &tp->selective_acks[0]; in tcp_sack_remove()
4611 int num_sacks = tp->rx_opt.num_sacks; in tcp_sack_remove()
4615 if (RB_EMPTY_ROOT(&tp->out_of_order_queue)) { in tcp_sack_remove()
4616 tp->rx_opt.num_sacks = 0; in tcp_sack_remove()
4622 if (!before(tp->rcv_nxt, sp->start_seq)) { in tcp_sack_remove()
4626 WARN_ON(before(tp->rcv_nxt, sp->end_seq)); in tcp_sack_remove()
4630 tp->selective_acks[i-1] = tp->selective_acks[i]; in tcp_sack_remove()
4637 tp->rx_opt.num_sacks = num_sacks; in tcp_sack_remove()
4722 struct tcp_sock *tp = tcp_sk(sk); in tcp_ofo_queue() local
4723 __u32 dsack_high = tp->rcv_nxt; in tcp_ofo_queue()
4728 p = rb_first(&tp->out_of_order_queue); in tcp_ofo_queue()
4731 if (after(TCP_SKB_CB(skb)->seq, tp->rcv_nxt)) in tcp_ofo_queue()
4741 rb_erase(&skb->rbnode, &tp->out_of_order_queue); in tcp_ofo_queue()
4743 if (unlikely(!after(TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt))) { in tcp_ofo_queue()
4750 tcp_rcv_nxt_update(tp, TCP_SKB_CB(skb)->end_seq); in tcp_ofo_queue()
4789 struct tcp_sock *tp = tcp_sk(sk); in tcp_data_queue_ofo() local
4805 tp->pred_flags = 0; in tcp_data_queue_ofo()
4808 tp->rcv_ooopack += max_t(u16, 1, skb_shinfo(skb)->gso_segs); in tcp_data_queue_ofo()
4813 p = &tp->out_of_order_queue.rb_node; in tcp_data_queue_ofo()
4814 if (RB_EMPTY_ROOT(&tp->out_of_order_queue)) { in tcp_data_queue_ofo()
4816 if (tcp_is_sack(tp)) { in tcp_data_queue_ofo()
4817 tp->rx_opt.num_sacks = 1; in tcp_data_queue_ofo()
4818 tp->selective_acks[0].start_seq = seq; in tcp_data_queue_ofo()
4819 tp->selective_acks[0].end_seq = end_seq; in tcp_data_queue_ofo()
4822 rb_insert_color(&skb->rbnode, &tp->out_of_order_queue); in tcp_data_queue_ofo()
4823 tp->ooo_last_skb = skb; in tcp_data_queue_ofo()
4830 if (tcp_ooo_try_coalesce(sk, tp->ooo_last_skb, in tcp_data_queue_ofo()
4836 if (tcp_is_sack(tp)) in tcp_data_queue_ofo()
4843 if (!before(seq, TCP_SKB_CB(tp->ooo_last_skb)->end_seq)) { in tcp_data_queue_ofo()
4844 parent = &tp->ooo_last_skb->rbnode; in tcp_data_queue_ofo()
4877 &tp->out_of_order_queue); in tcp_data_queue_ofo()
4896 rb_insert_color(&skb->rbnode, &tp->out_of_order_queue); in tcp_data_queue_ofo()
4908 rb_erase(&skb1->rbnode, &tp->out_of_order_queue); in tcp_data_queue_ofo()
4916 tp->ooo_last_skb = skb; in tcp_data_queue_ofo()
4919 if (tcp_is_sack(tp)) in tcp_data_queue_ofo()
4926 if (tcp_is_sack(tp)) in tcp_data_queue_ofo()
5010 struct tcp_sock *tp = tcp_sk(sk); in tcp_data_queue() local
5031 tp->rx_opt.dsack = 0; in tcp_data_queue()
5037 if (TCP_SKB_CB(skb)->seq == tp->rcv_nxt) { in tcp_data_queue()
5038 if (tcp_receive_window(tp) == 0) { in tcp_data_queue()
5061 if (!RB_EMPTY_ROOT(&tp->out_of_order_queue)) { in tcp_data_queue()
5067 if (RB_EMPTY_ROOT(&tp->out_of_order_queue)) in tcp_data_queue()
5071 if (tp->rx_opt.num_sacks) in tcp_data_queue()
5072 tcp_sack_remove(tp); in tcp_data_queue()
5083 if (!after(TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt)) { in tcp_data_queue()
5100 tp->rcv_nxt + tcp_receive_window(tp))) { in tcp_data_queue()
5105 if (before(TCP_SKB_CB(skb)->seq, tp->rcv_nxt)) { in tcp_data_queue()
5107 tcp_dsack_set(sk, TCP_SKB_CB(skb)->seq, tp->rcv_nxt); in tcp_data_queue()
5112 if (!tcp_receive_window(tp)) { in tcp_data_queue()
5283 struct tcp_sock *tp = tcp_sk(sk); in tcp_collapse_ofo_queue() local
5288 skb = skb_rb_first(&tp->out_of_order_queue); in tcp_collapse_ofo_queue()
5291 tp->ooo_last_skb = skb_rb_last(&tp->out_of_order_queue); in tcp_collapse_ofo_queue()
5310 tcp_collapse(sk, NULL, &tp->out_of_order_queue, in tcp_collapse_ofo_queue()
5341 struct tcp_sock *tp = tcp_sk(sk); in tcp_prune_ofo_queue() local
5345 if (RB_EMPTY_ROOT(&tp->out_of_order_queue)) in tcp_prune_ofo_queue()
5350 node = &tp->ooo_last_skb->rbnode; in tcp_prune_ofo_queue()
5353 rb_erase(node, &tp->out_of_order_queue); in tcp_prune_ofo_queue()
5365 tp->ooo_last_skb = rb_to_skb(prev); in tcp_prune_ofo_queue()
5372 if (tp->rx_opt.sack_ok) in tcp_prune_ofo_queue()
5373 tcp_sack_reset(&tp->rx_opt); in tcp_prune_ofo_queue()
5386 struct tcp_sock *tp = tcp_sk(sk); in tcp_prune_queue() local
5403 tp->copied_seq, tp->rcv_nxt); in tcp_prune_queue()
5423 tp->pred_flags = 0; in tcp_prune_queue()
5429 const struct tcp_sock *tp = tcp_sk(sk); in tcp_should_expand_sndbuf() local
5456 if (tcp_packets_in_flight(tp) >= tcp_snd_cwnd(tp)) in tcp_should_expand_sndbuf()
5464 struct tcp_sock *tp = tcp_sk(sk); in tcp_new_space() local
5468 tp->snd_cwnd_stamp = tcp_jiffies32; in tcp_new_space()
5507 struct tcp_sock *tp = tcp_sk(sk); in __tcp_ack_snd_check() local
5511 if (((tp->rcv_nxt - tp->rcv_wup) > inet_csk(sk)->icsk_ack.rcv_mss && in __tcp_ack_snd_check()
5517 (tp->rcv_nxt - tp->copied_seq < sk->sk_rcvlowat || in __tcp_ack_snd_check()
5518 __tcp_select_window(sk) >= tp->rcv_wnd)) || in __tcp_ack_snd_check()
5528 if (!ofo_possible || RB_EMPTY_ROOT(&tp->out_of_order_queue)) { in __tcp_ack_snd_check()
5533 if (!tcp_is_sack(tp) || in __tcp_ack_snd_check()
5534 tp->compressed_ack >= READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_comp_sack_nr)) in __tcp_ack_snd_check()
5537 if (tp->compressed_ack_rcv_nxt != tp->rcv_nxt) { in __tcp_ack_snd_check()
5538 tp->compressed_ack_rcv_nxt = tp->rcv_nxt; in __tcp_ack_snd_check()
5539 tp->dup_ack_counter = 0; in __tcp_ack_snd_check()
5541 if (tp->dup_ack_counter < TCP_FASTRETRANS_THRESH) { in __tcp_ack_snd_check()
5542 tp->dup_ack_counter++; in __tcp_ack_snd_check()
5545 tp->compressed_ack++; in __tcp_ack_snd_check()
5546 if (hrtimer_is_queued(&tp->compressed_ack_timer)) in __tcp_ack_snd_check()
5551 rtt = tp->rcv_rtt_est.rtt_us; in __tcp_ack_snd_check()
5552 if (tp->srtt_us && tp->srtt_us < rtt) in __tcp_ack_snd_check()
5553 rtt = tp->srtt_us; in __tcp_ack_snd_check()
5559 hrtimer_start_range_ns(&tp->compressed_ack_timer, ns_to_ktime(delay), in __tcp_ack_snd_check()
5585 struct tcp_sock *tp = tcp_sk(sk); in tcp_check_urg() local
5593 if (after(tp->copied_seq, ptr)) in tcp_check_urg()
5606 if (before(ptr, tp->rcv_nxt)) in tcp_check_urg()
5610 if (tp->urg_data && !after(ptr, tp->urg_seq)) in tcp_check_urg()
5631 if (tp->urg_seq == tp->copied_seq && tp->urg_data && in tcp_check_urg()
5632 !sock_flag(sk, SOCK_URGINLINE) && tp->copied_seq != tp->rcv_nxt) { in tcp_check_urg()
5634 tp->copied_seq++; in tcp_check_urg()
5635 if (skb && !before(tp->copied_seq, TCP_SKB_CB(skb)->end_seq)) { in tcp_check_urg()
5641 WRITE_ONCE(tp->urg_data, TCP_URG_NOTYET); in tcp_check_urg()
5642 WRITE_ONCE(tp->urg_seq, ptr); in tcp_check_urg()
5645 tp->pred_flags = 0; in tcp_check_urg()
5651 struct tcp_sock *tp = tcp_sk(sk); in tcp_urg() local
5658 if (unlikely(tp->urg_data == TCP_URG_NOTYET)) { in tcp_urg()
5659 u32 ptr = tp->urg_seq - ntohl(th->seq) + (th->doff * 4) - in tcp_urg()
5667 WRITE_ONCE(tp->urg_data, TCP_URG_VALID | tmp); in tcp_urg()
5684 struct tcp_sock *tp = tcp_sk(sk); in tcp_reset_check() local
5686 return unlikely(TCP_SKB_CB(skb)->seq == (tp->rcv_nxt - 1) && in tcp_reset_check()
5697 struct tcp_sock *tp = tcp_sk(sk); in tcp_validate_incoming() local
5701 if (tcp_fast_parse_options(sock_net(sk), skb, th, tp) && in tcp_validate_incoming()
5702 tp->rx_opt.saw_tstamp && in tcp_validate_incoming()
5708 &tp->last_oow_ack_time)) in tcp_validate_incoming()
5717 if (!tcp_sequence(tp, TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq)) { in tcp_validate_incoming()
5729 &tp->last_oow_ack_time)) in tcp_validate_incoming()
5749 if (TCP_SKB_CB(skb)->seq == tp->rcv_nxt || in tcp_validate_incoming()
5753 if (tcp_is_sack(tp) && tp->rx_opt.num_sacks > 0) { in tcp_validate_incoming()
5754 struct tcp_sack_block *sp = &tp->selective_acks[0]; in tcp_validate_incoming()
5758 for (this_sack = 1; this_sack < tp->rx_opt.num_sacks; in tcp_validate_incoming()
5773 if (tp->syn_fastopen && !tp->data_segs_in && in tcp_validate_incoming()
5837 struct tcp_sock *tp = tcp_sk(sk); in tcp_rcv_established() local
5843 tcp_mstamp_refresh(tp); in tcp_rcv_established()
5861 tp->rx_opt.saw_tstamp = 0; in tcp_rcv_established()
5872 if ((tcp_flag_word(th) & TCP_HP_BITS) == tp->pred_flags && in tcp_rcv_established()
5873 TCP_SKB_CB(skb)->seq == tp->rcv_nxt && in tcp_rcv_established()
5874 !after(TCP_SKB_CB(skb)->ack_seq, tp->snd_nxt)) { in tcp_rcv_established()
5875 int tcp_header_len = tp->tcp_header_len; in tcp_rcv_established()
5885 if (!tcp_parse_aligned_timestamp(tp, th)) in tcp_rcv_established()
5889 if ((s32)(tp->rx_opt.rcv_tsval - tp->rx_opt.ts_recent) < 0) in tcp_rcv_established()
5908 tp->rcv_nxt == tp->rcv_wup) in tcp_rcv_established()
5909 tcp_store_ts_recent(tp); in tcp_rcv_established()
5921 tp->rcv_rtt_last_tsecr = tp->rx_opt.rcv_tsecr; in tcp_rcv_established()
5944 tp->rcv_nxt == tp->rcv_wup) in tcp_rcv_established()
5945 tcp_store_ts_recent(tp); in tcp_rcv_established()
5958 if (TCP_SKB_CB(skb)->ack_seq != tp->snd_una) { in tcp_rcv_established()
5965 tcp_update_wl(tp, TCP_SKB_CB(skb)->seq); in tcp_rcv_established()
6025 struct tcp_sock *tp = tcp_sk(sk); in tcp_init_transfer() local
6037 if (tp->total_retrans > 1 && tp->undo_marker) in tcp_init_transfer()
6038 tcp_snd_cwnd_set(tp, 1); in tcp_init_transfer()
6040 tcp_snd_cwnd_set(tp, tcp_init_cwnd(tp, __sk_dst_get(sk))); in tcp_init_transfer()
6041 tp->snd_cwnd_stamp = tcp_jiffies32; in tcp_init_transfer()
6052 struct tcp_sock *tp = tcp_sk(sk); in tcp_finish_connect() local
6069 tp->lsndtime = tcp_jiffies32; in tcp_finish_connect()
6072 inet_csk_reset_keepalive_timer(sk, keepalive_time_when(tp)); in tcp_finish_connect()
6074 if (!tp->rx_opt.snd_wscale) in tcp_finish_connect()
6075 __tcp_fast_path_on(tp, tp->snd_wnd); in tcp_finish_connect()
6077 tp->pred_flags = 0; in tcp_finish_connect()
6083 struct tcp_sock *tp = tcp_sk(sk); in tcp_rcv_fastopen_synack() local
6084 struct sk_buff *data = tp->syn_data ? tcp_rtx_queue_head(sk) : NULL; in tcp_rcv_fastopen_synack()
6085 u16 mss = tp->rx_opt.mss_clamp, try_exp = 0; in tcp_rcv_fastopen_synack()
6088 if (mss == tp->rx_opt.user_mss) { in tcp_rcv_fastopen_synack()
6098 if (!tp->syn_fastopen) { in tcp_rcv_fastopen_synack()
6101 } else if (tp->total_retrans) { in tcp_rcv_fastopen_synack()
6108 } else if (cookie->len < 0 && !tp->syn_data) { in tcp_rcv_fastopen_synack()
6113 try_exp = tp->syn_fastopen_exp ? 2 : 1; in tcp_rcv_fastopen_synack()
6119 if (tp->total_retrans) in tcp_rcv_fastopen_synack()
6120 tp->fastopen_client_fail = TFO_SYN_RETRANSMITTED; in tcp_rcv_fastopen_synack()
6122 tp->fastopen_client_fail = TFO_DATA_NOT_ACKED; in tcp_rcv_fastopen_synack()
6130 tp->syn_data_acked = tp->syn_data; in tcp_rcv_fastopen_synack()
6131 if (tp->syn_data_acked) { in tcp_rcv_fastopen_synack()
6134 if (tp->delivered > 1) in tcp_rcv_fastopen_synack()
6135 --tp->delivered; in tcp_rcv_fastopen_synack()
6143 static void smc_check_reset_syn(struct tcp_sock *tp) in smc_check_reset_syn() argument
6147 if (tp->syn_smc && !tp->rx_opt.smc_ok) in smc_check_reset_syn()
6148 tp->syn_smc = 0; in smc_check_reset_syn()
6155 struct tcp_sock *tp = tcp_sk(sk); in tcp_try_undo_spurious_syn() local
6162 syn_stamp = tp->retrans_stamp; in tcp_try_undo_spurious_syn()
6163 if (tp->undo_marker && syn_stamp && tp->rx_opt.saw_tstamp && in tcp_try_undo_spurious_syn()
6164 syn_stamp == tp->rx_opt.rcv_tsecr) in tcp_try_undo_spurious_syn()
6165 tp->undo_marker = 0; in tcp_try_undo_spurious_syn()
6172 struct tcp_sock *tp = tcp_sk(sk); in tcp_rcv_synsent_state_process() local
6174 int saved_clamp = tp->rx_opt.mss_clamp; in tcp_rcv_synsent_state_process()
6178 tcp_parse_options(sock_net(sk), skb, &tp->rx_opt, 0, &foc); in tcp_rcv_synsent_state_process()
6179 if (tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr) in tcp_rcv_synsent_state_process()
6180 tp->rx_opt.rcv_tsecr -= tp->tsoffset; in tcp_rcv_synsent_state_process()
6191 if (!after(TCP_SKB_CB(skb)->ack_seq, tp->snd_una) || in tcp_rcv_synsent_state_process()
6192 after(TCP_SKB_CB(skb)->ack_seq, tp->snd_nxt)) { in tcp_rcv_synsent_state_process()
6201 if (tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr && in tcp_rcv_synsent_state_process()
6202 !between(tp->rx_opt.rcv_tsecr, tp->retrans_stamp, in tcp_rcv_synsent_state_process()
6203 tcp_time_stamp(tp))) { in tcp_rcv_synsent_state_process()
6242 tcp_ecn_rcv_synack(tp, th); in tcp_rcv_synsent_state_process()
6244 tcp_init_wl(tp, TCP_SKB_CB(skb)->seq); in tcp_rcv_synsent_state_process()
6251 WRITE_ONCE(tp->rcv_nxt, TCP_SKB_CB(skb)->seq + 1); in tcp_rcv_synsent_state_process()
6252 tp->rcv_wup = TCP_SKB_CB(skb)->seq + 1; in tcp_rcv_synsent_state_process()
6257 tp->snd_wnd = ntohs(th->window); in tcp_rcv_synsent_state_process()
6259 if (!tp->rx_opt.wscale_ok) { in tcp_rcv_synsent_state_process()
6260 tp->rx_opt.snd_wscale = tp->rx_opt.rcv_wscale = 0; in tcp_rcv_synsent_state_process()
6261 tp->window_clamp = min(tp->window_clamp, 65535U); in tcp_rcv_synsent_state_process()
6264 if (tp->rx_opt.saw_tstamp) { in tcp_rcv_synsent_state_process()
6265 tp->rx_opt.tstamp_ok = 1; in tcp_rcv_synsent_state_process()
6266 tp->tcp_header_len = in tcp_rcv_synsent_state_process()
6268 tp->advmss -= TCPOLEN_TSTAMP_ALIGNED; in tcp_rcv_synsent_state_process()
6269 tcp_store_ts_recent(tp); in tcp_rcv_synsent_state_process()
6271 tp->tcp_header_len = sizeof(struct tcphdr); in tcp_rcv_synsent_state_process()
6280 WRITE_ONCE(tp->copied_seq, tp->rcv_nxt); in tcp_rcv_synsent_state_process()
6282 smc_check_reset_syn(tp); in tcp_rcv_synsent_state_process()
6288 fastopen_fail = (tp->syn_fastopen || tp->syn_data) && in tcp_rcv_synsent_state_process()
6330 if (tp->rx_opt.ts_recent_stamp && tp->rx_opt.saw_tstamp && in tcp_rcv_synsent_state_process()
6331 tcp_paws_reject(&tp->rx_opt, 0)) { in tcp_rcv_synsent_state_process()
6342 if (tp->rx_opt.saw_tstamp) { in tcp_rcv_synsent_state_process()
6343 tp->rx_opt.tstamp_ok = 1; in tcp_rcv_synsent_state_process()
6344 tcp_store_ts_recent(tp); in tcp_rcv_synsent_state_process()
6345 tp->tcp_header_len = in tcp_rcv_synsent_state_process()
6348 tp->tcp_header_len = sizeof(struct tcphdr); in tcp_rcv_synsent_state_process()
6351 WRITE_ONCE(tp->rcv_nxt, TCP_SKB_CB(skb)->seq + 1); in tcp_rcv_synsent_state_process()
6352 WRITE_ONCE(tp->copied_seq, tp->rcv_nxt); in tcp_rcv_synsent_state_process()
6353 tp->rcv_wup = TCP_SKB_CB(skb)->seq + 1; in tcp_rcv_synsent_state_process()
6358 tp->snd_wnd = ntohs(th->window); in tcp_rcv_synsent_state_process()
6359 tp->snd_wl1 = TCP_SKB_CB(skb)->seq; in tcp_rcv_synsent_state_process()
6360 tp->max_window = tp->snd_wnd; in tcp_rcv_synsent_state_process()
6362 tcp_ecn_rcv_syn(tp, th); in tcp_rcv_synsent_state_process()
6391 tcp_clear_options(&tp->rx_opt); in tcp_rcv_synsent_state_process()
6392 tp->rx_opt.mss_clamp = saved_clamp; in tcp_rcv_synsent_state_process()
6397 tcp_clear_options(&tp->rx_opt); in tcp_rcv_synsent_state_process()
6398 tp->rx_opt.mss_clamp = saved_clamp; in tcp_rcv_synsent_state_process()
6443 struct tcp_sock *tp = tcp_sk(sk); in tcp_rcv_state_process() local
6487 tp->rx_opt.saw_tstamp = 0; in tcp_rcv_state_process()
6488 tcp_mstamp_refresh(tp); in tcp_rcv_state_process()
6500 tcp_mstamp_refresh(tp); in tcp_rcv_state_process()
6501 tp->rx_opt.saw_tstamp = 0; in tcp_rcv_state_process()
6502 req = rcu_dereference_protected(tp->fastopen_rsk, in tcp_rcv_state_process()
6537 tp->delivered++; /* SYN-ACK delivery isn't tracked in tcp_ack */ in tcp_rcv_state_process()
6538 if (!tp->srtt_us) in tcp_rcv_state_process()
6545 tp->retrans_stamp = 0; in tcp_rcv_state_process()
6548 WRITE_ONCE(tp->copied_seq, tp->rcv_nxt); in tcp_rcv_state_process()
6561 tp->snd_una = TCP_SKB_CB(skb)->ack_seq; in tcp_rcv_state_process()
6562 tp->snd_wnd = ntohs(th->window) << tp->rx_opt.snd_wscale; in tcp_rcv_state_process()
6563 tcp_init_wl(tp, TCP_SKB_CB(skb)->seq); in tcp_rcv_state_process()
6565 if (tp->rx_opt.tstamp_ok) in tcp_rcv_state_process()
6566 tp->advmss -= TCPOLEN_TSTAMP_ALIGNED; in tcp_rcv_state_process()
6572 tp->lsndtime = tcp_jiffies32; in tcp_rcv_state_process()
6575 tcp_fast_path_on(tp); in tcp_rcv_state_process()
6584 if (tp->snd_una != tp->write_seq) in tcp_rcv_state_process()
6598 if (tp->linger2 < 0) { in tcp_rcv_state_process()
6604 after(TCP_SKB_CB(skb)->end_seq - th->fin, tp->rcv_nxt)) { in tcp_rcv_state_process()
6606 if (tp->syn_fastopen && th->fin) in tcp_rcv_state_process()
6632 if (tp->snd_una == tp->write_seq) { in tcp_rcv_state_process()
6639 if (tp->snd_una == tp->write_seq) { in tcp_rcv_state_process()
6655 if (!before(TCP_SKB_CB(skb)->seq, tp->rcv_nxt)) { in tcp_rcv_state_process()
6672 after(TCP_SKB_CB(skb)->end_seq - th->fin, tp->rcv_nxt)) { in tcp_rcv_state_process()
6879 struct tcp_sock *tp = tcp_sk(sk); in tcp_get_syncookie_mss() local
6894 mss = tcp_parse_mss_option(th, tp->rx_opt.user_mss); in tcp_get_syncookie_mss()
6909 struct tcp_sock *tp = tcp_sk(sk); in tcp_conn_request() local
6948 tmp_opt.user_mss = tp->rx_opt.user_mss; in tcp_conn_request()