VirtualBox

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

Last change on this file since 97441 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

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