xref: /original-bsd/sys/netinet/tcp_var.h (revision 5aaec600)
1 /*
2  * Copyright (c) 1982, 1986, 1993, 1994, 1995
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)tcp_var.h	8.4 (Berkeley) 05/24/95
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_short	t_flags;
28 #define	TF_ACKNOW	0x0001		/* ack peer immediately */
29 #define	TF_DELACK	0x0002		/* ack, but try to delay it */
30 #define	TF_NODELAY	0x0004		/* don't delay packets to coalesce */
31 #define	TF_NOOPT	0x0008		/* don't use tcp options */
32 #define	TF_SENTFIN	0x0010		/* have sent FIN */
33 #define	TF_REQ_SCALE	0x0020		/* have/will request window scaling */
34 #define	TF_RCVD_SCALE	0x0040		/* other side has requested scaling */
35 #define	TF_REQ_TSTMP	0x0080		/* have/will request timestamps */
36 #define	TF_RCVD_TSTMP	0x0100		/* a timestamp was received in SYN */
37 #define	TF_SACK_PERMIT	0x0200		/* other side said I could SACK */
38 
39 	struct	tcpiphdr *t_template;	/* skeletal packet for transmit */
40 	struct	inpcb *t_inpcb;		/* back pointer to internet pcb */
41 /*
42  * The following fields are used as in the protocol specification.
43  * See RFC783, Dec. 1981, page 21.
44  */
45 /* send sequence variables */
46 	tcp_seq	snd_una;		/* send unacknowledged */
47 	tcp_seq	snd_nxt;		/* send next */
48 	tcp_seq	snd_up;			/* send urgent pointer */
49 	tcp_seq	snd_wl1;		/* window update seg seq number */
50 	tcp_seq	snd_wl2;		/* window update seg ack number */
51 	tcp_seq	iss;			/* initial send sequence number */
52 	u_long	snd_wnd;		/* send window */
53 /* receive sequence variables */
54 	u_long	rcv_wnd;		/* receive window */
55 	tcp_seq	rcv_nxt;		/* receive next */
56 	tcp_seq	rcv_up;			/* receive urgent pointer */
57 	tcp_seq	irs;			/* initial receive sequence number */
58 /*
59  * Additional variables for this implementation.
60  */
61 /* receive variables */
62 	tcp_seq	rcv_adv;		/* advertised window */
63 /* retransmit variables */
64 	tcp_seq	snd_max;		/* highest sequence number sent;
65 					 * used to recognize retransmits
66 					 */
67 /* congestion control (for slow start, source quench, retransmit after loss) */
68 	u_long	snd_cwnd;		/* congestion-controlled window */
69 	u_long	snd_ssthresh;		/* snd_cwnd size threshhold for
70 					 * for slow start exponential to
71 					 * linear switch
72 					 */
73 /*
74  * transmit timing stuff.  See below for scale of srtt and rttvar.
75  * "Variance" is actually smoothed difference.
76  */
77 	u_short	t_idle;			/* inactivity time */
78 	short	t_rtt;			/* round trip time */
79 	tcp_seq	t_rtseq;		/* sequence number being timed */
80 	short	t_srtt;			/* smoothed round-trip time */
81 	short	t_rttvar;		/* variance in round-trip time */
82 	u_short	t_rttmin;		/* minimum rtt allowed */
83 	u_long	max_sndwnd;		/* largest window peer has offered */
84 
85 /* out-of-band data */
86 	char	t_oobflags;		/* have some */
87 	char	t_iobc;			/* input character */
88 #define	TCPOOB_HAVEDATA	0x01
89 #define	TCPOOB_HADDATA	0x02
90 	short	t_softerror;		/* possible error not yet reported */
91 
92 /* RFC 1323 variables */
93 	u_char	snd_scale;		/* window scaling for send window */
94 	u_char	rcv_scale;		/* window scaling for recv window */
95 	u_char	request_r_scale;	/* pending window scaling */
96 	u_char	requested_s_scale;
97 	u_long	ts_recent;		/* timestamp echo data */
98 	u_long	ts_recent_age;		/* when last updated */
99 	tcp_seq	last_ack_sent;
100 
101 /* TUBA stuff */
102 	caddr_t	t_tuba_pcb;		/* next level down pcb for TCP over z */
103 };
104 
105 #define	intotcpcb(ip)	((struct tcpcb *)(ip)->inp_ppcb)
106 #define	sototcpcb(so)	(intotcpcb(sotoinpcb(so)))
107 
108 /*
109  * The smoothed round-trip time and estimated variance
110  * are stored as fixed point numbers scaled by the values below.
111  * For convenience, these scales are also used in smoothing the average
112  * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed).
113  * With these scales, srtt has 3 bits to the right of the binary point,
114  * and thus an "ALPHA" of 0.875.  rttvar has 2 bits to the right of the
115  * binary point, and is smoothed with an ALPHA of 0.75.
116  */
117 #define	TCP_RTT_SCALE		8	/* multiplier for srtt; 3 bits frac. */
118 #define	TCP_RTT_SHIFT		3	/* shift for srtt; 3 bits frac. */
119 #define	TCP_RTTVAR_SCALE	4	/* multiplier for rttvar; 2 bits */
120 #define	TCP_RTTVAR_SHIFT	2	/* multiplier for rttvar; 2 bits */
121 
122 /*
123  * The initial retransmission should happen at rtt + 4 * rttvar.
124  * Because of the way we do the smoothing, srtt and rttvar
125  * will each average +1/2 tick of bias.  When we compute
126  * the retransmit timer, we want 1/2 tick of rounding and
127  * 1 extra tick because of +-1/2 tick uncertainty in the
128  * firing of the timer.  The bias will give us exactly the
129  * 1.5 tick we need.  But, because the bias is
130  * statistical, we have to test that we don't drop below
131  * the minimum feasible timer (which is 2 ticks).
132  * This macro assumes that the value of TCP_RTTVAR_SCALE
133  * is the same as the multiplier for rttvar.
134  */
135 #define	TCP_REXMTVAL(tp) \
136 	(((tp)->t_srtt >> TCP_RTT_SHIFT) + (tp)->t_rttvar)
137 
138 /* XXX
139  * We want to avoid doing m_pullup on incoming packets but that
140  * means avoiding dtom on the tcp reassembly code.  That in turn means
141  * keeping an mbuf pointer in the reassembly queue (since we might
142  * have a cluster).  As a quick hack, the source & destination
143  * port numbers (which are no longer needed once we've located the
144  * tcpcb) are overlayed with an mbuf pointer.
145  */
146 #define REASS_MBUF(ti) (*(struct mbuf **)&((ti)->ti_t))
147 
148 /*
149  * TCP statistics.
150  * Many of these should be kept per connection,
151  * but that's inconvenient at the moment.
152  */
153 struct	tcpstat {
154 	u_long	tcps_connattempt;	/* connections initiated */
155 	u_long	tcps_accepts;		/* connections accepted */
156 	u_long	tcps_connects;		/* connections established */
157 	u_long	tcps_drops;		/* connections dropped */
158 	u_long	tcps_conndrops;		/* embryonic connections dropped */
159 	u_long	tcps_closed;		/* conn. closed (includes drops) */
160 	u_long	tcps_segstimed;		/* segs where we tried to get rtt */
161 	u_long	tcps_rttupdated;	/* times we succeeded */
162 	u_long	tcps_delack;		/* delayed acks sent */
163 	u_long	tcps_timeoutdrop;	/* conn. dropped in rxmt timeout */
164 	u_long	tcps_rexmttimeo;	/* retransmit timeouts */
165 	u_long	tcps_persisttimeo;	/* persist timeouts */
166 	u_long	tcps_keeptimeo;		/* keepalive timeouts */
167 	u_long	tcps_keepprobe;		/* keepalive probes sent */
168 	u_long	tcps_keepdrops;		/* connections dropped in keepalive */
169 
170 	u_long	tcps_sndtotal;		/* total packets sent */
171 	u_long	tcps_sndpack;		/* data packets sent */
172 	u_long	tcps_sndbyte;		/* data bytes sent */
173 	u_long	tcps_sndrexmitpack;	/* data packets retransmitted */
174 	u_long	tcps_sndrexmitbyte;	/* data bytes retransmitted */
175 	u_long	tcps_sndacks;		/* ack-only packets sent */
176 	u_long	tcps_sndprobe;		/* window probes sent */
177 	u_long	tcps_sndurg;		/* packets sent with URG only */
178 	u_long	tcps_sndwinup;		/* window update-only packets sent */
179 	u_long	tcps_sndctrl;		/* control (SYN|FIN|RST) packets sent */
180 
181 	u_long	tcps_rcvtotal;		/* total packets received */
182 	u_long	tcps_rcvpack;		/* packets received in sequence */
183 	u_long	tcps_rcvbyte;		/* bytes received in sequence */
184 	u_long	tcps_rcvbadsum;		/* packets received with ccksum errs */
185 	u_long	tcps_rcvbadoff;		/* packets received with bad offset */
186 	u_long	tcps_rcvshort;		/* packets received too short */
187 	u_long	tcps_rcvduppack;	/* duplicate-only packets received */
188 	u_long	tcps_rcvdupbyte;	/* duplicate-only bytes received */
189 	u_long	tcps_rcvpartduppack;	/* packets with some duplicate data */
190 	u_long	tcps_rcvpartdupbyte;	/* dup. bytes in part-dup. packets */
191 	u_long	tcps_rcvoopack;		/* out-of-order packets received */
192 	u_long	tcps_rcvoobyte;		/* out-of-order bytes received */
193 	u_long	tcps_rcvpackafterwin;	/* packets with data after window */
194 	u_long	tcps_rcvbyteafterwin;	/* bytes rcvd after window */
195 	u_long	tcps_rcvafterclose;	/* packets rcvd after "close" */
196 	u_long	tcps_rcvwinprobe;	/* rcvd window probe packets */
197 	u_long	tcps_rcvdupack;		/* rcvd duplicate acks */
198 	u_long	tcps_rcvacktoomuch;	/* rcvd acks for unsent data */
199 	u_long	tcps_rcvackpack;	/* rcvd ack packets */
200 	u_long	tcps_rcvackbyte;	/* bytes acked by rcvd acks */
201 	u_long	tcps_rcvwinupd;		/* rcvd window update packets */
202 	u_long	tcps_pawsdrop;		/* segments dropped due to PAWS */
203 	u_long	tcps_predack;		/* times hdr predict ok for acks */
204 	u_long	tcps_preddat;		/* times hdr predict ok for data pkts */
205 	u_long	tcps_pcbcachemiss;
206 	u_long	tcps_persistdrop;	/* timeout in persist state */
207 	u_long	tcps_badsyn;		/* bogus SYN, e.g. premature ACK */
208 };
209 
210 #ifdef KERNEL
211 struct	inpcb tcb;		/* head of queue of active tcpcb's */
212 struct	tcpstat tcpstat;	/* tcp statistics */
213 u_long	tcp_now;		/* for RFC 1323 timestamps */
214 
215 int	 tcp_attach __P((struct socket *));
216 void	 tcp_canceltimers __P((struct tcpcb *));
217 struct tcpcb *
218 	 tcp_close __P((struct tcpcb *));
219 void	 tcp_ctlinput __P((int, struct sockaddr *, struct ip *));
220 int	 tcp_ctloutput __P((int, struct socket *, int, int, struct mbuf **));
221 struct tcpcb *
222 	 tcp_disconnect __P((struct tcpcb *));
223 struct tcpcb *
224 	 tcp_drop __P((struct tcpcb *, int));
225 void	 tcp_dooptions __P((struct tcpcb *,
226 	    u_char *, int, struct tcpiphdr *, int *, u_long *, u_long *));
227 void	 tcp_drain __P((void));
228 void	 tcp_fasttimo __P((void));
229 void	 tcp_init __P((void));
230 void	 tcp_input __P((struct mbuf *, int));
231 int	 tcp_mss __P((struct tcpcb *, u_int));
232 struct tcpcb *
233 	 tcp_newtcpcb __P((struct inpcb *));
234 void	 tcp_notify __P((struct inpcb *, int));
235 int	 tcp_output __P((struct tcpcb *));
236 void	 tcp_pulloutofband __P((struct socket *,
237 	    struct tcpiphdr *, struct mbuf *));
238 void	 tcp_quench __P((struct inpcb *, int));
239 int	 tcp_reass __P((struct tcpcb *, struct tcpiphdr *, struct mbuf *));
240 void	 tcp_respond __P((struct tcpcb *,
241 	    struct tcpiphdr *, struct mbuf *, u_long, u_long, int));
242 void	 tcp_setpersist __P((struct tcpcb *));
243 void	 tcp_slowtimo __P((void));
244 struct tcpiphdr *
245 	 tcp_template __P((struct tcpcb *));
246 struct tcpcb *
247 	 tcp_timers __P((struct tcpcb *, int));
248 void	 tcp_trace __P((int, int, struct tcpcb *, struct tcpiphdr *, int));
249 struct tcpcb *
250 	 tcp_usrclosed __P((struct tcpcb *));
251 int	 tcp_usrreq __P((struct socket *,
252 	    int, struct mbuf *, struct mbuf *, struct mbuf *));
253 void	 tcp_xmit_timer __P((struct tcpcb *, int));
254 #endif
255