]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
2d21ac55 | 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. |
5d5c5d0d | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * Copyright (c) 1982, 1986, 1993, 1994, 1995 | |
30 | * The Regents of the University of California. All rights reserved. | |
31 | * | |
32 | * Redistribution and use in source and binary forms, with or without | |
33 | * modification, are permitted provided that the following conditions | |
34 | * are met: | |
35 | * 1. Redistributions of source code must retain the above copyright | |
36 | * notice, this list of conditions and the following disclaimer. | |
37 | * 2. Redistributions in binary form must reproduce the above copyright | |
38 | * notice, this list of conditions and the following disclaimer in the | |
39 | * documentation and/or other materials provided with the distribution. | |
40 | * 3. All advertising materials mentioning features or use of this software | |
41 | * must display the following acknowledgement: | |
42 | * This product includes software developed by the University of | |
43 | * California, Berkeley and its contributors. | |
44 | * 4. Neither the name of the University nor the names of its contributors | |
45 | * may be used to endorse or promote products derived from this software | |
46 | * without specific prior written permission. | |
47 | * | |
48 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
49 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
50 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
51 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
54 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
55 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
58 | * SUCH DAMAGE. | |
59 | * | |
60 | * @(#)tcp_var.h 8.4 (Berkeley) 5/24/95 | |
9bccf70c | 61 | * $FreeBSD: src/sys/netinet/tcp_var.h,v 1.56.2.8 2001/08/22 00:59:13 silby Exp $ |
1c79356b A |
62 | */ |
63 | ||
64 | #ifndef _NETINET_TCP_VAR_H_ | |
65 | #define _NETINET_TCP_VAR_H_ | |
9bccf70c | 66 | #include <sys/appleapiopts.h> |
91447636 A |
67 | #include <sys/queue.h> |
68 | #include <netinet/in_pcb.h> | |
9bccf70c | 69 | #include <netinet/tcp_timer.h> |
91447636 | 70 | |
2d21ac55 A |
71 | #if defined(__LP64__) |
72 | #define _TCPCB_PTR(x) u_int32_t | |
73 | #define _TCPCB_LIST_HEAD(name, type) \ | |
74 | struct name { \ | |
75 | u_int32_t lh_first; \ | |
76 | }; | |
77 | #else | |
78 | #define _TCPCB_PTR(x) x | |
79 | #define _TCPCB_LIST_HEAD(name, type) LIST_HEAD(name, type) | |
80 | #endif | |
81 | ||
82 | #define TCP_RETRANSHZ 10 /* tcp retrans timer (100ms) per hz */ | |
9bccf70c | 83 | |
2d21ac55 A |
84 | #ifdef KERNEL_PRIVATE |
85 | #define N_TIME_WAIT_SLOTS 128 /* must be power of 2 */ | |
1c79356b A |
86 | |
87 | /* | |
9bccf70c | 88 | * Kernel variables for tcp. |
1c79356b | 89 | */ |
9bccf70c A |
90 | |
91 | /* TCP segment queue entry */ | |
92 | struct tseg_qent { | |
93 | LIST_ENTRY(tseg_qent) tqe_q; | |
94 | int tqe_len; /* TCP segment data length */ | |
95 | struct tcphdr *tqe_th; /* a pointer to tcp header */ | |
96 | struct mbuf *tqe_m; /* mbuf contains packet */ | |
1c79356b | 97 | }; |
9bccf70c | 98 | LIST_HEAD(tsegqe_head, tseg_qent); |
e5568f75 A |
99 | extern int tcp_reass_maxseg; |
100 | extern int tcp_reass_qsize; | |
9bccf70c A |
101 | #ifdef MALLOC_DECLARE |
102 | MALLOC_DECLARE(M_TSEGQ); | |
1c79356b | 103 | #endif |
9bccf70c | 104 | |
8ad349bb A |
105 | struct sackblk { |
106 | tcp_seq start; /* start seq no. of sack block */ | |
107 | tcp_seq end; /* end seq no. */ | |
108 | }; | |
109 | ||
110 | struct sackhole { | |
111 | tcp_seq start; /* start seq no. of hole */ | |
112 | tcp_seq end; /* end seq no. */ | |
113 | tcp_seq rxmit; /* next seq. no in hole to be retransmitted */ | |
114 | TAILQ_ENTRY(sackhole) scblink; /* scoreboard linkage */ | |
115 | }; | |
116 | ||
117 | struct sackhint { | |
118 | struct sackhole *nexthole; | |
119 | int sack_bytes_rexmit; | |
120 | }; | |
121 | ||
9bccf70c A |
122 | struct tcptemp { |
123 | u_char tt_ipgen[40]; /* the size must be of max ip header, now IPv6 */ | |
124 | struct tcphdr tt_t; | |
125 | }; | |
126 | ||
1c79356b A |
127 | #define tcp6cb tcpcb /* for KAME src sync over BSD*'s */ |
128 | ||
1c79356b A |
129 | /* |
130 | * Tcp control block, one per tcp; fields: | |
131 | * Organized for 16 byte cacheline efficiency. | |
132 | */ | |
133 | struct tcpcb { | |
9bccf70c | 134 | struct tsegqe_head t_segq; |
1c79356b | 135 | int t_dupacks; /* consecutive dup acks recd */ |
9bccf70c | 136 | struct tcptemp *unused; /* unused now: was t_template */ |
1c79356b A |
137 | |
138 | int t_timer[TCPT_NTIMERS]; /* tcp timers */ | |
139 | ||
140 | struct inpcb *t_inpcb; /* back pointer to internet pcb */ | |
141 | int t_state; /* state of this connection */ | |
142 | u_int t_flags; | |
143 | #define TF_ACKNOW 0x00001 /* ack peer immediately */ | |
144 | #define TF_DELACK 0x00002 /* ack, but try to delay it */ | |
145 | #define TF_NODELAY 0x00004 /* don't delay packets to coalesce */ | |
146 | #define TF_NOOPT 0x00008 /* don't use tcp options */ | |
147 | #define TF_SENTFIN 0x00010 /* have sent FIN */ | |
148 | #define TF_REQ_SCALE 0x00020 /* have/will request window scaling */ | |
149 | #define TF_RCVD_SCALE 0x00040 /* other side has requested scaling */ | |
150 | #define TF_REQ_TSTMP 0x00080 /* have/will request timestamps */ | |
151 | #define TF_RCVD_TSTMP 0x00100 /* a timestamp was received in SYN */ | |
152 | #define TF_SACK_PERMIT 0x00200 /* other side said I could SACK */ | |
153 | #define TF_NEEDSYN 0x00400 /* send SYN (implicit state) */ | |
154 | #define TF_NEEDFIN 0x00800 /* send FIN (implicit state) */ | |
155 | #define TF_NOPUSH 0x01000 /* don't push */ | |
156 | #define TF_REQ_CC 0x02000 /* have/will request CC */ | |
157 | #define TF_RCVD_CC 0x04000 /* a CC was received in SYN */ | |
158 | #define TF_SENDCCNEW 0x08000 /* send CCnew instead of CC in SYN */ | |
159 | #define TF_MORETOCOME 0x10000 /* More data to be appended to sock */ | |
2d21ac55 | 160 | #define TF_LQ_OVERFLOW 0x20000 /* UNUSED listen queue overflow */ |
9bccf70c | 161 | #define TF_RXWIN0SENT 0x40000 /* sent a receiver win 0 in response */ |
d12e1678 | 162 | #define TF_SLOWLINK 0x80000 /* route is a on a modem speed link */ |
9bccf70c | 163 | |
8ad349bb | 164 | |
2d21ac55 | 165 | #define TF_LASTIDLE 0x100000 /* connection was previously idle */ |
8ad349bb A |
166 | #define TF_FASTRECOVERY 0x200000 /* in NewReno Fast Recovery */ |
167 | #define TF_WASFRECOVERY 0x400000 /* was in NewReno Fast Recovery */ | |
168 | #define TF_SIGNATURE 0x800000 /* require MD5 digests (RFC2385) */ | |
169 | #define TF_MAXSEGSNT 0x1000000 /* last segment sent was a full segment */ | |
2d21ac55 A |
170 | #define TF_SENDINPROG 0x2000000 /* send is in progress */ |
171 | #define TF_PMTUD 0x4000000 /* Perform Path MTU Discovery for this connection */ | |
172 | #define TF_CLOSING 0x8000000 /* pending tcp close */ | |
8ad349bb | 173 | |
1c79356b A |
174 | int t_force; /* 1 if forcing out a byte */ |
175 | ||
176 | tcp_seq snd_una; /* send unacknowledged */ | |
177 | tcp_seq snd_max; /* highest sequence number sent; | |
178 | * used to recognize retransmits | |
179 | */ | |
180 | tcp_seq snd_nxt; /* send next */ | |
181 | tcp_seq snd_up; /* send urgent pointer */ | |
182 | ||
183 | tcp_seq snd_wl1; /* window update seg seq number */ | |
184 | tcp_seq snd_wl2; /* window update seg ack number */ | |
185 | tcp_seq iss; /* initial send sequence number */ | |
186 | tcp_seq irs; /* initial receive sequence number */ | |
187 | ||
188 | tcp_seq rcv_nxt; /* receive next */ | |
189 | tcp_seq rcv_adv; /* advertised window */ | |
190 | u_long rcv_wnd; /* receive window */ | |
191 | tcp_seq rcv_up; /* receive urgent pointer */ | |
192 | ||
193 | u_long snd_wnd; /* send window */ | |
194 | u_long snd_cwnd; /* congestion-controlled window */ | |
2d21ac55 | 195 | u_long snd_bwnd; /* bandwidth-controlled window */ |
1c79356b A |
196 | u_long snd_ssthresh; /* snd_cwnd size threshold for |
197 | * for slow start exponential to | |
198 | * linear switch | |
199 | */ | |
2d21ac55 A |
200 | u_long snd_bandwidth; /* calculated bandwidth or 0 */ |
201 | tcp_seq snd_recover; /* for use in NewReno Fast Recovery */ | |
202 | ||
1c79356b A |
203 | u_int t_maxopd; /* mss plus options */ |
204 | ||
9bccf70c A |
205 | u_long t_rcvtime; /* inactivity time */ |
206 | u_long t_starttime; /* time connection was established */ | |
207 | int t_rtttime; /* round trip time */ | |
1c79356b A |
208 | tcp_seq t_rtseq; /* sequence number being timed */ |
209 | ||
2d21ac55 A |
210 | int t_bw_rtttime; /* used for bandwidth calculation */ |
211 | tcp_seq t_bw_rtseq; /* used for bandwidth calculation */ | |
212 | ||
9bccf70c | 213 | int t_rxtcur; /* current retransmit value (ticks) */ |
1c79356b A |
214 | u_int t_maxseg; /* maximum segment size */ |
215 | int t_srtt; /* smoothed round-trip time */ | |
216 | int t_rttvar; /* variance in round-trip time */ | |
217 | ||
218 | int t_rxtshift; /* log(2) of rexmt exp. backoff */ | |
219 | u_int t_rttmin; /* minimum rtt allowed */ | |
2d21ac55 | 220 | u_int t_rttbest; /* best rtt we've seen */ |
1c79356b A |
221 | u_long t_rttupdated; /* number of times rtt sampled */ |
222 | u_long max_sndwnd; /* largest window peer has offered */ | |
223 | ||
224 | int t_softerror; /* possible error not yet reported */ | |
225 | /* out-of-band data */ | |
226 | char t_oobflags; /* have some */ | |
227 | char t_iobc; /* input character */ | |
228 | #define TCPOOB_HAVEDATA 0x01 | |
229 | #define TCPOOB_HADDATA 0x02 | |
230 | /* RFC 1323 variables */ | |
231 | u_char snd_scale; /* window scaling for send window */ | |
232 | u_char rcv_scale; /* window scaling for recv window */ | |
233 | u_char request_r_scale; /* pending window scaling */ | |
234 | u_char requested_s_scale; | |
235 | u_long ts_recent; /* timestamp echo data */ | |
236 | ||
237 | u_long ts_recent_age; /* when last updated */ | |
238 | tcp_seq last_ack_sent; | |
239 | /* RFC 1644 variables */ | |
240 | tcp_cc cc_send; /* send connection count */ | |
241 | tcp_cc cc_recv; /* receive connection count */ | |
2d21ac55 A |
242 | /* RFC 3465 variables */ |
243 | u_long t_bytes_acked; /* ABC "bytes_acked" parameter */ | |
9bccf70c A |
244 | /* experimental */ |
245 | u_long snd_cwnd_prev; /* cwnd prior to retransmit */ | |
246 | u_long snd_ssthresh_prev; /* ssthresh prior to retransmit */ | |
247 | u_long t_badrxtwin; /* window for retransmit recovery */ | |
55e303ae A |
248 | |
249 | int t_keepidle; /* keepalive idle timer (override global if > 0) */ | |
91447636 | 250 | int t_lastchain; /* amount of packets chained last time around */ |
2d21ac55 A |
251 | int t_unacksegs; /* received but unacked segments: used for delaying acks */ |
252 | ||
91447636 A |
253 | |
254 | /* 3529618 MSS overload prevention */ | |
255 | u_long rcv_reset; | |
256 | u_long rcv_pps; | |
257 | u_long rcv_byps; | |
2d21ac55 | 258 | u_long rcv_maxbyps; |
91447636 A |
259 | tcp_seq snd_high; /* for use in NewReno Fast Recovery */ |
260 | tcp_seq snd_high_prev; /* snd_high prior to retransmit */ | |
261 | ||
8ad349bb A |
262 | tcp_seq snd_recover_prev; /* snd_recover prior to retransmit */ |
263 | u_char snd_limited; /* segments limited transmitted */ | |
264 | /* anti DoS counters */ | |
265 | u_long rcv_second; /* start of interval second */ | |
266 | /* SACK related state */ | |
267 | int sack_enable; /* enable SACK for this connection */ | |
268 | int snd_numholes; /* number of holes seen by sender */ | |
269 | ||
270 | TAILQ_HEAD(sackhole_head, sackhole) snd_holes; | |
271 | /* SACK scoreboard (sorted) */ | |
272 | tcp_seq snd_fack; /* last seq number(+1) sack'd by rcv'r*/ | |
273 | int rcv_numsacks; /* # distinct sack blks present */ | |
274 | struct sackblk sackblks[MAX_SACK_BLKS]; /* seq nos. of sack blocks */ | |
275 | tcp_seq sack_newdata; /* New data xmitted in this recovery | |
276 | episode starts at this seq number */ | |
277 | struct sackhint sackhint; /* SACK scoreboard hint */ | |
278 | int t_rttlow; /* smallest observerved RTT */ | |
2d21ac55 A |
279 | u_long ecn_flags; |
280 | #define TE_SETUPSENT 0x01 /* Indicate we have sent ECN-SETUP SYN or SYN-ACK */ | |
281 | #define TE_SETUPRECEIVED 0x02 /* Indicate we have received ECN-SETUP SYN or SYN-ACK */ | |
282 | #define TE_SENDIPECT 0x04 /* Indicate we haven't sent or received non-ECN-setup SYN or SYN-ACK */ | |
283 | #define TE_SENDCWR 0x08 /* Indicate that the next non-retransmit should have the TCP CWR flag set */ | |
284 | #define TE_SENDECE 0x10 /* Indicate that the next packet should have the TCP ECE flag set */ | |
285 | ||
286 | #if TRAFFIC_MGT | |
287 | u_int32_t tot_recv_snapshot; /* snapshot of global total pkts received */ | |
288 | u_int32_t bg_recv_snapshot; /* snapshot of global background pkts received */ | |
289 | #endif /* TRAFFIC_MGT */ | |
290 | u_int32_t t_pktlist_sentlen; /* total bytes in transmit chain */ | |
291 | struct mbuf *t_pktlist_head; /* First packet in transmit chain */ | |
292 | struct mbuf *t_pktlist_tail; /* Last packet in transmit chain */ | |
55e303ae | 293 | }; |
55e303ae | 294 | |
8ad349bb A |
295 | #define IN_FASTRECOVERY(tp) (tp->t_flags & TF_FASTRECOVERY) |
296 | #define ENTER_FASTRECOVERY(tp) tp->t_flags |= TF_FASTRECOVERY | |
297 | #define EXIT_FASTRECOVERY(tp) tp->t_flags &= ~TF_FASTRECOVERY | |
298 | ||
299 | ||
91447636 A |
300 | /* |
301 | * Structure to hold TCP options that are only used during segment | |
302 | * processing (in tcp_input), but not held in the tcpcb. | |
303 | * It's basically used to reduce the number of parameters | |
304 | * to tcp_dooptions. | |
305 | */ | |
306 | struct tcpopt { | |
8ad349bb | 307 | u_long to_flags; /* which options are present */ |
91447636 | 308 | #define TOF_TS 0x0001 /* timestamp */ |
8ad349bb A |
309 | #define TOF_MSS 0x0010 |
310 | #define TOF_SCALE 0x0020 | |
311 | #define TOF_SIGNATURE 0x0040 /* signature option present */ | |
312 | #define TOF_SIGLEN 0x0080 /* signature length valid (RFC2385) */ | |
313 | #define TOF_SACK 0x0100 /* Peer sent SACK option */ | |
314 | u_long to_tsval; | |
315 | u_long to_tsecr; | |
316 | u_int16_t to_mss; | |
317 | u_int8_t to_requested_s_scale; | |
318 | u_int8_t to_nsacks; /* number of SACK blocks */ | |
319 | u_char *to_sacks; /* pointer to the first SACK blocks */ | |
91447636 | 320 | }; |
55e303ae | 321 | |
91447636 A |
322 | /* |
323 | * The TAO cache entry which is stored in the protocol family specific | |
324 | * portion of the route metrics. | |
325 | */ | |
326 | struct rmxp_tao { | |
327 | tcp_cc tao_cc; /* latest CC in valid SYN */ | |
328 | tcp_cc tao_ccsent; /* latest CC sent to peer */ | |
329 | u_short tao_mssopt; /* peer's cached MSS */ | |
330 | #ifdef notyet | |
331 | u_short tao_flags; /* cache status flags */ | |
332 | #define TAOF_DONT 0x0001 /* peer doesn't understand rfc1644 */ | |
333 | #define TAOF_OK 0x0002 /* peer does understand rfc1644 */ | |
334 | #define TAOF_UNDEF 0 /* we don't know yet */ | |
335 | #endif /* notyet */ | |
336 | }; | |
337 | #define rmx_taop(r) ((struct rmxp_tao *)(r).rmx_filler) | |
338 | ||
339 | #define intotcpcb(ip) ((struct tcpcb *)(ip)->inp_ppcb) | |
340 | #define sototcpcb(so) (intotcpcb(sotoinpcb(so))) | |
55e303ae | 341 | |
91447636 A |
342 | /* |
343 | * The smoothed round-trip time and estimated variance | |
344 | * are stored as fixed point numbers scaled by the values below. | |
345 | * For convenience, these scales are also used in smoothing the average | |
346 | * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed). | |
347 | * With these scales, srtt has 3 bits to the right of the binary point, | |
348 | * and thus an "ALPHA" of 0.875. rttvar has 2 bits to the right of the | |
349 | * binary point, and is smoothed with an ALPHA of 0.75. | |
350 | */ | |
351 | #define TCP_RTT_SCALE 32 /* multiplier for srtt; 3 bits frac. */ | |
352 | #define TCP_RTT_SHIFT 5 /* shift for srtt; 3 bits frac. */ | |
353 | #define TCP_RTTVAR_SCALE 16 /* multiplier for rttvar; 2 bits */ | |
354 | #define TCP_RTTVAR_SHIFT 4 /* shift for rttvar; 2 bits */ | |
355 | #define TCP_DELTA_SHIFT 2 /* see tcp_input.c */ | |
356 | ||
357 | /* | |
358 | * The initial retransmission should happen at rtt + 4 * rttvar. | |
359 | * Because of the way we do the smoothing, srtt and rttvar | |
360 | * will each average +1/2 tick of bias. When we compute | |
361 | * the retransmit timer, we want 1/2 tick of rounding and | |
362 | * 1 extra tick because of +-1/2 tick uncertainty in the | |
363 | * firing of the timer. The bias will give us exactly the | |
364 | * 1.5 tick we need. But, because the bias is | |
365 | * statistical, we have to test that we don't drop below | |
366 | * the minimum feasible timer (which is 2 ticks). | |
367 | * This version of the macro adapted from a paper by Lawrence | |
368 | * Brakmo and Larry Peterson which outlines a problem caused | |
369 | * by insufficient precision in the original implementation, | |
370 | * which results in inappropriately large RTO values for very | |
371 | * fast networks. | |
372 | */ | |
373 | #define TCP_REXMTVAL(tp) \ | |
374 | max((tp)->t_rttmin, (((tp)->t_srtt >> (TCP_RTT_SHIFT - TCP_DELTA_SHIFT)) \ | |
375 | + (tp)->t_rttvar) >> TCP_DELTA_SHIFT) | |
55e303ae A |
376 | |
377 | /* | |
378 | * Jaguar compatible TCP control block, for xtcpcb | |
379 | * Does not have the old fields | |
380 | */ | |
381 | struct otcpcb { | |
91447636 A |
382 | #else |
383 | struct tseg_qent; | |
2d21ac55 | 384 | _TCPCB_LIST_HEAD(tsegqe_head, tseg_qent); |
91447636 A |
385 | |
386 | struct tcpcb { | |
387 | #endif /* KERNEL_PRIVATE */ | |
55e303ae A |
388 | struct tsegqe_head t_segq; |
389 | int t_dupacks; /* consecutive dup acks recd */ | |
2d21ac55 | 390 | u_int32_t unused; /* unused now: was t_template */ |
55e303ae A |
391 | |
392 | int t_timer[TCPT_NTIMERS]; /* tcp timers */ | |
393 | ||
2d21ac55 | 394 | _TCPCB_PTR(struct inpcb *) t_inpcb; /* back pointer to internet pcb */ |
55e303ae A |
395 | int t_state; /* state of this connection */ |
396 | u_int t_flags; | |
397 | #define TF_ACKNOW 0x00001 /* ack peer immediately */ | |
398 | #define TF_DELACK 0x00002 /* ack, but try to delay it */ | |
399 | #define TF_NODELAY 0x00004 /* don't delay packets to coalesce */ | |
400 | #define TF_NOOPT 0x00008 /* don't use tcp options */ | |
401 | #define TF_SENTFIN 0x00010 /* have sent FIN */ | |
402 | #define TF_REQ_SCALE 0x00020 /* have/will request window scaling */ | |
403 | #define TF_RCVD_SCALE 0x00040 /* other side has requested scaling */ | |
404 | #define TF_REQ_TSTMP 0x00080 /* have/will request timestamps */ | |
405 | #define TF_RCVD_TSTMP 0x00100 /* a timestamp was received in SYN */ | |
406 | #define TF_SACK_PERMIT 0x00200 /* other side said I could SACK */ | |
407 | #define TF_NEEDSYN 0x00400 /* send SYN (implicit state) */ | |
408 | #define TF_NEEDFIN 0x00800 /* send FIN (implicit state) */ | |
409 | #define TF_NOPUSH 0x01000 /* don't push */ | |
410 | #define TF_REQ_CC 0x02000 /* have/will request CC */ | |
411 | #define TF_RCVD_CC 0x04000 /* a CC was received in SYN */ | |
412 | #define TF_SENDCCNEW 0x08000 /* send CCnew instead of CC in SYN */ | |
413 | #define TF_MORETOCOME 0x10000 /* More data to be appended to sock */ | |
414 | #define TF_LQ_OVERFLOW 0x20000 /* listen queue overflow */ | |
415 | #define TF_RXWIN0SENT 0x40000 /* sent a receiver win 0 in response */ | |
416 | #define TF_SLOWLINK 0x80000 /* route is a on a modem speed link */ | |
417 | ||
418 | int t_force; /* 1 if forcing out a byte */ | |
419 | ||
420 | tcp_seq snd_una; /* send unacknowledged */ | |
421 | tcp_seq snd_max; /* highest sequence number sent; | |
422 | * used to recognize retransmits | |
423 | */ | |
424 | tcp_seq snd_nxt; /* send next */ | |
425 | tcp_seq snd_up; /* send urgent pointer */ | |
426 | ||
427 | tcp_seq snd_wl1; /* window update seg seq number */ | |
428 | tcp_seq snd_wl2; /* window update seg ack number */ | |
429 | tcp_seq iss; /* initial send sequence number */ | |
430 | tcp_seq irs; /* initial receive sequence number */ | |
431 | ||
432 | tcp_seq rcv_nxt; /* receive next */ | |
433 | tcp_seq rcv_adv; /* advertised window */ | |
2d21ac55 | 434 | u_int32_t rcv_wnd; /* receive window */ |
55e303ae A |
435 | tcp_seq rcv_up; /* receive urgent pointer */ |
436 | ||
2d21ac55 A |
437 | u_int32_t snd_wnd; /* send window */ |
438 | u_int32_t snd_cwnd; /* congestion-controlled window */ | |
439 | u_int32_t snd_ssthresh; /* snd_cwnd size threshold for | |
55e303ae A |
440 | * for slow start exponential to |
441 | * linear switch | |
442 | */ | |
443 | u_int t_maxopd; /* mss plus options */ | |
444 | ||
2d21ac55 A |
445 | u_int32_t t_rcvtime; /* inactivity time */ |
446 | u_int32_t t_starttime; /* time connection was established */ | |
55e303ae A |
447 | int t_rtttime; /* round trip time */ |
448 | tcp_seq t_rtseq; /* sequence number being timed */ | |
449 | ||
450 | int t_rxtcur; /* current retransmit value (ticks) */ | |
451 | u_int t_maxseg; /* maximum segment size */ | |
452 | int t_srtt; /* smoothed round-trip time */ | |
453 | int t_rttvar; /* variance in round-trip time */ | |
454 | ||
455 | int t_rxtshift; /* log(2) of rexmt exp. backoff */ | |
456 | u_int t_rttmin; /* minimum rtt allowed */ | |
2d21ac55 A |
457 | u_int32_t t_rttupdated; /* number of times rtt sampled */ |
458 | u_int32_t max_sndwnd; /* largest window peer has offered */ | |
55e303ae A |
459 | |
460 | int t_softerror; /* possible error not yet reported */ | |
461 | /* out-of-band data */ | |
462 | char t_oobflags; /* have some */ | |
463 | char t_iobc; /* input character */ | |
464 | #define TCPOOB_HAVEDATA 0x01 | |
465 | #define TCPOOB_HADDATA 0x02 | |
466 | /* RFC 1323 variables */ | |
467 | u_char snd_scale; /* window scaling for send window */ | |
468 | u_char rcv_scale; /* window scaling for recv window */ | |
469 | u_char request_r_scale; /* pending window scaling */ | |
470 | u_char requested_s_scale; | |
2d21ac55 | 471 | u_int32_t ts_recent; /* timestamp echo data */ |
55e303ae | 472 | |
2d21ac55 | 473 | u_int32_t ts_recent_age; /* when last updated */ |
55e303ae A |
474 | tcp_seq last_ack_sent; |
475 | /* RFC 1644 variables */ | |
476 | tcp_cc cc_send; /* send connection count */ | |
477 | tcp_cc cc_recv; /* receive connection count */ | |
2d21ac55 | 478 | tcp_seq snd_recover; /* for use in fast recovery */ |
55e303ae | 479 | /* experimental */ |
2d21ac55 A |
480 | u_int32_t snd_cwnd_prev; /* cwnd prior to retransmit */ |
481 | u_int32_t snd_ssthresh_prev; /* ssthresh prior to retransmit */ | |
482 | u_int32_t t_badrxtwin; /* window for retransmit recovery */ | |
1c79356b A |
483 | }; |
484 | ||
1c79356b A |
485 | /* |
486 | * TCP statistics. | |
487 | * Many of these should be kept per connection, | |
488 | * but that's inconvenient at the moment. | |
489 | */ | |
490 | struct tcpstat { | |
2d21ac55 A |
491 | u_int32_t tcps_connattempt; /* connections initiated */ |
492 | u_int32_t tcps_accepts; /* connections accepted */ | |
493 | u_int32_t tcps_connects; /* connections established */ | |
494 | u_int32_t tcps_drops; /* connections dropped */ | |
495 | u_int32_t tcps_conndrops; /* embryonic connections dropped */ | |
496 | u_int32_t tcps_closed; /* conn. closed (includes drops) */ | |
497 | u_int32_t tcps_segstimed; /* segs where we tried to get rtt */ | |
498 | u_int32_t tcps_rttupdated; /* times we succeeded */ | |
499 | u_int32_t tcps_delack; /* delayed acks sent */ | |
500 | u_int32_t tcps_timeoutdrop; /* conn. dropped in rxmt timeout */ | |
501 | u_int32_t tcps_rexmttimeo; /* retransmit timeouts */ | |
502 | u_int32_t tcps_persisttimeo; /* persist timeouts */ | |
503 | u_int32_t tcps_keeptimeo; /* keepalive timeouts */ | |
504 | u_int32_t tcps_keepprobe; /* keepalive probes sent */ | |
505 | u_int32_t tcps_keepdrops; /* connections dropped in keepalive */ | |
506 | ||
507 | u_int32_t tcps_sndtotal; /* total packets sent */ | |
508 | u_int32_t tcps_sndpack; /* data packets sent */ | |
509 | u_int32_t tcps_sndbyte; /* data bytes sent */ | |
510 | u_int32_t tcps_sndrexmitpack; /* data packets retransmitted */ | |
511 | u_int32_t tcps_sndrexmitbyte; /* data bytes retransmitted */ | |
512 | u_int32_t tcps_sndacks; /* ack-only packets sent */ | |
513 | u_int32_t tcps_sndprobe; /* window probes sent */ | |
514 | u_int32_t tcps_sndurg; /* packets sent with URG only */ | |
515 | u_int32_t tcps_sndwinup; /* window update-only packets sent */ | |
516 | u_int32_t tcps_sndctrl; /* control (SYN|FIN|RST) packets sent */ | |
517 | ||
518 | u_int32_t tcps_rcvtotal; /* total packets received */ | |
519 | u_int32_t tcps_rcvpack; /* packets received in sequence */ | |
520 | u_int32_t tcps_rcvbyte; /* bytes received in sequence */ | |
521 | u_int32_t tcps_rcvbadsum; /* packets received with ccksum errs */ | |
522 | u_int32_t tcps_rcvbadoff; /* packets received with bad offset */ | |
523 | u_int32_t tcps_rcvmemdrop; /* packets dropped for lack of memory */ | |
524 | u_int32_t tcps_rcvshort; /* packets received too short */ | |
525 | u_int32_t tcps_rcvduppack; /* duplicate-only packets received */ | |
526 | u_int32_t tcps_rcvdupbyte; /* duplicate-only bytes received */ | |
527 | u_int32_t tcps_rcvpartduppack; /* packets with some duplicate data */ | |
528 | u_int32_t tcps_rcvpartdupbyte; /* dup. bytes in part-dup. packets */ | |
529 | u_int32_t tcps_rcvoopack; /* out-of-order packets received */ | |
530 | u_int32_t tcps_rcvoobyte; /* out-of-order bytes received */ | |
531 | u_int32_t tcps_rcvpackafterwin; /* packets with data after window */ | |
532 | u_int32_t tcps_rcvbyteafterwin; /* bytes rcvd after window */ | |
533 | u_int32_t tcps_rcvafterclose; /* packets rcvd after "close" */ | |
534 | u_int32_t tcps_rcvwinprobe; /* rcvd window probe packets */ | |
535 | u_int32_t tcps_rcvdupack; /* rcvd duplicate acks */ | |
536 | u_int32_t tcps_rcvacktoomuch; /* rcvd acks for unsent data */ | |
537 | u_int32_t tcps_rcvackpack; /* rcvd ack packets */ | |
538 | u_int32_t tcps_rcvackbyte; /* bytes acked by rcvd acks */ | |
539 | u_int32_t tcps_rcvwinupd; /* rcvd window update packets */ | |
540 | u_int32_t tcps_pawsdrop; /* segments dropped due to PAWS */ | |
541 | u_int32_t tcps_predack; /* times hdr predict ok for acks */ | |
542 | u_int32_t tcps_preddat; /* times hdr predict ok for data pkts */ | |
543 | u_int32_t tcps_pcbcachemiss; | |
544 | u_int32_t tcps_cachedrtt; /* times cached RTT in route updated */ | |
545 | u_int32_t tcps_cachedrttvar; /* times cached rttvar updated */ | |
546 | u_int32_t tcps_cachedssthresh; /* times cached ssthresh updated */ | |
547 | u_int32_t tcps_usedrtt; /* times RTT initialized from route */ | |
548 | u_int32_t tcps_usedrttvar; /* times RTTVAR initialized from rt */ | |
549 | u_int32_t tcps_usedssthresh; /* times ssthresh initialized from rt*/ | |
550 | u_int32_t tcps_persistdrop; /* timeout in persist state */ | |
551 | u_int32_t tcps_badsyn; /* bogus SYN, e.g. premature ACK */ | |
552 | u_int32_t tcps_mturesent; /* resends due to MTU discovery */ | |
553 | u_int32_t tcps_listendrop; /* listen queue overflows */ | |
554 | ||
555 | /* new stats from FreeBSD 5.4 sync up */ | |
556 | u_int32_t tcps_minmssdrops; /* average minmss too low drops */ | |
557 | u_int32_t tcps_sndrexmitbad; /* unnecessary packet retransmissions */ | |
558 | u_int32_t tcps_badrst; /* ignored RSTs in the window */ | |
559 | ||
560 | u_int32_t tcps_sc_added; /* entry added to syncache */ | |
561 | u_int32_t tcps_sc_retransmitted; /* syncache entry was retransmitted */ | |
562 | u_int32_t tcps_sc_dupsyn; /* duplicate SYN packet */ | |
563 | u_int32_t tcps_sc_dropped; /* could not reply to packet */ | |
564 | u_int32_t tcps_sc_completed; /* successful extraction of entry */ | |
565 | u_int32_t tcps_sc_bucketoverflow; /* syncache per-bucket limit hit */ | |
566 | u_int32_t tcps_sc_cacheoverflow; /* syncache cache limit hit */ | |
567 | u_int32_t tcps_sc_reset; /* RST removed entry from syncache */ | |
568 | u_int32_t tcps_sc_stale; /* timed out or listen socket gone */ | |
569 | u_int32_t tcps_sc_aborted; /* syncache entry aborted */ | |
570 | u_int32_t tcps_sc_badack; /* removed due to bad ACK */ | |
571 | u_int32_t tcps_sc_unreach; /* ICMP unreachable received */ | |
572 | u_int32_t tcps_sc_zonefail; /* zalloc() failed */ | |
573 | u_int32_t tcps_sc_sendcookie; /* SYN cookie sent */ | |
574 | u_int32_t tcps_sc_recvcookie; /* SYN cookie received */ | |
575 | ||
576 | u_int32_t tcps_hc_added; /* entry added to hostcache */ | |
577 | u_int32_t tcps_hc_bucketoverflow; /* hostcache per bucket limit hit */ | |
8ad349bb A |
578 | |
579 | /* SACK related stats */ | |
2d21ac55 A |
580 | u_int32_t tcps_sack_recovery_episode; /* SACK recovery episodes */ |
581 | u_int32_t tcps_sack_rexmits; /* SACK rexmit segments */ | |
582 | u_int32_t tcps_sack_rexmit_bytes; /* SACK rexmit bytes */ | |
583 | u_int32_t tcps_sack_rcv_blocks; /* SACK blocks (options) received */ | |
584 | u_int32_t tcps_sack_send_blocks; /* SACK blocks (options) sent */ | |
585 | u_int32_t tcps_sack_sboverflow; /* SACK sendblock overflow */ | |
586 | ||
587 | #if TRAFFIC_MGT | |
588 | u_int32_t tcps_bg_rcvtotal; /* total background packets received */ | |
589 | #endif /* TRAFFIC_MGT */ | |
1c79356b A |
590 | }; |
591 | ||
2d21ac55 A |
592 | #pragma pack(4) |
593 | ||
1c79356b A |
594 | /* |
595 | * TCB structure exported to user-land via sysctl(3). | |
596 | * Evil hack: declare only if in_pcb.h and sys/socketvar.h have been | |
597 | * included. Not all of our clients do. | |
598 | */ | |
1c79356b | 599 | struct xtcpcb { |
2d21ac55 | 600 | u_int32_t xt_len; |
91447636 A |
601 | #ifdef KERNEL_PRIVATE |
602 | struct inpcb_compat xt_inp; | |
603 | #else | |
1c79356b | 604 | struct inpcb xt_inp; |
91447636 A |
605 | #endif |
606 | #ifdef KERNEL_PRIVATE | |
55e303ae A |
607 | struct otcpcb xt_tp; |
608 | #else | |
609 | struct tcpcb xt_tp; | |
610 | #endif | |
1c79356b A |
611 | struct xsocket xt_socket; |
612 | u_quad_t xt_alignment_hack; | |
613 | }; | |
1c79356b | 614 | |
2d21ac55 A |
615 | #pragma pack() |
616 | ||
1c79356b A |
617 | /* |
618 | * Names for TCP sysctl objects | |
619 | */ | |
620 | #define TCPCTL_DO_RFC1323 1 /* use RFC-1323 extensions */ | |
621 | #define TCPCTL_DO_RFC1644 2 /* use RFC-1644 extensions */ | |
622 | #define TCPCTL_MSSDFLT 3 /* MSS default */ | |
623 | #define TCPCTL_STATS 4 /* statistics (read-only) */ | |
624 | #define TCPCTL_RTTDFLT 5 /* default RTT estimate */ | |
625 | #define TCPCTL_KEEPIDLE 6 /* keepalive idle timer */ | |
626 | #define TCPCTL_KEEPINTVL 7 /* interval to send keepalives */ | |
627 | #define TCPCTL_SENDSPACE 8 /* send buffer space */ | |
628 | #define TCPCTL_RECVSPACE 9 /* receive buffer space */ | |
9bccf70c | 629 | #define TCPCTL_KEEPINIT 10 /* timeout for establishing syn */ |
1c79356b | 630 | #define TCPCTL_PCBLIST 11 /* list of all outstanding PCBs */ |
9bccf70c A |
631 | #define TCPCTL_DELACKTIME 12 /* time before sending delayed ACK */ |
632 | #define TCPCTL_V6MSSDFLT 13 /* MSS default for IPv6 */ | |
633 | #define TCPCTL_MAXID 14 | |
1c79356b | 634 | |
91447636 | 635 | #ifdef KERNEL_PRIVATE |
2d21ac55 A |
636 | #define TCP_PKTLIST_CLEAR(tp) { \ |
637 | (tp)->t_pktlist_head = (tp)->t_pktlist_tail = NULL; \ | |
638 | (tp)->t_lastchain = (tp)->t_pktlist_sentlen = 0; \ | |
639 | } | |
640 | ||
1c79356b A |
641 | #define TCPCTL_NAMES { \ |
642 | { 0, 0 }, \ | |
643 | { "rfc1323", CTLTYPE_INT }, \ | |
644 | { "rfc1644", CTLTYPE_INT }, \ | |
645 | { "mssdflt", CTLTYPE_INT }, \ | |
646 | { "stats", CTLTYPE_STRUCT }, \ | |
647 | { "rttdflt", CTLTYPE_INT }, \ | |
648 | { "keepidle", CTLTYPE_INT }, \ | |
649 | { "keepintvl", CTLTYPE_INT }, \ | |
650 | { "sendspace", CTLTYPE_INT }, \ | |
651 | { "recvspace", CTLTYPE_INT }, \ | |
652 | { "keepinit", CTLTYPE_INT }, \ | |
653 | { "pcblist", CTLTYPE_STRUCT }, \ | |
9bccf70c | 654 | { "delacktime", CTLTYPE_INT }, \ |
1c79356b A |
655 | { "v6mssdflt", CTLTYPE_INT }, \ |
656 | } | |
657 | ||
1c79356b A |
658 | #ifdef SYSCTL_DECL |
659 | SYSCTL_DECL(_net_inet_tcp); | |
91447636 | 660 | #endif /* SYSCTL_DECL */ |
1c79356b A |
661 | |
662 | extern struct inpcbhead tcb; /* head of queue of active tcpcb's */ | |
663 | extern struct inpcbinfo tcbinfo; | |
664 | extern struct tcpstat tcpstat; /* tcp statistics */ | |
665 | extern int tcp_mssdflt; /* XXX */ | |
e5568f75 | 666 | extern int tcp_minmss; |
91447636 | 667 | extern int tcp_minmssoverload; |
9bccf70c A |
668 | extern int tcp_do_newreno; |
669 | extern int ss_fltsz; | |
670 | extern int ss_fltsz_local; | |
671 | #ifdef __APPLE__ | |
672 | extern u_long tcp_now; /* for RFC 1323 timestamps */ | |
673 | extern int tcp_delack_enabled; | |
91447636 | 674 | #endif /* __APPLE__ */ |
9bccf70c | 675 | |
8ad349bb | 676 | extern int tcp_do_sack; /* SACK enabled/disabled */ |
1c79356b | 677 | |
91447636 | 678 | void tcp_canceltimers(struct tcpcb *); |
1c79356b | 679 | struct tcpcb * |
91447636 A |
680 | tcp_close(struct tcpcb *); |
681 | void tcp_ctlinput(int, struct sockaddr *, void *); | |
682 | int tcp_ctloutput(struct socket *, struct sockopt *); | |
1c79356b | 683 | struct tcpcb * |
91447636 A |
684 | tcp_drop(struct tcpcb *, int); |
685 | void tcp_drain(void); | |
686 | void tcp_fasttimo(void); | |
1c79356b | 687 | struct rmxp_tao * |
91447636 | 688 | tcp_gettaocache(struct inpcb *); |
2d21ac55 | 689 | void tcp_init(void) __attribute__((section("__TEXT, initcode"))); |
91447636 A |
690 | void tcp_input(struct mbuf *, int); |
691 | void tcp_mss(struct tcpcb *, int); | |
692 | int tcp_mssopt(struct tcpcb *); | |
693 | void tcp_drop_syn_sent(struct inpcb *, int); | |
694 | void tcp_mtudisc(struct inpcb *, int); | |
1c79356b | 695 | struct tcpcb * |
91447636 A |
696 | tcp_newtcpcb(struct inpcb *); |
697 | int tcp_output(struct tcpcb *); | |
698 | void tcp_quench(struct inpcb *, int); | |
699 | void tcp_respond(struct tcpcb *, void *, | |
2d21ac55 | 700 | struct tcphdr *, struct mbuf *, tcp_seq, tcp_seq, int, ifnet_t); |
1c79356b | 701 | struct rtentry * |
91447636 A |
702 | tcp_rtlookup(struct inpcb *); |
703 | void tcp_setpersist(struct tcpcb *); | |
704 | void tcp_slowtimo(void); | |
1c79356b | 705 | struct tcptemp * |
91447636 A |
706 | tcp_maketemplate(struct tcpcb *); |
707 | void tcp_fillheaders(struct tcpcb *, void *, void *); | |
1c79356b | 708 | struct tcpcb * |
91447636 A |
709 | tcp_timers(struct tcpcb *, int); |
710 | void tcp_trace(int, int, struct tcpcb *, void *, struct tcphdr *, int); | |
8ad349bb | 711 | |
2d21ac55 | 712 | void tcp_sack_doack(struct tcpcb *, struct tcpopt *, tcp_seq); |
8ad349bb A |
713 | void tcp_update_sack_list(struct tcpcb *tp, tcp_seq rcv_laststart, tcp_seq rcv_lastend); |
714 | void tcp_clean_sackreport(struct tcpcb *tp); | |
715 | void tcp_sack_adjust(struct tcpcb *tp); | |
716 | struct sackhole *tcp_sack_output(struct tcpcb *tp, int *sack_bytes_rexmt); | |
717 | void tcp_sack_partialack(struct tcpcb *, struct tcphdr *); | |
718 | void tcp_free_sackholes(struct tcpcb *tp); | |
2d21ac55 | 719 | long tcp_sbspace(struct tcpcb *tp); |
8ad349bb A |
720 | |
721 | ||
91447636 A |
722 | int tcp_lock (struct socket *, int, int); |
723 | int tcp_unlock (struct socket *, int, int); | |
724 | #ifdef _KERN_LOCKS_H_ | |
725 | lck_mtx_t * tcp_getlock (struct socket *, int); | |
726 | #else | |
727 | void * tcp_getlock (struct socket *, int); | |
728 | #endif | |
729 | ||
1c79356b A |
730 | |
731 | extern struct pr_usrreqs tcp_usrreqs; | |
1c79356b A |
732 | extern u_long tcp_sendspace; |
733 | extern u_long tcp_recvspace; | |
91447636 | 734 | tcp_seq tcp_new_isn(struct tcpcb *); |
1c79356b | 735 | |
91447636 | 736 | #endif /* KERNEL_RPIVATE */ |
1c79356b A |
737 | |
738 | #endif /* _NETINET_TCP_VAR_H_ */ |