Leaked source code of windows server 2003
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.

302 lines
14 KiB

  1. /********************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1990-2000 **/
  4. /********************************************************************/
  5. /* :ts=4 */
  6. //** ADDR.H - TDI address object definitions.
  7. //
  8. // This file contains the definitions of TDI address objects and related
  9. // constants and structures.
  10. #include "tcp.h"
  11. #include <gpcifc.h>
  12. #define ao_signature 0x20204F41 // 'AO '
  13. #define WILDCARD_PORT 0 // 0 means assign a port.
  14. #define MIN_USER_PORT 1025 // Minimum value for a wildcard port
  15. #define NUM_USER_PORTS (uint)(MaxUserPort - MIN_USER_PORT + 1)
  16. #define NETBT_SESSION_PORT 139
  17. typedef struct AddrObj AddrObj;
  18. #define IS_PROMIS_AO(A) ((A)->ao_rcvall || (A)->ao_rcvall_mcast || (A)->ao_absorb_rtralert)
  19. //* Datagram transport-specific send function.
  20. typedef void (*DGSendProc)(AddrObj *SrcAO, void *SendReq);
  21. //* Definition of the structure of an address object. Each object represents
  22. // a local address, and the IP portion may be a wildcard.
  23. typedef struct AddrObj {
  24. #if DBG
  25. ulong ao_sig;
  26. #endif
  27. struct AddrObj *ao_next; // Pointer to next address object in chain.
  28. DEFINE_LOCK_STRUCTURE(ao_lock) // Lock for this object.
  29. struct AORequest *ao_request; // Pointer to pending request.
  30. Queue ao_sendq; // Queue of sends waiting for transmission.
  31. Queue ao_pendq; // Linkage for pending queue.
  32. Queue ao_rcvq; // Receive queue.
  33. ulong ao_flags; // Flags for this object.
  34. uint ao_listencnt; // Number of listening connections.
  35. IPAddr ao_addr; // IP address for this address object.
  36. ushort ao_port; // Local port for this address object.
  37. uchar ao_prot; // Protocol for this AO.
  38. // [uchar space]
  39. ushort ao_usecnt; // Count of 'uses' on AO.
  40. ushort ao_maxdgsize; // maximum user datagram size.
  41. uchar ao_mcast_loop; // MCast loop allowed/denied flag.
  42. uchar ao_rcvall; // rcv all packets or not (3 bits)
  43. uchar ao_rcvall_mcast;// rcv all mcast packets or not (3 bits)
  44. uchar ao_absorb_rtralert;
  45. IPOptInfo ao_opt; // Opt info for this address object.
  46. IPOptInfo ao_mcastopt; // MCast opt info.
  47. Queue ao_activeq; // Queue of active connections.
  48. Queue ao_idleq; // Queue of inactive (no TCB) connections.
  49. Queue ao_listenq; // Queue of listening connections.
  50. CTEEvent ao_event; // Event to use for this AO.
  51. PConnectEvent ao_connect; // Connect event handle.
  52. PVOID ao_conncontext; // Receive DG context.
  53. PDisconnectEvent ao_disconnect; // Disconnect event routine.
  54. PVOID ao_disconncontext;// Disconnect event context.
  55. PErrorEvent ao_error; // Error event routine.
  56. PVOID ao_errcontext; // Error event context.
  57. PRcvEvent ao_rcv; // Receive event handler
  58. PVOID ao_rcvcontext; // Receive context.
  59. PRcvDGEvent ao_rcvdg; // Receive DG event handler
  60. PVOID ao_rcvdgcontext;// Receive DG context.
  61. PRcvExpEvent ao_exprcv; // Expedited receive event handler
  62. PVOID ao_exprcvcontext;// Expedited receive context.
  63. struct AOMCastAddr *ao_mcastlist; // List of active multicast
  64. // addresses.
  65. DGSendProc ao_dgsend; // Datagram transport send function.
  66. PErrorEx ao_errorex; // Error event routine.
  67. PVOID ao_errorexcontext; // Error event context.
  68. PChainedRcvEvent ao_chainedrcv; // Chained Receive event handler
  69. PVOID ao_chainedrcvcontext; // Chained Receive context.
  70. TDI_CONNECTION_INFORMATION ao_udpconn;
  71. PVOID ao_RemoteAddress;
  72. PVOID ao_Options;
  73. RouteCacheEntry *ao_rce;
  74. CLASSIFICATION_HANDLE ao_GPCHandle;
  75. ULONG ao_GPCCachedIF;
  76. ULONG ao_GPCCachedLink;
  77. struct RouteTableEntry *ao_GPCCachedRTE;
  78. IPAddr ao_rcesrc;
  79. IPAddr ao_destaddr;
  80. ushort ao_destport;
  81. ulong ao_promis_ifindex;
  82. ulong ao_bindindex; // interface socket is bound to
  83. uint* ao_iflist;
  84. ulong ao_owningpid;
  85. uint ao_window;
  86. PSECURITY_DESCRIPTOR ao_sd;
  87. } AddrObj;
  88. #define AO_DELETE_FLAG 0x00000001 // Delete pending.
  89. #define AO_OPTIONS_FLAG 0x00000002 // Options pending.
  90. #define AO_SEND_FLAG 0x00000004 // Send is pending.
  91. #define AO_XSUM_FLAG 0x00000008 // Xsums are used on this AO.
  92. // either the pending or delayed queue.
  93. #define AO_QUEUED_FLAG 0x00000010 // AddrObj is on the pending queue.
  94. #define AO_OOR_FLAG 0x00000020 // AddrObj is out of resources, and on
  95. #define AO_BUSY_FLAG 0x00000040 // AddrObj is busy (i.e., has it exclusive).
  96. #define AO_VALID_FLAG 0x00000080 // AddrObj is valid.
  97. #define AO_DHCP_FLAG 0x00000100 // AO is bound to real 0 address.
  98. #define AO_RAW_FLAG 0x00000200 // AO is for a raw endpoint.
  99. #define AO_BROADCAST_FLAG 0x00000400 // Broadcast enable flag
  100. #define AO_CONNUDP_FLAG 0x00000800 // Connected udp
  101. #define AO_SHARE_FLAG 0x00001000 // AddrObj can be shared
  102. #define AO_PKTINFO_FLAG 0x00002000 // Packet info structure passed up in
  103. // control info.
  104. #define AO_DEFERRED_FLAG 0x00004000 // Deferred processing has been
  105. // scheduled
  106. #define AO_SCALE_CWIN_FLAG 0x00008000 // CWin-scaling has been enabled.
  107. #define AO_WINSET_FLAG 0x00010000 // TCP window has been set.
  108. #define AO_CONNECT_FLAG 0x00020000 // Pending Connect Request.
  109. #define AO_DISCONNECT_FLAG 0x00040000 // Pending Disconnect Request.
  110. #define AO_VALID(A) ((A)->ao_flags & AO_VALID_FLAG)
  111. #define SET_AO_INVALID(A) (A)->ao_flags &= ~AO_VALID_FLAG
  112. #define AO_BUSY(A) ((A)->ao_flags & AO_BUSY_FLAG)
  113. #define SET_AO_BUSY(A) (A)->ao_flags |= AO_BUSY_FLAG
  114. #define CLEAR_AO_BUSY(A) (A)->ao_flags &= ~AO_BUSY_FLAG
  115. #define AO_OOR(A) ((A)->ao_flags & AO_OOR_FLAG)
  116. #define SET_AO_OOR(A) (A)->ao_flags |= AO_OOR_FLAG
  117. #define CLEAR_AO_OOR(A) (A)->ao_flags &= ~AO_OOR_FLAG
  118. #define AO_QUEUED(A) ((A)->ao_flags & AO_QUEUED_FLAG)
  119. #define SET_AO_QUEUED(A) (A)->ao_flags |= AO_QUEUED_FLAG
  120. #define CLEAR_AO_QUEUED(A) (A)->ao_flags &= ~AO_QUEUED_FLAG
  121. #define AO_XSUM(A) ((A)->ao_flags & AO_XSUM_FLAG)
  122. #define SET_AO_XSUM(A) (A)->ao_flags |= AO_XSUM_FLAG
  123. #define CLEAR_AO_XSUM(A) (A)->ao_flags &= ~AO_XSUM_FLAG
  124. #define AO_REQUEST(A, f) ((A)->ao_flags & f##_FLAG)
  125. #define SET_AO_REQUEST(A, f) (A)->ao_flags |= f##_FLAG
  126. #define CLEAR_AO_REQUEST(A, f) (A)->ao_flags &= ~f##_FLAG
  127. #define AO_PENDING(A) \
  128. ((A)->ao_flags & (AO_DELETE_FLAG | AO_OPTIONS_FLAG \
  129. | AO_SEND_FLAG | AO_CONNECT_FLAG | AO_DISCONNECT_FLAG))
  130. #define AO_BROADCAST(A) ((A)->ao_flags & AO_BROADCAST_FLAG)
  131. #define SET_AO_BROADCAST(A) (A)->ao_flags |= AO_BROADCAST_FLAG
  132. #define CLEAR_AO_BROADCAST(A) (A)->ao_flags &= ~AO_BROADCAST_FLAG
  133. #define AO_CONNUDP(A) ((A)->ao_flags & AO_CONNUDP_FLAG)
  134. #define SET_AO_CONNUDP(A) (A)->ao_flags |= AO_CONNUDP_FLAG
  135. #define CLEAR_AO_CONNUDP(A) (A)->ao_flags &= ~AO_CONNUDP_FLAG
  136. #define AO_SHARE(A) ((A)->ao_flags & AO_SHARE_FLAG)
  137. #define SET_AO_SHARE(A) (A)->ao_flags |= AO_SHARE_FLAG
  138. #define CLEAR_AO_SHARE(A) (A)->ao_flags &= ~AO_SHARE_FLAG
  139. #define AO_PKTINFO(A) ((A)->ao_flags & AO_PKTINFO_FLAG)
  140. #define SET_AO_PKTINFO(A) (A)->ao_flags |= AO_PKTINFO_FLAG
  141. #define CLEAR_AO_PKTINFO(A) (A)->ao_flags &= ~AO_PKTINFO_FLAG
  142. #define AO_DEFERRED(A) ((A)->ao_flags & AO_DEFERRED_FLAG)
  143. #define SET_AO_DEFERRED(A) (A)->ao_flags |= AO_DEFERRED_FLAG
  144. #define CLEAR_AO_DEFERRED(A) (A)->ao_flags &= ~AO_DEFERRED_FLAG
  145. #define AO_SCALE_CWIN(A) ((A)->ao_flags & AO_SCALE_CWIN_FLAG)
  146. #define SET_AO_SCALE_CWIN(A) (A)->ao_flags |= AO_SCALE_CWIN_FLAG
  147. #define CLEAR_AO_SCALE_CWIN(A) (A)->ao_flags &= ~AO_SCALE_CWIN_FLAG
  148. #define AO_WINSET(A) ((A)->ao_flags & AO_WINSET_FLAG)
  149. #define SET_AO_WINSET(A) (A)->ao_flags |= AO_WINSET_FLAG
  150. #define CLEAR_AO_WINSET(A) (A)->ao_flags &= ~AO_WINSET_FLAG
  151. //* Definition of an address object search context. This is a data structure used
  152. // when the address object table is to be read sequentially.
  153. struct AOSearchContext {
  154. AddrObj *asc_previous; // Previous AO found.
  155. IPAddr asc_addr; // IPAddress to be found.
  156. ushort asc_port; // Port to be found.
  157. uchar asc_prot; // Protocol
  158. uchar asc_pad; // Pad to dword boundary.
  159. }; /* AOSearchContext */
  160. //* Definition of an address object search context. This is a data structure used
  161. // when the address object table is to be read sequentially. Used for RAW only
  162. struct AOSearchContextEx {
  163. AddrObj *asc_previous; // Previous AO found.
  164. IPAddr asc_addr; // IPAddress to be found.
  165. ushort asc_port; // Port to be found.
  166. uint asc_ifindex; // ifindex the packet came on
  167. uchar asc_prot; // Protocol
  168. uchar asc_pad; // Pad to dword boundary.
  169. uint asc_previousindex; // Previous AO's index
  170. }; /* AOSearchContextEx */
  171. typedef struct AOSearchContext AOSearchContext;
  172. typedef struct AOSearchContextEx AOSearchContextEx;
  173. //* Definition of an AO request structure. There structures are used only for
  174. // queuing delete and option set requests.
  175. typedef struct AOMCastAddr {
  176. struct AOMCastAddr *ama_next; // Next in list.
  177. IPAddr ama_addr; // The address.
  178. IPAddr ama_if; // The "interface" requested.
  179. IPAddr ama_if_used; // The actual ifaddr used.
  180. BOOLEAN ama_flags; // Flags.
  181. BOOLEAN ama_inclusion; // Inclusion or exclusion mode?
  182. ulong ama_srccount; // Number of entries in srclist
  183. struct AOMCastSrcAddr *ama_srclist;// List of active sources.
  184. } AOMCastAddr;
  185. #define AMA_VALID_FLAG 0x01
  186. #define AMA_VALID(A) ((A)->ama_flags & AMA_VALID_FLAG)
  187. #define SET_AMA_INVALID(A) (A)->ama_flags &= ~AMA_VALID_FLAG
  188. typedef struct AOMCastSrcAddr {
  189. struct AOMCastSrcAddr *asa_next; // Next in list.
  190. IPAddr asa_addr; // The address.
  191. } AOMCastSrcAddr;
  192. //* External declarations for exported functions.
  193. extern CACHE_LINE_KSPIN_LOCK AddrObjTableLock;
  194. extern uint AddrObjTableSize;
  195. extern AddrObj **AddrObjTable;
  196. extern AddrObj *GetAddrObj(IPAddr LocalAddr, ushort LocalPort, uchar Prot,
  197. PVOID PreviousAO, uint Flags);
  198. #define GAO_FLAG_CHECK_IF_LIST 0x00000001
  199. #define GAO_FLAG_INCLUDE_ALL 0x00000002
  200. extern AddrObj *GetNextAddrObj(AOSearchContext *SearchContext);
  201. extern AddrObj *GetNextBestAddrObj(IPAddr LocalAddr, ushort LocalPort, uchar Prot,
  202. AddrObj *PreviousAO, uint Flags);
  203. extern AddrObj *GetFirstAddrObj(IPAddr LocalAddr, ushort LocalPort, uchar Prot,
  204. AOSearchContext *SearchContext);
  205. extern AddrObj *GetAddrObjEx(IPAddr LocalAddr, ushort LocalPort, uchar Protocol, uint IfIndex,
  206. AddrObj *PreviousAO, uint PreviousIndex, uint *CurrentIndex);
  207. extern AddrObj *GetNextAddrObjEx(AOSearchContextEx *SearchContext);
  208. extern AddrObj *GetFirstAddrObjEx(IPAddr LocalAddr, ushort LocalPort, uchar Prot, uint IfIndex,
  209. AOSearchContextEx *SearchContext);
  210. extern TDI_STATUS TdiOpenAddress(PTDI_REQUEST Request,
  211. TRANSPORT_ADDRESS UNALIGNED *AddrList, uint Protocol,
  212. void *Reuse, PSECURITY_DESCRIPTOR AddrSD, BOOLEAN IsRawOpen);
  213. extern TDI_STATUS TdiCloseAddress(PTDI_REQUEST Request);
  214. extern TDI_STATUS SetAddrOptions(PTDI_REQUEST Request, uint ID, uint OptLength,
  215. void *Options);
  216. extern TDI_STATUS GetAddrOptionsEx(PTDI_REQUEST Request, uint ID,
  217. uint OptLength, PNDIS_BUFFER Options,
  218. uint *InfoSize, void *Context);
  219. extern TDI_STATUS TdiSetEvent(PVOID Handle, int Type, PVOID Handler,
  220. PVOID Context);
  221. extern uchar GetAddress(TRANSPORT_ADDRESS UNALIGNED *AddrList,
  222. IPAddr *Addr, ushort *Port);
  223. extern int InitAddr(void);
  224. extern void ProcessAORequests(AddrObj *RequestAO);
  225. extern void DelayDerefAO(AddrObj *RequestAO);
  226. extern void DerefAO(AddrObj *RequestAO);
  227. extern void FreeAORequest(AORequest *FreedRequest);
  228. extern uint ValidateAOContext(void *Context, uint *Valid);
  229. extern uint ReadNextAO(void *Context, void *OutBuf);
  230. extern void InvalidateAddrs(IPAddr Addr);
  231. extern void RevalidateAddrs(IPAddr Addr);
  232. extern uint MCastAddrOnAO(AddrObj *AO, IPAddr Dest, IPAddr Src, uint IfIndex, IPAddr LocalAddr);
  233. #define GetBestAddrObj(addr, port, prot, flags) \
  234. GetAddrObj(addr, port, prot, NULL, flags)
  235. #define REF_AO(a) (a)->ao_usecnt++
  236. #define DELAY_DEREF_AO(a) DelayDerefAO((a))
  237. #define DEREF_AO(a) DerefAO((a))
  238. #define LOCKED_DELAY_DEREF_AO(a) \
  239. (a)->ao_usecnt--; \
  240. if (!(a)->ao_usecnt && !AO_BUSY((a)) && AO_PENDING((a))) { \
  241. SET_AO_BUSY((a)); \
  242. CTEScheduleEvent(&(a)->ao_event, (a)); \
  243. }