1 |
/*!\file netinet/tcp_seq.h
|
1 |
/*!\file netinet/tcp_seq.h
|
2 |
* TCP serquence number handling.
|
2 |
* TCP serquence number handling.
|
3 |
*/
|
3 |
*/
|
4 |
|
4 |
|
5 |
/*
|
5 |
/*
|
6 |
* Copyright (c) 1982, 1986, 1993, 1995
|
6 |
* Copyright (c) 1982, 1986, 1993, 1995
|
7 |
* The Regents of the University of California. All rights reserved.
|
7 |
* The Regents of the University of California. All rights reserved.
|
8 |
*
|
8 |
*
|
9 |
* Redistribution and use in source and binary forms, with or without
|
9 |
* Redistribution and use in source and binary forms, with or without
|
10 |
* modification, are permitted provided that the following conditions
|
10 |
* modification, are permitted provided that the following conditions
|
11 |
* are met:
|
11 |
* are met:
|
12 |
* 1. Redistributions of source code must retain the above copyright
|
12 |
* 1. Redistributions of source code must retain the above copyright
|
13 |
* notice, this list of conditions and the following disclaimer.
|
13 |
* notice, this list of conditions and the following disclaimer.
|
14 |
* 2. Redistributions in binary form must reproduce the above copyright
|
14 |
* 2. Redistributions in binary form must reproduce the above copyright
|
15 |
* notice, this list of conditions and the following disclaimer in the
|
15 |
* notice, this list of conditions and the following disclaimer in the
|
16 |
* documentation and/or other materials provided with the distribution.
|
16 |
* documentation and/or other materials provided with the distribution.
|
17 |
* 3. All advertising materials mentioning features or use of this software
|
17 |
* 3. All advertising materials mentioning features or use of this software
|
18 |
* must display the following acknowledgement:
|
18 |
* must display the following acknowledgement:
|
19 |
* This product includes software developed by the University of
|
19 |
* This product includes software developed by the University of
|
20 |
* California, Berkeley and its contributors.
|
20 |
* California, Berkeley and its contributors.
|
21 |
* 4. Neither the name of the University nor the names of its contributors
|
21 |
* 4. Neither the name of the University nor the names of its contributors
|
22 |
* may be used to endorse or promote products derived from this software
|
22 |
* may be used to endorse or promote products derived from this software
|
23 |
* without specific prior written permission.
|
23 |
* without specific prior written permission.
|
24 |
*
|
24 |
*
|
25 |
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
25 |
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
26 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
26 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
27 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
27 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
28 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
28 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
29 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
29 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
30 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
30 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
31 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
31 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
32 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
32 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
33 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
33 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
34 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
34 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
35 |
* SUCH DAMAGE.
|
35 |
* SUCH DAMAGE.
|
36 |
*
|
36 |
*
|
37 |
* @(#)tcp_seq.h 8.3 (Berkeley) 6/21/95
|
37 |
* @(#)tcp_seq.h 8.3 (Berkeley) 6/21/95
|
38 |
* $Id: tcp_seq.h,v 1.6 1995/10/03 16:54:14 wollman Exp $
|
38 |
* $Id: tcp_seq.h,v 1.6 1995/10/03 16:54:14 wollman Exp $
|
39 |
*/
|
39 |
*/
|
40 |
|
40 |
|
41 |
#ifndef __NETINET_TCP_SEQ_H
|
41 |
#ifndef __NETINET_TCP_SEQ_H
|
42 |
#define __NETINET_TCP_SEQ_H
|
42 |
#define __NETINET_TCP_SEQ_H
|
43 |
|
43 |
|
44 |
/*
|
44 |
/*
|
45 |
* TCP sequence numbers are 32 bit integers operated
|
45 |
* TCP sequence numbers are 32 bit integers operated
|
46 |
* on with modular arithmetic. These macros can be
|
46 |
* on with modular arithmetic. These macros can be
|
47 |
* used to compare such integers.
|
47 |
* used to compare such integers.
|
48 |
*/
|
48 |
*/
|
49 |
#define SEQ_LT(a,b) ((long)((a)-(b)) < 0)
|
49 |
#define SEQ_LT(a,b) ((long)((a)-(b)) < 0)
|
50 |
#define SEQ_LEQ(a,b) ((long)((a)-(b)) <= 0)
|
50 |
#define SEQ_LEQ(a,b) ((long)((a)-(b)) <= 0)
|
51 |
#define SEQ_GT(a,b) ((long)((a)-(b)) > 0)
|
51 |
#define SEQ_GT(a,b) ((long)((a)-(b)) > 0)
|
52 |
#define SEQ_GEQ(a,b) ((long)((a)-(b)) >= 0)
|
52 |
#define SEQ_GEQ(a,b) ((long)((a)-(b)) >= 0)
|
53 |
|
53 |
|
54 |
/* for modulo comparisons of timestamps */
|
54 |
/* for modulo comparisons of timestamps */
|
55 |
#define TSTMP_LT(a,b) ((long)((a)-(b)) < 0)
|
55 |
#define TSTMP_LT(a,b) ((long)((a)-(b)) < 0)
|
56 |
#define TSTMP_GEQ(a,b) ((long)((a)-(b)) >= 0)
|
56 |
#define TSTMP_GEQ(a,b) ((long)((a)-(b)) >= 0)
|
57 |
|
57 |
|
58 |
/*
|
58 |
/*
|
59 |
* TCP connection counts are 32 bit integers operated
|
59 |
* TCP connection counts are 32 bit integers operated
|
60 |
* on with modular arithmetic. These macros can be
|
60 |
* on with modular arithmetic. These macros can be
|
61 |
* used to compare such integers.
|
61 |
* used to compare such integers.
|
62 |
*/
|
62 |
*/
|
63 |
#define CC_LT(a,b) ((long)((a)-(b)) < 0)
|
63 |
#define CC_LT(a,b) ((long)((a)-(b)) < 0)
|
64 |
#define CC_LEQ(a,b) ((long)((a)-(b)) <= 0)
|
64 |
#define CC_LEQ(a,b) ((long)((a)-(b)) <= 0)
|
65 |
#define CC_GT(a,b) ((long)((a)-(b)) > 0)
|
65 |
#define CC_GT(a,b) ((long)((a)-(b)) > 0)
|
66 |
#define CC_GEQ(a,b) ((long)((a)-(b)) >= 0)
|
66 |
#define CC_GEQ(a,b) ((long)((a)-(b)) >= 0)
|
67 |
|
67 |
|
68 |
/* Macro to increment a CC: skip 0 which has a special meaning */
|
68 |
/* Macro to increment a CC: skip 0 which has a special meaning */
|
69 |
#define CC_INC(c) (++(c) == 0 ? ++(c) : (c))
|
69 |
#define CC_INC(c) (++(c) == 0 ? ++(c) : (c))
|
70 |
|
70 |
|
71 |
/*
|
71 |
/*
|
72 |
* Macros to initialize tcp sequence numbers for
|
72 |
* Macros to initialize tcp sequence numbers for
|
73 |
* send and receive from initial send and receive
|
73 |
* send and receive from initial send and receive
|
74 |
* sequence numbers.
|
74 |
* sequence numbers.
|
75 |
*/
|
75 |
*/
|
76 |
#define tcp_rcvseqinit(tp) \
|
76 |
#define tcp_rcvseqinit(tp) \
|
77 |
(tp)->rcv_adv = (tp)->rcv_nxt = (tp)->irs + 1
|
77 |
(tp)->rcv_adv = (tp)->rcv_nxt = (tp)->irs + 1
|
78 |
|
78 |
|
79 |
#if defined(TCP_SACK)
|
79 |
#if defined(TCP_SACK)
|
80 |
#define tcp_sendseqinit(tp) \
|
80 |
#define tcp_sendseqinit(tp) \
|
81 |
(tp)->snd_una = (tp)->snd_nxt = (tp)->snd_max = (tp)->snd_up = \
|
81 |
(tp)->snd_una = (tp)->snd_nxt = (tp)->snd_max = (tp)->snd_up = \
|
82 |
(tp)->recover = (tp)->sb.last_ack = (tp)->iss
|
82 |
(tp)->recover = (tp)->sb.last_ack = (tp)->iss
|
83 |
|
83 |
|
84 |
#elif defined(TCP_FACK)
|
84 |
#elif defined(TCP_FACK)
|
85 |
#define tcp_sendseqinit(tp) \
|
85 |
#define tcp_sendseqinit(tp) \
|
86 |
(tp)->snd_una = (tp)->snd_nxt = (tp)->snd_max = (tp)->snd_up = \
|
86 |
(tp)->snd_una = (tp)->snd_nxt = (tp)->snd_max = (tp)->snd_up = \
|
87 |
(tp)->recover = (tp)->scrb.last_ack = (tp)->snd_fack = (tp)->iss
|
87 |
(tp)->recover = (tp)->scrb.last_ack = (tp)->snd_fack = (tp)->iss
|
88 |
|
88 |
|
89 |
#else
|
89 |
#else
|
90 |
#define tcp_sendseqinit(tp) \
|
90 |
#define tcp_sendseqinit(tp) \
|
91 |
(tp)->snd_una = (tp)->snd_nxt = (tp)->snd_max = (tp)->snd_up = \
|
91 |
(tp)->snd_una = (tp)->snd_nxt = (tp)->snd_max = (tp)->snd_up = \
|
92 |
(tp)->iss
|
92 |
(tp)->iss
|
93 |
#endif
|
93 |
#endif
|
94 |
|
94 |
|
95 |
#define TCP_PAWS_IDLE (24 * 24 * 60 * 60 * PR_SLOWHZ)
|
95 |
#define TCP_PAWS_IDLE (24 * 24 * 60 * 60 * PR_SLOWHZ)
|
96 |
/* timestamp wrap-around time */
|
96 |
/* timestamp wrap-around time */
|
97 |
|
97 |
|
98 |
#define TCP_ISSINCR (125*1024) /* increment for tcp_iss each second */
|
98 |
#define TCP_ISSINCR (125*1024) /* increment for tcp_iss each second */
|
99 |
|
99 |
|
100 |
#ifdef _KERNEL
|
100 |
#ifdef _KERNEL
|
101 |
tcp_seq tcp_iss; /* tcp initial send seq # */
|
101 |
tcp_seq tcp_iss; /* tcp initial send seq # */
|
102 |
#endif
|
102 |
#endif
|
103 |
|
103 |
|
104 |
#endif
|
104 |
#endif
|
105 |
|
105 |
|