xref: /original-bsd/sys/netinet/tcp_var.h (revision a95f03a8)
1 /*
2  * Copyright (c) 1982, 1986 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)tcp_var.h	7.10 (Berkeley) 06/28/90
8  */
9 
10 /*
11  * Kernel variables for tcp.
12  */
13 
14 /*
15  * Tcp control block, one per tcp; fields:
16  */
17 struct tcpcb {
18 	struct	tcpiphdr *seg_next;	/* sequencing queue */
19 	struct	tcpiphdr *seg_prev;
20 	short	t_state;		/* state of this connection */
21 	short	t_timer[TCPT_NTIMERS];	/* tcp timers */
22 	short	t_rxtshift;		/* log(2) of rexmt exp. backoff */
23 	short	t_rxtcur;		/* current retransmit value */
24 	short	t_dupacks;		/* consecutive dup acks recd */
25 	u_short	t_maxseg;		/* maximum segment size */
26 	char	t_force;		/* 1 if forcing out a byte */
27 	u_char	t_flags;
28 #define	TF_ACKNOW	0x01		/* ack peer immediately */
29 #define	TF_DELACK	0x02		/* ack, but try to delay it */
30 #define	TF_NODELAY	0x04		/* don't delay packets to coalesce */
31 #define	TF_NOOPT	0x08		/* don't use tcp options */
32 #define	TF_SENTFIN	0x10		/* have sent FIN */
33 	struct	tcpiphdr *t_template;	/* skeletal packet for transmit */
34 	struct	inpcb *t_inpcb;		/* back pointer to internet pcb */
35 /*
36  * The following fields are used as in the protocol specification.
37  * See RFC783, Dec. 1981, page 21.
38  */
39 /* send sequence variables */
40 	tcp_seq	snd_una;		/* send unacknowledged */
41 	tcp_seq	snd_nxt;		/* send next */
42 	tcp_seq	snd_up;			/* send urgent pointer */
43 	tcp_seq	snd_wl1;		/* window update seg seq number */
44 	tcp_seq	snd_wl2;		/* window update seg ack number */
45 	tcp_seq	iss;			/* initial send sequence number */
46 	u_short	snd_wnd;		/* send window */
47 /* receive sequence variables */
48 	u_short	rcv_wnd;		/* receive window */
49 	tcp_seq	rcv_nxt;		/* receive next */
50 	tcp_seq	rcv_up;			/* receive urgent pointer */
51 	tcp_seq	irs;			/* initial receive sequence number */
52 /*
53  * Additional variables for this implementation.
54  */
55 /* receive variables */
56 	tcp_seq	rcv_adv;		/* advertised window */
57 /* retransmit variables */
58 	tcp_seq	snd_max;		/* highest sequence number sent;
59 					 * used to recognize retransmits
60 					 */
61 /* congestion control (for slow start, source quench, retransmit after loss) */
62 	u_short	snd_cwnd;		/* congestion-controlled window */
63 	u_short snd_ssthresh;		/* snd_cwnd size threshhold for
64 					 * for slow start exponential to
65 					 * linear switch
66 					 */
67 /*
68  * transmit timing stuff.  See below for scale of srtt and rttvar.
69  * "Variance" is actually smoothed difference.
70  */
71 	short	t_idle;			/* inactivity time */
72 	short	t_rtt;			/* round trip time */
73 	tcp_seq	t_rtseq;		/* sequence number being timed */
74 	short	t_srtt;			/* smoothed round-trip time */
75 	short	t_rttvar;		/* variance in round-trip time */
76 	u_short	t_rttmin;		/* minimum rtt allowed */
77 	u_short	max_sndwnd;		/* largest window peer has offered */
78 
79 /* out-of-band data */
80 	char	t_oobflags;		/* have some */
81 	char	t_iobc;			/* input character */
82 #define	TCPOOB_HAVEDATA	0x01
83 #define	TCPOOB_HADDATA	0x02
84 	short	t_softerror;		/* possible error not yet reported */
85 };
86 
87 #define	intotcpcb(ip)	((struct tcpcb *)(ip)->inp_ppcb)
88 #define	sototcpcb(so)	(intotcpcb(sotoinpcb(so)))
89 
90 /*
91  * The smoothed round-trip time and estimated variance
92  * are stored as fixed point numbers scaled by the values below.
93  * For convenience, these scales are also used in smoothing the average
94  * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed).
95  * With these scales, srtt has 3 bits to the right of the binary point,
96  * and thus an "ALPHA" of 0.875.  rttvar has 2 bits to the right of the
97  * binary point, and is smoothed with an ALPHA of 0.75.
98  */
99 #define	TCP_RTT_SCALE		8	/* multiplier for srtt; 3 bits frac. */
100 #define	TCP_RTT_SHIFT		3	/* shift for srtt; 3 bits frac. */
101 #define	TCP_RTTVAR_SCALE	4	/* multiplier for rttvar; 2 bits */
102 #define	TCP_RTTVAR_SHIFT	2	/* multiplier for rttvar; 2 bits */
103 
104 /*
105  * The initial retransmission should happen at rtt + 4 * rttvar.
106  * Because of the way we do the smoothing, srtt and rttvar
107  * will each average +1/2 tick of bias.  When we compute
108  * the retransmit timer, we want 1/2 tick of rounding and
109  * 1 extra tick because of +-1/2 tick uncertainty in the
110  * firing of the timer.  The bias will give us exactly the
111  * 1.5 tick we need.  But, because the bias is
112  * statistical, we have to test that we don't drop below
113  * the minimum feasible timer (which is 2 ticks).
114  * This macro assumes that the value of TCP_RTTVAR_SCALE
115  * is the same as the multiplier for rttvar.
116  */
117 #define	TCP_REXMTVAL(tp) \
118 	(((tp)->t_srtt >> TCP_RTT_SHIFT) + (tp)->t_rttvar)
119 
120 /* XXX
121  * We want to avoid doing m_pullup on incoming packets but that
122  * means avoiding dtom on the tcp reassembly code.  That in turn means
123  * keeping an mbuf pointer in the reassembly queue (since we might
124  * have a cluster).  As a quick hack, the source & destination
125  * port numbers (which are no longer needed once we've located the
126  * tcpcb) are overlayed with an mbuf pointer.
127  */
128 #define REASS_MBUF(ti) (*(struct mbuf **)&((ti)->ti_t))
129 
130 /*
131  * TCP statistics.
132  * Many of these should be kept per connection,
133  * but that's inconvenient at the moment.
134  */
135 struct	tcpstat {
136 	u_long	tcps_connattempt;	/* connections initiated */
137 	u_long	tcps_accepts;		/* connections accepted */
138 	u_long	tcps_connects;		/* connections established */
139 	u_long	tcps_drops;		/* connections dropped */
140 	u_long	tcps_conndrops;		/* embryonic connections dropped */
141 	u_long	tcps_closed;		/* conn. closed (includes drops) */
142 	u_long	tcps_segstimed;		/* segs where we tried to get rtt */
143 	u_long	tcps_rttupdated;	/* times we succeeded */
144 	u_long	tcps_delack;		/* delayed acks sent */
145 	u_long	tcps_timeoutdrop;	/* conn. dropped in rxmt timeout */
146 	u_long	tcps_rexmttimeo;	/* retransmit timeouts */
147 	u_long	tcps_persisttimeo;	/* persist timeouts */
148 	u_long	tcps_keeptimeo;		/* keepalive timeouts */
149 	u_long	tcps_keepprobe;		/* keepalive probes sent */
150 	u_long	tcps_keepdrops;		/* connections dropped in keepalive */
151 
152 	u_long	tcps_sndtotal;		/* total packets sent */
153 	u_long	tcps_sndpack;		/* data packets sent */
154 	u_long	tcps_sndbyte;		/* data bytes sent */
155 	u_long	tcps_sndrexmitpack;	/* data packets retransmitted */
156 	u_long	tcps_sndrexmitbyte;	/* data bytes retransmitted */
157 	u_long	tcps_sndacks;		/* ack-only packets sent */
158 	u_long	tcps_sndprobe;		/* window probes sent */
159 	u_long	tcps_sndurg;		/* packets sent with URG only */
160 	u_long	tcps_sndwinup;		/* window update-only packets sent */
161 	u_long	tcps_sndctrl;		/* control (SYN|FIN|RST) packets sent */
162 
163 	u_long	tcps_rcvtotal;		/* total packets received */
164 	u_long	tcps_rcvpack;		/* packets received in sequence */
165 	u_long	tcps_rcvbyte;		/* bytes received in sequence */
166 	u_long	tcps_rcvbadsum;		/* packets received with ccksum errs */
167 	u_long	tcps_rcvbadoff;		/* packets received with bad offset */
168 	u_long	tcps_rcvshort;		/* packets received too short */
169 	u_long	tcps_rcvduppack;	/* duplicate-only packets received */
170 	u_long	tcps_rcvdupbyte;	/* duplicate-only bytes received */
171 	u_long	tcps_rcvpartduppack;	/* packets with some duplicate data */
172 	u_long	tcps_rcvpartdupbyte;	/* dup. bytes in part-dup. packets */
173 	u_long	tcps_rcvoopack;		/* out-of-order packets received */
174 	u_long	tcps_rcvoobyte;		/* out-of-order bytes received */
175 	u_long	tcps_rcvpackafterwin;	/* packets with data after window */
176 	u_long	tcps_rcvbyteafterwin;	/* bytes rcvd after window */
177 	u_long	tcps_rcvafterclose;	/* packets rcvd after "close" */
178 	u_long	tcps_rcvwinprobe;	/* rcvd window probe packets */
179 	u_long	tcps_rcvdupack;		/* rcvd duplicate acks */
180 	u_long	tcps_rcvacktoomuch;	/* rcvd acks for unsent data */
181 	u_long	tcps_rcvackpack;	/* rcvd ack packets */
182 	u_long	tcps_rcvackbyte;	/* bytes acked by rcvd acks */
183 	u_long	tcps_rcvwinupd;		/* rcvd window update packets */
184 };
185 
186 #ifdef KERNEL
187 struct	inpcb tcb;		/* head of queue of active tcpcb's */
188 struct	tcpstat tcpstat;	/* tcp statistics */
189 struct	tcpiphdr *tcp_template();
190 struct	tcpcb *tcp_close(), *tcp_drop();
191 struct	tcpcb *tcp_timers(), *tcp_disconnect(), *tcp_usrclosed();
192 #endif
193