Statistics
| Branch: | Revision:

root / slirp / tcp.h @ 927d4878

History | View | Annotate | Download (6 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 b6dce92e Stefan Weil
typedef        uint32_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 b7221056 Paolo Bonzini
#define tcphdr slirp_tcphdr
49 f0cbd3ec bellard
struct tcphdr {
50 b6dce92e Stefan Weil
        uint16_t th_sport;              /* source port */
51 b6dce92e Stefan Weil
        uint16_t th_dport;              /* destination port */
52 f0cbd3ec bellard
        tcp_seq        th_seq;                        /* sequence number */
53 f0cbd3ec bellard
        tcp_seq        th_ack;                        /* acknowledgement number */
54 e2542fe2 Juan Quintela
#ifdef HOST_WORDS_BIGENDIAN
55 1b930bfa Jan Kiszka
        uint8_t        th_off:4,                /* data offset */
56 f0cbd3ec bellard
                th_x2:4;                /* (unused) */
57 f0cbd3ec bellard
#else
58 1b930bfa Jan Kiszka
        uint8_t        th_x2:4,                /* (unused) */
59 f0cbd3ec bellard
                th_off:4;                /* data offset */
60 f0cbd3ec bellard
#endif
61 b6dce92e Stefan Weil
        uint8_t th_flags;
62 b6dce92e Stefan Weil
        uint16_t th_win;                /* window */
63 b6dce92e Stefan Weil
        uint16_t th_sum;                /* checksum */
64 b6dce92e Stefan Weil
        uint16_t th_urp;                /* urgent pointer */
65 f0cbd3ec bellard
};
66 f0cbd3ec bellard
67 f0cbd3ec bellard
#include "tcp_var.h"
68 f0cbd3ec bellard
69 b7221056 Paolo Bonzini
#ifndef TH_FIN
70 b7221056 Paolo Bonzini
#define        TH_FIN        0x01
71 b7221056 Paolo Bonzini
#define        TH_SYN        0x02
72 b7221056 Paolo Bonzini
#define        TH_RST        0x04
73 b7221056 Paolo Bonzini
#define        TH_PUSH        0x08
74 b7221056 Paolo Bonzini
#define        TH_ACK        0x10
75 b7221056 Paolo Bonzini
#define        TH_URG        0x20
76 b7221056 Paolo Bonzini
#endif
77 b7221056 Paolo Bonzini
78 b7221056 Paolo Bonzini
#ifndef TCPOPT_EOL
79 f0cbd3ec bellard
#define        TCPOPT_EOL                0
80 f0cbd3ec bellard
#define        TCPOPT_NOP                1
81 f0cbd3ec bellard
#define        TCPOPT_MAXSEG                2
82 f0cbd3ec bellard
#define TCPOPT_WINDOW                3
83 f0cbd3ec bellard
#define TCPOPT_SACK_PERMITTED        4                /* Experimental */
84 f0cbd3ec bellard
#define TCPOPT_SACK                5                /* Experimental */
85 f0cbd3ec bellard
#define TCPOPT_TIMESTAMP        8
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 b7221056 Paolo Bonzini
#endif
90 f0cbd3ec bellard
91 e20e48a8 Andreas Färber
#ifndef TCPOLEN_MAXSEG
92 e20e48a8 Andreas Färber
#define    TCPOLEN_MAXSEG                4
93 e20e48a8 Andreas Färber
#define    TCPOLEN_WINDOW                3
94 e20e48a8 Andreas Färber
#define    TCPOLEN_SACK_PERMITTED        2
95 e20e48a8 Andreas Färber
#define    TCPOLEN_TIMESTAMP                10
96 e20e48a8 Andreas Färber
#define    TCPOLEN_TSTAMP_APPA                (TCPOLEN_TIMESTAMP+2) /* appendix A */
97 e20e48a8 Andreas Färber
#endif
98 e20e48a8 Andreas Färber
99 f0cbd3ec bellard
/*
100 f0cbd3ec bellard
 * Default maximum segment size for TCP.
101 f0cbd3ec bellard
 * With an IP MSS of 576, this is 536,
102 f0cbd3ec bellard
 * but 512 is probably more convenient.
103 f0cbd3ec bellard
 * This should be defined as MIN(512, IP_MSS - sizeof (struct tcpiphdr)).
104 773f2cdd bellard
 *
105 773f2cdd bellard
 * We make this 1460 because we only care about Ethernet in the qemu context.
106 f0cbd3ec bellard
 */
107 b7221056 Paolo Bonzini
#undef TCP_MSS
108 773f2cdd bellard
#define        TCP_MSS        1460
109 f0cbd3ec bellard
110 b7221056 Paolo Bonzini
#undef TCP_MAXWIN
111 f0cbd3ec bellard
#define        TCP_MAXWIN        65535        /* largest value for (unscaled) window */
112 f0cbd3ec bellard
113 b7221056 Paolo Bonzini
#undef TCP_MAX_WINSHIFT
114 f0cbd3ec bellard
#define TCP_MAX_WINSHIFT        14        /* maximum window shift */
115 f0cbd3ec bellard
116 f0cbd3ec bellard
/*
117 f0cbd3ec bellard
 * User-settable options (used with setsockopt).
118 28d657fc ths
 *
119 28d657fc ths
 * We don't use the system headers on unix because we have conflicting
120 28d657fc ths
 * local structures. We can't avoid the system definitions on Windows,
121 28d657fc ths
 * so we undefine them.
122 f0cbd3ec bellard
 */
123 28d657fc ths
#undef TCP_NODELAY
124 eaf7e70b ths
#define        TCP_NODELAY        0x01        /* don't delay send to coalesce packets */
125 28d657fc ths
#undef TCP_MAXSEG
126 f0cbd3ec bellard
127 f0cbd3ec bellard
/*
128 f0cbd3ec bellard
 * TCP FSM state definitions.
129 f0cbd3ec bellard
 * Per RFC793, September, 1981.
130 f0cbd3ec bellard
 */
131 f0cbd3ec bellard
132 f0cbd3ec bellard
#define TCP_NSTATES     11
133 f0cbd3ec bellard
134 f0cbd3ec bellard
#define TCPS_CLOSED             0       /* closed */
135 f0cbd3ec bellard
#define TCPS_LISTEN             1       /* listening for connection */
136 f0cbd3ec bellard
#define TCPS_SYN_SENT           2       /* active, have sent syn */
137 f0cbd3ec bellard
#define TCPS_SYN_RECEIVED       3       /* have send and received syn */
138 f0cbd3ec bellard
/* states < TCPS_ESTABLISHED are those where connections not established */
139 f0cbd3ec bellard
#define TCPS_ESTABLISHED        4       /* established */
140 f0cbd3ec bellard
#define TCPS_CLOSE_WAIT         5       /* rcvd fin, waiting for close */
141 f0cbd3ec bellard
/* states > TCPS_CLOSE_WAIT are those where user has closed */
142 f0cbd3ec bellard
#define TCPS_FIN_WAIT_1         6       /* have closed, sent fin */
143 f0cbd3ec bellard
#define TCPS_CLOSING            7       /* closed xchd FIN; await FIN ACK */
144 f0cbd3ec bellard
#define TCPS_LAST_ACK           8       /* had fin and close; await FIN ACK */
145 f0cbd3ec bellard
/* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */
146 f0cbd3ec bellard
#define TCPS_FIN_WAIT_2         9       /* have closed, fin is acked */
147 f0cbd3ec bellard
#define TCPS_TIME_WAIT          10      /* in 2*msl quiet wait after close */
148 f0cbd3ec bellard
149 f0cbd3ec bellard
#define TCPS_HAVERCVDSYN(s)     ((s) >= TCPS_SYN_RECEIVED)
150 f0cbd3ec bellard
#define TCPS_HAVEESTABLISHED(s) ((s) >= TCPS_ESTABLISHED)
151 f0cbd3ec bellard
#define TCPS_HAVERCVDFIN(s)     ((s) >= TCPS_TIME_WAIT)
152 f0cbd3ec bellard
153 f0cbd3ec bellard
/*
154 f0cbd3ec bellard
 * TCP sequence numbers are 32 bit integers operated
155 f0cbd3ec bellard
 * on with modular arithmetic.  These macros can be
156 f0cbd3ec bellard
 * used to compare such integers.
157 f0cbd3ec bellard
 */
158 f0cbd3ec bellard
#define SEQ_LT(a,b)     ((int)((a)-(b)) < 0)
159 f0cbd3ec bellard
#define SEQ_LEQ(a,b)    ((int)((a)-(b)) <= 0)
160 f0cbd3ec bellard
#define SEQ_GT(a,b)     ((int)((a)-(b)) > 0)
161 f0cbd3ec bellard
#define SEQ_GEQ(a,b)    ((int)((a)-(b)) >= 0)
162 f0cbd3ec bellard
163 f0cbd3ec bellard
/*
164 f0cbd3ec bellard
 * Macros to initialize tcp sequence numbers for
165 f0cbd3ec bellard
 * send and receive from initial send and receive
166 f0cbd3ec bellard
 * sequence numbers.
167 f0cbd3ec bellard
 */
168 f0cbd3ec bellard
#define tcp_rcvseqinit(tp) \
169 f0cbd3ec bellard
     (tp)->rcv_adv = (tp)->rcv_nxt = (tp)->irs + 1
170 f0cbd3ec bellard
171 f0cbd3ec bellard
#define tcp_sendseqinit(tp) \
172 f0cbd3ec bellard
    (tp)->snd_una = (tp)->snd_nxt = (tp)->snd_max = (tp)->snd_up = (tp)->iss
173 f0cbd3ec bellard
174 f0cbd3ec bellard
#define TCP_ISSINCR     (125*1024)      /* increment for tcp_iss each second */
175 f0cbd3ec bellard
176 f0cbd3ec bellard
#endif