]> git.saurik.com Git - apple/xnu.git/blame - bsd/netinet/tcp_var.h
xnu-2782.1.97.tar.gz
[apple/xnu.git] / bsd / netinet / tcp_var.h
CommitLineData
1c79356b 1/*
fe8ab488 2 * Copyright (c) 2000-2014 Apple Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
8f6c56a5 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
29 * Copyright (c) 1982, 1986, 1993, 1994, 1995
30 * The Regents of the University of California. All rights reserved.
31 *
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
34 * are met:
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE.
59 *
60 * @(#)tcp_var.h 8.4 (Berkeley) 5/24/95
9bccf70c 61 * $FreeBSD: src/sys/netinet/tcp_var.h,v 1.56.2.8 2001/08/22 00:59:13 silby Exp $
1c79356b
A
62 */
63
64#ifndef _NETINET_TCP_VAR_H_
65#define _NETINET_TCP_VAR_H_
9bccf70c 66#include <sys/appleapiopts.h>
91447636
A
67#include <sys/queue.h>
68#include <netinet/in_pcb.h>
9bccf70c 69#include <netinet/tcp_timer.h>
91447636 70
2d21ac55
A
71#if defined(__LP64__)
72#define _TCPCB_PTR(x) u_int32_t
73#define _TCPCB_LIST_HEAD(name, type) \
74struct name { \
75 u_int32_t lh_first; \
76};
77#else
78#define _TCPCB_PTR(x) x
79#define _TCPCB_LIST_HEAD(name, type) LIST_HEAD(name, type)
80#endif
81
fe8ab488 82#ifdef KERNEL_PRIVATE
6d2010ae 83
fe8ab488 84#define TCP_RETRANSHZ 1000 /* granularity of TCP timestamps, 1ms */
6d2010ae 85/* Minimum time quantum within which the timers are coalesced */
fe8ab488
A
86#define TCP_TIMER_10MS_QUANTUM (TCP_RETRANSHZ/100) /* every 10ms */
87#define TCP_TIMER_100MS_QUANTUM (TCP_RETRANSHZ/10) /* every 100ms */
88#define TCP_TIMER_500MS_QUANTUM (TCP_RETRANSHZ/2) /* every 500ms */
6d2010ae
A
89
90#define TCP_RETRANSHZ_TO_USEC 1000
9bccf70c 91
2d21ac55 92#define N_TIME_WAIT_SLOTS 128 /* must be power of 2 */
1c79356b 93
6d2010ae
A
94/* Base RTT is stored for N_MIN_RTT_HISTORY slots. This is used to
95 * estimate expected minimum RTT for delay based congestion control
96 * algorithms.
97 */
98#define N_RTT_BASE 5
99
100/* Always allow at least 4 packets worth of recv window when adjusting
101 * recv window using inter-packet arrival jitter.
102 */
103#define MIN_IAJ_WIN 4
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
39236c6e
A
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
1c79356b 150/*
9bccf70c 151 * Kernel variables for tcp.
1c79356b 152 */
9bccf70c
A
153
154/* TCP segment queue entry */
155struct tseg_qent {
156 LIST_ENTRY(tseg_qent) tqe_q;
157 int tqe_len; /* TCP segment data length */
158 struct tcphdr *tqe_th; /* a pointer to tcp header */
159 struct mbuf *tqe_m; /* mbuf contains packet */
1c79356b 160};
9bccf70c 161LIST_HEAD(tsegqe_head, tseg_qent);
9bccf70c 162
8ad349bb
A
163struct sackblk {
164 tcp_seq start; /* start seq no. of sack block */
165 tcp_seq end; /* end seq no. */
166};
167
168struct sackhole {
169 tcp_seq start; /* start seq no. of hole */
170 tcp_seq end; /* end seq no. */
171 tcp_seq rxmit; /* next seq. no in hole to be retransmitted */
fe8ab488 172 u_int32_t rxmit_start; /* timestamp of first retransmission */
8ad349bb
A
173 TAILQ_ENTRY(sackhole) scblink; /* scoreboard linkage */
174};
175
176struct sackhint {
177 struct sackhole *nexthole;
178 int sack_bytes_rexmit;
179};
180
9bccf70c
A
181struct tcptemp {
182 u_char tt_ipgen[40]; /* the size must be of max ip header, now IPv6 */
183 struct tcphdr tt_t;
184};
185
316670eb
A
186struct bwmeas {
187 tcp_seq bw_start; /* start of bw measurement */
188 uint32_t bw_ts; /* timestamp when bw measurement started */
189 uint32_t bw_size; /* burst size in bytes for this bw measurement */
190 uint32_t bw_minsizepkts; /* Min burst size as segments */
191 uint32_t bw_maxsizepkts; /* Max burst size as segments */
192 uint32_t bw_minsize; /* Min size in bytes */
193 uint32_t bw_maxsize; /* Max size in bytes */
194 uint32_t bw_sndbw; /* Measured send bw */
195};
196
39236c6e
A
197/* MPTCP Data sequence map entry */
198struct mpt_dsn_map {
199 uint64_t mpt_dsn; /* data seq num recvd */
200 uint32_t mpt_sseq; /* relative subflow # */
201 uint16_t mpt_len; /* length of mapping */
202 uint16_t mpt_csum; /* checksum value if on */
203};
1c79356b
A
204#define tcp6cb tcpcb /* for KAME src sync over BSD*'s */
205
fe8ab488
A
206struct tcp_ccstate {
207 union {
208 struct tcp_cubic_state {
209 u_int32_t tc_last_max; /* cwnd at last loss */
210 u_int32_t tc_epoch_start; /* TS of last loss */
211 u_int32_t tc_origin_point; /* window at the start of an epoch */
212 u_int32_t tc_tcp_win; /* computed tcp win */
213 u_int32_t tc_tcp_bytes_acked; /* bytes acked */
214 u_int32_t tc_target_win; /* cubic target win */
215 u_int32_t tc_avg_lastmax; /* Average of last max */
216 u_int32_t tc_mean_deviation; /* Mean absolute deviation */
217 float tc_epoch_period; /* K parameter */
218 } _cubic_state_;
219#define cub_last_max __u__._cubic_state_.tc_last_max
220#define cub_epoch_start __u__._cubic_state_.tc_epoch_start
221#define cub_origin_point __u__._cubic_state_.tc_origin_point
222#define cub_tcp_win __u__._cubic_state_.tc_tcp_win
223#define cub_tcp_bytes_acked __u__._cubic_state_.tc_tcp_bytes_acked
224#define cub_epoch_period __u__._cubic_state_.tc_epoch_period
225#define cub_target_win __u__._cubic_state_.tc_target_win
226#define cub_avg_lastmax __u__._cubic_state_.tc_avg_lastmax
227#define cub_mean_dev __u__._cubic_state_.tc_mean_deviation
228 } __u__;
229};
230
1c79356b
A
231/*
232 * Tcp control block, one per tcp; fields:
233 * Organized for 16 byte cacheline efficiency.
234 */
235struct tcpcb {
9bccf70c 236 struct tsegqe_head t_segq;
1c79356b 237 int t_dupacks; /* consecutive dup acks recd */
6d2010ae
A
238 uint32_t t_timer[TCPT_NTIMERS]; /* tcp timers */
239 struct tcptimerentry tentry; /* entry in timer list */
1c79356b
A
240
241 struct inpcb *t_inpcb; /* back pointer to internet pcb */
242 int t_state; /* state of this connection */
39236c6e 243 uint32_t t_flags;
1c79356b
A
244#define TF_ACKNOW 0x00001 /* ack peer immediately */
245#define TF_DELACK 0x00002 /* ack, but try to delay it */
246#define TF_NODELAY 0x00004 /* don't delay packets to coalesce */
247#define TF_NOOPT 0x00008 /* don't use tcp options */
248#define TF_SENTFIN 0x00010 /* have sent FIN */
249#define TF_REQ_SCALE 0x00020 /* have/will request window scaling */
250#define TF_RCVD_SCALE 0x00040 /* other side has requested scaling */
251#define TF_REQ_TSTMP 0x00080 /* have/will request timestamps */
252#define TF_RCVD_TSTMP 0x00100 /* a timestamp was received in SYN */
253#define TF_SACK_PERMIT 0x00200 /* other side said I could SACK */
254#define TF_NEEDSYN 0x00400 /* send SYN (implicit state) */
255#define TF_NEEDFIN 0x00800 /* send FIN (implicit state) */
256#define TF_NOPUSH 0x01000 /* don't push */
257#define TF_REQ_CC 0x02000 /* have/will request CC */
258#define TF_RCVD_CC 0x04000 /* a CC was received in SYN */
259#define TF_SENDCCNEW 0x08000 /* send CCnew instead of CC in SYN */
260#define TF_MORETOCOME 0x10000 /* More data to be appended to sock */
6d2010ae 261#define TF_LOCAL 0x20000 /* connection to a host on local link */
9bccf70c 262#define TF_RXWIN0SENT 0x40000 /* sent a receiver win 0 in response */
d12e1678 263#define TF_SLOWLINK 0x80000 /* route is a on a modem speed link */
2d21ac55 264#define TF_LASTIDLE 0x100000 /* connection was previously idle */
8ad349bb
A
265#define TF_FASTRECOVERY 0x200000 /* in NewReno Fast Recovery */
266#define TF_WASFRECOVERY 0x400000 /* was in NewReno Fast Recovery */
267#define TF_SIGNATURE 0x800000 /* require MD5 digests (RFC2385) */
268#define TF_MAXSEGSNT 0x1000000 /* last segment sent was a full segment */
fe8ab488 269#define TF_ENABLE_ECN 0x2000000 /* Enable ECN */
2d21ac55
A
270#define TF_PMTUD 0x4000000 /* Perform Path MTU Discovery for this connection */
271#define TF_CLOSING 0x8000000 /* pending tcp close */
b0d623f7
A
272#define TF_TSO 0x10000000 /* TCP Segment Offloading is enable on this connection */
273#define TF_BLACKHOLE 0x20000000 /* Path MTU Discovery Black Hole detection */
6d2010ae
A
274#define TF_TIMER_ONLIST 0x40000000 /* pcb is on tcp_timer_list */
275#define TF_STRETCHACK 0x80000000 /* receiver is going to delay acks */
8ad349bb 276
1c79356b
A
277 tcp_seq snd_una; /* send unacknowledged */
278 tcp_seq snd_max; /* highest sequence number sent;
279 * used to recognize retransmits
280 */
281 tcp_seq snd_nxt; /* send next */
282 tcp_seq snd_up; /* send urgent pointer */
283
284 tcp_seq snd_wl1; /* window update seg seq number */
285 tcp_seq snd_wl2; /* window update seg ack number */
286 tcp_seq iss; /* initial send sequence number */
287 tcp_seq irs; /* initial receive sequence number */
288
289 tcp_seq rcv_nxt; /* receive next */
290 tcp_seq rcv_adv; /* advertised window */
b0d623f7 291 u_int32_t rcv_wnd; /* receive window */
1c79356b
A
292 tcp_seq rcv_up; /* receive urgent pointer */
293
b0d623f7
A
294 u_int32_t snd_wnd; /* send window */
295 u_int32_t snd_cwnd; /* congestion-controlled window */
b0d623f7 296 u_int32_t snd_ssthresh; /* snd_cwnd size threshold for
1c79356b
A
297 * for slow start exponential to
298 * linear switch
299 */
2d21ac55
A
300 tcp_seq snd_recover; /* for use in NewReno Fast Recovery */
301
1c79356b
A
302 u_int t_maxopd; /* mss plus options */
303
6d2010ae
A
304 u_int32_t t_rcvtime; /* time at which a packet was received */
305 u_int32_t t_starttime; /* time connection was established */
306 int t_rtttime; /* tcp clock when rtt calculation was started */
1c79356b
A
307 tcp_seq t_rtseq; /* sequence number being timed */
308
316670eb
A
309 u_int32_t rfbuf_ts; /* recv buffer autoscaling timestamp */
310 u_int32_t rfbuf_cnt; /* recv buffer autoscaling byte count */
2d21ac55 311
9bccf70c 312 int t_rxtcur; /* current retransmit value (ticks) */
1c79356b
A
313 u_int t_maxseg; /* maximum segment size */
314 int t_srtt; /* smoothed round-trip time */
315 int t_rttvar; /* variance in round-trip time */
316
fe8ab488
A
317 u_int16_t t_reassqlen; /* length of reassembly queue */
318 u_int16_t t_rxtshift; /* log(2) of rexmt exp. backoff */
1c79356b 319 u_int t_rttmin; /* minimum rtt allowed */
2d21ac55 320 u_int t_rttbest; /* best rtt we've seen */
6d2010ae 321 u_int t_rttcur; /* most recent value of rtt */
b0d623f7 322 u_int32_t t_rttupdated; /* number of times rtt sampled */
39236c6e
A
323 u_int32_t t_rxt_conndroptime; /* retxmt conn gets dropped after this time, when set */
324 u_int32_t t_rxtstart; /* time at which retransmission started */
b0d623f7 325 u_int32_t max_sndwnd; /* largest window peer has offered */
1c79356b
A
326
327 int t_softerror; /* possible error not yet reported */
328/* out-of-band data */
329 char t_oobflags; /* have some */
330 char t_iobc; /* input character */
331#define TCPOOB_HAVEDATA 0x01
332#define TCPOOB_HADDATA 0x02
333/* RFC 1323 variables */
fe8ab488 334 u_int8_t snd_scale; /* window scaling for send window */
39236c6e
A
335 u_int8_t rcv_scale; /* window scaling for recv window */
336 u_int8_t request_r_scale; /* pending window scaling */
337 u_int8_t requested_s_scale;
338 u_int8_t tcp_cc_index; /* index of congestion control algorithm */
339 u_int8_t t_adaptive_rtimo; /* Read timeout used as a multiple of RTT */
340 u_int8_t t_adaptive_wtimo; /* Write timeout used as a multiple of RTT */
fe8ab488
A
341 u_int8_t t_stretchack_delayed; /* stretch ack delayed */
342
343/* State for limiting early retransmits when SACK is not enabled */
344 u_int16_t t_early_rexmt_count; /* count of early rexmts */
345 u_int32_t t_early_rexmt_win; /* window for limiting early rexmts */
346
b0d623f7 347 u_int32_t ts_recent; /* timestamp echo data */
1c79356b 348
b0d623f7 349 u_int32_t ts_recent_age; /* when last updated */
1c79356b
A
350 tcp_seq last_ack_sent;
351/* RFC 1644 variables */
352 tcp_cc cc_send; /* send connection count */
353 tcp_cc cc_recv; /* receive connection count */
2d21ac55 354/* RFC 3465 variables */
b0d623f7 355 u_int32_t t_bytes_acked; /* ABC "bytes_acked" parameter */
55e303ae 356
91447636 357 int t_lastchain; /* amount of packets chained last time around */
39236c6e
A
358 u_int16_t t_unacksegs; /* received but unacked segments for delaying acks */
359 u_int8_t t_rexmtthresh; /* duplicate ack threshold for entering fast recovery */
360 u_int8_t t_rtimo_probes; /* number of adaptive rtimo probes sent */
6d2010ae
A
361 u_int32_t t_persist_timeout; /* ZWP persistence limit as set by PERSIST_TIMEOUT */
362 u_int32_t t_persist_stop; /* persistence limit deadline if triggered by ZWP */
316670eb 363 u_int32_t t_notsent_lowat; /* Low water for not sent data */
91447636 364
6d2010ae
A
365/* Receiver state for stretch-ack algorithm */
366 u_int32_t rcv_unackwin; /* to measure win for stretching acks */
367 u_int32_t rcv_by_unackwin; /* bytes seen during the last ack-stretching win */
fe8ab488 368 u_int32_t rcv_nostrack_ts; /* timestamp when stretch ack was disabled automatically */
6d2010ae
A
369 u_int16_t rcv_waitforss; /* wait for packets during slow-start */
370 u_int16_t ecn_flags;
371#define TE_SETUPSENT 0x01 /* Indicate we have sent ECN-SETUP SYN or SYN-ACK */
372#define TE_SETUPRECEIVED 0x02 /* Indicate we have received ECN-SETUP SYN or SYN-ACK */
373#define TE_SENDIPECT 0x04 /* Indicate we haven't sent or received non-ECN-setup SYN or SYN-ACK */
374#define TE_SENDCWR 0x08 /* Indicate that the next non-retransmit should have the TCP CWR flag set */
375#define TE_SENDECE 0x10 /* Indicate that the next packet should have the TCP ECE flag set */
fe8ab488 376#define TE_INRECOVERY 0x20 /* connection entered recovery after receiving ECE */
316670eb
A
377#define TE_ECN_ON (TE_SETUPSENT | TE_SETUPRECEIVED) /* Indicate ECN was successfully negotiated on a connection) */
378
39236c6e
A
379/* state for bad retransmit recovery */
380 u_int32_t snd_cwnd_prev; /* cwnd prior to retransmit */
fe8ab488 381 u_int32_t snd_ssthresh_prev; /* ssthresh prior to retransmit */
8ad349bb 382 tcp_seq snd_recover_prev; /* snd_recover prior to retransmit */
39236c6e
A
383 int t_srtt_prev; /* srtt prior to retransmit */
384 int t_rttvar_prev; /* rttvar prior to retransmit */
fe8ab488 385 u_int32_t t_badrexmt_time; /* bad rexmt detection time */
39236c6e 386
fe8ab488
A
387/* Packet reordering metric */
388 u_int16_t t_reorderwin; /* Reordering late time offset */
6d2010ae 389
8ad349bb 390/* SACK related state */
39236c6e 391 int16_t snd_numholes; /* number of holes seen by sender */
8ad349bb
A
392 TAILQ_HEAD(sackhole_head, sackhole) snd_holes;
393 /* SACK scoreboard (sorted) */
394 tcp_seq snd_fack; /* last seq number(+1) sack'd by rcv'r*/
395 int rcv_numsacks; /* # distinct sack blks present */
396 struct sackblk sackblks[MAX_SACK_BLKS]; /* seq nos. of sack blocks */
397 tcp_seq sack_newdata; /* New data xmitted in this recovery
398 episode starts at this seq number */
399 struct sackhint sackhint; /* SACK scoreboard hint */
2d21ac55 400
2d21ac55
A
401 u_int32_t t_pktlist_sentlen; /* total bytes in transmit chain */
402 struct mbuf *t_pktlist_head; /* First packet in transmit chain */
403 struct mbuf *t_pktlist_tail; /* Last packet in transmit chain */
b0d623f7 404
39236c6e
A
405 u_int32_t t_keepidle; /* keepalive idle timer (override global if > 0) */
406 u_int32_t t_keepinit; /* connection timeout, i.e. idle time
407 in SYN_SENT or SYN_RECV state */
408 u_int32_t t_keepintvl; /* interval between keepalives */
409 u_int32_t t_keepcnt; /* number of keepalives before close */
410
fe8ab488
A
411 u_int32_t tso_max_segment_size; /* TSO maximum segment unit for NIC */
412 u_int32_t t_pmtud_saved_maxopd; /* MSS saved before performing PMTU-D BlackHole detection */
413 u_int32_t t_pmtud_start_ts; /* Time of PMTUD blackhole detection */
6d2010ae
A
414
415 struct
416 {
417 u_int32_t rxduplicatebytes;
418 u_int32_t rxoutoforderbytes;
419 u_int32_t txretransmitbytes;
39236c6e
A
420 u_int8_t synrxtshift;
421 u_int8_t unused;
422 u_int16_t unused_pad_to_8;
6d2010ae
A
423 } t_stat;
424
425 /* Background congestion related state */
426 uint32_t rtt_hist[N_RTT_BASE]; /* history of minimum RTT */
427 uint32_t rtt_count; /* Number of RTT samples in recent base history */
428 uint32_t bg_ssthresh; /* Slow start threshold until delay increases */
429 uint32_t t_flagsext; /* Another field to accommodate more flags */
430#define TF_RXTFINDROP 0x1 /* Drop conn after retransmitting FIN 3 times */
431#define TF_RCVUNACK_WAITSS 0x2 /* set when the receiver should not stretch acks */
316670eb
A
432#define TF_BWMEAS_INPROGRESS 0x4 /* Indicate BW meas is happening */
433#define TF_MEASURESNDBW 0x8 /* Measure send bw on this connection */
434#define TF_LRO_OFFLOADED 0x10 /* Connection LRO offloaded */
39236c6e
A
435#define TF_SACK_ENABLE 0x20 /* SACK is enabled */
436#define TF_RECOMPUTE_RTT 0x40 /* recompute RTT after spurious retransmit */
437#define TF_DETECT_READSTALL 0x80 /* Used to detect a stall during read operation */
438#define TF_RECV_THROTTLE 0x100 /* Input throttling active */
439#define TF_NOSTRETCHACK 0x200 /* ack every other packet */
440#define TF_STREAMEOW 0x400 /* Last packet was small indicating end of write */
fe8ab488
A
441#define TF_NOTIMEWAIT 0x800 /* Avoid going into time-wait */
442#define TF_SENT_TLPROBE 0x1000 /* Sent data in PTO */
443#define TF_PKTS_REORDERED 0x2000 /* Detected reordering */
444#define TF_DELAY_RECOVERY 0x4000 /* delay fast recovery */
445#define TF_FORCE 0x8000 /* force 1 byte out */
446#define TF_DISABLE_STRETCHACK 0x10000 /* auto-disable stretch ack */
447#define TF_NOBLACKHOLE_DETECTION 0x20000 /* Disable PMTU blackhole detection */
448
6d2010ae
A
449#if TRAFFIC_MGT
450 /* Inter-arrival jitter related state */
451 uint32_t iaj_rcv_ts; /* tcp clock when the first packet was received */
452 uint16_t iaj_size; /* Size of packet for iaj measurement */
453 uint16_t iaj_small_pkt; /* Count of packets smaller than iaj_size */
454 uint16_t iaj_pktcnt; /* packet count, to avoid throttling initially */
455 uint16_t acc_iaj; /* Accumulated iaj */
456 tcp_seq iaj_rwintop; /* recent max advertised window */
457 uint32_t avg_iaj; /* Mean */
458 uint32_t std_dev_iaj; /* Standard deviation */
459#endif /* TRAFFIC_MGT */
316670eb
A
460 struct bwmeas *t_bwmeas; /* State for bandwidth measurement */
461 uint32_t t_lropktlen; /* Bytes in a LRO frame */
462 tcp_seq t_idleat; /* rcv_nxt at idle time */
39236c6e 463 TAILQ_ENTRY(tcpcb) t_twentry; /* link for time wait queue */
fe8ab488
A
464 struct tcp_ccstate *t_ccstate; /* congestion control related state */
465/* Tail loss probe related state */
466 tcp_seq t_tlphighrxt; /* snd_nxt after PTO */
467 u_int32_t t_tlpstart; /* timestamp at PTO */
39236c6e
A
468#if MPTCP
469 u_int32_t t_mpflags; /* flags for multipath TCP */
470
471#define TMPF_PREESTABLISHED 0x00000001 /* conn in pre-established state */
472#define TMPF_SENT_KEYS 0x00000002 /* indicates that keys were sent */
473#define TMPF_MPTCP_TRUE 0x00000004 /* negotiated MPTCP successfully */
474#define TMPF_MPTCP_RCVD_KEY 0x00000008 /* state for 3-way handshake */
475#define TMPF_SND_MPPRIO 0x00000010 /* send priority of subflow */
476#define TMPF_SND_REM_ADDR 0x00000020 /* initiate address removal */
477#define TMPF_UNUSED 0x00000040 /* address addition acked by peer */
478#define TMPF_JOINED_FLOW 0x00000080 /* Indicates additional flow */
479#define TMPF_BACKUP_PATH 0x00000100 /* Indicates backup path */
480#define TMPF_MPTCP_ACKNOW 0x00000200 /* Send Data ACK */
481#define TMPF_SEND_DSN 0x00000400 /* Send DSN mapping */
482#define TMPF_SEND_DFIN 0x00000800 /* Send Data FIN */
483#define TMPF_RECV_DFIN 0x00001000 /* Recv Data FIN */
484#define TMPF_SENT_JOIN 0x00002000 /* Sent Join */
485#define TMPF_RECVD_JOIN 0x00004000 /* Received Join */
486#define TMPF_RESET 0x00008000 /* Send RST */
487#define TMPF_TCP_FALLBACK 0x00010000 /* Fallback to TCP */
488#define TMPF_FASTCLOSE 0x00020000 /* Send Fastclose option */
489#define TMPF_EMBED_DSN 0x00040000 /* tp has DSN mapping */
490#define TMPF_MPTCP_READY 0x00080000 /* Can send DSS options on data */
491#define TMPF_INFIN_SENT 0x00100000 /* Sent infinite mapping */
492#define TMPF_SND_MPFAIL 0x00200000 /* Received mapping csum failure */
fe8ab488
A
493#define TMPF_FASTJOIN_SEND 0x00400000 /* Fast join early data send */
494#define TMPF_FASTJOINBY2_SEND 0x00800000 /* Fast join send after 3 WHS */
495
39236c6e
A
496 void *t_mptcb; /* pointer to MPTCP TCB */
497 tcp_seq t_mpuna; /* unacknowledged sequence */
498 struct mpt_dsn_map t_rcv_map; /* Receive mapping list */
499 u_int8_t t_local_aid; /* Addr Id for authentication */
500 u_int8_t t_rem_aid; /* Addr ID of another subflow */
501 u_int8_t t_mprxtshift; /* join retransmission */
502#endif /* MPTCP */
55e303ae 503};
55e303ae 504
8ad349bb 505#define IN_FASTRECOVERY(tp) (tp->t_flags & TF_FASTRECOVERY)
39236c6e 506#define SACK_ENABLED(tp) (tp->t_flagsext & TF_SACK_ENABLE)
316670eb
A
507
508/*
509 * If the connection is in a throttled state due to advisory feedback from
510 * the interface output queue, reset that state. We do this in favor
511 * of entering recovery because the data transfer during recovery
512 * should be just a trickle and it will help to improve performance.
513 * We also do not want to back off twice in the same RTT.
514 */
515#define ENTER_FASTRECOVERY(_tp_) do { \
516 (_tp_)->t_flags |= TF_FASTRECOVERY; \
517 if (INP_IS_FLOW_CONTROLLED((_tp_)->t_inpcb)) \
518 inp_reset_fc_state((_tp_)->t_inpcb); \
519} while(0)
520
39236c6e
A
521#define EXIT_FASTRECOVERY(_tp_) do { \
522 (_tp_)->t_flags &= ~TF_FASTRECOVERY; \
523 (_tp_)->t_dupacks = 0; \
524 (_tp_)->t_rexmtthresh = tcprexmtthresh; \
525 (_tp_)->t_bytes_acked = 0; \
fe8ab488
A
526 (_tp_)->ecn_flags &= ~TE_INRECOVERY; \
527 (_tp_)->t_timer[TCPT_PTO] = 0; \
39236c6e
A
528} while(0)
529
530/*
531 * When the number of duplicate acks received is less than
532 * the retransmit threshold, use Limited Transmit algorithm
533 */
534extern int tcprexmtthresh;
535#define ALLOW_LIMITED_TRANSMIT(_tp_) \
536 ((_tp_)->t_dupacks > 0 && \
fe8ab488
A
537 (_tp_)->t_dupacks < (_tp_)->t_rexmtthresh && \
538 ((_tp_)->t_flagsext & (TF_PKTS_REORDERED|TF_DELAY_RECOVERY)) \
539 != (TF_PKTS_REORDERED|TF_DELAY_RECOVERY))
39236c6e
A
540
541/*
542 * This condition is true is timestamp option is supported
543 * on a connection.
544 */
545#define TSTMP_SUPPORTED(_tp_) \
546 (((_tp_)->t_flags & (TF_REQ_TSTMP|TF_RCVD_TSTMP)) == \
547 (TF_REQ_TSTMP|TF_RCVD_TSTMP))
548
549/*
550 * Gives number of bytes acked by this ack
551 */
552#define BYTES_ACKED(_th_, _tp_) \
553 ((_th_)->th_ack - (_tp_)->snd_una)
8ad349bb 554
6d2010ae
A
555enum tcp_cc_event {
556 TCP_CC_CWND_INIT,
557 TCP_CC_INSEQ_ACK_RCVD,
558 TCP_CC_ACK_RCVD,
559 TCP_CC_ENTER_FASTRECOVERY,
560 TCP_CC_IN_FASTRECOVERY,
561 TCP_CC_EXIT_FASTRECOVERY,
562 TCP_CC_PARTIAL_ACK,
563 TCP_CC_IDLE_TIMEOUT,
564 TCP_CC_REXMT_TIMEOUT,
565 TCP_CC_ECN_RCVD,
566 TCP_CC_BAD_REXMT_RECOVERY,
567 TCP_CC_OUTPUT_ERROR,
316670eb
A
568 TCP_CC_CHANGE_ALGO,
569 TCP_CC_FLOW_CONTROL,
39236c6e
A
570 TCP_CC_SUSPEND,
571 TCP_CC_LIMITED_TRANSMIT,
fe8ab488
A
572 TCP_CC_EARLY_RETRANSMIT,
573 TCP_CC_TLP_RECOVERY,
574 TCP_CC_TLP_RECOVER_LASTPACKET,
575 TCP_CC_DELAY_FASTRECOVERY,
576 TCP_CC_TLP_IN_FASTRECOVERY
6d2010ae 577};
8ad349bb 578
91447636
A
579/*
580 * Structure to hold TCP options that are only used during segment
581 * processing (in tcp_input), but not held in the tcpcb.
582 * It's basically used to reduce the number of parameters
583 * to tcp_dooptions.
584 */
585struct tcpopt {
b0d623f7 586 u_int32_t to_flags; /* which options are present */
91447636 587#define TOF_TS 0x0001 /* timestamp */
8ad349bb
A
588#define TOF_MSS 0x0010
589#define TOF_SCALE 0x0020
590#define TOF_SIGNATURE 0x0040 /* signature option present */
591#define TOF_SIGLEN 0x0080 /* signature length valid (RFC2385) */
592#define TOF_SACK 0x0100 /* Peer sent SACK option */
39236c6e 593#define TOF_MPTCP 0x0200 /* MPTCP options to be dropped */
b0d623f7
A
594 u_int32_t to_tsval;
595 u_int32_t to_tsecr;
8ad349bb
A
596 u_int16_t to_mss;
597 u_int8_t to_requested_s_scale;
598 u_int8_t to_nsacks; /* number of SACK blocks */
599 u_char *to_sacks; /* pointer to the first SACK blocks */
91447636 600};
55e303ae 601
91447636
A
602/*
603 * The TAO cache entry which is stored in the protocol family specific
604 * portion of the route metrics.
605 */
606struct rmxp_tao {
607 tcp_cc tao_cc; /* latest CC in valid SYN */
608 tcp_cc tao_ccsent; /* latest CC sent to peer */
609 u_short tao_mssopt; /* peer's cached MSS */
610#ifdef notyet
611 u_short tao_flags; /* cache status flags */
612#define TAOF_DONT 0x0001 /* peer doesn't understand rfc1644 */
613#define TAOF_OK 0x0002 /* peer does understand rfc1644 */
614#define TAOF_UNDEF 0 /* we don't know yet */
615#endif /* notyet */
616};
617#define rmx_taop(r) ((struct rmxp_tao *)(r).rmx_filler)
618
619#define intotcpcb(ip) ((struct tcpcb *)(ip)->inp_ppcb)
620#define sototcpcb(so) (intotcpcb(sotoinpcb(so)))
55e303ae 621
91447636 622/*
6d2010ae
A
623 * The rtt measured is in milliseconds as the timestamp granularity is
624 * a millisecond. The smoothed round-trip time and estimated variance
91447636
A
625 * are stored as fixed point numbers scaled by the values below.
626 * For convenience, these scales are also used in smoothing the average
627 * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed).
6d2010ae
A
628 * With these scales, srtt has 5 bits to the right of the binary point,
629 * and thus an "ALPHA" of 0.875. rttvar has 4 bits to the right of the
91447636
A
630 * binary point, and is smoothed with an ALPHA of 0.75.
631 */
632#define TCP_RTT_SCALE 32 /* multiplier for srtt; 3 bits frac. */
6d2010ae
A
633#define TCP_RTT_SHIFT 5 /* shift for srtt; 5 bits frac. */
634#define TCP_RTTVAR_SCALE 16 /* multiplier for rttvar; 4 bits */
635#define TCP_RTTVAR_SHIFT 4 /* shift for rttvar; 4 bits */
91447636
A
636#define TCP_DELTA_SHIFT 2 /* see tcp_input.c */
637
638/*
639 * The initial retransmission should happen at rtt + 4 * rttvar.
640 * Because of the way we do the smoothing, srtt and rttvar
641 * will each average +1/2 tick of bias. When we compute
642 * the retransmit timer, we want 1/2 tick of rounding and
643 * 1 extra tick because of +-1/2 tick uncertainty in the
644 * firing of the timer. The bias will give us exactly the
645 * 1.5 tick we need. But, because the bias is
646 * statistical, we have to test that we don't drop below
647 * the minimum feasible timer (which is 2 ticks).
648 * This version of the macro adapted from a paper by Lawrence
649 * Brakmo and Larry Peterson which outlines a problem caused
650 * by insufficient precision in the original implementation,
651 * which results in inappropriately large RTO values for very
652 * fast networks.
653 */
654#define TCP_REXMTVAL(tp) \
655 max((tp)->t_rttmin, (((tp)->t_srtt >> (TCP_RTT_SHIFT - TCP_DELTA_SHIFT)) \
656 + (tp)->t_rttvar) >> TCP_DELTA_SHIFT)
55e303ae
A
657
658/*
659 * Jaguar compatible TCP control block, for xtcpcb
660 * Does not have the old fields
661 */
662struct otcpcb {
91447636
A
663#else
664struct tseg_qent;
2d21ac55 665_TCPCB_LIST_HEAD(tsegqe_head, tseg_qent);
91447636
A
666
667struct tcpcb {
668#endif /* KERNEL_PRIVATE */
b0d623f7
A
669#if defined(KERNEL_PRIVATE)
670 u_int32_t t_segq;
671#else
55e303ae 672 struct tsegqe_head t_segq;
b0d623f7 673#endif /* KERNEL_PRIVATE */
55e303ae 674 int t_dupacks; /* consecutive dup acks recd */
2d21ac55 675 u_int32_t unused; /* unused now: was t_template */
55e303ae 676
6d2010ae 677 int t_timer[TCPT_NTIMERS_EXT]; /* tcp timers */
55e303ae 678
2d21ac55 679 _TCPCB_PTR(struct inpcb *) t_inpcb; /* back pointer to internet pcb */
55e303ae
A
680 int t_state; /* state of this connection */
681 u_int t_flags;
682#define TF_ACKNOW 0x00001 /* ack peer immediately */
683#define TF_DELACK 0x00002 /* ack, but try to delay it */
684#define TF_NODELAY 0x00004 /* don't delay packets to coalesce */
685#define TF_NOOPT 0x00008 /* don't use tcp options */
686#define TF_SENTFIN 0x00010 /* have sent FIN */
687#define TF_REQ_SCALE 0x00020 /* have/will request window scaling */
688#define TF_RCVD_SCALE 0x00040 /* other side has requested scaling */
689#define TF_REQ_TSTMP 0x00080 /* have/will request timestamps */
690#define TF_RCVD_TSTMP 0x00100 /* a timestamp was received in SYN */
691#define TF_SACK_PERMIT 0x00200 /* other side said I could SACK */
692#define TF_NEEDSYN 0x00400 /* send SYN (implicit state) */
693#define TF_NEEDFIN 0x00800 /* send FIN (implicit state) */
694#define TF_NOPUSH 0x01000 /* don't push */
695#define TF_REQ_CC 0x02000 /* have/will request CC */
696#define TF_RCVD_CC 0x04000 /* a CC was received in SYN */
697#define TF_SENDCCNEW 0x08000 /* send CCnew instead of CC in SYN */
698#define TF_MORETOCOME 0x10000 /* More data to be appended to sock */
699#define TF_LQ_OVERFLOW 0x20000 /* listen queue overflow */
700#define TF_RXWIN0SENT 0x40000 /* sent a receiver win 0 in response */
701#define TF_SLOWLINK 0x80000 /* route is a on a modem speed link */
702
703 int t_force; /* 1 if forcing out a byte */
704
705 tcp_seq snd_una; /* send unacknowledged */
706 tcp_seq snd_max; /* highest sequence number sent;
707 * used to recognize retransmits
708 */
709 tcp_seq snd_nxt; /* send next */
710 tcp_seq snd_up; /* send urgent pointer */
711
712 tcp_seq snd_wl1; /* window update seg seq number */
713 tcp_seq snd_wl2; /* window update seg ack number */
714 tcp_seq iss; /* initial send sequence number */
715 tcp_seq irs; /* initial receive sequence number */
716
717 tcp_seq rcv_nxt; /* receive next */
718 tcp_seq rcv_adv; /* advertised window */
2d21ac55 719 u_int32_t rcv_wnd; /* receive window */
55e303ae
A
720 tcp_seq rcv_up; /* receive urgent pointer */
721
2d21ac55
A
722 u_int32_t snd_wnd; /* send window */
723 u_int32_t snd_cwnd; /* congestion-controlled window */
724 u_int32_t snd_ssthresh; /* snd_cwnd size threshold for
55e303ae
A
725 * for slow start exponential to
726 * linear switch
727 */
728 u_int t_maxopd; /* mss plus options */
729
6d2010ae 730 u_int32_t t_rcvtime; /* time at which a packet was received */
2d21ac55 731 u_int32_t t_starttime; /* time connection was established */
55e303ae
A
732 int t_rtttime; /* round trip time */
733 tcp_seq t_rtseq; /* sequence number being timed */
734
735 int t_rxtcur; /* current retransmit value (ticks) */
736 u_int t_maxseg; /* maximum segment size */
737 int t_srtt; /* smoothed round-trip time */
738 int t_rttvar; /* variance in round-trip time */
739
740 int t_rxtshift; /* log(2) of rexmt exp. backoff */
741 u_int t_rttmin; /* minimum rtt allowed */
2d21ac55
A
742 u_int32_t t_rttupdated; /* number of times rtt sampled */
743 u_int32_t max_sndwnd; /* largest window peer has offered */
55e303ae
A
744
745 int t_softerror; /* possible error not yet reported */
746/* out-of-band data */
747 char t_oobflags; /* have some */
748 char t_iobc; /* input character */
749#define TCPOOB_HAVEDATA 0x01
750#define TCPOOB_HADDATA 0x02
751/* RFC 1323 variables */
752 u_char snd_scale; /* window scaling for send window */
753 u_char rcv_scale; /* window scaling for recv window */
754 u_char request_r_scale; /* pending window scaling */
755 u_char requested_s_scale;
2d21ac55 756 u_int32_t ts_recent; /* timestamp echo data */
55e303ae 757
2d21ac55 758 u_int32_t ts_recent_age; /* when last updated */
55e303ae
A
759 tcp_seq last_ack_sent;
760/* RFC 1644 variables */
761 tcp_cc cc_send; /* send connection count */
762 tcp_cc cc_recv; /* receive connection count */
2d21ac55 763 tcp_seq snd_recover; /* for use in fast recovery */
55e303ae 764/* experimental */
2d21ac55
A
765 u_int32_t snd_cwnd_prev; /* cwnd prior to retransmit */
766 u_int32_t snd_ssthresh_prev; /* ssthresh prior to retransmit */
767 u_int32_t t_badrxtwin; /* window for retransmit recovery */
1c79356b
A
768};
769
b0d623f7 770
1c79356b
A
771/*
772 * TCP statistics.
773 * Many of these should be kept per connection,
774 * but that's inconvenient at the moment.
775 */
776struct tcpstat {
2d21ac55
A
777 u_int32_t tcps_connattempt; /* connections initiated */
778 u_int32_t tcps_accepts; /* connections accepted */
779 u_int32_t tcps_connects; /* connections established */
780 u_int32_t tcps_drops; /* connections dropped */
781 u_int32_t tcps_conndrops; /* embryonic connections dropped */
782 u_int32_t tcps_closed; /* conn. closed (includes drops) */
783 u_int32_t tcps_segstimed; /* segs where we tried to get rtt */
784 u_int32_t tcps_rttupdated; /* times we succeeded */
785 u_int32_t tcps_delack; /* delayed acks sent */
786 u_int32_t tcps_timeoutdrop; /* conn. dropped in rxmt timeout */
787 u_int32_t tcps_rexmttimeo; /* retransmit timeouts */
788 u_int32_t tcps_persisttimeo; /* persist timeouts */
789 u_int32_t tcps_keeptimeo; /* keepalive timeouts */
790 u_int32_t tcps_keepprobe; /* keepalive probes sent */
791 u_int32_t tcps_keepdrops; /* connections dropped in keepalive */
792
793 u_int32_t tcps_sndtotal; /* total packets sent */
794 u_int32_t tcps_sndpack; /* data packets sent */
795 u_int32_t tcps_sndbyte; /* data bytes sent */
796 u_int32_t tcps_sndrexmitpack; /* data packets retransmitted */
797 u_int32_t tcps_sndrexmitbyte; /* data bytes retransmitted */
798 u_int32_t tcps_sndacks; /* ack-only packets sent */
799 u_int32_t tcps_sndprobe; /* window probes sent */
800 u_int32_t tcps_sndurg; /* packets sent with URG only */
801 u_int32_t tcps_sndwinup; /* window update-only packets sent */
802 u_int32_t tcps_sndctrl; /* control (SYN|FIN|RST) packets sent */
803
804 u_int32_t tcps_rcvtotal; /* total packets received */
805 u_int32_t tcps_rcvpack; /* packets received in sequence */
806 u_int32_t tcps_rcvbyte; /* bytes received in sequence */
807 u_int32_t tcps_rcvbadsum; /* packets received with ccksum errs */
808 u_int32_t tcps_rcvbadoff; /* packets received with bad offset */
809 u_int32_t tcps_rcvmemdrop; /* packets dropped for lack of memory */
810 u_int32_t tcps_rcvshort; /* packets received too short */
811 u_int32_t tcps_rcvduppack; /* duplicate-only packets received */
812 u_int32_t tcps_rcvdupbyte; /* duplicate-only bytes received */
813 u_int32_t tcps_rcvpartduppack; /* packets with some duplicate data */
814 u_int32_t tcps_rcvpartdupbyte; /* dup. bytes in part-dup. packets */
815 u_int32_t tcps_rcvoopack; /* out-of-order packets received */
816 u_int32_t tcps_rcvoobyte; /* out-of-order bytes received */
817 u_int32_t tcps_rcvpackafterwin; /* packets with data after window */
818 u_int32_t tcps_rcvbyteafterwin; /* bytes rcvd after window */
819 u_int32_t tcps_rcvafterclose; /* packets rcvd after "close" */
820 u_int32_t tcps_rcvwinprobe; /* rcvd window probe packets */
821 u_int32_t tcps_rcvdupack; /* rcvd duplicate acks */
822 u_int32_t tcps_rcvacktoomuch; /* rcvd acks for unsent data */
823 u_int32_t tcps_rcvackpack; /* rcvd ack packets */
824 u_int32_t tcps_rcvackbyte; /* bytes acked by rcvd acks */
825 u_int32_t tcps_rcvwinupd; /* rcvd window update packets */
826 u_int32_t tcps_pawsdrop; /* segments dropped due to PAWS */
827 u_int32_t tcps_predack; /* times hdr predict ok for acks */
828 u_int32_t tcps_preddat; /* times hdr predict ok for data pkts */
829 u_int32_t tcps_pcbcachemiss;
830 u_int32_t tcps_cachedrtt; /* times cached RTT in route updated */
831 u_int32_t tcps_cachedrttvar; /* times cached rttvar updated */
832 u_int32_t tcps_cachedssthresh; /* times cached ssthresh updated */
833 u_int32_t tcps_usedrtt; /* times RTT initialized from route */
834 u_int32_t tcps_usedrttvar; /* times RTTVAR initialized from rt */
835 u_int32_t tcps_usedssthresh; /* times ssthresh initialized from rt*/
836 u_int32_t tcps_persistdrop; /* timeout in persist state */
837 u_int32_t tcps_badsyn; /* bogus SYN, e.g. premature ACK */
838 u_int32_t tcps_mturesent; /* resends due to MTU discovery */
839 u_int32_t tcps_listendrop; /* listen queue overflows */
840
841 /* new stats from FreeBSD 5.4 sync up */
842 u_int32_t tcps_minmssdrops; /* average minmss too low drops */
843 u_int32_t tcps_sndrexmitbad; /* unnecessary packet retransmissions */
844 u_int32_t tcps_badrst; /* ignored RSTs in the window */
845
846 u_int32_t tcps_sc_added; /* entry added to syncache */
847 u_int32_t tcps_sc_retransmitted; /* syncache entry was retransmitted */
848 u_int32_t tcps_sc_dupsyn; /* duplicate SYN packet */
849 u_int32_t tcps_sc_dropped; /* could not reply to packet */
850 u_int32_t tcps_sc_completed; /* successful extraction of entry */
851 u_int32_t tcps_sc_bucketoverflow; /* syncache per-bucket limit hit */
852 u_int32_t tcps_sc_cacheoverflow; /* syncache cache limit hit */
853 u_int32_t tcps_sc_reset; /* RST removed entry from syncache */
854 u_int32_t tcps_sc_stale; /* timed out or listen socket gone */
855 u_int32_t tcps_sc_aborted; /* syncache entry aborted */
856 u_int32_t tcps_sc_badack; /* removed due to bad ACK */
857 u_int32_t tcps_sc_unreach; /* ICMP unreachable received */
858 u_int32_t tcps_sc_zonefail; /* zalloc() failed */
859 u_int32_t tcps_sc_sendcookie; /* SYN cookie sent */
860 u_int32_t tcps_sc_recvcookie; /* SYN cookie received */
861
862 u_int32_t tcps_hc_added; /* entry added to hostcache */
863 u_int32_t tcps_hc_bucketoverflow; /* hostcache per bucket limit hit */
8ad349bb
A
864
865 /* SACK related stats */
2d21ac55 866 u_int32_t tcps_sack_recovery_episode; /* SACK recovery episodes */
316670eb
A
867 u_int32_t tcps_sack_rexmits; /* SACK rexmit segments */
868 u_int32_t tcps_sack_rexmit_bytes; /* SACK rexmit bytes */
869 u_int32_t tcps_sack_rcv_blocks; /* SACK blocks (options) received */
870 u_int32_t tcps_sack_send_blocks; /* SACK blocks (options) sent */
871 u_int32_t tcps_sack_sboverflow; /* SACK sendblock overflow */
2d21ac55 872
2d21ac55 873 u_int32_t tcps_bg_rcvtotal; /* total background packets received */
6d2010ae 874 u_int32_t tcps_rxtfindrop; /* drop conn after retransmitting FIN */
316670eb
A
875 u_int32_t tcps_fcholdpacket; /* packets withheld because of flow control */
876
877 /* LRO related stats */
878 u_int32_t tcps_coalesced_pack; /* number of coalesced packets */
879 u_int32_t tcps_flowtbl_full; /* times flow table was full */
880 u_int32_t tcps_flowtbl_collision; /* collisions in flow tbl */
881 u_int32_t tcps_lro_twopack; /* 2 packets coalesced */
882 u_int32_t tcps_lro_multpack; /* 3 or 4 pkts coalesced */
883 u_int32_t tcps_lro_largepack; /* 5 or more pkts coalesced */
39236c6e
A
884
885 u_int32_t tcps_limited_txt; /* Limited transmit used */
886 u_int32_t tcps_early_rexmt; /* Early retransmit used */
887 u_int32_t tcps_sack_ackadv; /* Cumulative ack advanced along with sack */
888
889 /* Checksum related stats */
890 u_int32_t tcps_rcv_swcsum; /* tcp swcksum (inbound), packets */
891 u_int32_t tcps_rcv_swcsum_bytes; /* tcp swcksum (inbound), bytes */
892 u_int32_t tcps_rcv6_swcsum; /* tcp6 swcksum (inbound), packets */
893 u_int32_t tcps_rcv6_swcsum_bytes; /* tcp6 swcksum (inbound), bytes */
894 u_int32_t tcps_snd_swcsum; /* tcp swcksum (outbound), packets */
895 u_int32_t tcps_snd_swcsum_bytes; /* tcp swcksum (outbound), bytes */
896 u_int32_t tcps_snd6_swcsum; /* tcp6 swcksum (outbound), packets */
897 u_int32_t tcps_snd6_swcsum_bytes; /* tcp6 swcksum (outbound), bytes */
898 u_int32_t tcps_msg_unopkts; /* unordered packet on TCP msg stream */
899 u_int32_t tcps_msg_unoappendfail; /* failed to append unordered pkt */
900 u_int32_t tcps_msg_sndwaithipri; /* send is waiting for high priority data */
901
902 /* MPTCP Related stats */
903 u_int32_t tcps_invalid_mpcap; /* Invalid MPTCP capable opts */
904 u_int32_t tcps_invalid_joins; /* Invalid MPTCP joins */
905 u_int32_t tcps_mpcap_fallback; /* TCP fallback in primary */
906 u_int32_t tcps_join_fallback; /* No MPTCP in secondary */
907 u_int32_t tcps_estab_fallback; /* DSS option dropped */
908 u_int32_t tcps_invalid_opt; /* Catchall error stat */
909 u_int32_t tcps_mp_outofwin; /* Packet lies outside the
910 shared recv window */
911 u_int32_t tcps_mp_reducedwin; /* Reduced subflow window */
912 u_int32_t tcps_mp_badcsum; /* Bad DSS csum */
913 u_int32_t tcps_mp_oodata; /* Out of order data */
914 u_int32_t tcps_mp_switches; /* number of subflow switch */
915 u_int32_t tcps_mp_rcvtotal; /* number of rcvd packets */
916 u_int32_t tcps_mp_rcvbytes; /* number of bytes received */
917 u_int32_t tcps_mp_sndpacks; /* number of data packs sent */
918 u_int32_t tcps_mp_sndbytes; /* number of bytes sent */
919 u_int32_t tcps_join_rxmts; /* join ack retransmits */
fe8ab488
A
920 u_int32_t tcps_tailloss_rto; /* RTO due to tail loss */
921 u_int32_t tcps_reordered_pkts; /* packets reorderd */
922 u_int32_t tcps_recovered_pkts; /* recovered after loss */
923 u_int32_t tcps_pto; /* probe timeout */
924 u_int32_t tcps_rto_after_pto; /* RTO after a probe */
925 u_int32_t tcps_tlp_recovery; /* TLP induced fast recovery */
926 u_int32_t tcps_tlp_recoverlastpkt; /* TLP recoverd last pkt */
927 u_int32_t tcps_ecn_setup; /* connection negotiated ECN */
928 u_int32_t tcps_sent_cwr; /* Sent CWR, ECE received */
929 u_int32_t tcps_sent_ece; /* Sent ECE notification */
930 u_int32_t tcps_detect_reordering; /* Detect pkt reordering */
931 u_int32_t tcps_delay_recovery; /* Delay fast recovery */
932 u_int32_t tcps_avoid_rxmt; /* Retransmission was avoided */
933 u_int32_t tcps_unnecessary_rxmt; /* Retransmission was not needed */
934 u_int32_t tcps_nostretchack; /* disabled stretch ack algorithm on a connection */
935 u_int32_t tcps_rescue_rxmt; /* SACK rescue retransmit */
936 u_int32_t tcps_pto_in_recovery; /* PTO during fast recovery */
937 u_int32_t tcps_pmtudbh_reverted; /* PMTU Blackhole detection, segement size reverted */
316670eb
A
938};
939
940struct tcpstat_local {
941 u_int64_t badformat;
942 u_int64_t unspecv6;
943 u_int64_t synfin;
944 u_int64_t badformatipsec;
945 u_int64_t noconnnolist;
946 u_int64_t noconnlist;
947 u_int64_t listbadsyn;
948 u_int64_t icmp6unreach;
949 u_int64_t deprecate6;
950 u_int64_t ooopacket;
951 u_int64_t rstinsynrcv;
952 u_int64_t dospacket;
953 u_int64_t cleanup;
954 u_int64_t synwindow;
1c79356b
A
955};
956
2d21ac55
A
957#pragma pack(4)
958
1c79356b
A
959/*
960 * TCB structure exported to user-land via sysctl(3).
961 * Evil hack: declare only if in_pcb.h and sys/socketvar.h have been
962 * included. Not all of our clients do.
963 */
b0d623f7
A
964
965struct xtcpcb {
966 u_int32_t xt_len;
91447636 967#ifdef KERNEL_PRIVATE
b0d623f7 968 struct inpcb_compat xt_inp;
91447636 969#else
b0d623f7 970 struct inpcb xt_inp;
91447636
A
971#endif
972#ifdef KERNEL_PRIVATE
b0d623f7 973 struct otcpcb xt_tp;
55e303ae 974#else
b0d623f7 975 struct tcpcb xt_tp;
55e303ae 976#endif
b0d623f7
A
977 struct xsocket xt_socket;
978 u_quad_t xt_alignment_hack;
979};
980
b0d623f7
A
981
982struct xtcpcb64 {
983 u_int32_t xt_len;
984 struct xinpcb64 xt_inpcb;
985
986 u_int64_t t_segq;
987 int t_dupacks; /* consecutive dup acks recd */
988
6d2010ae 989 int t_timer[TCPT_NTIMERS_EXT]; /* tcp timers */
b0d623f7
A
990
991 int t_state; /* state of this connection */
992 u_int t_flags;
993
994 int t_force; /* 1 if forcing out a byte */
995
996 tcp_seq snd_una; /* send unacknowledged */
997 tcp_seq snd_max; /* highest sequence number sent;
998 * used to recognize retransmits
999 */
1000 tcp_seq snd_nxt; /* send next */
1001 tcp_seq snd_up; /* send urgent pointer */
1002
1003 tcp_seq snd_wl1; /* window update seg seq number */
1004 tcp_seq snd_wl2; /* window update seg ack number */
1005 tcp_seq iss; /* initial send sequence number */
1006 tcp_seq irs; /* initial receive sequence number */
1007
1008 tcp_seq rcv_nxt; /* receive next */
1009 tcp_seq rcv_adv; /* advertised window */
1010 u_int32_t rcv_wnd; /* receive window */
1011 tcp_seq rcv_up; /* receive urgent pointer */
1012
1013 u_int32_t snd_wnd; /* send window */
1014 u_int32_t snd_cwnd; /* congestion-controlled window */
1015 u_int32_t snd_ssthresh; /* snd_cwnd size threshold for
1016 * for slow start exponential to
1017 * linear switch
1018 */
1019 u_int t_maxopd; /* mss plus options */
1020
6d2010ae 1021 u_int32_t t_rcvtime; /* time at which a packet was received */
b0d623f7
A
1022 u_int32_t t_starttime; /* time connection was established */
1023 int t_rtttime; /* round trip time */
1024 tcp_seq t_rtseq; /* sequence number being timed */
1025
1026 int t_rxtcur; /* current retransmit value (ticks) */
1027 u_int t_maxseg; /* maximum segment size */
1028 int t_srtt; /* smoothed round-trip time */
1029 int t_rttvar; /* variance in round-trip time */
1030
1031 int t_rxtshift; /* log(2) of rexmt exp. backoff */
1032 u_int t_rttmin; /* minimum rtt allowed */
1033 u_int32_t t_rttupdated; /* number of times rtt sampled */
1034 u_int32_t max_sndwnd; /* largest window peer has offered */
1035
1036 int t_softerror; /* possible error not yet reported */
1037/* out-of-band data */
1038 char t_oobflags; /* have some */
1039 char t_iobc; /* input character */
1040/* RFC 1323 variables */
1041 u_char snd_scale; /* window scaling for send window */
1042 u_char rcv_scale; /* window scaling for recv window */
1043 u_char request_r_scale; /* pending window scaling */
1044 u_char requested_s_scale;
1045 u_int32_t ts_recent; /* timestamp echo data */
1046
1047 u_int32_t ts_recent_age; /* when last updated */
1048 tcp_seq last_ack_sent;
1049/* RFC 1644 variables */
1050 tcp_cc cc_send; /* send connection count */
1051 tcp_cc cc_recv; /* receive connection count */
1052 tcp_seq snd_recover; /* for use in fast recovery */
1053/* experimental */
1054 u_int32_t snd_cwnd_prev; /* cwnd prior to retransmit */
1055 u_int32_t snd_ssthresh_prev; /* ssthresh prior to retransmit */
1056 u_int32_t t_badrxtwin; /* window for retransmit recovery */
1057
1058 u_quad_t xt_alignment_hack;
1c79356b 1059};
1c79356b 1060
b0d623f7 1061
6d2010ae
A
1062#ifdef PRIVATE
1063
1064struct xtcpcb_n {
1065 u_int32_t xt_len;
1066 u_int32_t xt_kind; /* XSO_TCPCB */
1067
1068 u_int64_t t_segq;
1069 int t_dupacks; /* consecutive dup acks recd */
1070
1071 int t_timer[TCPT_NTIMERS_EXT]; /* tcp timers */
1072
1073 int t_state; /* state of this connection */
1074 u_int t_flags;
1075
1076 int t_force; /* 1 if forcing out a byte */
1077
1078 tcp_seq snd_una; /* send unacknowledged */
1079 tcp_seq snd_max; /* highest sequence number sent;
1080 * used to recognize retransmits
1081 */
1082 tcp_seq snd_nxt; /* send next */
1083 tcp_seq snd_up; /* send urgent pointer */
1084
1085 tcp_seq snd_wl1; /* window update seg seq number */
1086 tcp_seq snd_wl2; /* window update seg ack number */
1087 tcp_seq iss; /* initial send sequence number */
1088 tcp_seq irs; /* initial receive sequence number */
1089
1090 tcp_seq rcv_nxt; /* receive next */
1091 tcp_seq rcv_adv; /* advertised window */
1092 u_int32_t rcv_wnd; /* receive window */
1093 tcp_seq rcv_up; /* receive urgent pointer */
1094
1095 u_int32_t snd_wnd; /* send window */
1096 u_int32_t snd_cwnd; /* congestion-controlled window */
1097 u_int32_t snd_ssthresh; /* snd_cwnd size threshold for
1098 * for slow start exponential to
1099 * linear switch
1100 */
1101 u_int t_maxopd; /* mss plus options */
1102
1103 u_int32_t t_rcvtime; /* time at which a packet was received */
1104 u_int32_t t_starttime; /* time connection was established */
1105 int t_rtttime; /* round trip time */
1106 tcp_seq t_rtseq; /* sequence number being timed */
1107
1108 int t_rxtcur; /* current retransmit value (ticks) */
1109 u_int t_maxseg; /* maximum segment size */
1110 int t_srtt; /* smoothed round-trip time */
1111 int t_rttvar; /* variance in round-trip time */
1112
1113 int t_rxtshift; /* log(2) of rexmt exp. backoff */
1114 u_int t_rttmin; /* minimum rtt allowed */
1115 u_int32_t t_rttupdated; /* number of times rtt sampled */
1116 u_int32_t max_sndwnd; /* largest window peer has offered */
1117
1118 int t_softerror; /* possible error not yet reported */
1119 /* out-of-band data */
1120 char t_oobflags; /* have some */
1121 char t_iobc; /* input character */
1122 /* RFC 1323 variables */
1123 u_char snd_scale; /* window scaling for send window */
1124 u_char rcv_scale; /* window scaling for recv window */
1125 u_char request_r_scale; /* pending window scaling */
1126 u_char requested_s_scale;
1127 u_int32_t ts_recent; /* timestamp echo data */
1128
1129 u_int32_t ts_recent_age; /* when last updated */
1130 tcp_seq last_ack_sent;
1131 /* RFC 1644 variables */
1132 tcp_cc cc_send; /* send connection count */
1133 tcp_cc cc_recv; /* receive connection count */
1134 tcp_seq snd_recover; /* for use in fast recovery */
1135 /* experimental */
1136 u_int32_t snd_cwnd_prev; /* cwnd prior to retransmit */
1137 u_int32_t snd_ssthresh_prev; /* ssthresh prior to retransmit */
6d2010ae
A
1138};
1139
1140#endif /* PRIVATE */
1141
2d21ac55
A
1142#pragma pack()
1143
1c79356b
A
1144/*
1145 * Names for TCP sysctl objects
1146 */
1147#define TCPCTL_DO_RFC1323 1 /* use RFC-1323 extensions */
1148#define TCPCTL_DO_RFC1644 2 /* use RFC-1644 extensions */
1149#define TCPCTL_MSSDFLT 3 /* MSS default */
1150#define TCPCTL_STATS 4 /* statistics (read-only) */
1151#define TCPCTL_RTTDFLT 5 /* default RTT estimate */
1152#define TCPCTL_KEEPIDLE 6 /* keepalive idle timer */
1153#define TCPCTL_KEEPINTVL 7 /* interval to send keepalives */
1154#define TCPCTL_SENDSPACE 8 /* send buffer space */
1155#define TCPCTL_RECVSPACE 9 /* receive buffer space */
9bccf70c 1156#define TCPCTL_KEEPINIT 10 /* timeout for establishing syn */
1c79356b 1157#define TCPCTL_PCBLIST 11 /* list of all outstanding PCBs */
9bccf70c
A
1158#define TCPCTL_DELACKTIME 12 /* time before sending delayed ACK */
1159#define TCPCTL_V6MSSDFLT 13 /* MSS default for IPv6 */
1160#define TCPCTL_MAXID 14
1c79356b 1161
39236c6e
A
1162#ifdef BSD_KERNEL_PRIVATE
1163#include <sys/bitstring.h>
1164
2d21ac55
A
1165#define TCP_PKTLIST_CLEAR(tp) { \
1166 (tp)->t_pktlist_head = (tp)->t_pktlist_tail = NULL; \
1167 (tp)->t_lastchain = (tp)->t_pktlist_sentlen = 0; \
1168}
1169
1c79356b
A
1170#define TCPCTL_NAMES { \
1171 { 0, 0 }, \
1172 { "rfc1323", CTLTYPE_INT }, \
1173 { "rfc1644", CTLTYPE_INT }, \
1174 { "mssdflt", CTLTYPE_INT }, \
1175 { "stats", CTLTYPE_STRUCT }, \
1176 { "rttdflt", CTLTYPE_INT }, \
1177 { "keepidle", CTLTYPE_INT }, \
1178 { "keepintvl", CTLTYPE_INT }, \
1179 { "sendspace", CTLTYPE_INT }, \
1180 { "recvspace", CTLTYPE_INT }, \
1181 { "keepinit", CTLTYPE_INT }, \
1182 { "pcblist", CTLTYPE_STRUCT }, \
9bccf70c 1183 { "delacktime", CTLTYPE_INT }, \
1c79356b
A
1184 { "v6mssdflt", CTLTYPE_INT }, \
1185}
1186
1c79356b
A
1187#ifdef SYSCTL_DECL
1188SYSCTL_DECL(_net_inet_tcp);
91447636 1189#endif /* SYSCTL_DECL */
1c79356b 1190
39236c6e
A
1191/*
1192 * Flags for TCP's connectx(2) user-protocol request routine.
1193 */
1194#if MPTCP
1195#define TCP_CONNREQF_MPTCP 0x1 /* called internally by MPTCP */
1196#endif /* MPTCP */
1197
1c79356b
A
1198extern struct inpcbhead tcb; /* head of queue of active tcpcb's */
1199extern struct inpcbinfo tcbinfo;
1200extern struct tcpstat tcpstat; /* tcp statistics */
1201extern int tcp_mssdflt; /* XXX */
e5568f75 1202extern int tcp_minmss;
9bccf70c
A
1203extern int ss_fltsz;
1204extern int ss_fltsz_local;
6d2010ae 1205extern int tcp_do_rfc3390; /* Calculate ss_fltsz according to RFC 3390 */
39236c6e 1206extern int target_qdelay;
b0d623f7 1207extern u_int32_t tcp_now; /* for RFC 1323 timestamps */
6d2010ae
A
1208extern struct timeval tcp_uptime;
1209extern lck_spin_t *tcp_uptime_lock;
9bccf70c 1210extern int tcp_delack_enabled;
8ad349bb 1211extern int tcp_do_sack; /* SACK enabled/disabled */
fe8ab488
A
1212extern int tcp_do_rfc3465;
1213extern int tcp_do_rfc3465_lim2;
1214extern int maxseg_unacked;
1215extern int tcp_use_newreno;
1216
1c79356b 1217
b0d623f7
A
1218#if CONFIG_IFEF_NOWINDOWSCALE
1219extern int tcp_obey_ifef_nowindowscale;
1220#endif
1221
39236c6e
A
1222struct protosw;
1223struct domain;
1224
fe8ab488
A
1225struct tcp_respond_args {
1226 unsigned int ifscope;
1227 unsigned int nocell:1,
1228 noexpensive:1,
1229 awdl_unrestricted:1;
1230};
1231
91447636 1232void tcp_canceltimers(struct tcpcb *);
1c79356b 1233struct tcpcb *
91447636
A
1234 tcp_close(struct tcpcb *);
1235void tcp_ctlinput(int, struct sockaddr *, void *);
1236int tcp_ctloutput(struct socket *, struct sockopt *);
1c79356b 1237struct tcpcb *
91447636
A
1238 tcp_drop(struct tcpcb *, int);
1239void tcp_drain(void);
316670eb 1240void tcp_getrt_rtt(struct tcpcb *tp, struct rtentry *rt);
1c79356b 1241struct rmxp_tao *
91447636 1242 tcp_gettaocache(struct inpcb *);
39236c6e 1243void tcp_init(struct protosw *, struct domain *);
91447636 1244void tcp_input(struct mbuf *, int);
c910b4d9 1245void tcp_mss(struct tcpcb *, int, unsigned int);
91447636
A
1246int tcp_mssopt(struct tcpcb *);
1247void tcp_drop_syn_sent(struct inpcb *, int);
1248void tcp_mtudisc(struct inpcb *, int);
1c79356b 1249struct tcpcb *
91447636
A
1250 tcp_newtcpcb(struct inpcb *);
1251int tcp_output(struct tcpcb *);
fe8ab488
A
1252void tcp_respond(struct tcpcb *, void *, struct tcphdr *, struct mbuf *,
1253 tcp_seq, tcp_seq, int, struct tcp_respond_args *);
1254struct rtentry *
1255 tcp_rtlookup(struct inpcb *, unsigned int);
91447636 1256void tcp_setpersist(struct tcpcb *);
fe8ab488 1257void tcp_gc(struct inpcbinfo *);
6d2010ae
A
1258void tcp_check_timer_state(struct tcpcb *tp);
1259void tcp_run_timerlist(void *arg1, void *arg2);
1260
fe8ab488 1261struct tcptemp *tcp_maketemplate(struct tcpcb *);
91447636 1262void tcp_fillheaders(struct tcpcb *, void *, void *);
fe8ab488 1263struct tcpcb *tcp_timers(struct tcpcb *, int);
91447636 1264void tcp_trace(int, int, struct tcpcb *, void *, struct tcphdr *, int);
8ad349bb 1265
fe8ab488
A
1266void tcp_sack_doack(struct tcpcb *, struct tcpopt *, struct tcphdr *,
1267 u_int32_t *);
1268int tcp_detect_bad_rexmt(struct tcpcb *, struct tcphdr *, struct tcpopt *,
1269 u_int32_t rxtime);
8ad349bb
A
1270void tcp_update_sack_list(struct tcpcb *tp, tcp_seq rcv_laststart, tcp_seq rcv_lastend);
1271void tcp_clean_sackreport(struct tcpcb *tp);
1272void tcp_sack_adjust(struct tcpcb *tp);
1273struct sackhole *tcp_sack_output(struct tcpcb *tp, int *sack_bytes_rexmt);
1274void tcp_sack_partialack(struct tcpcb *, struct tcphdr *);
1275void tcp_free_sackholes(struct tcpcb *tp);
b0d623f7
A
1276int32_t tcp_sbspace(struct tcpcb *tp);
1277void tcp_set_tso(struct tcpcb *tp, struct ifnet *ifp);
6d2010ae 1278void tcp_reset_stretch_ack(struct tcpcb *tp);
39236c6e 1279extern void tcp_get_ports_used(u_int32_t, int, u_int32_t, bitstr_t *);
316670eb 1280uint32_t tcp_count_opportunistic(unsigned int ifindex, u_int32_t flags);
39236c6e 1281uint32_t tcp_find_anypcb_byaddr(struct ifaddr *ifa);
316670eb 1282void tcp_set_max_rwinscale(struct tcpcb *tp, struct socket *so);
316670eb
A
1283struct bwmeas* tcp_bwmeas_alloc(struct tcpcb *tp);
1284void tcp_bwmeas_free(struct tcpcb *tp);
fe8ab488 1285extern int32_t timer_diff(uint32_t t1, uint32_t toff1, uint32_t t2, uint32_t toff2);
316670eb
A
1286
1287extern void tcp_set_background_cc(struct socket *);
1288extern void tcp_set_foreground_cc(struct socket *);
1289extern void tcp_set_recv_bg(struct socket *);
1290extern void tcp_clear_recv_bg(struct socket *);
fe8ab488 1291extern boolean_t tcp_sack_byte_islost(struct tcpcb *tp);
316670eb
A
1292#define IS_TCP_RECV_BG(_so) \
1293 ((_so)->so_traffic_mgt_flags & TRAFFIC_MGT_TCP_RECVBG)
8ad349bb 1294
6d2010ae 1295#if TRAFFIC_MGT
316670eb 1296#define CLEAR_IAJ_STATE(_tp_) (_tp_)->iaj_rcv_ts = 0
6d2010ae
A
1297void reset_acc_iaj(struct tcpcb *tp);
1298#endif /* TRAFFIC_MGT */
8ad349bb 1299
b0d623f7
A
1300int tcp_lock (struct socket *, int, void *);
1301int tcp_unlock (struct socket *, int, void *);
6d2010ae
A
1302void calculate_tcp_clock(void);
1303
39236c6e 1304extern void tcp_keepalive_reset(struct tcpcb *);
fe8ab488 1305extern uint32_t get_base_rtt(struct tcpcb *tp);
39236c6e 1306
91447636
A
1307#ifdef _KERN_LOCKS_H_
1308lck_mtx_t * tcp_getlock (struct socket *, int);
1309#else
1310void * tcp_getlock (struct socket *, int);
1311#endif
1312
1c79356b
A
1313
1314extern struct pr_usrreqs tcp_usrreqs;
b0d623f7
A
1315extern u_int32_t tcp_sendspace;
1316extern u_int32_t tcp_recvspace;
91447636 1317tcp_seq tcp_new_isn(struct tcpcb *);
1c79356b 1318
39236c6e
A
1319extern int tcp_input_checksum(int, struct mbuf *, struct tcphdr *, int, int);
1320extern void tcp_getconninfo(struct socket *, struct conninfo_tcp *);
fe8ab488
A
1321extern void add_to_time_wait(struct tcpcb *, uint32_t delay);
1322extern void tcp_pmtud_revert_segment_size(struct tcpcb *tp);
39236c6e
A
1323#if MPTCP
1324extern uint16_t mptcp_input_csum(struct tcpcb *, struct mbuf *, int);
1325extern void mptcp_output_csum(struct tcpcb *, struct mbuf *, int32_t, unsigned,
1326 u_int64_t, u_int32_t *);
1327extern int mptcp_adj_mss(struct tcpcb *, boolean_t);
fe8ab488 1328extern void mptcp_insert_rmap(struct tcpcb *, struct mbuf *);
39236c6e
A
1329#endif
1330#endif /* BSD_KERNEL_RPIVATE */
1c79356b
A
1331
1332#endif /* _NETINET_TCP_VAR_H_ */