123197Smckusick /* 229156Smckusick * Copyright (c) 1982, 1986 Regents of the University of California. 332789Sbostic * All rights reserved. 423197Smckusick * 532789Sbostic * Redistribution and use in source and binary forms are permitted 634855Sbostic * provided that the above copyright notice and this paragraph are 734855Sbostic * duplicated in all such forms and that any documentation, 834855Sbostic * advertising materials, and other materials related to such 934855Sbostic * distribution and use acknowledge that the software was developed 1034855Sbostic * by the University of California, Berkeley. The name of the 1134855Sbostic * University may not be used to endorse or promote products derived 1234855Sbostic * from this software without specific prior written permission. 1334855Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1434855Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1534855Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1632789Sbostic * 17*44376Skarels * @(#)tcp_var.h 7.9 (Berkeley) 06/28/90 1823197Smckusick */ 194808Swnj 204808Swnj /* 214808Swnj * Kernel variables for tcp. 224808Swnj */ 234808Swnj 244808Swnj /* 255166Swnj * Tcp control block, one per tcp; fields: 264808Swnj */ 274881Swnj struct tcpcb { 285076Swnj struct tcpiphdr *seg_next; /* sequencing queue */ 295076Swnj struct tcpiphdr *seg_prev; 305246Sroot short t_state; /* state of this connection */ 315092Swnj short t_timer[TCPT_NTIMERS]; /* tcp timers */ 325166Swnj short t_rxtshift; /* log(2) of rexmt exp. backoff */ 3332034Skarels short t_rxtcur; /* current retransmit value */ 3432099Skarels short t_dupacks; /* consecutive dup acks recd */ 3527068Skarels u_short t_maxseg; /* maximum segment size */ 365246Sroot char t_force; /* 1 if forcing out a byte */ 375067Swnj u_char t_flags; 3825894Skarels #define TF_ACKNOW 0x01 /* ack peer immediately */ 3925894Skarels #define TF_DELACK 0x02 /* ack, but try to delay it */ 4025894Skarels #define TF_NODELAY 0x04 /* don't delay packets to coalesce */ 4125894Skarels #define TF_NOOPT 0x08 /* don't use tcp options */ 4227068Skarels #define TF_SENTFIN 0x10 /* have sent FIN */ 434881Swnj struct tcpiphdr *t_template; /* skeletal packet for transmit */ 445067Swnj struct inpcb *t_inpcb; /* back pointer to internet pcb */ 454808Swnj /* 465067Swnj * The following fields are used as in the protocol specification. 475067Swnj * See RFC783, Dec. 1981, page 21. 484808Swnj */ 495067Swnj /* send sequence variables */ 505067Swnj tcp_seq snd_una; /* send unacknowledged */ 515067Swnj tcp_seq snd_nxt; /* send next */ 525067Swnj tcp_seq snd_up; /* send urgent pointer */ 535067Swnj tcp_seq snd_wl1; /* window update seg seq number */ 545067Swnj tcp_seq snd_wl2; /* window update seg ack number */ 555067Swnj tcp_seq iss; /* initial send sequence number */ 565246Sroot u_short snd_wnd; /* send window */ 575067Swnj /* receive sequence variables */ 5825894Skarels u_short rcv_wnd; /* receive window */ 595067Swnj tcp_seq rcv_nxt; /* receive next */ 605067Swnj tcp_seq rcv_up; /* receive urgent pointer */ 615067Swnj tcp_seq irs; /* initial receive sequence number */ 625067Swnj /* 635067Swnj * Additional variables for this implementation. 645067Swnj */ 655076Swnj /* receive variables */ 665076Swnj tcp_seq rcv_adv; /* advertised window */ 675067Swnj /* retransmit variables */ 68*44376Skarels tcp_seq snd_max; /* highest sequence number sent; 6917359Skarels * used to recognize retransmits 7017359Skarels */ 7132099Skarels /* congestion control (for slow start, source quench, retransmit after loss) */ 7217359Skarels u_short snd_cwnd; /* congestion-controlled window */ 7332099Skarels u_short snd_ssthresh; /* snd_cwnd size threshhold for 7432099Skarels * for slow start exponential to 75*44376Skarels * linear switch 76*44376Skarels */ 7731726Skarels /* 78*44376Skarels * transmit timing stuff. See below for scale of srtt and rttvar. 7932099Skarels * "Variance" is actually smoothed difference. 8031726Skarels */ 815166Swnj short t_idle; /* inactivity time */ 825166Swnj short t_rtt; /* round trip time */ 835166Swnj tcp_seq t_rtseq; /* sequence number being timed */ 8431726Skarels short t_srtt; /* smoothed round-trip time */ 8531726Skarels short t_rttvar; /* variance in round-trip time */ 86*44376Skarels u_short t_rttmin; /* minimum rtt allowed */ 8725262Skarels u_short max_sndwnd; /* largest window peer has offered */ 88*44376Skarels 895443Swnj /* out-of-band data */ 905443Swnj char t_oobflags; /* have some */ 915550Swnj char t_iobc; /* input character */ 925443Swnj #define TCPOOB_HAVEDATA 0x01 9324822Skarels #define TCPOOB_HADDATA 0x02 94*44376Skarels short t_softerror; /* possible error not yet reported */ 955067Swnj }; 964808Swnj 974881Swnj #define intotcpcb(ip) ((struct tcpcb *)(ip)->inp_ppcb) 984881Swnj #define sototcpcb(so) (intotcpcb(sotoinpcb(so))) 994881Swnj 10030527Skarels /* 101*44376Skarels * The smoothed round-trip time and estimated variance 102*44376Skarels * are stored as fixed point numbers scaled by the values below. 103*44376Skarels * For convenience, these scales are also used in smoothing the average 104*44376Skarels * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed). 105*44376Skarels * With these scales, srtt has 3 bits to the right of the binary point, 106*44376Skarels * and thus an "ALPHA" of 0.875. rttvar has 2 bits to the right of the 107*44376Skarels * binary point, and is smoothed with an ALPHA of 0.75. 108*44376Skarels */ 109*44376Skarels #define TCP_RTT_SCALE 8 /* multiplier for srtt; 3 bits frac. */ 110*44376Skarels #define TCP_RTT_SHIFT 3 /* shift for srtt; 3 bits frac. */ 111*44376Skarels #define TCP_RTTVAR_SCALE 4 /* multiplier for rttvar; 2 bits */ 112*44376Skarels #define TCP_RTTVAR_SHIFT 2 /* multiplier for rttvar; 2 bits */ 113*44376Skarels 114*44376Skarels /* 115*44376Skarels * The initial retransmission should happen at rtt + 4 * rttvar. 116*44376Skarels * Because of the way we do the smoothing, srtt and rttvar 117*44376Skarels * will each average +1/2 tick of bias. When we compute 118*44376Skarels * the retransmit timer, we want 1/2 tick of rounding and 119*44376Skarels * 1 extra tick because of +-1/2 tick uncertainty in the 120*44376Skarels * firing of the timer. The bias will give us exactly the 121*44376Skarels * 1.5 tick we need. But, because the bias is 122*44376Skarels * statistical, we have to test that we don't drop below 123*44376Skarels * the minimum feasible timer (which is 2 ticks). 124*44376Skarels * This macro assumes that the value of TCP_RTTVAR_SCALE 125*44376Skarels * is the same as the multiplier for rttvar. 126*44376Skarels */ 127*44376Skarels #define TCP_REXMTVAL(tp) \ 128*44376Skarels (((tp)->t_srtt >> TCP_RTT_SHIFT) + (tp)->t_rttvar) 129*44376Skarels 130*44376Skarels /* XXX 131*44376Skarels * We want to avoid doing m_pullup on incoming packets but that 132*44376Skarels * means avoiding dtom on the tcp reassembly code. That in turn means 133*44376Skarels * keeping an mbuf pointer in the reassembly queue (since we might 134*44376Skarels * have a cluster). As a quick hack, the source & destination 135*44376Skarels * port numbers (which are no longer needed once we've located the 136*44376Skarels * tcpcb) are overlayed with an mbuf pointer. 137*44376Skarels */ 138*44376Skarels #define REASS_MBUF(ti) (*(struct mbuf **)&((ti)->ti_t)) 139*44376Skarels 140*44376Skarels /* 14130527Skarels * TCP statistics. 14230527Skarels * Many of these should be kept per connection, 14330527Skarels * but that's inconvenient at the moment. 14430527Skarels */ 1454926Swnj struct tcpstat { 14630527Skarels u_long tcps_connattempt; /* connections initiated */ 14730527Skarels u_long tcps_accepts; /* connections accepted */ 14830527Skarels u_long tcps_connects; /* connections established */ 14930527Skarels u_long tcps_drops; /* connections dropped */ 15030527Skarels u_long tcps_conndrops; /* embryonic connections dropped */ 15130527Skarels u_long tcps_closed; /* conn. closed (includes drops) */ 15230527Skarels u_long tcps_segstimed; /* segs where we tried to get rtt */ 15330527Skarels u_long tcps_rttupdated; /* times we succeeded */ 15430527Skarels u_long tcps_delack; /* delayed acks sent */ 15530527Skarels u_long tcps_timeoutdrop; /* conn. dropped in rxmt timeout */ 15630527Skarels u_long tcps_rexmttimeo; /* retransmit timeouts */ 15730527Skarels u_long tcps_persisttimeo; /* persist timeouts */ 15830527Skarels u_long tcps_keeptimeo; /* keepalive timeouts */ 15930527Skarels u_long tcps_keepprobe; /* keepalive probes sent */ 16030527Skarels u_long tcps_keepdrops; /* connections dropped in keepalive */ 16130527Skarels 16230527Skarels u_long tcps_sndtotal; /* total packets sent */ 16330527Skarels u_long tcps_sndpack; /* data packets sent */ 16430527Skarels u_long tcps_sndbyte; /* data bytes sent */ 16530527Skarels u_long tcps_sndrexmitpack; /* data packets retransmitted */ 16630527Skarels u_long tcps_sndrexmitbyte; /* data bytes retransmitted */ 16730527Skarels u_long tcps_sndacks; /* ack-only packets sent */ 16830527Skarels u_long tcps_sndprobe; /* window probes sent */ 16930527Skarels u_long tcps_sndurg; /* packets sent with URG only */ 17030527Skarels u_long tcps_sndwinup; /* window update-only packets sent */ 17130527Skarels u_long tcps_sndctrl; /* control (SYN|FIN|RST) packets sent */ 17230527Skarels 17330527Skarels u_long tcps_rcvtotal; /* total packets received */ 17430527Skarels u_long tcps_rcvpack; /* packets received in sequence */ 17530527Skarels u_long tcps_rcvbyte; /* bytes received in sequence */ 17630527Skarels u_long tcps_rcvbadsum; /* packets received with ccksum errs */ 17730527Skarels u_long tcps_rcvbadoff; /* packets received with bad offset */ 17830527Skarels u_long tcps_rcvshort; /* packets received too short */ 17930527Skarels u_long tcps_rcvduppack; /* duplicate-only packets received */ 18030527Skarels u_long tcps_rcvdupbyte; /* duplicate-only bytes received */ 18130527Skarels u_long tcps_rcvpartduppack; /* packets with some duplicate data */ 18230527Skarels u_long tcps_rcvpartdupbyte; /* dup. bytes in part-dup. packets */ 18330527Skarels u_long tcps_rcvoopack; /* out-of-order packets received */ 18430527Skarels u_long tcps_rcvoobyte; /* out-of-order bytes received */ 18530527Skarels u_long tcps_rcvpackafterwin; /* packets with data after window */ 18630527Skarels u_long tcps_rcvbyteafterwin; /* bytes rcvd after window */ 18730527Skarels u_long tcps_rcvafterclose; /* packets rcvd after "close" */ 18830527Skarels u_long tcps_rcvwinprobe; /* rcvd window probe packets */ 18930527Skarels u_long tcps_rcvdupack; /* rcvd duplicate acks */ 19030527Skarels u_long tcps_rcvacktoomuch; /* rcvd acks for unsent data */ 19130527Skarels u_long tcps_rcvackpack; /* rcvd ack packets */ 19230527Skarels u_long tcps_rcvackbyte; /* bytes acked by rcvd acks */ 19330527Skarels u_long tcps_rcvwinupd; /* rcvd window update packets */ 1944926Swnj }; 1954926Swnj 1964808Swnj #ifdef KERNEL 1975067Swnj struct inpcb tcb; /* head of queue of active tcpcb's */ 1985067Swnj struct tcpstat tcpstat; /* tcp statistics */ 1994881Swnj struct tcpiphdr *tcp_template(); 20010398Ssam struct tcpcb *tcp_close(), *tcp_drop(); 20110398Ssam struct tcpcb *tcp_timers(), *tcp_disconnect(), *tcp_usrclosed(); 2024808Swnj #endif 203