Lines Matching refs:tp

264 tcp_is_sack_recovery(struct tcpcb *tp, struct tcpopt *to)  in tcp_is_sack_recovery()  argument
266 return ((tp->t_flags & TF_SACK_PERMIT) && in tcp_is_sack_recovery()
268 (!TAILQ_EMPTY(&tp->snd_holes)))); in tcp_is_sack_recovery()
276 hhook_run_tcp_est_in(struct tcpcb *tp, struct tcphdr *th, struct tcpopt *to) in hhook_run_tcp_est_in() argument
281 hhook_data.tp = tp; in hhook_run_tcp_est_in()
286 &tp->t_osd); in hhook_run_tcp_est_in()
295 cc_ack_received(struct tcpcb *tp, struct tcphdr *th, uint16_t nsegs, in cc_ack_received() argument
302 INP_WLOCK_ASSERT(tptoinpcb(tp)); in cc_ack_received()
304 tp->t_ccv.nsegs = nsegs; in cc_ack_received()
305 tp->t_ccv.bytes_this_ack = BYTES_THIS_ACK(tp, th); in cc_ack_received()
306 if ((!V_tcp_do_newcwv && (tp->snd_cwnd <= tp->snd_wnd)) || in cc_ack_received()
307 (V_tcp_do_newcwv && (tp->snd_cwnd <= tp->snd_wnd) && in cc_ack_received()
308 (tp->snd_cwnd < (tcp_compute_pipe(tp) * 2)))) in cc_ack_received()
309 tp->t_ccv.flags |= CCF_CWND_LIMITED; in cc_ack_received()
311 tp->t_ccv.flags &= ~CCF_CWND_LIMITED; in cc_ack_received()
315 stats_voi_update_abs_s32(tp->t_stats, VOI_TCP_CALCFRWINDIFF, in cc_ack_received()
316 ((int32_t)tp->snd_cwnd) - tp->snd_wnd); in cc_ack_received()
317 if (!IN_RECOVERY(tp->t_flags)) in cc_ack_received()
318 stats_voi_update_abs_u32(tp->t_stats, VOI_TCP_ACKLEN, in cc_ack_received()
319 tp->t_ccv.bytes_this_ack / (tcp_maxseg(tp) * nsegs)); in cc_ack_received()
320 if ((tp->t_flags & TF_GPUTINPROG) && in cc_ack_received()
321 SEQ_GEQ(th->th_ack, tp->gput_ack)) { in cc_ack_received()
325 gput = (((int64_t)SEQ_SUB(th->th_ack, tp->gput_seq)) << 3) / in cc_ack_received()
326 max(1, tcp_ts_getticks() - tp->gput_ts); in cc_ack_received()
327 stats_voi_update_abs_u32(tp->t_stats, VOI_TCP_GPUT, in cc_ack_received()
334 if (tp->t_stats_gput_prev > 0) in cc_ack_received()
335 stats_voi_update_abs_s32(tp->t_stats, in cc_ack_received()
337 ((gput - tp->t_stats_gput_prev) * 100) / in cc_ack_received()
338 tp->t_stats_gput_prev); in cc_ack_received()
339 tp->t_flags &= ~TF_GPUTINPROG; in cc_ack_received()
340 tp->t_stats_gput_prev = gput; in cc_ack_received()
343 if (tp->snd_cwnd > tp->snd_ssthresh) { in cc_ack_received()
344 tp->t_bytes_acked += tp->t_ccv.bytes_this_ack; in cc_ack_received()
345 if (tp->t_bytes_acked >= tp->snd_cwnd) { in cc_ack_received()
346 tp->t_bytes_acked -= tp->snd_cwnd; in cc_ack_received()
347 tp->t_ccv.flags |= CCF_ABC_SENTAWND; in cc_ack_received()
350 tp->t_ccv.flags &= ~CCF_ABC_SENTAWND; in cc_ack_received()
351 tp->t_bytes_acked = 0; in cc_ack_received()
355 if (CC_ALGO(tp)->ack_received != NULL) { in cc_ack_received()
357 tp->t_ccv.curack = th->th_ack; in cc_ack_received()
358 CC_ALGO(tp)->ack_received(&tp->t_ccv, type); in cc_ack_received()
361 stats_voi_update_abs_ulong(tp->t_stats, VOI_TCP_LCWIN, tp->snd_cwnd); in cc_ack_received()
366 cc_conn_init(struct tcpcb *tp) in cc_conn_init() argument
369 struct inpcb *inp = tptoinpcb(tp); in cc_conn_init()
376 maxseg = tcp_maxseg(tp); in cc_conn_init()
378 if (tp->t_srtt == 0 && (rtt = metrics.rmx_rtt)) { in cc_conn_init()
379 tp->t_srtt = rtt; in cc_conn_init()
382 tp->t_rttvar = metrics.rmx_rttvar; in cc_conn_init()
386 tp->t_rttvar = in cc_conn_init()
387 tp->t_srtt * TCP_RTTVAR_SCALE / TCP_RTT_SCALE; in cc_conn_init()
389 TCPT_RANGESET(tp->t_rxtcur, in cc_conn_init()
390 ((tp->t_srtt >> 2) + tp->t_rttvar) >> 1, in cc_conn_init()
391 tp->t_rttmin, TCPTV_REXMTMAX); in cc_conn_init()
400 tp->snd_ssthresh = max(2 * maxseg, metrics.rmx_ssthresh); in cc_conn_init()
411 if (tp->snd_cwnd == 1) in cc_conn_init()
412 tp->snd_cwnd = maxseg; /* SYN(-ACK) lost */ in cc_conn_init()
414 tp->snd_cwnd = tcp_compute_initwnd(maxseg); in cc_conn_init()
416 if (CC_ALGO(tp)->conn_init != NULL) in cc_conn_init()
417 CC_ALGO(tp)->conn_init(&tp->t_ccv); in cc_conn_init()
421 cc_cong_signal(struct tcpcb *tp, struct tcphdr *th, uint32_t type) in cc_cong_signal() argument
423 INP_WLOCK_ASSERT(tptoinpcb(tp)); in cc_cong_signal()
426 stats_voi_update_abs_u32(tp->t_stats, VOI_TCP_CSIG, type); in cc_cong_signal()
431 if (!IN_FASTRECOVERY(tp->t_flags)) { in cc_cong_signal()
432 tp->snd_recover = tp->snd_max; in cc_cong_signal()
433 if (tp->t_flags2 & TF2_ECN_PERMIT) in cc_cong_signal()
434 tp->t_flags2 |= TF2_ECN_SND_CWR; in cc_cong_signal()
438 if (!IN_CONGRECOVERY(tp->t_flags) || in cc_cong_signal()
443 SEQ_GEQ(th->th_ack, tp->snd_recover)) { in cc_cong_signal()
444 EXIT_CONGRECOVERY(tp->t_flags); in cc_cong_signal()
446 tp->snd_recover = tp->snd_max + 1; in cc_cong_signal()
447 if (tp->t_flags2 & TF2_ECN_PERMIT) in cc_cong_signal()
448 tp->t_flags2 |= TF2_ECN_SND_CWR; in cc_cong_signal()
452 tp->t_dupacks = 0; in cc_cong_signal()
453 tp->t_bytes_acked = 0; in cc_cong_signal()
454 EXIT_RECOVERY(tp->t_flags); in cc_cong_signal()
455 if (tp->t_flags2 & TF2_ECN_PERMIT) in cc_cong_signal()
456 tp->t_flags2 |= TF2_ECN_SND_CWR; in cc_cong_signal()
461 tp->snd_cwnd = tp->snd_cwnd_prev; in cc_cong_signal()
462 tp->snd_ssthresh = tp->snd_ssthresh_prev; in cc_cong_signal()
463 tp->snd_recover = tp->snd_recover_prev; in cc_cong_signal()
464 if (tp->t_flags & TF_WASFRECOVERY) in cc_cong_signal()
465 ENTER_FASTRECOVERY(tp->t_flags); in cc_cong_signal()
466 if (tp->t_flags & TF_WASCRECOVERY) in cc_cong_signal()
467 ENTER_CONGRECOVERY(tp->t_flags); in cc_cong_signal()
468 tp->snd_nxt = tp->snd_max; in cc_cong_signal()
469 tp->t_flags &= ~TF_PREVVALID; in cc_cong_signal()
470 tp->t_badrxtwin = 0; 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 tp->t_ccv.curack = th->th_ack; in cc_post_recovery()
488 CC_ALGO(tp)->post_recovery(&tp->t_ccv); in cc_post_recovery()
490 EXIT_RECOVERY(tp->t_flags); in cc_post_recovery()
492 tp->t_bytes_acked = 0; in cc_post_recovery()
493 tp->sackhint.delivered_data = 0; in cc_post_recovery()
494 tp->sackhint.prr_delivered = 0; in cc_post_recovery()
495 tp->sackhint.prr_out = 0; in cc_post_recovery()
507 #define DELAY_ACK(tp, tlen) \ argument
508 ((!tcp_timer_active(tp, TT_DELACK) && \
509 (tp->t_flags & TF_RXWIN0SENT) == 0) && \
510 (tlen <= tp->t_maxseg) && \
511 (V_tcp_delack_enabled || (tp->t_flags & TF_NEEDSYN)))
514 cc_ecnpkt_handler_flags(struct tcpcb *tp, uint16_t flags, uint8_t iptos) in cc_ecnpkt_handler_flags() argument
516 INP_WLOCK_ASSERT(tptoinpcb(tp)); in cc_ecnpkt_handler_flags()
518 if (CC_ALGO(tp)->ecnpkt_handler != NULL) { in cc_ecnpkt_handler_flags()
521 tp->t_ccv.flags |= CCF_IPHDR_CE; in cc_ecnpkt_handler_flags()
528 tp->t_ccv.flags &= ~CCF_IPHDR_CE; in cc_ecnpkt_handler_flags()
533 tp->t_ccv.flags |= CCF_TCPHDR_CWR; in cc_ecnpkt_handler_flags()
535 tp->t_ccv.flags &= ~CCF_TCPHDR_CWR; in cc_ecnpkt_handler_flags()
537 CC_ALGO(tp)->ecnpkt_handler(&tp->t_ccv); in cc_ecnpkt_handler_flags()
539 if (tp->t_ccv.flags & CCF_ACKNOW) { in cc_ecnpkt_handler_flags()
540 tcp_timer_activate(tp, TT_DELACK, tcp_delacktime); in cc_ecnpkt_handler_flags()
541 tp->t_flags |= TF_ACKNOW; in cc_ecnpkt_handler_flags()
547 cc_ecnpkt_handler(struct tcpcb *tp, struct tcphdr *th, uint8_t iptos) in cc_ecnpkt_handler() argument
549 cc_ecnpkt_handler_flags(tp, tcp_get_flags(th), iptos); in cc_ecnpkt_handler()
611 struct tcpcb *tp = NULL; in tcp_input_with_port() local
837 tp = NULL; in tcp_input_with_port()
988 tp = intotcpcb(inp); in tcp_input_with_port()
989 switch (tp->t_state) { in tcp_input_with_port()
1015 if ((tp->t_port != port) && (tp->t_state > TCPS_LISTEN)) { in tcp_input_with_port()
1021 if (tp->t_flags & TF_TOE) { in tcp_input_with_port()
1022 tcp_offload_input(tp, m); in tcp_input_with_port()
1039 KASSERT(tp->t_state == TCPS_LISTEN || !SOLISTENING(so), in tcp_input_with_port()
1040 ("%s: so accepting but tp %p not listening", __func__, tp)); in tcp_input_with_port()
1041 if (tp->t_state == TCPS_LISTEN && SOLISTENING(so)) { in tcp_input_with_port()
1148 tp = intotcpcb(inp); in tcp_input_with_port()
1149 KASSERT(tp->t_state == TCPS_SYN_RECEIVED, in tcp_input_with_port()
1156 TCP_PROBE5(receive, NULL, tp, m, tp, th); in tcp_input_with_port()
1157 tp->t_fb->tfb_tcp_do_segment(tp, m, th, drop_hdrlen, in tcp_input_with_port()
1345 TCP_PROBE3(debug__input, tp, th, m); in tcp_input_with_port()
1356 } else if (tp->t_state == TCPS_LISTEN) { in tcp_input_with_port()
1367 if (tp->t_flags & TF_SIGNATURE) { in tcp_input_with_port()
1378 TCP_PROBE5(receive, NULL, tp, m, tp, th); in tcp_input_with_port()
1394 tp->t_fb->tfb_tcp_do_segment(tp, m, th, drop_hdrlen, tlen, iptos); in tcp_input_with_port()
1416 TCP_PROBE5(receive, NULL, tp, m, tp, th); in tcp_input_with_port()
1417 tcp_dropwithreset(m, th, tp, tlen, rstreason); in tcp_input_with_port()
1422 TCP_PROBE5(receive, NULL, tp, m, tp, th); in tcp_input_with_port()
1475 struct tcpcb *tp, int tlen) in tcp_autorcvbuf() argument
1480 tp->t_srtt != 0 && tp->rfbuf_ts != 0 && in tcp_autorcvbuf()
1481 TCP_TS_TO_TICKS(tcp_ts_getticks() - tp->rfbuf_ts) > in tcp_autorcvbuf()
1482 ((tp->t_srtt >> TCP_RTT_SHIFT)/2)) { in tcp_autorcvbuf()
1483 if (tp->rfbuf_cnt > ((so->so_rcv.sb_hiwat / 2)/ 4 * 3) && in tcp_autorcvbuf()
1487 TCP_PROBE6(receive__autoresize, NULL, tp, m, tp, th, newsize); in tcp_autorcvbuf()
1490 tp->rfbuf_ts = 0; in tcp_autorcvbuf()
1491 tp->rfbuf_cnt = 0; in tcp_autorcvbuf()
1493 tp->rfbuf_cnt += tlen; /* add up */ in tcp_autorcvbuf()
1505 tcp_handle_wakeup(struct tcpcb *tp) in tcp_handle_wakeup() argument
1508 INP_WLOCK_ASSERT(tptoinpcb(tp)); in tcp_handle_wakeup()
1510 if (tp->t_flags & TF_WAKESOR) { in tcp_handle_wakeup()
1511 struct socket *so = tptosocket(tp); in tcp_handle_wakeup()
1513 tp->t_flags &= ~TF_WAKESOR; in tcp_handle_wakeup()
1520 tcp_do_segment(struct tcpcb *tp, struct mbuf *m, struct tcphdr *th, in tcp_do_segment() argument
1530 struct inpcb *inp = tptoinpcb(tp); in tcp_do_segment()
1531 struct socket *so = tptosocket(tp); in tcp_do_segment()
1539 tp->sackhint.last_sack_ack = 0; in tcp_do_segment()
1545 KASSERT(tp->t_state > TCPS_LISTEN, ("%s: TCPS_LISTEN", in tcp_do_segment()
1547 KASSERT(tp->t_state != TCPS_TIME_WAIT, ("%s: TCPS_TIME_WAIT", in tcp_do_segment()
1552 tcp_pcap_add(th, m, &(tp->t_inpkts)); in tcp_do_segment()
1554 TCP_LOG_EVENT(tp, th, &so->so_rcv, &so->so_snd, TCP_LOG_IN, 0, in tcp_do_segment()
1571 if ((tp->t_state == TCPS_SYN_SENT) && (thflags & TH_ACK) && in tcp_do_segment()
1572 (SEQ_LEQ(th->th_ack, tp->iss) || SEQ_GT(th->th_ack, tp->snd_max))) { in tcp_do_segment()
1574 tcp_log_end_status(tp, TCP_EI_STATUS_RST_IN_FRONT); in tcp_do_segment()
1584 if (tp->t_idle_reduce && in tcp_do_segment()
1585 (tp->snd_max == tp->snd_una) && in tcp_do_segment()
1586 ((ticks - tp->t_rcvtime) >= tp->t_rxtcur)) in tcp_do_segment()
1587 cc_after_idle(tp); in tcp_do_segment()
1588 tp->t_rcvtime = ticks; in tcp_do_segment()
1591 tcp_log_end_status(tp, TCP_EI_STATUS_CLIENT_FIN); in tcp_do_segment()
1596 tiwin = th->th_win << tp->snd_scale; in tcp_do_segment()
1598 stats_voi_update_abs_ulong(tp->t_stats, VOI_TCP_FRWIN, tiwin); in tcp_do_segment()
1604 if (tcp_ecn_input_segment(tp, thflags, tlen, in tcp_do_segment()
1605 tcp_packets_this_ack(tp, th->th_ack), in tcp_do_segment()
1607 cc_cong_signal(tp, th, CC_ECN); in tcp_do_segment()
1617 if ((tp->t_flags & TF_SIGNATURE) != 0 && in tcp_do_segment()
1630 to.to_tsecr -= tp->ts_offset; in tcp_do_segment()
1633 else if (tp->t_rxtshift == 1 && in tcp_do_segment()
1634 tp->t_flags & TF_PREVVALID && in tcp_do_segment()
1635 tp->t_badrxtwin != 0 && in tcp_do_segment()
1636 TSTMP_LT(to.to_tsecr, tp->t_badrxtwin)) in tcp_do_segment()
1637 cc_cong_signal(tp, th, CC_RTO_ERR); in tcp_do_segment()
1646 if (tp->t_state == TCPS_SYN_SENT && (thflags & TH_SYN)) { in tcp_do_segment()
1648 tcp_ecn_input_parallel_syn(tp, thflags, iptos); in tcp_do_segment()
1650 (tp->t_flags & TF_REQ_SCALE) && in tcp_do_segment()
1651 !(tp->t_flags & TF_NOOPT)) { in tcp_do_segment()
1652 tp->t_flags |= TF_RCVD_SCALE; in tcp_do_segment()
1653 tp->snd_scale = to.to_wscale; in tcp_do_segment()
1655 tp->t_flags &= ~TF_REQ_SCALE; in tcp_do_segment()
1660 tp->snd_wnd = th->th_win; in tcp_do_segment()
1662 (tp->t_flags & TF_REQ_TSTMP) && in tcp_do_segment()
1663 !(tp->t_flags & TF_NOOPT)) { in tcp_do_segment()
1664 tp->t_flags |= TF_RCVD_TSTMP; in tcp_do_segment()
1665 tp->ts_recent = to.to_tsval; in tcp_do_segment()
1666 tp->ts_recent_age = tcp_ts_getticks(); in tcp_do_segment()
1668 tp->t_flags &= ~TF_REQ_TSTMP; in tcp_do_segment()
1670 tcp_mss(tp, to.to_mss); in tcp_do_segment()
1671 if ((tp->t_flags & TF_SACK_PERMIT) && in tcp_do_segment()
1673 (tp->t_flags & TF_NOOPT))) in tcp_do_segment()
1674 tp->t_flags &= ~TF_SACK_PERMIT; in tcp_do_segment()
1675 if (IS_FASTOPEN(tp->t_flags)) { in tcp_do_segment()
1677 !(tp->t_flags & TF_NOOPT)) { in tcp_do_segment()
1687 tcp_fastopen_update_cache(tp, mss, in tcp_do_segment()
1690 tcp_fastopen_disable_path(tp); in tcp_do_segment()
1701 if ((tp->t_flags & TF_RCVD_TSTMP) && !(to.to_flags & TOF_TS)) { in tcp_do_segment()
1724 if (!(tp->t_flags & TF_RCVD_TSTMP) && (to.to_flags & TOF_TS)) { in tcp_do_segment()
1749 if (tp->t_state == TCPS_ESTABLISHED && in tcp_do_segment()
1750 th->th_seq == tp->rcv_nxt && in tcp_do_segment()
1752 tp->snd_nxt == tp->snd_max && in tcp_do_segment()
1753 tiwin && tiwin == tp->snd_wnd && in tcp_do_segment()
1754 ((tp->t_flags & (TF_NEEDSYN|TF_NEEDFIN)) == 0) && in tcp_do_segment()
1755 SEGQ_EMPTY(tp) && in tcp_do_segment()
1757 TSTMP_GEQ(to.to_tsval, tp->ts_recent)) ) { in tcp_do_segment()
1765 SEQ_LEQ(th->th_seq, tp->last_ack_sent)) { in tcp_do_segment()
1766 tp->ts_recent_age = tcp_ts_getticks(); in tcp_do_segment()
1767 tp->ts_recent = to.to_tsval; in tcp_do_segment()
1771 if (SEQ_GT(th->th_ack, tp->snd_una) && in tcp_do_segment()
1772 SEQ_LEQ(th->th_ack, tp->snd_max) && in tcp_do_segment()
1773 !IN_RECOVERY(tp->t_flags) && in tcp_do_segment()
1775 TAILQ_EMPTY(&tp->snd_holes)) { in tcp_do_segment()
1785 tp->t_rxtshift == 1 && in tcp_do_segment()
1786 tp->t_flags & TF_PREVVALID && in tcp_do_segment()
1787 tp->t_badrxtwin != 0 && in tcp_do_segment()
1788 TSTMP_LT(ticks, tp->t_badrxtwin)) { in tcp_do_segment()
1789 cc_cong_signal(tp, th, CC_RTO_ERR); in tcp_do_segment()
1805 if (!tp->t_rttlow || tp->t_rttlow > t) in tcp_do_segment()
1806 tp->t_rttlow = t; in tcp_do_segment()
1807 tcp_xmit_timer(tp, in tcp_do_segment()
1809 } else if (tp->t_rtttime && in tcp_do_segment()
1810 SEQ_GT(th->th_ack, tp->t_rtseq)) { in tcp_do_segment()
1811 if (!tp->t_rttlow || in tcp_do_segment()
1812 tp->t_rttlow > ticks - tp->t_rtttime) in tcp_do_segment()
1813 tp->t_rttlow = ticks - tp->t_rtttime; in tcp_do_segment()
1814 tcp_xmit_timer(tp, in tcp_do_segment()
1815 ticks - tp->t_rtttime); in tcp_do_segment()
1817 acked = BYTES_THIS_ACK(tp, th); in tcp_do_segment()
1821 hhook_run_tcp_est_in(tp, th, &to); in tcp_do_segment()
1827 if (SEQ_GT(tp->snd_una, tp->snd_recover) && in tcp_do_segment()
1828 SEQ_LEQ(th->th_ack, tp->snd_recover)) in tcp_do_segment()
1829 tp->snd_recover = th->th_ack - 1; in tcp_do_segment()
1837 cc_ack_received(tp, th, nsegs, CC_ACK); in tcp_do_segment()
1839 tp->snd_una = th->th_ack; in tcp_do_segment()
1844 tp->snd_wl2 = th->th_ack; in tcp_do_segment()
1845 tp->t_dupacks = 0; in tcp_do_segment()
1857 TCP_PROBE3(debug__input, tp, th, m); in tcp_do_segment()
1865 tp->t_acktime = 0; in tcp_do_segment()
1867 tp->t_acktime = ticks; in tcp_do_segment()
1868 if (tp->snd_una == tp->snd_max) in tcp_do_segment()
1869 tcp_timer_activate(tp, TT_REXMT, 0); in tcp_do_segment()
1870 else if (!tcp_timer_active(tp, TT_PERSIST)) in tcp_do_segment()
1871 tcp_timer_activate(tp, TT_REXMT, in tcp_do_segment()
1872 TP_RXTCUR(tp)); in tcp_do_segment()
1879 if (SEQ_GT(tp->snd_una + sbavail(&so->so_snd), in tcp_do_segment()
1880 tp->snd_max) || tp->t_flags & TF_ACKNOW) in tcp_do_segment()
1881 (void) tcp_output(tp); in tcp_do_segment()
1884 } else if (th->th_ack == tp->snd_una && in tcp_do_segment()
1894 if ((tp->t_flags & TF_SACK_PERMIT) && tp->rcv_numsacks) in tcp_do_segment()
1895 tcp_clean_sackreport(tp); in tcp_do_segment()
1897 tp->rcv_nxt += tlen; in tcp_do_segment()
1899 ((tp->t_flags2 & TF2_FBYTES_COMPLETE) == 0) && in tcp_do_segment()
1900 (tp->t_fbyte_in == 0)) { in tcp_do_segment()
1901 tp->t_fbyte_in = ticks; in tcp_do_segment()
1902 if (tp->t_fbyte_in == 0) in tcp_do_segment()
1903 tp->t_fbyte_in = 1; in tcp_do_segment()
1904 if (tp->t_fbyte_out && tp->t_fbyte_in) in tcp_do_segment()
1905 tp->t_flags2 |= TF2_FBYTES_COMPLETE; in tcp_do_segment()
1911 tp->snd_wl1 = th->th_seq; in tcp_do_segment()
1916 tp->rcv_up = tp->rcv_nxt; in tcp_do_segment()
1919 TCP_PROBE3(debug__input, tp, th, m); in tcp_do_segment()
1921 newsize = tcp_autorcvbuf(m, th, so, tp, tlen); in tcp_do_segment()
1941 if (DELAY_ACK(tp, tlen)) { in tcp_do_segment()
1942 tp->t_flags |= TF_DELACK; in tcp_do_segment()
1944 tp->t_flags |= TF_ACKNOW; in tcp_do_segment()
1945 (void) tcp_output(tp); in tcp_do_segment()
1960 tp->rcv_wnd = imax(win, (int)(tp->rcv_adv - tp->rcv_nxt)); in tcp_do_segment()
1962 switch (tp->t_state) { in tcp_do_segment()
1973 (SEQ_LEQ(th->th_ack, tp->snd_una) || in tcp_do_segment()
1974 SEQ_GT(th->th_ack, tp->snd_max))) { in tcp_do_segment()
1976 tcp_log_end_status(tp, TCP_EI_STATUS_RST_IN_FRONT); in tcp_do_segment()
1979 if (IS_FASTOPEN(tp->t_flags)) { in tcp_do_segment()
1989 tcp_log_end_status(tp, TCP_EI_STATUS_RST_IN_FRONT); in tcp_do_segment()
1993 if ((tcp_timer_active(tp, TT_DELACK) || in tcp_do_segment()
1994 tcp_timer_active(tp, TT_REXMT))) in tcp_do_segment()
2019 TCP_PROBE5(connect__refused, NULL, tp, in tcp_do_segment()
2020 m, tp, th); in tcp_do_segment()
2021 tcp_log_end_status(tp, TCP_EI_STATUS_RST_IN_FRONT); in tcp_do_segment()
2022 tp = tcp_drop(tp, ECONNREFUSED); in tcp_do_segment()
2029 tp->irs = th->th_seq; in tcp_do_segment()
2030 tcp_rcvseqinit(tp); in tcp_do_segment()
2040 if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) == in tcp_do_segment()
2042 tp->rcv_scale = tp->request_r_scale; in tcp_do_segment()
2044 tp->rcv_adv += min(tp->rcv_wnd, in tcp_do_segment()
2045 TCP_MAXWIN << tp->rcv_scale); in tcp_do_segment()
2046 tp->snd_una++; /* SYN is acked */ in tcp_do_segment()
2047 if (SEQ_LT(tp->snd_nxt, tp->snd_una)) in tcp_do_segment()
2048 tp->snd_nxt = tp->snd_una; in tcp_do_segment()
2053 if (IS_FASTOPEN(tp->t_flags) && in tcp_do_segment()
2054 (tp->snd_una != tp->snd_max)) { in tcp_do_segment()
2055 tp->snd_nxt = th->th_ack; in tcp_do_segment()
2062 if (DELAY_ACK(tp, tlen) && tlen != 0 && !tfo_partial_ack) in tcp_do_segment()
2063 tcp_timer_activate(tp, TT_DELACK, in tcp_do_segment()
2066 tp->t_flags |= TF_ACKNOW; in tcp_do_segment()
2068 tcp_ecn_input_syn_sent(tp, thflags, iptos); in tcp_do_segment()
2076 tp->t_starttime = ticks; in tcp_do_segment()
2077 if (tp->t_flags & TF_NEEDFIN) { in tcp_do_segment()
2078 tp->t_acktime = ticks; in tcp_do_segment()
2079 tcp_state_change(tp, TCPS_FIN_WAIT_1); in tcp_do_segment()
2080 tp->t_flags &= ~TF_NEEDFIN; in tcp_do_segment()
2083 tcp_state_change(tp, TCPS_ESTABLISHED); in tcp_do_segment()
2084 TCP_PROBE5(connect__established, NULL, tp, in tcp_do_segment()
2085 m, tp, th); in tcp_do_segment()
2086 cc_conn_init(tp); in tcp_do_segment()
2087 tcp_timer_activate(tp, TT_KEEP, in tcp_do_segment()
2088 TP_KEEPIDLE(tp)); in tcp_do_segment()
2099 tp->t_flags |= (TF_ACKNOW | TF_NEEDSYN | TF_SONOTCONN); in tcp_do_segment()
2100 tcp_timer_activate(tp, TT_REXMT, 0); in tcp_do_segment()
2101 tcp_state_change(tp, TCPS_SYN_RECEIVED); in tcp_do_segment()
2110 if (tlen > tp->rcv_wnd) { in tcp_do_segment()
2111 todrop = tlen - tp->rcv_wnd; in tcp_do_segment()
2113 tlen = tp->rcv_wnd; in tcp_do_segment()
2118 tp->snd_wl1 = th->th_seq - 1; in tcp_do_segment()
2119 tp->rcv_up = th->th_seq; in tcp_do_segment()
2160 if ((SEQ_GEQ(th->th_seq, tp->last_ack_sent) && in tcp_do_segment()
2161 SEQ_LT(th->th_seq, tp->last_ack_sent + tp->rcv_wnd)) || in tcp_do_segment()
2162 (tp->rcv_wnd == 0 && tp->last_ack_sent == th->th_seq)) { in tcp_do_segment()
2163 KASSERT(tp->t_state != TCPS_SYN_SENT, in tcp_do_segment()
2165 __func__, th, tp)); in tcp_do_segment()
2168 tp->last_ack_sent == th->th_seq) { in tcp_do_segment()
2171 switch (tp->t_state) { in tcp_do_segment()
2185 tcp_log_end_status(tp, TCP_EI_STATUS_CLIENT_RST); in tcp_do_segment()
2186 tp = tcp_close(tp); in tcp_do_segment()
2190 tcp_send_challenge_ack(tp, th, m); in tcp_do_segment()
2201 if ((thflags & TH_SYN) && tp->t_state != TCPS_SYN_SENT && in tcp_do_segment()
2202 tp->t_state != TCPS_SYN_RECEIVED) { in tcp_do_segment()
2205 SEQ_GEQ(th->th_seq, tp->last_ack_sent) && in tcp_do_segment()
2206 SEQ_LT(th->th_seq, tp->last_ack_sent + tp->rcv_wnd)) { in tcp_do_segment()
2207 tcp_log_end_status(tp, TCP_EI_STATUS_RST_IN_FRONT); in tcp_do_segment()
2208 tp = tcp_drop(tp, ECONNRESET); in tcp_do_segment()
2211 tcp_ecn_input_syn_sent(tp, thflags, iptos); in tcp_do_segment()
2212 tcp_send_challenge_ack(tp, th, m); in tcp_do_segment()
2222 if ((to.to_flags & TOF_TS) != 0 && tp->ts_recent && in tcp_do_segment()
2223 TSTMP_LT(to.to_tsval, tp->ts_recent)) { in tcp_do_segment()
2225 if (tcp_ts_getticks() - tp->ts_recent_age > TCP_PAWS_IDLE) { in tcp_do_segment()
2237 tp->ts_recent = 0; in tcp_do_segment()
2255 if (tp->t_state == TCPS_SYN_RECEIVED && SEQ_LT(th->th_seq, tp->irs)) { in tcp_do_segment()
2257 tcp_log_end_status(tp, TCP_EI_STATUS_RST_IN_FRONT); in tcp_do_segment()
2261 todrop = tp->rcv_nxt - th->th_seq; in tcp_do_segment()
2288 tp->t_flags |= TF_ACKNOW; in tcp_do_segment()
2299 if ((todrop > 0) && (tp->t_flags & TF_SACK_PERMIT)) { in tcp_do_segment()
2300 tcp_update_sack_list(tp, th->th_seq, in tcp_do_segment()
2306 tp->t_flags |= TF_ACKNOW; in tcp_do_segment()
2324 if ((tp->t_flags & TF_CLOSED) && tlen > 0 && in tcp_do_segment()
2325 TCPS_HAVERCVDFIN(tp->t_state) == 0) { in tcp_do_segment()
2330 s, __func__, tcpstates[tp->t_state], tlen); in tcp_do_segment()
2333 tcp_log_end_status(tp, TCP_EI_STATUS_DATA_A_CLOSE); in tcp_do_segment()
2335 tcp_log_end_status(tp, TCP_EI_STATUS_SERVER_RST); in tcp_do_segment()
2336 tp = tcp_close(tp); in tcp_do_segment()
2346 todrop = (th->th_seq + tlen) - (tp->rcv_nxt + tp->rcv_wnd); in tcp_do_segment()
2358 if (tp->rcv_wnd == 0 && th->th_seq == tp->rcv_nxt) { in tcp_do_segment()
2359 tp->t_flags |= TF_ACKNOW; in tcp_do_segment()
2389 SEQ_LEQ(th->th_seq, tp->last_ack_sent) && in tcp_do_segment()
2390 SEQ_LEQ(tp->last_ack_sent, th->th_seq + tlen + in tcp_do_segment()
2392 tp->ts_recent_age = tcp_ts_getticks(); in tcp_do_segment()
2393 tp->ts_recent = to.to_tsval; in tcp_do_segment()
2402 if (tp->t_state == TCPS_SYN_RECEIVED || in tcp_do_segment()
2403 (tp->t_flags & TF_NEEDSYN)) { in tcp_do_segment()
2404 if (tp->t_state == TCPS_SYN_RECEIVED && in tcp_do_segment()
2405 IS_FASTOPEN(tp->t_flags)) { in tcp_do_segment()
2406 tp->snd_wnd = tiwin; in tcp_do_segment()
2407 cc_conn_init(tp); in tcp_do_segment()
2410 } else if (tp->t_flags & TF_ACKNOW) in tcp_do_segment()
2419 if (SEQ_GEQ(tp->snd_una, tp->iss + (TCP_MAXWIN << tp->snd_scale))) { in tcp_do_segment()
2421 tp->t_flags2 |= TF2_NO_ISS_CHECK; in tcp_do_segment()
2427 if (tp->t_flags2 & TF2_NO_ISS_CHECK) { in tcp_do_segment()
2429 seq_min = tp->snd_una - tp->max_sndwnd; in tcp_do_segment()
2432 if (SEQ_GT(tp->iss + 1, tp->snd_una - tp->max_sndwnd)) { in tcp_do_segment()
2434 seq_min = tp->iss + 1; in tcp_do_segment()
2441 seq_min = tp->snd_una - tp->max_sndwnd; in tcp_do_segment()
2450 tcp_send_challenge_ack(tp, th, m); in tcp_do_segment()
2455 switch (tp->t_state) { in tcp_do_segment()
2464 if (tp->t_flags & TF_SONOTCONN) { in tcp_do_segment()
2474 tp->t_flags &= ~TF_SONOTCONN; in tcp_do_segment()
2478 if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) == in tcp_do_segment()
2480 tp->rcv_scale = tp->request_r_scale; in tcp_do_segment()
2482 tp->snd_wnd = tiwin; in tcp_do_segment()
2488 tp->t_starttime = ticks; in tcp_do_segment()
2489 if (IS_FASTOPEN(tp->t_flags) && tp->t_tfo_pending) { in tcp_do_segment()
2490 tcp_fastopen_decrement_counter(tp->t_tfo_pending); in tcp_do_segment()
2491 tp->t_tfo_pending = NULL; in tcp_do_segment()
2493 if (tp->t_flags & TF_NEEDFIN) { in tcp_do_segment()
2494 tp->t_acktime = ticks; in tcp_do_segment()
2495 tcp_state_change(tp, TCPS_FIN_WAIT_1); in tcp_do_segment()
2496 tp->t_flags &= ~TF_NEEDFIN; in tcp_do_segment()
2498 tcp_state_change(tp, TCPS_ESTABLISHED); in tcp_do_segment()
2499 TCP_PROBE5(accept__established, NULL, tp, in tcp_do_segment()
2500 m, tp, th); in tcp_do_segment()
2508 if (!IS_FASTOPEN(tp->t_flags)) in tcp_do_segment()
2509 cc_conn_init(tp); in tcp_do_segment()
2510 tcp_timer_activate(tp, TT_KEEP, TP_KEEPIDLE(tp)); in tcp_do_segment()
2517 if (SEQ_GT(th->th_ack, tp->snd_una) && !(tp->t_flags & TF_NEEDSYN)) in tcp_do_segment()
2524 (void) tcp_reass(tp, (struct tcphdr *)0, NULL, 0, in tcp_do_segment()
2526 tcp_handle_wakeup(tp); in tcp_do_segment()
2528 tp->snd_wl1 = th->th_seq - 1; in tcp_do_segment()
2545 if (SEQ_GT(th->th_ack, tp->snd_max)) { in tcp_do_segment()
2549 if (tcp_is_sack_recovery(tp, &to)) { in tcp_do_segment()
2550 sack_changed = tcp_sack_doack(tp, &to, th->th_ack); in tcp_do_segment()
2552 (tp->t_flags & TF_LRD)) { in tcp_do_segment()
2553 tcp_sack_lost_retransmission(tp, th); in tcp_do_segment()
2560 tp->sackhint.sacked_bytes = 0; in tcp_do_segment()
2564 hhook_run_tcp_est_in(tp, th, &to); in tcp_do_segment()
2567 if (SEQ_LEQ(th->th_ack, tp->snd_una)) { in tcp_do_segment()
2568 maxseg = tcp_maxseg(tp); in tcp_do_segment()
2570 (tiwin == tp->snd_wnd || in tcp_do_segment()
2571 (tp->t_flags & TF_SACK_PERMIT))) { in tcp_do_segment()
2580 (TCPS_HAVERCVDFIN(tp->t_state) == 0)) { in tcp_do_segment()
2581 tp->t_dupacks = 0; in tcp_do_segment()
2622 if (th->th_ack != tp->snd_una || in tcp_do_segment()
2623 (tcp_is_sack_recovery(tp, &to) && in tcp_do_segment()
2626 else if (!tcp_timer_active(tp, TT_REXMT)) in tcp_do_segment()
2627 tp->t_dupacks = 0; in tcp_do_segment()
2628 else if (++tp->t_dupacks > tcprexmtthresh || in tcp_do_segment()
2629 IN_FASTRECOVERY(tp->t_flags)) { in tcp_do_segment()
2630 cc_ack_received(tp, th, nsegs, in tcp_do_segment()
2633 IN_FASTRECOVERY(tp->t_flags) && in tcp_do_segment()
2634 (tp->t_flags & TF_SACK_PERMIT)) { in tcp_do_segment()
2635 tcp_do_prr_ack(tp, th, &to, sack_changed); in tcp_do_segment()
2636 } else if (tcp_is_sack_recovery(tp, &to) && in tcp_do_segment()
2637 IN_FASTRECOVERY(tp->t_flags)) { in tcp_do_segment()
2647 awnd = tcp_compute_pipe(tp); in tcp_do_segment()
2649 awnd = (tp->snd_nxt - tp->snd_fack) + in tcp_do_segment()
2650 tp->sackhint.sack_bytes_rexmit; in tcp_do_segment()
2652 if (awnd < tp->snd_ssthresh) { in tcp_do_segment()
2653 tp->snd_cwnd += maxseg; in tcp_do_segment()
2654 if (tp->snd_cwnd > tp->snd_ssthresh) in tcp_do_segment()
2655 tp->snd_cwnd = tp->snd_ssthresh; in tcp_do_segment()
2658 tp->snd_cwnd += maxseg; in tcp_do_segment()
2659 (void) tcp_output(tp); in tcp_do_segment()
2661 } else if (tp->t_dupacks == tcprexmtthresh || in tcp_do_segment()
2662 (tp->t_flags & TF_SACK_PERMIT && in tcp_do_segment()
2664 tp->sackhint.sacked_bytes > in tcp_do_segment()
2675 tp->t_dupacks = tcprexmtthresh; in tcp_do_segment()
2676 tcp_seq onxt = tp->snd_nxt; in tcp_do_segment()
2686 (tp->t_flags & TF_SACK_PERMIT)) { in tcp_do_segment()
2687 if (IN_FASTRECOVERY(tp->t_flags)) { in tcp_do_segment()
2688 tp->t_dupacks = 0; in tcp_do_segment()
2693 tp->snd_recover)) { in tcp_do_segment()
2694 tp->t_dupacks = 0; in tcp_do_segment()
2699 cc_cong_signal(tp, th, CC_NDUPACK); in tcp_do_segment()
2700 cc_ack_received(tp, th, nsegs, in tcp_do_segment()
2702 tcp_timer_activate(tp, TT_REXMT, 0); in tcp_do_segment()
2703 tp->t_rtttime = 0; in tcp_do_segment()
2709 if (tcp_is_sack_recovery(tp, &to)) { in tcp_do_segment()
2714 tp->sackhint.prr_delivered = in tcp_do_segment()
2717 tp->sackhint.prr_delivered = in tcp_do_segment()
2718 imin(tp->snd_max - tp->snd_una, in tcp_do_segment()
2720 tp->t_dupacks) * maxseg); in tcp_do_segment()
2722 tp->sackhint.recover_fs = max(1, in tcp_do_segment()
2723 tp->snd_nxt - tp->snd_una); in tcp_do_segment()
2725 if (tcp_is_sack_recovery(tp, &to)) { in tcp_do_segment()
2727 tp->snd_cwnd = maxseg; in tcp_do_segment()
2728 (void) tcp_output(tp); in tcp_do_segment()
2729 if (SEQ_GT(th->th_ack, tp->snd_una)) in tcp_do_segment()
2733 tp->snd_nxt = th->th_ack; in tcp_do_segment()
2734 tp->snd_cwnd = maxseg; in tcp_do_segment()
2735 (void) tcp_output(tp); in tcp_do_segment()
2736 KASSERT(tp->snd_limited <= 2, in tcp_do_segment()
2739 tp->snd_cwnd = tp->snd_ssthresh + in tcp_do_segment()
2741 (tp->t_dupacks - tp->snd_limited); in tcp_do_segment()
2742 if (SEQ_GT(onxt, tp->snd_nxt)) in tcp_do_segment()
2743 tp->snd_nxt = onxt; in tcp_do_segment()
2756 cc_ack_received(tp, th, nsegs, in tcp_do_segment()
2758 uint32_t oldcwnd = tp->snd_cwnd; in tcp_do_segment()
2759 tcp_seq oldsndmax = tp->snd_max; in tcp_do_segment()
2763 KASSERT(tp->t_dupacks == 1 || in tcp_do_segment()
2764 tp->t_dupacks == 2, in tcp_do_segment()
2767 if (tp->t_dupacks == 1) in tcp_do_segment()
2768 tp->snd_limited = 0; in tcp_do_segment()
2769 if ((tp->snd_nxt == tp->snd_max) && in tcp_do_segment()
2770 (tp->t_rxtshift == 0)) in tcp_do_segment()
2771 tp->snd_cwnd = in tcp_do_segment()
2772 SEQ_SUB(tp->snd_nxt, in tcp_do_segment()
2773 tp->snd_una); in tcp_do_segment()
2774 tp->snd_cwnd += in tcp_do_segment()
2775 (tp->t_dupacks - tp->snd_limited) * in tcp_do_segment()
2784 (tp->snd_nxt - tp->snd_una); in tcp_do_segment()
2786 if (avail > 0 || tp->t_flags & TF_ACKNOW) in tcp_do_segment()
2787 (void) tcp_output(tp); in tcp_do_segment()
2788 sent = tp->snd_max - oldsndmax; in tcp_do_segment()
2790 KASSERT((tp->t_dupacks == 2 && in tcp_do_segment()
2791 tp->snd_limited == 0) || in tcp_do_segment()
2793 tp->t_flags & TF_SENTFIN), in tcp_do_segment()
2796 tp->snd_limited = 2; in tcp_do_segment()
2798 ++tp->snd_limited; in tcp_do_segment()
2799 tp->snd_cwnd = oldcwnd; in tcp_do_segment()
2809 tp->t_dupacks = 0; in tcp_do_segment()
2819 if (tcp_is_sack_recovery(tp, &to) && in tcp_do_segment()
2820 (((tp->t_rxtshift == 0) && (sack_changed != SACK_NOCHANGE)) || in tcp_do_segment()
2821 ((tp->t_rxtshift > 0) && (sack_changed == SACK_NEWLOSS))) && in tcp_do_segment()
2822 (tp->snd_nxt == tp->snd_max)) { in tcp_do_segment()
2823 tp->t_dupacks++; in tcp_do_segment()
2825 if (!IN_FASTRECOVERY(tp->t_flags) && in tcp_do_segment()
2826 (tp->sackhint.sacked_bytes > in tcp_do_segment()
2828 (maxseg = tcp_maxseg(tp))))) { in tcp_do_segment()
2835 KASSERT(SEQ_GT(th->th_ack, tp->snd_una), in tcp_do_segment()
2842 if (SEQ_LT(th->th_ack, tp->snd_recover)) { in tcp_do_segment()
2843 if (IN_FASTRECOVERY(tp->t_flags)) { in tcp_do_segment()
2844 if (tp->t_flags & TF_SACK_PERMIT) { in tcp_do_segment()
2847 tcp_timer_activate(tp, in tcp_do_segment()
2849 tp->t_rtttime = 0; in tcp_do_segment()
2850 tcp_do_prr_ack(tp, th, &to, in tcp_do_segment()
2852 tp->t_flags |= TF_ACKNOW; in tcp_do_segment()
2853 (void) tcp_output(tp); in tcp_do_segment()
2855 tcp_sack_partialack(tp, th); in tcp_do_segment()
2858 tcp_newreno_partial_ack(tp, th); in tcp_do_segment()
2860 } else if (IN_CONGRECOVERY(tp->t_flags) && in tcp_do_segment()
2862 tp->sackhint.delivered_data = in tcp_do_segment()
2863 BYTES_THIS_ACK(tp, th); in tcp_do_segment()
2864 tp->snd_fack = th->th_ack; in tcp_do_segment()
2869 tcp_do_prr_ack(tp, th, &to, SACK_CHANGE); in tcp_do_segment()
2870 (void) tcp_output(tp); in tcp_do_segment()
2877 if (tp->t_flags & TF_NEEDSYN) { in tcp_do_segment()
2885 tp->t_flags &= ~TF_NEEDSYN; in tcp_do_segment()
2886 tp->snd_una++; in tcp_do_segment()
2888 if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) == in tcp_do_segment()
2890 tp->rcv_scale = tp->request_r_scale; in tcp_do_segment()
2906 tp->snd_una++; in tcp_do_segment()
2907 acked = BYTES_THIS_ACK(tp, th); in tcp_do_segment()
2910 tp->snd_una, th->th_ack, tp, m)); in tcp_do_segment()
2921 if (tp->t_rxtshift == 1 && in tcp_do_segment()
2922 tp->t_flags & TF_PREVVALID && in tcp_do_segment()
2923 tp->t_badrxtwin != 0 && in tcp_do_segment()
2926 TSTMP_LT(to.to_tsecr, tp->t_badrxtwin)) in tcp_do_segment()
2927 cc_cong_signal(tp, th, CC_RTO_ERR); in tcp_do_segment()
2947 if (!tp->t_rttlow || tp->t_rttlow > t) in tcp_do_segment()
2948 tp->t_rttlow = t; in tcp_do_segment()
2949 tcp_xmit_timer(tp, TCP_TS_TO_TICKS(t) + 1); in tcp_do_segment()
2950 } else if (tp->t_rtttime && SEQ_GT(th->th_ack, tp->t_rtseq)) { in tcp_do_segment()
2951 if (!tp->t_rttlow || tp->t_rttlow > ticks - tp->t_rtttime) in tcp_do_segment()
2952 tp->t_rttlow = ticks - tp->t_rtttime; in tcp_do_segment()
2953 tcp_xmit_timer(tp, ticks - tp->t_rtttime); in tcp_do_segment()
2963 if ((tp->t_state <= TCPS_CLOSE_WAIT && in tcp_do_segment()
2966 tp->t_acktime = 0; in tcp_do_segment()
2968 tp->t_acktime = ticks; in tcp_do_segment()
2976 if (th->th_ack == tp->snd_max) { in tcp_do_segment()
2977 tcp_timer_activate(tp, TT_REXMT, 0); in tcp_do_segment()
2979 } else if (!tcp_timer_active(tp, TT_PERSIST)) in tcp_do_segment()
2980 tcp_timer_activate(tp, TT_REXMT, TP_RXTCUR(tp)); in tcp_do_segment()
2996 cc_ack_received(tp, th, nsegs, CC_ACK); in tcp_do_segment()
2999 if (tp->snd_wnd >= sbavail(&so->so_snd)) in tcp_do_segment()
3000 tp->snd_wnd -= sbavail(&so->so_snd); in tcp_do_segment()
3002 tp->snd_wnd = 0; in tcp_do_segment()
3008 if (tp->snd_wnd >= (uint32_t) acked) in tcp_do_segment()
3009 tp->snd_wnd -= acked; in tcp_do_segment()
3011 tp->snd_wnd = 0; in tcp_do_segment()
3018 if (!IN_RECOVERY(tp->t_flags) && in tcp_do_segment()
3019 SEQ_GT(tp->snd_una, tp->snd_recover) && in tcp_do_segment()
3020 SEQ_LEQ(th->th_ack, tp->snd_recover)) in tcp_do_segment()
3021 tp->snd_recover = th->th_ack - 1; in tcp_do_segment()
3022 tp->snd_una = th->th_ack; in tcp_do_segment()
3023 if (IN_RECOVERY(tp->t_flags) && in tcp_do_segment()
3024 SEQ_GEQ(th->th_ack, tp->snd_recover)) { in tcp_do_segment()
3025 cc_post_recovery(tp, th); in tcp_do_segment()
3027 if (tp->t_flags & TF_SACK_PERMIT) { in tcp_do_segment()
3028 if (SEQ_GT(tp->snd_una, tp->snd_recover)) in tcp_do_segment()
3029 tp->snd_recover = tp->snd_una; in tcp_do_segment()
3031 if (SEQ_LT(tp->snd_nxt, tp->snd_una)) in tcp_do_segment()
3032 tp->snd_nxt = tp->snd_una; in tcp_do_segment()
3034 switch (tp->t_state) { in tcp_do_segment()
3051 tcp_timer_activate(tp, TT_2MSL, in tcp_do_segment()
3054 TP_MAXIDLE(tp))); in tcp_do_segment()
3056 tcp_state_change(tp, TCPS_FIN_WAIT_2); in tcp_do_segment()
3068 tcp_twstart(tp); in tcp_do_segment()
3082 tp = tcp_close(tp); in tcp_do_segment()
3097 (SEQ_LT(tp->snd_wl1, th->th_seq) || in tcp_do_segment()
3098 (tp->snd_wl1 == th->th_seq && (SEQ_LT(tp->snd_wl2, th->th_ack) || in tcp_do_segment()
3099 (tp->snd_wl2 == th->th_ack && tiwin > tp->snd_wnd))))) { in tcp_do_segment()
3102 tp->snd_wl2 == th->th_ack && tiwin > tp->snd_wnd) in tcp_do_segment()
3104 tp->snd_wnd = tiwin; in tcp_do_segment()
3105 tp->snd_wl1 = th->th_seq; in tcp_do_segment()
3106 tp->snd_wl2 = th->th_ack; in tcp_do_segment()
3107 if (tp->snd_wnd > tp->max_sndwnd) in tcp_do_segment()
3108 tp->max_sndwnd = tp->snd_wnd; in tcp_do_segment()
3116 TCPS_HAVERCVDFIN(tp->t_state) == 0) { in tcp_do_segment()
3144 if (SEQ_GT(th->th_seq+th->th_urp, tp->rcv_up)) { in tcp_do_segment()
3145 tp->rcv_up = th->th_seq + th->th_urp; in tcp_do_segment()
3147 (tp->rcv_up - tp->rcv_nxt) - 1; in tcp_do_segment()
3151 tp->t_oobflags &= ~(TCPOOB_HAVEDATA | TCPOOB_HADDATA); in tcp_do_segment()
3171 if (SEQ_GT(tp->rcv_nxt, tp->rcv_up)) in tcp_do_segment()
3172 tp->rcv_up = tp->rcv_nxt; in tcp_do_segment()
3185 tfo_syn = ((tp->t_state == TCPS_SYN_RECEIVED) && in tcp_do_segment()
3186 IS_FASTOPEN(tp->t_flags)); in tcp_do_segment()
3188 TCPS_HAVERCVDFIN(tp->t_state) == 0) { in tcp_do_segment()
3190 tcp_seq save_rnxt = tp->rcv_nxt; in tcp_do_segment()
3205 if (th->th_seq == tp->rcv_nxt && in tcp_do_segment()
3206 SEGQ_EMPTY(tp) && in tcp_do_segment()
3207 (TCPS_HAVEESTABLISHED(tp->t_state) || in tcp_do_segment()
3209 if (DELAY_ACK(tp, tlen) || tfo_syn) in tcp_do_segment()
3210 tp->t_flags |= TF_DELACK; in tcp_do_segment()
3212 tp->t_flags |= TF_ACKNOW; in tcp_do_segment()
3213 tp->rcv_nxt += tlen; in tcp_do_segment()
3215 ((tp->t_flags2 & TF2_FBYTES_COMPLETE) == 0) && in tcp_do_segment()
3216 (tp->t_fbyte_in == 0)) { in tcp_do_segment()
3217 tp->t_fbyte_in = ticks; in tcp_do_segment()
3218 if (tp->t_fbyte_in == 0) in tcp_do_segment()
3219 tp->t_fbyte_in = 1; in tcp_do_segment()
3220 if (tp->t_fbyte_out && tp->t_fbyte_in) in tcp_do_segment()
3221 tp->t_flags2 |= TF2_FBYTES_COMPLETE; in tcp_do_segment()
3231 tp->t_flags |= TF_WAKESOR; in tcp_do_segment()
3241 thflags = tcp_reass(tp, th, &temp, &tlen, m); in tcp_do_segment()
3242 tp->t_flags |= TF_ACKNOW; in tcp_do_segment()
3244 if ((tp->t_flags & TF_SACK_PERMIT) && in tcp_do_segment()
3246 TCPS_HAVEESTABLISHED(tp->t_state)) { in tcp_do_segment()
3252 tcp_update_sack_list(tp, save_start, in tcp_do_segment()
3254 } else if ((tlen > 0) && SEQ_GT(tp->rcv_nxt, save_rnxt)) { in tcp_do_segment()
3255 if ((tp->rcv_numsacks >= 1) && in tcp_do_segment()
3256 (tp->sackblks[0].end == save_start)) { in tcp_do_segment()
3261 tcp_update_sack_list(tp, in tcp_do_segment()
3262 tp->sackblks[0].start, in tcp_do_segment()
3263 tp->sackblks[0].end); in tcp_do_segment()
3265 tcp_update_dsack_list(tp, save_start, in tcp_do_segment()
3270 tcp_update_dsack_list(tp, save_start, in tcp_do_segment()
3273 tcp_update_dsack_list(tp, save_start, in tcp_do_segment()
3277 tcp_handle_wakeup(tp); in tcp_do_segment()
3285 if (SEQ_GT(tp->rcv_adv, tp->rcv_nxt)) in tcp_do_segment()
3286 len = so->so_rcv.sb_hiwat - (tp->rcv_adv - tp->rcv_nxt); in tcp_do_segment()
3299 tcpstates[tp->t_state], tlen); in tcp_do_segment()
3306 tcpstates[tp->t_state], tlen); in tcp_do_segment()
3315 tcpstates[tp->t_state]); in tcp_do_segment()
3329 if (TCPS_HAVERCVDFIN(tp->t_state) == 0) { in tcp_do_segment()
3339 if (tp->t_flags & TF_NEEDSYN) in tcp_do_segment()
3340 tp->t_flags |= TF_DELACK; in tcp_do_segment()
3342 tp->t_flags |= TF_ACKNOW; in tcp_do_segment()
3343 tp->rcv_nxt++; in tcp_do_segment()
3345 switch (tp->t_state) { in tcp_do_segment()
3351 tp->t_starttime = ticks; in tcp_do_segment()
3354 tcp_state_change(tp, TCPS_CLOSE_WAIT); in tcp_do_segment()
3362 tcp_state_change(tp, TCPS_CLOSING); in tcp_do_segment()
3371 tcp_twstart(tp); in tcp_do_segment()
3375 TCP_PROBE3(debug__input, tp, th, m); in tcp_do_segment()
3380 if (needoutput || (tp->t_flags & TF_ACKNOW)) in tcp_do_segment()
3381 (void) tcp_output(tp); in tcp_do_segment()
3386 if (tp->t_flags & TF_DELACK) { in tcp_do_segment()
3387 tp->t_flags &= ~TF_DELACK; in tcp_do_segment()
3388 tcp_timer_activate(tp, TT_DELACK, tcp_delacktime); in tcp_do_segment()
3409 if (tp->t_state == TCPS_SYN_RECEIVED && (thflags & TH_ACK) && in tcp_do_segment()
3410 (SEQ_GT(tp->snd_una, th->th_ack) || in tcp_do_segment()
3411 SEQ_GT(th->th_ack, tp->snd_max)) ) { in tcp_do_segment()
3413 tcp_log_end_status(tp, TCP_EI_STATUS_RST_IN_FRONT); in tcp_do_segment()
3416 TCP_PROBE3(debug__input, tp, th, m); in tcp_do_segment()
3417 tp->t_flags |= TF_ACKNOW; in tcp_do_segment()
3418 (void) tcp_output(tp); in tcp_do_segment()
3424 if (tp != NULL) { in tcp_do_segment()
3425 tcp_dropwithreset(m, th, tp, tlen, rstreason); in tcp_do_segment()
3435 TCP_PROBE3(debug__input, tp, th, m); in tcp_do_segment()
3436 if (tp != NULL) { in tcp_do_segment()
3448 tcp_dropwithreset(struct mbuf *m, struct tcphdr *th, struct tcpcb *tp, in tcp_dropwithreset() argument
3458 if (tp != NULL) { in tcp_dropwithreset()
3459 INP_LOCK_ASSERT(tptoinpcb(tp)); in tcp_dropwithreset()
3494 tcp_respond(tp, mtod(m, void *), th, m, (tcp_seq)0, in tcp_dropwithreset()
3501 tcp_respond(tp, mtod(m, void *), th, m, th->th_seq+tlen, in tcp_dropwithreset()
3629 struct tcpcb *tp = sototcpcb(so); in tcp_pulloutofband() local
3631 INP_WLOCK_ASSERT(tptoinpcb(tp)); in tcp_pulloutofband()
3633 tp->t_iobc = *cp; in tcp_pulloutofband()
3634 tp->t_oobflags |= TCPOOB_HAVEDATA; in tcp_pulloutofband()
3654 tcp_xmit_timer(struct tcpcb *tp, int rtt) in tcp_xmit_timer() argument
3658 INP_WLOCK_ASSERT(tptoinpcb(tp)); in tcp_xmit_timer()
3661 if (tp->t_rttupdated < UCHAR_MAX) in tcp_xmit_timer()
3662 tp->t_rttupdated++; in tcp_xmit_timer()
3664 stats_voi_update_abs_u32(tp->t_stats, VOI_TCP_RTT, in tcp_xmit_timer()
3667 if ((tp->t_srtt != 0) && (tp->t_rxtshift <= TCP_RTT_INVALIDATE)) { in tcp_xmit_timer()
3676 - (tp->t_srtt >> (TCP_RTT_SHIFT - TCP_DELTA_SHIFT)); in tcp_xmit_timer()
3678 if ((tp->t_srtt += delta) <= 0) in tcp_xmit_timer()
3679 tp->t_srtt = 1; in tcp_xmit_timer()
3693 delta -= tp->t_rttvar >> (TCP_RTTVAR_SHIFT - TCP_DELTA_SHIFT); in tcp_xmit_timer()
3694 if ((tp->t_rttvar += delta) <= 0) in tcp_xmit_timer()
3695 tp->t_rttvar = 1; in tcp_xmit_timer()
3702 tp->t_srtt = rtt << TCP_RTT_SHIFT; in tcp_xmit_timer()
3703 tp->t_rttvar = rtt << (TCP_RTTVAR_SHIFT - 1); in tcp_xmit_timer()
3705 tp->t_rtttime = 0; in tcp_xmit_timer()
3706 tp->t_rxtshift = 0; in tcp_xmit_timer()
3719 TCPT_RANGESET(tp->t_rxtcur, TCP_REXMTVAL(tp), in tcp_xmit_timer()
3720 max(tp->t_rttmin, rtt + 2), TCPTV_REXMTMAX); in tcp_xmit_timer()
3729 tp->t_softerror = 0; in tcp_xmit_timer()
3754 tcp_mss_update(struct tcpcb *tp, int offer, int mtuoffer, in tcp_mss_update() argument
3759 struct inpcb *inp = tptoinpcb(tp); in tcp_mss_update()
3772 if (tp->t_port) in tcp_mss_update()
3783 tp->t_maxseg = V_tcp_v6mssdflt; in tcp_mss_update()
3792 tp->t_maxseg = V_tcp_mssdflt; in tcp_mss_update()
3818 offer = tp->t_maxseg; in tcp_mss_update()
3899 tp->t_maxseg = mss; in tcp_mss_update()
3903 tcp_mss(struct tcpcb *tp, int offer) in tcp_mss() argument
3907 struct inpcb *inp = tptoinpcb(tp); in tcp_mss()
3912 KASSERT(tp != NULL, ("%s: tp == NULL", __func__)); in tcp_mss()
3915 tcp_mss_update(tp, offer, -1, &metrics, &cap); in tcp_mss()
3917 mss = tp->t_maxseg; in tcp_mss()
3950 tp->t_maxseg = max(mss, 64); in tcp_mss()
3968 tp->t_flags |= TF_TSO; in tcp_mss()
3969 tp->t_tsomax = cap.tsomax; in tcp_mss()
3970 tp->t_tsomaxsegcount = cap.tsomaxsegcount; in tcp_mss()
3971 tp->t_tsomaxsegsize = cap.tsomaxsegsize; in tcp_mss()
4018 tcp_do_prr_ack(struct tcpcb *tp, struct tcphdr *th, struct tcpopt *to, sackstatus_t sack_changed) in tcp_do_prr_ack() argument
4021 int maxseg = tcp_maxseg(tp); in tcp_do_prr_ack()
4023 INP_WLOCK_ASSERT(tptoinpcb(tp)); in tcp_do_prr_ack()
4030 if (tcp_is_sack_recovery(tp, to) || in tcp_do_prr_ack()
4031 (IN_CONGRECOVERY(tp->t_flags) && in tcp_do_prr_ack()
4032 !IN_FASTRECOVERY(tp->t_flags))) { in tcp_do_prr_ack()
4033 del_data = tp->sackhint.delivered_data; in tcp_do_prr_ack()
4035 pipe = tcp_compute_pipe(tp); in tcp_do_prr_ack()
4037 pipe = (tp->snd_nxt - tp->snd_fack) + in tcp_do_prr_ack()
4038 tp->sackhint.sack_bytes_rexmit; in tcp_do_prr_ack()
4040 if (tp->sackhint.prr_delivered < (tcprexmtthresh * maxseg + in tcp_do_prr_ack()
4041 tp->snd_recover - tp->snd_una)) in tcp_do_prr_ack()
4043 pipe = imax(0, tp->snd_max - tp->snd_una - in tcp_do_prr_ack()
4044 imin(INT_MAX / 65536, tp->t_dupacks) * maxseg); in tcp_do_prr_ack()
4046 tp->sackhint.prr_delivered += del_data; in tcp_do_prr_ack()
4050 if (pipe >= tp->snd_ssthresh) { in tcp_do_prr_ack()
4051 if (tp->sackhint.recover_fs == 0) in tcp_do_prr_ack()
4052 tp->sackhint.recover_fs = in tcp_do_prr_ack()
4053 imax(1, tp->snd_nxt - tp->snd_una); in tcp_do_prr_ack()
4054 snd_cnt = howmany((long)tp->sackhint.prr_delivered * in tcp_do_prr_ack()
4055 tp->snd_ssthresh, tp->sackhint.recover_fs) - in tcp_do_prr_ack()
4056 tp->sackhint.prr_out + maxseg - 1; in tcp_do_prr_ack()
4069 limit = tp->sackhint.prr_delivered - in tcp_do_prr_ack()
4070 tp->sackhint.prr_out; in tcp_do_prr_ack()
4072 limit = imax(tp->sackhint.prr_delivered - in tcp_do_prr_ack()
4073 tp->sackhint.prr_out, del_data) + in tcp_do_prr_ack()
4075 snd_cnt = imin((tp->snd_ssthresh - pipe), limit); in tcp_do_prr_ack()
4083 if (IN_FASTRECOVERY(tp->t_flags)) { in tcp_do_prr_ack()
4084 if (tcp_is_sack_recovery(tp, to)) { in tcp_do_prr_ack()
4085 tp->snd_cwnd = tp->snd_nxt - tp->snd_recover + in tcp_do_prr_ack()
4086 tp->sackhint.sack_bytes_rexmit + in tcp_do_prr_ack()
4089 tp->snd_cwnd = (tp->snd_max - tp->snd_una) + in tcp_do_prr_ack()
4092 } else if (IN_CONGRECOVERY(tp->t_flags)) in tcp_do_prr_ack()
4093 tp->snd_cwnd = pipe - del_data + (snd_cnt * maxseg); in tcp_do_prr_ack()
4094 tp->snd_cwnd = imax(maxseg, tp->snd_cwnd); in tcp_do_prr_ack()
4104 tcp_newreno_partial_ack(struct tcpcb *tp, struct tcphdr *th) in tcp_newreno_partial_ack() argument
4106 tcp_seq onxt = tp->snd_nxt; in tcp_newreno_partial_ack()
4107 uint32_t ocwnd = tp->snd_cwnd; in tcp_newreno_partial_ack()
4108 u_int maxseg = tcp_maxseg(tp); in tcp_newreno_partial_ack()
4110 INP_WLOCK_ASSERT(tptoinpcb(tp)); in tcp_newreno_partial_ack()
4112 tcp_timer_activate(tp, TT_REXMT, 0); in tcp_newreno_partial_ack()
4113 tp->t_rtttime = 0; in tcp_newreno_partial_ack()
4114 tp->snd_nxt = th->th_ack; in tcp_newreno_partial_ack()
4119 tp->snd_cwnd = maxseg + BYTES_THIS_ACK(tp, th); in tcp_newreno_partial_ack()
4120 tp->t_flags |= TF_ACKNOW; in tcp_newreno_partial_ack()
4121 (void) tcp_output(tp); in tcp_newreno_partial_ack()
4122 tp->snd_cwnd = ocwnd; in tcp_newreno_partial_ack()
4123 if (SEQ_GT(onxt, tp->snd_nxt)) in tcp_newreno_partial_ack()
4124 tp->snd_nxt = onxt; in tcp_newreno_partial_ack()
4129 if (tp->snd_cwnd > BYTES_THIS_ACK(tp, th)) in tcp_newreno_partial_ack()
4130 tp->snd_cwnd -= BYTES_THIS_ACK(tp, th); in tcp_newreno_partial_ack()
4132 tp->snd_cwnd = 0; in tcp_newreno_partial_ack()
4133 tp->snd_cwnd += maxseg; in tcp_newreno_partial_ack()
4137 tcp_compute_pipe(struct tcpcb *tp) in tcp_compute_pipe() argument
4139 if (tp->t_fb->tfb_compute_pipe == NULL) { in tcp_compute_pipe()
4140 return (tp->snd_max - tp->snd_una + in tcp_compute_pipe()
4141 tp->sackhint.sack_bytes_rexmit - in tcp_compute_pipe()
4142 tp->sackhint.sacked_bytes); in tcp_compute_pipe()
4144 return((*tp->t_fb->tfb_compute_pipe)(tp)); in tcp_compute_pipe()