VirtualBox

source: vbox/trunk/src/VBox/Devices/Network/slirp/tcp.h@ 28449

Last change on this file since 28449 was 28449, checked in by vboxsync, 15 years ago

NAT: slirp file headers

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 KB
Line 
1/* $Id: tcp.h 28449 2010-04-19 09:52:59Z vboxsync $ */
2/** @file
3 * NAT - TCP.
4 */
5
6/*
7 * Copyright (C) 2006-2010 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22/*
23 * This code is based on:
24 *
25 * Copyright (c) 1982, 1986, 1993
26 * The Regents of the University of California. All rights reserved.
27 *
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
30 * are met:
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. All advertising materials mentioning features or use of this software
37 * must display the following acknowledgement:
38 * This product includes software developed by the University of
39 * California, Berkeley and its contributors.
40 * 4. Neither the name of the University nor the names of its contributors
41 * may be used to endorse or promote products derived from this software
42 * without specific prior written permission.
43 *
44 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54 * SUCH DAMAGE.
55 *
56 * @(#)tcp.h 8.1 (Berkeley) 6/10/93
57 * tcp.h,v 1.3 1994/08/21 05:27:34 paul Exp
58 */
59
60#ifndef _TCP_H_
61#define _TCP_H_
62
63typedef uint32_t tcp_seq;
64
65#define PR_SLOWHZ 2 /* 2 slow timeouts per second (approx) */
66#define PR_FASTHZ 5 /* 5 fast timeouts per second (not important) */
67
68extern int tcp_rcvspace;
69extern int tcp_sndspace;
70extern struct socket *tcp_last_so;
71
72#define TCP_SNDSPACE 8192
73#define TCP_RCVSPACE 8192
74
75/*
76 * TCP header.
77 * Per RFC 793, September, 1981.
78 */
79struct tcphdr
80{
81 uint16_t th_sport; /* source port */
82 uint16_t th_dport; /* destination port */
83 tcp_seq th_seq; /* sequence number */
84 tcp_seq th_ack; /* acknowledgement number */
85#ifdef WORDS_BIGENDIAN
86# ifdef _MSC_VER
87 uint8_t th_off:4; /* data offset */
88 uint8_t th_x2:4; /* (unused) */
89# else
90 unsigned th_off:4; /* data offset */
91 unsigned th_x2:4; /* (unused) */
92# endif
93#else
94# ifdef _MSC_VER
95 uint8_t th_x2:4; /* (unused) */
96 uint8_t th_off:4; /* data offset */
97# else
98 unsigned th_x2:4; /* (unused) */
99 unsigned th_off:4; /* data offset */
100# endif
101#endif
102 uint8_t th_flags;
103#define TH_FIN 0x01
104#define TH_SYN 0x02
105#define TH_RST 0x04
106#define TH_PUSH 0x08
107#define TH_ACK 0x10
108#define TH_URG 0x20
109 uint16_t th_win; /* window */
110 uint16_t th_sum; /* checksum */
111 uint16_t th_urp; /* urgent pointer */
112};
113AssertCompileSize(struct tcphdr, 20);
114
115#include "tcp_var.h"
116
117#define TCPOPT_EOL 0
118#define TCPOPT_NOP 1
119#define TCPOPT_MAXSEG 2
120#define TCPOLEN_MAXSEG 4
121#define TCPOPT_WINDOW 3
122#define TCPOLEN_WINDOW 3
123#define TCPOPT_SACK_PERMITTED 4 /* Experimental */
124#define TCPOLEN_SACK_PERMITTED 2
125#define TCPOPT_SACK 5 /* Experimental */
126#define TCPOPT_TIMESTAMP 8
127#define TCPOLEN_TIMESTAMP 10
128#define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2) /* appendix A */
129
130#define TCPOPT_TSTAMP_HDR \
131 (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP)
132
133/*
134 * Default maximum segment size for TCP.
135 * With an IP MSS of 576, this is 536,
136 * but 512 is probably more convenient.
137 * This should be defined as MIN(512, IP_MSS - sizeof (struct tcpiphdr)).
138 *
139 * We make this 1460 because we only care about Ethernet in the qemu context.
140 */
141#ifndef VBOX_WITH_SLIRP_BSD_MBUF
142#define TCP_MSS 1460
143#else
144#define TCP_MSS (if_mtu - 80)
145#endif
146
147#define TCP_MAXWIN 65535 /* largest value for (unscaled) window */
148
149#define TCP_MAX_WINSHIFT 14 /* maximum window shift */
150
151/*
152 * User-settable options (used with setsockopt).
153 *
154 * We don't use the system headers on unix because we have conflicting
155 * local structures. We can't avoid the system definitions on Windows,
156 * so we undefine them.
157 */
158#undef TCP_NODELAY
159#define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */
160#undef TCP_MAXSEG
161/* #define TCP_MAXSEG 0x02 */ /* set maximum segment size */
162
163/*
164 * TCP FSM state definitions.
165 * Per RFC793, September, 1981.
166 */
167
168#define TCP_NSTATES 11
169
170#define TCPS_CLOSED 0 /* closed */
171#define TCPS_LISTEN 1 /* listening for connection */
172#define TCPS_SYN_SENT 2 /* active, have sent syn */
173#define TCPS_SYN_RECEIVED 3 /* have send and received syn */
174/* states < TCPS_ESTABLISHED are those where connections not established */
175#define TCPS_ESTABLISHED 4 /* established */
176#define TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */
177/* states > TCPS_CLOSE_WAIT are those where user has closed */
178#define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */
179#define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */
180#define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */
181/* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */
182#define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */
183#define TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */
184
185#define TCPS_HAVERCVDSYN(s) ((s) >= TCPS_SYN_RECEIVED)
186#define TCPS_HAVEESTABLISHED(s) ((s) >= TCPS_ESTABLISHED)
187#define TCPS_HAVERCVDFIN(s) ((s) >= TCPS_TIME_WAIT)
188
189/*
190 * TCP sequence numbers are 32 bit integers operated on with modular arithmetic.
191 * These macros can be used to compare such integers.
192 */
193#define SEQ_LT(a,b) ((int)((a)-(b)) < 0)
194#define SEQ_LEQ(a,b) ((int)((a)-(b)) <= 0)
195#define SEQ_GT(a,b) ((int)((a)-(b)) > 0)
196#define SEQ_GEQ(a,b) ((int)((a)-(b)) >= 0)
197
198/*
199 * Macros to initialize tcp sequence numbers for
200 * send and receive from initial send and receive
201 * sequence numbers.
202 */
203#define tcp_rcvseqinit(tp) \
204 (tp)->rcv_adv = (tp)->rcv_nxt = (tp)->irs + 1
205
206#define tcp_sendseqinit(tp) \
207 (tp)->snd_una = (tp)->snd_nxt = (tp)->snd_max = (tp)->snd_up = (tp)->iss
208
209#define TCP_ISSINCR (125*1024) /* increment for tcp_iss each second */
210
211
212extern const char * const tcpstates[];
213
214#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette