|
|
1.1 ! root 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 [email protected] 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: struct tcp_header ! 26: { ! 27: unsigned short source; ! 28: unsigned short dest; ! 29: unsigned long seq; ! 30: unsigned long ack_seq; ! 31: unsigned short res1:4, doff:4, fin:1, syn:1, rst:1, psh:1, ! 32: ack:1, urg:1,res2:2; ! 33: unsigned short window; ! 34: unsigned short check; ! 35: unsigned short urg_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: #define MAX_SYN_SIZE 44 + sizeof (struct sk_buff) + MAX_HEADER ! 53: #define MAX_FIN_SIZE 40 + sizeof (struct sk_buff) + MAX_HEADER ! 54: #define MAX_ACK_SIZE 40 + sizeof (struct sk_buff) + MAX_HEADER ! 55: #define MAX_RESET_SIZE 40 + sizeof (struct sk_buff) + MAX_HEADER ! 56: #define MAX_WINDOW 12000 ! 57: #define MIN_WINDOW 2048 ! 58: #define MAX_ACK_BACKLOG 2 ! 59: #define MIN_WRITE_SPACE 2048 ! 60: #define TCP_WINDOW_DIFF 2048 ! 61: ! 62: #define TCP_RETR1 7 /* this is howmany retries it does ! 63: before it tries to figure out ! 64: if the gateway is down. */ ! 65: ! 66: #define TCP_RETR2 10 /* this should take between 3 and ! 67: ten minutes ( 1024 * rtt). */ ! 68: ! 69: ! 70: #define TCP_TIMEOUT_LEN 720000 /* should be about 2 hrs. */ ! 71: #define TCP_TIMEWAIT_LEN 6000 /* How long to wait to sucessfully ! 72: close the socket, about 60 seconds. */ ! 73: #define TCP_ACK_TIME 35 /* time to delay before sending an ack. */ ! 74: #define TCP_DONE_TIME 2500 /* maximum time to wait before actually destroying ! 75: a socket. */ ! 76: #define TCP_WRITE_TIME 100 /* initial time to wait for an ack, ! 77: after last transmit. */ ! 78: #define TCP_CONNECT_TIME 200 /* time to retransmit first syn. */ ! 79: #define TCP_SYN_RETRIES 30 /* number of times to retry openning a connection. ! 80: */ ! 81: ! 82: #define TCP_NO_CHECK 0 /* turn to one if you want the default to be no ! 83: checksum . */ ! 84: ! 85: void print_th (struct tcp_header *); ! 86: #define HEADER_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: static inline int ! 95: before (unsigned long seq1, unsigned long seq2) ! 96: { ! 97: /* this inequality is strict. */ ! 98: if (seq1 == seq2) return (0); ! 99: if (seq1 < seq2) ! 100: { ! 101: if ((unsigned long)seq2-(unsigned long)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: static inline int ! 121: after (unsigned long seq1, unsigned long seq2) ! 122: { ! 123: return (before (seq2, seq1)); ! 124: } ! 125: ! 126: /* is s2<=s1<=s3 ? */ ! 127: static inline int ! 128: between (unsigned long seq1, unsigned long seq2, unsigned long seq3) ! 129: { ! 130: return (after (seq1+1, seq2) && before (seq1, seq3+1)); ! 131: } ! 132: ! 133: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.