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.

496 lines
17 KiB

  1. #ifndef _RPL_
  2. #define _RPL_
  3. /*++
  4. Copyright (c) 1989 Microsoft Corporation
  5. Module Name:
  6. Abstract:
  7. Functions:
  8. Portability:
  9. This header is portable.
  10. Author:
  11. Pradeep Bahl (PradeepB) Jan-1993
  12. Revision History:
  13. Modification Date Person Description of Modification
  14. ------------------ ------- ---------------------------
  15. --*/
  16. /*
  17. includes
  18. */
  19. #include "wins.h"
  20. #include "comm.h"
  21. #include "nmsdb.h"
  22. #include "winsque.h"
  23. /*
  24. defines
  25. */
  26. /*
  27. RPL_OPCODE_SIZE -- size of opcode in message sent between two replicators.
  28. This define is used by rplmsgf
  29. */
  30. #define RPL_OPCODE_SIZE 4 //sizeof the Opcode in an RPL message
  31. /*
  32. The maximum numbers of RQ WINS on a network.
  33. */
  34. #define RPL_MAX_OWNERS_INITIALLY NMSDB_MAX_OWNERS_INITIALLY
  35. /*
  36. RPL_MAX_GRP_MEMBERS --
  37. Maximum members allowed in a group
  38. */
  39. #define RPL_MAX_GRP_MEMBERS 25
  40. //
  41. // We don't send more than 5000 records at a time. Note: This value is
  42. // used to define MAX_BYTES_IN_MSG in comm.c
  43. //
  44. // By not having a very bug number we have a better chance for being serviced
  45. // within our timeout period for a request. This is because of queuing that
  46. // results when there are a lot of replication requests
  47. //
  48. //
  49. #define RPL_MAX_LIMIT_FOR_RPL 5000
  50. /*
  51. This define is used by ReadPartnerInfo and by RplPull functions. The size
  52. is made a multiple of 8. I could have used sizeof(LARGE_INTEGER) instead of
  53. 8 but I am not sure whether that will remain a multiple of 8 in the future.
  54. The size is made a multiple of 8 to avoid alignment exceptions on MIPS (
  55. check out ReadPartnerInfo in winscnf.c or GetReplicas in rplpull.c for
  56. more details)
  57. */
  58. #define RPL_CONFIG_REC_SIZE (sizeof(RPL_CONFIG_REC_T) + \
  59. (8 - sizeof(RPL_CONFIG_REC_T)%8))
  60. //
  61. // check out GetDataRecs in nmsdb.c
  62. //
  63. #define RPL_REC_ENTRY_SIZE (sizeof(RPL_REC_ENTRY_T) + \
  64. (8 - sizeof(RPL_REC_ENTRY_T)%8))
  65. //
  66. // check out GetDataRecs in nmsdb.c
  67. //
  68. #define RPL_REC_ENTRY2_SIZE (sizeof(RPL_REC_ENTRY2_T) + \
  69. (8 - sizeof(RPL_REC_ENTRY2_T)%8))
  70. //
  71. // The following define is used to initialize the TimeInterval/UpdateCount
  72. // field of a RPL_REC_ENTRY_T structure to indicate that it is invalid
  73. //
  74. #define RPL_INVALID_METRIC -1
  75. //
  76. // defines to indicate whether the trigger needs to be propagated to all WINS
  77. // in the PUSH chain
  78. //
  79. #define RPL_PUSH_PROP TRUE //must remain TRUE since in
  80. //NmsNmhNamRegInd, at one place
  81. //we use fAddDiff value in place of
  82. //this symbol. fAddDiff when TRUE
  83. //indicates that the address has
  84. //changed, thus initiating propagation
  85. #define RPL_PUSH_NO_PROP FALSE
  86. /*
  87. macros
  88. */
  89. //
  90. // Macro called in an NBT thread after it increments the version number
  91. // counter. This macro is supposed to be called from within the
  92. // NmsNmhNamRegCrtSec.
  93. //
  94. #define RPL_PUSH_NTF_M(fAddDiff, pCtx, pNoPushWins1, pNoPushWins2) { \
  95. if ((WinsCnf.PushInfo.NoPushRecsWValUpdCnt \
  96. != 0) || \
  97. fAddDiff) \
  98. { \
  99. ERplPushProc(fAddDiff, pCtx, pNoPushWins1, \
  100. pNoPushWins2); \
  101. } \
  102. }
  103. /*
  104. FIND_ADD_BY_OWNER_ID_M - This macro is called by the PUSH thread
  105. when sending data records to its Pull Partner. It calls this function
  106. to determine the Address of the WINS owning the database record
  107. The caller of this macro, if not executing in the PULL thread, must
  108. synchronize using NmsDbOwnAddTblCrtSec (Only PULL thread updates
  109. the NmsDbOwnAddTbl array during steady state).
  110. I am not putting the critical section entry and exit inside this
  111. macro for performance reasons (refer StoreGrpMems in nmsdb.c where
  112. this macro may be called many times -once for each member of a
  113. special group). Also refer RplMsgfFrmAddVersMapRsp() and
  114. WinsRecordAction (in winsintf.c)
  115. */
  116. #define RPL_FIND_ADD_BY_OWNER_ID_M(OwnerId, pWinsAdd, pWinsState_e, pStartVersNo) \
  117. { \
  118. PNMSDB_ADD_STATE_T pWinsRec; \
  119. if (OwnerId < NmsDbTotNoOfSlots) \
  120. { \
  121. pWinsRec = pNmsDbOwnAddTbl+OwnerId; \
  122. (pWinsAdd) = &(pWinsRec->WinsAdd); \
  123. (pWinsState_e) = &pWinsRec->WinsState_e; \
  124. (pStartVersNo) = &pWinsRec->StartVersNo; \
  125. } \
  126. else \
  127. { \
  128. (pWinsAdd) = NULL; \
  129. (pWinsState_e) = NULL; \
  130. (pStartVersNo) = NULL; \
  131. } \
  132. }
  133. //
  134. // Names of event variables signaled when Pull and/or Push configuration
  135. // changes
  136. //
  137. #define RPL_PULL_CNF_EVT_NM TEXT("RplPullCnfEvt")
  138. #define RPL_PUSH_CNF_EVT_NM TEXT("RplPushCnfEvt")
  139. /*
  140. externs
  141. */
  142. /*
  143. Handle of heap used for allocating/deallocating work items for the RPL
  144. queues
  145. */
  146. extern HANDLE RplWrkItmHeapHdl;
  147. #if 0
  148. extern HANDLE RplRecHeapHdl;
  149. #endif
  150. /*
  151. OwnerIdAddressTbl
  152. This table stores the Addresses corresponding to different WINS servers.
  153. In the local database, the local WINS's owner id is always 0. The owner ids
  154. of other WINS servers are 1, 2, 3 .... The owner ids form a sequential list,
  155. without any gap. This is because, the first time the database is created
  156. at a WINS, it assigns sequential numbers to the other WINS.
  157. Note: The table is static for now. We might change it to be a dynamic one
  158. later.
  159. */
  160. /*
  161. PushPnrVersNoTbl
  162. This table stores the Max. version number pertaining to each WINS server
  163. owning entries in the database of Push Partners
  164. Note: The table is static for now. We might change it to be a dynamic one
  165. later.
  166. */
  167. #if 0
  168. extern VERS_NO_T pPushPnrVersNoTbl;
  169. #endif
  170. /*
  171. OwnerVersNo -- this array stores the maximum version number for each
  172. owner in the local database
  173. This is used by HandleAddVersMapReq() in RplPush.c
  174. */
  175. extern VERS_NO_T pRplOwnerVersNo;
  176. extern HANDLE RplSyncWTcpThdEvtHdl; //Sync up with the TCP thread
  177. //
  178. // critical section to guard the RplPullOwnerVersNo array
  179. //
  180. extern CRITICAL_SECTION RplVersNoStoreCrtSec;
  181. /*
  182. typedef definitions
  183. */
  184. /*
  185. The different types of records that can be read from the registry
  186. */
  187. typedef enum _RPL_RR_TYPE_E {
  188. RPL_E_PULL = 0, // pull record
  189. RPL_E_PUSH, //push record
  190. RPL_E_QUERY //query record
  191. } RPL_RR_TYPE_E, *PRPL_RR_TYPE_E;
  192. typedef struct _RPL_VERS_NOS_T {
  193. VERS_NO_T VersNo;
  194. VERS_NO_T StartVersNo;
  195. } RPL_VERS_NOS_T, *PRPL_VERS_NOS_T;
  196. /*
  197. RPL_CONFIG_REC_T -- Configuration record for the WINS replicator. It
  198. specifies the Pull/Push/Query partner and associated
  199. parameters
  200. NOTE NOTE NOTE: Keep the datatype of UpdateCount and TimeInterval the same
  201. (see LnkWSameMetricRecs)
  202. */
  203. typedef struct _RPL_CONFIG_REC_T {
  204. DWORD MagicNo; //Same as that in WinsCnf
  205. COMM_ADD_T WinsAdd; /*address of partner */
  206. LPVOID pWinsCnf; //back pointer to the old WINS struct
  207. LONG TimeInterval; /*time interval in secs for pulling or
  208. * pushing */
  209. BOOL fSpTime; //indicates whether pull/push
  210. //replication should be done at
  211. // a specific time
  212. LONG SpTimeIntvl; //Number of secs to specific time
  213. LONG UpdateCount; /*Count of updates after which
  214. *notification will be sent (applies
  215. *only to Push RR types*/
  216. DWORD RetryCount; //No of retries done
  217. DWORD RetryAfterThisManyRpl; //Retry after this many rpl
  218. //time intervals have elapsed
  219. //from the time we stopped
  220. //replicating due to RetryCount
  221. //hitting the limit
  222. time_t LastCommFailTime; //time of last comm. failure
  223. time_t LastRplTime; //time of last replication
  224. #if PRSCONN
  225. time_t LastCommTime; //time of last comm.
  226. #endif
  227. DWORD PushNtfTries; //No of tries for establishing
  228. //comm. in the past few minutes
  229. //
  230. // The two counters below have to 32 bit aligned otherwise
  231. // the Interlock instructions will fail on x86 MP machines
  232. //
  233. DWORD NoOfRpls; //no of times replication
  234. //happened with this partner
  235. DWORD NoOfCommFails; //no of times replication
  236. //failed due to comm failure
  237. DWORD MemberPrec; //precedence of members of special grp
  238. //relative to other WINS servers
  239. struct _RPL_CONFIG_REC_T *pNext; //ptr to next rec. with same
  240. //time interval (in case of
  241. //of PULL record) or update
  242. //count (in case of PUSH record)
  243. VERS_NO_T LastVersNo; //Only valid for Push records.
  244. //Indicates what the value of the
  245. //local version number counter at the
  246. //time a push notification is sent
  247. DWORD RplType; //type of replication with this guy
  248. BOOL fTemp; //Indicates whether it is a temp
  249. //record that should be deallocated
  250. //after use.
  251. BOOL fLinked; //indicates whether the record is
  252. //is linked to a record before it in
  253. //the buffer of records of the same type //as this record
  254. BOOL fOnlyDynRecs; //indicates whether only dynamic
  255. //records should be pulled/pushed
  256. RPL_RR_TYPE_E RRTyp_e; /*Type of record PULL/PUSH/QUERY*/
  257. #if MCAST > 0
  258. BOOL fSelfFnd; //indicates whether this record was self found
  259. #endif
  260. #if PRSCONN
  261. BOOL fPrsConn;
  262. COMM_HDL_T PrsDlgHdl;
  263. #endif
  264. } RPL_CONFIG_REC_T, *PRPL_CONFIG_REC_T;
  265. /*
  266. RPL_ADD_VERS_NO_T - stores the highest version No. pertaining to an owner
  267. in the directory.
  268. Used by GetVersNo and RplMsgUfrmAddVersMapRsp
  269. */
  270. typedef struct _RPL_ADD_VERS_NO_T {
  271. COMM_ADD_T OwnerWinsAdd;
  272. VERS_NO_T VersNo;
  273. VERS_NO_T StartVersNo;
  274. } RPL_ADD_VERS_NO_T, *PRPL_ADD_VERS_NO_T;
  275. /*
  276. RPL_PUSHPNR_VERS_NO_T -- stores the Push Pnr Id, the id. of the owner whose
  277. records should be pulled, and the max version
  278. number of these records
  279. This structure is initializes at replication time. The PULL thread
  280. looks at this structure and sends requests to its Push partners to
  281. pull records.
  282. This structure is used by functions in the rplpull.c and rplmsgf.c
  283. modules.
  284. */
  285. typedef struct _RPL_PUSHPNR_VERS_NO_T {
  286. DWORD PushPnrId;
  287. DWORD OwnerId;
  288. VERS_NO_T MaxVersNo;
  289. } RPL_PUSHPNR_VERS_NO_T, *PRPL_PUSHPNR_VERS_NO_T;
  290. FUTURES("Use NmsDbRowInfo struture")
  291. /*
  292. RPL_REC_ENTRY_T -- structure that holds a record in the range
  293. Min version no - Max version no for an owner WINS
  294. Used by RplPushHandleSndEntriesReq
  295. Size of this structure is 68 bytes
  296. */
  297. typedef struct _RPL_REC_ENTRY_T {
  298. DWORD NameLen;
  299. DWORD NoOfAdds;
  300. union {
  301. PCOMM_ADD_T pNodeAdd;
  302. COMM_ADD_T NodeAdd[2];
  303. };
  304. VERS_NO_T VersNo;
  305. DWORD TimeStamp; //used only when doing scavenging
  306. DWORD NewTimeStamp; //used only when doing scavenging
  307. BOOL fScv; //used only when doing scavenging
  308. BOOL fGrp;
  309. LPBYTE pName;
  310. DWORD Flag;
  311. } RPL_REC_ENTRY_T, *PRPL_REC_ENTRY_T;
  312. // this struct is same as above plus has the ownerid.
  313. // winsgetdatarecsbyname routine needs to know the ownerid of each
  314. // record and so this new structure is created.
  315. typedef struct _RPL_REC_ENTRY2_T {
  316. DWORD NameLen;
  317. DWORD NoOfAdds;
  318. union {
  319. PCOMM_ADD_T pNodeAdd;
  320. COMM_ADD_T NodeAdd[2];
  321. };
  322. VERS_NO_T VersNo;
  323. DWORD TimeStamp; //used only when doing scavenging
  324. DWORD NewTimeStamp; //used only when doing scavenging
  325. BOOL fScv; //used only when doing scavenging
  326. BOOL fGrp;
  327. LPBYTE pName;
  328. DWORD Flag;
  329. DWORD OwnerId;
  330. } RPL_REC_ENTRY2_T, *PRPL_REC_ENTRY2_T;
  331. //
  332. // Argument to GetReplicas, EstablishComm (both in rplpull.c), and
  333. // WinsCnfGetNextCnfRec to indicate to it how it should traverse
  334. // the buffer of Configuration records
  335. //
  336. typedef enum _RPL_REC_TRAVERSAL_E {
  337. RPL_E_VIA_LINK = 0,
  338. RPL_E_IN_SEQ,
  339. RPL_E_NO_TRAVERSAL
  340. } RPL_REC_TRAVERSAL_E, *PRPL_REC_TRAVERSAL_E;
  341. /*
  342. function declarations
  343. */
  344. extern
  345. STATUS
  346. ERplInit(
  347. VOID
  348. );
  349. extern
  350. STATUS
  351. ERplInsertQue(
  352. WINS_CLIENT_E Client_e,
  353. QUE_CMD_TYP_E CmdTyp_e,
  354. PCOMM_HDL_T pDlgHdl,
  355. MSG_T pMsg,
  356. MSG_LEN_T MsgLen,
  357. LPVOID pClientCtx,
  358. DWORD MagicNo
  359. );
  360. extern
  361. STATUS
  362. RplFindOwnerId (
  363. IN PCOMM_ADD_T pWinsAdd,
  364. IN OUT LPBOOL pfAllocNew,
  365. OUT DWORD UNALIGNED *pOwnerId,
  366. IN DWORD InitpAction_e,
  367. IN DWORD MemberPrec
  368. );
  369. extern
  370. VOID
  371. ERplPushProc(
  372. BOOL fAddDiff,
  373. LPVOID pCtx,
  374. PCOMM_ADD_T pNoPushWins1,
  375. PCOMM_ADD_T pNoPushWins2
  376. );
  377. extern
  378. PRPL_CONFIG_REC_T
  379. RplGetConfigRec(
  380. RPL_RR_TYPE_E TypeOfRec_e,
  381. PCOMM_HDL_T pDlgHdl,
  382. PCOMM_ADD_T pAdd
  383. );
  384. #if 0
  385. extern
  386. VOID
  387. ERplPushCompl(
  388. PCOMM_ADD_T pNoPushWins
  389. );
  390. #endif
  391. #endif //_RPL_