Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2965 lines
89 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. if(dwTTL > 255)
  306. {
  307. TRACE0("TTL must be less than 255");
  308. TraceLeave("MibSetIpGroup");
  309. return MIB_S_INVALID_PARAMETER;
  310. }
  311. if((dwForw isnot MIB_IP_FORWARDING) and
  312. (dwForw isnot MIB_IP_NOT_FORWARDING))
  313. {
  314. TRACE0("Forwarding value wrong");
  315. TraceLeave("MibSetIpGroup");
  316. return MIB_S_INVALID_PARAMETER;
  317. }
  318. pSetStats->dwForwarding = dwForw;
  319. pSetStats->dwDefaultTTL = dwTTL;
  320. TraceLeave("MibSetIpGroup");
  321. return MIB_S_SUCCESS;
  322. }
  323. case MIB_ACTION_SET:
  324. {
  325. TraceEnter("MibSetIpGroup - SET");
  326. dwResult = InternalSetIpStats(pInfo);
  327. #ifdef MIB_DEBUG
  328. if(dwResult isnot NO_ERROR)
  329. {
  330. TRACE1("Set returned error %d!!",dwResult);
  331. }
  332. #endif
  333. TraceLeave("MibSetIpGroup");
  334. return dwResult;
  335. }
  336. case MIB_ACTION_CLEANUP:
  337. {
  338. TraceEnter("MibSetIpGroup - CLEANUP");
  339. TraceLeave("MibSetIpGroup");
  340. return MIB_S_SUCCESS;
  341. }
  342. default:
  343. {
  344. TraceEnter("MibSetIpGroup - WRONG ACTION");
  345. TraceLeave("MibSetIpGroup");
  346. return MIB_S_INVALID_PARAMETER;
  347. }
  348. }
  349. }
  350. UINT
  351. MibGetIpAddressEntry(
  352. UINT actionId,
  353. AsnAny *objectArray,
  354. UINT *errorIndex
  355. )
  356. {
  357. PMIB_IPADDRROW pRpcIpAddr;
  358. DWORD dwResult;
  359. PIP_ADDRESS_ENTRY_GET pOutput;
  360. TraceEnter("MibGetIpAddressEntry");
  361. dwResult = UpdateCache(MIB_II_IPADDR);
  362. if(dwResult isnot NO_ERROR)
  363. {
  364. TRACE1("Couldnt update IP Addr cache. Error %d", dwResult);
  365. TraceLeave("MibGetIpAddressEntry");
  366. return dwResult;
  367. }
  368. pOutput = (PIP_ADDRESS_ENTRY_GET)objectArray;
  369. EnterReader(MIB_II_IPADDR);
  370. pRpcIpAddr = LocateIpAddrRow(actionId,
  371. &(pOutput->ipAdEntAddr));
  372. if(pRpcIpAddr is NULL)
  373. {
  374. ReleaseLock(MIB_II_IPADDR);
  375. TRACE2("Unable to locate IP Addr Row. Action is %d, Address is %x",
  376. actionId,
  377. GetAsnIPAddress(&(pOutput->ipAdEntAddr),0xffffffff));
  378. TraceLeave("MibGetIpAddressEntry");
  379. if(actionId is MIB_ACTION_GETNEXT)
  380. {
  381. return MIB_S_NO_MORE_ENTRIES;
  382. }
  383. return MIB_S_ENTRY_NOT_FOUND;
  384. }
  385. ForceSetAsnIPAddress(&(pOutput->ipAdEntAddr),
  386. &(pOutput->dwIpAdEntAddrInfo),
  387. pRpcIpAddr->dwAddr);
  388. SetAsnInteger(&(pOutput->ipAdEntIfIndex), pRpcIpAddr->dwIndex);
  389. SetAsnIPAddress(&(pOutput->ipAdEntNetMask),
  390. &(pOutput->dwIpAdEntNetMaskInfo),
  391. pRpcIpAddr->dwMask);
  392. SetAsnInteger(&(pOutput->ipAdEntBcastAddr), pRpcIpAddr->dwBCastAddr);
  393. SetAsnInteger(&(pOutput->ipAdEntReasmMaxSize), pRpcIpAddr->dwReasmSize);
  394. ReleaseLock(MIB_II_IPADDR);
  395. TraceLeave("MibGetIpAddressEntry");
  396. return MIB_S_SUCCESS;
  397. }
  398. UINT
  399. MibGetIpRouteEntry(
  400. UINT actionId,
  401. AsnAny *objectArray,
  402. UINT *errorIndex
  403. )
  404. {
  405. DWORD dwResult;
  406. PMIB_IPFORWARDROW pRpcIpForw;
  407. PIP_ROUTE_ENTRY_GET pOutput;
  408. TraceEnter("MibGetIpRouteEntry");
  409. dwResult = UpdateCache(FORWARD_MIB);
  410. if(dwResult isnot NO_ERROR)
  411. {
  412. TRACE1("Couldnt update IP Forward cache. Error %d", dwResult);
  413. TraceLeave("MibGetIpRouteEntry");
  414. return dwResult;
  415. }
  416. pOutput = (PIP_ROUTE_ENTRY_GET)objectArray;
  417. EnterReader(FORWARD_MIB);
  418. pRpcIpForw = LocateIpRouteRow(actionId,
  419. &(pOutput->ipRouteDest));
  420. if(pRpcIpForw is NULL)
  421. {
  422. ReleaseLock(FORWARD_MIB);
  423. TRACE2("Unable to locate IP ROUTE Row. Action is %d. Dest is %x",
  424. actionId,
  425. GetAsnIPAddress(&(pOutput->ipRouteDest),0xffffffff));
  426. TraceLeave("MibGetIpRouteEntry");
  427. if(actionId is MIB_ACTION_GETNEXT)
  428. {
  429. return MIB_S_NO_MORE_ENTRIES;
  430. }
  431. return MIB_S_ENTRY_NOT_FOUND;
  432. }
  433. ForceSetAsnIPAddress(&(pOutput->ipRouteDest),
  434. &(pOutput->dwIpRouteDestInfo),
  435. pRpcIpForw->dwForwardDest);
  436. SetAsnInteger(&(pOutput->ipRouteIfIndex), pRpcIpForw->dwForwardIfIndex);
  437. SetAsnInteger(&(pOutput->ipRouteMetric1), pRpcIpForw->dwForwardMetric1);
  438. SetAsnInteger(&(pOutput->ipRouteMetric2), pRpcIpForw->dwForwardMetric2);
  439. SetAsnInteger(&(pOutput->ipRouteMetric3), pRpcIpForw->dwForwardMetric3);
  440. SetAsnInteger(&(pOutput->ipRouteMetric4), pRpcIpForw->dwForwardMetric4);
  441. SetAsnIPAddress(&(pOutput->ipRouteNextHop),
  442. &(pOutput->dwIpRouteNextHopInfo),
  443. pRpcIpForw->dwForwardNextHop);
  444. SetAsnInteger(&(pOutput->ipRouteType), pRpcIpForw->dwForwardType);
  445. SetAsnInteger(&(pOutput->ipRouteProto), pRpcIpForw->dwForwardProto);
  446. SetAsnInteger(&(pOutput->ipRouteAge), pRpcIpForw->dwForwardAge);
  447. SetAsnIPAddress(&(pOutput->ipRouteMask),
  448. &(pOutput->dwIpRouteMaskInfo),
  449. pRpcIpForw->dwForwardMask);
  450. SetAsnInteger(&(pOutput->ipRouteMetric5), pRpcIpForw->dwForwardMetric5);
  451. SetToZeroOid(&(pOutput->ipRouteInfo));
  452. ReleaseLock(FORWARD_MIB);
  453. TraceLeave("MibGetIpRouteEntry");
  454. return MIB_S_SUCCESS;
  455. }
  456. UINT
  457. MibSetIpRouteEntry(
  458. UINT actionId,
  459. AsnAny *objectArray,
  460. UINT *errorIndex
  461. )
  462. {
  463. DWORD dwResult,dwType,dwIfIndex,dwNextHop;
  464. PMIB_IPFORWARDROW pRpcIpForw;
  465. PIP_ROUTE_ENTRY_SET pInput;
  466. PMIB_OPAQUE_INFO pInfo;
  467. PMIB_IPFORWARDROW pSetRow;
  468. pInput = (PIP_ROUTE_ENTRY_SET)objectArray;
  469. pInfo = (PMIB_OPAQUE_INFO)(pInput->rgdwSetBuffer);
  470. pSetRow = (PMIB_IPFORWARDROW)(pInfo->rgbyData);
  471. switch(actionId)
  472. {
  473. case MIB_ACTION_VALIDATE:
  474. {
  475. TraceEnter("MibSetIpRouteEntry - VALIDATE");
  476. ASSERT(!(IsAsnTypeNull(&(pInput->ipRouteDest))));
  477. pInput->bLocked = FALSE;
  478. dwResult = UpdateCache(FORWARD_MIB);
  479. if(dwResult isnot NO_ERROR)
  480. {
  481. TRACE1("Couldnt update IP Forward cache. Error %d", dwResult);
  482. TraceLeave("MibGetIpRouteEntry");
  483. return dwResult;
  484. }
  485. pInfo->dwId = IP_FORWARDROW;
  486. EnterWriter(FORWARD_MIB);
  487. pInput->bLocked = TRUE;
  488. pRpcIpForw = LocateIpRouteRow(GET_EXACT,
  489. &(pInput->ipRouteDest));
  490. if(pRpcIpForw is NULL)
  491. {
  492. //
  493. // So we are creating a row. We need the If index,
  494. // the mask, next hop and metric 1. We will try to
  495. // determine If index later if necessary.
  496. //
  497. if(IsAsnTypeNull(&(pInput->ipRouteMask)) or
  498. IsAsnTypeNull(&(pInput->ipRouteNextHop)) or
  499. IsAsnTypeNull(&(pInput->ipRouteMetric1)))
  500. {
  501. ReleaseLock(FORWARD_MIB);
  502. pInput->bLocked = FALSE;
  503. TRACE0("Not enough information to create a route");
  504. TraceLeave("MibSetIpRouteEntry");
  505. return MIB_S_INVALID_PARAMETER;
  506. }
  507. dwType = GetAsnInteger(&(pInput->ipRouteType),
  508. MIB_IPROUTE_TYPE_OTHER);
  509. if(dwType is MIB_IPROUTE_TYPE_INVALID)
  510. {
  511. //
  512. // We couldnt be creating and deleting a row at the
  513. // same time
  514. //
  515. ReleaseLock(FORWARD_MIB);
  516. pInput->bLocked = FALSE;
  517. TRACE0("Wrong type");
  518. TraceLeave("MibSetIpRouteEntry");
  519. return MIB_S_INVALID_PARAMETER;
  520. }
  521. dwIfIndex = GetAsnInteger(&(pInput->ipRouteIfIndex),0);
  522. dwNextHop = GetAsnIPAddress(&(pInput->ipRouteNextHop),0x00000000);
  523. if(dwIfIndex is 0)
  524. {
  525. //
  526. // Attempt to determine the correct ifIndex
  527. //
  528. dwIfIndex = GetIfIndexFromAddr(dwNextHop);
  529. if(dwIfIndex is INVALID_IFINDEX)
  530. {
  531. //
  532. // We couldnt determine the correct ifIndex
  533. //
  534. ReleaseLock(FORWARD_MIB);
  535. pInput->bLocked = FALSE;
  536. TRACE0("Could not determine ifIndex");
  537. TraceLeave("MibSetIpRouteEntry");
  538. return MIB_S_INVALID_PARAMETER;
  539. }
  540. }
  541. pInput->raAction = CREATE_ROW;
  542. pSetRow->dwForwardType = dwType;
  543. pSetRow->dwForwardIfIndex = dwIfIndex;
  544. pSetRow->dwForwardNextHop = dwNextHop;
  545. pSetRow->dwForwardDest =
  546. GetAsnIPAddress(&(pInput->ipRouteDest),0xffffffff);
  547. pSetRow->dwForwardMask =
  548. GetAsnIPAddress(&(pInput->ipRouteMask),0x00000000);
  549. pSetRow->dwForwardPolicy = 0;
  550. pSetRow->dwForwardProto =
  551. GetAsnInteger(&(pInput->ipRouteProto),MIB_IPPROTO_NETMGMT);
  552. //
  553. // We default to an age of INFINITE
  554. //
  555. pSetRow->dwForwardAge =
  556. GetAsnInteger(&(pInput->ipRouteAge),INFINITE);
  557. pSetRow->dwForwardNextHopAS = 0;
  558. pSetRow->dwForwardMetric1 =
  559. GetAsnInteger(&(pInput->ipRouteMetric1),0);
  560. pSetRow->dwForwardMetric2 =
  561. GetAsnInteger(&(pInput->ipRouteMetric2),-1);
  562. pSetRow->dwForwardMetric3 =
  563. GetAsnInteger(&(pInput->ipRouteMetric3),-1);
  564. pSetRow->dwForwardMetric4 =
  565. GetAsnInteger(&(pInput->ipRouteMetric4),-1);
  566. pSetRow->dwForwardMetric5 =
  567. GetAsnInteger(&(pInput->ipRouteMetric5),-1);
  568. TraceLeave("MibSetIpRouteEntry");
  569. return MIB_S_SUCCESS;
  570. }
  571. else
  572. {
  573. //
  574. // Ok so we are only changing some stuff in the route
  575. //
  576. dwType = GetAsnInteger(&(pInput->ipRouteType),
  577. pRpcIpForw->dwForwardType);
  578. if(dwType is MIB_IPROUTE_TYPE_INVALID)
  579. {
  580. //
  581. // Deleting a row
  582. //
  583. pInput->raAction = DELETE_ROW;
  584. *pSetRow = *pRpcIpForw;
  585. TraceLeave("MibSetIpRouteEntry");
  586. return MIB_S_SUCCESS;
  587. }
  588. pInput->raAction = SET_ROW;
  589. pSetRow->dwForwardDest =
  590. GetAsnIPAddress(&(pInput->ipRouteDest),
  591. pRpcIpForw->dwForwardDest);
  592. pSetRow->dwForwardMask =
  593. GetAsnIPAddress(&(pInput->ipRouteMask),
  594. pRpcIpForw->dwForwardMask);
  595. pSetRow->dwForwardPolicy = 0;
  596. pSetRow->dwForwardNextHop =
  597. GetAsnIPAddress(&(pInput->ipRouteNextHop),
  598. pRpcIpForw->dwForwardNextHop);
  599. pSetRow->dwForwardIfIndex =
  600. GetAsnInteger(&(pInput->ipRouteIfIndex),
  601. pRpcIpForw->dwForwardIfIndex);
  602. //
  603. // The type gets set by the router manager. But incase
  604. // we are writing to the stack we need some kind of valid type
  605. //
  606. pSetRow->dwForwardType =
  607. GetAsnInteger(&(pInput->ipRouteType),
  608. pRpcIpForw->dwForwardType);
  609. pSetRow->dwForwardProto =
  610. GetAsnInteger(&(pInput->ipRouteProto),
  611. pRpcIpForw->dwForwardProto);
  612. //
  613. // We default to an age of 10 seconds
  614. //
  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. ForceSetAsnInteger(&(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 10 seconds
  1816. //
  1817. pSetRow->dwForwardAge =
  1818. GetAsnInteger(&(pInput->ipForwardAge),10);
  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. }