Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

551 lines
17 KiB

  1. //=============================================================================
  2. // MODULE: cnp.c
  3. //
  4. // Description:
  5. //
  6. // Bloodhound Parser DLL for the Cluster Network Protocol
  7. //
  8. // Modification History
  9. //
  10. // Mike Massa 03/21/97 Created
  11. //=============================================================================
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. //
  15. // Constants
  16. //
  17. #define CNP_VERSION_1 0x1 // original CNP
  18. #define CNP_VERSION_2 0x2 // original CNP + multicast
  19. #define CNP_VERSION_UNICAST CNP_VERSION_1
  20. #define CNP_VERSION_MULTICAST CNP_VERSION_2
  21. #define PROTOCOL_CDP 2
  22. #define PROTOCOL_CCMP 1
  23. #define ClusterAnyNodeId 0 // from clusdef.h
  24. //
  25. // Types
  26. //
  27. typedef struct {
  28. UCHAR Version;
  29. UCHAR NextHeader;
  30. USHORT PayloadLength;
  31. ULONG SourceAddress;
  32. ULONG DestinationAddress;
  33. } CNP_HEADER, *PCNP_HEADER;
  34. //
  35. // Multicast signature data.
  36. //
  37. #include <packon.h>
  38. typedef ULONG CL_NETWORK_ID, *PCL_NETWORK_ID;
  39. typedef struct {
  40. UCHAR Version;
  41. UCHAR Reserved;
  42. USHORT PayloadOffset;
  43. CL_NETWORK_ID NetworkId;
  44. ULONG ClusterNetworkBrand;
  45. USHORT SigBufferLen;
  46. UCHAR SigBuffer[1]; // dynamic
  47. } CNP_SIGNATURE, *PCNP_SIGNATURE;
  48. #include <packoff.h>
  49. //
  50. // Data
  51. //
  52. LPSTR CdpName = "CDP";
  53. LPSTR CcmpName = "CCMP";
  54. LPSTR UnknownProtocolName = "Unknown";
  55. //=============================================================================
  56. // Forward references.
  57. //=============================================================================
  58. VOID WINAPIV CnpFormatSummary(LPPROPERTYINST lpPropertyInst);
  59. DWORD WINAPIV CnpFormatSigData(LPPROPERTYINST lpPropertyInst);
  60. DWORD WINAPIV CnpFormatSignature(HFRAME hFrame,
  61. CNP_SIGNATURE UNALIGNED * CnpSig);
  62. //=============================================================================
  63. // CNP database.
  64. //=============================================================================
  65. #define CNP_SUMMARY 0
  66. #define CNP_VERSION 1
  67. #define CNP_NEXT_HEADER 2
  68. #define CNP_PAYLOAD_LENGTH 3
  69. #define CNP_SOURCE_ADDRESS 4
  70. #define CNP_DESTINATION_ADDRESS 5
  71. // CNP signature properties
  72. #define CNP_SIG_SIGDATA 6
  73. #define CNP_SIG_VERSION 7
  74. #define CNP_SIG_PAYLOADOFFSET 8
  75. #define CNP_SIG_NETWORK_ID 9
  76. #define CNP_SIG_NETWORK_BRAND 10
  77. #define CNP_SIG_SIGBUFFERLEN 11
  78. #define CNP_SIG_SIGNATURE 12
  79. PROPERTYINFO CnpDatabase[] =
  80. {
  81. { // CNP_SUMMARY 0
  82. 0,0,
  83. "Summary",
  84. "Summary of the CNP packet",
  85. PROP_TYPE_SUMMARY,
  86. PROP_QUAL_NONE,
  87. NULL,
  88. 132,
  89. CnpFormatSummary},
  90. { // CNP_VERSION 1
  91. 0,0,
  92. "Version",
  93. "Version of CNP that created this packet",
  94. PROP_TYPE_BYTE,
  95. PROP_QUAL_NONE,
  96. NULL,
  97. 80,
  98. FormatPropertyInstance},
  99. { // CNP_NEXT_HEADER 2
  100. 0,0,
  101. "Next Header",
  102. "Protocol ID of the header following the CNP header",
  103. PROP_TYPE_BYTE,
  104. PROP_QUAL_NONE,
  105. NULL,
  106. 80,
  107. FormatPropertyInstance},
  108. { // CNP_PAYLOAD_LENGTH 3
  109. 0,0,
  110. "Payload Length",
  111. "Number of data bytes carried by the packet",
  112. PROP_TYPE_WORD,
  113. PROP_QUAL_NONE,
  114. NULL,
  115. 80,
  116. FormatPropertyInstance},
  117. { // CNP_SOURCE_ADDRESS 4
  118. 0,0,
  119. "Source Address",
  120. "ID of the node which originated the packet",
  121. PROP_TYPE_DWORD,
  122. PROP_QUAL_NONE,
  123. NULL,
  124. 80,
  125. FormatPropertyInstance},
  126. { // CNP_DESTINATION_ADDRESS 5
  127. 0,0,
  128. "Destination Address",
  129. "ID of the node for which the packet is destined",
  130. PROP_TYPE_DWORD,
  131. PROP_QUAL_NONE,
  132. NULL,
  133. 80,
  134. FormatPropertyInstance},
  135. { // CNP_SIG_SIGDATA 6
  136. 0,0,
  137. "Signature Data",
  138. "CNP Multicast Signature Data",
  139. PROP_TYPE_SUMMARY,
  140. PROP_QUAL_NONE,
  141. NULL,
  142. 80,
  143. CnpFormatSigData},
  144. { // CNP_SIG_VERSION 7
  145. 0,0,
  146. "Signature Version",
  147. "Identifies algorithm to sign and verify messages.",
  148. PROP_TYPE_BYTE,
  149. PROP_QUAL_NONE,
  150. NULL,
  151. 80,
  152. FormatPropertyInstance},
  153. { // CNP_SIG_PAYLOADOFFSET 8
  154. 0,0,
  155. "Payload Offset",
  156. "Offset of message payload from start of CNP signature data",
  157. PROP_TYPE_WORD,
  158. PROP_QUAL_NONE,
  159. NULL,
  160. 80,
  161. FormatPropertyInstance},
  162. { // CNP_SIG_NETWORK_ID 9
  163. 0,0,
  164. "Network ID",
  165. "Network ID number assigned by the cluster",
  166. PROP_TYPE_DWORD,
  167. PROP_QUAL_NONE,
  168. NULL,
  169. 80,
  170. FormatPropertyInstance},
  171. { // CNP_SIG_NETWORK_BRAND 10
  172. 0,0,
  173. "Network Brand",
  174. "Pseudo-random 32-bit value differentiating this "
  175. "network from networks in other clusters",
  176. PROP_TYPE_DWORD,
  177. PROP_QUAL_NONE,
  178. NULL,
  179. 80,
  180. FormatPropertyInstance},
  181. { // CNP_SIG_SIGBUFFERLEN 11
  182. 0,0,
  183. "Signature Buffer Length",
  184. "Length of signature buffer following node data",
  185. PROP_TYPE_WORD,
  186. PROP_QUAL_NONE,
  187. NULL,
  188. 80,
  189. FormatPropertyInstance},
  190. { // CNP_SIG_SIGNATURE 12
  191. 0,0,
  192. "Signature",
  193. "Signature",
  194. PROP_TYPE_RAW_DATA,
  195. PROP_QUAL_NONE,
  196. NULL,
  197. 80,
  198. FormatPropertyInstance},
  199. };
  200. DWORD nCnpProperties = ((sizeof CnpDatabase) / PROPERTYINFO_SIZE);
  201. //=============================================================================
  202. // FUNCTION: CnpRegister()
  203. //
  204. // Modification History
  205. //
  206. // Steve Hiskey 07/07/94 Created
  207. //=============================================================================
  208. VOID WINAPI CnpRegister(HPROTOCOL hCnpProtocol)
  209. {
  210. register DWORD i;
  211. //=========================================================================
  212. // Create the property database.
  213. //=========================================================================
  214. CreatePropertyDatabase(hCnpProtocol, nCnpProperties);
  215. for(i = 0; i < nCnpProperties; ++i)
  216. {
  217. AddProperty(hCnpProtocol, &CnpDatabase[i]);
  218. }
  219. }
  220. //=============================================================================
  221. // FUNCTION: Deregister()
  222. //
  223. // Modification History
  224. //
  225. // Steve Hiskey 07/07/94 Created
  226. //=============================================================================
  227. VOID WINAPI CnpDeregister(HPROTOCOL hCnpProtocol)
  228. {
  229. DestroyPropertyDatabase(hCnpProtocol);
  230. }
  231. //=============================================================================
  232. // FUNCTION: CnpRecognizeFrame()
  233. //
  234. // Modification History
  235. //
  236. // Steve Hiskey 07/07/94 Created
  237. //=============================================================================
  238. LPBYTE WINAPI CnpRecognizeFrame(HFRAME hFrame, //... frame handle.
  239. LPBYTE MacFrame, //... Frame pointer.
  240. LPBYTE MyFrame, //... Relative pointer.
  241. DWORD MacType, //... MAC type.
  242. DWORD BytesLeft, //... Bytes left.
  243. HPROTOCOL hPreviousProtocol, //... Previous protocol or NULL if none.
  244. DWORD nPreviousProtocolOffset, //... Offset of previous protocol.
  245. LPDWORD ProtocolStatusCode, //... Pointer to return status code in.
  246. LPHPROTOCOL hNextProtocol, //... Next protocol to call (optional).
  247. LPDWORD InstData) //... Next protocol instance data.
  248. {
  249. CNP_HEADER UNALIGNED * cnpHeader = (CNP_HEADER UNALIGNED *) MyFrame;
  250. CNP_SIGNATURE UNALIGNED * cnpSig = (CNP_SIGNATURE UNALIGNED *)(cnpHeader + 1);
  251. LPBYTE lpNextByte;
  252. if (cnpHeader->Version == CNP_VERSION_MULTICAST) {
  253. lpNextByte = (LPBYTE)cnpSig + cnpSig->PayloadOffset;
  254. } else {
  255. lpNextByte = (LPBYTE)cnpSig;
  256. }
  257. if (cnpHeader->NextHeader == PROTOCOL_CDP) {
  258. *hNextProtocol = hCdp;
  259. *ProtocolStatusCode = PROTOCOL_STATUS_NEXT_PROTOCOL;
  260. }
  261. else if (cnpHeader->NextHeader == PROTOCOL_CCMP) {
  262. *hNextProtocol = hCcmp;
  263. *ProtocolStatusCode = PROTOCOL_STATUS_NEXT_PROTOCOL;
  264. }
  265. else {
  266. *ProtocolStatusCode = PROTOCOL_STATUS_CLAIMED;
  267. }
  268. return lpNextByte;
  269. }
  270. //=============================================================================
  271. // FUNCTION: CnpAttachProperties()
  272. //
  273. // Modification History
  274. //
  275. // Steve Hiskey 07/07/94 Created
  276. //=============================================================================
  277. LPBYTE WINAPI CnpAttachProperties(HFRAME hFrame,
  278. LPBYTE Frame,
  279. LPBYTE MyFrame,
  280. DWORD MacType,
  281. DWORD BytesLeft,
  282. HPROTOCOL hPreviousProtocol,
  283. DWORD nPreviousProtocolOffset,
  284. DWORD InstData)
  285. {
  286. CNP_HEADER UNALIGNED * cnpHeader = (CNP_HEADER UNALIGNED *) MyFrame;
  287. AttachPropertyInstance(hFrame,
  288. CnpDatabase[CNP_SUMMARY].hProperty,
  289. sizeof(CNP_HEADER),
  290. cnpHeader,
  291. 0, 0, 0);
  292. AttachPropertyInstance(hFrame,
  293. CnpDatabase[CNP_VERSION].hProperty,
  294. sizeof(BYTE),
  295. &(cnpHeader->Version),
  296. 0, 1, 0);
  297. AttachPropertyInstance(hFrame,
  298. CnpDatabase[CNP_NEXT_HEADER].hProperty,
  299. sizeof(BYTE),
  300. &(cnpHeader->NextHeader),
  301. 0, 1, 0);
  302. AttachPropertyInstance(hFrame,
  303. CnpDatabase[CNP_PAYLOAD_LENGTH].hProperty,
  304. sizeof(WORD),
  305. &(cnpHeader->PayloadLength),
  306. 0, 1, 0);
  307. AttachPropertyInstance(hFrame,
  308. CnpDatabase[CNP_SOURCE_ADDRESS].hProperty,
  309. sizeof(DWORD),
  310. &(cnpHeader->SourceAddress),
  311. 0, 1, 0);
  312. AttachPropertyInstance(hFrame,
  313. CnpDatabase[CNP_DESTINATION_ADDRESS].hProperty,
  314. sizeof(DWORD),
  315. &(cnpHeader->DestinationAddress),
  316. 0, 1, 0);
  317. if (cnpHeader->Version == CNP_VERSION_MULTICAST) {
  318. CnpFormatSignature(hFrame,
  319. (CNP_SIGNATURE UNALIGNED *)(cnpHeader + 1)
  320. );
  321. }
  322. return NULL;
  323. }
  324. //==============================================================================
  325. // FUNCTION: CnpFormatSummary()
  326. //
  327. // Modification History
  328. //
  329. // Steve Hiskey 07/07/94 Created
  330. //==============================================================================
  331. VOID WINAPIV CnpFormatSummary(LPPROPERTYINST lpPropertyInst)
  332. {
  333. LPSTR SummaryStr;
  334. DWORD Length;
  335. LPSTR NextHeaderStr;
  336. CNP_HEADER UNALIGNED * cnpHeader =
  337. (CNP_HEADER UNALIGNED *) lpPropertyInst->lpData;
  338. if (cnpHeader->NextHeader == PROTOCOL_CDP) {
  339. NextHeaderStr = CdpName;
  340. }
  341. else if (cnpHeader->NextHeader == PROTOCOL_CCMP) {
  342. NextHeaderStr = CcmpName;
  343. }
  344. else {
  345. NextHeaderStr = UnknownProtocolName;
  346. }
  347. Length = wsprintf( lpPropertyInst->szPropertyText,
  348. "Src = %u; Dst = %u; Proto = %s; Payload Len = %u",
  349. cnpHeader->SourceAddress,
  350. cnpHeader->DestinationAddress,
  351. NextHeaderStr,
  352. cnpHeader->PayloadLength
  353. );
  354. }
  355. //==============================================================================
  356. // FUNCTION: CnpFormatProperties()
  357. //
  358. // Modification History
  359. //
  360. // Steve Hiskey 07/07/94 Created
  361. //==============================================================================
  362. DWORD WINAPI CnpFormatProperties(HFRAME hFrame,
  363. LPBYTE MacFrame,
  364. LPBYTE FrameData,
  365. DWORD nPropertyInsts,
  366. LPPROPERTYINST p)
  367. {
  368. //=========================================================================
  369. // Format each property in the property instance table.
  370. //
  371. // The property-specific instance data was used to store the address of a
  372. // property-specific formatting function so all we do here is call each
  373. // function via the instance data pointer.
  374. //=========================================================================
  375. while (nPropertyInsts--)
  376. {
  377. ((FORMAT) p->lpPropertyInfo->InstanceData)(p);
  378. p++;
  379. }
  380. return NMERR_SUCCESS;
  381. }
  382. //==============================================================================
  383. // FUNCTION: CnpFormatMcastSigData()
  384. //
  385. // Modification History
  386. //
  387. // David Dion 04/16/2001 Created
  388. //==============================================================================
  389. DWORD WINAPIV CnpFormatSigData(LPPROPERTYINST lpPropertyInst)
  390. {
  391. wsprintf( lpPropertyInst->szPropertyText,
  392. "CNP Signature Data:"
  393. );
  394. return NMERR_SUCCESS;
  395. }
  396. //==============================================================================
  397. // FUNCTION: CnpFormatSignature()
  398. //
  399. // Modification History
  400. //
  401. // David Dion 04/16/01 Created
  402. //==============================================================================
  403. DWORD WINAPIV CnpFormatSignature(HFRAME hFrame,
  404. CNP_SIGNATURE UNALIGNED * CnpSig)
  405. {
  406. AttachPropertyInstance(hFrame,
  407. CnpDatabase[CNP_SIG_SIGDATA].hProperty,
  408. CnpSig->PayloadOffset,
  409. CnpSig,
  410. 0, 1, 0);
  411. AttachPropertyInstance(hFrame,
  412. CnpDatabase[CNP_SIG_VERSION].hProperty,
  413. sizeof(UCHAR),
  414. &(CnpSig->Version),
  415. 0, 2, 0);
  416. AttachPropertyInstance(hFrame,
  417. CnpDatabase[CNP_SIG_PAYLOADOFFSET].hProperty,
  418. sizeof(WORD),
  419. &(CnpSig->PayloadOffset),
  420. 0, 2, 0);
  421. AttachPropertyInstance(hFrame,
  422. CnpDatabase[CNP_SIG_NETWORK_ID].hProperty,
  423. sizeof(DWORD),
  424. &(CnpSig->NetworkId),
  425. 0, 2, 0);
  426. AttachPropertyInstance(hFrame,
  427. CnpDatabase[CNP_SIG_NETWORK_BRAND].hProperty,
  428. sizeof(DWORD),
  429. &(CnpSig->ClusterNetworkBrand),
  430. 0, 2, 0);
  431. AttachPropertyInstance(hFrame,
  432. CnpDatabase[CNP_SIG_SIGBUFFERLEN].hProperty,
  433. sizeof(WORD),
  434. &(CnpSig->SigBufferLen),
  435. 0, 2, 0);
  436. AttachPropertyInstance(hFrame,
  437. CnpDatabase[CNP_SIG_SIGNATURE].hProperty,
  438. CnpSig->SigBufferLen,
  439. &(CnpSig->SigBuffer[0]),
  440. 0, 2, 0);
  441. return NMERR_SUCCESS;
  442. }
  443. //==============================================================================
  444. // FUNCTION: CnpIsMulticast()
  445. //
  446. // Modification History
  447. //
  448. // David Dion 04/16/2001 Created
  449. //==============================================================================
  450. BOOLEAN WINAPIV CnpIsMulticast(
  451. HPROTOCOL hPreviousProtocol, //... Previous protocol or NULL if none.
  452. LPBYTE MacFrame, //... Frame pointer.
  453. DWORD nPreviousProtocolOffset //... Offset of previous protocol.
  454. )
  455. {
  456. CNP_HEADER UNALIGNED * cnpHeader;
  457. cnpHeader = (CNP_HEADER UNALIGNED *)(MacFrame + nPreviousProtocolOffset);
  458. return (BOOLEAN)(hPreviousProtocol == hCnp &&
  459. cnpHeader->DestinationAddress == ClusterAnyNodeId
  460. );
  461. }
  462.