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