1 /* tcp.h */ 2 /* 3 Copyright (C) 1992 Ross Biro 4
5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2, or (at your option) 8 any later version. 9
10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14
15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18
19 The Author may be reached as bir7@leland.stanford.edu or 20 C/O Department of Mathematics; Stanford University; Stanford, CA 94305 21 */ 22 #ifndef_TCP_TCP_H 23 #define_TCP_TCP_H 24
25 structtcp_header 26 { 27 unsignedshortsource;
28 unsignedshortdest;
29 unsignedlongseq;
30 unsignedlongack_seq;
31 unsignedshortres1:4, doff:4, fin:1, syn:1, rst:1, psh:1,
32 ack:1, urg:1,res2:2;
33 unsignedshortwindow;
34 unsignedshortcheck;
35 unsignedshorturg_ptr;
36 };
37
38 enum{ 39 TCP_ESTABLISHED=1,
40 TCP_SYN_SENT,
41 TCP_SYN_RECV,
42 TCP_CLOSING, /* not a valid state, just a seperator so we can use 43 < tcp_closing or > tcp_closing for checks. */ 44 TCP_FIN_WAIT1,
45 TCP_FIN_WAIT2,
46 TCP_TIME_WAIT,
47 TCP_CLOSE,
48 TCP_LAST_ACK,
49 TCP_LISTEN 50 };
51
52 #defineMAX_SYN_SIZE 44 + sizeof (structsk_buff) + MAX_HEADER 53 #defineMAX_FIN_SIZE 40 + sizeof (structsk_buff) + MAX_HEADER 54 #defineMAX_ACK_SIZE 40 + sizeof (structsk_buff) + MAX_HEADER 55 #defineMAX_RESET_SIZE 40 + sizeof (structsk_buff) + MAX_HEADER 56 #defineMAX_WINDOW 12000
57 #defineMIN_WINDOW 2048
58 #defineMAX_ACK_BACKLOG 2
59 #defineMIN_WRITE_SPACE 2048
60 #defineTCP_WINDOW_DIFF 2048
61
62 #defineTCP_RETR1 7 /* this is howmany retries it does 63 before it tries to figure out 64 if the gateway is down. */ 65
66 #defineTCP_RETR2 10 /* this should take between 3 and 67 ten minutes ( 1024 * rtt). */ 68
69
70 #defineTCP_TIMEOUT_LEN 720000 /* should be about 2 hrs. */ 71 #defineTCP_TIMEWAIT_LEN 6000 /* How long to wait to sucessfully 72 close the socket, about 60 seconds. */ 73 #defineTCP_ACK_TIME 35 /* time to delay before sending an ack. */ 74 #defineTCP_DONE_TIME 2500 /* maximum time to wait before actually destroying 75 a socket. */ 76 #defineTCP_WRITE_TIME 100 /* initial time to wait for an ack, 77 after last transmit. */ 78 #defineTCP_CONNECT_TIME 200 /* time to retransmit first syn. */ 79 #defineTCP_SYN_RETRIES 30 /* number of times to retry openning a connection. 80 */ 81
82 #defineTCP_NO_CHECK 0 /* turn to one if you want the default to be no 83 checksum . */ 84
85 voidprint_th (structtcp_header *);
86 #defineHEADER_SIZE 64
87
88
89 /* this next routines deal with comparing 32 bit unsigned ints and 90 worry about wrap around. The general strategy is to do a normal 91 compare so long as neither of the numbers is within 4k of wrapping. 92 Otherwise we must check for the wrap. */ 93
94 staticinlineint 95 before (unsignedlongseq1, unsignedlongseq2)
/* */ 96 { 97 /* this inequality is strict. */ 98 if (seq1 == seq2) return (0);
99 if (seq1 < seq2)
100 { 101 if ((unsignedlong)seq2-(unsignedlong)seq1 < 32767UL)
102 { 103 return (1);
104 } 105 else 106 { 107 return (0);
108 } 109 } 110 /* now we know seq1 > seq2. So all we need to do is check to see 111 if seq1 has wrapped. */ 112 if (seq2 < 4096UL && seq1 > (0xffffffUL - 4096UL))
113 { 114 return (1);
115 } 116 return (0);
117
118 } 119
120 staticinlineint 121 after (unsignedlongseq1, unsignedlongseq2)
/* */ 122 { 123 return (before (seq2, seq1));
124 } 125
126 /* is s2<=s1<=s3 ? */ 127 staticinlineint 128 between (unsignedlongseq1, unsignedlongseq2, unsignedlongseq3)
/* */ 129 { 130 return (after (seq1+1, seq2) && before (seq1, seq3+1));
131 } 132
133 #endif