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.

1627 lines
70 KiB

  1. /*++
  2. Copyright(c) 1998,99 Microsoft Corporation
  3. Module Name:
  4. main.h
  5. Abstract:
  6. Windows Load Balancing Service (WLBS)
  7. Driver - packet handing
  8. Author:
  9. kyrilf
  10. --*/
  11. #ifndef _Main_h_
  12. #define _Main_h_
  13. #define NDIS_MINIPORT_DRIVER 1
  14. #define NDIS50 1
  15. #define NDIS51_MINIPORT 1
  16. #define NDIS51 1
  17. #include <ndis.h>
  18. #include "univ.h"
  19. #include "load.h"
  20. #include "util.h"
  21. #include "wlbsip.h"
  22. #include "wlbsparm.h"
  23. #include "params.h"
  24. #include "wlbsiocl.h"
  25. #include "diplist.h"
  26. #if defined (NLB_HOOK_ENABLE)
  27. #include <ntddnlb.h>
  28. #endif
  29. /* NOTE: This assumes that we're on a little endian architecture, like x86 or IA64. */
  30. #define HTONS(x) ((USHORT)((((x) & 0x000000ff) << 8) | (((x) & 0x0000ff00) >> 8)))
  31. #define NTOHS(x) ((USHORT)((((x) & 0x000000ff) << 8) | (((x) & 0x0000ff00) >> 8)))
  32. /* CONSTANTS */
  33. /* type codes for main datastructures */
  34. #define MAIN_CTXT_CODE 0xc0dedead
  35. #define MAIN_ACTION_CODE 0xc0deac10
  36. #define MAIN_BUFFER_CODE 0xc0deb4fe
  37. #define MAIN_ADAPTER_CODE 0xc0deadbe
  38. /* protocol specific constants */
  39. #define MAIN_FRAME_SIG 0x886f /* new and approved 802.3 ping frame signature */
  40. #define MAIN_FRAME_SIG_OLD 0xbf01 /* old convoy 802.3 ping frame signature */
  41. #define MAIN_FRAME_CODE 0xc0de01bf /* ping frame code */
  42. #define MAIN_FRAME_EX_CODE 0xc0de01c0 /* code for identity heartbeats*/
  43. #define MAIN_IP_SIG 0x0800 /* IP code for IGMP messages */
  44. /* reset states */
  45. #define MAIN_RESET_NONE 0
  46. #define MAIN_RESET_START 1
  47. #define MAIN_RESET_START_DONE 2
  48. #define MAIN_RESET_END 3
  49. /* post-filtering operation types */
  50. #define MAIN_FILTER_OP_NONE 0 /* not operation */
  51. #define MAIN_FILTER_OP_NBT 1 /* netbios spoofing */
  52. #define MAIN_FILTER_OP_CTRL_REQUEST 2 /* remote control requests */
  53. #define MAIN_FILTER_OP_CTRL_RESPONSE 3 /* remote control responses */
  54. /* extended heartbeat type */
  55. #define MAIN_PING_EX_TYPE_NONE 0 /* invalid number */
  56. #define MAIN_PING_EX_TYPE_IDENTITY 1 /* identity heartbeat */
  57. /* packet type */
  58. #define MAIN_PACKET_TYPE_NONE 0 /* invalid number */
  59. #define MAIN_PACKET_TYPE_PING 1 /* ping packet */
  60. #define MAIN_PACKET_TYPE_PASS 3 /* pass-through packet */
  61. #define MAIN_PACKET_TYPE_CTRL 4 /* remote control packet */
  62. #define MAIN_PACKET_TYPE_TRANSFER 6 /* protocol layer initiated transfer packet */
  63. #define MAIN_PACKET_TYPE_IGMP 7 /* igmp message packet */
  64. #define MAIN_PACKET_TYPE_IDHB 8 /* identity heartbeat message packet */
  65. /* frame type */
  66. #define MAIN_FRAME_UNKNOWN 0
  67. #define MAIN_FRAME_DIRECTED 1
  68. #define MAIN_FRAME_MULTICAST 2
  69. #define MAIN_FRAME_BROADCAST 3
  70. /* adapter constants */
  71. #define MAIN_ADAPTER_NOT_FOUND -1
  72. /* identity heartbeat constants */
  73. #define WLBS_MAX_ID_HB_BODY_SIZE 0xFF /* Maxumum size of a TLV structure in 8-byte units */
  74. #define WLBS_ID_HB_TOLERANCE 3 /* Number of identity heartbeats that can be missed before we age out the cached entry */
  75. /* TYPES */
  76. /* actions are used for passing parameter info between Nic and Prot modules,
  77. and ensure that if miniport syncronization requires queueing we do not
  78. loose parameters and context */
  79. #pragma pack(1)
  80. typedef struct
  81. {
  82. LIST_ENTRY link;
  83. PVOID ctxtp; /* pointer to main context */
  84. ULONG code; /* type-checking code */
  85. NDIS_STATUS status; /* general status */
  86. /* per-operation type data */
  87. union
  88. {
  89. struct
  90. {
  91. PULONG xferred;
  92. PULONG needed;
  93. ULONG external;
  94. ULONG buffer_len;
  95. PVOID buffer;
  96. NDIS_EVENT event;
  97. NDIS_REQUEST req;
  98. } request;
  99. } op;
  100. }
  101. MAIN_ACTION, * PMAIN_ACTION;
  102. #pragma pack()
  103. /* V2.0.6 per-packet protocol reserved information. this structure has to be at
  104. most 16 bytes in length */
  105. #pragma pack(1)
  106. typedef struct
  107. {
  108. PVOID miscp; /* dscrp for ping frame,
  109. bufp for recv_indicate frame,
  110. external packet for pass through frames */
  111. USHORT type; /* packet type */
  112. USHORT group; /* if the frame direct, multicast or
  113. broadcast */
  114. LONG data; /* used for keeping expected xfer len on
  115. recv_indicate until transfer_complete
  116. occurs and for doing locking on
  117. send/receive paths */
  118. ULONG len; /* packet length for stats */
  119. }
  120. MAIN_PROTOCOL_RESERVED, * PMAIN_PROTOCOL_RESERVED;
  121. #pragma pack()
  122. /* per receive buffer wrapper structure */
  123. typedef struct
  124. {
  125. LIST_ENTRY link;
  126. ULONG code; /* type-checking code */
  127. PNDIS_BUFFER full_bufp; /* describes enture buffer */
  128. PNDIS_BUFFER frame_bufp; /* describes payload only */
  129. PUCHAR framep; /* pointer to payload */
  130. UCHAR data [1]; /* beginning of buffer */
  131. }
  132. MAIN_BUFFER, * PMAIN_BUFFER;
  133. /* convoy ping message header */
  134. #pragma pack(1)
  135. typedef struct
  136. {
  137. ULONG code; /* distinguishes Convoy frames */
  138. ULONG version; /* software version */
  139. ULONG host; /* source host id */
  140. ULONG cl_ip_addr; /* cluster IP address */
  141. ULONG ded_ip_addr; /* dedicated IP address V2.0.6 */
  142. }
  143. MAIN_FRAME_HDR, * PMAIN_FRAME_HDR;
  144. /* Identity heartbeat payload */
  145. typedef struct {
  146. UCHAR type; /* Type defining this structure */
  147. UCHAR length8; /* Size of the data in this struct in units of 8-bytes */
  148. USHORT flags; /* Reserved; for 8 byte alignment */
  149. ULONG flags2; /* Reserved; for 8 byte alignment */
  150. } TLV_HEADER, * PTLV_HEADER;
  151. typedef struct {
  152. TLV_HEADER header; /* Self-describing header structure */
  153. WCHAR fqdn[CVY_MAX_FQDN + 1]; /* Fully qualified host name or netbt name */
  154. } PING_MSG_EX, * PPING_MSG_EX;
  155. #pragma pack()
  156. /* per ping message wrapper structure */
  157. typedef struct
  158. {
  159. LIST_ENTRY link;
  160. CVY_MEDIA_HDR media_hdr; /* filled-out media header */
  161. MAIN_FRAME_HDR frame_hdr; /* frame header */
  162. PING_MSG msg; /* ping msg V1.1.4 */
  163. ULONG recv_len; /* used on receive path */
  164. PNDIS_BUFFER media_hdr_bufp; /* describes media header */
  165. PNDIS_BUFFER frame_hdr_bufp; /* describes frame header */
  166. PNDIS_BUFFER send_data_bufp; /* describes payload source for
  167. outgoing frames */
  168. PNDIS_BUFFER recv_data_bufp; /* describes payload destination
  169. for incoming frames */
  170. }
  171. MAIN_FRAME_DSCR, * PMAIN_FRAME_DSCR;
  172. #pragma pack(1)
  173. typedef struct
  174. {
  175. UCHAR igmp_vertype; /* Version and Type */
  176. UCHAR igmp_unused; /* Unused */
  177. USHORT igmp_xsum; /* Checksum */
  178. ULONG igmp_address; /* Multicast Group Address */
  179. }
  180. MAIN_IGMP_DATA, * PMAIN_IGMP_DATA;
  181. typedef struct
  182. {
  183. UCHAR iph_verlen; /* Version and length */
  184. UCHAR iph_tos; /* Type of service */
  185. USHORT iph_length; /* Total length of datagram */
  186. USHORT iph_id; /* Identification */
  187. USHORT iph_offset; /* Flags and fragment offset */
  188. UCHAR iph_ttl; /* Time to live */
  189. UCHAR iph_protocol; /* Protocol */
  190. USHORT iph_xsum; /* Header checksum */
  191. ULONG iph_src; /* Source address */
  192. ULONG iph_dest; /* Destination address */
  193. }
  194. MAIN_IP_HEADER, * PMAIN_IP_HEADER;
  195. typedef struct
  196. {
  197. MAIN_IP_HEADER ip_data;
  198. MAIN_IGMP_DATA igmp_data;
  199. }
  200. MAIN_IGMP_FRAME, * PMAIN_IGMP_FRAME;
  201. #pragma pack()
  202. #if defined (NLB_HOOK_ENABLE)
  203. /* State indications to protect the register/de-register process. */
  204. enum _HOOK_OPERATION {
  205. HOOK_OPERATION_NONE = 0, /* Ready for register/de-register. */
  206. HOOK_OPERATION_REGISTERING, /* Register operation in progress. */
  207. HOOK_OPERATION_DEREGISTERING /* De-register operation in progress. */
  208. };
  209. /* This union of function pointers contains all available
  210. hook types in all hook interfaces. Its used to avoid
  211. the need to cast function pointers stored in the generic
  212. hook structure below. */
  213. typedef union {
  214. NLBSendFilterHook SendHookFunction; /* The send packet filter hook. */
  215. NLBQueryFilterHook QueryHookFunction; /* The query packet filter hook. */
  216. NLBReceiveFilterHook ReceiveHookFunction; /* The receive packet filter hook. */
  217. } HOOK_FUNCTION, * PHOOK_FUNCTION;
  218. /* This structure contains all information and state for a
  219. single hook that is part of a hook interface. This
  220. includes whether or not the hook has been registered and
  221. the function pointer to invoke. */
  222. typedef struct {
  223. BOOLEAN Registered; /* Has this hook been specified? */
  224. HOOK_FUNCTION Hook; /* The function pointer. */
  225. } HOOK, * PHOOK;
  226. /* This structure contains all information and state for a
  227. hook interface, which is a related group of hooks. This
  228. information includes whether or not the interface is
  229. currently "owned", who the owner is, the current number
  230. of references on this interface, which prevents the interface
  231. from being de-registered while its in use, and the callback
  232. function to invoke whenever the interface is de-registered,
  233. either gracefully or forcefully. */
  234. typedef struct {
  235. BOOLEAN Registered; /* Has this interface been registered? */
  236. ULONG References; /* Number of references on the interface - must be zero to de-register. */
  237. HANDLE Owner; /* Who owns this interface? */
  238. NLBHookDeregister Deregister; /* A function to call when the interface is de-registered. */
  239. } HOOK_INTERFACE, * PHOOK_INTERFACE;
  240. /* This structure contains all of the related filter hook
  241. information, including the interface configuration and
  242. state as well as that of all hooks that are part of this
  243. interface. It also includes a spin lock, which is used
  244. to serialize access to the interface. */
  245. typedef struct {
  246. NDIS_SPIN_LOCK Lock; /* A spin lock to control access to the filter interface and hooks. */
  247. ULONG Operation; /* The current operation under way on this interface, if any. */
  248. HOOK_INTERFACE Interface; /* The interface/registration information. */
  249. HOOK SendHook; /* Send hook state and function pointer. */
  250. HOOK QueryHook; /* Query hook state and function pointer. */
  251. HOOK ReceiveHook; /* Receive hook state and function pointer. */
  252. } FILTER_HOOK_TABLE, * PFILTER_HOOK_TABLE;
  253. /* This structure contains all supported NLB hooks. */
  254. typedef struct {
  255. FILTER_HOOK_TABLE FilterHook;
  256. } HOOK_TABLE, * PHOOK_TABLE;
  257. /* The global table of NLB hooks. */
  258. extern HOOK_TABLE univ_hooks;
  259. #endif
  260. #define CVY_BDA_MAXIMUM_MEMBER_ID (CVY_MAX_ADAPTERS - 1)
  261. #define CVY_BDA_INVALID_MEMBER_ID CVY_MAX_ADAPTERS
  262. enum _BDA_TEAMING_OPERATION {
  263. BDA_TEAMING_OPERATION_NONE = 0, /* Ready for create/delete. */
  264. BDA_TEAMING_OPERATION_CREATING, /* Create operation in progress. */
  265. BDA_TEAMING_OPERATION_DELETING /* Delete operation in progress. */
  266. };
  267. /* This structure holds the configuration of a BDA team. Each
  268. member holds a pointer to this structure, which its uses to
  269. update state and acquire references to and utilize the master
  270. load context for packet handling. */
  271. typedef struct _BDA_TEAM {
  272. struct _BDA_TEAM * prev; /* Pointer to the previous team in this doubly-linked list. */
  273. struct _BDA_TEAM * next; /* Pointer to the next team in this doubly-linked list. */
  274. PLOAD_CTXT load; /* Pointer to the "shared" load module for this team. This
  275. is the load module of the master. If there is no master
  276. in the team, this pointer is NULL. */
  277. PNDIS_SPIN_LOCK load_lock; /* Pointer to the load lock for the "shared" load module. */
  278. ULONG active; /* Is this team active. Teams become inactive under two
  279. conditions; (1) inconsistent teaming detected via heart-
  280. beats or (2) the team has no master. */
  281. ULONG membership_count; /* This is the number of members in the team. This acts as
  282. a reference count on the team state. */
  283. ULONG membership_fingerprint; /* This is an XOR of the least significant 16 bits of each
  284. member's primary cluster IP address. This is used as a
  285. sort of signature on the team membership. */
  286. ULONG membership_map; /* This is a bit map of the team membership. Each member is
  287. assigned a member ID, which is its index in this bit map. */
  288. ULONG consistency_map; /* This is a bit map of the member consistency. Each mamber
  289. is assigned a member ID, which is its index in this bit map.
  290. When a member detects bad configuration via its heartbeats,
  291. it resets its bit in this map. */
  292. WCHAR team_id[CVY_MAX_BDA_TEAM_ID + 1]; /* This is the team ID - a GUID - which is used to match
  293. adapters to the correct team. */
  294. } BDA_TEAM, * PBDA_TEAM;
  295. /* This structure holds the teaming configuration for a single
  296. adapter and is a member of the MAIN_CTXT structure. */
  297. typedef struct _BDA_MEMBER {
  298. ULONG operation; /* Used for synchronization of creating/deleting BDA teaming. */
  299. ULONG active; /* Is this adapter part of a BDA team. */
  300. ULONG master; /* Is this adapter the master of its team. */
  301. ULONG reverse_hash; /* Is this adapter using reverse hashing (reverse source and
  302. destination IP addresses and ports before hashing). */
  303. ULONG member_id; /* The member ID - a unique (per-team) ID between 0 and 15.
  304. Used as the index in several team bit arrays. */
  305. PBDA_TEAM bda_team; /* Pointer to a BDA_TEAM structure, which contains the
  306. ocnfiguration and state of my team. */
  307. } BDA_MEMBER, * PBDA_MEMBER;
  308. /* 802.3. */
  309. typedef struct _MAIN_PACKET_ETHERNET_INFO {
  310. PCVY_ETHERNET_HDR pHeader; /* A pointer to the 802.3 media header, if the medium is NdisMedium802_3. */
  311. ULONG Length; /* The length of contiguous packet memory accessible from pHeader,
  312. guaranteed to be AT LEAST the size of a 802.3 media header (14 bytes). */
  313. } MAIN_PACKET_ETHERNET_INFO, * PMAIN_PACKET_ETHERNET_INFO;
  314. /* ARP. */
  315. typedef struct _MAIN_PACKET_ARP_INFO {
  316. PARP_HDR pHeader; /* A pointer to the ARP header, if the packet Type is TCPIP_ARP_SIG. */
  317. ULONG Length; /* The length of contiguous packet memory accessible from pHeader,
  318. guaranteed to be AT LEAST the size of an ARP header (28 bytes). */
  319. } MAIN_PACKET_ARP_INFO, * PMAIN_PACKET_ARP_INFO;
  320. /* TCP payload. */
  321. typedef struct _MAIN_PACKET_TCP_PAYLOAD_INFO {
  322. PUCHAR pPayload; /* A pointer to the TCP payload, if the IP Protocol is TCPIP_PROTOCOL_TCP. */
  323. ULONG Length; /* The length of contiguous packet memory accessible from pPayload,
  324. with no guarantees on the minimum length, except in the case of NetBT. */
  325. PNDIS_BUFFER pPayloadBuffer; /* The NDIS buffer in which the UDP payload resides. In cases where a payload
  326. stretches across more than one buffer, this pointer can be used to get a
  327. pointer to the next buffer, and so on, by calling NdisGetNextBuffer and
  328. NdisQueryBuffer. */
  329. } MAIN_PACKET_TCP_PAYLOAD_INFO, * PMAIN_PACKET_TCP_PAYLOAD_INFO;
  330. /* TCP. */
  331. typedef struct _MAIN_PACKET_TCP_INFO {
  332. PTCP_HDR pHeader; /* A pointer to the TCP header, if the IP Protocol is TCPIP_PROTOCOL_TCP. */
  333. ULONG Length; /* The length of contiguous packet memory accessible from pHeader,
  334. guaranteed to be AT LEAST as long as indicated the indicated
  335. header length in the TCP header itself (20 bytes minimum). */
  336. MAIN_PACKET_TCP_PAYLOAD_INFO Payload; /* The payload information. Note, this information is not guaranteed to
  337. be filled in for every packet; i.e., not every TCP packet even HAS a
  338. payload. Users must check the payload pointer to be sure its not NULL,
  339. and ensure that the length indication is greater than zero before
  340. accessing the payload. */
  341. } MAIN_PACKET_TCP_INFO, * PMAIN_PACKET_TCP_INFO;
  342. /* UDP payload. */
  343. typedef struct _MAIN_PACKET_UDP_PAYLOAD_INFO {
  344. PUCHAR pPayload; /* A pointer to the UDP payload, if the IP Protocol is TCPIP_PROTOCOL_UDP. */
  345. ULONG Length; /* The length of contiguous packet memory accessible from pHeader,
  346. with no guarantees on the minimum length, except in the case of remote control. */
  347. PNDIS_BUFFER pPayloadBuffer; /* The NDIS buffer in which the UDP payload resides. In cases where a payload
  348. stretches across more than one buffer, this pointer can be used to get a
  349. pointer to the next buffer, and so on, by calling NdisGetNextBuffer and
  350. NdisQueryBuffer. */
  351. } MAIN_PACKET_UDP_PAYLOAD_INFO, * PMAIN_PACKET_UDP_PAYLOAD_INFO;
  352. /* UDP. */
  353. typedef struct _MAIN_PACKET_UDP_INFO {
  354. PUDP_HDR pHeader; /* A pointer to the UDP header, if the IP Protocol is TCPIP_PROTOCOL_UDP. */
  355. ULONG Length; /* The length of contiguous packet memory accessible from pHeader,
  356. guaranteed to be AT LEAST the size of a UDP header (8 bytes). */
  357. MAIN_PACKET_UDP_PAYLOAD_INFO Payload; /* The payload information. Note, this information is not guaranteed to
  358. be filled in for every packet; i.e., not every UDP packet even HAS a
  359. payload. Users must check the payload pointer to be sure its not NULL,
  360. and ensure that the length indication is greater than zero before
  361. accessing the payload. */
  362. } MAIN_PACKET_UDP_INFO, * PMAIN_PACKET_UDP_INFO;
  363. /* IP. */
  364. typedef struct _MAIN_PACKET_IP_INFO {
  365. PIP_HDR pHeader; /* A pointer to the IP header, if the packet Type is TCPIP_IP_SIG. */
  366. ULONG Length; /* The length of contiguous packet memory accessible from pHeader,
  367. guaranteed to be AT LEAST as long as indicated the indicated
  368. header length in the IP header itself (20 bytes minimum). */
  369. ULONG Protocol; /* The IP protocol (TCP, UDP, ICMP, etc.). */
  370. BOOLEAN bFragment; /* If TRUE, then this IP packet is a [subsequent] IP fragment that does
  371. NOT contain a protocol header. Therefore, the TCP and UDP information
  372. below is NOT populated. */
  373. union {
  374. /* TCP. */
  375. MAIN_PACKET_TCP_INFO TCP; /* If Protocol == TCP, the TCP packet information. */
  376. /* UDP. */
  377. MAIN_PACKET_UDP_INFO UDP; /* If protocol == UDP, the UDP packet information. */
  378. };
  379. } MAIN_PACKET_IP_INFO, * PMAIN_PACKET_IP_INFO;
  380. /* NLB Heartbeat payload. */
  381. typedef struct MAIN_PACKET_HEARTBEAT_PAYLOAD_INFO {
  382. union {
  383. PPING_MSG pPayload; /* A pointer to the NLB heartbeat payload, if the packet Type is MAIN_FRAME_SIG[_OLD]. */
  384. PTLV_HEADER pPayloadEx; /* A pointer to the NLB heartbeat payload for new heartbeat types, including identity heartbeats */
  385. };
  386. ULONG Length; /* The length of contiguous packet memory accessible from pHeader,
  387. guaranteed to be AT LEAST the size of a PING message. */
  388. } MAIN_PACKET_HEARTBEAT_PAYLOAD_INFO, * PMAIN_PACKET_HEARTBEAT_PAYLOAD_INFO;
  389. /* NLB Heartbeat. */
  390. typedef struct _MAIN_PACKET_HEARTBEAT_INFO {
  391. PMAIN_FRAME_HDR pHeader; /* A pointer to the NLB heartbeat header, if the packet Type is MAIN_FRAME_SIG[_OLD]. */
  392. ULONG Length; /* The length of contiguous packet memory accessible from pHeader,
  393. guaranteed to be AT LEAST the size of an NLB heartbeat header (20 bytes). */
  394. MAIN_PACKET_HEARTBEAT_PAYLOAD_INFO Payload; /* The PING paylod, which is passed to the load module. */
  395. } MAIN_PACKET_HEARTBEAT_INFO, * PMAIN_PACKET_HEARTBEAT_INFO;
  396. /* Unknown. */
  397. typedef struct _MAIN_PACKET_UNKNOWN_INFO {
  398. PUCHAR pHeader; /* A pointer to the frame of unkonwn type, if the packet Type is not known. */
  399. ULONG Length; /* The length of contiguous packet memory accessible from pHeader,
  400. with no guarantees on the minimum length. */
  401. } MAIN_PACKET_UNKNOWN_INFO, * PMAIN_PACKET_UNKNOWN_INFO;
  402. typedef struct {
  403. ULONG ded_ip_addr; /* Dedicated IP address */
  404. ULONG ttl; /* Time-to-live for this cached identity entry */
  405. USHORT host_id; /* Host ID of the member. Range: [0-31] */
  406. WCHAR fqdn[CVY_MAX_FQDN + 1]; /* Fully qualified domain name */
  407. } MAIN_IDENTITY, * PMAIN_IDENTITY;
  408. /* Represents the information parsed from a given network packet.
  409. All information in the packet is trusted, but the information
  410. to which it points is NOT trusted (i.e., the actual contents
  411. of the packet).
  412. Note: We could parse out IPs, flags, ports, etc such that nobody
  413. but Main_frame_parse should have to operate on the packet itself,
  414. unless it parses/modifies the payload, such as UDP 500 (IKE),
  415. remote control or NetBT. */
  416. typedef struct _MAIN_PACKET_INFO {
  417. PNDIS_PACKET pPacket; /* Storage for a pointer to the original NDIS packet. */
  418. NDIS_MEDIUM Medium; /* The network medium - should always be NdisMedium802_3. */
  419. ULONG Length; /* The total packet length, not including the MAC header. */
  420. USHORT Group; /* Whether the packet is unicast, multicast or broadcast. */
  421. USHORT Type; /* The packet type (ARP, IP, Heartbeat, etc.). */
  422. USHORT Operation; /* A packet-type specific operation (Remote control, NetBT, etc.). */
  423. /* The MAC header, as determined by the Medium. */
  424. union {
  425. /* 802.3. */
  426. MAIN_PACKET_ETHERNET_INFO Ethernet; /* If Medium == 802.3, the ethernet MAC header information. */
  427. };
  428. /* The frame type, as determined by the Type. */
  429. union {
  430. /* ARP. */
  431. MAIN_PACKET_ARP_INFO ARP; /* If Type == ARP, the ARP packet information. */
  432. /* IP. */
  433. MAIN_PACKET_IP_INFO IP; /* If Type == IP, the IP packet information. */
  434. /* NLB Heartbeat. */
  435. MAIN_PACKET_HEARTBEAT_INFO Heartbeat; /* If Type == PING, the heartbeat packet information. */
  436. /* Unknown. */
  437. MAIN_PACKET_UNKNOWN_INFO Unknown; /* If Type == otherwise, the unknown packet information. */
  438. };
  439. } MAIN_PACKET_INFO, * PMAIN_PACKET_INFO;
  440. /* main context type */
  441. typedef struct
  442. {
  443. ULONG ref_count; /* The reference count on this load module. */
  444. ULONG code; /* type checking code */
  445. DIPLIST dip_list; /* A list of all DIPs on all hosts in this cluster. */
  446. NDIS_STATUS completion_status; /* open/close completion status */
  447. NDIS_EVENT completion_event; /* open/close completion trigger */
  448. NDIS_HANDLE bind_handle; /* bind context handle */
  449. NDIS_HANDLE unbind_handle; /* unbind context handle */
  450. NDIS_HANDLE mac_handle; /* underlying adapter handle */
  451. NDIS_HANDLE prot_handle; /* overlying protocol handle */
  452. NDIS_MEDIUM medium; /* adapter medium */
  453. ULONG curr_tout; /* current heartbeat period */
  454. ULONG igmp_sent; /* time elapsed since the last
  455. igmp message was sent */
  456. ULONG conn_purge; /* time elapsed since the last
  457. descriptor cleanup */
  458. ULONG num_purged; /* number of connections purged */
  459. ULONG idhb_sent; /* time elapsed (ms) since the last identity HB was sent*/
  460. ULONG packets_exhausted; /* out of send packets */
  461. ULONG mac_options; /* adapter options V1.3.1b */
  462. ULONG media_connected; /* media plugged in V1.3.2b */
  463. ULONG max_frame_size; /* MTU of the medium V1.3.2b */
  464. ULONG max_mcast_list_size;
  465. ULONG reverse_hash; /* Whether or not to reverse the source
  466. and destination information in hashing. */
  467. BDA_MEMBER bda_teaming; /* BDA membership information. */
  468. ULONG cached_state; /* Cached initial state. */
  469. PVOID timer; /* points to Nic module allocated
  470. ping time V1.2.3b */
  471. ULONG num_packets; /* number of packets per alloc */
  472. ULONG num_actions; /* number of actions per alloc */
  473. ULONG num_send_msgs; /* number of heartbeats to alloc */
  474. /* states */
  475. ULONG reset_state; /* current reset state V1.1.2 */
  476. ULONG recv_indicated; /* first receive trigger after
  477. reset V1.1.2 */
  478. ULONG draining; /* draining mode */
  479. ULONG stopping; /* draining->stop mode */
  480. ULONG suspended; /* cluster control suspended */
  481. ULONG convoy_enabled; /* cluster mode active */
  482. ULONG ctrl_op_in_progress; /* Critical section flag for Main_ctrl.
  483. Only one control operation can be in
  484. progress at a given time. */
  485. /* PnP */
  486. NDIS_DEVICE_POWER_STATE prot_pnp_state; /* PNP state */
  487. NDIS_DEVICE_POWER_STATE nic_pnp_state; /* PNP state */
  488. PMAIN_ACTION out_request; /* outstanding request */
  489. ULONG requests_pending; /* set or query requests pending */
  490. ULONG standby_state; /* entering standby state */
  491. /* IP and MAC addresses */
  492. ULONG ded_ip_addr; /* dedicated IP */
  493. ULONG ded_net_mask; /* dedicated mask */
  494. ULONG ded_bcast_addr; /* dedicated broadcast IP */
  495. ULONG cl_ip_addr; /* cluster IP */
  496. ULONG cl_net_mask; /* cluster mask */
  497. ULONG cl_bcast_addr; /* cluster broadcast IP */
  498. ULONG cl_igmp_addr; /* IGMP address for join messages */
  499. CVY_MAC_ADR ded_mac_addr; /* dedicated MAC V1.3.0b */
  500. CVY_MAC_ADR cl_mac_addr; /* cluster MAC V1.3.0b */
  501. /* event logging - prevent event log from filling with error messages */
  502. ULONG actions_warned;
  503. ULONG packets_warned;
  504. ULONG bad_host_warned;
  505. ULONG send_msgs_warned;
  506. ULONG dup_ded_ip_warned; /* duplicate dedicated IP address */
  507. ULONG recv_indicate_warned; /* NIC does not indicate NDIS packets. */
  508. /* actions */
  509. LIST_ENTRY act_list; /* list of allocated actions */
  510. NDIS_SPIN_LOCK act_lock; /* corresponding lock */
  511. PMAIN_ACTION act_buf [CVY_MAX_ALLOCS];
  512. /* array of allocated sets of
  513. actions */
  514. ULONG num_action_allocs; /* number of allocated action
  515. sets */
  516. ULONG act_size;
  517. /* packet stacking */
  518. NPAGED_LOOKASIDE_LIST resp_list; /* list for main protocol field
  519. to be allocated for ps */
  520. /* packets */
  521. NDIS_SPIN_LOCK send_lock; /* send packet lock */
  522. NDIS_HANDLE send_pool_handle [CVY_MAX_ALLOCS];
  523. /* array of allocated sets of
  524. send packet pools V1.1.2 */
  525. ULONG num_send_packet_allocs; /* number of allocated send
  526. packet pools */
  527. ULONG cur_send_packet_pool; /* current send pool to draw
  528. packets from V1.3.2b */
  529. ULONG num_sends_alloced; /* number of send packets allocated */
  530. ULONG num_sends_out; /* number of send packets out */
  531. ULONG send_allocing; /* TRUE if some thread is allocing a send packet pool */
  532. NDIS_SPIN_LOCK recv_lock; /* receive packet lock */
  533. NDIS_HANDLE recv_pool_handle [CVY_MAX_ALLOCS];
  534. /* array of allocated sets of
  535. recv packet pools V1.1.2 */
  536. ULONG num_recv_packet_allocs; /* number of allocated recv
  537. packet pools */
  538. ULONG cur_recv_packet_pool; /* current recv pool to draw
  539. packets from V1.3.2b */
  540. ULONG num_recvs_alloced; /* number of recv packets allocated */
  541. ULONG num_recvs_out; /* number of recv packets out */
  542. ULONG recv_allocing; /* TRUE if some thread is allocing a recv packet pool */
  543. /* buffers */
  544. NDIS_HANDLE buf_pool_handle [CVY_MAX_ALLOCS];
  545. /* array of buffer descriptor
  546. sets V1.3.2b */
  547. PUCHAR buf_array [CVY_MAX_ALLOCS];
  548. /* array of buffer pools V1.3.2b */
  549. ULONG buf_size; /* buffer + descriptor size
  550. V1.3.2b */
  551. ULONG buf_mac_hdr_len; /* length of full media header
  552. V1.3.2b */
  553. LIST_ENTRY buf_list; /* list of buffers V1.3.2b */
  554. NDIS_SPIN_LOCK buf_lock; /* corresponding lock V1.3.2b */
  555. ULONG num_buf_allocs; /* number of allocated buffer
  556. pools V1.3.2b */
  557. ULONG num_bufs_alloced; /* number of buffers allocated */
  558. ULONG num_bufs_out; /* number of buffers out */
  559. /* heartbeats */
  560. CVY_MEDIA_HDR media_hdr; /* filled-out media master header
  561. for heartbeat messages */
  562. CVY_MEDIA_HDR media_hdr_igmp; /* filled-out media master header
  563. for igmp messages. Need a separate one
  564. since the EtherType will be different */
  565. MAIN_IGMP_FRAME igmp_frame; /* IGMP message */
  566. ULONG etype_old; /* ethernet type was set to
  567. convoy compatibility value */
  568. LIST_ENTRY frame_list; /* list of heartbeat frames */
  569. NDIS_SPIN_LOCK frame_lock; /* corresponding lock */
  570. PMAIN_FRAME_DSCR frame_dscrp; /* heartbeat frame descriptors */
  571. NDIS_HANDLE frame_pool_handle; /* packet pool for heartbeats */
  572. NDIS_HANDLE frame_buf_pool_handle; /* buffer pool for heartbeats */
  573. /* remote control */
  574. ULONG rct_last_addr; /* source of last request */
  575. ULONG rct_last_id; /* last request epoch */
  576. ULONG cntr_recv_tcp_resets; /* The number of TCP resets received. */
  577. ULONG cntr_xmit_tcp_resets; /* The number of TCP resets transmitted. */
  578. /* V2.0.6 performance counters */
  579. ULONG cntr_xmit_ok;
  580. ULONG cntr_recv_ok;
  581. ULONG cntr_xmit_err;
  582. ULONG cntr_recv_err;
  583. ULONG cntr_recv_no_buf;
  584. ULONGLONG cntr_xmit_bytes_dir;
  585. ULONG cntr_xmit_frames_dir;
  586. ULONGLONG cntr_xmit_bytes_mcast;
  587. ULONG cntr_xmit_frames_mcast;
  588. ULONGLONG cntr_xmit_bytes_bcast;
  589. ULONG cntr_xmit_frames_bcast;
  590. ULONGLONG cntr_recv_bytes_dir;
  591. ULONG cntr_recv_frames_dir;
  592. ULONGLONG cntr_recv_bytes_mcast;
  593. ULONG cntr_recv_frames_mcast;
  594. ULONGLONG cntr_recv_bytes_bcast;
  595. ULONG cntr_recv_frames_bcast;
  596. ULONG cntr_recv_crc_err;
  597. ULONG cntr_xmit_queue_len;
  598. ULONG cntr_frame_no_buf;
  599. ULONG num_frames_out;
  600. /* sub-module contexts */
  601. TCPIP_CTXT tcpip; /* TCP/IP handling context V1.1.1 */
  602. NDIS_SPIN_LOCK load_lock; /* load context lock */
  603. LOAD_CTXT load; /* load processing context */
  604. PPING_MSG load_msgp; /* load ping message to send
  605. out as heartbeat */
  606. /* Parameter contexts */
  607. CVY_PARAMS params;
  608. ULONG params_valid;
  609. #if defined (OPTIMIZE_FRAGMENTS)
  610. ULONG optimized_frags;
  611. #endif
  612. // Name of the nic. Used by Nic_announce and Nic_unannounce
  613. WCHAR virtual_nic_name [CVY_MAX_VIRTUAL_NIC + 1];
  614. #if 0
  615. /* for tracking send filtering */
  616. ULONG sends_in;
  617. ULONG sends_filtered;
  618. ULONG sends_completed;
  619. ULONG arps_filtered;
  620. ULONG mac_modified;
  621. ULONG uninited_return;
  622. #endif
  623. ULONG adapter_id;
  624. WCHAR log_msg_str [80]; /* This was added for log messages for multi nic support */
  625. /* Identity cache */
  626. MAIN_IDENTITY identity_cache[CVY_MAX_HOSTS];
  627. PING_MSG_EX idhb_msg; /* Identity heartbeat transmitted by this host */
  628. ULONG idhb_size; /* Size (in bytes) of the identity heartbeat */
  629. }
  630. MAIN_CTXT, * PMAIN_CTXT;
  631. #if defined (NLB_TCP_NOTIFICATION)
  632. enum _IF_INDEX_OPERATION {
  633. IF_INDEX_OPERATION_NONE = 0,
  634. IF_INDEX_OPERATION_UPDATE
  635. };
  636. #endif
  637. /* adapter context */
  638. typedef struct
  639. {
  640. ULONG code; /* type checking code */
  641. #if defined (NLB_TCP_NOTIFICATION)
  642. ULONG if_index; /* tcpip interface index for this adapter */
  643. ULONG if_index_operation; /* whether or not an if_index update is in progress */
  644. #endif
  645. BOOLEAN used; /* whether this element is in use or not */
  646. BOOLEAN inited; /* context has been initialized */
  647. BOOLEAN bound; /* convoy has been bound to the stack */
  648. BOOLEAN announced; /* tcpip has been bound to convoy */
  649. PMAIN_CTXT ctxtp; /* pointer to the context that is used */
  650. ULONG device_name_len; /* length of the string allocated for the device name */
  651. PWSTR device_name; /* name of the device to which this context is bound */
  652. }
  653. MAIN_ADAPTER, * PMAIN_ADAPTER;
  654. /* MACROS */
  655. /* compute offset to protocol reserved space in the packet */
  656. /* Set/retrieve the pointer to our private buffer, which we store in the
  657. MiniportReserved field of an NDIS packet. */
  658. #define MAIN_MINIPORT_FIELD(p) (*(PMAIN_PROTOCOL_RESERVED *) ((p) -> MiniportReserved))
  659. #define MAIN_PROTOCOL_FIELD(p) ((PMAIN_PROTOCOL_RESERVED) ((p) -> ProtocolReserved))
  660. #define MAIN_IMRESERVED_FIELD(p) ((PMAIN_PROTOCOL_RESERVED) ((p) -> IMReserved [0]))
  661. /* If the current packet stack exists, then get the IMReserved pointer and return it if
  662. it is non-NULL - this is where we have stored / are storing our private data. If it
  663. NULL, or if the current packet stack is NULL, then we are either using ProtocolReserved
  664. or MiniportReserved, depending on whether this is in the send or receive path. We
  665. also make sure that there is a non-NULL pointer in MiniportReserved before returning
  666. it because CTRL packets, although they are allocated on the receive path, use Protocol
  667. Reserved. */
  668. #define MAIN_RESP_FIELD(pkt, left, ps, rsp, send) \
  669. { \
  670. (ps) = NdisIMGetCurrentPacketStack((pkt), &(left)); \
  671. if ((ps)) \
  672. { \
  673. if (MAIN_IMRESERVED_FIELD((ps))) \
  674. (rsp) = MAIN_IMRESERVED_FIELD((ps)); \
  675. else if ((send)) \
  676. (rsp) = MAIN_PROTOCOL_FIELD((pkt)); \
  677. else if (MAIN_MINIPORT_FIELD((pkt))) \
  678. (rsp) = MAIN_MINIPORT_FIELD((pkt)); \
  679. else \
  680. (rsp) = MAIN_PROTOCOL_FIELD((pkt)); \
  681. } \
  682. else \
  683. { \
  684. if ((send)) \
  685. (rsp) = MAIN_PROTOCOL_FIELD((pkt)); \
  686. else if (MAIN_MINIPORT_FIELD((pkt))) \
  687. (rsp) = MAIN_MINIPORT_FIELD((pkt)); \
  688. else \
  689. (rsp) = MAIN_PROTOCOL_FIELD((pkt)); \
  690. } \
  691. }
  692. #define MAIN_PNP_DEV_ON(c) ((c)->nic_pnp_state == NdisDeviceStateD0 && (c)->prot_pnp_state == NdisDeviceStateD0 )
  693. /* Global variables that are exported */
  694. extern MAIN_ADAPTER univ_adapters [CVY_MAX_ADAPTERS]; // ###### ramkrish
  695. extern ULONG univ_adapters_count;
  696. /* PROCEDURES */
  697. extern NDIS_STATUS Main_init (
  698. PMAIN_CTXT ctxtp);
  699. /*
  700. Initialize context
  701. returns NDIS_STATUS:
  702. function:
  703. */
  704. extern VOID Main_cleanup (
  705. PMAIN_CTXT ctxtp);
  706. /*
  707. Cleanup context
  708. returns VOID:
  709. function:
  710. */
  711. extern ULONG Main_arp_handle (
  712. PMAIN_CTXT ctxtp,
  713. PMAIN_PACKET_INFO pPacketInfo,
  714. ULONG send);
  715. /*
  716. Process ARP packets
  717. returns ULONG :
  718. TRUE => accept
  719. FALSE => drop
  720. function:
  721. */
  722. extern ULONG Main_recv_ping (
  723. PMAIN_CTXT ctxtp,
  724. PMAIN_PACKET_HEARTBEAT_INFO heartbeatp);
  725. /*
  726. Process heartbeat packets
  727. returns ULONG :
  728. TRUE => accept
  729. FALSE => drop
  730. function:
  731. */
  732. extern PNDIS_PACKET Main_send (
  733. PMAIN_CTXT ctxtp,
  734. PNDIS_PACKET packetp,
  735. PULONG exhausted);
  736. /*
  737. Process outgoing packets
  738. returns PNDIS_PACKET:
  739. function:
  740. */
  741. extern PNDIS_PACKET Main_recv (
  742. PMAIN_CTXT ctxtp,
  743. PNDIS_PACKET packetp);
  744. /*
  745. Process incoming packets
  746. returns PNDIS_PACKET:
  747. function:
  748. */
  749. extern ULONG Main_actions_alloc (
  750. PMAIN_CTXT ctxtp);
  751. /*
  752. Allocate additional actions
  753. returns ULONG :
  754. TRUE => success
  755. FALSE => failure
  756. function:
  757. */
  758. extern ULONG Main_bufs_alloc (
  759. PMAIN_CTXT ctxtp);
  760. /*
  761. Allocate additional buffers
  762. returns ULONG :
  763. TRUE => success
  764. FALSE => failure
  765. function:
  766. */
  767. extern PNDIS_PACKET Main_frame_get (
  768. PMAIN_CTXT ctxtp,
  769. PULONG len,
  770. USHORT frame_type);
  771. /*
  772. Get a fresh heartbeat/igmp frame from the list
  773. returns PNDIS_PACKET:
  774. function:
  775. */
  776. extern VOID Main_frame_put (
  777. PMAIN_CTXT ctxtp,
  778. PNDIS_PACKET packet,
  779. PMAIN_FRAME_DSCR dscrp);
  780. /*
  781. Return heartbeat frame to the list
  782. returns VOID:
  783. function:
  784. */
  785. extern PMAIN_ACTION Main_action_get (
  786. PMAIN_CTXT ctxtp);
  787. /*
  788. Get a fresh action from the list
  789. returns PMAIN_ACTION:
  790. function:
  791. */
  792. extern VOID Main_action_put (
  793. PMAIN_CTXT ctxtp,
  794. PMAIN_ACTION reqp);
  795. /*
  796. Return action to the list
  797. returns VOID:
  798. function:
  799. */
  800. extern VOID Main_action_slow_put (
  801. PMAIN_CTXT ctxtp,
  802. PMAIN_ACTION reqp);
  803. /*
  804. Return action to the list using slow (non-DPC) locking
  805. returns VOID:
  806. function:
  807. */
  808. extern PNDIS_PACKET Main_packet_alloc (
  809. PMAIN_CTXT ctxtp,
  810. ULONG send,
  811. PULONG low);
  812. /*
  813. Allocate a fresh packet from the pool
  814. returns PNDIS_PACKET:
  815. function:
  816. */
  817. extern PNDIS_PACKET Main_packet_get (
  818. PMAIN_CTXT ctxtp,
  819. PNDIS_PACKET packet,
  820. ULONG send,
  821. USHORT group,
  822. ULONG len);
  823. /*
  824. Get a fresh packet
  825. returns PNDIS_PACKET:
  826. function:
  827. */
  828. extern PNDIS_PACKET Main_packet_put (
  829. PMAIN_CTXT ctxtp,
  830. PNDIS_PACKET packet,
  831. ULONG send,
  832. NDIS_STATUS status);
  833. /*
  834. Return packet to the pool
  835. returns PNDIS_PACKET:
  836. <linked packet>
  837. function:
  838. */
  839. extern VOID Main_send_done (
  840. PVOID ctxtp,
  841. PNDIS_PACKET packetp,
  842. NDIS_STATUS status);
  843. /*
  844. Heartbeat send completion routine
  845. returns VOID:
  846. function:
  847. */
  848. extern VOID Main_ping (
  849. PMAIN_CTXT ctxtp,
  850. PULONG tout);
  851. /*
  852. Handle ping timeout
  853. returns VOID:
  854. function:
  855. */
  856. extern ULONG Main_ip_addr_init (
  857. PMAIN_CTXT ctxtp);
  858. /*
  859. Convert IP strings in dotted notation to ulongs
  860. returns ULONG :
  861. TRUE => success
  862. FALSE => failure
  863. function:
  864. */
  865. extern ULONG Main_mac_addr_init (
  866. PMAIN_CTXT ctxtp);
  867. /*
  868. Convert MAC string in dashed notation to array of bytes
  869. returns ULONG :
  870. TRUE => success
  871. FALSE => failure
  872. function:
  873. */
  874. extern ULONG Main_igmp_init (
  875. PMAIN_CTXT ctxtp,
  876. BOOLEAN join);
  877. /*
  878. Initialize the Ethernet frame and IP Packet to send out IGMP joins or leaves
  879. returns ULONG :
  880. TRUE => success
  881. FALSE => failure
  882. function:
  883. */
  884. NDIS_STATUS Main_dispatch(
  885. PVOID DeviceObject,
  886. PVOID Irp);
  887. /*
  888. Handle all requests
  889. returns NDIS_STATUS:
  890. function:
  891. */
  892. extern NDIS_STATUS Main_ioctl (
  893. PVOID device,
  894. PVOID irp_irp);
  895. /*
  896. Handle IOCTL request
  897. returns NDIS_STATUS:
  898. function:
  899. */
  900. extern NDIS_STATUS Main_ctrl_recv (
  901. PMAIN_CTXT ctxtp,
  902. PMAIN_PACKET_INFO pPacketInfo);
  903. /*
  904. Handle remote control requests
  905. returns VOID:
  906. function:
  907. */
  908. // code added for multiple nic support for looking up the array of elements
  909. extern INT Main_adapter_alloc (
  910. PNDIS_STRING device_name);
  911. /*
  912. Returns the first available adapter element.
  913. This function is called at bind time, when context is to be allocated for a
  914. new binding
  915. returns INT:
  916. -1 : falied to allocate a new context for this binding
  917. 0 - CVY_MAX_ADAPTERS : success
  918. function:
  919. */
  920. extern INT Main_adapter_get (
  921. PWSTR device_name);
  922. /*
  923. Look up an adapter that is bound to this device.
  924. returns:
  925. -1 : adapter not found
  926. 0 - CVY_MAX_ADAPTERS : success
  927. function:
  928. */
  929. extern INT Main_adapter_put (
  930. PMAIN_ADAPTER adapterp);
  931. /*
  932. Look up an adapter that is bound to this device.
  933. returns:
  934. -1 : adapter not found
  935. 0 - CVY_MAX_ADAPTERS : success
  936. function:
  937. */
  938. extern INT Main_adapter_selfbind (
  939. PWSTR device_name);
  940. /*
  941. Finds if a ProtocolBind call is being made to ourself
  942. returns;
  943. -1 : adapter not found
  944. 0 - CVY_MAX_ADAPTERS : success
  945. function:
  946. */
  947. /*
  948. * Function: Main_spoof_mac
  949. * Description: This function spoofs the source/destination MAC address(es) of incoming
  950. * and/or outgoing packets. Incoming packets in multicast mode must change
  951. * the cluster multicast MAC to the NIC's permanent MAC address before sending
  952. * the packet up the protocol stack. Outgoing packets in unicast mode must
  953. * mask the source MAC address to prevent switches from learning the cluster
  954. * MAC address and associating it with a particular switch port.
  955. * Parameters: ctxtp - pointer the the main NLB context structure for this adapter.
  956. * pPacketInfo - the previously parse packet information structure, which,
  957. * among other things, contains a pointer to the MAC header.
  958. * send - boolean indication of send v. receive.
  959. * Returns: Nothing.
  960. * Author: shouse, 3.4.02
  961. * Notes:
  962. */
  963. VOID Main_spoof_mac (
  964. PMAIN_CTXT ctxtp,
  965. PMAIN_PACKET_INFO pPacketInfo,
  966. ULONG send);
  967. /*
  968. * Function: Main_recv_frame_parse
  969. * Description: This function parses an NDIS_PACKET and carefully extracts the information
  970. * necessary to handle the packet. The information extracted includes pointers
  971. * to all relevant headers and payloads as well as the packet type (EType), IP
  972. * protocol (if appropriate), etc. This function does all necessary validation
  973. * to ensure that all pointers are accessible for at least the specified number
  974. * of bytes; i.e., if this function returns successfully, the pointer to the IP
  975. * header is guaranteed to be accessible for at LEAST the length of the IP header.
  976. * No contents inside headers or payloads is validated, except for header lengths,
  977. * and special cases, such as NLB heartbeats or remote control packets. If this
  978. * function returns unsuccessfully, the contents of MAIN_PACKET_INFO cannot be
  979. * trusted and the packet should be discarded. See the definition of MAIN_PACKET_INFO
  980. * in main.h for more specific indications of what fields are filled in and under
  981. * what circumstances.
  982. * Parameters: ctxtp - pointer to the main NLB context structure for this adapter.
  983. * pPacket - pointer to the received NDIS_PACKET.
  984. * pPacketInfo - pointer to a MAIN_PACKET_INFO structure to hold the information
  985. * parsed from the packet.
  986. * Returns: BOOLEAN - TRUE if successful, FALSE if not.
  987. * Author: shouse, 3.4.02
  988. * Notes:
  989. */
  990. BOOLEAN Main_recv_frame_parse (
  991. PMAIN_CTXT ctxtp,
  992. IN PNDIS_PACKET pPacket,
  993. OUT PMAIN_PACKET_INFO pPacketInfo);
  994. /*
  995. * Function: Main_send_frame_parse
  996. * Description: This function parses an NDIS_PACKET and carefully extracts the information
  997. * necessary to handle the packet. The information extracted includes pointers
  998. * to all relevant headers and payloads as well as the packet type (EType), IP
  999. * protocol (if appropriate), etc. This function does all necessary validation
  1000. * to ensure that all pointers are accessible for at least the specified number
  1001. * of bytes; i.e., if this function returns successfully, the pointer to the IP
  1002. * header is guaranteed to be accessible for at LEAST the length of the IP header.
  1003. * No contents inside headers or payloads is validated, except for header lengths,
  1004. * and special cases, such as NLB heartbeats or remote control packets. If this
  1005. * function returns unsuccessfully, the contents of MAIN_PACKET_INFO cannot be
  1006. * trusted and the packet should be discarded. See the definition of MAIN_PACKET_INFO
  1007. * in main.h for more specific indications of what fields are filled in and under
  1008. * what circumstances.
  1009. * Parameters: ctxtp - pointer to the main NLB context structure for this adapter.
  1010. * pPacket - pointer to the sent NDIS_PACKET.
  1011. * pPacketInfo - pointer to a MAIN_PACKET_INFO structure to hold the information
  1012. * parsed from the packet.
  1013. * Returns: BOOLEAN - TRUE if successful, FALSE if not.
  1014. * Author: shouse, 3.4.02
  1015. * Notes:
  1016. */
  1017. BOOLEAN Main_send_frame_parse (
  1018. PMAIN_CTXT ctxtp,
  1019. IN PNDIS_PACKET pPacket,
  1020. OUT PMAIN_PACKET_INFO pPacketInfo);
  1021. /*
  1022. * Function: Main_ip_recv_filter
  1023. * Description: This function filters incoming IP traffic, often by querying the load
  1024. * module for load-balancing decisions. Packets addressed to the dedicated
  1025. * address are always allowed to pass, as are protocols that are not
  1026. * specifically filtered by NLB.
  1027. * Parameters: ctxtp - a pointer to the NLB main context structure for this adapter.
  1028. * pPacketInfo - a pointer to the MAIN_PACKET_INFO structure parsed by Main_recv_frame_parse
  1029. * which contains pointers to the IP and TCP/UDP headers.
  1030. #if defined (NLB_HOOK_ENABLE)
  1031. * filter - the filtering directive returned by the filtering hook, if registered.
  1032. #endif
  1033. * Returns: BOOLEAN - if TRUE, accept the packet, otherwise, reject it.
  1034. * Author: kyrilf, shouse 3.4.02
  1035. * Notes:
  1036. */
  1037. BOOLEAN Main_ip_recv_filter(
  1038. PMAIN_CTXT ctxtp,
  1039. #if defined (NLB_HOOK_ENABLE)
  1040. PMAIN_PACKET_INFO pPacketInfo,
  1041. NLB_FILTER_HOOK_DIRECTIVE filter
  1042. #else
  1043. PMAIN_PACKET_INFO pPacketInfo
  1044. #endif
  1045. );
  1046. /*
  1047. * Function: Main_ip_send_filter
  1048. * Description: This function filters outgoing IP traffic, often by querying the load
  1049. * module for load-balancing decisions. Packets addressed to the dedicated
  1050. * address are always allowed to pass, as are protocols that are not
  1051. * specifically filtered by NLB. Generally, all outgoing traffic is allowed
  1052. * to pass.
  1053. * Parameters: ctxtp - a pointer to the NLB main context structure for this adapter.
  1054. * pPacketInfo - a pointer to the MAIN_PACKET_INFO structure parsed by Main_send_frame_parse
  1055. * which contains pointers to the IP and TCP/UDP headers.
  1056. #if defined (NLB_HOOK_ENABLE)
  1057. * filter - the filtering directive returned by the filtering hook, if registered.
  1058. #endif
  1059. * Returns: BOOLEAN - if TRUE, accept the packet, otherwise, reject it.
  1060. * Author: kyrilf, shouse 3.4.02
  1061. * Notes:
  1062. */
  1063. BOOLEAN Main_ip_send_filter(
  1064. PMAIN_CTXT ctxtp,
  1065. #if defined (NLB_HOOK_ENABLE)
  1066. PMAIN_PACKET_INFO pPacketInfo,
  1067. NLB_FILTER_HOOK_DIRECTIVE filter
  1068. #else
  1069. PMAIN_PACKET_INFO pPacketInfo
  1070. #endif
  1071. );
  1072. /*
  1073. * Function: Main_ctrl
  1074. * Description: This function performs a control function on a given NLB instance, such as
  1075. * RELOAD, STOP, START, etc.
  1076. * Parameters: ctxtp - a pointer to the adapter context for the operation.
  1077. * ioctl - the operation to be performed.
  1078. * pBuf - the (legacy) control buffer (input and output in some cases).
  1079. * pCommon - the input/output buffer for operations common to both local and remote control.
  1080. * pLocal - the input/output buffer for operations that can be executed locally only.
  1081. * pRemote - the input/output buffer for operations that can be executed remotely only.
  1082. * Returns: NDIS_STATUS - the status of the operation; NDIS_STATUS_SUCCESS if successful.
  1083. * Author: shouse, 3.29.01
  1084. * Notes:
  1085. */
  1086. extern NDIS_STATUS Main_ctrl (PMAIN_CTXT ctxtp, ULONG ioctl, PIOCTL_CVY_BUF pBuf, PIOCTL_COMMON_OPTIONS pCommon, PIOCTL_LOCAL_OPTIONS pLocal, PIOCTL_REMOTE_OPTIONS pRemote);
  1087. /*
  1088. * Function: Main_add_reference
  1089. * Description: This function adds a reference to the context of a given adapter.
  1090. * Parameters: ctxtp - a pointer to the context to reference.
  1091. * Returns: ULONG - The incremented value.
  1092. * Author: shouse, 3.29.01
  1093. * Notes:
  1094. */
  1095. ULONG Main_add_reference (IN PMAIN_CTXT ctxtp);
  1096. /*
  1097. * Function: Main_release_reference
  1098. * Description: This function releases a reference on the context of a given adapter.
  1099. * Parameters: ctxtp - a pointer to the context to dereference.
  1100. * Returns: ULONG - The decremented value.
  1101. * Author: shouse, 3.29.01
  1102. * Notes:
  1103. */
  1104. ULONG Main_release_reference (IN PMAIN_CTXT ctxtp);
  1105. /*
  1106. * Function: Main_get_reference_count
  1107. * Description: This function returns the current context reference count on a given adapter.
  1108. * Parameters: ctxtp - a pointer to the context to check.
  1109. * Returns: ULONG - The current reference count.
  1110. * Author: shouse, 3.29.01
  1111. * Notes:
  1112. */
  1113. ULONG Main_get_reference_count (IN PMAIN_CTXT ctxtp);
  1114. /*
  1115. * Function: Main_set_host_state
  1116. * Desctription: This function queues a work item to set the current host
  1117. * state registry key, HostState. This MUST be done in a work
  1118. * item, rather than inline because if the state of the host
  1119. * changes as a result of the reception of a remote control
  1120. * request, that code will be running at DISPATCH_LEVEL;
  1121. * registry manipulation MUST be done at PASSIVE_LEVEL. Work
  1122. * items are completed at PASSIVE_LEVEL.
  1123. * Parameters: ctxtp - a pointer to the main context structure for this adapter.
  1124. * state - the new host state; one of started, stopped, suspended.
  1125. * Returns: Nothing
  1126. * Author: shouse, 7.13.01
  1127. */
  1128. VOID Main_set_host_state (PMAIN_CTXT ctxtp, ULONG state);
  1129. /*
  1130. * Function: Main_ctrl_process
  1131. * Description: This function processes a remote control request and replies if
  1132. * the request is proper and the cluster is configured to handle
  1133. * remote control. If not, the packet is released HERE. If the
  1134. * reply succeeds and the packet send is not pending, the packet
  1135. * is released HERE. If the send is pending, the packet will be
  1136. * released in Prot_send_complete.
  1137. * Parameters: ctxtp - a pointer to the context structure for thie NLB instance.
  1138. * packetp - a pointer to the NDIS packet on the send path.
  1139. * Returns: NDIS_STATUS - the status of the remote control request.
  1140. * Author: shouse, 10.15.01
  1141. * Notes:
  1142. */
  1143. NDIS_STATUS Main_ctrl_process (PMAIN_CTXT ctxtp, PNDIS_PACKET packetp) ;
  1144. #if defined (NLB_HOOK_ENABLE)
  1145. /*
  1146. * Function: Main_hook_interface_init
  1147. * Description: This function initializes a hook interface by marking it unregistered.
  1148. * Parameters: pInterface - a pointer to the hook interface.
  1149. * Returns: Nothing.
  1150. * Author: shouse, 12.14.01
  1151. * Notes:
  1152. */
  1153. VOID Main_hook_interface_init (PHOOK_INTERFACE pInterface);
  1154. /*
  1155. * Function: Main_hook_init
  1156. * Description: This function initializes a hook by marking it unused and unreferenced.
  1157. * Parameters: pHook - a pointer to the hook.
  1158. * Returns: Nothing.
  1159. * Author: shouse, 12.14.01
  1160. * Notes:
  1161. */
  1162. VOID Main_hook_init (PHOOK pHook);
  1163. #endif
  1164. /*
  1165. * Function: Main_schedule_work_item
  1166. * Description: This function schedules the given procedure to be invoked as part of a
  1167. * deferred NDIS work item, which will be scheduled to run at PASSIVE_LEVEL.
  1168. * This function will refernce the adapter context to keep it from being
  1169. * destroyed before the work item executed. The given procedure is required
  1170. * to both free the memory in the work item pointer passed to it and to
  1171. * dereference the adapter context before returning.
  1172. * Parameters: ctxtp - the adapter context.
  1173. * funcp - the procedure to invoke when the work item fires.
  1174. * Returns: NTSTATUS - the status of the operation; STATUS_SUCCESS if successful.
  1175. * Author: shouse, 4.15.02
  1176. * Notes:
  1177. */
  1178. NTSTATUS Main_schedule_work_item (PMAIN_CTXT ctxtp, NDIS_PROC funcp);
  1179. #if defined (NLB_TCP_NOTIFICATION)
  1180. /*
  1181. * Function: Main_tcp_callback
  1182. * Description: This function is invoked by TCP/IP as the state of TCP connections change.
  1183. * We register for this callback when the first NLB instance goes up and de-
  1184. * register when the last instance of NLB goes away. When SYNs are received
  1185. * and TCP creates state, they use this callback to notify NLB so that it can
  1186. * create state to track the connection. Likewise, when the connection is
  1187. * closed, TCP notifies NLB so that it may destroy the associated state for
  1188. * that connection.
  1189. * Parameters: Context - NULL, unused.
  1190. * Argument1 - pointer to a TCPCcbInfo structure (See net\published\inc\tcpinfo.w).
  1191. * Argument2 - NULL, unused.
  1192. * Returns: Nothing.
  1193. * Author: shouse, 4.15.02
  1194. * Notes:
  1195. */
  1196. extern VOID Main_tcp_callback (PVOID Context, PVOID Argument1, PVOID Argument2);
  1197. /*
  1198. * Function: Main_alternate_callback
  1199. * Description: This function is invoked by external components as the state of connections
  1200. * change. We register for this callback when the first NLB instance goes up
  1201. * and de-register when the last instance of NLB goes away. When connections
  1202. * are created and a protocol creates state, they use this callback to notify
  1203. * NLB so that it can create state to track the connection. Likewise, when the
  1204. * connection is closed, the protocol notifies NLB so that it may destroy the
  1205. * associated state for that connection.
  1206. * Parameters: Context - NULL, unused.
  1207. * Argument1 - pointer to a NLBConnectionInfo structure (See net\published\inc\ntddnlb.w).
  1208. * Argument2 - NULL, unused.
  1209. * Returns: Nothing.
  1210. * Author: shouse, 8.1.02
  1211. * Notes:
  1212. */
  1213. extern VOID Main_alternate_callback (PVOID Context, PVOID Argument1, PVOID Argument2);
  1214. /*
  1215. * Function: Main_set_interface_index
  1216. * Description: This function is called as a result of either the IP address table being
  1217. * modified (triggers a OID_GEN_NETWORK_LAYER_ADDRESSES NDIS request), or
  1218. * when the NLB instance is reloaded (IOCTL_CVY_RELOAD). This function
  1219. * retrieves the IP address table from IP and searches for its primary
  1220. * cluster IP address in the table. If it finds it, it notes the IP interface
  1221. * index on which the primary cluster IP address is configured; this infor-
  1222. * mation is required in order to process TCP connection notifcation callbacks.
  1223. * If NLB cannot find its primary cluster IP address in the IP table, or
  1224. * if the cluster is misconfigured (primary cluster IP address configured on
  1225. * the wrong NIC, perhaps), NLB will be unable to properly handle notifications.
  1226. * Because this function performs IOCTLs on other drivers, it MUST run at
  1227. * PASSIVE_LEVEL, in which case NDIS work items might be required to invoke it.
  1228. * Parameters: pWorkItem - the work item pointer, which must be freed if non-NULL.
  1229. * nlbctxt - the adapter context.
  1230. * Returns: Nothing.
  1231. * Author: shouse, 4.15.02
  1232. * Notes:
  1233. */
  1234. VOID Main_set_interface_index (PNDIS_WORK_ITEM pWorkItem, PVOID nlbctxt);
  1235. /*
  1236. * Function: Main_conn_up
  1237. * Description: This function is used to notify NLB that a new connection has been established
  1238. * on the given NLB instance. This function performs a few house-keeping duties
  1239. * such as BDA state lookup, hook filter feedback processing, etc. before calling
  1240. * the load module to create state to track this connection.
  1241. * Parameters: ctxtp - the adapter context for the NLB instance on which the connection was established.
  1242. * svr_addr - the server IP address of the connection, in network byte order.
  1243. * svr_port - the server port of the connection, in host byte order.
  1244. * clt_addr - the client IP address of the connection, in network byte order.
  1245. * clt_port - the client port of the connection, in host byte order.
  1246. * protocol - the protocol of the connection.
  1247. #if defined (NLB_HOOK_ENABLE)
  1248. * filter - the feedback from the query hook, if one was registered.
  1249. #endif
  1250. * Returns: BOOLEAN - whether or not state was successfully created to track this connection.
  1251. * Author: shouse, 4.15.02
  1252. * Notes: DO NOT ACQUIRE ANY LOAD LOCKS IN THIS FUNCTION.
  1253. */
  1254. __inline BOOLEAN Main_conn_up (
  1255. PMAIN_CTXT ctxtp,
  1256. ULONG svr_addr,
  1257. ULONG svr_port,
  1258. ULONG clt_addr,
  1259. ULONG clt_port,
  1260. #if defined (NLB_HOOK_ENABLE)
  1261. USHORT protocol,
  1262. NLB_FILTER_HOOK_DIRECTIVE filter
  1263. #else
  1264. USHORT protocol
  1265. #endif
  1266. );
  1267. /*
  1268. * Function: Main_conn_establish
  1269. * Description: This function is used to notify NLB that a new OUTGOING connection has been
  1270. * established on the given NLB adapter. Note that the context CAN BE NULL if
  1271. * the connection was established on a non-NLB adapter. In that case, we don't
  1272. * want to create state to track the connection, but we need to remove our state
  1273. * that was tracking this pending outgoing connection. If the context is non-
  1274. * NULL, then in addition, we need to create the state to track this new connection.
  1275. * This function performs a few house-keeping duties such as BDA state lookup, hook
  1276. * filter feedback processing, etc. before calling the load module to modify the
  1277. * state for this connection.
  1278. * Parameters: ctxtp - the adapter context for the NLB instance on which the connection was established.
  1279. * svr_addr - the server IP address of the connection, in network byte order.
  1280. * svr_port - the server port of the connection, in host byte order.
  1281. * clt_addr - the client IP address of the connection, in network byte order.
  1282. * clt_port - the client port of the connection, in host byte order.
  1283. * protocol - the protocol of the connection.
  1284. #if defined (NLB_HOOK_ENABLE)
  1285. * filter - the feedback from the query hook, if one was registered.
  1286. #endif
  1287. * Returns: BOOLEAN - whether or not state was successfully updated for this connection.
  1288. * Author: shouse, 4.15.02
  1289. * Notes: ctxtp CAN BE NULL if the outgoing connection was established on a non-NLB NIC.
  1290. * DO NOT ACQUIRE ANY LOAD LOCKS IN THIS FUNCTION.
  1291. */
  1292. __inline BOOLEAN Main_conn_establish (
  1293. PMAIN_CTXT ctxtp,
  1294. ULONG svr_addr,
  1295. ULONG svr_port,
  1296. ULONG clt_addr,
  1297. ULONG clt_port,
  1298. #if defined (NLB_HOOK_ENABLE)
  1299. USHORT protocol,
  1300. NLB_FILTER_HOOK_DIRECTIVE filter
  1301. #else
  1302. USHORT protocol
  1303. #endif
  1304. );
  1305. /*
  1306. * Function: Main_conn_down
  1307. * Description: This function is used to notify NLB that a protocol is removing state for an exisiting
  1308. * (but not necessarily established) connection. This function calls into the load module
  1309. * to find and destroy and state associated with this connection, which may or may not
  1310. * exist; if the connection was established on a non-NLB adapter, then NLB has no state
  1311. * associated with the connection.
  1312. * Parameters: svr_addr - the server IP address of the connection, in network byte order.
  1313. * svr_port - the server port of the connection, in host byte order.
  1314. * clt_addr - the client IP address of the connection, in network byte order.
  1315. * clt_port - the client port of the connection, in host byte order.
  1316. * protocol - the protocol of the connection.
  1317. * conn_status - whether the connection is being torn-down or reset.
  1318. * Returns: BOOLEAN - whether or not NLB found and destroyed the state for this connection.
  1319. * Author: shouse, 4.15.02
  1320. * Notes: DO NOT ACQUIRE ANY LOAD LOCKS IN THIS FUNCTION.
  1321. */
  1322. __inline BOOLEAN Main_conn_down (ULONG svr_addr, ULONG svr_port, ULONG clt_addr, ULONG clt_port, USHORT protocol, ULONG conn_status);
  1323. /*
  1324. * Function: Main_conn_pending
  1325. * Description: This function is used to notify NLB that an OUTGOING connection is being established.
  1326. * Because it is unknown on which adapter the connection will return and ultimately be
  1327. * established, NLB creates state to track this connection globally and when the connection
  1328. * is finally established, the protocol informs NLB on which adapter the connection was
  1329. * completed (via Main_conn_established). This function merely creates some global state
  1330. * to ensure that if the connection DOES come back on an NLB adapter, we'll be sure to
  1331. * pass the packet(s) up to the protocol.
  1332. * Parameters: svr_addr - the server IP address of the connection, in network byte order.
  1333. * svr_port - the server port of the connection, in host byte order.
  1334. * clt_addr - the client IP address of the connection, in network byte order.
  1335. * clt_port - the client port of the connection, in host byte order.
  1336. * protocol - the protocol of the connection.
  1337. * Returns: BOOLEAN - whether or not NLB was able to create state to track this pending connection.
  1338. * Author: shouse, 4.15.02
  1339. * Notes: DO NOT ACQUIRE ANY LOAD LOCKS IN THIS FUNCTION.
  1340. */
  1341. __inline BOOLEAN Main_conn_pending (ULONG svr_addr, ULONG svr_port, ULONG clt_addr, ULONG clt_port, USHORT protocol);
  1342. #endif
  1343. #endif /* _Main_h_ */