rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 1 | /************************************************************* |
| 2 | * |
| 3 | * This Software is the property of VIA Telecom, Inc. and may only be used pursuant to a license from VIA Telecom, Inc. |
| 4 | * |
| 5 | * Any unauthorized use inconsistent with the terms of such license is strictly prohibited. |
| 6 | * |
| 7 | * Copyright (c) 2002-2010 VIA Telecom, Inc. All rights reserved. |
| 8 | * |
| 9 | *************************************************************/ |
| 10 | /************************************************************************* |
| 11 | * |
| 12 | * File Name: tcp.h |
| 13 | * Project: TCP/IP |
| 14 | * |
| 15 | * Original Author: Steve Pye |
| 16 | * Creation Date: Based on PVCS Rev 1.1 (15 Apr 1998) |
| 17 | * |
| 18 | * Description: TCP Data Structures |
| 19 | * Restrictions: |
| 20 | * Dependencies: |
| 21 | * |
| 22 | ************************************************************************* |
| 23 | * |
| 24 | * This Software is the property of ISOTEL Research Ltd. |
| 25 | * Unauthorized use is prohibited. |
| 26 | * |
| 27 | * ISOTEL Research Ltd. |
| 28 | * Suite 340, 525 - 28th Street S.E. |
| 29 | * Calgary, Alberta, Canada T2A 6W9 |
| 30 | * Tel: (403)275-0041 Fax: (403)274-3598 |
| 31 | * |
| 32 | * |
| 33 | ************************************************************************* |
| 34 | * |
| 35 | * RCS Log Information |
| 36 | * |
| 37 | * removed! |
| 38 | * |
| 39 | * removed! |
| 40 | * |
| 41 | * removed! |
| 42 | * removed! |
| 43 | * removed! |
| 44 | * removed! |
| 45 | * removed! |
| 46 | * removed! |
| 47 | * removed! |
| 48 | * removed! |
| 49 | * removed! |
| 50 | * removed! |
| 51 | * removed! |
| 52 | * removed! |
| 53 | * removed! |
| 54 | * removed! |
| 55 | * removed! |
| 56 | * removed! |
| 57 | * removed! |
| 58 | * removed! |
| 59 | * removed! |
| 60 | * removed! |
| 61 | * |
| 62 | * removed! |
| 63 | * removed! |
| 64 | * |
| 65 | * |
| 66 | ************************************************************************/ |
| 67 | |
| 68 | #ifndef _TCP_H_ |
| 69 | #define _TCP_H_ 1 |
| 70 | |
| 71 | #include "IP_TYPE.H" |
| 72 | #include "IP.H" |
| 73 | |
| 74 | |
| 75 | /* TCP Header */ |
| 76 | |
| 77 | struct tcp_header |
| 78 | { |
| 79 | kal_uint16 src; /* source port number */ |
| 80 | kal_uint16 dst; /* destination port number */ |
| 81 | kal_uint32 seq; /* sequence number */ |
| 82 | kal_uint32 ack; /* acknowledgement sequence number */ |
| 83 | kal_uint8 hlen; /* [7:3] header 32-bit word length */ |
| 84 | kal_uint8 ctl; /* TCP control bit flags */ |
| 85 | kal_uint16 win; /* offered window */ |
| 86 | kal_uint16 chk; /* checksum over TCP header+data */ |
| 87 | kal_uint16 urg; /* offset from seq of last byte of */ |
| 88 | }; /* urgent data */ |
| 89 | |
| 90 | |
| 91 | /* TCP Header Control Field Bit Flags */ |
| 92 | |
| 93 | #define TCP_FIN 0x01 |
| 94 | #define TCP_SYN 0x02 |
| 95 | #define TCP_RST 0x04 |
| 96 | #define TCP_PSH 0x08 |
| 97 | #define TCP_ACK 0x10 |
| 98 | #define TCP_URG 0x20 |
| 99 | |
| 100 | |
| 101 | /* TCP/IP Header */ |
| 102 | |
| 103 | struct tcpip_header |
| 104 | { |
| 105 | struct ip_header ip; /* IP header without options */ |
| 106 | struct tcp_header tcp; /* TCP header without options */ |
| 107 | }; |
| 108 | |
| 109 | |
| 110 | /* TCP Constant Sizes */ |
| 111 | |
| 112 | #define TCP_HEADERSIZE 20 /* default TCP header size */ |
| 113 | #define TCP_MAXHDRSIZE 40 /* should really be 24 but nops ok */ |
| 114 | #define TCP_MAXSEGSIZE 536 /* IP_MAXDGMSIZE-TCPIP_HEADERSIZE */ |
| 115 | #define TCP_MSSOPTSIZE 4 /* max seg size option length */ |
| 116 | #define TCP_MSS_BACKOFF 80 /* in the case of VSNP type packets */ |
| 117 | |
| 118 | |
| 119 | /* TCP Maximum Segment Size Option */ |
| 120 | |
| 121 | struct tcp_mssopt |
| 122 | { |
| 123 | kal_uint8 type; /* TCPOPT_MAXSEG */ |
| 124 | kal_uint8 len; /* TCP_MSSOPTSIZE */ |
| 125 | kal_uint16 mss; /* maximum segment size */ |
| 126 | }; |
| 127 | |
| 128 | #define TCPOPT_TYPE 0 /* option type field offset */ |
| 129 | #define TCPOPT_LEN 1 /* option length field offset */ |
| 130 | #define TCPOPT_MSS 2 /* option mss field offset */ |
| 131 | |
| 132 | |
| 133 | /* TCP Option Types */ |
| 134 | |
| 135 | #define TCPOPT_EOL 0 /* end-of-list option */ |
| 136 | #define TCPOPT_NOP 1 /* no-operation option (padding) */ |
| 137 | #define TCPOPT_MAXSEG 2 /* maximum segment size option */ |
| 138 | |
| 139 | |
| 140 | /* TCP Protocol States */ |
| 141 | |
| 142 | #define TCPS_CLOSED 0 /* closed */ |
| 143 | #define TCPS_LISTEN 1 /* passive: listening for SYN */ |
| 144 | #define TCPS_SYNSENT 2 /* active: have sent SYN */ |
| 145 | #define TCPS_SYNRCVD 3 /* have sent and received SYN */ |
| 146 | #define TCPS_ESTABLISHED 4 /* established */ |
| 147 | #define TCPS_CLOSEWAIT 5 /* rcvd FIN, awaiting user close */ |
| 148 | #define TCPS_FINWAIT1 6 /* user closed, sent FIN */ |
| 149 | #define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */ |
| 150 | #define TCPS_LASTACK 8 /* had FIN and close await FIN ACK */ |
| 151 | #define TCPS_FINWAIT2 9 /* have closed, FIN is acked */ |
| 152 | #define TCPS_TIMEWAIT 10 /* in 2*MSL quiet wait after close */ |
| 153 | |
| 154 | #define TCP_NSTATES 11 |
| 155 | |
| 156 | /*set for trace, copy from TCP Protocol States above*/ |
| 157 | enum TraceTcpStates |
| 158 | { |
| 159 | TCP_CLOSED, |
| 160 | TCP_LISTEN, |
| 161 | TCP_SYNSENT, |
| 162 | TCP_SYNRCVD, |
| 163 | TCP_ESTABLISHED, |
| 164 | TCP_CLOSEWAIT, |
| 165 | TCP_FINWAIT1, |
| 166 | TCP_CLOSING, |
| 167 | TCP_LASTACK, |
| 168 | TCP_FINWAIT2, |
| 169 | TCP_TIMEWAIT, |
| 170 | TCP_STATE_NUM |
| 171 | }; |
| 172 | |
| 173 | #define TCP_HAVERCVDSYN(s) ((s) >= TCPS_SYNRCVD) |
| 174 | #define TCP_HAVERCVDFIN(s) ((s) >= TCPS_TIMEWAIT) |
| 175 | #define TCP_HAVESENTSYN(s) ((s) >= TCPS_SYNSENT) |
| 176 | #define TCP_HAVESENTFIN(s) ((s) >= TCPS_FINWAIT1) |
| 177 | |
| 178 | |
| 179 | /* TCP Sequence Number Ordinality Macros. Note that if two sequence numbers |
| 180 | differ by more than half the sequence space, then their ordinality is |
| 181 | reversed and wraparound is assumed to have occurred. */ |
| 182 | |
| 183 | #define SEQ_LT(a,b) ( (kal_int32)((a)-(b)) < 0 ) |
| 184 | #define SEQ_LE(a,b) ( (kal_int32)((a)-(b)) <= 0 ) |
| 185 | #define SEQ_GT(a,b) ( (kal_int32)((a)-(b)) > 0 ) |
| 186 | #define SEQ_GE(a,b) ( (kal_int32)((a)-(b)) >= 0 ) |
| 187 | |
| 188 | |
| 189 | /* TCP Send and Receive Sequence Number Initialization Macros */ |
| 190 | |
| 191 | #define TCP_RECVSEQINIT(tp) \ |
| 192 | (tp)->rcv_adv = (tp)->rcv_nxt = (tp)->rcv_irs + 1 |
| 193 | |
| 194 | #define TCP_SENDSEQINIT(tp) \ |
| 195 | (tp)->snd_una = (tp)->snd_nxt = (tp)->snd_max = (tp)->snd_iss |
| 196 | |
| 197 | #define TCP_PUSHURGINIT(tp) \ |
| 198 | (tp)->snd_psh = (tp)->snd_urg = (tp)->snd_una-1 |
| 199 | |
| 200 | |
| 201 | /* TCP Set Time Value Within a Defined Range Macro */ |
| 202 | |
| 203 | #define TCPT_RANGESET( tv, value, tvmin, tvmax ) \ |
| 204 | { \ |
| 205 | (tv) = (value); \ |
| 206 | if( (tv) < (tvmin) ) \ |
| 207 | (tv) = (tvmin); \ |
| 208 | else if( (tv) > (tvmax) ) \ |
| 209 | (tv) = (tvmax); \ |
| 210 | } |
| 211 | |
| 212 | |
| 213 | /* TCP Initial Sequence Number Assignment Increment. RFC793 suggests that |
| 214 | the TCP connection snd_iss should be assigned from a counter that is |
| 215 | incremented by 1 every 4 usecs. Then TCP_ISSINCR = |
| 216 | |
| 217 | 1 (incr) 1 (secs) 10^6 (incr) |
| 218 | ------------------ x ------------------ = -------------------- |
| 219 | 4 x 10^(-6) (secs) IP_CLOCKHZ (ticks) 4 x IP_CLOCKHZ (tick) |
| 220 | |
| 221 | For an IP clock tick of 250 msecs (i.e. IP_CLOCKHZ = 4 ticks/sec) |
| 222 | TCP_ISSINCR = 1/16 x 10^6 = 62500 incr/tick. */ |
| 223 | |
| 224 | #define TCP_ISSINCR (62500UL) /* tcp_iss increment on each tick */ |
| 225 | |
| 226 | |
| 227 | /* Round-Trip Time and Variance Scaling Factors. The smoothed round-trip |
| 228 | time and estimated variance are stored in the tcb as fixed point |
| 229 | values scaled-up by the multipliers below. */ |
| 230 | |
| 231 | #define TCP_RTT_SCALE 8 /* multiplier for SRTT */ |
| 232 | #define TCP_RTT_SHIFT 3 /* log2 of SRTT multiplier */ |
| 233 | #define TCP_RTTVAR_SCALE 4 /* multiplier for RTTVAR */ |
| 234 | #define TCP_RTTVAR_SHIFT 2 /* log2 of RTTVAR multiplier */ |
| 235 | |
| 236 | #define REAL_RTTUNIT 1000000UL /* route cache rtt values recorded */ |
| 237 | /* in units of microseconds */ |
| 238 | |
| 239 | /* TCP Retransmit Timeout Macro */ |
| 240 | |
| 241 | #define TCP_REXMTVAL(tp) ((((kal_int32)(tp)->t_srtt)>>TCP_RTT_SHIFT)+((kal_int32)(tp)->t_rttvar)) |
| 242 | |
| 243 | #endif /* _TCP_H_ */ |