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.

657 lines
19 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. net\routing\netsh\ip\protocols\msdpmib.c
  5. Abstract:
  6. Functions to get and display MSDP MIB information.
  7. Author:
  8. Dave Thaler 11/03/99
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. #define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
  14. ULONG
  15. QueryTagArray(
  16. PTCHAR ArgumentArray[],
  17. ULONG ArgumentCount,
  18. TAG_TYPE TagTypeArray[],
  19. ULONG TagTypeCount,
  20. OUT PULONG* TagArray
  21. );
  22. //
  23. // Flag for printing header
  24. //
  25. BOOL g_bMsdpFirst = TRUE;
  26. HANDLE g_hConsole, g_hStdOut;
  27. // This can have the other fields pfn etc
  28. MIB_OBJECT_PARSER MsdpMIBObjectMap[] =
  29. {
  30. {TOKEN_MSDP_MIB_OBJECT_GLOBALSTATS,0,0,NULL},
  31. {TOKEN_MSDP_MIB_OBJECT_PEERSTATS, 1,1,GetMsdpMIBIpAddress},
  32. {TOKEN_MSDP_MIB_OBJECT_SA, 0,2,GetMsdpMIBSAIndex},
  33. };
  34. #define MAX_MSDP_MIB_OBJECTS (sizeof(MsdpMIBObjectMap)/sizeof(MIB_OBJECT_PARSER))
  35. MSDP_MAGIC_TABLE MsdpMIBVar[] = {
  36. {MIBID_MSDP_GLOBAL, PrintMsdpGlobalStats, 0},
  37. {MIBID_MSDP_IPV4_PEER_ENTRY, PrintMsdpPeerStats, 4},
  38. {MIBID_MSDP_SA_CACHE_ENTRY, PrintMsdpSA, 8},
  39. };
  40. DWORD
  41. GetMsdpMIBIpAddress(
  42. IN LPCWSTR *ppwcArguments,
  43. IN ULONG ulArgumentIndex,
  44. IN ULONG ulArgumentCount,
  45. OUT PDWORD pdwIndices,
  46. OUT PDWORD pdwNumParsed
  47. )
  48. /*++
  49. Routine Description:
  50. Gets the index IP address for peer Mib variable.
  51. Arguments:
  52. ppwcArguments - Argument array
  53. ulArgumentIndex - Index of the first argument in array
  54. pdwIndices - Indices specified in command
  55. pdwNumParsed - Number of indices in command
  56. Return Value:
  57. NO_ERROR
  58. --*/
  59. {
  60. DWORD dwErr;
  61. ULONG i;
  62. PULONG pulTagArray;
  63. ULONG ulArgumentsLeft = ulArgumentCount - ulArgumentIndex;
  64. TAG_TYPE TagTypeArray[] = { { TOKEN_OPT_REMADDR, FALSE, FALSE }
  65. };
  66. *pdwNumParsed = 0;
  67. if (ulArgumentsLeft < 1)
  68. {
  69. return NO_ERROR;
  70. }
  71. dwErr = QueryTagArray( &ppwcArguments[ulArgumentIndex],
  72. ulArgumentsLeft,
  73. TagTypeArray,
  74. NUM_TAGS_IN_TABLE(TagTypeArray),
  75. &pulTagArray );
  76. if (dwErr is NO_ERROR) {
  77. for (i=0; i<ulArgumentsLeft; i++) {
  78. switch(pulTagArray ? pulTagArray[i] : i) {
  79. case 0: { // remaddr
  80. pdwIndices[0] = GetIpAddress(ppwcArguments[i+
  81. ulArgumentIndex]);
  82. (*pdwNumParsed)++;
  83. break;
  84. }
  85. }
  86. }
  87. } else {
  88. dwErr = ERROR_SHOW_USAGE;
  89. }
  90. if (pulTagArray) { FREE(pulTagArray); }
  91. return dwErr;
  92. }
  93. DWORD
  94. GetMsdpMIBSAIndex(
  95. IN LPCWSTR *ppwcArguments,
  96. IN ULONG ulArgumentIndex,
  97. IN ULONG ulArgumentCount,
  98. OUT PDWORD pdwIndices,
  99. OUT PDWORD pdwNumParsed
  100. )
  101. {
  102. DWORD dwErr;
  103. ULONG i;
  104. ULONG ulArgumentsLeft = ulArgumentCount - ulArgumentIndex;
  105. PULONG pulTagArray;
  106. TAG_TYPE TagTypeArray[] = { { TOKEN_OPT_GROUPADDR, FALSE, FALSE },
  107. { TOKEN_OPT_SOURCEADDR, FALSE, FALSE },
  108. };
  109. *pdwNumParsed = 0;
  110. if (ulArgumentsLeft < 1)
  111. {
  112. return NO_ERROR;
  113. }
  114. dwErr = QueryTagArray( &ppwcArguments[ulArgumentIndex],
  115. ulArgumentsLeft,
  116. TagTypeArray,
  117. NUM_TAGS_IN_TABLE(TagTypeArray),
  118. &pulTagArray );
  119. if (dwErr is NO_ERROR) {
  120. for (i=0; i<ulArgumentsLeft; i++) {
  121. switch(pulTagArray ? pulTagArray[i] : i) {
  122. case 0: { // grpaddr
  123. pdwIndices[0] = GetIpAddress(ppwcArguments[i+
  124. ulArgumentIndex]);
  125. (*pdwNumParsed)++;
  126. break;
  127. }
  128. case 1: { // srcaddr
  129. pdwIndices[1] = GetIpAddress(ppwcArguments[i+
  130. ulArgumentIndex]);
  131. (*pdwNumParsed)++;
  132. break;
  133. }
  134. }
  135. }
  136. }
  137. if (pulTagArray) { FREE(pulTagArray); }
  138. return dwErr;
  139. }
  140. PWCHAR
  141. GetTceStateString(
  142. DWORD dwState
  143. )
  144. {
  145. PWCHAR pwszStr;
  146. static WCHAR buff[80];
  147. VALUE_STRING ppsList[] = {{MSDP_STATE_IDLE, STRING_IDLE},
  148. {MSDP_STATE_CONNECT, STRING_CONNECT},
  149. {MSDP_STATE_ACTIVE, STRING_ACTIVE},
  150. {MSDP_STATE_OPENSENT, STRING_OPENSENT},
  151. {MSDP_STATE_OPENCONFIRM, STRING_OPENCONFIRM},
  152. {MSDP_STATE_ESTABLISHED, STRING_ESTABLISHED},
  153. };
  154. DWORD dwNum = sizeof(ppsList)/sizeof(VALUE_STRING), i;
  155. DWORD dwMsgId = 0;
  156. for (i=0; i<dwNum; i++)
  157. {
  158. if (dwState is ppsList[i].dwValue)
  159. {
  160. dwMsgId = ppsList[i].dwStringId;
  161. break;
  162. }
  163. }
  164. if (dwMsgId)
  165. {
  166. pwszStr = MakeString( g_hModule, dwMsgId);
  167. wcscpy(buff, pwszStr);
  168. FreeString(pwszStr);
  169. }
  170. else
  171. {
  172. wsprintf(buff, L"%d", dwState);
  173. }
  174. return buff;
  175. }
  176. DWORD
  177. HandleMsdpMibShowObject(
  178. PWCHAR pwszMachine,
  179. PWCHAR *ppwcArguments,
  180. DWORD dwCurrentIndex,
  181. DWORD dwArgCount,
  182. DWORD dwFlags,
  183. MIB_SERVER_HANDLE hMibServer,
  184. BOOL *pbDone
  185. )
  186. /*++
  187. Routine Description:
  188. Parses command to get MIB object and optional parameters
  189. Arguments:
  190. Return Value:
  191. --*/
  192. {
  193. DWORD dwIndices[MAX_NUM_INDICES];
  194. DWORD dwNumParsed = 0;
  195. MIB_OPAQUE_QUERY rgQueryBuff[2];
  196. PMIB_OPAQUE_QUERY pQuery = rgQueryBuff;
  197. PMIB_OPAQUE_INFO pRpcInfo;
  198. DWORD dwQuerySize;
  199. BOOL bFound = FALSE,bOptPresent = FALSE;
  200. DWORD dwRefreshRate;
  201. DWORD dwOutEntrySize;
  202. DWORD i,dwResult,dwErr;
  203. DWORD dwMIBIndex, dwIndex;
  204. BOOL bIndex = FALSE, dwType;
  205. DWORD dwRR = 0, dwInd = 0;
  206. HANDLE hMib;
  207. DWORD dwDisplayInfoId, dwDisplayInfoType, dwOptVar;
  208. DWORD dwOutSize;
  209. VERIFY_INSTALLED(MS_IP_MSDP, L"MSDP");
  210. //
  211. // Match MIB object
  212. //
  213. g_hMibServer = hMibServer;
  214. ppwcArguments += (dwCurrentIndex-1);
  215. dwArgCount -= (dwCurrentIndex-1);
  216. dwCurrentIndex = 1;
  217. DEBUG1("In MSDP MIB Show : %s\n",ppwcArguments[0]);
  218. for (i = 0; i < MAX_MSDP_MIB_OBJECTS; i++)
  219. {
  220. if (MatchToken(ppwcArguments[0],MsdpMIBObjectMap[i].pwszMIBObj))
  221. {
  222. dwIndex = i;
  223. bFound = TRUE;
  224. DEBUG("found");
  225. break;
  226. }
  227. }
  228. if (!bFound)
  229. {
  230. return ERROR_CMD_NOT_FOUND;
  231. }
  232. #if 0
  233. if ((dwArgCount > 1) && IsHelpToken(ppwcArguments[1]))
  234. {
  235. DisplayMessage(g_hModule,
  236. MsdpMIBObjectMap[i].dwCmdHelpToken,
  237. MsdpMIBObjectMap[i].pwszMIBObj);
  238. return NO_ERROR;
  239. }
  240. #endif
  241. if (MsdpMIBObjectMap[dwIndex].pfnMIBObjParser)
  242. {
  243. dwErr = (*MsdpMIBObjectMap[dwIndex].pfnMIBObjParser)(ppwcArguments,
  244. 1 + dwInd,
  245. dwArgCount,
  246. dwIndices,
  247. &dwNumParsed);
  248. if (dwErr isnot NO_ERROR)
  249. {
  250. return dwErr;
  251. }
  252. }
  253. //
  254. // Convert refresh rate to msec
  255. //
  256. dwRR *= 1000;
  257. dwMIBIndex = dwIndex;
  258. pQuery->dwVarId = MsdpMIBVar[dwMIBIndex].dwId;
  259. if (!InitializeConsole(&dwRR, &hMib, &g_hConsole))
  260. {
  261. return ERROR_INIT_DISPLAY;
  262. }
  263. for ( ; ; )
  264. {
  265. if(dwRR)
  266. {
  267. DisplayMessageToConsole(g_hModule, g_hConsole, MSG_CTRL_C_TO_QUIT);
  268. }
  269. // See if we just need to do a GET
  270. if (dwNumParsed is MsdpMIBObjectMap[dwIndex].dwNumArgs)
  271. {
  272. pQuery->rgdwVarIndex[0] = 0;
  273. for (i=0; i<MsdpMIBObjectMap[dwIndex].dwNumArgs; i++)
  274. {
  275. pQuery->rgdwVarIndex[i] = dwIndices[i];
  276. }
  277. dwResult = MprAdminMIBEntryGet(hMibServer,
  278. PID_IP,
  279. MS_IP_MSDP,
  280. (LPVOID) pQuery,
  281. sizeof(MIB_OPAQUE_QUERY)
  282. + MsdpMIBVar[dwMIBIndex].ulIndexBytes-sizeof(DWORD),
  283. (LPVOID *) &pRpcInfo,
  284. &dwOutSize );
  285. if (( dwResult isnot NO_ERROR ) and (dwResult isnot ERROR_NOT_FOUND))
  286. {
  287. DisplayMessageToConsole( g_hModule, g_hConsole, MSG_IP_DIM_ERROR, dwResult );
  288. break;
  289. }
  290. if ( pRpcInfo is NULL )
  291. {
  292. break;
  293. }
  294. (*MsdpMIBVar[dwMIBIndex].pfnPrintFunction)(pRpcInfo, FORMAT_VERBOSE);
  295. MprAdminMIBBufferFree( (PVOID) pRpcInfo );
  296. }
  297. else if (dwNumParsed is 0)
  298. {
  299. // Display All
  300. g_bMsdpFirst = TRUE;
  301. dwResult = MprAdminMIBEntryGetFirst(hMibServer,
  302. PID_IP,
  303. MS_IP_MSDP,
  304. (LPVOID) pQuery,
  305. sizeof(MIB_OPAQUE_INFO)
  306. + MsdpMIBVar[dwMIBIndex].ulIndexBytes-sizeof(DWORD),
  307. (LPVOID *) &pRpcInfo,
  308. &dwOutSize );
  309. if (( dwResult isnot NO_ERROR ) and (dwResult isnot ERROR_NO_MORE_ITEMS))
  310. {
  311. DisplayMessageToConsole( g_hModule, g_hConsole, MSG_IP_DIM_ERROR, dwResult );
  312. break;
  313. }
  314. if ( pRpcInfo is NULL )
  315. {
  316. DisplayMessageToConsole( g_hModule, g_hConsole, MSG_IP_NO_ENTRIES );
  317. break;
  318. }
  319. (*MsdpMIBVar[dwMIBIndex].pfnPrintFunction)(pRpcInfo, FORMAT_TABLE);
  320. g_bMsdpFirst = FALSE;
  321. do
  322. {
  323. // pQuery->rgdwVarIndex[0] = pRpcInfo->IMGOD_IfIndex;
  324. //
  325. // prepare for next request
  326. //
  327. CopyMemory(pQuery->rgdwVarIndex, pRpcInfo->rgbyData,
  328. MsdpMIBVar[dwMIBIndex].ulIndexBytes );
  329. MprAdminMIBBufferFree( (PVOID) pRpcInfo );
  330. pRpcInfo = NULL;
  331. DEBUG2("calling next with index %d", pQuery->rgdwVarIndex[0]);
  332. dwResult = MprAdminMIBEntryGetNext(hMibServer,
  333. PID_IP,
  334. MS_IP_MSDP,
  335. (LPVOID) pQuery,
  336. sizeof(MIB_OPAQUE_QUERY)
  337. + MsdpMIBVar[dwMIBIndex].ulIndexBytes-sizeof(DWORD),
  338. (LPVOID *) &pRpcInfo,
  339. &dwOutSize );
  340. if (dwResult is ERROR_NO_MORE_ITEMS)
  341. {
  342. g_bMsdpFirst = TRUE;
  343. return dwResult;
  344. }
  345. if ( dwResult isnot NO_ERROR )
  346. {
  347. g_bMsdpFirst = TRUE;
  348. break;
  349. }
  350. if ( pRpcInfo is NULL )
  351. {
  352. g_bMsdpFirst = TRUE;
  353. break;
  354. }
  355. if (pQuery->dwVarId isnot pRpcInfo->dwId)
  356. {
  357. g_bMsdpFirst = TRUE;
  358. break;
  359. }
  360. (*MsdpMIBVar[dwMIBIndex].pfnPrintFunction)(pRpcInfo, FORMAT_TABLE);
  361. } while (1);
  362. }
  363. else
  364. {
  365. // partially-specified index
  366. g_bMsdpFirst = TRUE;
  367. pQuery->rgdwVarIndex[0] = 0;
  368. for (i=0; i<dwNumParsed; i++)
  369. {
  370. pQuery->rgdwVarIndex[i] = dwIndices[i];
  371. }
  372. for (; i<MsdpMIBObjectMap[dwIndex].dwNumArgs; i++)
  373. {
  374. pQuery->rgdwVarIndex[i] = 0;
  375. }
  376. do
  377. {
  378. dwResult = MprAdminMIBEntryGetNext(hMibServer,
  379. PID_IP,
  380. MS_IP_MSDP,
  381. (LPVOID) pQuery,
  382. sizeof(MIB_OPAQUE_QUERY)
  383. + MsdpMIBVar[dwMIBIndex].ulIndexBytes-sizeof(DWORD),
  384. (LPVOID *) &pRpcInfo,
  385. &dwOutSize );
  386. if (dwResult is NO_ERROR)
  387. {
  388. // See if we've gone too far
  389. for (i=0; i<dwNumParsed; i++)
  390. {
  391. // All index fields are DWORDs
  392. if (memcmp(pQuery->rgdwVarIndex, pRpcInfo->rgbyData,
  393. dwNumParsed * sizeof(DWORD)))
  394. {
  395. dwResult = ERROR_NO_MORE_ITEMS;
  396. break;
  397. }
  398. }
  399. }
  400. if (dwResult is ERROR_NO_MORE_ITEMS)
  401. {
  402. g_bMsdpFirst = TRUE;
  403. return dwResult;
  404. }
  405. if ( dwResult isnot NO_ERROR )
  406. {
  407. g_bMsdpFirst = TRUE;
  408. break;
  409. }
  410. if ( pRpcInfo is NULL )
  411. {
  412. g_bMsdpFirst = TRUE;
  413. break;
  414. }
  415. if (pQuery->dwVarId isnot pRpcInfo->dwId)
  416. {
  417. g_bMsdpFirst = TRUE;
  418. break;
  419. }
  420. (*MsdpMIBVar[dwMIBIndex].pfnPrintFunction)(pRpcInfo, FORMAT_TABLE);
  421. //
  422. // prepare for next request
  423. //
  424. CopyMemory(pQuery->rgdwVarIndex, pRpcInfo->rgbyData,
  425. MsdpMIBVar[dwMIBIndex].ulIndexBytes );
  426. MprAdminMIBBufferFree( (PVOID) pRpcInfo );
  427. pRpcInfo = NULL;
  428. g_bMsdpFirst = FALSE;
  429. } while (1);
  430. }
  431. if (!RefreshConsole(hMib, g_hConsole, dwRR))
  432. {
  433. break;
  434. }
  435. }
  436. return dwResult;
  437. }
  438. VOID
  439. PrintMsdpGlobalStats(
  440. PMIB_OPAQUE_INFO pRpcInfo,
  441. DWORD dwFormat
  442. )
  443. /*++
  444. Routine Description:
  445. Prints msdp global statistics
  446. Arguments:
  447. Return Value:
  448. --*/
  449. {
  450. WCHAR wszRouterId[20];
  451. PMSDP_GLOBAL_ENTRY pEntry = (PMSDP_GLOBAL_ENTRY)(pRpcInfo->rgbyData);
  452. IP_TO_TSTR(wszRouterId, &pEntry->dwRouterId);
  453. DisplayMessageToConsole(g_hModule,g_hConsole,MSG_MSDP_GLOBAL_STATS,
  454. pEntry->ulNumSACacheEntries,
  455. wszRouterId);
  456. }
  457. VOID
  458. PrintMsdpSA(
  459. PMIB_OPAQUE_INFO pRpcInfo,
  460. DWORD dwFormat
  461. )
  462. {
  463. PMSDP_SA_CACHE_ENTRY psa;
  464. WCHAR wszGroupAddress[20];
  465. WCHAR wszSourceAddress[20];
  466. WCHAR wszOriginAddress[20];
  467. WCHAR wszLearnedFromAddress[20];
  468. WCHAR wszRPFPeerAddress[20];
  469. DWORD dwId = (dwFormat is FORMAT_TABLE)? MSG_MSDP_SA_INFO :
  470. MSG_MSDP_SA_INFO_EX;
  471. if (g_bMsdpFirst && (dwFormat is FORMAT_TABLE))
  472. {
  473. DisplayMessageToConsole(g_hModule,g_hConsole,MSG_MSDP_SA_INFO_HEADER);
  474. }
  475. psa = (PMSDP_SA_CACHE_ENTRY)(pRpcInfo->rgbyData);
  476. IP_TO_TSTR(wszGroupAddress, &psa->ipGroupAddr);
  477. IP_TO_TSTR(wszSourceAddress, &psa->ipSourceAddr);
  478. IP_TO_TSTR(wszOriginAddress, &psa->ipOriginRP);
  479. IP_TO_TSTR(wszLearnedFromAddress, &psa->ipPeerLearnedFrom);
  480. IP_TO_TSTR(wszRPFPeerAddress, &psa->ipRPFPeer);
  481. DisplayMessageToConsole(g_hModule, g_hConsole,
  482. dwId,
  483. wszGroupAddress,
  484. wszSourceAddress,
  485. wszOriginAddress,
  486. wszLearnedFromAddress,
  487. wszRPFPeerAddress,
  488. psa->ulInSAs,
  489. psa->ulUpTime/100,
  490. psa->ulExpiryTime/100);
  491. }
  492. VOID
  493. PrintMsdpPeerStats(
  494. PMIB_OPAQUE_INFO pRpcInfo,
  495. DWORD dwFormat
  496. )
  497. /*++
  498. Routine Description:
  499. Prints msdp neighbor stats
  500. Arguments:
  501. Return Value:
  502. --*/
  503. {
  504. PMSDP_IPV4_PEER_ENTRY pPeer;
  505. WCHAR wszAddr[ADDR_LENGTH + 1];
  506. if (g_bMsdpFirst && (dwFormat is FORMAT_TABLE))
  507. {
  508. DisplayMessageToConsole(g_hModule,g_hConsole,MSG_MSDP_PEER_STATS_HEADER);
  509. }
  510. pPeer = (PMSDP_IPV4_PEER_ENTRY)(pRpcInfo->rgbyData);
  511. MakeUnicodeIpAddr(wszAddr, inet_ntoa(*((struct in_addr *)
  512. (&pPeer->ipRemoteAddress))));
  513. DisplayMessageToConsole(g_hModule, g_hConsole,
  514. (dwFormat is FORMAT_TABLE)? MSG_MSDP_PEER_STATS
  515. : MSG_MSDP_PEER_STATS_EX,
  516. wszAddr,
  517. GetTceStateString(pPeer->dwState),
  518. pPeer->ulRPFFailures,
  519. pPeer->ulInSAs,
  520. pPeer->ulOutSAs,
  521. pPeer->ulInSARequests,
  522. pPeer->ulOutSARequests,
  523. pPeer->ulInSAResponses,
  524. pPeer->ulOutSAResponses,
  525. pPeer->ulInControlMessages,
  526. pPeer->ulOutControlMessages,
  527. pPeer->ulFsmEstablishedTransitions,
  528. pPeer->ulFsmEstablishedTime,
  529. pPeer->ulInMessageElapsedTime);
  530. }