Lines Matching refs:tp
251 nd_hint(struct tcpcb *tp)
256 if (tp == NULL)
259 ro = &tp->t_inpcb->inp_route;
267 switch (tp->t_family) {
290 tcp_setup_ack(struct tcpcb *tp, const struct tcphdr *th)
293 if (tp->t_flags & TF_DELACK ||
295 tp->t_flags |= TF_ACKNOW;
297 TCP_SET_DELACK(tp);
301 icmp_check(struct tcpcb *tp, const struct tcphdr *th, int acked)
308 if ((tp->t_flags & TF_PMTUD_PEND) &&
309 SEQ_GT(th->th_ack, tp->t_pmtud_th_seq))
310 tp->t_flags &= ~TF_PMTUD_PEND;
316 if (tp->t_pmtud_mss_acked < acked)
317 tp->t_pmtud_mss_acked = acked;
451 * control block tp. Return TH_FIN if reassembly now includes
455 tcp_reass(struct tcpcb *tp, const struct tcphdr *th, struct mbuf *m, int tlen)
469 so = tp->t_inpcb->inp_socket;
471 TCP_REASS_LOCK_CHECK(tp);
493 if ((p = TAILQ_LAST(&tp->segq, ipqehead)) != NULL) {
504 TAILQ_REMOVE(&tp->timeq, p, ipqe_timeq);
518 q = TAILQ_FIRST(&tp->segq);
533 TAILQ_REMOVE(&tp->timeq, q, ipqe_timeq);
593 tcp_new_dsack(tp, pkt_seq, pkt_len);
659 TAILQ_REMOVE(&tp->segq, q, ipqe_q);
660 TAILQ_REMOVE(&tp->timeq, q, ipqe_timeq);
661 tp->t_segqlen--;
662 KASSERT(tp->t_segqlen >= 0);
663 KASSERT(tp->t_segqlen != 0 ||
664 (TAILQ_EMPTY(&tp->segq) &&
665 TAILQ_EMPTY(&tp->timeq)));
691 TAILQ_REMOVE(&tp->segq, q, ipqe_q);
692 TAILQ_REMOVE(&tp->timeq, q, ipqe_timeq);
693 tp->t_segqlen--;
694 KASSERT(tp->t_segqlen >= 0);
695 KASSERT(tp->t_segqlen != 0 ||
696 (TAILQ_EMPTY(&tp->segq) && TAILQ_EMPTY(&tp->timeq)));
713 if (tp->t_segqlen > tcp_reass_maxqueuelen) {
738 tp->t_rcvoopack++;
757 TAILQ_INSERT_HEAD(&tp->segq, tiqe, ipqe_q);
759 TAILQ_INSERT_AFTER(&tp->segq, p, tiqe, ipqe_q);
761 tp->t_segqlen++;
764 TAILQ_INSERT_HEAD(&tp->timeq, tiqe, ipqe_timeq);
771 if (TCPS_HAVEESTABLISHED(tp->t_state) == 0)
773 q = TAILQ_FIRST(&tp->segq);
774 if (q == NULL || q->ipqe_seq != tp->rcv_nxt)
776 if (tp->t_state == TCPS_SYN_RECEIVED && q->ipqe_len)
779 tp->rcv_nxt += q->ipqe_len;
781 nd_hint(tp);
783 TAILQ_REMOVE(&tp->segq, q, ipqe_q);
784 TAILQ_REMOVE(&tp->timeq, q, ipqe_timeq);
785 tp->t_segqlen--;
786 KASSERT(tp->t_segqlen >= 0);
787 KASSERT(tp->t_segqlen != 0 ||
788 (TAILQ_EMPTY(&tp->segq) && TAILQ_EMPTY(&tp->timeq)));
794 TCP_REASS_UNLOCK(tp);
799 TCP_REASS_UNLOCK(tp);
1042 // tcp_new_dsack(tp, th->th_seq, todrop);
1197 struct tcpcb *tp = NULL;
1463 tp = NULL;
1470 tp = intotcpcb(inp);
1479 if (tp == NULL)
1481 if (tp->t_state == TCPS_CLOSED)
1489 tiwin = th->th_win << tp->snd_scale;
1504 ostate = tp->t_state;
1540 KASSERT(tp->t_state == TCPS_LISTEN);
1605 tp = intotcpcb(inp);
1606 if (tp == NULL)
1608 tiwin <<= tp->snd_scale;
1669 tp = NULL;
1718 KASSERT(tp->t_state != TCPS_LISTEN);
1724 tp->t_rcvtime = tcp_now;
1725 if (TCPS_HAVEESTABLISHED(tp->t_state))
1726 TCP_TIMER_ARM(tp, TCPT_KEEP, tp->t_keepidle);
1732 if (optp || (tp->t_flags & TF_SIGNATURE))
1736 if (tcp_dooptions(tp, optp, optlen, th, m, off, &opti) < 0)
1739 if (TCP_SACK_ENABLED(tp)) {
1740 tcp_del_sackholes(tp, th);
1743 if (TCP_ECN_ALLOWED(tp)) {
1745 tp->t_flags &= ~TF_ECN_SND_ECE;
1749 tp->t_flags |= TF_ECN_SND_ECE;
1763 if ((tiflags & TH_ECE) && SEQ_GEQ(tp->snd_una, tp->snd_recover))
1764 tp->t_congctl->cong_exp(tp);
1787 ts_rtt = TCP_TIMESTAMP(tp) - opti.ts_ecr + 1;
1814 if (tp->t_state == TCPS_ESTABLISHED &&
1817 (!opti.ts_present || TSTMP_GEQ(opti.ts_val, tp->ts_recent)) &&
1818 th->th_seq == tp->rcv_nxt &&
1819 tiwin && tiwin == tp->snd_wnd &&
1820 tp->snd_nxt == tp->snd_max) {
1829 * TSTMP_GEQ(opti.ts_val, tp->ts_recent)
1831 if (opti.ts_present && SEQ_LEQ(th->th_seq, tp->last_ack_sent)) {
1832 tp->ts_recent_age = tcp_now;
1833 tp->ts_recent = opti.ts_val;
1838 if (SEQ_GT(th->th_ack, tp->snd_una) &&
1839 SEQ_LEQ(th->th_ack, tp->snd_max) &&
1840 tp->snd_cwnd >= tp->snd_wnd &&
1841 tp->t_partialacks < 0) {
1846 tcp_xmit_timer(tp, ts_rtt - 1);
1847 else if (tp->t_rtttime &&
1848 SEQ_GT(th->th_ack, tp->t_rtseq))
1849 tcp_xmit_timer(tp,
1850 tcp_now - tp->t_rtttime);
1851 acked = th->th_ack - tp->snd_una;
1858 nd_hint(tp);
1860 if (acked > (tp->t_lastoff - tp->t_inoff))
1861 tp->t_lastm = NULL;
1863 tp->t_lastoff -= acked;
1865 icmp_check(tp, th, acked);
1867 tp->snd_una = th->th_ack;
1868 tp->snd_fack = tp->snd_una;
1869 if (SEQ_LT(tp->snd_high, tp->snd_una))
1870 tp->snd_high = tp->snd_una;
1882 tp->snd_wl2 = tp->snd_una;
1895 if (tp->snd_una == tp->snd_max)
1896 TCP_TIMER_DISARM(tp, TCPT_REXMT);
1897 else if (TCP_TIMER_ISARMED(tp,
1899 TCP_TIMER_ARM(tp, TCPT_REXMT,
1900 tp->t_rxtcur);
1905 (void)tcp_output(tp);
1911 } else if (th->th_ack == tp->snd_una &&
1912 TAILQ_FIRST(&tp->segq) == NULL &&
1921 tp->rcv_nxt += tlen;
1927 tp->rcv_up = tp->rcv_nxt;
1933 tp->snd_wl1 = th->th_seq;
1940 nd_hint(tp);
1975 if (opti.ts_ecr > tp->rfbuf_ts &&
1976 opti.ts_ecr - tp->rfbuf_ts < PR_SLOWHZ) {
1977 if (tp->rfbuf_cnt >
1987 tp->rfbuf_ts = 0;
1988 tp->rfbuf_cnt = 0;
1990 tp->rfbuf_cnt += tlen; /* add up */
2012 tcp_setup_ack(tp, th);
2013 if (tp->t_flags & TF_ACKNOW) {
2015 (void)tcp_output(tp);
2038 tp->rcv_wnd = imax(win, (int)(tp->rcv_adv - tp->rcv_nxt));
2042 tp->rfbuf_ts = 0;
2043 tp->rfbuf_cnt = 0;
2045 switch (tp->t_state) {
2052 * initialize tp->rcv_nxt and tp->irs
2053 * if seg contains ack then advance tp->snd_una
2062 (SEQ_LEQ(th->th_ack, tp->iss) ||
2063 SEQ_GT(th->th_ack, tp->snd_max)))
2067 tp = tcp_drop(tp, ECONNREFUSED);
2073 tp->snd_una = th->th_ack;
2074 if (SEQ_LT(tp->snd_nxt, tp->snd_una))
2075 tp->snd_nxt = tp->snd_una;
2076 if (SEQ_LT(tp->snd_high, tp->snd_una))
2077 tp->snd_high = tp->snd_una;
2078 TCP_TIMER_DISARM(tp, TCPT_REXMT);
2081 tp->t_flags |= TF_ECN_PERMIT;
2085 tp->irs = th->th_seq;
2086 tcp_rcvseqinit(tp);
2087 tp->t_flags |= TF_ACKNOW;
2088 tcp_mss_from_peer(tp, opti.maxseg);
2095 if (tp->t_flags & TF_SYN_REXMT)
2096 tp->snd_cwnd = tp->t_peermss;
2105 tp->snd_cwnd = TCP_INITIAL_WINDOW(ss, tp->t_peermss);
2108 tcp_rmx_rtt(tp);
2118 tcp_established(tp);
2121 if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) ==
2123 tp->snd_scale = tp->requested_s_scale;
2124 tp->rcv_scale = tp->request_r_scale;
2126 TCP_REASS_LOCK(tp);
2127 (void)tcp_reass(tp, NULL, NULL, tlen);
2132 if (tp->t_rtttime)
2133 tcp_xmit_timer(tp, tcp_now - tp->t_rtttime);
2135 tp->t_state = TCPS_SYN_RECEIVED;
2144 if (tlen > tp->rcv_wnd) {
2145 todrop = tlen - tp->rcv_wnd;
2147 tlen = tp->rcv_wnd;
2155 tp->snd_wl1 = th->th_seq - 1;
2156 tp->rcv_up = th->th_seq;
2166 (SEQ_LEQ(th->th_ack, tp->iss) ||
2167 SEQ_GT(th->th_ack, tp->snd_max)))
2175 KASSERT(tp->t_state != TCPS_LISTEN &&
2176 tp->t_state != TCPS_SYN_SENT);
2182 if (opti.ts_present && (tiflags & TH_RST) == 0 && tp->ts_recent &&
2183 TSTMP_LT(opti.ts_val, tp->ts_recent)) {
2185 if (tcp_now - tp->ts_recent_age > TCP_PAWS_IDLE) {
2197 tp->ts_recent = 0;
2204 tcp_new_dsack(tp, th->th_seq, tlen);
2214 todrop = tp->rcv_nxt - th->th_seq;
2238 tp->t_flags |= TF_ACKNOW;
2245 } else if ((tiflags & TH_RST) && th->th_seq != tp->rcv_nxt) {
2258 tcp_new_dsack(tp, th->th_seq, todrop);
2270 tp->t_state > TCPS_CLOSE_WAIT && tlen) {
2271 tp = tcp_close(tp);
2280 todrop = (th->th_seq + tlen) - (tp->rcv_nxt + tp->rcv_wnd);
2286 * th->th_seq + tlen - tp->rcv_nxt - tp->rcv_wnd >= tlen
2287 * th->th_seq - tp->rcv_nxt - tp->rcv_wnd >= 0
2288 * th->th_seq >= tp->rcv_nxt + tp->rcv_wnd
2302 tp->t_state == TCPS_TIME_WAIT &&
2303 SEQ_GT(th->th_seq, tp->rcv_nxt)) {
2304 tp = tcp_close(tp);
2318 if (tp->rcv_wnd == 0 && th->th_seq == tp->rcv_nxt) {
2320 tp->t_flags |= TF_ACKNOW;
2352 SEQ_LEQ(th->th_seq, tp->last_ack_sent) &&
2353 SEQ_LEQ(tp->last_ack_sent, th->th_seq + tlen +
2355 tp->ts_recent_age = tcp_now;
2356 tp->ts_recent = opti.ts_val;
2370 if (th->th_seq != tp->rcv_nxt)
2373 switch (tp->t_state) {
2384 tp->t_state = TCPS_CLOSED;
2386 tp = tcp_close(tp);
2392 tp = tcp_close(tp);
2406 if (tp->rcv_nxt == th->th_seq) {
2407 tcp_respond(tp, m, m, th, (tcp_seq)0, th->th_ack - 1,
2420 if (tp->t_flags & TF_ACKNOW)
2429 switch (tp->t_state) {
2436 if (SEQ_GT(tp->snd_una, th->th_ack) ||
2437 SEQ_GT(th->th_ack, tp->snd_max))
2441 tcp_established(tp);
2443 if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) ==
2445 tp->snd_scale = tp->requested_s_scale;
2446 tp->rcv_scale = tp->request_r_scale;
2448 TCP_REASS_LOCK(tp);
2449 (void)tcp_reass(tp, NULL, NULL, tlen);
2450 tp->snd_wl1 = th->th_seq - 1;
2456 * tp->snd_una < th->th_ack <= tp->snd_max
2457 * then advance tp->snd_una to th->th_ack and drop
2468 if (SEQ_LEQ(th->th_ack, tp->snd_una)) {
2469 if (tlen == 0 && !dupseg && tiwin == tp->snd_wnd) {
2483 if (TCP_TIMER_ISARMED(tp, TCPT_REXMT) == 0 ||
2484 th->th_ack != tp->snd_una)
2485 tp->t_dupacks = 0;
2486 else if (tp->t_partialacks < 0 &&
2487 (++tp->t_dupacks == tcprexmtthresh ||
2488 TCP_FACK_FASTRECOV(tp))) {
2493 if (tp->t_congctl->fast_retransmit(tp, th)) {
2498 } else if (tp->t_dupacks > tcprexmtthresh) {
2499 tp->snd_cwnd += tp->t_segsz;
2501 (void)tcp_output(tp);
2514 if (tlen && th->th_seq != tp->rcv_nxt &&
2516 tp->snd_una - tp->max_sndwnd))
2525 tp->t_congctl->fast_retransmit_newack(tp, th);
2527 if (SEQ_GT(th->th_ack, tp->snd_max)) {
2531 acked = th->th_ack - tp->snd_una;
2547 tcp_xmit_timer(tp, ts_rtt - 1);
2548 else if (tp->t_rtttime && SEQ_GT(th->th_ack, tp->t_rtseq))
2549 tcp_xmit_timer(tp, tcp_now - tp->t_rtttime);
2557 if (th->th_ack == tp->snd_max) {
2558 TCP_TIMER_DISARM(tp, TCPT_REXMT);
2560 } else if (TCP_TIMER_ISARMED(tp, TCPT_PERSIST) == 0)
2561 TCP_TIMER_ARM(tp, TCPT_REXMT, tp->t_rxtcur);
2566 tp->t_congctl->newack(tp, th);
2568 nd_hint(tp);
2570 tp->snd_wnd -= so->so_snd.sb_cc;
2574 if (acked > (tp->t_lastoff - tp->t_inoff))
2575 tp->t_lastm = NULL;
2577 tp->t_lastoff -= acked;
2578 if (tp->snd_wnd > acked)
2579 tp->snd_wnd -= acked;
2581 tp->snd_wnd = 0;
2586 icmp_check(tp, th, acked);
2588 tp->snd_una = th->th_ack;
2589 if (SEQ_GT(tp->snd_una, tp->snd_fack))
2590 tp->snd_fack = tp->snd_una;
2591 if (SEQ_LT(tp->snd_nxt, tp->snd_una))
2592 tp->snd_nxt = tp->snd_una;
2593 if (SEQ_LT(tp->snd_high, tp->snd_una))
2594 tp->snd_high = tp->snd_una;
2596 switch (tp->t_state) {
2614 if (tp->t_maxidle > 0)
2615 TCP_TIMER_ARM(tp, TCPT_2MSL,
2616 tp->t_maxidle);
2618 tp->t_state = TCPS_FIN_WAIT_2;
2630 tp->t_state = TCPS_TIME_WAIT;
2631 tcp_canceltimers(tp);
2632 TCP_TIMER_ARM(tp, TCPT_2MSL, 2 * tp->t_msl);
2645 tp = tcp_close(tp);
2656 TCP_TIMER_ARM(tp, TCPT_2MSL, 2 * tp->t_msl);
2666 if ((tiflags & TH_ACK) && (SEQ_LT(tp->snd_wl1, th->th_seq) ||
2667 (tp->snd_wl1 == th->th_seq && (SEQ_LT(tp->snd_wl2, th->th_ack) ||
2668 (tp->snd_wl2 == th->th_ack && tiwin > tp->snd_wnd))))) {
2671 tp->snd_wl2 == th->th_ack && tiwin > tp->snd_wnd)
2673 tp->snd_wnd = tiwin;
2674 tp->snd_wl1 = th->th_seq;
2675 tp->snd_wl2 = th->th_ack;
2676 if (tp->snd_wnd > tp->max_sndwnd)
2677 tp->max_sndwnd = tp->snd_wnd;
2685 TCPS_HAVERCVDFIN(tp->t_state) == 0) {
2712 if (SEQ_GT(th->th_seq+th->th_urp, tp->rcv_up)) {
2713 tp->rcv_up = th->th_seq + th->th_urp;
2715 (tp->rcv_up - tp->rcv_nxt) - 1;
2719 tp->t_oobflags &= ~(TCPOOB_HAVEDATA | TCPOOB_HADDATA);
2737 if (SEQ_GT(tp->rcv_nxt, tp->rcv_up))
2738 tp->rcv_up = tp->rcv_nxt;
2745 * This process logically involves adjusting tp->rcv_wnd as data
2751 TCPS_HAVERCVDFIN(tp->t_state) == 0) {
2763 TCP_REASS_LOCK(tp);
2764 if (th->th_seq == tp->rcv_nxt &&
2765 TAILQ_FIRST(&tp->segq) == NULL &&
2766 tp->t_state == TCPS_ESTABLISHED) {
2767 tcp_setup_ack(tp, th);
2768 tp->rcv_nxt += tlen;
2774 nd_hint(tp);
2781 TCP_REASS_UNLOCK(tp);
2785 tiflags = tcp_reass(tp, th, m, tlen);
2786 tp->t_flags |= TF_ACKNOW;
2794 len = so->so_rcv.sb_hiwat - (tp->rcv_adv - tp->rcv_nxt);
2806 if ((tiflags & TH_FIN) && TCPS_HAVEESTABLISHED(tp->t_state)) {
2807 if (TCPS_HAVERCVDFIN(tp->t_state) == 0) {
2809 tp->t_flags |= TF_ACKNOW;
2810 tp->rcv_nxt++;
2812 switch (tp->t_state) {
2818 tp->t_state = TCPS_CLOSE_WAIT;
2826 tp->t_state = TCPS_CLOSING;
2835 tp->t_state = TCPS_TIME_WAIT;
2836 tcp_canceltimers(tp);
2837 TCP_TIMER_ARM(tp, TCPT_2MSL, 2 * tp->t_msl);
2845 TCP_TIMER_ARM(tp, TCPT_2MSL, 2 * tp->t_msl);
2851 tcp_trace(TA_INPUT, ostate, tp, tcp_saveti, 0);
2857 if (needoutput || (tp->t_flags & TF_ACKNOW)) {
2859 (void)tcp_output(tp);
2864 if (tp->t_state == TCPS_TIME_WAIT
2866 && (tp->t_inpcb || af != AF_INET || af != AF_INET6)
2868 && TAILQ_EMPTY(&tp->segq)
2869 && vtw_add(af, tp)) {
2879 tp = NULL;
2903 tp->t_flags |= TF_ACKNOW;
2905 (void)tcp_output(tp);
2931 (void)tcp_respond(tp, m, m, th, (tcp_seq)0, th->th_ack, TH_RST);
2935 (void)tcp_respond(tp, m, m, th, th->th_seq + tlen, (tcp_seq)0,
2946 if (tp) {
2947 so = tp->t_inpcb->inp_socket;
2950 tcp_trace(TA_DROP, ostate, tp, tcp_saveti, 0);
3086 tcp_dooptions(struct tcpcb *tp, const u_char *cp, int cnt, struct tcphdr *th,
3120 if (TCPS_HAVERCVDSYN(tp->t_state))
3131 if (TCPS_HAVERCVDSYN(tp->t_state))
3133 tp->t_flags |= TF_RCVD_SCALE;
3134 tp->requested_s_scale = cp[2];
3135 if (tp->requested_s_scale > TCP_MAX_WINSHIFT) {
3160 tp->requested_s_scale, buf,
3162 tp->requested_s_scale = TCP_MAX_WINSHIFT;
3177 if (TCPS_HAVERCVDSYN(tp->t_state))
3183 tp->t_flags |= TF_RCVD_TSTMP;
3184 tp->ts_recent = oi->ts_val;
3185 tp->ts_recent_age = tcp_now;
3193 if (TCPS_HAVERCVDSYN(tp->t_state))
3196 tp->t_flags |= TF_SACK_PERMIT;
3197 tp->t_flags |= TF_WILL_SACK;
3202 tcp_sack_option(tp, th, cp, optlen);
3214 tp->t_flags |= TF_SIGNATURE;
3223 if (tp->t_flags & TF_SIGNATURE) {
3225 if (sav == NULL && tp->t_state == TCPS_LISTEN)
3229 if ((sigp ? TF_SIGNATURE : 0) ^ (tp->t_flags & TF_SIGNATURE))
3274 struct tcpcb *tp = sototcpcb(so);
3276 tp->t_iobc = *cp;
3277 tp->t_oobflags |= TCPOOB_HAVEDATA;
3298 tcp_xmit_timer(struct tcpcb *tp, uint32_t rtt)
3303 if (tp->t_srtt != 0) {
3312 delta = (rtt << 2) - (tp->t_srtt >> TCP_RTT_SHIFT);
3319 if ((tp->t_srtt += delta) <= 0)
3320 tp->t_srtt = 1 << 2;
3337 delta -= (tp->t_rttvar >> TCP_RTTVAR_SHIFT);
3344 if ((tp->t_rttvar += delta) <= 0)
3345 tp->t_rttvar = 1 << 2;
3358 && tp->t_srtt > tcp_msl_remote_threshold
3359 && tp->t_msl < tcp_msl_remote) {
3360 tp->t_msl = MIN(tcp_msl_remote, TCP_MAXMSL);
3371 tp->t_srtt = rtt << (TCP_RTT_SHIFT + 2);
3372 tp->t_rttvar = rtt << (TCP_RTTVAR_SHIFT + 2 - 1);
3374 tp->t_rtttime = 0;
3375 tp->t_rxtshift = 0;
3388 TCPT_RANGESET(tp->t_rxtcur, TCP_REXMTVAL(tp),
3389 uimax(tp->t_rttmin, rtt + 2), TCPTV_REXMTMAX);
3398 tp->t_softerror = 0;