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.

280 lines
13 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 ConnLimitReached;// set when there are no connections left
  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. IPAddr ao_mcastaddr; // Source address for MCast from this addr object.
  48. Queue ao_activeq; // Queue of active connections.
  49. Queue ao_idleq; // Queue of inactive (no TCB) connections.
  50. Queue ao_listenq; // Queue of listening connections.
  51. CTEEvent ao_event; // Event to use for this AO.
  52. PConnectEvent ao_connect; // Connect event handle.
  53. PVOID ao_conncontext; // Receive DG context.
  54. PDisconnectEvent ao_disconnect; // Disconnect event routine.
  55. PVOID ao_disconncontext;// Disconnect event context.
  56. PErrorEvent ao_error; // Error event routine.
  57. PVOID ao_errcontext; // Error event context.
  58. PRcvEvent ao_rcv; // Receive event handler
  59. PVOID ao_rcvcontext; // Receive context.
  60. PRcvDGEvent ao_rcvdg; // Receive DG event handler
  61. PVOID ao_rcvdgcontext;// Receive DG context.
  62. PRcvExpEvent ao_exprcv; // Expedited receive event handler
  63. PVOID ao_exprcvcontext;// Expedited receive context.
  64. struct AOMCastAddr *ao_mcastlist; // List of active multicast
  65. // addresses.
  66. DGSendProc ao_dgsend; // Datagram transport send function.
  67. PErrorEx ao_errorex; // Error event routine.
  68. PVOID ao_errorexcontext; // Error event context.
  69. PChainedRcvEvent ao_chainedrcv; // Chained Receive event handler
  70. PVOID ao_chainedrcvcontext; // Chained Receive context.
  71. TDI_CONNECTION_INFORMATION ao_udpconn;
  72. PVOID ao_RemoteAddress;
  73. PVOID ao_Options;
  74. RouteCacheEntry *ao_rce;
  75. CLASSIFICATION_HANDLE ao_GPCHandle;
  76. ULONG ao_GPCCachedIF;
  77. ULONG ao_GPCCachedLink;
  78. struct RouteTableEntry *ao_GPCCachedRTE;
  79. IPAddr ao_rcesrc;
  80. IPAddr ao_destaddr;
  81. ushort ao_destport;
  82. ulong ao_promis_ifindex;
  83. ulong ao_bindindex; // interface socket is bound to
  84. uint* ao_iflist;
  85. ulong ao_owningpid;
  86. } AddrObj;
  87. #define AO_RAW_FLAG 0x0200 // AO is for a raw endpoint.
  88. #define AO_DHCP_FLAG 0x0100 // AO is bound to real 0 address.
  89. #define AO_VALID_FLAG 0x0080 // AddrObj is valid.
  90. #define AO_BUSY_FLAG 0x0040 // AddrObj is busy (i.e., has it exclusive).
  91. #define AO_OOR_FLAG 0x0020 // AddrObj is out of resources, and on
  92. // either the pending or delayed queue.
  93. #define AO_QUEUED_FLAG 0x0010 // AddrObj is on the pending queue.
  94. #define AO_XSUM_FLAG 0x0008 // Xsums are used on this AO.
  95. #define AO_SEND_FLAG 0x0004 // Send is pending.
  96. #define AO_OPTIONS_FLAG 0x0002 // Options pending.
  97. #define AO_DELETE_FLAG 0x0001 // Delete pending.
  98. #define AO_BROADCAST_FLAG 0x400 // Broadcast enable flag
  99. #define AO_CONNUDP_FLAG 0x800 // Connected udp
  100. #define AO_SHARE_FLAG 0x1000 // AddrObj can be shared
  101. #define AO_PKTINFO_FLAG 0x2000 // Packet info structure passed up in
  102. // control info.
  103. #define AO_DEFERRED_FLAG 0x4000 // Deferred processing has been
  104. // scheduled
  105. #define AO_VALID(A) ((A)->ao_flags & AO_VALID_FLAG)
  106. #define SET_AO_INVALID(A) (A)->ao_flags &= ~AO_VALID_FLAG
  107. #define AO_BUSY(A) ((A)->ao_flags & AO_BUSY_FLAG)
  108. #define SET_AO_BUSY(A) (A)->ao_flags |= AO_BUSY_FLAG
  109. #define CLEAR_AO_BUSY(A) (A)->ao_flags &= ~AO_BUSY_FLAG
  110. #define AO_OOR(A) ((A)->ao_flags & AO_OOR_FLAG)
  111. #define SET_AO_OOR(A) (A)->ao_flags |= AO_OOR_FLAG
  112. #define CLEAR_AO_OOR(A) (A)->ao_flags &= ~AO_OOR_FLAG
  113. #define AO_QUEUED(A) ((A)->ao_flags & AO_QUEUED_FLAG)
  114. #define SET_AO_QUEUED(A) (A)->ao_flags |= AO_QUEUED_FLAG
  115. #define CLEAR_AO_QUEUED(A) (A)->ao_flags &= ~AO_QUEUED_FLAG
  116. #define AO_XSUM(A) ((A)->ao_flags & AO_XSUM_FLAG)
  117. #define SET_AO_XSUM(A) (A)->ao_flags |= AO_XSUM_FLAG
  118. #define CLEAR_AO_XSUM(A) (A)->ao_flags &= ~AO_XSUM_FLAG
  119. #define AO_REQUEST(A, f) ((A)->ao_flags & f##_FLAG)
  120. #define SET_AO_REQUEST(A, f) (A)->ao_flags |= f##_FLAG
  121. #define CLEAR_AO_REQUEST(A, f) (A)->ao_flags &= ~f##_FLAG
  122. #define AO_PENDING(A) ((A)->ao_flags & (AO_DELETE_FLAG | AO_OPTIONS_FLAG | AO_SEND_FLAG))
  123. #define AO_BROADCAST(A) ((A)->ao_flags & AO_BROADCAST_FLAG)
  124. #define SET_AO_BROADCAST(A) (A)->ao_flags |= AO_BROADCAST_FLAG
  125. #define CLEAR_AO_BROADCAST(A) (A)->ao_flags &= ~AO_BROADCAST_FLAG
  126. #define AO_CONNUDP(A) ((A)->ao_flags & AO_CONNUDP_FLAG)
  127. #define SET_AO_CONNUDP(A) (A)->ao_flags |= AO_CONNUDP_FLAG
  128. #define CLEAR_AO_CONNUDP(A) (A)->ao_flags &= ~AO_CONNUDP_FLAG
  129. #define AO_SHARE(A) ((A)->ao_flags & AO_SHARE_FLAG)
  130. #define SET_AO_SHARE(A) (A)->ao_flags |= AO_SHARE_FLAG
  131. #define CLEAR_AO_SHARE(A) (A)->ao_flags &= ~AO_SHARE_FLAG
  132. #define AO_PKTINFO(A) ((A)->ao_flags & AO_PKTINFO_FLAG)
  133. #define SET_AO_PKTINFO(A) (A)->ao_flags |= AO_PKTINFO_FLAG
  134. #define CLEAR_AO_PKTINFO(A) (A)->ao_flags &= ~AO_PKTINFO_FLAG
  135. #define AO_DEFERRED(A) ((A)->ao_flags & AO_DEFERRED_FLAG)
  136. #define SET_AO_DEFERRED(A) (A)->ao_flags |= AO_DEFERRED_FLAG
  137. #define CLEAR_AO_DEFERRED(A) (A)->ao_flags &= ~AO_DEFERRED_FLAG
  138. //* Definition of an address object search context. This is a data structure used
  139. // when the address object table is to be read sequentially.
  140. struct AOSearchContext {
  141. AddrObj *asc_previous; // Previous AO found.
  142. IPAddr asc_addr; // IPAddress to be found.
  143. ushort asc_port; // Port to be found.
  144. uchar asc_prot; // Protocol
  145. uchar asc_pad; // Pad to dword boundary.
  146. }; /* AOSearchContext */
  147. //* Definition of an address object search context. This is a data structure used
  148. // when the address object table is to be read sequentially. Used for RAW only
  149. struct AOSearchContextEx {
  150. AddrObj *asc_previous; // Previous AO found.
  151. IPAddr asc_addr; // IPAddress to be found.
  152. ushort asc_port; // Port to be found.
  153. uint asc_ifindex; // ifindex the packet came on
  154. uchar asc_prot; // Protocol
  155. uchar asc_pad; // Pad to dword boundary.
  156. uint asc_previousindex; // Previous AO's index
  157. }; /* AOSearchContextEx */
  158. typedef struct AOSearchContext AOSearchContext;
  159. typedef struct AOSearchContextEx AOSearchContextEx;
  160. //* Definition of an AO request structure. There structures are used only for
  161. // queuing delete and option set requests.
  162. typedef struct AOMCastAddr {
  163. struct AOMCastAddr *ama_next; // Next in list.
  164. IPAddr ama_addr; // The address.
  165. IPAddr ama_if; // The "interface" requested.
  166. IPAddr ama_if_used; // The actual ifaddr used.
  167. BOOLEAN ama_flags; // Flags.
  168. BOOLEAN ama_inclusion; // Inclusion or exclusion mode?
  169. ulong ama_srccount; // Number of entries in srclist
  170. struct AOMCastSrcAddr *ama_srclist;// List of active sources.
  171. } AOMCastAddr;
  172. #define AMA_VALID_FLAG 0x01
  173. #define AMA_VALID(A) ((A)->ama_flags & AMA_VALID_FLAG)
  174. #define SET_AMA_INVALID(A) (A)->ama_flags &= ~AMA_VALID_FLAG
  175. typedef struct AOMCastSrcAddr {
  176. struct AOMCastSrcAddr *asa_next; // Next in list.
  177. IPAddr asa_addr; // The address.
  178. } AOMCastSrcAddr;
  179. //* External declarations for exported functions.
  180. extern CACHE_LINE_KSPIN_LOCK AddrObjTableLock;
  181. extern uint AddrObjTableSize;
  182. extern AddrObj **AddrObjTable;
  183. extern AddrObj *GetAddrObj(IPAddr LocalAddr, ushort LocalPort, uchar Prot,
  184. AddrObj *PreviousAO, BOOLEAN CheckIfList);
  185. extern AddrObj *GetNextAddrObj(AOSearchContext *SearchContext);
  186. extern AddrObj *GetNextBestAddrObj(IPAddr LocalAddr, ushort LocalPort, uchar Prot,
  187. AddrObj *PreviousAO, BOOLEAN CheckIfList);
  188. extern AddrObj *GetFirstAddrObj(IPAddr LocalAddr, ushort LocalPort, uchar Prot,
  189. AOSearchContext *SearchContext);
  190. extern AddrObj *GetAddrObjEx(IPAddr LocalAddr, ushort LocalPort, uchar Protocol, uint IfIndex,
  191. AddrObj *PreviousAO, uint PreviousIndex, uint *CurrentIndex);
  192. extern AddrObj *GetNextAddrObjEx(AOSearchContextEx *SearchContext);
  193. extern AddrObj *GetFirstAddrObjEx(IPAddr LocalAddr, ushort LocalPort, uchar Prot, uint IfIndex,
  194. AOSearchContextEx *SearchContext);
  195. extern TDI_STATUS TdiOpenAddress(PTDI_REQUEST Request,
  196. TRANSPORT_ADDRESS UNALIGNED *AddrList, uint Protocol,
  197. void *Reuse);
  198. extern TDI_STATUS TdiCloseAddress(PTDI_REQUEST Request);
  199. extern TDI_STATUS SetAddrOptions(PTDI_REQUEST Request, uint ID, uint OptLength,
  200. void *Options);
  201. extern TDI_STATUS GetAddrOptionsEx(PTDI_REQUEST Request, uint ID,
  202. uint OptLength, PNDIS_BUFFER Options,
  203. uint *InfoSize, void *Context);
  204. extern TDI_STATUS TdiSetEvent(PVOID Handle, int Type, PVOID Handler,
  205. PVOID Context);
  206. extern uchar GetAddress(TRANSPORT_ADDRESS UNALIGNED *AddrList,
  207. IPAddr *Addr, ushort *Port);
  208. extern int InitAddr(void);
  209. extern void ProcessAORequests(AddrObj *RequestAO);
  210. extern void DelayDerefAO(AddrObj *RequestAO);
  211. extern void DerefAO(AddrObj *RequestAO);
  212. extern void FreeAORequest(AORequest *FreedRequest);
  213. extern uint ValidateAOContext(void *Context, uint *Valid);
  214. extern uint ReadNextAO(void *Context, void *OutBuf);
  215. extern void InvalidateAddrs(IPAddr Addr);
  216. extern void RevalidateAddrs(IPAddr Addr);
  217. extern uint MCastAddrOnAO(AddrObj *AO, IPAddr Dest, IPAddr Src);
  218. #define GetBestAddrObj(addr, port, prot, checkiflist) \
  219. GetAddrObj(addr, port, prot, NULL, checkiflist)
  220. #define REF_AO(a) (a)->ao_usecnt++
  221. #define DELAY_DEREF_AO(a) DelayDerefAO((a))
  222. #define DEREF_AO(a) DerefAO((a))
  223. #define LOCKED_DELAY_DEREF_AO(a) \
  224. (a)->ao_usecnt--; \
  225. if (!(a)->ao_usecnt && !AO_BUSY((a)) && AO_PENDING((a))) { \
  226. SET_AO_BUSY((a)); \
  227. CTEScheduleEvent(&(a)->ao_event, (a)); \
  228. }