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