Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

872 lines
32 KiB

  1. /** Microsoft LAN Manager **/
  2. /** Copyright(c) Microsoft Corp., 1990-2000 **/
  3. /********************************************************************/
  4. /* :ts=4 */
  5. #ifndef _TCP_INCLUDED_
  6. #define _TCP_INCLUDED_
  7. //** TCP.H - TCP definitions.
  8. //
  9. // This file contains the definitions of TCP protocol specific options, such
  10. // as the sequence numbers and TCB.
  11. //
  12. #define PROTOCOL_TCP 6
  13. #define MIN_LOCAL_MSS 88
  14. #define MAX_REMOTE_MSS 536
  15. //* Timer stuff. We keep timers as ticks.
  16. #define MS_PER_TICK 100
  17. #define MS_TO_TICKS(m) ((m) / MS_PER_TICK)
  18. #define MIN_RETRAN_TICKS 3
  19. #define DEL_ACK_TICKS 2
  20. #define MAX_DEL_ACK_TICKS 6
  21. // Define MAX_REXMIT_TO to be number of ticks in 2MSL
  22. #define MAX_REXMIT_TO ((ushort)FinWait2TO)
  23. #define SWS_TO MS_TO_TICKS(5000)
  24. #define PUSH_TO MS_TO_TICKS(500)
  25. typedef ulong TCP_TIME;
  26. #define MAX_CONN_TO_TICKS 0xffff
  27. #define INFINITE_CONN_TO(t) ((t) == 0)
  28. #define TCP_TIME_TO_TICKS(t) (((t)/MS_PER_TICK)+1)
  29. // Sequence numbers are kept as signed 32 bit quantities, with macros
  30. // defined to do wraparound comparisons on them.
  31. typedef int SeqNum; // A sequence number.
  32. //* Macros for comparions on sequence numbers.
  33. #define SEQ_GT(a, b) ((SeqNum)((a) - (b)) > 0)
  34. #define SEQ_GTE(a, b) ((SeqNum)((a) - (b)) >= 0)
  35. #define SEQ_LT(a, b) ((SeqNum)((a) - (b)) < 0)
  36. #define SEQ_LTE(a, b) ((SeqNum)((a) - (b)) <= 0)
  37. #define SEQ_EQ(a, b) ((a) == (b))
  38. #define TS_LT(a, b) (((a) - (b)) < 0)
  39. #define TS_LTE(a, b) (((a) - (b)) <= 0)
  40. #define TS_GTE(a, b) (((a) - (b)) >= 0)
  41. #define TCPTIME_LTE(a, b) ((int)((a) - (b)) <= 0)
  42. #define TCPTIME_LT(a, b) ((int)((a) - (b)) < 0)
  43. #define TIMWAITTABLE 1 //turn on timed wait TCB table changes
  44. #define IRPFIX 1 //turn on quick Irp to Conn find
  45. #if DBG && !MILLEN
  46. #ifndef REFERENCE_DEBUG
  47. #define REFERENCE_DEBUG 1
  48. #endif
  49. #else // DBG && !MILLEN
  50. #ifndef REFERENCE_DEBUG
  51. #define REFERENCE_DEBUG 0
  52. #endif
  53. #endif // DBG && !MILLEN
  54. #if REFERENCE_DEBUG
  55. // Reference history structure.
  56. //
  57. #define MAX_REFERENCE_HISTORY 64
  58. typedef struct _TCP_REFERENCE_HISTORY {
  59. uchar *File;
  60. uint Line;
  61. void *Caller;
  62. uint Count;
  63. } TCP_REFERENCE_HISTORY;
  64. #endif // REFERENCE_DEBUG
  65. //* The TCB - transport control block structure. This is the
  66. // structure that contains all of the state for the transport
  67. // connection, including sequence numbers, flow control information,
  68. // pending sends and receives, etc.
  69. #define tcb_signature 0x20424354 // 'TCB '
  70. #define twtcb_signature 0x22424354 // 'TCB2'
  71. #define syntcb_signature 0x23424354 // 'TCB3'
  72. typedef struct TWTCB {
  73. #if DBG
  74. ulong twtcb_sig;
  75. #endif
  76. Queue twtcb_link;
  77. IPAddr twtcb_daddr; // Destination IP address.
  78. IPAddr twtcb_saddr; // Source IP address.
  79. ushort twtcb_dport; // Destination port.
  80. ushort twtcb_sport; // Source port.
  81. Queue twtcb_TWQueue; // Place to hang all the timed_waits
  82. ushort twtcb_delta;
  83. ushort twtcb_rexmittimer;
  84. SeqNum twtcb_senduna;
  85. SeqNum twtcb_rcvnext;
  86. SeqNum twtcb_sendnext;
  87. #if DBG
  88. uint twtcb_flags;
  89. #endif
  90. } TWTCB;
  91. typedef struct SYNTCB {
  92. #if DBG
  93. ulong syntcb_sig; // Debug signature.
  94. #endif
  95. Queue syntcb_link; // Next pointer in TCB table.
  96. DEFINE_LOCK_STRUCTURE(syntcb_lock)
  97. // Addressing info.
  98. IPAddr syntcb_daddr; // Destination IP address.
  99. IPAddr syntcb_saddr; // Source IP address.
  100. ushort syntcb_dport; // Destination port.
  101. ushort syntcb_sport; // Source port.
  102. // State information.
  103. uchar syntcb_state; // State of this TCB.
  104. uchar syntcb_rexmitcnt; // Count of rexmits on this TCB.
  105. // Highly used receive sequence variables.
  106. ushort syntcb_mss; // MSS for this connection.
  107. ushort syntcb_remmss; // MSS advertised by peer.
  108. ushort syntcb_tcpopts; // rfc 1323 and 2018 options holder
  109. SeqNum syntcb_rcvnext; // Next byte we expect to receive.
  110. int syntcb_rcvwin; // Receive window we're offering.
  111. // Send sequence variables.
  112. SeqNum syntcb_senduna; // Sequence number of first unack'd data.
  113. SeqNum syntcb_sendnext; // Sequence number of next byte to send.
  114. SeqNum syntcb_sendmax; // Max value of sendnext this epoch.
  115. uint syntcb_sendwin; // Send window.
  116. uint syntcb_flags; // Flags for this TCB.
  117. uint syntcb_refcnt; // Reference count for TCB.
  118. ushort syntcb_rexmit; // Rexmit value.
  119. // Retransmit timer information. These are stored as ticks, where by
  120. // default each tick is 100ms.
  121. ushort syntcb_smrtt; // Smoothed rtt value.
  122. ushort syntcb_delta; // Delta value.
  123. ushort syntcb_rexmittimer;// Timer for rexmit.
  124. uint syntcb_rtt; // Current round trip time TS.
  125. uint syntcb_defaultwin; // Default rcv. window.
  126. short syntcb_sndwinscale;// send window scale
  127. short syntcb_rcvwinscale;// receive window scale
  128. int syntcb_tsrecent; // time stamp recent
  129. SeqNum syntcb_lastack; // ack number in the last segment sent
  130. int syntcb_tsupdatetime; // Time when tsrecent was updated
  131. uint syntcb_walkcount;
  132. uint syntcb_partition;
  133. } SYNTCB;
  134. #if TRACE_EVENT
  135. typedef struct WMIData {
  136. ulong wmi_context; // PID
  137. ulong wmi_size; // num Bytes successfully sent.
  138. IPAddr wmi_destaddr; // Remote IPAddr.
  139. IPAddr wmi_srcaddr; // Local IPAddr.
  140. ushort wmi_destport; // Remote port.
  141. ushort wmi_srcport; // Local Port.
  142. } WMIData;
  143. #endif
  144. // We will have 7 timers in TCP, and integrate all their processing
  145. typedef enum {
  146. RXMIT_TIMER = 0,
  147. DELACK_TIMER,
  148. PUSH_TIMER,
  149. SWS_TIMER,
  150. ACD_TIMER,
  151. CONN_TIMER,
  152. KA_TIMER,
  153. NUM_TIMERS
  154. } TCP_TIMER_TYPE;
  155. #define NO_TIMER NUM_TIMERS
  156. typedef struct TCB {
  157. #if DBG
  158. ulong tcb_sig; // Debug signature.
  159. #endif
  160. struct TCB *tcb_next; // Next pointer in TCB table.
  161. DEFINE_LOCK_STRUCTURE(tcb_lock)
  162. uint tcb_refcnt; // Reference count for TCB.
  163. // Addressing info.
  164. IPAddr tcb_daddr; // Destination IP address.
  165. IPAddr tcb_saddr; // Source IP address.
  166. ushort tcb_dport; // Destination port.
  167. ushort tcb_sport; // Source port.
  168. #if TRACE_EVENT
  169. ulong tcb_cpcontext;
  170. #endif
  171. // State information.
  172. uchar tcb_state; // State of this TCB.
  173. uchar tcb_rexmitcnt; // Count of rexmits on this TCB.
  174. uchar tcb_pending; // Pending actions on this TCB.
  175. uchar tcb_kacount; // Count of keep alive probes sent.
  176. // Highly used receive sequence variables.
  177. ushort tcb_mss; // MSS for this connection.
  178. ushort tcb_remmss; // MSS advertised by peer.
  179. SeqNum tcb_rcvnext; // Next byte we expect to receive.
  180. int tcb_rcvwin; // Receive window we're offering.
  181. // Send sequence variables.
  182. SeqNum tcb_senduna; // Sequence number of first unack'd data.
  183. SeqNum tcb_sendnext; // Sequence number of next byte to send.
  184. SeqNum tcb_sendmax; // Max value of sendnext this epoch.
  185. uint tcb_sendwin; // Send window.
  186. uint tcb_unacked; // Total number of bytes of unacked data.
  187. uint tcb_maxwin; // Max send window seen.
  188. uint tcb_cwin; // Congestion window.
  189. uint tcb_ssthresh; // Slow start threshold.
  190. uint tcb_phxsum; // Precomputed pseudo-header xsum.
  191. struct TCPSendReq *tcb_cursend; // Current send in use.
  192. PNDIS_BUFFER tcb_sendbuf; // Current buffer chain being sent.
  193. uint tcb_sendofs; // Offset into start of chain.
  194. uint tcb_sendsize; // Number of bytes unsent in current send.
  195. Queue tcb_sendq; // Queue of send requests.
  196. // Less highly used receive sequence variables.
  197. SeqNum tcb_sendwl1; // Window update sequence number.
  198. SeqNum tcb_sendwl2; // Window update ack number.
  199. struct TCPRcvReq *tcb_currcv; // Current receive buffer.
  200. uint tcb_indicated; // Bytes of data indicated.
  201. uint tcb_flags; // Flags for this TCB.
  202. uint tcb_fastchk; // Fast receive path check field.
  203. uint (*tcb_rcvhndlr)(struct TCB *, uint, struct IPRcvBuf *, uint Size);
  204. SeqNum tcb_rttseq; // Sequence number being measured for RTT.
  205. ushort tcb_rexmit; // Rexmit value.
  206. // Retransmit timer information. These are stored as ticks, where by
  207. // default each tick is 100ms.
  208. ushort tcb_smrtt; // Smoothed rtt value.
  209. ushort tcb_delta; // Delta value.
  210. uchar tcb_slowcount; // Count of reasons why we're on the slow path.
  211. uchar tcb_closereason; // Reason we're closing.
  212. IP_STATUS tcb_error; // Last error we heard about from IP.
  213. uint tcb_rtt; // Current round trip time TS.
  214. uint tcb_defaultwin; // Default rcv. window.
  215. struct TCPRAHdr *tcb_raq; // Reassembly queue.
  216. struct TCPRcvReq *tcb_rcvhead; // Head of recv. buffer queue.
  217. struct TCPRcvReq *tcb_rcvtail; // Tail of recv. buffer queue.
  218. uint tcb_pendingcnt; // Bytes waiting to be received.
  219. struct IPRcvBuf *tcb_pendhead; // Head of pending recv. queue.
  220. struct IPRcvBuf *tcb_pendtail; // Tail of pending recv. queue.
  221. struct TCPConnReq *tcb_connreq; // Connection-type request for
  222. // this connection.
  223. void *tcb_conncontext; // Connection context for this
  224. // connection.
  225. uint tcb_bcountlow; // Low part of byte count.
  226. uint tcb_bcounthi; // High part of bytecount.
  227. uint tcb_totaltime; // Total number of ticks spent
  228. // sending.
  229. struct TCB *tcb_aonext; // Next pointer on AddrObj.
  230. struct TCPConn *tcb_conn; // Back pointer to conn for TCB.
  231. Queue tcb_delayq; // Queue linkage for delay queue.
  232. void *tcb_rcvind; // Receive indication handler.
  233. void *tcb_ricontext; // Receive indication context.
  234. // Miscellaneous info, for IP.
  235. IPOptInfo tcb_opt; // Option information.
  236. RouteCacheEntry *tcb_rce; // RCE for this connection.
  237. struct TCPConnReq *tcb_discwait; // Disc-Wait req., if there is one.
  238. struct TCPRcvReq *tcb_exprcv; // Head of expedited recv. buffer
  239. // queue.
  240. struct IPRcvBuf *tcb_urgpending; // Urgent data queue.
  241. uint tcb_urgcnt; // Byte count of data on urgent q.
  242. uint tcb_urgind; // Urgent bytes indicated.
  243. SeqNum tcb_urgstart; // Start of urgent data.
  244. SeqNum tcb_urgend; // End of urgent data.
  245. uint tcb_walkcount; // Count of number of people
  246. // 'walking' this TCB.
  247. Queue tcb_TWQueue; // Place to hang all the timed_waits
  248. ushort tcb_dup; // For Fast recovery algorithm
  249. ushort tcb_force : 1; // Force next send after fast send
  250. ushort tcb_tcpopts : 3;// rfc 1323 and 2018 options holder
  251. ushort tcb_moreflag : 3;
  252. struct SACKSendBlock *tcb_SackBlock;// Sacks which needs to be sent
  253. struct SackListEntry *tcb_SackRcvd; // Sacks which needs to be processed
  254. short tcb_sndwinscale;// send window scale
  255. short tcb_rcvwinscale;// receive window scale
  256. int tcb_tsrecent; // time stamp recent
  257. SeqNum tcb_lastack; // ack number in the last segment sent
  258. int tcb_tsupdatetime; // Time when tsrecent was updated
  259. void *tcb_chainedrcvind; //for chained receives
  260. void *tcb_chainedrcvcontext;
  261. #if GPC
  262. ULONG tcb_GPCCachedIF;
  263. ULONG tcb_GPCCachedLink;
  264. struct RouteTableEntry *tcb_GPCCachedRTE;
  265. #endif
  266. #if DBG
  267. uint tcb_LargeSend; // Counts the number of outstanding
  268. // large-send transmit-requests
  269. #endif
  270. uint tcb_partition;
  271. uint tcb_connid;
  272. // ACK behavior
  273. uchar tcb_delackticks;
  274. uchar tcb_numdelacks;
  275. uchar tcb_rcvdsegs;
  276. uchar tcb_bhprobecnt; // BH probe count.
  277. // Timer wheel parameters
  278. // The first two are one logical group called wheel state.
  279. // They indicate which slot in the timer wheel the TCB is in,
  280. // and it's linkage in the timer slot queue.
  281. Queue tcb_timerwheelq;
  282. ushort tcb_timerslot : 12;
  283. // These three variables are another logical group called timer
  284. // state. They indicate the state of timers active on the TCB,
  285. // tcb_timertime maintains the time at which the earliest timer
  286. // will fire, and tcb_timertype maintains the earliest timer's
  287. // type.
  288. // To see why this whole thing is important, see comments after
  289. // the TIMER_WHEEL structure definition.
  290. ushort tcb_timertype : 4;
  291. uint tcb_timertime;
  292. uint tcb_timer[NUM_TIMERS];
  293. #if ACK_DEBUG
  294. #define NUM_ACK_HISTORY_ITEMS 64
  295. uint tcb_history_index;
  296. struct {
  297. SeqNum sequence;
  298. uint unacked;
  299. } tcb_ack_history[NUM_ACK_HISTORY_ITEMS];
  300. #endif // ACK_DEBUG
  301. #if REFERENCE_DEBUG
  302. uint tcb_refhistory_index;
  303. TCP_REFERENCE_HISTORY tcb_refhistory[MAX_REFERENCE_HISTORY];
  304. #endif //REFERENCE_DEBUG
  305. } TCB;
  306. #define TIMER_WHEEL_SIZE 511
  307. #define DUMMY_SLOT TIMER_WHEEL_SIZE
  308. #define MAX_TIME_VALUE 0xffffffff
  309. // The Timer wheel structure definition has:
  310. // tw_timerslot: An array of queues, one for each timer slot.
  311. // tw_lock: A lock protecting the complete timer wheel.
  312. // (Contention is reduced by having as many timer
  313. // wheels as partitions in the system).
  314. // tw_starttick: Indicates the first time tick that has to
  315. // be looked at.
  316. // For e.g., if a timer routine looked at all
  317. // TCBs firing on or before tick 5 in a pass,
  318. // it would set tw_starttick to 6, and that is
  319. // the point it would start processing from on
  320. // the next pass.
  321. typedef struct CACHE_ALIGN _Timer_Wheel {
  322. Queue tw_timerslot[TIMER_WHEEL_SIZE];
  323. uint tw_starttick;
  324. CTELock tw_lock;
  325. } TIMER_WHEEL, *PTIMER_WHEEL;
  326. C_ASSERT(sizeof(TIMER_WHEEL) % MAX_CACHE_LINE_SIZE == 0);
  327. C_ASSERT(__alignof(TIMER_WHEEL) == MAX_CACHE_LINE_SIZE);
  328. // The first two functions operate on timer state (see comments in definition
  329. // of TCB for meaning of timer state). StopTCBTimerR and StartTCBTimerR
  330. // operate on the timer state (tcb_timertype, tcb_timertime, tcb_timer)
  331. // atomically. A call to either of these functions will always leave wheel
  332. // state consistent.
  333. extern void StopTCBTimerR(TCB *StopTCB, TCP_TIMER_TYPE TimerType);
  334. extern BOOLEAN StartTCBTimerR(TCB *StartTCB, TCP_TIMER_TYPE TimerType, uint TimerValue);
  335. // The following functions operate on the TCB's wheel state (tcb_timerwheelq
  336. // and tcb_timerslot). A call to any of these functions changes the value
  337. // of both the variables in such a way that they are consistent.
  338. extern void InsertIntoTimerWheel(TCB *InsertTCB, ushort Slot);
  339. extern void RemoveFromTimerWheel(TCB *RemoveTCB);
  340. extern void RemoveAndInsertIntoTimerWheel(TCB *RemInsTCB, ushort Slot);
  341. // The job of the inline functions below, is to sort-of act as glue, and they ensure
  342. // that the wheel state and timer state of a TCB are in tandem with each
  343. // other.
  344. // STOP_TCB_TIMER_R modifies the timer state but never
  345. // does anything to the wheel state. This means that the TCB will remain
  346. // where it was in the timer wheel, and the timer routine will eventually
  347. // bring the wheel state in conformance with the timer state.
  348. extern void STOP_TCB_TIMER_R(TCB *Tcb, TCP_TIMER_TYPE Type);
  349. // START_TCB_TIMER_R modifies the timer state and only modifies
  350. // wheel state if the timer that was started was earlier than all the
  351. // other timers on that TCB. This is in accordance with the lazy evaluation
  352. // strategy.
  353. extern void START_TCB_TIMER_R(TCB *Tcb, TCP_TIMER_TYPE Type, uint Value);
  354. #define COMPUTE_SLOT(Time) ((Time) % TIMER_WHEEL_SIZE)
  355. #define TCB_TIMER_FIRED_R(tcb, type, time) \
  356. ((tcb->tcb_timer[type]) && (tcb->tcb_timer[type] == time))
  357. #define TCB_TIMER_RUNNING_R(tcb, type) (tcb->tcb_timer[type] != 0)
  358. //* Definitions for TCP states.
  359. #define TCB_CLOSED 0 // Closed.
  360. #define TCB_LISTEN 1 // Listening.
  361. #define TCB_SYN_SENT 2 // SYN Sent.
  362. #define TCB_SYN_RCVD 3 // SYN received.
  363. #define TCB_ESTAB 4 // Established.
  364. #define TCB_FIN_WAIT1 5 // FIN-WAIT-1
  365. #define TCB_FIN_WAIT2 6 // FIN-WAIT-2
  366. #define TCB_CLOSE_WAIT 7 // Close waiting.
  367. #define TCB_CLOSING 8 // Closing state.
  368. #define TCB_LAST_ACK 9 // Last ack state.
  369. #define TCB_TIME_WAIT 10 // Time wait state.
  370. #define SYNC_STATE(s) ((s) > TCB_SYN_RCVD)
  371. #define SYNC_RCVD_STATE(s) ((s) > TCB_SYN_SENT)
  372. #define GRACEFUL_CLOSED_STATE(s) ((s) >= TCB_LAST_ACK)
  373. #define DATA_RCV_STATE(s) ((s) >= TCB_ESTAB && (s) <= TCB_FIN_WAIT2)
  374. #define DATA_SEND_STATE(s) ((s) == TCB_ESTAB || (s) == TCB_CLOSE_WAIT)
  375. //* Definitions for flags.
  376. #define WINDOW_SET 0x00000001 // Window explictly set.
  377. #define CLIENT_OPTIONS 0x00000002 // Have client IP options on conn.
  378. #define CONN_ACCEPTED 0x00000004 // Connection was accepted.
  379. #define ACTIVE_OPEN 0x00000008 // Connection came from an active
  380. // open.
  381. #define DISC_NOTIFIED 0x00000010 // Client has been notified of a
  382. // disconnect.
  383. #define IN_DELAY_Q 0x00000020 // We're in the delayed action Q.
  384. #define RCV_CMPLTING 0x00000040 // We're completeing rcvs.
  385. #define IN_RCV_IND 0x00000080 // We're calling a rcv. indicate
  386. // handler.
  387. #define NEED_RCV_CMPLT 0x00000100 // We need to have recvs. completed.
  388. #define NEED_ACK 0x00000200 // We need to send an ACK.
  389. #define NEED_OUTPUT 0x00000400 // We need to output.
  390. #define DELAYED_FLAGS (NEED_RCV_CMPLT | NEED_ACK | NEED_OUTPUT)
  391. #define ACK_DELAYED 0x00000800 // We've delayed sending an ACK.
  392. #define PMTU_BH_PROBE 0x00001000 // We're probing for a PMTU BH.
  393. #define BSD_URGENT 0x00002000 // We're using BSD urgent semantics.
  394. #define IN_DELIV_URG 0x00004000 // We're in the DeliverUrgent routine.
  395. #define URG_VALID 0x00008000 // We've seen urgent data, and
  396. // the urgent data fields are valid.
  397. #define FIN_NEEDED 0x00010000 // We need to send a FIN.
  398. #define NAGLING 0x00020000 // We are using Nagle's algorithm.
  399. #define IN_TCP_SEND 0x00040000 // We're in TCPSend.
  400. #define FLOW_CNTLD 0x00080000 // We've received a zero window
  401. // from our peer.
  402. #define DISC_PENDING 0x00100000 // A disconnect notification is
  403. // pending.
  404. #define TW_PENDING 0x00200000 // We're waiting to finish going
  405. // to TIME-WAIT.
  406. #define FORCE_OUTPUT 0x00400000 // Output is being forced.
  407. #define FORCE_OUT_SHIFT 22 // Shift to get FORCE_OUTPUT into
  408. // low bit.
  409. #define SEND_AFTER_RCV 0x00800000 // We need to send after we get out
  410. // of recv.
  411. #define GC_PENDING 0x01000000 // A graceful close is pending.
  412. #define KEEPALIVE 0x02000000 // Doing keepalives on this TCB.
  413. #define URG_INLINE 0x04000000 // Urgent data to be processed
  414. // inline.
  415. #define SCALE_CWIN 0x08000000 // Increment CWin proportionally to
  416. // amount of data acknowledged.
  417. #define FIN_OUTSTANDING 0x10000000 // We've sent a FIN 'recently', i.e.
  418. // since the last retransmit. When
  419. // this flag is set sendnext ==
  420. // sendmax.
  421. #define FIN_OUTS_SHIFT 28 // Shift to FIN_OUTSTANDING bit into
  422. // low bit.
  423. #define FIN_SENT 0x20000000 // We've sent a FIN that hasn't
  424. // been acknowledged. Once this
  425. // bit has been turned on in
  426. // FIN-WAIT-1 the sequence number
  427. // of the FIN will be sendmax-1.
  428. #define NEED_RST 0x40000000 // We need to send a RST when
  429. // closing.
  430. #define IN_TCB_TABLE 0x80000000 // TCB is in the TCB table.
  431. #define IN_TWTCB_TABLE 0x00000001
  432. #define IN_TWQUEUE 0x00000010
  433. #define SCAVENGER_SEEN 0x00000100
  434. #define TIMEOUT_SEEN 0x00001000
  435. #define SYN_ON_TWTCB 0x00010000
  436. #define IN_FINDTWTCB 0x00100000
  437. #define IN_SYNTCB_TABLE 0x00000001
  438. //* The defintion of the 'slow flags'. If any of these flags are set we'll
  439. // be forced off of the fast path.
  440. #define TCP_SLOW_FLAGS (URG_VALID | FLOW_CNTLD | GC_PENDING | \
  441. TW_PENDING | DISC_NOTIFIED | IN_DELIV_URG | \
  442. FIN_NEEDED | FIN_SENT | FIN_OUTSTANDING | \
  443. DISC_PENDING | PMTU_BH_PROBE)
  444. //* Close reasons.
  445. #define TCB_CLOSE_RST 0x80 // Received a RST segment.
  446. #define TCB_CLOSE_ABORTED 0x40 // Had a local abort.
  447. #define TCB_CLOSE_TIMEOUT 0x20 // Connection timed out.
  448. #define TCB_CLOSE_REFUSED 0x10 // Connect attempt was refused.
  449. #define TCB_CLOSE_UNREACH 0x08 // Remote destination unreachable.
  450. #define TCB_CLOSE_SUCCESS 0x01 // Successfull close.
  451. //* TCB Timer macros.
  452. #define START_TCB_TIMER(t, v) (t) = (v)
  453. #define STOP_TCB_TIMER(t) (t) = 0
  454. #define TCB_TIMER_RUNNING(t) ((t) != 0)
  455. // Macro to compute retransmit timeout.
  456. #define REXMIT_TO(t) ((((t)->tcb_smrtt >> 2) + (t)->tcb_delta) >> 1)
  457. //* Definitons for pending actions. We define a PENDING_ACTION macro
  458. // that can be used to decide whether or not we can proceed with an
  459. // activity. The only pending action we really care about is DELETE - others
  460. // are low priority and can be put off.
  461. #define PENDING_ACTION(t) ((t)->tcb_pending & DEL_PENDING)
  462. #define DEL_PENDING 0x01 // Delete is pending.
  463. #define OPT_PENDING 0x02 // Option set is pending.
  464. #define FREE_PENDING 0x04 // Can be freed
  465. //* Macro to see if a TCB is closing.
  466. #define CLOSING(t) ((t)->tcb_pending & DEL_PENDING)
  467. //* Structure of a TCP packet header.
  468. struct TCPHeader {
  469. ushort tcp_src; // Source port.
  470. ushort tcp_dest; // Destination port.
  471. SeqNum tcp_seq; // Sequence number.
  472. SeqNum tcp_ack; // Ack number.
  473. ushort tcp_flags; // Flags and data offset.
  474. ushort tcp_window; // Window offered.
  475. ushort tcp_xsum; // Checksum.
  476. ushort tcp_urgent; // Urgent pointer.
  477. };
  478. typedef struct TCPHeader TCPHeader;
  479. //* Definitions for header flags.
  480. #define TCP_FLAG_FIN 0x00000100
  481. #define TCP_FLAG_SYN 0x00000200
  482. #define TCP_FLAG_RST 0x00000400
  483. #define TCP_FLAG_PUSH 0x00000800
  484. #define TCP_FLAG_ACK 0x00001000
  485. #define TCP_FLAG_URG 0x00002000
  486. #define TCP_FLAGS_ALL (TCP_FLAG_FIN | TCP_FLAG_SYN | TCP_FLAG_RST | \
  487. TCP_FLAG_ACK | TCP_FLAG_URG)
  488. //* Flags in the tcb_fastchk field that are not in the TCP header proper.
  489. // Setting these flags forces us off the fast path.
  490. #define TCP_FLAG_SLOW 0x00000001 // Need to be on slow path.
  491. #define TCP_FLAG_IN_RCV 0x00000002 // In recv. path already.
  492. #define TCP_FLAG_FASTREC 0x00000004 // This is used to mark tcb
  493. #define TCP_FLAG_SEND_AND_DISC 0x00000008
  494. // former tcb_flag2 flags, now in tcb_fastchk
  495. #define TCP_FLAG_ACCEPT_PENDING 0x00000010
  496. #define TCP_FLAG_REQUEUE_FROM_SEND_AND_DISC 0x00000020
  497. #define TCP_FLAG_RST_WHILE_SYN 0x00000040 // Valid RST was received while
  498. // establishing outboud connct.
  499. #define TCP_OFFSET_MASK 0xf0
  500. #define TCP_HDR_SIZE(t) (uint)(((*(uchar *)&(t)->tcp_flags) & TCP_OFFSET_MASK) >> 2)
  501. #define MAKE_TCP_FLAGS(o, f) ((f) | ((o) << 4))
  502. #define TCP_OPT_EOL 0
  503. #define TCP_OPT_NOP 1
  504. #define TCP_OPT_MSS 2
  505. #define MSS_OPT_SIZE 4
  506. #define TCP_SACK_PERMITTED_OPT 4
  507. #define SACK_PERMITTED_OPT_SIZE 2 // SACK "permitted" option size, in SYN segments
  508. #define TCP_FLAG_SACK 0x00000004
  509. #define TCP_OPT_SACK 5 // Sack option
  510. #define ALIGNED_TS_OPT_SIZE 12
  511. #define TCP_OPT_WS 3 // Window scale option
  512. #define TCP_OPT_TS 8 // Time stamp option
  513. #define WS_OPT_SIZE 3
  514. #define TS_OPT_SIZE 10
  515. #define TCP_MAXWIN 65535 // maximum unscaled window size
  516. #define TCP_MAX_WINSHIFT 14 // Maximum shift allowed
  517. #define TCP_FLAG_WS 0x00000001 // Flags in tcb_options for ws and ts
  518. #define TCP_FLAG_TS 0x00000002
  519. #define PAWS_IDLE 24*24*60*60*100 // Paws idle time - 24 days
  520. //* Convenient byte swapped structure for receives.
  521. struct TCPRcvInfo {
  522. SeqNum tri_seq; // Sequence number.
  523. SeqNum tri_ack; // Ack number.
  524. uint tri_window; // Window.
  525. uint tri_urgent; // Urgent pointer.
  526. uint tri_flags; // Flags.
  527. };
  528. typedef struct TCPRcvInfo TCPRcvInfo;
  529. //* General structure, at the start of all command specific request structures.
  530. #define tr_signature 0x20205254 // 'TR '
  531. struct TCPReq {
  532. #if DBG
  533. ulong tr_sig;
  534. #endif
  535. struct Queue tr_q; // Q linkage.
  536. CTEReqCmpltRtn tr_rtn; // Completion routine.
  537. PVOID tr_context; // User context.
  538. int tr_status; // Final complete status.
  539. };
  540. typedef struct TCPReq TCPReq;
  541. // structures to support SACK
  542. struct SackSeg {
  543. SeqNum begin;
  544. SeqNum end;
  545. };
  546. typedef struct SackSeg SackSeg;
  547. // Maximum 4 sack entries can be sent
  548. // so, size sack send block acordingly
  549. struct SACKSendBlock {
  550. uchar Mask[4];
  551. SackSeg Block[4];
  552. };
  553. typedef struct SACKSendBlock SACKSendBlock;
  554. // list of received sack entries
  555. struct SackListEntry {
  556. struct SackListEntry *next;
  557. SeqNum begin;
  558. SeqNum end;
  559. };
  560. typedef struct SackListEntry SackListEntry;
  561. struct ReservedPortListEntry {
  562. struct ReservedPortListEntry *next;
  563. ushort UpperRange;
  564. ushort LowerRange;
  565. };
  566. typedef struct ReservedPortListEntry ReservedPortListEntry;
  567. #ifdef POOL_TAGGING
  568. #ifdef ExAllocatePool
  569. #undef ExAllocatePool
  570. #endif
  571. #ifdef CTEAllocMemN
  572. #undef CTEAllocMemN
  573. #endif
  574. #define ExAllocatePool(type, size) ExAllocatePoolWithTag(type, size, 'tPCT')
  575. #ifndef CTEAllocMem
  576. #error "CTEAllocMem is not already defined - will override tagging"
  577. #else
  578. #undef CTEAllocMem
  579. #endif
  580. #ifdef CTEAllocMemBoot
  581. #undef CTEAllocMemBoot
  582. #endif
  583. #if MILLEN
  584. #define CTEAllocMem(size) ExAllocatePoolWithTag(NonPagedPool, size, 'tPCT')
  585. #define CTEAllocMemN(size,tag) ExAllocatePoolWithTag(NonPagedPool, size, tag)
  586. #define CTEAllocMemLow(size,tag) ExAllocatePoolWithTag(NonPagedPool, size, tag)
  587. #define CTEAllocMemBoot(size) ExAllocatePoolWithTag(NonPagedPool, size, 'tPCT')
  588. #else // MILLEN
  589. #define CTEAllocMem(size) ExAllocatePoolWithTagPriority(NonPagedPool, size, 'tPCT', NormalPoolPriority)
  590. #define CTEAllocMemN(size,tag) ExAllocatePoolWithTagPriority(NonPagedPool, size, tag,NormalPoolPriority)
  591. #define CTEAllocMemLow(size,tag) ExAllocatePoolWithTagPriority(NonPagedPool, size, tag,LowPoolPriority)
  592. #define CTEAllocMemBoot(size) ExAllocatePoolWithTag(NonPagedPool, size, 'tPCT')
  593. #endif // !MILLEN
  594. #endif // POOL_TAGGING
  595. #if TRACE_EVENT
  596. #define _WMIKM_
  597. #include "evntrace.h"
  598. #include "wmikm.h"
  599. #include "wmistr.h"
  600. #define EVENT_TRACE_GROUP_TCPIP 0x0600
  601. #define EVENT_TRACE_GROUP_UDPIP 0x0800
  602. typedef VOID (*PTDI_DATA_REQUEST_NOTIFY_ROUTINE)(
  603. IN ULONG EventType,
  604. IN PVOID DataBlock,
  605. IN ULONG Size,
  606. IN PETHREAD Thread);
  607. extern PTDI_DATA_REQUEST_NOTIFY_ROUTINE TCPCPHandlerRoutine;
  608. typedef struct _CPTRACE_DATABLOCK {
  609. IPAddr saddr;
  610. IPAddr daddr;
  611. ushort sport;
  612. ushort dport;
  613. uint size;
  614. HANDLE cpcontext;
  615. } CPTRACE_DATABLOCK, *PCPTRACE_BLOCK;
  616. #endif
  617. //
  618. // TCP endpoint context structure allocated for each open of TCP/UDP.
  619. // A pointer to this structure is stored in FileObject->FsContext.
  620. //
  621. typedef struct _TCP_CONTEXT {
  622. union {
  623. HANDLE AddressHandle;
  624. CONNECTION_CONTEXT ConnectionContext;
  625. HANDLE ControlChannel;
  626. } Handle;
  627. ULONG ReferenceCount;
  628. BOOLEAN CancelIrps;
  629. BOOLEAN Cleanup;
  630. #if DBG
  631. LIST_ENTRY PendingIrpList;
  632. LIST_ENTRY CancelledIrpList;
  633. #endif
  634. KEVENT CleanupEvent;
  635. UINT_PTR Conn;
  636. PIRP Irp;
  637. DEFINE_LOCK_STRUCTURE(EndpointLock)
  638. } TCP_CONTEXT, *PTCP_CONTEXT;
  639. #define MAJOR_TDI_VERSION 2
  640. #define MINOR_TDI_VERSION 0
  641. extern HANDLE DgHeaderPool;
  642. //* Definition of an AO request structure. There structures are used only for
  643. // queuing delete and option get/set requests.
  644. #define aor_signature 0x20524F41
  645. typedef struct AORequest {
  646. #if DBG
  647. ulong aor_sig;
  648. #endif
  649. struct AORequest *aor_next; // Next pointer in chain.
  650. uint aor_id; // ID for the request.
  651. uint aor_length; // Length of buffer.
  652. void *aor_buffer; // Buffer for this request.
  653. CTEReqCmpltRtn aor_rtn; // Request complete routine for
  654. // this request.
  655. PVOID aor_context; // Request context.
  656. uint aor_type; // Request type.
  657. } AORequest;
  658. //
  659. // Values of aor_type
  660. //
  661. #define AOR_TYPE_GET_OPTIONS 1
  662. #define AOR_TYPE_SET_OPTIONS 2
  663. #define AOR_TYPE_REVALIDATE_MCAST 3
  664. #define AOR_TYPE_DELETE 4
  665. extern AORequest *AORequestBlockPtr;
  666. #include "tcpdeb.h"
  667. #if REFERENCE_DEBUG
  668. uint
  669. TcpReferenceTCB (
  670. IN TCB *RefTCB,
  671. IN uchar *File,
  672. IN uint Line
  673. );
  674. uint
  675. TcpDereferenceTCB (
  676. IN TCB *DerefTCB,
  677. IN uchar *File,
  678. IN uint Line
  679. );
  680. #define REFERENCE_TCB(_a) TcpReferenceTCB((_a), __FILE__, __LINE__)
  681. #define DEREFERENCE_TCB(_a) TcpDereferenceTCB((_a), __FILE__, __LINE__)
  682. #else // REFERENCE_DEBUG
  683. #define REFERENCE_TCB(_a) ++(_a)->tcb_refcnt
  684. #define DEREFERENCE_TCB(_a) --(_a)->tcb_refcnt
  685. #endif // REFERENCE_DEBUG
  686. #endif // _TCP_INCLUDED_