xref: /xnu-11215.81.4/bsd/netinet/tcp_var.h (revision d4514f0bc1d3f944c22d92e68b646ac3fb40d452)
1 /*
2  * Copyright (c) 2000-2022 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 #if !KERNEL
73 #include <TargetConditionals.h>
74 #endif
75 
76 #if defined(__LP64__)
77 #define _TCPCB_PTR(x)                   u_int32_t
78 #define _TCPCB_LIST_HEAD(name, type)    \
79 struct name {                           \
80 	u_int32_t	lh_first;       \
81 }
82 #else
83 #define _TCPCB_PTR(x)                   x
84 #define _TCPCB_LIST_HEAD(name, type)    LIST_HEAD(name, type)
85 #endif
86 
87 #ifdef KERNEL_PRIVATE
88 #include <sys/tree.h>
89 
90 #define TCP_RETRANSHZ   1000    /* granularity of TCP timestamps, 1ms */
91 /* Minimum time quantum within which the timers are coalesced */
92 #define TCP_TIMER_10MS_QUANTUM  (TCP_RETRANSHZ/100) /* every 10ms */
93 #define TCP_TIMER_100MS_QUANTUM   (TCP_RETRANSHZ/10) /* every 100ms */
94 #define TCP_TIMER_500MS_QUANTUM   (TCP_RETRANSHZ/2) /* every 500ms */
95 
96 #define TCP_RETRANSHZ_TO_USEC 1000
97 
98 #define N_TIME_WAIT_SLOTS   128         /* must be power of 2 */
99 
100 /* Always allow at least 16 packets worth of recv window when adjusting
101  * recv window using inter-packet arrival jitter.
102  */
103 #define MIN_IAJ_WIN 16
104 
105 /* A variation in delay of this many milliseconds is tolerable. This limit has to
106  * be low but greater than zero. We also use standard deviation on jitter to adjust
107  * this limit for different link and connection types.
108  */
109 #define ALLOWED_IAJ 5
110 
111 /* Ignore the first few packets on a connection until the ACK clock gets going
112  */
113 #define IAJ_IGNORE_PKTCNT 40
114 
115 /* Let the accumulated IAJ value increase by this threshold at most. This limit
116  * will control how many ALLOWED_IAJ measurements a receiver will have to see
117  * before opening the receive window
118  */
119 #define ACC_IAJ_HIGH_THRESH 100
120 
121 /* When accumulated IAJ reaches this value, the receiver starts to react by
122  * closing the window
123  */
124 #define ACC_IAJ_REACT_LIMIT 200
125 
126 /* If the number of small packets (smaller than IAJ packet size) seen on a
127  * connection is more than this threshold, reset the size and learn it again.
128  * This is needed because the sender might send smaller segments after PMTU
129  * discovery and the receiver has to learn the new size.
130  */
131 #define RESET_IAJ_SIZE_THRESH 20
132 
133 /*
134  * Adaptive timeout is a read/write timeout specified by the application to
135  * get a socket event when the transport layer detects a stall in data
136  * transfer. The value specified is the number of probes that can be sent
137  * to the peer before generating an event. Since it is not specified as
138  * a time value, the timeout will adjust based on the RTT seen on the link.
139  * The timeout will start only when there is an indication that the read/write
140  * operation is not making progress.
141  *
142  * If a write operation stalls, the probe will be retransmission of data.
143  * If a read operation stalls, the probe will be a keep-alive packet.
144  *
145  * The maximum value of adaptive timeout is set to 10 which will allow
146  * transmission of enough number of probes to the peer.
147  */
148 #define TCP_ADAPTIVE_TIMEOUT_MAX        10
149 
150 #define TCP_CONNECTIVITY_PROBES_MAX     5
151 
152 /* 3 bit mask used for Accurate ECN ACE field */
153 #define TCP_ACE_MASK (0x7)
154 /* Divisor used for Accurate ECN ACE field */
155 #define TCP_ACE_DIV (1 << 3)
156 
157 /* 24 bit mask used for Accurate ECN option */
158 #define TCP_ACO_MASK (0xFFFFFF)
159 /* Divisor used for Accurate ECN options field */
160 #define TCP_ACO_DIV (1 << 24)
161 
162 /*
163  * Kernel variables for tcp.
164  */
165 
166 /* TCP segment queue entry */
167 struct tseg_qent {
168 	LIST_ENTRY(tseg_qent) tqe_q;
169 	int     tqe_len;                /* TCP segment data length */
170 	struct  tcphdr *tqe_th;         /* a pointer to tcp header */
171 	struct  mbuf    *tqe_m;         /* mbuf contains packet */
172 };
173 LIST_HEAD(tsegqe_head, tseg_qent);
174 
175 struct sackblk {
176 	tcp_seq start;          /* start seq no. of sack block */
177 	tcp_seq end;            /* end seq no. */
178 };
179 
180 struct sackhole {
181 	tcp_seq start;          /* start seq no. of hole */
182 	tcp_seq end;            /* end seq no. */
183 	tcp_seq rxmit;          /* next seq. no in hole to be retransmitted */
184 	u_int32_t rxmit_start;  /* timestamp of first retransmission */
185 	TAILQ_ENTRY(sackhole) scblink;  /* scoreboard linkage */
186 };
187 
188 struct sackhint {
189 	struct sackhole *nexthole;
190 	int     sack_bytes_rexmit;
191 	int sack_bytes_acked;
192 };
193 
194 struct tcp_rxt_seg {
195 	tcp_seq rx_start;
196 	tcp_seq rx_end;
197 	u_int16_t rx_count;
198 	u_int16_t rx_flags;
199 #define TCP_RXT_SPURIOUS        0x1     /* received DSACK notification */
200 	SLIST_ENTRY(tcp_rxt_seg) rx_link;
201 };
202 
203 /* TCP state of a segment that was sent */
204 struct tcp_seg_sent {
205 	tcp_seq start_seq;
206 	tcp_seq end_seq;        /* last seq sent + 1 */
207 	uint32_t xmit_ts;
208 	uint8_t flags;
209 	uint8_t pad[3];
210 #define TCP_SEGMENT_SACKED                  0x1
211 #define TCP_SEGMENT_LOST                    0x2
212 #define TCP_RACK_RETRANSMITTED              0x4
213 #define TCP_SEGMENT_RETRANSMITTED_ATLEAST_ONCE      0x8 /* If a segment was retransmitted at least once; used for reordering detection and to avoid spurious inferences for RACK.rtt */
214 #define TCP_SEGMENT_RETRANSMITTED           (TCP_RACK_RETRANSMITTED | TCP_SEGMENT_RETRANSMITTED_ATLEAST_ONCE)
215 
216 	TAILQ_ENTRY(tcp_seg_sent) tx_link; /* Time ordered list of segments */
217 	RB_ENTRY(tcp_seg_sent)    seg_link; /* RB tree to keep track of S/ACKed segments */
218 	TAILQ_ENTRY(tcp_seg_sent) ack_link; /* List of ACKed segments to be deleted from time ordered list and RB tree */
219 	TAILQ_ENTRY(tcp_seg_sent) free_link; /* List of free segments from the pool */
220 };
221 
222 typedef struct tcp_seg_pool {
223 	TAILQ_HEAD(, tcp_seg_sent) free_segs;
224 	uint32_t free_segs_count;
225 	char pad[4];
226 } *tcp_seg_pool_t;
227 
228 #define TCP_SEG_POOL_MAX_ITEM_COUNT (64)
229 
230 int tcp_seg_cmp(const struct tcp_seg_sent *, const struct tcp_seg_sent *);
231 
232 RB_HEAD(tcp_seg_sent_tree_head, tcp_seg_sent);
233 RB_PROTOTYPE(tcp_seg_sent_tree_head, tcp_seg_sent, seg_link, tcp_seg_cmp)
234 
235 struct tcp_notify_ack_marker {
236 	tcp_seq notify_snd_una; /* Notify when snd_una crosses this seq */
237 	tcp_notify_ack_id_t notify_id;
238 	SLIST_ENTRY(tcp_notify_ack_marker) notify_next;
239 };
240 
241 struct tcptemp {
242 	u_char  tt_ipgen[40]; /* the size must be of max ip header, now IPv6 */
243 	struct  tcphdr tt_t;
244 };
245 
246 struct bwmeas {
247 	tcp_seq bw_start;       /* start of bw measurement */
248 	uint32_t bw_ts;         /* timestamp when bw measurement started */
249 	uint32_t bw_size;       /* burst size in bytes for this bw measurement */
250 	uint32_t bw_minsizepkts; /* Min burst size as segments */
251 	uint32_t bw_maxsizepkts; /* Max burst size as segments */
252 	uint32_t bw_minsize;    /* Min size in bytes */
253 	uint32_t bw_maxsize;    /* Max size in bytes */
254 	uint32_t bw_sndbw;      /* Measured send bandwidth */
255 	uint32_t bw_sndbw_max;  /* Max measured bandwidth */
256 	uint32_t bw_rcvbw_max;  /* Max receive bandwidth measured */
257 };
258 
259 /* MPTCP Data sequence map entry */
260 struct mpt_dsn_map {
261 	uint64_t                mpt_dsn;        /* data seq num recvd */
262 	uint32_t                mpt_sseq;       /* relative subflow # */
263 	uint16_t                mpt_len;        /* length of mapping */
264 	uint16_t                mpt_csum;       /* checksum value if on */
265 	uint8_t                 mpt_dfin;       /* It's a DATA_FIN */
266 };
267 #define tcp6cb          tcpcb  /* for KAME src sync over BSD*'s */
268 
269 struct tcp_ccstate {
270 	union {
271 		struct tcp_cubic_state {
272 			u_int32_t tc_last_max;  /* cwnd at last loss */
273 			u_int32_t tc_epoch_start; /* TS of last loss */
274 			u_int32_t tc_origin_point; /* window at the start of an epoch */
275 			u_int32_t tc_tcp_win; /* computed tcp win */
276 			u_int32_t tc_tcp_bytes_acked; /* bytes acked */
277 			u_int32_t tc_avg_lastmax; /* Average of last max */
278 			u_int32_t tc_mean_deviation; /* Mean absolute deviation */
279 			float     tc_epoch_period; /* K parameter */
280 		} _cubic_state_;
281 #define cub_last_max __u__._cubic_state_.tc_last_max
282 #define cub_epoch_start __u__._cubic_state_.tc_epoch_start
283 #define cub_origin_point __u__._cubic_state_.tc_origin_point
284 #define cub_tcp_win __u__._cubic_state_.tc_tcp_win
285 #define cub_tcp_bytes_acked __u__._cubic_state_.tc_tcp_bytes_acked
286 #define cub_epoch_period __u__._cubic_state_.tc_epoch_period
287 #define cub_avg_lastmax __u__._cubic_state_.tc_avg_lastmax
288 #define cub_mean_dev __u__._cubic_state_.tc_mean_deviation
289 		struct tcp_prague_state {
290 			uint16_t num_cong_events_loss;
291 			uint16_t num_cong_events_ce;
292 			uint32_t packets_acked;   /* cumulative packets ack'ed updated at round start for alpha */
293 			uint32_t packets_marked;  /* cumulative CE counts updated at round start for alpha */
294 			uint32_t ce_counter;      /* cumulative CE counts updated on every ACK,
295 			                           *                        used for calculating non-CE acked and performing any CE related action */
296 			uint32_t bytes_acked;     /* bytes acked in this ACK that were not CE marked, used for cwnd increase */
297 			uint32_t snd_nxt_alpha;   /* snd_nxt at round start to track 1 RTT elapsed for alpha */
298 			uint32_t snd_nxt_cwr;     /* snd_nxt at round start to track 1 RTT elapsed for CWR */
299 			uint8_t ever_saw_ce:1,       /* To test if there is a AQM on path */
300 			    in_loss:1,                       /* Are we in loss recovery */
301 			    reduced_due_to_ce:1,             /* Was the last reduction due to CE */
302 			    unused:5;
303 			uint8_t pad[3];
304 			uint64_t scaled_alpha;    /* Scaled value of DCTCP.alpha */
305 			uint64_t alpha_ai;        /* AI.alpha used after CE for additive increase */
306 			/* After reduction due to loss CUBIC window increase state */
307 			struct tcp_cubic_state cubic_state;
308 		} _prague_state_;
309 #define num_cong_events_loss __u__._prague_state_.num_cong_events_loss
310 #define num_cong_events_ce __u__._prague_state_.num_cong_events_ce
311 #define prague_packets_acked __u__._prague_state_.packets_acked
312 #define prague_packets_marked __u__._prague_state_.packets_marked
313 #define prague_ce_counter __u__._prague_state_.ce_counter
314 #define prague_bytes_acked __u__._prague_state_.bytes_acked
315 #define snd_nxt_alpha __u__._prague_state_.snd_nxt_alpha
316 #define snd_nxt_cwr __u__._prague_state_.snd_nxt_cwr
317 #define prague_scaled_alpha __u__._prague_state_.scaled_alpha
318 #define prague_alpha_ai __u__._prague_state_.alpha_ai
319 #define ever_saw_ce __u__._prague_state_.ever_saw_ce
320 #define in_loss __u__._prague_state_.in_loss
321 #define reduced_due_to_ce __u__._prague_state_.reduced_due_to_ce
322 #define cubic_K __u__._prague_state_.cubic_state.tc_epoch_period
323 #define cubic_epoch_start __u__._prague_state_.cubic_state.tc_epoch_start
324 #define cubic_origin_point __u__._prague_state_.cubic_state.tc_origin_point
325 #define cubic_W_max __u__._prague_state_.cubic_state.tc_last_max
326 #define reno_acked __u__._prague_state_.cubic_state.tc_tcp_bytes_acked
327 #define reno_cwnd __u__._prague_state_.cubic_state.tc_tcp_win
328 		struct tcp_ledbat_state {
329 			uint32_t num_slowdown_events;
330 			uint32_t slowdown_ts;
331 			uint32_t slowdown_begin;
332 			uint32_t md_bytes_acked;
333 		} _ledbat_state_;
334 #define ledbat_slowdown_events __u__._ledbat_state_.num_slowdown_events
335 #define ledbat_slowdown_ts __u__._ledbat_state_.slowdown_ts
336 #define ledbat_slowdown_begin __u__._ledbat_state_.slowdown_begin
337 #define ledbat_md_bytes_acked __u__._ledbat_state_.md_bytes_acked
338 	} __u__;
339 };
340 
341 struct tcp_rledbat_state {
342 	uint32_t num_slowdown_events;  /* Number of slowdown events until reset */
343 	uint32_t slowdown_ts;          /* Next slowdown timestamp */
344 	uint32_t slowdown_begin;       /* Slowdown begin time */
345 	uint32_t reduction_end;        /* Used to track rl_win reduction once per RTT */
346 	uint32_t rcvd_bytes;           /* bytes received used for byte counting */
347 	uint32_t md_rcvd_bytes;        /* bytes received during MD used for byte counting */
348 	uint32_t win;                  /* receive Ledbat window size */
349 	uint32_t ssthresh;             /* receive Ledbat ssthresh */
350 	uint32_t drained_bytes;        /* bytes drained from the flight-size */
351 	uint32_t win_ws;               /* receive Ledbat window after avoiding window shrinking */
352 };
353 
354 struct accecn {
355 	/* ACE CE packet counters */
356 	uint32_t        t_rcv_ce_packets;                  /* Number of CE received packets at the receiver */
357 	uint32_t        t_snd_ce_packets;                  /* Synced number of CE received feedback at the sender */
358 	uint32_t        t_delta_ce_packets;                /* Change in CE count between previous and current ACK */
359 	uint8_t         accecn_processed:1,                /* Accurate ECN feedback has already been processed */
360 	    unused:7;
361 
362 	/* AccECN option byte counters */
363 	uint64_t        t_rcv_ect1_bytes;                  /* ECT1 byte counter at the receiver, used for AccECN option feedback */
364 	uint64_t        t_rcv_ect0_bytes;                  /* ECT0 byte counter at the receiver, used for AccECN option feedback */
365 	uint64_t        t_rcv_ce_bytes;                    /* CE byte counter at the receiver, used for AccECN option feedback */
366 	uint64_t        t_snd_ect1_bytes;                  /* Synced ECT1 byte counter at the sender */
367 	uint64_t        t_snd_ect0_bytes;                  /* Synced ECT0 byte counter at the sender */
368 	uint64_t        t_snd_ce_bytes;                    /* Synced CE byte counter at the sender */
369 };
370 
371 struct pacer {
372 	uint64_t rate;
373 	uint32_t tso_burst_size; /* maximum allowed burst size, segments that fit in a burst have the same Tx timestamp */
374 	uint32_t current_size; /* track how many bytes have been accumulated in a burst */
375 	uint64_t packet_tx_time;
376 };
377 
378 /*
379  * Tcp control block, one per tcp; fields:
380  * Organized for 16 byte cacheline efficiency.
381  */
382 struct tcpcb {
383 	struct tsegqe_head t_segq;
384 	uint32_t t_dupacks;             /* consecutive dup acks recd */
385 	int      t_state;               /* state of this connection */
386 	uint32_t t_timer[TCPT_NTIMERS]; /* tcp timers */
387 	struct tcptimerentry tentry;    /* entry in timer list */
388 
389 	struct  inpcb *t_inpcb;         /* back pointer to internet pcb */
390 	uint32_t        t_flags;
391 #define TF_ACKNOW       0x00001         /* ack peer immediately */
392 #define TF_DELACK       0x00002         /* ack, but try to delay it */
393 #define TF_NODELAY      0x00004         /* don't delay packets to coalesce */
394 #define TF_NOOPT        0x00008         /* don't use tcp options */
395 #define TF_SENTFIN      0x00010         /* have sent FIN */
396 #define TF_REQ_SCALE    0x00020         /* have/will request window scaling */
397 #define TF_RCVD_SCALE   0x00040         /* other side has requested scaling */
398 #define TF_REQ_TSTMP    0x00080         /* have/will request timestamps */
399 #define TF_RCVD_TSTMP   0x00100         /* a timestamp was received in SYN */
400 #define TF_SACK_PERMIT  0x00200         /* other side said I could SACK */
401 #define TF_NEEDSYN      0x00400         /* send SYN (implicit state) - unused but needed for backwards compatibility */
402 #define TF_NEEDFIN      0x00800         /* send FIN (implicit state) */
403 #define TF_NOPUSH       0x01000         /* don't push */
404 #define TF_UNUSED1      0x02000         /* Unused */
405 #define TF_UNUSED2      0x04000         /* Unused */
406 #define TF_UNUSED3      0x08000         /* Unused */
407 #define TF_MORETOCOME   0x10000         /* More data to be appended to sock */
408 #define TF_LOCAL        0x20000         /* connection to a host on local link */
409 #define TF_RXWIN0SENT   0x40000         /* sent a receiver win 0 in response */
410 #define TF_SLOWLINK     0x80000         /* route is a on a modem speed link */
411 #define TF_LASTIDLE     0x100000        /* connection was previously idle */
412 #define TF_FASTRECOVERY 0x200000        /* in NewReno Fast Recovery */
413 #define TF_WASFRECOVERY 0x400000        /* was in NewReno Fast Recovery */
414 #define TF_SIGNATURE    0x800000        /* require MD5 digests (RFC2385) */
415 #define TF_MAXSEGSNT    0x1000000       /* last segment sent was a full segment */
416 #define TF_STREAMING_ON 0x2000000       /* Receiver detected streaming */
417 #define TF_PMTUD        0x4000000       /* Perform Path MTU Discovery for this connection */
418 #define TF_CLOSING      0x8000000       /* pending tcp close */
419 #define TF_TSO          0x10000000      /* TCP Segment Offloading is enable on this connection */
420 #define TF_BLACKHOLE    0x20000000      /* Path MTU Discovery Black Hole detection */
421 #define TF_TIMER_ONLIST 0x40000000      /* pcb is on tcp_timer_list */
422 #define TF_STRETCHACK   0x80000000      /* receiver is going to delay acks */
423 
424 	tcp_seq snd_una;                /* send unacknowledged */
425 	tcp_seq snd_max;                /* highest sequence number sent;
426 	                                 * used to recognize retransmits
427 	                                 */
428 	tcp_seq snd_nxt;                /* send next */
429 	tcp_seq snd_up;                 /* send urgent pointer */
430 
431 	tcp_seq snd_wl1;                /* window update seg seq number */
432 	tcp_seq snd_wl2;                /* window update seg ack number */
433 	tcp_seq iss;                    /* initial send sequence number */
434 	tcp_seq irs;                    /* initial receive sequence number */
435 
436 	tcp_seq rcv_nxt;                /* receive next */
437 	tcp_seq rcv_adv;                /* advertised window */
438 	uint32_t        rcv_wnd;        /* receive window */
439 	uint32_t        t_last_recwin;
440 	tcp_seq rcv_up;                 /* receive urgent pointer */
441 
442 	uint32_t        snd_wnd;        /* send window */
443 	uint32_t        snd_cwnd;       /* congestion-controlled window */
444 	uint32_t        snd_ssthresh;   /* snd_cwnd size threshold for
445 	                                 * for slow start exponential to
446 	                                 * linear switch
447 	                                 */
448 	tcp_seq snd_recover;            /* for use in NewReno Fast Recovery */
449 
450 	uint32_t        t_maxopd;       /* mss plus options */
451 	uint32_t        t_rcvtime;      /* time at which a packet was received */
452 	uint32_t        t_sndtime;      /* time at which we last sent new data */
453 	uint32_t        t_starttime;    /* time connection was established */
454 	int     t_rtttime;              /* tcp clock when rtt calculation was started */
455 	tcp_seq t_rtseq;                /* sequence number being timed */
456 
457 	uint32_t rfbuf_ts;              /* recv buffer autoscaling timestamp */
458 	uint32_t rfbuf_cnt;             /* recv buffer autoscaling byte count */
459 	uint32_t rfbuf_space;           /* Current "ideal" estimate of the space */
460 
461 	int            t_rxtcur;        /* current retransmit value (ticks) */
462 	unsigned int   t_maxseg;        /* maximum segment size */
463 	int            t_srtt;          /* smoothed round-trip time */
464 	int            t_rttvar;        /* variance in round-trip time */
465 
466 	uint64_t t_accsleep_ms;         /* accumulated sleep time since last boot */
467 	uint32_t t_reassqlen;           /* length of reassembly queue */
468 	uint32_t t_reassq_mbcnt;        /* amount in bytes of mbuf space used */
469 	uint16_t t_rxtshift;            /* log(2) of rexmt exp. backoff */
470 	uint32_t t_rttmin;              /* minimum rtt allowed */
471 	uint32_t t_rttbest;             /* best rtt we've seen */
472 	uint32_t t_rttcur;              /* most recent value of rtt */
473 	uint32_t t_rttupdated;          /* number of times rtt sampled */
474 	uint32_t t_rxt_conndroptime;    /* retxmt conn gets dropped after this time, when set */
475 	uint32_t t_rxtstart;            /* time at which retransmission started */
476 	uint32_t max_sndwnd;            /* largest window peer has offered */
477 
478 	int     t_softerror;            /* possible error not yet reported */
479 /* out-of-band data */
480 	char    t_oobflags;             /* have some */
481 	char    t_iobc;                 /* input character */
482 #define TCPOOB_HAVEDATA 0x01
483 #define TCPOOB_HADDATA  0x02
484 /* RFC 1323 variables */
485 	u_int8_t        snd_scale;      /* window scaling for send window */
486 	u_int8_t        rcv_scale;      /* window scaling for recv window */
487 	u_int8_t        request_r_scale; /* pending window scaling */
488 	u_int8_t        requested_s_scale;
489 	u_int8_t        tcp_cc_index;   /* index of congestion control algorithm */
490 	u_int8_t        t_adaptive_rtimo;       /* Read timeout used as a multiple of RTT */
491 	u_int8_t        t_adaptive_wtimo;       /* Write timeout used as a multiple of RTT */
492 	u_int8_t        t_stretchack_delayed;   /* stretch ack delayed */
493 
494 /* State for limiting early retransmits when SACK is not enabled */
495 	u_int16_t       t_early_rexmt_count; /* count of early rexmts */
496 	u_int32_t       t_early_rexmt_win; /* window for limiting early rexmts */
497 
498 	u_int32_t       ts_recent;      /* timestamp echo data */
499 
500 	u_int32_t       ts_recent_age;  /* when last updated */
501 	tcp_seq last_ack_sent;
502 
503 	uint32_t        t_bytes_acked;  /* RFC 3465 variable for ABC, used by CCA only */
504 	uint32_t        total_ect_packets_marked; /* Cumulative count of total ECT packets marked */
505 	uint32_t        total_ect_packets_acked;  /* Cumulative count of total ECT packets acked */
506 
507 	int             t_lastchain;    /* amount of packets chained last time around */
508 	uint16_t        t_unacksegs;    /* received but unacked segments for delaying acks */
509 	uint16_t        t_unacksegs_ce; /* received but unacked segments/pure ACKs that were CE marked */
510 
511 	/*
512 	 * Pretty arbitrary value ;-)
513 	 * Goal is to make sure that some ACKs are being sent more frequently
514 	 * to allow the other side to ramp-up.
515 	 */
516 #define TCP_FORCED_ACKS_COUNT 16
517 	uint16_t        t_forced_acks;  /* count of pure ACKs that need to be forced out */
518 	uint8_t         t_rexmtthresh;  /* duplicate ack threshold for entering fast recovery */
519 	uint8_t         t_rtimo_probes; /* number of adaptive rtimo probes sent */
520 	uint32_t        t_persist_timeout; /* ZWP persistence limit as set by PERSIST_TIMEOUT */
521 	uint32_t        t_persist_stop;    /* persistence limit deadline if triggered by ZWP */
522 	uint32_t        t_notsent_lowat;   /* Low water for not sent data */
523 
524 /* Receiver state for stretch-ack algorithm */
525 	u_int32_t       rcv_unackwin;   /* to measure win for stretching acks */
526 	u_int32_t       rcv_by_unackwin; /* bytes seen during the last ack-stretching win */
527 	u_int32_t       rcv_by_unackhalfwin;
528 	u_int32_t       rcv_nostrack_ts; /* timestamp when stretch ack was disabled automatically */
529 	u_int32_t       rcv_nostrack_pkts; /* pkts received since strech ack was disabled */
530 	u_int16_t       rcv_waitforss;  /* wait for packets during slow-start */
531 
532 /* ECN stats */
533 	u_int32_t       ecn_flags;
534 #define TE_SETUPSENT            0x00000001  /* We have sent classic ECN-SETUP SYN or SYN-ACK */
535 #define TE_SETUPRECEIVED        0x00000002  /* We have received classic ECN-SETUP SYN or SYN-ACK */
536 #define TE_SENDIPECT            0x00000004  /* We haven't sent or received non-ECN-setup SYN or SYN-ACK, set IP ECT on outbound packet */
537 #define TE_SENDCWR              0x00000008  /* Next non-retransmit should have TCP CWR set, only used for classic ECN */
538 #define TE_SENDECE              0x00000010  /* Next packet should have TCP ECE set, only used for classic ECN */
539 #define TE_INRECOVERY           0x00000020  /* connection entered recovery after receiving ECE */
540 #define TE_RECV_ECN_CE          0x00000040  /* Received IPTOS_ECN_CE marking atleast once */
541 #define TE_RECV_ECN_ECE         0x00000080  /* Received ECE marking atleast once */
542 #define TE_LOST_SYN             0x00000100  /* Lost SYN with ECN setup */
543 #define TE_LOST_SYNACK          0x00000200  /* Lost SYN-ACK with ECN setup */
544 #define TE_ECN_MODE_ENABLE      0x00000400  /* Option ECN mode set to enable */
545 #define TE_ECN_MODE_DISABLE     0x00000800  /* Option ECN mode set to disable */
546 #define TE_ENABLE_ECN           0x00001000  /* Enable negotiation of ECN */
547 #define TE_ECN_ON               (TE_SETUPSENT | TE_SETUPRECEIVED) /* ECN was successfully negotiated on a connection */
548 #define TE_CEHEURI_SET          0x00002000  /* We did our CE-probing at the beginning */
549 #define TE_CLIENT_SETUP         0x00004000  /* setup from client side */
550 #define TE_RCVD_SYN_RST         0x00008000  /* Received RST to the first ECN enabled SYN */
551 #define TE_ACE_SETUP_NON_ECT    0x00010000  /* Encode received non-ECT either for SYN-ACK (server) or final ACK (client) */
552 #define TE_ACE_SETUP_ECT1       0x00020000  /* Encode received ECT1 either for SYN-ACK (server) or final ACK (client) */
553 #define TE_ACE_SETUP_ECT0       0x00040000  /* Encode received ECT0 either for SYN-ACK (server) or final ACK (client) */
554 #define TE_ACE_SETUP_CE         0x00080000  /* Encode received CE either for SYN-ACK (server) or final ACK (client) */
555 #define TE_ACE_SETUPSENT        0x00100000  /* We have sent Accurate ECN setup SYN or SYN-ACK */
556 #define TE_ACE_SETUPRECEIVED    0x00200000  /* We have received Accurate ECN setup SYN or SYN-ACK */
557 #define TE_ACC_ECN_ON          (TE_ACE_SETUPSENT | TE_ACE_SETUPRECEIVED) /* Accurate ECN was negotiated */
558 #define TE_ACE_FINAL_ACK_3WHS   0x00400000  /* Client has received SYN-ACK and will now send final ACK of 3WHS, only used for AccECN */
559 #define TE_ACO_ECT1             0x00800000  /* ECT1 counter changed flag, used to decide ordering for AccECN option */
560 #define TE_ACO_ECT0             0x01000000  /* ECT0 counter changed flag, used to decide ordering for AccECN option */
561 #define TE_RETRY_WITHOUT_ACO    0x02000000  /* Data segment with AccECN option was not acknowledged, retry without AccECN option */
562 #define TE_FORCE_ECT1           0x40000000  /* Force setting ECT1 on outgoing packets for testing purpose */
563 #define TE_FORCE_ECT0           0x80000000  /* Force setting ECT0 on outgoing packets for testing purpose */
564 
565 	u_int32_t       t_ecn_recv_ce;  /* Received CE from the network */
566 	u_int32_t       t_ecn_recv_cwr; /* Packets received with CWR */
567 	uint32_t        t_client_accecn_state;    /* Client's Accurate ECN state */
568 	uint32_t        t_server_accecn_state;    /* Server's Accurate ECN state */
569 	uint64_t        t_ecn_capable_packets_sent;     /* Packets sent with ECT */
570 	uint64_t        t_ecn_capable_packets_acked;    /* Packets sent with ECT that were acked */
571 	uint64_t        t_ecn_capable_packets_marked;   /* Packets sent with ECT that were marked */
572 	uint64_t        t_ecn_capable_packets_lost;     /* Packets sent with ECT that were lost */
573 
574 	uint32_t        t_last_ack_tsecr;       /* TS Echo Reply for last ACK that acknowledged a data or control packet */
575 	uint16_t        t_prev_ace_flags;   /* ACE flags that were sent in previous packet, used for retransmitting after timeout */
576 	uint8_t         t_prev_ip_ecn;      /* IP ECN flag on the previous packet, used for change-triggered ACKs */
577 
578 	struct accecn   t_aecn;         /* AccECN related byte counters */
579 
580 	struct pacer    t_pacer;        /* Pacer state used to pace packets */
581 
582 /* state for bad retransmit recovery */
583 	u_int32_t       snd_cwnd_prev;  /* cwnd prior to retransmit */
584 	u_int32_t       snd_ssthresh_prev; /* ssthresh prior to retransmit */
585 	tcp_seq snd_recover_prev;       /* snd_recover prior to retransmit */
586 	int     t_srtt_prev;            /* srtt prior to retransmit */
587 	int     t_rttvar_prev;          /* rttvar prior to retransmit */
588 	u_int32_t       t_badrexmt_time; /* bad rexmt detection time */
589 
590 /* Packet reordering metric */
591 	u_int32_t       t_reorderwin; /* Reordering late time offset */
592 
593 /* SACK related state */
594 	int16_t snd_numholes;           /* number of holes seen by sender */
595 	TAILQ_HEAD(sackhole_head, sackhole) snd_holes;
596 	/* SACK scoreboard (sorted) */
597 	tcp_seq snd_fack;               /* last seq number(+1) sack'd by rcv'r*/
598 	int     rcv_numsacks;           /* # distinct sack blks present */
599 	struct sackblk sackblks[MAX_SACK_BLKS]; /* seq nos. of sack blocks */
600 	struct sackhint sackhint;       /* SACK scoreboard hint */
601 
602 	struct mbuf     *t_pktlist_head; /* First packet in transmit chain */
603 	struct mbuf     *t_pktlist_tail; /* Last packet in transmit chain */
604 	u_int32_t       t_pktlist_sentlen; /* total bytes in transmit chain */
605 
606 	u_int32_t       t_keepidle;     /* keepalive idle timer (override global if > 0) */
607 	u_int32_t       t_keepinit;     /* connection timeout, i.e. idle time
608 	                                 *  in SYN_SENT or SYN_RECV state */
609 	u_int32_t       t_keepintvl;    /* interval between keepalives */
610 	u_int32_t       t_keepcnt;      /* number of keepalives before close */
611 
612 	u_int32_t       tso_max_segment_size;   /* TSO maximum segment unit for NIC */
613 	u_int16_t       t_pmtud_lastseg_size;   /* size of the last sent segment */
614 	u_int32_t       t_pmtud_saved_maxopd;   /* MSS saved before performing PMTU-D BlackHole detection */
615 	u_int32_t       t_pmtud_start_ts;       /* Time of PMTUD blackhole detection */
616 
617 	struct{
618 		u_int32_t       rxduplicatebytes;
619 		u_int32_t       rxoutoforderbytes;
620 		u_int32_t       txretransmitbytes;
621 		u_int16_t       synrxtshift;
622 		u_int16_t       rxmitsyns;
623 		u_int16_t       unused_pad_to_8;
624 		u_int32_t       rxmitpkts;
625 		uint32_t        delayed_acks_sent;
626 		uint32_t        acks_delayed;
627 	} t_stat;
628 	u_int8_t        t_syn_sent;
629 	u_int8_t        t_syn_rcvd;
630 	u_int8_t        t_notify_ack_count;
631 	u_int8_t        t_ecn_recv_ce_pkt; /* Received packet with CE-bit set (independent from last_ack_sent) */
632 	u_int32_t       t_cached_maxopd; /* default for MSS adjustment using link status report */
633 
634 	uint32_t        bg_ssthresh;            /* Slow start threshold until delay increases */
635 	uint32_t        t_flagsext;             /* Another field to accommodate more flags */
636 #define TF_RXTFINDROP           0x1                     /* Drop conn after retransmitting FIN 3 times */
637 #define TF_RCVUNACK_WAITSS      0x2             /* set when the receiver should not stretch acks */
638 #define TF_BWMEAS_INPROGRESS    0x4             /* Indicate BW meas is happening */
639 #define TF_MEASURESNDBW         0x8             /* Measure send bw on this connection */
640 #define TF_LAST_IS_PSH          0x10            /* Indicates whether the last packet in the rcv socket buffer had the PUSH-flag set */
641 #define TF_SACK_ENABLE          0x20            /* SACK is enabled */
642 #define TF_RECOMPUTE_RTT        0x40            /* recompute RTT after spurious retransmit */
643 #define TF_DETECT_READSTALL     0x80            /* Used to detect a stall during read operation */
644 #define TF_RECV_THROTTLE        0x100           /* Input throttling active */
645 #define TF_NOSTRETCHACK         0x200           /* ack every other packet */
646 #define TF_NOTIMEWAIT           0x800           /* Avoid going into time-wait */
647 #define TF_SENT_TLPROBE         0x1000          /* Sent data in PTO */
648 #define TF_PKTS_REORDERED       0x2000          /* Detected reordering */
649 #define TF_DELAY_RECOVERY       0x4000          /* delay fast recovery */
650 #define TF_FORCE                0x8000          /* force 1 byte out */
651 #define TF_DISABLE_STRETCHACK   0x10000         /* auto-disable stretch ack */
652 #define TF_NOBLACKHOLE_DETECTION 0x20000        /* Disable PMTU blackhole detection */
653 #define TF_RESCUE_RXT           0x80000         /* SACK rescue retransmit */
654 #define TF_CWND_NONVALIDATED    0x100000        /* cwnd non validated */
655 #define TF_IF_PROBING           0x200000        /* Trigger interface probe timeout */
656 #define TF_FASTOPEN             0x400000        /* TCP Fastopen is enabled */
657 #define TF_REASS_INPROG         0x800000        /* Reassembly is in progress */
658 #define TF_FASTOPEN_FORCE_ENABLE 0x1000000      /* Force-enable TCP Fastopen */
659 #define TF_USR_OUTPUT           0x2000000       /* In connect() or send() so tcp_output() can log */
660 #define TF_L4S_ENABLED          0x8000000       /* L4S was force enabled */
661 #define TF_L4S_DISABLED         0x10000000      /* L4S was force disabled */
662 #define TF_RACK_ENABLED         0x20000000      /* RACK is enabled */
663 #define TF_TLP_IS_RETRANS       0x40000000      /* Is TLP-probe a retransmission ? (field TLP.is_retrans in RFC 8985) */
664 
665 #if TRAFFIC_MGT
666 	/* Inter-arrival jitter related state */
667 	uint32_t        iaj_rcv_ts;             /* tcp clock when the first packet was received */
668 	int             iaj_size;               /* Size of packet for iaj measurement */
669 	uint8_t         iaj_small_pkt;          /* Count of packets smaller than iaj_size */
670 	uint8_t         t_pipeack_ind;          /* index for next pipeack sample */
671 	uint16_t        iaj_pktcnt;             /* packet count, to avoid throttling initially */
672 	uint32_t        acc_iaj;                /* Accumulated iaj */
673 	uint32_t        avg_iaj;                /* Mean */
674 	uint32_t        std_dev_iaj;            /* Standard deviation */
675 #endif /* TRAFFIC_MGT */
676 	struct bwmeas   *t_bwmeas;              /* State for bandwidth measurement */
677 	tcp_seq         t_idleat;               /* rcv_nxt at idle time */
678 	uint8_t         t_fin_sent;
679 	uint8_t         t_fin_rcvd;
680 	uint8_t         t_rst_sent;
681 	uint8_t         t_rst_rcvd;
682 	TAILQ_ENTRY(tcpcb) t_twentry;           /* link for time wait queue */
683 	struct tcp_ccstate      *t_ccstate;     /* congestion control related state */
684 	struct tcp_ccstate      _t_ccstate;     /* congestion control related state, non-allocated */
685 /* Tail loss probe related state */
686 	tcp_seq         t_tlphighrxt;           /* snd_nxt after PTO */
687 	tcp_seq         t_tlphightrxt_persist;  /* like t_tlphighrxt but persists over ACKs until DSACK (if any) is processed */
688 	uint32_t        t_tlpstart;             /* timestamp at PTO */
689 /* DSACK data receiver state */
690 	tcp_seq         t_dsack_lseq;           /* DSACK left sequence */
691 	tcp_seq         t_dsack_rseq;           /* DSACK right sequence */
692 /* DSACK data sender state */
693 	SLIST_HEAD(tcp_rxt_seghead, tcp_rxt_seg) t_rxt_segments;
694 	uint32_t        t_rxt_seg_count;
695 	uint32_t        t_rxt_seg_drop;
696 	tcp_seq         t_dsack_lastuna;        /* snd_una when last recovery episode started */
697 /* state for congestion window validation (draft-ietf-tcpm-newcwv-07) */
698 #define TCP_PIPEACK_SAMPLE_COUNT        3
699 	u_int32_t       t_pipeack_sample[TCP_PIPEACK_SAMPLE_COUNT];     /* pipeack, bytes acked within RTT */
700 	tcp_seq         t_pipeack_lastuna; /* una when pipeack measurement started */
701 	u_int32_t       t_pipeack;
702 	u_int32_t       t_lossflightsize;
703 
704 #if MPTCP
705 	u_int32_t       t_mpflags;              /* flags for multipath TCP */
706 
707 #define TMPF_PREESTABLISHED     0x00000001 /* conn in pre-established state */
708 #define TMPF_SND_KEYS           0x00000002 /* indicates that keys should be send */
709 #define TMPF_MPTCP_TRUE         0x00000004 /* negotiated MPTCP successfully */
710 /* UNUSED */
711 #define TMPF_SND_MPPRIO         0x00000010 /* send priority of subflow */
712 #define TMPF_SND_REM_ADDR       0x00000020 /* initiate address removal */
713 #define TMPF_RCVD_DACK          0x00000040 /* received a data-ack */
714 #define TMPF_JOINED_FLOW        0x00000080 /* Indicates additional flow */
715 #define TMPF_BACKUP_PATH        0x00000100 /* Indicates backup path */
716 #define TMPF_MPTCP_ACKNOW       0x00000200 /* Send Data ACK */
717 #define TMPF_SEND_DSN           0x00000400 /* Send DSN mapping */
718 #define TMPF_SEND_DFIN          0x00000800 /* Send Data FIN */
719 #define TMPF_RECV_DFIN          0x00001000 /* Recv Data FIN */
720 #define TMPF_SENT_JOIN          0x00002000 /* Sent Join */
721 #define TMPF_RECVD_JOIN         0x00004000 /* Received Join */
722 #define TMPF_RESET              0x00008000 /* Send RST */
723 #define TMPF_TCP_FALLBACK       0x00010000 /* Fallback to TCP */
724 #define TMPF_FASTCLOSERCV       0x00020000 /* Received Fastclose option */
725 #define TMPF_EMBED_DSN          0x00040000 /* tp has DSN mapping */
726 #define TMPF_MPTCP_READY        0x00080000 /* Can send DSS options on data */
727 #define TMPF_INFIN_SENT         0x00100000 /* Sent infinite mapping */
728 #define TMPF_SND_MPFAIL         0x00200000 /* Received mapping csum failure */
729 #define TMPF_SND_JACK           0x00400000 /* Send a Join-ACK */
730 #define TMPF_TFO_REQUEST        0x00800000 /* TFO Requested */
731 #define TMPF_MPTCP_ECHO_ADDR    0x01000000 /* MPTCP echoes add_addr */
732 
733 #define TMPF_MPTCP_SIGNALS      (TMPF_SND_MPPRIO | TMPF_SND_REM_ADDR | TMPF_SND_MPFAIL | TMPF_SND_JACK | TMPF_MPTCP_ECHO_ADDR)
734 
735 	tcp_seq                 t_mpuna;        /* unacknowledged sequence */
736 	struct mptcb            *t_mptcb;       /* pointer to MPTCP TCB */
737 	struct mptsub           *t_mpsub;       /* pointer to the MPTCP subflow */
738 	struct mpt_dsn_map      t_rcv_map;      /* Receive mapping list */
739 	u_int8_t                t_local_aid;    /* Addr Id for authentication */
740 	u_int8_t                t_rem_aid;      /* Addr ID of another subflow */
741 	u_int8_t                t_mprxtshift;   /* join retransmission */
742 #endif /* MPTCP */
743 
744 #define TFO_F_OFFER_COOKIE      0x01 /* We will offer a cookie */
745 #define TFO_F_COOKIE_VALID      0x02 /* The received cookie is valid */
746 #define TFO_F_COOKIE_REQ        0x04 /* Client requested a new cookie */
747 #define TFO_F_COOKIE_SENT       0x08 /* Client did send a cookie in the SYN */
748 #define TFO_F_SYN_LOSS          0x10 /* A SYN-loss triggered a fallback to regular TCP on the client-side */
749 #define TFO_F_NO_SNDPROBING     0x20 /* This network is guaranteed to support TFO in the upstream direction */
750 #define TFO_F_HEURISTIC_DONE    0x40 /* We have already marked this network as bad */
751 	u_int8_t                t_tfo_flags;
752 #define TFO_S_SYNDATA_RCV       0x01 /* SYN+data has been received */
753 #define TFO_S_COOKIEREQ_RECV    0x02 /* TFO-cookie request received */
754 #define TFO_S_COOKIE_SENT       0x04 /* TFO-cookie announced in SYN/ACK */
755 #define TFO_S_COOKIE_INVALID    0x08 /* Received TFO-cookie is invalid */
756 #define TFO_S_COOKIE_REQ        0x10 /* TFO-cookie requested within the SYN */
757 #define TFO_S_COOKIE_RCV        0x20 /* TFO-cookie received in SYN/ACK */
758 #define TFO_S_SYN_DATA_SENT     0x40 /* SYN+data sent */
759 #define TFO_S_SYN_DATA_ACKED    0x80 /* SYN+data has been acknowledged in SYN/ACK */
760 #define TFO_S_SYN_LOSS          0x0100 /* SYN+TFO has been lost - fallback to regular TCP */
761 #define TFO_S_COOKIE_WRONG      0x0200 /* Cookie we sent in the SYN was wrong */
762 #define TFO_S_NO_COOKIE_RCV     0x0400 /* We asked for a cookie but didn't get one */
763 #define TFO_S_HEURISTICS_DISABLE 0x0800 /* TFO-heuristics disabled it for this connection */
764 #define TFO_S_SEND_BLACKHOLE    0x1000 /* TFO got blackholed in the send direction */
765 #define TFO_S_RECV_BLACKHOLE    0x2000 /* TFO got blackholed in the recv direction */
766 #define TFO_S_ONE_BYTE_PROXY    0x4000 /* TFO failed because of a proxy acknowledging just one byte */
767 	u_int16_t               t_tfo_stats;
768 
769 	u_int8_t                t_tfo_probes; /* TFO-probes we did send */
770 /*
771  * This here is the TFO-probing state-machine. Transitions are as follows:
772  *
773  * Current state: PROBE_NONE
774  *		  Event: SYN+DATA acknowledged
775  *			 Action: Transition to PROBE_PROBING and set keepalive-timer
776  *
777  * Current state: PROBE_PROBING (initial state)
778  *		  Event: Receive data
779  *			 Action: Transition to PROBE_NONE and cancel keepalive-timer
780  *		  Event: Receive ACK that does not indicate a hole
781  *			 Action: Transition to PROBE_NONE and cancel keepalive-timer
782  *		  Event: Receive ACK that indicates a hole
783  *			 Action: Transition to PROBE_WAIT_DATA and set a short timer
784  *				 to wait for the final segment.
785  *		  Event: Keepalive-timeout (did not receive any segment)
786  *			 Action: Signal ETIMEDOUT as with regular keepalive-timers
787  *
788  * Current state: PROBE_WAIT_DATA
789  *		  Event: Receive data
790  *			 Action: Transition to PROBE_NONE and cancel keepalive-timer
791  *		  Event: Data-timeout (did not receive the expected data)
792  *			 Action: Signal ENODATA up to the app and close everything.
793  */
794 #define TFO_PROBE_NONE          0 /* Not probing now */
795 #define TFO_PROBE_PROBING       1 /* Sending out TCP-keepalives waiting for reply */
796 #define TFO_PROBE_WAIT_DATA     2 /* Received reply, waiting for data */
797 	u_int8_t                t_tfo_probe_state;
798 
799 	u_int32_t       t_rcvoopack;            /* out-of-order packets received */
800 	u_int32_t       t_pawsdrop;             /* segments dropped due to PAWS */
801 	u_int32_t       t_sack_recovery_episode; /* SACK recovery episodes */
802 	uint32_t        t_rack_recovery_episode; /* RACK recovery episodes */
803 	uint32_t        t_rack_reo_timeout_recovery_episode; /* RACK recovery triggered by reordering timeout */
804 	u_int32_t       t_reordered_pkts;       /* packets reorderd */
805 	u_int32_t       t_dsack_sent;           /* Sent DSACK notification */
806 	u_int32_t       t_dsack_recvd;          /* Received a valid DSACK option */
807 	SLIST_HEAD(, tcp_notify_ack_marker) t_notify_ack; /* state for notifying data acknowledgements */
808 	u_int32_t       t_recv_throttle_ts;     /* TS for start of recv throttle */
809 	u_int32_t       t_rxt_minimum_timeout;  /* minimum retransmit timeout in ms */
810 	uint32_t        t_challengeack_last;    /* last time challenge ACK was sent per sec */
811 	uint32_t        t_challengeack_count;   /* # of challenge ACKs already sent per sec */
812 
813 	u_int32_t       t_connect_time;         /* time when the connection started */
814 
815 	uint64_t        t_rcvwnd_limited_total_time;
816 	uint64_t        t_rcvwnd_limited_start_time;
817 
818 	uint32_t        t_comp_gencnt; /* Current compression generation-count */
819 	uint32_t        t_comp_lastinc; /* Last time the gen-count was changed - should change every TCP_COMP_CHANGE_RATE ms */
820 #define TCP_COMP_CHANGE_RATE    5 /* Intervals at which we change the gencnt. Means that worst-case we send one ACK every TCP_COMP_CHANGE_RATE ms */
821 
822 	uint32_t        t_ts_offset; /* Randomized timestamp offset to hide on-the-wire timestamp */
823 
824 #define NCURR_RTT_HIST 4                         /* Number of current RTT samples (k) */
825 	uint32_t curr_rtt_hist[NCURR_RTT_HIST];  /* last k current RTT samples */
826 	uint32_t curr_rtt_min;                   /* Minimum current RTT from last k samples */
827 	uint32_t curr_rtt_index;                 /* Index for current RTT samples */
828 
829 	tcp_seq rcv_high;                   /* highest sequence number received */
830 	uint32_t tsv_high;                  /* timestamp value of highest received sequence number */
831 	struct tcp_rledbat_state t_rlstate; /* State used by rLedbat */
832 
833 	uint32_t rcv_srtt;                  /* receiver's SRTT, coarse when Timestamp not supported */
834 	uint32_t rcv_rtt_est_ts;            /* start of measurement for estimating RTT when Timestamp not supported */
835 	uint32_t rcv_rtt_est_seq;           /* expected sequence number for completion of 1RTT when Timestamp not supported */
836 
837 	TAILQ_HEAD(tcp_seg_sent_head, tcp_seg_sent) t_segs_sent; /* Time ordered segment list used for RACK */
838 	struct tcp_seg_sent_tree_head t_segs_sent_tree; /* RB tree to track S/ACKED segments used for RACK */
839 	TAILQ_HEAD(tcp_seg_acked_head, tcp_seg_sent) t_segs_acked; /* Temporary storage for ACKed segments used for RACK */
840 	struct tcp_seg_pool seg_pool;
841 
842 # define TCP_RACK_RECOVERY_PERSIST_MAX (16)
843 	struct tcp_rack {
844 		uint32_t        xmit_ts;
845 		uint32_t        end_seq;
846 		uint32_t        rtt; /* RTT of the most recently delivered segment that was not marked as invalid as a possible spurious retransmission. */
847 		tcp_seq         dsack_round_end;
848 		uint32_t        reo_wnd;
849 		uint8_t         reo_wnd_multi;
850 		uint8_t         reo_wnd_persist:5,
851 		    advanced:1,
852 		    dsack_round_seen:1,
853 		    segs_retransmitted:1;
854 	} rack;
855 
856 	/*
857 	 * Below counters are used to estmitate current flight size,
858 	 * hence these counters reflect current values instead of total
859 	 */
860 	uint32_t bytes_lost;
861 	uint32_t bytes_retransmitted;
862 	uint32_t bytes_sacked;
863 
864 	uuid_t          t_fsw_uuid;
865 	uuid_t          t_flow_uuid;
866 };
867 
868 #define IN_FASTRECOVERY(tp)     (tp->t_flags & TF_FASTRECOVERY)
869 #define SACK_ENABLED(tp)        (tp->t_flagsext & TF_SACK_ENABLE)
870 #define TFO_ENABLED(tp)         (tp->t_flagsext & TF_FASTOPEN)
871 #define TCP_RACK_ENABLED(tp)    ((tp->t_flagsext & TF_RACK_ENABLED) && SACK_ENABLED(tp) && !TFO_ENABLED(tp))
872 
873 static inline bool
tcp_sent_tlp_retrans(const struct tcpcb * tp)874 tcp_sent_tlp_retrans(const struct tcpcb *tp)
875 {
876 	return (tp->t_flagsext & (TF_SENT_TLPROBE | TF_TLP_IS_RETRANS)) == (TF_SENT_TLPROBE | TF_TLP_IS_RETRANS);
877 }
878 
879 /*
880  * If the connection is in a throttled state due to advisory feedback from
881  * the interface output queue, reset that state. We do this in favor
882  * of entering recovery because the data transfer during recovery
883  * should be just a trickle and it will help to improve performance.
884  * We also do not want to back off twice in the same RTT.
885  */
886 #define ENTER_FASTRECOVERY(_tp_) do {                                           \
887 	(_tp_)->t_flags |= TF_FASTRECOVERY;                                     \
888 	if (INP_IS_FLOW_CONTROLLED((_tp_)->t_inpcb))                            \
889 	        inp_reset_fc_state((_tp_)->t_inpcb);                            \
890 	if (!SLIST_EMPTY(&tp->t_rxt_segments))                                  \
891 	        tcp_rxtseg_clean(tp);                                           \
892 } while(0)
893 
894 #define EXIT_FASTRECOVERY(_tp_) do {                                            \
895 	(_tp_)->t_flags &= ~TF_FASTRECOVERY;                                    \
896 	(_tp_)->t_dupacks = 0;                                                  \
897 	(_tp_)->t_rexmtthresh = (uint8_t)tcprexmtthresh;                        \
898 	(_tp_)->t_bytes_acked = 0;                                              \
899 	(_tp_)->ecn_flags &= ~TE_INRECOVERY;                                    \
900 	(_tp_)->t_timer[TCPT_PTO] = 0;                                          \
901 	(_tp_)->t_flagsext &= ~TF_RESCUE_RXT;                                   \
902 	(_tp_)->t_lossflightsize = 0;                                           \
903 	(_tp_)->sackhint.sack_bytes_acked = 0;                                  \
904 } while(0)
905 
906 /*
907  * When the number of duplicate acks received is less than
908  * the retransmit threshold, use Limited Transmit algorithm
909  */
910 extern uint8_t tcprexmtthresh;
911 #define ALLOW_LIMITED_TRANSMIT(_tp_)                                            \
912 	((_tp_)->t_dupacks > 0 &&                                               \
913 	(_tp_)->t_dupacks < (_tp_)->t_rexmtthresh &&                            \
914 	((_tp_)->t_flagsext & (TF_PKTS_REORDERED|TF_DELAY_RECOVERY))            \
915 	    != (TF_PKTS_REORDERED|TF_DELAY_RECOVERY))
916 
917 /*
918  * This condition is true if timestamp option is supported
919  * on a connection.
920  */
921 #define TSTMP_SUPPORTED(_tp_) \
922 	(((_tp_)->t_flags & (TF_REQ_TSTMP|TF_RCVD_TSTMP)) == \
923 	        (TF_REQ_TSTMP|TF_RCVD_TSTMP))
924 
925 /*
926  * This condition is true if window scale option is supported
927  * on a connection
928  */
929 #define TCP_WINDOW_SCALE_ENABLED(_tp_) \
930 	(((_tp_)->t_flags & (TF_RCVD_SCALE|TF_REQ_SCALE)) == \
931 	        (TF_RCVD_SCALE|TF_REQ_SCALE))
932 
933 /* Is ECN negotiated end-to-end */
934 #define TCP_ECN_ENABLED(_tp_) \
935 	(((_tp_)->ecn_flags & (TE_ECN_ON)) == (TE_ECN_ON))
936 
937 extern int tcp_acc_ecn;
938 extern int tcp_l4s;
939 /*
940  * Accurate ECN feedback is enabled if
941  * 1. It is not disabled explicitly by tcp options
942  * 2. It is enabled either by sysctl or L4S toggle or A/B deployment or tcp_options,
943  * It supports ACE field as well as AccECN option for ECN feedback
944  */
945 #define TCP_ACC_ECN_ENABLED(_tp_) \
946    (((_tp_)->t_flagsext & TF_L4S_DISABLED) == 0 && \
947    (tcp_acc_ecn == 1 || ((_tp_)->t_flagsext & TF_L4S_ENABLED)))
948 
949 /* Accurate ECN is enabled and negotiated end-to-end */
950 #define TCP_ACC_ECN_ON(_tp_) \
951     (TCP_ACC_ECN_ENABLED(_tp_) && \
952     (((_tp_)->ecn_flags & (TE_ACC_ECN_ON)) == (TE_ACC_ECN_ON)))
953 
954 #define TCP_L4S_ENABLED(_tp_) \
955     (((_tp_)->t_flagsext & TF_L4S_DISABLED) == 0 && \
956     (tcp_l4s == 1 || ((_tp_)->t_flagsext & TF_L4S_ENABLED)))
957 /*
958  * Gives number of bytes acked by this ack
959  */
960 #define BYTES_ACKED(_th_, _tp_) \
961 	((_th_)->th_ack - (_tp_)->snd_una)
962 
963 /* Returns true if a DSACK option should be sent */
964 #define TCP_SEND_DSACK_OPT(_tp_) \
965 	((_tp_)->t_dsack_lseq > 0 && (_tp_)->t_dsack_rseq > 0)
966 
967 /*
968  * Returns true if a DSACK sequence is within the max send window that will
969  * be accepted. In order to set a window to validate sequence numbers, the
970  * max send window within which a DSACK option is processed is limited.
971  *
972  * We need to choose a maximum window to check if the sequence number is
973  * within the window. One arbitrary choice is 256 * MSS because if the
974  * window is as large as 256 segments it might be big enough to ignore the
975  * DSACK option. Choosing a much larger limit means that the memory for
976  * retransmit segments can be held for a longer time.
977  */
978 #define TCP_DSACK_MAX_SEND_WINDOW(_tp_) (MIN((_tp_)->snd_wnd, tcp_autosndbuf_max))
979 #define TCP_DSACK_SEQ_IN_WINDOW(_tp_, _seq_, _una_) \
980     (SEQ_LEQ((_seq_), (_tp_)->snd_max) && \
981     SEQ_GEQ((_seq_), ((_una_) - TCP_DSACK_MAX_SEND_WINDOW(_tp_))))
982 
983 #define TCP_RESET_REXMT_STATE(_tp_) do { \
984 	(_tp_)->t_rxtshift = 0; \
985 	(_tp_)->t_rxtstart = 0; \
986 	mptcp_reset_rexmit_state((_tp_)); \
987 } while(0);
988 
989 #define TCP_IF_STATE_CHANGED(tp, probe_if_index)                        \
990 	(probe_if_index > 0 && tp->t_inpcb->inp_last_outifp != NULL &&  \
991 	probe_if_index == tp->t_inpcb->inp_last_outifp->if_index)
992 
993 #define TCP_RLEDBAT_ENABLED(_tp) \
994     (tcp_rledbat == 1 && TSTMP_SUPPORTED(_tp))
995 
996 #define TCP_RECV_BG(_so) \
997     (tcp_recv_bg == 1 || IS_TCP_RECV_BG(_so))
998 
999 #define TCP_USE_RLEDBAT(_tp, _so) \
1000     TCP_RLEDBAT_ENABLED(_tp) && TCP_RECV_BG(_so)
1001 
1002 /*
1003  * Structure to hold TCP options that are only used during segment
1004  * processing (in tcp_input), but not held in the tcpcb.
1005  * It's basically used to reduce the number of parameters
1006  * to tcp_dooptions.
1007  */
1008 struct tcpopt {
1009 	uint32_t        to_flags;               /* which options are present */
1010 #define TOF_TS          0x0001          /* timestamp */
1011 #define TOF_MSS         0x0010
1012 #define TOF_SCALE       0x0020
1013 #define TOF_SIGNATURE   0x0040  /* signature option present */
1014 #define TOF_SIGLEN      0x0080  /* signature length valid (RFC2385) */
1015 #define TOF_SACK        0x0100          /* Peer sent SACK option */
1016 #define TOF_MPTCP       0x0200  /* MPTCP options to be dropped */
1017 #define TOF_TFO         0x0400  /* TFO cookie option present */
1018 #define TOF_TFOREQ      0x0800  /* TFO cookie request present */
1019 	uint32_t        to_tsval;
1020 	uint32_t        to_tsecr;
1021 	uint16_t        to_mss;
1022 	uint8_t         to_requested_s_scale;
1023 	uint8_t         to_nsacks;       /* number of SACK blocks */
1024 	u_char          *to_sacks;       /* pointer to the first SACK blocks */
1025 	u_char          *to_tfo;         /* pointer to the TFO cookie */
1026 	uint8_t         to_num_accecn;   /* number of Accurate ECN counters */
1027 	uint8_t         *to_accecn;      /* pointer to the first Accurate ECN counter */
1028 	uint8_t         to_accecn_order; /* Accurate ECN ordering */
1029 };
1030 
1031 #define intotcpcb(ip)   ((struct tcpcb *)(ip)->inp_ppcb)
1032 #define sototcpcb(so)   (intotcpcb(sotoinpcb(so)))
1033 
1034 /* TFO-specific defines */
1035 #define TFO_COOKIE_LEN_MIN      4
1036 #define TFO_COOKIE_LEN_DEFAULT  8
1037 #define TFO_COOKIE_LEN_MAX      16
1038 
1039 /*
1040  * The initial retransmission should happen at rtt + 4 * rttvar.
1041  * Because of the way we do the smoothing, srtt and rttvar
1042  * will each average +1/2 tick of bias.  When we compute
1043  * the retransmit timer, we want 1/2 tick of rounding and
1044  * 1 extra tick because of +-1/2 tick uncertainty in the
1045  * firing of the timer.  The bias will give us exactly the
1046  * 1.5 tick we need.  But, because the bias is
1047  * statistical, we have to test that we don't drop below
1048  * the minimum feasible timer (which is 2 ticks).
1049  * This version of the macro adapted from a paper by Lawrence
1050  * Brakmo and Larry Peterson which outlines a problem caused
1051  * by insufficient precision in the original implementation,
1052  * which results in inappropriately large RTO values for very
1053  * fast networks.
1054  */
1055 #define TCP_REXMTVAL(tp) \
1056 	max((tp)->t_rttmin, (((tp)->t_srtt >> (TCP_RTT_SHIFT - TCP_DELTA_SHIFT))  \
1057 	  + (tp)->t_rttvar) >> TCP_DELTA_SHIFT)
1058 
1059 /*
1060  * Jaguar compatible TCP control block, for xtcpcb
1061  * Does not have the old fields
1062  */
1063 struct otcpcb {
1064 #else
1065 struct tseg_qent;
1066 _TCPCB_LIST_HEAD(tsegqe_head, tseg_qent);
1067 
1068 struct tcpcb {
1069 #endif /* KERNEL_PRIVATE */
1070 #if defined(KERNEL_PRIVATE)
1071 	u_int32_t t_segq;
1072 #else
1073 	struct  tsegqe_head t_segq;
1074 #endif /* KERNEL_PRIVATE */
1075 	int     t_dupacks;              /* consecutive dup acks recd */
1076 	u_int32_t unused;               /* unused now: was t_template */
1077 
1078 	int     t_timer[TCPT_NTIMERS_EXT];      /* tcp timers */
1079 
1080 	_TCPCB_PTR(struct inpcb *) t_inpcb;     /* back pointer to internet pcb */
1081 	int     t_state;                /* state of this connection */
1082 	u_int   t_flags;
1083 #define TF_ACKNOW       0x00001         /* ack peer immediately */
1084 #define TF_DELACK       0x00002         /* ack, but try to delay it */
1085 #define TF_NODELAY      0x00004         /* don't delay packets to coalesce */
1086 #define TF_NOOPT        0x00008         /* don't use tcp options */
1087 #define TF_SENTFIN      0x00010         /* have sent FIN */
1088 #define TF_REQ_SCALE    0x00020         /* have/will request window scaling */
1089 #define TF_RCVD_SCALE   0x00040         /* other side has requested scaling */
1090 #define TF_REQ_TSTMP    0x00080         /* have/will request timestamps */
1091 #define TF_RCVD_TSTMP   0x00100         /* a timestamp was received in SYN */
1092 #define TF_SACK_PERMIT  0x00200         /* other side said I could SACK */
1093 #define TF_NEEDSYN      0x00400         /* send SYN (implicit state) - unused but needed for backwards compatibility */
1094 #define TF_NEEDFIN      0x00800         /* send FIN (implicit state) */
1095 #define TF_NOPUSH       0x01000         /* don't push */
1096 #define TF_REQ_CC       0x02000         /* have/will request CC */
1097 #define TF_RCVD_CC      0x04000         /* a CC was received in SYN */
1098 #define TF_SENDCCNEW    0x08000         /* Not implemented */
1099 #define TF_MORETOCOME   0x10000         /* More data to be appended to sock */
1100 #define TF_LQ_OVERFLOW  0x20000         /* listen queue overflow */
1101 #define TF_RXWIN0SENT   0x40000         /* sent a receiver win 0 in response */
1102 #define TF_SLOWLINK     0x80000         /* route is a on a modem speed link */
1103 
1104 	int     t_force;                /* 1 if forcing out a byte */
1105 
1106 	tcp_seq snd_una;                /* send unacknowledged */
1107 	tcp_seq snd_max;                /* highest sequence number sent;
1108 	                                 * used to recognize retransmits
1109 	                                 */
1110 	tcp_seq snd_nxt;                /* send next */
1111 	tcp_seq snd_up;                 /* send urgent pointer */
1112 
1113 	tcp_seq snd_wl1;                /* window update seg seq number */
1114 	tcp_seq snd_wl2;                /* window update seg ack number */
1115 	tcp_seq iss;                    /* initial send sequence number */
1116 	tcp_seq irs;                    /* initial receive sequence number */
1117 
1118 	tcp_seq rcv_nxt;                /* receive next */
1119 	tcp_seq rcv_adv;                /* advertised window */
1120 	u_int32_t rcv_wnd;              /* receive window */
1121 	tcp_seq rcv_up;                 /* receive urgent pointer */
1122 
1123 	u_int32_t snd_wnd;              /* send window */
1124 	u_int32_t snd_cwnd;             /* congestion-controlled window */
1125 	u_int32_t snd_ssthresh;         /* snd_cwnd size threshold for
1126 	                                 * for slow start exponential to
1127 	                                 * linear switch
1128 	                                 */
1129 	u_int   t_maxopd;               /* mss plus options */
1130 
1131 	u_int32_t t_rcvtime;            /* time at which a packet was received */
1132 	u_int32_t t_starttime;          /* time connection was established */
1133 	int     t_rtttime;              /* round trip time */
1134 	tcp_seq t_rtseq;                /* sequence number being timed */
1135 
1136 	int     t_rxtcur;               /* current retransmit value (ticks) */
1137 	u_int   t_maxseg;               /* maximum segment size */
1138 	int     t_srtt;                 /* smoothed round-trip time */
1139 	int     t_rttvar;               /* variance in round-trip time */
1140 
1141 	int     t_rxtshift;             /* log(2) of rexmt exp. backoff */
1142 	u_int   t_rttmin;               /* minimum rtt allowed */
1143 	u_int32_t t_rttupdated;         /* number of times rtt sampled */
1144 	u_int32_t max_sndwnd;           /* largest window peer has offered */
1145 
1146 	int     t_softerror;            /* possible error not yet reported */
1147 /* out-of-band data */
1148 	char    t_oobflags;             /* have some */
1149 	char    t_iobc;                 /* input character */
1150 #define TCPOOB_HAVEDATA 0x01
1151 #define TCPOOB_HADDATA  0x02
1152 /* RFC 1323 variables */
1153 	u_char  snd_scale;              /* window scaling for send window */
1154 	u_char  rcv_scale;              /* window scaling for recv window */
1155 	u_char  request_r_scale;        /* pending window scaling */
1156 	u_char  requested_s_scale;
1157 	u_int32_t ts_recent;            /* timestamp echo data */
1158 
1159 	u_int32_t ts_recent_age;        /* when last updated */
1160 	tcp_seq last_ack_sent;
1161 /* RFC 1644 variables */
1162 	tcp_cc  cc_send;                /* send connection count */
1163 	tcp_cc  cc_recv;                /* receive connection count */
1164 	tcp_seq snd_recover;            /* for use in fast recovery */
1165 /* experimental */
1166 	u_int32_t snd_cwnd_prev;        /* cwnd prior to retransmit */
1167 	u_int32_t snd_ssthresh_prev;    /* ssthresh prior to retransmit */
1168 	u_int32_t t_badrxtwin;          /* window for retransmit recovery */
1169 };
1170 
1171 #define        tcps_ecn_setup  tcps_ecn_client_success
1172 #define        tcps_sent_cwr   tcps_ecn_recv_ece
1173 #define        tcps_sent_ece   tcps_ecn_sent_ece
1174 
1175 /*
1176  * TCP statistics.
1177  * Many of these should be kept per connection,
1178  * but that's inconvenient at the moment.
1179  */
1180 struct  tcpstat {
1181 	u_int32_t       tcps_connattempt;       /* connections initiated */
1182 	u_int32_t       tcps_accepts;           /* connections accepted */
1183 	u_int32_t       tcps_connects;          /* connections established */
1184 	u_int32_t       tcps_drops;             /* connections dropped */
1185 	u_int32_t       tcps_conndrops;         /* embryonic connections dropped */
1186 	u_int32_t       tcps_closed;            /* conn. closed (includes drops) */
1187 	u_int32_t       tcps_segstimed;         /* segs where we tried to get rtt */
1188 	u_int32_t       tcps_rttupdated;        /* times we succeeded */
1189 	u_int32_t       tcps_delack;            /* delayed acks sent */
1190 	u_int32_t       tcps_timeoutdrop;       /* conn. dropped in rxmt timeout */
1191 	u_int32_t       tcps_rexmttimeo;        /* retransmit timeouts */
1192 	u_int32_t       tcps_persisttimeo;      /* persist timeouts */
1193 	u_int32_t       tcps_keeptimeo;         /* keepalive timeouts */
1194 	u_int32_t       tcps_keepprobe;         /* keepalive probes sent */
1195 	u_int32_t       tcps_keepdrops;         /* connections dropped in keepalive */
1196 
1197 	u_int32_t       tcps_sndtotal;          /* total packets sent */
1198 	u_int32_t       tcps_sndpack;           /* data packets sent */
1199 	u_int32_t       tcps_sndbyte;           /* data bytes sent */
1200 	u_int32_t       tcps_sndrexmitpack;     /* data packets retransmitted */
1201 	u_int32_t       tcps_sndrexmitbyte;     /* data bytes retransmitted */
1202 	u_int32_t       tcps_sndacks;           /* ack-only packets sent */
1203 	u_int32_t       tcps_sndprobe;          /* window probes sent */
1204 	u_int32_t       tcps_sndurg;            /* packets sent with URG only */
1205 	u_int32_t       tcps_sndwinup;          /* window update-only packets sent */
1206 	u_int32_t       tcps_sndctrl;           /* control (SYN|FIN|RST) packets sent */
1207 
1208 	u_int32_t       tcps_rcvtotal;          /* total packets received */
1209 	u_int32_t       tcps_rcvpack;           /* packets received in sequence */
1210 	u_int32_t       tcps_rcvbyte;           /* bytes received in sequence */
1211 	u_int32_t       tcps_rcvbadsum;         /* packets received with ccksum errs */
1212 	u_int32_t       tcps_rcvbadoff;         /* packets received with bad offset */
1213 	u_int32_t       tcps_rcvmemdrop;        /* packets dropped for lack of memory */
1214 	u_int32_t       tcps_rcvshort;          /* packets received too short */
1215 	u_int32_t       tcps_rcvduppack;        /* duplicate-only packets received */
1216 	u_int32_t       tcps_rcvdupbyte;        /* duplicate-only bytes received */
1217 	u_int32_t       tcps_rcvpartduppack;    /* packets with some duplicate data */
1218 	u_int32_t       tcps_rcvpartdupbyte;    /* dup. bytes in part-dup. packets */
1219 	u_int32_t       tcps_rcvoopack;         /* out-of-order packets received */
1220 	u_int32_t       tcps_rcvoobyte;         /* out-of-order bytes received */
1221 	u_int32_t       tcps_rcvpackafterwin;   /* packets with data after window */
1222 	u_int32_t       tcps_rcvbyteafterwin;   /* bytes rcvd after window */
1223 	u_int32_t       tcps_rcvafterclose;     /* packets rcvd after "close" */
1224 	u_int32_t       tcps_rcvwinprobe;       /* rcvd window probe packets */
1225 	u_int32_t       tcps_rcvdupack;         /* rcvd duplicate acks */
1226 	u_int32_t       tcps_rcvacktoomuch;     /* rcvd acks for unsent data */
1227 	u_int32_t       tcps_rcvackpack;        /* rcvd ack packets */
1228 	u_int32_t       tcps_rcvackbyte;        /* bytes acked by rcvd acks */
1229 	u_int32_t       tcps_rcvwinupd;         /* rcvd window update packets */
1230 	u_int32_t       tcps_pawsdrop;          /* segments dropped due to PAWS */
1231 	u_int32_t       tcps_predack;           /* times hdr predict ok for acks */
1232 	u_int32_t       tcps_preddat;           /* times hdr predict ok for data pkts */
1233 	u_int32_t       tcps_pcbcachemiss;
1234 	u_int32_t       tcps_cachedrtt;         /* times cached RTT in route updated */
1235 	u_int32_t       tcps_cachedrttvar;      /* times cached rttvar updated */
1236 	u_int32_t       tcps_cachedssthresh;    /* times cached ssthresh updated */
1237 	u_int32_t       tcps_usedrtt;           /* times RTT initialized from route */
1238 	u_int32_t       tcps_usedrttvar;        /* times RTTVAR initialized from rt */
1239 	u_int32_t       tcps_usedssthresh;      /* times ssthresh initialized from rt*/
1240 	u_int32_t       tcps_persistdrop;       /* timeout in persist state */
1241 	u_int32_t       tcps_badsyn;            /* bogus SYN, e.g. premature ACK */
1242 	u_int32_t       tcps_mturesent;         /* resends due to MTU discovery */
1243 	u_int32_t       tcps_listendrop;        /* listen queue overflows */
1244 	u_int32_t       tcps_synchallenge;      /* challenge ACK due to bad SYN */
1245 	u_int32_t       tcps_rstchallenge;      /* challenge ACK due to bad RST */
1246 
1247 	/* new stats from FreeBSD 5.4 sync up */
1248 	u_int32_t       tcps_minmssdrops;       /* average minmss too low drops */
1249 
1250 	u_int32_t       tcps_sndrexmitbad;      /* unnecessary packet retransmissions */
1251 	u_int32_t       tcps_badrst;            /* ignored RSTs in the window */
1252 
1253 	u_int32_t       tcps_sc_added;          /* entry added to syncache */
1254 	u_int32_t       tcps_sc_retransmitted;  /* syncache entry was retransmitted */
1255 	u_int32_t       tcps_sc_dupsyn;         /* duplicate SYN packet */
1256 	u_int32_t       tcps_sc_dropped;        /* could not reply to packet */
1257 	u_int32_t       tcps_sc_completed;      /* successful extraction of entry */
1258 	u_int32_t       tcps_sc_bucketoverflow; /* syncache per-bucket limit hit */
1259 	u_int32_t       tcps_sc_cacheoverflow;  /* syncache cache limit hit */
1260 	u_int32_t       tcps_sc_reset;          /* RST removed entry from syncache */
1261 	u_int32_t       tcps_sc_stale;          /* timed out or listen socket gone */
1262 	u_int32_t       tcps_sc_aborted;        /* syncache entry aborted */
1263 	u_int32_t       tcps_sc_badack;         /* removed due to bad ACK */
1264 	u_int32_t       tcps_sc_unreach;        /* ICMP unreachable received */
1265 	u_int32_t       tcps_sc_zonefail;       /* zalloc() failed */
1266 	u_int32_t       tcps_sc_sendcookie;     /* SYN cookie sent */
1267 	u_int32_t       tcps_sc_recvcookie;     /* SYN cookie received */
1268 
1269 	u_int32_t       tcps_hc_added;          /* entry added to hostcache */
1270 	u_int32_t       tcps_hc_bucketoverflow; /* hostcache per bucket limit hit */
1271 
1272 	/* SACK related stats */
1273 	u_int32_t       tcps_sack_recovery_episode; /* SACK recovery episodes */
1274 	u_int32_t       tcps_sack_rexmits;          /* SACK rexmit segments   */
1275 	u_int32_t       tcps_sack_rexmit_bytes;     /* SACK rexmit bytes      */
1276 	u_int32_t       tcps_sack_rcv_blocks;       /* SACK blocks (options) received */
1277 	u_int32_t       tcps_sack_send_blocks;      /* SACK blocks (options) sent     */
1278 	u_int32_t       tcps_sack_sboverflow;       /* SACK sendblock overflow   */
1279 
1280 	/* RACK related stats */
1281 	u_int32_t       tcps_rack_recovery_episode; /* RACK recovery episodes */
1282 	u_int32_t       tcps_rack_reordering_timeout_recovery_episode; /* RACK recovery episodes due to reordering timeout */
1283 	u_int32_t       tcps_rack_rexmits;          /* RACK rexmit segments   */
1284 
1285 	u_int32_t       tcps_bg_rcvtotal;       /* total background packets received */
1286 	u_int32_t       tcps_rxtfindrop;        /* drop conn after retransmitting FIN */
1287 	u_int32_t       tcps_fcholdpacket;      /* packets withheld because of flow control */
1288 
1289 	u_int32_t       tcps_limited_txt;       /* Limited transmit used */
1290 	u_int32_t       tcps_early_rexmt;       /* Early retransmit used */
1291 	u_int32_t       tcps_sack_ackadv;       /* Cumulative ack advanced along with sack */
1292 
1293 	/* Checksum related stats */
1294 	u_int32_t       tcps_rcv_swcsum;        /* tcp swcksum (inbound), packets */
1295 	u_int32_t       tcps_rcv_swcsum_bytes;  /* tcp swcksum (inbound), bytes */
1296 	u_int32_t       tcps_rcv6_swcsum;       /* tcp6 swcksum (inbound), packets */
1297 	u_int32_t       tcps_rcv6_swcsum_bytes; /* tcp6 swcksum (inbound), bytes */
1298 	u_int32_t       tcps_snd_swcsum;        /* tcp swcksum (outbound), packets */
1299 	u_int32_t       tcps_snd_swcsum_bytes;  /* tcp swcksum (outbound), bytes */
1300 	u_int32_t       tcps_snd6_swcsum;       /* tcp6 swcksum (outbound), packets */
1301 	u_int32_t       tcps_snd6_swcsum_bytes; /* tcp6 swcksum (outbound), bytes */
1302 	u_int32_t       tcps_unused_1;
1303 	u_int32_t       tcps_unused_2;
1304 	u_int32_t       tcps_unused_3;
1305 
1306 	/* MPTCP Related stats */
1307 	u_int32_t       tcps_invalid_mpcap;     /* Invalid MPTCP capable opts */
1308 	u_int32_t       tcps_invalid_joins;     /* Invalid MPTCP joins */
1309 	u_int32_t       tcps_mpcap_fallback;    /* TCP fallback in primary */
1310 	u_int32_t       tcps_join_fallback;     /* No MPTCP in secondary */
1311 	u_int32_t       tcps_estab_fallback;    /* DSS option dropped */
1312 	u_int32_t       tcps_invalid_opt;       /* Catchall error stat */
1313 	u_int32_t       tcps_mp_outofwin;       /* Packet lies outside the
1314 	                                         *  shared recv window */
1315 	u_int32_t       tcps_mp_reducedwin;     /* Reduced subflow window */
1316 	u_int32_t       tcps_mp_badcsum;        /* Bad DSS csum */
1317 	u_int32_t       tcps_mp_oodata;         /* Out of order data */
1318 	u_int32_t       tcps_mp_switches;       /* number of subflow switch */
1319 	u_int32_t       tcps_mp_rcvtotal;       /* number of rcvd packets */
1320 	u_int32_t       tcps_mp_rcvbytes;       /* number of bytes received */
1321 	u_int32_t       tcps_mp_sndpacks;       /* number of data packs sent */
1322 	u_int32_t       tcps_mp_sndbytes;       /* number of bytes sent */
1323 	u_int32_t       tcps_join_rxmts;        /* join ack retransmits */
1324 	u_int32_t       tcps_tailloss_rto;      /* RTO due to tail loss */
1325 	u_int32_t       tcps_reordered_pkts;    /* packets reorderd */
1326 	u_int32_t       tcps_recovered_pkts;    /* recovered after loss */
1327 	u_int32_t       tcps_pto;               /* probe timeout */
1328 	u_int32_t       tcps_rto_after_pto;     /* RTO after a probe */
1329 	u_int32_t       tcps_tlp_recovery;      /* TLP induced fast recovery */
1330 	u_int32_t       tcps_tlp_recoverlastpkt; /* TLP recoverd last pkt */
1331 	u_int32_t       tcps_ecn_client_success; /* client-side connection negotiated ECN */
1332 	u_int32_t       tcps_ecn_recv_ece;      /* ECE received, sent CWR */
1333 	u_int32_t       tcps_ecn_sent_ece;      /* Sent ECE notification */
1334 	u_int32_t       tcps_detect_reordering; /* Detect pkt reordering */
1335 	u_int32_t       tcps_delay_recovery;    /* Delay fast recovery */
1336 	u_int32_t       tcps_avoid_rxmt;        /* Retransmission was avoided */
1337 	u_int32_t       tcps_unnecessary_rxmt;  /* Retransmission was not needed */
1338 	u_int32_t       tcps_nostretchack;      /* disabled stretch ack algorithm on a connection */
1339 	u_int32_t       tcps_rescue_rxmt;       /* SACK rescue retransmit */
1340 	u_int32_t       tcps_pto_in_recovery;   /* rescue retransmit in fast recovery */
1341 	u_int32_t       tcps_pmtudbh_reverted;  /* PMTU Blackhole detection, segment size reverted */
1342 
1343 	/* DSACK related statistics */
1344 	u_int32_t       tcps_dsack_disable;     /* DSACK disabled due to n/w duplication */
1345 	u_int32_t       tcps_dsack_ackloss;     /* ignore DSACK due to ack loss */
1346 	u_int32_t       tcps_dsack_badrexmt;    /* DSACK based bad rexmt recovery */
1347 	u_int32_t       tcps_dsack_sent;        /* Sent DSACK notification */
1348 	u_int32_t       tcps_dsack_recvd;       /* Received a valid DSACK option */
1349 	u_int32_t       tcps_dsack_recvd_old;   /* Received an out of window DSACK option */
1350 
1351 	/* MPTCP Subflow selection stats */
1352 	u_int32_t       tcps_mp_sel_symtomsd;   /* By symptomsd */
1353 	u_int32_t       tcps_mp_sel_rtt;        /* By RTT comparison */
1354 	u_int32_t       tcps_mp_sel_rto;        /* By RTO comparison */
1355 	u_int32_t       tcps_mp_sel_peer;       /* By peer's output pattern */
1356 	u_int32_t       tcps_mp_num_probes;     /* Number of probes sent */
1357 	u_int32_t       tcps_mp_verdowngrade;   /* MPTCP version downgrade */
1358 	u_int32_t       tcps_drop_after_sleep;  /* drop after long AP sleep */
1359 	u_int32_t       tcps_probe_if;          /* probe packets after interface availability */
1360 	u_int32_t       tcps_probe_if_conflict; /* Can't send probe packets for interface */
1361 
1362 	u_int32_t       tcps_ecn_client_setup;    /* Attempted ECN setup from client side */
1363 	u_int32_t       tcps_ecn_server_setup;    /* Attempted ECN setup from server side */
1364 	u_int32_t       tcps_ecn_server_success;  /* server-side connection negotiated ECN */
1365 	u_int32_t       tcps_ecn_ace_syn_not_ect; /* received AccECN SYN packet with Not-ECT */
1366 	u_int32_t       tcps_ecn_ace_syn_ect1;    /* received AccECN SYN packet with ECT1 */
1367 	u_int32_t       tcps_ecn_ace_syn_ect0;    /* received AccECN SYN packet with ECT0 */
1368 	u_int32_t       tcps_ecn_ace_syn_ce;      /* received AccECN SYN packet with CE */
1369 	u_int32_t       tcps_ecn_lost_synack;   /* Lost SYN-ACK with ECN setup */
1370 	u_int32_t       tcps_ecn_lost_syn;      /* Lost SYN with ECN setup */
1371 	u_int32_t       tcps_ecn_not_supported; /* Server did not support ECN setup */
1372 	u_int32_t       tcps_ecn_recv_ce;       /* Received CE from the network */
1373 	u_int32_t       tcps_ecn_ace_recv_ce;   /* CE count received in ACE field */
1374 	u_int32_t       tcps_ecn_conn_recv_ce;  /* Number of connections received CE atleast once */
1375 	u_int32_t       tcps_ecn_conn_recv_ece; /* Number of connections received ECE atleast once */
1376 	u_int32_t       tcps_ecn_conn_plnoce;   /* Number of connections that received no CE and sufferred packet loss */
1377 	u_int32_t       tcps_ecn_conn_pl_ce;    /* Number of connections that received CE and sufferred packet loss */
1378 	u_int32_t       tcps_ecn_conn_nopl_ce;  /* Number of connections that received CE and sufferred no packet loss */
1379 	u_int32_t       tcps_ecn_fallback_synloss; /* Number of times we did fall back due to SYN-Loss */
1380 	u_int32_t       tcps_ecn_fallback_reorder; /* Number of times we fallback because we detected the PAWS-issue */
1381 	u_int32_t       tcps_ecn_fallback_ce;   /* Number of times we fallback because we received too many CEs */
1382 
1383 	/* TFO-related statistics */
1384 	u_int32_t       tcps_tfo_syn_data_rcv;  /* Received a SYN+data with valid cookie */
1385 	u_int32_t       tcps_tfo_cookie_req_rcv;/* Received a TFO cookie-request */
1386 	u_int32_t       tcps_tfo_cookie_sent;   /* Offered a TFO-cookie to the client */
1387 	u_int32_t       tcps_tfo_cookie_invalid;/* Received an invalid TFO-cookie */
1388 	u_int32_t       tcps_tfo_cookie_req;    /* Cookie requested with the SYN */
1389 	u_int32_t       tcps_tfo_cookie_rcv;    /* Cookie received in a SYN/ACK */
1390 	u_int32_t       tcps_tfo_syn_data_sent; /* SYN+data+cookie sent */
1391 	u_int32_t       tcps_tfo_syn_data_acked;/* SYN+data has been acknowledged */
1392 	u_int32_t       tcps_tfo_syn_loss;      /* SYN+TFO has been lost and we fallback */
1393 	u_int32_t       tcps_tfo_blackhole;     /* TFO got blackholed by a middlebox. */
1394 	u_int32_t       tcps_tfo_cookie_wrong;  /* TFO-cookie we sent was wrong */
1395 	u_int32_t       tcps_tfo_no_cookie_rcv; /* We asked for a cookie but didn't get one */
1396 	u_int32_t       tcps_tfo_heuristics_disable; /* TFO got disabled due to heuristics */
1397 	u_int32_t       tcps_tfo_sndblackhole;  /* TFO got blackholed in the sending direction */
1398 	u_int32_t       tcps_mss_to_default;    /* Change MSS to default using link status report */
1399 	u_int32_t       tcps_mss_to_medium;     /* Change MSS to medium using link status report */
1400 	u_int32_t       tcps_mss_to_low;        /* Change MSS to low using link status report */
1401 	u_int32_t       tcps_ecn_fallback_droprst; /* ECN fallback caused by connection drop due to RST */
1402 	u_int32_t       tcps_ecn_fallback_droprxmt; /* ECN fallback due to drop after multiple retransmits */
1403 	u_int32_t       tcps_ecn_fallback_synrst; /* ECN fallback due to rst after syn */
1404 
1405 	u_int32_t       tcps_mptcp_rcvmemdrop;  /* MPTCP packets dropped for lack of memory */
1406 	u_int32_t       tcps_mptcp_rcvduppack;  /* MPTCP duplicate-only packets received */
1407 	u_int32_t       tcps_mptcp_rcvpackafterwin; /* MPTCP packets with data after window */
1408 
1409 	/* TCP timer statistics */
1410 	u_int32_t       tcps_timer_drift_le_1_ms;       /* Timer drift less or equal to 1 ms */
1411 	u_int32_t       tcps_timer_drift_le_10_ms;      /* Timer drift less or equal to 10 ms */
1412 	u_int32_t       tcps_timer_drift_le_20_ms;      /* Timer drift less or equal to 20 ms */
1413 	u_int32_t       tcps_timer_drift_le_50_ms;      /* Timer drift less or equal to 50 ms */
1414 	u_int32_t       tcps_timer_drift_le_100_ms;     /* Timer drift less or equal to 100 ms */
1415 	u_int32_t       tcps_timer_drift_le_200_ms;     /* Timer drift less or equal to 200 ms */
1416 	u_int32_t       tcps_timer_drift_le_500_ms;     /* Timer drift less or equal to 500 ms */
1417 	u_int32_t       tcps_timer_drift_le_1000_ms;    /* Timer drift less or equal to 1000 ms */
1418 	u_int32_t       tcps_timer_drift_gt_1000_ms;    /* Timer drift greater than 1000 ms */
1419 
1420 	u_int32_t       tcps_mptcp_handover_attempt;    /* Total number of MPTCP-attempts using handover mode */
1421 	u_int32_t       tcps_mptcp_interactive_attempt; /* Total number of MPTCP-attempts using interactive mode */
1422 	u_int32_t       tcps_mptcp_aggregate_attempt;   /* Total number of MPTCP-attempts using aggregate mode */
1423 	u_int32_t       tcps_mptcp_fp_handover_attempt; /* Same as previous three but only for first-party apps */
1424 	u_int32_t       tcps_mptcp_fp_interactive_attempt;
1425 	u_int32_t       tcps_mptcp_fp_aggregate_attempt;
1426 	u_int32_t       tcps_mptcp_heuristic_fallback;  /* Total number of MPTCP-connections that fell back due to heuristics */
1427 	u_int32_t       tcps_mptcp_fp_heuristic_fallback;       /* Same as previous but for first-party apps */
1428 	u_int32_t       tcps_mptcp_handover_success_wifi;       /* Total number of successfull handover-mode connections that *started* on WiFi */
1429 	u_int32_t       tcps_mptcp_handover_success_cell;       /* Total number of successfull handover-mode connections that *started* on Cell */
1430 	u_int32_t       tcps_mptcp_interactive_success;         /* Total number of interactive-mode connections that negotiated MPTCP */
1431 	u_int32_t       tcps_mptcp_aggregate_success;           /* Same as previous but for aggregate */
1432 	u_int32_t       tcps_mptcp_fp_handover_success_wifi;    /* Same as previous four, but for first-party apps */
1433 	u_int32_t       tcps_mptcp_fp_handover_success_cell;
1434 	u_int32_t       tcps_mptcp_fp_interactive_success;
1435 	u_int32_t       tcps_mptcp_fp_aggregate_success;
1436 	u_int32_t       tcps_mptcp_handover_cell_from_wifi;     /* Total number of connections that use cell in handover-mode (coming from WiFi) */
1437 	u_int32_t       tcps_mptcp_handover_wifi_from_cell;     /* Total number of connections that use WiFi in handover-mode (coming from cell) */
1438 	u_int32_t       tcps_mptcp_interactive_cell_from_wifi;  /* Total number of connections that use cell in interactive mode (coming from WiFi) */
1439 	u_int64_t       tcps_mptcp_handover_cell_bytes;         /* Total number of bytes sent on cell in handover-mode (on new subflows, ignoring initial one) */
1440 	u_int64_t       tcps_mptcp_interactive_cell_bytes;      /* Same as previous but for interactive */
1441 	u_int64_t       tcps_mptcp_aggregate_cell_bytes;
1442 	u_int64_t       tcps_mptcp_handover_all_bytes;          /* Total number of bytes sent in handover */
1443 	u_int64_t       tcps_mptcp_interactive_all_bytes;
1444 	u_int64_t       tcps_mptcp_aggregate_all_bytes;
1445 	u_int32_t       tcps_mptcp_back_to_wifi;        /* Total number of connections that succeed to move traffic away from cell (when starting on cell) */
1446 	u_int32_t       tcps_mptcp_wifi_proxy;          /* Total number of new subflows that fell back to regular TCP on cell */
1447 	u_int32_t       tcps_mptcp_cell_proxy;          /* Total number of new subflows that fell back to regular TCP on WiFi */
1448 
1449 	/* TCP offload statistics */
1450 	u_int32_t       tcps_ka_offload_drops;  /* Keep alive drops for timeout reported by firmware */
1451 
1452 	u_int32_t       tcps_mptcp_triggered_cell;      /* Total number of times an MPTCP-connection triggered cell bringup */
1453 
1454 	u_int32_t       tcps_fin_timeout_drops;
1455 };
1456 
1457 
1458 struct tcpstat_local {
1459 	u_int64_t badformat;
1460 	u_int64_t unspecv6;
1461 	u_int64_t synfin;
1462 	u_int64_t badformatipsec;
1463 	u_int64_t noconnnolist;
1464 	u_int64_t noconnlist;
1465 	u_int64_t listbadsyn;
1466 	u_int64_t icmp6unreach;
1467 	u_int64_t deprecate6;
1468 	u_int64_t ooopacket;
1469 	u_int64_t rstinsynrcv;
1470 	u_int64_t dospacket;
1471 	u_int64_t cleanup;
1472 	u_int64_t synwindow;
1473 };
1474 
1475 #pragma pack(4)
1476 
1477 /*
1478  * TCB structure exported to user-land via sysctl(3).
1479  * Evil hack: declare only if in_pcb.h and sys/socketvar.h have been
1480  * included.  Not all of our clients do.
1481  */
1482 
1483 struct  xtcpcb {
1484 	u_int32_t       xt_len;
1485 #ifdef KERNEL_PRIVATE
1486 	struct  inpcb_compat    xt_inp;
1487 #else
1488 	struct  inpcb   xt_inp;
1489 #endif
1490 #ifdef KERNEL_PRIVATE
1491 	struct  otcpcb  xt_tp;
1492 #else
1493 	struct  tcpcb   xt_tp;
1494 #endif
1495 	struct  xsocket xt_socket;
1496 	u_quad_t        xt_alignment_hack;
1497 };
1498 
1499 #if XNU_TARGET_OS_OSX || KERNEL || !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
1500 
1501 struct  xtcpcb64 {
1502 	u_int32_t               xt_len;
1503 	struct xinpcb64         xt_inpcb;
1504 
1505 	u_int64_t t_segq;
1506 	int     t_dupacks;              /* consecutive dup acks recd */
1507 
1508 	int t_timer[TCPT_NTIMERS_EXT];  /* tcp timers */
1509 
1510 	int     t_state;                /* state of this connection */
1511 	u_int   t_flags;
1512 
1513 	int     t_force;                /* 1 if forcing out a byte */
1514 
1515 	tcp_seq snd_una;                /* send unacknowledged */
1516 	tcp_seq snd_max;                /* highest sequence number sent;
1517 	                                 * used to recognize retransmits
1518 	                                 */
1519 	tcp_seq snd_nxt;                /* send next */
1520 	tcp_seq snd_up;                 /* send urgent pointer */
1521 
1522 	tcp_seq snd_wl1;                /* window update seg seq number */
1523 	tcp_seq snd_wl2;                /* window update seg ack number */
1524 	tcp_seq iss;                    /* initial send sequence number */
1525 	tcp_seq irs;                    /* initial receive sequence number */
1526 
1527 	tcp_seq rcv_nxt;                /* receive next */
1528 	tcp_seq rcv_adv;                /* advertised window */
1529 	u_int32_t rcv_wnd;              /* receive window */
1530 	tcp_seq rcv_up;                 /* receive urgent pointer */
1531 
1532 	u_int32_t snd_wnd;              /* send window */
1533 	u_int32_t snd_cwnd;             /* congestion-controlled window */
1534 	u_int32_t snd_ssthresh;         /* snd_cwnd size threshold for
1535 	                                 * for slow start exponential to
1536 	                                 * linear switch
1537 	                                 */
1538 	u_int   t_maxopd;               /* mss plus options */
1539 
1540 	u_int32_t t_rcvtime;            /* time at which a packet was received */
1541 	u_int32_t t_starttime;          /* time connection was established */
1542 	int     t_rtttime;              /* round trip time */
1543 	tcp_seq t_rtseq;                /* sequence number being timed */
1544 
1545 	int     t_rxtcur;               /* current retransmit value (ticks) */
1546 	u_int   t_maxseg;               /* maximum segment size */
1547 	int     t_srtt;                 /* smoothed round-trip time */
1548 	int     t_rttvar;               /* variance in round-trip time */
1549 
1550 	int     t_rxtshift;             /* log(2) of rexmt exp. backoff */
1551 	u_int   t_rttmin;               /* minimum rtt allowed */
1552 	u_int32_t t_rttupdated;         /* number of times rtt sampled */
1553 	u_int32_t max_sndwnd;           /* largest window peer has offered */
1554 
1555 	int     t_softerror;            /* possible error not yet reported */
1556 /* out-of-band data */
1557 	char    t_oobflags;             /* have some */
1558 	char    t_iobc;                 /* input character */
1559 /* RFC 1323 variables */
1560 	u_char  snd_scale;              /* window scaling for send window */
1561 	u_char  rcv_scale;              /* window scaling for recv window */
1562 	u_char  request_r_scale;        /* pending window scaling */
1563 	u_char  requested_s_scale;
1564 	u_int32_t ts_recent;            /* timestamp echo data */
1565 
1566 	u_int32_t ts_recent_age;        /* when last updated */
1567 	tcp_seq last_ack_sent;
1568 /* RFC 1644 variables */
1569 	tcp_cc  cc_send;                /* send connection count */
1570 	tcp_cc  cc_recv;                /* receive connection count */
1571 	tcp_seq snd_recover;            /* for use in fast recovery */
1572 /* experimental */
1573 	u_int32_t snd_cwnd_prev;        /* cwnd prior to retransmit */
1574 	u_int32_t snd_ssthresh_prev;    /* ssthresh prior to retransmit */
1575 	u_int32_t t_badrxtwin;          /* window for retransmit recovery */
1576 
1577 	u_quad_t                xt_alignment_hack;
1578 };
1579 
1580 #endif /* XNU_TARGET_OS_OSX || KERNEL || !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) */
1581 
1582 #ifdef PRIVATE
1583 
1584 struct  xtcpcb_n {
1585 	u_int32_t               xt_len;
1586 	u_int32_t                       xt_kind;                /* XSO_TCPCB */
1587 
1588 	u_int64_t t_segq;
1589 	int     t_dupacks;              /* consecutive dup acks recd */
1590 
1591 	int t_timer[TCPT_NTIMERS_EXT];  /* tcp timers */
1592 
1593 	int     t_state;                /* state of this connection */
1594 	u_int   t_flags;
1595 
1596 	int     t_force;                /* 1 if forcing out a byte */
1597 
1598 	tcp_seq snd_una;                /* send unacknowledged */
1599 	tcp_seq snd_max;                /* highest sequence number sent;
1600 	                                 * used to recognize retransmits
1601 	                                 */
1602 	tcp_seq snd_nxt;                /* send next */
1603 	tcp_seq snd_up;                 /* send urgent pointer */
1604 
1605 	tcp_seq snd_wl1;                /* window update seg seq number */
1606 	tcp_seq snd_wl2;                /* window update seg ack number */
1607 	tcp_seq iss;                    /* initial send sequence number */
1608 	tcp_seq irs;                    /* initial receive sequence number */
1609 
1610 	tcp_seq rcv_nxt;                /* receive next */
1611 	tcp_seq rcv_adv;                /* advertised window */
1612 	u_int32_t rcv_wnd;              /* receive window */
1613 	tcp_seq rcv_up;                 /* receive urgent pointer */
1614 
1615 	u_int32_t snd_wnd;              /* send window */
1616 	u_int32_t snd_cwnd;             /* congestion-controlled window */
1617 	u_int32_t snd_ssthresh;         /* snd_cwnd size threshold for
1618 	                                 * for slow start exponential to
1619 	                                 * linear switch
1620 	                                 */
1621 	u_int   t_maxopd;               /* mss plus options */
1622 
1623 	u_int32_t t_rcvtime;            /* time at which a packet was received */
1624 	u_int32_t t_starttime;          /* time connection was established */
1625 	int     t_rtttime;              /* round trip time */
1626 	tcp_seq t_rtseq;                /* sequence number being timed */
1627 
1628 	int     t_rxtcur;               /* current retransmit value (ticks) */
1629 	u_int   t_maxseg;               /* maximum segment size */
1630 	int     t_srtt;                 /* smoothed round-trip time */
1631 	int     t_rttvar;               /* variance in round-trip time */
1632 
1633 	int     t_rxtshift;             /* log(2) of rexmt exp. backoff */
1634 	u_int   t_rttmin;               /* minimum rtt allowed */
1635 	u_int32_t t_rttupdated;         /* number of times rtt sampled */
1636 	u_int32_t max_sndwnd;           /* largest window peer has offered */
1637 
1638 	int     t_softerror;            /* possible error not yet reported */
1639 	/* out-of-band data */
1640 	char    t_oobflags;             /* have some */
1641 	char    t_iobc;                 /* input character */
1642 	/* RFC 1323 variables */
1643 	u_char  snd_scale;              /* window scaling for send window */
1644 	u_char  rcv_scale;              /* window scaling for recv window */
1645 	u_char  request_r_scale;        /* pending window scaling */
1646 	u_char  requested_s_scale;
1647 	u_int32_t ts_recent;            /* timestamp echo data */
1648 
1649 	u_int32_t ts_recent_age;        /* when last updated */
1650 	tcp_seq last_ack_sent;
1651 	/* RFC 1644 variables */
1652 	tcp_cc  cc_send;                /* send connection count */
1653 	tcp_cc  cc_recv;                /* receive connection count */
1654 	tcp_seq snd_recover;            /* for use in fast recovery */
1655 	/* experimental */
1656 	u_int32_t snd_cwnd_prev;        /* cwnd prior to retransmit */
1657 	u_int32_t snd_ssthresh_prev;    /* ssthresh prior to retransmit */
1658 };
1659 
1660 /*
1661  * The rtt measured is in milliseconds as the timestamp granularity is
1662  * a millisecond. The smoothed round-trip time and estimated variance
1663  * are stored as fixed point numbers scaled by the values below.
1664  * For convenience, these scales are also used in smoothing the average
1665  * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed).
1666  * With these scales, srtt has 5 bits to the right of the binary point,
1667  * and thus an "ALPHA" of 0.875.  rttvar has 4 bits to the right of the
1668  * binary point, and is smoothed with an ALPHA of 0.75.
1669  */
1670 #define TCP_RTT_SCALE           32      /* multiplier for srtt; 3 bits frac. */
1671 #define TCP_RTT_SHIFT           5       /* shift for srtt; 5 bits frac. */
1672 #define TCP_RTTVAR_SCALE        16      /* multiplier for rttvar; 4 bits */
1673 #define TCP_RTTVAR_SHIFT        4       /* shift for rttvar; 4 bits */
1674 #define TCP_DELTA_SHIFT         2       /* see tcp_input.c */
1675 
1676 struct tcpprobereq {
1677 	u_int64_t       ifindex;                /* Optional interface index for TCP keep-alive probing */
1678 	u_int64_t       enable;                 /* Flag to enable or disable probing (1=on, 0=off)*/
1679 	u_int64_t       filter_flags;           /* Optional flags for filtering interfaces per ntstat.h (NSTAT_IFNET_IS_*) */
1680 	u_int32_t       reserved;               /* Expansion */
1681 	u_int32_t       reserved2;              /* Expansion */
1682 };
1683 
1684 #endif /* PRIVATE */
1685 
1686 #pragma pack()
1687 
1688 /*
1689  * Names for TCP sysctl objects
1690  */
1691 #define TCPCTL_DO_RFC1323       1       /* use RFC-1323 extensions */
1692 #define TCPCTL_DO_RFC1644       2       /* use RFC-1644 extensions */
1693 #define TCPCTL_MSSDFLT          3       /* MSS default */
1694 #define TCPCTL_STATS            4       /* statistics (read-only) */
1695 #define TCPCTL_RTTDFLT          5       /* default RTT estimate */
1696 #define TCPCTL_KEEPIDLE         6       /* keepalive idle timer */
1697 #define TCPCTL_KEEPINTVL        7       /* interval to send keepalives */
1698 #define TCPCTL_SENDSPACE        8       /* send buffer space */
1699 #define TCPCTL_RECVSPACE        9       /* receive buffer space */
1700 #define TCPCTL_KEEPINIT         10      /* timeout for establishing syn */
1701 #define TCPCTL_PCBLIST          11      /* list of all outstanding PCBs */
1702 #define TCPCTL_DELACKTIME       12      /* time before sending delayed ACK */
1703 #define TCPCTL_V6MSSDFLT        13      /* MSS default for IPv6 */
1704 #define TCPCTL_MAXID            14
1705 
1706 #ifdef BSD_KERNEL_PRIVATE
1707 #include <sys/bitstring.h>
1708 
1709 #define TCP_PKTLIST_CLEAR(tp) {                                         \
1710 	(tp)->t_pktlist_head = (tp)->t_pktlist_tail = NULL;             \
1711 	(tp)->t_lastchain = (tp)->t_pktlist_sentlen = 0;                \
1712 }
1713 
1714 extern int tcp_TCPTV_MIN;
1715 
1716 #ifdef SYSCTL_DECL
1717 SYSCTL_DECL(_net_inet_tcp);
1718 #endif /* SYSCTL_DECL */
1719 
1720 extern  struct inpcbhead tcb;           /* head of queue of active tcpcb's */
1721 extern  struct inpcbinfo tcbinfo;
1722 extern  struct tcpstat tcpstat; /* tcp statistics */
1723 extern  int tcp_mssdflt;        /* XXX */
1724 extern  int tcp_minmss;
1725 #define TCP_FASTOPEN_SERVER 0x01
1726 #define TCP_FASTOPEN_CLIENT 0x02
1727 
1728 extern int tcp_tfo_halfcnt;
1729 extern int tcp_tfo_backlog;
1730 extern int tcp_fastopen;
1731 extern int ss_fltsz_local;
1732 extern int target_qdelay;
1733 extern uint32_t tcp_now;               /* for RFC 1323 timestamps */
1734 extern struct timeval tcp_uptime;
1735 extern lck_spin_t tcp_uptime_lock;
1736 extern int tcp_delack_enabled;
1737 extern int maxseg_unacked;
1738 KALLOC_TYPE_DECLARE(tcp_reass_zone);
1739 KALLOC_TYPE_DECLARE(tcp_rxt_seg_zone);
1740 KALLOC_TYPE_DECLARE(tcp_seg_sent_zone);
1741 extern int tcp_ecn_outbound;
1742 extern int tcp_ecn_inbound;
1743 extern uint32_t tcp_do_autorcvbuf;
1744 extern uint32_t tcp_autorcvbuf_max;
1745 extern int tcp_recv_bg;
1746 extern int tcp_do_ack_compression;
1747 extern int tcp_randomize_timestamps;
1748 extern int tcp_rledbat;
1749 extern int tcp_use_min_curr_rtt;
1750 extern int tcp_do_timestamps;
1751 /*
1752  * Dummy value used for when there is no flow and we want to ensure that compression
1753  * can happen.
1754  */
1755 #define TCP_ACK_COMPRESSION_DUMMY 1
1756 
1757 extern int tcp_do_better_lr;
1758 extern int tcp_cubic_minor_fixes;
1759 extern int tcp_cubic_rfc_compliant;
1760 extern int tcp_flow_control_response;
1761 
1762 extern int tcp_rack;
1763 
1764 extern int tcp_reass_total_qlen;
1765 
1766 struct protosw;
1767 struct domain;
1768 
1769 struct tcp_respond_args {
1770 	unsigned int ifscope;
1771 	unsigned int nocell:1,
1772 	    noexpensive:1,
1773 	    awdl_unrestricted:1,
1774 	    intcoproc_allowed:1,
1775 	    keep_alive:1,
1776 	    noconstrained:1,
1777 	    management_allowed:1;
1778 };
1779 
1780 void     tcp_canceltimers(struct tcpcb *);
1781 struct tcpcb *
1782 tcp_close(struct tcpcb *);
1783 void     tcp_ctlinput(int, struct sockaddr *, void *, struct ifnet *);
1784 int      tcp_ctloutput(struct socket *, struct sockopt *);
1785 struct tcpcb *
1786 tcp_drop(struct tcpcb *, int);
1787 void     tcp_drain(void);
1788 void     tcp_getrt_rtt(struct tcpcb *tp, struct rtentry *rt);
1789 void     tcp_init(struct protosw *, struct domain *);
1790 void     tcp_input(struct mbuf *, int);
1791 void     tcp_mss(struct tcpcb *, int, unsigned int);
1792 uint32_t tcp_ceil(double a);
1793 uint32_t tcp_round_to(uint32_t val, uint32_t round);
1794 uint32_t tcp_round_up(uint32_t val, uint32_t base);
1795 uint32_t ntoh24(u_char *p);
1796 uint32_t tcp_packets_this_ack(struct tcpcb *tp, uint32_t acked);
1797 int      tcp_mssopt(struct tcpcb *);
1798 void     tcp_drop_syn_sent(struct inpcb *, int);
1799 uint32_t tcp_get_effective_mtu(struct rtentry *, uint32_t);
1800 void     tcp_mtudisc(struct inpcb *, int);
1801 struct tcpcb *
1802 tcp_newtcpcb(struct inpcb *);
1803 int      tcp_output(struct tcpcb *);
1804 void     tcp_respond(struct tcpcb *, void *, struct tcphdr *, struct mbuf *,
1805     tcp_seq, tcp_seq, uint8_t, struct tcp_respond_args *);
1806 struct rtentry *
1807 tcp_rtlookup(struct inpcb *, unsigned int);
1808 void     tcp_setpersist(struct tcpcb *);
1809 void     tcp_gc(struct inpcbinfo *);
1810 void     tcp_itimer(struct inpcbinfo *ipi);
1811 void     tcp_check_timer_state(struct tcpcb *tp);
1812 void     tcp_run_timerlist(void *arg1, void *arg2);
1813 void     tcp_sched_timers(struct tcpcb *tp);
1814 
1815 struct tcptemp *tcp_maketemplate(struct tcpcb *, struct mbuf **);
1816 void     tcp_fillheaders(struct mbuf *, struct tcpcb *, void *, void *);
1817 struct tcpcb *tcp_timers(struct tcpcb *, int);
1818 void     tcp_trace(int, int, struct tcpcb *, void *, struct tcphdr *, int);
1819 
1820 void tcp_fill_info(struct tcpcb *, struct tcp_info *);
1821 void tcp_sack_doack(struct tcpcb *, struct tcpopt *, struct tcphdr *,
1822     uint32_t *, uint32_t *);
1823 extern boolean_t tcp_sack_process_dsack(struct tcpcb *, struct tcpopt *,
1824     struct tcphdr *, boolean_t *);
1825 int tcp_detect_bad_rexmt(struct tcpcb *, struct tcphdr *, struct tcpopt *,
1826     u_int32_t rxtime);
1827 void     tcp_update_sack_list(struct tcpcb *tp, tcp_seq rcv_laststart, tcp_seq rcv_lastend);
1828 void     tcp_clean_sackreport(struct tcpcb *tp);
1829 uint32_t tcp_sack_adjust(struct tcpcb *tp);
1830 struct sackhole *tcp_sack_output(struct tcpcb *tp, int *sack_bytes_rexmt);
1831 void     tcp_sack_partialack(struct tcpcb *, struct tcphdr *);
1832 void     tcp_free_sackholes(struct tcpcb *tp);
1833 int32_t  tcp_sbspace(struct tcpcb *tp);
1834 void     tcp_set_tso(struct tcpcb *tp, struct ifnet *ifp);
1835 void     tcp_set_ecn(struct tcpcb *tp, struct ifnet *ifp);
1836 uint8_t  tcp_get_ace(struct tcphdr *th);
1837 uint32_t tcp_flight_size(struct tcpcb *tp);
1838 void     tcp_reset_stretch_ack(struct tcpcb *tp);
1839 extern void tcp_get_ports_used(ifnet_t ifp, int, u_int32_t, bitstr_t *);
1840 uint32_t tcp_count_opportunistic(unsigned int ifindex, u_int32_t flags);
1841 uint32_t tcp_find_anypcb_byaddr(struct ifaddr *ifa);
1842 void tcp_set_max_rwinscale(struct tcpcb *tp, struct socket *so);
1843 struct bwmeas* tcp_bwmeas_alloc(struct tcpcb *tp);
1844 void tcp_bwmeas_free(struct tcpcb *tp);
1845 extern int32_t timer_diff(uint32_t t1, uint32_t toff1, uint32_t t2, uint32_t toff2);
1846 
1847 /* RACK related functions */
1848 void tcp_rack_transmit_seg(struct tcpcb *tp, struct tcp_seg_sent *seg, tcp_seq start, tcp_seq end, uint32_t xmit_ts, uint8_t flags);
1849 void tcp_rack_update_reordering_window(struct tcpcb *tp, tcp_seq th_ack);
1850 void tcp_rack_update_reordering_win_persist(struct tcpcb *tp);
1851 void tcp_rack_bad_rexmt_restore(struct tcpcb *tp);
1852 void tcp_rack_reset_segs_retransmitted(struct tcpcb *tp);
1853 void tcp_rack_update_segment_acked(struct tcpcb *tp, uint32_t tsecr, uint32_t xmit_ts, uint32_t end_seq, bool retransmitted);
1854 bool tcp_rack_detect_loss_and_arm_timer(struct tcpcb *tp, uint32_t dup_acks);
1855 void tcp_rack_reordering_timeout(struct tcpcb *tp, uint32_t dup_acks);
1856 struct tcp_seg_sent * tcp_rack_output(struct tcpcb *tp, uint32_t cwin, uint16_t *rack_seg_len);
1857 void tcp_rack_loss_on_rto(struct tcpcb *tp, bool in_rto);
1858 uint32_t tcp_rack_adjust(struct tcpcb *tp, uint32_t cwin);
1859 void tcp_rack_detect_reordering_dsack(struct tcpcb *tp, tcp_seq start, tcp_seq end);
1860 void tcp_rack_detect_reordering_acked(struct tcpcb *tp, struct tcp_seg_sent *seg);
1861 /* RACK segment related functions */
1862 uint32_t tcp_seg_len(struct tcp_seg_sent *seg);
1863 void tcp_seg_sent_insert(struct tcpcb *tp, struct tcp_seg_sent *seg, tcp_seq start, tcp_seq end, uint32_t xmit_ts, uint8_t flags);
1864 void tcp_segs_doack(struct tcpcb *tp, tcp_seq th_ack, struct tcpopt *to);
1865 void tcp_segs_dosack(struct tcpcb *tp, tcp_seq sblk_start, tcp_seq sblk_end, uint32_t tsecr, uint32_t *newbytes_sacked);
1866 void tcp_segs_clear_sacked(struct tcpcb *tp);
1867 void tcp_mark_seg_lost(struct tcpcb *tp, struct tcp_seg_sent *seg);
1868 void tcp_seg_delete(struct tcpcb *tp, struct tcp_seg_sent *seg);
1869 void tcp_segs_sent_clean(struct tcpcb *tp, bool free_segs);
1870 
1871 extern void tcp_set_background_cc(struct socket *);
1872 extern void tcp_set_foreground_cc(struct socket *);
1873 extern void tcp_set_recv_bg(struct socket *);
1874 extern void tcp_clear_recv_bg(struct socket *);
1875 extern boolean_t tcp_sack_byte_islost(struct tcpcb *tp);
1876 #define IS_TCP_RECV_BG(_so)     \
1877 	((_so)->so_flags1 & SOF1_TRAFFIC_MGT_TCP_RECVBG)
1878 
1879 #if TRAFFIC_MGT
1880 #define CLEAR_IAJ_STATE(_tp_) (_tp_)->iaj_rcv_ts = 0
1881 void     reset_acc_iaj(struct tcpcb *tp);
1882 #endif /* TRAFFIC_MGT */
1883 
1884 int      tcp_lock(struct socket *, int, void *);
1885 int      tcp_unlock(struct socket *, int, void *);
1886 void     calculate_tcp_clock(void);
1887 uint64_t microuptime_ns(void);
1888 uint64_t tcp_pacer_get_packet_tx_time(struct tcpcb *tp, uint16_t pkt_len);
1889 void tcp_set_mbuf_tx_time(struct mbuf *m, uint64_t tx_time);
1890 
1891 extern void tcp_keepalive_reset(struct tcpcb *);
1892 extern uint32_t get_base_rtt(struct tcpcb *tp);
1893 
1894 #ifdef _KERN_LOCKS_H_
1895 lck_mtx_t *      tcp_getlock(struct socket *, int);
1896 #else
1897 void *   tcp_getlock(struct socket *, int);
1898 #endif
1899 
1900 extern struct pr_usrreqs tcp_usrreqs;
1901 extern uint32_t tcp_sendspace;
1902 extern uint32_t tcp_recvspace;
1903 extern tcp_seq tcp_new_isn(struct tcpcb *tp);
1904 
1905 extern int tcp_input_checksum(int, struct mbuf *, struct tcphdr *, int, int);
1906 extern void tcp_getconninfo(struct socket *, struct conninfo_tcp *);
1907 extern void add_to_time_wait(struct tcpcb *, uint32_t delay);
1908 extern void add_to_time_wait_now(struct tcpcb *tp, uint32_t delay);
1909 extern void tcp_pmtud_revert_segment_size(struct tcpcb *tp);
1910 extern void tcp_rxtseg_insert(struct tcpcb *, tcp_seq, tcp_seq);
1911 extern struct tcp_rxt_seg *tcp_rxtseg_find(struct tcpcb *, tcp_seq, tcp_seq);
1912 extern void tcp_rxtseg_set_spurious(struct tcpcb *tp, tcp_seq start, tcp_seq end);
1913 extern void tcp_rxtseg_clean(struct tcpcb *);
1914 extern boolean_t tcp_rxtseg_detect_bad_rexmt(struct tcpcb *, tcp_seq);
1915 extern boolean_t tcp_rxtseg_dsack_for_tlp(struct tcpcb *);
1916 extern u_int32_t tcp_rxtseg_total_size(struct tcpcb *tp);
1917 extern void tcp_rexmt_save_state(struct tcpcb *tp);
1918 void tcp_enter_fast_recovery(struct tcpcb *tp);
1919 extern void tcp_interface_send_probe(u_int16_t if_index_available);
1920 extern void tcp_probe_connectivity(struct ifnet *ifp, u_int32_t enable);
1921 extern void tcp_get_connectivity_status(struct tcpcb *,
1922     struct tcp_conn_status *);
1923 
1924 extern void tcp_clear_keep_alive_offload(struct socket *so);
1925 extern void tcp_fill_keepalive_offload_frames(struct ifnet *,
1926     struct ifnet_keepalive_offload_frame *, u_int32_t, size_t, u_int32_t *);
1927 extern int tcp_notify_kao_timeout(ifnet_t ifp,
1928     struct ifnet_keepalive_offload_frame *frame);
1929 
1930 extern void tcp_disable_tfo(struct tcpcb *tp);
1931 extern void tcp_tfo_gen_cookie(struct inpcb *inp, u_char *out, size_t blk_size);
1932 #define TCP_FASTOPEN_KEYLEN 16
1933 extern int tcp_freeq(struct tcpcb *tp);
1934 extern errno_t tcp_notify_ack_id_valid(struct tcpcb *, struct socket *, u_int32_t);
1935 extern errno_t tcp_add_notify_ack_marker(struct tcpcb *, u_int32_t);
1936 extern void tcp_notify_ack_free(struct tcpcb *);
1937 extern void tcp_notify_acknowledgement(struct tcpcb *, struct socket *);
1938 extern void tcp_get_notify_ack_count(struct tcpcb *,
1939     struct tcp_notify_ack_complete *);
1940 extern void tcp_get_notify_ack_ids(struct tcpcb *tp,
1941     struct tcp_notify_ack_complete *);
1942 extern void tcp_update_mss_locked(struct socket *, struct ifnet *);
1943 
1944 extern int get_tcp_inp_list(struct inpcb * __single * __counted_by(n), size_t n, inp_gen_t);
1945 extern bool tcp_notify_ack_active(struct socket *so);
1946 extern void tcp_set_finwait_timeout(struct tcpcb *);
1947 
1948 #if MPTCP
1949 extern uint16_t mptcp_output_csum(struct mbuf *m, uint64_t dss_val,
1950     uint32_t sseq, uint16_t dlen);
1951 extern int mptcp_adj_mss(struct tcpcb *, boolean_t);
1952 extern void mptcp_insert_rmap(struct tcpcb *tp, struct mbuf *m, struct tcphdr *th);
1953 extern int dump_mptcp_reass_qlen(char *, int);
1954 #endif
1955 
1956 extern int dump_tcp_reass_qlen(char *, int);
1957 extern uint32_t tcp_reass_qlen_space(struct socket *);
1958 
1959 __private_extern__ void tcp_update_stats_per_flow(
1960 	struct ifnet_stats_per_flow *, struct ifnet *);
1961 
1962 #define TCP_ACK_STRATEGY_LEGACY 0
1963 #define TCP_ACK_STRATEGY_MODERN 1
1964 
1965 extern int tcp_ack_strategy;
1966 
1967 #if SKYWALK
1968 void tcp_add_fsw_flow(struct tcpcb *, struct ifnet *);
1969 void tcp_del_fsw_flow(struct tcpcb *);
1970 #else /* !SKYWALK */
1971 #define tcp_add_fsw_flow(...)
1972 #define tcp_del_fsw_flow(...)
1973 #endif /* !SKYWALK */
1974 
1975 #endif /* BSD_KERNEL_PRIVATE */
1976 
1977 #endif /* _NETINET_TCP_VAR_H_ */
1978