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 /* $Id: tcp.h,v 0.8.4.1 1992/11/10 00:17:18 bir7 Exp $ */ 23 /* $Log: tcp.h,v $ 24 * Revision 0.8.4.1 1992/11/10 00:17:18 bir7 25 * version change only. 26 * 27 * Revision 0.8.3.2 1992/11/10 00:14:47 bir7 28 * Changed malloc to kmalloc and added $iId$ and $Log: tcp.h,v $ 29 * Revision 0.8.4.1 1992/11/10 00:17:18 bir7 30 * version change only. 31 *. 32 * */ 33
34 #ifndef_TCP_TCP_H 35 #define_TCP_TCP_H 36
37 structtcp_header 38 { 39 unsignedshortsource;
40 unsignedshortdest;
41 unsignedlongseq;
42 unsignedlongack_seq;
43 unsignedshortres1:4, doff:4, fin:1, syn:1, rst:1, psh:1,
44 ack:1, urg:1,res2:2;
45 unsignedshortwindow;
46 unsignedshortcheck;
47 unsignedshorturg_ptr;
48 };
49
50 enum{ 51 TCP_ESTABLISHED=1,
52 TCP_SYN_SENT,
53 TCP_SYN_RECV,
54 TCP_CLOSING, /* not a valid state, just a seperator so we can use 55 < tcp_closing or > tcp_closing for checks. */ 56 TCP_FIN_WAIT1,
57 TCP_FIN_WAIT2,
58 TCP_TIME_WAIT,
59 TCP_CLOSE,
60 TCP_LAST_ACK,
61 TCP_LISTEN 62 };
63
64 #defineMAX_SYN_SIZE 44 + sizeof (structsk_buff) + MAX_HEADER 65 #defineMAX_FIN_SIZE 40 + sizeof (structsk_buff) + MAX_HEADER 66 #defineMAX_ACK_SIZE 40 + sizeof (structsk_buff) + MAX_HEADER 67 #defineMAX_RESET_SIZE 40 + sizeof (structsk_buff) + MAX_HEADER 68 #defineMAX_WINDOW 12000
69 #defineMIN_WINDOW 2048
70 #defineMAX_ACK_BACKLOG 2
71 #defineMIN_WRITE_SPACE 2048
72 #defineTCP_WINDOW_DIFF 2048
73
74 #defineTCP_RETR1 7 /* this is howmany retries it does 75 before it tries to figure out 76 if the gateway is down. */ 77
78 #defineTCP_RETR2 10 /* this should take between 3 and 79 ten minutes ( 1024 * rtt). */ 80
81
82 #defineTCP_TIMEOUT_LEN 720000 /* should be about 2 hrs. */ 83 #defineTCP_TIMEWAIT_LEN 6000 /* How long to wait to sucessfully 84 close the socket, about 60 seconds. */ 85 #defineTCP_ACK_TIME 35 /* time to delay before sending an ack. */ 86 #defineTCP_DONE_TIME 2500 /* maximum time to wait before actually destroying 87 a socket. */ 88 #defineTCP_WRITE_TIME 100 /* initial time to wait for an ack, 89 after last transmit. */ 90 #defineTCP_CONNECT_TIME 200 /* time to retransmit first syn. */ 91 #defineTCP_SYN_RETRIES 30 /* number of times to retry openning a connection. 92 */ 93
94 #defineTCP_NO_CHECK 0 /* turn to one if you want the default to be no 95 checksum . */ 96
97 voidprint_th (structtcp_header *);
98 #defineHEADER_SIZE 100
99
100
101 /* this next routines deal with comparing 32 bit unsigned ints and 102 worry about wrap around. The general strategy is to do a normal 103 compare so long as neither of the numbers is within 4k of wrapping. 104 Otherwise we must check for the wrap. */ 105
106 staticinlineint 107 before (unsignedlongseq1, unsignedlongseq2)
/* */ 108 { 109 /* this inequality is strict. */ 110 if (seq1 == seq2) return (0);
111 if (seq1 < seq2)
112 { 113 if ((unsignedlong)seq2-(unsignedlong)seq1 < 32767UL)
114 { 115 return (1);
116 } 117 else 118 { 119 return (0);
120 } 121 } 122 /* now we know seq1 > seq2. So all we need to do is check to see 123 if seq1 has wrapped. */ 124 if (seq2 < 4096UL && seq1 > (0xffffffUL - 4096UL))
125 { 126 return (1);
127 } 128 return (0);
129
130 } 131
132 staticinlineint 133 after (unsignedlongseq1, unsignedlongseq2)
/* */ 134 { 135 return (before (seq2, seq1));
136 } 137
138 /* is s2<=s1<=s3 ? */ 139 staticinlineint 140 between (unsignedlongseq1, unsignedlongseq2, unsignedlongseq3)
/* */ 141 { 142 return (after (seq1+1, seq2) && before (seq1, seq3+1));
143 } 144
145 #endif