Lines Matching refs:tp

77 #define DELAY_ACK(tp, ti)                           \
79 tp->t_flags |= TF_ACKNOW; \
81 tp->t_flags |= TF_DELACK;
83 #define DELAY_ACK(tp, ign) \
84 tp->t_flags |= TF_DELACK;
94 tcp_reass(PNATState pData, struct tcpcb *tp, struct tcphdr *th, int *tlenp, struct mbuf *m)
100 struct socket *so = tp->t_socket;
103 LogFlowFunc(("ENTER: pData:%p, tp:%R[tcpcb793], th:%p, tlenp:%p, m:%p\n", pData, tp, th, tlenp, m));
128 if ( th->th_seq != tp->rcv_nxt
130 || tp->t_segqlen >= tcp_reass_maxqlen))
155 tp->t_segqlen++;
161 LIST_FOREACH(q, &tp->t_segq, tqe_q)
186 tp->t_segqlen--;
226 tp->t_segqlen--;
238 LIST_INSERT_HEAD(&tp->t_segq, te, tqe_q);
250 if (!TCPS_HAVEESTABLISHED(tp->t_state))
255 q = LIST_FIRST(&tp->t_segq);
256 if (!q || q->tqe_th->th_seq != tp->rcv_nxt)
263 tp->rcv_nxt += q->tqe_len;
275 tp->t_segqlen--;
279 while (q && q->tqe_th->th_seq == tp->rcv_nxt);
297 register struct tcpcb *tp = 0;
327 tp = sototcpcb(so);
344 tcp_close(pData, tp);
536 /* tp = sototcpcb(so); */
545 tp = sototcpcb(so);
546 TCP_STATE_SWITCH_TO(tp, TCPS_LISTEN);
560 tp = sototcpcb(so);
563 if (tp == 0)
568 if (tp->t_state == TCPS_CLOSED)
576 * tiwin = ti->ti_win << tp->snd_scale;
585 tp->t_idle = 0;
587 tp->t_timer[TCPT_KEEP] = tcp_keepintvl;
589 tp->t_timer[TCPT_KEEP] = tcp_keepidle;
595 if (optp && tp->t_state != TCPS_LISTEN)
596 tcp_dooptions(pData, tp, (u_char *)optp, optlen, ti);
615 * eg: the tiwin == tp->snd_wnd prevents many more
618 if ( tp->t_state == TCPS_ESTABLISHED
620 /* && (!ts_present || TSTMP_GEQ(ts_val, tp->ts_recent)) */
621 && ti->ti_seq == tp->rcv_nxt
622 && tiwin && tiwin == tp->snd_wnd
623 && tp->snd_nxt == tp->snd_max)
630 if (ts_present && SEQ_LEQ(ti->ti_seq, tp->last_ack_sent) &&
631 SEQ_LT(tp->last_ack_sent, ti->ti_seq + ti->ti_len))
633 tp->ts_recent_age = tcp_now;
634 tp->ts_recent = ts_val;
640 if ( SEQ_GT(ti->ti_ack, tp->snd_una)
641 && SEQ_LEQ(ti->ti_ack, tp->snd_max)
642 && tp->snd_cwnd >= tp->snd_wnd)
650 tcp_xmit_timer(tp, tcp_now-ts_ecr+1);
653 if ( tp->t_rtt
654 && SEQ_GT(ti->ti_ack, tp->t_rtseq))
655 tcp_xmit_timer(pData, tp, tp->t_rtt);
656 acked = ti->ti_ack - tp->snd_una;
660 tp->snd_una = ti->ti_ack;
672 if (tp->snd_una == tp->snd_max)
673 tp->t_timer[TCPT_REXMT] = 0;
674 else if (tp->t_timer[TCPT_PERSIST] == 0)
675 tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
691 (void) tcp_output(pData, tp);
698 else if ( ti->ti_ack == tp->snd_una
699 && LIST_FIRST(&tp->t_segq)
708 tp->rcv_nxt += ti->ti_len;
731 tp->t_flags |= TF_ACKNOW;
732 tcp_output(pData, tp);
749 tp->rcv_wnd = max(win, (int)(tp->rcv_adv - tp->rcv_nxt));
752 switch (tp->t_state)
759 * Otherwise initialize tp->rcv_nxt, and tp->irs, select an initial
760 * tp->iss, and send a segment:
762 * Also initialize tp->snd_nxt to tp->iss+1 and tp->snd_una to tp->iss.
798 tcp_respond(pData, tp, ti, m, ti->ti_seq+1, (tcp_seq)0,
813 tp->t_socket->so_m = NULL;
815 tp = tcp_close(pData, tp);
828 tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT;
829 TCP_STATE_SWITCH_TO(tp, TCPS_SYN_RECEIVED);
843 tp = tcp_close(pData, tp);
848 tcp_template(tp);
851 tcp_dooptions(pData, tp, (u_char *)optp, optlen, ti);
854 tp->iss = iss;
856 tp->iss = tcp_iss;
858 tp->irs = ti->ti_seq;
859 tcp_sendseqinit(tp);
860 tcp_rcvseqinit(tp);
861 tp->t_flags |= TF_ACKNOW;
862 TCP_STATE_SWITCH_TO(tp, TCPS_SYN_RECEIVED);
863 tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT;
875 * initialize tp->rcv_nxt and tp->irs
876 * if seg contains ack then advance tp->snd_una
883 && ( SEQ_LEQ(ti->ti_ack, tp->iss)
884 || SEQ_GT(ti->ti_ack, tp->snd_max)))
893 tp = tcp_drop(pData, tp, 0); /* XXX Check t_softerror! */
905 tp->snd_una = ti->ti_ack;
906 if (SEQ_LT(tp->snd_nxt, tp->snd_una))
907 tp->snd_nxt = tp->snd_una;
910 tp->t_timer[TCPT_REXMT] = 0;
911 tp->irs = ti->ti_seq;
912 tcp_rcvseqinit(tp);
913 tp->t_flags |= TF_ACKNOW;
914 if (tiflags & TH_ACK && SEQ_GT(tp->snd_una, tp->iss))
918 TCP_STATE_SWITCH_TO(tp, TCPS_ESTABLISHED);
922 if (( tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE))
925 tp->snd_scale = tp->requested_s_scale;
926 tp->rcv_scale = tp->request_r_scale;
929 (void) tcp_reass(pData, tp, (struct tcphdr *)0, NULL, (struct mbuf *)0);
934 if (tp->t_rtt)
935 tcp_xmit_timer(pData, tp, tp->t_rtt);
938 TCP_STATE_SWITCH_TO(tp, TCPS_SYN_RECEIVED);
948 if (ti->ti_len > tp->rcv_wnd)
950 todrop = ti->ti_len - tp->rcv_wnd;
952 ti->ti_len = tp->rcv_wnd;
957 tp->snd_wl1 = ti->ti_seq - 1;
958 tp->rcv_up = ti->ti_seq;
961 } /* switch tp->t_state */
975 && tp->ts_recent
976 && TSTMP_LT(ts_val, tp->ts_recent))
979 if ((int)(tcp_now - tp->ts_recent_age) > TCP_PAWS_IDLE)
992 tp->ts_recent = 0;
1004 todrop = tp->rcv_nxt - ti->ti_seq;
1035 tp->t_flags |= TF_ACKNOW;
1061 && tp->t_state > TCPS_CLOSE_WAIT && ti->ti_len)
1063 tp = tcp_close(pData, tp);
1073 todrop = (ti->ti_seq+ti->ti_len) - (tp->rcv_nxt+tp->rcv_wnd);
1087 && tp->t_state == TCPS_TIME_WAIT
1088 && SEQ_GT(ti->ti_seq, tp->rcv_nxt))
1090 iss = tp->rcv_nxt + TCP_ISSINCR;
1091 tp = tcp_close(pData, tp);
1092 SOCKET_UNLOCK(tp->t_socket);
1103 if (tp->rcv_wnd == 0 && ti->ti_seq == tp->rcv_nxt)
1105 tp->t_flags |= TF_ACKNOW;
1127 && SEQ_LEQ(ti->ti_seq, tp->last_ack_sent)
1128 && SEQ_LT(tp->last_ack_sent, ti->ti_seq + ti->ti_len + ((tiflags & (TH_SYN|TH_FIN)) != 0)))
1130 tp->ts_recent_age = tcp_now;
1131 tp->ts_recent = ts_val;
1146 switch (tp->t_state)
1160 TCP_STATE_SWITCH_TO(tp, TCPS_CLOSED);
1162 tp = tcp_close(pData, tp);
1169 tp = tcp_close(pData, tp);
1180 tp = tcp_drop(pData, tp, 0);
1197 switch (tp->t_state)
1206 if ( SEQ_GT(tp->snd_una, ti->ti_ack)
1207 || SEQ_GT(ti->ti_ack, tp->snd_max))
1210 TCP_STATE_SWITCH_TO(tp, TCPS_ESTABLISHED);
1216 * tp->snd_una++; or:
1218 tp->snd_una = ti->ti_ack;
1223 if ( (tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE))
1226 tp->snd_scale = tp->requested_s_scale;
1227 tp->rcv_scale = tp->request_r_scale;
1230 (void) tcp_reass(pData, tp, (struct tcphdr *)0, (int *)0, (struct mbuf *)0);
1231 tp->snd_wl1 = ti->ti_seq - 1;
1240 * tp->snd_una < ti->ti_ack <= tp->snd_max
1241 * then advance tp->snd_una to ti->ti_ack and drop
1254 if (SEQ_LEQ(ti->ti_ack, tp->snd_una))
1256 if (ti->ti_len == 0 && tiwin == tp->snd_wnd)
1284 if ( tp->t_timer[TCPT_REXMT] == 0
1285 || ti->ti_ack != tp->snd_una)
1286 tp->t_dupacks = 0;
1287 else if (++tp->t_dupacks == tcprexmtthresh)
1289 tcp_seq onxt = tp->snd_nxt;
1290 u_int win = min(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_maxseg;
1293 tp->snd_ssthresh = win * tp->t_maxseg;
1294 tp->t_timer[TCPT_REXMT] = 0;
1295 tp->t_rtt = 0;
1296 tp->snd_nxt = ti->ti_ack;
1297 tp->snd_cwnd = tp->t_maxseg;
1298 (void) tcp_output(pData, tp);
1299 tp->snd_cwnd = tp->snd_ssthresh +
1300 tp->t_maxseg * tp->t_dupacks;
1301 if (SEQ_GT(onxt, tp->snd_nxt))
1302 tp->snd_nxt = onxt;
1306 else if (tp->t_dupacks > tcprexmtthresh)
1308 tp->snd_cwnd += tp->t_maxseg;
1309 (void) tcp_output(pData, tp);
1315 tp->t_dupacks = 0;
1324 if ( tp->t_dupacks > tcprexmtthresh
1325 && tp->snd_cwnd > tp->snd_ssthresh)
1326 tp->snd_cwnd = tp->snd_ssthresh;
1327 tp->t_dupacks = 0;
1328 if (SEQ_GT(ti->ti_ack, tp->snd_max))
1334 acked = ti->ti_ack - tp->snd_una;
1349 tcp_xmit_timer(tp, tcp_now-ts_ecr+1);
1352 if (tp->t_rtt && SEQ_GT(ti->ti_ack, tp->t_rtseq))
1353 tcp_xmit_timer(pData, tp, tp->t_rtt);
1361 if (ti->ti_ack == tp->snd_max)
1363 tp->t_timer[TCPT_REXMT] = 0;
1366 else if (tp->t_timer[TCPT_PERSIST] == 0)
1367 tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
1376 register u_int cw = tp->snd_cwnd;
1377 register u_int incr = tp->t_maxseg;
1379 if (cw > tp->snd_ssthresh)
1381 tp->snd_cwnd = min(cw + incr, TCP_MAXWIN<<tp->snd_scale);
1385 tp->snd_wnd -= SBUF_LEN(&so->so_snd);
1392 tp->snd_wnd -= acked;
1403 tp->snd_una = ti->ti_ack;
1404 if (SEQ_LT(tp->snd_nxt, tp->snd_una))
1405 tp->snd_nxt = tp->snd_una;
1407 switch (tp->t_state)
1427 tp->t_timer[TCPT_2MSL] = tcp_maxidle;
1429 TCP_STATE_SWITCH_TO(tp, TCPS_FIN_WAIT_2);
1442 TCP_STATE_SWITCH_TO(tp, TCPS_TIME_WAIT);
1443 tcp_canceltimers(tp);
1444 tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL;
1458 tp = tcp_close(pData, tp);
1470 tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL;
1474 } /* switch(tp->t_state) */
1483 && ( SEQ_LT(tp->snd_wl1, ti->ti_seq)
1484 || ( tp->snd_wl1 == ti->ti_seq
1485 && ( SEQ_LT(tp->snd_wl2, ti->ti_ack)
1486 || ( tp->snd_wl2 == ti->ti_ack
1487 && tiwin > tp->snd_wnd)))))
1491 && tp->snd_wl2 == ti->ti_ack
1492 && tiwin > tp->snd_wnd)
1494 tp->snd_wnd = tiwin;
1495 tp->snd_wl1 = ti->ti_seq;
1496 tp->snd_wl2 = ti->ti_ack;
1497 if (tp->snd_wnd > tp->max_sndwnd)
1498 tp->max_sndwnd = tp->snd_wnd;
1506 TCPS_HAVERCVDFIN(tp->t_state) == 0)
1536 if (SEQ_GT(ti->ti_seq+ti->ti_urp, tp->rcv_up))
1538 tp->rcv_up = ti->ti_seq + ti->ti_urp;
1540 (tp->rcv_up - tp->rcv_nxt); /* -1; */
1541 tp->rcv_up = ti->ti_seq + ti->ti_urp;
1550 if (SEQ_GT(tp->rcv_nxt, tp->rcv_up))
1551 tp->rcv_up = tp->rcv_nxt;
1566 tp->t_flags |= TF_ACKNOW;
1572 * This process logically involves adjusting tp->rcv_wnd as data
1578 && TCPS_HAVERCVDFIN(tp->t_state) == 0)
1580 if ( ti->ti_seq == tp->rcv_nxt
1581 && LIST_EMPTY(&tp->t_segq)
1582 && tp->t_state == TCPS_ESTABLISHED)
1584 DELAY_ACK(tp, ti); /* little bit different from BSD declaration see netinet/tcp_input.c */
1585 tp->rcv_nxt += tlen;
1596 tiflags = tcp_reass(pData, tp, &ti->ti_t, &tlen, m);
1597 tp->t_flags |= TF_ACKNOW;
1604 len = SBUF_SIZE(&so->so_rcv) - (tp->rcv_adv - tp->rcv_nxt);
1618 if (TCPS_HAVERCVDFIN(tp->t_state) == 0)
1632 tp->t_flags |= TF_ACKNOW;
1633 tp->rcv_nxt++;
1635 switch (tp->t_state)
1643 TCP_STATE_SWITCH_TO(tp, TCPS_CLOSE_WAIT);
1651 TCP_STATE_SWITCH_TO(tp, TCPS_CLOSING);
1660 TCP_STATE_SWITCH_TO(tp, TCPS_TIME_WAIT);
1661 tcp_canceltimers(tp);
1662 tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL;
1670 tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL;
1678 if (needoutput || (tp->t_flags & TF_ACKNOW))
1679 tcp_output(pData, tp);
1698 tp->t_flags |= TF_ACKNOW;
1699 (void) tcp_output(pData, tp);
1709 tcp_respond(pData, tp, ti, m, (tcp_seq)0, ti->ti_ack, TH_RST);
1714 tcp_respond(pData, tp, ti, m, ti->ti_seq+ti->ti_len, (tcp_seq)0,
1747 struct tcpcb *tp;
1762 tp = sototcpcb(so);
1763 if (RT_UNLIKELY(tp == NULL)) /* should never happen */
1765 LogRel(("NAT: tp == NULL %R[natsock]\n", so));
1800 tcp_close(pData, tp);
1805 tcp_dooptions(PNATState pData, struct tcpcb *tp, u_char *cp, int cnt, struct tcpiphdr *ti)
1810 LogFlowFunc(("tcp_dooptions: tp = %R[tcpcb793], cnt=%i\n", tp, cnt));
1837 (void) tcp_mss(pData, tp, mss); /* sets t_maxseg */
1846 tp->t_flags |= TF_RCVD_SCALE;
1847 tp->requested_s_scale = min(cp[2], TCP_MAX_WINSHIFT);
1865 tp->t_flags |= TF_RCVD_TSTMP;
1866 tp->ts_recent = *ts_val;
1867 tp->ts_recent_age = tcp_now;
1894 struct tcpcb *tp = sototcpcb(so);
1896 tp->t_iobc = *cp;
1897 tp->t_oobflags |= TCPOOB_HAVEDATA;
1917 tcp_xmit_timer(PNATState pData, register struct tcpcb *tp, int rtt)
1921 LogFlowFunc(("ENTER: tcp_xmit_timer: tp = %R[tcpcb793] rtt = %d\n", tp, rtt));
1924 if (tp->t_srtt != 0)
1933 delta = rtt - 1 - (tp->t_srtt >> TCP_RTT_SHIFT);
1934 if ((tp->t_srtt += delta) <= 0)
1935 tp->t_srtt = 1;
1948 delta -= (tp->t_rttvar >> TCP_RTTVAR_SHIFT);
1949 if ((tp->t_rttvar += delta) <= 0)
1950 tp->t_rttvar = 1;
1959 tp->t_srtt = rtt << TCP_RTT_SHIFT;
1960 tp->t_rttvar = rtt << (TCP_RTTVAR_SHIFT - 1);
1962 tp->t_rtt = 0;
1963 tp->t_rxtshift = 0;
1976 TCPT_RANGESET(tp->t_rxtcur, TCP_REXMTVAL(tp),
1977 (short)tp->t_rttmin, TCPTV_REXMTMAX); /* XXX */
1986 tp->t_softerror = 0;
2006 tcp_mss(PNATState pData, register struct tcpcb *tp, u_int offer)
2008 struct socket *so = tp->t_socket;
2011 LogFlowFunc(("ENTER: tcp_mss: tp = %R[tcpcb793], offer = %d\n", tp, offer));
2017 if (mss < tp->t_maxseg || offer != 0)
2018 tp->t_maxseg = mss;
2020 tp->snd_cwnd = mss;