rename project to visftp
[oftp] / watt32 / netinet / tcp_var.h
1 /*!\file netinet/tcp_var.h
2  * Internal TCP structures and statistics.
3  */
4
5 /*
6  * Copyright (c) 1982, 1986, 1993, 1994, 1995
7  *      The Regents of the University of California.  All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *      This product includes software developed by the University of
20  *      California, Berkeley and its contributors.
21  * 4. Neither the name of the University nor the names of its contributors
22  *    may be used to endorse or promote products derived from this software
23  *    without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  *      @(#)tcp_var.h   8.4 (Berkeley) 5/24/95
38  *      $Id: tcp_var.h,v 1.36 1996/09/13 23:54:03 pst Exp $
39  */
40
41 #ifndef __NETINET_TCP_VAR_H
42 #define __NETINET_TCP_VAR_H
43
44 /*
45  * Kernel variables for tcp.
46  */
47
48 #ifdef TCP_AUTO
49   /* AUTO_RCV_HITHRESH flush reassembly queue, drop incoming packets
50    */
51   #define AUTO_RCV_HITHRESH   (u_long)(0.95 * NMBCLUSTERS)
52
53   /* AUTO_RCV_LOWTHRESH drop incoming packets
54    */
55   #define AUTO_RCV_LOWTHRESH  (u_long)(0.9 * NMBCLUSTERS)
56
57   /* AUTO_SND_THRESH reduce so_snd.sb_hiwat by acked
58    */
59   #define AUTO_SND_THRESH     (u_long)(0.50 * NMBCLUSTERS)
60 #endif
61
62 #if defined(TCP_SACK) || defined(TCP_FACK)
63 #include <netinet/tcp_scor.h>
64
65 struct sackblock {
66        tcp_seq start;
67        tcp_seq end;
68      };
69 #endif
70
71 /*
72  * Tcp control block, one per tcp; fields:
73  */
74 struct tcpcb {
75         struct  tcpiphdr *seg_next;     /* sequencing queue */
76         struct  tcpiphdr *seg_prev;
77   /* !! struct  ipqehead segq; */       /* sequencing queue */
78         int     t_state;                /* state of this connection */
79         int     t_timer[TCPT_NTIMERS];  /* tcp timers */
80         int     t_rxtshift;             /* log(2) of rexmt exp. backoff */
81         int     t_rxtcur;               /* current retransmit value */
82 #ifdef TCP_FACK
83         short   t_padd;                 /* filler to preserve alignment */
84 #else
85         short   t_dupacks;              /* consecutive dup acks recd */
86 #endif
87         u_int   t_maxseg;               /* maximum segment size */
88         u_int   t_maxopd;               /* mss plus options */
89         int     t_force;                /* 1 if forcing out a byte */
90         u_int   t_flags;
91 #define TF_ACKNOW       0x0001          /* ack peer immediately */
92 #define TF_DELACK       0x0002          /* ack, but try to delay it */
93 #define TF_NODELAY      0x0004          /* don't delay packets to coalesce */
94 #define TF_NOOPT        0x0008          /* don't use tcp options */
95 #define TF_SENTFIN      0x0010          /* have sent FIN */
96 #define TF_REQ_SCALE    0x0020          /* have/will request window scaling */
97 #define TF_RCVD_SCALE   0x0040          /* other side has requested scaling */
98 #define TF_REQ_TSTMP    0x0080          /* have/will request timestamps */
99 #define TF_RCVD_TSTMP   0x0100          /* a timestamp was received in SYN */
100 #define TF_SACK_PERMIT  0x0200          /* other side said I could SACK */
101 #define TF_NEEDSYN      0x0400          /* send SYN (implicit state) */
102 #define TF_NEEDFIN      0x0800          /* send FIN (implicit state) */
103 #define TF_NOPUSH       0x1000          /* don't push */
104 #define TF_REQ_CC       0x2000          /* have/will request CC */
105 #define TF_RCVD_CC      0x4000          /* a CC was received in SYN */
106 #define TF_SENDCCNEW    0x8000          /* send CCnew instead of CC in SYN */
107
108         struct  tcpiphdr *t_template;   /* skeletal packet for transmit */
109         struct  inpcb *t_inpcb;         /* back pointer to internet pcb */
110 /*
111  * The following fields are used as in the protocol specification.
112  * See RFC783, Dec. 1981, page 21.
113  */
114 /* send sequence variables */
115         tcp_seq snd_una;                /* send unacknowledged */
116         tcp_seq snd_nxt;                /* send next */
117         tcp_seq snd_up;                 /* send urgent pointer */
118         tcp_seq snd_wl1;                /* window update seg seq number */
119         tcp_seq snd_wl2;                /* window update seg ack number */
120         tcp_seq iss;                    /* initial send sequence number */
121         u_long  snd_wnd;                /* send window */
122 /* receive sequence variables */
123         u_long  rcv_wnd;                /* receive window */
124         tcp_seq rcv_nxt;                /* receive next */
125         tcp_seq rcv_up;                 /* receive urgent pointer */
126         tcp_seq irs;                    /* initial receive sequence number */
127 /*
128  * Additional variables for this implementation.
129  */
130 /* receive variables */
131         tcp_seq rcv_adv;                /* advertised window */
132 /* retransmit variables */
133         tcp_seq snd_max;                /* highest sequence number sent;
134                                          * used to recognize retransmits
135                                          */
136 /* congestion control (for slow start, source quench, retransmit after loss) */
137         u_long  snd_cwnd;               /* congestion-controlled window */
138         u_long  snd_ssthresh;           /* snd_cwnd size threshold for
139                                          * for slow start exponential to
140                                          * linear switch
141                                          */
142 /*
143  * transmit timing stuff.  See below for scale of srtt and rttvar.
144  * "Variance" is actually smoothed difference.
145  */
146         u_int   t_idle;                 /* inactivity time */
147         int     t_rtt;                  /* round trip time */
148         tcp_seq t_rtseq;                /* sequence number being timed */
149         int     t_srtt;                 /* smoothed round-trip time */
150         int     t_rttvar;               /* variance in round-trip time */
151         u_int   t_rttmin;               /* minimum rtt allowed */
152         u_long  max_sndwnd;             /* largest window peer has offered */
153
154 /* out-of-band data */
155         char    t_oobflags;             /* have some */
156         char    t_iobc;                 /* input character */
157 #define TCPOOB_HAVEDATA 0x01
158 #define TCPOOB_HADDATA  0x02
159         int     t_softerror;            /* possible error not yet reported */
160
161 /* RFC 1323 variables */
162         u_char  snd_scale;              /* window scaling for send window */
163         u_char  rcv_scale;              /* window scaling for recv window */
164         u_char  request_r_scale;        /* pending window scaling */
165         u_char  requested_s_scale;
166         u_long  ts_recent;              /* timestamp echo data */
167         u_long  ts_recent_age;          /* when last updated */
168         tcp_seq last_ack_sent;
169 /* RFC 1644 variables */
170         tcp_cc  cc_send;                /* send connection count */
171         tcp_cc  cc_recv;                /* receive connection count */
172         u_long  t_duration;             /* connection duration */
173
174 /* TUBA stuff */
175         caddr_t t_tuba_pcb;             /* next level down pcb for TCP over z */
176 /* More RTT stuff */
177         u_long  t_rttupdated;           /* number of times rtt sampled */
178
179 #if defined(TCP_FACK) || defined(TCP_AUTO)
180         u_short t_alt_flags;   /* experimental flags */
181 #define TAF_SACK_SEEN   0x0001 /* other side can send SACKs */
182 #define TAF_RECOVERY    0x0002 /* We are recovering from a lost segment */
183 #define TAF_RATEHALF    0x0004 /* We are reducing the window during recovery */
184 #define TAF_REPAIRED    0x0008 /* We have retransmitted something */
185 #define TAF_WHOLD       0x0010 /* we are in the window hold state */
186 #define TAF_TOGGLE      0x0020 /* divide by 2 toggle */
187 #define TAF_AUTO_OFF    0x0040 /* autotuning is forced off */
188 #endif
189
190 #if defined(TCP_SACK) || defined(TCP_FACK)
191 #define SACK_LIST_LEN 10
192
193 /* Needed for SACK and FACK:  */
194         struct sackblock sack_list[SACK_LIST_LEN];  /*  Hack, keep 5 most recent SACKs  */
195         struct scoreboard scrb;
196         int snd_retran_data;
197         tcp_seq recover;
198 #endif
199 #ifdef TCP_SACK
200         int pipe;
201 #endif
202 #ifdef TCP_FACK
203         tcp_seq snd_fack;
204 #define TCP_FACK_REXMTTHRESH 3    /* number of SACKs before retransmitting a block */
205         u_long lothresh;                /* recovery window floor */
206         u_long hithresh;                /* maximum window following recovery */
207 #endif
208 };
209
210 /*
211  * Structure to hold TCP options that are only used during segment
212  * processing (in tcp_input), but not held in the tcpcb.
213  * It's basically used to reduce the number of parameters
214  * to tcp_dooptions.
215  */
216 struct tcpopt {
217         u_long  to_flag;                /* which options are present */
218 #define TOF_TS          0x0001          /* timestamp */
219 #define TOF_CC          0x0002          /* CC and CCnew are exclusive */
220 #define TOF_CCNEW       0x0004
221 #define TOF_CCECHO      0x0008
222         u_long  to_tsval;
223         u_long  to_tsecr;
224         tcp_cc  to_cc;          /* holds CC or CCnew */
225         tcp_cc  to_ccecho;
226 };
227
228 /*
229  * The TAO cache entry which is stored in the protocol family specific
230  * portion of the route metrics.
231  */
232 struct rmxp_tao {
233         tcp_cc  tao_cc;                 /* latest CC in valid SYN */
234         tcp_cc  tao_ccsent;             /* latest CC sent to peer */
235         u_short tao_mssopt;             /* peer's cached MSS */
236 #ifdef notyet
237         u_short tao_flags;              /* cache status flags */
238 #define TAOF_DONT       0x0001          /* peer doesn't understand rfc1644 */
239 #define TAOF_OK         0x0002          /* peer does understand rfc1644 */
240 #define TAOF_UNDEF      0               /* we don't know yet */
241 #endif /* notyet */
242 };
243 #define rmx_taop(r)     ((struct rmxp_tao *)(r).rmx_filler)
244
245 #define intotcpcb(ip)   ((struct tcpcb *)(ip)->inp_ppcb)
246 #define sototcpcb(so)   (intotcpcb(sotoinpcb(so)))
247
248 /*
249  * The smoothed round-trip time and estimated variance
250  * are stored as fixed point numbers scaled by the values below.
251  * For convenience, these scales are also used in smoothing the average
252  * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed).
253  * With these scales, srtt has 3 bits to the right of the binary point,
254  * and thus an "ALPHA" of 0.875.  rttvar has 2 bits to the right of the
255  * binary point, and is smoothed with an ALPHA of 0.75.
256  */
257 #define TCP_RTT_SCALE           32      /* multiplier for srtt; 3 bits frac. */
258 #define TCP_RTT_SHIFT           5       /* shift for srtt; 3 bits frac. */
259 #define TCP_RTTVAR_SCALE        16      /* multiplier for rttvar; 2 bits */
260 #define TCP_RTTVAR_SHIFT        4       /* shift for rttvar; 2 bits */
261 #define TCP_DELTA_SHIFT         2       /* see tcp_input.c */
262
263 /*
264  * The initial retransmission should happen at rtt + 4 * rttvar.
265  * Because of the way we do the smoothing, srtt and rttvar
266  * will each average +1/2 tick of bias.  When we compute
267  * the retransmit timer, we want 1/2 tick of rounding and
268  * 1 extra tick because of +-1/2 tick uncertainty in the
269  * firing of the timer.  The bias will give us exactly the
270  * 1.5 tick we need.  But, because the bias is
271  * statistical, we have to test that we don't drop below
272  * the minimum feasible timer (which is 2 ticks).
273  * This version of the macro adapted from a paper by Lawrence
274  * Brakmo and Larry Peterson which outlines a problem caused
275  * by insufficient precision in the original implementation,
276  * which results in inappropriately large RTO values for very
277  * fast networks.
278  */
279 #define TCP_REXMTVAL(tp) \
280         ((((tp)->t_srtt >> (TCP_RTT_SHIFT - TCP_DELTA_SHIFT))  \
281           + (tp)->t_rttvar) >> TCP_DELTA_SHIFT)
282
283 /* XXX
284  * We want to avoid doing m_pullup on incoming packets but that
285  * means avoiding dtom on the tcp reassembly code.  That in turn means
286  * keeping an mbuf pointer in the reassembly queue (since we might
287  * have a cluster).  As a quick hack, the source & destination
288  * port numbers (which are no longer needed once we've located the
289  * tcpcb) are overlayed with an mbuf pointer.
290  */
291 #define REASS_MBUF(ti) (*(struct mbuf **)&((ti)->ti_t))
292
293 /*
294  * TCP statistics.
295  * Many of these should be kept per connection,
296  * but that's inconvenient at the moment.
297  */
298 struct  tcpstat {
299         u_long  tcps_connattempt;       /* connections initiated */
300         u_long  tcps_accepts;           /* connections accepted */
301         u_long  tcps_connects;          /* connections established */
302         u_long  tcps_drops;             /* connections dropped */
303         u_long  tcps_conndrops;         /* embryonic connections dropped */
304         u_long  tcps_closed;            /* conn. closed (includes drops) */
305         u_long  tcps_segstimed;         /* segs where we tried to get rtt */
306         u_long  tcps_rttupdated;        /* times we succeeded */
307         u_long  tcps_delack;            /* delayed acks sent */
308         u_long  tcps_timeoutdrop;       /* conn. dropped in rxmt timeout */
309         u_long  tcps_rexmttimeo;        /* retransmit timeouts */
310         u_long  tcps_persisttimeo;      /* persist timeouts */
311         u_long  tcps_keeptimeo;         /* keepalive timeouts */
312         u_long  tcps_keepprobe;         /* keepalive probes sent */
313         u_long  tcps_keepdrops;         /* connections dropped in keepalive */
314
315         u_long  tcps_sndtotal;          /* total packets sent */
316         u_long  tcps_sndpack;           /* data packets sent */
317         u_long  tcps_sndbyte;           /* data bytes sent */
318         u_long  tcps_sndrexmitpack;     /* data packets retransmitted */
319         u_long  tcps_sndrexmitbyte;     /* data bytes retransmitted */
320         u_long  tcps_sndacks;           /* ack-only packets sent */
321         u_long  tcps_sndprobe;          /* window probes sent */
322         u_long  tcps_sndurg;            /* packets sent with URG only */
323         u_long  tcps_sndwinup;          /* window update-only packets sent */
324         u_long  tcps_sndctrl;           /* control (SYN|FIN|RST) packets sent */
325
326         u_long  tcps_rcvtotal;          /* total packets received */
327         u_long  tcps_rcvpack;           /* packets received in sequence */
328         u_long  tcps_rcvbyte;           /* bytes received in sequence */
329         u_long  tcps_rcvbadsum;         /* packets received with ccksum errs */
330         u_long  tcps_rcvbadoff;         /* packets received with bad offset */
331         u_long  tcps_rcvshort;          /* packets received too short */
332         u_long  tcps_rcvduppack;        /* duplicate-only packets received */
333         u_long  tcps_rcvdupbyte;        /* duplicate-only bytes received */
334         u_long  tcps_rcvpartduppack;    /* packets with some duplicate data */
335         u_long  tcps_rcvpartdupbyte;    /* dup. bytes in part-dup. packets */
336         u_long  tcps_rcvoopack;         /* out-of-order packets received */
337         u_long  tcps_rcvoobyte;         /* out-of-order bytes received */
338         u_long  tcps_rcvpackafterwin;   /* packets with data after window */
339         u_long  tcps_rcvbyteafterwin;   /* bytes rcvd after window */
340         u_long  tcps_rcvafterclose;     /* packets rcvd after "close" */
341         u_long  tcps_rcvwinprobe;       /* rcvd window probe packets */
342         u_long  tcps_rcvdupack;         /* rcvd duplicate acks */
343         u_long  tcps_rcvacktoomuch;     /* rcvd acks for unsent data */
344         u_long  tcps_rcvackpack;        /* rcvd ack packets */
345         u_long  tcps_rcvackbyte;        /* bytes acked by rcvd acks */
346         u_long  tcps_rcvwinupd;         /* rcvd window update packets */
347         u_long  tcps_pawsdrop;          /* segments dropped due to PAWS */
348         u_long  tcps_predack;           /* times hdr predict ok for acks */
349         u_long  tcps_preddat;           /* times hdr predict ok for data pkts */
350         u_long  tcps_pcbcachemiss;
351         u_long  tcps_cachedrtt;         /* times cached RTT in route updated */
352         u_long  tcps_cachedrttvar;      /* times cached rttvar updated */
353         u_long  tcps_cachedssthresh;    /* times cached ssthresh updated */
354         u_long  tcps_usedrtt;           /* times RTT initialized from route */
355         u_long  tcps_usedrttvar;        /* times RTTVAR initialized from rt */
356         u_long  tcps_usedssthresh;      /* times ssthresh initialized from rt*/
357         u_long  tcps_persistdrop;       /* timeout in persist state */
358         u_long  tcps_badsyn;            /* bogus SYN, e.g. premature ACK */
359         u_long  tcps_mturesent;         /* resends due to MTU discovery */
360         u_long  tcps_listendrop;        /* listen queue overflows */
361
362 #ifdef TCP_FACK
363        /* NOTE: This may break some programs that rely on this structure
364         * being fixed length.
365         */
366         u_long  tcps_fack_recovery;     /* fack: recovery episodes */
367         u_long  tcps_fack_sndpack;      /* fack: data packets sent */
368         u_long  tcps_fack_sndbyte;      /* fack: data bytes sent */
369         u_long  tcps_fack_sndrexmitpack;/* fack: data packets retransmitted */
370         u_long  tcps_fack_sndrexmitbyte;/* fack: data bytes retransmitted */
371 #endif
372 };
373
374 /*
375  * Names for TCP sysctl objects
376  */
377 #define TCPCTL_DO_RFC1323       1       /* use RFC-1323 extensions */
378 #define TCPCTL_DO_RFC1644       2       /* use RFC-1644 extensions */
379 #define TCPCTL_MSSDFLT          3       /* MSS default */
380 #define TCPCTL_STATS            4       /* statistics (read-only) */
381 #define TCPCTL_RTTDFLT          5       /* default RTT estimate */
382 #define TCPCTL_KEEPIDLE         6       /* keepalive idle timer */
383 #define TCPCTL_KEEPINTVL        7       /* interval to send keepalives */
384 #define TCPCTL_SENDSPACE        8       /* send buffer space */
385 #define TCPCTL_RECVSPACE        9       /* receive buffer space */
386 #define TCPCTL_KEEPINIT         10      /* receive buffer space */
387 #define TCPCTL_MAXID            11
388
389 #define TCPCTL_NAMES { \
390         { 0, 0 }, \
391         { "rfc1323", CTLTYPE_INT }, \
392         { "rfc1644", CTLTYPE_INT }, \
393         { "mssdflt", CTLTYPE_INT }, \
394         { "stats", CTLTYPE_STRUCT }, \
395         { "rttdflt", CTLTYPE_INT }, \
396         { "keepidle", CTLTYPE_INT }, \
397         { "keepintvl", CTLTYPE_INT }, \
398         { "sendspace", CTLTYPE_INT }, \
399         { "recvspace", CTLTYPE_INT }, \
400         { "keepinit", CTLTYPE_INT }, \
401 }
402
403 #endif