Lines Matching refs:tp

282 hhook_run_tcp_est_in(struct tcpcb *tp, struct tcphdr *th, struct tcpopt *to)
287 hhook_data.tp = tp;
292 tp->osd);
300 cc_ack_received(struct tcpcb *tp, struct tcphdr *th, uint16_t type)
302 INP_WLOCK_ASSERT(tp->t_inpcb);
304 tp->ccv->bytes_this_ack = BYTES_THIS_ACK(tp, th);
305 if (tp->snd_cwnd <= tp->snd_wnd)
306 tp->ccv->flags |= CCF_CWND_LIMITED;
308 tp->ccv->flags &= ~CCF_CWND_LIMITED;
311 if (tp->snd_cwnd > tp->snd_ssthresh) {
312 tp->t_bytes_acked += min(tp->ccv->bytes_this_ack,
313 V_tcp_abc_l_var * tcp_maxseg(tp));
314 if (tp->t_bytes_acked >= tp->snd_cwnd) {
315 tp->t_bytes_acked -= tp->snd_cwnd;
316 tp->ccv->flags |= CCF_ABC_SENTAWND;
319 tp->ccv->flags &= ~CCF_ABC_SENTAWND;
320 tp->t_bytes_acked = 0;
324 if (CC_ALGO(tp)->ack_received != NULL) {
326 tp->ccv->curack = th->th_ack;
327 CC_ALGO(tp)->ack_received(tp->ccv, type);
332 cc_conn_init(struct tcpcb *tp)
335 struct inpcb *inp = tp->t_inpcb;
339 INP_WLOCK_ASSERT(tp->t_inpcb);
342 maxseg = tcp_maxseg(tp);
344 if (tp->t_srtt == 0 && (rtt = metrics.rmx_rtt)) {
345 tp->t_srtt = rtt;
346 tp->t_rttbest = tp->t_srtt + TCP_RTT_SCALE;
349 tp->t_rttvar = metrics.rmx_rttvar;
353 tp->t_rttvar =
354 tp->t_srtt * TCP_RTTVAR_SCALE / TCP_RTT_SCALE;
356 TCPT_RANGESET(tp->t_rxtcur,
357 ((tp->t_srtt >> 2) + tp->t_rttvar) >> 1,
358 tp->t_rttmin, TCPTV_REXMTMAX);
367 tp->snd_ssthresh = max(2 * maxseg, metrics.rmx_ssthresh);
383 if (tp->snd_cwnd == 1)
384 tp->snd_cwnd = maxseg; /* SYN(-ACK) lost */
386 tp->snd_cwnd = min(V_tcp_initcwnd_segments * maxseg,
389 tp->snd_cwnd = min(4 * maxseg, max(2 * maxseg, 4380));
393 tp->snd_cwnd = 2 * maxseg;
395 tp->snd_cwnd = 3 * maxseg;
397 tp->snd_cwnd = 4 * maxseg;
400 if (CC_ALGO(tp)->conn_init != NULL)
401 CC_ALGO(tp)->conn_init(tp->ccv);
405 cc_cong_signal(struct tcpcb *tp, struct tcphdr *th, uint32_t type)
409 INP_WLOCK_ASSERT(tp->t_inpcb);
413 if (!IN_FASTRECOVERY(tp->t_flags)) {
414 tp->snd_recover = tp->snd_max;
415 if (tp->t_flags & TF_ECN_PERMIT)
416 tp->t_flags |= TF_ECN_SND_CWR;
420 if (!IN_CONGRECOVERY(tp->t_flags) ||
425 SEQ_GEQ(th->th_ack, tp->snd_recover)) {
426 EXIT_CONGRECOVERY(tp->t_flags);
428 tp->snd_recover = tp->snd_max + 1;
429 if (tp->t_flags & TF_ECN_PERMIT)
430 tp->t_flags |= TF_ECN_SND_CWR;
434 maxseg = tcp_maxseg(tp);
435 tp->t_dupacks = 0;
436 tp->t_bytes_acked = 0;
437 EXIT_RECOVERY(tp->t_flags);
438 tp->snd_ssthresh = max(2, min(tp->snd_wnd, tp->snd_cwnd) / 2 /
440 tp->snd_cwnd = maxseg;
445 tp->snd_cwnd = tp->snd_cwnd_prev;
446 tp->snd_ssthresh = tp->snd_ssthresh_prev;
447 tp->snd_recover = tp->snd_recover_prev;
448 if (tp->t_flags & TF_WASFRECOVERY)
449 ENTER_FASTRECOVERY(tp->t_flags);
450 if (tp->t_flags & TF_WASCRECOVERY)
451 ENTER_CONGRECOVERY(tp->t_flags);
452 tp->snd_nxt = tp->snd_max;
453 tp->t_flags &= ~TF_PREVVALID;
454 tp->t_badrxtwin = 0;
458 if (CC_ALGO(tp)->cong_signal != NULL) {
460 tp->ccv->curack = th->th_ack;
461 CC_ALGO(tp)->cong_signal(tp->ccv, type);
466 cc_post_recovery(struct tcpcb *tp, struct tcphdr *th)
468 INP_WLOCK_ASSERT(tp->t_inpcb);
472 if (CC_ALGO(tp)->post_recovery != NULL) {
473 tp->ccv->curack = th->th_ack;
474 CC_ALGO(tp)->post_recovery(tp->ccv);
477 tp->t_bytes_acked = 0;
489 #define DELAY_ACK(tp, tlen) \
490 ((!tcp_timer_active(tp, TT_DELACK) && \
491 (tp->t_flags & TF_RXWIN0SENT) == 0) && \
492 (tlen <= tp->t_maxseg) && \
493 (V_tcp_delack_enabled || (tp->t_flags & TF_NEEDSYN)))
496 cc_ecnpkt_handler(struct tcpcb *tp, struct tcphdr *th, uint8_t iptos)
498 INP_WLOCK_ASSERT(tp->t_inpcb);
500 if (CC_ALGO(tp)->ecnpkt_handler != NULL) {
503 tp->ccv->flags |= CCF_IPHDR_CE;
506 tp->ccv->flags &= ~CCF_IPHDR_CE;
509 tp->ccv->flags &= ~CCF_IPHDR_CE;
514 tp->ccv->flags |= CCF_TCPHDR_CWR;
516 tp->ccv->flags &= ~CCF_TCPHDR_CWR;
518 if (tp->t_flags & TF_DELACK)
519 tp->ccv->flags |= CCF_DELACK;
521 tp->ccv->flags &= ~CCF_DELACK;
523 CC_ALGO(tp)->ecnpkt_handler(tp->ccv);
525 if (tp->ccv->flags & CCF_ACKNOW)
526 tcp_timer_activate(tp, TT_DELACK, tcp_delacktime);
579 struct tcpcb *tp = NULL;
1010 tp = intotcpcb(inp);
1011 if (tp == NULL || tp->t_state == TCPS_CLOSED) {
1017 if (tp->t_flags & TF_TOE) {
1018 tcp_offload_input(tp, m);
1035 if (!((tp->t_state == TCPS_ESTABLISHED && (thflags & TH_SYN) == 0) ||
1036 (tp->t_state == TCPS_LISTEN && (thflags & TH_SYN) &&
1037 !(tp->t_flags & TF_FASTOPEN)))) {
1069 ostate = tp->t_state;
1084 KASSERT(tp->t_state == TCPS_LISTEN || !(so->so_options & SO_ACCEPTCONN),
1085 ("%s: so accepting but tp %p not listening", __func__, tp));
1086 if (tp->t_state == TCPS_LISTEN && (so->so_options & SO_ACCEPTCONN)) {
1174 * created socket and update the tp variable.
1183 tp = intotcpcb(inp);
1184 KASSERT(tp->t_state == TCPS_SYN_RECEIVED,
1191 TCP_PROBE5(receive, NULL, tp, m, tp, th);
1192 tp->t_fb->tfb_tcp_do_segment(m, th, so, tp, drop_hdrlen, tlen,
1385 tcp_trace(TA_INPUT, ostate, tp,
1388 TCP_PROBE3(debug__input, tp, th, m);
1406 } else if (tp->t_state == TCPS_LISTEN) {
1417 if (tp->t_flags & TF_SIGNATURE) {
1428 TCP_PROBE5(receive, NULL, tp, m, tp, th);
1435 tp->t_fb->tfb_tcp_do_segment(m, th, so, tp, drop_hdrlen, tlen, iptos, ti_locked);
1440 TCP_PROBE5(receive, NULL, tp, m, tp, th);
1455 tcp_dropwithreset(m, th, tp, tlen, rstreason);
1464 TCP_PROBE5(receive, NULL, tp, m, tp, th);
1527 struct tcpcb *tp, int tlen)
1532 tp->t_srtt != 0 && tp->rfbuf_ts != 0 &&
1533 TCP_TS_TO_TICKS(tcp_ts_getticks() - tp->rfbuf_ts) >
1534 (tp->t_srtt >> TCP_RTT_SHIFT)) {
1535 if (tp->rfbuf_cnt > (so->so_rcv.sb_hiwat / 8 * 7) &&
1540 TCP_PROBE6(receive__autoresize, NULL, tp, m, tp, th, newsize);
1543 tp->rfbuf_ts = 0;
1544 tp->rfbuf_cnt = 0;
1546 tp->rfbuf_cnt += tlen; /* add up */
1553 struct tcpcb *tp, int drop_hdrlen, int tlen, uint8_t iptos,
1575 inc = &tp->t_inpcb->inp_inc;
1576 tp->sackhint.last_sack_ack = 0;
1586 tp->t_state != TCPS_ESTABLISHED) {
1601 INP_WLOCK_ASSERT(tp->t_inpcb);
1602 KASSERT(tp->t_state > TCPS_LISTEN, ("%s: TCPS_LISTEN",
1604 KASSERT(tp->t_state != TCPS_TIME_WAIT, ("%s: TCPS_TIME_WAIT",
1609 tcp_pcap_add(th, m, &(tp->t_inpkts));
1626 if ((tp->t_state == TCPS_SYN_SENT) && (thflags & TH_ACK) &&
1627 (SEQ_LEQ(th->th_ack, tp->iss) || SEQ_GT(th->th_ack, tp->snd_max))) {
1638 tp->t_rcvtime = ticks;
1639 if (TCPS_HAVEESTABLISHED(tp->t_state))
1640 tcp_timer_activate(tp, TT_KEEP, TP_KEEPIDLE(tp));
1646 tiwin = th->th_win << tp->snd_scale;
1651 if (tp->t_flags & TF_ECN_PERMIT) {
1653 tp->t_flags &= ~TF_ECN_SND_ECE;
1656 tp->t_flags |= TF_ECN_SND_ECE;
1668 cc_ecnpkt_handler(tp, th, iptos);
1672 cc_cong_signal(tp, th, CC_ECN);
1684 if ((tp->t_flags & TF_SIGNATURE) != 0 &&
1697 to.to_tsecr -= tp->ts_offset;
1708 if (tp->t_state == TCPS_SYN_SENT && (thflags & TH_SYN)) {
1710 (tp->t_flags & TF_REQ_SCALE)) {
1711 tp->t_flags |= TF_RCVD_SCALE;
1712 tp->snd_scale = to.to_wscale;
1718 tp->snd_wnd = th->th_win;
1720 tp->t_flags |= TF_RCVD_TSTMP;
1721 tp->ts_recent = to.to_tsval;
1722 tp->ts_recent_age = tcp_ts_getticks();
1725 tcp_mss(tp, to.to_mss);
1726 if ((tp->t_flags & TF_SACK_PERMIT) &&
1728 tp->t_flags &= ~TF_SACK_PERMIT;
1737 if ((tp->t_flags & TF_RCVD_TSTMP) && !(to.to_flags & TOF_TS)) {
1751 if (!(tp->t_flags & TF_RCVD_TSTMP) && (to.to_flags & TOF_TS)) {
1776 if (tp->t_state == TCPS_ESTABLISHED &&
1777 th->th_seq == tp->rcv_nxt &&
1779 tp->snd_nxt == tp->snd_max &&
1780 tiwin && tiwin == tp->snd_wnd &&
1781 ((tp->t_flags & (TF_NEEDSYN|TF_NEEDFIN)) == 0) &&
1782 SEGQ_EMPTY(tp) &&
1784 TSTMP_GEQ(to.to_tsval, tp->ts_recent)) ) {
1793 SEQ_LEQ(th->th_seq, tp->last_ack_sent)) {
1794 tp->ts_recent_age = tcp_ts_getticks();
1795 tp->ts_recent = to.to_tsval;
1799 if (SEQ_GT(th->th_ack, tp->snd_una) &&
1800 SEQ_LEQ(th->th_ack, tp->snd_max) &&
1801 !IN_RECOVERY(tp->t_flags) &&
1803 TAILQ_EMPTY(&tp->snd_holes)) {
1816 if (tp->t_rxtshift == 1 &&
1817 tp->t_flags & TF_PREVVALID &&
1818 (int)(ticks - tp->t_badrxtwin) < 0) {
1819 cc_cong_signal(tp, th, CC_RTO_ERR);
1835 if (!tp->t_rttlow || tp->t_rttlow > t)
1836 tp->t_rttlow = t;
1837 tcp_xmit_timer(tp,
1839 } else if (tp->t_rtttime &&
1840 SEQ_GT(th->th_ack, tp->t_rtseq)) {
1841 if (!tp->t_rttlow ||
1842 tp->t_rttlow > ticks - tp->t_rtttime)
1843 tp->t_rttlow = ticks - tp->t_rtttime;
1844 tcp_xmit_timer(tp,
1845 ticks - tp->t_rtttime);
1847 acked = BYTES_THIS_ACK(tp, th);
1850 hhook_run_tcp_est_in(tp, th, &to);
1855 if (SEQ_GT(tp->snd_una, tp->snd_recover) &&
1856 SEQ_LEQ(th->th_ack, tp->snd_recover))
1857 tp->snd_recover = th->th_ack - 1;
1865 cc_ack_received(tp, th, CC_ACK);
1867 tp->snd_una = th->th_ack;
1872 tp->snd_wl2 = th->th_ack;
1873 tp->t_dupacks = 0;
1887 tcp_trace(TA_INPUT, ostate, tp,
1891 TCP_PROBE3(debug__input, tp, th, m);
1892 if (tp->snd_una == tp->snd_max)
1893 tcp_timer_activate(tp, TT_REXMT, 0);
1894 else if (!tcp_timer_active(tp, TT_PERSIST))
1895 tcp_timer_activate(tp, TT_REXMT,
1896 tp->t_rxtcur);
1899 (void) tp->t_fb->tfb_tcp_output(tp);
1902 } else if (th->th_ack == tp->snd_una &&
1916 if ((tp->t_flags & TF_SACK_PERMIT) && tp->rcv_numsacks)
1917 tcp_clean_sackreport(tp);
1919 tp->rcv_nxt += tlen;
1924 tp->snd_wl1 = th->th_seq;
1929 tp->rcv_up = tp->rcv_nxt;
1934 tcp_trace(TA_INPUT, ostate, tp,
1937 TCP_PROBE3(debug__input, tp, th, m);
1939 newsize = tcp_autorcvbuf(m, th, so, tp, tlen);
1959 if (DELAY_ACK(tp, tlen)) {
1960 tp->t_flags |= TF_DELACK;
1962 tp->t_flags |= TF_ACKNOW;
1963 tp->t_fb->tfb_tcp_output(tp);
1978 tp->rcv_wnd = imax(win, (int)(tp->rcv_adv - tp->rcv_nxt));
1980 switch (tp->t_state) {
1988 (SEQ_LEQ(th->th_ack, tp->snd_una) ||
1989 SEQ_GT(th->th_ack, tp->snd_max))) {
1994 if (tp->t_flags & TF_FASTOPEN) {
2007 if ((tcp_timer_active(tp, TT_DELACK) ||
2008 tcp_timer_active(tp, TT_REXMT)))
2022 * initialize tp->rcv_nxt and tp->irs
2023 * if seg contains ack then advance tp->snd_una
2032 TCP_PROBE5(connect__refused, NULL, tp,
2033 m, tp, th);
2034 tp = tcp_drop(tp, ECONNREFUSED);
2041 tp->irs = th->th_seq;
2042 tcp_rcvseqinit(tp);
2050 if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) ==
2052 tp->rcv_scale = tp->request_r_scale;
2054 tp->rcv_adv += imin(tp->rcv_wnd,
2055 TCP_MAXWIN << tp->rcv_scale);
2056 tp->snd_una++; /* SYN is acked */
2061 if (DELAY_ACK(tp, tlen) && tlen != 0)
2062 tcp_timer_activate(tp, TT_DELACK,
2065 tp->t_flags |= TF_ACKNOW;
2068 tp->t_flags |= TF_ECN_PERMIT;
2078 tp->t_starttime = ticks;
2079 if (tp->t_flags & TF_NEEDFIN) {
2080 tcp_state_change(tp, TCPS_FIN_WAIT_1);
2081 tp->t_flags &= ~TF_NEEDFIN;
2084 tcp_state_change(tp, TCPS_ESTABLISHED);
2085 TCP_PROBE5(connect__established, NULL, tp,
2086 m, tp, th);
2087 cc_conn_init(tp);
2088 tcp_timer_activate(tp, TT_KEEP,
2089 TP_KEEPIDLE(tp));
2100 tp->t_flags |= (TF_ACKNOW | TF_NEEDSYN);
2101 tcp_timer_activate(tp, TT_REXMT, 0);
2102 tcp_state_change(tp, TCPS_SYN_RECEIVED);
2108 INP_WLOCK_ASSERT(tp->t_inpcb);
2116 if (tlen > tp->rcv_wnd) {
2117 todrop = tlen - tp->rcv_wnd;
2119 tlen = tp->rcv_wnd;
2124 tp->snd_wl1 = th->th_seq - 1;
2125 tp->rcv_up = th->th_seq;
2176 if ((SEQ_GEQ(th->th_seq, tp->last_ack_sent) &&
2177 SEQ_LT(th->th_seq, tp->last_ack_sent + tp->rcv_wnd)) ||
2178 (tp->rcv_wnd == 0 && tp->last_ack_sent == th->th_seq)) {
2182 ("%s: TH_RST ti_locked %d, th %p tp %p",
2183 __func__, ti_locked, th, tp));
2184 KASSERT(tp->t_state != TCPS_SYN_SENT,
2185 ("%s: TH_RST for TCPS_SYN_SENT th %p tp %p",
2186 __func__, th, tp));
2189 tp->last_ack_sent == th->th_seq) {
2192 switch (tp->t_state) {
2206 tp = tcp_close(tp);
2211 tcp_respond(tp, mtod(m, void *), th, m,
2212 tp->rcv_nxt, tp->snd_nxt, TH_ACK);
2213 tp->last_ack_sent = tp->rcv_nxt;
2224 if ((thflags & TH_SYN) && tp->t_state != TCPS_SYN_SENT &&
2225 tp->t_state != TCPS_SYN_RECEIVED) {
2232 SEQ_GEQ(th->th_seq, tp->last_ack_sent) &&
2233 SEQ_LT(th->th_seq, tp->last_ack_sent + tp->rcv_wnd)) {
2234 tp = tcp_drop(tp, ECONNRESET);
2238 tcp_respond(tp, mtod(m, void *), th, m, tp->rcv_nxt,
2239 tp->snd_nxt, TH_ACK);
2240 tp->last_ack_sent = tp->rcv_nxt;
2250 if ((to.to_flags & TOF_TS) != 0 && tp->ts_recent &&
2251 TSTMP_LT(to.to_tsval, tp->ts_recent)) {
2254 if (tcp_ts_getticks() - tp->ts_recent_age > TCP_PAWS_IDLE) {
2266 tp->ts_recent = 0;
2284 if (tp->t_state == TCPS_SYN_RECEIVED && SEQ_LT(th->th_seq, tp->irs)) {
2289 todrop = tp->rcv_nxt - th->th_seq;
2316 tp->t_flags |= TF_ACKNOW;
2327 if ((todrop > 0) && (tp->t_flags & TF_SACK_PERMIT)) {
2328 tcp_update_sack_list(tp, th->th_seq,
2334 tp->t_flags |= TF_ACKNOW;
2352 tp->t_state > TCPS_CLOSE_WAIT && tlen) {
2361 s, __func__, tcpstates[tp->t_state], tlen);
2364 tp = tcp_close(tp);
2374 todrop = (th->th_seq + tlen) - (tp->rcv_nxt + tp->rcv_wnd);
2386 if (tp->rcv_wnd == 0 && th->th_seq == tp->rcv_nxt) {
2387 tp->t_flags |= TF_ACKNOW;
2417 SEQ_LEQ(th->th_seq, tp->last_ack_sent) &&
2418 SEQ_LEQ(tp->last_ack_sent, th->th_seq + tlen +
2420 tp->ts_recent_age = tcp_ts_getticks();
2421 tp->ts_recent = to.to_tsval;
2430 if (tp->t_state == TCPS_SYN_RECEIVED ||
2431 (tp->t_flags & TF_NEEDSYN)) {
2433 if (tp->t_state == TCPS_SYN_RECEIVED &&
2434 tp->t_flags & TF_FASTOPEN) {
2435 tp->snd_wnd = tiwin;
2436 cc_conn_init(tp);
2440 } else if (tp->t_flags & TF_ACKNOW)
2449 switch (tp->t_state) {
2461 if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) ==
2463 tp->rcv_scale = tp->request_r_scale;
2464 tp->snd_wnd = tiwin;
2471 tp->t_starttime = ticks;
2472 if (tp->t_flags & TF_NEEDFIN) {
2473 tcp_state_change(tp, TCPS_FIN_WAIT_1);
2474 tp->t_flags &= ~TF_NEEDFIN;
2476 tcp_state_change(tp, TCPS_ESTABLISHED);
2477 TCP_PROBE5(accept__established, NULL, tp,
2478 m, tp, th);
2480 if (tp->t_tfo_pending) {
2481 tcp_fastopen_decrement_counter(tp->t_tfo_pending);
2482 tp->t_tfo_pending = NULL;
2488 tp->snd_una++;
2497 if (!(tp->t_flags & TF_FASTOPEN))
2499 cc_conn_init(tp);
2500 tcp_timer_activate(tp, TT_KEEP, TP_KEEPIDLE(tp));
2507 (void) tcp_reass(tp, (struct tcphdr *)0, NULL, 0,
2509 tp->snd_wl1 = th->th_seq - 1;
2515 * tp->snd_una < th->th_ack <= tp->snd_max
2516 * then advance tp->snd_una to th->th_ack and drop
2526 if (SEQ_GT(th->th_ack, tp->snd_max)) {
2530 if ((tp->t_flags & TF_SACK_PERMIT) &&
2532 !TAILQ_EMPTY(&tp->snd_holes)))
2533 sack_changed = tcp_sack_doack(tp, &to, th->th_ack);
2539 tp->sackhint.sacked_bytes = 0;
2542 hhook_run_tcp_est_in(tp, th, &to);
2544 if (SEQ_LEQ(th->th_ack, tp->snd_una)) {
2547 maxseg = tcp_maxseg(tp);
2549 (tiwin == tp->snd_wnd ||
2550 (tp->t_flags & TF_SACK_PERMIT))) {
2559 (TCPS_HAVERCVDFIN(tp->t_state) == 0)) {
2560 tp->t_dupacks = 0;
2601 if (th->th_ack != tp->snd_una ||
2602 ((tp->t_flags & TF_SACK_PERMIT) &&
2605 else if (!tcp_timer_active(tp, TT_REXMT))
2606 tp->t_dupacks = 0;
2607 else if (++tp->t_dupacks > tcprexmtthresh ||
2608 IN_FASTRECOVERY(tp->t_flags)) {
2609 cc_ack_received(tp, th, CC_DUPACK);
2610 if ((tp->t_flags & TF_SACK_PERMIT) &&
2611 IN_FASTRECOVERY(tp->t_flags)) {
2621 awnd = tcp_compute_pipe(tp);
2623 awnd = (tp->snd_nxt - tp->snd_fack) +
2624 tp->sackhint.sack_bytes_rexmit;
2626 if (awnd < tp->snd_ssthresh) {
2627 tp->snd_cwnd += maxseg;
2628 if (tp->snd_cwnd > tp->snd_ssthresh)
2629 tp->snd_cwnd = tp->snd_ssthresh;
2632 tp->snd_cwnd += maxseg;
2633 (void) tp->t_fb->tfb_tcp_output(tp);
2635 } else if (tp->t_dupacks == tcprexmtthresh) {
2636 tcp_seq onxt = tp->snd_nxt;
2645 if (tp->t_flags & TF_SACK_PERMIT) {
2646 if (IN_FASTRECOVERY(tp->t_flags)) {
2647 tp->t_dupacks = 0;
2652 tp->snd_recover)) {
2653 tp->t_dupacks = 0;
2658 cc_cong_signal(tp, th, CC_NDUPACK);
2659 cc_ack_received(tp, th, CC_DUPACK);
2660 tcp_timer_activate(tp, TT_REXMT, 0);
2661 tp->t_rtttime = 0;
2662 if (tp->t_flags & TF_SACK_PERMIT) {
2665 tp->sack_newdata = tp->snd_nxt;
2666 tp->snd_cwnd = maxseg;
2667 (void) tp->t_fb->tfb_tcp_output(tp);
2670 tp->snd_nxt = th->th_ack;
2671 tp->snd_cwnd = maxseg;
2672 (void) tp->t_fb->tfb_tcp_output(tp);
2673 KASSERT(tp->snd_limited <= 2,
2674 ("%s: tp->snd_limited too big",
2676 tp->snd_cwnd = tp->snd_ssthresh +
2678 (tp->t_dupacks - tp->snd_limited);
2679 if (SEQ_GT(onxt, tp->snd_nxt))
2680 tp->snd_nxt = onxt;
2693 cc_ack_received(tp, th, CC_DUPACK);
2694 u_long oldcwnd = tp->snd_cwnd;
2695 tcp_seq oldsndmax = tp->snd_max;
2699 KASSERT(tp->t_dupacks == 1 ||
2700 tp->t_dupacks == 2,
2703 if (tp->t_dupacks == 1)
2704 tp->snd_limited = 0;
2705 tp->snd_cwnd =
2706 (tp->snd_nxt - tp->snd_una) +
2707 (tp->t_dupacks - tp->snd_limited) *
2716 (tp->snd_nxt - tp->snd_una);
2719 (void) tp->t_fb->tfb_tcp_output(tp);
2720 sent = tp->snd_max - oldsndmax;
2722 KASSERT((tp->t_dupacks == 2 &&
2723 tp->snd_limited == 0) ||
2725 tp->t_flags & TF_SENTFIN),
2728 tp->snd_limited = 2;
2730 ++tp->snd_limited;
2731 tp->snd_cwnd = oldcwnd;
2741 tp->t_dupacks = 0;
2746 if ((tp->t_flags & TF_SACK_PERMIT) && sack_changed)
2747 tp->t_dupacks++;
2750 KASSERT(SEQ_GT(th->th_ack, tp->snd_una),
2757 if (IN_FASTRECOVERY(tp->t_flags)) {
2758 if (SEQ_LT(th->th_ack, tp->snd_recover)) {
2759 if (tp->t_flags & TF_SACK_PERMIT)
2760 tcp_sack_partialack(tp, th);
2762 tcp_newreno_partial_ack(tp, th);
2764 cc_post_recovery(tp, th);
2770 if (tp->t_flags & TF_NEEDSYN) {
2778 tp->t_flags &= ~TF_NEEDSYN;
2779 tp->snd_una++;
2781 if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) ==
2783 tp->rcv_scale = tp->request_r_scale;
2789 INP_WLOCK_ASSERT(tp->t_inpcb);
2791 acked = BYTES_THIS_ACK(tp, th);
2793 "(tp->snd_una=%u, th->th_ack=%u, tp=%p, m=%p)", __func__,
2794 tp->snd_una, th->th_ack, tp, m));
2805 if (tp->t_rxtshift == 1 && tp->t_flags & TF_PREVVALID &&
2806 (int)(ticks - tp->t_badrxtwin) < 0)
2807 cc_cong_signal(tp, th, CC_RTO_ERR);
2827 if (!tp->t_rttlow || tp->t_rttlow > t)
2828 tp->t_rttlow = t;
2829 tcp_xmit_timer(tp, TCP_TS_TO_TICKS(t) + 1);
2830 } else if (tp->t_rtttime && SEQ_GT(th->th_ack, tp->t_rtseq)) {
2831 if (!tp->t_rttlow || tp->t_rttlow > ticks - tp->t_rtttime)
2832 tp->t_rttlow = ticks - tp->t_rtttime;
2833 tcp_xmit_timer(tp, ticks - tp->t_rtttime);
2842 if (th->th_ack == tp->snd_max) {
2843 tcp_timer_activate(tp, TT_REXMT, 0);
2845 } else if (!tcp_timer_active(tp, TT_PERSIST))
2846 tcp_timer_activate(tp, TT_REXMT, tp->t_rxtcur);
2860 cc_ack_received(tp, th, CC_ACK);
2864 if (tp->snd_wnd >= sbavail(&so->so_snd))
2865 tp->snd_wnd -= sbavail(&so->so_snd);
2867 tp->snd_wnd = 0;
2873 if (tp->snd_wnd >= (u_long) acked)
2874 tp->snd_wnd -= acked;
2876 tp->snd_wnd = 0;
2883 if (!IN_RECOVERY(tp->t_flags) &&
2884 SEQ_GT(tp->snd_una, tp->snd_recover) &&
2885 SEQ_LEQ(th->th_ack, tp->snd_recover))
2886 tp->snd_recover = th->th_ack - 1;
2888 if (IN_RECOVERY(tp->t_flags) &&
2889 SEQ_GEQ(th->th_ack, tp->snd_recover)) {
2890 EXIT_RECOVERY(tp->t_flags);
2892 tp->snd_una = th->th_ack;
2893 if (tp->t_flags & TF_SACK_PERMIT) {
2894 if (SEQ_GT(tp->snd_una, tp->snd_recover))
2895 tp->snd_recover = tp->snd_una;
2897 if (SEQ_LT(tp->snd_nxt, tp->snd_una))
2898 tp->snd_nxt = tp->snd_una;
2900 switch (tp->t_state) {
2917 * we should release the tp also, and use a
2922 tcp_timer_activate(tp, TT_2MSL,
2925 TP_MAXIDLE(tp)));
2927 tcp_state_change(tp, TCPS_FIN_WAIT_2);
2940 tcp_twstart(tp);
2956 tp = tcp_close(tp);
2964 INP_WLOCK_ASSERT(tp->t_inpcb);
2971 (SEQ_LT(tp->snd_wl1, th->th_seq) ||
2972 (tp->snd_wl1 == th->th_seq && (SEQ_LT(tp->snd_wl2, th->th_ack) ||
2973 (tp->snd_wl2 == th->th_ack && tiwin > tp->snd_wnd))))) {
2976 tp->snd_wl2 == th->th_ack && tiwin > tp->snd_wnd)
2978 tp->snd_wnd = tiwin;
2979 tp->snd_wl1 = th->th_seq;
2980 tp->snd_wl2 = th->th_ack;
2981 if (tp->snd_wnd > tp->max_sndwnd)
2982 tp->max_sndwnd = tp->snd_wnd;
2990 TCPS_HAVERCVDFIN(tp->t_state) == 0) {
3018 if (SEQ_GT(th->th_seq+th->th_urp, tp->rcv_up)) {
3019 tp->rcv_up = th->th_seq + th->th_urp;
3021 (tp->rcv_up - tp->rcv_nxt) - 1;
3025 tp->t_oobflags &= ~(TCPOOB_HAVEDATA | TCPOOB_HADDATA);
3045 if (SEQ_GT(tp->rcv_nxt, tp->rcv_up))
3046 tp->rcv_up = tp->rcv_nxt;
3049 INP_WLOCK_ASSERT(tp->t_inpcb);
3054 * This process logically involves adjusting tp->rcv_wnd as data
3059 tfo_syn = ((tp->t_state == TCPS_SYN_RECEIVED) &&
3060 (tp->t_flags & TF_FASTOPEN));
3062 TCPS_HAVERCVDFIN(tp->t_state) == 0) {
3064 tcp_seq save_rnxt = tp->rcv_nxt;
3069 * with control block tp. Set thflags to whether reassembly now
3079 if (th->th_seq == tp->rcv_nxt &&
3080 SEGQ_EMPTY(tp) &&
3081 (TCPS_HAVEESTABLISHED(tp->t_state) ||
3083 if (DELAY_ACK(tp, tlen) || tfo_syn)
3084 tp->t_flags |= TF_DELACK;
3086 tp->t_flags |= TF_ACKNOW;
3087 tp->rcv_nxt += tlen;
3106 thflags = tcp_reass(tp, th, &temp, &tlen, m);
3107 tp->t_flags |= TF_ACKNOW;
3109 if ((tp->t_flags & TF_SACK_PERMIT) && (save_tlen > 0)) {
3115 tcp_update_sack_list(tp, save_start,
3117 } else if ((tlen > 0) && SEQ_GT(tp->rcv_nxt, save_rnxt)) {
3118 if ((tp->rcv_numsacks >= 1) &&
3119 (tp->sackblks[0].end == save_start)) {
3124 tcp_update_sack_list(tp,
3125 tp->sackblks[0].start,
3126 tp->sackblks[0].end);
3128 tcp_update_dsack_list(tp, save_start,
3133 tcp_update_dsack_list(tp, save_start,
3136 tcp_update_dsack_list(tp, save_start,
3147 if (SEQ_GT(tp->rcv_adv, tp->rcv_nxt))
3148 len = so->so_rcv.sb_hiwat - (tp->rcv_adv - tp->rcv_nxt);
3162 if (TCPS_HAVERCVDFIN(tp->t_state) == 0) {
3171 if (tp->t_flags & TF_NEEDSYN)
3172 tp->t_flags |= TF_DELACK;
3174 tp->t_flags |= TF_ACKNOW;
3175 tp->rcv_nxt++;
3177 switch (tp->t_state) {
3184 tp->t_starttime = ticks;
3187 tcp_state_change(tp, TCPS_CLOSE_WAIT);
3195 tcp_state_change(tp, TCPS_CLOSING);
3209 tcp_twstart(tp);
3220 tcp_trace(TA_INPUT, ostate, tp, (void *)tcp_saveipgen,
3223 TCP_PROBE3(debug__input, tp, th, m);
3228 if (needoutput || (tp->t_flags & TF_ACKNOW))
3229 (void) tp->t_fb->tfb_tcp_output(tp);
3235 INP_WLOCK_ASSERT(tp->t_inpcb);
3237 if (tp->t_flags & TF_DELACK) {
3238 tp->t_flags &= ~TF_DELACK;
3239 tcp_timer_activate(tp, TT_DELACK, tcp_delacktime);
3241 INP_WUNLOCK(tp->t_inpcb);
3260 if (tp->t_state == TCPS_SYN_RECEIVED && (thflags & TH_ACK) &&
3261 (SEQ_GT(tp->snd_una, th->th_ack) ||
3262 SEQ_GT(th->th_ack, tp->snd_max)) ) {
3268 tcp_trace(TA_DROP, ostate, tp, (void *)tcp_saveipgen,
3271 TCP_PROBE3(debug__input, tp, th, m);
3276 tp->t_flags |= TF_ACKNOW;
3277 (void) tp->t_fb->tfb_tcp_output(tp);
3278 INP_WUNLOCK(tp->t_inpcb);
3287 if (tp != NULL) {
3288 tcp_dropwithreset(m, th, tp, tlen, rstreason);
3289 INP_WUNLOCK(tp->t_inpcb);
3308 if (tp == NULL || (tp->t_inpcb->inp_socket->so_options & SO_DEBUG))
3309 tcp_trace(TA_DROP, ostate, tp, (void *)tcp_saveipgen,
3312 TCP_PROBE3(debug__input, tp, th, m);
3313 if (tp != NULL)
3314 INP_WUNLOCK(tp->t_inpcb);
3321 * tp may be NULL.
3324 tcp_dropwithreset(struct mbuf *m, struct tcphdr *th, struct tcpcb *tp,
3334 if (tp != NULL) {
3335 INP_WLOCK_ASSERT(tp->t_inpcb);
3370 tcp_respond(tp, mtod(m, void *), th, m, (tcp_seq)0,
3377 tcp_respond(tp, mtod(m, void *), th, m, th->th_seq+tlen,
3505 struct tcpcb *tp = sototcpcb(so);
3507 INP_WLOCK_ASSERT(tp->t_inpcb);
3509 tp->t_iobc = *cp;
3510 tp->t_oobflags |= TCPOOB_HAVEDATA;
3530 tcp_xmit_timer(struct tcpcb *tp, int rtt)
3534 INP_WLOCK_ASSERT(tp->t_inpcb);
3537 tp->t_rttupdated++;
3538 if (tp->t_srtt != 0) {
3547 - (tp->t_srtt >> (TCP_RTT_SHIFT - TCP_DELTA_SHIFT));
3549 if ((tp->t_srtt += delta) <= 0)
3550 tp->t_srtt = 1;
3564 delta -= tp->t_rttvar >> (TCP_RTTVAR_SHIFT - TCP_DELTA_SHIFT);
3565 if ((tp->t_rttvar += delta) <= 0)
3566 tp->t_rttvar = 1;
3567 if (tp->t_rttbest > tp->t_srtt + tp->t_rttvar)
3568 tp->t_rttbest = tp->t_srtt + tp->t_rttvar;
3575 tp->t_srtt = rtt << TCP_RTT_SHIFT;
3576 tp->t_rttvar = rtt << (TCP_RTTVAR_SHIFT - 1);
3577 tp->t_rttbest = tp->t_srtt + tp->t_rttvar;
3579 tp->t_rtttime = 0;
3580 tp->t_rxtshift = 0;
3593 TCPT_RANGESET(tp->t_rxtcur, TCP_REXMTVAL(tp),
3594 max(tp->t_rttmin, rtt + 2), TCPTV_REXMTMAX);
3603 tp->t_softerror = 0;
3628 tcp_mss_update(struct tcpcb *tp, int offer, int mtuoffer,
3633 struct inpcb *inp = tp->t_inpcb;
3644 INP_WLOCK_ASSERT(tp->t_inpcb);
3655 tp->t_maxseg = V_tcp_v6mssdflt;
3664 tp->t_maxseg = V_tcp_mssdflt;
3690 offer = tp->t_maxseg;
3771 tp->t_maxseg = mss;
3775 tcp_mss(struct tcpcb *tp, int offer)
3784 KASSERT(tp != NULL, ("%s: tp == NULL", __func__));
3787 tcp_mss_update(tp, offer, -1, &metrics, &cap);
3789 mss = tp->t_maxseg;
3790 inp = tp->t_inpcb;
3823 tp->t_maxseg = max(mss, 64);
3841 tp->t_flags |= TF_TSO;
3842 tp->t_tsomax = cap.tsomax;
3843 tp->t_tsomaxsegcount = cap.tsomaxsegcount;
3844 tp->t_tsomaxsegsize = cap.tsomaxsegsize;
3893 * next unacknowledged segment. Do not clear tp->t_dupacks.
3898 tcp_newreno_partial_ack(struct tcpcb *tp, struct tcphdr *th)
3900 tcp_seq onxt = tp->snd_nxt;
3901 u_long ocwnd = tp->snd_cwnd;
3902 u_int maxseg = tcp_maxseg(tp);
3904 INP_WLOCK_ASSERT(tp->t_inpcb);
3906 tcp_timer_activate(tp, TT_REXMT, 0);
3907 tp->t_rtttime = 0;
3908 tp->snd_nxt = th->th_ack;
3911 * (tp->snd_una has not yet been updated when this function is called.)
3913 tp->snd_cwnd = maxseg + BYTES_THIS_ACK(tp, th);
3914 tp->t_flags |= TF_ACKNOW;
3915 (void) tp->t_fb->tfb_tcp_output(tp);
3916 tp->snd_cwnd = ocwnd;
3917 if (SEQ_GT(onxt, tp->snd_nxt))
3918 tp->snd_nxt = onxt;
3920 * Partial window deflation. Relies on fact that tp->snd_una
3923 if (tp->snd_cwnd > BYTES_THIS_ACK(tp, th))
3924 tp->snd_cwnd -= BYTES_THIS_ACK(tp, th);
3926 tp->snd_cwnd = 0;
3927 tp->snd_cwnd += maxseg;
3931 tcp_compute_pipe(struct tcpcb *tp)
3933 return (tp->snd_max - tp->snd_una +
3934 tp->sackhint.sack_bytes_rexmit -
3935 tp->sackhint.sacked_bytes);