1 /* tcp_timer.c 4.29 83/01/04 */ 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 <errno.h> 10 11 #include "../net/if.h" 12 #include "../net/route.h" 13 #include "../netinet/in.h" 14 #include "../netinet/in_pcb.h" 15 #include "../netinet/in_systm.h" 16 #include "../netinet/ip.h" 17 #include "../netinet/ip_var.h" 18 #include "../netinet/tcp.h" 19 #include "../netinet/tcp_fsm.h" 20 #include "../netinet/tcp_seq.h" 21 #include "../netinet/tcp_timer.h" 22 #include "../netinet/tcp_var.h" 23 #include "../netinet/tcpip.h" 24 25 int tcpnodelack = 0; 26 /* 27 * Fast timeout routine for processing delayed acks 28 */ 29 tcp_fasttimo() 30 { 31 register struct inpcb *inp; 32 register struct tcpcb *tp; 33 int s = splnet(); 34 35 inp = tcb.inp_next; 36 if (inp) 37 for (; inp != &tcb; inp = inp->inp_next) 38 if ((tp = (struct tcpcb *)inp->inp_ppcb) && 39 (tp->t_flags & TF_DELACK)) { 40 tp->t_flags &= ~TF_DELACK; 41 tp->t_flags |= TF_ACKNOW; 42 (void) tcp_output(tp); 43 } 44 splx(s); 45 } 46 47 /* 48 * Tcp protocol timeout routine called every 500 ms. 49 * Updates the timers in all active tcb's and 50 * causes finite state machine actions if timers expire. 51 */ 52 tcp_slowtimo() 53 { 54 register struct inpcb *ip, *ipnxt; 55 register struct tcpcb *tp; 56 int s = splnet(); 57 register int i; 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 (struct mbuf *)i, 77 (struct socketopt *)0); 78 if (ipnxt->inp_prev != ip) 79 goto tpgone; 80 } 81 } 82 tp->t_idle++; 83 if (tp->t_rtt) 84 tp->t_rtt++; 85 tpgone: 86 ip = ipnxt; 87 } 88 tcp_iss += TCP_ISSINCR/PR_SLOWHZ; /* increment iss */ 89 splx(s); 90 } 91 92 /* 93 * Cancel all timers for TCP tp. 94 */ 95 tcp_canceltimers(tp) 96 struct tcpcb *tp; 97 { 98 register int i; 99 100 for (i = 0; i < TCPT_NTIMERS; i++) 101 tp->t_timer[i] = 0; 102 } 103 104 float tcp_backoff[TCP_MAXRXTSHIFT] = 105 { 1.0, 1.2, 1.4, 1.7, 2.0, 3.0, 5.0, 8.0, 16.0, 32.0 }; 106 int tcpexprexmtbackoff = 0; 107 /* 108 * TCP timer processing. 109 */ 110 tcp_timers(tp, timer) 111 register struct tcpcb *tp; 112 int timer; 113 { 114 115 switch (timer) { 116 117 /* 118 * 2 MSL timeout in shutdown went off. Delete connection 119 * control block. 120 */ 121 case TCPT_2MSL: 122 tcp_close(tp); 123 return; 124 125 /* 126 * Retransmission timer went off. Message has not 127 * been acked within retransmit interval. Back off 128 * to a longer retransmit interval and retransmit all 129 * unacknowledged messages in the window. 130 */ 131 case TCPT_REXMT: 132 tp->t_rxtshift++; 133 if (tp->t_rxtshift > TCP_MAXRXTSHIFT) { 134 tcp_drop(tp, ETIMEDOUT); 135 return; 136 } 137 TCPT_RANGESET(tp->t_timer[TCPT_REXMT], 138 (int)tp->t_srtt, TCPTV_MIN, TCPTV_MAX); 139 if (tcpexprexmtbackoff) { 140 TCPT_RANGESET(tp->t_timer[TCPT_REXMT], 141 tp->t_timer[TCPT_REXMT] << tp->t_rxtshift, 142 TCPTV_MIN, TCPTV_MAX); 143 } else { 144 TCPT_RANGESET(tp->t_timer[TCPT_REXMT], 145 tp->t_timer[TCPT_REXMT] * 146 tcp_backoff[tp->t_rxtshift - 1], 147 TCPTV_MIN, TCPTV_MAX); 148 } 149 tp->snd_nxt = tp->snd_una; 150 /* this only transmits one segment! */ 151 (void) tcp_output(tp); 152 return; 153 154 /* 155 * Persistance timer into zero window. 156 * Force a byte to be output, if possible. 157 */ 158 case TCPT_PERSIST: 159 tcp_setpersist(tp); 160 tp->t_force = 1; 161 (void) tcp_output(tp); 162 tp->t_force = 0; 163 return; 164 165 /* 166 * Keep-alive timer went off; send something 167 * or drop connection if idle for too long. 168 */ 169 case TCPT_KEEP: 170 if (tp->t_state < TCPS_ESTABLISHED) 171 goto dropit; 172 if (tp->t_inpcb->inp_socket->so_options & SO_KEEPALIVE) { 173 if (tp->t_idle >= TCPTV_MAXIDLE) 174 goto dropit; 175 /* 176 * Saying tp->rcv_nxt-1 lies about what 177 * we have received, and by the protocol spec 178 * requires the correspondent TCP to respond. 179 * Saying tp->snd_una-1 causes the transmitted 180 * byte to lie outside the receive window; this 181 * is important because we don't necessarily 182 * have a byte in the window to send (consider 183 * a one-way stream!) 184 */ 185 tcp_respond(tp, 186 tp->t_template, tp->rcv_nxt-1, tp->snd_una-1, 0); 187 } else 188 tp->t_idle = 0; 189 tp->t_timer[TCPT_KEEP] = TCPTV_KEEP; 190 return; 191 dropit: 192 tcp_drop(tp, ETIMEDOUT); 193 return; 194 } 195 } 196