Lines Matching refs:tp

59  * control block tp.  Return TH_FIN if reassembly now includes
68 #define TCP_REASS(tp, ti, m, so, flags) {\
69 if ((ti)->ti_seq == (tp)->rcv_nxt && \
70 tcpfrag_list_empty(tp) && \
71 (tp)->t_state == TCPS_ESTABLISHED) {\
73 tp->t_flags |= TF_ACKNOW; \
75 tp->t_flags |= TF_DELACK; \
76 (tp)->rcv_nxt += (ti)->ti_len; \
86 (flags) = tcp_reass((tp), (ti), (m)); \
87 tp->t_flags |= TF_ACKNOW; \
91 #define TCP_REASS(tp, ti, m, so, flags) { \
92 if ((ti)->ti_seq == (tp)->rcv_nxt && \
93 tcpfrag_list_empty(tp) && \
94 (tp)->t_state == TCPS_ESTABLISHED) { \
95 tp->t_flags |= TF_DELACK; \
96 (tp)->rcv_nxt += (ti)->ti_len; \
106 (flags) = tcp_reass((tp), (ti), (m)); \
107 tp->t_flags |= TF_ACKNOW; \
111 static void tcp_dooptions(struct tcpcb *tp, u_char *cp, int cnt,
113 static void tcp_xmit_timer(register struct tcpcb *tp, int rtt);
116 tcp_reass(register struct tcpcb *tp, register struct tcpiphdr *ti,
120 struct socket *so = tp->t_socket;
133 for (q = tcpfrag_list_first(tp); !tcpfrag_list_end(q, tp);
143 if (!tcpfrag_list_end(tcpiphdr_prev(q), tp)) {
175 while (!tcpfrag_list_end(q, tp)) {
201 if (!TCPS_HAVEESTABLISHED(tp->t_state))
203 ti = tcpfrag_list_first(tp);
204 if (tcpfrag_list_end(ti, tp) || ti->ti_seq != tp->rcv_nxt)
206 if (tp->t_state == TCPS_SYN_RECEIVED && ti->ti_len)
209 tp->rcv_nxt += ti->ti_len;
223 } while (ti != (struct tcpiphdr *)tp && ti->ti_seq == tp->rcv_nxt);
240 register struct tcpcb *tp = NULL;
262 tp = sototcpcb(so);
419 /* tp = sototcpcb(so); */
429 tp = sototcpcb(so);
430 tp->t_state = TCPS_LISTEN;
441 tp = sototcpcb(so);
444 if (tp == NULL)
446 if (tp->t_state == TCPS_CLOSED)
451 * tiwin = ti->ti_win << tp->snd_scale;
460 tp->t_idle = 0;
462 tp->t_timer[TCPT_KEEP] = TCPTV_KEEPINTVL;
464 tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_IDLE;
470 if (optp && tp->t_state != TCPS_LISTEN)
471 tcp_dooptions(tp, (u_char *)optp, optlen, ti);
490 * eg: the tiwin == tp->snd_wnd prevents many more
493 if (tp->t_state == TCPS_ESTABLISHED &&
495 /* (!ts_present || TSTMP_GEQ(ts_val, tp->ts_recent)) && */
496 ti->ti_seq == tp->rcv_nxt &&
497 tiwin && tiwin == tp->snd_wnd &&
498 tp->snd_nxt == tp->snd_max) {
503 /* if (ts_present && SEQ_LEQ(ti->ti_seq, tp->last_ack_sent) &&
504 * SEQ_LT(tp->last_ack_sent, ti->ti_seq + ti->ti_len)) {
505 * tp->ts_recent_age = tcp_now;
506 * tp->ts_recent = ts_val;
510 if (SEQ_GT(ti->ti_ack, tp->snd_una) &&
511 SEQ_LEQ(ti->ti_ack, tp->snd_max) &&
512 tp->snd_cwnd >= tp->snd_wnd) {
518 * tcp_xmit_timer(tp, tcp_now-ts_ecr+1);
520 */ if (tp->t_rtt &&
521 SEQ_GT(ti->ti_ack, tp->t_rtseq))
522 tcp_xmit_timer(tp, tp->t_rtt);
523 acked = ti->ti_ack - tp->snd_una;
527 tp->snd_una = ti->ti_ack;
539 if (tp->snd_una == tp->snd_max)
540 tp->t_timer[TCPT_REXMT] = 0;
541 else if (tp->t_timer[TCPT_PERSIST] == 0)
542 tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
557 (void) tcp_output(tp);
561 } else if (ti->ti_ack == tp->snd_una &&
562 tcpfrag_list_empty(tp) &&
570 tp->rcv_nxt += ti->ti_len;
596 tp->t_flags |= TF_ACKNOW;
597 tcp_output(tp);
611 tp->rcv_wnd = max(win, (int)(tp->rcv_adv - tp->rcv_nxt));
614 switch (tp->t_state) {
621 * Otherwise initialize tp->rcv_nxt, and tp->irs, select an initial
622 * tp->iss, and send a segment:
624 * Also initialize tp->snd_nxt to tp->iss+1 and tp->snd_una to tp->iss.
683 tcp_respond(tp, ti, m, ti->ti_seq+1, (tcp_seq)0,
696 tp = tcp_close(tp);
707 tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT;
708 tp->t_state = TCPS_SYN_RECEIVED;
717 tp = tcp_close(tp);
721 tcp_template(tp);
724 tcp_dooptions(tp, (u_char *)optp, optlen, ti);
729 tp->iss = iss;
731 tp->iss = tcp_iss;
733 tp->irs = ti->ti_seq;
734 tcp_sendseqinit(tp);
735 tcp_rcvseqinit(tp);
736 tp->t_flags |= TF_ACKNOW;
737 tp->t_state = TCPS_SYN_RECEIVED;
738 tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT;
749 * initialize tp->rcv_nxt and tp->irs
750 * if seg contains ack then advance tp->snd_una
757 (SEQ_LEQ(ti->ti_ack, tp->iss) ||
758 SEQ_GT(ti->ti_ack, tp->snd_max)))
763 tp = tcp_drop(tp,0); /* XXX Check t_softerror! */
770 tp->snd_una = ti->ti_ack;
771 if (SEQ_LT(tp->snd_nxt, tp->snd_una))
772 tp->snd_nxt = tp->snd_una;
775 tp->t_timer[TCPT_REXMT] = 0;
776 tp->irs = ti->ti_seq;
777 tcp_rcvseqinit(tp);
778 tp->t_flags |= TF_ACKNOW;
779 if (tiflags & TH_ACK && SEQ_GT(tp->snd_una, tp->iss)) {
782 tp->t_state = TCPS_ESTABLISHED;
785 /* if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) ==
787 * tp->snd_scale = tp->requested_s_scale;
788 * tp->rcv_scale = tp->request_r_scale;
791 (void) tcp_reass(tp, (struct tcpiphdr *)0,
797 if (tp->t_rtt)
798 tcp_xmit_timer(tp, tp->t_rtt);
800 tp->t_state = TCPS_SYN_RECEIVED;
809 if (ti->ti_len > tp->rcv_wnd) {
810 todrop = ti->ti_len - tp->rcv_wnd;
812 ti->ti_len = tp->rcv_wnd;
817 tp->snd_wl1 = ti->ti_seq - 1;
818 tp->rcv_up = ti->ti_seq;
820 } /* switch tp->t_state */
831 /* if (ts_present && (tiflags & TH_RST) == 0 && tp->ts_recent &&
832 * TSTMP_LT(ts_val, tp->ts_recent)) {
835 /* if ((int)(tcp_now - tp->ts_recent_age) > TCP_PAWS_IDLE) {
847 /* tp->ts_recent = 0;
857 todrop = tp->rcv_nxt - ti->ti_seq;
884 tp->t_flags |= TF_ACKNOW;
907 tp->t_state > TCPS_CLOSE_WAIT && ti->ti_len) {
908 tp = tcp_close(tp);
917 todrop = (ti->ti_seq+ti->ti_len) - (tp->rcv_nxt+tp->rcv_wnd);
929 tp->t_state == TCPS_TIME_WAIT &&
930 SEQ_GT(ti->ti_seq, tp->rcv_nxt)) {
931 iss = tp->rcv_nxt + TCP_ISSINCR;
932 tp = tcp_close(tp);
942 if (tp->rcv_wnd == 0 && ti->ti_seq == tp->rcv_nxt) {
943 tp->t_flags |= TF_ACKNOW;
958 /* if (ts_present && SEQ_LEQ(ti->ti_seq, tp->last_ack_sent) &&
959 * SEQ_LT(tp->last_ack_sent, ti->ti_seq + ti->ti_len +
961 * tp->ts_recent_age = tcp_now;
962 * tp->ts_recent = ts_val;
976 if (tiflags&TH_RST) switch (tp->t_state) {
988 tp->t_state = TCPS_CLOSED;
990 tp = tcp_close(tp);
996 tp = tcp_close(tp);
1005 tp = tcp_drop(tp,0);
1017 switch (tp->t_state) {
1025 if (SEQ_GT(tp->snd_una, ti->ti_ack) ||
1026 SEQ_GT(ti->ti_ack, tp->snd_max))
1029 tp->t_state = TCPS_ESTABLISHED;
1035 * tp->snd_una++; or:
1037 tp->snd_una=ti->ti_ack;
1048 tp->t_state = TCPS_FIN_WAIT_1;
1055 /* if ((tp->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) ==
1057 * tp->snd_scale = tp->requested_s_scale;
1058 * tp->rcv_scale = tp->request_r_scale;
1061 (void) tcp_reass(tp, (struct tcpiphdr *)0, (struct mbuf *)0);
1062 tp->snd_wl1 = ti->ti_seq - 1;
1070 * tp->snd_una < ti->ti_ack <= tp->snd_max
1071 * then advance tp->snd_una to ti->ti_ack and drop
1083 if (SEQ_LEQ(ti->ti_ack, tp->snd_una)) {
1084 if (ti->ti_len == 0 && tiwin == tp->snd_wnd) {
1112 if (tp->t_timer[TCPT_REXMT] == 0 ||
1113 ti->ti_ack != tp->snd_una)
1114 tp->t_dupacks = 0;
1115 else if (++tp->t_dupacks == TCPREXMTTHRESH) {
1116 tcp_seq onxt = tp->snd_nxt;
1118 min(tp->snd_wnd, tp->snd_cwnd) / 2 /
1119 tp->t_maxseg;
1123 tp->snd_ssthresh = win * tp->t_maxseg;
1124 tp->t_timer[TCPT_REXMT] = 0;
1125 tp->t_rtt = 0;
1126 tp->snd_nxt = ti->ti_ack;
1127 tp->snd_cwnd = tp->t_maxseg;
1128 (void) tcp_output(tp);
1129 tp->snd_cwnd = tp->snd_ssthresh +
1130 tp->t_maxseg * tp->t_dupacks;
1131 if (SEQ_GT(onxt, tp->snd_nxt))
1132 tp->snd_nxt = onxt;
1134 } else if (tp->t_dupacks > TCPREXMTTHRESH) {
1135 tp->snd_cwnd += tp->t_maxseg;
1136 (void) tcp_output(tp);
1140 tp->t_dupacks = 0;
1148 if (tp->t_dupacks > TCPREXMTTHRESH &&
1149 tp->snd_cwnd > tp->snd_ssthresh)
1150 tp->snd_cwnd = tp->snd_ssthresh;
1151 tp->t_dupacks = 0;
1152 if (SEQ_GT(ti->ti_ack, tp->snd_max)) {
1156 acked = ti->ti_ack - tp->snd_una;
1170 * tcp_xmit_timer(tp, tcp_now-ts_ecr+1);
1173 if (tp->t_rtt && SEQ_GT(ti->ti_ack, tp->t_rtseq))
1174 tcp_xmit_timer(tp,tp->t_rtt);
1182 if (ti->ti_ack == tp->snd_max) {
1183 tp->t_timer[TCPT_REXMT] = 0;
1185 } else if (tp->t_timer[TCPT_PERSIST] == 0)
1186 tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
1195 register u_int cw = tp->snd_cwnd;
1196 register u_int incr = tp->t_maxseg;
1198 if (cw > tp->snd_ssthresh)
1200 tp->snd_cwnd = min(cw + incr, TCP_MAXWIN<<tp->snd_scale);
1203 tp->snd_wnd -= so->so_snd.sb_cc;
1208 tp->snd_wnd -= acked;
1218 tp->snd_una = ti->ti_ack;
1219 if (SEQ_LT(tp->snd_nxt, tp->snd_una))
1220 tp->snd_nxt = tp->snd_una;
1222 switch (tp->t_state) {
1240 tp->t_timer[TCPT_2MSL] = TCP_MAXIDLE;
1242 tp->t_state = TCPS_FIN_WAIT_2;
1254 tp->t_state = TCPS_TIME_WAIT;
1255 tcp_canceltimers(tp);
1256 tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL;
1269 tp = tcp_close(tp);
1280 tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL;
1283 } /* switch(tp->t_state) */
1291 (SEQ_LT(tp->snd_wl1, ti->ti_seq) ||
1292 (tp->snd_wl1 == ti->ti_seq && (SEQ_LT(tp->snd_wl2, ti->ti_ack) ||
1293 (tp->snd_wl2 == ti->ti_ack && tiwin > tp->snd_wnd))))) {
1296 tp->snd_wl2 == ti->ti_ack && tiwin > tp->snd_wnd)
1298 tp->snd_wnd = tiwin;
1299 tp->snd_wl1 = ti->ti_seq;
1300 tp->snd_wl2 = ti->ti_ack;
1301 if (tp->snd_wnd > tp->max_sndwnd)
1302 tp->max_sndwnd = tp->snd_wnd;
1310 TCPS_HAVERCVDFIN(tp->t_state) == 0) {
1336 if (SEQ_GT(ti->ti_seq+ti->ti_urp, tp->rcv_up)) {
1337 tp->rcv_up = ti->ti_seq + ti->ti_urp;
1339 (tp->rcv_up - tp->rcv_nxt); /* -1; */
1340 tp->rcv_up = ti->ti_seq + ti->ti_urp;
1349 if (SEQ_GT(tp->rcv_nxt, tp->rcv_up))
1350 tp->rcv_up = tp->rcv_nxt;
1356 * This process logically involves adjusting tp->rcv_wnd as data
1362 TCPS_HAVERCVDFIN(tp->t_state) == 0) {
1363 TCP_REASS(tp, ti, m, so, tiflags);
1369 len = so->so_rcv.sb_datalen - (tp->rcv_adv - tp->rcv_nxt);
1380 if (TCPS_HAVERCVDFIN(tp->t_state) == 0) {
1393 tp->t_flags |= TF_ACKNOW;
1394 tp->rcv_nxt++;
1396 switch (tp->t_state) {
1405 tp->t_state = TCPS_LAST_ACK;
1407 tp->t_state = TCPS_CLOSE_WAIT;
1415 tp->t_state = TCPS_CLOSING;
1424 tp->t_state = TCPS_TIME_WAIT;
1425 tcp_canceltimers(tp);
1426 tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL;
1434 tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL;
1446 /* if (ti->ti_len && (unsigned)ti->ti_len < tp->t_maxseg) {
1448 /* if ((ti->ti_len && (unsigned)ti->ti_len < tp->t_maxseg &&
1455 tp->t_flags |= TF_ACKNOW;
1461 if (needoutput || (tp->t_flags & TF_ACKNOW)) {
1462 (void) tcp_output(tp);
1474 tp->t_flags |= TF_ACKNOW;
1475 (void) tcp_output(tp);
1481 tcp_respond(tp, ti, m, (tcp_seq)0, ti->ti_ack, TH_RST);
1484 tcp_respond(tp, ti, m, ti->ti_seq+ti->ti_len, (tcp_seq)0,
1504 tcp_dooptions(struct tcpcb *tp, u_char *cp, int cnt, struct tcpiphdr *ti)
1510 DEBUG_ARGS((dfd," tp = %lx cnt=%i \n", (long )tp, cnt));
1535 (void) tcp_mss(tp, mss); /* sets t_maxseg */
1543 * tp->t_flags |= TF_RCVD_SCALE;
1544 * tp->requested_s_scale = min(cp[2], TCP_MAX_WINSHIFT);
1561 * tp->t_flags |= TF_RCVD_TSTMP;
1562 * tp->ts_recent = *ts_val;
1563 * tp->ts_recent_age = tcp_now;
1591 struct tcpcb *tp = sototcpcb(so);
1593 tp->t_iobc = *cp;
1594 tp->t_oobflags |= TCPOOB_HAVEDATA;
1615 tcp_xmit_timer(register struct tcpcb *tp, int rtt)
1620 DEBUG_ARG("tp = %lx", (long)tp);
1624 if (tp->t_srtt != 0) {
1632 delta = rtt - 1 - (tp->t_srtt >> TCP_RTT_SHIFT);
1633 if ((tp->t_srtt += delta) <= 0)
1634 tp->t_srtt = 1;
1647 delta -= (tp->t_rttvar >> TCP_RTTVAR_SHIFT);
1648 if ((tp->t_rttvar += delta) <= 0)
1649 tp->t_rttvar = 1;
1656 tp->t_srtt = rtt << TCP_RTT_SHIFT;
1657 tp->t_rttvar = rtt << (TCP_RTTVAR_SHIFT - 1);
1659 tp->t_rtt = 0;
1660 tp->t_rxtshift = 0;
1673 TCPT_RANGESET(tp->t_rxtcur, TCP_REXMTVAL(tp),
1674 (short)tp->t_rttmin, TCPTV_REXMTMAX); /* XXX */
1683 tp->t_softerror = 0;
1703 tcp_mss(struct tcpcb *tp, u_int offer)
1705 struct socket *so = tp->t_socket;
1709 DEBUG_ARG("tp = %lx", (long)tp);
1716 if (mss < tp->t_maxseg || offer != 0)
1717 tp->t_maxseg = mss;
1719 tp->snd_cwnd = mss;