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.

931 lines
44 KiB

  1. /*++
  2. Copyright(c) 1998,99 Microsoft Corporation
  3. Module Name:
  4. load.h
  5. Abstract:
  6. Windows Load Balancing Service (WLBS)
  7. Driver - load balancing mechanism
  8. Author:
  9. bbain
  10. --*/
  11. #ifndef _Load_h_
  12. #define _Load_h_
  13. #ifndef KERNEL_MODE
  14. #define SPINLOCK THREADLOCK
  15. #define IRQLEVEL ULONG
  16. #define LOCK_INIT(lp) Lock_init(lp)
  17. #define LOCK_ENTER(lp, pirql) {if (Lock_enter((lp), INFINITE) != 1) \
  18. UNIV_PRINT(("Lock enter error")); }
  19. #define LOCK_EXIT(lp, irql) {if (Lock_exit(lp) != 1) \
  20. UNIV_PRINT(("Lock exit error")); }
  21. #else
  22. #include <ntddk.h>
  23. #include <ndis.h> /* Fixed-size block implementation. */
  24. #define LINK LIST_ENTRY
  25. #define QUEUE LIST_ENTRY
  26. #define Link_init(lp) InitializeListHead (lp)
  27. #define Link_unlink(lp) { RemoveEntryList (lp); InitializeListHead (lp); }
  28. #define Queue_init(qp) InitializeListHead (qp)
  29. #define Queue_enq(qp, lp) if (IsListEmpty(lp)) { InsertTailList(qp, lp); } else DbgBreakPoint()
  30. #define Queue_front(qp) (IsListEmpty(qp) ? NULL : (qp)->Flink)
  31. #define Queue_tail(qp) (IsListEmpty(qp) ? NULL : (qp)->Blink)
  32. #define Queue_deq(qp) Queue_front(qp); \
  33. if (!IsListEmpty (qp)) { PLIST_ENTRY _lp = RemoveHeadList (qp); InitializeListHead(_lp); }
  34. #define Queue_next(qp, lp) ((IsListEmpty (qp) || (lp)->Flink == (qp)) ? NULL : (lp)->Flink)
  35. #define SPINLOCK KSPIN_LOCK
  36. #define IRQLEVEL KIRQL
  37. #if 0 /* 1.03: Removed kernel mode locking in this module */
  38. #define LOCK_INIT(lp) KeInitializeSpinLock (lp)
  39. #define LOCK_ENTER(lp, pirql) KeAcquireSpinLock (lp, pirql)
  40. #define LOCK_EXIT(lp, irql) KeReleaseSpinLock (lp, irql)
  41. #else
  42. #define LOCK_INIT(lp)
  43. #define LOCK_ENTER(lp, pirql)
  44. #define LOCK_EXIT(lp, irql)
  45. #endif
  46. #endif
  47. #include "wlbsparm.h"
  48. #include "params.h"
  49. #include "wlbsiocl.h"
  50. /* CONSTANTS */
  51. /* This is the hardcoded second paramter to Map() when map function limiting is needed. */
  52. #define MAP_FN_PARAMETER 0x00000000
  53. #define CVY_LOADCODE 0xc0deba1c /* type checking code for load structure */
  54. #define CVY_ENTRCODE 0xc0debaa5 /* type checking code for conn entry */
  55. #define CVY_DESCCODE 0xc0deba5a /* type checking code for conn descr */
  56. #define CVY_BINCODE 0xc0debabc /* type checking code for bin structure */
  57. #if defined (NLB_TCP_NOTIFICATION)
  58. #define CVY_PENDINGCODE 0xc0deba55 /* type checking code for pending connection entries */
  59. #endif
  60. #define CVY_MAXBINS 60 /* number of load balancing bins; must conform to MAP_T definition */
  61. #define CVY_MAX_CHASH 4099 /* maximum hash entries for connection hashing */
  62. #define CVY_EQUAL_LOAD 50 /* load percentage used for equal load balance */
  63. /* TCP connection status */
  64. #define CVY_CONN_UP 1 /* connection may be coming up */
  65. #define CVY_CONN_DOWN 2 /* connection may be going down */
  66. #define CVY_CONN_RESET 3 /* connection is getting reset */
  67. /* broadcast host states */
  68. #define HST_NORMAL 1 /* normal operations */
  69. #define HST_STABLE 2 /* stable convergence detected */
  70. #define HST_CVG 3 /* converging to new load balance */
  71. #define IS_TCP_PKT(protocol) (((protocol) == TCPIP_PROTOCOL_TCP) || ((protocol) == TCPIP_PROTOCOL_GRE) || ((protocol) == TCPIP_PROTOCOL_PPTP))
  72. #define IS_SESSION_PKT(protocol) (IS_TCP_PKT(protocol) || ((protocol) == TCPIP_PROTOCOL_IPSEC1))
  73. #if defined (NLB_TCP_NOTIFICATION)
  74. #define GET_LOAD_LOCK(lp) (&((PMAIN_CTXT)(CONTAINING_RECORD((lp), MAIN_CTXT, load)))->load_lock)
  75. #endif
  76. /* Bitmap for teaming, which is of the form:
  77. -------------------------------------
  78. |XXXXXXXX|PPPPPPPP|PPPPPPPP|NNNNNHMA|
  79. -------------------------------------
  80. X: Reserved
  81. P: XOR of the least significant 16 bits of each participant
  82. N: Number of participants
  83. H: Hashing (Reverse=1, Normal=0)
  84. M: Master (Yes=1, No=0)
  85. A: Teaming active (Yes=1, No=0)
  86. */
  87. #define CVY_BDA_TEAMING_CODE_ACTIVE_OFFSET 0
  88. #define CVY_BDA_TEAMING_CODE_MASTER_OFFSET 1
  89. #define CVY_BDA_TEAMING_CODE_HASHING_OFFSET 2
  90. #define CVY_BDA_TEAMING_CODE_NUM_MEMBERS_OFFSET 3
  91. #define CVY_BDA_TEAMING_CODE_MEMBERS_OFFSET 8
  92. #define CVY_BDA_TEAMING_CODE_ACTIVE_MASK 0x00000001
  93. #define CVY_BDA_TEAMING_CODE_MASTER_MASK 0x00000002
  94. #define CVY_BDA_TEAMING_CODE_HASHING_MASK 0x00000004
  95. #define CVY_BDA_TEAMING_CODE_NUM_MEMBERS_MASK 0x000000f8
  96. #define CVY_BDA_TEAMING_CODE_MEMBERS_MASK 0x00ffff00
  97. #define CVY_BDA_TEAMING_CODE_CREATE(code,active,master,hashing,num,members) \
  98. (code) |= ((active) << CVY_BDA_TEAMING_CODE_ACTIVE_OFFSET) & CVY_BDA_TEAMING_CODE_ACTIVE_MASK; \
  99. (code) |= ((master) << CVY_BDA_TEAMING_CODE_MASTER_OFFSET) & CVY_BDA_TEAMING_CODE_MASTER_MASK; \
  100. (code) |= ((hashing) << CVY_BDA_TEAMING_CODE_HASHING_OFFSET) & CVY_BDA_TEAMING_CODE_HASHING_MASK; \
  101. (code) |= ((num) << CVY_BDA_TEAMING_CODE_NUM_MEMBERS_OFFSET) & CVY_BDA_TEAMING_CODE_NUM_MEMBERS_MASK; \
  102. (code) |= ((members) << CVY_BDA_TEAMING_CODE_MEMBERS_OFFSET) & CVY_BDA_TEAMING_CODE_MEMBERS_MASK;
  103. #define CVY_BDA_TEAMING_CODE_RETRIEVE(code,active,master,hashing,num,members) \
  104. active = (code & CVY_BDA_TEAMING_CODE_ACTIVE_MASK) >> CVY_BDA_TEAMING_CODE_ACTIVE_OFFSET; \
  105. master = (code & CVY_BDA_TEAMING_CODE_MASTER_MASK) >> CVY_BDA_TEAMING_CODE_MASTER_OFFSET; \
  106. hashing = (code & CVY_BDA_TEAMING_CODE_HASHING_MASK) >> CVY_BDA_TEAMING_CODE_HASHING_OFFSET; \
  107. num = (code & CVY_BDA_TEAMING_CODE_NUM_MEMBERS_MASK) >> CVY_BDA_TEAMING_CODE_NUM_MEMBERS_OFFSET; \
  108. members = (code & CVY_BDA_TEAMING_CODE_MEMBERS_MASK) >> CVY_BDA_TEAMING_CODE_MEMBERS_OFFSET;
  109. /* DATA STRUCTURES */
  110. /* type for a bin map (V2.04) */
  111. typedef ULONGLONG MAP_T, * PMAP_T;
  112. /* state for all bins within a port group */
  113. typedef struct {
  114. ULONG index; /* index in array of bin states */
  115. ULONG code; /* type checking code (bbain 8/17/99) */
  116. MAP_T targ_map; /* new target load map for local host */
  117. MAP_T all_idle_map; /* map of bins idle in all other hosts */
  118. MAP_T cmap; /* cache of cur_map for this host (v2.1) */
  119. MAP_T new_map[CVY_MAX_HOSTS]; /* new map for hosts while converging */
  120. MAP_T cur_map[CVY_MAX_HOSTS]; /* current ownership mask per host */
  121. MAP_T chk_map[CVY_MAX_HOSTS]; /* map of cur & rdy bins for all hosts */
  122. /* used as a check for coverage */
  123. MAP_T idle_map[CVY_MAX_HOSTS]; /* map of idle bins per host */
  124. BOOLEAN initialized; /* TRUE => port group has been initialized (v2.06) */
  125. BOOLEAN compatible; /* TRUE => detected that rule codes do not match */
  126. BOOLEAN equal_bal; /* TRUE => all hosts balance evenly */
  127. USHORT affinity; /* TRUE => client affinity for this port */
  128. ULONG mode; /* processing mode */
  129. ULONG prot; /* protocol */
  130. ULONG tot_load; /* total load percentages for all hosts */
  131. ULONG orig_load_amt; /* original load amt. for this host */
  132. ULONG load_amt[CVY_MAX_HOSTS]; /* multi: load percentages per host
  133. single: host priorities (1..CVY_MAXHOSTS)
  134. equal: 100
  135. dead: 0 */
  136. MAP_T snd_bins; /* local bins to send when ready */
  137. MAP_T rcv_bins; /* remote bins to receive when ready */
  138. MAP_T rdy_bins; /* snd bins that are ready to send
  139. or have been sent but not acknowledged */
  140. MAP_T idle_bins; /* bins with no connections active */
  141. LONG tconn; /* total # active local connections (v2.06) */
  142. LONG nconn[CVY_MAXBINS]; /* # active local connections per bin */
  143. QUEUE connq; /* queue of active connections on all bins */
  144. /* Some performance counters. */
  145. ULONGLONG packets_accepted; /* The number of packets accepted by this host on this port rule. */
  146. ULONGLONG packets_dropped; /* The number of packets dropped by this host on this port rule. */
  147. ULONGLONG bytes_accepted; /* The number of bytes accepted by this host on this port rule. */
  148. ULONGLONG bytes_dropped; /* The number of bytes dropped by this host on this port rule. */
  149. } BIN_STATE, * PBIN_STATE;
  150. /* ping message */
  151. #pragma pack(1)
  152. typedef struct {
  153. USHORT host_id; /* my host id */
  154. USHORT master_id; /* current master host id */
  155. USHORT state; /* my host's state */
  156. USHORT nrules; /* # active rules */
  157. ULONG hcode; /* unique host code */
  158. ULONG pkt_count; /* count of packets handled since cvg'd (1.32B) */
  159. ULONG teaming; /* BDA teaming configuraiton information. */
  160. ULONG reserved; /* unused. */
  161. ULONG rcode[CVY_MAX_RULES]; /* rule code */
  162. MAP_T cur_map[CVY_MAX_RULES]; /* my current load map for each port group */
  163. MAP_T new_map[CVY_MAX_RULES]; /* my new load map for each port group */
  164. /* if converging */
  165. MAP_T idle_map[CVY_MAX_RULES]; /* map of idle bins for each port group */
  166. MAP_T rdy_bins[CVY_MAX_RULES]; /* my rdy to send bins for each port group */
  167. ULONG load_amt[CVY_MAX_RULES]; /* my load amount for each port group */
  168. ULONG pg_rsvd1[CVY_MAX_RULES]; /* reserved */
  169. } PING_MSG, * PPING_MSG;
  170. /* Connection entry flags. */
  171. #define NLB_CONN_ENTRY_FLAGS_USED 0x0001 /* Whether or not the descriptor is currently in use. */
  172. #define NLB_CONN_ENTRY_FLAGS_DIRTY 0x0002 /* Whether or not the descriptor is DIRTY. */
  173. #define NLB_CONN_ENTRY_FLAGS_ALLOCATED 0x0004 /* Whether or not the descriptor was dynamically allocated. */
  174. #define NLB_CONN_ENTRY_FLAGS_VIRTUAL 0x0008 /* Whether or not the descriptor is virtual. */
  175. #pragma pack()
  176. /* unique connection entry */
  177. typedef struct {
  178. LINK blink; /* Link into bin queue or dirty queue. */
  179. LINK rlink; /* Link into the recovery or expired queue. */
  180. #if defined (NLB_TCP_NOTIFICATION)
  181. LINK glink; /* Link into the global established queue. */
  182. PVOID load; /* A pointer to the load module on which this descriptor belongs. */
  183. #endif
  184. ULONG code; /* Type checking code. */
  185. ULONG timeout; /* The time at which this descriptor expires (clock_sec + lifetime). */
  186. USHORT flags; /* Flags => alloc, dirty, used, etc. */
  187. UCHAR bin; /* The bin number this connection belongs on. */
  188. UCHAR protocol; /* The protocol type for this descriptor - we no
  189. longer use descriptors only for TCP connections. */
  190. ULONG client_ipaddr; /* The client IP address. */
  191. ULONG svr_ipaddr; /* The server IP address. */
  192. USHORT client_port; /* The client port. */
  193. USHORT svr_port; /* The server port. */
  194. SHORT ref_count; /* The number of references on this descriptor. */
  195. USHORT index; /* The connection queue index. */
  196. } CONN_ENTRY, * PCONN_ENTRY;
  197. /* connection descriptor */
  198. typedef struct {
  199. LINK link; /* Link into free descriptor pool or hash table queue. */
  200. ULONG code; /* Type checking code. */
  201. CONN_ENTRY entry; /* The connection entry. */
  202. } CONN_DESCR, * PCONN_DESCR;
  203. #if defined (NLB_TCP_NOTIFICATION)
  204. typedef struct {
  205. LINK link; /* Link into the global pending queue. */
  206. ULONG code; /* Type checking code. */
  207. ULONG client_ipaddr; /* The client IP address. */
  208. ULONG svr_ipaddr; /* The server IP address. */
  209. USHORT client_port; /* The client port. */
  210. USHORT svr_port; /* The server port. */
  211. UCHAR protocol; /* The IP protocol. */
  212. } PENDING_ENTRY, * PPENDING_ENTRY;
  213. typedef struct {
  214. NDIS_SPIN_LOCK lock; /* A lock to protect access to the queue. */
  215. ULONG length; /* The length of the queue - for debugging purposes. */
  216. QUEUE queue; /* The connection entry queue. */
  217. } GLOBAL_CONN_QUEUE, * PGLOBAL_CONN_QUEUE;
  218. #endif
  219. /* load module's context */
  220. typedef struct {
  221. ULONG ref_count; /* The reference count on this load module. */
  222. ULONG my_host_id; /* local host id and priority MINUS one */
  223. ULONG code; /* type checking code (bbain 8/17/99) */
  224. PING_MSG send_msg; /* current message to send */
  225. #ifndef KERNEL_MODE /* 1.03: Removed kernel mode locking in this module */
  226. SPINLOCK lock; /* lock for mutual exclusion */
  227. #endif
  228. ULONG def_timeout, /* default timeout in msec */
  229. cur_timeout; /* current timeout in msec */
  230. ULONG cln_timeout; /* cleanup timeout in msec */
  231. ULONG cur_time; /* current time waiting for cleanup */
  232. ULONG host_map, /* map of currently active hosts */
  233. ping_map, /* map of currently pinged hosts */
  234. min_missed_pings, /* # missed pings to trigger host dead */
  235. pkt_count; /* count of packets handled since cvg'd (1.32B) */
  236. ULONG last_hmap; /* host map after last convergence (bbain RTM RC1 6/23/99) */
  237. ULONG nmissed_pings[CVY_MAX_HOSTS];
  238. /* missed ping count for each host */
  239. BOOLEAN initialized; /* TRUE => this module has been initialized */
  240. BOOLEAN active; /* TRUE => this module is active */
  241. BOOLEAN consistent; /* TRUE => this host has seen consistent
  242. information from other hosts */
  243. ULONG legacy_hosts; /* a host map of legacy (win2k/NT4.0) hosts in the cluster. */
  244. BOOLEAN bad_team_config; /* TRUE => inconsistent BDA teaming configuration detected. */
  245. BOOLEAN dup_hosts; /* TRUE => duplicate host id's seen */
  246. BOOLEAN dup_sspri; /* TRUE => duplicate single server
  247. priorities seen */
  248. BOOLEAN bad_map; /* TRUE => bad new map detected */
  249. BOOLEAN overlap_maps; /* TRUE => overlapping maps detected */
  250. BOOLEAN err_rcving_bins; /* TRUE => error receiving bins detected */
  251. BOOLEAN err_orphans; /* TRUE => orphan bins detected */
  252. BOOLEAN bad_num_rules; /* TRUE => different number of rules seen */
  253. BOOLEAN alloc_inhibited; /* TRUE => inhibited malloc of conn's. */
  254. BOOLEAN alloc_failed; /* TRUE => malloc failed */
  255. BOOLEAN bad_defrule; /* TRUE => invalid default rule detected */
  256. BOOLEAN scale_client; /* TRUE => scale client requests;
  257. FALSE => hash all client requests to one
  258. server host */
  259. BOOLEAN cln_waiting; /* TRUE => waiting for cleanup (v1.32B) */
  260. ULONG num_dirty; /* Total number of dirty connections. */
  261. ULONG dirty_bin[CVY_MAXBINS]; /* Count of dirty connections per bin. */
  262. ULONG stable_map; /* map of stable hosts */
  263. ULONG min_stable_ct; /* min needed # of timeouts with stable
  264. condition */
  265. ULONG my_stable_ct; /* count of timeouts locally stable */
  266. ULONG all_stable_ct; /* count of timeouts with all stable
  267. condition */
  268. LONG nconn; /* # active conns across all port rules (v2.1) */
  269. ULONG dscr_per_alloc; /* # conn. descriptors per allocation */
  270. ULONG max_dscr_allocs; /* max # descriptor allocations */
  271. ULONG num_dscr_out; /* number of outstanding descriptors (in use). */
  272. ULONG max_dscr_out; /* maximum number of outstanding descriptors (in use) allowed. */
  273. HANDLE free_dscr_pool; /* FSB descriptor pool handle. */
  274. BIN_STATE pg_state[CVY_MAX_RULES]; /* bin state for all active rules */
  275. CONN_ENTRY hashed_conn[CVY_MAX_CHASH]; /* hashed connection entries */
  276. QUEUE connq[CVY_MAX_CHASH]; /* queues for overloaded hashed conn's. */
  277. QUEUE conn_dirtyq; /* queue of dirty connection entries (v1.32B) */
  278. QUEUE conn_rcvryq; /* connection recover queue V2.1.5 */
  279. /* NOTE: This general clock mechanism should be moved out to MAIN_CTXT and maintained by main.c
  280. for use by both the load module and main module. The load module uses it for things like
  281. timing out descriptors and the main module should use it for things like IGMP, cluster IP
  282. change and descriptor cleanup timeouts. */
  283. ULONG clock_sec; /* internal clock (sec) used for timing out descriptors. This clock is used to
  284. count seconds from the time the load module started, which will cause this
  285. to overflow in approximately 132 years if the machine stayed alive with NLB
  286. running constantly. */
  287. ULONG clock_msec; /* internal clock (msec w/in a sec) used for timing out descriptors. */
  288. QUEUE tcp_expiredq; /* expired TCP connection descriptor queue */
  289. QUEUE ipsec_expiredq; /* expired IPSec connection descriptor queue */
  290. ULONG tcp_timeout; /* TCP connection descriptor timeout. */
  291. ULONG ipsec_timeout; /* IPSec connection descriptor timeout. */
  292. ULONG num_convergences; /* The total number of convergences since we joined the cluster. */
  293. ULONG last_convergence; /* The time of the last convergence. */
  294. PCVY_PARAMS params; /* pointer to the global parameters */
  295. } LOAD_CTXT, * PLOAD_CTXT;
  296. #if defined (NLB_TCP_NOTIFICATION)
  297. #define CVY_PENDING_MATCH(pp, sa, sp, ca, cp, prot) ((pp)->client_ipaddr == (ca) && \
  298. (pp)->client_port == ((USHORT)(cp)) && \
  299. (pp)->svr_ipaddr == (sa) && \
  300. (pp)->svr_port == ((USHORT)(sp)) && \
  301. (pp)->protocol == ((UCHAR)(prot)))
  302. #define CVY_PENDING_SET(pp, sa, sp, ca, cp, prot) { \
  303. (pp)->svr_ipaddr = (sa); \
  304. (pp)->svr_port = (USHORT)(sp); \
  305. (pp)->client_ipaddr = (ca); \
  306. (pp)->client_port = (USHORT)(cp); \
  307. (pp)->protocol = (UCHAR)(prot); \
  308. }
  309. #endif
  310. /* FUNCTIONS */
  311. /* Load Module Functions */
  312. #define CVY_CONN_MATCH(ep, sa, sp, ca, cp, prot) (((ep)->flags & NLB_CONN_ENTRY_FLAGS_USED) && \
  313. (ep)->client_ipaddr == (ca) && \
  314. (ep)->client_port == ((USHORT)(cp)) && \
  315. (ep)->svr_ipaddr == (sa) && \
  316. (ep)->svr_port == ((USHORT)(sp)) && \
  317. (ep)->protocol == ((UCHAR)(prot)))
  318. /*
  319. Determine if a connection entry matches supplied parameters
  320. */
  321. #define CVY_CONN_SET(ep, sa, sp, ca, cp, prot) { \
  322. (ep)->svr_ipaddr = (sa); \
  323. (ep)->svr_port = (USHORT)(sp); \
  324. (ep)->client_ipaddr = (ca); \
  325. (ep)->client_port = (USHORT)(cp); \
  326. (ep)->protocol = (UCHAR)(prot); \
  327. (ep)->flags |= NLB_CONN_ENTRY_FLAGS_USED; \
  328. }
  329. /*
  330. Sets up a connection entry for the supplied parameters
  331. */
  332. #define CVY_CONN_IN_USE(ep) ((ep)->flags & NLB_CONN_ENTRY_FLAGS_USED)
  333. /*
  334. Checks if connection entry is in use
  335. */
  336. #define CVY_CONN_CLEAR(ep) { ((ep)->flags &= ~NLB_CONN_ENTRY_FLAGS_USED); }
  337. /*
  338. Clears a connection entry
  339. */
  340. extern BOOLEAN Load_start(
  341. PLOAD_CTXT lp);
  342. /*
  343. Start load module
  344. function:
  345. Starts load module after previously initialized or stopped.
  346. returns: Was convergence initiated ?
  347. */
  348. extern void Load_stop(
  349. PLOAD_CTXT lp);
  350. /*
  351. Stop load module
  352. function:
  353. Stops load module after previously initialized or started.
  354. */
  355. extern void Load_init(
  356. PLOAD_CTXT lp,
  357. PCVY_PARAMS params);
  358. /*
  359. Initialize load module
  360. function:
  361. Initializes the load module for the first time.
  362. */
  363. extern void Load_cleanup( /* (bbain 2/25/99) */
  364. PLOAD_CTXT lp);
  365. /*
  366. Cleanup load module
  367. function:
  368. Cleans up the load module by releasing dynamically allocated memory.
  369. */
  370. extern BOOLEAN Load_msg_rcv(
  371. PLOAD_CTXT lp,
  372. PVOID phdr,
  373. PPING_MSG pmsg); /* ptr. to ping message */
  374. /*
  375. Receive a ping message
  376. */
  377. extern PPING_MSG Load_snd_msg_get(
  378. PLOAD_CTXT lp);
  379. /*
  380. Get local ping message to send
  381. returns PPING_MSG:
  382. <ptr. to ping message to send>
  383. */
  384. extern BOOLEAN Load_timeout(
  385. PLOAD_CTXT lp,
  386. PULONG new_timeout,
  387. PULONG pnconn); /* ptr. to # active conns across all port rules (v2.1) */
  388. /*
  389. Handle timeout
  390. returns BOOLEAN:
  391. TRUE => host is attached to the network
  392. FALSE => host lost network connection
  393. */
  394. extern ULONG Load_port_change(
  395. PLOAD_CTXT lp,
  396. ULONG ipaddr,
  397. ULONG port,
  398. ULONG cmd, /* enable, disable, set value */
  399. ULONG value);
  400. /*
  401. Enable or disable traffic handling for a rule containing specified port
  402. returns ULONG:
  403. IOCTL_CVY_OK => port handling changed
  404. IOCTL_CVY_NOT_FOUND => rule for this port was found
  405. IOCTL_CVY_ALREADY => port handling was previously completed
  406. */
  407. extern ULONG Load_hosts_query(
  408. PLOAD_CTXT lp,
  409. BOOLEAN internal,
  410. PULONG host_map);
  411. /*
  412. Log and return current host map
  413. returns ULONG:
  414. <one of IOCTL_CVY_...state defined in params.h>
  415. */
  416. /*
  417. * Function: Load_packet_check
  418. * Description: This function determines whether or not to take a data packet
  419. * in the IP stream identified by the IP tuple in question.
  420. * Protocols that are session-less depend only on the hashing
  421. * result and the ownership map. Session-ful protocols may need
  422. * to perform a descriptor look-up if ambiguity exists.
  423. * Parameters: lp - a pointer to the load module context (LOAD_CTXT)
  424. * svr_ipaddr - the server IP address in network byte order
  425. * svr_port - the server port in host byte order
  426. * client_ipaddr - the client IP address in network byte order
  427. * client_port - the client port in host byte order
  428. * protocol - the protocol of this connection
  429. * limit_map_fn - whether or not to include server-side parameters in hashing
  430. * reverse_hash - whether or not to reverse client and server during hashing
  431. * Returns: BOOLEAN - do we accept the packet? (TRUE = yes)
  432. * Author: bbain, shouse, 10.4.01
  433. * Notes:
  434. */
  435. extern BOOLEAN Load_packet_check(
  436. PLOAD_CTXT lp,
  437. ULONG svr_ipaddr,
  438. ULONG svr_port,
  439. ULONG client_ipaddr,
  440. ULONG client_port,
  441. USHORT protocol,
  442. BOOLEAN limit_map_fn,
  443. BOOLEAN reverse_hash);
  444. /*
  445. * Function: Load_conn_advise
  446. * Description: This function determines whether or not to accept this packet,
  447. * which represents the beginning or end of a session-ful connection.
  448. * If the connection is going up, and is successful, this function
  449. * creates state to track the connection. If the connection is
  450. * going down, this function removes the state for tracking the
  451. * connection.
  452. * Parameters: lp - a pointer to the load module context (LOAD_CTXT)
  453. * svr_ipaddr - the server IP address in network byte order
  454. * svr_port - the server port in host byte order
  455. * client_ipaddr - the client IP address in network byte order
  456. * client_port - the client port in host byte order
  457. * protocol - the protocol of this connection
  458. * conn_status - whether the connection is going UP, DOWN, or being RESET
  459. * limit_map_fn - whether or not to include server-side parameters in hashing
  460. * reverse_hash - whether or not to reverse client and server during hashing
  461. * Returns: BOOLEAN - do we accept the packet (TRUE = yes)
  462. * Author: bbain, shouse, 10.4.01
  463. * Notes:
  464. */
  465. extern BOOLEAN Load_conn_advise(
  466. PLOAD_CTXT lp,
  467. ULONG svr_ipaddr,
  468. ULONG svr_port,
  469. ULONG client_ipaddr,
  470. ULONG client_port,
  471. USHORT protocol,
  472. ULONG conn_status,
  473. BOOLEAN limit_map_fn,
  474. BOOLEAN reverse_hash);
  475. /*
  476. * Function: Load_add_reference
  477. * Description: Adds a reference to the load module to keep it from disappearing while in use.
  478. * Parameters: pLoad - a pointer to the load module context.
  479. * Returns: ULONG - the updated number of references.
  480. * Author: shouse, 3.29.01
  481. * Notes:
  482. */
  483. extern ULONG Load_add_reference (IN PLOAD_CTXT pLoad);
  484. /*
  485. * Function: Load_release_reference
  486. * Description: Releases a reference on the load module.
  487. * Parameters: pLoad - a pointer to the load module context.
  488. * Returns: ULONG - the updated number of references.
  489. * Author: shouse, 3.29.01
  490. * Notes:
  491. */
  492. extern ULONG Load_release_reference (IN PLOAD_CTXT pLoad);
  493. /*
  494. * Function: Load_get_reference_count
  495. * Description: Returns the current number of references on the given load module.
  496. * Parameters: pLoad - a pointer to the load module context.
  497. * Returns: ULONG - the current number of references.
  498. * Author: shouse, 3.29.01
  499. * Notes:
  500. */
  501. extern ULONG Load_get_reference_count (IN PLOAD_CTXT pLoad);
  502. /*
  503. * Function: Load_query_packet_filter
  504. * Description: This function takes a IP tuple and protocol and consults the load-
  505. * balancing state to determine whether or not this packet would be
  506. * accepted by the load module. In either case, the reason for the
  507. * decision is also provided, plus, in most cases, some of the load
  508. * module state is also returned to provide some context to justify
  509. * the decision. This function is COMPLETELY unobtrusive and makes
  510. * NO changes to the actual state of the load module.
  511. * Parameters: lp - a pointer to the load module.
  512. * pQuery - a pointer to a buffer into which the results are placed.
  513. * svr_ipaddr - the server side IP address of this virtual packet.
  514. * svr_port - the server side port of this virtual packet.
  515. * client_ipaddr - the client side IP address of this virtual packet.
  516. * client_ipaddr - the client side port of this virtual packet.
  517. * protocol - the protocol of this virtual packet (UDP, TCP or IPSec1).
  518. * limit_map_fin - a boolean indication of whether or not to use server
  519. * side parameters in the Map function. This is controlled
  520. * by BDA teaming.
  521. * reverse_hash - whether or not to reverse client and server during hashing
  522. * Returns: Nothing.
  523. * Author: shouse, 5.18.01
  524. * Notes: This function is only observatory and makes NO changes to the state of
  525. * the load module.
  526. */
  527. extern VOID Load_query_packet_filter
  528. (
  529. PLOAD_CTXT lp,
  530. PNLB_OPTIONS_PACKET_FILTER pQuery,
  531. ULONG svr_ipaddr,
  532. ULONG svr_port,
  533. ULONG client_ipaddr,
  534. ULONG client_port,
  535. USHORT protocol,
  536. UCHAR flags,
  537. BOOLEAN limit_map_fn,
  538. BOOLEAN reverse_hash);
  539. /*
  540. * Function: Load_query_port_state
  541. * Description: Queries the load module for the current state (enabled/disabled/draining) of a port rule.
  542. * Parameters: lp - a pointer to the load module context.
  543. * pQuery - pointer to the input and output buffer for the query.
  544. * ipaddr - the VIP associated with the port rule.
  545. * port - a port in the range of the port rule.
  546. * Returns: Nothing.
  547. * Author: shouse, 5.18.01
  548. * Notes:
  549. */
  550. extern VOID Load_query_port_state
  551. (
  552. PLOAD_CTXT lp,
  553. PNLB_OPTIONS_PORT_RULE_STATE pQuery,
  554. ULONG ipaddr,
  555. USHORT port);
  556. /*
  557. * Function: Load_query_convergence_info
  558. * Description: Queries the load module for the convergence statistics
  559. * Parameters: lp - a pointer to the load module context.
  560. * OUT num_cvgs - a pointer to a ULONG to hold the total number of convergences on this host.
  561. * OUT last_cvg - a pointer to a ULONG to hold the time since the last convergence completed.
  562. * Returns: BOOLEAN - whether or not the load module is active. If TRUE, then the OUT params were filled in.
  563. * Author: shouse, 10.30.01
  564. * Notes:
  565. */
  566. extern BOOLEAN Load_query_convergence_info (PLOAD_CTXT lp, PULONG num_cvgs, PULONG last_cvg);
  567. /*
  568. * Function: Load_query_statistics
  569. * Description: Queries the load module for some relevant statisitics
  570. * Parameters: lp - a pointer to the load module context.
  571. * OUT num_cvgs - a pointer to a ULONG to hold the current number of active connections
  572. * OUT last_cvg - a pointer to a ULONG to hold the total number of descriptors allocated thusfar
  573. * Returns: BOOLEAN - whether or not the load module is active. If TRUE, then the OUT params were filled in.
  574. * Author: shouse, 4.19.02
  575. * Notes:
  576. */
  577. extern BOOLEAN Load_query_statistics (PLOAD_CTXT lp, PULONG num_conn, PULONG num_dscr);
  578. /*
  579. * Function: Load_conn_get
  580. * Description: This function returns the connection parameters for the descriptor
  581. * at the head of the recovery queue, if one exists. The recovery
  582. * queue holds all "active" connections, some of which may be stale.
  583. * If an active descriptor exists, it fills in the connection info
  584. * and returns TRUE to indicate success; otherwise it returns FALSE
  585. * to indicate that no connection was found.
  586. * Parameters: lp - a pointer to the load module context (LOAD_CTXT)
  587. * OUT svr_ipaddr - the server IP address in network byte order
  588. * OUT svr_port - the server port in host byte order
  589. * OUT client_ipaddr - the client IP address in network byte order
  590. * OUT client_port - the client port in host byte order
  591. * OUT protocol - the protocol of this connection
  592. * Returns: BOOLEAN -
  593. * Author: shouse, 10.4.01
  594. * Notes:
  595. */
  596. extern BOOLEAN Load_conn_get (PLOAD_CTXT lp, PULONG svr_ipaddr, PULONG svr_port, PULONG client_ipaddr, PULONG client_port, PUSHORT protocol);
  597. /*
  598. * Function: Load_conn_sanction
  599. * Description: This function is called to "sanction" an active connection descriptor.
  600. * Sanction means that NLB has verified that this connection is indeed
  601. * still active by querying other system entities (such as TCP/IP). To
  602. * sanction a descriptor simply involves moving it from its place in the
  603. * recovery queue (should be the head in most cases) to the tail of the
  604. * recovery queue, where it has the least chance of being cannibalized.
  605. * Parameters: lp - a pointer to the load module context (LOAD_CTXT)
  606. * svr_ipaddr - the server IP address in network byte order
  607. * svr_port - the server port in host byte order
  608. * client_ipaddr - the client IP address in network byte order
  609. * client_port - the client port in host byte order
  610. * protocol - the protocol of this connection
  611. * Returns: BOOLEAN - was i successful in approbating the descriptor? (TRUE = yes)
  612. * Author: shouse, 10.4.01
  613. * Notes:
  614. */
  615. extern BOOLEAN Load_conn_sanction (PLOAD_CTXT lp, ULONG svr_ipaddr, ULONG svr_port, ULONG client_ipaddr, ULONG client_port, USHORT protocol);
  616. /*
  617. * Function: Load_conn_notify
  618. * Description: This function is nearly identical to Load_conn_advise, except
  619. * for two important distinctions; (1) this function is a notification,
  620. * not a request, so load-balancing decisions are not made here, and
  621. * (2) packet handling statistics are not incremented here, as calls
  622. * to this function rarely stem from processing a real packet. For
  623. * example, when a TCP SYN packet is received, main.c calls Load_conn_advise
  624. * essentially asking, "hey, should accept this new connection i just
  625. * saw?" While, when IPSec notifies NLB that a new Main Mode SA has just
  626. * been established, main.c calls Load_conn_notify essentially dictating,
  627. * "hey a new connection just went up, so whether you like it or not,
  628. * create state to track this connection."
  629. * Parameters: lp - a pointer to the load module context (LOAD_CTXT)
  630. * svr_ipaddr - the server IP address in network byte order
  631. * svr_port - the server port in host byte order
  632. * client_ipaddr - the client IP address in network byte order
  633. * client_port - the client port in host byte order
  634. * protocol - the protocol of this connection
  635. * conn_status - whether the connection is going UP, DOWN, or being RESET
  636. * limit_map_fn - whether or not to include server-side parameters in hashing
  637. * reverse_hash - whether or not to reverse client and server during hashing
  638. * Returns: BOOLEAN - was i able to successfully update my state (TRUE = yes)
  639. * Author: shouse, 10.4.01
  640. * Notes:
  641. */
  642. extern BOOLEAN Load_conn_notify (
  643. PLOAD_CTXT lp,
  644. ULONG svr_ipaddr,
  645. ULONG svr_port,
  646. ULONG client_ipaddr,
  647. ULONG client_port,
  648. USHORT protocol,
  649. ULONG conn_status,
  650. BOOLEAN limit_map_fn,
  651. BOOLEAN reverse_hash);
  652. #if defined (NLB_TCP_NOTIFICATION)
  653. /*
  654. * Function: Load_conn_up
  655. * Description: This function is called to create state to track a connection (usually TCP
  656. * or IPSec/L2TP). This is not a function to ask the load module whether or
  657. * not to accept a packet, rather it is a request to create state to track a
  658. * connection that is being established.
  659. * Parameters: lp - a pointer to the load module context (LOAD_CTXT)
  660. * svr_ipaddr - the server IP address in network byte order
  661. * svr_port - the server port in host byte order
  662. * client_ipaddr - the client IP address in network byte order
  663. * client_port - the client port in host byte order
  664. * protocol - the protocol of this connection
  665. * limit_map_fn - whether or not to include server-side parameters in hashing
  666. * reverse_hash - whether or not to reverse client and server during hashing
  667. * Returns: BOOLEAN - whether or not state was successfully created to track this connection.
  668. * Author: shouse, 4.15.02
  669. * Notes: DO NOT CALL THIS FUNCTION WITH THE LOAD LOCK HELD.
  670. */
  671. BOOLEAN Load_conn_up (
  672. PLOAD_CTXT lp,
  673. ULONG svr_ipaddr,
  674. ULONG svr_port,
  675. ULONG client_ipaddr,
  676. ULONG client_port,
  677. USHORT protocol,
  678. BOOLEAN limit_map_fn,
  679. BOOLEAN reverse_hash);
  680. /*
  681. * Function: Load_conn_down
  682. * Description: This function is called to destroy the state being used to track an existing
  683. * connection (usually TCP or IPSec/L2TP). If state for the given 5-tuple is
  684. * found, it is de-referenced and destroyed if appropriate (based partially on
  685. * the conn_status). If state is not found, FALSE is returned, but it not
  686. * considered a catastrophic error. In the case of TCP notifications, perhaps
  687. * the connection was not even established across a NLB NIC.
  688. * Parameters: svr_ipaddr - the server IP address in network byte order
  689. * svr_port - the server port in host byte order
  690. * client_ipaddr - the client IP address in network byte order
  691. * client_port - the client port in host byte order
  692. * protocol - the protocol of this connection
  693. * conn_status - whether the connection is going DOWN or being RESET
  694. * Returns: BOOLEAN - whether or not the connection state was found and updated.
  695. * Author: shouse, 4.15.02
  696. * Notes: DO NOT CALL THIS FUNCTION WITH THE LOAD LOCK HELD.
  697. */
  698. BOOLEAN Load_conn_down (
  699. ULONG svr_ipaddr,
  700. ULONG svr_port,
  701. ULONG client_ipaddr,
  702. ULONG client_port,
  703. USHORT protocol,
  704. ULONG conn_status);
  705. /*
  706. * Function: Load_conn_pending
  707. * Description: This function is called to create state for a pending OUTGOING connection on
  708. * the server. Because at this time, it is unknown on what interface the connection
  709. * will ultimately be established, NLB creates global state to track the connection
  710. * only until it is established. For TCP, when the SYN+ACK arrives from the peer,
  711. * we only accept it if we find a match in our pending connection queues. When the
  712. * connection is established, this state is destroyed and new state is created to
  713. * track the connection is appropriate.
  714. * Parameters: svr_ipaddr - the server IP address in network byte order
  715. * svr_port - the server port in host byte order
  716. * client_ipaddr - the client IP address in network byte order
  717. * client_port - the client port in host byte order
  718. * protocol - the protocol of this connection
  719. * Returns: BOOLEAN - whether or not state was successfully created to track this pending connection.
  720. * Author: shouse, 4.15.02
  721. * Notes: DO NOT CALL THIS FUNCTION WITH THE LOAD LOCK HELD.
  722. */
  723. BOOLEAN Load_conn_pending (
  724. ULONG svr_ipaddr,
  725. ULONG svr_port,
  726. ULONG client_ipaddr,
  727. ULONG client_port,
  728. USHORT protocol);
  729. /*
  730. * Function: Load_pending_check
  731. * Description: This function is called to determine whether or not state exists in the pending
  732. * connection queues for this connection. If it does, the packet should be accepted.
  733. * If no state exists, the packet should be dropped.
  734. * Parameters: svr_ipaddr - the server IP address in network byte order
  735. * svr_port - the server port in host byte order
  736. * client_ipaddr - the client IP address in network byte order
  737. * client_port - the client port in host byte order
  738. * protocol - the protocol of this connection
  739. * Returns: BOOLEAN - whether or not to accept the packet.
  740. * Author: shouse, 4.15.02
  741. * Notes: DO NOT CALL THIS FUNCTION WITH THE LOAD LOCK HELD.
  742. */
  743. BOOLEAN Load_pending_check (
  744. ULONG svr_ipaddr,
  745. ULONG svr_port,
  746. ULONG client_ipaddr,
  747. ULONG client_port,
  748. USHORT protocol);
  749. /*
  750. * Function: Load_conn_establish
  751. * Description: This function is invoked when a pending connection has become established.
  752. * When the pending connection is established, its state in the pending
  753. * connection queues is destroyed. If the connection was ultimately established
  754. * on an NLB adapter (if lp != NULL), then state will be created to track this
  755. * new connection. Otherwise, the operation consists only of destroying the
  756. * pending connection state.
  757. * Parameters: lp - a pointer to the load module context (LOAD_CTXT)
  758. * svr_ipaddr - the server IP address in network byte order
  759. * svr_port - the server port in host byte order
  760. * client_ipaddr - the client IP address in network byte order
  761. * client_port - the client port in host byte order
  762. * protocol - the protocol of this connection
  763. * limit_map_fn - whether or not to include server-side parameters in hashing
  764. * reverse_hash - whether or not to reverse client and server during hashing
  765. * Returns: BOOLEAN - whether or not the operation was successfully completed.
  766. * Author: shouse, 4.15.02
  767. * Notes: DO NOT CALL THIS FUNCTION WITH THE LOAD LOCK HELD.
  768. */
  769. BOOLEAN Load_conn_establish (
  770. PLOAD_CTXT lp,
  771. ULONG svr_ipaddr,
  772. ULONG svr_port,
  773. ULONG client_ipaddr,
  774. ULONG client_port,
  775. USHORT protocol,
  776. BOOLEAN limit_map_fn,
  777. BOOLEAN reverse_hash);
  778. /*
  779. * Function: LoadEntry
  780. * Description: This function is called from DriverEntry to allow the load module to perform
  781. * any one-time intialization of global data.
  782. * Parameters: None.
  783. * Returns: Nothing.
  784. * Author: shouse, 4.21.02
  785. * Notes:
  786. */
  787. VOID LoadEntry ();
  788. /*
  789. * Function: LoadUnload
  790. * Description: This function is called from Init_unload to allow the load module to perform
  791. * any last minute tear-down of global data.
  792. * Parameters: None.
  793. * Returns: Nothing.
  794. * Author: shouse, 4.21.02
  795. * Notes: By the time this function is called, we are guaranteed to have de-registered
  796. * our TCP callback function, if it was indeed registered. Because ExUnregisterCallback
  797. * guarantees that it will not return until all pending ExNotifyCallback routines
  798. * have completed, we can be sure that by the time we get here, there will certainly
  799. * not be anybody accessing any of the global connection queues or FSB pools.
  800. */
  801. VOID LoadUnload ();
  802. #endif
  803. #endif /* _Load_h_ */