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