root / slirp / tcp.h @ d8bcbabf
History | View | Annotate | Download (5.8 kB)
1 | f0cbd3ec | bellard | /*
|
---|---|---|---|
2 | f0cbd3ec | bellard | * Copyright (c) 1982, 1986, 1993
|
3 | f0cbd3ec | bellard | * The Regents of the University of California. All rights reserved.
|
4 | f0cbd3ec | bellard | *
|
5 | f0cbd3ec | bellard | * Redistribution and use in source and binary forms, with or without
|
6 | f0cbd3ec | bellard | * modification, are permitted provided that the following conditions
|
7 | f0cbd3ec | bellard | * are met:
|
8 | f0cbd3ec | bellard | * 1. Redistributions of source code must retain the above copyright
|
9 | f0cbd3ec | bellard | * notice, this list of conditions and the following disclaimer.
|
10 | f0cbd3ec | bellard | * 2. Redistributions in binary form must reproduce the above copyright
|
11 | f0cbd3ec | bellard | * notice, this list of conditions and the following disclaimer in the
|
12 | f0cbd3ec | bellard | * documentation and/or other materials provided with the distribution.
|
13 | 2f5f8996 | aliguori | * 3. Neither the name of the University nor the names of its contributors
|
14 | f0cbd3ec | bellard | * may be used to endorse or promote products derived from this software
|
15 | f0cbd3ec | bellard | * without specific prior written permission.
|
16 | f0cbd3ec | bellard | *
|
17 | f0cbd3ec | bellard | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
18 | f0cbd3ec | bellard | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
19 | f0cbd3ec | bellard | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
20 | f0cbd3ec | bellard | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
21 | f0cbd3ec | bellard | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
22 | f0cbd3ec | bellard | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
23 | f0cbd3ec | bellard | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
24 | f0cbd3ec | bellard | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | f0cbd3ec | bellard | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
26 | f0cbd3ec | bellard | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
27 | f0cbd3ec | bellard | * SUCH DAMAGE.
|
28 | f0cbd3ec | bellard | *
|
29 | f0cbd3ec | bellard | * @(#)tcp.h 8.1 (Berkeley) 6/10/93
|
30 | f0cbd3ec | bellard | * tcp.h,v 1.3 1994/08/21 05:27:34 paul Exp
|
31 | f0cbd3ec | bellard | */
|
32 | f0cbd3ec | bellard | |
33 | f0cbd3ec | bellard | #ifndef _TCP_H_
|
34 | f0cbd3ec | bellard | #define _TCP_H_
|
35 | f0cbd3ec | bellard | |
36 | f0cbd3ec | bellard | typedef u_int32_t tcp_seq;
|
37 | f0cbd3ec | bellard | |
38 | f0cbd3ec | bellard | #define PR_SLOWHZ 2 /* 2 slow timeouts per second (approx) */ |
39 | f0cbd3ec | bellard | #define PR_FASTHZ 5 /* 5 fast timeouts per second (not important) */ |
40 | f0cbd3ec | bellard | |
41 | f0cbd3ec | bellard | #define TCP_SNDSPACE 8192 |
42 | f0cbd3ec | bellard | #define TCP_RCVSPACE 8192 |
43 | f0cbd3ec | bellard | |
44 | f0cbd3ec | bellard | /*
|
45 | f0cbd3ec | bellard | * TCP header.
|
46 | f0cbd3ec | bellard | * Per RFC 793, September, 1981.
|
47 | f0cbd3ec | bellard | */
|
48 | f0cbd3ec | bellard | struct tcphdr {
|
49 | f0cbd3ec | bellard | u_int16_t th_sport; /* source port */
|
50 | f0cbd3ec | bellard | u_int16_t th_dport; /* destination port */
|
51 | f0cbd3ec | bellard | tcp_seq th_seq; /* sequence number */
|
52 | f0cbd3ec | bellard | tcp_seq th_ack; /* acknowledgement number */
|
53 | e2542fe2 | Juan Quintela | #ifdef HOST_WORDS_BIGENDIAN
|
54 | f0cbd3ec | bellard | u_int th_off:4, /* data offset */ |
55 | f0cbd3ec | bellard | th_x2:4; /* (unused) */ |
56 | f0cbd3ec | bellard | #else
|
57 | f0cbd3ec | bellard | u_int th_x2:4, /* (unused) */ |
58 | f0cbd3ec | bellard | th_off:4; /* data offset */ |
59 | f0cbd3ec | bellard | #endif
|
60 | f0cbd3ec | bellard | u_int8_t th_flags; |
61 | f0cbd3ec | bellard | #define TH_FIN 0x01 |
62 | f0cbd3ec | bellard | #define TH_SYN 0x02 |
63 | f0cbd3ec | bellard | #define TH_RST 0x04 |
64 | f0cbd3ec | bellard | #define TH_PUSH 0x08 |
65 | f0cbd3ec | bellard | #define TH_ACK 0x10 |
66 | f0cbd3ec | bellard | #define TH_URG 0x20 |
67 | f0cbd3ec | bellard | u_int16_t th_win; /* window */
|
68 | f0cbd3ec | bellard | u_int16_t th_sum; /* checksum */
|
69 | f0cbd3ec | bellard | u_int16_t th_urp; /* urgent pointer */
|
70 | f0cbd3ec | bellard | }; |
71 | f0cbd3ec | bellard | |
72 | f0cbd3ec | bellard | #include "tcp_var.h" |
73 | f0cbd3ec | bellard | |
74 | f0cbd3ec | bellard | #define TCPOPT_EOL 0 |
75 | f0cbd3ec | bellard | #define TCPOPT_NOP 1 |
76 | f0cbd3ec | bellard | #define TCPOPT_MAXSEG 2 |
77 | f0cbd3ec | bellard | #define TCPOLEN_MAXSEG 4 |
78 | f0cbd3ec | bellard | #define TCPOPT_WINDOW 3 |
79 | f0cbd3ec | bellard | #define TCPOLEN_WINDOW 3 |
80 | f0cbd3ec | bellard | #define TCPOPT_SACK_PERMITTED 4 /* Experimental */ |
81 | f0cbd3ec | bellard | #define TCPOLEN_SACK_PERMITTED 2 |
82 | f0cbd3ec | bellard | #define TCPOPT_SACK 5 /* Experimental */ |
83 | f0cbd3ec | bellard | #define TCPOPT_TIMESTAMP 8 |
84 | f0cbd3ec | bellard | #define TCPOLEN_TIMESTAMP 10 |
85 | f0cbd3ec | bellard | #define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2) /* appendix A */ |
86 | f0cbd3ec | bellard | |
87 | f0cbd3ec | bellard | #define TCPOPT_TSTAMP_HDR \
|
88 | f0cbd3ec | bellard | (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP) |
89 | f0cbd3ec | bellard | |
90 | f0cbd3ec | bellard | /*
|
91 | f0cbd3ec | bellard | * Default maximum segment size for TCP.
|
92 | f0cbd3ec | bellard | * With an IP MSS of 576, this is 536,
|
93 | f0cbd3ec | bellard | * but 512 is probably more convenient.
|
94 | f0cbd3ec | bellard | * This should be defined as MIN(512, IP_MSS - sizeof (struct tcpiphdr)).
|
95 | 773f2cdd | bellard | *
|
96 | 773f2cdd | bellard | * We make this 1460 because we only care about Ethernet in the qemu context.
|
97 | f0cbd3ec | bellard | */
|
98 | 773f2cdd | bellard | #define TCP_MSS 1460 |
99 | f0cbd3ec | bellard | |
100 | f0cbd3ec | bellard | #define TCP_MAXWIN 65535 /* largest value for (unscaled) window */ |
101 | f0cbd3ec | bellard | |
102 | f0cbd3ec | bellard | #define TCP_MAX_WINSHIFT 14 /* maximum window shift */ |
103 | f0cbd3ec | bellard | |
104 | f0cbd3ec | bellard | /*
|
105 | f0cbd3ec | bellard | * User-settable options (used with setsockopt).
|
106 | 28d657fc | ths | *
|
107 | 28d657fc | ths | * We don't use the system headers on unix because we have conflicting
|
108 | 28d657fc | ths | * local structures. We can't avoid the system definitions on Windows,
|
109 | 28d657fc | ths | * so we undefine them.
|
110 | f0cbd3ec | bellard | */
|
111 | 28d657fc | ths | #undef TCP_NODELAY
|
112 | eaf7e70b | ths | #define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */ |
113 | 28d657fc | ths | #undef TCP_MAXSEG
|
114 | f0cbd3ec | bellard | |
115 | f0cbd3ec | bellard | /*
|
116 | f0cbd3ec | bellard | * TCP FSM state definitions.
|
117 | f0cbd3ec | bellard | * Per RFC793, September, 1981.
|
118 | f0cbd3ec | bellard | */
|
119 | f0cbd3ec | bellard | |
120 | f0cbd3ec | bellard | #define TCP_NSTATES 11 |
121 | f0cbd3ec | bellard | |
122 | f0cbd3ec | bellard | #define TCPS_CLOSED 0 /* closed */ |
123 | f0cbd3ec | bellard | #define TCPS_LISTEN 1 /* listening for connection */ |
124 | f0cbd3ec | bellard | #define TCPS_SYN_SENT 2 /* active, have sent syn */ |
125 | f0cbd3ec | bellard | #define TCPS_SYN_RECEIVED 3 /* have send and received syn */ |
126 | f0cbd3ec | bellard | /* states < TCPS_ESTABLISHED are those where connections not established */
|
127 | f0cbd3ec | bellard | #define TCPS_ESTABLISHED 4 /* established */ |
128 | f0cbd3ec | bellard | #define TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */ |
129 | f0cbd3ec | bellard | /* states > TCPS_CLOSE_WAIT are those where user has closed */
|
130 | f0cbd3ec | bellard | #define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */ |
131 | f0cbd3ec | bellard | #define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */ |
132 | f0cbd3ec | bellard | #define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */ |
133 | f0cbd3ec | bellard | /* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */
|
134 | f0cbd3ec | bellard | #define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */ |
135 | f0cbd3ec | bellard | #define TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */ |
136 | f0cbd3ec | bellard | |
137 | f0cbd3ec | bellard | #define TCPS_HAVERCVDSYN(s) ((s) >= TCPS_SYN_RECEIVED)
|
138 | f0cbd3ec | bellard | #define TCPS_HAVEESTABLISHED(s) ((s) >= TCPS_ESTABLISHED)
|
139 | f0cbd3ec | bellard | #define TCPS_HAVERCVDFIN(s) ((s) >= TCPS_TIME_WAIT)
|
140 | f0cbd3ec | bellard | |
141 | f0cbd3ec | bellard | /*
|
142 | f0cbd3ec | bellard | * TCP sequence numbers are 32 bit integers operated
|
143 | f0cbd3ec | bellard | * on with modular arithmetic. These macros can be
|
144 | f0cbd3ec | bellard | * used to compare such integers.
|
145 | f0cbd3ec | bellard | */
|
146 | f0cbd3ec | bellard | #define SEQ_LT(a,b) ((int)((a)-(b)) < 0) |
147 | f0cbd3ec | bellard | #define SEQ_LEQ(a,b) ((int)((a)-(b)) <= 0) |
148 | f0cbd3ec | bellard | #define SEQ_GT(a,b) ((int)((a)-(b)) > 0) |
149 | f0cbd3ec | bellard | #define SEQ_GEQ(a,b) ((int)((a)-(b)) >= 0) |
150 | f0cbd3ec | bellard | |
151 | f0cbd3ec | bellard | /*
|
152 | f0cbd3ec | bellard | * Macros to initialize tcp sequence numbers for
|
153 | f0cbd3ec | bellard | * send and receive from initial send and receive
|
154 | f0cbd3ec | bellard | * sequence numbers.
|
155 | f0cbd3ec | bellard | */
|
156 | f0cbd3ec | bellard | #define tcp_rcvseqinit(tp) \
|
157 | f0cbd3ec | bellard | (tp)->rcv_adv = (tp)->rcv_nxt = (tp)->irs + 1
|
158 | f0cbd3ec | bellard | |
159 | f0cbd3ec | bellard | #define tcp_sendseqinit(tp) \
|
160 | f0cbd3ec | bellard | (tp)->snd_una = (tp)->snd_nxt = (tp)->snd_max = (tp)->snd_up = (tp)->iss |
161 | f0cbd3ec | bellard | |
162 | f0cbd3ec | bellard | #define TCP_ISSINCR (125*1024) /* increment for tcp_iss each second */ |
163 | f0cbd3ec | bellard | |
164 | f0cbd3ec | bellard | #endif |