1 /* tcp_timer.c 4.18 82/03/24 */ 2 3 #include "../h/param.h" 4 #include "../h/systm.h" 5 #include "../h/mbuf.h" 6 #include "../h/socket.h" 7 #include "../h/socketvar.h" 8 #include "../h/protosw.h" 9 #include "../net/in.h" 10 #include "../net/in_pcb.h" 11 #include "../net/in_systm.h" 12 #include "../net/if.h" 13 #include "../net/ip.h" 14 #include "../net/ip_var.h" 15 #include "../net/tcp.h" 16 #include "../net/tcp_fsm.h" 17 #include "../net/tcp_seq.h" 18 #include "../net/tcp_timer.h" 19 #include "../net/tcp_var.h" 20 #include "../net/tcpip.h" 21 #include "../errno.h" 22 23 int tcpnodelack = 0; 24 /* 25 * Fast timeout routine for processing delayed acks 26 */ 27 tcp_fasttimo() 28 { 29 register struct inpcb *inp; 30 register struct tcpcb *tp; 31 int s = splnet(); 32 COUNT(TCP_FASTTIMO); 33 34 inp = tcb.inp_next; 35 if (inp) 36 for (; inp != &tcb; inp = inp->inp_next) 37 if ((tp = (struct tcpcb *)inp->inp_ppcb) && 38 (tp->t_flags & TF_DELACK)) { 39 tp->t_flags &= ~TF_DELACK; 40 tp->t_flags |= TF_ACKNOW; 41 (void) tcp_output(tp); 42 } 43 splx(s); 44 } 45 46 /* 47 * Tcp protocol timeout routine called every 500 ms. 48 * Updates the timers in all active tcb's and 49 * causes finite state machine actions if timers expire. 50 */ 51 tcp_slowtimo() 52 { 53 register struct inpcb *ip, *ipnxt; 54 register struct tcpcb *tp; 55 int s = splnet(); 56 register int i; 57 COUNT(TCP_SLOWTIMO); 58 59 /* 60 * Search through tcb's and update active timers. 61 */ 62 ip = tcb.inp_next; 63 if (ip == 0) { 64 splx(s); 65 return; 66 } 67 while (ip != &tcb) { 68 tp = intotcpcb(ip); 69 if (tp == 0) 70 continue; 71 ipnxt = ip->inp_next; 72 for (i = 0; i < TCPT_NTIMERS; i++) { 73 if (tp->t_timer[i] && --tp->t_timer[i] == 0) { 74 (void) tcp_usrreq(tp->t_inpcb->inp_socket, 75 PRU_SLOWTIMO, (struct mbuf *)0, 76 (caddr_t)i); 77 if (ipnxt->inp_prev != ip) 78 goto tpgone; 79 } 80 } 81 tp->t_idle++; 82 if (tp->t_rtt) 83 tp->t_rtt++; 84 tpgone: 85 ip = ipnxt; 86 } 87 tcp_iss += TCP_ISSINCR/PR_SLOWHZ; /* increment iss */ 88 splx(s); 89 } 90 91 /* 92 * Cancel all timers for TCP tp. 93 */ 94 tcp_canceltimers(tp) 95 struct tcpcb *tp; 96 { 97 register int i; 98 99 COUNT(TCP_CANCELTIMERS); 100 for (i = 0; i < TCPT_NTIMERS; i++) 101 tp->t_timer[i] = 0; 102 } 103 104 int tcprexmtprint; 105 /* 106 * TCP timer processing. 107 */ 108 tcp_timers(tp, timer) 109 register struct tcpcb *tp; 110 int timer; 111 { 112 113 COUNT(TCP_TIMERS); 114 switch (timer) { 115 116 /* 117 * 2 MSL timeout in shutdown went off. Delete connection 118 * control block. 119 */ 120 case TCPT_2MSL: 121 tcp_close(tp); 122 return; 123 124 /* 125 * Retransmission timer went off. Message has not 126 * been acked within retransmit interval. Back off 127 * to a longer retransmit interval and retransmit all 128 * unacknowledged messages in the window. 129 */ 130 case TCPT_REXMT: 131 tp->t_rxtshift++; 132 if (tp->t_rxtshift > TCP_MAXRXTSHIFT) { 133 tcp_drop(tp, ETIMEDOUT); 134 return; 135 } 136 TCPT_RANGESET(tp->t_timer[TCPT_REXMT], 137 (int)tp->t_srtt, TCPTV_MIN, TCPTV_MAX); 138 TCPT_RANGESET(tp->t_timer[TCPT_REXMT], 139 tp->t_timer[TCPT_REXMT] << tp->t_rxtshift, 140 TCPTV_MIN, TCPTV_MAX); 141 if (tcprexmtprint) 142 printf("rexmt set to %d\n", tp->t_timer[TCPT_REXMT]); 143 tp->snd_nxt = tp->snd_una; 144 /* this only transmits one segment! */ 145 (void) tcp_output(tp); 146 return; 147 148 /* 149 * Persistance timer into zero window. 150 * Force a byte to be output, if possible. 151 */ 152 case TCPT_PERSIST: 153 tp->t_force = 1; 154 (void) tcp_output(tp); 155 tp->t_force = 0; 156 TCPT_RANGESET(tp->t_timer[TCPT_PERSIST], 157 tcp_beta * tp->t_srtt, TCPTV_PERSMIN, TCPTV_MAX); 158 return; 159 160 /* 161 * Keep-alive timer went off; send something 162 * or drop connection if idle for too long. 163 */ 164 case TCPT_KEEP: 165 if (tp->t_state < TCPS_ESTABLISHED) 166 goto dropit; 167 if (tp->t_inpcb->inp_socket->so_options & SO_KEEPALIVE) { 168 if (tp->t_idle >= TCPTV_MAXIDLE) 169 goto dropit; 170 /* 171 * Saying tp->rcv_nxt-1 lies about what 172 * we have received, and by the protocol spec 173 * requires the correspondent TCP to respond. 174 * Saying tp->snd_una-1 causes the transmitted 175 * byte to lie outside the receive window; this 176 * is important because we don't necessarily 177 * have a byte in the window to send (consider 178 * a one-way stream!) 179 */ 180 tcp_respond(tp, 181 tp->t_template, tp->rcv_nxt-1, tp->snd_una-1, 0); 182 } else 183 tp->t_idle = 0; 184 tp->t_timer[TCPT_KEEP] = TCPTV_KEEP; 185 return; 186 dropit: 187 tcp_drop(tp, ETIMEDOUT); 188 return; 189 190 #ifdef TCPTRUEOOB 191 /* 192 * Out-of-band data retransmit timer. 193 */ 194 case TCPT_OOBREXMT: 195 if (tp->t_flags & TF_NOOPT) 196 return; 197 (void) tcp_output(tp); 198 TCPT_RANGESET(tp->t_timer[TCPT_OOBREXMT], 199 2 * tp->t_srtt, TCPTV_MIN, TCPTV_MAX); 200 return; 201 #endif 202 } 203 } 204