lint
[unix-history] / usr / src / sys / netinet / tcp_timer.c
CommitLineData
405c9168 1/* tcp_timer.c 4.5 81/12/02 */
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
BJ
22
23/*
24 * Fast timeout routine for processing delayed acks
25 */
26tcp_fasttimo()
27{
28
0974b45c 29COUNT(TCP_FASTTIMO);
f03530e6
BJ
30}
31
32/*
33 * Tcp protocol timeout routine called every 500 ms.
34 * Updates the timers in all active tcb's and
35 * causes finite state machine actions if timers expire.
36 */
37tcp_slowtimo()
38{
39 register struct inpcb *ip;
40 register struct tcpcb *tp;
41 int s = splnet();
f03530e6 42 register int i;
0974b45c 43COUNT(TCP_SLOWTIMO);
f03530e6
BJ
44
45 /*
46 * Search through tcb's and update active timers.
47 */
48 for (ip = tcb.inp_next; ip != &tcb; ip = ip->inp_next) {
49 tp = intotcpcb(ip);
a6503abf 50 for (i = 0; i < TCPT_NTIMERS; i++) {
0974b45c 51 if (tp->t_timer[i] && --tp->t_timer[i] == 0)
f03530e6
BJ
52 (void) tcp_usrreq(tp->t_inpcb->inp_socket,
53 PRU_SLOWTIMO, (struct mbuf *)0,
54 (caddr_t)i);
f03530e6 55 }
405c9168
BJ
56 tp->t_idle++;
57 if (tp->t_rtt)
58 tp->t_rtt++;
f03530e6 59 }
a6503abf 60 tcp_iss += TCP_ISSINCR/PR_SLOWHZ; /* increment iss */
f03530e6
BJ
61 splx(s);
62}
63
64/*
a6503abf 65 * Cancel all timers for TCP tp.
f03530e6 66 */
0974b45c 67tcp_canceltimers(tp)
f03530e6
BJ
68 struct tcpcb *tp;
69{
f03530e6
BJ
70 register int i;
71
0974b45c 72COUNT(TCP_CANCELTIMERS);
a6503abf
BJ
73 for (i = 0; i < TCPT_NTIMERS; i++)
74 tp->t_timer[i] = 0;
f03530e6
BJ
75}
76
77/*
405c9168 78 * TCP timer processing.
f03530e6 79 */
a6503abf 80tcp_timers(tp, timer)
f03530e6 81 register struct tcpcb *tp;
a6503abf 82 int timer;
f03530e6
BJ
83{
84
85COUNT(TCP_TIMERS);
0974b45c 86 switch (timer) {
f03530e6 87
405c9168
BJ
88 /*
89 * 2 MSL timeout in shutdown went off. Delete connection
90 * control block.
91 */
a6503abf
BJ
92 case TCPT_2MSL:
93 tcp_close(tp);
94 return;
f03530e6 95
405c9168
BJ
96 /*
97 * Retransmission timer went off. Message has not
98 * been acked within retransmit interval. Back off
99 * to a longer retransmit interval and retransmit all
100 * unacknowledged messages in the window.
101 */
a6503abf 102 case TCPT_REXMT:
405c9168
BJ
103 tp->t_rxtshift++;
104 TCPT_RANGESET(tp->t_timer[TCPT_REXMT],
105 ((int)(2 * tp->t_srtt)) << tp->t_rxtshift,
106 TCPTV_MIN, TCPTV_MAX);
107 tp->snd_nxt = tp->snd_una;
108 /* this only transmits one segment! */
109 (void) tcp_output(tp);
a6503abf 110 return;
f03530e6 111
405c9168
BJ
112 /*
113 * Persistance timer into zero window.
114 * Force a byte to be output, if possible.
115 */
a6503abf 116 case TCPT_PERSIST:
405c9168
BJ
117 tp->t_force = 1;
118 (void) tcp_output(tp);
119 tp->t_force = 0;
120 TCPT_RANGESET(tp->t_timer[TCPT_PERSIST],
121 2 * tp->t_srtt, TCPTV_PERSMIN, TCPTV_MAX);
0974b45c 122 return;
f03530e6 123
405c9168
BJ
124 /*
125 * Keep-alive timer went off; send something
126 * or drop connection if idle for too long.
127 */
a6503abf 128 case TCPT_KEEP:
405c9168
BJ
129 if (tp->t_state < TCPS_ESTABLISHED ||
130 tp->t_idle >= TCPTV_MAXIDLE) {
131 tcp_drop(tp, ETIMEDOUT);
132 return;
133 }
134 tcp_respond(tp->t_template, tp->rcv_nxt, tp->snd_una-1, 0);
135 tp->t_timer[TCPT_KEEP] = TCPTV_KEEP;
a6503abf 136 return;
f03530e6 137 }
f03530e6 138}