tcp_var.h revision 195654
1139823Simp/*- 210937Swollman * Copyright (c) 1982, 1986, 1993, 1994, 1995 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 4. Neither the name of the University nor the names of its contributors 141541Srgrimes * may be used to endorse or promote products derived from this software 151541Srgrimes * without specific prior written permission. 161541Srgrimes * 171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271541Srgrimes * SUCH DAMAGE. 281541Srgrimes * 2910937Swollman * @(#)tcp_var.h 8.4 (Berkeley) 5/24/95 3050477Speter * $FreeBSD: head/sys/netinet/tcp_var.h 195654 2009-07-13 11:51:02Z lstewart $ 311541Srgrimes */ 321541Srgrimes 332169Spaul#ifndef _NETINET_TCP_VAR_H_ 342169Spaul#define _NETINET_TCP_VAR_H_ 3586764Sjlemon 3698102Shsu#include <netinet/tcp.h> 3786764Sjlemon 38191688Szecstruct vnet; 39191688Szec 401541Srgrimes/* 411541Srgrimes * Kernel variables for tcp. 421541Srgrimes */ 43186048Sbz#ifdef VIMAGE_GLOBALS 4486764Sjlemonextern int tcp_do_rfc1323; 45186048Sbz#endif 461541Srgrimes 4755679Sshin/* TCP segment queue entry */ 4855679Sshinstruct tseg_qent { 4960938Sjake LIST_ENTRY(tseg_qent) tqe_q; 5055679Sshin int tqe_len; /* TCP segment data length */ 5155679Sshin struct tcphdr *tqe_th; /* a pointer to tcp header */ 5255679Sshin struct mbuf *tqe_m; /* mbuf contains packet */ 5355679Sshin}; 5460938SjakeLIST_HEAD(tsegqe_head, tseg_qent); 55186048Sbz#ifdef VIMAGE_GLOBALS 56126193Sandreextern int tcp_reass_qsize; 57186048Sbz#endif 58126225Sbdeextern struct uma_zone *tcp_reass_zone; 5955679Sshin 60130989Spsstruct sackblk { 61130989Sps tcp_seq start; /* start seq no. of sack block */ 62131078Sbms tcp_seq end; /* end seq no. */ 63130989Sps}; 64130989Sps 65130989Spsstruct sackhole { 66130989Sps tcp_seq start; /* start seq no. of hole */ 67130989Sps tcp_seq end; /* end seq no. */ 68130989Sps tcp_seq rxmit; /* next seq. no in hole to be retransmitted */ 69145370Sps TAILQ_ENTRY(sackhole) scblink; /* scoreboard linkage */ 70130989Sps}; 71131078Sbms 72146123Spsstruct sackhint { 73146123Sps struct sackhole *nexthole; 74146123Sps int sack_bytes_rexmit; 75195634Slstewart 76195634Slstewart int ispare; /* explicit pad for 64bit alignment */ 77195634Slstewart uint64_t _pad[2]; /* 1 sacked_bytes, 1 TBD */ 78146123Sps}; 79146123Sps 8055679Sshinstruct tcptemp { 8155679Sshin u_char tt_ipgen[40]; /* the size must be of max ip header, now IPv6 */ 8255679Sshin struct tcphdr tt_t; 8355679Sshin}; 8455679Sshin 8555679Sshin#define tcp6cb tcpcb /* for KAME src sync over BSD*'s */ 8655679Sshin 87169541Sandre/* Neighbor Discovery, Neighbor Unreachability Detection Upper layer hint. */ 88169541Sandre#ifdef INET6 89169541Sandre#define ND6_HINT(tp) \ 90169541Sandredo { \ 91169541Sandre if ((tp) && (tp)->t_inpcb && \ 92169541Sandre ((tp)->t_inpcb->inp_vflag & INP_IPV6) != 0) \ 93169541Sandre nd6_nud_hint(NULL, NULL, 0); \ 94169541Sandre} while (0) 95169541Sandre#else 96169541Sandre#define ND6_HINT(tp) 97169541Sandre#endif 98169541Sandre 991541Srgrimes/* 1001541Srgrimes * Tcp control block, one per tcp; fields: 10132821Sdg * Organized for 16 byte cacheline efficiency. 1021541Srgrimes */ 1031541Srgrimesstruct tcpcb { 104126193Sandre struct tsegqe_head t_segq; /* segment reassembly queue */ 105195634Slstewart void *t_pspare[2]; /* new reassembly queue */ 106126193Sandre int t_segqlen; /* segment reassembly queue length */ 10732821Sdg int t_dupacks; /* consecutive dup acks recd */ 10832821Sdg 109172309Ssilby struct tcp_timer *t_timers; /* All the TCP timers in one struct */ 11032821Sdg 11132821Sdg struct inpcb *t_inpcb; /* back pointer to internet pcb */ 11211187Swollman int t_state; /* state of this connection */ 11311187Swollman u_int t_flags; 1141541Srgrimes 115191688Szec struct vnet *t_vnet; /* back pointer to parent vnet */ 116191688Szec 1171541Srgrimes tcp_seq snd_una; /* send unacknowledged */ 11832821Sdg tcp_seq snd_max; /* highest sequence number sent; 11932821Sdg * used to recognize retransmits 12032821Sdg */ 1211541Srgrimes tcp_seq snd_nxt; /* send next */ 1221541Srgrimes tcp_seq snd_up; /* send urgent pointer */ 12332821Sdg 1241541Srgrimes tcp_seq snd_wl1; /* window update seg seq number */ 1251541Srgrimes tcp_seq snd_wl2; /* window update seg ack number */ 1261541Srgrimes tcp_seq iss; /* initial send sequence number */ 12732821Sdg tcp_seq irs; /* initial receive sequence number */ 12832821Sdg 12932821Sdg tcp_seq rcv_nxt; /* receive next */ 13032821Sdg tcp_seq rcv_adv; /* advertised window */ 1311541Srgrimes u_long rcv_wnd; /* receive window */ 1321541Srgrimes tcp_seq rcv_up; /* receive urgent pointer */ 13332821Sdg 13432821Sdg u_long snd_wnd; /* send window */ 1351541Srgrimes u_long snd_cwnd; /* congestion-controlled window */ 136102017Sdillon u_long snd_bwnd; /* bandwidth-controlled window */ 13713765Smpp u_long snd_ssthresh; /* snd_cwnd size threshold for 1381541Srgrimes * for slow start exponential to 1391541Srgrimes * linear switch 1401541Srgrimes */ 141102017Sdillon u_long snd_bandwidth; /* calculated bandwidth or 0 */ 142109175Shsu tcp_seq snd_recover; /* for use in NewReno Fast Recovery */ 14360067Sjlemon 14432821Sdg u_int t_maxopd; /* mss plus options */ 14532821Sdg 146194303Sjhb u_int t_rcvtime; /* inactivity time */ 147194303Sjhb u_int t_starttime; /* time connection was established */ 148194303Sjhb u_int t_rtttime; /* RTT measurement start time */ 1491541Srgrimes tcp_seq t_rtseq; /* sequence number being timed */ 15032821Sdg 151194303Sjhb u_int t_bw_rtttime; /* used for bandwidth calculation */ 152102017Sdillon tcp_seq t_bw_rtseq; /* used for bandwidth calculation */ 153102017Sdillon 15450673Sjlemon int t_rxtcur; /* current retransmit value (ticks) */ 15532821Sdg u_int t_maxseg; /* maximum segment size */ 15611187Swollman int t_srtt; /* smoothed round-trip time */ 15711187Swollman int t_rttvar; /* variance in round-trip time */ 15832821Sdg 15932821Sdg int t_rxtshift; /* log(2) of rexmt exp. backoff */ 16011187Swollman u_int t_rttmin; /* minimum rtt allowed */ 161102017Sdillon u_int t_rttbest; /* best rtt we've seen */ 16232821Sdg u_long t_rttupdated; /* number of times rtt sampled */ 1631541Srgrimes u_long max_sndwnd; /* largest window peer has offered */ 1641541Srgrimes 16532821Sdg int t_softerror; /* possible error not yet reported */ 1661541Srgrimes/* out-of-band data */ 1671541Srgrimes char t_oobflags; /* have some */ 1681541Srgrimes char t_iobc; /* input character */ 1691541Srgrimes/* RFC 1323 variables */ 1701541Srgrimes u_char snd_scale; /* window scaling for send window */ 1711541Srgrimes u_char rcv_scale; /* window scaling for recv window */ 1721541Srgrimes u_char request_r_scale; /* pending window scaling */ 173162277Sandre u_int32_t ts_recent; /* timestamp echo data */ 174194303Sjhb u_int ts_recent_age; /* when last updated */ 175162277Sandre u_int32_t ts_offset; /* our timestamp offset */ 17632821Sdg 1771541Srgrimes tcp_seq last_ack_sent; 17850673Sjlemon/* experimental */ 17950673Sjlemon u_long snd_cwnd_prev; /* cwnd prior to retransmit */ 18050673Sjlemon u_long snd_ssthresh_prev; /* ssthresh prior to retransmit */ 181117650Shsu tcp_seq snd_recover_prev; /* snd_recover prior to retransmit */ 182194303Sjhb u_int t_badrxtwin; /* window for retransmit recovery */ 183112957Shsu u_char snd_limited; /* segments limited transmitted */ 184131078Sbms/* SACK related state */ 185130989Sps int snd_numholes; /* number of holes seen by sender */ 186146953Sps TAILQ_HEAD(sackhole_head, sackhole) snd_holes; 187146953Sps /* SACK scoreboard (sorted) */ 188146630Sps tcp_seq snd_fack; /* last seq number(+1) sack'd by rcv'r*/ 189130989Sps int rcv_numsacks; /* # distinct sack blks present */ 190130989Sps struct sackblk sackblks[MAX_SACK_BLKS]; /* seq nos. of sack blocks */ 191136151Sps tcp_seq sack_newdata; /* New data xmitted in this recovery 192136151Sps episode starts at this seq number */ 193146123Sps struct sackhint sackhint; /* SACK scoreboard hint */ 194155767Sandre int t_rttlow; /* smallest observerved RTT */ 195166405Sandre u_int32_t rfbuf_ts; /* recv buffer autoscaling timestamp */ 196166405Sandre int rfbuf_cnt; /* recv buffer autoscaling byte count */ 197191688Szec struct toe_usrreqs *t_tu; /* offload operations vector */ 198174560Skmacy void *t_toe; /* TOE pcb pointer */ 199187289Slstewart int t_bytes_acked; /* # bytes acked during current RTT */ 200195634Slstewart 201195634Slstewart int t_ispare; /* explicit pad for 64bit alignment */ 202195634Slstewart void *t_pspare2[6]; /* 2 CC / 4 TBD */ 203195634Slstewart uint64_t _pad[12]; /* 7 UTO, 5 TBD (1-2 CC/RTT?) */ 2041541Srgrimes}; 2051541Srgrimes 206185855Srwatson/* 207185855Srwatson * Flags and utility macros for the t_flags field. 208185855Srwatson */ 209185855Srwatson#define TF_ACKNOW 0x000001 /* ack peer immediately */ 210185855Srwatson#define TF_DELACK 0x000002 /* ack, but try to delay it */ 211185855Srwatson#define TF_NODELAY 0x000004 /* don't delay packets to coalesce */ 212185855Srwatson#define TF_NOOPT 0x000008 /* don't use tcp options */ 213185855Srwatson#define TF_SENTFIN 0x000010 /* have sent FIN */ 214185855Srwatson#define TF_REQ_SCALE 0x000020 /* have/will request window scaling */ 215185855Srwatson#define TF_RCVD_SCALE 0x000040 /* other side has requested scaling */ 216185855Srwatson#define TF_REQ_TSTMP 0x000080 /* have/will request timestamps */ 217185855Srwatson#define TF_RCVD_TSTMP 0x000100 /* a timestamp was received in SYN */ 218185855Srwatson#define TF_SACK_PERMIT 0x000200 /* other side said I could SACK */ 219185855Srwatson#define TF_NEEDSYN 0x000400 /* send SYN (implicit state) */ 220185855Srwatson#define TF_NEEDFIN 0x000800 /* send FIN (implicit state) */ 221185855Srwatson#define TF_NOPUSH 0x001000 /* don't push */ 222185855Srwatson#define TF_MORETOCOME 0x010000 /* More data to be appended to sock */ 223185855Srwatson#define TF_LQ_OVERFLOW 0x020000 /* listen queue overflow */ 224185855Srwatson#define TF_LASTIDLE 0x040000 /* connection was previously idle */ 225185855Srwatson#define TF_RXWIN0SENT 0x080000 /* sent a receiver win 0 in response */ 226185855Srwatson#define TF_FASTRECOVERY 0x100000 /* in NewReno Fast Recovery */ 227185855Srwatson#define TF_WASFRECOVERY 0x200000 /* was in NewReno Fast Recovery */ 228185855Srwatson#define TF_SIGNATURE 0x400000 /* require MD5 digests (RFC2385) */ 229185855Srwatson#define TF_FORCEDATA 0x800000 /* force out a byte */ 230185855Srwatson#define TF_TSO 0x1000000 /* TSO enabled on this connection */ 231185855Srwatson#define TF_TOE 0x2000000 /* this connection is offloaded */ 232185855Srwatson#define TF_ECN_PERMIT 0x4000000 /* connection ECN-ready */ 233185855Srwatson#define TF_ECN_SND_CWR 0x8000000 /* ECN CWR in queue */ 234185855Srwatson#define TF_ECN_SND_ECE 0x10000000 /* ECN ECE in queue */ 235185855Srwatson 236117650Shsu#define IN_FASTRECOVERY(tp) (tp->t_flags & TF_FASTRECOVERY) 237117650Shsu#define ENTER_FASTRECOVERY(tp) tp->t_flags |= TF_FASTRECOVERY 238117650Shsu#define EXIT_FASTRECOVERY(tp) tp->t_flags &= ~TF_FASTRECOVERY 239117650Shsu 240185855Srwatson/* 241185855Srwatson * Flags for the t_oobflags field. 242185855Srwatson */ 243185855Srwatson#define TCPOOB_HAVEDATA 0x01 244185855Srwatson#define TCPOOB_HADDATA 0x02 245185855Srwatson 246125680Sbms#ifdef TCP_SIGNATURE 2476247Swollman/* 248125680Sbms * Defines which are needed by the xform_tcp module and tcp_[in|out]put 249125680Sbms * for SADB verification and lookup. 250125680Sbms */ 251125680Sbms#define TCP_SIGLEN 16 /* length of computed digest in bytes */ 252125680Sbms#define TCP_KEYLEN_MIN 1 /* minimum length of TCP-MD5 key */ 253125680Sbms#define TCP_KEYLEN_MAX 80 /* maximum length of TCP-MD5 key */ 254125680Sbms/* 255125680Sbms * Only a single SA per host may be specified at this time. An SPI is 256125680Sbms * needed in order for the KEY_ALLOCSA() lookup to work. 257125680Sbms */ 258125680Sbms#define TCP_SIG_SPI 0x1000 259125680Sbms#endif /* TCP_SIGNATURE */ 260125680Sbms 261125680Sbms/* 2626247Swollman * Structure to hold TCP options that are only used during segment 2636247Swollman * processing (in tcp_input), but not held in the tcpcb. 2646247Swollman * It's basically used to reduce the number of parameters 265167606Sandre * to tcp_dooptions and tcp_addoptions. 266167606Sandre * The binary order of the to_flags is relevant for packing of the 267167606Sandre * options in tcp_addoptions. 2686247Swollman */ 2696247Swollmanstruct tcpopt { 270195654Slstewart u_int64_t to_flags; /* which options are present */ 271167606Sandre#define TOF_MSS 0x0001 /* maximum segment size */ 272167606Sandre#define TOF_SCALE 0x0002 /* window scaling */ 273178349Sbz#define TOF_SACKPERM 0x0004 /* SACK permitted */ 274167606Sandre#define TOF_TS 0x0010 /* timestamp */ 275178349Sbz#define TOF_SIGNATURE 0x0040 /* TCP-MD5 signature option (RFC2385) */ 276168906Sandre#define TOF_SACK 0x0080 /* Peer sent SACK option */ 277168906Sandre#define TOF_MAXOPT 0x0100 278168906Sandre u_int32_t to_tsval; /* new timestamp */ 279167606Sandre u_int32_t to_tsecr; /* reflected timestamp */ 280195654Slstewart u_char *to_sacks; /* pointer to the first SACK blocks */ 281195654Slstewart u_char *to_signature; /* pointer to the TCP-MD5 signature */ 282167606Sandre u_int16_t to_mss; /* maximum segment size */ 283167606Sandre u_int8_t to_wscale; /* window scaling */ 284147637Sps u_int8_t to_nsacks; /* number of SACK blocks */ 2856247Swollman}; 2866247Swollman 287159949Sandre/* 288159949Sandre * Flags for tcp_dooptions. 289159949Sandre */ 290159949Sandre#define TO_SYN 0x01 /* parse SYN-only options */ 291159949Sandre 292122922Sandrestruct hc_metrics_lite { /* must stay in sync with hc_metrics */ 293122922Sandre u_long rmx_mtu; /* MTU for this path */ 294122922Sandre u_long rmx_ssthresh; /* outbound gateway buffer limit */ 295122922Sandre u_long rmx_rtt; /* estimated round trip time */ 296122922Sandre u_long rmx_rttvar; /* estimated rtt variance */ 297122922Sandre u_long rmx_bandwidth; /* estimated bandwidth */ 298122922Sandre u_long rmx_cwnd; /* congestion window */ 299122922Sandre u_long rmx_sendpipe; /* outbound delay-bandwidth product */ 300122922Sandre u_long rmx_recvpipe; /* inbound delay-bandwidth product */ 301122922Sandre}; 302122922Sandre 303159725Sandre#ifndef _NETINET_IN_PCB_H_ 304159725Sandrestruct in_conninfo; 305159725Sandre#endif /* _NETINET_IN_PCB_H_ */ 306159725Sandre 307111145Sjlemonstruct tcptw { 308111145Sjlemon struct inpcb *tw_inpcb; /* XXX back pointer to internet pcb */ 309111145Sjlemon tcp_seq snd_nxt; 310111145Sjlemon tcp_seq rcv_nxt; 311121850Ssilby tcp_seq iss; 312121884Ssilby tcp_seq irs; 313111145Sjlemon u_short last_win; /* cached window value */ 314111145Sjlemon u_short tw_so_options; /* copy of so_options */ 315111145Sjlemon struct ucred *tw_cred; /* user credentials */ 316194303Sjhb u_int32_t t_recent; 317169477Sandre u_int32_t ts_offset; /* our timestamp offset */ 318194303Sjhb u_int t_starttime; 319112009Sjlemon int tw_time; 320162111Sru TAILQ_ENTRY(tcptw) tw_2msl; 321111145Sjlemon}; 322133874Srwatson 3231541Srgrimes#define intotcpcb(ip) ((struct tcpcb *)(ip)->inp_ppcb) 324111145Sjlemon#define intotw(ip) ((struct tcptw *)(ip)->inp_ppcb) 3251541Srgrimes#define sototcpcb(so) (intotcpcb(sotoinpcb(so))) 3261541Srgrimes 3271541Srgrimes/* 3281541Srgrimes * The smoothed round-trip time and estimated variance 3291541Srgrimes * are stored as fixed point numbers scaled by the values below. 3301541Srgrimes * For convenience, these scales are also used in smoothing the average 3311541Srgrimes * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed). 3321541Srgrimes * With these scales, srtt has 3 bits to the right of the binary point, 3331541Srgrimes * and thus an "ALPHA" of 0.875. rttvar has 2 bits to the right of the 3341541Srgrimes * binary point, and is smoothed with an ALPHA of 0.75. 3351541Srgrimes */ 33614753Swollman#define TCP_RTT_SCALE 32 /* multiplier for srtt; 3 bits frac. */ 33714753Swollman#define TCP_RTT_SHIFT 5 /* shift for srtt; 3 bits frac. */ 33814753Swollman#define TCP_RTTVAR_SCALE 16 /* multiplier for rttvar; 2 bits */ 33914753Swollman#define TCP_RTTVAR_SHIFT 4 /* shift for rttvar; 2 bits */ 34014753Swollman#define TCP_DELTA_SHIFT 2 /* see tcp_input.c */ 3411541Srgrimes 3421541Srgrimes/* 3431541Srgrimes * The initial retransmission should happen at rtt + 4 * rttvar. 3441541Srgrimes * Because of the way we do the smoothing, srtt and rttvar 3451541Srgrimes * will each average +1/2 tick of bias. When we compute 3461541Srgrimes * the retransmit timer, we want 1/2 tick of rounding and 3471541Srgrimes * 1 extra tick because of +-1/2 tick uncertainty in the 3481541Srgrimes * firing of the timer. The bias will give us exactly the 3491541Srgrimes * 1.5 tick we need. But, because the bias is 3501541Srgrimes * statistical, we have to test that we don't drop below 3511541Srgrimes * the minimum feasible timer (which is 2 ticks). 35214753Swollman * This version of the macro adapted from a paper by Lawrence 35314753Swollman * Brakmo and Larry Peterson which outlines a problem caused 35414753Swollman * by insufficient precision in the original implementation, 35514753Swollman * which results in inappropriately large RTO values for very 35614753Swollman * fast networks. 3571541Srgrimes */ 3581541Srgrimes#define TCP_REXMTVAL(tp) \ 35935419Sdg max((tp)->t_rttmin, (((tp)->t_srtt >> (TCP_RTT_SHIFT - TCP_DELTA_SHIFT)) \ 36016141Swollman + (tp)->t_rttvar) >> TCP_DELTA_SHIFT) 3611541Srgrimes 3621541Srgrimes/* 3631541Srgrimes * TCP statistics. 3641541Srgrimes * Many of these should be kept per connection, 3651541Srgrimes * but that's inconvenient at the moment. 3661541Srgrimes */ 3671541Srgrimesstruct tcpstat { 3681541Srgrimes u_long tcps_connattempt; /* connections initiated */ 3691541Srgrimes u_long tcps_accepts; /* connections accepted */ 3701541Srgrimes u_long tcps_connects; /* connections established */ 3711541Srgrimes u_long tcps_drops; /* connections dropped */ 3721541Srgrimes u_long tcps_conndrops; /* embryonic connections dropped */ 373124258Sandre u_long tcps_minmssdrops; /* average minmss too low drops */ 3741541Srgrimes u_long tcps_closed; /* conn. closed (includes drops) */ 3751541Srgrimes u_long tcps_segstimed; /* segs where we tried to get rtt */ 3761541Srgrimes u_long tcps_rttupdated; /* times we succeeded */ 3771541Srgrimes u_long tcps_delack; /* delayed acks sent */ 3781541Srgrimes u_long tcps_timeoutdrop; /* conn. dropped in rxmt timeout */ 3791541Srgrimes u_long tcps_rexmttimeo; /* retransmit timeouts */ 3801541Srgrimes u_long tcps_persisttimeo; /* persist timeouts */ 3811541Srgrimes u_long tcps_keeptimeo; /* keepalive timeouts */ 3821541Srgrimes u_long tcps_keepprobe; /* keepalive probes sent */ 3831541Srgrimes u_long tcps_keepdrops; /* connections dropped in keepalive */ 3841541Srgrimes 3851541Srgrimes u_long tcps_sndtotal; /* total packets sent */ 3861541Srgrimes u_long tcps_sndpack; /* data packets sent */ 3871541Srgrimes u_long tcps_sndbyte; /* data bytes sent */ 3881541Srgrimes u_long tcps_sndrexmitpack; /* data packets retransmitted */ 3891541Srgrimes u_long tcps_sndrexmitbyte; /* data bytes retransmitted */ 390100373Sdillon u_long tcps_sndrexmitbad; /* unnecessary packet retransmissions */ 3911541Srgrimes u_long tcps_sndacks; /* ack-only packets sent */ 3921541Srgrimes u_long tcps_sndprobe; /* window probes sent */ 3931541Srgrimes u_long tcps_sndurg; /* packets sent with URG only */ 3941541Srgrimes u_long tcps_sndwinup; /* window update-only packets sent */ 3951541Srgrimes u_long tcps_sndctrl; /* control (SYN|FIN|RST) packets sent */ 3961541Srgrimes 3971541Srgrimes u_long tcps_rcvtotal; /* total packets received */ 3981541Srgrimes u_long tcps_rcvpack; /* packets received in sequence */ 3991541Srgrimes u_long tcps_rcvbyte; /* bytes received in sequence */ 4001541Srgrimes u_long tcps_rcvbadsum; /* packets received with ccksum errs */ 4011541Srgrimes u_long tcps_rcvbadoff; /* packets received with bad offset */ 40252904Sshin u_long tcps_rcvmemdrop; /* packets dropped for lack of memory */ 4031541Srgrimes u_long tcps_rcvshort; /* packets received too short */ 4041541Srgrimes u_long tcps_rcvduppack; /* duplicate-only packets received */ 4051541Srgrimes u_long tcps_rcvdupbyte; /* duplicate-only bytes received */ 4061541Srgrimes u_long tcps_rcvpartduppack; /* packets with some duplicate data */ 4071541Srgrimes u_long tcps_rcvpartdupbyte; /* dup. bytes in part-dup. packets */ 4081541Srgrimes u_long tcps_rcvoopack; /* out-of-order packets received */ 4091541Srgrimes u_long tcps_rcvoobyte; /* out-of-order bytes received */ 4101541Srgrimes u_long tcps_rcvpackafterwin; /* packets with data after window */ 4111541Srgrimes u_long tcps_rcvbyteafterwin; /* bytes rcvd after window */ 4121541Srgrimes u_long tcps_rcvafterclose; /* packets rcvd after "close" */ 4131541Srgrimes u_long tcps_rcvwinprobe; /* rcvd window probe packets */ 4141541Srgrimes u_long tcps_rcvdupack; /* rcvd duplicate acks */ 4151541Srgrimes u_long tcps_rcvacktoomuch; /* rcvd acks for unsent data */ 4161541Srgrimes u_long tcps_rcvackpack; /* rcvd ack packets */ 4171541Srgrimes u_long tcps_rcvackbyte; /* bytes acked by rcvd acks */ 4181541Srgrimes u_long tcps_rcvwinupd; /* rcvd window update packets */ 4191541Srgrimes u_long tcps_pawsdrop; /* segments dropped due to PAWS */ 4201541Srgrimes u_long tcps_predack; /* times hdr predict ok for acks */ 4211541Srgrimes u_long tcps_preddat; /* times hdr predict ok for data pkts */ 4221541Srgrimes u_long tcps_pcbcachemiss; 4239263Swollman u_long tcps_cachedrtt; /* times cached RTT in route updated */ 4249263Swollman u_long tcps_cachedrttvar; /* times cached rttvar updated */ 4259263Swollman u_long tcps_cachedssthresh; /* times cached ssthresh updated */ 4269470Swollman u_long tcps_usedrtt; /* times RTT initialized from route */ 4279470Swollman u_long tcps_usedrttvar; /* times RTTVAR initialized from rt */ 4289470Swollman u_long tcps_usedssthresh; /* times ssthresh initialized from rt*/ 42910937Swollman u_long tcps_persistdrop; /* timeout in persist state */ 43010937Swollman u_long tcps_badsyn; /* bogus SYN, e.g. premature ACK */ 43111415Swollman u_long tcps_mturesent; /* resends due to MTU discovery */ 43214281Sbde u_long tcps_listendrop; /* listen queue overflows */ 433128653Ssilby u_long tcps_badrst; /* ignored RSTs in the window */ 43486764Sjlemon 43586764Sjlemon u_long tcps_sc_added; /* entry added to syncache */ 43686764Sjlemon u_long tcps_sc_retransmitted; /* syncache entry was retransmitted */ 43786764Sjlemon u_long tcps_sc_dupsyn; /* duplicate SYN packet */ 43886764Sjlemon u_long tcps_sc_dropped; /* could not reply to packet */ 43986764Sjlemon u_long tcps_sc_completed; /* successful extraction of entry */ 44086764Sjlemon u_long tcps_sc_bucketoverflow; /* syncache per-bucket limit hit */ 44186764Sjlemon u_long tcps_sc_cacheoverflow; /* syncache cache limit hit */ 44286764Sjlemon u_long tcps_sc_reset; /* RST removed entry from syncache */ 44386764Sjlemon u_long tcps_sc_stale; /* timed out or listen socket gone */ 44486764Sjlemon u_long tcps_sc_aborted; /* syncache entry aborted */ 44586764Sjlemon u_long tcps_sc_badack; /* removed due to bad ACK */ 44686764Sjlemon u_long tcps_sc_unreach; /* ICMP unreachable received */ 44786764Sjlemon u_long tcps_sc_zonefail; /* zalloc() failed */ 44886764Sjlemon u_long tcps_sc_sendcookie; /* SYN cookie sent */ 44986764Sjlemon u_long tcps_sc_recvcookie; /* SYN cookie received */ 450122922Sandre 451122922Sandre u_long tcps_hc_added; /* entry added to hostcache */ 452122922Sandre u_long tcps_hc_bucketoverflow; /* hostcache per bucket limit hit */ 453130989Sps 454167036Smohans u_long tcps_finwait2_drops; /* Drop FIN_WAIT_2 connection after time limit */ 455167036Smohans 456130989Sps /* SACK related stats */ 457130989Sps u_long tcps_sack_recovery_episode; /* SACK recovery episodes */ 458130989Sps u_long tcps_sack_rexmits; /* SACK rexmit segments */ 459133874Srwatson u_long tcps_sack_rexmit_bytes; /* SACK rexmit bytes */ 460130989Sps u_long tcps_sack_rcv_blocks; /* SACK blocks (options) received */ 461130989Sps u_long tcps_sack_send_blocks; /* SACK blocks (options) sent */ 462143339Sps u_long tcps_sack_sboverflow; /* times scoreboard overflowed */ 463181056Srpaulo 464181056Srpaulo /* ECN related stats */ 465181056Srpaulo u_long tcps_ecn_ce; /* ECN Congestion Experienced */ 466181056Srpaulo u_long tcps_ecn_ect0; /* ECN Capable Transport */ 467181056Srpaulo u_long tcps_ecn_ect1; /* ECN Capable Transport */ 468181056Srpaulo u_long tcps_ecn_shs; /* ECN successful handshakes */ 469181056Srpaulo u_long tcps_ecn_rcwnd; /* # times ECN reduced the cwnd */ 470195634Slstewart 471195634Slstewart u_long _pad[12]; /* 6 UTO, 6 TBD */ 4721541Srgrimes}; 4731541Srgrimes 474190978Srwatson#ifdef _KERNEL 475190948Srwatson#define TCPSTAT_ADD(name, val) V_tcpstat.name += (val) 476190948Srwatson#define TCPSTAT_INC(name) TCPSTAT_ADD(name, 1) 477190978Srwatson#endif 478190948Srwatson 4796247Swollman/* 48036079Swollman * TCB structure exported to user-land via sysctl(3). 48137183Sjhay * Evil hack: declare only if in_pcb.h and sys/socketvar.h have been 48237183Sjhay * included. Not all of our clients do. 48336079Swollman */ 48437183Sjhay#if defined(_NETINET_IN_PCB_H_) && defined(_SYS_SOCKETVAR_H_) 48536079Swollmanstruct xtcpcb { 48636079Swollman size_t xt_len; 48736079Swollman struct inpcb xt_inp; 48836079Swollman struct tcpcb xt_tp; 48936079Swollman struct xsocket xt_socket; 49036079Swollman u_quad_t xt_alignment_hack; 49136079Swollman}; 49236079Swollman#endif 49336079Swollman 49436079Swollman/* 4956247Swollman * Names for TCP sysctl objects 4966247Swollman */ 4976247Swollman#define TCPCTL_DO_RFC1323 1 /* use RFC-1323 extensions */ 4986247Swollman#define TCPCTL_MSSDFLT 3 /* MSS default */ 4996472Swollman#define TCPCTL_STATS 4 /* statistics (read-only) */ 5006472Swollman#define TCPCTL_RTTDFLT 5 /* default RTT estimate */ 5016472Swollman#define TCPCTL_KEEPIDLE 6 /* keepalive idle timer */ 5026472Swollman#define TCPCTL_KEEPINTVL 7 /* interval to send keepalives */ 50318281Spst#define TCPCTL_SENDSPACE 8 /* send buffer space */ 50418281Spst#define TCPCTL_RECVSPACE 9 /* receive buffer space */ 50563431Ssheldonh#define TCPCTL_KEEPINIT 10 /* timeout for establishing syn */ 50636079Swollman#define TCPCTL_PCBLIST 11 /* list of all outstanding PCBs */ 50750673Sjlemon#define TCPCTL_DELACKTIME 12 /* time before sending delayed ACK */ 50852904Sshin#define TCPCTL_V6MSSDFLT 13 /* MSS default for IPv6 */ 509130989Sps#define TCPCTL_SACK 14 /* Selective Acknowledgement,rfc 2018 */ 510141381Smaxim#define TCPCTL_DROP 15 /* drop tcp connection */ 511141381Smaxim#define TCPCTL_MAXID 16 512167036Smohans#define TCPCTL_FINWAIT2_TIMEOUT 17 5136247Swollman 5146247Swollman#define TCPCTL_NAMES { \ 5156247Swollman { 0, 0 }, \ 5166348Swollman { "rfc1323", CTLTYPE_INT }, \ 5176247Swollman { "mssdflt", CTLTYPE_INT }, \ 5186472Swollman { "stats", CTLTYPE_STRUCT }, \ 5196472Swollman { "rttdflt", CTLTYPE_INT }, \ 5206472Swollman { "keepidle", CTLTYPE_INT }, \ 5216472Swollman { "keepintvl", CTLTYPE_INT }, \ 5226472Swollman { "sendspace", CTLTYPE_INT }, \ 5236472Swollman { "recvspace", CTLTYPE_INT }, \ 52418281Spst { "keepinit", CTLTYPE_INT }, \ 52536079Swollman { "pcblist", CTLTYPE_STRUCT }, \ 52650673Sjlemon { "delacktime", CTLTYPE_INT }, \ 52752904Sshin { "v6mssdflt", CTLTYPE_INT }, \ 528122922Sandre { "maxid", CTLTYPE_INT }, \ 5296247Swollman} 5306247Swollman 53144078Sdfr 53255205Speter#ifdef _KERNEL 53344078Sdfr#ifdef SYSCTL_DECL 53444078SdfrSYSCTL_DECL(_net_inet_tcp); 535136151SpsSYSCTL_DECL(_net_inet_tcp_sack); 536169683SandreMALLOC_DECLARE(M_TCPLOG); 53744078Sdfr#endif 53844078Sdfr 539185937Sbzextern int tcp_log_in_vain; 540185937Sbz 541185937Sbz#ifdef VIMAGE_GLOBALS 5427684Sdgextern struct inpcbhead tcb; /* head of queue of active tcpcb's */ 5437684Sdgextern struct inpcbinfo tcbinfo; 5446348Swollmanextern struct tcpstat tcpstat; /* tcp statistics */ 5457090Sbdeextern int tcp_mssdflt; /* XXX */ 546124258Sandreextern int tcp_minmss; 54733846Sdgextern int tcp_delack_enabled; 54860067Sjlemonextern int tcp_do_newreno; 54998204Ssilbyextern int path_mtu_discovery; 55050673Sjlemonextern int ss_fltsz; 55150673Sjlemonextern int ss_fltsz_local; 5521541Srgrimes 553185088Szecextern int blackhole; 554185088Szecextern int drop_synfin; 555185088Szecextern int tcp_do_rfc3042; 556185088Szecextern int tcp_do_rfc3390; 557185088Szecextern int tcp_insecure_rst; 558185088Szecextern int tcp_do_autorcvbuf; 559185088Szecextern int tcp_autorcvbuf_inc; 560185088Szecextern int tcp_autorcvbuf_max; 561187585Sbzextern int tcp_do_rfc3465; 562187585Sbzextern int tcp_abc_l_var; 563185088Szec 564185088Szecextern int tcp_do_tso; 565185088Szecextern int tcp_do_autosndbuf; 566185088Szecextern int tcp_autosndbuf_inc; 567185088Szecextern int tcp_autosndbuf_max; 568185088Szec 569185088Szecextern int nolocaltimewait; 570185088Szec 571170055Sandreextern int tcp_do_sack; /* SACK enabled/disabled */ 572185088Szecextern int tcp_sack_maxholes; 573185088Szecextern int tcp_sack_globalmaxholes; 574185088Szecextern int tcp_sack_globalholes; 575170055Sandreextern int tcp_sc_rst_sock_fail; /* RST on sock alloc failure */ 576181056Srpauloextern int tcp_do_ecn; /* TCP ECN enabled/disabled */ 577181056Srpauloextern int tcp_ecn_maxretries; 578185937Sbz#endif /* VIMAGE_GLOBALS */ 579130989Sps 580167606Sandreint tcp_addoptions(struct tcpopt *, u_char *); 5811541Srgrimesstruct tcpcb * 58292723Salfred tcp_close(struct tcpcb *); 583157376Srwatsonvoid tcp_discardcb(struct tcpcb *); 584111145Sjlemonvoid tcp_twstart(struct tcpcb *); 585162064Sglebius#if 0 586121850Ssilbyint tcp_twrecycleable(struct tcptw *tw); 587162064Sglebius#endif 588157376Srwatsonvoid tcp_twclose(struct tcptw *_tw, int _reuse); 58992723Salfredvoid tcp_ctlinput(int, struct sockaddr *, void *); 59092723Salfredint tcp_ctloutput(struct socket *, struct sockopt *); 5911541Srgrimesstruct tcpcb * 59292723Salfred tcp_drop(struct tcpcb *, int); 59392723Salfredvoid tcp_drain(void); 59492723Salfredvoid tcp_fasttimo(void); 59592723Salfredvoid tcp_init(void); 596193731Szec#ifdef VIMAGE 597193731Szecvoid tcp_destroy(void); 598193731Szec#endif 599128452Ssilbyvoid tcp_fini(void *); 600169683Sandrechar *tcp_log_addrs(struct in_conninfo *, struct tcphdr *, void *, 601171229Speter const void *); 602169541Sandreint tcp_reass(struct tcpcb *, struct tcphdr *, int *, struct mbuf *); 603126193Sandrevoid tcp_reass_init(void); 60492723Salfredvoid tcp_input(struct mbuf *, int); 605162084Sandreu_long tcp_maxmtu(struct in_conninfo *, int *); 606162084Sandreu_long tcp_maxmtu6(struct in_conninfo *, int *); 607184722Sbzvoid tcp_mss_update(struct tcpcb *, int, struct hc_metrics_lite *, int *); 60892723Salfredvoid tcp_mss(struct tcpcb *, int); 609122922Sandreint tcp_mssopt(struct in_conninfo *); 610133874Srwatsonstruct inpcb * 61198211Shsu tcp_drop_syn_sent(struct inpcb *, int); 61298211Shsustruct inpcb * 61398211Shsu tcp_mtudisc(struct inpcb *, int); 6141541Srgrimesstruct tcpcb * 61592723Salfred tcp_newtcpcb(struct inpcb *); 61692723Salfredint tcp_output(struct tcpcb *); 61792723Salfredvoid tcp_respond(struct tcpcb *, void *, 61892723Salfred struct tcphdr *, struct mbuf *, tcp_seq, tcp_seq, int); 619169541Sandrevoid tcp_tw_init(void); 620193731Szec#ifdef VIMAGE 621193731Szecvoid tcp_tw_destroy(void); 622193731Szec#endif 623169541Sandrevoid tcp_tw_zone_change(void); 624169608Sandreint tcp_twcheck(struct inpcb *, struct tcpopt *, struct tcphdr *, 625169608Sandre struct mbuf *, int); 626126351Srwatsonint tcp_twrespond(struct tcptw *, int); 62792723Salfredvoid tcp_setpersist(struct tcpcb *); 628125783Sbms#ifdef TCP_SIGNATURE 629125783Sbmsint tcp_signature_compute(struct mbuf *, int, int, int, u_char *, u_int); 630125783Sbms#endif 63192723Salfredvoid tcp_slowtimo(void); 63255679Sshinstruct tcptemp * 633111144Sjlemon tcpip_maketemplate(struct inpcb *); 634111144Sjlemonvoid tcpip_fillheaders(struct inpcb *, void *, void *); 635168615Sandrevoid tcp_timer_activate(struct tcpcb *, int, u_int); 636168615Sandreint tcp_timer_active(struct tcpcb *, int); 637169272Srwatsonvoid tcp_trace(short, short, struct tcpcb *, void *, struct tcphdr *, int); 638102017Sdillonvoid tcp_xmit_bandwidth_limit(struct tcpcb *tp, tcp_seq ack_seq); 639122922Sandre/* 640122922Sandre * All tcp_hc_* functions are IPv4 and IPv6 (via in_conninfo) 641122922Sandre */ 642122922Sandrevoid tcp_hc_init(void); 643193731Szec#ifdef VIMAGE 644193731Szecvoid tcp_hc_destroy(void); 645193731Szec#endif 646122922Sandrevoid tcp_hc_get(struct in_conninfo *, struct hc_metrics_lite *); 647122922Sandreu_long tcp_hc_getmtu(struct in_conninfo *); 648122922Sandrevoid tcp_hc_updatemtu(struct in_conninfo *, u_long); 649122922Sandrevoid tcp_hc_update(struct in_conninfo *, struct hc_metrics_lite *); 6509470Swollman 65117096Swollmanextern struct pr_usrreqs tcp_usrreqs; 6529470Swollmanextern u_long tcp_sendspace; 6539470Swollmanextern u_long tcp_recvspace; 65492723Salfredtcp_seq tcp_new_isn(struct tcpcb *); 6559470Swollman 656147637Spsvoid tcp_sack_doack(struct tcpcb *, struct tcpopt *, tcp_seq); 657142031Spsvoid tcp_update_sack_list(struct tcpcb *tp, tcp_seq rcv_laststart, tcp_seq rcv_lastend); 658130989Spsvoid tcp_clean_sackreport(struct tcpcb *tp); 659130989Spsvoid tcp_sack_adjust(struct tcpcb *tp); 660136151Spsstruct sackhole *tcp_sack_output(struct tcpcb *tp, int *sack_bytes_rexmt); 661130989Spsvoid tcp_sack_partialack(struct tcpcb *, struct tcphdr *); 662130989Spsvoid tcp_free_sackholes(struct tcpcb *tp); 663130989Spsint tcp_newreno(struct tcpcb *, struct tcphdr *); 664130989Spsu_long tcp_seq_subtract(u_long, u_long ); 665130989Sps 66655205Speter#endif /* _KERNEL */ 6672169Spaul 6686348Swollman#endif /* _NETINET_TCP_VAR_H_ */ 669