TIOCNOTTY
[unix-history] / usr / src / sys / netinet / tcp_timer.c
CommitLineData
b8b9174f 1/* tcp_timer.c 4.10 81/12/21 */
f03530e6
BJ
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"
0974b45c
BJ
9#include "../net/in.h"
10#include "../net/in_pcb.h"
11#include "../net/in_systm.h"
f03530e6 12#include "../net/if.h"
f03530e6
BJ
13#include "../net/ip.h"
14#include "../net/ip_var.h"
15#include "../net/tcp.h"
16#include "../net/tcp_fsm.h"
0974b45c
BJ
17#include "../net/tcp_seq.h"
18#include "../net/tcp_timer.h"
f03530e6 19#include "../net/tcp_var.h"
0974b45c 20#include "../net/tcpip.h"
f1b2fa5b 21#include "../errno.h"
f03530e6 22
b8b9174f 23int tcpdelack = 0;
f03530e6
BJ
24/*
25 * Fast timeout routine for processing delayed acks
26 */
27tcp_fasttimo()
28{
b8b9174f
BJ
29 register struct inpcb *inp;
30 register struct tcpcb *tp;
31 int s = splnet();
0974b45c 32COUNT(TCP_FASTTIMO);
b8b9174f
BJ
33
34 for (inp = tcb.inp_next; inp != &tcb; inp = inp->inp_next)
35 if ((tp = (struct tcpcb *)inp->inp_ppcb) &&
36 (tp->t_flags & TF_DELACK)) {
37 tp->t_flags &= ~TF_DELACK;
38 tp->t_flags |= TF_ACKNOW;
39 (void) tcp_output(tp);
40 }
41 splx(s);
f03530e6
BJ
42}
43
44/*
45 * Tcp protocol timeout routine called every 500 ms.
46 * Updates the timers in all active tcb's and
47 * causes finite state machine actions if timers expire.
48 */
49tcp_slowtimo()
50{
51 register struct inpcb *ip;
52 register struct tcpcb *tp;
53 int s = splnet();
f03530e6 54 register int i;
0974b45c 55COUNT(TCP_SLOWTIMO);
f03530e6
BJ
56
57 /*
58 * Search through tcb's and update active timers.
59 */
4aed14e3
BJ
60 ip = tcb.inp_next;
61 if (ip == 0) {
62 splx(s);
63 return;
64 }
65 for (; ip != &tcb; ip = ip->inp_next) {
f03530e6 66 tp = intotcpcb(ip);
37de812c
BJ
67 if (tp == 0)
68 continue;
a6503abf 69 for (i = 0; i < TCPT_NTIMERS; i++) {
0974b45c 70 if (tp->t_timer[i] && --tp->t_timer[i] == 0)
f03530e6
BJ
71 (void) tcp_usrreq(tp->t_inpcb->inp_socket,
72 PRU_SLOWTIMO, (struct mbuf *)0,
73 (caddr_t)i);
f03530e6 74 }
405c9168
BJ
75 tp->t_idle++;
76 if (tp->t_rtt)
77 tp->t_rtt++;
f03530e6 78 }
a6503abf 79 tcp_iss += TCP_ISSINCR/PR_SLOWHZ; /* increment iss */
f03530e6
BJ
80 splx(s);
81}
82
83/*
a6503abf 84 * Cancel all timers for TCP tp.
f03530e6 85 */
0974b45c 86tcp_canceltimers(tp)
f03530e6
BJ
87 struct tcpcb *tp;
88{
f03530e6
BJ
89 register int i;
90
0974b45c 91COUNT(TCP_CANCELTIMERS);
a6503abf
BJ
92 for (i = 0; i < TCPT_NTIMERS; i++)
93 tp->t_timer[i] = 0;
f03530e6
BJ
94}
95
96/*
405c9168 97 * TCP timer processing.
f03530e6 98 */
a6503abf 99tcp_timers(tp, timer)
f03530e6 100 register struct tcpcb *tp;
a6503abf 101 int timer;
f03530e6
BJ
102{
103
104COUNT(TCP_TIMERS);
0974b45c 105 switch (timer) {
f03530e6 106
405c9168
BJ
107 /*
108 * 2 MSL timeout in shutdown went off. Delete connection
109 * control block.
110 */
a6503abf
BJ
111 case TCPT_2MSL:
112 tcp_close(tp);
113 return;
f03530e6 114
405c9168
BJ
115 /*
116 * Retransmission timer went off. Message has not
117 * been acked within retransmit interval. Back off
118 * to a longer retransmit interval and retransmit all
119 * unacknowledged messages in the window.
120 */
a6503abf 121 case TCPT_REXMT:
405c9168
BJ
122 tp->t_rxtshift++;
123 TCPT_RANGESET(tp->t_timer[TCPT_REXMT],
b8b9174f 124 ((int)(2 * tp->t_srtt)),
405c9168 125 TCPTV_MIN, TCPTV_MAX);
b8b9174f
BJ
126 TCPT_RANGESET(tp->t_timer[TCPT_REXMT],
127 tp->t_timer[TCPT_REXMT] << tp->t_rxtshift,
128 TCPTV_MIN, TCPTV_MAX);
129 if (tp->t_timer[TCPT_REXMT] > TCPTV_MAXIDLE / 2) {
130 tcp_drop(tp, ETIMEDOUT);
131 return;
132 }
89413846 133printf("rexmt set to %d\n", tp->t_timer[TCPT_REXMT]);
405c9168
BJ
134 tp->snd_nxt = tp->snd_una;
135 /* this only transmits one segment! */
136 (void) tcp_output(tp);
a6503abf 137 return;
f03530e6 138
405c9168
BJ
139 /*
140 * Persistance timer into zero window.
141 * Force a byte to be output, if possible.
142 */
a6503abf 143 case TCPT_PERSIST:
405c9168
BJ
144 tp->t_force = 1;
145 (void) tcp_output(tp);
146 tp->t_force = 0;
147 TCPT_RANGESET(tp->t_timer[TCPT_PERSIST],
148 2 * tp->t_srtt, TCPTV_PERSMIN, TCPTV_MAX);
0974b45c 149 return;
f03530e6 150
405c9168
BJ
151 /*
152 * Keep-alive timer went off; send something
153 * or drop connection if idle for too long.
154 */
a6503abf 155 case TCPT_KEEP:
405c9168
BJ
156 if (tp->t_state < TCPS_ESTABLISHED ||
157 tp->t_idle >= TCPTV_MAXIDLE) {
158 tcp_drop(tp, ETIMEDOUT);
159 return;
160 }
161 tcp_respond(tp->t_template, tp->rcv_nxt, tp->snd_una-1, 0);
162 tp->t_timer[TCPT_KEEP] = TCPTV_KEEP;
a6503abf 163 return;
f03530e6 164 }
f03530e6 165}