]> git.saurik.com Git - apple/xnu.git/blob - bsd/netinet/tcp_var.h
xnu-3248.60.10.tar.gz
[apple/xnu.git] / bsd / netinet / tcp_var.h
1 /*
2 * Copyright (c) 2000-2015 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
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
61 * $FreeBSD: src/sys/netinet/tcp_var.h,v 1.56.2.8 2001/08/22 00:59:13 silby Exp $
62 */
63
64 #ifndef _NETINET_TCP_VAR_H_
65 #define _NETINET_TCP_VAR_H_
66 #include <sys/types.h>
67 #include <sys/appleapiopts.h>
68 #include <sys/queue.h>
69 #include <netinet/in_pcb.h>
70 #include <netinet/tcp.h>
71 #include <netinet/tcp_timer.h>
72
73 #if defined(__LP64__)
74 #define _TCPCB_PTR(x) u_int32_t
75 #define _TCPCB_LIST_HEAD(name, type) \
76 struct name { \
77 u_int32_t lh_first; \
78 };
79 #else
80 #define _TCPCB_PTR(x) x
81 #define _TCPCB_LIST_HEAD(name, type) LIST_HEAD(name, type)
82 #endif
83
84 #ifdef KERNEL_PRIVATE
85
86 #define TCP_RETRANSHZ 1000 /* granularity of TCP timestamps, 1ms */
87 /* Minimum time quantum within which the timers are coalesced */
88 #define TCP_TIMER_10MS_QUANTUM (TCP_RETRANSHZ/100) /* every 10ms */
89 #define TCP_TIMER_100MS_QUANTUM (TCP_RETRANSHZ/10) /* every 100ms */
90 #define TCP_TIMER_500MS_QUANTUM (TCP_RETRANSHZ/2) /* every 500ms */
91
92 #define TCP_RETRANSHZ_TO_USEC 1000
93
94 #define N_TIME_WAIT_SLOTS 128 /* must be power of 2 */
95
96 /* Always allow at least 4 packets worth of recv window when adjusting
97 * recv window using inter-packet arrival jitter.
98 */
99 #define MIN_IAJ_WIN 4
100
101 /* A variation in delay of this many milliseconds is tolerable. This limit has to
102 * be low but greater than zero. We also use standard deviation on jitter to adjust
103 * this limit for different link and connection types.
104 */
105 #define ALLOWED_IAJ 5
106
107 /* Ignore the first few packets on a connection until the ACK clock gets going
108 */
109 #define IAJ_IGNORE_PKTCNT 40
110
111 /* Let the accumulated IAJ value increase by this threshold at most. This limit
112 * will control how many ALLOWED_IAJ measurements a receiver will have to see
113 * before opening the receive window
114 */
115 #define ACC_IAJ_HIGH_THRESH 100
116
117 /* When accumulated IAJ reaches this value, the receiver starts to react by
118 * closing the window
119 */
120 #define ACC_IAJ_REACT_LIMIT 200
121
122 /* If the number of small packets (smaller than IAJ packet size) seen on a
123 * connection is more than this threshold, reset the size and learn it again.
124 * This is needed because the sender might send smaller segments after PMTU
125 * discovery and the receiver has to learn the new size.
126 */
127 #define RESET_IAJ_SIZE_THRESH 20
128
129 /*
130 * Adaptive timeout is a read/write timeout specified by the application to
131 * get a socket event when the transport layer detects a stall in data
132 * transfer. The value specified is the number of probes that can be sent
133 * to the peer before generating an event. Since it is not specified as
134 * a time value, the timeout will adjust based on the RTT seen on the link.
135 * The timeout will start only when there is an indication that the read/write
136 * operation is not making progress.
137 *
138 * If a write operation stalls, the probe will be retransmission of data.
139 * If a read operation stalls, the probe will be a keep-alive packet.
140 *
141 * The maximum value of adaptive timeout is set to 10 which will allow
142 * transmission of enough number of probes to the peer.
143 */
144 #define TCP_ADAPTIVE_TIMEOUT_MAX 10
145
146 #define TCP_CONNECTIVITY_PROBES_MAX 5
147
148 /*
149 * Kernel variables for tcp.
150 */
151
152 /* TCP segment queue entry */
153 struct tseg_qent {
154 LIST_ENTRY(tseg_qent) tqe_q;
155 int tqe_len; /* TCP segment data length */
156 struct tcphdr *tqe_th; /* a pointer to tcp header */
157 struct mbuf *tqe_m; /* mbuf contains packet */
158 };
159 LIST_HEAD(tsegqe_head, tseg_qent);
160
161 struct sackblk {
162 tcp_seq start; /* start seq no. of sack block */
163 tcp_seq end; /* end seq no. */
164 };
165
166 struct sackhole {
167 tcp_seq start; /* start seq no. of hole */
168 tcp_seq end; /* end seq no. */
169 tcp_seq rxmit; /* next seq. no in hole to be retransmitted */
170 u_int32_t rxmit_start; /* timestamp of first retransmission */
171 TAILQ_ENTRY(sackhole) scblink; /* scoreboard linkage */
172 };
173
174 struct sackhint {
175 struct sackhole *nexthole;
176 int sack_bytes_rexmit;
177 };
178
179 struct tcp_rxt_seg {
180 tcp_seq rx_start;
181 tcp_seq rx_end;
182 u_int16_t rx_count;
183 u_int16_t rx_flags;
184 #define TCP_RXT_SPURIOUS 0x1 /* received DSACK notification */
185 #define TCP_RXT_DSACK_FOR_TLP 0x2
186 SLIST_ENTRY(tcp_rxt_seg) rx_link;
187 };
188
189 struct tcptemp {
190 u_char tt_ipgen[40]; /* the size must be of max ip header, now IPv6 */
191 struct tcphdr tt_t;
192 };
193
194 struct bwmeas {
195 tcp_seq bw_start; /* start of bw measurement */
196 uint32_t bw_ts; /* timestamp when bw measurement started */
197 uint32_t bw_size; /* burst size in bytes for this bw measurement */
198 uint32_t bw_minsizepkts; /* Min burst size as segments */
199 uint32_t bw_maxsizepkts; /* Max burst size as segments */
200 uint32_t bw_minsize; /* Min size in bytes */
201 uint32_t bw_maxsize; /* Max size in bytes */
202 uint32_t bw_sndbw; /* Measured send bw */
203 };
204
205 /* MPTCP Data sequence map entry */
206 struct mpt_dsn_map {
207 uint64_t mpt_dsn; /* data seq num recvd */
208 uint32_t mpt_sseq; /* relative subflow # */
209 uint16_t mpt_len; /* length of mapping */
210 uint16_t mpt_csum; /* checksum value if on */
211 };
212 #define tcp6cb tcpcb /* for KAME src sync over BSD*'s */
213
214 struct tcp_ccstate {
215 union {
216 struct tcp_cubic_state {
217 u_int32_t tc_last_max; /* cwnd at last loss */
218 u_int32_t tc_epoch_start; /* TS of last loss */
219 u_int32_t tc_origin_point; /* window at the start of an epoch */
220 u_int32_t tc_tcp_win; /* computed tcp win */
221 u_int32_t tc_tcp_bytes_acked; /* bytes acked */
222 u_int32_t tc_target_win; /* cubic target win */
223 u_int32_t tc_avg_lastmax; /* Average of last max */
224 u_int32_t tc_mean_deviation; /* Mean absolute deviation */
225 float tc_epoch_period; /* K parameter */
226 } _cubic_state_;
227 #define cub_last_max __u__._cubic_state_.tc_last_max
228 #define cub_epoch_start __u__._cubic_state_.tc_epoch_start
229 #define cub_origin_point __u__._cubic_state_.tc_origin_point
230 #define cub_tcp_win __u__._cubic_state_.tc_tcp_win
231 #define cub_tcp_bytes_acked __u__._cubic_state_.tc_tcp_bytes_acked
232 #define cub_epoch_period __u__._cubic_state_.tc_epoch_period
233 #define cub_target_win __u__._cubic_state_.tc_target_win
234 #define cub_avg_lastmax __u__._cubic_state_.tc_avg_lastmax
235 #define cub_mean_dev __u__._cubic_state_.tc_mean_deviation
236 } __u__;
237 };
238
239 /*
240 * Tcp control block, one per tcp; fields:
241 * Organized for 16 byte cacheline efficiency.
242 */
243 struct tcpcb {
244 struct tsegqe_head t_segq;
245 int t_dupacks; /* consecutive dup acks recd */
246 int t_state; /* state of this connection */
247 uint32_t t_timer[TCPT_NTIMERS]; /* tcp timers */
248 struct tcptimerentry tentry; /* entry in timer list */
249
250 struct inpcb *t_inpcb; /* back pointer to internet pcb */
251 uint32_t t_flags;
252 #define TF_ACKNOW 0x00001 /* ack peer immediately */
253 #define TF_DELACK 0x00002 /* ack, but try to delay it */
254 #define TF_NODELAY 0x00004 /* don't delay packets to coalesce */
255 #define TF_NOOPT 0x00008 /* don't use tcp options */
256 #define TF_SENTFIN 0x00010 /* have sent FIN */
257 #define TF_REQ_SCALE 0x00020 /* have/will request window scaling */
258 #define TF_RCVD_SCALE 0x00040 /* other side has requested scaling */
259 #define TF_REQ_TSTMP 0x00080 /* have/will request timestamps */
260 #define TF_RCVD_TSTMP 0x00100 /* a timestamp was received in SYN */
261 #define TF_SACK_PERMIT 0x00200 /* other side said I could SACK */
262 #define TF_NEEDSYN 0x00400 /* send SYN (implicit state) */
263 #define TF_NEEDFIN 0x00800 /* send FIN (implicit state) */
264 #define TF_NOPUSH 0x01000 /* don't push */
265 #define TF_REQ_CC 0x02000 /* have/will request CC */
266 #define TF_RCVD_CC 0x04000 /* a CC was received in SYN */
267 #define TF_SENDCCNEW 0x08000 /* Unused */
268 #define TF_MORETOCOME 0x10000 /* More data to be appended to sock */
269 #define TF_LOCAL 0x20000 /* connection to a host on local link */
270 #define TF_RXWIN0SENT 0x40000 /* sent a receiver win 0 in response */
271 #define TF_SLOWLINK 0x80000 /* route is a on a modem speed link */
272 #define TF_LASTIDLE 0x100000 /* connection was previously idle */
273 #define TF_FASTRECOVERY 0x200000 /* in NewReno Fast Recovery */
274 #define TF_WASFRECOVERY 0x400000 /* was in NewReno Fast Recovery */
275 #define TF_SIGNATURE 0x800000 /* require MD5 digests (RFC2385) */
276 #define TF_MAXSEGSNT 0x1000000 /* last segment sent was a full segment */
277 #define TF_PMTUD 0x4000000 /* Perform Path MTU Discovery for this connection */
278 #define TF_CLOSING 0x8000000 /* pending tcp close */
279 #define TF_TSO 0x10000000 /* TCP Segment Offloading is enable on this connection */
280 #define TF_BLACKHOLE 0x20000000 /* Path MTU Discovery Black Hole detection */
281 #define TF_TIMER_ONLIST 0x40000000 /* pcb is on tcp_timer_list */
282 #define TF_STRETCHACK 0x80000000 /* receiver is going to delay acks */
283
284 tcp_seq snd_una; /* send unacknowledged */
285 tcp_seq snd_max; /* highest sequence number sent;
286 * used to recognize retransmits
287 */
288 tcp_seq snd_nxt; /* send next */
289 tcp_seq snd_up; /* send urgent pointer */
290
291 tcp_seq snd_wl1; /* window update seg seq number */
292 tcp_seq snd_wl2; /* window update seg ack number */
293 tcp_seq iss; /* initial send sequence number */
294 tcp_seq irs; /* initial receive sequence number */
295
296 tcp_seq rcv_nxt; /* receive next */
297 tcp_seq rcv_adv; /* advertised window */
298 u_int32_t rcv_wnd; /* receive window */
299 tcp_seq rcv_up; /* receive urgent pointer */
300
301 u_int32_t snd_wnd; /* send window */
302 u_int32_t snd_cwnd; /* congestion-controlled window */
303 u_int32_t snd_ssthresh; /* snd_cwnd size threshold for
304 * for slow start exponential to
305 * linear switch
306 */
307 tcp_seq snd_recover; /* for use in NewReno Fast Recovery */
308
309 u_int t_maxopd; /* mss plus options */
310
311 u_int32_t t_rcvtime; /* time at which a packet was received */
312 u_int32_t t_starttime; /* time connection was established */
313 int t_rtttime; /* tcp clock when rtt calculation was started */
314 tcp_seq t_rtseq; /* sequence number being timed */
315
316 u_int32_t rfbuf_ts; /* recv buffer autoscaling timestamp */
317 u_int32_t rfbuf_cnt; /* recv buffer autoscaling byte count */
318
319 int t_rxtcur; /* current retransmit value (ticks) */
320 u_int t_maxseg; /* maximum segment size */
321 int t_srtt; /* smoothed round-trip time */
322 int t_rttvar; /* variance in round-trip time */
323
324 u_int64_t t_accsleep_ms; /* accumulated sleep time since last boot */
325 u_int16_t t_reassqlen; /* length of reassembly queue */
326 u_int16_t t_rxtshift; /* log(2) of rexmt exp. backoff */
327 u_int32_t t_rttmin; /* minimum rtt allowed */
328 u_int32_t t_rttbest; /* best rtt we've seen */
329 u_int32_t t_rttcur; /* most recent value of rtt */
330 u_int32_t t_rttupdated; /* number of times rtt sampled */
331 u_int32_t t_rxt_conndroptime; /* retxmt conn gets dropped after this time, when set */
332 u_int32_t t_rxtstart; /* time at which retransmission started */
333 u_int32_t max_sndwnd; /* largest window peer has offered */
334
335 int t_softerror; /* possible error not yet reported */
336 /* out-of-band data */
337 char t_oobflags; /* have some */
338 char t_iobc; /* input character */
339 #define TCPOOB_HAVEDATA 0x01
340 #define TCPOOB_HADDATA 0x02
341 /* RFC 1323 variables */
342 u_int8_t snd_scale; /* window scaling for send window */
343 u_int8_t rcv_scale; /* window scaling for recv window */
344 u_int8_t request_r_scale; /* pending window scaling */
345 u_int8_t requested_s_scale;
346 u_int8_t tcp_cc_index; /* index of congestion control algorithm */
347 u_int8_t t_adaptive_rtimo; /* Read timeout used as a multiple of RTT */
348 u_int8_t t_adaptive_wtimo; /* Write timeout used as a multiple of RTT */
349 u_int8_t t_stretchack_delayed; /* stretch ack delayed */
350
351 /* State for limiting early retransmits when SACK is not enabled */
352 u_int16_t t_early_rexmt_count; /* count of early rexmts */
353 u_int32_t t_early_rexmt_win; /* window for limiting early rexmts */
354
355 u_int32_t ts_recent; /* timestamp echo data */
356
357 u_int32_t ts_recent_age; /* when last updated */
358 tcp_seq last_ack_sent;
359 /* RFC 3465 variables */
360 u_int32_t t_bytes_acked; /* ABC "bytes_acked" parameter */
361
362 int t_lastchain; /* amount of packets chained last time around */
363 u_int16_t t_unacksegs; /* received but unacked segments for delaying acks */
364 u_int8_t t_rexmtthresh; /* duplicate ack threshold for entering fast recovery */
365 u_int8_t t_rtimo_probes; /* number of adaptive rtimo probes sent */
366 u_int32_t t_persist_timeout; /* ZWP persistence limit as set by PERSIST_TIMEOUT */
367 u_int32_t t_persist_stop; /* persistence limit deadline if triggered by ZWP */
368 u_int32_t t_notsent_lowat; /* Low water for not sent data */
369
370 /* Receiver state for stretch-ack algorithm */
371 u_int32_t rcv_unackwin; /* to measure win for stretching acks */
372 u_int32_t rcv_by_unackwin; /* bytes seen during the last ack-stretching win */
373 u_int32_t rcv_nostrack_ts; /* timestamp when stretch ack was disabled automatically */
374 u_int16_t rcv_waitforss; /* wait for packets during slow-start */
375
376 /* ECN stats */
377 u_int16_t ecn_flags;
378 #define TE_SETUPSENT 0x0001 /* Indicate we have sent ECN-SETUP SYN or SYN-ACK */
379 #define TE_SETUPRECEIVED 0x0002 /* Indicate we have received ECN-SETUP SYN or SYN-ACK */
380 #define TE_SENDIPECT 0x0004 /* Indicate we haven't sent or received non-ECN-setup SYN or SYN-ACK */
381 #define TE_SENDCWR 0x0008 /* Indicate that the next non-retransmit should have the TCP CWR flag set */
382 #define TE_SENDECE 0x0010 /* Indicate that the next packet should have the TCP ECE flag set */
383 #define TE_INRECOVERY 0x0020 /* connection entered recovery after receiving ECE */
384 #define TE_RECV_ECN_CE 0x0040 /* Received IPTOS_ECN_CE marking atleast once */
385 #define TE_RECV_ECN_ECE 0x0080 /* Received ECE marking atleast once */
386 #define TE_LOST_SYN 0x0100 /* Lost SYN with ECN setup */
387 #define TE_LOST_SYNACK 0x0200 /* Lost SYN-ACK with ECN setup */
388 #define TE_ECN_MODE_ENABLE 0x0400 /* Option ECN mode set to enable */
389 #define TE_ECN_MODE_DISABLE 0x0800 /* Option ECN mode set to disable */
390 #define TE_ENABLE_ECN 0x1000 /* Enable negotiation of ECN */
391 #define TE_ECN_ON (TE_SETUPSENT | TE_SETUPRECEIVED) /* Indicate ECN was successfully negotiated on a connection) */
392 #define TE_CEHEURI_SET 0x2000 /* We did our CE-probing at the beginning */
393 #define TE_CLIENT_SETUP 0x4000 /* setup from client side */
394
395 u_int32_t t_ecn_recv_ce; /* Received CE from the network */
396 u_int32_t t_ecn_recv_cwr; /* Packets received with CWR */
397 u_int8_t t_ecn_recv_ce_pkt; /* Received packet with CE-bit set (independent from last_ack_sent) */
398
399 /* state for bad retransmit recovery */
400 u_int32_t snd_cwnd_prev; /* cwnd prior to retransmit */
401 u_int32_t snd_ssthresh_prev; /* ssthresh prior to retransmit */
402 tcp_seq snd_recover_prev; /* snd_recover prior to retransmit */
403 int t_srtt_prev; /* srtt prior to retransmit */
404 int t_rttvar_prev; /* rttvar prior to retransmit */
405 u_int32_t t_badrexmt_time; /* bad rexmt detection time */
406
407 /* Packet reordering metric */
408 u_int16_t t_reorderwin; /* Reordering late time offset */
409
410 /* SACK related state */
411 int16_t snd_numholes; /* number of holes seen by sender */
412 tcp_seq sack_newdata; /* New data xmitted in this recovery
413 episode starts at this seq number */
414 TAILQ_HEAD(sackhole_head, sackhole) snd_holes;
415 /* SACK scoreboard (sorted) */
416 tcp_seq snd_fack; /* last seq number(+1) sack'd by rcv'r*/
417 int rcv_numsacks; /* # distinct sack blks present */
418 struct sackblk sackblks[MAX_SACK_BLKS]; /* seq nos. of sack blocks */
419 struct sackhint sackhint; /* SACK scoreboard hint */
420
421 struct mbuf *t_pktlist_head; /* First packet in transmit chain */
422 struct mbuf *t_pktlist_tail; /* Last packet in transmit chain */
423 u_int32_t t_pktlist_sentlen; /* total bytes in transmit chain */
424
425 u_int32_t t_keepidle; /* keepalive idle timer (override global if > 0) */
426 u_int32_t t_keepinit; /* connection timeout, i.e. idle time
427 in SYN_SENT or SYN_RECV state */
428 u_int32_t t_keepintvl; /* interval between keepalives */
429 u_int32_t t_keepcnt; /* number of keepalives before close */
430
431 u_int32_t tso_max_segment_size; /* TSO maximum segment unit for NIC */
432 u_int16_t t_pmtud_lastseg_size; /* size of the last sent segment */
433 u_int16_t t_pmtud_saved_maxopd; /* MSS saved before performing PMTU-D BlackHole detection */
434 u_int32_t t_pmtud_start_ts; /* Time of PMTUD blackhole detection */
435
436 struct
437 {
438 u_int32_t rxduplicatebytes;
439 u_int32_t rxoutoforderbytes;
440 u_int32_t txretransmitbytes;
441 u_int8_t synrxtshift;
442 u_int8_t unused;
443 u_int16_t unused_pad_to_8;
444 u_int32_t rxmitpkts;
445 } t_stat;
446
447 /* Background congestion related state */
448 uint32_t bg_ssthresh; /* Slow start threshold until delay increases */
449 uint32_t t_flagsext; /* Another field to accommodate more flags */
450 #define TF_RXTFINDROP 0x1 /* Drop conn after retransmitting FIN 3 times */
451 #define TF_RCVUNACK_WAITSS 0x2 /* set when the receiver should not stretch acks */
452 #define TF_BWMEAS_INPROGRESS 0x4 /* Indicate BW meas is happening */
453 #define TF_MEASURESNDBW 0x8 /* Measure send bw on this connection */
454 #define TF_LRO_OFFLOADED 0x10 /* Connection LRO offloaded */
455 #define TF_SACK_ENABLE 0x20 /* SACK is enabled */
456 #define TF_RECOMPUTE_RTT 0x40 /* recompute RTT after spurious retransmit */
457 #define TF_DETECT_READSTALL 0x80 /* Used to detect a stall during read operation */
458 #define TF_RECV_THROTTLE 0x100 /* Input throttling active */
459 #define TF_NOSTRETCHACK 0x200 /* ack every other packet */
460 #define TF_STREAMEOW 0x400 /* Last packet was small indicating end of write */
461 #define TF_NOTIMEWAIT 0x800 /* Avoid going into time-wait */
462 #define TF_SENT_TLPROBE 0x1000 /* Sent data in PTO */
463 #define TF_PKTS_REORDERED 0x2000 /* Detected reordering */
464 #define TF_DELAY_RECOVERY 0x4000 /* delay fast recovery */
465 #define TF_FORCE 0x8000 /* force 1 byte out */
466 #define TF_DISABLE_STRETCHACK 0x10000 /* auto-disable stretch ack */
467 #define TF_NOBLACKHOLE_DETECTION 0x20000 /* Disable PMTU blackhole detection */
468 #define TF_DISABLE_DSACK 0x40000 /* Ignore DSACK due to n/w duplication */
469 #define TF_RESCUE_RXT 0x80000 /* SACK rescue retransmit */
470 #define TF_CWND_NONVALIDATED 0x100000 /* cwnd non validated */
471 #define TF_PROBING 0x200000 /* Trigger probe timeout */
472 #define TF_FASTOPEN 0x400000 /* TCP Fastopen is enabled */
473
474 #if TRAFFIC_MGT
475 /* Inter-arrival jitter related state */
476 uint32_t iaj_rcv_ts; /* tcp clock when the first packet was received */
477 uint16_t iaj_size; /* Size of packet for iaj measurement */
478 uint8_t iaj_small_pkt; /* Count of packets smaller than iaj_size */
479 uint8_t t_pipeack_ind; /* index for next pipeack sample */
480 uint16_t iaj_pktcnt; /* packet count, to avoid throttling initially */
481 uint16_t acc_iaj; /* Accumulated iaj */
482 tcp_seq iaj_rwintop; /* recent max advertised window */
483 uint32_t avg_iaj; /* Mean */
484 uint32_t std_dev_iaj; /* Standard deviation */
485 #endif /* TRAFFIC_MGT */
486 struct bwmeas *t_bwmeas; /* State for bandwidth measurement */
487 uint32_t t_lropktlen; /* Bytes in a LRO frame */
488 tcp_seq t_idleat; /* rcv_nxt at idle time */
489 TAILQ_ENTRY(tcpcb) t_twentry; /* link for time wait queue */
490 struct tcp_ccstate *t_ccstate; /* congestion control related state */
491 /* Tail loss probe related state */
492 tcp_seq t_tlphighrxt; /* snd_nxt after PTO */
493 u_int32_t t_tlpstart; /* timestamp at PTO */
494 /* DSACK data receiver state */
495 tcp_seq t_dsack_lseq; /* DSACK left sequence */
496 tcp_seq t_dsack_rseq; /* DSACK right sequence */
497 /* DSACK data sender state */
498 SLIST_HEAD(tcp_rxt_seghead, tcp_rxt_seg) t_rxt_segments;
499 tcp_seq t_dsack_lastuna; /* snd_una when last recovery episode started */
500 /* state for congestion window validation (draft-ietf-tcpm-newcwv-07) */
501 #define TCP_PIPEACK_SAMPLE_COUNT 3
502 u_int32_t t_pipeack_sample[TCP_PIPEACK_SAMPLE_COUNT]; /* pipeack, bytes acked within RTT */
503 tcp_seq t_pipeack_lastuna; /* una when pipeack measurement started */
504 u_int32_t t_pipeack;
505 u_int32_t t_lossflightsize;
506
507 #if MPTCP
508 u_int32_t t_mpflags; /* flags for multipath TCP */
509
510 #define TMPF_PREESTABLISHED 0x00000001 /* conn in pre-established state */
511 #define TMPF_SENT_KEYS 0x00000002 /* indicates that keys were sent */
512 #define TMPF_MPTCP_TRUE 0x00000004 /* negotiated MPTCP successfully */
513 #define TMPF_MPTCP_RCVD_KEY 0x00000008 /* state for 3-way handshake */
514 #define TMPF_SND_MPPRIO 0x00000010 /* send priority of subflow */
515 #define TMPF_SND_REM_ADDR 0x00000020 /* initiate address removal */
516 #define TMPF_UNUSED 0x00000040 /* address addition acked by peer */
517 #define TMPF_JOINED_FLOW 0x00000080 /* Indicates additional flow */
518 #define TMPF_BACKUP_PATH 0x00000100 /* Indicates backup path */
519 #define TMPF_MPTCP_ACKNOW 0x00000200 /* Send Data ACK */
520 #define TMPF_SEND_DSN 0x00000400 /* Send DSN mapping */
521 #define TMPF_SEND_DFIN 0x00000800 /* Send Data FIN */
522 #define TMPF_RECV_DFIN 0x00001000 /* Recv Data FIN */
523 #define TMPF_SENT_JOIN 0x00002000 /* Sent Join */
524 #define TMPF_RECVD_JOIN 0x00004000 /* Received Join */
525 #define TMPF_RESET 0x00008000 /* Send RST */
526 #define TMPF_TCP_FALLBACK 0x00010000 /* Fallback to TCP */
527 #define TMPF_FASTCLOSE 0x00020000 /* Send Fastclose option */
528 #define TMPF_EMBED_DSN 0x00040000 /* tp has DSN mapping */
529 #define TMPF_MPTCP_READY 0x00080000 /* Can send DSS options on data */
530 #define TMPF_INFIN_SENT 0x00100000 /* Sent infinite mapping */
531 #define TMPF_SND_MPFAIL 0x00200000 /* Received mapping csum failure */
532 #define TMPF_FASTJOIN_SEND 0x00400000 /* Fast join early data send */
533 #define TMPF_FASTJOINBY2_SEND 0x00800000 /* Fast join send after 3 WHS */
534 #define TMPF_MPCAP_RETRANSMIT 0x01000000 /* Retransmission of 3rd ACK */
535 #define TMPF_TFO_REQUEST 0x02000000 /* TFO Requested */
536
537 tcp_seq t_mpuna; /* unacknowledged sequence */
538 void *t_mptcb; /* pointer to MPTCP TCB */
539 struct mpt_dsn_map t_rcv_map; /* Receive mapping list */
540 u_int8_t t_local_aid; /* Addr Id for authentication */
541 u_int8_t t_rem_aid; /* Addr ID of another subflow */
542 u_int8_t t_mprxtshift; /* join retransmission */
543 #endif /* MPTCP */
544
545 #define TFO_F_OFFER_COOKIE 0x01 /* We will offer a cookie */
546 #define TFO_F_COOKIE_VALID 0x02 /* The received cookie is valid */
547 #define TFO_F_COOKIE_REQ 0x04 /* Client requested a new cookie */
548 #define TFO_F_COOKIE_SENT 0x08 /* Client did send a cookie in the SYN */
549 #define TFO_F_SYN_LOSS 0x10 /* A SYN-loss triggered a fallback to regular TCP on the client-side */
550 #define TFO_F_NO_RCVPROBING 0x20 /* This network is guaranteed to support TFO in the downstream direction */
551 #define TFO_F_NO_SNDPROBING 0x40 /* This network is guaranteed to support TFO in the upstream direction */
552 u_int8_t t_tfo_flags;
553 #define TFO_S_SYNDATA_RCV 0x01 /* SYN+data has been received */
554 #define TFO_S_COOKIEREQ_RECV 0x02 /* TFO-cookie request received */
555 #define TFO_S_COOKIE_SENT 0x04 /* TFO-cookie announced in SYN/ACK */
556 #define TFO_S_COOKIE_INVALID 0x08 /* Received TFO-cookie is invalid */
557 #define TFO_S_COOKIE_REQ 0x10 /* TFO-cookie requested within the SYN */
558 #define TFO_S_COOKIE_RCV 0x20 /* TFO-cookie received in SYN/ACK */
559 #define TFO_S_SYN_DATA_SENT 0x40 /* SYN+data sent */
560 #define TFO_S_SYN_DATA_ACKED 0x80 /* SYN+data has been acknowledged in SYN/ACK */
561 #define TFO_S_SYN_LOSS 0x0100 /* SYN+TFO has been lost - fallback to regular TCP */
562 u_int16_t t_tfo_stats;
563
564 u_int8_t t_tfo_probes; /* TFO-probes we did send */
565 /*
566 * This here is the TFO-probing state-machine. Transitions are as follows:
567 *
568 * Current state: PROBE_NONE
569 * Event: SYN+DATA acknowledged
570 * Action: Transition to PROBE_PROBING and set keepalive-timer
571 *
572 * Current state: PROBE_PROBING (initial state)
573 * Event: Receive data
574 * Action: Transition to PROBE_NONE and cancel keepalive-timer
575 * Event: Receive ACK that does not indicate a hole
576 * Action: Transition to PROBE_NONE and cancel keepalive-timer
577 * Event: Receive ACK that indicates a hole
578 * Action: Transition to PROBE_WAIT_DATA and set a short timer
579 * to wait for the final segment.
580 * Event: Keepalive-timeout (did not receive any segment)
581 * Action: Signal ETIMEDOUT as with regular keepalive-timers
582 *
583 * Current state: PROBE_WAIT_DATA
584 * Event: Receive data
585 * Action: Transition to PROBE_NONE and cancel keepalive-timer
586 * Event: Data-timeout (did not receive the expected data)
587 * Action: Signal ENODATA up to the app and close everything.
588 */
589 #define TFO_PROBE_NONE 0 /* Not probing now */
590 #define TFO_PROBE_PROBING 1 /* Sending out TCP-keepalives waiting for reply */
591 #define TFO_PROBE_WAIT_DATA 2 /* Received reply, waiting for data */
592 u_int8_t t_tfo_probe_state;
593
594 u_int32_t t_rcvoopack; /* out-of-order packets received */
595 u_int32_t t_pawsdrop; /* segments dropped due to PAWS */
596 u_int32_t t_sack_recovery_episode; /* SACK recovery episodes */
597 u_int32_t t_reordered_pkts; /* packets reorderd */
598 u_int32_t t_dsack_sent; /* Sent DSACK notification */
599 u_int32_t t_dsack_recvd; /* Received a valid DSACK option */
600 u_int32_t t_recv_throttle_ts;
601 };
602
603 #define IN_FASTRECOVERY(tp) (tp->t_flags & TF_FASTRECOVERY)
604 #define SACK_ENABLED(tp) (tp->t_flagsext & TF_SACK_ENABLE)
605
606 /*
607 * If the connection is in a throttled state due to advisory feedback from
608 * the interface output queue, reset that state. We do this in favor
609 * of entering recovery because the data transfer during recovery
610 * should be just a trickle and it will help to improve performance.
611 * We also do not want to back off twice in the same RTT.
612 */
613 #define ENTER_FASTRECOVERY(_tp_) do { \
614 (_tp_)->t_flags |= TF_FASTRECOVERY; \
615 if (INP_IS_FLOW_CONTROLLED((_tp_)->t_inpcb)) \
616 inp_reset_fc_state((_tp_)->t_inpcb); \
617 if (!SLIST_EMPTY(&tp->t_rxt_segments)) \
618 tcp_rxtseg_clean(tp); \
619 } while(0)
620
621 #define EXIT_FASTRECOVERY(_tp_) do { \
622 (_tp_)->t_flags &= ~TF_FASTRECOVERY; \
623 (_tp_)->t_dupacks = 0; \
624 (_tp_)->t_rexmtthresh = tcprexmtthresh; \
625 (_tp_)->t_bytes_acked = 0; \
626 (_tp_)->ecn_flags &= ~TE_INRECOVERY; \
627 (_tp_)->t_timer[TCPT_PTO] = 0; \
628 (_tp_)->t_flagsext &= ~TF_RESCUE_RXT; \
629 (_tp_)->t_lossflightsize = 0; \
630 } while(0)
631
632 /*
633 * When the number of duplicate acks received is less than
634 * the retransmit threshold, use Limited Transmit algorithm
635 */
636 extern int tcprexmtthresh;
637 #define ALLOW_LIMITED_TRANSMIT(_tp_) \
638 ((_tp_)->t_dupacks > 0 && \
639 (_tp_)->t_dupacks < (_tp_)->t_rexmtthresh && \
640 ((_tp_)->t_flagsext & (TF_PKTS_REORDERED|TF_DELAY_RECOVERY)) \
641 != (TF_PKTS_REORDERED|TF_DELAY_RECOVERY))
642
643 /*
644 * This condition is true is timestamp option is supported
645 * on a connection.
646 */
647 #define TSTMP_SUPPORTED(_tp_) \
648 (((_tp_)->t_flags & (TF_REQ_TSTMP|TF_RCVD_TSTMP)) == \
649 (TF_REQ_TSTMP|TF_RCVD_TSTMP))
650
651 /*
652 * This condition is true if window scale option is supported
653 * on a connection
654 */
655 #define TCP_WINDOW_SCALE_ENABLED(_tp_) \
656 (((_tp_)->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) == \
657 (TF_RCVD_SCALE|TF_REQ_SCALE))
658
659 /* Is ECN enabled end-to-end */
660 #define TCP_ECN_ENABLED(_tp_) \
661 (((_tp_)->ecn_flags & (TE_ECN_ON)) == (TE_ECN_ON))
662
663 /*
664 * Gives number of bytes acked by this ack
665 */
666 #define BYTES_ACKED(_th_, _tp_) \
667 ((_th_)->th_ack - (_tp_)->snd_una)
668
669 /* Returns true if a DSACK option should be sent */
670 #define TCP_SEND_DSACK_OPT(_tp_) \
671 ((_tp_)->t_dsack_lseq > 0 && (_tp_)->t_dsack_rseq > 0)
672
673 /* Check if DSACK option should be processed */
674 #define TCP_DSACK_ENABLED(tp) (tcp_dsack_enable == 1 && \
675 !(tp->t_flagsext & TF_DISABLE_DSACK))
676
677 /*
678 * Returns true if a DSACK sequence is within the max send window that will
679 * be accepted. In order to set a window to validate sequence numbers, the
680 * max send window within which a DSACK option is processed is limited.
681 *
682 * We need to choose a maximum window to check if the sequence number is
683 * within the window. One arbitrary choice is 256 * MSS because if the
684 * window is as large as 256 segments it might be big enough to ignore the
685 * DSACK option. Choosing a much larger limit means that the memory for
686 * retransmit segments can be held for a longer time.
687 */
688 #define TCP_DSACK_MAX_SEND_WINDOW(_tp_) ((_tp_)->t_maxseg << 8)
689 #define TCP_DSACK_SEQ_IN_WINDOW(_tp_, _seq_, _una_) \
690 (SEQ_LEQ((_seq_), (_tp_)->snd_max) && \
691 SEQ_GEQ((_seq_), ((_una_) - TCP_DSACK_MAX_SEND_WINDOW(_tp_))))
692
693
694 enum tcp_cc_event {
695 TCP_CC_CWND_INIT, /* 0 */
696 TCP_CC_INSEQ_ACK_RCVD, /* 1 */
697 TCP_CC_ACK_RCVD, /* 2 */
698 TCP_CC_ENTER_FASTRECOVERY, /* 3 */
699 TCP_CC_IN_FASTRECOVERY, /* 4 */
700 TCP_CC_EXIT_FASTRECOVERY, /* 5 */
701 TCP_CC_PARTIAL_ACK, /* 6 */
702 TCP_CC_IDLE_TIMEOUT, /* 7 */
703 TCP_CC_REXMT_TIMEOUT, /* 8 */
704 TCP_CC_ECN_RCVD, /* 9 */
705 TCP_CC_BAD_REXMT_RECOVERY, /* 10 */
706 TCP_CC_OUTPUT_ERROR, /* 11 */
707 TCP_CC_CHANGE_ALGO, /* 12 */
708 TCP_CC_FLOW_CONTROL, /* 13 */
709 TCP_CC_SUSPEND, /* 14 */
710 TCP_CC_LIMITED_TRANSMIT, /* 15 */
711 TCP_CC_EARLY_RETRANSMIT, /* 16 */
712 TCP_CC_TLP_RECOVERY, /* 17 */
713 TCP_CC_TLP_RECOVER_LASTPACKET, /* 18 */
714 TCP_CC_DELAY_FASTRECOVERY, /* 19 */
715 TCP_CC_TLP_IN_FASTRECOVERY, /* 20 */
716 TCP_CC_DSACK_BAD_REXMT /* 21 */
717 };
718
719 /*
720 * Structure to hold TCP options that are only used during segment
721 * processing (in tcp_input), but not held in the tcpcb.
722 * It's basically used to reduce the number of parameters
723 * to tcp_dooptions.
724 */
725 struct tcpopt {
726 u_int32_t to_flags; /* which options are present */
727 #define TOF_TS 0x0001 /* timestamp */
728 #define TOF_MSS 0x0010
729 #define TOF_SCALE 0x0020
730 #define TOF_SIGNATURE 0x0040 /* signature option present */
731 #define TOF_SIGLEN 0x0080 /* signature length valid (RFC2385) */
732 #define TOF_SACK 0x0100 /* Peer sent SACK option */
733 #define TOF_MPTCP 0x0200 /* MPTCP options to be dropped */
734 #define TOF_TFO 0x0400 /* TFO cookie option present */
735 #define TOF_TFOREQ 0x0800 /* TFO cookie request present */
736 u_int32_t to_tsval;
737 u_int32_t to_tsecr;
738 u_int16_t to_mss;
739 u_int8_t to_requested_s_scale;
740 u_int8_t to_nsacks; /* number of SACK blocks */
741 u_char *to_sacks; /* pointer to the first SACK blocks */
742 u_char *to_tfo; /* pointer to the TFO cookie */
743 };
744
745 /*
746 * The TAO cache entry which is stored in the protocol family specific
747 * portion of the route metrics.
748 */
749 struct rmxp_tao {
750 tcp_cc tao_cc; /* latest CC in valid SYN */
751 tcp_cc tao_ccsent; /* latest CC sent to peer */
752 u_short tao_mssopt; /* peer's cached MSS */
753 #ifdef notyet
754 u_short tao_flags; /* cache status flags */
755 #define TAOF_DONT 0x0001 /* peer doesn't understand rfc1644 */
756 #define TAOF_OK 0x0002 /* peer does understand rfc1644 */
757 #define TAOF_UNDEF 0 /* we don't know yet */
758 #endif /* notyet */
759 };
760 #define rmx_taop(r) ((struct rmxp_tao *)(r).rmx_filler)
761
762 #define intotcpcb(ip) ((struct tcpcb *)(ip)->inp_ppcb)
763 #define sototcpcb(so) (intotcpcb(sotoinpcb(so)))
764
765 /*
766 * The rtt measured is in milliseconds as the timestamp granularity is
767 * a millisecond. The smoothed round-trip time and estimated variance
768 * are stored as fixed point numbers scaled by the values below.
769 * For convenience, these scales are also used in smoothing the average
770 * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed).
771 * With these scales, srtt has 5 bits to the right of the binary point,
772 * and thus an "ALPHA" of 0.875. rttvar has 4 bits to the right of the
773 * binary point, and is smoothed with an ALPHA of 0.75.
774 */
775 #define TCP_RTT_SCALE 32 /* multiplier for srtt; 3 bits frac. */
776 #define TCP_RTT_SHIFT 5 /* shift for srtt; 5 bits frac. */
777 #define TCP_RTTVAR_SCALE 16 /* multiplier for rttvar; 4 bits */
778 #define TCP_RTTVAR_SHIFT 4 /* shift for rttvar; 4 bits */
779 #define TCP_DELTA_SHIFT 2 /* see tcp_input.c */
780
781 /* TFO-specific defines */
782 #define TFO_COOKIE_LEN_MIN 4
783 #define TFO_COOKIE_LEN_DEFAULT 8
784 #define TFO_COOKIE_LEN_MAX 16
785
786 /*
787 * The initial retransmission should happen at rtt + 4 * rttvar.
788 * Because of the way we do the smoothing, srtt and rttvar
789 * will each average +1/2 tick of bias. When we compute
790 * the retransmit timer, we want 1/2 tick of rounding and
791 * 1 extra tick because of +-1/2 tick uncertainty in the
792 * firing of the timer. The bias will give us exactly the
793 * 1.5 tick we need. But, because the bias is
794 * statistical, we have to test that we don't drop below
795 * the minimum feasible timer (which is 2 ticks).
796 * This version of the macro adapted from a paper by Lawrence
797 * Brakmo and Larry Peterson which outlines a problem caused
798 * by insufficient precision in the original implementation,
799 * which results in inappropriately large RTO values for very
800 * fast networks.
801 */
802 #define TCP_REXMTVAL(tp) \
803 max((tp)->t_rttmin, (((tp)->t_srtt >> (TCP_RTT_SHIFT - TCP_DELTA_SHIFT)) \
804 + (tp)->t_rttvar) >> TCP_DELTA_SHIFT)
805
806 /*
807 * Jaguar compatible TCP control block, for xtcpcb
808 * Does not have the old fields
809 */
810 struct otcpcb {
811 #else
812 struct tseg_qent;
813 _TCPCB_LIST_HEAD(tsegqe_head, tseg_qent);
814
815 struct tcpcb {
816 #endif /* KERNEL_PRIVATE */
817 #if defined(KERNEL_PRIVATE)
818 u_int32_t t_segq;
819 #else
820 struct tsegqe_head t_segq;
821 #endif /* KERNEL_PRIVATE */
822 int t_dupacks; /* consecutive dup acks recd */
823 u_int32_t unused; /* unused now: was t_template */
824
825 int t_timer[TCPT_NTIMERS_EXT]; /* tcp timers */
826
827 _TCPCB_PTR(struct inpcb *) t_inpcb; /* back pointer to internet pcb */
828 int t_state; /* state of this connection */
829 u_int t_flags;
830 #define TF_ACKNOW 0x00001 /* ack peer immediately */
831 #define TF_DELACK 0x00002 /* ack, but try to delay it */
832 #define TF_NODELAY 0x00004 /* don't delay packets to coalesce */
833 #define TF_NOOPT 0x00008 /* don't use tcp options */
834 #define TF_SENTFIN 0x00010 /* have sent FIN */
835 #define TF_REQ_SCALE 0x00020 /* have/will request window scaling */
836 #define TF_RCVD_SCALE 0x00040 /* other side has requested scaling */
837 #define TF_REQ_TSTMP 0x00080 /* have/will request timestamps */
838 #define TF_RCVD_TSTMP 0x00100 /* a timestamp was received in SYN */
839 #define TF_SACK_PERMIT 0x00200 /* other side said I could SACK */
840 #define TF_NEEDSYN 0x00400 /* send SYN (implicit state) */
841 #define TF_NEEDFIN 0x00800 /* send FIN (implicit state) */
842 #define TF_NOPUSH 0x01000 /* don't push */
843 #define TF_REQ_CC 0x02000 /* have/will request CC */
844 #define TF_RCVD_CC 0x04000 /* a CC was received in SYN */
845 #define TF_SENDCCNEW 0x08000 /* Not implemented */
846 #define TF_MORETOCOME 0x10000 /* More data to be appended to sock */
847 #define TF_LQ_OVERFLOW 0x20000 /* listen queue overflow */
848 #define TF_RXWIN0SENT 0x40000 /* sent a receiver win 0 in response */
849 #define TF_SLOWLINK 0x80000 /* route is a on a modem speed link */
850
851 int t_force; /* 1 if forcing out a byte */
852
853 tcp_seq snd_una; /* send unacknowledged */
854 tcp_seq snd_max; /* highest sequence number sent;
855 * used to recognize retransmits
856 */
857 tcp_seq snd_nxt; /* send next */
858 tcp_seq snd_up; /* send urgent pointer */
859
860 tcp_seq snd_wl1; /* window update seg seq number */
861 tcp_seq snd_wl2; /* window update seg ack number */
862 tcp_seq iss; /* initial send sequence number */
863 tcp_seq irs; /* initial receive sequence number */
864
865 tcp_seq rcv_nxt; /* receive next */
866 tcp_seq rcv_adv; /* advertised window */
867 u_int32_t rcv_wnd; /* receive window */
868 tcp_seq rcv_up; /* receive urgent pointer */
869
870 u_int32_t snd_wnd; /* send window */
871 u_int32_t snd_cwnd; /* congestion-controlled window */
872 u_int32_t snd_ssthresh; /* snd_cwnd size threshold for
873 * for slow start exponential to
874 * linear switch
875 */
876 u_int t_maxopd; /* mss plus options */
877
878 u_int32_t t_rcvtime; /* time at which a packet was received */
879 u_int32_t t_starttime; /* time connection was established */
880 int t_rtttime; /* round trip time */
881 tcp_seq t_rtseq; /* sequence number being timed */
882
883 int t_rxtcur; /* current retransmit value (ticks) */
884 u_int t_maxseg; /* maximum segment size */
885 int t_srtt; /* smoothed round-trip time */
886 int t_rttvar; /* variance in round-trip time */
887
888 int t_rxtshift; /* log(2) of rexmt exp. backoff */
889 u_int t_rttmin; /* minimum rtt allowed */
890 u_int32_t t_rttupdated; /* number of times rtt sampled */
891 u_int32_t max_sndwnd; /* largest window peer has offered */
892
893 int t_softerror; /* possible error not yet reported */
894 /* out-of-band data */
895 char t_oobflags; /* have some */
896 char t_iobc; /* input character */
897 #define TCPOOB_HAVEDATA 0x01
898 #define TCPOOB_HADDATA 0x02
899 /* RFC 1323 variables */
900 u_char snd_scale; /* window scaling for send window */
901 u_char rcv_scale; /* window scaling for recv window */
902 u_char request_r_scale; /* pending window scaling */
903 u_char requested_s_scale;
904 u_int32_t ts_recent; /* timestamp echo data */
905
906 u_int32_t ts_recent_age; /* when last updated */
907 tcp_seq last_ack_sent;
908 /* RFC 1644 variables */
909 tcp_cc cc_send; /* send connection count */
910 tcp_cc cc_recv; /* receive connection count */
911 tcp_seq snd_recover; /* for use in fast recovery */
912 /* experimental */
913 u_int32_t snd_cwnd_prev; /* cwnd prior to retransmit */
914 u_int32_t snd_ssthresh_prev; /* ssthresh prior to retransmit */
915 u_int32_t t_badrxtwin; /* window for retransmit recovery */
916 };
917
918 #define tcps_ecn_setup tcps_ecn_client_success
919 #define tcps_sent_cwr tcps_ecn_recv_ece
920 #define tcps_sent_ece tcps_ecn_sent_ece
921
922 /*
923 * TCP statistics.
924 * Many of these should be kept per connection,
925 * but that's inconvenient at the moment.
926 */
927 struct tcpstat {
928 u_int32_t tcps_connattempt; /* connections initiated */
929 u_int32_t tcps_accepts; /* connections accepted */
930 u_int32_t tcps_connects; /* connections established */
931 u_int32_t tcps_drops; /* connections dropped */
932 u_int32_t tcps_conndrops; /* embryonic connections dropped */
933 u_int32_t tcps_closed; /* conn. closed (includes drops) */
934 u_int32_t tcps_segstimed; /* segs where we tried to get rtt */
935 u_int32_t tcps_rttupdated; /* times we succeeded */
936 u_int32_t tcps_delack; /* delayed acks sent */
937 u_int32_t tcps_timeoutdrop; /* conn. dropped in rxmt timeout */
938 u_int32_t tcps_rexmttimeo; /* retransmit timeouts */
939 u_int32_t tcps_persisttimeo; /* persist timeouts */
940 u_int32_t tcps_keeptimeo; /* keepalive timeouts */
941 u_int32_t tcps_keepprobe; /* keepalive probes sent */
942 u_int32_t tcps_keepdrops; /* connections dropped in keepalive */
943
944 u_int32_t tcps_sndtotal; /* total packets sent */
945 u_int32_t tcps_sndpack; /* data packets sent */
946 u_int32_t tcps_sndbyte; /* data bytes sent */
947 u_int32_t tcps_sndrexmitpack; /* data packets retransmitted */
948 u_int32_t tcps_sndrexmitbyte; /* data bytes retransmitted */
949 u_int32_t tcps_sndacks; /* ack-only packets sent */
950 u_int32_t tcps_sndprobe; /* window probes sent */
951 u_int32_t tcps_sndurg; /* packets sent with URG only */
952 u_int32_t tcps_sndwinup; /* window update-only packets sent */
953 u_int32_t tcps_sndctrl; /* control (SYN|FIN|RST) packets sent */
954
955 u_int32_t tcps_rcvtotal; /* total packets received */
956 u_int32_t tcps_rcvpack; /* packets received in sequence */
957 u_int32_t tcps_rcvbyte; /* bytes received in sequence */
958 u_int32_t tcps_rcvbadsum; /* packets received with ccksum errs */
959 u_int32_t tcps_rcvbadoff; /* packets received with bad offset */
960 u_int32_t tcps_rcvmemdrop; /* packets dropped for lack of memory */
961 u_int32_t tcps_rcvshort; /* packets received too short */
962 u_int32_t tcps_rcvduppack; /* duplicate-only packets received */
963 u_int32_t tcps_rcvdupbyte; /* duplicate-only bytes received */
964 u_int32_t tcps_rcvpartduppack; /* packets with some duplicate data */
965 u_int32_t tcps_rcvpartdupbyte; /* dup. bytes in part-dup. packets */
966 u_int32_t tcps_rcvoopack; /* out-of-order packets received */
967 u_int32_t tcps_rcvoobyte; /* out-of-order bytes received */
968 u_int32_t tcps_rcvpackafterwin; /* packets with data after window */
969 u_int32_t tcps_rcvbyteafterwin; /* bytes rcvd after window */
970 u_int32_t tcps_rcvafterclose; /* packets rcvd after "close" */
971 u_int32_t tcps_rcvwinprobe; /* rcvd window probe packets */
972 u_int32_t tcps_rcvdupack; /* rcvd duplicate acks */
973 u_int32_t tcps_rcvacktoomuch; /* rcvd acks for unsent data */
974 u_int32_t tcps_rcvackpack; /* rcvd ack packets */
975 u_int32_t tcps_rcvackbyte; /* bytes acked by rcvd acks */
976 u_int32_t tcps_rcvwinupd; /* rcvd window update packets */
977 u_int32_t tcps_pawsdrop; /* segments dropped due to PAWS */
978 u_int32_t tcps_predack; /* times hdr predict ok for acks */
979 u_int32_t tcps_preddat; /* times hdr predict ok for data pkts */
980 u_int32_t tcps_pcbcachemiss;
981 u_int32_t tcps_cachedrtt; /* times cached RTT in route updated */
982 u_int32_t tcps_cachedrttvar; /* times cached rttvar updated */
983 u_int32_t tcps_cachedssthresh; /* times cached ssthresh updated */
984 u_int32_t tcps_usedrtt; /* times RTT initialized from route */
985 u_int32_t tcps_usedrttvar; /* times RTTVAR initialized from rt */
986 u_int32_t tcps_usedssthresh; /* times ssthresh initialized from rt*/
987 u_int32_t tcps_persistdrop; /* timeout in persist state */
988 u_int32_t tcps_badsyn; /* bogus SYN, e.g. premature ACK */
989 u_int32_t tcps_mturesent; /* resends due to MTU discovery */
990 u_int32_t tcps_listendrop; /* listen queue overflows */
991
992 /* new stats from FreeBSD 5.4 sync up */
993 u_int32_t tcps_minmssdrops; /* average minmss too low drops */
994 u_int32_t tcps_sndrexmitbad; /* unnecessary packet retransmissions */
995 u_int32_t tcps_badrst; /* ignored RSTs in the window */
996
997 u_int32_t tcps_sc_added; /* entry added to syncache */
998 u_int32_t tcps_sc_retransmitted; /* syncache entry was retransmitted */
999 u_int32_t tcps_sc_dupsyn; /* duplicate SYN packet */
1000 u_int32_t tcps_sc_dropped; /* could not reply to packet */
1001 u_int32_t tcps_sc_completed; /* successful extraction of entry */
1002 u_int32_t tcps_sc_bucketoverflow; /* syncache per-bucket limit hit */
1003 u_int32_t tcps_sc_cacheoverflow; /* syncache cache limit hit */
1004 u_int32_t tcps_sc_reset; /* RST removed entry from syncache */
1005 u_int32_t tcps_sc_stale; /* timed out or listen socket gone */
1006 u_int32_t tcps_sc_aborted; /* syncache entry aborted */
1007 u_int32_t tcps_sc_badack; /* removed due to bad ACK */
1008 u_int32_t tcps_sc_unreach; /* ICMP unreachable received */
1009 u_int32_t tcps_sc_zonefail; /* zalloc() failed */
1010 u_int32_t tcps_sc_sendcookie; /* SYN cookie sent */
1011 u_int32_t tcps_sc_recvcookie; /* SYN cookie received */
1012
1013 u_int32_t tcps_hc_added; /* entry added to hostcache */
1014 u_int32_t tcps_hc_bucketoverflow; /* hostcache per bucket limit hit */
1015
1016 /* SACK related stats */
1017 u_int32_t tcps_sack_recovery_episode; /* SACK recovery episodes */
1018 u_int32_t tcps_sack_rexmits; /* SACK rexmit segments */
1019 u_int32_t tcps_sack_rexmit_bytes; /* SACK rexmit bytes */
1020 u_int32_t tcps_sack_rcv_blocks; /* SACK blocks (options) received */
1021 u_int32_t tcps_sack_send_blocks; /* SACK blocks (options) sent */
1022 u_int32_t tcps_sack_sboverflow; /* SACK sendblock overflow */
1023
1024 u_int32_t tcps_bg_rcvtotal; /* total background packets received */
1025 u_int32_t tcps_rxtfindrop; /* drop conn after retransmitting FIN */
1026 u_int32_t tcps_fcholdpacket; /* packets withheld because of flow control */
1027
1028 /* LRO related stats */
1029 u_int32_t tcps_coalesced_pack; /* number of coalesced packets */
1030 u_int32_t tcps_flowtbl_full; /* times flow table was full */
1031 u_int32_t tcps_flowtbl_collision; /* collisions in flow tbl */
1032 u_int32_t tcps_lro_twopack; /* 2 packets coalesced */
1033 u_int32_t tcps_lro_multpack; /* 3 or 4 pkts coalesced */
1034 u_int32_t tcps_lro_largepack; /* 5 or more pkts coalesced */
1035
1036 u_int32_t tcps_limited_txt; /* Limited transmit used */
1037 u_int32_t tcps_early_rexmt; /* Early retransmit used */
1038 u_int32_t tcps_sack_ackadv; /* Cumulative ack advanced along with sack */
1039
1040 /* Checksum related stats */
1041 u_int32_t tcps_rcv_swcsum; /* tcp swcksum (inbound), packets */
1042 u_int32_t tcps_rcv_swcsum_bytes; /* tcp swcksum (inbound), bytes */
1043 u_int32_t tcps_rcv6_swcsum; /* tcp6 swcksum (inbound), packets */
1044 u_int32_t tcps_rcv6_swcsum_bytes; /* tcp6 swcksum (inbound), bytes */
1045 u_int32_t tcps_snd_swcsum; /* tcp swcksum (outbound), packets */
1046 u_int32_t tcps_snd_swcsum_bytes; /* tcp swcksum (outbound), bytes */
1047 u_int32_t tcps_snd6_swcsum; /* tcp6 swcksum (outbound), packets */
1048 u_int32_t tcps_snd6_swcsum_bytes; /* tcp6 swcksum (outbound), bytes */
1049 u_int32_t tcps_msg_unopkts; /* unordered packet on TCP msg stream */
1050 u_int32_t tcps_msg_unoappendfail; /* failed to append unordered pkt */
1051 u_int32_t tcps_msg_sndwaithipri; /* send is waiting for high priority data */
1052
1053 /* MPTCP Related stats */
1054 u_int32_t tcps_invalid_mpcap; /* Invalid MPTCP capable opts */
1055 u_int32_t tcps_invalid_joins; /* Invalid MPTCP joins */
1056 u_int32_t tcps_mpcap_fallback; /* TCP fallback in primary */
1057 u_int32_t tcps_join_fallback; /* No MPTCP in secondary */
1058 u_int32_t tcps_estab_fallback; /* DSS option dropped */
1059 u_int32_t tcps_invalid_opt; /* Catchall error stat */
1060 u_int32_t tcps_mp_outofwin; /* Packet lies outside the
1061 shared recv window */
1062 u_int32_t tcps_mp_reducedwin; /* Reduced subflow window */
1063 u_int32_t tcps_mp_badcsum; /* Bad DSS csum */
1064 u_int32_t tcps_mp_oodata; /* Out of order data */
1065 u_int32_t tcps_mp_switches; /* number of subflow switch */
1066 u_int32_t tcps_mp_rcvtotal; /* number of rcvd packets */
1067 u_int32_t tcps_mp_rcvbytes; /* number of bytes received */
1068 u_int32_t tcps_mp_sndpacks; /* number of data packs sent */
1069 u_int32_t tcps_mp_sndbytes; /* number of bytes sent */
1070 u_int32_t tcps_join_rxmts; /* join ack retransmits */
1071 u_int32_t tcps_tailloss_rto; /* RTO due to tail loss */
1072 u_int32_t tcps_reordered_pkts; /* packets reorderd */
1073 u_int32_t tcps_recovered_pkts; /* recovered after loss */
1074 u_int32_t tcps_pto; /* probe timeout */
1075 u_int32_t tcps_rto_after_pto; /* RTO after a probe */
1076 u_int32_t tcps_tlp_recovery; /* TLP induced fast recovery */
1077 u_int32_t tcps_tlp_recoverlastpkt; /* TLP recoverd last pkt */
1078 u_int32_t tcps_ecn_client_success; /* client-side connection negotiated ECN */
1079 u_int32_t tcps_ecn_recv_ece; /* ECE received, sent CWR */
1080 u_int32_t tcps_ecn_sent_ece; /* Sent ECE notification */
1081 u_int32_t tcps_detect_reordering; /* Detect pkt reordering */
1082 u_int32_t tcps_delay_recovery; /* Delay fast recovery */
1083 u_int32_t tcps_avoid_rxmt; /* Retransmission was avoided */
1084 u_int32_t tcps_unnecessary_rxmt; /* Retransmission was not needed */
1085 u_int32_t tcps_nostretchack; /* disabled stretch ack algorithm on a connection */
1086 u_int32_t tcps_rescue_rxmt; /* SACK rescue retransmit */
1087 u_int32_t tcps_pto_in_recovery; /* rescue retransmit in fast recovery */
1088 u_int32_t tcps_pmtudbh_reverted; /* PMTU Blackhole detection, segment size reverted */
1089
1090 /* DSACK related statistics */
1091 u_int32_t tcps_dsack_disable; /* DSACK disabled due to n/w duplication */
1092 u_int32_t tcps_dsack_ackloss; /* ignore DSACK due to ack loss */
1093 u_int32_t tcps_dsack_badrexmt; /* DSACK based bad rexmt recovery */
1094 u_int32_t tcps_dsack_sent; /* Sent DSACK notification */
1095 u_int32_t tcps_dsack_recvd; /* Received a valid DSACK option */
1096 u_int32_t tcps_dsack_recvd_old; /* Received an out of window DSACK option */
1097
1098 /* MPTCP Subflow selection stats */
1099 u_int32_t tcps_mp_sel_symtomsd; /* By symptomsd */
1100 u_int32_t tcps_mp_sel_rtt; /* By RTT comparison */
1101 u_int32_t tcps_mp_sel_rto; /* By RTO comparison */
1102 u_int32_t tcps_mp_sel_peer; /* By peer's output pattern */
1103 u_int32_t tcps_mp_num_probes; /* Number of probes sent */
1104 u_int32_t tcps_mp_verdowngrade; /* MPTCP version downgrade */
1105 u_int32_t tcps_drop_after_sleep; /* drop after long AP sleep */
1106 u_int32_t tcps_probe_if; /* probe packets after interface availability */
1107 u_int32_t tcps_probe_if_conflict; /* Can't send probe packets for interface */
1108
1109 u_int32_t tcps_ecn_client_setup; /* Attempted ECN setup from client side */
1110 u_int32_t tcps_ecn_server_setup; /* Attempted ECN setup from server side */
1111 u_int32_t tcps_ecn_server_success; /* server-side connection negotiated ECN */
1112 u_int32_t tcps_ecn_lost_synack; /* Lost SYN-ACK with ECN setup */
1113 u_int32_t tcps_ecn_lost_syn; /* Lost SYN with ECN setup */
1114 u_int32_t tcps_ecn_not_supported; /* Server did not support ECN setup */
1115 u_int32_t tcps_ecn_recv_ce; /* Received CE from the network */
1116 u_int32_t tcps_ecn_conn_recv_ce; /* Number of connections received CE atleast once */
1117 u_int32_t tcps_ecn_conn_recv_ece; /* Number of connections received ECE atleast once */
1118 u_int32_t tcps_ecn_conn_plnoce; /* Number of connections that received no CE and sufferred packet loss */
1119 u_int32_t tcps_ecn_conn_pl_ce; /* Number of connections that received CE and sufferred packet loss */
1120 u_int32_t tcps_ecn_conn_nopl_ce; /* Number of connections that received CE and sufferred no packet loss */
1121 u_int32_t tcps_ecn_fallback_synloss; /* Number of times we did fall back due to SYN-Loss */
1122 u_int32_t tcps_ecn_fallback_reorder; /* Number of times we fallback because we detected the PAWS-issue */
1123 u_int32_t tcps_ecn_fallback_ce; /* Number of times we fallback because we received too many CEs */
1124
1125 /* TFO-related statistics */
1126 u_int32_t tcps_tfo_syn_data_rcv; /* Received a SYN+data with valid cookie */
1127 u_int32_t tcps_tfo_cookie_req_rcv;/* Received a TFO cookie-request */
1128 u_int32_t tcps_tfo_cookie_sent; /* Offered a TFO-cookie to the client */
1129 u_int32_t tcps_tfo_cookie_invalid;/* Received an invalid TFO-cookie */
1130 u_int32_t tcps_tfo_cookie_req; /* Cookie requested with the SYN */
1131 u_int32_t tcps_tfo_cookie_rcv; /* Cookie received in a SYN/ACK */
1132 u_int32_t tcps_tfo_syn_data_sent; /* SYN+data+cookie sent */
1133 u_int32_t tcps_tfo_syn_data_acked;/* SYN+data has been acknowledged */
1134 u_int32_t tcps_tfo_syn_loss; /* SYN+TFO has been lost and we fallback */
1135 u_int32_t tcps_tfo_blackhole; /* TFO got blackholed by a middlebox. */
1136 };
1137
1138
1139 struct tcpstat_local {
1140 u_int64_t badformat;
1141 u_int64_t unspecv6;
1142 u_int64_t synfin;
1143 u_int64_t badformatipsec;
1144 u_int64_t noconnnolist;
1145 u_int64_t noconnlist;
1146 u_int64_t listbadsyn;
1147 u_int64_t icmp6unreach;
1148 u_int64_t deprecate6;
1149 u_int64_t ooopacket;
1150 u_int64_t rstinsynrcv;
1151 u_int64_t dospacket;
1152 u_int64_t cleanup;
1153 u_int64_t synwindow;
1154 };
1155
1156 #pragma pack(4)
1157
1158 /*
1159 * TCB structure exported to user-land via sysctl(3).
1160 * Evil hack: declare only if in_pcb.h and sys/socketvar.h have been
1161 * included. Not all of our clients do.
1162 */
1163
1164 struct xtcpcb {
1165 u_int32_t xt_len;
1166 #ifdef KERNEL_PRIVATE
1167 struct inpcb_compat xt_inp;
1168 #else
1169 struct inpcb xt_inp;
1170 #endif
1171 #ifdef KERNEL_PRIVATE
1172 struct otcpcb xt_tp;
1173 #else
1174 struct tcpcb xt_tp;
1175 #endif
1176 struct xsocket xt_socket;
1177 u_quad_t xt_alignment_hack;
1178 };
1179
1180
1181 struct xtcpcb64 {
1182 u_int32_t xt_len;
1183 struct xinpcb64 xt_inpcb;
1184
1185 u_int64_t t_segq;
1186 int t_dupacks; /* consecutive dup acks recd */
1187
1188 int t_timer[TCPT_NTIMERS_EXT]; /* tcp timers */
1189
1190 int t_state; /* state of this connection */
1191 u_int t_flags;
1192
1193 int t_force; /* 1 if forcing out a byte */
1194
1195 tcp_seq snd_una; /* send unacknowledged */
1196 tcp_seq snd_max; /* highest sequence number sent;
1197 * used to recognize retransmits
1198 */
1199 tcp_seq snd_nxt; /* send next */
1200 tcp_seq snd_up; /* send urgent pointer */
1201
1202 tcp_seq snd_wl1; /* window update seg seq number */
1203 tcp_seq snd_wl2; /* window update seg ack number */
1204 tcp_seq iss; /* initial send sequence number */
1205 tcp_seq irs; /* initial receive sequence number */
1206
1207 tcp_seq rcv_nxt; /* receive next */
1208 tcp_seq rcv_adv; /* advertised window */
1209 u_int32_t rcv_wnd; /* receive window */
1210 tcp_seq rcv_up; /* receive urgent pointer */
1211
1212 u_int32_t snd_wnd; /* send window */
1213 u_int32_t snd_cwnd; /* congestion-controlled window */
1214 u_int32_t snd_ssthresh; /* snd_cwnd size threshold for
1215 * for slow start exponential to
1216 * linear switch
1217 */
1218 u_int t_maxopd; /* mss plus options */
1219
1220 u_int32_t t_rcvtime; /* time at which a packet was received */
1221 u_int32_t t_starttime; /* time connection was established */
1222 int t_rtttime; /* round trip time */
1223 tcp_seq t_rtseq; /* sequence number being timed */
1224
1225 int t_rxtcur; /* current retransmit value (ticks) */
1226 u_int t_maxseg; /* maximum segment size */
1227 int t_srtt; /* smoothed round-trip time */
1228 int t_rttvar; /* variance in round-trip time */
1229
1230 int t_rxtshift; /* log(2) of rexmt exp. backoff */
1231 u_int t_rttmin; /* minimum rtt allowed */
1232 u_int32_t t_rttupdated; /* number of times rtt sampled */
1233 u_int32_t max_sndwnd; /* largest window peer has offered */
1234
1235 int t_softerror; /* possible error not yet reported */
1236 /* out-of-band data */
1237 char t_oobflags; /* have some */
1238 char t_iobc; /* input character */
1239 /* RFC 1323 variables */
1240 u_char snd_scale; /* window scaling for send window */
1241 u_char rcv_scale; /* window scaling for recv window */
1242 u_char request_r_scale; /* pending window scaling */
1243 u_char requested_s_scale;
1244 u_int32_t ts_recent; /* timestamp echo data */
1245
1246 u_int32_t ts_recent_age; /* when last updated */
1247 tcp_seq last_ack_sent;
1248 /* RFC 1644 variables */
1249 tcp_cc cc_send; /* send connection count */
1250 tcp_cc cc_recv; /* receive connection count */
1251 tcp_seq snd_recover; /* for use in fast recovery */
1252 /* experimental */
1253 u_int32_t snd_cwnd_prev; /* cwnd prior to retransmit */
1254 u_int32_t snd_ssthresh_prev; /* ssthresh prior to retransmit */
1255 u_int32_t t_badrxtwin; /* window for retransmit recovery */
1256
1257 u_quad_t xt_alignment_hack;
1258 };
1259
1260
1261 #ifdef PRIVATE
1262
1263 struct xtcpcb_n {
1264 u_int32_t xt_len;
1265 u_int32_t xt_kind; /* XSO_TCPCB */
1266
1267 u_int64_t t_segq;
1268 int t_dupacks; /* consecutive dup acks recd */
1269
1270 int t_timer[TCPT_NTIMERS_EXT]; /* tcp timers */
1271
1272 int t_state; /* state of this connection */
1273 u_int t_flags;
1274
1275 int t_force; /* 1 if forcing out a byte */
1276
1277 tcp_seq snd_una; /* send unacknowledged */
1278 tcp_seq snd_max; /* highest sequence number sent;
1279 * used to recognize retransmits
1280 */
1281 tcp_seq snd_nxt; /* send next */
1282 tcp_seq snd_up; /* send urgent pointer */
1283
1284 tcp_seq snd_wl1; /* window update seg seq number */
1285 tcp_seq snd_wl2; /* window update seg ack number */
1286 tcp_seq iss; /* initial send sequence number */
1287 tcp_seq irs; /* initial receive sequence number */
1288
1289 tcp_seq rcv_nxt; /* receive next */
1290 tcp_seq rcv_adv; /* advertised window */
1291 u_int32_t rcv_wnd; /* receive window */
1292 tcp_seq rcv_up; /* receive urgent pointer */
1293
1294 u_int32_t snd_wnd; /* send window */
1295 u_int32_t snd_cwnd; /* congestion-controlled window */
1296 u_int32_t snd_ssthresh; /* snd_cwnd size threshold for
1297 * for slow start exponential to
1298 * linear switch
1299 */
1300 u_int t_maxopd; /* mss plus options */
1301
1302 u_int32_t t_rcvtime; /* time at which a packet was received */
1303 u_int32_t t_starttime; /* time connection was established */
1304 int t_rtttime; /* round trip time */
1305 tcp_seq t_rtseq; /* sequence number being timed */
1306
1307 int t_rxtcur; /* current retransmit value (ticks) */
1308 u_int t_maxseg; /* maximum segment size */
1309 int t_srtt; /* smoothed round-trip time */
1310 int t_rttvar; /* variance in round-trip time */
1311
1312 int t_rxtshift; /* log(2) of rexmt exp. backoff */
1313 u_int t_rttmin; /* minimum rtt allowed */
1314 u_int32_t t_rttupdated; /* number of times rtt sampled */
1315 u_int32_t max_sndwnd; /* largest window peer has offered */
1316
1317 int t_softerror; /* possible error not yet reported */
1318 /* out-of-band data */
1319 char t_oobflags; /* have some */
1320 char t_iobc; /* input character */
1321 /* RFC 1323 variables */
1322 u_char snd_scale; /* window scaling for send window */
1323 u_char rcv_scale; /* window scaling for recv window */
1324 u_char request_r_scale; /* pending window scaling */
1325 u_char requested_s_scale;
1326 u_int32_t ts_recent; /* timestamp echo data */
1327
1328 u_int32_t ts_recent_age; /* when last updated */
1329 tcp_seq last_ack_sent;
1330 /* RFC 1644 variables */
1331 tcp_cc cc_send; /* send connection count */
1332 tcp_cc cc_recv; /* receive connection count */
1333 tcp_seq snd_recover; /* for use in fast recovery */
1334 /* experimental */
1335 u_int32_t snd_cwnd_prev; /* cwnd prior to retransmit */
1336 u_int32_t snd_ssthresh_prev; /* ssthresh prior to retransmit */
1337 };
1338
1339 #endif /* PRIVATE */
1340
1341 #pragma pack()
1342
1343 /*
1344 * Names for TCP sysctl objects
1345 */
1346 #define TCPCTL_DO_RFC1323 1 /* use RFC-1323 extensions */
1347 #define TCPCTL_DO_RFC1644 2 /* use RFC-1644 extensions */
1348 #define TCPCTL_MSSDFLT 3 /* MSS default */
1349 #define TCPCTL_STATS 4 /* statistics (read-only) */
1350 #define TCPCTL_RTTDFLT 5 /* default RTT estimate */
1351 #define TCPCTL_KEEPIDLE 6 /* keepalive idle timer */
1352 #define TCPCTL_KEEPINTVL 7 /* interval to send keepalives */
1353 #define TCPCTL_SENDSPACE 8 /* send buffer space */
1354 #define TCPCTL_RECVSPACE 9 /* receive buffer space */
1355 #define TCPCTL_KEEPINIT 10 /* timeout for establishing syn */
1356 #define TCPCTL_PCBLIST 11 /* list of all outstanding PCBs */
1357 #define TCPCTL_DELACKTIME 12 /* time before sending delayed ACK */
1358 #define TCPCTL_V6MSSDFLT 13 /* MSS default for IPv6 */
1359 #define TCPCTL_MAXID 14
1360
1361 #ifdef BSD_KERNEL_PRIVATE
1362 #include <sys/bitstring.h>
1363
1364 #define TCP_PKTLIST_CLEAR(tp) { \
1365 (tp)->t_pktlist_head = (tp)->t_pktlist_tail = NULL; \
1366 (tp)->t_lastchain = (tp)->t_pktlist_sentlen = 0; \
1367 }
1368
1369 #define TCPCTL_NAMES { \
1370 { 0, 0 }, \
1371 { "rfc1323", CTLTYPE_INT }, \
1372 { "rfc1644", CTLTYPE_INT }, \
1373 { "mssdflt", CTLTYPE_INT }, \
1374 { "stats", CTLTYPE_STRUCT }, \
1375 { "rttdflt", CTLTYPE_INT }, \
1376 { "keepidle", CTLTYPE_INT }, \
1377 { "keepintvl", CTLTYPE_INT }, \
1378 { "sendspace", CTLTYPE_INT }, \
1379 { "recvspace", CTLTYPE_INT }, \
1380 { "keepinit", CTLTYPE_INT }, \
1381 { "pcblist", CTLTYPE_STRUCT }, \
1382 { "delacktime", CTLTYPE_INT }, \
1383 { "v6mssdflt", CTLTYPE_INT }, \
1384 }
1385
1386 #ifdef SYSCTL_DECL
1387 SYSCTL_DECL(_net_inet_tcp);
1388 #endif /* SYSCTL_DECL */
1389
1390 extern struct inpcbhead tcb; /* head of queue of active tcpcb's */
1391 extern struct inpcbinfo tcbinfo;
1392 extern struct tcpstat tcpstat; /* tcp statistics */
1393 extern int tcp_mssdflt; /* XXX */
1394 extern int tcp_minmss;
1395 #define TCP_FASTOPEN_SERVER 0x01
1396 #define TCP_FASTOPEN_CLIENT 0x02
1397
1398 extern int tcp_tfo_halfcnt;
1399 extern int tcp_tfo_backlog;
1400 extern int tcp_fastopen;
1401 extern int tcp_tfo_fallback_min;
1402 extern int ss_fltsz;
1403 extern int ss_fltsz_local;
1404 extern int tcp_do_rfc3390; /* Calculate ss_fltsz according to RFC 3390 */
1405 extern int tcp_do_rfc1323;
1406 extern int target_qdelay;
1407 extern u_int32_t tcp_now; /* for RFC 1323 timestamps */
1408 extern struct timeval tcp_uptime;
1409 extern lck_spin_t *tcp_uptime_lock;
1410 extern int tcp_delack_enabled;
1411 extern int tcp_do_sack; /* SACK enabled/disabled */
1412 extern int tcp_do_rfc3465;
1413 extern int tcp_do_rfc3465_lim2;
1414 extern int maxseg_unacked;
1415 extern int tcp_use_newreno;
1416 extern struct zone *tcp_reass_zone;
1417 extern struct zone *tcp_rxt_seg_zone;
1418 extern int tcp_ecn_outbound;
1419 extern int tcp_ecn_inbound;
1420
1421
1422 #if CONFIG_IFEF_NOWINDOWSCALE
1423 extern int tcp_obey_ifef_nowindowscale;
1424 #endif
1425
1426 struct protosw;
1427 struct domain;
1428
1429 struct tcp_respond_args {
1430 unsigned int ifscope;
1431 unsigned int nocell:1,
1432 noexpensive:1,
1433 awdl_unrestricted:1;
1434 };
1435
1436 void tcp_canceltimers(struct tcpcb *);
1437 struct tcpcb *
1438 tcp_close(struct tcpcb *);
1439 void tcp_ctlinput(int, struct sockaddr *, void *);
1440 int tcp_ctloutput(struct socket *, struct sockopt *);
1441 struct tcpcb *
1442 tcp_drop(struct tcpcb *, int);
1443 void tcp_drain(void);
1444 void tcp_getrt_rtt(struct tcpcb *tp, struct rtentry *rt);
1445 struct rmxp_tao *
1446 tcp_gettaocache(struct inpcb *);
1447 void tcp_init(struct protosw *, struct domain *);
1448 void tcp_input(struct mbuf *, int);
1449 void tcp_mss(struct tcpcb *, int, unsigned int);
1450 int tcp_mssopt(struct tcpcb *);
1451 void tcp_drop_syn_sent(struct inpcb *, int);
1452 void tcp_mtudisc(struct inpcb *, int);
1453 struct tcpcb *
1454 tcp_newtcpcb(struct inpcb *);
1455 int tcp_output(struct tcpcb *);
1456 void tcp_respond(struct tcpcb *, void *, struct tcphdr *, struct mbuf *,
1457 tcp_seq, tcp_seq, int, struct tcp_respond_args *);
1458 struct rtentry *
1459 tcp_rtlookup(struct inpcb *, unsigned int);
1460 void tcp_setpersist(struct tcpcb *);
1461 void tcp_gc(struct inpcbinfo *);
1462 void tcp_itimer(struct inpcbinfo *ipi);
1463 void tcp_check_timer_state(struct tcpcb *tp);
1464 void tcp_run_timerlist(void *arg1, void *arg2);
1465
1466 struct tcptemp *tcp_maketemplate(struct tcpcb *);
1467 void tcp_fillheaders(struct tcpcb *, void *, void *);
1468 struct tcpcb *tcp_timers(struct tcpcb *, int);
1469 void tcp_trace(int, int, struct tcpcb *, void *, struct tcphdr *, int);
1470
1471 void tcp_sack_doack(struct tcpcb *, struct tcpopt *, struct tcphdr *,
1472 u_int32_t *);
1473 extern boolean_t tcp_sack_process_dsack(struct tcpcb *, struct tcpopt *,
1474 struct tcphdr *);
1475 int tcp_detect_bad_rexmt(struct tcpcb *, struct tcphdr *, struct tcpopt *,
1476 u_int32_t rxtime);
1477 void tcp_update_sack_list(struct tcpcb *tp, tcp_seq rcv_laststart, tcp_seq rcv_lastend);
1478 void tcp_clean_sackreport(struct tcpcb *tp);
1479 void tcp_sack_adjust(struct tcpcb *tp);
1480 struct sackhole *tcp_sack_output(struct tcpcb *tp, int *sack_bytes_rexmt);
1481 void tcp_sack_partialack(struct tcpcb *, struct tcphdr *);
1482 void tcp_free_sackholes(struct tcpcb *tp);
1483 int32_t tcp_sbspace(struct tcpcb *tp);
1484 void tcp_set_tso(struct tcpcb *tp, struct ifnet *ifp);
1485 void tcp_set_ecn(struct tcpcb *tp, struct ifnet *ifp);
1486 void tcp_reset_stretch_ack(struct tcpcb *tp);
1487 extern void tcp_get_ports_used(u_int32_t, int, u_int32_t, bitstr_t *);
1488 uint32_t tcp_count_opportunistic(unsigned int ifindex, u_int32_t flags);
1489 uint32_t tcp_find_anypcb_byaddr(struct ifaddr *ifa);
1490 void tcp_set_max_rwinscale(struct tcpcb *tp, struct socket *so);
1491 struct bwmeas* tcp_bwmeas_alloc(struct tcpcb *tp);
1492 void tcp_bwmeas_free(struct tcpcb *tp);
1493 extern int32_t timer_diff(uint32_t t1, uint32_t toff1, uint32_t t2, uint32_t toff2);
1494
1495 extern void tcp_set_background_cc(struct socket *);
1496 extern void tcp_set_foreground_cc(struct socket *);
1497 extern void tcp_set_recv_bg(struct socket *);
1498 extern void tcp_clear_recv_bg(struct socket *);
1499 extern boolean_t tcp_sack_byte_islost(struct tcpcb *tp);
1500 #define IS_TCP_RECV_BG(_so) \
1501 ((_so)->so_traffic_mgt_flags & TRAFFIC_MGT_TCP_RECVBG)
1502
1503 #if TRAFFIC_MGT
1504 #define CLEAR_IAJ_STATE(_tp_) (_tp_)->iaj_rcv_ts = 0
1505 void reset_acc_iaj(struct tcpcb *tp);
1506 #endif /* TRAFFIC_MGT */
1507
1508 int tcp_lock (struct socket *, int, void *);
1509 int tcp_unlock (struct socket *, int, void *);
1510 void calculate_tcp_clock(void);
1511
1512 extern void tcp_keepalive_reset(struct tcpcb *);
1513 extern uint32_t get_base_rtt(struct tcpcb *tp);
1514
1515 #ifdef _KERN_LOCKS_H_
1516 lck_mtx_t * tcp_getlock (struct socket *, int);
1517 #else
1518 void * tcp_getlock (struct socket *, int);
1519 #endif
1520
1521
1522 extern struct pr_usrreqs tcp_usrreqs;
1523 extern u_int32_t tcp_sendspace;
1524 extern u_int32_t tcp_recvspace;
1525 tcp_seq tcp_new_isn(struct tcpcb *);
1526
1527 extern int tcp_input_checksum(int, struct mbuf *, struct tcphdr *, int, int);
1528 extern void tcp_getconninfo(struct socket *, struct conninfo_tcp *);
1529 extern void add_to_time_wait(struct tcpcb *, uint32_t delay);
1530 extern void tcp_pmtud_revert_segment_size(struct tcpcb *tp);
1531 extern void tcp_rxtseg_insert(struct tcpcb *, tcp_seq, tcp_seq);
1532 extern struct tcp_rxt_seg *tcp_rxtseg_find(struct tcpcb *, tcp_seq, tcp_seq);
1533 extern void tcp_rxtseg_clean(struct tcpcb *);
1534 extern boolean_t tcp_rxtseg_detect_bad_rexmt(struct tcpcb *, tcp_seq);
1535 extern boolean_t tcp_rxtseg_dsack_for_tlp(struct tcpcb *);
1536 extern u_int32_t tcp_rxtseg_total_size(struct tcpcb *tp);
1537 extern void tcp_rexmt_save_state(struct tcpcb *tp);
1538 extern void tcp_interface_send_probe(u_int16_t if_index_available);
1539 extern void tcp_probe_connectivity(struct ifnet *ifp, u_int32_t enable);
1540 extern void tcp_get_connectivity_status(struct tcpcb *,
1541 struct tcp_conn_status *);
1542
1543 extern boolean_t tfo_enabled(const struct tcpcb *tp);
1544 extern void tcp_disable_tfo(struct tcpcb *tp);
1545 extern void tcp_tfo_gen_cookie(struct inpcb *inp, u_char *out, size_t blk_size);
1546 #define TCP_FASTOPEN_KEYLEN 16
1547
1548 #if MPTCP
1549 extern int mptcp_input_preproc(struct tcpcb *, struct mbuf *, int);
1550 extern void mptcp_output_csum(struct tcpcb *, struct mbuf *, int32_t, unsigned,
1551 u_int64_t, u_int32_t *);
1552 extern int mptcp_adj_mss(struct tcpcb *, boolean_t);
1553 extern void mptcp_insert_rmap(struct tcpcb *, struct mbuf *);
1554 #endif
1555 #endif /* BSD_KERNEL_RPIVATE */
1556
1557 #endif /* _NETINET_TCP_VAR_H_ */