1 /* $OpenBSD: tcp_var.h,v 1.37 2001/06/23 06:03:13 angelos 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. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by the University of 19 * California, Berkeley and its contributors. 20 * 4. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * @(#)tcp_var.h 8.3 (Berkeley) 4/10/94 37 */ 38 39 #ifndef _NETINET_TCP_VAR_H_ 40 #define _NETINET_TCP_VAR_H_ 41 42 struct sackblk { 43 tcp_seq start; /* start seq no. of sack block */ 44 tcp_seq end; /* end seq no. */ 45 }; 46 47 struct sackhole { 48 tcp_seq start; /* start seq no. of hole */ 49 tcp_seq end; /* end seq no. */ 50 int dups; /* number of dup(s)acks for this hole */ 51 tcp_seq rxmit; /* next seq. no in hole to be retransmitted */ 52 struct sackhole *next; /* next in list */ 53 }; 54 55 /* 56 * Kernel variables for tcp. 57 */ 58 59 /* 60 * Tcp control block, one per tcp; fields: 61 */ 62 struct tcpcb { 63 struct ipqehead segq; /* sequencing queue */ 64 short t_state; /* state of this connection */ 65 short t_timer[TCPT_NTIMERS]; /* tcp timers */ 66 short t_rxtshift; /* log(2) of rexmt exp. backoff */ 67 short t_rxtcur; /* current retransmit value */ 68 short t_dupacks; /* consecutive dup acks recd */ 69 u_short t_maxseg; /* maximum segment size */ 70 char t_force; /* 1 if forcing out a byte */ 71 u_short t_flags; 72 #define TF_ACKNOW 0x0001 /* ack peer immediately */ 73 #define TF_DELACK 0x0002 /* ack, but try to delay it */ 74 #define TF_NODELAY 0x0004 /* don't delay packets to coalesce */ 75 #define TF_NOOPT 0x0008 /* don't use tcp options */ 76 #define TF_SENTFIN 0x0010 /* have sent FIN */ 77 #define TF_REQ_SCALE 0x0020 /* have/will request window scaling */ 78 #define TF_RCVD_SCALE 0x0040 /* other side has requested scaling */ 79 #define TF_REQ_TSTMP 0x0080 /* have/will request timestamps */ 80 #define TF_RCVD_TSTMP 0x0100 /* a timestamp was received in SYN */ 81 #define TF_SACK_PERMIT 0x0200 /* other side said I could SACK */ 82 #define TF_SIGNATURE 0x0400 /* require TCP MD5 signature */ 83 84 struct mbuf *t_template; /* skeletal packet for transmit */ 85 struct inpcb *t_inpcb; /* back pointer to internet pcb */ 86 /* 87 * The following fields are used as in the protocol specification. 88 * See RFC783, Dec. 1981, page 21. 89 */ 90 /* send sequence variables */ 91 tcp_seq snd_una; /* send unacknowledged */ 92 tcp_seq snd_nxt; /* send next */ 93 tcp_seq snd_up; /* send urgent pointer */ 94 tcp_seq snd_wl1; /* window update seg seq number */ 95 tcp_seq snd_wl2; /* window update seg ack number */ 96 tcp_seq iss; /* initial send sequence number */ 97 u_long snd_wnd; /* send window */ 98 #ifdef TCP_SACK 99 int sack_disable; /* disable SACK for this connection */ 100 int snd_numholes; /* number of holes seen by sender */ 101 struct sackhole *snd_holes; /* linked list of holes (sorted) */ 102 #if defined(TCP_SACK) && defined(TCP_FACK) 103 tcp_seq snd_fack; /* for FACK congestion control */ 104 u_long snd_awnd; /* snd_nxt - snd_fack + */ 105 /* retransmitted data */ 106 int retran_data; /* amount of outstanding retx. data */ 107 #endif /* TCP_FACK */ 108 #endif /* TCP_SACK */ 109 #if defined(TCP_SACK) 110 tcp_seq snd_last; /* for use in fast recovery */ 111 #endif 112 /* receive sequence variables */ 113 u_long rcv_wnd; /* receive window */ 114 tcp_seq rcv_nxt; /* receive next */ 115 tcp_seq rcv_up; /* receive urgent pointer */ 116 tcp_seq irs; /* initial receive sequence number */ 117 #ifdef TCP_SACK 118 tcp_seq rcv_laststart; /* start of last segment recd. */ 119 tcp_seq rcv_lastend; /* end of ... */ 120 tcp_seq rcv_lastsack; /* last seq number(+1) sack'd by rcv'r*/ 121 int rcv_numsacks; /* # distinct sack blks present */ 122 struct sackblk sackblks[MAX_SACK_BLKS]; /* seq nos. of sack blocks */ 123 #endif 124 125 /* 126 * Additional variables for this implementation. 127 */ 128 /* receive variables */ 129 tcp_seq rcv_adv; /* advertised window */ 130 /* retransmit variables */ 131 tcp_seq snd_max; /* highest sequence number sent; 132 * used to recognize retransmits 133 */ 134 /* congestion control (for slow start, source quench, retransmit after loss) */ 135 u_long snd_cwnd; /* congestion-controlled window */ 136 u_long snd_ssthresh; /* snd_cwnd size threshhold for 137 * for slow start exponential to 138 * linear switch 139 */ 140 u_short t_maxopd; /* mss plus options */ 141 u_short t_peermss; /* peer's maximum segment size */ 142 143 /* 144 * transmit timing stuff. See below for scale of srtt and rttvar. 145 * "Variance" is actually smoothed difference. 146 */ 147 short t_idle; /* inactivity time */ 148 short t_rtt; /* round trip time */ 149 tcp_seq t_rtseq; /* sequence number being timed */ 150 short t_srtt; /* smoothed round-trip time */ 151 short t_rttvar; /* variance in round-trip time */ 152 u_short t_rttmin; /* minimum rtt allowed */ 153 u_long max_sndwnd; /* largest window peer has offered */ 154 155 /* out-of-band data */ 156 char t_oobflags; /* have some */ 157 char t_iobc; /* input character */ 158 #define TCPOOB_HAVEDATA 0x01 159 #define TCPOOB_HADDATA 0x02 160 short t_softerror; /* possible error not yet reported */ 161 162 /* RFC 1323 variables */ 163 u_char snd_scale; /* window scaling for send window */ 164 u_char rcv_scale; /* window scaling for recv window */ 165 u_char request_r_scale; /* pending window scaling */ 166 u_char requested_s_scale; 167 u_int32_t ts_recent; /* timestamp echo data */ 168 u_int32_t ts_recent_age; /* when last updated */ 169 tcp_seq last_ack_sent; 170 171 /* TUBA stuff */ 172 caddr_t t_tuba_pcb; /* next level down pcb for TCP over z */ 173 174 int pf; 175 }; 176 177 #define intotcpcb(ip) ((struct tcpcb *)(ip)->inp_ppcb) 178 #define sototcpcb(so) (intotcpcb(sotoinpcb(so))) 179 180 /* 181 * The smoothed round-trip time and estimated variance 182 * are stored as fixed point numbers scaled by the values below. 183 * For convenience, these scales are also used in smoothing the average 184 * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed). 185 * With these scales, srtt has 3 bits to the right of the binary point, 186 * and thus an "ALPHA" of 0.875. rttvar has 2 bits to the right of the 187 * binary point, and is smoothed with an ALPHA of 0.75. 188 */ 189 #define TCP_RTT_SCALE 8 /* multiplier for srtt; 3 bits frac. */ 190 #define TCP_RTT_SHIFT 3 /* shift for srtt; 3 bits frac. */ 191 #define TCP_RTTVAR_SCALE 4 /* multiplier for rttvar; 2 bits */ 192 #define TCP_RTTVAR_SHIFT 2 /* multiplier for rttvar; 2 bits */ 193 194 /* 195 * The initial retransmission should happen at rtt + 4 * rttvar. 196 * Because of the way we do the smoothing, srtt and rttvar 197 * will each average +1/2 tick of bias. When we compute 198 * the retransmit timer, we want 1/2 tick of rounding and 199 * 1 extra tick because of +-1/2 tick uncertainty in the 200 * firing of the timer. The bias will give us exactly the 201 * 1.5 tick we need. But, because the bias is 202 * statistical, we have to test that we don't drop below 203 * the minimum feasible timer (which is 2 ticks). 204 * This macro assumes that the value of TCP_RTTVAR_SCALE 205 * is the same as the multiplier for rttvar. 206 */ 207 #define TCP_REXMTVAL(tp) \ 208 ((((tp)->t_srtt >> TCP_RTT_SHIFT) + (tp)->t_rttvar) >> 2) 209 210 /* 211 * TCP statistics. 212 * Many of these should be kept per connection, 213 * but that's inconvenient at the moment. 214 */ 215 struct tcpstat { 216 u_int32_t tcps_connattempt; /* connections initiated */ 217 u_int32_t tcps_accepts; /* connections accepted */ 218 u_int32_t tcps_connects; /* connections established */ 219 u_int32_t tcps_drops; /* connections dropped */ 220 u_int32_t tcps_conndrops; /* embryonic connections dropped */ 221 u_int32_t tcps_closed; /* conn. closed (includes drops) */ 222 u_int32_t tcps_segstimed; /* segs where we tried to get rtt */ 223 u_int32_t tcps_rttupdated; /* times we succeeded */ 224 u_int32_t tcps_delack; /* delayed acks sent */ 225 u_int32_t tcps_timeoutdrop; /* conn. dropped in rxmt timeout */ 226 u_int32_t tcps_rexmttimeo; /* retransmit timeouts */ 227 u_int32_t tcps_persisttimeo; /* persist timeouts */ 228 u_int32_t tcps_persistdrop; /* connections dropped in persist */ 229 u_int32_t tcps_keeptimeo; /* keepalive timeouts */ 230 u_int32_t tcps_keepprobe; /* keepalive probes sent */ 231 u_int32_t tcps_keepdrops; /* connections dropped in keepalive */ 232 233 u_int32_t tcps_sndtotal; /* total packets sent */ 234 u_int32_t tcps_sndpack; /* data packets sent */ 235 u_int64_t tcps_sndbyte; /* data bytes sent */ 236 u_int32_t tcps_sndrexmitpack; /* data packets retransmitted */ 237 u_int64_t tcps_sndrexmitbyte; /* data bytes retransmitted */ 238 u_int64_t tcps_sndrexmitfast; /* Fast retransmits */ 239 u_int32_t tcps_sndacks; /* ack-only packets sent */ 240 u_int32_t tcps_sndprobe; /* window probes sent */ 241 u_int32_t tcps_sndurg; /* packets sent with URG only */ 242 u_int32_t tcps_sndwinup; /* window update-only packets sent */ 243 u_int32_t tcps_sndctrl; /* control (SYN|FIN|RST) packets sent */ 244 245 u_int32_t tcps_rcvtotal; /* total packets received */ 246 u_int32_t tcps_rcvpack; /* packets received in sequence */ 247 u_int64_t tcps_rcvbyte; /* bytes received in sequence */ 248 u_int32_t tcps_rcvbadsum; /* packets received with ccksum errs */ 249 u_int32_t tcps_rcvbadoff; /* packets received with bad offset */ 250 u_int32_t tcps_rcvmemdrop; /* packets dropped for lack of memory */ 251 u_int32_t tcps_rcvnosec; /* packets dropped for lack of ipsec */ 252 u_int32_t tcps_rcvshort; /* packets received too short */ 253 u_int32_t tcps_rcvduppack; /* duplicate-only packets received */ 254 u_int64_t tcps_rcvdupbyte; /* duplicate-only bytes received */ 255 u_int32_t tcps_rcvpartduppack; /* packets with some duplicate data */ 256 u_int64_t tcps_rcvpartdupbyte; /* dup. bytes in part-dup. packets */ 257 u_int32_t tcps_rcvoopack; /* out-of-order packets received */ 258 u_int64_t tcps_rcvoobyte; /* out-of-order bytes received */ 259 u_int32_t tcps_rcvpackafterwin; /* packets with data after window */ 260 u_int64_t tcps_rcvbyteafterwin; /* bytes rcvd after window */ 261 u_int32_t tcps_rcvafterclose; /* packets rcvd after "close" */ 262 u_int32_t tcps_rcvwinprobe; /* rcvd window probe packets */ 263 u_int32_t tcps_rcvdupack; /* rcvd duplicate acks */ 264 u_int32_t tcps_rcvacktoomuch; /* rcvd acks for unsent data */ 265 u_int32_t tcps_rcvackpack; /* rcvd ack packets */ 266 u_int64_t tcps_rcvackbyte; /* bytes acked by rcvd acks */ 267 u_int32_t tcps_rcvwinupd; /* rcvd window update packets */ 268 u_int32_t tcps_pawsdrop; /* segments dropped due to PAWS */ 269 u_int32_t tcps_predack; /* times hdr predict ok for acks */ 270 u_int32_t tcps_preddat; /* times hdr predict ok for data pkts */ 271 272 u_int32_t tcps_pcbhashmiss; /* input packets missing pcb hash */ 273 u_int32_t tcps_noport; /* no socket on port */ 274 u_int32_t tcps_badsyn; /* SYN packet with src==dst rcv'ed */ 275 276 u_int32_t tcps_rcvbadsig; /* rcvd bad/missing TCP signatures */ 277 u_int64_t tcps_rcvgoodsig; /* rcvd good TCP signatures */ 278 u_int32_t tcps_inhwcsum; /* input hardware-checksummed packets */ 279 u_int32_t tcps_outhwcsum; /* output hardware-checksummed packets */ 280 }; 281 282 /* 283 * Names for TCP sysctl objects. 284 */ 285 286 #define TCPCTL_RFC1323 1 /* enable/disable RFC1323 timestamps/scaling */ 287 #define TCPCTL_KEEPINITTIME 2 /* TCPT_KEEP value */ 288 #define TCPCTL_KEEPIDLE 3 /* allow tcp_keepidle to be changed */ 289 #define TCPCTL_KEEPINTVL 4 /* allow tcp_keepintvl to be changed */ 290 #define TCPCTL_SLOWHZ 5 /* return kernel idea of PR_SLOWHZ */ 291 #define TCPCTL_BADDYNAMIC 6 /* return bad dynamic port bitmap */ 292 #define TCPCTL_RECVSPACE 7 /* receive buffer space */ 293 #define TCPCTL_SENDSPACE 8 /* send buffer space */ 294 #define TCPCTL_IDENT 9 /* get connection owner */ 295 #define TCPCTL_SACK 10 /* selective acknowledgement, rfc 2018 */ 296 #define TCPCTL_MSSDFLT 11 /* Default maximum segment size */ 297 #define TCPCTL_RSTPPSLIMIT 12 /* RST pps limit */ 298 #define TCPCTL_MAXID 13 299 300 #define TCPCTL_NAMES { \ 301 { 0, 0 }, \ 302 { "rfc1323", CTLTYPE_INT }, \ 303 { "keepinittime", CTLTYPE_INT }, \ 304 { "keepidle", CTLTYPE_INT }, \ 305 { "keepintvl", CTLTYPE_INT }, \ 306 { "slowhz", CTLTYPE_INT }, \ 307 { "baddynamic", CTLTYPE_STRUCT }, \ 308 { "recvspace", CTLTYPE_INT }, \ 309 { "sendspace", CTLTYPE_INT }, \ 310 { "ident", CTLTYPE_STRUCT }, \ 311 { "sack", CTLTYPE_INT }, \ 312 { "mssdflt", CTLTYPE_INT }, \ 313 { "rstppslimit", CTLTYPE_INT }, \ 314 } 315 316 struct tcp_ident_mapping { 317 struct sockaddr_storage faddr, laddr; 318 int euid, ruid; 319 }; 320 321 #ifdef _KERNEL 322 struct inpcbtable tcbtable; /* head of queue of active tcpcb's */ 323 extern struct tcpstat tcpstat; /* tcp statistics */ 324 u_int32_t tcp_now; /* for RFC 1323 timestamps */ 325 extern int tcp_do_rfc1323; /* enabled/disabled? */ 326 extern int tcp_mssdflt; /* default maximum segment size */ 327 #ifdef TCP_SACK 328 extern int tcp_do_sack; /* SACK enabled/disabled */ 329 #endif 330 331 int tcp_attach __P((struct socket *)); 332 void tcp_canceltimers __P((struct tcpcb *)); 333 struct tcpcb * 334 tcp_close __P((struct tcpcb *)); 335 #if defined(INET6) && !defined(TCP6) 336 void tcp6_ctlinput __P((int, struct sockaddr *, void *)); 337 #endif 338 void *tcp_ctlinput __P((int, struct sockaddr *, void *)); 339 int tcp_ctloutput __P((int, struct socket *, int, int, struct mbuf **)); 340 struct tcpcb * 341 tcp_disconnect __P((struct tcpcb *)); 342 struct tcpcb * 343 tcp_drop __P((struct tcpcb *, int)); 344 void tcp_dooptions __P((struct tcpcb *, u_char *, int, struct tcphdr *, 345 int *, u_int32_t *, u_int32_t *)); 346 void tcp_drain __P((void)); 347 void tcp_fasttimo __P((void)); 348 void tcp_init __P((void)); 349 #if defined(INET6) && !defined(TCP6) 350 int tcp6_input __P((struct mbuf **, int *, int)); 351 #endif 352 void tcp_input __P((struct mbuf *, ...)); 353 int tcp_mss __P((struct tcpcb *, int)); 354 void tcp_mss_update __P((struct tcpcb *)); 355 void tcp_mtudisc __P((struct inpcb *, int)); 356 void tcp_mtudisc_increase __P((struct inpcb *, int)); 357 #ifdef INET6 358 void tcp6_mtudisc __P((struct inpcb *, int)); 359 void tcp6_mtudisc_callback __P((struct in6_addr *)); 360 #endif 361 struct tcpcb * 362 tcp_newtcpcb __P((struct inpcb *)); 363 void tcp_notify __P((struct inpcb *, int)); 364 int tcp_output __P((struct tcpcb *)); 365 void tcp_pulloutofband __P((struct socket *, u_int, struct mbuf *, int)); 366 void tcp_quench __P((struct inpcb *, int)); 367 int tcp_reass __P((struct tcpcb *, struct tcphdr *, struct mbuf *, int *)); 368 void tcp_rscale __P((struct tcpcb *, u_long)); 369 void tcp_respond __P((struct tcpcb *, caddr_t, struct mbuf *, tcp_seq, 370 tcp_seq, int)); 371 void tcp_setpersist __P((struct tcpcb *)); 372 void tcp_slowtimo __P((void)); 373 struct mbuf * 374 tcp_template __P((struct tcpcb *)); 375 struct tcpcb * 376 tcp_timers __P((struct tcpcb *, int)); 377 void tcp_trace __P((int, int, struct tcpcb *, caddr_t, int, int)); 378 struct tcpcb * 379 tcp_usrclosed __P((struct tcpcb *)); 380 int tcp_sysctl __P((int *, u_int, void *, size_t *, void *, size_t)); 381 #if defined(INET6) && !defined(TCP6) 382 int tcp6_usrreq __P((struct socket *, 383 int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *)); 384 #endif 385 int tcp_usrreq __P((struct socket *, 386 int, struct mbuf *, struct mbuf *, struct mbuf *)); 387 void tcp_xmit_timer __P((struct tcpcb *, int)); 388 void tcpdropoldhalfopen __P((struct tcpcb *, u_int16_t)); 389 #ifdef TCP_SACK 390 int tcp_sack_option __P((struct tcpcb *,struct tcphdr *,u_char *,int)); 391 void tcp_update_sack_list __P((struct tcpcb *tp)); 392 void tcp_del_sackholes __P((struct tcpcb *, struct tcphdr *)); 393 void tcp_clean_sackreport __P((struct tcpcb *tp)); 394 void tcp_sack_adjust __P((struct tcpcb *tp)); 395 struct sackhole * 396 tcp_sack_output __P((struct tcpcb *tp)); 397 int tcp_sack_partialack __P((struct tcpcb *, struct tcphdr *)); 398 #ifdef DEBUG 399 void tcp_print_holes __P((struct tcpcb *tp)); 400 #endif 401 #endif /* TCP_SACK */ 402 #if defined(TCP_SACK) 403 int tcp_newreno __P((struct tcpcb *, struct tcphdr *)); 404 u_long tcp_seq_subtract __P((u_long, u_long )); 405 #endif /* TCP_SACK */ 406 #ifdef TCP_SIGNATURE 407 int tcp_signature_apply __P((caddr_t, caddr_t, unsigned int)); 408 #endif /* TCP_SIGNATURE */ 409 void tcp_rndiss_init __P((void)); 410 tcp_seq tcp_rndiss_next __P((void)); 411 u_int16_t 412 tcp_rndiss_encrypt __P((u_int16_t)); 413 #endif /* _KERNEL */ 414 #endif /* _NETINET_TCP_VAR_H_ */ 415