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.7 1993/01/22 22:58:08 bir7 Exp $ */ 23 /* $Log: tcp.h,v $ 24 * Revision 0.8.4.7 1993/01/22 22:58:08 bir7 25 * Check in for merge with previous .99 pl 4. 26 * 27 * Revision 0.8.4.6 1992/12/12 19:25:04 bir7 28 * Fixed anti-memory Leak in shutdown. 29 * 30 * Revision 0.8.4.5 1992/12/12 01:50:49 bir7 31 * Fixed several bugs including half-duplex connections. 32 * 33 * Revision 0.8.4.4 1992/12/08 20:49:15 bir7 34 * Fixed minor bugs and checked out MSS. 35 * 36 * Revision 0.8.4.3 1992/12/06 23:29:59 bir7 37 * Added support for mss and half completed packets. Also added 38 * support for shrinking windows. 39 * 40 * Revision 0.8.4.2 1992/12/03 19:54:12 bir7 41 * Added paranoid queue checking. 42 * 43 * Revision 0.8.4.1 1992/11/10 00:17:18 bir7 44 * version change only. 45 * 46 * Revision 0.8.3.2 1992/11/10 00:14:47 bir7 47 * Changed malloc to kmalloc and added Id and Log 48 * 49 */ 50 51 #ifndef _TCP_TCP_H 52 #define _TCP_TCP_H 53 54 struct tcp_header 55 { 56 unsigned short source; 57 unsigned short dest; 58 unsigned long seq; 59 unsigned long ack_seq; 60 unsigned short res1:4, doff:4, fin:1, syn:1, rst:1, psh:1, 61 ack:1, urg:1,res2:2; 62 unsigned short window; 63 unsigned short check; 64 unsigned short urg_ptr; 65 }; 66 67 enum { 68 TCP_ESTABLISHED=1, 69 TCP_SYN_SENT, 70 TCP_SYN_RECV, 71 #if 0 72 TCP_CLOSING, /* not a valid state, just a seperator so we can use 73 < tcp_closing or > tcp_closing for checks. */ 74 #endif 75 TCP_FIN_WAIT1, 76 TCP_FIN_WAIT2, 77 TCP_TIME_WAIT, 78 TCP_CLOSE, 79 TCP_CLOSE_WAIT, 80 TCP_LAST_ACK, 81 TCP_LISTEN 82 }; 83 84 #define MAX_SYN_SIZE 44 + sizeof (struct sk_buff) + MAX_HEADER 85 #define MAX_FIN_SIZE 40 + sizeof (struct sk_buff) + MAX_HEADER 86 #define MAX_ACK_SIZE 40 + sizeof (struct sk_buff) + MAX_HEADER 87 #define MAX_RESET_SIZE 40 + sizeof (struct sk_buff) + MAX_HEADER 88 #define MAX_WINDOW 12000 89 #define MIN_WINDOW 2048 90 #define MAX_ACK_BACKLOG 2 91 #define MIN_WRITE_SPACE 2048 92 #define TCP_WINDOW_DIFF 2048 93 94 #define TCP_RETR1 10 /* this is howmany retries it does 95 before it tries to figure out 96 if the gateway is down. */ 97 98 #define TCP_RETR2 25 /* this should take at least 99 90 minutes to time out. */ 100 101 102 #define TCP_TIMEOUT_LEN 720000 /* should be about 2 hrs. */ 103 #define TCP_TIMEWAIT_LEN 6000 /* How long to wait to sucessfully 104 close the socket, about 60 seconds. */ 105 #define TCP_ACK_TIME 35 /* time to delay before sending an ack. */ 106 #define TCP_DONE_TIME 250 /* maximum time to wait before actually destroying 107 a socket. */ 108 #define TCP_WRITE_TIME 100 /* initial time to wait for an ack, 109 after last transmit. */ 110 #define TCP_CONNECT_TIME 200 /* time to retransmit first syn. */ 111 #define TCP_SYN_RETRIES 30 /* number of times to retry openning a connection. 112 */ 113 #define TCP_PROBEWAIT_LEN 250 /* time to wait between probes when I've got 114 something to write and there is no window. */ 115 116 #define TCP_NO_CHECK 0 /* turn to one if you want the default to be no 117 checksum . */ 118 119 void print_th (struct tcp_header *); 120 #define HEADER_SIZE 64 /* Maximum header size we need to deal with. */ 121 122 #define TCP_WRITE_QUEUE_MAGIC 0xa5f23477 123 124 /* this next routines deal with comparing 32 bit unsigned ints and 125 worry about wrap around. The general strategy is to do a normal 126 compare so long as neither of the numbers is within 4k of wrapping. 127 Otherwise we must check for the wrap. */ 128 129 static inline int 130 before (unsigned long seq1, unsigned long seq2) /* */ 131 { 132 /* this inequality is strict. */ 133 if (seq1 == seq2) return (0); 134 if (seq1 < seq2) 135 { 136 if ((unsigned long)seq2-(unsigned long)seq1 < 32767UL) 137 { 138 return (1); 139 } 140 else 141 { 142 return (0); 143 } 144 } 145 /* now we know seq1 > seq2. So all we need to do is check to see 146 if seq1 has wrapped. */ 147 if (seq2 < 4096UL && seq1 > (0xffffffUL - 4096UL)) 148 { 149 return (1); 150 } 151 return (0); 152 153 } 154 155 static inline int 156 after (unsigned long seq1, unsigned long seq2) /* */ 157 { 158 return (before (seq2, seq1)); 159 } 160 161 /* is s2<=s1<=s3 ? */ 162 static inline int 163 between (unsigned long seq1, unsigned long seq2, unsigned long seq3) /* */ 164 { 165 return (after (seq1+1, seq2) && before (seq1, seq3+1)); 166 } 167 168 static inline const int 169 tcp_connected (const int state) /* */ 170 { 171 return (state == TCP_ESTABLISHED || state == TCP_CLOSE_WAIT || 172 state == TCP_FIN_WAIT1 || state == TCP_FIN_WAIT2); 173 } 174 175 #endif