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