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.

503 lines
18 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. DWORD BufLen = sizeof(wcszName);
  177. MakePrefixStringW( wcszBuffer,
  178. lprpcTable->table[i].dwForwardDest,
  179. lprpcTable->table[i].dwForwardMask );
  180. if (IpmontrGetFriendlyNameFromIfIndex( g_hMIBServer,
  181. lprpcTable->table[i].dwForwardIfIndex,
  182. wcszName,
  183. BufLen ) != NO_ERROR)
  184. {
  185. //
  186. // If we do not have a name for this index, display index
  187. //
  188. swprintf( wcszName,
  189. L"0x%x",
  190. lprpcTable->table[i].dwForwardIfIndex );
  191. }
  192. MakeAddressStringW( wcszNHop,
  193. lprpcTable->table[i].dwForwardNextHop );
  194. wszViews[0] = (lprpcTable->table[i].dwForwardViewSet & RTM_VIEW_MASK_UCAST)? 'U':' ';
  195. wszViews[1] = (lprpcTable->table[i].dwForwardViewSet & RTM_VIEW_MASK_MCAST)? 'M':' ';
  196. wszViews[2] = '\0';
  197. DisplayMessage( g_hModule, MSG_RTR_ROUTE_INFO,
  198. wcszBuffer,
  199. GetProtoProtoString(
  200. PROTO_TYPE_UCAST,
  201. 0,
  202. lprpcTable->table[i].dwForwardProto ),
  203. lprpcTable->table[i].dwForwardPreference,
  204. lprpcTable->table[i].dwForwardMetric1,
  205. wcszNHop,
  206. wszViews,
  207. wcszName );
  208. }
  209. MprAdminMIBBufferFree( (PVOID) pRpcInfo );
  210. return dwErr;
  211. }
  212. DWORD
  213. HandleIpShowRtmRoutes(
  214. IN LPCWSTR pwszMachine,
  215. IN OUT LPWSTR *ppwcArguments,
  216. IN DWORD dwCurrentIndex,
  217. IN DWORD dwArgCount,
  218. IN DWORD dwFlags,
  219. IN LPCVOID pvData,
  220. OUT BOOL *pbDone
  221. )
  222. {
  223. TAG_TYPE pttTags[] = {{TOKEN_OPERATOR, FALSE,FALSE},
  224. {TOKEN_DEST, FALSE,FALSE},
  225. {TOKEN_MASK, FALSE,FALSE},
  226. {TOKEN_VIEW, FALSE,FALSE},
  227. {TOKEN_PROTOCOL, FALSE,FALSE}};
  228. DWORD pdwTagType[sizeof(pttTags)/sizeof(TAG_TYPE)];
  229. DWORD dwErr, i, dwOperator = ROUTE_LONGER;
  230. DWORD dwViewMask = DEFAULT_VIEW_MASK;
  231. DWORD dwProtocol = DEFAULT_PROTO;
  232. IPV4_ADDRESS ipMask = DEFAULT_MASK;
  233. IPV4_ADDRESS ipAddress = DEFAULT_ADDR;
  234. MIB_OPAQUE_QUERY QueryBuff[3]; // more than enough
  235. MIB_OPAQUE_QUERY *pQuery = QueryBuff;
  236. DWORD dwOutEntrySize, dwCount;
  237. PMIB_OPAQUE_INFO pRpcInfo;
  238. PMIB_IPDESTTABLE lprpcTable;
  239. WCHAR wcszBuffer[80], wcszNHop[80];
  240. WCHAR wcszName[MAX_INTERFACE_NAME_LEN+1];
  241. WCHAR wszViews[3];
  242. //
  243. // We can show non persistent info only if router is running
  244. //
  245. CHECK_ROUTER_RUNNING();
  246. // Do generic processing
  247. dwErr = PreHandleCommand( ppwcArguments,
  248. dwCurrentIndex,
  249. dwArgCount,
  250. pttTags,
  251. sizeof(pttTags)/sizeof(TAG_TYPE),
  252. 0,
  253. sizeof(pttTags)/sizeof(TAG_TYPE),
  254. pdwTagType );
  255. if (dwErr)
  256. {
  257. return dwErr;
  258. }
  259. dwArgCount -= dwCurrentIndex;
  260. for (i=0; i<dwArgCount; i++)
  261. {
  262. switch(pdwTagType[i])
  263. {
  264. case 0: // OPERATOR
  265. {
  266. TOKEN_VALUE rgEnums[] ={{ TOKEN_VALUE_MATCHING,ROUTE_MATCHING},
  267. { TOKEN_VALUE_LONGER, ROUTE_LONGER },
  268. { TOKEN_VALUE_SHORTER, ROUTE_SHORTER}};
  269. dwErr = MatchEnumTag( g_hModule,
  270. ppwcArguments[i + dwCurrentIndex],
  271. sizeof(rgEnums)/sizeof(TOKEN_VALUE),
  272. rgEnums,
  273. &dwOperator);
  274. if (dwErr isnot NO_ERROR)
  275. {
  276. DispTokenErrMsg( g_hModule,
  277. MSG_IP_BAD_OPTION_VALUE,
  278. pttTags[pdwTagType[i]].pwszTag,
  279. ppwcArguments[i + dwCurrentIndex] );
  280. return ERROR_INVALID_PARAMETER;
  281. }
  282. break;
  283. }
  284. case 1: // ADDR
  285. {
  286. dwErr = GetIpPrefix( ppwcArguments[i+dwCurrentIndex],
  287. &ipAddress,
  288. &ipMask );
  289. if (dwErr is ERROR_INVALID_PARAMETER)
  290. {
  291. DisplayMessage( g_hModule, MSG_IP_BAD_IP_ADDR,
  292. ppwcArguments[i + dwCurrentIndex]);
  293. DispTokenErrMsg(g_hModule, MSG_IP_BAD_OPTION_VALUE,
  294. pttTags[pdwTagType[i]].pwszTag,
  295. ppwcArguments[i + dwCurrentIndex]);
  296. i = dwArgCount;
  297. break;
  298. }
  299. break;
  300. }
  301. case 2: // MASK
  302. {
  303. dwErr = GetIpMask( ppwcArguments[i+dwCurrentIndex],
  304. &ipMask );
  305. if (dwErr is ERROR_INVALID_PARAMETER)
  306. {
  307. DisplayMessage( g_hModule, MSG_IP_BAD_IP_ADDR,
  308. ppwcArguments[i + dwCurrentIndex]);
  309. DispTokenErrMsg(g_hModule, MSG_IP_BAD_OPTION_VALUE,
  310. pttTags[pdwTagType[i]].pwszTag,
  311. ppwcArguments[i + dwCurrentIndex]);
  312. i = dwArgCount;
  313. break;
  314. }
  315. break;
  316. }
  317. case 3: // VIEW
  318. {
  319. TOKEN_VALUE rgMaskEnums[] = {
  320. { TOKEN_VALUE_UNICAST, RTM_VIEW_MASK_UCAST },
  321. { TOKEN_VALUE_MULTICAST, RTM_VIEW_MASK_MCAST },
  322. { TOKEN_VALUE_BOTH, RTM_VIEW_MASK_UCAST
  323. |RTM_VIEW_MASK_MCAST } };
  324. dwErr = MatchEnumTag( g_hModule,
  325. ppwcArguments[i + dwCurrentIndex],
  326. sizeof(rgMaskEnums)/sizeof(TOKEN_VALUE),
  327. rgMaskEnums,
  328. &dwViewMask);
  329. if (dwErr isnot NO_ERROR)
  330. {
  331. DispTokenErrMsg( g_hModule,
  332. MSG_IP_BAD_OPTION_VALUE,
  333. pttTags[pdwTagType[i]].pwszTag,
  334. ppwcArguments[i + dwCurrentIndex] );
  335. i = dwArgCount;
  336. return ERROR_INVALID_PARAMETER;
  337. }
  338. break;
  339. }
  340. case 4: // PROTO
  341. {
  342. dwProtocol =
  343. MatchRoutingProtoTag(ppwcArguments[i + dwCurrentIndex]);
  344. break;
  345. }
  346. }
  347. }
  348. if (dwErr isnot NO_ERROR)
  349. {
  350. return dwErr;
  351. }
  352. // Compose MIB query
  353. pQuery->dwVarId = dwOperator;
  354. pQuery->rgdwVarIndex[0] = ipAddress;
  355. pQuery->rgdwVarIndex[1] = ipMask;
  356. pQuery->rgdwVarIndex[2] = dwViewMask;
  357. pQuery->rgdwVarIndex[3] = dwProtocol;
  358. dwErr = MibGet( PID_IP,
  359. IPRTRMGR_PID,
  360. (PVOID) pQuery,
  361. sizeof(MIB_OPAQUE_QUERY) + 3*sizeof(DWORD),
  362. (PVOID *) &pRpcInfo,
  363. &dwOutEntrySize );
  364. if ( dwErr isnot NO_ERROR )
  365. {
  366. DisplayMessage(g_hModule, MSG_IP_DIM_ERROR, dwErr );
  367. return dwErr;
  368. }
  369. if ( pRpcInfo is NULL )
  370. {
  371. DisplayMessage(g_hModule, MSG_IP_NO_ENTRIES );
  372. return dwErr;
  373. }
  374. // Display info
  375. lprpcTable = (PMIB_IPDESTTABLE)(pRpcInfo->rgbyData);
  376. dwCount = lprpcTable->dwNumEntries;
  377. DisplayMessage( g_hModule, MSG_RTR_ROUTE_HDR );
  378. for (i=0; i<dwCount; i++)
  379. {
  380. DWORD BufLen = sizeof(wcszName);
  381. MakePrefixStringW( wcszBuffer,
  382. lprpcTable->table[i].dwForwardDest,
  383. lprpcTable->table[i].dwForwardMask );
  384. if (IpmontrGetFriendlyNameFromIfIndex( g_hMIBServer,
  385. lprpcTable->table[i].dwForwardIfIndex,
  386. wcszName,
  387. BufLen ) != NO_ERROR)
  388. {
  389. //
  390. // If we do not have a name for this index, display index
  391. //
  392. swprintf( wcszName,
  393. L"0x%x",
  394. lprpcTable->table[i].dwForwardIfIndex );
  395. }
  396. MakeAddressStringW( wcszNHop,
  397. lprpcTable->table[i].dwForwardNextHop );
  398. wszViews[0] = (lprpcTable->table[i].dwForwardViewSet & RTM_VIEW_MASK_UCAST)? 'U':' ';
  399. wszViews[1] = (lprpcTable->table[i].dwForwardViewSet & RTM_VIEW_MASK_MCAST)? 'M':' ';
  400. wszViews[2] = '\0';
  401. DisplayMessage( g_hModule,
  402. MSG_RTR_ROUTE_INFO,
  403. wcszBuffer,
  404. GetProtoProtoString(
  405. PROTO_TYPE_UCAST,
  406. 0,
  407. lprpcTable->table[i].dwForwardProto ),
  408. lprpcTable->table[i].dwForwardPreference,
  409. lprpcTable->table[i].dwForwardMetric1,
  410. wcszNHop,
  411. wszViews,
  412. wcszName );
  413. }
  414. MprAdminMIBBufferFree( (PVOID) pRpcInfo );
  415. return dwErr;
  416. }