123197Smckusick /* 2*69643Skarels * Copyright (c) 1982, 1986, 1993, 1994, 1995 363218Sbostic * The Regents of the University of California. All rights reserved. 423197Smckusick * 544492Sbostic * %sccs.include.redist.c% 632789Sbostic * 7*69643Skarels * @(#)tcp_var.h 8.4 (Berkeley) 05/24/95 823197Smckusick */ 94808Swnj 104808Swnj /* 114808Swnj * Kernel variables for tcp. 124808Swnj */ 134808Swnj 144808Swnj /* 155166Swnj * Tcp control block, one per tcp; fields: 164808Swnj */ 174881Swnj struct tcpcb { 185076Swnj struct tcpiphdr *seg_next; /* sequencing queue */ 195076Swnj struct tcpiphdr *seg_prev; 205246Sroot short t_state; /* state of this connection */ 215092Swnj short t_timer[TCPT_NTIMERS]; /* tcp timers */ 225166Swnj short t_rxtshift; /* log(2) of rexmt exp. backoff */ 2332034Skarels short t_rxtcur; /* current retransmit value */ 2432099Skarels short t_dupacks; /* consecutive dup acks recd */ 2527068Skarels u_short t_maxseg; /* maximum segment size */ 265246Sroot char t_force; /* 1 if forcing out a byte */ 2757433Sandrew u_short t_flags; 2857433Sandrew #define TF_ACKNOW 0x0001 /* ack peer immediately */ 2957433Sandrew #define TF_DELACK 0x0002 /* ack, but try to delay it */ 3057433Sandrew #define TF_NODELAY 0x0004 /* don't delay packets to coalesce */ 3157433Sandrew #define TF_NOOPT 0x0008 /* don't use tcp options */ 3257433Sandrew #define TF_SENTFIN 0x0010 /* have sent FIN */ 3357433Sandrew #define TF_REQ_SCALE 0x0020 /* have/will request window scaling */ 3457433Sandrew #define TF_RCVD_SCALE 0x0040 /* other side has requested scaling */ 3557433Sandrew #define TF_REQ_TSTMP 0x0080 /* have/will request timestamps */ 3657433Sandrew #define TF_RCVD_TSTMP 0x0100 /* a timestamp was received in SYN */ 3757433Sandrew #define TF_SACK_PERMIT 0x0200 /* other side said I could SACK */ 3857433Sandrew 394881Swnj struct tcpiphdr *t_template; /* skeletal packet for transmit */ 405067Swnj struct inpcb *t_inpcb; /* back pointer to internet pcb */ 414808Swnj /* 425067Swnj * The following fields are used as in the protocol specification. 435067Swnj * See RFC783, Dec. 1981, page 21. 444808Swnj */ 455067Swnj /* send sequence variables */ 465067Swnj tcp_seq snd_una; /* send unacknowledged */ 475067Swnj tcp_seq snd_nxt; /* send next */ 485067Swnj tcp_seq snd_up; /* send urgent pointer */ 495067Swnj tcp_seq snd_wl1; /* window update seg seq number */ 505067Swnj tcp_seq snd_wl2; /* window update seg ack number */ 515067Swnj tcp_seq iss; /* initial send sequence number */ 5257433Sandrew u_long snd_wnd; /* send window */ 535067Swnj /* receive sequence variables */ 5457433Sandrew u_long rcv_wnd; /* receive window */ 555067Swnj tcp_seq rcv_nxt; /* receive next */ 565067Swnj tcp_seq rcv_up; /* receive urgent pointer */ 575067Swnj tcp_seq irs; /* initial receive sequence number */ 585067Swnj /* 595067Swnj * Additional variables for this implementation. 605067Swnj */ 615076Swnj /* receive variables */ 625076Swnj tcp_seq rcv_adv; /* advertised window */ 635067Swnj /* retransmit variables */ 6444376Skarels tcp_seq snd_max; /* highest sequence number sent; 6517359Skarels * used to recognize retransmits 6617359Skarels */ 6732099Skarels /* congestion control (for slow start, source quench, retransmit after loss) */ 6857433Sandrew u_long snd_cwnd; /* congestion-controlled window */ 6957433Sandrew u_long snd_ssthresh; /* snd_cwnd size threshhold for 7032099Skarels * for slow start exponential to 7144376Skarels * linear switch 7244376Skarels */ 7331726Skarels /* 7444376Skarels * transmit timing stuff. See below for scale of srtt and rttvar. 7532099Skarels * "Variance" is actually smoothed difference. 7631726Skarels */ 77*69643Skarels u_short t_idle; /* inactivity time */ 785166Swnj short t_rtt; /* round trip time */ 795166Swnj tcp_seq t_rtseq; /* sequence number being timed */ 8031726Skarels short t_srtt; /* smoothed round-trip time */ 8131726Skarels short t_rttvar; /* variance in round-trip time */ 8244376Skarels u_short t_rttmin; /* minimum rtt allowed */ 8357433Sandrew u_long max_sndwnd; /* largest window peer has offered */ 8444376Skarels 855443Swnj /* out-of-band data */ 865443Swnj char t_oobflags; /* have some */ 875550Swnj char t_iobc; /* input character */ 885443Swnj #define TCPOOB_HAVEDATA 0x01 8924822Skarels #define TCPOOB_HADDATA 0x02 9044376Skarels short t_softerror; /* possible error not yet reported */ 9157433Sandrew 9257433Sandrew /* RFC 1323 variables */ 9357433Sandrew u_char snd_scale; /* window scaling for send window */ 9457433Sandrew u_char rcv_scale; /* window scaling for recv window */ 9557433Sandrew u_char request_r_scale; /* pending window scaling */ 9657433Sandrew u_char requested_s_scale; 9757433Sandrew u_long ts_recent; /* timestamp echo data */ 9857433Sandrew u_long ts_recent_age; /* when last updated */ 9957433Sandrew tcp_seq last_ack_sent; 10057947Ssklower 10157947Ssklower /* TUBA stuff */ 10257947Ssklower caddr_t t_tuba_pcb; /* next level down pcb for TCP over z */ 1035067Swnj }; 1044808Swnj 1054881Swnj #define intotcpcb(ip) ((struct tcpcb *)(ip)->inp_ppcb) 1064881Swnj #define sototcpcb(so) (intotcpcb(sotoinpcb(so))) 1074881Swnj 10830527Skarels /* 10944376Skarels * The smoothed round-trip time and estimated variance 11044376Skarels * are stored as fixed point numbers scaled by the values below. 11144376Skarels * For convenience, these scales are also used in smoothing the average 11244376Skarels * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed). 11344376Skarels * With these scales, srtt has 3 bits to the right of the binary point, 11444376Skarels * and thus an "ALPHA" of 0.875. rttvar has 2 bits to the right of the 11544376Skarels * binary point, and is smoothed with an ALPHA of 0.75. 11644376Skarels */ 11744376Skarels #define TCP_RTT_SCALE 8 /* multiplier for srtt; 3 bits frac. */ 11844376Skarels #define TCP_RTT_SHIFT 3 /* shift for srtt; 3 bits frac. */ 11944376Skarels #define TCP_RTTVAR_SCALE 4 /* multiplier for rttvar; 2 bits */ 12044376Skarels #define TCP_RTTVAR_SHIFT 2 /* multiplier for rttvar; 2 bits */ 12144376Skarels 12244376Skarels /* 12344376Skarels * The initial retransmission should happen at rtt + 4 * rttvar. 12444376Skarels * Because of the way we do the smoothing, srtt and rttvar 12544376Skarels * will each average +1/2 tick of bias. When we compute 12644376Skarels * the retransmit timer, we want 1/2 tick of rounding and 12744376Skarels * 1 extra tick because of +-1/2 tick uncertainty in the 12844376Skarels * firing of the timer. The bias will give us exactly the 12944376Skarels * 1.5 tick we need. But, because the bias is 13044376Skarels * statistical, we have to test that we don't drop below 13144376Skarels * the minimum feasible timer (which is 2 ticks). 13244376Skarels * This macro assumes that the value of TCP_RTTVAR_SCALE 13344376Skarels * is the same as the multiplier for rttvar. 13444376Skarels */ 13544376Skarels #define TCP_REXMTVAL(tp) \ 13644376Skarels (((tp)->t_srtt >> TCP_RTT_SHIFT) + (tp)->t_rttvar) 13744376Skarels 13844376Skarels /* XXX 13944376Skarels * We want to avoid doing m_pullup on incoming packets but that 14044376Skarels * means avoiding dtom on the tcp reassembly code. That in turn means 14144376Skarels * keeping an mbuf pointer in the reassembly queue (since we might 14244376Skarels * have a cluster). As a quick hack, the source & destination 14344376Skarels * port numbers (which are no longer needed once we've located the 14444376Skarels * tcpcb) are overlayed with an mbuf pointer. 14544376Skarels */ 14644376Skarels #define REASS_MBUF(ti) (*(struct mbuf **)&((ti)->ti_t)) 14744376Skarels 14844376Skarels /* 14930527Skarels * TCP statistics. 15030527Skarels * Many of these should be kept per connection, 15130527Skarels * but that's inconvenient at the moment. 15230527Skarels */ 1534926Swnj struct tcpstat { 15430527Skarels u_long tcps_connattempt; /* connections initiated */ 15530527Skarels u_long tcps_accepts; /* connections accepted */ 15630527Skarels u_long tcps_connects; /* connections established */ 15730527Skarels u_long tcps_drops; /* connections dropped */ 15830527Skarels u_long tcps_conndrops; /* embryonic connections dropped */ 15930527Skarels u_long tcps_closed; /* conn. closed (includes drops) */ 16030527Skarels u_long tcps_segstimed; /* segs where we tried to get rtt */ 16130527Skarels u_long tcps_rttupdated; /* times we succeeded */ 16230527Skarels u_long tcps_delack; /* delayed acks sent */ 16330527Skarels u_long tcps_timeoutdrop; /* conn. dropped in rxmt timeout */ 16430527Skarels u_long tcps_rexmttimeo; /* retransmit timeouts */ 16530527Skarels u_long tcps_persisttimeo; /* persist timeouts */ 16630527Skarels u_long tcps_keeptimeo; /* keepalive timeouts */ 16730527Skarels u_long tcps_keepprobe; /* keepalive probes sent */ 16830527Skarels u_long tcps_keepdrops; /* connections dropped in keepalive */ 16930527Skarels 17030527Skarels u_long tcps_sndtotal; /* total packets sent */ 17130527Skarels u_long tcps_sndpack; /* data packets sent */ 17230527Skarels u_long tcps_sndbyte; /* data bytes sent */ 17330527Skarels u_long tcps_sndrexmitpack; /* data packets retransmitted */ 17430527Skarels u_long tcps_sndrexmitbyte; /* data bytes retransmitted */ 17530527Skarels u_long tcps_sndacks; /* ack-only packets sent */ 17630527Skarels u_long tcps_sndprobe; /* window probes sent */ 17730527Skarels u_long tcps_sndurg; /* packets sent with URG only */ 17830527Skarels u_long tcps_sndwinup; /* window update-only packets sent */ 17930527Skarels u_long tcps_sndctrl; /* control (SYN|FIN|RST) packets sent */ 18030527Skarels 18130527Skarels u_long tcps_rcvtotal; /* total packets received */ 18230527Skarels u_long tcps_rcvpack; /* packets received in sequence */ 18330527Skarels u_long tcps_rcvbyte; /* bytes received in sequence */ 18430527Skarels u_long tcps_rcvbadsum; /* packets received with ccksum errs */ 18530527Skarels u_long tcps_rcvbadoff; /* packets received with bad offset */ 18630527Skarels u_long tcps_rcvshort; /* packets received too short */ 18730527Skarels u_long tcps_rcvduppack; /* duplicate-only packets received */ 18830527Skarels u_long tcps_rcvdupbyte; /* duplicate-only bytes received */ 18930527Skarels u_long tcps_rcvpartduppack; /* packets with some duplicate data */ 19030527Skarels u_long tcps_rcvpartdupbyte; /* dup. bytes in part-dup. packets */ 19130527Skarels u_long tcps_rcvoopack; /* out-of-order packets received */ 19230527Skarels u_long tcps_rcvoobyte; /* out-of-order bytes received */ 19330527Skarels u_long tcps_rcvpackafterwin; /* packets with data after window */ 19430527Skarels u_long tcps_rcvbyteafterwin; /* bytes rcvd after window */ 19530527Skarels u_long tcps_rcvafterclose; /* packets rcvd after "close" */ 19630527Skarels u_long tcps_rcvwinprobe; /* rcvd window probe packets */ 19730527Skarels u_long tcps_rcvdupack; /* rcvd duplicate acks */ 19830527Skarels u_long tcps_rcvacktoomuch; /* rcvd acks for unsent data */ 19930527Skarels u_long tcps_rcvackpack; /* rcvd ack packets */ 20030527Skarels u_long tcps_rcvackbyte; /* bytes acked by rcvd acks */ 20130527Skarels u_long tcps_rcvwinupd; /* rcvd window update packets */ 20257433Sandrew u_long tcps_pawsdrop; /* segments dropped due to PAWS */ 20366740Sbostic u_long tcps_predack; /* times hdr predict ok for acks */ 20466740Sbostic u_long tcps_preddat; /* times hdr predict ok for data pkts */ 20566740Sbostic u_long tcps_pcbcachemiss; 206*69643Skarels u_long tcps_persistdrop; /* timeout in persist state */ 207*69643Skarels u_long tcps_badsyn; /* bogus SYN, e.g. premature ACK */ 2084926Swnj }; 2094926Swnj 2104808Swnj #ifdef KERNEL 2115067Swnj struct inpcb tcb; /* head of queue of active tcpcb's */ 2125067Swnj struct tcpstat tcpstat; /* tcp statistics */ 21357433Sandrew u_long tcp_now; /* for RFC 1323 timestamps */ 21461335Sbostic 21561335Sbostic int tcp_attach __P((struct socket *)); 21661335Sbostic void tcp_canceltimers __P((struct tcpcb *)); 21761335Sbostic struct tcpcb * 21861335Sbostic tcp_close __P((struct tcpcb *)); 21961335Sbostic void tcp_ctlinput __P((int, struct sockaddr *, struct ip *)); 22061335Sbostic int tcp_ctloutput __P((int, struct socket *, int, int, struct mbuf **)); 22161335Sbostic struct tcpcb * 22261335Sbostic tcp_disconnect __P((struct tcpcb *)); 22361335Sbostic struct tcpcb * 22461335Sbostic tcp_drop __P((struct tcpcb *, int)); 22561335Sbostic void tcp_dooptions __P((struct tcpcb *, 22661335Sbostic u_char *, int, struct tcpiphdr *, int *, u_long *, u_long *)); 22761335Sbostic void tcp_drain __P((void)); 22861335Sbostic void tcp_fasttimo __P((void)); 22961335Sbostic void tcp_init __P((void)); 23061335Sbostic void tcp_input __P((struct mbuf *, int)); 23165607Sbostic int tcp_mss __P((struct tcpcb *, u_int)); 23261335Sbostic struct tcpcb * 23361335Sbostic tcp_newtcpcb __P((struct inpcb *)); 23461335Sbostic void tcp_notify __P((struct inpcb *, int)); 23561335Sbostic int tcp_output __P((struct tcpcb *)); 23661335Sbostic void tcp_pulloutofband __P((struct socket *, 23761335Sbostic struct tcpiphdr *, struct mbuf *)); 23861335Sbostic void tcp_quench __P((struct inpcb *, int)); 23961335Sbostic int tcp_reass __P((struct tcpcb *, struct tcpiphdr *, struct mbuf *)); 24061335Sbostic void tcp_respond __P((struct tcpcb *, 24161335Sbostic struct tcpiphdr *, struct mbuf *, u_long, u_long, int)); 24261335Sbostic void tcp_setpersist __P((struct tcpcb *)); 24361335Sbostic void tcp_slowtimo __P((void)); 24461335Sbostic struct tcpiphdr * 24561335Sbostic tcp_template __P((struct tcpcb *)); 24661335Sbostic struct tcpcb * 24761335Sbostic tcp_timers __P((struct tcpcb *, int)); 24861335Sbostic void tcp_trace __P((int, int, struct tcpcb *, struct tcpiphdr *, int)); 24961335Sbostic struct tcpcb * 25061335Sbostic tcp_usrclosed __P((struct tcpcb *)); 25161335Sbostic int tcp_usrreq __P((struct socket *, 25261335Sbostic int, struct mbuf *, struct mbuf *, struct mbuf *)); 25361335Sbostic void tcp_xmit_timer __P((struct tcpcb *, int)); 2544808Swnj #endif 255