Lines Matching refs:tp
259 tcp_is_sack_recovery(struct tcpcb *tp, struct tcpopt *to) in tcp_is_sack_recovery() argument
261 return ((tp->t_flags & TF_SACK_PERMIT) && in tcp_is_sack_recovery()
263 (!TAILQ_EMPTY(&tp->snd_holes)))); in tcp_is_sack_recovery()
271 hhook_run_tcp_est_in(struct tcpcb *tp, struct tcphdr *th, struct tcpopt *to) in hhook_run_tcp_est_in() argument
276 hhook_data.tp = tp; in hhook_run_tcp_est_in()
281 &tp->t_osd); in hhook_run_tcp_est_in()
290 cc_ack_received(struct tcpcb *tp, struct tcphdr *th, uint16_t nsegs, in cc_ack_received() argument
297 INP_WLOCK_ASSERT(tptoinpcb(tp)); in cc_ack_received()
299 tp->t_ccv.nsegs = nsegs; in cc_ack_received()
300 tp->t_ccv.bytes_this_ack = BYTES_THIS_ACK(tp, th); in cc_ack_received()
301 if ((!V_tcp_do_newcwv && (tp->snd_cwnd <= tp->snd_wnd)) || in cc_ack_received()
302 (V_tcp_do_newcwv && (tp->snd_cwnd <= tp->snd_wnd) && in cc_ack_received()
303 (tp->snd_cwnd < (tcp_compute_pipe(tp) * 2)))) in cc_ack_received()
304 tp->t_ccv.flags |= CCF_CWND_LIMITED; in cc_ack_received()
306 tp->t_ccv.flags &= ~CCF_CWND_LIMITED; in cc_ack_received()
310 stats_voi_update_abs_s32(tp->t_stats, VOI_TCP_CALCFRWINDIFF, in cc_ack_received()
311 ((int32_t)tp->snd_cwnd) - tp->snd_wnd); in cc_ack_received()
312 if (!IN_RECOVERY(tp->t_flags)) in cc_ack_received()
313 stats_voi_update_abs_u32(tp->t_stats, VOI_TCP_ACKLEN, in cc_ack_received()
314 tp->t_ccv.bytes_this_ack / (tcp_maxseg(tp) * nsegs)); in cc_ack_received()
315 if ((tp->t_flags & TF_GPUTINPROG) && in cc_ack_received()
316 SEQ_GEQ(th->th_ack, tp->gput_ack)) { in cc_ack_received()
320 gput = (((int64_t)SEQ_SUB(th->th_ack, tp->gput_seq)) << 3) / in cc_ack_received()
321 max(1, tcp_ts_getticks() - tp->gput_ts); in cc_ack_received()
322 stats_voi_update_abs_u32(tp->t_stats, VOI_TCP_GPUT, in cc_ack_received()
329 if (tp->t_stats_gput_prev > 0) in cc_ack_received()
330 stats_voi_update_abs_s32(tp->t_stats, in cc_ack_received()
332 ((gput - tp->t_stats_gput_prev) * 100) / in cc_ack_received()
333 tp->t_stats_gput_prev); in cc_ack_received()
334 tp->t_flags &= ~TF_GPUTINPROG; in cc_ack_received()
335 tp->t_stats_gput_prev = gput; in cc_ack_received()
338 if (tp->snd_cwnd > tp->snd_ssthresh) { in cc_ack_received()
339 tp->t_bytes_acked += tp->t_ccv.bytes_this_ack; in cc_ack_received()
340 if (tp->t_bytes_acked >= tp->snd_cwnd) { in cc_ack_received()
341 tp->t_bytes_acked -= tp->snd_cwnd; in cc_ack_received()
342 tp->t_ccv.flags |= CCF_ABC_SENTAWND; in cc_ack_received()
345 tp->t_ccv.flags &= ~CCF_ABC_SENTAWND; in cc_ack_received()
346 tp->t_bytes_acked = 0; in cc_ack_received()
350 if (CC_ALGO(tp)->ack_received != NULL) { in cc_ack_received()
352 tp->t_ccv.curack = th->th_ack; in cc_ack_received()
353 CC_ALGO(tp)->ack_received(&tp->t_ccv, type); in cc_ack_received()
356 stats_voi_update_abs_ulong(tp->t_stats, VOI_TCP_LCWIN, tp->snd_cwnd); in cc_ack_received()
361 cc_conn_init(struct tcpcb *tp) in cc_conn_init() argument
364 struct inpcb *inp = tptoinpcb(tp); in cc_conn_init()
371 maxseg = tcp_maxseg(tp); in cc_conn_init()
373 if (tp->t_srtt == 0 && (rtt = metrics.hc_rtt)) { in cc_conn_init()
374 tp->t_srtt = rtt; in cc_conn_init()
377 tp->t_rttvar = metrics.hc_rttvar; in cc_conn_init()
381 tp->t_rttvar = in cc_conn_init()
382 tp->t_srtt * TCP_RTTVAR_SCALE / TCP_RTT_SCALE; in cc_conn_init()
384 TCPT_RANGESET(tp->t_rxtcur, in cc_conn_init()
385 ((tp->t_srtt >> 2) + tp->t_rttvar) >> 1, in cc_conn_init()
386 tp->t_rttmin, TCPTV_REXMTMAX); in cc_conn_init()
395 tp->snd_ssthresh = max(2 * maxseg, metrics.hc_ssthresh); in cc_conn_init()
406 if (tp->snd_cwnd == 1) in cc_conn_init()
407 tp->snd_cwnd = maxseg; /* SYN(-ACK) lost */ in cc_conn_init()
409 tp->snd_cwnd = tcp_compute_initwnd(maxseg); in cc_conn_init()
411 if (CC_ALGO(tp)->conn_init != NULL) in cc_conn_init()
412 CC_ALGO(tp)->conn_init(&tp->t_ccv); in cc_conn_init()
416 cc_cong_signal(struct tcpcb *tp, struct tcphdr *th, uint32_t type) in cc_cong_signal() argument
418 INP_WLOCK_ASSERT(tptoinpcb(tp)); in cc_cong_signal()
421 stats_voi_update_abs_u32(tp->t_stats, VOI_TCP_CSIG, type); in cc_cong_signal()
426 if (!IN_FASTRECOVERY(tp->t_flags)) { in cc_cong_signal()
427 tp->snd_recover = tp->snd_max; in cc_cong_signal()
428 if (tp->t_flags2 & TF2_ECN_PERMIT) in cc_cong_signal()
429 tp->t_flags2 |= TF2_ECN_SND_CWR; in cc_cong_signal()
433 if (!IN_CONGRECOVERY(tp->t_flags) || in cc_cong_signal()
438 SEQ_GEQ(th->th_ack, tp->snd_recover)) { in cc_cong_signal()
439 EXIT_CONGRECOVERY(tp->t_flags); in cc_cong_signal()
441 tp->snd_recover = tp->snd_max + 1; in cc_cong_signal()
442 if (tp->t_flags2 & TF2_ECN_PERMIT) in cc_cong_signal()
443 tp->t_flags2 |= TF2_ECN_SND_CWR; in cc_cong_signal()
447 tp->t_dupacks = 0; in cc_cong_signal()
448 tp->t_bytes_acked = 0; in cc_cong_signal()
449 EXIT_RECOVERY(tp->t_flags); in cc_cong_signal()
450 if (tp->t_flags2 & TF2_ECN_PERMIT) in cc_cong_signal()
451 tp->t_flags2 |= TF2_ECN_SND_CWR; in cc_cong_signal()
456 tp->snd_cwnd = tp->snd_cwnd_prev; in cc_cong_signal()
457 tp->snd_ssthresh = tp->snd_ssthresh_prev; in cc_cong_signal()
458 tp->snd_recover = tp->snd_recover_prev; in cc_cong_signal()
459 if (tp->t_flags & TF_WASFRECOVERY) in cc_cong_signal()
460 ENTER_FASTRECOVERY(tp->t_flags); in cc_cong_signal()
461 if (tp->t_flags & TF_WASCRECOVERY) in cc_cong_signal()
462 ENTER_CONGRECOVERY(tp->t_flags); in cc_cong_signal()
463 tp->snd_nxt = tp->snd_max; in cc_cong_signal()
464 tp->t_flags &= ~TF_PREVVALID; in cc_cong_signal()
465 tp->t_rxtshift = 0; in cc_cong_signal()
466 tp->t_badrxtwin = 0; in cc_cong_signal()
469 if (SEQ_LT(tp->snd_fack, tp->snd_una) || in cc_cong_signal()
470 SEQ_GT(tp->snd_fack, tp->snd_max)) { in cc_cong_signal()
471 tp->snd_fack = tp->snd_una; in cc_cong_signal()
474 if (CC_ALGO(tp)->cong_signal != NULL) { in cc_cong_signal()
476 tp->t_ccv.curack = th->th_ack; in cc_cong_signal()
477 CC_ALGO(tp)->cong_signal(&tp->t_ccv, type); in cc_cong_signal()
482 cc_post_recovery(struct tcpcb *tp, struct tcphdr *th) in cc_post_recovery() argument
484 INP_WLOCK_ASSERT(tptoinpcb(tp)); in cc_post_recovery()
486 if (CC_ALGO(tp)->post_recovery != NULL) { in cc_post_recovery()
487 if (SEQ_LT(tp->snd_fack, th->th_ack) || in cc_post_recovery()
488 SEQ_GT(tp->snd_fack, tp->snd_max)) { in cc_post_recovery()
489 tp->snd_fack = th->th_ack; in cc_post_recovery()
491 tp->t_ccv.curack = th->th_ack; in cc_post_recovery()
492 CC_ALGO(tp)->post_recovery(&tp->t_ccv); in cc_post_recovery()
494 EXIT_RECOVERY(tp->t_flags); in cc_post_recovery()
496 tp->t_bytes_acked = 0; in cc_post_recovery()
497 tp->sackhint.delivered_data = 0; in cc_post_recovery()
498 tp->sackhint.prr_delivered = 0; in cc_post_recovery()
499 tp->sackhint.prr_out = 0; in cc_post_recovery()
511 #define DELAY_ACK(tp, tlen) \ argument
512 ((!tcp_timer_active(tp, TT_DELACK) && \
513 (tp->t_flags & TF_RXWIN0SENT) == 0) && \
514 (tlen <= tp->t_maxseg) && \
515 (V_tcp_delack_enabled || (tp->t_flags & TF_NEEDSYN)))
518 cc_ecnpkt_handler_flags(struct tcpcb *tp, uint16_t flags, uint8_t iptos) in cc_ecnpkt_handler_flags() argument
520 INP_WLOCK_ASSERT(tptoinpcb(tp)); in cc_ecnpkt_handler_flags()
522 if (CC_ALGO(tp)->ecnpkt_handler != NULL) { in cc_ecnpkt_handler_flags()
525 tp->t_ccv.flags |= CCF_IPHDR_CE; in cc_ecnpkt_handler_flags()
532 tp->t_ccv.flags &= ~CCF_IPHDR_CE; in cc_ecnpkt_handler_flags()
537 tp->t_ccv.flags |= CCF_TCPHDR_CWR; in cc_ecnpkt_handler_flags()
539 tp->t_ccv.flags &= ~CCF_TCPHDR_CWR; in cc_ecnpkt_handler_flags()
541 CC_ALGO(tp)->ecnpkt_handler(&tp->t_ccv); in cc_ecnpkt_handler_flags()
543 if (tp->t_ccv.flags & CCF_ACKNOW) { in cc_ecnpkt_handler_flags()
544 tcp_timer_activate(tp, TT_DELACK, tcp_delacktime); in cc_ecnpkt_handler_flags()
545 tp->t_flags |= TF_ACKNOW; in cc_ecnpkt_handler_flags()
551 cc_ecnpkt_handler(struct tcpcb *tp, struct tcphdr *th, uint8_t iptos) in cc_ecnpkt_handler() argument
553 cc_ecnpkt_handler_flags(tp, tcp_get_flags(th), iptos); in cc_ecnpkt_handler()
615 struct tcpcb *tp = NULL; in tcp_input_with_port() local
842 tp = NULL; in tcp_input_with_port()
993 tp = intotcpcb(inp); in tcp_input_with_port()
994 switch (tp->t_state) { in tcp_input_with_port()
1020 if ((tp->t_port != port) && (tp->t_state > TCPS_LISTEN)) { in tcp_input_with_port()
1026 if (tp->t_flags & TF_TOE) { in tcp_input_with_port()
1027 tcp_offload_input(tp, m); in tcp_input_with_port()
1044 KASSERT(tp->t_state == TCPS_LISTEN || !SOLISTENING(so), in tcp_input_with_port()
1045 ("%s: so accepting but tp %p not listening", __func__, tp)); in tcp_input_with_port()
1046 if (tp->t_state == TCPS_LISTEN && SOLISTENING(so)) { in tcp_input_with_port()
1153 tp = intotcpcb(inp); in tcp_input_with_port()
1154 KASSERT(tp->t_state == TCPS_SYN_RECEIVED, in tcp_input_with_port()
1161 TCP_PROBE5(receive, NULL, tp, m, tp, th); in tcp_input_with_port()
1162 tp->t_fb->tfb_tcp_do_segment(tp, m, th, drop_hdrlen, in tcp_input_with_port()
1350 TCP_PROBE3(debug__input, tp, th, m); in tcp_input_with_port()
1363 if (tp->t_flags & TF_SIGNATURE) { in tcp_input_with_port()
1374 TCP_PROBE5(receive, NULL, tp, m, tp, th); in tcp_input_with_port()
1390 tp->t_fb->tfb_tcp_do_segment(tp, m, th, drop_hdrlen, tlen, iptos); in tcp_input_with_port()
1412 TCP_PROBE5(receive, NULL, tp, m, tp, th); in tcp_input_with_port()
1413 tcp_dropwithreset(m, th, tp, tlen, rstreason); in tcp_input_with_port()
1418 TCP_PROBE5(receive, NULL, tp, m, tp, th); in tcp_input_with_port()
1471 struct tcpcb *tp, int tlen) in tcp_autorcvbuf() argument
1476 tp->t_srtt != 0 && tp->rfbuf_ts != 0 && in tcp_autorcvbuf()
1477 TCP_TS_TO_TICKS(tcp_ts_getticks() - tp->rfbuf_ts) > in tcp_autorcvbuf()
1478 ((tp->t_srtt >> TCP_RTT_SHIFT)/2)) { in tcp_autorcvbuf()
1479 if (tp->rfbuf_cnt > ((so->so_rcv.sb_hiwat / 2)/ 4 * 3) && in tcp_autorcvbuf()
1483 TCP_PROBE6(receive__autoresize, NULL, tp, m, tp, th, newsize); in tcp_autorcvbuf()
1486 tp->rfbuf_ts = 0; in tcp_autorcvbuf()
1487 tp->rfbuf_cnt = 0; in tcp_autorcvbuf()
1489 tp->rfbuf_cnt += tlen; /* add up */ in tcp_autorcvbuf()
1501 tcp_handle_wakeup(struct tcpcb *tp) in tcp_handle_wakeup() argument
1504 INP_WLOCK_ASSERT(tptoinpcb(tp)); in tcp_handle_wakeup()
1506 if (tp->t_flags & TF_WAKESOR) { in tcp_handle_wakeup()
1507 struct socket *so = tptosocket(tp); in tcp_handle_wakeup()
1509 tp->t_flags &= ~TF_WAKESOR; in tcp_handle_wakeup()
1516 tcp_do_segment(struct tcpcb *tp, struct mbuf *m, struct tcphdr *th, in tcp_do_segment() argument
1526 struct inpcb *inp = tptoinpcb(tp); in tcp_do_segment()
1527 struct socket *so = tptosocket(tp); in tcp_do_segment()
1535 tp->sackhint.last_sack_ack = 0; in tcp_do_segment()
1541 KASSERT(tp->t_state > TCPS_LISTEN, ("%s: TCPS_LISTEN", in tcp_do_segment()
1543 KASSERT(tp->t_state != TCPS_TIME_WAIT, ("%s: TCPS_TIME_WAIT", in tcp_do_segment()
1546 TCP_LOG_EVENT(tp, th, &so->so_rcv, &so->so_snd, TCP_LOG_IN, 0, in tcp_do_segment()
1563 if ((tp->t_state == TCPS_SYN_SENT) && (thflags & TH_ACK) && in tcp_do_segment()
1564 (SEQ_LEQ(th->th_ack, tp->iss) || SEQ_GT(th->th_ack, tp->snd_max))) { in tcp_do_segment()
1566 tcp_log_end_status(tp, TCP_EI_STATUS_RST_IN_FRONT); in tcp_do_segment()
1576 if (tp->t_idle_reduce && in tcp_do_segment()
1577 (tp->snd_max == tp->snd_una) && in tcp_do_segment()
1578 ((ticks - tp->t_rcvtime) >= tp->t_rxtcur)) in tcp_do_segment()
1579 cc_after_idle(tp); in tcp_do_segment()
1580 tp->t_rcvtime = ticks; in tcp_do_segment()
1583 tcp_log_end_status(tp, TCP_EI_STATUS_CLIENT_FIN); in tcp_do_segment()
1588 tiwin = th->th_win << tp->snd_scale; in tcp_do_segment()
1590 stats_voi_update_abs_ulong(tp->t_stats, VOI_TCP_FRWIN, tiwin); in tcp_do_segment()
1596 if (tcp_ecn_input_segment(tp, thflags, tlen, in tcp_do_segment()
1597 tcp_packets_this_ack(tp, th->th_ack), in tcp_do_segment()
1599 cc_cong_signal(tp, th, CC_ECN); in tcp_do_segment()
1607 if (tp->t_flags2 & TF2_PROC_SACK_PROHIBIT) { in tcp_do_segment()
1616 if ((tp->t_flags & TF_SIGNATURE) != 0 && in tcp_do_segment()
1629 to.to_tsecr -= tp->ts_offset; in tcp_do_segment()
1641 if (tp->t_state == TCPS_SYN_SENT && (thflags & TH_SYN)) { in tcp_do_segment()
1643 tcp_ecn_input_parallel_syn(tp, thflags, iptos); in tcp_do_segment()
1645 (tp->t_flags & TF_REQ_SCALE) && in tcp_do_segment()
1646 !(tp->t_flags & TF_NOOPT)) { in tcp_do_segment()
1647 tp->t_flags |= TF_RCVD_SCALE; in tcp_do_segment()
1648 tp->snd_scale = to.to_wscale; in tcp_do_segment()
1650 tp->t_flags &= ~TF_REQ_SCALE; in tcp_do_segment()
1656 tp->snd_wnd = th->th_win; in tcp_do_segment()
1658 (tp->t_flags & TF_REQ_TSTMP) && in tcp_do_segment()
1659 !(tp->t_flags & TF_NOOPT)) { in tcp_do_segment()
1660 tp->t_flags |= TF_RCVD_TSTMP; in tcp_do_segment()
1661 tp->ts_recent = to.to_tsval; in tcp_do_segment()
1662 tp->ts_recent_age = tcp_ts_getticks(); in tcp_do_segment()
1664 tp->t_flags &= ~TF_REQ_TSTMP; in tcp_do_segment()
1667 tcp_mss(tp, to.to_mss); in tcp_do_segment()
1669 if ((tp->t_flags & TF_SACK_PERMIT) && in tcp_do_segment()
1671 (tp->t_flags & TF_NOOPT))) { in tcp_do_segment()
1672 tp->t_flags &= ~TF_SACK_PERMIT; in tcp_do_segment()
1674 if (tp->t_flags & TF_FASTOPEN) { in tcp_do_segment()
1676 !(tp->t_flags & TF_NOOPT)) { in tcp_do_segment()
1688 tcp_fastopen_update_cache(tp, mss, in tcp_do_segment()
1691 tcp_fastopen_disable_path(tp); in tcp_do_segment()
1703 if ((tp->t_flags & TF_RCVD_TSTMP) && !(to.to_flags & TOF_TS)) { in tcp_do_segment()
1726 if (!(tp->t_flags & TF_RCVD_TSTMP) && (to.to_flags & TOF_TS)) { in tcp_do_segment()
1751 if (tp->t_state == TCPS_ESTABLISHED && in tcp_do_segment()
1752 th->th_seq == tp->rcv_nxt && in tcp_do_segment()
1754 tp->snd_nxt == tp->snd_max && in tcp_do_segment()
1755 tiwin && tiwin == tp->snd_wnd && in tcp_do_segment()
1756 ((tp->t_flags & (TF_NEEDSYN|TF_NEEDFIN)) == 0) && in tcp_do_segment()
1757 SEGQ_EMPTY(tp) && in tcp_do_segment()
1759 TSTMP_GEQ(to.to_tsval, tp->ts_recent)) ) { in tcp_do_segment()
1767 SEQ_LEQ(th->th_seq, tp->last_ack_sent)) { in tcp_do_segment()
1768 tp->ts_recent_age = tcp_ts_getticks(); in tcp_do_segment()
1769 tp->ts_recent = to.to_tsval; in tcp_do_segment()
1773 if (SEQ_GT(th->th_ack, tp->snd_una) && in tcp_do_segment()
1774 SEQ_LEQ(th->th_ack, tp->snd_max) && in tcp_do_segment()
1775 !IN_RECOVERY(tp->t_flags) && in tcp_do_segment()
1777 TAILQ_EMPTY(&tp->snd_holes)) { in tcp_do_segment()
1786 if (tp->t_rxtshift == 1 && in tcp_do_segment()
1787 tp->t_flags & TF_PREVVALID && in tcp_do_segment()
1788 tp->t_badrxtwin != 0 && in tcp_do_segment()
1791 TSTMP_LT(to.to_tsecr, tp->t_badrxtwin)) || in tcp_do_segment()
1793 TSTMP_LT(ticks, tp->t_badrxtwin)))) in tcp_do_segment()
1794 cc_cong_signal(tp, th, CC_RTO_ERR); in tcp_do_segment()
1809 if (!tp->t_rttlow || tp->t_rttlow > t) in tcp_do_segment()
1810 tp->t_rttlow = t; in tcp_do_segment()
1811 tcp_xmit_timer(tp, in tcp_do_segment()
1813 } else if (tp->t_rtttime && in tcp_do_segment()
1814 SEQ_GT(th->th_ack, tp->t_rtseq)) { in tcp_do_segment()
1815 if (!tp->t_rttlow || in tcp_do_segment()
1816 tp->t_rttlow > ticks - tp->t_rtttime) in tcp_do_segment()
1817 tp->t_rttlow = ticks - tp->t_rtttime; in tcp_do_segment()
1818 tcp_xmit_timer(tp, in tcp_do_segment()
1819 ticks - tp->t_rtttime); in tcp_do_segment()
1821 acked = BYTES_THIS_ACK(tp, th); in tcp_do_segment()
1825 hhook_run_tcp_est_in(tp, th, &to); in tcp_do_segment()
1831 if (SEQ_GT(tp->snd_una, tp->snd_recover) && in tcp_do_segment()
1832 SEQ_LEQ(th->th_ack, tp->snd_recover)) in tcp_do_segment()
1833 tp->snd_recover = th->th_ack - 1; in tcp_do_segment()
1841 cc_ack_received(tp, th, nsegs, CC_ACK); in tcp_do_segment()
1843 tp->snd_una = th->th_ack; in tcp_do_segment()
1848 tp->snd_wl2 = th->th_ack; in tcp_do_segment()
1849 tp->t_dupacks = 0; in tcp_do_segment()
1861 TCP_PROBE3(debug__input, tp, th, m); in tcp_do_segment()
1869 tp->t_acktime = 0; in tcp_do_segment()
1871 tp->t_acktime = ticks; in tcp_do_segment()
1872 if (tp->snd_una == tp->snd_max) in tcp_do_segment()
1873 tcp_timer_activate(tp, TT_REXMT, 0); in tcp_do_segment()
1874 else if (!tcp_timer_active(tp, TT_PERSIST)) in tcp_do_segment()
1875 tcp_timer_activate(tp, TT_REXMT, in tcp_do_segment()
1876 TP_RXTCUR(tp)); in tcp_do_segment()
1883 if ((tp->t_flags & TF_ACKNOW) || in tcp_do_segment()
1885 SEQ_SUB(tp->snd_max, tp->snd_una))) { in tcp_do_segment()
1886 (void) tcp_output(tp); in tcp_do_segment()
1890 } else if (th->th_ack == tp->snd_una && in tcp_do_segment()
1900 if ((tp->t_flags & TF_SACK_PERMIT) && tp->rcv_numsacks) in tcp_do_segment()
1901 tcp_clean_sackreport(tp); in tcp_do_segment()
1903 tp->rcv_nxt += tlen; in tcp_do_segment()
1905 ((tp->t_flags2 & TF2_FBYTES_COMPLETE) == 0) && in tcp_do_segment()
1906 (tp->t_fbyte_in == 0)) { in tcp_do_segment()
1907 tp->t_fbyte_in = ticks; in tcp_do_segment()
1908 if (tp->t_fbyte_in == 0) in tcp_do_segment()
1909 tp->t_fbyte_in = 1; in tcp_do_segment()
1910 if (tp->t_fbyte_out && tp->t_fbyte_in) in tcp_do_segment()
1911 tp->t_flags2 |= TF2_FBYTES_COMPLETE; in tcp_do_segment()
1917 tp->snd_wl1 = th->th_seq; in tcp_do_segment()
1922 tp->rcv_up = tp->rcv_nxt; in tcp_do_segment()
1925 TCP_PROBE3(debug__input, tp, th, m); in tcp_do_segment()
1927 newsize = tcp_autorcvbuf(m, th, so, tp, tlen); in tcp_do_segment()
1947 if (DELAY_ACK(tp, tlen)) { in tcp_do_segment()
1948 tp->t_flags |= TF_DELACK; in tcp_do_segment()
1950 tp->t_flags |= TF_ACKNOW; in tcp_do_segment()
1951 (void) tcp_output(tp); in tcp_do_segment()
1966 tp->rcv_wnd = imax(win, (int)(tp->rcv_adv - tp->rcv_nxt)); in tcp_do_segment()
1968 switch (tp->t_state) { in tcp_do_segment()
1979 (SEQ_LEQ(th->th_ack, tp->snd_una) || in tcp_do_segment()
1980 SEQ_GT(th->th_ack, tp->snd_max))) { in tcp_do_segment()
1982 tcp_log_end_status(tp, TCP_EI_STATUS_RST_IN_FRONT); in tcp_do_segment()
1985 if (tp->t_flags & TF_FASTOPEN) { in tcp_do_segment()
1995 tcp_log_end_status(tp, TCP_EI_STATUS_RST_IN_FRONT); in tcp_do_segment()
1999 if ((tcp_timer_active(tp, TT_DELACK) || in tcp_do_segment()
2000 tcp_timer_active(tp, TT_REXMT))) in tcp_do_segment()
2025 TCP_PROBE5(connect__refused, NULL, tp, in tcp_do_segment()
2026 m, tp, th); in tcp_do_segment()
2027 tcp_log_end_status(tp, TCP_EI_STATUS_RST_IN_FRONT); in tcp_do_segment()
2028 tp = tcp_drop(tp, ECONNREFUSED); in tcp_do_segment()
2035 tp->irs = th->th_seq; in tcp_do_segment()
2036 tcp_rcvseqinit(tp); in tcp_do_segment()
2046 if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) == in tcp_do_segment()
2048 tp->rcv_scale = tp->request_r_scale; in tcp_do_segment()
2050 tp->rcv_adv += min(tp->rcv_wnd, in tcp_do_segment()
2051 TCP_MAXWIN << tp->rcv_scale); in tcp_do_segment()
2052 tp->snd_una++; /* SYN is acked */ in tcp_do_segment()
2053 if (SEQ_LT(tp->snd_nxt, tp->snd_una)) in tcp_do_segment()
2054 tp->snd_nxt = tp->snd_una; in tcp_do_segment()
2059 if ((tp->t_flags & TF_FASTOPEN) && in tcp_do_segment()
2060 (tp->snd_una != tp->snd_max)) { in tcp_do_segment()
2061 tp->snd_nxt = th->th_ack; in tcp_do_segment()
2068 if (DELAY_ACK(tp, tlen) && tlen != 0 && !tfo_partial_ack) in tcp_do_segment()
2069 tcp_timer_activate(tp, TT_DELACK, in tcp_do_segment()
2072 tp->t_flags |= TF_ACKNOW; in tcp_do_segment()
2074 tcp_ecn_input_syn_sent(tp, thflags, iptos); in tcp_do_segment()
2082 tp->t_starttime = ticks; in tcp_do_segment()
2083 if (tp->t_flags & TF_NEEDFIN) { in tcp_do_segment()
2084 tp->t_acktime = ticks; in tcp_do_segment()
2085 tcp_state_change(tp, TCPS_FIN_WAIT_1); in tcp_do_segment()
2086 tp->t_flags &= ~TF_NEEDFIN; in tcp_do_segment()
2089 tcp_state_change(tp, TCPS_ESTABLISHED); in tcp_do_segment()
2090 TCP_PROBE5(connect__established, NULL, tp, in tcp_do_segment()
2091 m, tp, th); in tcp_do_segment()
2092 cc_conn_init(tp); in tcp_do_segment()
2093 tcp_timer_activate(tp, TT_KEEP, in tcp_do_segment()
2094 TP_KEEPIDLE(tp)); in tcp_do_segment()
2105 tp->t_flags |= (TF_ACKNOW | TF_NEEDSYN | TF_SONOTCONN); in tcp_do_segment()
2106 tcp_timer_activate(tp, TT_REXMT, 0); in tcp_do_segment()
2107 tcp_state_change(tp, TCPS_SYN_RECEIVED); in tcp_do_segment()
2116 if (tlen > tp->rcv_wnd) { in tcp_do_segment()
2117 todrop = tlen - tp->rcv_wnd; in tcp_do_segment()
2119 tlen = tp->rcv_wnd; in tcp_do_segment()
2124 tp->snd_wl1 = th->th_seq - 1; in tcp_do_segment()
2125 tp->rcv_up = th->th_seq; in tcp_do_segment()
2166 if ((SEQ_GEQ(th->th_seq, tp->last_ack_sent) && in tcp_do_segment()
2167 SEQ_LT(th->th_seq, tp->last_ack_sent + tp->rcv_wnd)) || in tcp_do_segment()
2168 (tp->rcv_wnd == 0 && tp->last_ack_sent == th->th_seq)) { in tcp_do_segment()
2169 KASSERT(tp->t_state != TCPS_SYN_SENT, in tcp_do_segment()
2171 __func__, th, tp)); in tcp_do_segment()
2174 tp->last_ack_sent == th->th_seq) { in tcp_do_segment()
2177 switch (tp->t_state) { in tcp_do_segment()
2191 tcp_log_end_status(tp, TCP_EI_STATUS_CLIENT_RST); in tcp_do_segment()
2192 tp = tcp_close(tp); in tcp_do_segment()
2196 tcp_send_challenge_ack(tp, th, m); in tcp_do_segment()
2207 if ((thflags & TH_SYN) && tp->t_state != TCPS_SYN_SENT && in tcp_do_segment()
2208 tp->t_state != TCPS_SYN_RECEIVED) { in tcp_do_segment()
2211 SEQ_GEQ(th->th_seq, tp->last_ack_sent) && in tcp_do_segment()
2212 SEQ_LT(th->th_seq, tp->last_ack_sent + tp->rcv_wnd)) { in tcp_do_segment()
2213 tcp_log_end_status(tp, TCP_EI_STATUS_RST_IN_FRONT); in tcp_do_segment()
2214 tp = tcp_drop(tp, ECONNRESET); in tcp_do_segment()
2217 tcp_ecn_input_syn_sent(tp, thflags, iptos); in tcp_do_segment()
2218 tcp_send_challenge_ack(tp, th, m); in tcp_do_segment()
2228 if ((to.to_flags & TOF_TS) != 0 && tp->ts_recent && in tcp_do_segment()
2229 TSTMP_LT(to.to_tsval, tp->ts_recent)) { in tcp_do_segment()
2231 if (tcp_ts_getticks() - tp->ts_recent_age > TCP_PAWS_IDLE) { in tcp_do_segment()
2243 tp->ts_recent = 0; in tcp_do_segment()
2261 if (tp->t_state == TCPS_SYN_RECEIVED && SEQ_LT(th->th_seq, tp->irs)) { in tcp_do_segment()
2263 tcp_log_end_status(tp, TCP_EI_STATUS_RST_IN_FRONT); in tcp_do_segment()
2267 todrop = tp->rcv_nxt - th->th_seq; in tcp_do_segment()
2294 tp->t_flags |= TF_ACKNOW; in tcp_do_segment()
2305 if ((todrop > 0) && (tp->t_flags & TF_SACK_PERMIT)) { in tcp_do_segment()
2306 tcp_update_sack_list(tp, th->th_seq, in tcp_do_segment()
2312 tp->t_flags |= TF_ACKNOW; in tcp_do_segment()
2330 if ((tp->t_flags & TF_CLOSED) && tlen > 0 && in tcp_do_segment()
2331 TCPS_HAVERCVDFIN(tp->t_state) == 0) { in tcp_do_segment()
2336 s, __func__, tcpstates[tp->t_state], tlen); in tcp_do_segment()
2339 tcp_log_end_status(tp, TCP_EI_STATUS_DATA_A_CLOSE); in tcp_do_segment()
2341 tcp_log_end_status(tp, TCP_EI_STATUS_SERVER_RST); in tcp_do_segment()
2342 tp = tcp_close(tp); in tcp_do_segment()
2352 todrop = (th->th_seq + tlen) - (tp->rcv_nxt + tp->rcv_wnd); in tcp_do_segment()
2364 if (tp->rcv_wnd == 0 && th->th_seq == tp->rcv_nxt) { in tcp_do_segment()
2365 tp->t_flags |= TF_ACKNOW; in tcp_do_segment()
2395 SEQ_LEQ(th->th_seq, tp->last_ack_sent) && in tcp_do_segment()
2396 SEQ_LEQ(tp->last_ack_sent, th->th_seq + tlen + in tcp_do_segment()
2398 tp->ts_recent_age = tcp_ts_getticks(); in tcp_do_segment()
2399 tp->ts_recent = to.to_tsval; in tcp_do_segment()
2408 if (tp->t_state == TCPS_SYN_RECEIVED || in tcp_do_segment()
2409 (tp->t_flags & TF_NEEDSYN)) { in tcp_do_segment()
2410 if (tp->t_state == TCPS_SYN_RECEIVED && in tcp_do_segment()
2411 (tp->t_flags & TF_FASTOPEN)) { in tcp_do_segment()
2412 tp->snd_wnd = tiwin; in tcp_do_segment()
2413 cc_conn_init(tp); in tcp_do_segment()
2416 } else if (tp->t_flags & TF_ACKNOW) in tcp_do_segment()
2425 if (SEQ_GEQ(tp->snd_una, tp->iss + (TCP_MAXWIN << tp->snd_scale))) { in tcp_do_segment()
2427 tp->t_flags2 |= TF2_NO_ISS_CHECK; in tcp_do_segment()
2433 if (tp->t_flags2 & TF2_NO_ISS_CHECK) { in tcp_do_segment()
2435 seq_min = tp->snd_una - tp->max_sndwnd; in tcp_do_segment()
2438 if (SEQ_GT(tp->iss + 1, tp->snd_una - tp->max_sndwnd)) { in tcp_do_segment()
2440 seq_min = tp->iss + 1; in tcp_do_segment()
2447 seq_min = tp->snd_una - tp->max_sndwnd; in tcp_do_segment()
2456 tcp_send_challenge_ack(tp, th, m); in tcp_do_segment()
2461 switch (tp->t_state) { in tcp_do_segment()
2470 if (tp->t_flags & TF_SONOTCONN) { in tcp_do_segment()
2480 tp->t_flags &= ~TF_SONOTCONN; in tcp_do_segment()
2484 if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) == in tcp_do_segment()
2486 tp->rcv_scale = tp->request_r_scale; in tcp_do_segment()
2488 tp->snd_wnd = tiwin; in tcp_do_segment()
2494 tp->t_starttime = ticks; in tcp_do_segment()
2495 if ((tp->t_flags & TF_FASTOPEN) && tp->t_tfo_pending) { in tcp_do_segment()
2496 tcp_fastopen_decrement_counter(tp->t_tfo_pending); in tcp_do_segment()
2497 tp->t_tfo_pending = NULL; in tcp_do_segment()
2499 if (tp->t_flags & TF_NEEDFIN) { in tcp_do_segment()
2500 tp->t_acktime = ticks; in tcp_do_segment()
2501 tcp_state_change(tp, TCPS_FIN_WAIT_1); in tcp_do_segment()
2502 tp->t_flags &= ~TF_NEEDFIN; in tcp_do_segment()
2504 tcp_state_change(tp, TCPS_ESTABLISHED); in tcp_do_segment()
2505 TCP_PROBE5(accept__established, NULL, tp, in tcp_do_segment()
2506 m, tp, th); in tcp_do_segment()
2514 if (!(tp->t_flags & TF_FASTOPEN)) in tcp_do_segment()
2515 cc_conn_init(tp); in tcp_do_segment()
2516 tcp_timer_activate(tp, TT_KEEP, TP_KEEPIDLE(tp)); in tcp_do_segment()
2523 if (SEQ_GT(th->th_ack, tp->snd_una) && !(tp->t_flags & TF_NEEDSYN)) in tcp_do_segment()
2530 (void) tcp_reass(tp, (struct tcphdr *)0, NULL, 0, in tcp_do_segment()
2532 tcp_handle_wakeup(tp); in tcp_do_segment()
2534 tp->snd_wl1 = th->th_seq - 1; in tcp_do_segment()
2551 if (SEQ_GT(th->th_ack, tp->snd_max)) { in tcp_do_segment()
2555 if (tcp_is_sack_recovery(tp, &to)) { in tcp_do_segment()
2556 sack_changed = tcp_sack_doack(tp, &to, th->th_ack); in tcp_do_segment()
2558 (tp->t_flags & TF_LRD)) { in tcp_do_segment()
2559 tcp_sack_lost_retransmission(tp, th); in tcp_do_segment()
2566 tp->sackhint.sacked_bytes = 0; in tcp_do_segment()
2570 hhook_run_tcp_est_in(tp, th, &to); in tcp_do_segment()
2573 if (SEQ_LEQ(th->th_ack, tp->snd_una)) { in tcp_do_segment()
2574 maxseg = tcp_maxseg(tp); in tcp_do_segment()
2576 (tiwin == tp->snd_wnd || in tcp_do_segment()
2577 (tp->t_flags & TF_SACK_PERMIT))) { in tcp_do_segment()
2586 (TCPS_HAVERCVDFIN(tp->t_state) == 0)) { in tcp_do_segment()
2587 tp->t_dupacks = 0; in tcp_do_segment()
2628 if (th->th_ack != tp->snd_una || in tcp_do_segment()
2629 (tcp_is_sack_recovery(tp, &to) && in tcp_do_segment()
2632 } else if (!tcp_timer_active(tp, TT_REXMT)) { in tcp_do_segment()
2633 tp->t_dupacks = 0; in tcp_do_segment()
2634 } else if (++tp->t_dupacks > tcprexmtthresh || in tcp_do_segment()
2635 IN_FASTRECOVERY(tp->t_flags)) { in tcp_do_segment()
2636 cc_ack_received(tp, th, nsegs, in tcp_do_segment()
2639 IN_FASTRECOVERY(tp->t_flags) && in tcp_do_segment()
2640 (tp->t_flags & TF_SACK_PERMIT)) { in tcp_do_segment()
2641 tcp_do_prr_ack(tp, th, &to, in tcp_do_segment()
2643 } else if (tcp_is_sack_recovery(tp, &to) && in tcp_do_segment()
2644 IN_FASTRECOVERY(tp->t_flags) && in tcp_do_segment()
2645 (tp->snd_nxt == tp->snd_max)) { in tcp_do_segment()
2654 awnd = tcp_compute_pipe(tp); in tcp_do_segment()
2655 if (awnd < tp->snd_ssthresh) { in tcp_do_segment()
2656 tp->snd_cwnd += imax(maxseg, in tcp_do_segment()
2658 tp->sackhint.delivered_data)); in tcp_do_segment()
2659 if (tp->snd_cwnd > tp->snd_ssthresh) in tcp_do_segment()
2660 tp->snd_cwnd = tp->snd_ssthresh; in tcp_do_segment()
2662 } else if (tcp_is_sack_recovery(tp, &to) && in tcp_do_segment()
2663 IN_FASTRECOVERY(tp->t_flags) && in tcp_do_segment()
2664 SEQ_LT(tp->snd_nxt, tp->snd_max)) { in tcp_do_segment()
2665 tp->snd_cwnd += imax(maxseg, in tcp_do_segment()
2667 tp->sackhint.delivered_data)); in tcp_do_segment()
2669 tp->snd_cwnd += maxseg; in tcp_do_segment()
2671 (void) tcp_output(tp); in tcp_do_segment()
2673 } else if (tp->t_dupacks == tcprexmtthresh || in tcp_do_segment()
2674 (tp->t_flags & TF_SACK_PERMIT && in tcp_do_segment()
2676 tp->sackhint.sacked_bytes > in tcp_do_segment()
2687 tp->t_dupacks = tcprexmtthresh; in tcp_do_segment()
2688 tcp_seq onxt = tp->snd_nxt; in tcp_do_segment()
2697 if (tcp_is_sack_recovery(tp, &to)) { in tcp_do_segment()
2698 if (IN_FASTRECOVERY(tp->t_flags)) { in tcp_do_segment()
2699 tp->t_dupacks = 0; in tcp_do_segment()
2704 tp->snd_recover)) { in tcp_do_segment()
2705 tp->t_dupacks = 0; in tcp_do_segment()
2710 cc_cong_signal(tp, th, CC_NDUPACK); in tcp_do_segment()
2711 cc_ack_received(tp, th, nsegs, in tcp_do_segment()
2713 tcp_timer_activate(tp, TT_REXMT, 0); in tcp_do_segment()
2714 tp->t_rtttime = 0; in tcp_do_segment()
2720 if (tcp_is_sack_recovery(tp, &to)) { in tcp_do_segment()
2725 tp->sackhint.prr_delivered = in tcp_do_segment()
2726 imin(tp->snd_max - th->th_ack, in tcp_do_segment()
2727 (tp->snd_limited + 1) * maxseg); in tcp_do_segment()
2729 tp->sackhint.prr_delivered = in tcp_do_segment()
2732 tp->sackhint.recover_fs = max(1, in tcp_do_segment()
2733 tp->snd_nxt - tp->snd_una); in tcp_do_segment()
2735 tp->snd_limited = 0; in tcp_do_segment()
2736 if (tcp_is_sack_recovery(tp, &to)) { in tcp_do_segment()
2743 tcp_resend_sackholes(tp); in tcp_do_segment()
2745 tp->snd_nxt = tp->snd_max; in tcp_do_segment()
2746 tp->snd_cwnd = tcp_compute_pipe(tp) + in tcp_do_segment()
2748 (void) tcp_output(tp); in tcp_do_segment()
2750 tp->snd_cwnd = tp->snd_ssthresh; in tcp_do_segment()
2751 if (SEQ_GT(th->th_ack, tp->snd_una)) { in tcp_do_segment()
2756 tp->snd_nxt = th->th_ack; in tcp_do_segment()
2757 tp->snd_cwnd = maxseg; in tcp_do_segment()
2758 (void) tcp_output(tp); in tcp_do_segment()
2759 KASSERT(tp->snd_limited <= 2, in tcp_do_segment()
2762 tp->snd_cwnd = tp->snd_ssthresh + in tcp_do_segment()
2764 (tp->t_dupacks - tp->snd_limited); in tcp_do_segment()
2765 if (SEQ_GT(onxt, tp->snd_nxt)) in tcp_do_segment()
2766 tp->snd_nxt = onxt; in tcp_do_segment()
2779 cc_ack_received(tp, th, nsegs, CC_DUPACK); in tcp_do_segment()
2780 uint32_t oldcwnd = tp->snd_cwnd; in tcp_do_segment()
2781 tcp_seq oldsndmax = tp->snd_max; in tcp_do_segment()
2785 KASSERT(tp->t_dupacks == 1 || in tcp_do_segment()
2786 tp->t_dupacks == 2, in tcp_do_segment()
2789 if (tp->t_dupacks == 1) in tcp_do_segment()
2790 tp->snd_limited = 0; in tcp_do_segment()
2791 if ((tp->snd_nxt == tp->snd_max) && in tcp_do_segment()
2792 (tp->t_rxtshift == 0)) in tcp_do_segment()
2793 tp->snd_cwnd = in tcp_do_segment()
2794 SEQ_SUB(tp->snd_nxt, in tcp_do_segment()
2795 tp->snd_una) - in tcp_do_segment()
2796 tcp_sack_adjust(tp); in tcp_do_segment()
2797 tp->snd_cwnd += in tcp_do_segment()
2798 (tp->t_dupacks - tp->snd_limited) * in tcp_do_segment()
2799 maxseg - tcp_sack_adjust(tp); in tcp_do_segment()
2808 if (tp->t_flags & TF_ACKNOW || in tcp_do_segment()
2810 SEQ_SUB(tp->snd_nxt, tp->snd_una))) { in tcp_do_segment()
2811 (void) tcp_output(tp); in tcp_do_segment()
2813 sent = SEQ_SUB(tp->snd_max, oldsndmax); in tcp_do_segment()
2815 KASSERT((tp->t_dupacks == 2 && in tcp_do_segment()
2816 tp->snd_limited == 0) || in tcp_do_segment()
2818 tp->t_flags & TF_SENTFIN), in tcp_do_segment()
2821 tp->snd_limited = 2; in tcp_do_segment()
2823 ++tp->snd_limited; in tcp_do_segment()
2825 tp->snd_cwnd = oldcwnd; in tcp_do_segment()
2835 tp->t_dupacks = 0; in tcp_do_segment()
2845 if (tcp_is_sack_recovery(tp, &to) && in tcp_do_segment()
2846 (((tp->t_rxtshift == 0) && (sack_changed != SACK_NOCHANGE)) || in tcp_do_segment()
2847 ((tp->t_rxtshift > 0) && (sack_changed == SACK_NEWLOSS))) && in tcp_do_segment()
2848 (tp->snd_nxt == tp->snd_max)) { in tcp_do_segment()
2849 tp->t_dupacks++; in tcp_do_segment()
2851 if (!IN_FASTRECOVERY(tp->t_flags) && in tcp_do_segment()
2852 (tp->sackhint.sacked_bytes > in tcp_do_segment()
2854 (maxseg = tcp_maxseg(tp))))) { in tcp_do_segment()
2861 KASSERT(SEQ_GT(th->th_ack, tp->snd_una), in tcp_do_segment()
2868 if (SEQ_LT(th->th_ack, tp->snd_recover)) { in tcp_do_segment()
2869 if (IN_FASTRECOVERY(tp->t_flags)) { in tcp_do_segment()
2870 if (tp->t_flags & TF_SACK_PERMIT) { in tcp_do_segment()
2873 tcp_timer_activate(tp, in tcp_do_segment()
2875 tp->t_rtttime = 0; in tcp_do_segment()
2876 tcp_do_prr_ack(tp, th, &to, in tcp_do_segment()
2878 tp->t_flags |= TF_ACKNOW; in tcp_do_segment()
2879 (void) tcp_output(tp); in tcp_do_segment()
2881 tcp_sack_partialack(tp, th, in tcp_do_segment()
2885 tcp_newreno_partial_ack(tp, th); in tcp_do_segment()
2887 } else if (IN_CONGRECOVERY(tp->t_flags) && in tcp_do_segment()
2889 tp->sackhint.delivered_data = in tcp_do_segment()
2890 BYTES_THIS_ACK(tp, th); in tcp_do_segment()
2891 tp->snd_fack = th->th_ack; in tcp_do_segment()
2896 tcp_do_prr_ack(tp, th, &to, SACK_CHANGE, in tcp_do_segment()
2898 (void) tcp_output(tp); in tcp_do_segment()
2905 if (tp->t_flags & TF_NEEDSYN) { in tcp_do_segment()
2913 tp->t_flags &= ~TF_NEEDSYN; in tcp_do_segment()
2914 tp->snd_una++; in tcp_do_segment()
2916 if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) == in tcp_do_segment()
2918 tp->rcv_scale = tp->request_r_scale; in tcp_do_segment()
2934 tp->snd_una++; in tcp_do_segment()
2935 acked = BYTES_THIS_ACK(tp, th); in tcp_do_segment()
2938 tp->snd_una, th->th_ack, tp, m)); in tcp_do_segment()
2949 if (tp->t_rxtshift == 1 && in tcp_do_segment()
2950 tp->t_flags & TF_PREVVALID && in tcp_do_segment()
2951 tp->t_badrxtwin != 0 && in tcp_do_segment()
2954 TSTMP_LT(to.to_tsecr, tp->t_badrxtwin)) in tcp_do_segment()
2955 cc_cong_signal(tp, th, CC_RTO_ERR); in tcp_do_segment()
2975 if (!tp->t_rttlow || tp->t_rttlow > t) in tcp_do_segment()
2976 tp->t_rttlow = t; in tcp_do_segment()
2977 tcp_xmit_timer(tp, TCP_TS_TO_TICKS(t) + 1); in tcp_do_segment()
2978 } else if (tp->t_rtttime && SEQ_GT(th->th_ack, tp->t_rtseq)) { in tcp_do_segment()
2979 if (!tp->t_rttlow || tp->t_rttlow > ticks - tp->t_rtttime) in tcp_do_segment()
2980 tp->t_rttlow = ticks - tp->t_rtttime; in tcp_do_segment()
2981 tcp_xmit_timer(tp, ticks - tp->t_rtttime); in tcp_do_segment()
2991 if ((tp->t_state <= TCPS_CLOSE_WAIT && in tcp_do_segment()
2994 tp->t_acktime = 0; in tcp_do_segment()
2996 tp->t_acktime = ticks; in tcp_do_segment()
3004 if (th->th_ack == tp->snd_max) { in tcp_do_segment()
3005 tcp_timer_activate(tp, TT_REXMT, 0); in tcp_do_segment()
3007 } else if (!tcp_timer_active(tp, TT_PERSIST)) in tcp_do_segment()
3008 tcp_timer_activate(tp, TT_REXMT, TP_RXTCUR(tp)); in tcp_do_segment()
3024 cc_ack_received(tp, th, nsegs, CC_ACK); in tcp_do_segment()
3027 if (tp->snd_wnd >= sbavail(&so->so_snd)) in tcp_do_segment()
3028 tp->snd_wnd -= sbavail(&so->so_snd); in tcp_do_segment()
3030 tp->snd_wnd = 0; in tcp_do_segment()
3036 if (tp->snd_wnd >= (uint32_t) acked) in tcp_do_segment()
3037 tp->snd_wnd -= acked; in tcp_do_segment()
3039 tp->snd_wnd = 0; in tcp_do_segment()
3046 if (!IN_RECOVERY(tp->t_flags) && in tcp_do_segment()
3047 SEQ_GT(tp->snd_una, tp->snd_recover) && in tcp_do_segment()
3048 SEQ_LEQ(th->th_ack, tp->snd_recover)) in tcp_do_segment()
3049 tp->snd_recover = th->th_ack - 1; in tcp_do_segment()
3050 tp->snd_una = th->th_ack; in tcp_do_segment()
3051 if (IN_RECOVERY(tp->t_flags) && in tcp_do_segment()
3052 SEQ_GEQ(th->th_ack, tp->snd_recover)) { in tcp_do_segment()
3053 cc_post_recovery(tp, th); in tcp_do_segment()
3055 if (SEQ_GT(tp->snd_una, tp->snd_recover)) { in tcp_do_segment()
3056 tp->snd_recover = tp->snd_una; in tcp_do_segment()
3058 if (SEQ_LT(tp->snd_nxt, tp->snd_una)) in tcp_do_segment()
3059 tp->snd_nxt = tp->snd_una; in tcp_do_segment()
3061 switch (tp->t_state) { in tcp_do_segment()
3077 tcp_free_sackholes(tp); in tcp_do_segment()
3079 tcp_timer_activate(tp, TT_2MSL, in tcp_do_segment()
3082 TP_MAXIDLE(tp))); in tcp_do_segment()
3084 tcp_state_change(tp, TCPS_FIN_WAIT_2); in tcp_do_segment()
3096 tcp_twstart(tp); in tcp_do_segment()
3110 tp = tcp_close(tp); in tcp_do_segment()
3125 (SEQ_LT(tp->snd_wl1, th->th_seq) || in tcp_do_segment()
3126 (tp->snd_wl1 == th->th_seq && (SEQ_LT(tp->snd_wl2, th->th_ack) || in tcp_do_segment()
3127 (tp->snd_wl2 == th->th_ack && tiwin > tp->snd_wnd))))) { in tcp_do_segment()
3130 tp->snd_wl2 == th->th_ack && tiwin > tp->snd_wnd) in tcp_do_segment()
3132 tp->snd_wnd = tiwin; in tcp_do_segment()
3133 tp->snd_wl1 = th->th_seq; in tcp_do_segment()
3134 tp->snd_wl2 = th->th_ack; in tcp_do_segment()
3135 if (tp->snd_wnd > tp->max_sndwnd) in tcp_do_segment()
3136 tp->max_sndwnd = tp->snd_wnd; in tcp_do_segment()
3144 TCPS_HAVERCVDFIN(tp->t_state) == 0) { in tcp_do_segment()
3172 if (SEQ_GT(th->th_seq+th->th_urp, tp->rcv_up)) { in tcp_do_segment()
3173 tp->rcv_up = th->th_seq + th->th_urp; in tcp_do_segment()
3175 (tp->rcv_up - tp->rcv_nxt) - 1; in tcp_do_segment()
3179 tp->t_oobflags &= ~(TCPOOB_HAVEDATA | TCPOOB_HADDATA); in tcp_do_segment()
3199 if (SEQ_GT(tp->rcv_nxt, tp->rcv_up)) in tcp_do_segment()
3200 tp->rcv_up = tp->rcv_nxt; in tcp_do_segment()
3213 tfo_syn = ((tp->t_state == TCPS_SYN_RECEIVED) && in tcp_do_segment()
3214 (tp->t_flags & TF_FASTOPEN)); in tcp_do_segment()
3216 TCPS_HAVERCVDFIN(tp->t_state) == 0) { in tcp_do_segment()
3218 tcp_seq save_rnxt = tp->rcv_nxt; in tcp_do_segment()
3233 if (th->th_seq == tp->rcv_nxt && in tcp_do_segment()
3234 SEGQ_EMPTY(tp) && in tcp_do_segment()
3235 (TCPS_HAVEESTABLISHED(tp->t_state) || in tcp_do_segment()
3237 if (DELAY_ACK(tp, tlen) || tfo_syn) in tcp_do_segment()
3238 tp->t_flags |= TF_DELACK; in tcp_do_segment()
3240 tp->t_flags |= TF_ACKNOW; in tcp_do_segment()
3241 tp->rcv_nxt += tlen; in tcp_do_segment()
3243 ((tp->t_flags2 & TF2_FBYTES_COMPLETE) == 0) && in tcp_do_segment()
3244 (tp->t_fbyte_in == 0)) { in tcp_do_segment()
3245 tp->t_fbyte_in = ticks; in tcp_do_segment()
3246 if (tp->t_fbyte_in == 0) in tcp_do_segment()
3247 tp->t_fbyte_in = 1; in tcp_do_segment()
3248 if (tp->t_fbyte_out && tp->t_fbyte_in) in tcp_do_segment()
3249 tp->t_flags2 |= TF2_FBYTES_COMPLETE; in tcp_do_segment()
3259 tp->t_flags |= TF_WAKESOR; in tcp_do_segment()
3269 thflags = tcp_reass(tp, th, &temp, &tlen, m); in tcp_do_segment()
3270 tp->t_flags |= TF_ACKNOW; in tcp_do_segment()
3272 if ((tp->t_flags & TF_SACK_PERMIT) && in tcp_do_segment()
3274 TCPS_HAVEESTABLISHED(tp->t_state)) { in tcp_do_segment()
3280 tcp_update_sack_list(tp, save_start, in tcp_do_segment()
3282 } else if ((tlen > 0) && SEQ_GT(tp->rcv_nxt, save_rnxt)) { in tcp_do_segment()
3283 if ((tp->rcv_numsacks >= 1) && in tcp_do_segment()
3284 (tp->sackblks[0].end == save_start)) { in tcp_do_segment()
3289 tcp_update_sack_list(tp, in tcp_do_segment()
3290 tp->sackblks[0].start, in tcp_do_segment()
3291 tp->sackblks[0].end); in tcp_do_segment()
3293 tcp_update_dsack_list(tp, save_start, in tcp_do_segment()
3298 tcp_update_dsack_list(tp, save_start, in tcp_do_segment()
3301 tcp_update_dsack_list(tp, save_start, in tcp_do_segment()
3305 tcp_handle_wakeup(tp); in tcp_do_segment()
3313 if (SEQ_GT(tp->rcv_adv, tp->rcv_nxt)) in tcp_do_segment()
3314 len = so->so_rcv.sb_hiwat - (tp->rcv_adv - tp->rcv_nxt); in tcp_do_segment()
3327 tcpstates[tp->t_state], tlen); in tcp_do_segment()
3334 tcpstates[tp->t_state], tlen); in tcp_do_segment()
3343 tcpstates[tp->t_state]); in tcp_do_segment()
3357 if (TCPS_HAVERCVDFIN(tp->t_state) == 0) { in tcp_do_segment()
3367 if (tp->t_flags & TF_NEEDSYN) in tcp_do_segment()
3368 tp->t_flags |= TF_DELACK; in tcp_do_segment()
3370 tp->t_flags |= TF_ACKNOW; in tcp_do_segment()
3371 tp->rcv_nxt++; in tcp_do_segment()
3373 switch (tp->t_state) { in tcp_do_segment()
3379 tp->t_starttime = ticks; in tcp_do_segment()
3382 tcp_state_change(tp, TCPS_CLOSE_WAIT); in tcp_do_segment()
3390 tcp_state_change(tp, TCPS_CLOSING); in tcp_do_segment()
3399 tcp_twstart(tp); in tcp_do_segment()
3403 TCP_PROBE3(debug__input, tp, th, m); in tcp_do_segment()
3408 if (needoutput || (tp->t_flags & TF_ACKNOW)) { in tcp_do_segment()
3409 (void) tcp_output(tp); in tcp_do_segment()
3414 if (tp->t_flags & TF_DELACK) { in tcp_do_segment()
3415 tp->t_flags &= ~TF_DELACK; in tcp_do_segment()
3416 tcp_timer_activate(tp, TT_DELACK, tcp_delacktime); in tcp_do_segment()
3437 if (tp->t_state == TCPS_SYN_RECEIVED && (thflags & TH_ACK) && in tcp_do_segment()
3438 (SEQ_GT(tp->snd_una, th->th_ack) || in tcp_do_segment()
3439 SEQ_GT(th->th_ack, tp->snd_max)) ) { in tcp_do_segment()
3441 tcp_log_end_status(tp, TCP_EI_STATUS_RST_IN_FRONT); in tcp_do_segment()
3444 TCP_PROBE3(debug__input, tp, th, m); in tcp_do_segment()
3445 tp->t_flags |= TF_ACKNOW; in tcp_do_segment()
3446 (void) tcp_output(tp); in tcp_do_segment()
3452 if (tp != NULL) { in tcp_do_segment()
3453 tcp_dropwithreset(m, th, tp, tlen, rstreason); in tcp_do_segment()
3463 TCP_PROBE3(debug__input, tp, th, m); in tcp_do_segment()
3464 if (tp != NULL) { in tcp_do_segment()
3476 tcp_dropwithreset(struct mbuf *m, struct tcphdr *th, struct tcpcb *tp, in tcp_dropwithreset() argument
3486 if (tp != NULL) { in tcp_dropwithreset()
3487 INP_LOCK_ASSERT(tptoinpcb(tp)); in tcp_dropwithreset()
3522 tcp_respond(tp, mtod(m, void *), th, m, (tcp_seq)0, in tcp_dropwithreset()
3529 tcp_respond(tp, mtod(m, void *), th, m, th->th_seq+tlen, in tcp_dropwithreset()
3657 struct tcpcb *tp = sototcpcb(so); in tcp_pulloutofband() local
3659 INP_WLOCK_ASSERT(tptoinpcb(tp)); in tcp_pulloutofband()
3661 tp->t_iobc = *cp; in tcp_pulloutofband()
3662 tp->t_oobflags |= TCPOOB_HAVEDATA; in tcp_pulloutofband()
3682 tcp_xmit_timer(struct tcpcb *tp, int rtt) in tcp_xmit_timer() argument
3686 INP_WLOCK_ASSERT(tptoinpcb(tp)); in tcp_xmit_timer()
3689 if (tp->t_rttupdated < UCHAR_MAX) in tcp_xmit_timer()
3690 tp->t_rttupdated++; in tcp_xmit_timer()
3692 stats_voi_update_abs_u32(tp->t_stats, VOI_TCP_RTT, in tcp_xmit_timer()
3695 if ((tp->t_srtt != 0) && (tp->t_rxtshift <= TCP_RTT_INVALIDATE)) { in tcp_xmit_timer()
3704 - (tp->t_srtt >> (TCP_RTT_SHIFT - TCP_DELTA_SHIFT)); in tcp_xmit_timer()
3706 if ((tp->t_srtt += delta) <= 0) in tcp_xmit_timer()
3707 tp->t_srtt = 1; in tcp_xmit_timer()
3721 delta -= tp->t_rttvar >> (TCP_RTTVAR_SHIFT - TCP_DELTA_SHIFT); in tcp_xmit_timer()
3722 if ((tp->t_rttvar += delta) <= 0) in tcp_xmit_timer()
3723 tp->t_rttvar = 1; in tcp_xmit_timer()
3730 tp->t_srtt = rtt << TCP_RTT_SHIFT; in tcp_xmit_timer()
3731 tp->t_rttvar = rtt << (TCP_RTTVAR_SHIFT - 1); in tcp_xmit_timer()
3733 tp->t_rtttime = 0; in tcp_xmit_timer()
3734 tp->t_rxtshift = 0; in tcp_xmit_timer()
3747 TCPT_RANGESET(tp->t_rxtcur, TCP_REXMTVAL(tp), in tcp_xmit_timer()
3748 max(tp->t_rttmin, rtt + 2), TCPTV_REXMTMAX); in tcp_xmit_timer()
3757 tp->t_softerror = 0; in tcp_xmit_timer()
3782 tcp_mss_update(struct tcpcb *tp, int offer, int mtuoffer, in tcp_mss_update() argument
3787 struct inpcb *inp = tptoinpcb(tp); in tcp_mss_update()
3800 if (tp->t_port) in tcp_mss_update()
3811 tp->t_maxseg = V_tcp_v6mssdflt; in tcp_mss_update()
3820 tp->t_maxseg = V_tcp_mssdflt; in tcp_mss_update()
3846 offer = tp->t_maxseg; in tcp_mss_update()
3924 tp->t_maxseg = mss; in tcp_mss_update()
3925 if (tp->t_maxseg < V_tcp_mssdflt) { in tcp_mss_update()
3931 tp->t_flags2 |= TF2_PROC_SACK_PROHIBIT; in tcp_mss_update()
3933 tp->t_flags2 &= ~TF2_PROC_SACK_PROHIBIT; in tcp_mss_update()
3939 tcp_mss(struct tcpcb *tp, int offer) in tcp_mss() argument
3943 struct inpcb *inp = tptoinpcb(tp); in tcp_mss()
3948 KASSERT(tp != NULL, ("%s: tp == NULL", __func__)); in tcp_mss()
3951 tcp_mss_update(tp, offer, -1, &metrics, &cap); in tcp_mss()
3953 mss = tp->t_maxseg; in tcp_mss()
3986 tp->t_maxseg = max(mss, 64); in tcp_mss()
3987 if (tp->t_maxseg < V_tcp_mssdflt) { in tcp_mss()
3993 tp->t_flags2 |= TF2_PROC_SACK_PROHIBIT; in tcp_mss()
3995 tp->t_flags2 &= ~TF2_PROC_SACK_PROHIBIT; in tcp_mss()
4014 tp->t_flags |= TF_TSO; in tcp_mss()
4015 tp->t_tsomax = cap.tsomax; in tcp_mss()
4016 tp->t_tsomaxsegcount = cap.tsomaxsegcount; in tcp_mss()
4017 tp->t_tsomaxsegsize = cap.tsomaxsegsize; in tcp_mss()
4019 tp->t_flags2 |= TF2_IPSEC_TSO; in tcp_mss()
4066 tcp_do_prr_ack(struct tcpcb *tp, struct tcphdr *th, struct tcpopt *to, in tcp_do_prr_ack() argument
4072 INP_WLOCK_ASSERT(tptoinpcb(tp)); in tcp_do_prr_ack()
4075 *maxsegp = tcp_maxseg(tp); in tcp_do_prr_ack()
4083 if (tcp_is_sack_recovery(tp, to) || in tcp_do_prr_ack()
4084 (IN_CONGRECOVERY(tp->t_flags) && in tcp_do_prr_ack()
4085 !IN_FASTRECOVERY(tp->t_flags))) { in tcp_do_prr_ack()
4086 del_data = tp->sackhint.delivered_data; in tcp_do_prr_ack()
4087 pipe = tcp_compute_pipe(tp); in tcp_do_prr_ack()
4089 if (tp->sackhint.prr_delivered < (tcprexmtthresh * maxseg + in tcp_do_prr_ack()
4090 tp->snd_recover - tp->snd_una)) { in tcp_do_prr_ack()
4093 pipe = imax(0, tp->snd_max - tp->snd_una - in tcp_do_prr_ack()
4094 imin(INT_MAX / 65536, tp->t_dupacks) * maxseg); in tcp_do_prr_ack()
4096 tp->sackhint.prr_delivered += del_data; in tcp_do_prr_ack()
4100 if (pipe >= tp->snd_ssthresh) { in tcp_do_prr_ack()
4101 if (tp->sackhint.recover_fs == 0) in tcp_do_prr_ack()
4102 tp->sackhint.recover_fs = in tcp_do_prr_ack()
4103 imax(1, tp->snd_nxt - tp->snd_una); in tcp_do_prr_ack()
4104 snd_cnt = howmany((long)tp->sackhint.prr_delivered * in tcp_do_prr_ack()
4105 tp->snd_ssthresh, tp->sackhint.recover_fs) - in tcp_do_prr_ack()
4106 tp->sackhint.prr_out + maxseg - 1; in tcp_do_prr_ack()
4119 limit = tp->sackhint.prr_delivered - in tcp_do_prr_ack()
4120 tp->sackhint.prr_out; in tcp_do_prr_ack()
4122 limit = imax(tp->sackhint.prr_delivered - in tcp_do_prr_ack()
4123 tp->sackhint.prr_out, del_data) + in tcp_do_prr_ack()
4126 snd_cnt = imin((tp->snd_ssthresh - pipe), limit); in tcp_do_prr_ack()
4134 if (IN_FASTRECOVERY(tp->t_flags)) { in tcp_do_prr_ack()
4135 if (tcp_is_sack_recovery(tp, to)) { in tcp_do_prr_ack()
4136 tp->snd_cwnd = pipe - del_data + (snd_cnt * maxseg); in tcp_do_prr_ack()
4138 tp->snd_cwnd = (tp->snd_max - tp->snd_una) + in tcp_do_prr_ack()
4141 } else if (IN_CONGRECOVERY(tp->t_flags)) { in tcp_do_prr_ack()
4142 tp->snd_cwnd = pipe - del_data + (snd_cnt * maxseg); in tcp_do_prr_ack()
4144 tp->snd_cwnd = imax(maxseg, tp->snd_cwnd); in tcp_do_prr_ack()
4154 tcp_newreno_partial_ack(struct tcpcb *tp, struct tcphdr *th) in tcp_newreno_partial_ack() argument
4156 tcp_seq onxt = tp->snd_nxt; in tcp_newreno_partial_ack()
4157 uint32_t ocwnd = tp->snd_cwnd; in tcp_newreno_partial_ack()
4158 u_int maxseg = tcp_maxseg(tp); in tcp_newreno_partial_ack()
4160 INP_WLOCK_ASSERT(tptoinpcb(tp)); in tcp_newreno_partial_ack()
4162 tcp_timer_activate(tp, TT_REXMT, 0); in tcp_newreno_partial_ack()
4163 tp->t_rtttime = 0; in tcp_newreno_partial_ack()
4164 if (IN_FASTRECOVERY(tp->t_flags)) { in tcp_newreno_partial_ack()
4165 tp->snd_nxt = th->th_ack; in tcp_newreno_partial_ack()
4170 tp->snd_cwnd = maxseg + BYTES_THIS_ACK(tp, th); in tcp_newreno_partial_ack()
4171 tp->t_flags |= TF_ACKNOW; in tcp_newreno_partial_ack()
4172 (void) tcp_output(tp); in tcp_newreno_partial_ack()
4173 tp->snd_cwnd = ocwnd; in tcp_newreno_partial_ack()
4174 if (SEQ_GT(onxt, tp->snd_nxt)) in tcp_newreno_partial_ack()
4175 tp->snd_nxt = onxt; in tcp_newreno_partial_ack()
4181 if (tp->snd_cwnd > BYTES_THIS_ACK(tp, th)) in tcp_newreno_partial_ack()
4182 tp->snd_cwnd -= BYTES_THIS_ACK(tp, th); in tcp_newreno_partial_ack()
4184 tp->snd_cwnd = 0; in tcp_newreno_partial_ack()
4185 tp->snd_cwnd += maxseg; in tcp_newreno_partial_ack()
4189 tcp_compute_pipe(struct tcpcb *tp) in tcp_compute_pipe() argument
4193 if (tp->t_fb->tfb_compute_pipe != NULL) { in tcp_compute_pipe()
4194 pipe = (*tp->t_fb->tfb_compute_pipe)(tp); in tcp_compute_pipe()
4196 pipe = tp->snd_max - tp->snd_una + in tcp_compute_pipe()
4197 tp->sackhint.sack_bytes_rexmit - in tcp_compute_pipe()
4198 tp->sackhint.sacked_bytes - in tcp_compute_pipe()
4199 tp->sackhint.lost_bytes; in tcp_compute_pipe()
4201 pipe = tp->snd_nxt - tp->snd_fack + tp->sackhint.sack_bytes_rexmit; in tcp_compute_pipe()