xref: /original-bsd/sys/netinet/tcp_seq.h (revision 9a35f7df)
1 /*
2  * Copyright (c) 1982, 1986, 1993, 1995
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)tcp_seq.h	8.2 (Berkeley) 05/24/95
8  */
9 
10 /*
11  * TCP sequence numbers are 32 bit integers operated
12  * on with modular arithmetic.  These macros can be
13  * used to compare such integers.
14  */
15 #define	SEQ_LT(a,b)	((int)((a)-(b)) < 0)
16 #define	SEQ_LEQ(a,b)	((int)((a)-(b)) <= 0)
17 #define	SEQ_GT(a,b)	((int)((a)-(b)) > 0)
18 #define	SEQ_GEQ(a,b)	((int)((a)-(b)) >= 0)
19 
20 /*
21  * Macros to initialize tcp sequence numbers for
22  * send and receive from initial send and receive
23  * sequence numbers.
24  */
25 #define	tcp_rcvseqinit(tp) \
26 	(tp)->rcv_adv = (tp)->rcv_nxt = (tp)->irs + 1
27 
28 #define	tcp_sendseqinit(tp) \
29 	(tp)->snd_una = (tp)->snd_nxt = (tp)->snd_max = (tp)->snd_up = \
30 	    (tp)->iss
31 
32 #ifdef KERNEL
33 /*
34  * Increment for tcp_iss each second.
35  * This is designed to increment at the standard 250 KB/s,
36  * but with a random component averaging 128 KB.
37  * We also increment tcp_iss by a quarter of this amount
38  * each time we use the value for a new connection.
39  * If defined, the tcp_random18() macro should produce a
40  * number in the range [0-0x3ffff] that is hard to predict.
41  */
42 #ifndef tcp_tandom18
43 #define	tcp_random18()	((random() >> 14) & 0x3ffff)
44 #endif
45 #define	TCP_ISSINCR	(122*1024 + tcp_random18())
46 
47 tcp_seq	tcp_iss;		/* tcp initial send seq # */
48 #else
49 #define	TCP_ISSINCR	(250*1024)	/* increment for tcp_iss each second */
50 #endif
51