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