|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24:
25: /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
26: /*
27: * Copyright (c) 1982, 1986, 1993, 1994, 1995
28: * The Regents of the University of California. All rights reserved.
29: *
30: * Redistribution and use in source and binary forms, with or without
31: * modification, are permitted provided that the following conditions
32: * are met:
33: * 1. Redistributions of source code must retain the above copyright
34: * notice, this list of conditions and the following disclaimer.
35: * 2. Redistributions in binary form must reproduce the above copyright
36: * notice, this list of conditions and the following disclaimer in the
37: * documentation and/or other materials provided with the distribution.
38: * 3. All advertising materials mentioning features or use of this software
39: * must display the following acknowledgement:
40: * This product includes software developed by the University of
41: * California, Berkeley and its contributors.
42: * 4. Neither the name of the University nor the names of its contributors
43: * may be used to endorse or promote products derived from this software
44: * without specific prior written permission.
45: *
46: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56: * SUCH DAMAGE.
57: *
58: * @(#)tcp_var.h 8.4 (Berkeley) 5/24/95
59: */
60:
61: /*
62: * Kernel variables for tcp.
63: */
64:
65: #define N_TIME_WAIT_SLOTS 120
66:
67: #define N_TCP_HASH_ELEMENTS (8 * 1024) /* must be power of 2 */
68: #define TCP_HASH_MASK (N_TCP_HASH_ELEMENTS - 1)
69: #define N_TCP_LPORT_HASH_ELEMENTS (1024)
70: #define TCP_LPORT_HASH_MASK (N_TCP_LPORT_HASH_ELEMENTS - 1)
71:
72: /*
73: * The macro below takes a value from 0 - 8192 and sets a corresponding bit in the
74: * 1024 byte delack_bitmask array. Each bit represents represents one of the
75: * hash-queue entries in the TCP hash queue array.
76: */
77:
78: #define TCP_DELACK_BITSET(hash_elem) \
79: delack_bitmask[((hash_elem) >> 5)] |= 1 << ((hash_elem) & 0x1F)
80:
81: #define DELACK_BITMASK_ON 1
82: #define DELACK_BITMASK_THRESH 300
83:
84:
85: /*
86: * Tcp control block, one per tcp; fields:
87: */
88: struct tcpcb {
89: struct tcpiphdr *seg_next; /* sequencing queue */
90: struct tcpiphdr *seg_prev;
91: short t_state; /* state of this connection */
92: short t_timer[TCPT_NTIMERS]; /* tcp timers */
93: short t_rxtshift; /* log(2) of rexmt exp. backoff */
94: short t_rxtcur; /* current retransmit value */
95: short t_dupacks; /* consecutive dup acks recd */
96: u_short t_maxseg; /* maximum segment size */
97: char t_force; /* 1 if forcing out a byte */
98: u_short t_flags;
99: #define TF_ACKNOW 0x0001 /* ack peer immediately */
100: #define TF_DELACK 0x0002 /* ack, but try to delay it */
101: #define TF_NODELAY 0x0004 /* don't delay packets to coalesce */
102: #define TF_NOOPT 0x0008 /* don't use tcp options */
103: #define TF_SENTFIN 0x0010 /* have sent FIN */
104: #define TF_REQ_SCALE 0x0020 /* have/will request window scaling */
105: #define TF_RCVD_SCALE 0x0040 /* other side has requested scaling */
106: #define TF_REQ_TSTMP 0x0080 /* have/will request timestamps */
107: #define TF_RCVD_TSTMP 0x0100 /* a timestamp was received in SYN */
108: #define TF_SACK_PERMIT 0x0200 /* other side said I could SACK */
109:
110: struct tcpiphdr *t_template; /* skeletal packet for transmit */
111: struct inpcb *t_inpcb; /* back pointer to internet pcb */
112: /*
113: * The following fields are used as in the protocol specification.
114: * See RFC783, Dec. 1981, page 21.
115: */
116: /* send sequence variables */
117: tcp_seq snd_una; /* send unacknowledged */
118: tcp_seq snd_nxt; /* send next */
119: tcp_seq snd_up; /* send urgent pointer */
120: tcp_seq snd_wl1; /* window update seg seq number */
121: tcp_seq snd_wl2; /* window update seg ack number */
122: tcp_seq iss; /* initial send sequence number */
123: u_long snd_wnd; /* send window */
124: /* receive sequence variables */
125: u_long rcv_wnd; /* receive window */
126: tcp_seq rcv_nxt; /* receive next */
127: tcp_seq rcv_up; /* receive urgent pointer */
128: tcp_seq irs; /* initial receive sequence number */
129: /*
130: * Additional variables for this implementation.
131: */
132: /* receive variables */
133: tcp_seq rcv_adv; /* advertised window */
134: /* retransmit variables */
135: tcp_seq snd_max; /* highest sequence number sent;
136: * used to recognize retransmits
137: */
138: /* congestion control (for slow start, source quench, retransmit after loss) */
139: u_long snd_cwnd; /* congestion-controlled window */
140: u_long snd_ssthresh; /* snd_cwnd size threshhold for
141: * for slow start exponential to
142: * linear switch
143: */
144: /*
145: * transmit timing stuff. See below for scale of srtt and rttvar.
146: * "Variance" is actually smoothed difference.
147: */
148: u_short t_idle; /* inactivity time */
149: short t_rtt; /* round trip time */
150: tcp_seq t_rtseq; /* sequence number being timed */
151: short t_srtt; /* smoothed round-trip time */
152: short t_rttvar; /* variance in round-trip time */
153: u_short t_rttmin; /* minimum rtt allowed */
154: u_long max_sndwnd; /* largest window peer has offered */
155:
156: /* out-of-band data */
157: char t_oobflags; /* have some */
158: char t_iobc; /* input character */
159: #define TCPOOB_HAVEDATA 0x01
160: #define TCPOOB_HADDATA 0x02
161: short t_softerror; /* possible error not yet reported */
162:
163: /* RFC 1323 variables */
164: u_char snd_scale; /* window scaling for send window */
165: u_char rcv_scale; /* window scaling for recv window */
166: u_char request_r_scale; /* pending window scaling */
167: u_char requested_s_scale;
168: u_long ts_recent; /* timestamp echo data */
169: u_long ts_recent_age; /* when last updated */
170: tcp_seq last_ack_sent;
171:
172: /* TUBA stuff */
173: caddr_t t_tuba_pcb; /* next level down pcb for TCP over z */
174: };
175:
176:
177:
178:
179: #define intotcpcb(ip) ((struct tcpcb *)(ip)->inp_ppcb)
180: #define sototcpcb(so) (intotcpcb(sotoinpcb(so)))
181:
182: /*
183: * The smoothed round-trip time and estimated variance
184: * are stored as fixed point numbers scaled by the values below.
185: * For convenience, these scales are also used in smoothing the average
186: * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed).
187: * With these scales, srtt has 3 bits to the right of the binary point,
188: * and thus an "ALPHA" of 0.875. rttvar has 2 bits to the right of the
189: * binary point, and is smoothed with an ALPHA of 0.75.
190: */
191: #define TCP_RTT_SCALE 8 /* multiplier for srtt; 3 bits frac. */
192: #define TCP_RTT_SHIFT 3 /* shift for srtt; 3 bits frac. */
193: #define TCP_RTTVAR_SCALE 4 /* multiplier for rttvar; 2 bits */
194: #define TCP_RTTVAR_SHIFT 2 /* multiplier for rttvar; 2 bits */
195:
196: /*
197: * The initial retransmission should happen at rtt + 4 * rttvar.
198: * Because of the way we do the smoothing, srtt and rttvar
199: * will each average +1/2 tick of bias. When we compute
200: * the retransmit timer, we want 1/2 tick of rounding and
201: * 1 extra tick because of +-1/2 tick uncertainty in the
202: * firing of the timer. The bias will give us exactly the
203: * 1.5 tick we need. But, because the bias is
204: * statistical, we have to test that we don't drop below
205: * the minimum feasible timer (which is 2 ticks).
206: * This macro assumes that the value of TCP_RTTVAR_SCALE
207: * is the same as the multiplier for rttvar.
208: */
209: #define TCP_REXMTVAL(tp) \
210: (((tp)->t_srtt >> TCP_RTT_SHIFT) + (tp)->t_rttvar)
211:
212: /* XXX
213: * We want to avoid doing m_pullup on incoming packets but that
214: * means avoiding dtom on the tcp reassembly code. That in turn means
215: * keeping an mbuf pointer in the reassembly queue (since we might
216: * have a cluster). As a quick hack, the source & destination
217: * port numbers (which are no longer needed once we've located the
218: * tcpcb) are overlayed with an mbuf pointer.
219: */
220: #define REASS_MBUF(ti) (*(struct mbuf **)&((ti)->ti_t))
221:
222: /*
223: * TCP statistics.
224: * Many of these should be kept per connection,
225: * but that's inconvenient at the moment.
226: */
227: struct tcpstat {
228: u_long tcps_connattempt; /* connections initiated */
229: u_long tcps_accepts; /* connections accepted */
230: u_long tcps_connects; /* connections established */
231: u_long tcps_drops; /* connections dropped */
232: u_long tcps_conndrops; /* embryonic connections dropped */
233: u_long tcps_closed; /* conn. closed (includes drops) */
234: u_long tcps_segstimed; /* segs where we tried to get rtt */
235: u_long tcps_rttupdated; /* times we succeeded */
236: u_long tcps_delack; /* delayed acks sent */
237: u_long tcps_timeoutdrop; /* conn. dropped in rxmt timeout */
238: u_long tcps_rexmttimeo; /* retransmit timeouts */
239: u_long tcps_persisttimeo; /* persist timeouts */
240: u_long tcps_keeptimeo; /* keepalive timeouts */
241: u_long tcps_keepprobe; /* keepalive probes sent */
242: u_long tcps_keepdrops; /* connections dropped in keepalive */
243:
244: u_long tcps_sndtotal; /* total packets sent */
245: u_long tcps_sndpack; /* data packets sent */
246: u_long tcps_sndbyte; /* data bytes sent */
247: u_long tcps_sndrexmitpack; /* data packets retransmitted */
248: u_long tcps_sndrexmitbyte; /* data bytes retransmitted */
249: u_long tcps_sndacks; /* ack-only packets sent */
250: u_long tcps_sndprobe; /* window probes sent */
251: u_long tcps_sndurg; /* packets sent with URG only */
252: u_long tcps_sndwinup; /* window update-only packets sent */
253: u_long tcps_sndctrl; /* control (SYN|FIN|RST) packets sent */
254:
255: u_long tcps_rcvtotal; /* total packets received */
256: u_long tcps_rcvpack; /* packets received in sequence */
257: u_long tcps_rcvbyte; /* bytes received in sequence */
258: u_long tcps_rcvbadsum; /* packets received with ccksum errs */
259: u_long tcps_rcvbadoff; /* packets received with bad offset */
260: u_long tcps_rcvshort; /* packets received too short */
261: u_long tcps_rcvduppack; /* duplicate-only packets received */
262: u_long tcps_rcvdupbyte; /* duplicate-only bytes received */
263: u_long tcps_rcvpartduppack; /* packets with some duplicate data */
264: u_long tcps_rcvpartdupbyte; /* dup. bytes in part-dup. packets */
265: u_long tcps_rcvoopack; /* out-of-order packets received */
266: u_long tcps_rcvoobyte; /* out-of-order bytes received */
267: u_long tcps_rcvpackafterwin; /* packets with data after window */
268: u_long tcps_rcvbyteafterwin; /* bytes rcvd after window */
269: u_long tcps_rcvafterclose; /* packets rcvd after "close" */
270: u_long tcps_rcvwinprobe; /* rcvd window probe packets */
271: u_long tcps_rcvdupack; /* rcvd duplicate acks */
272: u_long tcps_rcvacktoomuch; /* rcvd acks for unsent data */
273: u_long tcps_rcvackpack; /* rcvd ack packets */
274: u_long tcps_rcvackbyte; /* bytes acked by rcvd acks */
275: u_long tcps_rcvwinupd; /* rcvd window update packets */
276: u_long tcps_pawsdrop; /* segments dropped due to PAWS */
277: u_long tcps_predack; /* times hdr predict ok for acks */
278: u_long tcps_preddat; /* times hdr predict ok for data pkts */
279: u_long tcps_pcbcachemiss; /* tcp pcb cache misses - no longer used */
280: u_long tcps_persistdrop; /* timeout in persist state */
281: u_long tcps_badsyn; /* bogus SYN, e.g. premature ACK */
282: };
283:
284: #ifdef _KERNEL
285: extern struct inpcb tcb; /* head of queue of active tcpcb's */
286: extern struct tcpstat tcpstat; /* tcp statistics */
287: extern u_long tcp_now; /* for RFC 1323 timestamps */
288:
289: int tcp_attach __P((struct socket *));
290: void tcp_canceltimers __P((struct tcpcb *));
291: struct tcpcb *
292: tcp_close __P((struct tcpcb *));
293: void tcp_ctlinput __P((int, struct sockaddr *, struct ip *));
294: int tcp_ctloutput __P((int, struct socket *, int, int, struct mbuf **));
295: struct tcpcb *
296: tcp_disconnect __P((struct tcpcb *));
297: struct tcpcb *
298: tcp_drop __P((struct tcpcb *, int));
299: void tcp_dooptions __P((struct tcpcb *,
300: u_char *, int, struct tcpiphdr *, int *, u_long *, u_long *));
301: void tcp_drain __P((void));
302: void tcp_fasttimo __P((void));
303: void tcp_init __P((void));
304: void tcp_input __P((struct mbuf *, int));
305: int tcp_mss __P((struct tcpcb *, u_int));
306: struct tcpcb *
307: tcp_newtcpcb __P((struct inpcb *));
308: void tcp_notify __P((struct inpcb *, int));
309: int tcp_output __P((struct tcpcb *));
310: void tcp_pulloutofband __P((struct socket *,
311: struct tcpiphdr *, struct mbuf *));
312: void tcp_quench __P((struct inpcb *, int));
313: int tcp_reass __P((struct tcpcb *, struct tcpiphdr *, struct mbuf *));
314: void tcp_respond __P((struct tcpcb *,
315: struct tcpiphdr *, struct mbuf *, u_long, u_long, int));
316: void tcp_setpersist __P((struct tcpcb *));
317: void tcp_slowtimo __P((void));
318: struct tcpiphdr *
319: tcp_template __P((struct tcpcb *));
320: struct tcpcb *
321: tcp_timers __P((struct tcpcb *, int));
322: void tcp_trace __P((int, int, struct tcpcb *, struct tcpiphdr *, int));
323: struct tcpcb *
324: tcp_usrclosed __P((struct tcpcb *));
325: int tcp_usrreq __P((struct socket *,
326: int, struct mbuf *, struct mbuf *, struct mbuf *));
327: void tcp_xmit_timer __P((struct tcpcb *, int));
328: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.