1 /*
2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
5 *
6 * Definitions for the TCP module.
7 *
8 * Version: @(#)tcp.h 1.0.5 05/23/93
9 *
10 * Authors: Ross Biro, <bir7@leland.Stanford.Edu>
11 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version
16 * 2 of the License, or (at your option) any later version.
17 */
18 #ifndef _TCP_H
19 #define _TCP_H
20
21 #include <linux/tcp.h>
22
23 #define MAX_SYN_SIZE 44 + sizeof (struct sk_buff) + MAX_HEADER
24 #define MAX_FIN_SIZE 40 + sizeof (struct sk_buff) + MAX_HEADER
25 #define MAX_ACK_SIZE 40 + sizeof (struct sk_buff) + MAX_HEADER
26 #define MAX_RESET_SIZE 40 + sizeof (struct sk_buff) + MAX_HEADER
27 #define MAX_WINDOW 4096
28 #define MIN_WINDOW 2048
29 #define MAX_ACK_BACKLOG 2
30 #define MIN_WRITE_SPACE 2048
31 #define TCP_WINDOW_DIFF 2048
32
33 #define TCP_RETR1 7 /*
34 * This is howmany retries it does before it
35 * tries to figure out if the gateway is
36 * down.
37 */
38
39 #define TCP_RETR2 15 /*
40 * This should take at least
41 * 90 minutes to time out.
42 */
43
44 #define TCP_TIMEOUT_LEN 5000 /* should be about 5 mins */
45 #define TCP_TIMEWAIT_LEN 1000 /* how long to wait to sucessfully
46 * close the socket, about 60 seconds */
47 #define TCP_ACK_TIME 3000 /* time to delay before sending an ACK */
48 #define TCP_DONE_TIME 250 /* maximum time to wait before actually
49 * destroying a socket */
50 #define TCP_WRITE_TIME 3000 /* initial time to wait for an ACK,
51 * after last transmit */
52 #define TCP_CONNECT_TIME 2000 /* time to retransmit first SYN */
53 #define TCP_SYN_RETRIES 5 /* number of times to retry openning a
54 * connection */
55 #define TCP_PROBEWAIT_LEN 100 /* time to wait between probes when
56 * I've got something to write and
57 * there is no window */
58
59 #define TCP_NO_CHECK 0 /* turn to one if you want the default
60 * to be no checksum */
61
62 #define TCP_WRITE_QUEUE_MAGIC 0xa5f23477
63
64 /*
65 * TCP option
66 */
67
68 #define TCPOPT_NOP 1
69 #define TCPOPT_EOL 0
70 #define TCPOPT_MSS 2
71
72 /*
73 * The next routines deal with comparing 32 bit unsigned ints
74 * and worry about wraparound. The general strategy is to do a
75 * normal compare so long as neither of the numbers is within
76 * 4K of wrapping. Otherwise we must check for the wrap.
77 */
78 static inline int
79 before (unsigned long seq1, unsigned long seq2)
/* ![[previous]](../icons/n_left.png)
![[next]](../icons/right.png)
![[first]](../icons/n_first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
80 {
81 /* this inequality is strict. */
82 if (seq1 == seq2) return(0);
83
84 if (seq1 < seq2) {
85 if ((unsigned long)seq2-(unsigned long)seq1 < 65536UL) {
86 return(1);
87 } else {
88 return(0);
89 }
90 }
91
92 /*
93 * Now we know seq1 > seq2. So all we need to do is check
94 * to see if seq1 has wrapped.
95 */
96 if (seq2 < 8192UL && seq1 > (0xffffffffUL - 8192UL)) {
97 return(1);
98 }
99 return(0);
100 }
101
102
103 static inline int
104 after(unsigned long seq1, unsigned long seq2)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
105 {
106 return(before(seq2, seq1));
107 }
108
109
110 /* is s2<=s1<=s3 ? */
111 static inline int
112 between(unsigned long seq1, unsigned long seq2, unsigned long seq3)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
113 {
114 return(after(seq1+1, seq2) && before(seq1, seq3+1));
115 }
116
117
118 /*
119 * List all states of a TCP socket that can be viewed as a "connected"
120 * state. This now includes TCP_SYN_RECV, although I am not yet fully
121 * convinced that this is the solution for the 'getpeername(2)'
122 * problem. Thanks to Stephen A. Wood <saw@cebaf.gov> -FvK
123 */
124 static inline const int
125 tcp_connected(const int state)
/* ![[previous]](../icons/left.png)
![[next]](../icons/n_right.png)
![[first]](../icons/first.png)
![[last]](../icons/n_last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
126 {
127 return(state == TCP_ESTABLISHED || state == TCP_CLOSE_WAIT ||
128 state == TCP_FIN_WAIT1 || state == TCP_FIN_WAIT2 ||
129 state == TCP_SYN_RECV);
130 }
131
132
133 extern struct proto tcp_prot;
134
135
136 extern void print_th(struct tcphdr *);
137 extern void tcp_err(int err, unsigned char *header, unsigned long daddr,
138 unsigned long saddr, struct inet_protocol *protocol);
139 extern void tcp_shutdown (struct sock *sk, int how);
140 extern int tcp_rcv(struct sk_buff *skb, struct device *dev,
141 struct options *opt, unsigned long daddr,
142 unsigned short len, unsigned long saddr, int redo,
143 struct inet_protocol *protocol);
144
145 extern int tcp_ioctl(struct sock *sk, int cmd, unsigned long arg);
146
147
148 #endif /* _TCP_H */