00001 /* 00002 * Copyright (c) 1982, 1986, 1993, 1994, 1995 00003 * The Regents of the University of California. All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. All advertising materials mentioning features or use of this software 00014 * must display the following acknowledgement: 00015 * This product includes software developed by the University of 00016 * California, Berkeley and its contributors. 00017 * 4. Neither the name of the University nor the names of its contributors 00018 * may be used to endorse or promote products derived from this software 00019 * without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 00022 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00023 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00024 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 00025 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00026 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00027 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00028 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00029 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00030 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00031 * SUCH DAMAGE. 00032 * 00033 * @(#)tcp_var.h 8.4 (Berkeley) 5/24/95 00034 */ 00035 00036 /* 00037 * Kernel variables for tcp. 00038 */ 00039 00040 /* 00041 * Tcp control block, one per tcp; fields: 00042 */ 00043 struct tcpcb { 00044 struct tcpiphdr *seg_next; /* sequencing queue */ 00045 struct tcpiphdr *seg_prev; 00046 short t_state; /* state of this connection */ 00047 short t_timer[TCPT_NTIMERS]; /* tcp timers */ 00048 short t_rxtshift; /* log(2) of rexmt exp. backoff */ 00049 short t_rxtcur; /* current retransmit value */ 00050 short t_dupacks; /* consecutive dup acks recd */ 00051 u_short t_maxseg; /* maximum segment size */ 00052 char t_force; /* 1 if forcing out a byte */ 00053 u_short t_flags; 00054 #define TF_ACKNOW 0x0001 /* ack peer immediately */ 00055 #define TF_DELACK 0x0002 /* ack, but try to delay it */ 00056 #define TF_NODELAY 0x0004 /* don't delay packets to coalesce */ 00057 #define TF_NOOPT 0x0008 /* don't use tcp options */ 00058 #define TF_SENTFIN 0x0010 /* have sent FIN */ 00059 #define TF_REQ_SCALE 0x0020 /* have/will request window scaling */ 00060 #define TF_RCVD_SCALE 0x0040 /* other side has requested scaling */ 00061 #define TF_REQ_TSTMP 0x0080 /* have/will request timestamps */ 00062 #define TF_RCVD_TSTMP 0x0100 /* a timestamp was received in SYN */ 00063 #define TF_SACK_PERMIT 0x0200 /* other side said I could SACK */ 00064 00065 struct tcpiphdr *t_template; /* skeletal packet for transmit */ 00066 struct inpcb *t_inpcb; /* back pointer to internet pcb */ 00067 /* 00068 * The following fields are used as in the protocol specification. 00069 * See RFC783, Dec. 1981, page 21. 00070 */ 00071 /* send sequence variables */ 00072 tcp_seq snd_una; /* send unacknowledged */ 00073 tcp_seq snd_nxt; /* send next */ 00074 tcp_seq snd_up; /* send urgent pointer */ 00075 tcp_seq snd_wl1; /* window update seg seq number */ 00076 tcp_seq snd_wl2; /* window update seg ack number */ 00077 tcp_seq iss; /* initial send sequence number */ 00078 n_long snd_wnd; /* send window */ 00079 /* receive sequence variables */ 00080 n_long rcv_wnd; /* receive window */ 00081 tcp_seq rcv_nxt; /* receive next */ 00082 tcp_seq rcv_up; /* receive urgent pointer */ 00083 tcp_seq irs; /* initial receive sequence number */ 00084 /* 00085 * Additional variables for this implementation. 00086 */ 00087 /* receive variables */ 00088 tcp_seq rcv_adv; /* advertised window */ 00089 /* retransmit variables */ 00090 tcp_seq snd_max; /* highest sequence number sent; 00091 * used to recognize retransmits 00092 */ 00093 /* congestion control (for slow start, source quench, retransmit after loss) */ 00094 n_long snd_cwnd; /* congestion-controlled window */ 00095 n_long snd_ssthresh; /* snd_cwnd size threshhold for 00096 * for slow start exponential to 00097 * linear switch 00098 */ 00099 /* 00100 * transmit timing stuff. See below for scale of srtt and rttvar. 00101 * "Variance" is actually smoothed difference. 00102 */ 00103 u_short t_idle; /* inactivity time */ 00104 short t_rtt; /* round trip time */ 00105 tcp_seq t_rtseq; /* sequence number being timed */ 00106 short t_srtt; /* smoothed round-trip time */ 00107 short t_rttvar; /* variance in round-trip time */ 00108 u_short t_rttmin; /* minimum rtt allowed */ 00109 n_long max_sndwnd; /* largest window peer has offered */ 00110 00111 /* out-of-band data */ 00112 char t_oobflags; /* have some */ 00113 char t_iobc; /* input character */ 00114 #define TCPOOB_HAVEDATA 0x01 00115 #define TCPOOB_HADDATA 0x02 00116 short t_softerror; /* possible error not yet reported */ 00117 00118 /* RFC 1323 variables */ 00119 u_char snd_scale; /* window scaling for send window */ 00120 u_char rcv_scale; /* window scaling for recv window */ 00121 u_char request_r_scale; /* pending window scaling */ 00122 u_char requested_s_scale; 00123 n_long ts_recent; /* timestamp echo data */ 00124 n_long ts_recent_age; /* when last updated */ 00125 tcp_seq last_ack_sent; 00126 00127 /* TUBA stuff */ 00128 caddr_t t_tuba_pcb; /* next level down pcb for TCP over z */ 00129 }; 00130 00131 #define intotcpcb(ip) ((struct tcpcb *)(ip)->inp_ppcb) 00132 #define sototcpcb(so) (intotcpcb(sotoinpcb(so))) 00133 00134 /* 00135 * The smoothed round-trip time and estimated variance 00136 * are stored as fixed point numbers scaled by the values below. 00137 * For convenience, these scales are also used in smoothing the average 00138 * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed). 00139 * With these scales, srtt has 3 bits to the right of the binary point, 00140 * and thus an "ALPHA" of 0.875. rttvar has 2 bits to the right of the 00141 * binary point, and is smoothed with an ALPHA of 0.75. 00142 */ 00143 #define TCP_RTT_SCALE 8 /* multiplier for srtt; 3 bits frac. */ 00144 #define TCP_RTT_SHIFT 3 /* shift for srtt; 3 bits frac. */ 00145 #define TCP_RTTVAR_SCALE 4 /* multiplier for rttvar; 2 bits */ 00146 #define TCP_RTTVAR_SHIFT 2 /* multiplier for rttvar; 2 bits */ 00147 00148 /* 00149 * The initial retransmission should happen at rtt + 4 * rttvar. 00150 * Because of the way we do the smoothing, srtt and rttvar 00151 * will each average +1/2 tick of bias. When we compute 00152 * the retransmit timer, we want 1/2 tick of rounding and 00153 * 1 extra tick because of +-1/2 tick uncertainty in the 00154 * firing of the timer. The bias will give us exactly the 00155 * 1.5 tick we need. But, because the bias is 00156 * statistical, we have to test that we don't drop below 00157 * the minimum feasible timer (which is 2 ticks). 00158 * This macro assumes that the value of TCP_RTTVAR_SCALE 00159 * is the same as the multiplier for rttvar. 00160 */ 00161 #define TCP_REXMTVAL(tp) \ 00162 (((tp)->t_srtt >> TCP_RTT_SHIFT) + (tp)->t_rttvar) 00163 00164 /* XXX 00165 * We want to avoid doing m_pullup on incoming packets but that 00166 * means avoiding dtom on the tcp reassembly code. That in turn means 00167 * keeping an mbuf pointer in the reassembly queue (since we might 00168 * have a cluster). As a quick hack, the source & destination 00169 * port numbers (which are no longer needed once we've located the 00170 * tcpcb) are overlayed with an mbuf pointer. 00171 */ 00172 #define REASS_MBUF(ti) (*(struct mbuf **)&((ti)->ti_t)) 00173 00174 /* 00175 * TCP statistics. 00176 * Many of these should be kept per connection, 00177 * but that's inconvenient at the moment. 00178 */ 00179 struct tcpstat { 00180 n_long tcps_connattempt; /* connections initiated */ 00181 n_long tcps_accepts; /* connections accepted */ 00182 n_long tcps_connects; /* connections established */ 00183 n_long tcps_drops; /* connections dropped */ 00184 n_long tcps_conndrops; /* embryonic connections dropped */ 00185 n_long tcps_closed; /* conn. closed (includes drops) */ 00186 n_long tcps_segstimed; /* segs where we tried to get rtt */ 00187 n_long tcps_rttupdated; /* times we succeeded */ 00188 n_long tcps_delack; /* delayed acks sent */ 00189 n_long tcps_timeoutdrop; /* conn. dropped in rxmt timeout */ 00190 n_long tcps_rexmttimeo; /* retransmit timeouts */ 00191 n_long tcps_persisttimeo; /* persist timeouts */ 00192 n_long tcps_keeptimeo; /* keepalive timeouts */ 00193 n_long tcps_keepprobe; /* keepalive probes sent */ 00194 n_long tcps_keepdrops; /* connections dropped in keepalive */ 00195 00196 n_long tcps_sndtotal; /* total packets sent */ 00197 n_long tcps_sndpack; /* data packets sent */ 00198 n_long tcps_sndbyte; /* data bytes sent */ 00199 n_long tcps_sndrexmitpack; /* data packets retransmitted */ 00200 n_long tcps_sndrexmitbyte; /* data bytes retransmitted */ 00201 n_long tcps_sndacks; /* ack-only packets sent */ 00202 n_long tcps_sndprobe; /* window probes sent */ 00203 n_long tcps_sndurg; /* packets sent with URG only */ 00204 n_long tcps_sndwinup; /* window update-only packets sent */ 00205 n_long tcps_sndctrl; /* control (SYN|FIN|RST) packets sent */ 00206 00207 n_long tcps_rcvtotal; /* total packets received */ 00208 n_long tcps_rcvpack; /* packets received in sequence */ 00209 n_long tcps_rcvbyte; /* bytes received in sequence */ 00210 n_long tcps_rcvbadsum; /* packets received with ccksum errs */ 00211 n_long tcps_rcvbadoff; /* packets received with bad offset */ 00212 n_long tcps_rcvshort; /* packets received too short */ 00213 n_long tcps_rcvduppack; /* duplicate-only packets received */ 00214 n_long tcps_rcvdupbyte; /* duplicate-only bytes received */ 00215 n_long tcps_rcvpartduppack; /* packets with some duplicate data */ 00216 n_long tcps_rcvpartdupbyte; /* dup. bytes in part-dup. packets */ 00217 n_long tcps_rcvoopack; /* out-of-order packets received */ 00218 n_long tcps_rcvoobyte; /* out-of-order bytes received */ 00219 n_long tcps_rcvpackafterwin; /* packets with data after window */ 00220 n_long tcps_rcvbyteafterwin; /* bytes rcvd after window */ 00221 n_long tcps_rcvafterclose; /* packets rcvd after "close" */ 00222 n_long tcps_rcvwinprobe; /* rcvd window probe packets */ 00223 n_long tcps_rcvdupack; /* rcvd duplicate acks */ 00224 n_long tcps_rcvacktoomuch; /* rcvd acks for unsent data */ 00225 n_long tcps_rcvackpack; /* rcvd ack packets */ 00226 n_long tcps_rcvackbyte; /* bytes acked by rcvd acks */ 00227 n_long tcps_rcvwinupd; /* rcvd window update packets */ 00228 n_long tcps_pawsdrop; /* segments dropped due to PAWS */ 00229 n_long tcps_predack; /* times hdr predict ok for acks */ 00230 n_long tcps_preddat; /* times hdr predict ok for data pkts */ 00231 n_long tcps_pcbcachemiss; 00232 n_long tcps_persistdrop; /* timeout in persist state */ 00233 n_long tcps_badsyn; /* bogus SYN, e.g. premature ACK */ 00234 }; 00235 00236 #ifdef KERNEL 00237 struct inpcb tcb; /* head of queue of active tcpcb's */ 00238 struct tcpstat tcpstat; /* tcp statistics */ 00239 n_long tcp_now; /* for RFC 1323 timestamps */ 00240 00241 int tcp_attach __P((struct socket *)); 00242 void tcp_canceltimers __P((struct tcpcb *)); 00243 struct tcpcb * 00244 tcp_close __P((struct tcpcb *)); 00245 void tcp_ctlinput __P((int, struct sockaddr *, struct ip *)); 00246 int tcp_ctloutput __P((int, struct socket *, int, int, struct mbuf **)); 00247 struct tcpcb * 00248 tcp_disconnect __P((struct tcpcb *)); 00249 struct tcpcb * 00250 tcp_drop __P((struct tcpcb *, int)); 00251 void tcp_dooptions __P((struct tcpcb *, 00252 u_char *, int, struct tcpiphdr *, int *, n_long *, n_long *)); 00253 void tcp_drain __P((void)); 00254 void tcp_fasttimo __P((void)); 00255 void tcp_init __P((void)); 00256 void tcp_input __P((struct mbuf *, int)); 00257 int tcp_mss __P((struct tcpcb *, u_int)); 00258 struct tcpcb * 00259 tcp_newtcpcb __P((struct inpcb *)); 00260 void tcp_notify __P((struct inpcb *, int)); 00261 int tcp_output __P((struct tcpcb *)); 00262 void tcp_pulloutofband __P((struct socket *, 00263 struct tcpiphdr *, struct mbuf *)); 00264 void tcp_quench __P((struct inpcb *, int)); 00265 int tcp_reass __P((struct tcpcb *, struct tcpiphdr *, struct mbuf *)); 00266 void tcp_respond __P((struct tcpcb *, 00267 struct tcpiphdr *, struct mbuf *, n_long, n_long, int)); 00268 void tcp_setpersist __P((struct tcpcb *)); 00269 void tcp_slowtimo __P((void)); 00270 struct tcpiphdr * 00271 tcp_template __P((struct tcpcb *)); 00272 struct tcpcb * 00273 tcp_timers __P((struct tcpcb *, int)); 00274 void tcp_trace __P((int, int, struct tcpcb *, struct tcpiphdr *, int)); 00275 struct tcpcb * 00276 tcp_usrclosed __P((struct tcpcb *)); 00277 int tcp_usrreq __P((struct socket *, 00278 int, struct mbuf *, struct mbuf *, struct mbuf *)); 00279 void tcp_xmit_timer __P((struct tcpcb *, int)); 00280 #endif