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