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.

499 lines
17 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. #define DEFAULT_VIEW_MASK RTM_VIEW_MASK_UCAST|RTM_VIEW_MASK_MCAST // both
  4. #define DEFAULT_VIEW_ID RTM_VIEW_ID_UCAST
  5. #define DEFAULT_ADDR 0 // 0.0.0.0
  6. #define DEFAULT_MASK 0 // 0.0.0.0
  7. #define DEFAULT_PROTO RTM_BEST_PROTOCOL
  8. DWORD
  9. HandleIpShowRtmDestinations(
  10. IN LPCWSTR pwszMachine,
  11. IN OUT LPWSTR *ppwcArguments,
  12. IN DWORD dwCurrentIndex,
  13. IN DWORD dwArgCount,
  14. IN DWORD dwFlags,
  15. IN LPCVOID pvData,
  16. OUT BOOL *pbDone
  17. )
  18. {
  19. TAG_TYPE pttTags[] = {{TOKEN_OPERATOR, FALSE,FALSE},
  20. {TOKEN_DEST, FALSE,FALSE},
  21. {TOKEN_MASK, FALSE,FALSE},
  22. {TOKEN_VIEW, FALSE,FALSE},
  23. {TOKEN_PROTOCOL, FALSE,FALSE}};
  24. DWORD pdwTagType[sizeof(pttTags)/sizeof(TAG_TYPE)];
  25. DWORD dwErr, i, dwOperator = DEST_LONGER;
  26. DWORD dwViewMask = DEFAULT_VIEW_MASK;
  27. DWORD dwProtocol = DEFAULT_PROTO;
  28. IPV4_ADDRESS ipMask = DEFAULT_MASK;
  29. IPV4_ADDRESS ipAddress = DEFAULT_ADDR;
  30. MIB_OPAQUE_QUERY QueryBuff[3]; // more than enough
  31. MIB_OPAQUE_QUERY *pQuery = QueryBuff;
  32. DWORD dwOutEntrySize, dwCount;
  33. PMIB_OPAQUE_INFO pRpcInfo;
  34. PMIB_IPDESTTABLE lprpcTable;
  35. WCHAR wcszBuffer[80], wcszNHop[80];
  36. WCHAR wcszName[MAX_INTERFACE_NAME_LEN+1];
  37. WCHAR wszViews[3];
  38. //
  39. // We can show non persistent info only if router is running
  40. //
  41. CHECK_ROUTER_RUNNING();
  42. // Do generic processing
  43. dwErr = PreHandleCommand( ppwcArguments,
  44. dwCurrentIndex,
  45. dwArgCount,
  46. pttTags,
  47. sizeof(pttTags)/sizeof(TAG_TYPE),
  48. 0,
  49. sizeof(pttTags)/sizeof(TAG_TYPE),
  50. pdwTagType );
  51. if (dwErr)
  52. {
  53. return dwErr;
  54. }
  55. dwArgCount -= dwCurrentIndex;
  56. for (i=0; i<dwArgCount; i++)
  57. {
  58. switch(pdwTagType[i])
  59. {
  60. case 0: // OPERATOR
  61. {
  62. TOKEN_VALUE rgEnums[] ={{ TOKEN_VALUE_MATCHING, DEST_MATCHING},
  63. { TOKEN_VALUE_LONGER, DEST_LONGER },
  64. { TOKEN_VALUE_SHORTER, DEST_SHORTER}};
  65. dwErr = MatchEnumTag( g_hModule,
  66. ppwcArguments[i + dwCurrentIndex],
  67. sizeof(rgEnums)/sizeof(TOKEN_VALUE),
  68. rgEnums,
  69. &dwOperator);
  70. if (dwErr isnot NO_ERROR)
  71. {
  72. DispTokenErrMsg( g_hModule,
  73. MSG_IP_BAD_OPTION_VALUE,
  74. pttTags[pdwTagType[i]].pwszTag,
  75. ppwcArguments[i + dwCurrentIndex] );
  76. return ERROR_INVALID_PARAMETER;
  77. }
  78. break;
  79. }
  80. case 1: // ADDR
  81. {
  82. dwErr = GetIpPrefix( ppwcArguments[i+dwCurrentIndex],
  83. &ipAddress,
  84. &ipMask );
  85. if (dwErr is ERROR_INVALID_PARAMETER)
  86. {
  87. DisplayMessage( g_hModule, MSG_IP_BAD_IP_ADDR,
  88. ppwcArguments[i + dwCurrentIndex]);
  89. DispTokenErrMsg(g_hModule, MSG_IP_BAD_OPTION_VALUE,
  90. pttTags[pdwTagType[i]].pwszTag,
  91. ppwcArguments[i + dwCurrentIndex]);
  92. i = dwArgCount;
  93. break;
  94. }
  95. break;
  96. }
  97. case 2: // MASK
  98. {
  99. dwErr = GetIpMask( ppwcArguments[i+dwCurrentIndex],
  100. &ipMask );
  101. if (dwErr is ERROR_INVALID_PARAMETER)
  102. {
  103. DisplayMessage( g_hModule, MSG_IP_BAD_IP_ADDR,
  104. ppwcArguments[i + dwCurrentIndex]);
  105. DispTokenErrMsg(g_hModule, MSG_IP_BAD_OPTION_VALUE,
  106. pttTags[pdwTagType[i]].pwszTag,
  107. ppwcArguments[i + dwCurrentIndex]);
  108. i = dwArgCount;
  109. break;
  110. }
  111. break;
  112. }
  113. case 3: // VIEW
  114. {
  115. TOKEN_VALUE rgMaskEnums[] = {
  116. { TOKEN_VALUE_UNICAST, RTM_VIEW_MASK_UCAST },
  117. { TOKEN_VALUE_MULTICAST, RTM_VIEW_MASK_MCAST },
  118. { TOKEN_VALUE_BOTH, RTM_VIEW_MASK_UCAST
  119. |RTM_VIEW_MASK_MCAST } };
  120. dwErr = MatchEnumTag( g_hModule,
  121. ppwcArguments[i + dwCurrentIndex],
  122. sizeof(rgMaskEnums)/sizeof(TOKEN_VALUE),
  123. rgMaskEnums,
  124. &dwViewMask);
  125. if (dwErr isnot NO_ERROR)
  126. {
  127. DispTokenErrMsg( g_hModule,
  128. MSG_IP_BAD_OPTION_VALUE,
  129. pttTags[pdwTagType[i]].pwszTag,
  130. ppwcArguments[i + dwCurrentIndex] );
  131. i = dwArgCount;
  132. return ERROR_INVALID_PARAMETER;
  133. }
  134. break;
  135. }
  136. case 4: // PROTO
  137. {
  138. dwProtocol =
  139. MatchRoutingProtoTag(ppwcArguments[i + dwCurrentIndex]);
  140. break;
  141. }
  142. }
  143. }
  144. if (dwErr isnot NO_ERROR)
  145. {
  146. return dwErr;
  147. }
  148. // Compose MIB query
  149. pQuery->dwVarId = dwOperator;
  150. pQuery->rgdwVarIndex[0] = ipAddress;
  151. pQuery->rgdwVarIndex[1] = ipMask;
  152. pQuery->rgdwVarIndex[2] = dwViewMask;
  153. pQuery->rgdwVarIndex[3] = dwProtocol;
  154. dwErr = MibGet( PID_IP,
  155. IPRTRMGR_PID,
  156. (PVOID) pQuery,
  157. sizeof(MIB_OPAQUE_QUERY) + 3*sizeof(DWORD),
  158. (PVOID *) &pRpcInfo,
  159. &dwOutEntrySize );
  160. if ( dwErr isnot NO_ERROR )
  161. {
  162. DisplayMessage(g_hModule, MSG_IP_DIM_ERROR, dwErr );
  163. return dwErr;
  164. }
  165. if ( pRpcInfo is NULL )
  166. {
  167. DisplayMessage(g_hModule, MSG_IP_NO_ENTRIES );
  168. return dwErr;
  169. }
  170. // Display info
  171. lprpcTable = (PMIB_IPDESTTABLE)(pRpcInfo->rgbyData);
  172. dwCount = lprpcTable->dwNumEntries;
  173. DisplayMessage( g_hModule, MSG_RTR_ROUTE_HDR );
  174. for (i=0; i<dwCount; i++)
  175. {
  176. MakePrefixStringW( wcszBuffer,
  177. lprpcTable->table[i].dwForwardDest,
  178. lprpcTable->table[i].dwForwardMask );
  179. if (IpmontrGetFriendlyNameFromIfIndex( g_hMIBServer,
  180. lprpcTable->table[i].dwForwardIfIndex,
  181. wcszName,
  182. sizeof(wcszName) ) != NO_ERROR)
  183. {
  184. //
  185. // If we do not have a name for this index, display index
  186. //
  187. swprintf( wcszName,
  188. L"0x%x",
  189. lprpcTable->table[i].dwForwardIfIndex );
  190. }
  191. MakeAddressStringW( wcszNHop,
  192. lprpcTable->table[i].dwForwardNextHop );
  193. wszViews[0] = (lprpcTable->table[i].dwForwardViewSet & RTM_VIEW_MASK_UCAST)? 'U':' ';
  194. wszViews[1] = (lprpcTable->table[i].dwForwardViewSet & RTM_VIEW_MASK_MCAST)? 'M':' ';
  195. wszViews[2] = '\0';
  196. DisplayMessage( g_hModule, MSG_RTR_ROUTE_INFO,
  197. wcszBuffer,
  198. GetProtoProtoString(
  199. PROTO_TYPE_UCAST,
  200. 0,
  201. lprpcTable->table[i].dwForwardProto ),
  202. lprpcTable->table[i].dwForwardPreference,
  203. lprpcTable->table[i].dwForwardMetric1,
  204. wcszNHop,
  205. wszViews,
  206. wcszName );
  207. }
  208. MprAdminMIBBufferFree( (PVOID) pRpcInfo );
  209. return dwErr;
  210. }
  211. DWORD
  212. HandleIpShowRtmRoutes(
  213. IN LPCWSTR pwszMachine,
  214. IN OUT LPWSTR *ppwcArguments,
  215. IN DWORD dwCurrentIndex,
  216. IN DWORD dwArgCount,
  217. IN DWORD dwFlags,
  218. IN LPCVOID pvData,
  219. OUT BOOL *pbDone
  220. )
  221. {
  222. TAG_TYPE pttTags[] = {{TOKEN_OPERATOR, FALSE,FALSE},
  223. {TOKEN_DEST, FALSE,FALSE},
  224. {TOKEN_MASK, FALSE,FALSE},
  225. {TOKEN_VIEW, FALSE,FALSE},
  226. {TOKEN_PROTOCOL, FALSE,FALSE}};
  227. DWORD pdwTagType[sizeof(pttTags)/sizeof(TAG_TYPE)];
  228. DWORD dwErr, i, dwOperator = ROUTE_LONGER;
  229. DWORD dwViewMask = DEFAULT_VIEW_MASK;
  230. DWORD dwProtocol = DEFAULT_PROTO;
  231. IPV4_ADDRESS ipMask = DEFAULT_MASK;
  232. IPV4_ADDRESS ipAddress = DEFAULT_ADDR;
  233. MIB_OPAQUE_QUERY QueryBuff[3]; // more than enough
  234. MIB_OPAQUE_QUERY *pQuery = QueryBuff;
  235. DWORD dwOutEntrySize, dwCount;
  236. PMIB_OPAQUE_INFO pRpcInfo;
  237. PMIB_IPDESTTABLE lprpcTable;
  238. WCHAR wcszBuffer[80], wcszNHop[80];
  239. WCHAR wcszName[MAX_INTERFACE_NAME_LEN+1];
  240. WCHAR wszViews[3];
  241. //
  242. // We can show non persistent info only if router is running
  243. //
  244. CHECK_ROUTER_RUNNING();
  245. // Do generic processing
  246. dwErr = PreHandleCommand( ppwcArguments,
  247. dwCurrentIndex,
  248. dwArgCount,
  249. pttTags,
  250. sizeof(pttTags)/sizeof(TAG_TYPE),
  251. 0,
  252. sizeof(pttTags)/sizeof(TAG_TYPE),
  253. pdwTagType );
  254. if (dwErr)
  255. {
  256. return dwErr;
  257. }
  258. dwArgCount -= dwCurrentIndex;
  259. for (i=0; i<dwArgCount; i++)
  260. {
  261. switch(pdwTagType[i])
  262. {
  263. case 0: // OPERATOR
  264. {
  265. TOKEN_VALUE rgEnums[] ={{ TOKEN_VALUE_MATCHING,ROUTE_MATCHING},
  266. { TOKEN_VALUE_LONGER, ROUTE_LONGER },
  267. { TOKEN_VALUE_SHORTER, ROUTE_SHORTER}};
  268. dwErr = MatchEnumTag( g_hModule,
  269. ppwcArguments[i + dwCurrentIndex],
  270. sizeof(rgEnums)/sizeof(TOKEN_VALUE),
  271. rgEnums,
  272. &dwOperator);
  273. if (dwErr isnot NO_ERROR)
  274. {
  275. DispTokenErrMsg( g_hModule,
  276. MSG_IP_BAD_OPTION_VALUE,
  277. pttTags[pdwTagType[i]].pwszTag,
  278. ppwcArguments[i + dwCurrentIndex] );
  279. return ERROR_INVALID_PARAMETER;
  280. }
  281. break;
  282. }
  283. case 1: // ADDR
  284. {
  285. dwErr = GetIpPrefix( ppwcArguments[i+dwCurrentIndex],
  286. &ipAddress,
  287. &ipMask );
  288. if (dwErr is ERROR_INVALID_PARAMETER)
  289. {
  290. DisplayMessage( g_hModule, MSG_IP_BAD_IP_ADDR,
  291. ppwcArguments[i + dwCurrentIndex]);
  292. DispTokenErrMsg(g_hModule, MSG_IP_BAD_OPTION_VALUE,
  293. pttTags[pdwTagType[i]].pwszTag,
  294. ppwcArguments[i + dwCurrentIndex]);
  295. i = dwArgCount;
  296. break;
  297. }
  298. break;
  299. }
  300. case 2: // MASK
  301. {
  302. dwErr = GetIpMask( ppwcArguments[i+dwCurrentIndex],
  303. &ipMask );
  304. if (dwErr is ERROR_INVALID_PARAMETER)
  305. {
  306. DisplayMessage( g_hModule, MSG_IP_BAD_IP_ADDR,
  307. ppwcArguments[i + dwCurrentIndex]);
  308. DispTokenErrMsg(g_hModule, MSG_IP_BAD_OPTION_VALUE,
  309. pttTags[pdwTagType[i]].pwszTag,
  310. ppwcArguments[i + dwCurrentIndex]);
  311. i = dwArgCount;
  312. break;
  313. }
  314. break;
  315. }
  316. case 3: // VIEW
  317. {
  318. TOKEN_VALUE rgMaskEnums[] = {
  319. { TOKEN_VALUE_UNICAST, RTM_VIEW_MASK_UCAST },
  320. { TOKEN_VALUE_MULTICAST, RTM_VIEW_MASK_MCAST },
  321. { TOKEN_VALUE_BOTH, RTM_VIEW_MASK_UCAST
  322. |RTM_VIEW_MASK_MCAST } };
  323. dwErr = MatchEnumTag( g_hModule,
  324. ppwcArguments[i + dwCurrentIndex],
  325. sizeof(rgMaskEnums)/sizeof(TOKEN_VALUE),
  326. rgMaskEnums,
  327. &dwViewMask);
  328. if (dwErr isnot NO_ERROR)
  329. {
  330. DispTokenErrMsg( g_hModule,
  331. MSG_IP_BAD_OPTION_VALUE,
  332. pttTags[pdwTagType[i]].pwszTag,
  333. ppwcArguments[i + dwCurrentIndex] );
  334. i = dwArgCount;
  335. return ERROR_INVALID_PARAMETER;
  336. }
  337. break;
  338. }
  339. case 4: // PROTO
  340. {
  341. dwProtocol =
  342. MatchRoutingProtoTag(ppwcArguments[i + dwCurrentIndex]);
  343. break;
  344. }
  345. }
  346. }
  347. if (dwErr isnot NO_ERROR)
  348. {
  349. return dwErr;
  350. }
  351. // Compose MIB query
  352. pQuery->dwVarId = dwOperator;
  353. pQuery->rgdwVarIndex[0] = ipAddress;
  354. pQuery->rgdwVarIndex[1] = ipMask;
  355. pQuery->rgdwVarIndex[2] = dwViewMask;
  356. pQuery->rgdwVarIndex[3] = dwProtocol;
  357. dwErr = MibGet( PID_IP,
  358. IPRTRMGR_PID,
  359. (PVOID) pQuery,
  360. sizeof(MIB_OPAQUE_QUERY) + 3*sizeof(DWORD),
  361. (PVOID *) &pRpcInfo,
  362. &dwOutEntrySize );
  363. if ( dwErr isnot NO_ERROR )
  364. {
  365. DisplayMessage(g_hModule, MSG_IP_DIM_ERROR, dwErr );
  366. return dwErr;
  367. }
  368. if ( pRpcInfo is NULL )
  369. {
  370. DisplayMessage(g_hModule, MSG_IP_NO_ENTRIES );
  371. return dwErr;
  372. }
  373. // Display info
  374. lprpcTable = (PMIB_IPDESTTABLE)(pRpcInfo->rgbyData);
  375. dwCount = lprpcTable->dwNumEntries;
  376. DisplayMessage( g_hModule, MSG_RTR_ROUTE_HDR );
  377. for (i=0; i<dwCount; i++)
  378. {
  379. MakePrefixStringW( wcszBuffer,
  380. lprpcTable->table[i].dwForwardDest,
  381. lprpcTable->table[i].dwForwardMask );
  382. if (IpmontrGetFriendlyNameFromIfIndex( g_hMIBServer,
  383. lprpcTable->table[i].dwForwardIfIndex,
  384. wcszName,
  385. sizeof(wcszName) ) != NO_ERROR)
  386. {
  387. //
  388. // If we do not have a name for this index, display index
  389. //
  390. swprintf( wcszName,
  391. L"0x%x",
  392. lprpcTable->table[i].dwForwardIfIndex );
  393. }
  394. MakeAddressStringW( wcszNHop,
  395. lprpcTable->table[i].dwForwardNextHop );
  396. wszViews[0] = (lprpcTable->table[i].dwForwardViewSet & RTM_VIEW_MASK_UCAST)? 'U':' ';
  397. wszViews[1] = (lprpcTable->table[i].dwForwardViewSet & RTM_VIEW_MASK_MCAST)? 'M':' ';
  398. wszViews[2] = '\0';
  399. DisplayMessage( g_hModule,
  400. MSG_RTR_ROUTE_INFO,
  401. wcszBuffer,
  402. GetProtoProtoString(
  403. PROTO_TYPE_UCAST,
  404. 0,
  405. lprpcTable->table[i].dwForwardProto ),
  406. lprpcTable->table[i].dwForwardPreference,
  407. lprpcTable->table[i].dwForwardMetric1,
  408. wcszNHop,
  409. wszViews,
  410. wcszName );
  411. }
  412. MprAdminMIBBufferFree( (PVOID) pRpcInfo );
  413. return dwErr;
  414. }