Statistics
| Branch: | Revision:

root / slirp / tcp.h @ c94c8d64

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