tcp_var.h revision 6247
11541Srgrimes/* 21541Srgrimes * Copyright (c) 1982, 1986, 1993, 1994 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 * 3. All advertising materials mentioning features or use of this software 141541Srgrimes * must display the following acknowledgement: 151541Srgrimes * This product includes software developed by the University of 161541Srgrimes * California, Berkeley and its contributors. 171541Srgrimes * 4. Neither the name of the University nor the names of its contributors 181541Srgrimes * may be used to endorse or promote products derived from this software 191541Srgrimes * without specific prior written permission. 201541Srgrimes * 211541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311541Srgrimes * SUCH DAMAGE. 321541Srgrimes * 331541Srgrimes * @(#)tcp_var.h 8.3 (Berkeley) 4/10/94 346247Swollman * $Id: tcp_var.h,v 1.3 1994/08/21 05:27:39 paul Exp $ 351541Srgrimes */ 361541Srgrimes 372169Spaul#ifndef _NETINET_TCP_VAR_H_ 382169Spaul#define _NETINET_TCP_VAR_H_ 391541Srgrimes/* 401541Srgrimes * Kernel variables for tcp. 411541Srgrimes */ 421541Srgrimes 431541Srgrimes/* 441541Srgrimes * Tcp control block, one per tcp; fields: 451541Srgrimes */ 461541Srgrimesstruct tcpcb { 471541Srgrimes struct tcpiphdr *seg_next; /* sequencing queue */ 481541Srgrimes struct tcpiphdr *seg_prev; 491541Srgrimes short t_state; /* state of this connection */ 501541Srgrimes short t_timer[TCPT_NTIMERS]; /* tcp timers */ 511541Srgrimes short t_rxtshift; /* log(2) of rexmt exp. backoff */ 521541Srgrimes short t_rxtcur; /* current retransmit value */ 531541Srgrimes short t_dupacks; /* consecutive dup acks recd */ 541541Srgrimes u_short t_maxseg; /* maximum segment size */ 556247Swollman u_short t_maxopd; /* mss plus options */ 561541Srgrimes char t_force; /* 1 if forcing out a byte */ 571541Srgrimes u_short t_flags; 581541Srgrimes#define TF_ACKNOW 0x0001 /* ack peer immediately */ 591541Srgrimes#define TF_DELACK 0x0002 /* ack, but try to delay it */ 601541Srgrimes#define TF_NODELAY 0x0004 /* don't delay packets to coalesce */ 611541Srgrimes#define TF_NOOPT 0x0008 /* don't use tcp options */ 621541Srgrimes#define TF_SENTFIN 0x0010 /* have sent FIN */ 631541Srgrimes#define TF_REQ_SCALE 0x0020 /* have/will request window scaling */ 641541Srgrimes#define TF_RCVD_SCALE 0x0040 /* other side has requested scaling */ 651541Srgrimes#define TF_REQ_TSTMP 0x0080 /* have/will request timestamps */ 661541Srgrimes#define TF_RCVD_TSTMP 0x0100 /* a timestamp was received in SYN */ 671541Srgrimes#define TF_SACK_PERMIT 0x0200 /* other side said I could SACK */ 686247Swollman#ifdef TTCP 696247Swollman#define TF_NEEDSYN 0x0400 /* send SYN (implicit state) */ 706247Swollman#define TF_NEEDFIN 0x0800 /* send FIN (implicit state) */ 716247Swollman#define TF_NOPUSH 0x1000 /* don't push */ 726247Swollman#define TF_REQ_CC 0x2000 /* have/will request CC */ 736247Swollman#define TF_RCVD_CC 0x4000 /* a CC was received in SYN */ 746247Swollman#endif 751541Srgrimes 761541Srgrimes struct tcpiphdr *t_template; /* skeletal packet for transmit */ 771541Srgrimes struct inpcb *t_inpcb; /* back pointer to internet pcb */ 781541Srgrimes/* 791541Srgrimes * The following fields are used as in the protocol specification. 801541Srgrimes * See RFC783, Dec. 1981, page 21. 811541Srgrimes */ 821541Srgrimes/* send sequence variables */ 831541Srgrimes tcp_seq snd_una; /* send unacknowledged */ 841541Srgrimes tcp_seq snd_nxt; /* send next */ 851541Srgrimes tcp_seq snd_up; /* send urgent pointer */ 861541Srgrimes tcp_seq snd_wl1; /* window update seg seq number */ 871541Srgrimes tcp_seq snd_wl2; /* window update seg ack number */ 881541Srgrimes tcp_seq iss; /* initial send sequence number */ 891541Srgrimes u_long snd_wnd; /* send window */ 901541Srgrimes/* receive sequence variables */ 911541Srgrimes u_long rcv_wnd; /* receive window */ 921541Srgrimes tcp_seq rcv_nxt; /* receive next */ 931541Srgrimes tcp_seq rcv_up; /* receive urgent pointer */ 941541Srgrimes tcp_seq irs; /* initial receive sequence number */ 951541Srgrimes/* 961541Srgrimes * Additional variables for this implementation. 971541Srgrimes */ 981541Srgrimes/* receive variables */ 991541Srgrimes tcp_seq rcv_adv; /* advertised window */ 1001541Srgrimes/* retransmit variables */ 1011541Srgrimes tcp_seq snd_max; /* highest sequence number sent; 1021541Srgrimes * used to recognize retransmits 1031541Srgrimes */ 1041541Srgrimes/* congestion control (for slow start, source quench, retransmit after loss) */ 1051541Srgrimes u_long snd_cwnd; /* congestion-controlled window */ 1061541Srgrimes u_long snd_ssthresh; /* snd_cwnd size threshhold for 1071541Srgrimes * for slow start exponential to 1081541Srgrimes * linear switch 1091541Srgrimes */ 1101541Srgrimes/* 1111541Srgrimes * transmit timing stuff. See below for scale of srtt and rttvar. 1121541Srgrimes * "Variance" is actually smoothed difference. 1131541Srgrimes */ 1141541Srgrimes short t_idle; /* inactivity time */ 1151541Srgrimes short t_rtt; /* round trip time */ 1161541Srgrimes tcp_seq t_rtseq; /* sequence number being timed */ 1171541Srgrimes short t_srtt; /* smoothed round-trip time */ 1181541Srgrimes short t_rttvar; /* variance in round-trip time */ 1191541Srgrimes u_short t_rttmin; /* minimum rtt allowed */ 1201541Srgrimes u_long max_sndwnd; /* largest window peer has offered */ 1211541Srgrimes 1221541Srgrimes/* out-of-band data */ 1231541Srgrimes char t_oobflags; /* have some */ 1241541Srgrimes char t_iobc; /* input character */ 1251541Srgrimes#define TCPOOB_HAVEDATA 0x01 1261541Srgrimes#define TCPOOB_HADDATA 0x02 1271541Srgrimes short t_softerror; /* possible error not yet reported */ 1281541Srgrimes 1291541Srgrimes/* RFC 1323 variables */ 1301541Srgrimes u_char snd_scale; /* window scaling for send window */ 1311541Srgrimes u_char rcv_scale; /* window scaling for recv window */ 1321541Srgrimes u_char request_r_scale; /* pending window scaling */ 1331541Srgrimes u_char requested_s_scale; 1341541Srgrimes u_long ts_recent; /* timestamp echo data */ 1351541Srgrimes u_long ts_recent_age; /* when last updated */ 1361541Srgrimes tcp_seq last_ack_sent; 1376247Swollman#ifdef TTCP 1386247Swollman/* RFC 1644 variables */ 1396247Swollman tcp_cc cc_send; /* send connection count */ 1406247Swollman tcp_cc cc_recv; /* receive connection count */ 1416247Swollman u_long t_duration; /* connection duration */ 1426247Swollman#endif /* TTCP */ 1431541Srgrimes 1441541Srgrimes/* TUBA stuff */ 1451541Srgrimes caddr_t t_tuba_pcb; /* next level down pcb for TCP over z */ 1461541Srgrimes}; 1471541Srgrimes 1486247Swollman#ifdef TTCP 1496247Swollman/* 1506247Swollman * Structure to hold TCP options that are only used during segment 1516247Swollman * processing (in tcp_input), but not held in the tcpcb. 1526247Swollman * It's basically used to reduce the number of parameters 1536247Swollman * to tcp_dooptions. 1546247Swollman */ 1556247Swollmanstruct tcpopt { 1566247Swollman u_long to_flag; /* which options are present */ 1576247Swollman#define TOF_TS 0x0001 /* timestamp */ 1586247Swollman#define TOF_CC 0x0002 /* CC and CCnew are exclusive */ 1596247Swollman#define TOF_CCNEW 0x0004 1606247Swollman#define TOF_CCECHO 0x0008 1616247Swollman u_long to_tsval; 1626247Swollman u_long to_tsecr; 1636247Swollman tcp_cc to_cc; /* holds CC or CCnew */ 1646247Swollman tcp_cc to_ccecho; 1656247Swollman}; 1666247Swollman 1676247Swollman/* 1686247Swollman * The TAO cache entry which is stored in the protocol family specific 1696247Swollman * portion of the route metrics. 1706247Swollman */ 1716247Swollmanstruct rmxp_tao { 1726247Swollman tcp_cc tao_cc; /* latest CC in valid SYN */ 1736247Swollman tcp_cc tao_ccsent; /* latest CC sent to peer */ 1746247Swollman u_short tao_mssopt; /* peer's cached MSS */ 1756247Swollman#ifdef notyet 1766247Swollman u_short tao_flags; /* cache status flags */ 1776247Swollman#define TAOF_DONT 0x0001 /* peer doesn't understand rfc1644 */ 1786247Swollman#define TAOF_OK 0x0002 /* peer does understand rfc1644 */ 1796247Swollman#define TAOF_UNDEF 0 /* we don't know yet */ 1806247Swollman#endif /* notyet */ 1816247Swollman}; 1826247Swollman#define rmx_taop(r) ((struct rmxp_tao *)&(r).rmx_pspec) 1836247Swollman#endif /* TTCP */ 1846247Swollman 1851541Srgrimes#define intotcpcb(ip) ((struct tcpcb *)(ip)->inp_ppcb) 1861541Srgrimes#define sototcpcb(so) (intotcpcb(sotoinpcb(so))) 1871541Srgrimes 1881541Srgrimes/* 1891541Srgrimes * The smoothed round-trip time and estimated variance 1901541Srgrimes * are stored as fixed point numbers scaled by the values below. 1911541Srgrimes * For convenience, these scales are also used in smoothing the average 1921541Srgrimes * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed). 1931541Srgrimes * With these scales, srtt has 3 bits to the right of the binary point, 1941541Srgrimes * and thus an "ALPHA" of 0.875. rttvar has 2 bits to the right of the 1951541Srgrimes * binary point, and is smoothed with an ALPHA of 0.75. 1961541Srgrimes */ 1971541Srgrimes#define TCP_RTT_SCALE 8 /* multiplier for srtt; 3 bits frac. */ 1981541Srgrimes#define TCP_RTT_SHIFT 3 /* shift for srtt; 3 bits frac. */ 1991541Srgrimes#define TCP_RTTVAR_SCALE 4 /* multiplier for rttvar; 2 bits */ 2006247Swollman#define TCP_RTTVAR_SHIFT 2 /* shift for rttvar; 2 bits */ 2011541Srgrimes 2021541Srgrimes/* 2031541Srgrimes * The initial retransmission should happen at rtt + 4 * rttvar. 2041541Srgrimes * Because of the way we do the smoothing, srtt and rttvar 2051541Srgrimes * will each average +1/2 tick of bias. When we compute 2061541Srgrimes * the retransmit timer, we want 1/2 tick of rounding and 2071541Srgrimes * 1 extra tick because of +-1/2 tick uncertainty in the 2081541Srgrimes * firing of the timer. The bias will give us exactly the 2091541Srgrimes * 1.5 tick we need. But, because the bias is 2101541Srgrimes * statistical, we have to test that we don't drop below 2111541Srgrimes * the minimum feasible timer (which is 2 ticks). 2121541Srgrimes * This macro assumes that the value of TCP_RTTVAR_SCALE 2131541Srgrimes * is the same as the multiplier for rttvar. 2141541Srgrimes */ 2151541Srgrimes#define TCP_REXMTVAL(tp) \ 2161541Srgrimes (((tp)->t_srtt >> TCP_RTT_SHIFT) + (tp)->t_rttvar) 2171541Srgrimes 2181541Srgrimes/* XXX 2191541Srgrimes * We want to avoid doing m_pullup on incoming packets but that 2201541Srgrimes * means avoiding dtom on the tcp reassembly code. That in turn means 2211541Srgrimes * keeping an mbuf pointer in the reassembly queue (since we might 2221541Srgrimes * have a cluster). As a quick hack, the source & destination 2231541Srgrimes * port numbers (which are no longer needed once we've located the 2241541Srgrimes * tcpcb) are overlayed with an mbuf pointer. 2251541Srgrimes */ 2261541Srgrimes#define REASS_MBUF(ti) (*(struct mbuf **)&((ti)->ti_t)) 2271541Srgrimes 2281541Srgrimes/* 2291541Srgrimes * TCP statistics. 2301541Srgrimes * Many of these should be kept per connection, 2311541Srgrimes * but that's inconvenient at the moment. 2321541Srgrimes */ 2331541Srgrimesstruct tcpstat { 2341541Srgrimes u_long tcps_connattempt; /* connections initiated */ 2351541Srgrimes u_long tcps_accepts; /* connections accepted */ 2361541Srgrimes u_long tcps_connects; /* connections established */ 2371541Srgrimes u_long tcps_drops; /* connections dropped */ 2381541Srgrimes u_long tcps_conndrops; /* embryonic connections dropped */ 2391541Srgrimes u_long tcps_closed; /* conn. closed (includes drops) */ 2401541Srgrimes u_long tcps_segstimed; /* segs where we tried to get rtt */ 2411541Srgrimes u_long tcps_rttupdated; /* times we succeeded */ 2421541Srgrimes u_long tcps_delack; /* delayed acks sent */ 2431541Srgrimes u_long tcps_timeoutdrop; /* conn. dropped in rxmt timeout */ 2441541Srgrimes u_long tcps_rexmttimeo; /* retransmit timeouts */ 2451541Srgrimes u_long tcps_persisttimeo; /* persist timeouts */ 2461541Srgrimes u_long tcps_keeptimeo; /* keepalive timeouts */ 2471541Srgrimes u_long tcps_keepprobe; /* keepalive probes sent */ 2481541Srgrimes u_long tcps_keepdrops; /* connections dropped in keepalive */ 2491541Srgrimes 2501541Srgrimes u_long tcps_sndtotal; /* total packets sent */ 2511541Srgrimes u_long tcps_sndpack; /* data packets sent */ 2521541Srgrimes u_long tcps_sndbyte; /* data bytes sent */ 2531541Srgrimes u_long tcps_sndrexmitpack; /* data packets retransmitted */ 2541541Srgrimes u_long tcps_sndrexmitbyte; /* data bytes retransmitted */ 2551541Srgrimes u_long tcps_sndacks; /* ack-only packets sent */ 2561541Srgrimes u_long tcps_sndprobe; /* window probes sent */ 2571541Srgrimes u_long tcps_sndurg; /* packets sent with URG only */ 2581541Srgrimes u_long tcps_sndwinup; /* window update-only packets sent */ 2591541Srgrimes u_long tcps_sndctrl; /* control (SYN|FIN|RST) packets sent */ 2601541Srgrimes 2611541Srgrimes u_long tcps_rcvtotal; /* total packets received */ 2621541Srgrimes u_long tcps_rcvpack; /* packets received in sequence */ 2631541Srgrimes u_long tcps_rcvbyte; /* bytes received in sequence */ 2641541Srgrimes u_long tcps_rcvbadsum; /* packets received with ccksum errs */ 2651541Srgrimes u_long tcps_rcvbadoff; /* packets received with bad offset */ 2661541Srgrimes u_long tcps_rcvshort; /* packets received too short */ 2671541Srgrimes u_long tcps_rcvduppack; /* duplicate-only packets received */ 2681541Srgrimes u_long tcps_rcvdupbyte; /* duplicate-only bytes received */ 2691541Srgrimes u_long tcps_rcvpartduppack; /* packets with some duplicate data */ 2701541Srgrimes u_long tcps_rcvpartdupbyte; /* dup. bytes in part-dup. packets */ 2711541Srgrimes u_long tcps_rcvoopack; /* out-of-order packets received */ 2721541Srgrimes u_long tcps_rcvoobyte; /* out-of-order bytes received */ 2731541Srgrimes u_long tcps_rcvpackafterwin; /* packets with data after window */ 2741541Srgrimes u_long tcps_rcvbyteafterwin; /* bytes rcvd after window */ 2751541Srgrimes u_long tcps_rcvafterclose; /* packets rcvd after "close" */ 2761541Srgrimes u_long tcps_rcvwinprobe; /* rcvd window probe packets */ 2771541Srgrimes u_long tcps_rcvdupack; /* rcvd duplicate acks */ 2781541Srgrimes u_long tcps_rcvacktoomuch; /* rcvd acks for unsent data */ 2791541Srgrimes u_long tcps_rcvackpack; /* rcvd ack packets */ 2801541Srgrimes u_long tcps_rcvackbyte; /* bytes acked by rcvd acks */ 2811541Srgrimes u_long tcps_rcvwinupd; /* rcvd window update packets */ 2821541Srgrimes u_long tcps_pawsdrop; /* segments dropped due to PAWS */ 2831541Srgrimes u_long tcps_predack; /* times hdr predict ok for acks */ 2841541Srgrimes u_long tcps_preddat; /* times hdr predict ok for data pkts */ 2851541Srgrimes u_long tcps_pcbcachemiss; 2861541Srgrimes}; 2871541Srgrimes 2886247Swollman/* 2896247Swollman * Names for TCP sysctl objects 2906247Swollman */ 2916247Swollman#define TCPCTL_DO_RFC1323 1 /* use RFC-1323 extensions */ 2926247Swollman#define TCPCTL_DO_RFC1644 2 /* use RFC-1644 extensions */ 2936247Swollman#define TCPCTL_MSSDFLT 3 /* MSS default */ 2946247Swollman#define TCPCTL_MAXID 4 2956247Swollman 2966247Swollman#define TCPCTL_NAMES { \ 2976247Swollman { 0, 0 }, \ 2986247Swollman { "do_rfc1323", CTLTYPE_INT }, \ 2996247Swollman { "do_rfc1644", CTLTYPE_INT }, \ 3006247Swollman { "mssdflt", CTLTYPE_INT }, \ 3016247Swollman} 3026247Swollman 3031541Srgrimes#ifdef KERNEL 3041541Srgrimesstruct inpcb tcb; /* head of queue of active tcpcb's */ 3051541Srgrimesstruct tcpstat tcpstat; /* tcp statistics */ 3061541Srgrimesu_long tcp_now; /* for RFC 1323 timestamps */ 3071541Srgrimes 3081541Srgrimesint tcp_attach __P((struct socket *)); 3091541Srgrimesvoid tcp_canceltimers __P((struct tcpcb *)); 3101541Srgrimesstruct tcpcb * 3111541Srgrimes tcp_close __P((struct tcpcb *)); 3126247Swollman#ifdef TTCP 3136247Swollmanint tcp_connect __P((struct tcpcb *, struct mbuf *)); 3146247Swollman#endif 3151541Srgrimesvoid tcp_ctlinput __P((int, struct sockaddr *, struct ip *)); 3161541Srgrimesint tcp_ctloutput __P((int, struct socket *, int, int, struct mbuf **)); 3171541Srgrimesstruct tcpcb * 3181541Srgrimes tcp_disconnect __P((struct tcpcb *)); 3191541Srgrimesstruct tcpcb * 3201541Srgrimes tcp_drop __P((struct tcpcb *, int)); 3216247Swollman#ifdef TTCP 3221541Srgrimesvoid tcp_dooptions __P((struct tcpcb *, 3236247Swollman u_char *, int, struct tcpiphdr *, struct tcpopt *)); 3246247Swollman#else 3256247Swollmanvoid tcp_dooptions __P((struct tcpcb *, 3261541Srgrimes u_char *, int, struct tcpiphdr *, int *, u_long *, u_long *)); 3276247Swollman#endif 3281541Srgrimesvoid tcp_drain __P((void)); 3291541Srgrimesvoid tcp_fasttimo __P((void)); 3306247Swollman#ifdef TTCP 3316247Swollmanstruct rmxp_tao * 3326247Swollman tcp_gettaocache __P((struct inpcb *)); 3336247Swollman#endif 3341541Srgrimesvoid tcp_init __P((void)); 3351541Srgrimesvoid tcp_input __P((struct mbuf *, int)); 3366247Swollmanvoid tcp_mss __P((struct tcpcb *, int)); 3376247Swollmanint tcp_mssopt __P((struct tcpcb *)); 3381541Srgrimesstruct tcpcb * 3391541Srgrimes tcp_newtcpcb __P((struct inpcb *)); 3401541Srgrimesvoid tcp_notify __P((struct inpcb *, int)); 3411541Srgrimesint tcp_output __P((struct tcpcb *)); 3421541Srgrimesvoid tcp_pulloutofband __P((struct socket *, 3431541Srgrimes struct tcpiphdr *, struct mbuf *)); 3441541Srgrimesvoid tcp_quench __P((struct inpcb *, int)); 3451541Srgrimesint tcp_reass __P((struct tcpcb *, struct tcpiphdr *, struct mbuf *)); 3461541Srgrimesvoid tcp_respond __P((struct tcpcb *, 3471541Srgrimes struct tcpiphdr *, struct mbuf *, u_long, u_long, int)); 3486247Swollmanstruct rtentry * 3496247Swollman tcp_rtlookup __P((struct inpcb *)); 3501541Srgrimesvoid tcp_setpersist __P((struct tcpcb *)); 3511541Srgrimesvoid tcp_slowtimo __P((void)); 3526247Swollmanint tcp_sysctl __P((int *, u_int, void *, size_t *, void *, size_t)); 3531541Srgrimesstruct tcpiphdr * 3541541Srgrimes tcp_template __P((struct tcpcb *)); 3551541Srgrimesstruct tcpcb * 3561541Srgrimes tcp_timers __P((struct tcpcb *, int)); 3571541Srgrimesvoid tcp_trace __P((int, int, struct tcpcb *, struct tcpiphdr *, int)); 3581541Srgrimesstruct tcpcb * 3591541Srgrimes tcp_usrclosed __P((struct tcpcb *)); 3601541Srgrimesint tcp_usrreq __P((struct socket *, 3611541Srgrimes int, struct mbuf *, struct mbuf *, struct mbuf *)); 3621541Srgrimesvoid tcp_xmit_timer __P((struct tcpcb *, int)); 3631541Srgrimes#endif 3642169Spaul 3652169Spaul#endif 366