xref: /csrg-svn/sys/netinet/tcp_var.h (revision 33516)
1 /*
2  * Copyright (c) 1982, 1986 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of California at Berkeley. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  *
12  *	@(#)tcp_var.h	7.6.1.2 (Berkeley) 02/22/88
13  */
14 
15 /*
16  * TCP configuration:  This is a half-assed attempt to make TCP
17  * self-configure for a few varieties of 4.2 and 4.3-based unixes.
18  * If you don't have a) a 4.3bsd vax or b) a 3.x Sun (x<6), check
19  * this carefully (it's probably not right).  Please send me mail
20  * if you run into configuration problems.
21  *  - Van Jacobson (van@lbl-csam.arpa)
22  */
23 
24 #ifndef BSD
25 #define BSD 42	/* if we're not 4.3, pretend we're 4.2 */
26 #define OLDSTAT	/* set if we have to use old netstat binaries */
27 #endif
28 
29 /* #define OLDSTAT	/* set if we have to use old netstat binaries */
30 
31 #if sun || BSD < 43
32 #define TCP_COMPAT_42	/* set if we have to interop w/4.2 systems */
33 #endif
34 
35 #ifndef SB_MAX
36 #ifdef	SB_MAXCOUNT
37 #define	SB_MAX	SB_MAXCOUNT	/* Sun has to be a little bit different... */
38 #else
39 #define SB_MAX	32767		/* XXX */
40 #endif	SB_MAXCOUNT
41 #endif	SB_MAX
42 
43 /*
44  * Bill Nowicki pointed out that the page size (CLBYTES) has
45  * nothing to do with the mbuf cluster size.  So, we followed
46  * Sun's lead and made the new define MCLBYTES stand for the mbuf
47  * cluster size.  The following define makes up backwards compatible
48  * with 4.3 and 4.2.  If CLBYTES is >1024 on your machine, check
49  * this against the mbuf cluster definitions in /usr/include/sys/mbuf.h.
50  */
51 #ifndef MCLBYTES
52 #define	MCLBYTES CLBYTES	/* XXX */
53 #endif
54 
55 /*
56  * The routine in_localaddr is broken in Sun's 3.4.  We redefine ours
57  * (in tcp_input.c) so we use can it but won't have a name conflict.
58  */
59 #ifdef sun
60 #define in_localaddr tcp_in_localaddr
61 #endif
62 
63 /* --------------- end of TCP config ---------------- */
64 
65 /*
66  * Kernel variables for tcp.
67  */
68 
69 /*
70  * Tcp control block, one per tcp; fields:
71  */
72 struct tcpcb {
73 	struct	tcpiphdr *seg_next;	/* sequencing queue */
74 	struct	tcpiphdr *seg_prev;
75 	short	t_state;		/* state of this connection */
76 	short	t_timer[TCPT_NTIMERS];	/* tcp timers */
77 	short	t_rxtshift;		/* log(2) of rexmt exp. backoff */
78 	short	t_rxtcur;		/* current retransmit value */
79 	short	t_dupacks;		/* consecutive dup acks recd */
80 	u_short	t_maxseg;		/* maximum segment size */
81 	char	t_force;		/* 1 if forcing out a byte */
82 	u_char	t_flags;
83 #define	TF_ACKNOW	0x01		/* ack peer immediately */
84 #define	TF_DELACK	0x02		/* ack, but try to delay it */
85 #define	TF_NODELAY	0x04		/* don't delay packets to coalesce */
86 #define	TF_NOOPT	0x08		/* don't use tcp options */
87 #define	TF_SENTFIN	0x10		/* have sent FIN */
88 	struct	tcpiphdr *t_template;	/* skeletal packet for transmit */
89 	struct	inpcb *t_inpcb;		/* back pointer to internet pcb */
90 /*
91  * The following fields are used as in the protocol specification.
92  * See RFC783, Dec. 1981, page 21.
93  */
94 /* send sequence variables */
95 	tcp_seq	snd_una;		/* send unacknowledged */
96 	tcp_seq	snd_nxt;		/* send next */
97 	tcp_seq	snd_up;			/* send urgent pointer */
98 	tcp_seq	snd_wl1;		/* window update seg seq number */
99 	tcp_seq	snd_wl2;		/* window update seg ack number */
100 	tcp_seq	iss;			/* initial send sequence number */
101 	u_short	snd_wnd;		/* send window */
102 /* receive sequence variables */
103 	u_short	rcv_wnd;		/* receive window */
104 	tcp_seq	rcv_nxt;		/* receive next */
105 	tcp_seq	rcv_up;			/* receive urgent pointer */
106 	tcp_seq	irs;			/* initial receive sequence number */
107 /*
108  * Additional variables for this implementation.
109  */
110 /* receive variables */
111 	tcp_seq	rcv_adv;		/* advertised window */
112 /* retransmit variables */
113 	tcp_seq	snd_max;		/* highest sequence number sent
114 					 * used to recognize retransmits
115 					 */
116 /* congestion control (for slow start, source quench, retransmit after loss) */
117 	u_short	snd_cwnd;		/* congestion-controlled window */
118 	u_short snd_ssthresh;		/* snd_cwnd size threshhold for
119 					 * for slow start exponential to
120 					 * linear switch */
121 /*
122  * transmit timing stuff.
123  * srtt and rttvar are stored as fixed point; for convenience in smoothing,
124  * srtt has 3 bits to the right of the binary point, rttvar has 2.
125  * "Variance" is actually smoothed difference.
126  */
127 	short	t_idle;			/* inactivity time */
128 	short	t_rtt;			/* round trip time */
129 	tcp_seq	t_rtseq;		/* sequence number being timed */
130 	short	t_srtt;			/* smoothed round-trip time */
131 	short	t_rttvar;		/* variance in round-trip time */
132 	u_short max_rcvd;		/* most peer has sent into window */
133 	u_short	max_sndwnd;		/* largest window peer has offered */
134 /* out-of-band data */
135 	char	t_oobflags;		/* have some */
136 	char	t_iobc;			/* input character */
137 #define	TCPOOB_HAVEDATA	0x01
138 #define	TCPOOB_HADDATA	0x02
139 };
140 
141 #define	intotcpcb(ip)	((struct tcpcb *)(ip)->inp_ppcb)
142 #define	sototcpcb(so)	(intotcpcb(sotoinpcb(so)))
143 
144 /*
145  * TCP statistics.
146  * Many of these should be kept per connection,
147  * but that's inconvenient at the moment.
148  */
149 struct	tcpstat {
150 #ifdef OLDSTAT
151 	/*
152 	 * Declare statistics the same as in 4.3
153 	 * at the start of tcpstat (same size and
154 	 * position) for netstat.
155 	 */
156 	int	tcps_rcvbadsum;
157 	int	tcps_rcvbadoff;
158 	int	tcps_rcvshort;
159 	int	tcps_badsegs;
160 	int	tcps_unack;
161 #define	tcps_badsum	tcps_rcvbadsum
162 #define	tcps_badoff	tcps_rcvbadoff
163 #define	tcps_hdrops	tcps_rcvshort
164 
165 #endif OLDSTAT
166 	u_long	tcps_connattempt;	/* connections initiated */
167 	u_long	tcps_accepts;		/* connections accepted */
168 	u_long	tcps_connects;		/* connections established */
169 	u_long	tcps_drops;		/* connections dropped */
170 	u_long	tcps_conndrops;		/* embryonic connections dropped */
171 	u_long	tcps_closed;		/* conn. closed (includes drops) */
172 	u_long	tcps_segstimed;		/* segs where we tried to get rtt */
173 	u_long	tcps_rttupdated;	/* times we succeeded */
174 	u_long	tcps_delack;		/* delayed acks sent */
175 	u_long	tcps_timeoutdrop;	/* conn. dropped in rxmt timeout */
176 	u_long	tcps_rexmttimeo;	/* retransmit timeouts */
177 	u_long	tcps_persisttimeo;	/* persist timeouts */
178 	u_long	tcps_keeptimeo;		/* keepalive timeouts */
179 	u_long	tcps_keepprobe;		/* keepalive probes sent */
180 	u_long	tcps_keepdrops;		/* connections dropped in keepalive */
181 
182 	u_long	tcps_sndtotal;		/* total packets sent */
183 	u_long	tcps_sndpack;		/* data packets sent */
184 	u_long	tcps_sndbyte;		/* data bytes sent */
185 	u_long	tcps_sndrexmitpack;	/* data packets retransmitted */
186 	u_long	tcps_sndrexmitbyte;	/* data bytes retransmitted */
187 	u_long	tcps_sndacks;		/* ack-only packets sent */
188 	u_long	tcps_sndprobe;		/* window probes sent */
189 	u_long	tcps_sndurg;		/* packets sent with URG only */
190 	u_long	tcps_sndwinup;		/* window update-only packets sent */
191 	u_long	tcps_sndctrl;		/* control (SYN|FIN|RST) packets sent */
192 
193 	u_long	tcps_rcvtotal;		/* total packets received */
194 	u_long	tcps_rcvpack;		/* packets received in sequence */
195 	u_long	tcps_rcvbyte;		/* bytes received in sequence */
196 #ifndef OLDSTAT
197 	u_long	tcps_rcvbadsum;		/* packets received with ccksum errs */
198 	u_long	tcps_rcvbadoff;		/* packets received with bad offset */
199 	u_long	tcps_rcvshort;		/* packets received too short */
200 #endif
201 	u_long	tcps_rcvduppack;	/* duplicate-only packets received */
202 	u_long	tcps_rcvdupbyte;	/* duplicate-only bytes received */
203 	u_long	tcps_rcvpartduppack;	/* packets with some duplicate data */
204 	u_long	tcps_rcvpartdupbyte;	/* dup. bytes in part-dup. packets */
205 	u_long	tcps_rcvoopack;		/* out-of-order packets received */
206 	u_long	tcps_rcvoobyte;		/* out-of-order bytes received */
207 	u_long	tcps_rcvpackafterwin;	/* packets with data after window */
208 	u_long	tcps_rcvbyteafterwin;	/* bytes rcvd after window */
209 	u_long	tcps_rcvafterclose;	/* packets rcvd after "close" */
210 	u_long	tcps_rcvwinprobe;	/* rcvd window probe packets */
211 	u_long	tcps_rcvdupack;		/* rcvd duplicate acks */
212 	u_long	tcps_rcvacktoomuch;	/* rcvd acks for unsent data */
213 	u_long	tcps_rcvackpack;	/* rcvd ack packets */
214 	u_long	tcps_rcvackbyte;	/* bytes acked by rcvd acks */
215 	u_long	tcps_rcvwinupd;		/* rcvd window update packets */
216 };
217 
218 #ifdef KERNEL
219 struct	inpcb tcb;		/* head of queue of active tcpcb's */
220 struct	tcpstat tcpstat;	/* tcp statistics */
221 struct	tcpiphdr *tcp_template();
222 struct	tcpcb *tcp_close(), *tcp_drop();
223 struct	tcpcb *tcp_timers(), *tcp_disconnect(), *tcp_usrclosed();
224 #endif
225