xref: /original-bsd/sys/deprecated/bbnnet/tcp.h (revision 2c497c00)
1 #define RCSTCPHDR	"$Header: tcp.h,v 1.19 85/07/31 09:33:34 walsh Exp $"
2 
3 struct th {                     /* tcp header (fits over ip header) */
4 	struct th	*t_next;	/* -> next tcp on rcv chain */
5 	struct th	*t_prev;	/* -> prev tcp on rcv chain */
6 	u_char		 t_x1;		/* (unused) */
7 	u_char		 t_pr;		/* protocol */
8 	u_short		 t_len;		/* seg length */
9 	struct in_addr	 t_s;		/* source internet address */
10 	struct in_addr	 t_d;		/* destination internet address */
11 	u_short		 t_src;		/* source port */
12 	u_short		 t_dst;		/* destination port */
13 	sequence	 t_seq;		/* sequence number */
14 	sequence	 t_ackno;	/* acknowledgement number */
15 #define t_end(x) (x->t_seq + x->t_len - 1)
16 	u_char
17 		t_x2:4,                 /* (unused) */
18 		t_off:4;                /* data offset */
19 #define TCP_OFFSHIFT 2
20 	u_char		 t_flags;
21 #define T_FIN	0x01			/* fin flag */
22 #define T_SYN	0x02			/* syn flag */
23 #define T_RST	0x04			/* reset flag */
24 #define T_PUSH	0x08			/* push flag */
25 #define T_ACK	0x10			/* ack flag */
26 #define T_URG	0x20			/* urgent flag */
27 	u_short		 t_win;		/* window */
28 	u_short		 t_sum;		/* checksum */
29 	u_short		 t_urp;		/* urgent pointer */
30 };
31 
32 #define TCP_END_OPT	0		/* end of option list */
33 #define TCP_NOP_OPT	1		/* nop option */
34 #define TCP_MAXSEG_OPT	2		/* maximum segment size option */
35 #define	TCP_MAXSEG_OPTLEN 4		/* max seg option length */
36 #define	TCP_MAXSEG_OPTHDR ((TCP_MAXSEG_OPT<<8)|TCP_MAXSEG_OPTLEN)
37 
38 typedef u_char tcptimerval;		/* in 0.5 second units */
39 #define MAX_TCPTIMERVAL	255
40 
41 struct tcpcb {                    /* tcp control block */
42 
43 	/* various pointers */
44 
45 				/* where store data until gets to socket */
46 	struct th *t_rcv_next;          /* -> first el on rcv queue */
47 	struct th *t_rcv_prev;          /* -> last el on rcv queue */
48 	int	   t_rcv_len;		/* length of rcv queue */
49 
50 	struct inpcb *t_in_pcb;		/* -> in_pcb */
51 	struct mbuf *t_rcv_unack;       /* -> unacked message queue */
52 					/* ### how about a tail pointer */
53 
54 	/* sequence number variables */
55 
56 	sequence iss;                   /* initial send seq # */
57 	sequence irs;                   /* initial recv seq # */
58 	sequence rcv_urp;               /* rcv urgent pointer */
59 	sequence rcv_nxt;               /* next contiguous seq # to rcv */
60 	sequence seq_fin;               /* seq # of FIN sent */
61 	sequence snd_end;               /* send eol pointer. end of PUSH */
62 	sequence snd_urp;               /* snd urgent pointer. end of URG */
63 	sequence snd_lst;               /* seq # of last datum to send */
64 	sequence snd_nxt;               /* seq # of next datum to send */
65 	sequence snd_una;               /* seq # of first unacked datum */
66 	sequence snd_wl;                /* seq # of last sent window */
67 	sequence snd_hi;                /* highest seq # we sent */
68 	sequence t_xmt_val;             /* seq # measuring round trip time of */
69 
70 	/* various flags and state variables
71 	 * At one time booleans were a bitfield, but since are using mbufs,
72 	 * have space and is quicker to test/set byte than bit.
73 	 */
74 
75 	char	ack_due;		/* must we send ACK */
76 	char	cancelled;		/* retransmit timer cancelled */
77 	char	dropped_txt;		/* dropped incoming data */
78 	char	fin_rcvd;		/* FIN received */
79 	char	force_one;		/* force sending of one byte */
80 	char	new_window;		/* received new window size */
81 	char	rexmt;			/* this msg is a retransmission */
82 	char	snd_fin;		/* FIN should be sent */
83 	char	snd_rst;		/* RST should be sent */
84 	char	snd_urg;		/* urgent data to send */
85 	char	syn_acked;		/* SYN has been ACKed */
86 	char	syn_rcvd;		/* SYN has been received */
87 	char	usr_closed;		/* user has closed connection */
88 	char	waited_2_ml;		/* wait time for FIN ACK is up */
89 	char	usr_abort;		/* user has closed and does not expect
90 				           to receive any more data */
91 	char	sent_zero;		/* sent zero window */
92 	char	force_ack;		/* force sending of ack */
93 	char	t_push;
94 	char	t_urg;
95 	char	t_noactprobe;		/* see tcp_newtcpcb() */
96 	char	t_noactsig;
97 	    /* end booleans */
98 
99 	u_short		snd_wnd;	/* window he advertised */
100 	short		t_maxseg;	/* max seg size peer can handle */
101 	u_short		t_maxfrag;	/* max IP frag size received */
102 	u_short		t_olddata;	/* useless rexmts received */
103 	u_short		t_preproc;	/* #segs out of window rcvd */
104 	u_short		t_rxtct;	/* # of retransmissions */
105 	u_char		t_state;	/* state of this connection */
106 
107 	tcptimerval	t_srtt;		/* smoothed round trip time */
108 	/*
109 	 * Not used to limit t_srtt, but to estimate limits/values for the
110 	 * timers given the rxmitime = 1.5 srtt, and rxmitime doubles for
111 	 * each retransmission.
112 	 * This is the srtt on our slowest network connection.
113 	 */
114 #define TCP_tvMAXSRTT	20		    /* 10 seconds */
115 
116 	tcptimerval	t_rxmitime;	/* current rexmt time */
117 	/*
118 	 * Allow some slop for the maximum in case the network experiences
119 	 * a temporary peak loading
120 	 */
121 #define TCP_tvRXMIN  4
122 #define TCP_tvRXMAX ((3 * TCP_tvMAXSRTT) / 2)
123 
124 	tcptimerval	t_itimeo;	/* init timeout value */
125 	/* by default, try 3+ syns to get to the other side */
126 #define TCP_tvINIT  (TCP_tvMAXSRTT + 3 * TCP_tvRXMAX)
127 
128 	tcptimerval	t_rttltimeo;	/* rxmit took too long timeout value */
129 	/* by default, try 4+ retransmissions before warn user */
130 #define TCP_tvRTTL  (TCP_tvMAXSRTT + 4 * TCP_tvRXMAX)
131 
132 	tcptimerval	t_noact;	/* no activity timeout value (mins.) */
133 #define TCP_tvNOACT 10			    /* internal no activity timeout (min) */
134 
135 	tcptimerval	t_timers[NTIMERS];/* the timers */
136 #define TCP_tvMINPERSIST 10
137 #define TCP_tvMAXPERSIST 90
138 #define TCP_tv2ML	 40                 /* 2*maximum packet lifetime */
139 
140 	struct mbuf    *oob_data;	/* for 4.2 implementation of urgent */
141 	sequence	rcv_urpend;	/* (out-of-band) data */
142 
143 	short 		sws_qff;	/* silly window syndrome and icmp
144 					 * source quench fudge factor */
145 
146 	short		ack_skipped;
147 	sequence	lastack;	/* with force_ack, for TDELACK */
148 	u_short		rcv_wnd;	/* window we advertised */
149 
150 	struct th      *t_template;	/* for send_pkt() */
151 };
152 
153 #if TCP_tvRXMAX > MAX_TCPTIMERVAL
154 	whoops
155 #endif
156 #if TCP_tvINIT  > MAX_TCPTIMERVAL
157 	whoops
158 #endif
159 #if TCP_tvRTTL  > MAX_TCPTIMERVAL
160 	whoops
161 #endif
162 
163 struct t_debug {                /* tcp debugging record */
164 	u_long t_iptime;
165 	char t_oldstate;		/* old state */
166 	char t_input;			/* input */
167 	char t_timer;			/* timer id */
168 	char t_newstate;		/* new state */
169 
170 	struct tcpcb	t_tcb;		/* -> tcb */
171 	struct th	t_hdr;		/* valid iff input is INRECV */
172 };
173 
174 #define DB_PER_CHUNK(x)  (((x)/sizeof(struct t_debug)) * sizeof(struct t_debug))
175 #define TDBLEN	DB_PER_CHUNK(MLEN)
176 #define TCDBLEN DB_PER_CHUNK(CLBYTES)
177 
178 /*
179  * tcp statistics
180  */
181 
182 struct tcp_stat {
183     struct in_stat t_in;
184 #define t_total		t_in.in_total
185 #define t_badsum	t_in.in_badsum
186 #define t_tooshort	t_in.in_tooshort
187     int t_badsegs;		/* #bad tcp segments (to which we send RST) */
188     int t_unack;		/* #tcp segs placed on rcv_unack */
189     int t_retransmit;		/* #retransmissions we sent */
190     int t_ackonly;		/* #send_pkt just to send ack, no data */
191 };
192 
193 
194 /* size of TCP leader (bytes) */
195 #define TCPSIZE (sizeof(struct th)-sizeof(struct ip))
196 /*
197  * max size of TCP/IP leader.  If start using options on tcp connections,
198  * increase TCPIPMAX accordingly.
199  */
200 #define TCPIPMAX sizeof(struct th)
201 /* initial maximum segment size */
202 #define TCPMAXSND (IPMAX - TCPIPMAX)
203 
204 /* get the tcpcb from the inpcb */
205 #define inptotcpcb(inp)	((struct tcpcb *)((inp)->inp_ppcb))
206 #define sototcpcb(so)	(inptotcpcb((struct inpcb *)((so)->so_pcb)))
207 #define tcpcbtoso(tp)	((tp)->t_in_pcb->inp_socket)
208 
209 #define TCP_CTL	1			/* send/receive control call */
210 #define TCP_DATA 0			/* send/receive data call */
211 
212 #define T_LINGERTIME 120		/* two minutes of linger */
213 
214 /* tcp machine predicates */
215 
216 /*
217  * Is there unacked data on this TCP connection?
218  */
219 #define is_unacked(t) (SEQ_LT((t)->snd_una, (t)->snd_hi))
220 
221 /* ACK of local FIN */
222 #define ack_fin(x, y) (SEQ_GT((x)->seq_fin, (x)->iss) && \
223 			SEQ_GT((y)->t_ackno, (x)->seq_fin))
224 
225 /* receive buffer empty */
226 #define rcv_empty(x) ((x)->usr_abort || \
227 		((x)->t_in_pcb->inp_socket->so_rcv.sb_cc == 0 && \
228 		 (x)->t_rcv_next == (struct th *)(x)))
229 
230 #define t_cancel(tp, timer) ((tp)->t_timers[timer] = 0)
231 
232 sequence firstempty();
233 char *tcp_conn_used();	/* see note about return value */
234 struct th *tcp_template();
235 
236 /*
237  * If we have many incarnations of a connection in a time period, do not
238  * want the sequence number space of them to overlap and have packets for
239  * one be mistaken as from another.
240  * Assume max throughput of 1Mbit/sec == 125kbyte/sec for TCP
241  */
242 #define ISSINCR	((125*1024) / PR_SLOWHZ)
243 
244 /*
245  * 512 is arbitrary.
246  */
247 #define MAX_TCPOOB	512
248 
249 /*
250  * TCP port allocation
251  */
252 
253 #define TCP_RESERVED		1023	/* <= for root only */
254 #define TCP_USERRESERVED	5000	/* reserved for applications */
255 #define TCP_MAXPORT		0xffff
256 
257 #ifdef KERNEL
258 extern struct tcp_stat tcpstat;
259 #endif
260