This source file includes following definitions.
- before
- after
- between
- min
- max
- tcp_init_seq
- tcp_old_window
- tcp_raise_window
- tcp_select_window
- tcp_connected
- tcp_check
- tcp_set_state
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #ifndef _TCP_H
19 #define _TCP_H
20
21 #include <linux/tcp.h>
22 #include <net/checksum.h>
23
24
25
26
27
28 #define MAX_SYN_SIZE (sizeof(struct iphdr) + 40 + sizeof(struct tcphdr) + 4 + MAX_HEADER + 15)
29 #define MAX_FIN_SIZE (sizeof(struct iphdr) + 40 + sizeof(struct tcphdr) + MAX_HEADER + 15)
30 #define MAX_ACK_SIZE (sizeof(struct iphdr) + 40 + sizeof(struct tcphdr) + MAX_HEADER + 15)
31 #define MAX_RESET_SIZE (sizeof(struct iphdr) + 40 + sizeof(struct tcphdr) + MAX_HEADER + 15)
32
33 #define MAX_WINDOW 32767
34
35
36 #define MIN_WINDOW 2048
37 #define MAX_ACK_BACKLOG 2
38 #define MAX_DUP_ACKS 2
39 #define MIN_WRITE_SPACE 2048
40 #define TCP_WINDOW_DIFF 2048
41
42
43 #define URG_VALID 0x0100
44 #define URG_NOTYET 0x0200
45 #define URG_READ 0x0400
46
47 #define TCP_RETR1 7
48
49
50
51
52
53 #define TCP_RETR2 15
54
55
56
57
58 #define TCP_TIMEOUT_LEN (15*60*HZ)
59 #define TCP_TIMEWAIT_LEN (60*HZ)
60
61 #define TCP_FIN_TIMEOUT (3*60*HZ)
62 #define TCP_ACK_TIME (3*HZ)
63 #define TCP_DONE_TIME (5*HZ/2)
64
65 #define TCP_WRITE_TIME (30*HZ)
66
67 #define TCP_TIMEOUT_INIT (3*HZ)
68 #define TCP_SYN_RETRIES 10
69
70 #define TCP_PROBEWAIT_LEN (1*HZ)
71
72
73
74 #define TCP_NO_CHECK 0
75
76
77
78
79
80
81
82 #define TCPOPT_NOP 1
83 #define TCPOPT_EOL 0
84 #define TCPOPT_MSS 2
85
86
87
88 #define TCPOPT_WINDOW 3
89 #define TCPOPT_TIMESTAMP 8
90
91
92
93
94
95
96
97 extern __inline int before(__u32 seq1, __u32 seq2)
98 {
99 return (__s32)(seq1-seq2) < 0;
100 }
101
102 extern __inline int after(__u32 seq1, __u32 seq2)
103 {
104 return (__s32)(seq2-seq1) < 0;
105 }
106
107
108
109 extern __inline int between(__u32 seq1, __u32 seq2, __u32 seq3)
110 {
111 return (after(seq1+1, seq2) && before(seq1, seq3+1));
112 }
113
114 static __inline__ int min(unsigned int a, unsigned int b)
115 {
116 if (a > b)
117 a = b;
118 return a;
119 }
120
121 static __inline__ int max(unsigned int a, unsigned int b)
122 {
123 if (a < b)
124 a = b;
125 return a;
126 }
127
128 extern struct proto tcp_prot;
129 extern struct tcp_mib tcp_statistics;
130
131 extern void tcp_err(int type, int code, unsigned char *header, __u32 daddr,
132 __u32, struct inet_protocol *protocol);
133 extern void tcp_shutdown (struct sock *sk, int how);
134 extern int tcp_rcv(struct sk_buff *skb, struct device *dev,
135 struct options *opt, __u32 daddr,
136 unsigned short len, __u32 saddr, int redo,
137 struct inet_protocol *protocol);
138
139 extern int tcp_ioctl(struct sock *sk, int cmd, unsigned long arg);
140
141 extern void tcp_read_wakeup(struct sock *);
142 extern void tcp_write_xmit(struct sock *);
143 extern void tcp_time_wait(struct sock *);
144 extern void tcp_retransmit(struct sock *, int);
145 extern void tcp_do_retransmit(struct sock *, int);
146 extern void tcp_send_check(struct tcphdr *th, unsigned long saddr,
147 unsigned long daddr, int len, struct sk_buff *skb);
148
149
150
151 extern void tcp_send_probe0(struct sock *);
152 extern void tcp_send_partial(struct sock *);
153 extern void tcp_write_wakeup(struct sock *);
154 extern void tcp_send_fin(struct sock *sk);
155 extern void tcp_send_synack(struct sock *, struct sock *, struct sk_buff *);
156 extern void tcp_send_skb(struct sock *, struct sk_buff *);
157 extern void tcp_send_ack(struct sock *sk);
158 extern void tcp_send_delayed_ack(struct sock *sk, int timeout);
159 extern void tcp_send_reset(unsigned long saddr, unsigned long daddr, struct tcphdr *th,
160 struct proto *prot, struct options *opt, struct device *dev, int tos, int ttl);
161
162 extern void tcp_enqueue_partial(struct sk_buff *, struct sock *);
163 extern struct sk_buff * tcp_dequeue_partial(struct sock *);
164
165
166 extern void tcp_cache_zap(void);
167
168
169 #define tcp_reset_msl_timer(x,y,z) reset_timer(x,y,z)
170 extern void tcp_reset_xmit_timer(struct sock *, int, unsigned long);
171 extern void tcp_delack_timer(unsigned long);
172 extern void tcp_retransmit_timer(unsigned long);
173
174
175
176
177
178
179
180
181
182
183 static inline u32 tcp_init_seq(void)
184 {
185 struct timeval tv;
186 do_gettimeofday(&tv);
187 return tv.tv_usec+tv.tv_sec*1000000;
188 }
189
190 static __inline__ int tcp_old_window(struct sock * sk)
191 {
192 return sk->window - (sk->acked_seq - sk->lastwin_seq);
193 }
194
195 extern int tcp_new_window(struct sock *);
196
197
198
199
200
201
202
203
204
205 static __inline__ int tcp_raise_window(struct sock * sk)
206 {
207 int new = tcp_new_window(sk);
208 return new && (new >= 2*tcp_old_window(sk));
209 }
210
211 static __inline__ unsigned short tcp_select_window(struct sock *sk)
212 {
213 int window = tcp_new_window(sk);
214
215
216 if (window > tcp_old_window(sk)) {
217 sk->window = window;
218 sk->lastwin_seq = sk->acked_seq;
219 }
220 return sk->window;
221 }
222
223
224
225
226
227
228
229
230 extern __inline const int tcp_connected(const int state)
231 {
232 return(state == TCP_ESTABLISHED || state == TCP_CLOSE_WAIT ||
233 state == TCP_FIN_WAIT1 || state == TCP_FIN_WAIT2 ||
234 state == TCP_SYN_RECV);
235 }
236
237
238
239
240 static __inline__ u16 tcp_check(struct tcphdr *th, int len,
241 unsigned long saddr, unsigned long daddr, unsigned long base)
242 {
243 return csum_tcpudp_magic(saddr,daddr,len,IPPROTO_TCP,base);
244 }
245
246 #undef STATE_TRACE
247
248 #ifdef STATE_TRACE
249 static char *statename[]={
250 "Unused","Established","Syn Sent","Syn Recv",
251 "Fin Wait 1","Fin Wait 2","Time Wait", "Close",
252 "Close Wait","Last ACK","Listen","Closing"
253 };
254 #endif
255
256 static __inline__ void tcp_set_state(struct sock *sk, int state)
257 {
258 int oldstate = sk->state;
259
260 sk->state = state;
261
262 #ifdef STATE_TRACE
263 if(sk->debug)
264 printk("TCP sk=%p, State %s -> %s\n",sk, statename[oldstate],statename[state]);
265 #endif
266
267 switch (state) {
268 case TCP_ESTABLISHED:
269 if (oldstate != TCP_ESTABLISHED) {
270 tcp_statistics.TcpCurrEstab++;
271 }
272 break;
273
274 case TCP_CLOSE:
275 tcp_cache_zap();
276
277 reset_timer(sk, TIME_DONE, min(sk->rtt * 2, TCP_DONE_TIME));
278
279 default:
280 if (oldstate==TCP_ESTABLISHED)
281 tcp_statistics.TcpCurrEstab--;
282 }
283 }
284
285 #endif