2 * Copyright (c) 2000-2014 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1982, 1986, 1993, 1994, 1995
30 * The Regents of the University of California. All rights reserved.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
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.
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
60 * @(#)tcp_var.h 8.4 (Berkeley) 5/24/95
61 * $FreeBSD: src/sys/netinet/tcp_var.h,v 1.56.2.8 2001/08/22 00:59:13 silby Exp $
64 #ifndef _NETINET_TCP_VAR_H_
65 #define _NETINET_TCP_VAR_H_
66 #include <sys/appleapiopts.h>
67 #include <sys/queue.h>
68 #include <netinet/in_pcb.h>
69 #include <netinet/tcp_timer.h>
72 #define _TCPCB_PTR(x) u_int32_t
73 #define _TCPCB_LIST_HEAD(name, type) \
78 #define _TCPCB_PTR(x) x
79 #define _TCPCB_LIST_HEAD(name, type) LIST_HEAD(name, type)
84 #define TCP_RETRANSHZ 1000 /* granularity of TCP timestamps, 1ms */
85 /* Minimum time quantum within which the timers are coalesced */
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 */
90 #define TCP_RETRANSHZ_TO_USEC 1000
92 #define N_TIME_WAIT_SLOTS 128 /* must be power of 2 */
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
100 /* Always allow at least 4 packets worth of recv window when adjusting
101 * recv window using inter-packet arrival jitter.
103 #define MIN_IAJ_WIN 4
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.
109 #define ALLOWED_IAJ 5
111 /* Ignore the first few packets on a connection until the ACK clock gets going
113 #define IAJ_IGNORE_PKTCNT 40
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
119 #define ACC_IAJ_HIGH_THRESH 100
121 /* When accumulated IAJ reaches this value, the receiver starts to react by
124 #define ACC_IAJ_REACT_LIMIT 200
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.
131 #define RESET_IAJ_SIZE_THRESH 20
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.
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.
145 * The maximum value of adaptive timeout is set to 10 which will allow
146 * transmission of enough number of probes to the peer.
148 #define TCP_ADAPTIVE_TIMEOUT_MAX 10
151 * Kernel variables for tcp.
154 /* TCP segment queue entry */
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 */
161 LIST_HEAD(tsegqe_head
, tseg_qent
);
164 tcp_seq start
; /* start seq no. of sack block */
165 tcp_seq end
; /* end seq no. */
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 */
172 u_int32_t rxmit_start
; /* timestamp of first retransmission */
173 TAILQ_ENTRY(sackhole
) scblink
; /* scoreboard linkage */
177 struct sackhole
*nexthole
;
178 int sack_bytes_rexmit
;
182 u_char tt_ipgen
[40]; /* the size must be of max ip header, now IPv6 */
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 */
197 /* MPTCP Data sequence map entry */
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 */
204 #define tcp6cb tcpcb /* for KAME src sync over BSD*'s */
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 */
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
232 * Tcp control block, one per tcp; fields:
233 * Organized for 16 byte cacheline efficiency.
236 struct tsegqe_head t_segq
;
237 int t_dupacks
; /* consecutive dup acks recd */
238 uint32_t t_timer
[TCPT_NTIMERS
]; /* tcp timers */
239 struct tcptimerentry tentry
; /* entry in timer list */
241 struct inpcb
*t_inpcb
; /* back pointer to internet pcb */
242 int t_state
; /* state of this connection */
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 */
261 #define TF_LOCAL 0x20000 /* connection to a host on local link */
262 #define TF_RXWIN0SENT 0x40000 /* sent a receiver win 0 in response */
263 #define TF_SLOWLINK 0x80000 /* route is a on a modem speed link */
264 #define TF_LASTIDLE 0x100000 /* connection was previously idle */
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 */
269 #define TF_ENABLE_ECN 0x2000000 /* Enable ECN */
270 #define TF_PMTUD 0x4000000 /* Perform Path MTU Discovery for this connection */
271 #define TF_CLOSING 0x8000000 /* pending tcp close */
272 #define TF_TSO 0x10000000 /* TCP Segment Offloading is enable on this connection */
273 #define TF_BLACKHOLE 0x20000000 /* Path MTU Discovery Black Hole detection */
274 #define TF_TIMER_ONLIST 0x40000000 /* pcb is on tcp_timer_list */
275 #define TF_STRETCHACK 0x80000000 /* receiver is going to delay acks */
277 tcp_seq snd_una
; /* send unacknowledged */
278 tcp_seq snd_max
; /* highest sequence number sent;
279 * used to recognize retransmits
281 tcp_seq snd_nxt
; /* send next */
282 tcp_seq snd_up
; /* send urgent pointer */
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 */
289 tcp_seq rcv_nxt
; /* receive next */
290 tcp_seq rcv_adv
; /* advertised window */
291 u_int32_t rcv_wnd
; /* receive window */
292 tcp_seq rcv_up
; /* receive urgent pointer */
294 u_int32_t snd_wnd
; /* send window */
295 u_int32_t snd_cwnd
; /* congestion-controlled window */
296 u_int32_t snd_ssthresh
; /* snd_cwnd size threshold for
297 * for slow start exponential to
300 tcp_seq snd_recover
; /* for use in NewReno Fast Recovery */
302 u_int t_maxopd
; /* mss plus options */
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 */
307 tcp_seq t_rtseq
; /* sequence number being timed */
309 u_int32_t rfbuf_ts
; /* recv buffer autoscaling timestamp */
310 u_int32_t rfbuf_cnt
; /* recv buffer autoscaling byte count */
312 int t_rxtcur
; /* current retransmit value (ticks) */
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 */
317 u_int16_t t_reassqlen
; /* length of reassembly queue */
318 u_int16_t t_rxtshift
; /* log(2) of rexmt exp. backoff */
319 u_int t_rttmin
; /* minimum rtt allowed */
320 u_int t_rttbest
; /* best rtt we've seen */
321 u_int t_rttcur
; /* most recent value of rtt */
322 u_int32_t t_rttupdated
; /* number of times rtt sampled */
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 */
325 u_int32_t max_sndwnd
; /* largest window peer has offered */
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 */
334 u_int8_t snd_scale
; /* window scaling for send window */
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 */
341 u_int8_t t_stretchack_delayed
; /* stretch ack delayed */
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 */
347 u_int32_t ts_recent
; /* timestamp echo data */
349 u_int32_t ts_recent_age
; /* when last updated */
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 */
354 /* RFC 3465 variables */
355 u_int32_t t_bytes_acked
; /* ABC "bytes_acked" parameter */
357 int t_lastchain
; /* amount of packets chained last time around */
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 */
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 */
363 u_int32_t t_notsent_lowat
; /* Low water for not sent data */
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 */
368 u_int32_t rcv_nostrack_ts
; /* timestamp when stretch ack was disabled automatically */
369 u_int16_t rcv_waitforss
; /* wait for packets during slow-start */
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 */
376 #define TE_INRECOVERY 0x20 /* connection entered recovery after receiving ECE */
377 #define TE_ECN_ON (TE_SETUPSENT | TE_SETUPRECEIVED) /* Indicate ECN was successfully negotiated on a connection) */
379 /* state for bad retransmit recovery */
380 u_int32_t snd_cwnd_prev
; /* cwnd prior to retransmit */
381 u_int32_t snd_ssthresh_prev
; /* ssthresh prior to retransmit */
382 tcp_seq snd_recover_prev
; /* snd_recover prior to retransmit */
383 int t_srtt_prev
; /* srtt prior to retransmit */
384 int t_rttvar_prev
; /* rttvar prior to retransmit */
385 u_int32_t t_badrexmt_time
; /* bad rexmt detection time */
387 /* Packet reordering metric */
388 u_int16_t t_reorderwin
; /* Reordering late time offset */
390 /* SACK related state */
391 int16_t snd_numholes
; /* number of holes seen by sender */
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 */
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 */
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 */
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 */
417 u_int32_t rxduplicatebytes
;
418 u_int32_t rxoutoforderbytes
;
419 u_int32_t txretransmitbytes
;
420 u_int8_t synrxtshift
;
422 u_int16_t unused_pad_to_8
;
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 */
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 */
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 */
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 */
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 */
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 */
463 TAILQ_ENTRY(tcpcb
) t_twentry
; /* link for time wait queue */
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 */
469 u_int32_t t_mpflags
; /* flags for multipath TCP */
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 */
493 #define TMPF_FASTJOIN_SEND 0x00400000 /* Fast join early data send */
494 #define TMPF_FASTJOINBY2_SEND 0x00800000 /* Fast join send after 3 WHS */
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 */
505 #define IN_FASTRECOVERY(tp) (tp->t_flags & TF_FASTRECOVERY)
506 #define SACK_ENABLED(tp) (tp->t_flagsext & TF_SACK_ENABLE)
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.
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); \
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; \
526 (_tp_)->ecn_flags &= ~TE_INRECOVERY; \
527 (_tp_)->t_timer[TCPT_PTO] = 0; \
531 * When the number of duplicate acks received is less than
532 * the retransmit threshold, use Limited Transmit algorithm
534 extern int tcprexmtthresh
;
535 #define ALLOW_LIMITED_TRANSMIT(_tp_) \
536 ((_tp_)->t_dupacks > 0 && \
537 (_tp_)->t_dupacks < (_tp_)->t_rexmtthresh && \
538 ((_tp_)->t_flagsext & (TF_PKTS_REORDERED|TF_DELAY_RECOVERY)) \
539 != (TF_PKTS_REORDERED|TF_DELAY_RECOVERY))
542 * This condition is true is timestamp option is supported
545 #define TSTMP_SUPPORTED(_tp_) \
546 (((_tp_)->t_flags & (TF_REQ_TSTMP|TF_RCVD_TSTMP)) == \
547 (TF_REQ_TSTMP|TF_RCVD_TSTMP))
550 * Gives number of bytes acked by this ack
552 #define BYTES_ACKED(_th_, _tp_) \
553 ((_th_)->th_ack - (_tp_)->snd_una)
557 TCP_CC_INSEQ_ACK_RCVD
,
559 TCP_CC_ENTER_FASTRECOVERY
,
560 TCP_CC_IN_FASTRECOVERY
,
561 TCP_CC_EXIT_FASTRECOVERY
,
564 TCP_CC_REXMT_TIMEOUT
,
566 TCP_CC_BAD_REXMT_RECOVERY
,
571 TCP_CC_LIMITED_TRANSMIT
,
572 TCP_CC_EARLY_RETRANSMIT
,
574 TCP_CC_TLP_RECOVER_LASTPACKET
,
575 TCP_CC_DELAY_FASTRECOVERY
,
576 TCP_CC_TLP_IN_FASTRECOVERY
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
586 u_int32_t to_flags
; /* which options are present */
587 #define TOF_TS 0x0001 /* timestamp */
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 */
593 #define TOF_MPTCP 0x0200 /* MPTCP options to be dropped */
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 */
603 * The TAO cache entry which is stored in the protocol family specific
604 * portion of the route metrics.
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 */
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 */
617 #define rmx_taop(r) ((struct rmxp_tao *)(r).rmx_filler)
619 #define intotcpcb(ip) ((struct tcpcb *)(ip)->inp_ppcb)
620 #define sototcpcb(so) (intotcpcb(sotoinpcb(so)))
623 * The rtt measured is in milliseconds as the timestamp granularity is
624 * a millisecond. The smoothed round-trip time and estimated variance
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).
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
630 * binary point, and is smoothed with an ALPHA of 0.75.
632 #define TCP_RTT_SCALE 32 /* multiplier for srtt; 3 bits frac. */
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 */
636 #define TCP_DELTA_SHIFT 2 /* see tcp_input.c */
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
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)
659 * Jaguar compatible TCP control block, for xtcpcb
660 * Does not have the old fields
665 _TCPCB_LIST_HEAD(tsegqe_head
, tseg_qent
);
668 #endif /* KERNEL_PRIVATE */
669 #if defined(KERNEL_PRIVATE)
672 struct tsegqe_head t_segq
;
673 #endif /* KERNEL_PRIVATE */
674 int t_dupacks
; /* consecutive dup acks recd */
675 u_int32_t unused
; /* unused now: was t_template */
677 int t_timer
[TCPT_NTIMERS_EXT
]; /* tcp timers */
679 _TCPCB_PTR(struct inpcb
*) t_inpcb
; /* back pointer to internet pcb */
680 int t_state
; /* state of this connection */
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 */
703 int t_force
; /* 1 if forcing out a byte */
705 tcp_seq snd_una
; /* send unacknowledged */
706 tcp_seq snd_max
; /* highest sequence number sent;
707 * used to recognize retransmits
709 tcp_seq snd_nxt
; /* send next */
710 tcp_seq snd_up
; /* send urgent pointer */
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 */
717 tcp_seq rcv_nxt
; /* receive next */
718 tcp_seq rcv_adv
; /* advertised window */
719 u_int32_t rcv_wnd
; /* receive window */
720 tcp_seq rcv_up
; /* receive urgent pointer */
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
725 * for slow start exponential to
728 u_int t_maxopd
; /* mss plus options */
730 u_int32_t t_rcvtime
; /* time at which a packet was received */
731 u_int32_t t_starttime
; /* time connection was established */
732 int t_rtttime
; /* round trip time */
733 tcp_seq t_rtseq
; /* sequence number being timed */
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 */
740 int t_rxtshift
; /* log(2) of rexmt exp. backoff */
741 u_int t_rttmin
; /* minimum rtt allowed */
742 u_int32_t t_rttupdated
; /* number of times rtt sampled */
743 u_int32_t max_sndwnd
; /* largest window peer has offered */
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
;
756 u_int32_t ts_recent
; /* timestamp echo data */
758 u_int32_t ts_recent_age
; /* when last updated */
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 */
763 tcp_seq snd_recover
; /* for use in fast recovery */
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 */
773 * Many of these should be kept per connection,
774 * but that's inconvenient at the moment.
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 */
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 */
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 */
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 */
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 */
862 u_int32_t tcps_hc_added
; /* entry added to hostcache */
863 u_int32_t tcps_hc_bucketoverflow
; /* hostcache per bucket limit hit */
865 /* SACK related stats */
866 u_int32_t tcps_sack_recovery_episode
; /* SACK recovery episodes */
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 */
873 u_int32_t tcps_bg_rcvtotal
; /* total background packets received */
874 u_int32_t tcps_rxtfindrop
; /* drop conn after retransmitting FIN */
875 u_int32_t tcps_fcholdpacket
; /* packets withheld because of flow control */
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 */
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 */
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 */
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 */
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 */
940 struct tcpstat_local
{
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
;
951 u_int64_t rstinsynrcv
;
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.
967 #ifdef KERNEL_PRIVATE
968 struct inpcb_compat xt_inp
;
972 #ifdef KERNEL_PRIVATE
977 struct xsocket xt_socket
;
978 u_quad_t xt_alignment_hack
;
984 struct xinpcb64 xt_inpcb
;
987 int t_dupacks
; /* consecutive dup acks recd */
989 int t_timer
[TCPT_NTIMERS_EXT
]; /* tcp timers */
991 int t_state
; /* state of this connection */
994 int t_force
; /* 1 if forcing out a byte */
996 tcp_seq snd_una
; /* send unacknowledged */
997 tcp_seq snd_max
; /* highest sequence number sent;
998 * used to recognize retransmits
1000 tcp_seq snd_nxt
; /* send next */
1001 tcp_seq snd_up
; /* send urgent pointer */
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 */
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 */
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
1019 u_int t_maxopd
; /* mss plus options */
1021 u_int32_t t_rcvtime
; /* time at which a packet was received */
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 */
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 */
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 */
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 */
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 */
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 */
1058 u_quad_t xt_alignment_hack
;
1066 u_int32_t xt_kind
; /* XSO_TCPCB */
1069 int t_dupacks
; /* consecutive dup acks recd */
1071 int t_timer
[TCPT_NTIMERS_EXT
]; /* tcp timers */
1073 int t_state
; /* state of this connection */
1076 int t_force
; /* 1 if forcing out a byte */
1078 tcp_seq snd_una
; /* send unacknowledged */
1079 tcp_seq snd_max
; /* highest sequence number sent;
1080 * used to recognize retransmits
1082 tcp_seq snd_nxt
; /* send next */
1083 tcp_seq snd_up
; /* send urgent pointer */
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 */
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 */
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
1101 u_int t_maxopd
; /* mss plus options */
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 */
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 */
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 */
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 */
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 */
1136 u_int32_t snd_cwnd_prev
; /* cwnd prior to retransmit */
1137 u_int32_t snd_ssthresh_prev
; /* ssthresh prior to retransmit */
1140 #endif /* PRIVATE */
1145 * Names for TCP sysctl objects
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 */
1156 #define TCPCTL_KEEPINIT 10 /* timeout for establishing syn */
1157 #define TCPCTL_PCBLIST 11 /* list of all outstanding PCBs */
1158 #define TCPCTL_DELACKTIME 12 /* time before sending delayed ACK */
1159 #define TCPCTL_V6MSSDFLT 13 /* MSS default for IPv6 */
1160 #define TCPCTL_MAXID 14
1162 #ifdef BSD_KERNEL_PRIVATE
1163 #include <sys/bitstring.h>
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; \
1170 #define TCPCTL_NAMES { \
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 }, \
1183 { "delacktime", CTLTYPE_INT }, \
1184 { "v6mssdflt", CTLTYPE_INT }, \
1188 SYSCTL_DECL(_net_inet_tcp
);
1189 #endif /* SYSCTL_DECL */
1192 * Flags for TCP's connectx(2) user-protocol request routine.
1195 #define TCP_CONNREQF_MPTCP 0x1 /* called internally by MPTCP */
1198 extern struct inpcbhead tcb
; /* head of queue of active tcpcb's */
1199 extern struct inpcbinfo tcbinfo
;
1200 extern struct tcpstat tcpstat
; /* tcp statistics */
1201 extern int tcp_mssdflt
; /* XXX */
1202 extern int tcp_minmss
;
1203 extern int ss_fltsz
;
1204 extern int ss_fltsz_local
;
1205 extern int tcp_do_rfc3390
; /* Calculate ss_fltsz according to RFC 3390 */
1206 extern int target_qdelay
;
1207 extern u_int32_t tcp_now
; /* for RFC 1323 timestamps */
1208 extern struct timeval tcp_uptime
;
1209 extern lck_spin_t
*tcp_uptime_lock
;
1210 extern int tcp_delack_enabled
;
1211 extern int tcp_do_sack
; /* SACK enabled/disabled */
1212 extern int tcp_do_rfc3465
;
1213 extern int tcp_do_rfc3465_lim2
;
1214 extern int maxseg_unacked
;
1215 extern int tcp_use_newreno
;
1218 #if CONFIG_IFEF_NOWINDOWSCALE
1219 extern int tcp_obey_ifef_nowindowscale
;
1225 struct tcp_respond_args
{
1226 unsigned int ifscope
;
1227 unsigned int nocell
:1,
1229 awdl_unrestricted
:1;
1232 void tcp_canceltimers(struct tcpcb
*);
1234 tcp_close(struct tcpcb
*);
1235 void tcp_ctlinput(int, struct sockaddr
*, void *);
1236 int tcp_ctloutput(struct socket
*, struct sockopt
*);
1238 tcp_drop(struct tcpcb
*, int);
1239 void tcp_drain(void);
1240 void tcp_getrt_rtt(struct tcpcb
*tp
, struct rtentry
*rt
);
1242 tcp_gettaocache(struct inpcb
*);
1243 void tcp_init(struct protosw
*, struct domain
*);
1244 void tcp_input(struct mbuf
*, int);
1245 void tcp_mss(struct tcpcb
*, int, unsigned int);
1246 int tcp_mssopt(struct tcpcb
*);
1247 void tcp_drop_syn_sent(struct inpcb
*, int);
1248 void tcp_mtudisc(struct inpcb
*, int);
1250 tcp_newtcpcb(struct inpcb
*);
1251 int tcp_output(struct tcpcb
*);
1252 void tcp_respond(struct tcpcb
*, void *, struct tcphdr
*, struct mbuf
*,
1253 tcp_seq
, tcp_seq
, int, struct tcp_respond_args
*);
1255 tcp_rtlookup(struct inpcb
*, unsigned int);
1256 void tcp_setpersist(struct tcpcb
*);
1257 void tcp_gc(struct inpcbinfo
*);
1258 void tcp_check_timer_state(struct tcpcb
*tp
);
1259 void tcp_run_timerlist(void *arg1
, void *arg2
);
1261 struct tcptemp
*tcp_maketemplate(struct tcpcb
*);
1262 void tcp_fillheaders(struct tcpcb
*, void *, void *);
1263 struct tcpcb
*tcp_timers(struct tcpcb
*, int);
1264 void tcp_trace(int, int, struct tcpcb
*, void *, struct tcphdr
*, int);
1266 void tcp_sack_doack(struct tcpcb
*, struct tcpopt
*, struct tcphdr
*,
1268 int tcp_detect_bad_rexmt(struct tcpcb
*, struct tcphdr
*, struct tcpopt
*,
1270 void tcp_update_sack_list(struct tcpcb
*tp
, tcp_seq rcv_laststart
, tcp_seq rcv_lastend
);
1271 void tcp_clean_sackreport(struct tcpcb
*tp
);
1272 void tcp_sack_adjust(struct tcpcb
*tp
);
1273 struct sackhole
*tcp_sack_output(struct tcpcb
*tp
, int *sack_bytes_rexmt
);
1274 void tcp_sack_partialack(struct tcpcb
*, struct tcphdr
*);
1275 void tcp_free_sackholes(struct tcpcb
*tp
);
1276 int32_t tcp_sbspace(struct tcpcb
*tp
);
1277 void tcp_set_tso(struct tcpcb
*tp
, struct ifnet
*ifp
);
1278 void tcp_reset_stretch_ack(struct tcpcb
*tp
);
1279 extern void tcp_get_ports_used(u_int32_t
, int, u_int32_t
, bitstr_t
*);
1280 uint32_t tcp_count_opportunistic(unsigned int ifindex
, u_int32_t flags
);
1281 uint32_t tcp_find_anypcb_byaddr(struct ifaddr
*ifa
);
1282 void tcp_set_max_rwinscale(struct tcpcb
*tp
, struct socket
*so
);
1283 struct bwmeas
* tcp_bwmeas_alloc(struct tcpcb
*tp
);
1284 void tcp_bwmeas_free(struct tcpcb
*tp
);
1285 extern int32_t timer_diff(uint32_t t1
, uint32_t toff1
, uint32_t t2
, uint32_t toff2
);
1287 extern void tcp_set_background_cc(struct socket
*);
1288 extern void tcp_set_foreground_cc(struct socket
*);
1289 extern void tcp_set_recv_bg(struct socket
*);
1290 extern void tcp_clear_recv_bg(struct socket
*);
1291 extern boolean_t
tcp_sack_byte_islost(struct tcpcb
*tp
);
1292 #define IS_TCP_RECV_BG(_so) \
1293 ((_so)->so_traffic_mgt_flags & TRAFFIC_MGT_TCP_RECVBG)
1296 #define CLEAR_IAJ_STATE(_tp_) (_tp_)->iaj_rcv_ts = 0
1297 void reset_acc_iaj(struct tcpcb
*tp
);
1298 #endif /* TRAFFIC_MGT */
1300 int tcp_lock (struct socket
*, int, void *);
1301 int tcp_unlock (struct socket
*, int, void *);
1302 void calculate_tcp_clock(void);
1304 extern void tcp_keepalive_reset(struct tcpcb
*);
1305 extern uint32_t get_base_rtt(struct tcpcb
*tp
);
1307 #ifdef _KERN_LOCKS_H_
1308 lck_mtx_t
* tcp_getlock (struct socket
*, int);
1310 void * tcp_getlock (struct socket
*, int);
1314 extern struct pr_usrreqs tcp_usrreqs
;
1315 extern u_int32_t tcp_sendspace
;
1316 extern u_int32_t tcp_recvspace
;
1317 tcp_seq
tcp_new_isn(struct tcpcb
*);
1319 extern int tcp_input_checksum(int, struct mbuf
*, struct tcphdr
*, int, int);
1320 extern void tcp_getconninfo(struct socket
*, struct conninfo_tcp
*);
1321 extern void add_to_time_wait(struct tcpcb
*, uint32_t delay
);
1322 extern void tcp_pmtud_revert_segment_size(struct tcpcb
*tp
);
1324 extern uint16_t mptcp_input_csum(struct tcpcb
*, struct mbuf
*, int);
1325 extern void mptcp_output_csum(struct tcpcb
*, struct mbuf
*, int32_t, unsigned,
1326 u_int64_t
, u_int32_t
*);
1327 extern int mptcp_adj_mss(struct tcpcb
*, boolean_t
);
1328 extern void mptcp_insert_rmap(struct tcpcb
*, struct mbuf
*);
1330 #endif /* BSD_KERNEL_RPIVATE */
1332 #endif /* _NETINET_TCP_VAR_H_ */