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.

3596 lines
110 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. Author:
  6. Revision History:
  7. --*/
  8. #include "allinc.h"
  9. #include "oid.h"
  10. //
  11. // Values of InetAddressType.
  12. //
  13. typedef enum {
  14. INET_ADDRESS_TYPE_UNKNOWN = 0,
  15. INET_ADDRESS_TYPE_IPv4 = 1,
  16. INET_ADDRESS_TYPE_IPv6 = 2
  17. } INET_ADDRESS_TYPE;
  18. UINT
  19. MibGetIfNumber(
  20. UINT actionId,
  21. AsnAny *objectArray,
  22. UINT *errorIndex
  23. )
  24. {
  25. DWORD dwResult;
  26. PIF_NUMBER_GET pOutput;
  27. TraceEnter("MibGetIfNumber");
  28. dwResult = UpdateCache(MIB_II_IF);
  29. if(dwResult isnot NO_ERROR)
  30. {
  31. TRACE1("Couldnt update IF cache. Error %d", dwResult);
  32. TraceLeave("MibGetIfNumber");
  33. return dwResult;
  34. }
  35. pOutput = (PIF_NUMBER_GET)objectArray;
  36. EnterReader(MIB_II_IF);
  37. SetAsnInteger(&(pOutput->ifNumber),g_Cache.pRpcIfTable->dwNumEntries);
  38. ReleaseLock(MIB_II_IF);
  39. TraceLeave("MibGetIfNumber");
  40. return MIB_S_SUCCESS;
  41. }
  42. UINT
  43. MibGetIfEntry(
  44. UINT actionId,
  45. AsnAny *objectArray,
  46. UINT *errorIndex
  47. )
  48. {
  49. DWORD dwResult;
  50. PMIB_IFROW pRpcIf;
  51. PIF_ENTRY_GET pOutput;
  52. TraceEnter("MibGetIfEntry");
  53. dwResult = UpdateCache(MIB_II_IF);
  54. if(dwResult isnot NO_ERROR)
  55. {
  56. TRACE1("Couldnt update IF cache. Error %d",dwResult);
  57. TraceLeave("MibGetIfEntry");
  58. return dwResult;
  59. }
  60. pOutput = (PIF_ENTRY_GET)objectArray;
  61. EnterReader(MIB_II_IF);
  62. pRpcIf = LocateIfRow(actionId,
  63. &(pOutput->ifIndex));
  64. if(pRpcIf is NULL)
  65. {
  66. ReleaseLock(MIB_II_IF);
  67. TRACE2("Unable to locate IF Row. Action is %d. Index is %d",
  68. actionId,
  69. GetAsnInteger(&(pOutput->ifIndex),-1));
  70. TraceLeave("MibGetIfEntry");
  71. if(actionId is MIB_ACTION_GETNEXT)
  72. {
  73. return MIB_S_NO_MORE_ENTRIES;
  74. }
  75. return MIB_S_ENTRY_NOT_FOUND;
  76. }
  77. ForceSetAsnInteger(&(pOutput->ifIndex),pRpcIf->dwIndex);
  78. // SetAsnDispString(&(pOutput->ifDescr),
  79. SetAsnOctetString(&(pOutput->ifDescr),
  80. pOutput->rgbyIfDescrInfo,
  81. pRpcIf->bDescr,
  82. min(pRpcIf->dwDescrLen,MAX_IF_DESCR_LEN));
  83. SetAsnInteger(&(pOutput->ifType),pRpcIf->dwType);
  84. SetAsnInteger(&(pOutput->ifMtu),pRpcIf->dwMtu);
  85. SetAsnGauge(&(pOutput->ifSpeed),pRpcIf->dwSpeed);
  86. SetAsnOctetString(&(pOutput->ifPhysAddress),
  87. pOutput->rgbyIfPhysAddressInfo,
  88. pRpcIf->bPhysAddr,
  89. pRpcIf->dwPhysAddrLen);
  90. /*if(!IsAsnTypeNull(&(pOutput->ifPhysAddress)))
  91. {
  92. pOutput->ifPhysAddress.asnValue.string.length = pRpcIf->dwPhysAddrLen;
  93. pOutput->ifPhysAddress.asnValue.string.stream = pOutput->rgbyIfPhysAddressInfo;
  94. CopyMemory(pOutput->rgbyIfPhysAddressInfo,
  95. pRpcIf->rgbyPhysAddr,
  96. pRpcIf->dwPhysAddrLen);
  97. }*/
  98. SetAsnInteger(&(pOutput->ifAdminStatus), pRpcIf->dwAdminStatus);
  99. SetAsnInteger(&(pOutput->ifOperStatus), pRpcIf->dwOperStatus);
  100. SetAsnTimeTicks(&(pOutput->ifLastChange), SnmpSvcGetUptimeFromTime(pRpcIf->dwLastChange));
  101. SetAsnCounter(&(pOutput->ifInOctets), pRpcIf->dwInOctets);
  102. SetAsnCounter(&(pOutput->ifInUcastPkts), pRpcIf->dwInUcastPkts);
  103. SetAsnCounter(&(pOutput->ifInNUcastPkts), pRpcIf->dwInNUcastPkts);
  104. SetAsnCounter(&(pOutput->ifInDiscards), pRpcIf->dwInDiscards);
  105. SetAsnCounter(&(pOutput->ifInErrors), pRpcIf->dwInErrors);
  106. SetAsnCounter(&(pOutput->ifInUnknownProtos), pRpcIf->dwInUnknownProtos);
  107. SetAsnCounter(&(pOutput->ifOutOctets), pRpcIf->dwOutOctets);
  108. SetAsnCounter(&(pOutput->ifOutUcastPkts), pRpcIf->dwOutUcastPkts);
  109. SetAsnCounter(&(pOutput->ifOutNUcastPkts), pRpcIf->dwOutNUcastPkts);
  110. SetAsnCounter(&(pOutput->ifOutDiscards), pRpcIf->dwOutDiscards);
  111. SetAsnCounter(&(pOutput->ifOutErrors), pRpcIf->dwOutErrors);
  112. SetAsnGauge(&(pOutput->ifOutQLen), pRpcIf->dwOutQLen);
  113. SetToZeroOid(&(pOutput->ifSpecific));
  114. ReleaseLock(MIB_II_IF);
  115. TraceLeave("MibGetIfEntry");
  116. return MIB_S_SUCCESS;
  117. }
  118. UINT
  119. MibSetIfEntry(
  120. UINT actionId,
  121. AsnAny *objectArray,
  122. UINT *errorIndex
  123. )
  124. {
  125. DWORD dwResult,dwStatus;
  126. PMIB_IFROW pRpcIf;
  127. PIF_ENTRY_SET pInput;
  128. PMIB_OPAQUE_INFO pInfo;
  129. PMIB_IFROW pSetRow;
  130. pInput = (PIF_ENTRY_SET)objectArray;
  131. pInfo = (PMIB_OPAQUE_INFO)(pInput->rgdwSetBuffer);
  132. pSetRow = (PMIB_IFROW)(pInfo->rgbyData);
  133. switch(actionId)
  134. {
  135. case MIB_ACTION_VALIDATE:
  136. {
  137. TraceEnter("MibSetIfEntry - VALIDATE");
  138. ASSERT(!(IsAsnTypeNull(&(pInput->ifIndex)) or
  139. IsAsnTypeNull(&(pInput->ifAdminStatus))));
  140. pInput->bLocked = FALSE;
  141. dwStatus = GetAsnInteger(&(pInput->ifAdminStatus), 0);
  142. if((dwStatus isnot IF_ADMIN_STATUS_UP) and
  143. (dwStatus isnot IF_ADMIN_STATUS_DOWN))
  144. {
  145. TRACE0("Status must be UP or DOWN");
  146. TraceLeave("MibSetIfEntry");
  147. return MIB_S_INVALID_PARAMETER;
  148. }
  149. dwResult = UpdateCache(MIB_II_IF);
  150. if(dwResult isnot NO_ERROR)
  151. {
  152. TRACE1("Couldnt update IF cache. Error %d",dwResult);
  153. TraceLeave("MibSetIfEntry");
  154. return dwResult;
  155. }
  156. pInfo->dwId = IF_ROW;
  157. //
  158. // We take the lock here and then release it in the cleanup
  159. // This ensures that things dont change between the two calls
  160. //
  161. EnterWriter(MIB_II_IF);
  162. pInput->bLocked = TRUE;
  163. pRpcIf = LocateIfRow(GET_EXACT,
  164. &(pInput->ifIndex));
  165. if(pRpcIf is NULL)
  166. {
  167. ReleaseLock(MIB_II_IF);
  168. pInput->bLocked = FALSE;
  169. TRACE1("Unable to locate IF Row. Index is %d",
  170. GetAsnInteger(&(pInput->ifIndex),-1));
  171. TraceLeave("MibSetIfEntry");
  172. return MIB_S_ENTRY_NOT_FOUND;
  173. }
  174. if(pRpcIf->dwAdminStatus is dwStatus)
  175. {
  176. //
  177. // Since the types are same, this is a NOP.
  178. //
  179. pInput->raAction = NOP;
  180. TraceLeave("MibSetIfEntry - SET");
  181. return MIB_S_SUCCESS;
  182. }
  183. pInput->raAction = SET_ROW;
  184. pSetRow->dwIndex = pRpcIf->dwIndex;
  185. pSetRow->dwAdminStatus = dwStatus;
  186. TraceLeave("MibSetIfEntry - SET");
  187. return MIB_S_SUCCESS;
  188. }
  189. case MIB_ACTION_SET:
  190. {
  191. TraceEnter("MibSetIfEntry - SET");
  192. dwResult = NO_ERROR;
  193. if(pInput->raAction is SET_ROW)
  194. {
  195. dwResult = InternalSetIfEntry(pInfo);
  196. #ifdef MIB_DEBUG
  197. if(dwResult isnot NO_ERROR)
  198. {
  199. TRACE1("Set failed!!. Error %d",
  200. dwResult);
  201. }
  202. #endif
  203. InvalidateCache(MIB_II_IF);
  204. }
  205. TraceLeave("MibSetIfEntry");
  206. return dwResult;
  207. }
  208. case MIB_ACTION_CLEANUP:
  209. {
  210. if(pInput->bLocked)
  211. {
  212. ReleaseLock(MIB_II_IF);
  213. }
  214. TraceEnter("MibSetIfEntry - CLEANUP");
  215. TraceLeave("MibSetIfEntry");
  216. return MIB_S_SUCCESS;
  217. }
  218. default:
  219. {
  220. TraceEnter("MibSetIfEntry - WRONG ACTION");
  221. TraceLeave("MibSetIfEntry");
  222. return MIB_S_INVALID_PARAMETER;
  223. }
  224. }
  225. }
  226. UINT
  227. MibGetIpGroup(
  228. UINT actionId,
  229. AsnAny *objectArray,
  230. UINT *errorIndex
  231. )
  232. {
  233. DWORD dwResult;
  234. PIP_STATS_GET pOutput;
  235. MIB_IPSTATS rpcIpStats;
  236. TraceEnter("MibGetIpGroup");
  237. dwResult = GetIpStatistics(&rpcIpStats);
  238. if(dwResult isnot NO_ERROR)
  239. {
  240. TRACE1("Couldnt get IP stats. Error %d",dwResult);
  241. TraceLeave("MibGetIpGroup");
  242. return dwResult;
  243. }
  244. pOutput = (PIP_STATS_GET)objectArray;
  245. SetAsnInteger(&(pOutput->ipForwarding), rpcIpStats.dwForwarding);
  246. SetAsnInteger(&(pOutput->ipDefaultTTL), rpcIpStats.dwDefaultTTL);
  247. SetAsnCounter(&(pOutput->ipInReceives), rpcIpStats.dwInReceives);
  248. SetAsnCounter(&(pOutput->ipInHdrErrors), rpcIpStats.dwInHdrErrors);
  249. SetAsnCounter(&(pOutput->ipInAddrErrors), rpcIpStats.dwInAddrErrors);
  250. SetAsnCounter(&(pOutput->ipForwDatagrams), rpcIpStats.dwForwDatagrams);
  251. SetAsnCounter(&(pOutput->ipInUnknownProtos), rpcIpStats.dwInUnknownProtos);
  252. SetAsnCounter(&(pOutput->ipInDiscards), rpcIpStats.dwInDiscards);
  253. SetAsnCounter(&(pOutput->ipInDelivers), rpcIpStats.dwInDelivers);
  254. SetAsnCounter(&(pOutput->ipOutRequests), rpcIpStats.dwOutRequests);
  255. SetAsnCounter(&(pOutput->ipOutDiscards), rpcIpStats.dwOutDiscards);
  256. SetAsnCounter(&(pOutput->ipOutNoRoutes), rpcIpStats.dwOutNoRoutes);
  257. SetAsnInteger(&(pOutput->ipReasmTimeout), rpcIpStats.dwReasmTimeout);
  258. SetAsnCounter(&(pOutput->ipReasmReqds), rpcIpStats.dwReasmReqds);
  259. SetAsnCounter(&(pOutput->ipReasmOKs), rpcIpStats.dwReasmOks);
  260. SetAsnCounter(&(pOutput->ipReasmFails), rpcIpStats.dwReasmFails);
  261. SetAsnCounter(&(pOutput->ipFragOKs), rpcIpStats.dwFragOks);
  262. SetAsnCounter(&(pOutput->ipFragFails), rpcIpStats.dwFragFails);
  263. SetAsnCounter(&(pOutput->ipFragCreates), rpcIpStats.dwFragCreates);
  264. SetAsnCounter(&(pOutput->ipRoutingDiscards), rpcIpStats.dwRoutingDiscards);
  265. TraceLeave("MibGetIpGroup");
  266. return MIB_S_SUCCESS;
  267. }
  268. UINT
  269. MibSetIpGroup(
  270. UINT actionId,
  271. AsnAny *objectArray,
  272. UINT *errorIndex
  273. )
  274. {
  275. MIB_IPSTATS rpcIpStats;
  276. DWORD dwResult,dwTTL,dwForw;
  277. PIP_STATS_SET pInput;
  278. PMIB_OPAQUE_INFO pInfo;
  279. PMIB_IPSTATS pSetStats;
  280. pInput = (PIP_STATS_SET)objectArray;
  281. pInfo = (PMIB_OPAQUE_INFO)(pInput->rgdwSetBuffer);
  282. pSetStats = (PMIB_IPSTATS)(pInfo->rgbyData);
  283. switch(actionId)
  284. {
  285. case MIB_ACTION_VALIDATE:
  286. {
  287. TraceEnter("MibSetIpGroup- VALIDATE");
  288. if(IsAsnTypeNull(&(pInput->ipDefaultTTL)) and
  289. IsAsnTypeNull(&(pInput->ipForwarding)))
  290. {
  291. TRACE0("Can only set TTL and Forwarding");
  292. TraceLeave("MibSetIpGroup");
  293. return MIB_S_INVALID_PARAMETER;
  294. }
  295. dwResult = GetIpStatistics(&rpcIpStats);
  296. if(dwResult isnot NO_ERROR)
  297. {
  298. TRACE1("Couldnt get IP stats. Error %d",dwResult);
  299. TraceLeave("MibSetIpGroup");
  300. return dwResult;
  301. }
  302. pInfo->dwId = IP_STATS;
  303. dwTTL = GetAsnInteger(&(pInput->ipDefaultTTL), rpcIpStats.dwDefaultTTL);
  304. dwForw = GetAsnInteger(&(pInput->ipForwarding), rpcIpStats.dwForwarding);
  305. //
  306. // Per RFC 2011, the valid range is [1..255].
  307. //
  308. if((dwTTL < 1) || (dwTTL > 255))
  309. {
  310. TRACE0("TTL must be in the range [1..255]");
  311. TraceLeave("MibSetIpGroup");
  312. return MIB_S_INVALID_PARAMETER;
  313. }
  314. if((dwForw isnot MIB_IP_FORWARDING) and
  315. (dwForw isnot MIB_IP_NOT_FORWARDING))
  316. {
  317. TRACE0("Forwarding value wrong");
  318. TraceLeave("MibSetIpGroup");
  319. return MIB_S_INVALID_PARAMETER;
  320. }
  321. pSetStats->dwForwarding = dwForw;
  322. pSetStats->dwDefaultTTL = dwTTL;
  323. TraceLeave("MibSetIpGroup");
  324. return MIB_S_SUCCESS;
  325. }
  326. case MIB_ACTION_SET:
  327. {
  328. TraceEnter("MibSetIpGroup - SET");
  329. dwResult = InternalSetIpStats(pInfo);
  330. #ifdef MIB_DEBUG
  331. if(dwResult isnot NO_ERROR)
  332. {
  333. TRACE1("Set returned error %d!!",dwResult);
  334. }
  335. #endif
  336. TraceLeave("MibSetIpGroup");
  337. return dwResult;
  338. }
  339. case MIB_ACTION_CLEANUP:
  340. {
  341. TraceEnter("MibSetIpGroup - CLEANUP");
  342. TraceLeave("MibSetIpGroup");
  343. return MIB_S_SUCCESS;
  344. }
  345. default:
  346. {
  347. TraceEnter("MibSetIpGroup - WRONG ACTION");
  348. TraceLeave("MibSetIpGroup");
  349. return MIB_S_INVALID_PARAMETER;
  350. }
  351. }
  352. }
  353. UINT
  354. MibGetIpAddressEntry(
  355. UINT actionId,
  356. AsnAny *objectArray,
  357. UINT *errorIndex
  358. )
  359. {
  360. PMIB_IPADDRROW pRpcIpAddr;
  361. DWORD dwResult;
  362. PIP_ADDRESS_ENTRY_GET pOutput;
  363. TraceEnter("MibGetIpAddressEntry");
  364. dwResult = UpdateCache(MIB_II_IPADDR);
  365. if(dwResult isnot NO_ERROR)
  366. {
  367. TRACE1("Couldnt update IP Addr cache. Error %d", dwResult);
  368. TraceLeave("MibGetIpAddressEntry");
  369. return dwResult;
  370. }
  371. pOutput = (PIP_ADDRESS_ENTRY_GET)objectArray;
  372. EnterReader(MIB_II_IPADDR);
  373. pRpcIpAddr = LocateIpAddrRow(actionId,
  374. &(pOutput->ipAdEntAddr));
  375. if(pRpcIpAddr is NULL)
  376. {
  377. ReleaseLock(MIB_II_IPADDR);
  378. TRACE2("Unable to locate IP Addr Row. Action is %d, Address is %x",
  379. actionId,
  380. GetAsnIPAddress(&(pOutput->ipAdEntAddr),0xffffffff));
  381. TraceLeave("MibGetIpAddressEntry");
  382. if(actionId is MIB_ACTION_GETNEXT)
  383. {
  384. return MIB_S_NO_MORE_ENTRIES;
  385. }
  386. return MIB_S_ENTRY_NOT_FOUND;
  387. }
  388. ForceSetAsnIPAddress(&(pOutput->ipAdEntAddr),
  389. &(pOutput->dwIpAdEntAddrInfo),
  390. pRpcIpAddr->dwAddr);
  391. SetAsnInteger(&(pOutput->ipAdEntIfIndex), pRpcIpAddr->dwIndex);
  392. SetAsnIPAddress(&(pOutput->ipAdEntNetMask),
  393. &(pOutput->dwIpAdEntNetMaskInfo),
  394. pRpcIpAddr->dwMask);
  395. SetAsnInteger(&(pOutput->ipAdEntBcastAddr), pRpcIpAddr->dwBCastAddr);
  396. SetAsnInteger(&(pOutput->ipAdEntReasmMaxSize), pRpcIpAddr->dwReasmSize);
  397. ReleaseLock(MIB_II_IPADDR);
  398. TraceLeave("MibGetIpAddressEntry");
  399. return MIB_S_SUCCESS;
  400. }
  401. UINT
  402. MibGetIpRouteEntry(
  403. UINT actionId,
  404. AsnAny *objectArray,
  405. UINT *errorIndex
  406. )
  407. {
  408. DWORD dwResult;
  409. PMIB_IPFORWARDROW pRpcIpForw;
  410. PIP_ROUTE_ENTRY_GET pOutput;
  411. TraceEnter("MibGetIpRouteEntry");
  412. dwResult = UpdateCache(FORWARD_MIB);
  413. if(dwResult isnot NO_ERROR)
  414. {
  415. TRACE1("Couldnt update IP Forward cache. Error %d", dwResult);
  416. TraceLeave("MibGetIpRouteEntry");
  417. return dwResult;
  418. }
  419. pOutput = (PIP_ROUTE_ENTRY_GET)objectArray;
  420. EnterReader(FORWARD_MIB);
  421. pRpcIpForw = LocateIpRouteRow(actionId,
  422. &(pOutput->ipRouteDest));
  423. if(pRpcIpForw is NULL)
  424. {
  425. ReleaseLock(FORWARD_MIB);
  426. TRACE2("Unable to locate IP ROUTE Row. Action is %d. Dest is %x",
  427. actionId,
  428. GetAsnIPAddress(&(pOutput->ipRouteDest),0xffffffff));
  429. TraceLeave("MibGetIpRouteEntry");
  430. if(actionId is MIB_ACTION_GETNEXT)
  431. {
  432. return MIB_S_NO_MORE_ENTRIES;
  433. }
  434. return MIB_S_ENTRY_NOT_FOUND;
  435. }
  436. ForceSetAsnIPAddress(&(pOutput->ipRouteDest),
  437. &(pOutput->dwIpRouteDestInfo),
  438. pRpcIpForw->dwForwardDest);
  439. SetAsnInteger(&(pOutput->ipRouteIfIndex), pRpcIpForw->dwForwardIfIndex);
  440. SetAsnInteger(&(pOutput->ipRouteMetric1), pRpcIpForw->dwForwardMetric1);
  441. SetAsnInteger(&(pOutput->ipRouteMetric2), pRpcIpForw->dwForwardMetric2);
  442. SetAsnInteger(&(pOutput->ipRouteMetric3), pRpcIpForw->dwForwardMetric3);
  443. SetAsnInteger(&(pOutput->ipRouteMetric4), pRpcIpForw->dwForwardMetric4);
  444. SetAsnIPAddress(&(pOutput->ipRouteNextHop),
  445. &(pOutput->dwIpRouteNextHopInfo),
  446. pRpcIpForw->dwForwardNextHop);
  447. SetAsnInteger(&(pOutput->ipRouteType), pRpcIpForw->dwForwardType);
  448. SetAsnInteger(&(pOutput->ipRouteProto), pRpcIpForw->dwForwardProto);
  449. SetAsnInteger(&(pOutput->ipRouteAge), pRpcIpForw->dwForwardAge);
  450. SetAsnIPAddress(&(pOutput->ipRouteMask),
  451. &(pOutput->dwIpRouteMaskInfo),
  452. pRpcIpForw->dwForwardMask);
  453. SetAsnInteger(&(pOutput->ipRouteMetric5), pRpcIpForw->dwForwardMetric5);
  454. SetToZeroOid(&(pOutput->ipRouteInfo));
  455. ReleaseLock(FORWARD_MIB);
  456. TraceLeave("MibGetIpRouteEntry");
  457. return MIB_S_SUCCESS;
  458. }
  459. UINT
  460. MibSetIpRouteEntry(
  461. UINT actionId,
  462. AsnAny *objectArray,
  463. UINT *errorIndex
  464. )
  465. {
  466. DWORD dwResult,dwType,dwIfIndex,dwNextHop;
  467. PMIB_IPFORWARDROW pRpcIpForw;
  468. PIP_ROUTE_ENTRY_SET pInput;
  469. PMIB_OPAQUE_INFO pInfo;
  470. PMIB_IPFORWARDROW pSetRow;
  471. pInput = (PIP_ROUTE_ENTRY_SET)objectArray;
  472. pInfo = (PMIB_OPAQUE_INFO)(pInput->rgdwSetBuffer);
  473. pSetRow = (PMIB_IPFORWARDROW)(pInfo->rgbyData);
  474. switch(actionId)
  475. {
  476. case MIB_ACTION_VALIDATE:
  477. {
  478. TraceEnter("MibSetIpRouteEntry - VALIDATE");
  479. ASSERT(!(IsAsnTypeNull(&(pInput->ipRouteDest))));
  480. pInput->bLocked = FALSE;
  481. dwResult = UpdateCache(FORWARD_MIB);
  482. if(dwResult isnot NO_ERROR)
  483. {
  484. TRACE1("Couldnt update IP Forward cache. Error %d", dwResult);
  485. TraceLeave("MibGetIpRouteEntry");
  486. return dwResult;
  487. }
  488. pInfo->dwId = IP_FORWARDROW;
  489. EnterWriter(FORWARD_MIB);
  490. pInput->bLocked = TRUE;
  491. pRpcIpForw = LocateIpRouteRow(GET_EXACT,
  492. &(pInput->ipRouteDest));
  493. if(pRpcIpForw is NULL)
  494. {
  495. //
  496. // So we are creating a row. We need the If index,
  497. // the mask, next hop and metric 1. We will try to
  498. // determine If index later if necessary.
  499. //
  500. if(IsAsnTypeNull(&(pInput->ipRouteMask)) or
  501. IsAsnTypeNull(&(pInput->ipRouteNextHop)) or
  502. IsAsnTypeNull(&(pInput->ipRouteMetric1)))
  503. {
  504. ReleaseLock(FORWARD_MIB);
  505. pInput->bLocked = FALSE;
  506. TRACE0("Not enough information to create a route");
  507. TraceLeave("MibSetIpRouteEntry");
  508. return MIB_S_INVALID_PARAMETER;
  509. }
  510. dwType = GetAsnInteger(&(pInput->ipRouteType),
  511. MIB_IPROUTE_TYPE_OTHER);
  512. if(dwType is MIB_IPROUTE_TYPE_INVALID)
  513. {
  514. //
  515. // We couldnt be creating and deleting a row at the
  516. // same time
  517. //
  518. ReleaseLock(FORWARD_MIB);
  519. pInput->bLocked = FALSE;
  520. TRACE0("Wrong type");
  521. TraceLeave("MibSetIpRouteEntry");
  522. return MIB_S_INVALID_PARAMETER;
  523. }
  524. dwIfIndex = GetAsnInteger(&(pInput->ipRouteIfIndex),0);
  525. dwNextHop = GetAsnIPAddress(&(pInput->ipRouteNextHop),0x00000000);
  526. if(dwIfIndex is 0)
  527. {
  528. //
  529. // Attempt to determine the correct ifIndex
  530. //
  531. dwIfIndex = GetIfIndexFromAddr(dwNextHop);
  532. if(dwIfIndex is INVALID_IFINDEX)
  533. {
  534. //
  535. // We couldnt determine the correct ifIndex
  536. //
  537. ReleaseLock(FORWARD_MIB);
  538. pInput->bLocked = FALSE;
  539. TRACE0("Could not determine ifIndex");
  540. TraceLeave("MibSetIpRouteEntry");
  541. return MIB_S_INVALID_PARAMETER;
  542. }
  543. }
  544. pInput->raAction = CREATE_ROW;
  545. pSetRow->dwForwardType = dwType;
  546. pSetRow->dwForwardIfIndex = dwIfIndex;
  547. pSetRow->dwForwardNextHop = dwNextHop;
  548. pSetRow->dwForwardDest =
  549. GetAsnIPAddress(&(pInput->ipRouteDest),0xffffffff);
  550. pSetRow->dwForwardMask =
  551. GetAsnIPAddress(&(pInput->ipRouteMask),0x00000000);
  552. pSetRow->dwForwardPolicy = 0;
  553. pSetRow->dwForwardProto =
  554. GetAsnInteger(&(pInput->ipRouteProto),MIB_IPPROTO_NETMGMT);
  555. //
  556. // We default to an age of INFINITE
  557. //
  558. pSetRow->dwForwardAge =
  559. GetAsnInteger(&(pInput->ipRouteAge),INFINITE);
  560. pSetRow->dwForwardNextHopAS = 0;
  561. pSetRow->dwForwardMetric1 =
  562. GetAsnInteger(&(pInput->ipRouteMetric1),0);
  563. pSetRow->dwForwardMetric2 =
  564. GetAsnInteger(&(pInput->ipRouteMetric2),-1);
  565. pSetRow->dwForwardMetric3 =
  566. GetAsnInteger(&(pInput->ipRouteMetric3),-1);
  567. pSetRow->dwForwardMetric4 =
  568. GetAsnInteger(&(pInput->ipRouteMetric4),-1);
  569. pSetRow->dwForwardMetric5 =
  570. GetAsnInteger(&(pInput->ipRouteMetric5),-1);
  571. TraceLeave("MibSetIpRouteEntry");
  572. return MIB_S_SUCCESS;
  573. }
  574. else
  575. {
  576. //
  577. // Ok so we are only changing some stuff in the route
  578. //
  579. dwType = GetAsnInteger(&(pInput->ipRouteType),
  580. pRpcIpForw->dwForwardType);
  581. if(dwType is MIB_IPROUTE_TYPE_INVALID)
  582. {
  583. //
  584. // Deleting a row
  585. //
  586. pInput->raAction = DELETE_ROW;
  587. *pSetRow = *pRpcIpForw;
  588. TraceLeave("MibSetIpRouteEntry");
  589. return MIB_S_SUCCESS;
  590. }
  591. pInput->raAction = SET_ROW;
  592. pSetRow->dwForwardDest =
  593. GetAsnIPAddress(&(pInput->ipRouteDest),
  594. pRpcIpForw->dwForwardDest);
  595. pSetRow->dwForwardMask =
  596. GetAsnIPAddress(&(pInput->ipRouteMask),
  597. pRpcIpForw->dwForwardMask);
  598. pSetRow->dwForwardPolicy = 0;
  599. pSetRow->dwForwardNextHop =
  600. GetAsnIPAddress(&(pInput->ipRouteNextHop),
  601. pRpcIpForw->dwForwardNextHop);
  602. pSetRow->dwForwardIfIndex =
  603. GetAsnInteger(&(pInput->ipRouteIfIndex),
  604. pRpcIpForw->dwForwardIfIndex);
  605. //
  606. // The type gets set by the router manager. But incase
  607. // we are writing to the stack we need some kind of valid type
  608. //
  609. pSetRow->dwForwardType =
  610. GetAsnInteger(&(pInput->ipRouteType),
  611. pRpcIpForw->dwForwardType);
  612. pSetRow->dwForwardProto =
  613. GetAsnInteger(&(pInput->ipRouteProto),
  614. pRpcIpForw->dwForwardProto);
  615. pSetRow->dwForwardAge =
  616. GetAsnInteger(&(pInput->ipRouteAge),
  617. pRpcIpForw->dwForwardAge);
  618. pSetRow->dwForwardNextHopAS = 0;
  619. pSetRow->dwForwardMetric1 =
  620. GetAsnInteger(&(pInput->ipRouteMetric1),
  621. pRpcIpForw->dwForwardMetric1);
  622. pSetRow->dwForwardMetric2 =
  623. GetAsnInteger(&(pInput->ipRouteMetric2),
  624. pRpcIpForw->dwForwardMetric2);
  625. pSetRow->dwForwardMetric3 =
  626. GetAsnInteger(&(pInput->ipRouteMetric3),
  627. pRpcIpForw->dwForwardMetric3);
  628. pSetRow->dwForwardMetric4 =
  629. GetAsnInteger(&(pInput->ipRouteMetric4),
  630. pRpcIpForw->dwForwardMetric4);
  631. pSetRow->dwForwardMetric5 =
  632. GetAsnInteger(&(pInput->ipRouteMetric5),
  633. pRpcIpForw->dwForwardMetric5);
  634. TraceLeave("MibSetIpRouteEntry");
  635. return MIB_S_SUCCESS;
  636. }
  637. }
  638. case MIB_ACTION_SET:
  639. {
  640. TraceEnter("MibSetIpRouteEntry - SET");
  641. switch(pInput->raAction)
  642. {
  643. case CREATE_ROW:
  644. {
  645. dwResult = InternalCreateIpForwardEntry(pInfo);
  646. #ifdef MIB_DEBUG
  647. if(dwResult isnot NO_ERROR)
  648. {
  649. TRACE1("Create failed with error %d",dwResult);
  650. }
  651. #endif
  652. InvalidateCache(FORWARD_MIB);
  653. TraceLeave("MibSetIpRouteEntry");
  654. return dwResult;
  655. }
  656. case SET_ROW:
  657. {
  658. dwResult = InternalSetIpForwardEntry(pInfo);
  659. #ifdef MIB_DEBUG
  660. if(dwResult isnot NO_ERROR)
  661. {
  662. TRACE1("MibSet failed with error %d",dwResult);
  663. }
  664. #endif
  665. InvalidateCache(FORWARD_MIB);
  666. TraceLeave("MibSetIpRouteEntry");
  667. return dwResult;
  668. }
  669. case DELETE_ROW:
  670. {
  671. dwResult = InternalDeleteIpForwardEntry(pInfo);
  672. #ifdef MIB_DEBUG
  673. if(dwResult isnot NO_ERROR)
  674. {
  675. TRACE1("Delete failed with error %d",dwResult);
  676. }
  677. #endif
  678. InvalidateCache(FORWARD_MIB);
  679. TraceLeave("MibSetIpRouteEntry");
  680. return dwResult;
  681. }
  682. default:
  683. {
  684. TRACE1("Wrong row action %d",pInput->raAction);
  685. TraceLeave("MibSetIpRouteEntry");
  686. return MIB_S_SUCCESS;
  687. }
  688. }
  689. }
  690. case MIB_ACTION_CLEANUP:
  691. {
  692. TraceEnter("MibSetIpRouteEntry - CLEANUP");
  693. TraceLeave("MibSetIpRouteEntry");
  694. if(pInput->bLocked)
  695. {
  696. ReleaseLock(FORWARD_MIB);
  697. }
  698. return MIB_S_SUCCESS;
  699. }
  700. default:
  701. {
  702. TraceEnter("MibSetIpRouteEntry - WRONG ACTION");
  703. TraceLeave("MibSetIpRouteEntry");
  704. return MIB_S_INVALID_PARAMETER;
  705. }
  706. }
  707. }
  708. UINT
  709. MibGetIpNetToMediaEntry(
  710. UINT actionId,
  711. AsnAny *objectArray,
  712. UINT *errorIndex
  713. )
  714. {
  715. PMIB_IPNETROW pRpcIpNet;
  716. DWORD dwResult;
  717. PIP_NET_TO_MEDIA_ENTRY_GET pOutput;
  718. TraceEnter("MibGetIpNetToMediaEntry");
  719. dwResult = UpdateCache(MIB_II_IPNET);
  720. if(dwResult isnot NO_ERROR)
  721. {
  722. TRACE1("Couldnt update IP Net cache. Error %d", dwResult);
  723. TraceLeave("MibGetIpNetToMediaEntry");
  724. return dwResult;
  725. }
  726. pOutput = (PIP_NET_TO_MEDIA_ENTRY_GET)objectArray;
  727. EnterReader(MIB_II_IPNET);
  728. pRpcIpNet = LocateIpNetRow(actionId,
  729. &(pOutput->ipNetToMediaIfIndex),
  730. &(pOutput->ipNetToMediaNetAddress));
  731. if(pRpcIpNet is NULL)
  732. {
  733. ReleaseLock(MIB_II_IPNET);
  734. TRACE3("Unable to locateIP Net Row. Action is %d. IfIndex %d. Address %x",
  735. actionId,
  736. GetAsnInteger(&(pOutput->ipNetToMediaIfIndex), -1),
  737. GetAsnIPAddress(&(pOutput->ipNetToMediaNetAddress),0xffffffff));
  738. TraceLeave("MibGetIpNetToMediaEntry");
  739. if(actionId is MIB_ACTION_GETNEXT)
  740. {
  741. return MIB_S_NO_MORE_ENTRIES;
  742. }
  743. return MIB_S_ENTRY_NOT_FOUND;
  744. }
  745. ForceSetAsnInteger(&(pOutput->ipNetToMediaIfIndex), pRpcIpNet->dwIndex);
  746. SetAsnOctetString(&(pOutput->ipNetToMediaPhysAddress),
  747. pOutput->rgbyIpNetToMediaPhysAddressInfo,
  748. pRpcIpNet->bPhysAddr,
  749. pRpcIpNet->dwPhysAddrLen);
  750. ForceSetAsnIPAddress(&(pOutput->ipNetToMediaNetAddress),
  751. &(pOutput->dwIpNetToMediaNetAddressInfo),
  752. pRpcIpNet->dwAddr);
  753. SetAsnInteger(&(pOutput->ipNetToMediaType), pRpcIpNet->dwType);
  754. ReleaseLock(MIB_II_IPNET);
  755. TraceLeave("MibGetIpNetToMediaEntry");
  756. return MIB_S_SUCCESS;
  757. }
  758. UINT
  759. MibSetIpNetToMediaEntry(
  760. UINT actionId,
  761. AsnAny *objectArray,
  762. UINT *errorIndex
  763. )
  764. {
  765. PMIB_IPNETROW pRpcIpNet;
  766. DWORD dwResult,dwType;
  767. PIP_NET_TO_MEDIA_ENTRY_SET pInput;
  768. PMIB_OPAQUE_INFO pInfo;
  769. PMIB_IPNETROW pSetRow;
  770. pInput = (PIP_NET_TO_MEDIA_ENTRY_SET)objectArray;
  771. pInfo = (PMIB_OPAQUE_INFO)(pInput->rgdwSetBuffer);
  772. pSetRow = (PMIB_IPNETROW)(pInfo->rgbyData);
  773. switch(actionId)
  774. {
  775. case MIB_ACTION_VALIDATE:
  776. {
  777. TraceEnter("MibSetIpNetToMediaEntry - VALIDATE");
  778. ASSERT(!(IsAsnTypeNull(&(pInput->ipNetToMediaIfIndex)) or
  779. IsAsnTypeNull(&(pInput->ipNetToMediaNetAddress))));
  780. pInput->bLocked = FALSE;
  781. dwResult = UpdateCache(MIB_II_IPNET);
  782. if(dwResult isnot NO_ERROR)
  783. {
  784. TRACE1("Couldnt update IP Net cache. Error %d", dwResult);
  785. TraceLeave("MibSetIpNetToMediaEntry");
  786. return dwResult;
  787. }
  788. pInfo->dwId = IP_NETROW;
  789. EnterWriter(MIB_II_IPNET);
  790. pInput->bLocked = TRUE;
  791. pRpcIpNet = LocateIpNetRow(GET_EXACT,
  792. &(pInput->ipNetToMediaIfIndex),
  793. &(pInput->ipNetToMediaNetAddress));
  794. if(pRpcIpNet is NULL)
  795. {
  796. //
  797. // ok so we are creating an entry. We need to have all
  798. // the fields
  799. //
  800. if(IsAsnTypeNull(&(pInput->ipNetToMediaPhysAddress)) or
  801. IsAsnTypeNull(&(pInput->ipNetToMediaType)))
  802. {
  803. ReleaseLock(MIB_II_IPNET);
  804. pInput->bLocked = FALSE;
  805. TRACE0("Not enough info to create ARP entry");
  806. TraceLeave("MibSetIpNetToMediaEntry");
  807. return MIB_S_INVALID_PARAMETER;
  808. }
  809. dwType = GetAsnInteger(&(pInput->ipNetToMediaType), 0);
  810. if((dwType isnot MIB_IPNET_TYPE_DYNAMIC) and
  811. (dwType isnot MIB_IPNET_TYPE_STATIC))
  812. {
  813. ReleaseLock(MIB_II_IPNET);
  814. pInput->bLocked = FALSE;
  815. TRACE1("Type %d is wrong",dwType);
  816. TraceLeave("MibSetIpNetToMediaEntry");
  817. return MIB_S_INVALID_PARAMETER;
  818. }
  819. if(pInput->ipNetToMediaPhysAddress.asnValue.string.length > MAX_PHYS_ADDR_LEN)
  820. {
  821. ReleaseLock(MIB_II_IPNET);
  822. pInput->bLocked = FALSE;
  823. TRACE1("Length of phys addr (%d) is too large",
  824. pInput->ipNetToMediaPhysAddress.asnValue.string.length);
  825. TraceLeave("MibSetIpNetToMediaEntry");
  826. return MIB_S_INVALID_PARAMETER;
  827. }
  828. pInput->raAction = CREATE_ROW;
  829. pSetRow->dwIndex = GetAsnInteger(&(pInput->ipNetToMediaIfIndex),
  830. 0);
  831. pSetRow->dwPhysAddrLen =
  832. pInput->ipNetToMediaPhysAddress.asnValue.string.length;
  833. CopyMemory(pSetRow->bPhysAddr,
  834. pInput->ipNetToMediaPhysAddress.asnValue.string.stream,
  835. pInput->ipNetToMediaPhysAddress.asnValue.string.length);
  836. pSetRow->dwAddr =
  837. GetAsnIPAddress(&(pInput->ipNetToMediaNetAddress),
  838. 0xffffffff);
  839. pSetRow->dwType = dwType;
  840. TraceLeave("MibSetIpNetToMediaEntry");
  841. return MIB_S_SUCCESS;
  842. }
  843. else
  844. {
  845. //
  846. // only changing stuff
  847. //
  848. dwType = GetAsnInteger(&(pInput->ipNetToMediaType),
  849. pRpcIpNet->dwType);
  850. if((dwType < 1) or
  851. (dwType > 4))
  852. {
  853. ReleaseLock(MIB_II_IPNET);
  854. pInput->bLocked = FALSE;
  855. TRACE1("Type %d is wrong",dwType);
  856. TraceLeave("MibSetIpNetToMediaEntry");
  857. return MIB_S_INVALID_PARAMETER;
  858. }
  859. if(dwType is MIB_IPNET_TYPE_INVALID)
  860. {
  861. //
  862. // We want to delete stuff
  863. //
  864. *pSetRow = *pRpcIpNet;
  865. pInput->raAction = DELETE_ROW;
  866. TraceLeave("MibSetIpNetToMediaEntry");
  867. return MIB_S_SUCCESS;
  868. }
  869. if(pInput->ipNetToMediaPhysAddress.asnType isnot ASN_NULL)
  870. {
  871. if(pInput->ipNetToMediaPhysAddress.asnValue.string.length > MAX_PHYS_ADDR_LEN)
  872. {
  873. ReleaseLock(MIB_II_IPNET);
  874. pInput->bLocked = FALSE;
  875. TRACE1("Length of phys addr (%d) is too large",
  876. pInput->ipNetToMediaPhysAddress.asnValue.string.length);
  877. TraceLeave("MibSetIpNetToMediaEntry");
  878. return MIB_S_INVALID_PARAMETER;
  879. }
  880. pSetRow->dwPhysAddrLen = pInput->ipNetToMediaPhysAddress.asnValue.string.length;
  881. CopyMemory(pSetRow->bPhysAddr,
  882. pInput->ipNetToMediaPhysAddress.asnValue.string.stream,
  883. pInput->ipNetToMediaPhysAddress.asnValue.string.length);
  884. }
  885. else
  886. {
  887. pSetRow->dwPhysAddrLen = pRpcIpNet->dwPhysAddrLen;
  888. CopyMemory(pSetRow->bPhysAddr,
  889. pRpcIpNet->bPhysAddr,
  890. pRpcIpNet->dwPhysAddrLen);
  891. }
  892. pInput->raAction = SET_ROW;
  893. pSetRow->dwAddr =
  894. GetAsnIPAddress(&(pInput->ipNetToMediaNetAddress),
  895. pRpcIpNet->dwAddr);
  896. pSetRow->dwType = dwType;
  897. pSetRow->dwIndex = GetAsnInteger(&(pInput->ipNetToMediaIfIndex),0);
  898. TraceLeave("MibSetIpNetToMediaEntry");
  899. return MIB_S_SUCCESS;
  900. }
  901. }
  902. case MIB_ACTION_SET:
  903. {
  904. TraceEnter("MibSetIpNetToMediaEntry- SET");
  905. switch(pInput->raAction)
  906. {
  907. case CREATE_ROW:
  908. {
  909. dwResult = InternalCreateIpNetEntry(pInfo);
  910. #ifdef MIB_DEBUG
  911. if(dwResult isnot NO_ERROR)
  912. {
  913. TRACE1("Create failed with error %d!!",dwResult);
  914. }
  915. #endif
  916. InvalidateCache(MIB_II_IPNET);
  917. TraceLeave("MibSetIpNetToMediaEntry");
  918. return dwResult;
  919. }
  920. case SET_ROW:
  921. {
  922. dwResult = InternalSetIpNetEntry(pInfo);
  923. #ifdef MIB_DEBUG
  924. if(dwResult isnot NO_ERROR)
  925. {
  926. TRACE1("Create failed with error %d!!",dwResult);
  927. }
  928. #endif
  929. InvalidateCache(MIB_II_IPNET);
  930. TraceLeave("MibSetIpNetToMediaEntry");
  931. return dwResult;
  932. }
  933. case DELETE_ROW:
  934. {
  935. dwResult = InternalDeleteIpNetEntry(pInfo);
  936. #ifdef MIB_DEBUG
  937. if(dwResult isnot NO_ERROR)
  938. {
  939. TRACE1("Create failed with error %d!!",dwResult);
  940. }
  941. #endif
  942. InvalidateCache(MIB_II_IPNET);
  943. TraceLeave("MibSetIpNetToMediaEntry");
  944. return dwResult;
  945. }
  946. default:
  947. {
  948. TRACE1("Wrong row action %d",pInput->raAction);
  949. TraceLeave("MibSetIpNetToMediaEntry");
  950. return MIB_S_SUCCESS;
  951. }
  952. }
  953. }
  954. case MIB_ACTION_CLEANUP:
  955. {
  956. TraceEnter("MibSetIpNetToMediaEntry - CLEANUP");
  957. TraceLeave("MibSetIpNetToMediaEntry");
  958. if(pInput->bLocked)
  959. {
  960. ReleaseLock(MIB_II_IPNET);
  961. }
  962. return MIB_S_SUCCESS;
  963. }
  964. default:
  965. {
  966. TraceEnter("MibSetIpNetToMediaEntry - WRONG ACTION");
  967. TraceLeave("MibSetIpNetToMediaEntry");
  968. return MIB_S_INVALID_PARAMETER;
  969. }
  970. }
  971. }
  972. UINT
  973. MibGetIcmpGroup(
  974. UINT actionId,
  975. AsnAny *objectArray,
  976. UINT *errorIndex
  977. )
  978. {
  979. MIB_ICMP rpcIcmp;
  980. DWORD dwResult;
  981. PICMP_GROUP_GET pOutput;
  982. TraceEnter("MibGetIcmpGroup");
  983. dwResult = GetIcmpStatistics(&rpcIcmp);
  984. if(dwResult isnot NO_ERROR)
  985. {
  986. TRACE1("Couldnt get ICMP stats. Error %d",dwResult);
  987. TraceLeave("MibGetIcmpGroup");
  988. return dwResult;
  989. }
  990. pOutput = (PICMP_GROUP_GET)objectArray;
  991. SetAsnCounter(&(pOutput->icmpInMsgs), rpcIcmp.stats.icmpInStats.dwMsgs);
  992. SetAsnCounter(&(pOutput->icmpInErrors), rpcIcmp.stats.icmpInStats.dwErrors);
  993. SetAsnCounter(&(pOutput->icmpInDestUnreachs), rpcIcmp.stats.icmpInStats.dwDestUnreachs);
  994. SetAsnCounter(&(pOutput->icmpInTimeExcds), rpcIcmp.stats.icmpInStats.dwTimeExcds);
  995. SetAsnCounter(&(pOutput->icmpInParmProbs), rpcIcmp.stats.icmpInStats.dwParmProbs);
  996. SetAsnCounter(&(pOutput->icmpInSrcQuenchs), rpcIcmp.stats.icmpInStats.dwSrcQuenchs);
  997. SetAsnCounter(&(pOutput->icmpInRedirects), rpcIcmp.stats.icmpInStats.dwRedirects);
  998. SetAsnCounter(&(pOutput->icmpInEchos), rpcIcmp.stats.icmpInStats.dwEchos);
  999. SetAsnCounter(&(pOutput->icmpInEchoReps), rpcIcmp.stats.icmpInStats.dwEchoReps);
  1000. SetAsnCounter(&(pOutput->icmpInTimestamps), rpcIcmp.stats.icmpInStats.dwTimestamps);
  1001. SetAsnCounter(&(pOutput->icmpInTimestampReps), rpcIcmp.stats.icmpInStats.dwTimestampReps);
  1002. SetAsnCounter(&(pOutput->icmpInAddrMasks), rpcIcmp.stats.icmpInStats.dwAddrMasks);
  1003. SetAsnCounter(&(pOutput->icmpInAddrMaskReps), rpcIcmp.stats.icmpInStats.dwAddrMaskReps);
  1004. SetAsnCounter(&(pOutput->icmpOutMsgs), rpcIcmp.stats.icmpOutStats.dwMsgs);
  1005. SetAsnCounter(&(pOutput->icmpOutErrors), rpcIcmp.stats.icmpOutStats.dwErrors);
  1006. SetAsnCounter(&(pOutput->icmpOutDestUnreachs), rpcIcmp.stats.icmpOutStats.dwDestUnreachs);
  1007. SetAsnCounter(&(pOutput->icmpOutTimeExcds), rpcIcmp.stats.icmpOutStats.dwTimeExcds);
  1008. SetAsnCounter(&(pOutput->icmpOutParmProbs), rpcIcmp.stats.icmpOutStats.dwParmProbs);
  1009. SetAsnCounter(&(pOutput->icmpOutSrcQuenchs), rpcIcmp.stats.icmpOutStats.dwSrcQuenchs);
  1010. SetAsnCounter(&(pOutput->icmpOutRedirects), rpcIcmp.stats.icmpOutStats.dwRedirects);
  1011. SetAsnCounter(&(pOutput->icmpOutEchos), rpcIcmp.stats.icmpOutStats.dwEchos);
  1012. SetAsnCounter(&(pOutput->icmpOutEchoReps), rpcIcmp.stats.icmpOutStats.dwEchoReps);
  1013. SetAsnCounter(&(pOutput->icmpOutTimestamps), rpcIcmp.stats.icmpOutStats.dwTimestamps);
  1014. SetAsnCounter(&(pOutput->icmpOutTimestampReps), rpcIcmp.stats.icmpOutStats.dwTimestampReps);
  1015. SetAsnCounter(&(pOutput->icmpOutAddrMasks), rpcIcmp.stats.icmpOutStats.dwAddrMasks);
  1016. SetAsnCounter(&(pOutput->icmpOutAddrMaskReps), rpcIcmp.stats.icmpOutStats.dwAddrMaskReps);
  1017. TraceLeave("MibGetIcmpGroup");
  1018. return MIB_S_SUCCESS;
  1019. }
  1020. UINT
  1021. MibGetTcpGroup(
  1022. UINT actionId,
  1023. AsnAny *objectArray,
  1024. UINT *errorIndex
  1025. )
  1026. {
  1027. MIB_TCPSTATS rpcTcp4, rpcTcp6;
  1028. DWORD dwResult4, dwResult6;
  1029. PTCP_STATS_GET pOutput;
  1030. TraceEnter("MibGetTcpGroup");
  1031. ZeroMemory(&rpcTcp4, sizeof(rpcTcp4));
  1032. ZeroMemory(&rpcTcp6, sizeof(rpcTcp6));
  1033. dwResult4 = GetTcpStatisticsEx(&rpcTcp4, AF_INET);
  1034. dwResult6 = GetTcpStatisticsEx(&rpcTcp6, AF_INET6);
  1035. if ((dwResult4 isnot NO_ERROR) && (dwResult6 isnot NO_ERROR))
  1036. {
  1037. TRACE1("Couldnt get Tcp stats. Error %d",dwResult4);
  1038. TraceLeave("MibGetTcpGroup");
  1039. return dwResult4;
  1040. }
  1041. pOutput = (PTCP_STATS_GET)objectArray;
  1042. //
  1043. // The current MIB only has one object (per stat) for both IPv4 and IPv6.
  1044. // That is, it assumes a combination TCP stack). We can add together
  1045. // counters but for enumerated objects, we arbitrarily report the IPv4
  1046. // stack value.
  1047. //
  1048. SetAsnInteger(&(pOutput->tcpRtoAlgorithm), rpcTcp4.dwRtoAlgorithm);
  1049. SetAsnInteger(&(pOutput->tcpRtoMin), rpcTcp4.dwRtoMin);
  1050. SetAsnInteger(&(pOutput->tcpRtoMax), rpcTcp4.dwRtoMax);
  1051. SetAsnInteger(&(pOutput->tcpMaxConn), rpcTcp4.dwMaxConn);
  1052. SetAsnCounter(&(pOutput->tcpActiveOpens),
  1053. rpcTcp4.dwActiveOpens + rpcTcp6.dwActiveOpens);
  1054. SetAsnCounter(&(pOutput->tcpPassiveOpens),
  1055. rpcTcp4.dwPassiveOpens + rpcTcp6.dwPassiveOpens);
  1056. SetAsnCounter(&(pOutput->tcpAttemptFails),
  1057. rpcTcp4.dwAttemptFails + rpcTcp6.dwAttemptFails);
  1058. SetAsnCounter(&(pOutput->tcpEstabResets),
  1059. rpcTcp4.dwEstabResets + rpcTcp6.dwEstabResets);
  1060. SetAsnGauge(&(pOutput->tcpCurrEstab),
  1061. rpcTcp4.dwCurrEstab + rpcTcp6.dwCurrEstab);
  1062. SetAsnCounter(&(pOutput->tcpInSegs),
  1063. rpcTcp4.dwInSegs + rpcTcp6.dwInSegs);
  1064. SetAsnCounter(&(pOutput->tcpOutSegs),
  1065. rpcTcp4.dwOutSegs + rpcTcp6.dwOutSegs);
  1066. SetAsnCounter(&(pOutput->tcpRetransSegs),
  1067. rpcTcp4.dwRetransSegs + rpcTcp6.dwRetransSegs);
  1068. SetAsnCounter(&(pOutput->tcpInErrs),
  1069. rpcTcp4.dwInErrs + rpcTcp6.dwInErrs);
  1070. SetAsnCounter(&(pOutput->tcpOutRsts),
  1071. rpcTcp4.dwOutRsts + rpcTcp6.dwOutRsts);
  1072. TraceLeave("MibGetTcpGroup");
  1073. return MIB_S_SUCCESS;
  1074. }
  1075. UINT
  1076. MibGetTcpConnectionEntry(
  1077. UINT actionId,
  1078. AsnAny *objectArray,
  1079. UINT *errorIndex
  1080. )
  1081. {
  1082. DWORD dwResult;
  1083. PMIB_TCPROW pRpcTcp;
  1084. PTCP_CONNECTION_ENTRY_GET pOutput;
  1085. TraceEnter("MibGetTcpConnectionEntry");
  1086. dwResult = UpdateCache(MIB_II_TCP);
  1087. if(dwResult isnot NO_ERROR)
  1088. {
  1089. TRACE1("Couldnt update TCP Connection cache. Error %d", dwResult);
  1090. TraceLeave("MibGetTcpConnectionEntry");
  1091. return dwResult;
  1092. }
  1093. pOutput = (PTCP_CONNECTION_ENTRY_GET)objectArray;
  1094. EnterReader(MIB_II_TCP);
  1095. pRpcTcp = LocateTcpRow(actionId,
  1096. &(pOutput->tcpConnLocalAddress),
  1097. &(pOutput->tcpConnLocalPort),
  1098. &(pOutput->tcpConnRemAddress),
  1099. &(pOutput->tcpConnRemPort));
  1100. if(pRpcTcp is NULL)
  1101. {
  1102. ReleaseLock(MIB_II_TCP);
  1103. TRACE5("Couldnt find TCP Row. Action %d. LocalAddr %x, Localport %d, RemAddr %x, RemPort %d",
  1104. actionId,
  1105. GetAsnIPAddress(&(pOutput->tcpConnLocalAddress), 0xffffffff),
  1106. GetAsnInteger(&(pOutput->tcpConnLocalPort), -1),
  1107. GetAsnIPAddress(&(pOutput->tcpConnRemAddress), 0xffffffff),
  1108. GetAsnInteger(&(pOutput->tcpConnRemPort), -1));
  1109. TraceLeave("MibGetTcpConnectionEntry");
  1110. if(actionId is MIB_ACTION_GETNEXT)
  1111. {
  1112. return MIB_S_NO_MORE_ENTRIES;
  1113. }
  1114. return MIB_S_ENTRY_NOT_FOUND;
  1115. }
  1116. SetAsnInteger(&(pOutput->tcpConnState), pRpcTcp->dwState);
  1117. ForceSetAsnIPAddress(&(pOutput->tcpConnLocalAddress),
  1118. &(pOutput->dwTcpConnLocalAddressInfo),
  1119. pRpcTcp->dwLocalAddr);
  1120. ForceSetAsnInteger(&(pOutput->tcpConnLocalPort), pRpcTcp->dwLocalPort);
  1121. ForceSetAsnIPAddress(&(pOutput->tcpConnRemAddress),
  1122. &(pOutput->dwTcpConnRemAddressInfo),
  1123. pRpcTcp->dwRemoteAddr);
  1124. ForceSetAsnInteger(&(pOutput->tcpConnRemPort), pRpcTcp->dwRemotePort);
  1125. ReleaseLock(MIB_II_TCP);
  1126. TraceLeave("MibGetTcpConnectionEntry");
  1127. return MIB_S_SUCCESS;
  1128. }
  1129. UINT
  1130. MibGetTcpNewConnectionEntry(
  1131. UINT actionId,
  1132. AsnAny *objectArray,
  1133. UINT *errorIndex
  1134. )
  1135. {
  1136. DWORD dwResult = MIB_S_NO_MORE_ENTRIES;
  1137. PMIB_TCPROW pRpcTcp4;
  1138. PTCP6ConnTableEntry pRpcTcp6;
  1139. PTCP_NEW_CONNECTION_ENTRY_GET pOutput;
  1140. DWORD dwFamily;
  1141. TraceEnter("MibGetTcpNewConnectionEntry");
  1142. pOutput = (PTCP_NEW_CONNECTION_ENTRY_GET)objectArray;
  1143. dwFamily = GetAsnInteger(&pOutput->tcpNewConnLocalAddressType, INET_ADDRESS_TYPE_UNKNOWN);
  1144. if (dwFamily > INET_ADDRESS_TYPE_IPv6) {
  1145. return (actionId is MIB_ACTION_GETNEXT)?
  1146. MIB_S_NO_MORE_ENTRIES : MIB_S_ENTRY_NOT_FOUND;
  1147. }
  1148. //
  1149. // First try IPv4
  1150. //
  1151. if ((dwFamily == INET_ADDRESS_TYPE_UNKNOWN) ||
  1152. (dwFamily == INET_ADDRESS_TYPE_IPv4)) {
  1153. dwResult = UpdateCache(MIB_II_TCP);
  1154. if (dwResult isnot NO_ERROR) {
  1155. goto IPv4Done;
  1156. }
  1157. EnterReader(MIB_II_TCP);
  1158. pRpcTcp4 = LocateTcpRow(actionId,
  1159. &(pOutput->tcpNewConnLocalAddress),
  1160. &(pOutput->tcpNewConnLocalPort),
  1161. &(pOutput->tcpNewConnRemAddress),
  1162. &(pOutput->tcpNewConnRemPort));
  1163. if (pRpcTcp4 is NULL) {
  1164. dwResult = (actionId is MIB_ACTION_GETNEXT)?
  1165. MIB_S_NO_MORE_ENTRIES : MIB_S_ENTRY_NOT_FOUND;
  1166. goto IPv4Cleanup;
  1167. }
  1168. ForceSetAsnInteger(&(pOutput->tcpNewConnLocalAddressType), INET_ADDRESS_TYPE_IPv4);
  1169. ForceSetAsnOctetString(&(pOutput->tcpNewConnLocalAddress),
  1170. pOutput->rgbyTcpNewConnLocalAddressInfo,
  1171. &pRpcTcp4->dwLocalAddr,
  1172. sizeof(pRpcTcp4->dwLocalAddr));
  1173. ForceSetAsnInteger(&(pOutput->tcpNewConnLocalPort), pRpcTcp4->dwLocalPort);
  1174. ForceSetAsnInteger(&(pOutput->tcpNewConnRemAddressType), INET_ADDRESS_TYPE_IPv4);
  1175. ForceSetAsnOctetString(&(pOutput->tcpNewConnRemAddress),
  1176. pOutput->rgbyTcpNewConnRemAddressInfo,
  1177. &pRpcTcp4->dwRemoteAddr,
  1178. sizeof(pRpcTcp4->dwRemoteAddr));
  1179. ForceSetAsnInteger(&(pOutput->tcpNewConnRemPort), pRpcTcp4->dwRemotePort);
  1180. SetAsnInteger(&(pOutput->tcpNewConnState), pRpcTcp4->dwState);
  1181. dwResult = MIB_S_SUCCESS;
  1182. IPv4Cleanup:
  1183. ReleaseLock(MIB_II_TCP);
  1184. }
  1185. IPv4Done:
  1186. if (dwResult != MIB_S_NO_MORE_ENTRIES) {
  1187. return dwResult;
  1188. }
  1189. if ((dwFamily == INET_ADDRESS_TYPE_IPv4) && (actionId == MIB_ACTION_GETNEXT)) {
  1190. dwFamily = INET_ADDRESS_TYPE_IPv6;
  1191. actionId = MIB_ACTION_GETFIRST;
  1192. }
  1193. //
  1194. // Now try IPv6
  1195. //
  1196. if ((dwFamily == INET_ADDRESS_TYPE_UNKNOWN) ||
  1197. (dwFamily == INET_ADDRESS_TYPE_IPv6)) {
  1198. dwResult = UpdateCache(MIB_II_TCP6);
  1199. if (dwResult isnot NO_ERROR) {
  1200. goto IPv6Done;
  1201. }
  1202. EnterReader(MIB_II_TCP6);
  1203. pRpcTcp6 = LocateTcp6Row(actionId,
  1204. &(pOutput->tcpNewConnLocalAddress),
  1205. &(pOutput->tcpNewConnLocalPort),
  1206. &(pOutput->tcpNewConnRemAddress),
  1207. &(pOutput->tcpNewConnRemPort));
  1208. if (pRpcTcp6 is NULL) {
  1209. dwResult = (actionId is MIB_ACTION_GETNEXT)?
  1210. MIB_S_NO_MORE_ENTRIES : MIB_S_ENTRY_NOT_FOUND;
  1211. goto IPv6Cleanup;
  1212. }
  1213. ForceSetAsnInteger(&(pOutput->tcpNewConnLocalAddressType), INET_ADDRESS_TYPE_IPv6);
  1214. ForceSetAsnOctetString(&(pOutput->tcpNewConnLocalAddress),
  1215. pOutput->rgbyTcpNewConnLocalAddressInfo,
  1216. &pRpcTcp6->tct_localaddr,
  1217. (pRpcTcp6->tct_localscopeid)? 20 : 16);
  1218. ForceSetAsnInteger(&(pOutput->tcpNewConnLocalPort), pRpcTcp6->tct_localport);
  1219. ForceSetAsnInteger(&(pOutput->tcpNewConnRemAddressType), INET_ADDRESS_TYPE_IPv6);
  1220. ForceSetAsnOctetString(&(pOutput->tcpNewConnRemAddress),
  1221. pOutput->rgbyTcpNewConnRemAddressInfo,
  1222. &pRpcTcp6->tct_remoteaddr,
  1223. (pRpcTcp6->tct_remotescopeid)? 20 : 16);
  1224. ForceSetAsnInteger(&(pOutput->tcpNewConnRemPort), pRpcTcp6->tct_remoteport);
  1225. SetAsnInteger(&(pOutput->tcpNewConnState), pRpcTcp6->tct_state);
  1226. dwResult = MIB_S_SUCCESS;
  1227. IPv6Cleanup:
  1228. ReleaseLock(MIB_II_TCP6);
  1229. }
  1230. IPv6Done:
  1231. TraceLeave("MibGetTcpConnectionEntry");
  1232. return dwResult;
  1233. }
  1234. UINT
  1235. MibSetTcpConnectionEntry(
  1236. UINT actionId,
  1237. AsnAny *objectArray,
  1238. UINT *errorIndex
  1239. )
  1240. {
  1241. DWORD dwResult,dwState;
  1242. PMIB_TCPROW pRpcTcp;
  1243. PTCP_CONNECTION_ENTRY_SET pInput;
  1244. PMIB_OPAQUE_INFO pInfo;
  1245. PMIB_TCPROW pSetRow;
  1246. pInput = (PTCP_CONNECTION_ENTRY_SET)objectArray;
  1247. pInfo = (PMIB_OPAQUE_INFO)(pInput->rgdwSetBuffer);
  1248. pSetRow = (PMIB_TCPROW)(pInfo->rgbyData);
  1249. switch(actionId)
  1250. {
  1251. case MIB_ACTION_VALIDATE:
  1252. {
  1253. TraceEnter("MibSetTcpConnectionEntry - VALIDATE");
  1254. ASSERT(!(IsAsnTypeNull(&(pInput->tcpConnLocalAddress)) or
  1255. IsAsnTypeNull(&(pInput->tcpConnLocalPort)) or
  1256. IsAsnTypeNull(&(pInput->tcpConnRemAddress)) or
  1257. IsAsnTypeNull(&(pInput->tcpConnRemPort)) or
  1258. IsAsnTypeNull(&(pInput->tcpConnState))));
  1259. pInput->bLocked = FALSE;
  1260. dwState = GetAsnInteger(&(pInput->tcpConnState), 0);
  1261. if(dwState isnot MIB_TCP_STATE_DELETE_TCB)
  1262. {
  1263. TRACE1("State is %d. Only state allowed is DELETE",dwState);
  1264. return MIB_S_INVALID_PARAMETER;
  1265. }
  1266. dwResult = UpdateCache(MIB_II_TCP);
  1267. if(dwResult isnot NO_ERROR)
  1268. {
  1269. TRACE1("Couldnt update TCP Connection cache. Error %d", dwResult);
  1270. TraceLeave("MibGetTcpConnectionEntry");
  1271. return dwResult;
  1272. }
  1273. EnterWriter(MIB_II_TCP);
  1274. pInput->bLocked = TRUE;
  1275. pRpcTcp = LocateTcpRow(GET_EXACT,
  1276. &(pInput->tcpConnLocalAddress),
  1277. &(pInput->tcpConnLocalPort),
  1278. &(pInput->tcpConnRemAddress),
  1279. &(pInput->tcpConnRemPort));
  1280. if(pRpcTcp is NULL)
  1281. {
  1282. ReleaseLock(MIB_II_TCP);
  1283. pInput->bLocked = FALSE;
  1284. TRACE5("Couldnt find TCP Row. Action %d. LocalAddr %x, Localport %d, RemAddr %x, RemPort %d",
  1285. actionId,
  1286. GetAsnIPAddress(&(pInput->tcpConnLocalAddress),
  1287. 0xffffffff),
  1288. GetAsnInteger(&(pInput->tcpConnLocalPort),
  1289. -1),
  1290. GetAsnIPAddress(&(pInput->tcpConnRemAddress),
  1291. 0xffffffff),
  1292. GetAsnInteger(&(pInput->tcpConnRemPort),
  1293. -1));
  1294. TraceLeave("MibSetTcpConnectionEntry");
  1295. return MIB_S_ENTRY_NOT_FOUND;
  1296. }
  1297. pInput->raAction = SET_ROW;
  1298. *pSetRow = *pRpcTcp;
  1299. pSetRow->dwState = MIB_TCP_STATE_DELETE_TCB;
  1300. //
  1301. // change port to network byte order
  1302. //
  1303. pSetRow->dwLocalPort = (DWORD)htons((WORD)pSetRow->dwLocalPort);
  1304. //
  1305. // chnage port to network byte order
  1306. //
  1307. pSetRow->dwRemotePort = (DWORD)htons((WORD)pSetRow->dwRemotePort);
  1308. return MIB_S_SUCCESS;
  1309. }
  1310. case MIB_ACTION_SET:
  1311. {
  1312. TraceEnter("MibSetTcpConnectionEntry - SET");
  1313. dwResult = NO_ERROR;
  1314. if(pInput->raAction is SET_ROW)
  1315. {
  1316. dwResult = InternalSetTcpEntry(pInfo);
  1317. #ifdef MIB_DEBUG
  1318. if(dwResult isnot NO_ERROR)
  1319. {
  1320. TRACE1("MibSet returned error %d!!",dwResult);
  1321. }
  1322. #endif
  1323. InvalidateCache(MIB_II_TCP);
  1324. }
  1325. TraceLeave("MibSetTcpConnectionEntry");
  1326. return dwResult;
  1327. }
  1328. case MIB_ACTION_CLEANUP:
  1329. {
  1330. TraceEnter("MibSetTcpConnectionEntry - CLEANUP");
  1331. if(pInput->bLocked)
  1332. {
  1333. ReleaseLock(MIB_II_TCP);
  1334. }
  1335. TraceLeave("MibSetTcpConnectionEntry");
  1336. return MIB_S_SUCCESS;
  1337. }
  1338. default:
  1339. {
  1340. TraceEnter("MibSetTcpConnectionEntry - WRONG ACTION");
  1341. TraceLeave("MibSetTcpConnectionEntry");
  1342. return MIB_S_INVALID_PARAMETER;
  1343. }
  1344. }
  1345. }
  1346. UINT
  1347. MibSetTcpNewConnectionEntry(
  1348. UINT actionId,
  1349. AsnAny *objectArray,
  1350. UINT *errorIndex
  1351. )
  1352. {
  1353. DWORD dwResult,dwState;
  1354. PMIB_TCPROW pRpcTcp4;
  1355. PTCP_NEW_CONNECTION_ENTRY_SET pInput;
  1356. PMIB_OPAQUE_INFO pInfo;
  1357. PMIB_TCPROW pSetRow;
  1358. pInput = (PTCP_NEW_CONNECTION_ENTRY_SET)objectArray;
  1359. pInfo = (PMIB_OPAQUE_INFO)(pInput->rgdwSetBuffer);
  1360. pSetRow = (PMIB_TCPROW)(pInfo->rgbyData);
  1361. switch(actionId)
  1362. {
  1363. case MIB_ACTION_VALIDATE:
  1364. {
  1365. TraceEnter("MibSetTcpNewConnectionEntry - VALIDATE");
  1366. ASSERT(!(IsAsnTypeNull(&(pInput->tcpNewConnLocalAddressType)) or
  1367. IsAsnTypeNull(&(pInput->tcpNewConnLocalAddress)) or
  1368. IsAsnTypeNull(&(pInput->tcpNewConnLocalPort)) or
  1369. IsAsnTypeNull(&(pInput->tcpNewConnRemAddressType)) or
  1370. IsAsnTypeNull(&(pInput->tcpNewConnRemAddress)) or
  1371. IsAsnTypeNull(&(pInput->tcpNewConnRemPort)) or
  1372. IsAsnTypeNull(&(pInput->tcpNewConnState))));
  1373. pInput->bLocked = FALSE;
  1374. dwState = GetAsnInteger(&(pInput->tcpNewConnState), 0);
  1375. if(dwState isnot MIB_TCP_STATE_DELETE_TCB)
  1376. {
  1377. TRACE1("State is %d. Only state allowed is DELETE",dwState);
  1378. return MIB_S_INVALID_PARAMETER;
  1379. }
  1380. dwResult = UpdateCache(MIB_II_TCP);
  1381. if(dwResult isnot NO_ERROR)
  1382. {
  1383. TRACE1("Couldnt update TCP Connection cache. Error %d", dwResult);
  1384. TraceLeave("MibGetTcpNewConnectionEntry");
  1385. return dwResult;
  1386. }
  1387. EnterWriter(MIB_II_TCP);
  1388. pInput->bLocked = TRUE;
  1389. pRpcTcp4 = LocateTcpRow(GET_EXACT,
  1390. &(pInput->tcpNewConnLocalAddress),
  1391. &(pInput->tcpNewConnLocalPort),
  1392. &(pInput->tcpNewConnRemAddress),
  1393. &(pInput->tcpNewConnRemPort));
  1394. if(pRpcTcp4 is NULL)
  1395. {
  1396. ReleaseLock(MIB_II_TCP);
  1397. pInput->bLocked = FALSE;
  1398. TRACE5("Couldn't find TCP Row. Action %d. LocalAddr %x, Localport %d, RemAddr %x, RemPort %d",
  1399. actionId,
  1400. GetAsnIPAddress(&(pInput->tcpConnLocalAddress),
  1401. 0xffffffff),
  1402. GetAsnInteger(&(pInput->tcpConnLocalPort),
  1403. -1),
  1404. GetAsnIPAddress(&(pInput->tcpConnRemAddress),
  1405. 0xffffffff),
  1406. GetAsnInteger(&(pInput->tcpConnRemPort),
  1407. -1));
  1408. TraceLeave("MibSetTcpNewConnectionEntry");
  1409. return MIB_S_ENTRY_NOT_FOUND;
  1410. }
  1411. pInput->raAction = SET_ROW;
  1412. *pSetRow = *pRpcTcp4;
  1413. pSetRow->dwState = MIB_TCP_STATE_DELETE_TCB;
  1414. //
  1415. // change port to network byte order
  1416. //
  1417. pSetRow->dwLocalPort = (DWORD)htons((WORD)pSetRow->dwLocalPort);
  1418. //
  1419. // chnage port to network byte order
  1420. //
  1421. pSetRow->dwRemotePort = (DWORD)htons((WORD)pSetRow->dwRemotePort);
  1422. return MIB_S_SUCCESS;
  1423. }
  1424. case MIB_ACTION_SET:
  1425. {
  1426. TraceEnter("MibSetTcpNewConnectionEntry - SET");
  1427. dwResult = NO_ERROR;
  1428. if(pInput->raAction is SET_ROW)
  1429. {
  1430. dwResult = InternalSetTcpEntry(pInfo);
  1431. #ifdef MIB_DEBUG
  1432. if(dwResult isnot NO_ERROR)
  1433. {
  1434. TRACE1("MibSet returned error %d!!",dwResult);
  1435. }
  1436. #endif
  1437. InvalidateCache(MIB_II_TCP);
  1438. }
  1439. TraceLeave("MibSetTcpNewConnectionEntry");
  1440. return dwResult;
  1441. }
  1442. case MIB_ACTION_CLEANUP:
  1443. {
  1444. TraceEnter("MibSetTcpNewConnectionEntry - CLEANUP");
  1445. if(pInput->bLocked)
  1446. {
  1447. ReleaseLock(MIB_II_TCP);
  1448. }
  1449. TraceLeave("MibSetTcpNewConnectionEntry");
  1450. return MIB_S_SUCCESS;
  1451. }
  1452. default:
  1453. {
  1454. TraceEnter("MibSetTcpNewConnectionEntry - WRONG ACTION");
  1455. TraceLeave("MibSetTcpNewConnectionEntry");
  1456. return MIB_S_INVALID_PARAMETER;
  1457. }
  1458. }
  1459. }
  1460. UINT
  1461. MibGetUdpGroup(
  1462. UINT actionId,
  1463. AsnAny *objectArray,
  1464. UINT *errorIndex
  1465. )
  1466. {
  1467. DWORD dwResult;
  1468. MIB_UDPSTATS rpcUdpStats;
  1469. PUDP_STATS_GET pOutput;
  1470. TraceEnter("MibGetUdpGroup");
  1471. dwResult = GetUdpStatistics(&rpcUdpStats);
  1472. if(dwResult isnot NO_ERROR)
  1473. {
  1474. TRACE1("Couldnt get Udp stats. Error %d",dwResult);
  1475. TraceLeave("MibGetUdpGroup");
  1476. return dwResult;
  1477. }
  1478. pOutput = (PUDP_STATS_GET)objectArray;
  1479. SetAsnCounter(&(pOutput->udpInDatagrams), rpcUdpStats.dwInDatagrams);
  1480. SetAsnCounter(&(pOutput->udpNoPorts), rpcUdpStats.dwNoPorts);
  1481. SetAsnCounter(&(pOutput->udpInErrors), rpcUdpStats.dwInErrors);
  1482. SetAsnCounter(&(pOutput->udpOutDatagrams), rpcUdpStats.dwOutDatagrams);
  1483. TraceLeave("MibGetUdpGroup");
  1484. return MIB_S_SUCCESS;
  1485. }
  1486. UINT
  1487. MibGetUdpEntry(
  1488. UINT actionId,
  1489. AsnAny *objectArray,
  1490. UINT *errorIndex
  1491. )
  1492. {
  1493. DWORD dwResult;
  1494. PMIB_UDPROW pRpcUdp;
  1495. PUDP_ENTRY_GET pOutput;
  1496. TraceEnter("MibGetUdpEntry");
  1497. dwResult = UpdateCache(MIB_II_UDP);
  1498. if(dwResult isnot NO_ERROR)
  1499. {
  1500. TRACE1("Couldnt update UDP Connection cache. Error %d", dwResult);
  1501. TraceLeave("MibGetUdpEntry");
  1502. return dwResult;
  1503. }
  1504. pOutput = (PUDP_ENTRY_GET)objectArray;
  1505. EnterReader(MIB_II_UDP);
  1506. pRpcUdp = LocateUdpRow(actionId,
  1507. &(pOutput->udpLocalAddress),
  1508. &(pOutput->udpLocalPort));
  1509. if(pRpcUdp is NULL)
  1510. {
  1511. ReleaseLock(MIB_II_UDP);
  1512. TRACE3("Couldnt find UDP Row. Action %d. LocalAddr %x, Localport %d",
  1513. actionId,
  1514. GetAsnIPAddress(&(pOutput->udpLocalAddress), 0xffffffff),
  1515. GetAsnInteger(&(pOutput->udpLocalPort), -1));
  1516. TraceLeave("MibGetUdpEntry");
  1517. if(actionId is MIB_ACTION_GETNEXT)
  1518. {
  1519. return MIB_S_NO_MORE_ENTRIES;
  1520. }
  1521. return MIB_S_ENTRY_NOT_FOUND;
  1522. }
  1523. ForceSetAsnIPAddress(&(pOutput->udpLocalAddress),
  1524. &(pOutput->dwUdpLocalAddressInfo),
  1525. pRpcUdp->dwLocalAddr);
  1526. ForceSetAsnInteger(&(pOutput->udpLocalPort), pRpcUdp->dwLocalPort);
  1527. ReleaseLock(MIB_II_UDP);
  1528. TraceLeave("MibGetUdpEntry");
  1529. return MIB_S_SUCCESS;
  1530. }
  1531. UINT
  1532. MibGetUdpListenerEntry(
  1533. UINT actionId,
  1534. AsnAny *objectArray,
  1535. UINT *errorIndex
  1536. )
  1537. {
  1538. DWORD dwResult = MIB_S_NO_MORE_ENTRIES;
  1539. PMIB_UDPROW pRpcUdp4;
  1540. PUDP6ListenerEntry pRpcUdp6;
  1541. PUDP_LISTENER_ENTRY_GET pOutput;
  1542. DWORD dwFamily;
  1543. TraceEnter("MibGetUdpListenerEntry");
  1544. pOutput = (PUDP_LISTENER_ENTRY_GET)objectArray;
  1545. dwFamily = GetAsnInteger(&pOutput->udpListenerLocalAddressType,
  1546. INET_ADDRESS_TYPE_UNKNOWN);
  1547. if (dwFamily > INET_ADDRESS_TYPE_IPv6) {
  1548. return (actionId is MIB_ACTION_GETNEXT)?
  1549. MIB_S_NO_MORE_ENTRIES : MIB_S_ENTRY_NOT_FOUND;
  1550. }
  1551. //
  1552. // First try IPv4
  1553. //
  1554. if ((dwFamily == INET_ADDRESS_TYPE_UNKNOWN) ||
  1555. (dwFamily == INET_ADDRESS_TYPE_IPv4)) {
  1556. dwResult = UpdateCache(MIB_II_UDP);
  1557. if(dwResult isnot NO_ERROR)
  1558. {
  1559. goto IPv4Done;
  1560. }
  1561. EnterReader(MIB_II_UDP);
  1562. pRpcUdp4 = LocateUdpRow(actionId,
  1563. &(pOutput->udpListenerLocalAddress),
  1564. &(pOutput->udpListenerLocalPort));
  1565. if(pRpcUdp4 is NULL)
  1566. {
  1567. dwResult = (actionId is MIB_ACTION_GETNEXT)?
  1568. MIB_S_NO_MORE_ENTRIES : MIB_S_ENTRY_NOT_FOUND;
  1569. goto IPv4Cleanup;
  1570. }
  1571. ForceSetAsnInteger(&(pOutput->udpListenerLocalAddressType),
  1572. INET_ADDRESS_TYPE_IPv4);
  1573. ForceSetAsnOctetString(&(pOutput->udpListenerLocalAddress),
  1574. pOutput->rgbyUdpLocalAddressInfo,
  1575. &pRpcUdp4->dwLocalAddr,
  1576. sizeof(pRpcUdp4->dwLocalAddr));
  1577. ForceSetAsnUnsigned32(&(pOutput->udpListenerLocalPort),
  1578. pRpcUdp4->dwLocalPort);
  1579. dwResult = MIB_S_SUCCESS;
  1580. IPv4Cleanup:
  1581. ReleaseLock(MIB_II_UDP);
  1582. }
  1583. IPv4Done:
  1584. if (dwResult != MIB_S_NO_MORE_ENTRIES) {
  1585. return dwResult;
  1586. }
  1587. if ((dwFamily == INET_ADDRESS_TYPE_IPv4) && (actionId == MIB_ACTION_GETNEXT)) {
  1588. dwFamily = INET_ADDRESS_TYPE_IPv6;
  1589. actionId = MIB_ACTION_GETFIRST;
  1590. }
  1591. //
  1592. // Now try IPv6
  1593. //
  1594. if ((dwFamily == INET_ADDRESS_TYPE_UNKNOWN) ||
  1595. (dwFamily == INET_ADDRESS_TYPE_IPv6)) {
  1596. dwResult = UpdateCache(MIB_II_UDP6_LISTENER);
  1597. if(dwResult isnot NO_ERROR)
  1598. {
  1599. goto IPv6Done;
  1600. }
  1601. EnterReader(MIB_II_UDP6_LISTENER);
  1602. pRpcUdp6 = LocateUdp6Row(actionId,
  1603. &(pOutput->udpListenerLocalAddress),
  1604. &(pOutput->udpListenerLocalPort));
  1605. if(pRpcUdp6 is NULL)
  1606. {
  1607. dwResult = (actionId is MIB_ACTION_GETNEXT)?
  1608. MIB_S_NO_MORE_ENTRIES : MIB_S_ENTRY_NOT_FOUND;
  1609. goto IPv6Cleanup;
  1610. }
  1611. ForceSetAsnInteger(&(pOutput->udpListenerLocalAddressType),
  1612. INET_ADDRESS_TYPE_IPv6);
  1613. ForceSetAsnOctetString(&(pOutput->udpListenerLocalAddress),
  1614. pOutput->rgbyUdpLocalAddressInfo,
  1615. &pRpcUdp6->ule_localaddr,
  1616. (pRpcUdp6->ule_localscopeid)? 20 : 16);
  1617. ForceSetAsnInteger(&(pOutput->udpListenerLocalPort),
  1618. pRpcUdp6->ule_localport);
  1619. dwResult = MIB_S_SUCCESS;
  1620. IPv6Cleanup:
  1621. ReleaseLock(MIB_II_UDP6_LISTENER);
  1622. }
  1623. IPv6Done:
  1624. TraceLeave("MibGetUdpEntry");
  1625. return dwResult;
  1626. }
  1627. UINT
  1628. MibGetIpForwardNumber(
  1629. UINT actionId,
  1630. AsnAny *objectArray,
  1631. UINT *errorIndex
  1632. )
  1633. {
  1634. DWORD dwResult;
  1635. PIP_FORWARD_NUMBER_GET pOutput;
  1636. TraceEnter("MibGetIpForwardNumber");
  1637. dwResult = UpdateCache(FORWARD_MIB);
  1638. if(dwResult isnot NO_ERROR)
  1639. {
  1640. TRACE1("Couldnt update IP Forward cache",dwResult);
  1641. TraceLeave("MibGetIpForwardNumber");
  1642. return dwResult;
  1643. }
  1644. pOutput = (PIP_FORWARD_NUMBER_GET)objectArray;
  1645. EnterReader(FORWARD_MIB);
  1646. SetAsnGauge(&(pOutput->ipForwardNumber), g_Cache.pRpcIpForwardTable->dwNumEntries);
  1647. ReleaseLock(FORWARD_MIB);
  1648. TraceLeave("MibGetIpForwardNumber");
  1649. return MIB_S_SUCCESS;
  1650. }
  1651. UINT
  1652. MibGetIpForwardEntry(
  1653. UINT actionId,
  1654. AsnAny *objectArray,
  1655. UINT *errorIndex
  1656. )
  1657. {
  1658. DWORD dwResult;
  1659. PMIB_IPFORWARDROW pRpcIpForw;
  1660. PIP_FORWARD_ENTRY_GET pOutput;
  1661. TraceEnter("MibGetIpForwardEntry");
  1662. dwResult = UpdateCache(FORWARD_MIB);
  1663. if(dwResult isnot NO_ERROR)
  1664. {
  1665. TRACE1("Couldnt update IP Forward cache. Error %d", dwResult);
  1666. TraceLeave("MibGetIpForwardEntry");
  1667. return dwResult;
  1668. }
  1669. pOutput = (PIP_FORWARD_ENTRY_GET)objectArray;
  1670. EnterReader(FORWARD_MIB);
  1671. pRpcIpForw = LocateIpForwardRow(actionId,
  1672. &(pOutput->ipForwardDest),
  1673. &(pOutput->ipForwardProto),
  1674. &(pOutput->ipForwardPolicy),
  1675. &(pOutput->ipForwardNextHop));
  1676. if(pRpcIpForw is NULL)
  1677. {
  1678. ReleaseLock(FORWARD_MIB);
  1679. TRACE5("Unable to locateIP Forward Row. Action %d. Dest %x Proto %d Policy %d NextHop %x",
  1680. actionId,
  1681. GetAsnIPAddress(&(pOutput->ipForwardDest),0),
  1682. GetAsnInteger(&(pOutput->ipForwardProto),0),
  1683. GetAsnInteger(&(pOutput->ipForwardPolicy),0),
  1684. GetAsnIPAddress(&(pOutput->ipForwardNextHop),0));
  1685. TraceLeave("MibGetIpForwardEntry");
  1686. if(actionId is MIB_ACTION_GETNEXT)
  1687. {
  1688. return MIB_S_NO_MORE_ENTRIES;
  1689. }
  1690. return MIB_S_ENTRY_NOT_FOUND;
  1691. }
  1692. ForceSetAsnIPAddress(&(pOutput->ipForwardDest),
  1693. &(pOutput->dwIpForwardDestInfo),
  1694. pRpcIpForw->dwForwardDest);
  1695. SetAsnIPAddress(&(pOutput->ipForwardMask),
  1696. &(pOutput->dwIpForwardMaskInfo),
  1697. pRpcIpForw->dwForwardMask);
  1698. ForceSetAsnInteger(&(pOutput->ipForwardPolicy), pRpcIpForw->dwForwardPolicy);
  1699. ForceSetAsnIPAddress(&(pOutput->ipForwardNextHop),
  1700. &(pOutput->dwIpForwardNextHopInfo),
  1701. pRpcIpForw->dwForwardNextHop);
  1702. SetAsnInteger(&(pOutput->ipForwardIfIndex), pRpcIpForw->dwForwardIfIndex);
  1703. SetAsnInteger(&(pOutput->ipForwardType), pRpcIpForw->dwForwardType);
  1704. ForceSetAsnInteger(&(pOutput->ipForwardProto), pRpcIpForw->dwForwardProto);
  1705. SetAsnInteger(&(pOutput->ipForwardAge), pRpcIpForw->dwForwardAge);
  1706. SetToZeroOid(&(pOutput->ipForwardInfo));
  1707. SetAsnInteger(&(pOutput->ipForwardNextHopAS), pRpcIpForw->dwForwardNextHopAS);
  1708. SetAsnInteger(&(pOutput->ipForwardMetric1), pRpcIpForw->dwForwardMetric1);
  1709. SetAsnInteger(&(pOutput->ipForwardMetric2), pRpcIpForw->dwForwardMetric2);
  1710. SetAsnInteger(&(pOutput->ipForwardMetric3), pRpcIpForw->dwForwardMetric3);
  1711. SetAsnInteger(&(pOutput->ipForwardMetric4), pRpcIpForw->dwForwardMetric4);
  1712. SetAsnInteger(&(pOutput->ipForwardMetric5), pRpcIpForw->dwForwardMetric5);
  1713. ReleaseLock(FORWARD_MIB);
  1714. TraceLeave("MibGetIpForwardEntry");
  1715. return MIB_S_SUCCESS;
  1716. }
  1717. UINT
  1718. MibSetIpForwardEntry(
  1719. UINT actionId,
  1720. AsnAny *objectArray,
  1721. UINT *errorIndex
  1722. )
  1723. {
  1724. DWORD dwResult,dwType;
  1725. PMIB_IPFORWARDROW pRpcIpForw;
  1726. PIP_FORWARD_ENTRY_SET pInput;
  1727. PMIB_OPAQUE_INFO pInfo;
  1728. PMIB_IPFORWARDROW pSetRow;
  1729. pInput = (PIP_FORWARD_ENTRY_SET)objectArray;
  1730. pInfo = (PMIB_OPAQUE_INFO)(pInput->rgdwSetBuffer);
  1731. pSetRow = (PMIB_IPFORWARDROW)(pInfo->rgbyData);
  1732. switch(actionId)
  1733. {
  1734. case MIB_ACTION_VALIDATE:
  1735. {
  1736. TraceEnter("MibSetIpForwardEntry - VALIDATE");
  1737. dwResult = UpdateCache(FORWARD_MIB);
  1738. if(dwResult isnot NO_ERROR)
  1739. {
  1740. TRACE1("Couldnt update IP Forward cache. Error %d", dwResult);
  1741. TraceLeave("GetIpForwardEntry");
  1742. return dwResult;
  1743. }
  1744. ASSERT(!(IsAsnTypeNull(&(pInput->ipForwardDest))));
  1745. pInfo->dwId = IP_FORWARDROW;
  1746. EnterWriter(FORWARD_MIB);
  1747. pInput->bLocked = TRUE;
  1748. pRpcIpForw = LocateIpForwardRow(actionId,
  1749. &(pInput->ipForwardDest),
  1750. &(pInput->ipForwardProto),
  1751. &(pInput->ipForwardPolicy),
  1752. &(pInput->ipForwardNextHop));
  1753. if(pRpcIpForw is NULL)
  1754. {
  1755. //
  1756. // So we are creating a row. We need the If index, the mask,
  1757. // next hop and metric 1
  1758. //
  1759. if(IsAsnTypeNull(&(pInput->ipForwardIfIndex)) or
  1760. IsAsnTypeNull(&(pInput->ipForwardMask)) or
  1761. IsAsnTypeNull(&(pInput->ipForwardNextHop)) or
  1762. IsAsnTypeNull(&(pInput->ipForwardMetric1)))
  1763. {
  1764. TRACE0("Not enough information to create a route");
  1765. ReleaseLock(FORWARD_MIB);
  1766. pInput->bLocked = FALSE;
  1767. TraceLeave("MibSetIpForwardEntry");
  1768. return MIB_S_INVALID_PARAMETER;
  1769. }
  1770. dwType = GetAsnInteger(&(pInput->ipForwardType),
  1771. MIB_IPROUTE_TYPE_OTHER);
  1772. if(dwType is MIB_IPROUTE_TYPE_INVALID)
  1773. {
  1774. //
  1775. // We couldnt be creating and deleting a row at the
  1776. // same time
  1777. //
  1778. ReleaseLock(FORWARD_MIB);
  1779. pInput->bLocked = FALSE;
  1780. TRACE0("Wrong type");
  1781. TraceLeave("MibSetIpForwardEntry");
  1782. return MIB_S_INVALID_PARAMETER;
  1783. }
  1784. pSetRow->dwForwardProto =
  1785. GetAsnInteger(&(pInput->ipForwardProto),
  1786. MIB_IPPROTO_NETMGMT);
  1787. if((pSetRow->dwForwardProto isnot MIB_IPPROTO_NETMGMT) and
  1788. (pSetRow->dwForwardProto isnot MIB_IPPROTO_LOCAL))
  1789. {
  1790. //
  1791. // wrong protocol
  1792. //
  1793. ReleaseLock(FORWARD_MIB);
  1794. pInput->bLocked = FALSE;
  1795. TRACE1("Wrong protocol %d",
  1796. pSetRow->dwForwardProto);
  1797. TraceLeave("MibSetIpForwardEntry");
  1798. return MIB_S_INVALID_PARAMETER;
  1799. }
  1800. pInput->raAction = CREATE_ROW;
  1801. pSetRow->dwForwardDest =
  1802. GetAsnIPAddress(&(pInput->ipForwardDest),
  1803. 0xffffffff);
  1804. pSetRow->dwForwardMask =
  1805. GetAsnIPAddress(&(pInput->ipForwardMask),
  1806. 0x00000000);
  1807. pSetRow->dwForwardPolicy = 0;
  1808. pSetRow->dwForwardNextHop =
  1809. GetAsnIPAddress(&(pInput->ipForwardNextHop),
  1810. 0x00000000);
  1811. pSetRow->dwForwardIfIndex =
  1812. GetAsnInteger(&(pInput->ipForwardIfIndex),
  1813. 0);
  1814. //
  1815. // We default to an age of 0 seconds, per RFC 2096.
  1816. //
  1817. pSetRow->dwForwardAge =
  1818. GetAsnInteger(&(pInput->ipForwardAge),0);
  1819. pSetRow->dwForwardNextHopAS = 0;
  1820. pSetRow->dwForwardMetric1 =
  1821. GetAsnInteger(&(pInput->ipForwardMetric1),0);
  1822. pSetRow->dwForwardMetric2 =
  1823. GetAsnInteger(&(pInput->ipForwardMetric2),-1);
  1824. pSetRow->dwForwardMetric3 =
  1825. GetAsnInteger(&(pInput->ipForwardMetric3),-1);
  1826. pSetRow->dwForwardMetric4 =
  1827. GetAsnInteger(&(pInput->ipForwardMetric4),-1);
  1828. pSetRow->dwForwardMetric5 =
  1829. GetAsnInteger(&(pInput->ipForwardMetric5),-1);
  1830. TraceLeave("MibSetIpForwardEntry");
  1831. return MIB_S_SUCCESS;
  1832. }
  1833. else
  1834. {
  1835. //
  1836. // Ok so we are only changing some stuff in the route
  1837. //
  1838. dwType = GetAsnInteger(&(pInput->ipForwardType),
  1839. pRpcIpForw->dwForwardType);
  1840. if(dwType is MIB_IPROUTE_TYPE_INVALID)
  1841. {
  1842. //
  1843. // Deleting a row
  1844. //
  1845. pInput->raAction = DELETE_ROW;
  1846. *pSetRow = *pRpcIpForw;
  1847. ReleaseLock(FORWARD_MIB);
  1848. pInput->bLocked = FALSE;
  1849. TraceLeave("MibSetIpForwardEntry");
  1850. return MIB_S_SUCCESS;
  1851. }
  1852. pSetRow->dwForwardProto =
  1853. GetAsnInteger(&(pInput->ipForwardProto),
  1854. pRpcIpForw->dwForwardProto);
  1855. if((pSetRow->dwForwardProto isnot MIB_IPPROTO_NETMGMT) and
  1856. (pSetRow->dwForwardProto isnot MIB_IPPROTO_LOCAL))
  1857. {
  1858. //
  1859. // wrong protocol
  1860. //
  1861. ReleaseLock(FORWARD_MIB);
  1862. pInput->bLocked = FALSE;
  1863. TRACE1("Wrong protocol %d",
  1864. pSetRow->dwForwardProto);
  1865. TraceLeave("MibSetIpForwardEntry");
  1866. return MIB_S_INVALID_PARAMETER;
  1867. }
  1868. pInput->raAction = SET_ROW;
  1869. pSetRow->dwForwardDest =
  1870. GetAsnIPAddress(&(pInput->ipForwardDest),
  1871. pRpcIpForw->dwForwardDest);
  1872. pSetRow->dwForwardMask =
  1873. GetAsnIPAddress(&(pInput->ipForwardMask),
  1874. pRpcIpForw->dwForwardMask);
  1875. pSetRow->dwForwardPolicy = 0;
  1876. pSetRow->dwForwardNextHop =
  1877. GetAsnIPAddress(&(pInput->ipForwardNextHop),
  1878. pRpcIpForw->dwForwardNextHop);
  1879. pSetRow->dwForwardIfIndex =
  1880. GetAsnInteger(&(pInput->ipForwardIfIndex),
  1881. pRpcIpForw->dwForwardIfIndex);
  1882. //
  1883. // The type gets set by the router manager. But incase
  1884. // we are writing to the stack we need some kind of valid type
  1885. //
  1886. pSetRow->dwForwardType =
  1887. GetAsnInteger(&(pInput->ipForwardType),
  1888. pRpcIpForw->dwForwardType);
  1889. pSetRow->dwForwardAge =
  1890. GetAsnInteger(&(pInput->ipForwardAge),
  1891. pRpcIpForw->dwForwardAge);
  1892. pSetRow->dwForwardNextHopAS = 0;
  1893. pSetRow->dwForwardMetric1 =
  1894. GetAsnInteger(&(pInput->ipForwardMetric1),
  1895. pRpcIpForw->dwForwardMetric1);
  1896. pSetRow->dwForwardMetric2 =
  1897. GetAsnInteger(&(pInput->ipForwardMetric2),
  1898. pRpcIpForw->dwForwardMetric2);
  1899. pSetRow->dwForwardMetric3 =
  1900. GetAsnInteger(&(pInput->ipForwardMetric3),
  1901. pRpcIpForw->dwForwardMetric3);
  1902. pSetRow->dwForwardMetric4 =
  1903. GetAsnInteger(&(pInput->ipForwardMetric4),
  1904. pRpcIpForw->dwForwardMetric4);
  1905. pSetRow->dwForwardMetric5 =
  1906. GetAsnInteger(&(pInput->ipForwardMetric5),
  1907. pRpcIpForw->dwForwardMetric5);
  1908. TraceLeave("MibSetIpForwardEntry");
  1909. return MIB_S_SUCCESS;
  1910. }
  1911. }
  1912. case MIB_ACTION_SET:
  1913. {
  1914. TraceEnter("MibSetIpForwardEntry - SET");
  1915. switch(pInput->raAction)
  1916. {
  1917. case CREATE_ROW:
  1918. {
  1919. dwResult = InternalCreateIpForwardEntry(pInfo);
  1920. #ifdef MIB_DEBUG
  1921. if(dwResult isnot NO_ERROR)
  1922. {
  1923. TRACE1("Create failed with error %d",dwResult);
  1924. }
  1925. #endif
  1926. InvalidateCache(FORWARD_MIB);
  1927. TraceLeave("MibSetIpForwardEntry");
  1928. return dwResult;
  1929. }
  1930. case SET_ROW:
  1931. {
  1932. dwResult = InternalSetIpForwardEntry(pInfo);
  1933. #ifdef MIB_DEBUG
  1934. if(dwResult isnot NO_ERROR)
  1935. {
  1936. TRACE1("Set failed with error %d",dwResult);
  1937. }
  1938. #endif
  1939. InvalidateCache(FORWARD_MIB);
  1940. TraceLeave("MibSetIpForwardEntry");
  1941. return dwResult;
  1942. }
  1943. case DELETE_ROW:
  1944. {
  1945. dwResult = InternalDeleteIpForwardEntry(pInfo);
  1946. #ifdef MIB_DEBUG
  1947. if(dwResult isnot NO_ERROR)
  1948. {
  1949. TRACE1("Delete failed with error %d",dwResult);
  1950. }
  1951. #endif
  1952. InvalidateCache(FORWARD_MIB);
  1953. TraceLeave("MibSetIpForwardEntry");
  1954. return dwResult;
  1955. }
  1956. default:
  1957. {
  1958. TRACE1("Wrong row action %d",pInput->raAction);
  1959. TraceLeave("MibSetIpForwardEntry");
  1960. return MIB_S_SUCCESS;
  1961. }
  1962. }
  1963. }
  1964. case MIB_ACTION_CLEANUP:
  1965. {
  1966. TraceEnter("MibSetIpForwardEntry - CLEANUP");
  1967. if(pInput->bLocked)
  1968. {
  1969. ReleaseLock(FORWARD_MIB);
  1970. }
  1971. TraceLeave("MibSetIpForwardEntry");
  1972. return MIB_S_SUCCESS;
  1973. }
  1974. default:
  1975. {
  1976. TraceEnter("MibSetIpForwardEntry - WRONG ACTION");
  1977. TraceLeave("MibSetIpForwardEntry");
  1978. return MIB_S_INVALID_PARAMETER;
  1979. }
  1980. }
  1981. }
  1982. UINT
  1983. MibGetSysInfo(
  1984. UINT actionId,
  1985. AsnAny *objectArray,
  1986. UINT *errorIndex
  1987. )
  1988. {
  1989. DWORD dwResult;
  1990. PSYS_INFO_GET pOutput;
  1991. TraceEnter("MibGetSysInfo");
  1992. dwResult = UpdateCache(MIB_II_SYS);
  1993. if(dwResult isnot NO_ERROR)
  1994. {
  1995. TRACE1("Couldnt update SYS cache. Error %d", dwResult);
  1996. TraceLeave("MibGetSysInfo");
  1997. return dwResult;
  1998. }
  1999. pOutput = (PSYS_INFO_GET)objectArray;
  2000. EnterReader(MIB_II_SYS);
  2001. SetAsnOctetString(&(pOutput->sysDescr),
  2002. pOutput->rgbySysDescrInfo,
  2003. g_Cache.pRpcSysInfo->rgbySysDescr,
  2004. (strlen(g_Cache.pRpcSysInfo->rgbySysDescr)));
  2005. SetAsnInteger(&(pOutput->sysServices),g_Cache.pRpcSysInfo->dwSysServices);
  2006. SetAsnOctetString(&(pOutput->sysContact),
  2007. pOutput->rgbySysContactInfo,
  2008. g_Cache.pRpcSysInfo->rgbySysContact,
  2009. (strlen(g_Cache.pRpcSysInfo->rgbySysContact)));
  2010. SetAsnOctetString(&(pOutput->sysLocation),
  2011. pOutput->rgbySysLocationInfo,
  2012. g_Cache.pRpcSysInfo->rgbySysLocation,
  2013. (strlen(g_Cache.pRpcSysInfo->rgbySysLocation)));
  2014. SetAsnOctetString(&(pOutput->sysName),
  2015. pOutput->rgbySysNameInfo,
  2016. g_Cache.pRpcSysInfo->rgbySysName,
  2017. (strlen(g_Cache.pRpcSysInfo->rgbySysName)));
  2018. //
  2019. // must not cache system uptime so get update from dll
  2020. //
  2021. SetAsnTimeTicks(&(pOutput->sysUpTime),SnmpSvcGetUptime());
  2022. if (!IsAsnTypeNull(&pOutput->sysObjectID)) {
  2023. SnmpUtilOidCpy(&pOutput->sysObjectID.asnValue.object,
  2024. &g_Cache.pRpcSysInfo->aaSysObjectID.asnValue.object);
  2025. }
  2026. ReleaseLock(MIB_II_SYS);
  2027. TraceLeave("MibGetSysInfo");
  2028. return MIB_S_SUCCESS;
  2029. }
  2030. UINT
  2031. MibSetSysInfo(
  2032. UINT actionId,
  2033. AsnAny *objectArray,
  2034. UINT *errorIndex
  2035. )
  2036. {
  2037. DWORD dwResult,dwValueLen,dwValueType,dwStringLen;
  2038. PSYS_INFO_SET pInput;
  2039. HKEY hkeyMib2;
  2040. pInput = (PSYS_INFO_SET)objectArray;
  2041. switch(actionId)
  2042. {
  2043. case MIB_ACTION_VALIDATE:
  2044. {
  2045. pInput->bLocked = FALSE;
  2046. EnterWriter(MIB_II_SYS);
  2047. pInput->bLocked = TRUE;
  2048. TraceEnter("MibSetSysInfo - VALIDATE");
  2049. dwResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  2050. REG_KEY_MIB2,
  2051. 0,
  2052. KEY_ALL_ACCESS,
  2053. &pInput->hkeyMib2);
  2054. if(dwResult isnot NO_ERROR)
  2055. {
  2056. ReleaseLock(MIB_II_SYS);
  2057. pInput->bLocked = FALSE;
  2058. TRACE1("Couldnt open mib2 registry key. Error %d", dwResult);
  2059. TraceLeave("MibSetSysInfo");
  2060. return dwResult;
  2061. }
  2062. TraceLeave("MibSetSysInfo");
  2063. return MIB_S_SUCCESS;
  2064. }
  2065. case MIB_ACTION_SET:
  2066. {
  2067. TraceEnter("MibSetSysInfo - SET");
  2068. hkeyMib2 = pInput->hkeyMib2;
  2069. dwValueType = REG_SZ;
  2070. if (!IsAsnTypeNull(&pInput->sysName)) {
  2071. dwStringLen = pInput->sysName.asnValue.string.length;
  2072. dwValueLen = dwStringLen + 1;
  2073. memcpy(&pInput->rgbySysNameInfo,
  2074. pInput->sysName.asnValue.string.stream,
  2075. dwStringLen);
  2076. pInput->rgbySysNameInfo[dwStringLen] = '\0';
  2077. dwResult = RegSetValueEx(
  2078. hkeyMib2,
  2079. TEXT("sysName"),
  2080. 0,
  2081. dwValueType,
  2082. pInput->rgbySysNameInfo,
  2083. dwValueLen);
  2084. if (dwResult isnot NO_ERROR) {
  2085. TRACE1("Couldnt write sysName value. Error %d", dwResult);
  2086. TraceLeave("MibSetSysInfo");
  2087. return dwResult;
  2088. }
  2089. InvalidateCache(MIB_II_SYS);
  2090. }
  2091. if (!IsAsnTypeNull(&pInput->sysContact)) {
  2092. dwStringLen = pInput->sysContact.asnValue.string.length;
  2093. dwValueLen = dwStringLen + 1;
  2094. memcpy(&pInput->rgbySysContactInfo,
  2095. pInput->sysContact.asnValue.string.stream,
  2096. dwStringLen);
  2097. pInput->rgbySysContactInfo[dwStringLen] = '\0';
  2098. dwResult = RegSetValueEx(
  2099. hkeyMib2,
  2100. TEXT("sysContact"),
  2101. 0,
  2102. dwValueType,
  2103. pInput->rgbySysContactInfo,
  2104. dwValueLen);
  2105. if (dwResult isnot NO_ERROR) {
  2106. TRACE1("Couldnt write sysContact value. Error %d", dwResult);
  2107. TraceLeave("MibSetSysInfo");
  2108. return dwResult;
  2109. }
  2110. InvalidateCache(MIB_II_SYS);
  2111. }
  2112. if (!IsAsnTypeNull(&pInput->sysLocation)) {
  2113. dwStringLen = pInput->sysLocation.asnValue.string.length;
  2114. dwValueLen = dwStringLen + 1;
  2115. memcpy(&pInput->rgbySysLocationInfo,
  2116. pInput->sysLocation.asnValue.string.stream,
  2117. dwStringLen);
  2118. pInput->rgbySysLocationInfo[dwStringLen] = '\0';
  2119. dwResult = RegSetValueEx(
  2120. hkeyMib2,
  2121. TEXT("sysLocation"),
  2122. 0,
  2123. dwValueType,
  2124. pInput->rgbySysLocationInfo,
  2125. dwValueLen);
  2126. if (dwResult isnot NO_ERROR) {
  2127. TRACE1("Couldnt write sysLocation value. Error %d", dwResult);
  2128. TraceLeave("MibSetSysInfo");
  2129. return dwResult;
  2130. }
  2131. InvalidateCache(MIB_II_SYS);
  2132. }
  2133. TraceLeave("MibSetSysInfo");
  2134. return MIB_S_SUCCESS;
  2135. }
  2136. case MIB_ACTION_CLEANUP:
  2137. {
  2138. TraceEnter("MibSetSysInfo - CLEANUP");
  2139. if (pInput->hkeyMib2) {
  2140. RegCloseKey(pInput->hkeyMib2);
  2141. }
  2142. if(pInput->bLocked)
  2143. {
  2144. ReleaseLock(MIB_II_SYS);
  2145. }
  2146. TraceLeave("MibSetSysInfo");
  2147. return MIB_S_SUCCESS;
  2148. }
  2149. default:
  2150. {
  2151. TraceEnter("MibSetSysInfo - WRONG ACTION");
  2152. TraceLeave("MibSetSysInfo");
  2153. return MIB_S_INVALID_PARAMETER;
  2154. }
  2155. }
  2156. }
  2157. DWORD
  2158. GetIfIndexFromAddr(
  2159. DWORD dwAddr
  2160. )
  2161. {
  2162. DWORD dwResult, i;
  2163. PMIB_IPADDRROW pRpcIpAddr;
  2164. DWORD dwIfIndex = INVALID_IFINDEX;
  2165. TraceEnter("GetIfIndexFromIpAddr");
  2166. dwResult = UpdateCache(MIB_II_IPADDR);
  2167. if(dwResult isnot NO_ERROR)
  2168. {
  2169. TRACE1("Couldnt update IP Addr cache. Error %d", dwResult);
  2170. TraceLeave("GetIfIndexFromIpAddr");
  2171. return dwIfIndex;
  2172. }
  2173. EnterReader(MIB_II_IPADDR);
  2174. pRpcIpAddr = &g_Cache.pRpcIpAddrTable->table[0];
  2175. for (i = 0; i < g_Cache.pRpcIpAddrTable->dwNumEntries; i++, pRpcIpAddr++)
  2176. {
  2177. if (dwAddr is pRpcIpAddr->dwAddr)
  2178. {
  2179. dwIfIndex = pRpcIpAddr->dwIndex;
  2180. TRACE1("Found exact match. ifIndex %d", dwIfIndex);
  2181. break;
  2182. }
  2183. if ((dwIfIndex is INVALID_IFINDEX) and (pRpcIpAddr->dwMask))
  2184. {
  2185. //
  2186. // See if addr is on the same subnet as this address.
  2187. //
  2188. if ((dwAddr & pRpcIpAddr->dwMask) is
  2189. (pRpcIpAddr->dwAddr & pRpcIpAddr->dwMask))
  2190. {
  2191. dwIfIndex = pRpcIpAddr->dwIndex;
  2192. TRACE1("Found possible match. ifIndex %d", dwIfIndex);
  2193. }
  2194. }
  2195. }
  2196. ReleaseLock(MIB_II_IPADDR);
  2197. TraceLeave("GetIfIndexFromIpAddr");
  2198. return dwIfIndex;
  2199. }
  2200. UINT
  2201. MibGetIpv6Group(
  2202. UINT actionId,
  2203. AsnAny *objectArray,
  2204. UINT *errorIndex
  2205. )
  2206. {
  2207. DWORD dwResult;
  2208. PIPV6_STATS_GET pOutput;
  2209. MIB_IPSTATS rpcIpStats;
  2210. TraceEnter("MibGetIpv6Group");
  2211. dwResult = GetIpStatisticsEx(&rpcIpStats, AF_INET6);
  2212. if(dwResult isnot NO_ERROR)
  2213. {
  2214. TRACE1("Couldnt get IP stats. Error %d",dwResult);
  2215. TraceLeave("MibGetIpGroup");
  2216. if(actionId is MIB_ACTION_GETNEXT)
  2217. {
  2218. return MIB_S_NO_MORE_ENTRIES;
  2219. }
  2220. return MIB_S_ENTRY_NOT_FOUND;
  2221. }
  2222. pOutput = (PIPV6_STATS_GET)objectArray;
  2223. SetAsnInteger(&(pOutput->ipv6Forwarding), rpcIpStats.dwForwarding);
  2224. SetAsnInteger(&(pOutput->ipv6DefaultHopLimit), rpcIpStats.dwDefaultTTL);
  2225. SetAsnUnsigned32(&(pOutput->ipv6Interfaces), rpcIpStats.dwNumIf);
  2226. SetAsnTimeTicks(&(pOutput->ipv6IfTableLastChange), 0);
  2227. SetAsnGauge(&(pOutput->ipv6RouteNumber), rpcIpStats.dwNumRoutes);
  2228. SetAsnCounter(&(pOutput->ipv6DiscardedRoutes), 0);
  2229. TraceLeave("MibGetIpv6Group");
  2230. return MIB_S_SUCCESS;
  2231. }
  2232. UINT
  2233. MibGetIpv6IfEntry(
  2234. UINT actionId,
  2235. AsnAny *objectArray,
  2236. UINT *errorIndex
  2237. )
  2238. {
  2239. DWORD dwResult;
  2240. PMIB_IPV6_IF pRpcIf;
  2241. PIPV6_IF_GET pOutput;
  2242. CHAR szDescription[MAX_IF_DESCR_LEN + 1];
  2243. TraceEnter("MibGetIf6Entry");
  2244. dwResult = UpdateCache(MIB_II_IPV6_IF);
  2245. if(dwResult isnot NO_ERROR)
  2246. {
  2247. TRACE1("Couldn't update IF cache. Error %d",dwResult);
  2248. TraceLeave("MibGetIfEntry");
  2249. return dwResult;
  2250. }
  2251. pOutput = (PIPV6_IF_GET)objectArray;
  2252. EnterReader(MIB_II_IPV6_IF);
  2253. pRpcIf = LocateIpv6IfRow(actionId,
  2254. &(pOutput->ipv6IfIndex));
  2255. if(pRpcIf is NULL)
  2256. {
  2257. ReleaseLock(MIB_II_IPV6_IF);
  2258. TRACE2("Unable to locate IF Row. Action is %d. Index is %d",
  2259. actionId,
  2260. GetAsnInteger(&(pOutput->ifIndex),-1));
  2261. TraceLeave("MibGetIfEntry");
  2262. if(actionId is MIB_ACTION_GETNEXT)
  2263. {
  2264. return MIB_S_NO_MORE_ENTRIES;
  2265. }
  2266. return MIB_S_ENTRY_NOT_FOUND;
  2267. }
  2268. ForceSetAsnInteger(&(pOutput->ipv6IfIndex),pRpcIf->dwIndex);
  2269. WideCharToMultiByte(CP_UTF8, 0, pRpcIf->wszDescription, -1,
  2270. szDescription, MAX_IF_DESCR_LEN,
  2271. NULL, NULL);
  2272. SetAsnOctetString(&(pOutput->ipv6IfDescr),
  2273. pOutput->rgbyIpv6IfDescrInfo,
  2274. szDescription,
  2275. min(strlen(szDescription),MAX_IF_DESCR_LEN));
  2276. //
  2277. // Don't implement ifLowerLayer, since it's non-trivial,
  2278. // and is obsoleted in the latest draft updating the RFC.
  2279. //
  2280. SetToZeroOid(&(pOutput->ipv6IfLowerLayer));
  2281. SetAsnUnsigned32(&(pOutput->ipv6IfEffectiveMtu), pRpcIf->dwEffectiveMtu);
  2282. SetAsnUnsigned32(&(pOutput->ipv6IfReasmMaxSize), pRpcIf->dwReasmMaxSize);
  2283. //
  2284. // TODO: The EUI-64 is not currently retrievable from user-mode.
  2285. //
  2286. SetAsnOctetString(&(pOutput->ipv6IfIdentifier),
  2287. pOutput->rgbyIpv6IfIdentifierInfo,
  2288. NULL,
  2289. 0);
  2290. SetAsnInteger(&(pOutput->ipv6IfIdentifierLength), 0);
  2291. SetAsnOctetString(&(pOutput->ipv6IfPhysicalAddress),
  2292. pOutput->rgbyIpv6IfPhysicalAddressInfo,
  2293. pRpcIf->bPhysicalAddress,
  2294. min(pRpcIf->dwPhysicalAddressLength,MAX_PHYS_ADDR_LEN));
  2295. SetAsnInteger(&(pOutput->ipv6IfAdminStatus), pRpcIf->dwAdminStatus);
  2296. SetAsnInteger(&(pOutput->ipv6IfOperStatus), pRpcIf->dwOperStatus);
  2297. SetAsnTimeTicks(&(pOutput->ipv6IfLastChange), pRpcIf->dwLastChange);
  2298. ReleaseLock(MIB_II_IPV6_IF);
  2299. TraceLeave("MibGetIpv6IfEntry");
  2300. return MIB_S_SUCCESS;
  2301. }
  2302. UINT
  2303. MibGetIpv6IfStatsEntry(
  2304. UINT actionId,
  2305. AsnAny *objectArray,
  2306. UINT *errorIndex
  2307. )
  2308. {
  2309. DWORD dwResult;
  2310. LONG IfIndex;
  2311. PIPV6_IF_STATS_GET pOutput = (PIPV6_IF_STATS_GET)objectArray;
  2312. MIB_IPSTATS rpcIpStats;
  2313. TraceEnter("MibGetIpv6IfStatsEntry");
  2314. IfIndex = GetAsnInteger(&(pOutput->ipv6IfIndex),-1);
  2315. if ((actionId is MIB_ACTION_GETNEXT) && (IfIndex >= 0))
  2316. {
  2317. TraceLeave("MibGetIpv6IfStatsEntry");
  2318. return MIB_S_NO_MORE_ENTRIES;
  2319. }
  2320. if ((actionId is MIB_ACTION_GET) && (IfIndex != 0))
  2321. {
  2322. TraceLeave("MibGetIpv6IfStatsEntry");
  2323. return MIB_S_ENTRY_NOT_FOUND;
  2324. }
  2325. dwResult = GetIpStatisticsEx(&rpcIpStats, AF_INET6);
  2326. if(dwResult isnot NO_ERROR)
  2327. {
  2328. TRACE1("Couldn't get IPv6 stats. Error %d",dwResult);
  2329. TraceLeave("MibGetIpv6IfStatsEntry");
  2330. if(actionId is MIB_ACTION_GETNEXT)
  2331. {
  2332. return MIB_S_NO_MORE_ENTRIES;
  2333. }
  2334. return MIB_S_ENTRY_NOT_FOUND;
  2335. }
  2336. ForceSetAsnInteger(&(pOutput->ipv6IfIndex), 0);
  2337. SetAsnCounter(&(pOutput->ipv6IfStatsInReceives), rpcIpStats.dwInReceives);
  2338. SetAsnCounter(&(pOutput->ipv6IfStatsInHdrErrors), rpcIpStats.dwInHdrErrors);
  2339. SetAsnCounter(&(pOutput->ipv6IfStatsInTooBigErrors), 0);
  2340. SetAsnCounter(&(pOutput->ipv6IfStatsInNoRoutes), rpcIpStats.dwOutNoRoutes);
  2341. SetAsnCounter(&(pOutput->ipv6IfStatsInAddrErrors), rpcIpStats.dwInAddrErrors);
  2342. SetAsnCounter(&(pOutput->ipv6IfStatsInUnknownProtos), rpcIpStats.dwInUnknownProtos);
  2343. SetAsnCounter(&(pOutput->ipv6IfStatsInTruncatedPkts), 0);
  2344. SetAsnCounter(&(pOutput->ipv6IfStatsInDiscards), rpcIpStats.dwInDiscards);
  2345. SetAsnCounter(&(pOutput->ipv6IfStatsInDelivers), rpcIpStats.dwInDelivers);
  2346. SetAsnCounter(&(pOutput->ipv6IfStatsOutForwDatagrams), rpcIpStats.dwForwDatagrams);
  2347. SetAsnCounter(&(pOutput->ipv6IfStatsOutRequests), rpcIpStats.dwOutRequests);
  2348. SetAsnCounter(&(pOutput->ipv6IfStatsOutDiscards), rpcIpStats.dwOutDiscards);
  2349. SetAsnCounter(&(pOutput->ipv6IfStatsOutFragOKs), rpcIpStats.dwFragOks);
  2350. SetAsnCounter(&(pOutput->ipv6IfStatsOutFragFails), rpcIpStats.dwFragFails);
  2351. SetAsnCounter(&(pOutput->ipv6IfStatsOutFragCreates), rpcIpStats.dwFragCreates);
  2352. SetAsnCounter(&(pOutput->ipv6IfStatsReasmReqds), rpcIpStats.dwReasmReqds);
  2353. SetAsnCounter(&(pOutput->ipv6IfStatsReasmOKs), rpcIpStats.dwReasmOks);
  2354. SetAsnCounter(&(pOutput->ipv6IfStatsReasmFails), rpcIpStats.dwReasmFails);
  2355. SetAsnCounter(&(pOutput->ipv6IfStatsInMcastPkts), 0);
  2356. SetAsnCounter(&(pOutput->ipv6IfStatsOutMcastPkts), 0);
  2357. TraceLeave("MibGetIpv6IfStatsEntry");
  2358. return MIB_S_SUCCESS;
  2359. }
  2360. UINT
  2361. MibGetInetIcmpEntry(
  2362. UINT actionId,
  2363. AsnAny *objectArray,
  2364. UINT *errorIndex
  2365. )
  2366. {
  2367. DWORD dwResult;
  2368. PINET_ICMP_GET pOutput = (PINET_ICMP_GET)objectArray;
  2369. PMIB_INET_ICMP pRow;
  2370. TraceEnter("MibGetInetIcmpEntry");
  2371. dwResult = UpdateCache(MIB_II_ICMP);
  2372. if(dwResult isnot NO_ERROR)
  2373. {
  2374. TRACE1("Couldn't update ICMP cache. Error %d",dwResult);
  2375. TraceLeave("MibGetInetIcmpEntry");
  2376. return dwResult;
  2377. }
  2378. EnterReader(MIB_II_ICMP);
  2379. pOutput = (PINET_ICMP_GET)objectArray;
  2380. pRow = LocateInetIcmpRow(actionId,
  2381. &(pOutput->inetIcmpAFType),
  2382. &(pOutput->inetIcmpIfIndex));
  2383. if(pRow is NULL)
  2384. {
  2385. ReleaseLock(MIB_II_ICMP);
  2386. TRACE0("Unable to locate icmp row");
  2387. TraceLeave("MibGetInetIcmpEntry");
  2388. if(actionId is MIB_ACTION_GETNEXT)
  2389. {
  2390. return MIB_S_NO_MORE_ENTRIES;
  2391. }
  2392. return MIB_S_ENTRY_NOT_FOUND;
  2393. }
  2394. ForceSetAsnInteger(&(pOutput->inetIcmpAFType), pRow->dwAFType);
  2395. ForceSetAsnInteger(&(pOutput->inetIcmpIfIndex), pRow->dwIfIndex);
  2396. SetAsnCounter(&(pOutput->inetIcmpInMsgs), pRow->dwInMsgs);
  2397. SetAsnCounter(&(pOutput->inetIcmpInErrors), pRow->dwInErrors);
  2398. SetAsnCounter(&(pOutput->inetIcmpOutMsgs), pRow->dwOutMsgs);
  2399. SetAsnCounter(&(pOutput->inetIcmpOutErrors), pRow->dwOutErrors);
  2400. ReleaseLock(MIB_II_ICMP);
  2401. TraceLeave("MibGetInetIcmpEntry");
  2402. return MIB_S_SUCCESS;
  2403. }
  2404. UINT
  2405. MibGetInetIcmpMsgEntry(
  2406. UINT actionId,
  2407. AsnAny *objectArray,
  2408. UINT *errorIndex
  2409. )
  2410. {
  2411. DWORD dwResult;
  2412. PINET_ICMP_MSG_GET pOutput = (PINET_ICMP_MSG_GET)objectArray;
  2413. PMIB_INET_ICMP_MSG pRow;
  2414. TraceEnter("MibGetInetIcmpMsgEntry");
  2415. dwResult = UpdateCache(MIB_II_ICMP);
  2416. if(dwResult isnot NO_ERROR)
  2417. {
  2418. TRACE1("Couldnt update ICMP cache. Error %d",dwResult);
  2419. TraceLeave("MibGetInetIcmpMsgEntry");
  2420. return dwResult;
  2421. }
  2422. EnterReader(MIB_II_ICMP);
  2423. pOutput = (PINET_ICMP_MSG_GET)objectArray;
  2424. pRow = LocateInetIcmpMsgRow(actionId,
  2425. &(pOutput->inetIcmpMsgAFType),
  2426. &(pOutput->inetIcmpMsgIfIndex),
  2427. &(pOutput->inetIcmpMsgType),
  2428. &(pOutput->inetIcmpMsgCode));
  2429. if(pRow is NULL)
  2430. {
  2431. ReleaseLock(MIB_II_ICMP);
  2432. TRACE0("Unable to locate icmp row");
  2433. TraceLeave("MibGetInetIcmpMsgEntry");
  2434. if(actionId is MIB_ACTION_GETNEXT)
  2435. {
  2436. return MIB_S_NO_MORE_ENTRIES;
  2437. }
  2438. return MIB_S_ENTRY_NOT_FOUND;
  2439. }
  2440. ForceSetAsnInteger(&(pOutput->inetIcmpMsgAFType), pRow->dwAFType);
  2441. ForceSetAsnInteger(&(pOutput->inetIcmpMsgIfIndex), pRow->dwIfIndex);
  2442. ForceSetAsnInteger(&(pOutput->inetIcmpMsgType), pRow->dwType);
  2443. ForceSetAsnInteger(&(pOutput->inetIcmpMsgCode), pRow->dwCode);
  2444. SetAsnCounter(&(pOutput->inetIcmpMsgInPkts), pRow->dwInPkts);
  2445. SetAsnCounter(&(pOutput->inetIcmpMsgOutPkts), pRow->dwOutPkts);
  2446. ReleaseLock(MIB_II_ICMP);
  2447. TraceLeave("MibGetInetIcmpMsgEntry");
  2448. return MIB_S_SUCCESS;
  2449. }
  2450. UINT
  2451. MibGetIpv6AddrEntry(
  2452. UINT actionId,
  2453. AsnAny *objectArray,
  2454. UINT *errorIndex
  2455. )
  2456. {
  2457. DWORD dwResult;
  2458. PIPV6_ADDR_GET pOutput;
  2459. PMIB_IPV6_ADDR pAddr;
  2460. TraceEnter("MibGetIpv6AddrEntry");
  2461. dwResult = UpdateCache(MIB_II_IPV6_IF);
  2462. if(dwResult isnot NO_ERROR)
  2463. {
  2464. TRACE1("Couldn't update IPv6 address cache. Error %d",dwResult);
  2465. TraceLeave("MibGetIpv6AddrEntry");
  2466. return dwResult;
  2467. }
  2468. EnterReader(MIB_II_IPV6_IF);
  2469. pOutput = (PIPV6_ADDR_GET)objectArray;
  2470. pAddr = LocateIpv6AddrRow(actionId,
  2471. &(pOutput->ipv6IfIndex),
  2472. &(pOutput->ipv6AddrAddress));
  2473. if(pAddr is NULL)
  2474. {
  2475. ReleaseLock(MIB_II_IPV6_IF);
  2476. TRACE0("Unable to locate IPv6 address row");
  2477. TraceLeave("MibGetIpv6AddrEntry");
  2478. if(actionId is MIB_ACTION_GETNEXT)
  2479. {
  2480. return MIB_S_NO_MORE_ENTRIES;
  2481. }
  2482. return MIB_S_ENTRY_NOT_FOUND;
  2483. }
  2484. ForceSetAsnInteger(&(pOutput->ipv6IfIndex), pAddr->dwIfIndex);
  2485. ForceSetAsnOctetString(&(pOutput->ipv6AddrAddress),
  2486. &pOutput->ipv6AddrAddressInfo,
  2487. &pAddr->ipAddress,
  2488. sizeof(IN6_ADDR));
  2489. SetAsnInteger(&(pOutput->ipv6AddrPfxLength), pAddr->dwPrefixLength);
  2490. SetAsnInteger(&(pOutput->ipv6AddrType), pAddr->dwType);
  2491. SetAsnInteger(&(pOutput->ipv6AddrAnycastFlag), pAddr->dwAnycastFlag);
  2492. SetAsnInteger(&(pOutput->ipv6AddrStatus), pAddr->dwStatus);
  2493. ReleaseLock(MIB_II_IPV6_IF);
  2494. TraceLeave("MibGetIpv6AddrEntry");
  2495. return MIB_S_SUCCESS;
  2496. }
  2497. UINT
  2498. MibGetIpv6AddrPrefixEntry(
  2499. UINT actionId,
  2500. AsnAny *objectArray,
  2501. UINT *errorIndex
  2502. )
  2503. {
  2504. DWORD dwResult;
  2505. PIPV6_ADDR_PREFIX_GET pOutput;
  2506. PMIB_IPV6_ADDR_PREFIX pRow;
  2507. TraceEnter("MibGetIpv6AddrPrefixEntry");
  2508. dwResult = UpdateCache(MIB_II_IPV6_ROUTE);
  2509. if(dwResult isnot NO_ERROR)
  2510. {
  2511. TRACE1("Couldn't update IPv6 addr prefix table. Error %d",dwResult);
  2512. TraceLeave("MibGetIpv6AddrPrefixEntry");
  2513. if(actionId is MIB_ACTION_GETNEXT)
  2514. {
  2515. return MIB_S_NO_MORE_ENTRIES;
  2516. }
  2517. return MIB_S_ENTRY_NOT_FOUND;
  2518. }
  2519. EnterReader(MIB_II_IPV6_ROUTE);
  2520. pOutput = (PIPV6_ADDR_PREFIX_GET)objectArray;
  2521. pRow = LocateIpv6AddrPrefixRow(actionId,
  2522. &(pOutput->ipv6IfIndex),
  2523. &(pOutput->ipv6AddrPrefix),
  2524. &(pOutput->ipv6AddrPrefixLength));
  2525. if(pRow is NULL)
  2526. {
  2527. ReleaseLock(MIB_II_IPV6_ROUTE);
  2528. TRACE0("Unable to locate IPv6 route row");
  2529. TraceLeave("MibGetIpv6AddrPrefixEntry");
  2530. if(actionId is MIB_ACTION_GETNEXT)
  2531. {
  2532. return MIB_S_NO_MORE_ENTRIES;
  2533. }
  2534. return MIB_S_ENTRY_NOT_FOUND;
  2535. }
  2536. ForceSetAsnInteger(&(pOutput->ipv6IfIndex), pRow->dwIfIndex);
  2537. ForceSetAsnOctetString(&(pOutput->ipv6AddrPrefix),
  2538. &pOutput->ipv6AddrPrefixInfo,
  2539. &pRow->ipPrefix,
  2540. sizeof(IN6_ADDR));
  2541. ForceSetAsnInteger(&(pOutput->ipv6AddrPrefixLength), pRow->dwPrefixLength);
  2542. SetAsnInteger(&(pOutput->ipv6AddrPrefixOnLinkFlag), pRow->dwOnLinkFlag);
  2543. SetAsnInteger(&(pOutput->ipv6AddrPrefixAutonomousFlag),
  2544. pRow->dwAutonomousFlag);
  2545. SetAsnUnsigned32(&(pOutput->ipv6AddrPrefixAdvPreferredLifetime),
  2546. pRow->dwPreferredLifetime);
  2547. SetAsnUnsigned32(&(pOutput->ipv6AddrPrefixAdvValidLifetime),
  2548. pRow->dwValidLifetime);
  2549. ReleaseLock(MIB_II_IPV6_ROUTE);
  2550. TraceLeave("MibGetIpv6AddrPrefixEntry");
  2551. return MIB_S_SUCCESS;
  2552. }
  2553. UINT
  2554. MibGetIpv6RouteEntry(
  2555. UINT actionId,
  2556. AsnAny *objectArray,
  2557. UINT *errorIndex
  2558. )
  2559. {
  2560. DWORD dwResult;
  2561. PIPV6_ROUTE_GET pOutput;
  2562. PMIB_IPV6_ROUTE pRow;
  2563. TraceEnter("MibGetIpv6RouteEntry");
  2564. dwResult = UpdateCache(MIB_II_IPV6_ROUTE);
  2565. if(dwResult isnot NO_ERROR)
  2566. {
  2567. TRACE1("Couldn't update IPv6 route table. Error %d",dwResult);
  2568. TraceLeave("MibGetIpv6RouteEntry");
  2569. if(actionId is MIB_ACTION_GETNEXT)
  2570. {
  2571. return MIB_S_NO_MORE_ENTRIES;
  2572. }
  2573. return MIB_S_ENTRY_NOT_FOUND;
  2574. }
  2575. EnterReader(MIB_II_IPV6_ROUTE);
  2576. pOutput = (PIPV6_ROUTE_GET)objectArray;
  2577. pRow = LocateIpv6RouteRow(actionId,
  2578. &(pOutput->ipv6RouteDest),
  2579. &(pOutput->ipv6RoutePfxLength),
  2580. &(pOutput->ipv6RouteIndex));
  2581. if(pRow is NULL)
  2582. {
  2583. ReleaseLock(MIB_II_IPV6_ROUTE);
  2584. TRACE0("Unable to locate IPv6 route row");
  2585. TraceLeave("MibGetIpv6RouteEntry");
  2586. if(actionId is MIB_ACTION_GETNEXT)
  2587. {
  2588. return MIB_S_NO_MORE_ENTRIES;
  2589. }
  2590. return MIB_S_ENTRY_NOT_FOUND;
  2591. }
  2592. ForceSetAsnOctetString(&(pOutput->ipv6RouteDest),
  2593. &pOutput->ipv6RouteDestInfo,
  2594. &pRow->ipPrefix,
  2595. sizeof(IN6_ADDR));
  2596. ForceSetAsnInteger(&(pOutput->ipv6RoutePfxLength), pRow->dwPrefixLength);
  2597. ForceSetAsnInteger(&(pOutput->ipv6RouteIndex), pRow->dwIndex);
  2598. SetAsnInteger(&(pOutput->ipv6RouteIfIndex), pRow->dwIfIndex);
  2599. SetAsnOctetString(&(pOutput->ipv6RouteNextHop),
  2600. &pOutput->ipv6RouteNextHopInfo,
  2601. &pRow->ipNextHop,
  2602. sizeof(IN6_ADDR));
  2603. SetAsnInteger(&(pOutput->ipv6RouteType), pRow->dwType);
  2604. SetAsnInteger(&(pOutput->ipv6RouteProtocol), pRow->dwProtocol);
  2605. SetAsnInteger(&(pOutput->ipv6RoutePolicy), pRow->dwPolicy);
  2606. SetAsnUnsigned32(&(pOutput->ipv6RouteAge), pRow->dwAge);
  2607. SetAsnUnsigned32(&(pOutput->ipv6RouteNextHopRDI), pRow->dwNextHopRDI);
  2608. SetAsnUnsigned32(&(pOutput->ipv6RouteMetric), pRow->dwMetric);
  2609. SetAsnUnsigned32(&(pOutput->ipv6RouteWeight), pRow->dwWeight);
  2610. SetToZeroOid(&(pOutput->ipv6RouteInfo));
  2611. SetAsnInteger(&(pOutput->ipv6RouteValid), pRow->dwValid);
  2612. ReleaseLock(MIB_II_IPV6_ROUTE);
  2613. TraceLeave("MibGetIpv6RouteEntry");
  2614. return MIB_S_SUCCESS;
  2615. }
  2616. UINT
  2617. MibGetIpv6NetToMediaEntry(
  2618. UINT actionId,
  2619. AsnAny *objectArray,
  2620. UINT *errorIndex
  2621. )
  2622. {
  2623. DWORD dwResult;
  2624. PIPV6_NET_TO_MEDIA_GET pOutput;
  2625. PMIB_IPV6_NET_TO_MEDIA pRow;
  2626. TraceEnter("MibGetIpv6NetToMediaEntry");
  2627. dwResult = UpdateCache(MIB_II_IPV6_NET_TO_MEDIA);
  2628. if(dwResult isnot NO_ERROR)
  2629. {
  2630. TRACE1("Couldn't update IPv6 neighbor cache. Error %d",dwResult);
  2631. TraceLeave("MibGetIpv6NetToMediaEntry");
  2632. if(actionId is MIB_ACTION_GETNEXT)
  2633. {
  2634. return MIB_S_NO_MORE_ENTRIES;
  2635. }
  2636. return MIB_S_ENTRY_NOT_FOUND;
  2637. }
  2638. EnterReader(MIB_II_IPV6_NET_TO_MEDIA);
  2639. pOutput = (PIPV6_NET_TO_MEDIA_GET)objectArray;
  2640. pRow = LocateIpv6NetToMediaRow(actionId,
  2641. &(pOutput->ipv6IfIndex),
  2642. &(pOutput->ipv6NetToMediaNetAddress));
  2643. if(pRow is NULL)
  2644. {
  2645. ReleaseLock(MIB_II_IPV6_NET_TO_MEDIA);
  2646. TRACE0("Unable to locate IPv6 neighbor row");
  2647. TraceLeave("MibGetIpv6NetToMediaEntry");
  2648. if(actionId is MIB_ACTION_GETNEXT)
  2649. {
  2650. return MIB_S_NO_MORE_ENTRIES;
  2651. }
  2652. return MIB_S_ENTRY_NOT_FOUND;
  2653. }
  2654. ForceSetAsnInteger(&(pOutput->ipv6IfIndex), pRow->dwIfIndex);
  2655. ForceSetAsnOctetString(&(pOutput->ipv6NetToMediaNetAddress),
  2656. &pOutput->ipv6NetToMediaNetAddressInfo,
  2657. &pRow->ipAddress,
  2658. sizeof(IN6_ADDR));
  2659. SetAsnOctetString(&(pOutput->ipv6NetToMediaPhysAddress),
  2660. pOutput->ipv6NetToMediaPhysAddressInfo,
  2661. pRow->bPhysAddress,
  2662. min(pRow->dwPhysAddressLen,MAX_PHYS_ADDR_LEN));
  2663. SetAsnInteger(&(pOutput->ipv6NetToMediaType), pRow->dwType);
  2664. SetAsnInteger(&(pOutput->ipv6NetToMediaState), pRow->dwState);
  2665. SetAsnTimeTicks(&(pOutput->ipv6NetToMediaLastUpdated), pRow->dwLastUpdated);
  2666. SetAsnInteger(&(pOutput->ipv6NetToMediaValid), pRow->dwValid);
  2667. ReleaseLock(MIB_II_IPV6_NET_TO_MEDIA);
  2668. TraceLeave("MibGetIpv6NetToMediaEntry");
  2669. return MIB_S_SUCCESS;
  2670. }