1 /* $OpenBSD: tcp_var.h,v 1.131 2018/02/07 00:31:10 bluhm Exp $ */ 2 /* $NetBSD: tcp_var.h,v 1.17 1996/02/13 23:44:24 christos Exp $ */ 3 4 /* 5 * Copyright (c) 1982, 1986, 1993, 1994 6 * The Regents of the University of California. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of the University nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * @(#)tcp_var.h 8.3 (Berkeley) 4/10/94 33 */ 34 35 #ifndef _NETINET_TCP_VAR_H_ 36 #define _NETINET_TCP_VAR_H_ 37 38 #include <sys/timeout.h> 39 40 /* 41 * Kernel variables for tcp. 42 */ 43 44 struct sackblk { 45 tcp_seq start; /* start seq no. of sack block */ 46 tcp_seq end; /* end seq no. */ 47 }; 48 49 struct sackhole { 50 tcp_seq start; /* start seq no. of hole */ 51 tcp_seq end; /* end seq no. */ 52 int dups; /* number of dup(s)acks for this hole */ 53 tcp_seq rxmit; /* next seq. no in hole to be retransmitted */ 54 struct sackhole *next; /* next in list */ 55 }; 56 57 /* 58 * TCP sequence queue structures. 59 */ 60 TAILQ_HEAD(tcpqehead, tcpqent); 61 struct tcpqent { 62 TAILQ_ENTRY(tcpqent) tcpqe_q; 63 struct tcphdr *tcpqe_tcp; 64 struct mbuf *tcpqe_m; /* mbuf contains packet */ 65 }; 66 67 /* 68 * Tcp control block, one per tcp; fields: 69 */ 70 struct tcpcb { 71 struct tcpqehead t_segq; /* sequencing queue */ 72 struct timeout t_timer[TCPT_NTIMERS]; /* tcp timers */ 73 short t_state; /* state of this connection */ 74 short t_rxtshift; /* log(2) of rexmt exp. backoff */ 75 short t_rxtcur; /* current retransmit value */ 76 short t_dupacks; /* consecutive dup acks recd */ 77 u_short t_maxseg; /* maximum segment size */ 78 char t_force; /* 1 if forcing out a byte */ 79 u_int t_flags; 80 #define TF_ACKNOW 0x0001 /* ack peer immediately */ 81 #define TF_DELACK 0x0002 /* ack, but try to delay it */ 82 #define TF_NODELAY 0x0004 /* don't delay packets to coalesce */ 83 #define TF_NOOPT 0x0008 /* don't use tcp options */ 84 #define TF_SENTFIN 0x0010 /* have sent FIN */ 85 #define TF_REQ_SCALE 0x0020 /* have/will request window scaling */ 86 #define TF_RCVD_SCALE 0x0040 /* other side has requested scaling */ 87 #define TF_REQ_TSTMP 0x0080 /* have/will request timestamps */ 88 #define TF_RCVD_TSTMP 0x0100 /* a timestamp was received in SYN */ 89 #define TF_SACK_PERMIT 0x0200 /* other side said I could SACK */ 90 #define TF_SIGNATURE 0x0400 /* require TCP MD5 signature */ 91 #ifdef TCP_ECN 92 #define TF_ECN_PERMIT 0x00008000 /* other side said I could ECN */ 93 #define TF_RCVD_CE 0x00010000 /* send ECE in subsequent segs */ 94 #define TF_SEND_CWR 0x00020000 /* send CWR in next seg */ 95 #define TF_DISABLE_ECN 0x00040000 /* disable ECN for this connection */ 96 #endif 97 #define TF_LASTIDLE 0x00100000 /* no outstanding ACK on last send */ 98 #define TF_DEAD 0x00200000 /* dead and to-be-released */ 99 #define TF_PMTUD_PEND 0x00400000 /* Path MTU Discovery pending */ 100 #define TF_NEEDOUTPUT 0x00800000 /* call tcp_output after tcp_input */ 101 #define TF_BLOCKOUTPUT 0x01000000 /* avert tcp_output during tcp_input */ 102 #define TF_NOPUSH 0x02000000 /* don't push */ 103 #define TF_TMR_REXMT 0x04000000 /* retransmit timer armed */ 104 #define TF_TMR_PERSIST 0x08000000 /* retransmit persistence timer armed */ 105 #define TF_TMR_KEEP 0x10000000 /* keep alive timer armed */ 106 #define TF_TMR_2MSL 0x20000000 /* 2*msl quiet time timer armed */ 107 #define TF_TMR_REAPER 0x40000000 /* delayed cleanup timer armed, dead */ 108 #define TF_TIMER TF_TMR_REXMT /* used to shift with TCPT values */ 109 110 struct mbuf *t_template; /* skeletal packet for transmit */ 111 struct inpcb *t_inpcb; /* back pointer to internet pcb */ 112 struct timeout t_delack_to; /* delayed ACK callback */ 113 /* 114 * The following fields are used as in the protocol specification. 115 * See RFC793, Dec. 1981, page 21. 116 */ 117 /* send sequence variables */ 118 tcp_seq snd_una; /* send unacknowledged */ 119 tcp_seq snd_nxt; /* send next */ 120 tcp_seq snd_up; /* send urgent pointer */ 121 tcp_seq snd_wl1; /* window update seg seq number */ 122 tcp_seq snd_wl2; /* window update seg ack number */ 123 tcp_seq iss; /* initial send sequence number */ 124 u_long snd_wnd; /* send window */ 125 int sack_enable; /* enable SACK for this connection */ 126 int snd_numholes; /* number of holes seen by sender */ 127 struct sackhole *snd_holes; /* linked list of holes (sorted) */ 128 tcp_seq snd_last; /* for use in fast recovery */ 129 /* receive sequence variables */ 130 u_long rcv_wnd; /* receive window */ 131 tcp_seq rcv_nxt; /* receive next */ 132 tcp_seq rcv_up; /* receive urgent pointer */ 133 tcp_seq irs; /* initial receive sequence number */ 134 tcp_seq rcv_lastsack; /* last seq number(+1) sack'd by rcv'r*/ 135 int rcv_numsacks; /* # distinct sack blks present */ 136 struct sackblk sackblks[MAX_SACK_BLKS]; /* seq nos. of sack blocks */ 137 138 /* 139 * Additional variables for this implementation. 140 */ 141 /* receive variables */ 142 tcp_seq rcv_adv; /* advertised window */ 143 /* retransmit variables */ 144 tcp_seq snd_max; /* highest sequence number sent; 145 * used to recognize retransmits 146 */ 147 /* congestion control (for slow start, source quench, retransmit after loss) */ 148 u_long snd_cwnd; /* congestion-controlled window */ 149 u_long snd_ssthresh; /* snd_cwnd size threshold for 150 * for slow start exponential to 151 * linear switch 152 */ 153 154 /* auto-sizing variables */ 155 u_int rfbuf_cnt; /* recv buffer autoscaling byte count */ 156 u_int32_t rfbuf_ts; /* recv buffer autoscaling time stamp */ 157 158 u_short t_maxopd; /* mss plus options */ 159 u_short t_peermss; /* peer's maximum segment size */ 160 161 /* 162 * transmit timing stuff. See below for scale of srtt and rttvar. 163 * "Variance" is actually smoothed difference. 164 */ 165 uint32_t t_rcvtime; /* time last segment received */ 166 uint32_t t_rtttime; /* time we started measuring rtt */ 167 tcp_seq t_rtseq; /* sequence number being timed */ 168 short t_srtt; /* smoothed round-trip time */ 169 short t_rttvar; /* variance in round-trip time */ 170 u_short t_rttmin; /* minimum rtt allowed */ 171 u_long max_sndwnd; /* largest window peer has offered */ 172 173 /* out-of-band data */ 174 char t_oobflags; /* have some */ 175 char t_iobc; /* input character */ 176 #define TCPOOB_HAVEDATA 0x01 177 #define TCPOOB_HADDATA 0x02 178 short t_softerror; /* possible error not yet reported */ 179 180 /* RFC 1323 variables */ 181 u_char snd_scale; /* window scaling for send window */ 182 u_char rcv_scale; /* window scaling for recv window */ 183 u_char request_r_scale; /* pending window scaling */ 184 u_char requested_s_scale; 185 u_int32_t ts_recent; /* timestamp echo data */ 186 u_int32_t ts_modulate; /* modulation on timestamp */ 187 u_int32_t ts_recent_age; /* when last updated */ 188 tcp_seq last_ack_sent; 189 190 /* pointer for syn cache entries*/ 191 LIST_HEAD(, syn_cache) t_sc; /* list of entries by this tcb */ 192 193 /* Path-MTU Discovery Information */ 194 u_int t_pmtud_mss_acked; /* MSS acked, lower bound for MTU */ 195 u_int t_pmtud_mtu_sent; /* MTU used, upper bound for MTU */ 196 tcp_seq t_pmtud_th_seq; /* TCP SEQ from ICMP payload */ 197 u_int t_pmtud_nextmtu; /* Advertised Next-Hop MTU from ICMP */ 198 u_short t_pmtud_ip_len; /* IP length from ICMP payload */ 199 u_short t_pmtud_ip_hl; /* IP header length from ICMP payload */ 200 201 int pf; 202 }; 203 204 #define intotcpcb(ip) ((struct tcpcb *)(ip)->inp_ppcb) 205 #define sototcpcb(so) (intotcpcb(sotoinpcb(so))) 206 207 #ifdef _KERNEL 208 void tcp_delack(void *); 209 210 #define TCP_INIT_DELACK(tp) \ 211 timeout_set_proc(&(tp)->t_delack_to, tcp_delack, tp) 212 213 #define TCP_RESTART_DELACK(tp) \ 214 timeout_add_msec(&(tp)->t_delack_to, tcp_delack_msecs) 215 216 #define TCP_SET_DELACK(tp) \ 217 do { \ 218 if (((tp)->t_flags & TF_DELACK) == 0) { \ 219 (tp)->t_flags |= TF_DELACK; \ 220 TCP_RESTART_DELACK(tp); \ 221 } \ 222 } while (/* CONSTCOND */ 0) 223 224 #define TCP_CLEAR_DELACK(tp) \ 225 do { \ 226 if ((tp)->t_flags & TF_DELACK) { \ 227 (tp)->t_flags &= ~TF_DELACK; \ 228 timeout_del(&(tp)->t_delack_to); \ 229 } \ 230 } while (/* CONSTCOND */ 0) 231 232 /* 233 * Handy way of passing around TCP option info. 234 */ 235 struct tcp_opt_info { 236 int ts_present; 237 u_int32_t ts_val; 238 u_int32_t ts_ecr; 239 u_int16_t maxseg; 240 }; 241 242 /* 243 * Data for the TCP compressed state engine. 244 */ 245 246 #define TCP_SYN_HASH_SIZE 293 247 #define TCP_SYN_BUCKET_SIZE 35 248 249 union syn_cache_sa { 250 struct sockaddr sa; 251 struct sockaddr_in sin; 252 struct sockaddr_in6 sin6; 253 }; 254 255 struct syn_cache { 256 TAILQ_ENTRY(syn_cache) sc_bucketq; /* link on bucket list */ 257 struct timeout sc_timer; /* rexmt timer */ 258 union { /* cached route */ 259 struct route route4; 260 #ifdef INET6 261 struct route_in6 route6; 262 #endif 263 } sc_route_u; 264 #define sc_route4 sc_route_u.route4 265 #ifdef INET6 266 #define sc_route6 sc_route_u.route6 267 #endif 268 long sc_win; /* advertised window */ 269 struct syn_cache_head *sc_buckethead; /* our bucket index */ 270 struct syn_cache_set *sc_set; /* our syn cache set */ 271 u_int32_t sc_hash; 272 u_int32_t sc_timestamp; /* timestamp from SYN */ 273 u_int32_t sc_modulate; /* our timestamp modulator */ 274 #if 0 275 u_int32_t sc_timebase; /* our local timebase */ 276 #endif 277 union syn_cache_sa sc_src; 278 union syn_cache_sa sc_dst; 279 tcp_seq sc_irs; 280 tcp_seq sc_iss; 281 u_int sc_rtableid; 282 u_int sc_rxtcur; /* current rxt timeout */ 283 u_int sc_rxttot; /* total time spend on queues */ 284 u_short sc_rxtshift; /* for computing backoff */ 285 u_short sc_flags; 286 287 #define SCF_UNREACH 0x0001 /* we've had an unreach error */ 288 #define SCF_TIMESTAMP 0x0002 /* peer will do timestamps */ 289 #define SCF_DEAD 0x0004 /* this entry to be released */ 290 #define SCF_SACK_PERMIT 0x0008 /* permit sack */ 291 #define SCF_ECN_PERMIT 0x0010 /* permit ecn */ 292 #define SCF_SIGNATURE 0x0020 /* enforce tcp signatures */ 293 294 struct mbuf *sc_ipopts; /* IP options */ 295 u_int16_t sc_peermaxseg; 296 u_int16_t sc_ourmaxseg; 297 u_int sc_request_r_scale : 4, 298 sc_requested_s_scale : 4; 299 300 struct tcpcb *sc_tp; /* tcb for listening socket */ 301 LIST_ENTRY(syn_cache) sc_tpq; /* list of entries by same tp */ 302 }; 303 304 struct syn_cache_head { 305 TAILQ_HEAD(, syn_cache) sch_bucket; /* bucket entries */ 306 u_short sch_length; /* # entries in bucket */ 307 }; 308 309 struct syn_cache_set { 310 struct syn_cache_head *scs_buckethead; 311 int scs_size; 312 int scs_count; 313 int scs_use; 314 u_int32_t scs_random[5]; 315 }; 316 317 #endif /* _KERNEL */ 318 319 /* 320 * The smoothed round-trip time and estimated variance 321 * are stored as fixed point numbers scaled by the values below. 322 * For convenience, these scales are also used in smoothing the average 323 * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed). 324 * With these scales, srtt has 5 bits to the right of the binary point, 325 * and thus an "ALPHA" of 0.875. rttvar has 4 bits to the right of the 326 * binary point, and is smoothed with an ALPHA of 0.75. 327 */ 328 #define TCP_RTT_SHIFT 3 /* shift for srtt; 5 bits frac. */ 329 #define TCP_RTTVAR_SHIFT 2 /* shift for rttvar; 4 bits */ 330 #define TCP_RTT_BASE_SHIFT 2 /* remaining 2 bit shift */ 331 #define TCP_RTT_MAX (1<<9) /* maximum rtt */ 332 333 /* 334 * The initial retransmission should happen at rtt + 4 * rttvar. 335 * Because of the way we do the smoothing, srtt and rttvar 336 * will each average +1/2 tick of bias. When we compute 337 * the retransmit timer, we want 1/2 tick of rounding and 338 * 1 extra tick because of +-1/2 tick uncertainty in the 339 * firing of the timer. The bias will give us exactly the 340 * 1.5 tick we need. But, because the bias is 341 * statistical, we have to test that we don't drop below 342 * the minimum feasible timer (which is 2 ticks). 343 * This macro assumes that the value of (1 << TCP_RTTVAR_SHIFT) 344 * is the same as the multiplier for rttvar. 345 */ 346 #define TCP_REXMTVAL(tp) \ 347 ((((tp)->t_srtt >> TCP_RTT_SHIFT) + (tp)->t_rttvar) >> TCP_RTT_BASE_SHIFT) 348 349 /* 350 * TCP statistics. 351 * Many of these should be kept per connection, 352 * but that's inconvenient at the moment. 353 */ 354 struct tcpstat { 355 u_int32_t tcps_connattempt; /* connections initiated */ 356 u_int32_t tcps_accepts; /* connections accepted */ 357 u_int32_t tcps_connects; /* connections established */ 358 u_int32_t tcps_drops; /* connections dropped */ 359 u_int32_t tcps_conndrops; /* embryonic connections dropped */ 360 u_int32_t tcps_closed; /* conn. closed (includes drops) */ 361 u_int32_t tcps_segstimed; /* segs where we tried to get rtt */ 362 u_int32_t tcps_rttupdated; /* times we succeeded */ 363 u_int32_t tcps_delack; /* delayed acks sent */ 364 u_int32_t tcps_timeoutdrop; /* conn. dropped in rxmt timeout */ 365 u_int32_t tcps_rexmttimeo; /* retransmit timeouts */ 366 u_int32_t tcps_persisttimeo; /* persist timeouts */ 367 u_int32_t tcps_persistdrop; /* connections dropped in persist */ 368 u_int32_t tcps_keeptimeo; /* keepalive timeouts */ 369 u_int32_t tcps_keepprobe; /* keepalive probes sent */ 370 u_int32_t tcps_keepdrops; /* connections dropped in keepalive */ 371 372 u_int32_t tcps_sndtotal; /* total packets sent */ 373 u_int32_t tcps_sndpack; /* data packets sent */ 374 u_int64_t tcps_sndbyte; /* data bytes sent */ 375 u_int32_t tcps_sndrexmitpack; /* data packets retransmitted */ 376 u_int64_t tcps_sndrexmitbyte; /* data bytes retransmitted */ 377 u_int64_t tcps_sndrexmitfast; /* Fast retransmits */ 378 u_int32_t tcps_sndacks; /* ack-only packets sent */ 379 u_int32_t tcps_sndprobe; /* window probes sent */ 380 u_int32_t tcps_sndurg; /* packets sent with URG only */ 381 u_int32_t tcps_sndwinup; /* window update-only packets sent */ 382 u_int32_t tcps_sndctrl; /* control (SYN|FIN|RST) packets sent */ 383 384 u_int32_t tcps_rcvtotal; /* total packets received */ 385 u_int32_t tcps_rcvpack; /* packets received in sequence */ 386 u_int64_t tcps_rcvbyte; /* bytes received in sequence */ 387 u_int32_t tcps_rcvbadsum; /* packets received with ccksum errs */ 388 u_int32_t tcps_rcvbadoff; /* packets received with bad offset */ 389 u_int32_t tcps_rcvmemdrop; /* packets dropped for lack of memory */ 390 u_int32_t tcps_rcvnosec; /* packets dropped for lack of ipsec */ 391 u_int32_t tcps_rcvshort; /* packets received too short */ 392 u_int32_t tcps_rcvduppack; /* duplicate-only packets received */ 393 u_int64_t tcps_rcvdupbyte; /* duplicate-only bytes received */ 394 u_int32_t tcps_rcvpartduppack; /* packets with some duplicate data */ 395 u_int64_t tcps_rcvpartdupbyte; /* dup. bytes in part-dup. packets */ 396 u_int32_t tcps_rcvoopack; /* out-of-order packets received */ 397 u_int64_t tcps_rcvoobyte; /* out-of-order bytes received */ 398 u_int32_t tcps_rcvpackafterwin; /* packets with data after window */ 399 u_int64_t tcps_rcvbyteafterwin; /* bytes rcvd after window */ 400 u_int32_t tcps_rcvafterclose; /* packets rcvd after "close" */ 401 u_int32_t tcps_rcvwinprobe; /* rcvd window probe packets */ 402 u_int32_t tcps_rcvdupack; /* rcvd duplicate acks */ 403 u_int32_t tcps_rcvacktoomuch; /* rcvd acks for unsent data */ 404 u_int32_t tcps_rcvacktooold; /* rcvd acks for old data */ 405 u_int32_t tcps_rcvackpack; /* rcvd ack packets */ 406 u_int64_t tcps_rcvackbyte; /* bytes acked by rcvd acks */ 407 u_int32_t tcps_rcvwinupd; /* rcvd window update packets */ 408 u_int32_t tcps_pawsdrop; /* segments dropped due to PAWS */ 409 u_int32_t tcps_predack; /* times hdr predict ok for acks */ 410 u_int32_t tcps_preddat; /* times hdr predict ok for data pkts */ 411 412 u_int32_t tcps_pcbhashmiss; /* input packets missing pcb hash */ 413 u_int32_t tcps_noport; /* no socket on port */ 414 u_int32_t tcps_badsyn; /* SYN packet with src==dst rcv'ed */ 415 u_int32_t tcps_dropsyn; /* SYN packet dropped */ 416 417 u_int32_t tcps_rcvbadsig; /* rcvd bad/missing TCP signatures */ 418 u_int64_t tcps_rcvgoodsig; /* rcvd good TCP signatures */ 419 u_int32_t tcps_inswcsum; /* input software-checksummed packets */ 420 u_int32_t tcps_outswcsum; /* output software-checksummed packets */ 421 422 /* ECN stats */ 423 u_int32_t tcps_ecn_accepts; /* ecn connections accepted */ 424 u_int32_t tcps_ecn_rcvece; /* # of rcvd ece */ 425 u_int32_t tcps_ecn_rcvcwr; /* # of rcvd cwr */ 426 u_int32_t tcps_ecn_rcvce; /* # of rcvd ce in ip header */ 427 u_int32_t tcps_ecn_sndect; /* # of cwr sent */ 428 u_int32_t tcps_ecn_sndece; /* # of ece sent */ 429 u_int32_t tcps_ecn_sndcwr; /* # of cwr sent */ 430 u_int32_t tcps_cwr_ecn; /* # of cwnd reduced by ecn */ 431 u_int32_t tcps_cwr_frecovery; /* # of cwnd reduced by fastrecovery */ 432 u_int32_t tcps_cwr_timeout; /* # of cwnd reduced by timeout */ 433 434 /* These statistics deal with the SYN cache. */ 435 u_int64_t tcps_sc_added; /* # of entries added */ 436 u_int64_t tcps_sc_completed; /* # of connections completed */ 437 u_int64_t tcps_sc_timed_out; /* # of entries timed out */ 438 u_int64_t tcps_sc_overflowed; /* # dropped due to overflow */ 439 u_int64_t tcps_sc_reset; /* # dropped due to RST */ 440 u_int64_t tcps_sc_unreach; /* # dropped due to ICMP unreach */ 441 u_int64_t tcps_sc_bucketoverflow;/* # dropped due to bucket overflow */ 442 u_int64_t tcps_sc_aborted; /* # of entries aborted (no mem) */ 443 u_int64_t tcps_sc_dupesyn; /* # of duplicate SYNs received */ 444 u_int64_t tcps_sc_dropped; /* # of SYNs dropped (no route/mem) */ 445 u_int64_t tcps_sc_collisions; /* # of hash collisions */ 446 u_int64_t tcps_sc_retransmitted;/* # of retransmissions */ 447 u_int64_t tcps_sc_seedrandom; /* # of syn cache seeds with random */ 448 u_int64_t tcps_sc_hash_size; /* hash buckets in current syn cache */ 449 u_int64_t tcps_sc_entry_count; /* # of entries in current syn cache */ 450 u_int64_t tcps_sc_entry_limit; /* limit of syn cache entries */ 451 u_int64_t tcps_sc_bucket_maxlen;/* maximum # of entries in any bucket */ 452 u_int64_t tcps_sc_bucket_limit; /* limit of syn cache bucket list */ 453 u_int64_t tcps_sc_uses_left; /* use counter of current syn cache */ 454 455 u_int64_t tcps_conndrained; /* # of connections drained */ 456 457 u_int64_t tcps_sack_recovery_episode; /* SACK recovery episodes */ 458 u_int64_t tcps_sack_rexmits; /* SACK rexmit segments */ 459 u_int64_t tcps_sack_rexmit_bytes; /* SACK rexmit bytes */ 460 u_int64_t tcps_sack_rcv_opts; /* SACK options received */ 461 u_int64_t tcps_sack_snd_opts; /* SACK options sent */ 462 }; 463 464 /* 465 * Names for TCP sysctl objects. 466 */ 467 468 #define TCPCTL_RFC1323 1 /* enable/disable RFC1323 timestamps/scaling */ 469 #define TCPCTL_KEEPINITTIME 2 /* TCPT_KEEP value */ 470 #define TCPCTL_KEEPIDLE 3 /* allow tcp_keepidle to be changed */ 471 #define TCPCTL_KEEPINTVL 4 /* allow tcp_keepintvl to be changed */ 472 #define TCPCTL_SLOWHZ 5 /* return kernel idea of PR_SLOWHZ */ 473 #define TCPCTL_BADDYNAMIC 6 /* return bad dynamic port bitmap */ 474 #define TCPCTL_RECVSPACE 7 /* receive buffer space */ 475 #define TCPCTL_SENDSPACE 8 /* send buffer space */ 476 #define TCPCTL_IDENT 9 /* get connection owner */ 477 #define TCPCTL_SACK 10 /* selective acknowledgement, rfc 2018 */ 478 #define TCPCTL_MSSDFLT 11 /* Default maximum segment size */ 479 #define TCPCTL_RSTPPSLIMIT 12 /* RST pps limit */ 480 #define TCPCTL_ACK_ON_PUSH 13 /* ACK immediately on PUSH */ 481 #define TCPCTL_ECN 14 /* RFC3168 ECN */ 482 #define TCPCTL_SYN_CACHE_LIMIT 15 /* max size of comp. state engine */ 483 #define TCPCTL_SYN_BUCKET_LIMIT 16 /* max size of hash bucket */ 484 #define TCPCTL_RFC3390 17 /* enable/disable RFC3390 increased cwnd */ 485 #define TCPCTL_REASS_LIMIT 18 /* max entries for tcp reass queues */ 486 #define TCPCTL_DROP 19 /* drop tcp connection */ 487 #define TCPCTL_SACKHOLE_LIMIT 20 /* max entries for tcp sack queues */ 488 #define TCPCTL_STATS 21 /* TCP statistics */ 489 #define TCPCTL_ALWAYS_KEEPALIVE 22 /* assume SO_KEEPALIVE is always set */ 490 #define TCPCTL_SYN_USE_LIMIT 23 /* number of uses before reseeding hash */ 491 #define TCPCTL_ROOTONLY 24 /* return root only port bitmap */ 492 #define TCPCTL_SYN_HASH_SIZE 25 /* number of buckets in the hash */ 493 #define TCPCTL_MAXID 26 494 495 #define TCPCTL_NAMES { \ 496 { 0, 0 }, \ 497 { "rfc1323", CTLTYPE_INT }, \ 498 { "keepinittime", CTLTYPE_INT }, \ 499 { "keepidle", CTLTYPE_INT }, \ 500 { "keepintvl", CTLTYPE_INT }, \ 501 { "slowhz", CTLTYPE_INT }, \ 502 { "baddynamic", CTLTYPE_STRUCT }, \ 503 { NULL, 0 }, \ 504 { NULL, 0 }, \ 505 { "ident", CTLTYPE_STRUCT }, \ 506 { "sack", CTLTYPE_INT }, \ 507 { "mssdflt", CTLTYPE_INT }, \ 508 { "rstppslimit", CTLTYPE_INT }, \ 509 { "ackonpush", CTLTYPE_INT }, \ 510 { "ecn", CTLTYPE_INT }, \ 511 { "syncachelimit", CTLTYPE_INT }, \ 512 { "synbucketlimit", CTLTYPE_INT }, \ 513 { "rfc3390", CTLTYPE_INT }, \ 514 { "reasslimit", CTLTYPE_INT }, \ 515 { "drop", CTLTYPE_STRUCT }, \ 516 { "sackholelimit", CTLTYPE_INT }, \ 517 { "stats", CTLTYPE_STRUCT }, \ 518 { "always_keepalive", CTLTYPE_INT }, \ 519 { "synuselimit", CTLTYPE_INT }, \ 520 { "rootonly", CTLTYPE_STRUCT }, \ 521 { "synhashsize", CTLTYPE_INT }, \ 522 } 523 524 #define TCPCTL_VARS { \ 525 NULL, \ 526 &tcp_do_rfc1323, \ 527 &tcptv_keep_init, \ 528 &tcp_keepidle, \ 529 &tcp_keepintvl, \ 530 NULL, \ 531 NULL, \ 532 NULL, \ 533 NULL, \ 534 NULL, \ 535 NULL, \ 536 &tcp_mssdflt, \ 537 &tcp_rst_ppslim, \ 538 &tcp_ack_on_push, \ 539 NULL, \ 540 &tcp_syn_cache_limit, \ 541 &tcp_syn_bucket_limit, \ 542 &tcp_do_rfc3390, \ 543 NULL, \ 544 NULL, \ 545 NULL, \ 546 NULL, \ 547 NULL, \ 548 NULL, \ 549 NULL, \ 550 NULL \ 551 } 552 553 struct tcp_ident_mapping { 554 struct sockaddr_storage faddr, laddr; 555 int euid, ruid; 556 u_int rdomain; 557 }; 558 559 #ifdef _KERNEL 560 561 #include <sys/percpu.h> 562 563 enum tcpstat_counters { 564 tcps_connattempt, 565 tcps_accepts, 566 tcps_connects, 567 tcps_drops, 568 tcps_conndrops, 569 tcps_closed, 570 tcps_segstimed, 571 tcps_rttupdated, 572 tcps_delack, 573 tcps_timeoutdrop, 574 tcps_rexmttimeo, 575 tcps_persisttimeo, 576 tcps_persistdrop, 577 tcps_keeptimeo, 578 tcps_keepprobe, 579 tcps_keepdrops, 580 tcps_sndtotal, 581 tcps_sndpack, 582 tcps_sndbyte, 583 tcps_sndrexmitpack, 584 tcps_sndrexmitbyte, 585 tcps_sndrexmitfast, 586 tcps_sndacks, 587 tcps_sndprobe, 588 tcps_sndurg, 589 tcps_sndwinup, 590 tcps_sndctrl, 591 tcps_rcvtotal, 592 tcps_rcvpack, 593 tcps_rcvbyte, 594 tcps_rcvbadsum, 595 tcps_rcvbadoff, 596 tcps_rcvmemdrop, 597 tcps_rcvnosec, 598 tcps_rcvshort, 599 tcps_rcvduppack, 600 tcps_rcvdupbyte, 601 tcps_rcvpartduppack, 602 tcps_rcvpartdupbyte, 603 tcps_rcvoopack, 604 tcps_rcvoobyte, 605 tcps_rcvpackafterwin, 606 tcps_rcvbyteafterwin, 607 tcps_rcvafterclose, 608 tcps_rcvwinprobe, 609 tcps_rcvdupack, 610 tcps_rcvacktoomuch, 611 tcps_rcvacktooold, 612 tcps_rcvackpack, 613 tcps_rcvackbyte, 614 tcps_rcvwinupd, 615 tcps_pawsdrop, 616 tcps_predack, 617 tcps_preddat, 618 tcps_pcbhashmiss, 619 tcps_noport, 620 tcps_badsyn, 621 tcps_dropsyn, 622 tcps_rcvbadsig, 623 tcps_rcvgoodsig, 624 tcps_inswcsum, 625 tcps_outswcsum, 626 tcps_ecn_accepts, 627 tcps_ecn_rcvece, 628 tcps_ecn_rcvcwr, 629 tcps_ecn_rcvce, 630 tcps_ecn_sndect, 631 tcps_ecn_sndece, 632 tcps_ecn_sndcwr, 633 tcps_cwr_ecn, 634 tcps_cwr_frecovery, 635 tcps_cwr_timeout, 636 tcps_sc_added, 637 tcps_sc_completed, 638 tcps_sc_timed_out, 639 tcps_sc_overflowed, 640 tcps_sc_reset, 641 tcps_sc_unreach, 642 tcps_sc_bucketoverflow, 643 tcps_sc_aborted, 644 tcps_sc_dupesyn, 645 tcps_sc_dropped, 646 tcps_sc_collisions, 647 tcps_sc_retransmitted, 648 tcps_sc_seedrandom, 649 tcps_sc_hash_size, 650 tcps_sc_entry_count, 651 tcps_sc_entry_limit, 652 tcps_sc_bucket_maxlen, 653 tcps_sc_bucket_limit, 654 tcps_sc_uses_left, 655 tcps_conndrained, 656 tcps_sack_recovery_episode, 657 tcps_sack_rexmits, 658 tcps_sack_rexmit_bytes, 659 tcps_sack_rcv_opts, 660 tcps_sack_snd_opts, 661 tcps_ncounters, 662 }; 663 664 extern struct cpumem *tcpcounters; 665 666 static inline void 667 tcpstat_inc(enum tcpstat_counters c) 668 { 669 counters_inc(tcpcounters, c); 670 } 671 672 static inline void 673 tcpstat_add(enum tcpstat_counters c, uint64_t v) 674 { 675 counters_add(tcpcounters, c, v); 676 } 677 678 static inline void 679 tcpstat_pkt(enum tcpstat_counters pcounter, enum tcpstat_counters bcounter, 680 uint64_t v) 681 { 682 counters_pkt(tcpcounters, pcounter, bcounter, v); 683 } 684 685 extern struct pool tcpcb_pool; 686 extern struct inpcbtable tcbtable; /* head of queue of active tcpcb's */ 687 extern u_int32_t tcp_now; /* for RFC 1323 timestamps */ 688 extern int tcp_do_rfc1323; /* enabled/disabled? */ 689 extern int tcptv_keep_init; /* time to keep alive the initial SYN packet */ 690 extern int tcp_mssdflt; /* default maximum segment size */ 691 extern int tcp_rst_ppslim; /* maximum outgoing RST packet per second */ 692 extern int tcp_ack_on_push; /* ACK immediately on PUSH */ 693 extern int tcp_do_sack; /* SACK enabled/disabled */ 694 extern struct pool sackhl_pool; 695 extern int tcp_sackhole_limit; /* max entries for tcp sack queues */ 696 extern int tcp_do_ecn; /* RFC3168 ECN enabled/disabled? */ 697 extern int tcp_do_rfc3390; /* RFC3390 Increasing TCP's Initial Window */ 698 699 extern struct pool tcpqe_pool; 700 extern int tcp_reass_limit; /* max entries for tcp reass queues */ 701 702 extern int tcp_syn_hash_size; /* adjustable size of the hash array */ 703 extern int tcp_syn_cache_limit; /* max entries for compressed state engine */ 704 extern int tcp_syn_bucket_limit;/* max entries per hash bucket */ 705 extern int tcp_syn_use_limit; /* number of uses before reseeding hash */ 706 extern struct syn_cache_set tcp_syn_cache[]; 707 extern int tcp_syn_cache_active; /* active syn cache, may be 0 or 1 */ 708 709 void tcp_canceltimers(struct tcpcb *); 710 struct tcpcb * 711 tcp_close(struct tcpcb *); 712 int tcp_freeq(struct tcpcb *); 713 #ifdef INET6 714 void tcp6_ctlinput(int, struct sockaddr *, u_int, void *); 715 #endif 716 void tcp_ctlinput(int, struct sockaddr *, u_int, void *); 717 int tcp_ctloutput(int, struct socket *, int, int, struct mbuf *); 718 struct tcpcb * 719 tcp_disconnect(struct tcpcb *); 720 struct tcpcb * 721 tcp_drop(struct tcpcb *, int); 722 int tcp_dooptions(struct tcpcb *, u_char *, int, struct tcphdr *, 723 struct mbuf *, int, struct tcp_opt_info *, u_int); 724 void tcp_init(void); 725 int tcp_input(struct mbuf **, int *, int, int); 726 int tcp_mss(struct tcpcb *, int); 727 void tcp_mss_update(struct tcpcb *); 728 u_int tcp_hdrsz(struct tcpcb *); 729 void tcp_mtudisc(struct inpcb *, int); 730 void tcp_mtudisc_increase(struct inpcb *, int); 731 #ifdef INET6 732 void tcp6_mtudisc(struct inpcb *, int); 733 void tcp6_mtudisc_callback(struct sockaddr_in6 *, u_int); 734 #endif 735 struct tcpcb * 736 tcp_newtcpcb(struct inpcb *); 737 void tcp_notify(struct inpcb *, int); 738 int tcp_output(struct tcpcb *); 739 void tcp_pulloutofband(struct socket *, u_int, struct mbuf *, int); 740 int tcp_reass(struct tcpcb *, struct tcphdr *, struct mbuf *, int *); 741 void tcp_rscale(struct tcpcb *, u_long); 742 void tcp_respond(struct tcpcb *, caddr_t, struct tcphdr *, tcp_seq, 743 tcp_seq, int, u_int); 744 void tcp_setpersist(struct tcpcb *); 745 void tcp_update_sndspace(struct tcpcb *); 746 void tcp_update_rcvspace(struct tcpcb *); 747 void tcp_slowtimo(void); 748 struct mbuf * 749 tcp_template(struct tcpcb *); 750 void tcp_trace(short, short, struct tcpcb *, caddr_t, int, int); 751 struct tcpcb * 752 tcp_usrclosed(struct tcpcb *); 753 int tcp_sysctl(int *, u_int, void *, size_t *, void *, size_t); 754 int tcp_usrreq(struct socket *, 755 int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); 756 int tcp_attach(struct socket *, int); 757 int tcp_detach(struct socket *); 758 void tcp_xmit_timer(struct tcpcb *, int); 759 void tcpdropoldhalfopen(struct tcpcb *, u_int16_t); 760 void tcp_sack_option(struct tcpcb *,struct tcphdr *,u_char *,int); 761 void tcp_update_sack_list(struct tcpcb *tp, tcp_seq, tcp_seq); 762 void tcp_del_sackholes(struct tcpcb *, struct tcphdr *); 763 void tcp_clean_sackreport(struct tcpcb *tp); 764 void tcp_sack_adjust(struct tcpcb *tp); 765 struct sackhole * 766 tcp_sack_output(struct tcpcb *tp); 767 #ifdef DEBUG 768 void tcp_print_holes(struct tcpcb *tp); 769 #endif 770 u_long tcp_seq_subtract(u_long, u_long ); 771 #ifdef TCP_SIGNATURE 772 int tcp_signature_apply(caddr_t, caddr_t, unsigned int); 773 int tcp_signature(struct tdb *, int, struct mbuf *, struct tcphdr *, 774 int, int, char *); 775 #endif /* TCP_SIGNATURE */ 776 void tcp_set_iss_tsm(struct tcpcb *); 777 778 void syn_cache_unreach(struct sockaddr *, struct sockaddr *, 779 struct tcphdr *, u_int); 780 void syn_cache_init(void); 781 void syn_cache_cleanup(struct tcpcb *); 782 783 #endif /* _KERNEL */ 784 #endif /* _NETINET_TCP_VAR_H_ */ 785