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.

460 lines
14 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. atkerror.c
  5. Abstract:
  6. This module contains the event logging and all error log code.
  7. Author:
  8. Jameel Hyder (jameelh@microsoft.com)
  9. Nikhil Kamkolkar (nikhilk@microsoft.com)
  10. Revision History:
  11. 19 Jun 1992 Initial Version
  12. Notes: Tab stop: 4
  13. --*/
  14. #include <atalk.h>
  15. #pragma hdrstop
  16. #define FILENUM ATKERROR
  17. LONG AtalkLastRawDataLen = 0;
  18. NTSTATUS AtalkLastErrorCode = STATUS_SUCCESS;
  19. ULONG AtalkLastErrorCount = 0;
  20. LONG AtalkLastErrorTime = 0;
  21. BYTE AtalkLastRawData[PORT_MAXIMUM_MESSAGE_LENGTH - \
  22. sizeof(IO_ERROR_LOG_PACKET)] = {0};
  23. VOID
  24. AtalkWriteErrorLogEntry(
  25. IN PPORT_DESCRIPTOR pPortDesc OPTIONAL,
  26. IN NTSTATUS UniqueErrorCode,
  27. IN ULONG UniqueErrorValue,
  28. IN NTSTATUS NtStatusCode,
  29. IN PVOID RawDataBuf OPTIONAL,
  30. IN LONG RawDataLen
  31. )
  32. /*++
  33. Routine Description:
  34. Arguments:
  35. Return Value:
  36. --*/
  37. {
  38. PIO_ERROR_LOG_PACKET errorLogEntry;
  39. int AdapterNameLen = 0;
  40. PUNICODE_STRING pAdapterName = NULL;
  41. if (pPortDesc != NULL)
  42. {
  43. // do we have the friendly name (always yes, unless mem alloc failed)
  44. if (pPortDesc->pd_FriendlyAdapterName.Buffer)
  45. {
  46. pAdapterName = &pPortDesc->pd_FriendlyAdapterName;
  47. }
  48. else
  49. {
  50. pAdapterName = &pPortDesc->pd_AdapterKey;
  51. }
  52. AdapterNameLen += pAdapterName->Length;
  53. }
  54. //ASSERT ((AdapterNameLen + sizeof(IO_ERROR_LOG_PACKET)) <
  55. //PORT_MAXIMUM_MESSAGE_LENGTH);
  56. #if DBG
  57. if ((AdapterNameLen + sizeof(IO_ERROR_LOG_PACKET)) > PORT_MAXIMUM_MESSAGE_LENGTH)
  58. {
  59. DBGPRINT(DBG_COMP_UTILS, DBG_LEVEL_ERR,
  60. ("AtalkWriteErrorLogEntry: Adapter Name for Port Descriptor has length = %d, which is greater than space allocated for it in the port message buffer = %d. The adapter name will be truncated in the log.\n", AdapterNameLen, PORT_MAXIMUM_MESSAGE_LENGTH-sizeof(IO_ERROR_LOG_PACKET)));
  61. }
  62. #endif
  63. // make sure the adaptername isn't huge: if it is, chop it
  64. if ((AdapterNameLen + sizeof(IO_ERROR_LOG_PACKET)) > PORT_MAXIMUM_MESSAGE_LENGTH)
  65. {
  66. AdapterNameLen = PORT_MAXIMUM_MESSAGE_LENGTH - sizeof(IO_ERROR_LOG_PACKET);
  67. }
  68. //
  69. if ((RawDataLen + AdapterNameLen + sizeof(IO_ERROR_LOG_PACKET)) >
  70. PORT_MAXIMUM_MESSAGE_LENGTH)
  71. {
  72. RawDataLen = PORT_MAXIMUM_MESSAGE_LENGTH -
  73. (AdapterNameLen + sizeof(IO_ERROR_LOG_PACKET));
  74. }
  75. // Filter out events such that the same event recurring close together does not
  76. // cause errorlog clogging. The scheme is - if the event is same as the last event
  77. // and the elapsed time is > THRESHOLD and ERROR_CONSEQ_FREQ simulataneous errors
  78. // have happened, then log it else skip
  79. if (UniqueErrorCode == AtalkLastErrorCode)
  80. {
  81. AtalkLastErrorCount++;
  82. if ((AtalkLastRawDataLen == RawDataLen) &&
  83. (AtalkFixedCompareCaseSensitive(AtalkLastRawData,
  84. RawDataLen,
  85. RawDataBuf,
  86. RawDataLen)) &&
  87. ((AtalkLastErrorCount % ERROR_CONSEQ_FREQ) != 0) &&
  88. ((AtalkGetCurrentTick() - AtalkLastErrorTime) < ERROR_CONSEQ_TIME))
  89. {
  90. return;
  91. }
  92. }
  93. AtalkLastErrorCode = UniqueErrorCode;
  94. AtalkLastErrorCount = 0;
  95. AtalkLastErrorTime = AtalkGetCurrentTick();
  96. ASSERT(RawDataLen < (PORT_MAXIMUM_MESSAGE_LENGTH -
  97. sizeof(IO_ERROR_LOG_PACKET)));
  98. if (RawDataLen != 0)
  99. {
  100. AtalkLastRawDataLen = RawDataLen;
  101. RtlCopyMemory(
  102. AtalkLastRawData,
  103. RawDataBuf,
  104. RawDataLen);
  105. }
  106. errorLogEntry =
  107. (PIO_ERROR_LOG_PACKET)IoAllocateErrorLogEntry(
  108. (PDEVICE_OBJECT)AtalkDeviceObject[0],
  109. (UCHAR)(sizeof(IO_ERROR_LOG_PACKET) +
  110. AdapterNameLen + RawDataLen));
  111. if (errorLogEntry != NULL)
  112. {
  113. // Fill in the Error log entry
  114. errorLogEntry->ErrorCode = UniqueErrorCode;
  115. errorLogEntry->UniqueErrorValue = UniqueErrorValue;
  116. errorLogEntry->MajorFunctionCode = 0;
  117. errorLogEntry->RetryCount = 0;
  118. errorLogEntry->FinalStatus = NtStatusCode;
  119. errorLogEntry->IoControlCode = 0;
  120. errorLogEntry->DeviceOffset.LowPart = 0;
  121. errorLogEntry->DeviceOffset.HighPart = 0;
  122. errorLogEntry->DumpDataSize = (USHORT)RawDataLen;
  123. errorLogEntry->StringOffset =
  124. (USHORT)(FIELD_OFFSET(IO_ERROR_LOG_PACKET, DumpData) + RawDataLen);
  125. errorLogEntry->NumberOfStrings = (ARGUMENT_PRESENT(pPortDesc)) ? 1 : 0;
  126. if (ARGUMENT_PRESENT(RawDataBuf))
  127. {
  128. ASSERT(RawDataLen > 0);
  129. RtlCopyMemory((PCHAR)&errorLogEntry->DumpData[0], RawDataBuf, RawDataLen);
  130. }
  131. if (ARGUMENT_PRESENT(pPortDesc))
  132. {
  133. RtlCopyMemory((PCHAR)errorLogEntry->DumpData + RawDataLen,
  134. pAdapterName->Buffer,
  135. AdapterNameLen);
  136. }
  137. // Write the entry
  138. IoWriteErrorLogEntry(errorLogEntry);
  139. }
  140. else
  141. {
  142. DBGPRINT(DBG_ALL, DBG_LEVEL_FATAL,
  143. ("AtalkWriteErrorLogEntry: IoAllocErrorlogEntry Failed %d = %d+%d+%d\n",
  144. sizeof(IO_ERROR_LOG_PACKET)+AdapterNameLen+RawDataLen,
  145. sizeof(IO_ERROR_LOG_PACKET),AdapterNameLen,RawDataLen));
  146. }
  147. }
  148. VOID
  149. AtalkLogBadPacket(
  150. IN struct _PORT_DESCRIPTOR * pPortDesc,
  151. IN PATALK_ADDR pSrcAddr,
  152. IN PATALK_ADDR pDstAddr OPTIONAL,
  153. IN PBYTE pPkt,
  154. IN USHORT PktLen
  155. )
  156. {
  157. PBYTE RawData;
  158. if ((RawData = AtalkAllocMemory(PktLen + sizeof(ATALK_ADDR) + sizeof(ATALK_ADDR))) != NULL)
  159. {
  160. RtlCopyMemory(RawData,
  161. pSrcAddr,
  162. sizeof(ATALK_ADDR));
  163. if (ARGUMENT_PRESENT(pDstAddr))
  164. {
  165. RtlCopyMemory(RawData + sizeof(ATALK_ADDR),
  166. pDstAddr,
  167. sizeof(ATALK_ADDR));
  168. }
  169. else RtlZeroMemory(RawData + sizeof(ATALK_ADDR), sizeof(ATALK_ADDR));
  170. RtlCopyMemory(RawData + sizeof(ATALK_ADDR) + sizeof(ATALK_ADDR),
  171. pPkt,
  172. PktLen);
  173. LOG_ERRORONPORT(pPortDesc,
  174. EVENT_ATALK_PACKETINVALID,
  175. 0,
  176. RawData,
  177. PktLen + sizeof(ATALK_ADDR) + sizeof(ATALK_ADDR));
  178. AtalkFreeMemory(RawData);
  179. }
  180. }
  181. struct _NdisToAtalkCodes
  182. {
  183. NDIS_STATUS _NdisCode;
  184. ATALK_ERROR _AtalkCode;
  185. } atalkNdisToAtalkCodes[] =
  186. {
  187. { NDIS_STATUS_SUCCESS, ATALK_NO_ERROR },
  188. { NDIS_STATUS_PENDING, ATALK_PENDING },
  189. { NDIS_STATUS_RESOURCES, ATALK_RESR_MEM },
  190. { NDIS_STATUS_UNSUPPORTED_MEDIA, ATALK_INIT_MEDIA_INVALID },
  191. { NDIS_STATUS_BAD_VERSION, ATALK_INIT_REGPROTO_FAIL },
  192. { NDIS_STATUS_BAD_CHARACTERISTICS, ATALK_INIT_REGPROTO_FAIL },
  193. { NDIS_STATUS_BUFFER_TOO_SHORT, ATALK_BUFFER_TOO_SMALL },
  194. { NDIS_STATUS_ADAPTER_NOT_FOUND, ATALK_INIT_BINDFAIL },
  195. { NDIS_STATUS_OPEN_FAILED, ATALK_INIT_BINDFAIL },
  196. { NDIS_STATUS_OPEN_LIST_FULL, ATALK_INIT_BINDFAIL },
  197. { NDIS_STATUS_ADAPTER_NOT_READY, ATALK_INIT_BINDFAIL }
  198. };
  199. ATALK_ERROR FASTCALL
  200. AtalkNdisToAtalkError(
  201. IN NDIS_STATUS Error
  202. )
  203. /*++
  204. Routine Description:
  205. Arguments:
  206. Return Value:
  207. --*/
  208. {
  209. ATALK_ERROR err = ATALK_FAILURE; // default
  210. int i;
  211. struct _NdisToAtalkCodes *pCodes;
  212. for (i = 0, pCodes = &atalkNdisToAtalkCodes[0];
  213. i < sizeof(atalkNdisToAtalkCodes)/sizeof(struct _NdisToAtalkCodes);
  214. i++, pCodes++)
  215. {
  216. if (pCodes->_NdisCode == Error)
  217. {
  218. err = pCodes->_AtalkCode;
  219. break;
  220. }
  221. }
  222. return(err);
  223. }
  224. struct _AtalkToNtCodes
  225. {
  226. ATALK_ERROR _AtalkCode;
  227. NTSTATUS _NtCode;
  228. } atalkToNtCodes[] =
  229. {
  230. { ATALK_NO_ERROR, STATUS_SUCCESS },
  231. { ATALK_PENDING, STATUS_PENDING },
  232. { ATALK_RESR_MEM, STATUS_INSUFFICIENT_RESOURCES },
  233. { ATALK_CONNECTION_TIMEOUT, STATUS_REMOTE_DISCONNECT },
  234. { ATALK_LOCAL_CLOSE, STATUS_LOCAL_DISCONNECT },
  235. { ATALK_REMOTE_CLOSE, STATUS_REMOTE_DISCONNECT },
  236. { ATALK_INVALID_PARAMETER, STATUS_INVALID_PARAMETER },
  237. { ATALK_BUFFER_TOO_SMALL, STATUS_BUFFER_TOO_SMALL },
  238. { ATALK_INVALID_REQUEST, STATUS_REQUEST_NOT_ACCEPTED },
  239. { ATALK_DEVICE_NOT_READY, STATUS_DEVICE_NOT_READY },
  240. { ATALK_REQUEST_NOT_ACCEPTED, STATUS_REQUEST_NOT_ACCEPTED },
  241. { ATALK_NEW_SOCKET, STATUS_INVALID_ADDRESS },
  242. { ATALK_TIMEOUT, STATUS_IO_TIMEOUT },
  243. { ATALK_SHARING_VIOLATION, STATUS_SHARING_VIOLATION },
  244. { ATALK_INIT_BINDFAIL, (NTSTATUS)NDIS_STATUS_OPEN_FAILED },
  245. { ATALK_INIT_REGPROTO_FAIL, (NTSTATUS)NDIS_STATUS_BAD_VERSION },
  246. { ATALK_INIT_MEDIA_INVALID, (NTSTATUS)NDIS_STATUS_UNSUPPORTED_MEDIA },
  247. { ATALK_PORT_INVALID, STATUS_INVALID_PORT_HANDLE },
  248. { ATALK_PORT_CLOSING, STATUS_PORT_DISCONNECTED },
  249. { ATALK_NODE_FINDING, STATUS_TOO_MANY_COMMANDS },
  250. { ATALK_NODE_NONEXISTENT, STATUS_INVALID_ADDRESS_COMPONENT },
  251. { ATALK_NODE_CLOSING, STATUS_ADDRESS_CLOSED },
  252. { ATALK_NODE_NOMORE, STATUS_TOO_MANY_NODES },
  253. { ATALK_SOCKET_INVALID, STATUS_INVALID_ADDRESS_COMPONENT },
  254. { ATALK_SOCKET_NODEFULL, STATUS_TOO_MANY_ADDRESSES },
  255. { ATALK_SOCKET_EXISTS, STATUS_ADDRESS_ALREADY_EXISTS },
  256. { ATALK_SOCKET_CLOSED, STATUS_ADDRESS_CLOSED },
  257. { ATALK_DDP_CLOSING, STATUS_ADDRESS_CLOSED },
  258. { ATALK_DDP_NOTFOUND, STATUS_INVALID_ADDRESS },
  259. { ATALK_DDP_INVALID_LEN, STATUS_INVALID_PARAMETER },
  260. { ATALK_DDP_INVALID_SRC, STATUS_INVALID_ADDRESS },
  261. { ATALK_DDP_INVALID_DEST, STATUS_INVALID_ADDRESS },
  262. { ATALK_DDP_INVALID_ADDR, STATUS_INVALID_ADDRESS },
  263. { ATALK_DDP_INVALID_PARAM, STATUS_INVALID_PARAMETER },
  264. { ATALK_ATP_RESP_TIMEOUT, STATUS_SUCCESS },
  265. { ATALK_ATP_INVALID_RETRYCNT, STATUS_INVALID_PARAMETER },
  266. { ATALK_ATP_INVALID_TIMERVAL, STATUS_INVALID_PARAMETER },
  267. { ATALK_ATP_INVALID_RELINT, STATUS_INVALID_PARAMETER },
  268. { ATALK_ATP_RESP_CANCELLED, STATUS_CANCELLED },
  269. { ATALK_ATP_REQ_CANCELLED, STATUS_CANCELLED },
  270. { ATALK_ATP_GET_REQ_CANCELLED, STATUS_CANCELLED },
  271. { ATALK_ASP_INVALID_REQUEST, STATUS_REQUEST_NOT_ACCEPTED },
  272. { ATALK_PAP_INVALID_REQUEST, STATUS_REQUEST_NOT_ACCEPTED },
  273. { ATALK_PAP_TOO_MANY_READS, STATUS_TOO_MANY_COMMANDS },
  274. { ATALK_PAP_TOO_MANY_WRITES, STATUS_TOO_MANY_COMMANDS },
  275. { ATALK_PAP_CONN_NOT_ACTIVE, STATUS_INVALID_CONNECTION },
  276. { ATALK_PAP_ADDR_CLOSING, STATUS_INVALID_HANDLE },
  277. { ATALK_PAP_CONN_CLOSING, STATUS_INVALID_HANDLE },
  278. { ATALK_PAP_CONN_NOT_FOUND, STATUS_INVALID_HANDLE },
  279. { ATALK_PAP_SERVER_BUSY, STATUS_REMOTE_NOT_LISTENING },
  280. { ATALK_PAP_INVALID_STATUS, STATUS_INVALID_PARAMETER },
  281. { ATALK_PAP_PARTIAL_RECEIVE, STATUS_RECEIVE_PARTIAL },
  282. { ATALK_ADSP_INVALID_REQUEST, STATUS_REQUEST_NOT_ACCEPTED },
  283. { ATALK_ADSP_CONN_NOT_ACTIVE, STATUS_INVALID_CONNECTION },
  284. { ATALK_ADSP_ADDR_CLOSING, STATUS_INVALID_HANDLE },
  285. { ATALK_ADSP_CONN_CLOSING, STATUS_INVALID_HANDLE },
  286. { ATALK_ADSP_CONN_NOT_FOUND, STATUS_INVALID_HANDLE },
  287. { ATALK_ADSP_CONN_RESET, STATUS_CONNECTION_RESET },
  288. { ATALK_ADSP_SERVER_BUSY, STATUS_REMOTE_NOT_LISTENING },
  289. { ATALK_ADSP_PARTIAL_RECEIVE, STATUS_RECEIVE_PARTIAL },
  290. { ATALK_ADSP_EXPED_RECEIVE, STATUS_RECEIVE_EXPEDITED },
  291. { ATALK_ADSP_PAREXPED_RECEIVE, STATUS_RECEIVE_PARTIAL_EXPEDITED },
  292. { ATALK_ADSP_REMOTE_RESR, STATUS_REMOTE_RESOURCES }
  293. };
  294. NTSTATUS FASTCALL
  295. AtalkErrorToNtStatus(
  296. ATALK_ERROR AtalkError
  297. )
  298. /*++
  299. Routine Description:
  300. Arguments:
  301. Return Value:
  302. --*/
  303. {
  304. NTSTATUS Status = STATUS_UNSUCCESSFUL; // default
  305. int i;
  306. struct _AtalkToNtCodes *pCodes;
  307. for (i = 0, pCodes = &atalkToNtCodes[0];
  308. i < sizeof(atalkToNtCodes)/sizeof(struct _AtalkToNtCodes);
  309. i++, pCodes++)
  310. {
  311. if (pCodes->_AtalkCode == AtalkError)
  312. {
  313. Status = pCodes->_NtCode;
  314. break;
  315. }
  316. }
  317. return(Status);
  318. }
  319. #if DBG
  320. struct
  321. {
  322. ULONG DumpMask;
  323. DUMP_ROUTINE DumpRoutine;
  324. } AtalkDumpTable[32] =
  325. {
  326. { DBG_DUMP_PORTINFO, AtalkPortDumpInfo },
  327. { DBG_DUMP_AMT, AtalkAmtDumpTable },
  328. { DBG_DUMP_ZONETABLE, AtalkZoneDumpTable },
  329. { DBG_DUMP_RTES, AtalkRtmpDumpTable },
  330. { DBG_DUMP_TIMERS, AtalkTimerDumpList },
  331. { DBG_DUMP_ATPINFO, NULL },
  332. { DBG_DUMP_ASPSESSIONS, AtalkAspDumpSessions },
  333. { DBG_DUMP_PAPJOBS, NULL },
  334. { 0, NULL },
  335. { 0, NULL },
  336. { 0, NULL },
  337. { 0, NULL },
  338. { 0, NULL },
  339. { 0, NULL },
  340. { 0, NULL },
  341. { 0, NULL },
  342. { 0, NULL },
  343. { 0, NULL },
  344. { 0, NULL },
  345. { 0, NULL },
  346. { 0, NULL },
  347. { 0, NULL },
  348. { 0, NULL },
  349. { 0, NULL },
  350. { 0, NULL },
  351. { 0, NULL },
  352. { 0, NULL },
  353. { 0, NULL },
  354. { 0, NULL },
  355. { 0, NULL },
  356. { 0, NULL },
  357. { 0, NULL }
  358. };
  359. LONG FASTCALL
  360. AtalkDumpComponents(
  361. IN PTIMERLIST Context,
  362. IN BOOLEAN TimerShuttingDown
  363. )
  364. {
  365. int i;
  366. if (!TimerShuttingDown)
  367. {
  368. for (i = 0;AtalkDebugDump && (i < 32); i++)
  369. {
  370. if ((AtalkDebugDump & AtalkDumpTable[i].DumpMask) &&
  371. (AtalkDumpTable[i].DumpRoutine != NULL))
  372. {
  373. (*AtalkDumpTable[i].DumpRoutine)();
  374. }
  375. }
  376. if (AtalkDumpInterval == 0)
  377. {
  378. AtalkDumpInterval = DBG_DUMP_DEF_INTERVAL;
  379. }
  380. }
  381. else AtalkDumpInterval = ATALK_TIMER_NO_REQUEUE;
  382. return AtalkDumpInterval;
  383. }
  384. #endif