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