1*6353Ssam /* tcp_timer.c 4.19 82/03/29 */ 25069Swnj 35069Swnj #include "../h/param.h" 45069Swnj #include "../h/systm.h" 55069Swnj #include "../h/mbuf.h" 65069Swnj #include "../h/socket.h" 75069Swnj #include "../h/socketvar.h" 85069Swnj #include "../h/protosw.h" 95089Swnj #include "../net/in.h" 10*6353Ssam #include "../net/route.h" 115089Swnj #include "../net/in_pcb.h" 125089Swnj #include "../net/in_systm.h" 135069Swnj #include "../net/if.h" 145069Swnj #include "../net/ip.h" 155069Swnj #include "../net/ip_var.h" 165069Swnj #include "../net/tcp.h" 175069Swnj #include "../net/tcp_fsm.h" 185089Swnj #include "../net/tcp_seq.h" 195089Swnj #include "../net/tcp_timer.h" 205069Swnj #include "../net/tcp_var.h" 215089Swnj #include "../net/tcpip.h" 225112Swnj #include "../errno.h" 235069Swnj 245442Swnj int tcpnodelack = 0; 255069Swnj /* 265069Swnj * Fast timeout routine for processing delayed acks 275069Swnj */ 285069Swnj tcp_fasttimo() 295069Swnj { 305284Sroot register struct inpcb *inp; 315284Sroot register struct tcpcb *tp; 325284Sroot int s = splnet(); 335284Sroot COUNT(TCP_FASTTIMO); 345069Swnj 355691Swnj inp = tcb.inp_next; 365691Swnj if (inp) 375691Swnj for (; inp != &tcb; inp = inp->inp_next) 385284Sroot if ((tp = (struct tcpcb *)inp->inp_ppcb) && 395284Sroot (tp->t_flags & TF_DELACK)) { 405284Sroot tp->t_flags &= ~TF_DELACK; 415284Sroot tp->t_flags |= TF_ACKNOW; 425284Sroot (void) tcp_output(tp); 435284Sroot } 445284Sroot splx(s); 455069Swnj } 465069Swnj 475069Swnj /* 485069Swnj * Tcp protocol timeout routine called every 500 ms. 495069Swnj * Updates the timers in all active tcb's and 505069Swnj * causes finite state machine actions if timers expire. 515069Swnj */ 525069Swnj tcp_slowtimo() 535069Swnj { 546212Swnj register struct inpcb *ip, *ipnxt; 555069Swnj register struct tcpcb *tp; 565069Swnj int s = splnet(); 575069Swnj register int i; 585089Swnj COUNT(TCP_SLOWTIMO); 595069Swnj 605069Swnj /* 615069Swnj * Search through tcb's and update active timers. 625069Swnj */ 635245Sroot ip = tcb.inp_next; 645245Sroot if (ip == 0) { 655245Sroot splx(s); 665245Sroot return; 675245Sroot } 686212Swnj while (ip != &tcb) { 695069Swnj tp = intotcpcb(ip); 705260Swnj if (tp == 0) 715260Swnj continue; 726212Swnj ipnxt = ip->inp_next; 735075Swnj for (i = 0; i < TCPT_NTIMERS; i++) { 746212Swnj if (tp->t_timer[i] && --tp->t_timer[i] == 0) { 755069Swnj (void) tcp_usrreq(tp->t_inpcb->inp_socket, 765069Swnj PRU_SLOWTIMO, (struct mbuf *)0, 775069Swnj (caddr_t)i); 786212Swnj if (ipnxt->inp_prev != ip) 796212Swnj goto tpgone; 806212Swnj } 815069Swnj } 825165Swnj tp->t_idle++; 835165Swnj if (tp->t_rtt) 845165Swnj tp->t_rtt++; 856212Swnj tpgone: 866212Swnj ip = ipnxt; 875069Swnj } 885075Swnj tcp_iss += TCP_ISSINCR/PR_SLOWHZ; /* increment iss */ 895069Swnj splx(s); 905069Swnj } 915069Swnj 925069Swnj /* 935075Swnj * Cancel all timers for TCP tp. 945069Swnj */ 955089Swnj tcp_canceltimers(tp) 965069Swnj struct tcpcb *tp; 975069Swnj { 985069Swnj register int i; 995069Swnj 1005089Swnj COUNT(TCP_CANCELTIMERS); 1015075Swnj for (i = 0; i < TCPT_NTIMERS; i++) 1025075Swnj tp->t_timer[i] = 0; 1035069Swnj } 1045069Swnj 1055952Swnj int tcprexmtprint; 1065069Swnj /* 1075165Swnj * TCP timer processing. 1085069Swnj */ 1095075Swnj tcp_timers(tp, timer) 1105069Swnj register struct tcpcb *tp; 1115075Swnj int timer; 1125069Swnj { 1135069Swnj 1145069Swnj COUNT(TCP_TIMERS); 1155089Swnj switch (timer) { 1165069Swnj 1175165Swnj /* 1185165Swnj * 2 MSL timeout in shutdown went off. Delete connection 1195165Swnj * control block. 1205165Swnj */ 1215075Swnj case TCPT_2MSL: 1225075Swnj tcp_close(tp); 1235075Swnj return; 1245069Swnj 1255165Swnj /* 1265165Swnj * Retransmission timer went off. Message has not 1275165Swnj * been acked within retransmit interval. Back off 1285165Swnj * to a longer retransmit interval and retransmit all 1295165Swnj * unacknowledged messages in the window. 1305165Swnj */ 1315075Swnj case TCPT_REXMT: 1325165Swnj tp->t_rxtshift++; 1335691Swnj if (tp->t_rxtshift > TCP_MAXRXTSHIFT) { 1345691Swnj tcp_drop(tp, ETIMEDOUT); 1355691Swnj return; 1365691Swnj } 1375165Swnj TCPT_RANGESET(tp->t_timer[TCPT_REXMT], 1385952Swnj (int)tp->t_srtt, TCPTV_MIN, TCPTV_MAX); 1395284Sroot TCPT_RANGESET(tp->t_timer[TCPT_REXMT], 1405284Sroot tp->t_timer[TCPT_REXMT] << tp->t_rxtshift, 1415284Sroot TCPTV_MIN, TCPTV_MAX); 1425952Swnj if (tcprexmtprint) 1435952Swnj printf("rexmt set to %d\n", tp->t_timer[TCPT_REXMT]); 1445165Swnj tp->snd_nxt = tp->snd_una; 1455165Swnj /* this only transmits one segment! */ 1465165Swnj (void) tcp_output(tp); 1475075Swnj return; 1485069Swnj 1495165Swnj /* 1505165Swnj * Persistance timer into zero window. 1515165Swnj * Force a byte to be output, if possible. 1525165Swnj */ 1535075Swnj case TCPT_PERSIST: 1545165Swnj tp->t_force = 1; 1555165Swnj (void) tcp_output(tp); 1565165Swnj tp->t_force = 0; 1575165Swnj TCPT_RANGESET(tp->t_timer[TCPT_PERSIST], 1585952Swnj tcp_beta * tp->t_srtt, TCPTV_PERSMIN, TCPTV_MAX); 1595089Swnj return; 1605069Swnj 1615165Swnj /* 1625165Swnj * Keep-alive timer went off; send something 1635165Swnj * or drop connection if idle for too long. 1645165Swnj */ 1655075Swnj case TCPT_KEEP: 1666304Sroot if (tp->t_state < TCPS_ESTABLISHED) 1676304Sroot goto dropit; 1686267Sroot if (tp->t_inpcb->inp_socket->so_options & SO_KEEPALIVE) { 1696304Sroot if (tp->t_idle >= TCPTV_MAXIDLE) 1706304Sroot goto dropit; 1716267Sroot /* 1726267Sroot * Saying tp->rcv_nxt-1 lies about what 1736267Sroot * we have received, and by the protocol spec 1746267Sroot * requires the correspondent TCP to respond. 1756267Sroot * Saying tp->snd_una-1 causes the transmitted 1766267Sroot * byte to lie outside the receive window; this 1776267Sroot * is important because we don't necessarily 1786267Sroot * have a byte in the window to send (consider 1796267Sroot * a one-way stream!) 1806267Sroot */ 1815392Swnj tcp_respond(tp, 1826267Sroot tp->t_template, tp->rcv_nxt-1, tp->snd_una-1, 0); 1836267Sroot } else 1846212Swnj tp->t_idle = 0; 1855165Swnj tp->t_timer[TCPT_KEEP] = TCPTV_KEEP; 1865075Swnj return; 1876304Sroot dropit: 1886304Sroot tcp_drop(tp, ETIMEDOUT); 1896304Sroot return; 1905442Swnj 1915442Swnj #ifdef TCPTRUEOOB 1925442Swnj /* 1935442Swnj * Out-of-band data retransmit timer. 1945442Swnj */ 1955442Swnj case TCPT_OOBREXMT: 1965442Swnj if (tp->t_flags & TF_NOOPT) 1975442Swnj return; 1985442Swnj (void) tcp_output(tp); 1995442Swnj TCPT_RANGESET(tp->t_timer[TCPT_OOBREXMT], 2005442Swnj 2 * tp->t_srtt, TCPTV_MIN, TCPTV_MAX); 2015442Swnj return; 2025442Swnj #endif 2035069Swnj } 2045069Swnj } 205