1*5165Swnj /* tcp_timer.c 4.5 81/12/02 */ 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" 105089Swnj #include "../net/in_pcb.h" 115089Swnj #include "../net/in_systm.h" 125069Swnj #include "../net/if.h" 135069Swnj #include "../net/ip.h" 145069Swnj #include "../net/ip_var.h" 155069Swnj #include "../net/tcp.h" 165069Swnj #include "../net/tcp_fsm.h" 175089Swnj #include "../net/tcp_seq.h" 185089Swnj #include "../net/tcp_timer.h" 195069Swnj #include "../net/tcp_var.h" 205089Swnj #include "../net/tcpip.h" 215112Swnj #include "../errno.h" 225069Swnj 235069Swnj /* 245069Swnj * Fast timeout routine for processing delayed acks 255069Swnj */ 265069Swnj tcp_fasttimo() 275069Swnj { 285069Swnj 295089Swnj COUNT(TCP_FASTTIMO); 305069Swnj } 315069Swnj 325069Swnj /* 335069Swnj * Tcp protocol timeout routine called every 500 ms. 345069Swnj * Updates the timers in all active tcb's and 355069Swnj * causes finite state machine actions if timers expire. 365069Swnj */ 375069Swnj tcp_slowtimo() 385069Swnj { 395069Swnj register struct inpcb *ip; 405069Swnj register struct tcpcb *tp; 415069Swnj int s = splnet(); 425069Swnj register int i; 435089Swnj COUNT(TCP_SLOWTIMO); 445069Swnj 455069Swnj /* 465069Swnj * Search through tcb's and update active timers. 475069Swnj */ 485069Swnj for (ip = tcb.inp_next; ip != &tcb; ip = ip->inp_next) { 495069Swnj tp = intotcpcb(ip); 505075Swnj for (i = 0; i < TCPT_NTIMERS; i++) { 515089Swnj if (tp->t_timer[i] && --tp->t_timer[i] == 0) 525069Swnj (void) tcp_usrreq(tp->t_inpcb->inp_socket, 535069Swnj PRU_SLOWTIMO, (struct mbuf *)0, 545069Swnj (caddr_t)i); 555069Swnj } 56*5165Swnj tp->t_idle++; 57*5165Swnj if (tp->t_rtt) 58*5165Swnj tp->t_rtt++; 595069Swnj } 605075Swnj tcp_iss += TCP_ISSINCR/PR_SLOWHZ; /* increment iss */ 615069Swnj splx(s); 625069Swnj } 635069Swnj 645069Swnj /* 655075Swnj * Cancel all timers for TCP tp. 665069Swnj */ 675089Swnj tcp_canceltimers(tp) 685069Swnj struct tcpcb *tp; 695069Swnj { 705069Swnj register int i; 715069Swnj 725089Swnj COUNT(TCP_CANCELTIMERS); 735075Swnj for (i = 0; i < TCPT_NTIMERS; i++) 745075Swnj tp->t_timer[i] = 0; 755069Swnj } 765069Swnj 775069Swnj /* 78*5165Swnj * TCP timer processing. 795069Swnj */ 805075Swnj tcp_timers(tp, timer) 815069Swnj register struct tcpcb *tp; 825075Swnj int timer; 835069Swnj { 845069Swnj 855069Swnj COUNT(TCP_TIMERS); 865089Swnj switch (timer) { 875069Swnj 88*5165Swnj /* 89*5165Swnj * 2 MSL timeout in shutdown went off. Delete connection 90*5165Swnj * control block. 91*5165Swnj */ 925075Swnj case TCPT_2MSL: 935075Swnj tcp_close(tp); 945075Swnj return; 955069Swnj 96*5165Swnj /* 97*5165Swnj * Retransmission timer went off. Message has not 98*5165Swnj * been acked within retransmit interval. Back off 99*5165Swnj * to a longer retransmit interval and retransmit all 100*5165Swnj * unacknowledged messages in the window. 101*5165Swnj */ 1025075Swnj case TCPT_REXMT: 103*5165Swnj tp->t_rxtshift++; 104*5165Swnj TCPT_RANGESET(tp->t_timer[TCPT_REXMT], 105*5165Swnj ((int)(2 * tp->t_srtt)) << tp->t_rxtshift, 106*5165Swnj TCPTV_MIN, TCPTV_MAX); 107*5165Swnj tp->snd_nxt = tp->snd_una; 108*5165Swnj /* this only transmits one segment! */ 109*5165Swnj (void) tcp_output(tp); 1105075Swnj return; 1115069Swnj 112*5165Swnj /* 113*5165Swnj * Persistance timer into zero window. 114*5165Swnj * Force a byte to be output, if possible. 115*5165Swnj */ 1165075Swnj case TCPT_PERSIST: 117*5165Swnj tp->t_force = 1; 118*5165Swnj (void) tcp_output(tp); 119*5165Swnj tp->t_force = 0; 120*5165Swnj TCPT_RANGESET(tp->t_timer[TCPT_PERSIST], 121*5165Swnj 2 * tp->t_srtt, TCPTV_PERSMIN, TCPTV_MAX); 1225089Swnj return; 1235069Swnj 124*5165Swnj /* 125*5165Swnj * Keep-alive timer went off; send something 126*5165Swnj * or drop connection if idle for too long. 127*5165Swnj */ 1285075Swnj case TCPT_KEEP: 129*5165Swnj if (tp->t_state < TCPS_ESTABLISHED || 130*5165Swnj tp->t_idle >= TCPTV_MAXIDLE) { 131*5165Swnj tcp_drop(tp, ETIMEDOUT); 132*5165Swnj return; 133*5165Swnj } 134*5165Swnj tcp_respond(tp->t_template, tp->rcv_nxt, tp->snd_una-1, 0); 135*5165Swnj tp->t_timer[TCPT_KEEP] = TCPTV_KEEP; 1365075Swnj return; 1375069Swnj } 1385069Swnj } 139