OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [net/] [tcpip/] [v2_0/] [src/] [sys/] [netinet/] [tcp_timer.c] - Blame information for rev 27

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      sys/netinet/tcp_timer.c
4
//
5
//     
6
//
7
//==========================================================================
8
//####BSDCOPYRIGHTBEGIN####
9
//
10
// -------------------------------------------
11
//
12
// Portions of this software may have been derived from OpenBSD or other sources,
13
// and are covered by the appropriate copyright disclaimers included herein.
14
//
15
// -------------------------------------------
16
//
17
//####BSDCOPYRIGHTEND####
18
//==========================================================================
19
//#####DESCRIPTIONBEGIN####
20
//
21
// Author(s):    gthomas
22
// Contributors: gthomas
23
// Date:         2000-01-10
24
// Purpose:      
25
// Description:  
26
//              
27
//
28
//####DESCRIPTIONEND####
29
//
30
//==========================================================================
31
 
32
 
33
/*      $OpenBSD: tcp_timer.c,v 1.15 1999/11/15 05:50:59 hugh Exp $     */
34
/*      $NetBSD: tcp_timer.c,v 1.14 1996/02/13 23:44:09 christos Exp $  */
35
 
36
/*
37
 * Copyright (c) 1982, 1986, 1988, 1990, 1993
38
 *      The Regents of the University of California.  All rights reserved.
39
 *
40
 * Redistribution and use in source and binary forms, with or without
41
 * modification, are permitted provided that the following conditions
42
 * are met:
43
 * 1. Redistributions of source code must retain the above copyright
44
 *    notice, this list of conditions and the following disclaimer.
45
 * 2. Redistributions in binary form must reproduce the above copyright
46
 *    notice, this list of conditions and the following disclaimer in the
47
 *    documentation and/or other materials provided with the distribution.
48
 * 3. All advertising materials mentioning features or use of this software
49
 *    must display the following acknowledgement:
50
 *      This product includes software developed by the University of
51
 *      California, Berkeley and its contributors.
52
 * 4. Neither the name of the University nor the names of its contributors
53
 *    may be used to endorse or promote products derived from this software
54
 *    without specific prior written permission.
55
 *
56
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
57
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
59
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
60
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
61
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
62
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
64
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
65
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66
 * SUCH DAMAGE.
67
 *
68
 *      @(#)tcp_timer.c 8.1 (Berkeley) 6/10/93
69
 */
70
 
71
#ifndef TUBA_INCLUDE
72
#include <sys/param.h>
73
#ifndef __ECOS
74
#include <sys/systm.h>
75
#endif
76
#include <sys/malloc.h>
77
#include <sys/mbuf.h>
78
#include <sys/socket.h>
79
#include <sys/socketvar.h>
80
#include <sys/protosw.h>
81
#include <sys/errno.h>
82
 
83
#include <net/if.h>
84
#include <net/route.h>
85
 
86
#include <netinet/in.h>
87
#include <netinet/in_systm.h>
88
#include <netinet/ip.h>
89
#include <netinet/in_pcb.h>
90
#include <netinet/ip_var.h>
91
#include <netinet/tcp.h>
92
#include <netinet/tcp_fsm.h>
93
#include <netinet/tcp_seq.h>
94
#include <netinet/tcp_timer.h>
95
#include <netinet/tcp_var.h>
96
#include <netinet/tcpip.h>
97
#ifndef __ECOS
98
#include <dev/rndvar.h>
99
#endif
100
 
101
int     tcp_keepidle = TCPTV_KEEP_IDLE;
102
int     tcp_keepintvl = TCPTV_KEEPINTVL;
103
int     tcp_maxpersistidle = TCPTV_KEEP_IDLE;   /* max idle time in persist */
104
int     tcp_maxidle;
105
#endif /* TUBA_INCLUDE */
106
/*
107
 * Fast timeout routine for processing delayed acks
108
 */
109
void
110
tcp_fasttimo()
111
{
112
        register struct inpcb *inp;
113
        register struct tcpcb *tp;
114
        int s;
115
 
116
        s = splsoftnet();
117
        inp = tcbtable.inpt_queue.cqh_first;
118
        if (inp)                                                /* XXX */
119
        for (; inp != (struct inpcb *)&tcbtable.inpt_queue;
120
            inp = inp->inp_queue.cqe_next) {
121
                if ((tp = (struct tcpcb *)inp->inp_ppcb) &&
122
                    (tp->t_flags & TF_DELACK)) {
123
                        tp->t_flags &= ~TF_DELACK;
124
                        tp->t_flags |= TF_ACKNOW;
125
                        tcpstat.tcps_delack++;
126
                        (void) tcp_output(tp);
127
                }
128
        }
129
        splx(s);
130
}
131
 
132
/*
133
 * Tcp protocol timeout routine called every 500 ms.
134
 * Updates the timers in all active tcb's and
135
 * causes finite state machine actions if timers expire.
136
 */
137
void
138
tcp_slowtimo()
139
{
140
        register struct inpcb *ip, *ipnxt;
141
        register struct tcpcb *tp;
142
        int s;
143
        register long i;
144
 
145
        s = splsoftnet();
146
        tcp_maxidle = TCPTV_KEEPCNT * tcp_keepintvl;
147
        /*
148
         * Search through tcb's and update active timers.
149
         */
150
        ip = tcbtable.inpt_queue.cqh_first;
151
        if (ip == (struct inpcb *)0) {                           /* XXX */
152
                splx(s);
153
                return;
154
        }
155
        for (; ip != (struct inpcb *)&tcbtable.inpt_queue; ip = ipnxt) {
156
                ipnxt = ip->inp_queue.cqe_next;
157
                tp = intotcpcb(ip);
158
                if (tp == 0 || tp->t_state == TCPS_LISTEN)
159
                        continue;
160
                for (i = 0; i < TCPT_NTIMERS; i++) {
161
                        if (tp->t_timer[i] && --tp->t_timer[i] == 0) {
162
                                (void) tcp_usrreq(tp->t_inpcb->inp_socket,
163
                                    PRU_SLOWTIMO, (struct mbuf *)0,
164
                                    (struct mbuf *)i, (struct mbuf *)0);
165
                                /* XXX NOT MP SAFE */
166
                                if ((ipnxt == (void *)&tcbtable.inpt_queue &&
167
                                    tcbtable.inpt_queue.cqh_last != ip) ||
168
                                    ipnxt->inp_queue.cqe_prev != ip)
169
                                        goto tpgone;
170
                        }
171
                }
172
                tp->t_idle++;
173
                if (tp->t_rtt)
174
                        tp->t_rtt++;
175
tpgone:
176
                ;
177
        }
178
#ifdef TCP_COMPAT_42
179
        tcp_iss += TCP_ISSINCR/PR_SLOWHZ;               /* increment iss */
180
        if ((int)tcp_iss < 0)
181
                tcp_iss = 0;                             /* XXX */
182
#else /* TCP_COMPAT_42 */
183
        tcp_iss += arc4random() % (2 * TCP_ISSINCR / PR_SLOWHZ) + 1; /* increment iss */
184
#endif /* !TCP_COMPAT_42 */
185
        tcp_now++;                                      /* for timestamps */
186
        splx(s);
187
}
188
#ifndef TUBA_INCLUDE
189
 
190
/*
191
 * Cancel all timers for TCP tp.
192
 */
193
void
194
tcp_canceltimers(tp)
195
        struct tcpcb *tp;
196
{
197
        register int i;
198
 
199
        for (i = 0; i < TCPT_NTIMERS; i++)
200
                tp->t_timer[i] = 0;
201
}
202
 
203
int     tcp_backoff[TCP_MAXRXTSHIFT + 1] =
204
    { 1, 2, 4, 8, 16, 32, 64, 64, 64, 64, 64, 64, 64 };
205
 
206
int tcp_totbackoff = 511;       /* sum of tcp_backoff[] */
207
 
208
/*
209
 * TCP timer processing.
210
 */
211
struct tcpcb *
212
tcp_timers(tp, timer)
213
        register struct tcpcb *tp;
214
        int timer;
215
{
216
        short rto;
217
#ifdef TCP_SACK
218
        struct sackhole *p, *q;
219
        /*
220
         * Free SACK holes for 2MSL and REXMT timers.
221
         */
222
        if (timer == TCPT_2MSL || timer == TCPT_REXMT) {
223
                q = p = tp->snd_holes;
224
                while (p != 0) {
225
                        q = p->next;
226
                        free(p, M_PCB);
227
                        p = q;
228
                }
229
                tp->snd_holes = 0;
230
#if defined(TCP_SACK) && defined(TCP_FACK)
231
                tp->snd_fack = tp->snd_una;
232
                tp->retran_data = 0;
233
                tp->snd_awnd = 0;
234
#endif /* TCP_FACK */
235
        }
236
#endif /* TCP_SACK */
237
 
238
        switch (timer) {
239
 
240
        /*
241
         * 2 MSL timeout in shutdown went off.  If we're closed but
242
         * still waiting for peer to close and connection has been idle
243
         * too long, or if 2MSL time is up from TIME_WAIT, delete connection
244
         * control block.  Otherwise, check again in a bit.
245
         */
246
        case TCPT_2MSL:
247
                if (tp->t_state != TCPS_TIME_WAIT &&
248
                    tp->t_idle <= tcp_maxidle)
249
                        tp->t_timer[TCPT_2MSL] = tcp_keepintvl;
250
                else
251
                        tp = tcp_close(tp);
252
                break;
253
 
254
        /*
255
         * Retransmission timer went off.  Message has not
256
         * been acked within retransmit interval.  Back off
257
         * to a longer retransmit interval and retransmit one segment.
258
         */
259
        case TCPT_REXMT:
260
                if (++tp->t_rxtshift > TCP_MAXRXTSHIFT) {
261
                        tp->t_rxtshift = TCP_MAXRXTSHIFT;
262
                        tcpstat.tcps_timeoutdrop++;
263
                        tp = tcp_drop(tp, tp->t_softerror ?
264
                            tp->t_softerror : ETIMEDOUT);
265
                        break;
266
                }
267
                tcpstat.tcps_rexmttimeo++;
268
                rto = TCP_REXMTVAL(tp);
269
                if (rto < tp->t_rttmin)
270
                        rto = tp->t_rttmin;
271
                TCPT_RANGESET((long) tp->t_rxtcur,
272
                    rto * tcp_backoff[tp->t_rxtshift],
273
                    tp->t_rttmin, TCPTV_REXMTMAX);
274
                tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
275
                /*
276
                 * If losing, let the lower level know and try for
277
                 * a better route.  Also, if we backed off this far,
278
                 * our srtt estimate is probably bogus.  Clobber it
279
                 * so we'll take the next rtt measurement as our srtt;
280
                 * move the current srtt into rttvar to keep the current
281
                 * retransmit times until then.
282
                 */
283
                if (tp->t_rxtshift > TCP_MAXRXTSHIFT / 4) {
284
                        in_losing(tp->t_inpcb);
285
                        tp->t_rttvar += (tp->t_srtt >> TCP_RTT_SHIFT);
286
                        tp->t_srtt = 0;
287
                }
288
                tp->snd_nxt = tp->snd_una;
289
#if defined(TCP_SACK) || defined(TCP_NEWRENO)
290
                /*
291
                 * Note:  We overload snd_last to function also as the
292
                 * snd_last variable described in RFC 2582
293
                 */
294
                tp->snd_last = tp->snd_max;
295
#endif /* TCP_SACK or TCP_NEWRENO */
296
                /*
297
                 * If timing a segment in this window, stop the timer.
298
                 */
299
                tp->t_rtt = 0;
300
                /*
301
                 * Close the congestion window down to one segment
302
                 * (we'll open it by one segment for each ack we get).
303
                 * Since we probably have a window's worth of unacked
304
                 * data accumulated, this "slow start" keeps us from
305
                 * dumping all that data as back-to-back packets (which
306
                 * might overwhelm an intermediate gateway).
307
                 *
308
                 * There are two phases to the opening: Initially we
309
                 * open by one mss on each ack.  This makes the window
310
                 * size increase exponentially with time.  If the
311
                 * window is larger than the path can handle, this
312
                 * exponential growth results in dropped packet(s)
313
                 * almost immediately.  To get more time between
314
                 * drops but still "push" the network to take advantage
315
                 * of improving conditions, we switch from exponential
316
                 * to linear window opening at some threshhold size.
317
                 * For a threshhold, we use half the current window
318
                 * size, truncated to a multiple of the mss.
319
                 *
320
                 * (the minimum cwnd that will give us exponential
321
                 * growth is 2 mss.  We don't allow the threshhold
322
                 * to go below this.)
323
                 */
324
                {
325
                u_long win = ulmin(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_maxseg;
326
                if (win < 2)
327
                        win = 2;
328
                tp->snd_cwnd = tp->t_maxseg;
329
                tp->snd_ssthresh = win * tp->t_maxseg;
330
                tp->t_dupacks = 0;
331
                }
332
                (void) tcp_output(tp);
333
                break;
334
 
335
        /*
336
         * Persistance timer into zero window.
337
         * Force a byte to be output, if possible.
338
         */
339
        case TCPT_PERSIST:
340
                tcpstat.tcps_persisttimeo++;
341
                /*
342
                 * Hack: if the peer is dead/unreachable, we do not
343
                 * time out if the window is closed.  After a full
344
                 * backoff, drop the connection if the idle time
345
                 * (no responses to probes) reaches the maximum
346
                 * backoff that we would use if retransmitting.
347
                 */
348
                rto = TCP_REXMTVAL(tp);
349
                if (rto < tp->t_rttmin)
350
                        rto = tp->t_rttmin;
351
                if (tp->t_rxtshift == TCP_MAXRXTSHIFT &&
352
                    (tp->t_idle >= tcp_maxpersistidle ||
353
                     tp->t_idle >= rto * tcp_totbackoff)) {
354
                        tcpstat.tcps_persistdrop++;
355
                        tp = tcp_drop(tp, ETIMEDOUT);
356
                        break;
357
                }
358
                tcp_setpersist(tp);
359
                tp->t_force = 1;
360
                (void) tcp_output(tp);
361
                tp->t_force = 0;
362
                break;
363
 
364
        /*
365
         * Keep-alive timer went off; send something
366
         * or drop connection if idle for too long.
367
         */
368
        case TCPT_KEEP:
369
                tcpstat.tcps_keeptimeo++;
370
                if (TCPS_HAVEESTABLISHED(tp->t_state) == 0)
371
                        goto dropit;
372
                if (tp->t_inpcb->inp_socket->so_options & SO_KEEPALIVE &&
373
                    tp->t_state <= TCPS_CLOSE_WAIT) {
374
                        if (tp->t_idle >= tcp_keepidle + tcp_maxidle)
375
                                goto dropit;
376
                        /*
377
                         * Send a packet designed to force a response
378
                         * if the peer is up and reachable:
379
                         * either an ACK if the connection is still alive,
380
                         * or an RST if the peer has closed the connection
381
                         * due to timeout or reboot.
382
                         * Using sequence number tp->snd_una-1
383
                         * causes the transmitted zero-length segment
384
                         * to lie outside the receive window;
385
                         * by the protocol spec, this requires the
386
                         * correspondent TCP to respond.
387
                         */
388
                        tcpstat.tcps_keepprobe++;
389
#ifdef TCP_COMPAT_42
390
                        /*
391
                         * The keepalive packet must have nonzero length
392
                         * to get a 4.2 host to respond.
393
                         */
394
                        tcp_respond(tp,
395
                                mtod(tp->t_template, caddr_t),
396
                                (struct mbuf *)NULL,
397
                                tp->rcv_nxt - 1, tp->snd_una - 1, 0);
398
#else
399
                        tcp_respond(tp,
400
                                mtod(tp->t_template, caddr_t),
401
                                (struct mbuf *)NULL,
402
                                tp->rcv_nxt, tp->snd_una - 1, 0);
403
#endif
404
                        tp->t_timer[TCPT_KEEP] = tcp_keepintvl;
405
                } else
406
                        tp->t_timer[TCPT_KEEP] = tcp_keepidle;
407
                break;
408
        dropit:
409
                tcpstat.tcps_keepdrops++;
410
                tp = tcp_drop(tp, ETIMEDOUT);
411
                break;
412
        }
413
        return (tp);
414
}
415
#endif /* TUBA_INCLUDE */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.