Statistics
| Branch: | Revision:

root / slirp / tcp_var.h @ 94909d9f

History | View | Annotate | Download (9.7 kB)

1 f0cbd3ec bellard
/*
2 f0cbd3ec bellard
 * Copyright (c) 1982, 1986, 1993, 1994
3 f0cbd3ec bellard
 *        The Regents of the University of California.  All rights reserved.
4 f0cbd3ec bellard
 *
5 f0cbd3ec bellard
 * Redistribution and use in source and binary forms, with or without
6 f0cbd3ec bellard
 * modification, are permitted provided that the following conditions
7 f0cbd3ec bellard
 * are met:
8 f0cbd3ec bellard
 * 1. Redistributions of source code must retain the above copyright
9 f0cbd3ec bellard
 *    notice, this list of conditions and the following disclaimer.
10 f0cbd3ec bellard
 * 2. Redistributions in binary form must reproduce the above copyright
11 f0cbd3ec bellard
 *    notice, this list of conditions and the following disclaimer in the
12 f0cbd3ec bellard
 *    documentation and/or other materials provided with the distribution.
13 2f5f8996 aliguori
 * 3. Neither the name of the University nor the names of its contributors
14 f0cbd3ec bellard
 *    may be used to endorse or promote products derived from this software
15 f0cbd3ec bellard
 *    without specific prior written permission.
16 f0cbd3ec bellard
 *
17 f0cbd3ec bellard
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 f0cbd3ec bellard
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 f0cbd3ec bellard
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 f0cbd3ec bellard
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 f0cbd3ec bellard
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 f0cbd3ec bellard
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 f0cbd3ec bellard
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 f0cbd3ec bellard
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 f0cbd3ec bellard
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 f0cbd3ec bellard
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 f0cbd3ec bellard
 * SUCH DAMAGE.
28 f0cbd3ec bellard
 *
29 f0cbd3ec bellard
 *        @(#)tcp_var.h        8.3 (Berkeley) 4/10/94
30 f0cbd3ec bellard
 * tcp_var.h,v 1.3 1994/08/21 05:27:39 paul Exp
31 f0cbd3ec bellard
 */
32 f0cbd3ec bellard
33 f0cbd3ec bellard
#ifndef _TCP_VAR_H_
34 f0cbd3ec bellard
#define _TCP_VAR_H_
35 f0cbd3ec bellard
36 f0cbd3ec bellard
#include "tcpip.h"
37 f0cbd3ec bellard
#include "tcp_timer.h"
38 f0cbd3ec bellard
39 f0cbd3ec bellard
/*
40 f0cbd3ec bellard
 * Tcp control block, one per tcp; fields:
41 f0cbd3ec bellard
 */
42 f0cbd3ec bellard
struct tcpcb {
43 429d0a3d blueswir1
        struct tcpiphdr *seg_next;        /* sequencing queue */
44 429d0a3d blueswir1
        struct tcpiphdr *seg_prev;
45 f0cbd3ec bellard
        short        t_state;                /* state of this connection */
46 f0cbd3ec bellard
        short        t_timer[TCPT_NTIMERS];        /* tcp timers */
47 f0cbd3ec bellard
        short        t_rxtshift;                /* log(2) of rexmt exp. backoff */
48 f0cbd3ec bellard
        short        t_rxtcur;                /* current retransmit value */
49 f0cbd3ec bellard
        short        t_dupacks;                /* consecutive dup acks recd */
50 f0cbd3ec bellard
        u_short        t_maxseg;                /* maximum segment size */
51 f0cbd3ec bellard
        char        t_force;                /* 1 if forcing out a byte */
52 f0cbd3ec bellard
        u_short        t_flags;
53 f0cbd3ec bellard
#define        TF_ACKNOW        0x0001                /* ack peer immediately */
54 f0cbd3ec bellard
#define        TF_DELACK        0x0002                /* ack, but try to delay it */
55 f0cbd3ec bellard
#define        TF_NODELAY        0x0004                /* don't delay packets to coalesce */
56 f0cbd3ec bellard
#define        TF_NOOPT        0x0008                /* don't use tcp options */
57 f0cbd3ec bellard
#define        TF_SENTFIN        0x0010                /* have sent FIN */
58 f0cbd3ec bellard
#define        TF_REQ_SCALE        0x0020                /* have/will request window scaling */
59 f0cbd3ec bellard
#define        TF_RCVD_SCALE        0x0040                /* other side has requested scaling */
60 f0cbd3ec bellard
#define        TF_REQ_TSTMP        0x0080                /* have/will request timestamps */
61 f0cbd3ec bellard
#define        TF_RCVD_TSTMP        0x0100                /* a timestamp was received in SYN */
62 f0cbd3ec bellard
#define        TF_SACK_PERMIT        0x0200                /* other side said I could SACK */
63 f0cbd3ec bellard
64 f0cbd3ec bellard
        /* Make it static  for now */
65 f0cbd3ec bellard
/*        struct        tcpiphdr *t_template;        / * skeletal packet for transmit */
66 f0cbd3ec bellard
        struct        tcpiphdr t_template;
67 f0cbd3ec bellard
68 f0cbd3ec bellard
        struct        socket *t_socket;                /* back pointer to socket */
69 f0cbd3ec bellard
/*
70 f0cbd3ec bellard
 * The following fields are used as in the protocol specification.
71 f0cbd3ec bellard
 * See RFC783, Dec. 1981, page 21.
72 f0cbd3ec bellard
 */
73 f0cbd3ec bellard
/* send sequence variables */
74 f0cbd3ec bellard
        tcp_seq        snd_una;                /* send unacknowledged */
75 f0cbd3ec bellard
        tcp_seq        snd_nxt;                /* send next */
76 f0cbd3ec bellard
        tcp_seq        snd_up;                        /* send urgent pointer */
77 f0cbd3ec bellard
        tcp_seq        snd_wl1;                /* window update seg seq number */
78 f0cbd3ec bellard
        tcp_seq        snd_wl2;                /* window update seg ack number */
79 f0cbd3ec bellard
        tcp_seq        iss;                        /* initial send sequence number */
80 f0cbd3ec bellard
        u_int32_t snd_wnd;                /* send window */
81 f0cbd3ec bellard
/* receive sequence variables */
82 f0cbd3ec bellard
        u_int32_t rcv_wnd;                /* receive window */
83 f0cbd3ec bellard
        tcp_seq        rcv_nxt;                /* receive next */
84 f0cbd3ec bellard
        tcp_seq        rcv_up;                        /* receive urgent pointer */
85 f0cbd3ec bellard
        tcp_seq        irs;                        /* initial receive sequence number */
86 f0cbd3ec bellard
/*
87 f0cbd3ec bellard
 * Additional variables for this implementation.
88 f0cbd3ec bellard
 */
89 f0cbd3ec bellard
/* receive variables */
90 f0cbd3ec bellard
        tcp_seq        rcv_adv;                /* advertised window */
91 f0cbd3ec bellard
/* retransmit variables */
92 f0cbd3ec bellard
        tcp_seq        snd_max;                /* highest sequence number sent;
93 f0cbd3ec bellard
                                         * used to recognize retransmits
94 f0cbd3ec bellard
                                         */
95 f0cbd3ec bellard
/* congestion control (for slow start, source quench, retransmit after loss) */
96 f0cbd3ec bellard
        u_int32_t snd_cwnd;                /* congestion-controlled window */
97 f0cbd3ec bellard
        u_int32_t snd_ssthresh;                /* snd_cwnd size threshold for
98 f0cbd3ec bellard
                                         * for slow start exponential to
99 f0cbd3ec bellard
                                         * linear switch
100 f0cbd3ec bellard
                                         */
101 f0cbd3ec bellard
/*
102 f0cbd3ec bellard
 * transmit timing stuff.  See below for scale of srtt and rttvar.
103 f0cbd3ec bellard
 * "Variance" is actually smoothed difference.
104 f0cbd3ec bellard
 */
105 f0cbd3ec bellard
        short        t_idle;                        /* inactivity time */
106 f0cbd3ec bellard
        short        t_rtt;                        /* round trip time */
107 f0cbd3ec bellard
        tcp_seq        t_rtseq;                /* sequence number being timed */
108 f0cbd3ec bellard
        short        t_srtt;                        /* smoothed round-trip time */
109 f0cbd3ec bellard
        short        t_rttvar;                /* variance in round-trip time */
110 f0cbd3ec bellard
        u_short        t_rttmin;                /* minimum rtt allowed */
111 f0cbd3ec bellard
        u_int32_t max_sndwnd;                /* largest window peer has offered */
112 f0cbd3ec bellard
113 f0cbd3ec bellard
/* out-of-band data */
114 f0cbd3ec bellard
        char        t_oobflags;                /* have some */
115 f0cbd3ec bellard
        char        t_iobc;                        /* input character */
116 f0cbd3ec bellard
#define        TCPOOB_HAVEDATA        0x01
117 f0cbd3ec bellard
#define        TCPOOB_HADDATA        0x02
118 f0cbd3ec bellard
        short        t_softerror;                /* possible error not yet reported */
119 f0cbd3ec bellard
120 f0cbd3ec bellard
/* RFC 1323 variables */
121 f0cbd3ec bellard
        u_char        snd_scale;                /* window scaling for send window */
122 f0cbd3ec bellard
        u_char        rcv_scale;                /* window scaling for recv window */
123 f0cbd3ec bellard
        u_char        request_r_scale;        /* pending window scaling */
124 f0cbd3ec bellard
        u_char        requested_s_scale;
125 f0cbd3ec bellard
        u_int32_t        ts_recent;                /* timestamp echo data */
126 f0cbd3ec bellard
        u_int32_t        ts_recent_age;                /* when last updated */
127 f0cbd3ec bellard
        tcp_seq        last_ack_sent;
128 f0cbd3ec bellard
129 f0cbd3ec bellard
};
130 f0cbd3ec bellard
131 f0cbd3ec bellard
#define        sototcpcb(so)        ((so)->so_tcpcb)
132 f0cbd3ec bellard
133 f0cbd3ec bellard
/*
134 f0cbd3ec bellard
 * The smoothed round-trip time and estimated variance
135 f0cbd3ec bellard
 * are stored as fixed point numbers scaled by the values below.
136 f0cbd3ec bellard
 * For convenience, these scales are also used in smoothing the average
137 f0cbd3ec bellard
 * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed).
138 f0cbd3ec bellard
 * With these scales, srtt has 3 bits to the right of the binary point,
139 f0cbd3ec bellard
 * and thus an "ALPHA" of 0.875.  rttvar has 2 bits to the right of the
140 f0cbd3ec bellard
 * binary point, and is smoothed with an ALPHA of 0.75.
141 f0cbd3ec bellard
 */
142 f0cbd3ec bellard
#define        TCP_RTT_SCALE                8        /* multiplier for srtt; 3 bits frac. */
143 f0cbd3ec bellard
#define        TCP_RTT_SHIFT                3        /* shift for srtt; 3 bits frac. */
144 f0cbd3ec bellard
#define        TCP_RTTVAR_SCALE        4        /* multiplier for rttvar; 2 bits */
145 f0cbd3ec bellard
#define        TCP_RTTVAR_SHIFT        2        /* multiplier for rttvar; 2 bits */
146 f0cbd3ec bellard
147 f0cbd3ec bellard
/*
148 f0cbd3ec bellard
 * The initial retransmission should happen at rtt + 4 * rttvar.
149 f0cbd3ec bellard
 * Because of the way we do the smoothing, srtt and rttvar
150 f0cbd3ec bellard
 * will each average +1/2 tick of bias.  When we compute
151 f0cbd3ec bellard
 * the retransmit timer, we want 1/2 tick of rounding and
152 f0cbd3ec bellard
 * 1 extra tick because of +-1/2 tick uncertainty in the
153 f0cbd3ec bellard
 * firing of the timer.  The bias will give us exactly the
154 f0cbd3ec bellard
 * 1.5 tick we need.  But, because the bias is
155 f0cbd3ec bellard
 * statistical, we have to test that we don't drop below
156 f0cbd3ec bellard
 * the minimum feasible timer (which is 2 ticks).
157 f0cbd3ec bellard
 * This macro assumes that the value of TCP_RTTVAR_SCALE
158 f0cbd3ec bellard
 * is the same as the multiplier for rttvar.
159 f0cbd3ec bellard
 */
160 f0cbd3ec bellard
#define        TCP_REXMTVAL(tp) \
161 f0cbd3ec bellard
        (((tp)->t_srtt >> TCP_RTT_SHIFT) + (tp)->t_rttvar)
162 f0cbd3ec bellard
163 31a60e22 blueswir1
#ifdef LOG_ENABLED
164 f0cbd3ec bellard
/*
165 f0cbd3ec bellard
 * TCP statistics.
166 f0cbd3ec bellard
 * Many of these should be kept per connection,
167 f0cbd3ec bellard
 * but that's inconvenient at the moment.
168 f0cbd3ec bellard
 */
169 f0cbd3ec bellard
struct tcpstat {
170 f0cbd3ec bellard
        u_long        tcps_connattempt;        /* connections initiated */
171 f0cbd3ec bellard
        u_long        tcps_accepts;                /* connections accepted */
172 f0cbd3ec bellard
        u_long        tcps_connects;                /* connections established */
173 f0cbd3ec bellard
        u_long        tcps_drops;                /* connections dropped */
174 f0cbd3ec bellard
        u_long        tcps_conndrops;                /* embryonic connections dropped */
175 f0cbd3ec bellard
        u_long        tcps_closed;                /* conn. closed (includes drops) */
176 f0cbd3ec bellard
        u_long        tcps_segstimed;                /* segs where we tried to get rtt */
177 f0cbd3ec bellard
        u_long        tcps_rttupdated;        /* times we succeeded */
178 f0cbd3ec bellard
        u_long        tcps_delack;                /* delayed acks sent */
179 f0cbd3ec bellard
        u_long        tcps_timeoutdrop;        /* conn. dropped in rxmt timeout */
180 f0cbd3ec bellard
        u_long        tcps_rexmttimeo;        /* retransmit timeouts */
181 f0cbd3ec bellard
        u_long        tcps_persisttimeo;        /* persist timeouts */
182 f0cbd3ec bellard
        u_long        tcps_keeptimeo;                /* keepalive timeouts */
183 f0cbd3ec bellard
        u_long        tcps_keepprobe;                /* keepalive probes sent */
184 f0cbd3ec bellard
        u_long        tcps_keepdrops;                /* connections dropped in keepalive */
185 f0cbd3ec bellard
186 f0cbd3ec bellard
        u_long        tcps_sndtotal;                /* total packets sent */
187 f0cbd3ec bellard
        u_long        tcps_sndpack;                /* data packets sent */
188 f0cbd3ec bellard
        u_long        tcps_sndbyte;                /* data bytes sent */
189 f0cbd3ec bellard
        u_long        tcps_sndrexmitpack;        /* data packets retransmitted */
190 f0cbd3ec bellard
        u_long        tcps_sndrexmitbyte;        /* data bytes retransmitted */
191 f0cbd3ec bellard
        u_long        tcps_sndacks;                /* ack-only packets sent */
192 f0cbd3ec bellard
        u_long        tcps_sndprobe;                /* window probes sent */
193 f0cbd3ec bellard
        u_long        tcps_sndurg;                /* packets sent with URG only */
194 f0cbd3ec bellard
        u_long        tcps_sndwinup;                /* window update-only packets sent */
195 f0cbd3ec bellard
        u_long        tcps_sndctrl;                /* control (SYN|FIN|RST) packets sent */
196 f0cbd3ec bellard
197 f0cbd3ec bellard
        u_long        tcps_rcvtotal;                /* total packets received */
198 f0cbd3ec bellard
        u_long        tcps_rcvpack;                /* packets received in sequence */
199 f0cbd3ec bellard
        u_long        tcps_rcvbyte;                /* bytes received in sequence */
200 f0cbd3ec bellard
        u_long        tcps_rcvbadsum;                /* packets received with ccksum errs */
201 f0cbd3ec bellard
        u_long        tcps_rcvbadoff;                /* packets received with bad offset */
202 f0cbd3ec bellard
/*        u_long        tcps_rcvshort;        */        /* packets received too short */
203 f0cbd3ec bellard
        u_long        tcps_rcvduppack;        /* duplicate-only packets received */
204 f0cbd3ec bellard
        u_long        tcps_rcvdupbyte;        /* duplicate-only bytes received */
205 f0cbd3ec bellard
        u_long        tcps_rcvpartduppack;        /* packets with some duplicate data */
206 f0cbd3ec bellard
        u_long        tcps_rcvpartdupbyte;        /* dup. bytes in part-dup. packets */
207 f0cbd3ec bellard
        u_long        tcps_rcvoopack;                /* out-of-order packets received */
208 f0cbd3ec bellard
        u_long        tcps_rcvoobyte;                /* out-of-order bytes received */
209 f0cbd3ec bellard
        u_long        tcps_rcvpackafterwin;        /* packets with data after window */
210 f0cbd3ec bellard
        u_long        tcps_rcvbyteafterwin;        /* bytes rcvd after window */
211 f0cbd3ec bellard
        u_long        tcps_rcvafterclose;        /* packets rcvd after "close" */
212 f0cbd3ec bellard
        u_long        tcps_rcvwinprobe;        /* rcvd window probe packets */
213 f0cbd3ec bellard
        u_long        tcps_rcvdupack;                /* rcvd duplicate acks */
214 f0cbd3ec bellard
        u_long        tcps_rcvacktoomuch;        /* rcvd acks for unsent data */
215 f0cbd3ec bellard
        u_long        tcps_rcvackpack;        /* rcvd ack packets */
216 f0cbd3ec bellard
        u_long        tcps_rcvackbyte;        /* bytes acked by rcvd acks */
217 f0cbd3ec bellard
        u_long        tcps_rcvwinupd;                /* rcvd window update packets */
218 f0cbd3ec bellard
/*        u_long        tcps_pawsdrop;        */        /* segments dropped due to PAWS */
219 f0cbd3ec bellard
        u_long        tcps_predack;                /* times hdr predict ok for acks */
220 f0cbd3ec bellard
        u_long        tcps_preddat;                /* times hdr predict ok for data pkts */
221 f0cbd3ec bellard
        u_long        tcps_socachemiss;        /* tcp_last_so misses */
222 f0cbd3ec bellard
        u_long        tcps_didnuttin;                /* Times tcp_output didn't do anything XXX */
223 f0cbd3ec bellard
};
224 f0cbd3ec bellard
225 f0cbd3ec bellard
extern struct        tcpstat tcpstat;        /* tcp statistics */
226 31a60e22 blueswir1
#endif
227 31a60e22 blueswir1
228 f0cbd3ec bellard
extern u_int32_t        tcp_now;                /* for RFC 1323 timestamps */
229 f0cbd3ec bellard
230 f0cbd3ec bellard
#endif