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.

1251 lines
33 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. File contains the following functions
  6. LocateIfRow
  7. LocateIpAddrRow
  8. LocateIpForwardRow
  9. LocateIpNetRow
  10. LocateUdpRow
  11. LocateUdp6Row
  12. LocateTcpRow
  13. LocateTcp6Row
  14. LocateIpv6IfRow
  15. LocateIpv6AddrRow
  16. LocateIpv6NetToMediaRow
  17. LocateIpv6RouteRow
  18. LocateIpv6AddrPrefixRow
  19. LocateInetIcmpRow
  20. LocateInetIcmpMsgRow
  21. The LocateXXXRow Functions are passed a variable sized array of indices, a count of
  22. the number of indices passed and the type of query for which the location is being
  23. done (GET_FIRST, NEXT or GET/SET/CREATE/DELETE - there are only three type of
  24. behaviours of the locators). They fill in the index of the corresponding row and return
  25. ERROR_NO_DATA, ERROR_INVALID_INDEX, NO_ERROR or ERROR_NO_MORE_ITEMS
  26. The general search algorithm is this;
  27. If the table is empty, return ERROR_NO_DATA
  28. else
  29. If the query is a GET_FIRST
  30. Return the first row
  31. else
  32. Build the index as follows:
  33. Set the Index to all 0s
  34. From the number of indices passed figure out how much of the index you can build
  35. keeping the rest 0. If the query is a GET, SET, CREATE_ENTRY or DELETE_ENTRY
  36. then the complete index must be given. This check is, however, supposed to be done
  37. at the agent.
  38. If the full index has not been given, the index is deemed to be modified (Again
  39. this can only happen in the NEXT case).
  40. After this a search is done. We try for an exact match with the index. For all
  41. queries other than NEXT there is no problem. For NEXT there are two cases:
  42. If the complete index was given and and you get an exact match, then you
  43. return the next entry. If you dont get an exact match you return the next
  44. higher entry
  45. If an incomplete index was given and you modified it by padding 0s, and if
  46. an exact match is found, then you return the matching entry (Of course if an
  47. exact match is not found you again return the next higher entry)
  48. Revision History:
  49. Amritansh Raghav 6/8/95 Created
  50. --*/
  51. #include "allinc.h"
  52. PMIB_IFROW
  53. LocateIfRow(
  54. DWORD dwQueryType,
  55. AsnAny *paaIfIndex
  56. )
  57. {
  58. DWORD i;
  59. DWORD dwIndex;
  60. //
  61. // If there is no index the type is ASN_NULL. This causes the macro to return the
  62. // default value (0 in this case)
  63. //
  64. dwIndex = GetAsnInteger(paaIfIndex, 0);
  65. TraceEnter("LocateIfRow");
  66. if (g_Cache.pRpcIfTable->dwNumEntries is 0)
  67. {
  68. TraceLeave("LocateIfRow");
  69. return NULL;
  70. }
  71. if (dwQueryType is GET_FIRST)
  72. {
  73. TraceLeave("LocateIfRow");
  74. return &(g_Cache.pRpcIfTable->table[0]);
  75. }
  76. for (i = 0; i < g_Cache.pRpcIfTable->dwNumEntries; i++)
  77. {
  78. if ((g_Cache.pRpcIfTable->table[i].dwIndex is dwIndex) and dwQueryType is GET_EXACT)
  79. {
  80. TraceLeave("LocateIfRow");
  81. return &(g_Cache.pRpcIfTable->table[i]);
  82. }
  83. if (g_Cache.pRpcIfTable->table[i].dwIndex > dwIndex)
  84. {
  85. if (dwQueryType is GET_NEXT)
  86. {
  87. TraceLeave("LocateIfRow");
  88. return &(g_Cache.pRpcIfTable->table[i]);
  89. }
  90. else
  91. {
  92. TraceLeave("LocateIfRow");
  93. return NULL;
  94. }
  95. }
  96. }
  97. TraceLeave("LocateIfRow");
  98. return NULL;
  99. }
  100. PMIB_IPV6_IF
  101. LocateIpv6IfRow(
  102. DWORD dwQueryType,
  103. AsnAny *paaIfIndex
  104. )
  105. {
  106. DWORD i;
  107. DWORD dwIndex;
  108. //
  109. // If there is no index the type is ASN_NULL. This causes the macro to
  110. // return the default value (0 in this case)
  111. //
  112. dwIndex = GetAsnInteger(paaIfIndex, 0);
  113. TraceEnter("LocateIpv6IfRow");
  114. if (g_Cache.pRpcIpv6IfTable.dwNumEntries is 0)
  115. {
  116. TraceLeave("LocateIpv6IfRow");
  117. return NULL;
  118. }
  119. if (dwQueryType is GET_FIRST)
  120. {
  121. TraceLeave("LocateIpv6IfRow");
  122. return &(g_Cache.pRpcIpv6IfTable.table[0]);
  123. }
  124. for (i = 0; i < g_Cache.pRpcIpv6IfTable.dwNumEntries; i++)
  125. {
  126. if ((g_Cache.pRpcIpv6IfTable.table[i].dwIndex is dwIndex) and dwQueryType is GET_EXACT)
  127. {
  128. TraceLeave("LocateIpv6IfRow");
  129. return &(g_Cache.pRpcIpv6IfTable.table[i]);
  130. }
  131. if (g_Cache.pRpcIpv6IfTable.table[i].dwIndex > dwIndex)
  132. {
  133. if (dwQueryType is GET_NEXT)
  134. {
  135. TraceLeave("LocateIpv6IfRow");
  136. return &(g_Cache.pRpcIpv6IfTable.table[i]);
  137. }
  138. else
  139. {
  140. TraceLeave("LocateIpv6IfRow");
  141. return NULL;
  142. }
  143. }
  144. }
  145. TraceLeave("LocateIpv6IfRow");
  146. return NULL;
  147. }
  148. PMIB_IPV6_ADDR
  149. LocateIpv6AddrRow(
  150. DWORD dwQueryType,
  151. AsnAny *paaIfIndex,
  152. AsnAny *paaAddress
  153. )
  154. {
  155. LONG lCompare;
  156. DWORD i;
  157. BOOL bNext, bModified;
  158. IN6_ADDR ipAddress;
  159. DWORD dwIfIndex;
  160. TraceEnter("LocateIpv6AddrRow");
  161. if (g_Cache.pRpcIpv6AddrTable.dwNumEntries is 0)
  162. {
  163. TraceLeave("LocateIpv6AddrRow");
  164. return NULL;
  165. }
  166. if (dwQueryType is GET_FIRST)
  167. {
  168. TraceLeave("LocateIpv6AddrRow");
  169. return &(g_Cache.pRpcIpv6AddrTable.table[0]);
  170. }
  171. ZeroMemory(&ipAddress, sizeof(ipAddress));
  172. dwIfIndex = GetAsnInteger(paaIfIndex, -1);
  173. bModified = FALSE;
  174. if (IsAsnOctetStringTypeNull(paaAddress) ||
  175. (paaAddress->asnValue.string.length < sizeof(ipAddress)))
  176. {
  177. bModified = TRUE;
  178. }
  179. else
  180. {
  181. GetAsnOctetString(&ipAddress, paaAddress);
  182. }
  183. bNext = (dwQueryType is GET_NEXT) and (bModified is FALSE);
  184. for (i = 0; i < g_Cache.pRpcIpv6AddrTable.dwNumEntries; i++)
  185. {
  186. Cmp(dwIfIndex, g_Cache.pRpcIpv6AddrTable.table[i].dwIfIndex, lCompare);
  187. if (lCompare is 0) {
  188. lCompare = memcmp(&ipAddress,
  189. &g_Cache.pRpcIpv6AddrTable.table[i].ipAddress,
  190. sizeof(ipAddress));
  191. }
  192. if ((lCompare is 0) and !bNext)
  193. {
  194. TraceLeave("LocateIpv6AddrRow");
  195. return &(g_Cache.pRpcIpv6AddrTable.table[i]);
  196. }
  197. if (lCompare < 0)
  198. {
  199. if (dwQueryType is GET_NEXT)
  200. {
  201. TraceLeave("LocateIpv6AddrRow");
  202. return &(g_Cache.pRpcIpv6AddrTable.table[i]);
  203. }
  204. else
  205. {
  206. TraceLeave("LocateIpv6AddrRow");
  207. return NULL;
  208. }
  209. }
  210. }
  211. TraceLeave("LocateIpv6AddrRow");
  212. return NULL;
  213. }
  214. PMIB_IPV6_NET_TO_MEDIA
  215. LocateIpv6NetToMediaRow(
  216. DWORD dwQueryType,
  217. AsnAny *paaIfIndex,
  218. AsnAny *paaAddress
  219. )
  220. {
  221. LONG lCompare;
  222. DWORD i, dwIfIndex;
  223. BOOL bNext, bModified;
  224. IN6_ADDR ipAddress;
  225. TraceEnter("LocateIpv6NetToMediaRow");
  226. if (g_Cache.pRpcIpv6NetToMediaTable.dwNumEntries is 0)
  227. {
  228. TraceLeave("LocateIpv6NetToMediaRow");
  229. return NULL;
  230. }
  231. if (dwQueryType is GET_FIRST)
  232. {
  233. TraceLeave("LocateIpv6NetToMediaRow");
  234. return &(g_Cache.pRpcIpv6NetToMediaTable.table[0]);
  235. }
  236. ZeroMemory(&ipAddress, sizeof(ipAddress));
  237. dwIfIndex = GetAsnInteger(paaIfIndex, -1);
  238. bModified = FALSE;
  239. if (IsAsnOctetStringTypeNull(paaAddress) ||
  240. (paaAddress->asnValue.string.length < sizeof(ipAddress)))
  241. {
  242. bModified = TRUE;
  243. }
  244. else
  245. {
  246. GetAsnOctetString(&ipAddress, paaAddress);
  247. }
  248. bNext = (dwQueryType is GET_NEXT) and (bModified is FALSE);
  249. for (i = 0; i < g_Cache.pRpcIpv6NetToMediaTable.dwNumEntries; i++)
  250. {
  251. Cmp(dwIfIndex, g_Cache.pRpcIpv6NetToMediaTable.table[i].dwIfIndex,
  252. lCompare);
  253. if (lCompare is 0) {
  254. lCompare = memcmp(&ipAddress,
  255. &g_Cache.pRpcIpv6NetToMediaTable.table[i].ipAddress,
  256. sizeof(ipAddress));
  257. }
  258. if ((lCompare is 0) and !bNext)
  259. {
  260. TraceLeave("LocateIpv6NetToMediaRow");
  261. return &(g_Cache.pRpcIpv6NetToMediaTable.table[i]);
  262. }
  263. if (lCompare < 0)
  264. {
  265. if (dwQueryType is GET_NEXT)
  266. {
  267. TraceLeave("LocateIpv6NetToMediaRow");
  268. return &(g_Cache.pRpcIpv6NetToMediaTable.table[i]);
  269. }
  270. else
  271. {
  272. TraceLeave("LocateIpv6NetToMediaRow");
  273. return NULL;
  274. }
  275. }
  276. }
  277. TraceLeave("LocateIpv6NetToMediaRow");
  278. return NULL;
  279. }
  280. PMIB_IPV6_ROUTE
  281. LocateIpv6RouteRow(
  282. DWORD dwQueryType,
  283. AsnAny *paaPrefix,
  284. AsnAny *paaPrefixLength,
  285. AsnAny *paaIndex
  286. )
  287. {
  288. LONG lCompare;
  289. DWORD i, dwPrefixLength, dwIndex;
  290. BOOL bNext, bModified;
  291. IN6_ADDR ipPrefix;
  292. TraceEnter("LocateIpv6RouteRow");
  293. if (g_Cache.pRpcIpv6RouteTable.dwNumEntries is 0)
  294. {
  295. TraceLeave("LocateIpv6RouteRow");
  296. return NULL;
  297. }
  298. if (dwQueryType is GET_FIRST)
  299. {
  300. TraceLeave("LocateIpv6RouteRow");
  301. return &(g_Cache.pRpcIpv6RouteTable.table[0]);
  302. }
  303. ZeroMemory(&ipPrefix, sizeof(ipPrefix));
  304. dwPrefixLength = GetAsnInteger(paaPrefixLength, -1);
  305. dwIndex = GetAsnInteger(paaIndex, -1);
  306. bModified = FALSE;
  307. if (IsAsnOctetStringTypeNull(paaPrefix) ||
  308. (paaPrefix->asnValue.string.length < sizeof(ipPrefix)))
  309. {
  310. bModified = TRUE;
  311. }
  312. else
  313. {
  314. GetAsnOctetString(&ipPrefix, paaPrefix);
  315. }
  316. bNext = (dwQueryType is GET_NEXT) and (bModified is FALSE);
  317. for (i = 0; i < g_Cache.pRpcIpv6RouteTable.dwNumEntries; i++)
  318. {
  319. lCompare = memcmp(&ipPrefix,
  320. &g_Cache.pRpcIpv6RouteTable.table[i].ipPrefix,
  321. sizeof(ipPrefix));
  322. if (lCompare is 0) {
  323. if (Cmp(dwPrefixLength, g_Cache.pRpcIpv6RouteTable.table[i].dwPrefixLength, lCompare) is 0) {
  324. Cmp(dwIndex, g_Cache.pRpcIpv6RouteTable.table[i].dwIndex, lCompare);
  325. }
  326. }
  327. if ((lCompare is 0) and !bNext)
  328. {
  329. TraceLeave("LocateIpv6RouteRow");
  330. return &(g_Cache.pRpcIpv6RouteTable.table[i]);
  331. }
  332. if (lCompare < 0)
  333. {
  334. if (dwQueryType is GET_NEXT)
  335. {
  336. TraceLeave("LocateIpv6RouteRow");
  337. return &(g_Cache.pRpcIpv6RouteTable.table[i]);
  338. }
  339. else
  340. {
  341. TraceLeave("LocateIpv6RouteRow");
  342. return NULL;
  343. }
  344. }
  345. }
  346. TraceLeave("LocateIpv6RouteRow");
  347. return NULL;
  348. }
  349. PMIB_IPV6_ADDR_PREFIX
  350. LocateIpv6AddrPrefixRow(
  351. DWORD dwQueryType,
  352. AsnAny *paaIfIndex,
  353. AsnAny *paaPrefix,
  354. AsnAny *paaPrefixLength
  355. )
  356. {
  357. LONG lCompare;
  358. DWORD i, dwPrefixLength, dwIfIndex;
  359. BOOL bNext, bModified;
  360. IN6_ADDR ipPrefix;
  361. TraceEnter("LocateIpv6AddrPrefixRow");
  362. if (g_Cache.pRpcIpv6AddrPrefixTable.dwNumEntries is 0)
  363. {
  364. TraceLeave("LocateIpv6AddrPrefixRow");
  365. return NULL;
  366. }
  367. if (dwQueryType is GET_FIRST)
  368. {
  369. TraceLeave("LocateIpv6AddrPrefixRow");
  370. return &(g_Cache.pRpcIpv6AddrPrefixTable.table[0]);
  371. }
  372. dwIfIndex = GetAsnInteger(paaIfIndex, -1);
  373. ZeroMemory(&ipPrefix, sizeof(ipPrefix));
  374. dwPrefixLength = GetAsnInteger(paaPrefixLength, -1);
  375. bModified = FALSE;
  376. if (IsAsnOctetStringTypeNull(paaPrefix) ||
  377. (paaPrefix->asnValue.string.length < sizeof(ipPrefix)))
  378. {
  379. bModified = TRUE;
  380. }
  381. else
  382. {
  383. GetAsnOctetString(&ipPrefix, paaPrefix);
  384. }
  385. bNext = (dwQueryType is GET_NEXT) and (bModified is FALSE);
  386. for (i = 0; i < g_Cache.pRpcIpv6AddrPrefixTable.dwNumEntries; i++)
  387. {
  388. if (Cmp(dwIfIndex, g_Cache.pRpcIpv6AddrPrefixTable.table[i].dwIfIndex,
  389. lCompare) is 0)
  390. {
  391. lCompare = memcmp(&ipPrefix,
  392. &g_Cache.pRpcIpv6AddrPrefixTable.table[i].ipPrefix,
  393. sizeof(ipPrefix));
  394. if (lCompare is 0)
  395. {
  396. Cmp(dwPrefixLength,
  397. g_Cache.pRpcIpv6AddrPrefixTable.table[i].dwPrefixLength,
  398. lCompare);
  399. }
  400. }
  401. if ((lCompare is 0) and !bNext)
  402. {
  403. TraceLeave("LocateIpv6AddrPrefixRow");
  404. return &(g_Cache.pRpcIpv6AddrPrefixTable.table[i]);
  405. }
  406. if (lCompare < 0)
  407. {
  408. if (dwQueryType is GET_NEXT)
  409. {
  410. TraceLeave("LocateIpv6AddrPrefixRow");
  411. return &(g_Cache.pRpcIpv6AddrPrefixTable.table[i]);
  412. }
  413. else
  414. {
  415. TraceLeave("LocateIpv6AddrPrefixRow");
  416. return NULL;
  417. }
  418. }
  419. }
  420. TraceLeave("LocateIpv6AddrPrefixRow");
  421. return NULL;
  422. }
  423. PMIB_INET_ICMP
  424. LocateInetIcmpRow(
  425. DWORD dwQueryType,
  426. AsnAny *paaAFType,
  427. AsnAny *paaIfIndex
  428. )
  429. {
  430. DWORD i;
  431. DWORD dwAFType, dwIfIndex;
  432. TraceEnter("LocateInetIcmpRow");
  433. if (g_Cache.pRpcInetIcmpTable.dwNumEntries is 0)
  434. {
  435. TraceLeave("LocateInetIcmpRow");
  436. return NULL;
  437. }
  438. if (dwQueryType is GET_FIRST)
  439. {
  440. TraceLeave("LocateInetIcmpRow");
  441. return &(g_Cache.pRpcInetIcmpTable.table[0]);
  442. }
  443. //
  444. // If there is no index the type is ASN_NULL. This causes the macro to
  445. // return the default value.
  446. //
  447. dwAFType = GetAsnInteger(paaAFType, 0);
  448. dwIfIndex = GetAsnInteger(paaIfIndex, 0);
  449. for (i = 0; i < g_Cache.pRpcInetIcmpTable.dwNumEntries; i++)
  450. {
  451. if ((g_Cache.pRpcInetIcmpTable.table[i].dwIfIndex is dwIfIndex) and
  452. (g_Cache.pRpcInetIcmpTable.table[i].dwAFType is dwAFType) and
  453. (dwQueryType is GET_EXACT))
  454. {
  455. TraceLeave("LocateInetIcmpRow");
  456. return &(g_Cache.pRpcInetIcmpTable.table[i]);
  457. }
  458. if ((g_Cache.pRpcInetIcmpTable.table[i].dwAFType > dwAFType) or
  459. ((g_Cache.pRpcInetIcmpTable.table[i].dwAFType == dwAFType) and
  460. (g_Cache.pRpcInetIcmpTable.table[i].dwIfIndex > dwIfIndex)))
  461. {
  462. if (dwQueryType is GET_NEXT)
  463. {
  464. TraceLeave("LocateInetIcmpRow");
  465. return &(g_Cache.pRpcInetIcmpTable.table[i]);
  466. }
  467. else
  468. {
  469. TraceLeave("LocateInetIcmpRow");
  470. return NULL;
  471. }
  472. }
  473. }
  474. TraceLeave("LocateInetIcmpRow");
  475. return NULL;
  476. }
  477. PMIB_INET_ICMP_MSG
  478. LocateInetIcmpMsgRow(
  479. DWORD dwQueryType,
  480. AsnAny *paaAFType,
  481. AsnAny *paaIfIndex,
  482. AsnAny *paaType,
  483. AsnAny *paaCode
  484. )
  485. {
  486. DWORD i;
  487. DWORD dwAFType, dwIfIndex, dwType, dwCode;
  488. LONG lCompare;
  489. TraceEnter("LocateInetIcmpMsgRow");
  490. if (g_Cache.pRpcInetIcmpMsgTable.dwNumEntries is 0)
  491. {
  492. TraceLeave("LocateInetIcmpMsgRow");
  493. return NULL;
  494. }
  495. if (dwQueryType is GET_FIRST)
  496. {
  497. TraceLeave("LocateInetIcmpMsgRow");
  498. return &(g_Cache.pRpcInetIcmpMsgTable.table[0]);
  499. }
  500. //
  501. // If there is no index the type is ASN_NULL. This causes the macro to
  502. // return the default value.
  503. //
  504. dwAFType = GetAsnInteger(paaAFType, 0);
  505. dwIfIndex = GetAsnInteger(paaIfIndex, 0);
  506. dwType = GetAsnInteger(paaType, 0);
  507. dwCode = GetAsnInteger(paaCode, 0);
  508. for (i = 0; i < g_Cache.pRpcInetIcmpMsgTable.dwNumEntries; i++)
  509. {
  510. Cmp(dwAFType, g_Cache.pRpcInetIcmpMsgTable.table[i].dwAFType, lCompare);
  511. if (lCompare is 0)
  512. {
  513. Cmp(dwIfIndex, g_Cache.pRpcInetIcmpMsgTable.table[i].dwIfIndex,
  514. lCompare);
  515. }
  516. if (lCompare is 0)
  517. {
  518. Cmp(dwType, g_Cache.pRpcInetIcmpMsgTable.table[i].dwType, lCompare);
  519. }
  520. if (lCompare is 0)
  521. {
  522. Cmp(dwCode, g_Cache.pRpcInetIcmpMsgTable.table[i].dwCode, lCompare);
  523. }
  524. if ((lCompare is 0) and (dwQueryType is GET_EXACT))
  525. {
  526. TraceLeave("LocateInetIcmpMsgRow");
  527. return &(g_Cache.pRpcInetIcmpMsgTable.table[i]);
  528. }
  529. if (lCompare < 0)
  530. {
  531. if (dwQueryType is GET_NEXT)
  532. {
  533. TraceLeave("LocateInetIcmpMsgRow");
  534. return &(g_Cache.pRpcInetIcmpMsgTable.table[i]);
  535. }
  536. else
  537. {
  538. TraceLeave("LocateInetIcmpMsgRow");
  539. return NULL;
  540. }
  541. }
  542. }
  543. TraceLeave("LocateInetIcmpMsgRow");
  544. return NULL;
  545. }
  546. PMIB_IPADDRROW
  547. LocateIpAddrRow(
  548. DWORD dwQueryType,
  549. AsnAny *paaIpAddr
  550. )
  551. {
  552. LONG lCompare;
  553. DWORD i, dwAddr;
  554. BOOL bNext, bModified;
  555. TraceEnter("LocateIpAddrRow");
  556. if (g_Cache.pRpcIpAddrTable->dwNumEntries is 0)
  557. {
  558. TraceLeave("LocateIpAddrRow");
  559. return NULL;
  560. }
  561. if (dwQueryType is GET_FIRST)
  562. {
  563. TraceLeave("LocateIpAddrRow");
  564. return &(g_Cache.pRpcIpAddrTable->table[0]);
  565. }
  566. dwAddr = GetAsnIPAddress(paaIpAddr, 0x00000000);
  567. bModified = FALSE;
  568. if (IsAsnIPAddressTypeNull(paaIpAddr))
  569. {
  570. bModified = TRUE;
  571. }
  572. bNext = (dwQueryType is GET_NEXT) and (bModified is FALSE);
  573. for (i = 0; i < g_Cache.pRpcIpAddrTable->dwNumEntries; i++)
  574. {
  575. if ((InetCmp(dwAddr, g_Cache.pRpcIpAddrTable->table[i].dwAddr, lCompare) is 0) and !bNext)
  576. {
  577. TraceLeave("LocateIpAddrRow");
  578. return &(g_Cache.pRpcIpAddrTable->table[i]);
  579. }
  580. if (lCompare < 0)
  581. {
  582. if (dwQueryType is GET_NEXT)
  583. {
  584. TraceLeave("LocateIpAddrRow");
  585. return &(g_Cache.pRpcIpAddrTable->table[i]);
  586. }
  587. else
  588. {
  589. TraceLeave("LocateIpAddrRow");
  590. return NULL;
  591. }
  592. }
  593. }
  594. TraceLeave("LocateIpAddrRow");
  595. return NULL;
  596. }
  597. PMIB_IPFORWARDROW
  598. LocateIpRouteRow(
  599. DWORD dwQueryType,
  600. AsnAny *paaIpDest
  601. )
  602. {
  603. DWORD dwDest;
  604. LONG lCompare;
  605. DWORD i;
  606. BOOL bNext, bModified;
  607. TraceEnter("LocateIpRouteRow");
  608. if (g_Cache.pRpcIpForwardTable->dwNumEntries is 0)
  609. {
  610. TraceLeave("LocateIpRouteRow");
  611. return NULL;
  612. }
  613. if (dwQueryType is GET_FIRST)
  614. {
  615. TraceLeave("LocateIpRouteRow");
  616. return &(g_Cache.pRpcIpForwardTable->table[0]);
  617. }
  618. dwDest = GetAsnIPAddress(paaIpDest, 0x00000000);
  619. bModified = FALSE;
  620. if (IsAsnIPAddressTypeNull(paaIpDest))
  621. {
  622. bModified = TRUE;
  623. }
  624. bNext = (dwQueryType is GET_NEXT) and (bModified is FALSE);
  625. for (i = 0; i < g_Cache.pRpcIpForwardTable->dwNumEntries; i++)
  626. {
  627. if ((InetCmp(dwDest, g_Cache.pRpcIpForwardTable->table[i].dwForwardDest, lCompare) is 0) and !bNext)
  628. {
  629. TraceLeave("LocateIpRouteRow");
  630. return &(g_Cache.pRpcIpForwardTable->table[i]);
  631. }
  632. if (lCompare < 0)
  633. {
  634. if (dwQueryType is GET_NEXT)
  635. {
  636. TraceLeave("LocateIpRouteRow");
  637. return &(g_Cache.pRpcIpForwardTable->table[i]);
  638. }
  639. else
  640. {
  641. TraceLeave("LocateIpRouteRow");
  642. return NULL;
  643. }
  644. }
  645. }
  646. TraceLeave("LocateIpRouteRow");
  647. return NULL;
  648. }
  649. PMIB_IPFORWARDROW
  650. LocateIpForwardRow(
  651. DWORD dwQueryType,
  652. AsnAny *paaDest,
  653. AsnAny *paaProto,
  654. AsnAny *paaPolicy,
  655. AsnAny *paaNextHop
  656. )
  657. {
  658. DWORD dwIpForwardIndex[4];
  659. LONG lCompare;
  660. DWORD i;
  661. BOOL bNext, bModified;
  662. TraceEnter("LocateIpForwardRow");
  663. if (g_Cache.pRpcIpForwardTable->dwNumEntries is 0)
  664. {
  665. TraceLeave("LocateIpForwardRow");
  666. return NULL;
  667. }
  668. if (dwQueryType is GET_FIRST)
  669. {
  670. TraceLeave("LocateIpForwardRow");
  671. return &(g_Cache.pRpcIpForwardTable->table[0]);
  672. }
  673. dwIpForwardIndex[0] = GetAsnIPAddress(paaDest, 0x00000000);
  674. dwIpForwardIndex[1] = GetAsnInteger(paaProto, 0);
  675. dwIpForwardIndex[2] = GetAsnInteger(paaPolicy, 0);
  676. dwIpForwardIndex[3] = GetAsnIPAddress(paaNextHop, 0x00000000);
  677. bModified = FALSE;
  678. if (IsAsnIPAddressTypeNull(paaDest) or
  679. IsAsnTypeNull(paaProto) or
  680. IsAsnTypeNull(paaPolicy) or
  681. IsAsnIPAddressTypeNull(paaNextHop))
  682. {
  683. bModified = TRUE;
  684. }
  685. bNext = (dwQueryType is GET_NEXT) and (bModified is FALSE);
  686. for (i = 0; i < g_Cache.pRpcIpForwardTable->dwNumEntries; i++)
  687. {
  688. lCompare = IpForwardCmp(dwIpForwardIndex[0],
  689. dwIpForwardIndex[1],
  690. dwIpForwardIndex[2],
  691. dwIpForwardIndex[3],
  692. g_Cache.pRpcIpForwardTable->table[i].dwForwardDest,
  693. g_Cache.pRpcIpForwardTable->table[i].dwForwardProto,
  694. g_Cache.pRpcIpForwardTable->table[i].dwForwardPolicy,
  695. g_Cache.pRpcIpForwardTable->table[i].dwForwardNextHop);
  696. if ((lCompare is 0) and !bNext)
  697. {
  698. TraceLeave("LocateIpForwardRow");
  699. return &(g_Cache.pRpcIpForwardTable->table[i]);
  700. }
  701. if (lCompare < 0)
  702. {
  703. if (dwQueryType is GET_NEXT)
  704. {
  705. TraceLeave("LocateIpForwardRow");
  706. return &(g_Cache.pRpcIpForwardTable->table[i]);
  707. }
  708. else
  709. {
  710. TraceLeave("LocateIpForwardRow");
  711. return NULL;
  712. }
  713. }
  714. }
  715. TraceLeave("LocateIpForwardRow");
  716. return NULL;
  717. }
  718. PMIB_IPNETROW
  719. LocateIpNetRow(
  720. DWORD dwQueryType,
  721. AsnAny *paaIndex,
  722. AsnAny *paaAddr
  723. )
  724. {
  725. DWORD i;
  726. LONG lCompare;
  727. DWORD dwIpNetIfIndex, dwIpNetIpAddr;
  728. BOOL bNext, bModified;
  729. TraceEnter("LocateIfNetRow");
  730. if (g_Cache.pRpcIpNetTable->dwNumEntries is 0)
  731. {
  732. TraceLeave("LocateIpNetRow");
  733. return NULL;
  734. }
  735. if (dwQueryType is GET_FIRST)
  736. {
  737. TraceLeave("LocateIpNetRow");
  738. return &(g_Cache.pRpcIpNetTable->table[0]);
  739. }
  740. bModified = FALSE;
  741. dwIpNetIfIndex = GetAsnInteger(paaIndex, 0);
  742. dwIpNetIpAddr = GetAsnIPAddress(paaAddr, 0x00000000);
  743. if (IsAsnTypeNull(paaIndex) or
  744. IsAsnIPAddressTypeNull(paaAddr))
  745. {
  746. bModified = TRUE;
  747. }
  748. bNext = (dwQueryType is GET_NEXT) and (bModified is FALSE);
  749. for (i = 0; i < g_Cache.pRpcIpNetTable->dwNumEntries; i++)
  750. {
  751. lCompare = IpNetCmp(dwIpNetIfIndex,
  752. dwIpNetIpAddr,
  753. g_Cache.pRpcIpNetTable->table[i].dwIndex,
  754. g_Cache.pRpcIpNetTable->table[i].dwAddr);
  755. if ((lCompare is 0) and !bNext)
  756. {
  757. TraceLeave("LocateIpNetRow");
  758. return &(g_Cache.pRpcIpNetTable->table[i]);
  759. }
  760. if (lCompare < 0)
  761. {
  762. if (dwQueryType is GET_NEXT)
  763. {
  764. TraceLeave("LocateIpNetRow");
  765. return &(g_Cache.pRpcIpNetTable->table[i]);
  766. }
  767. else
  768. {
  769. TraceLeave("LocateIpNetRow");
  770. return NULL;
  771. }
  772. }
  773. }
  774. TraceLeave("LocateIpNetRow");
  775. return NULL;
  776. }
  777. PMIB_UDPROW
  778. LocateUdpRow(
  779. DWORD dwQueryType,
  780. AsnAny *paaLocalAddr,
  781. AsnAny *paaLocalPort
  782. )
  783. {
  784. DWORD i;
  785. LONG lCompare;
  786. DWORD dwIndex[2];
  787. BOOL bNext, bModified;
  788. TraceEnter("LocateUdpRow");
  789. if (g_Cache.pRpcUdpTable->dwNumEntries is 0)
  790. {
  791. TraceLeave("LocateUdpRow");
  792. return NULL;
  793. }
  794. if (dwQueryType is GET_FIRST)
  795. {
  796. TraceLeave("LocateUdpRow");
  797. return &(g_Cache.pRpcUdpTable->table[0]);
  798. }
  799. #define LOCAL_ADDR 0
  800. #define LOCAL_PORT 1
  801. dwIndex[LOCAL_ADDR] = GetAsnIPAddress(paaLocalAddr, 0x00000000);
  802. dwIndex[LOCAL_PORT] = GetAsnInteger(paaLocalPort, 0);
  803. bModified = FALSE;
  804. if (IsAsnIPAddressTypeNull(paaLocalAddr) or
  805. IsAsnTypeNull(paaLocalPort))
  806. {
  807. bModified = TRUE;
  808. }
  809. bNext = (dwQueryType is GET_NEXT) and (bModified is FALSE);
  810. for (i = 0; i < g_Cache.pRpcUdpTable->dwNumEntries; i++)
  811. {
  812. lCompare = UdpCmp(dwIndex[LOCAL_ADDR],
  813. dwIndex[LOCAL_PORT],
  814. g_Cache.pRpcUdpTable->table[i].dwLocalAddr,
  815. g_Cache.pRpcUdpTable->table[i].dwLocalPort);
  816. if ((lCompare is 0) and !bNext)
  817. {
  818. TraceLeave("LocateUdpRow");
  819. return &(g_Cache.pRpcUdpTable->table[i]);
  820. }
  821. if (lCompare < 0)
  822. {
  823. if (dwQueryType is GET_NEXT)
  824. {
  825. TraceLeave("LocateUdpRow");
  826. return &(g_Cache.pRpcUdpTable->table[i]);
  827. }
  828. else
  829. {
  830. TraceLeave("LocateUdpRow");
  831. return NULL;
  832. }
  833. }
  834. }
  835. TraceLeave("LocateUdpRow");
  836. return NULL;
  837. }
  838. PUDP6ListenerEntry
  839. LocateUdp6Row(
  840. DWORD dwQueryType,
  841. AsnAny *paaLocalAddr,
  842. AsnAny *paaLocalPort
  843. )
  844. {
  845. DWORD i;
  846. LONG lCompare;
  847. DWORD dwLocalPort;
  848. BOOL bNext, bModified;
  849. // address plus scope id
  850. BYTE rgbyLocalAddrEx[20];
  851. TraceEnter("LocateUdp6Row");
  852. if (g_Cache.pRpcUdp6ListenerTable->dwNumEntries is 0)
  853. {
  854. TraceLeave("LocateUdp6Row");
  855. return NULL;
  856. }
  857. if (dwQueryType is GET_FIRST)
  858. {
  859. TraceLeave("LocateUdp6Row");
  860. return &(g_Cache.pRpcUdp6ListenerTable->table[0]);
  861. }
  862. // zero out scope id in case the octet string doesn't include it
  863. ZeroMemory(rgbyLocalAddrEx, sizeof(rgbyLocalAddrEx));
  864. GetAsnOctetString(rgbyLocalAddrEx, paaLocalAddr);
  865. dwLocalPort = GetAsnInteger(paaLocalPort, 0);
  866. bModified = FALSE;
  867. if (IsAsnIPAddressTypeNull(paaLocalAddr) or
  868. IsAsnTypeNull(paaLocalPort))
  869. {
  870. bModified = TRUE;
  871. }
  872. bNext = (dwQueryType is GET_NEXT) and (bModified is FALSE);
  873. for (i = 0; i < g_Cache.pRpcUdp6ListenerTable->dwNumEntries; i++)
  874. {
  875. lCompare = Udp6Cmp(rgbyLocalAddrEx,
  876. dwLocalPort,
  877. g_Cache.pRpcUdp6ListenerTable->table[i].ule_localaddr.s6_bytes,
  878. g_Cache.pRpcUdp6ListenerTable->table[i].ule_localport);
  879. if ((lCompare is 0) and !bNext)
  880. {
  881. TraceLeave("LocateUdp6Row");
  882. return &(g_Cache.pRpcUdp6ListenerTable->table[i]);
  883. }
  884. if (lCompare < 0)
  885. {
  886. if (dwQueryType is GET_NEXT)
  887. {
  888. TraceLeave("LocateUdp6Row");
  889. return &(g_Cache.pRpcUdp6ListenerTable->table[i]);
  890. }
  891. else
  892. {
  893. TraceLeave("LocateUdp6Row");
  894. return NULL;
  895. }
  896. }
  897. }
  898. TraceLeave("LocateUdp6Row");
  899. return NULL;
  900. }
  901. PMIB_TCPROW
  902. LocateTcpRow(
  903. DWORD dwQueryType,
  904. AsnAny *paaLocalAddr,
  905. AsnAny *paaLocalPort,
  906. AsnAny *paaRemoteAddr,
  907. AsnAny *paaRemotePort
  908. )
  909. {
  910. LONG lCompare;
  911. DWORD dwIndex[4];
  912. BOOL bNext, bModified;
  913. DWORD startIndex, stopIndex, i;
  914. TraceEnter("LocateTcpRow");
  915. if (g_Cache.pRpcTcpTable->dwNumEntries is 0)
  916. {
  917. TraceLeave("LocateTcpRow");
  918. return NULL;
  919. }
  920. if (dwQueryType is GET_FIRST)
  921. {
  922. TraceLeave("LocateTcpRow");
  923. return &(g_Cache.pRpcTcpTable->table[0]);
  924. }
  925. #define REM_ADDR 2
  926. #define REM_PORT 3
  927. dwIndex[LOCAL_ADDR] = GetAsnIPAddress(paaLocalAddr, 0x00000000);
  928. dwIndex[LOCAL_PORT] = GetAsnInteger(paaLocalPort, 0);
  929. dwIndex[REM_ADDR] = GetAsnIPAddress(paaRemoteAddr, 0x00000000);
  930. dwIndex[REM_PORT] = GetAsnInteger(paaRemotePort, 0);
  931. bModified = FALSE;
  932. if (IsAsnIPAddressTypeNull(paaLocalAddr) or
  933. IsAsnTypeNull(paaLocalPort) or
  934. IsAsnIPAddressTypeNull(paaRemoteAddr) or
  935. IsAsnTypeNull(paaRemotePort))
  936. {
  937. bModified = TRUE;
  938. }
  939. bNext = (dwQueryType is GET_NEXT) and (bModified is FALSE);
  940. for (i = 0; i < g_Cache.pRpcTcpTable->dwNumEntries; i++)
  941. {
  942. lCompare = TcpCmp(dwIndex[LOCAL_ADDR],
  943. dwIndex[LOCAL_PORT],
  944. dwIndex[REM_ADDR],
  945. dwIndex[REM_PORT],
  946. g_Cache.pRpcTcpTable->table[i].dwLocalAddr,
  947. g_Cache.pRpcTcpTable->table[i].dwLocalPort,
  948. g_Cache.pRpcTcpTable->table[i].dwRemoteAddr,
  949. g_Cache.pRpcTcpTable->table[i].dwRemotePort);
  950. if ((lCompare is 0) and !bNext)
  951. {
  952. TraceLeave("LocateTcpRow");
  953. return &(g_Cache.pRpcTcpTable->table[i]);
  954. }
  955. if (lCompare < 0)
  956. {
  957. if (dwQueryType is GET_NEXT)
  958. {
  959. TraceLeave("LocateTcpRow");
  960. return &(g_Cache.pRpcTcpTable->table[i]);
  961. }
  962. else
  963. {
  964. TraceLeave("LocateTcpRow");
  965. return NULL;
  966. }
  967. }
  968. }
  969. TraceLeave("LocateTcpRow");
  970. return NULL;
  971. }
  972. PTCP6ConnTableEntry
  973. LocateTcp6Row(
  974. DWORD dwQueryType,
  975. AsnAny *paaLocalAddr,
  976. AsnAny *paaLocalPort,
  977. AsnAny *paaRemoteAddr,
  978. AsnAny *paaRemotePort
  979. )
  980. {
  981. LONG lCompare;
  982. DWORD dwLocalPort, dwRemotePort;
  983. BOOL bNext, bModified;
  984. DWORD startIndex, stopIndex, i;
  985. // address plus scope id
  986. BYTE rgbyLocalAddrEx[20];
  987. BYTE rgbyRemoteAddrEx[20];
  988. TraceEnter("LocateTcp6Row");
  989. if (g_Cache.pRpcTcp6Table->dwNumEntries is 0)
  990. {
  991. TraceLeave("LocateTcp6Row");
  992. return NULL;
  993. }
  994. if (dwQueryType is GET_FIRST)
  995. {
  996. TraceLeave("LocateTcp6Row");
  997. return &(g_Cache.pRpcTcp6Table->table[0]);
  998. }
  999. // zero out scope id in case the octet string doesn't include it
  1000. ZeroMemory(rgbyLocalAddrEx, sizeof(rgbyLocalAddrEx));
  1001. ZeroMemory(rgbyRemoteAddrEx, sizeof(rgbyRemoteAddrEx));
  1002. GetAsnOctetString(rgbyLocalAddrEx, paaLocalAddr);
  1003. dwLocalPort = GetAsnInteger(paaLocalPort, 0);
  1004. GetAsnOctetString(rgbyRemoteAddrEx, paaRemoteAddr);
  1005. dwRemotePort = GetAsnInteger(paaRemotePort, 0);
  1006. bModified = FALSE;
  1007. if (IsAsnOctetStringTypeNull(paaLocalAddr) or
  1008. IsAsnTypeNull(paaLocalPort) or
  1009. IsAsnOctetStringTypeNull(paaRemoteAddr) or
  1010. IsAsnTypeNull(paaRemotePort))
  1011. {
  1012. bModified = TRUE;
  1013. }
  1014. bNext = (dwQueryType is GET_NEXT) and (bModified is FALSE);
  1015. for (i = 0; i < g_Cache.pRpcTcp6Table->dwNumEntries; i++)
  1016. {
  1017. lCompare = Tcp6Cmp(rgbyLocalAddrEx,
  1018. dwLocalPort,
  1019. rgbyRemoteAddrEx,
  1020. dwRemotePort,
  1021. g_Cache.pRpcTcp6Table->table[i].tct_localaddr.s6_bytes,
  1022. g_Cache.pRpcTcp6Table->table[i].tct_localport,
  1023. g_Cache.pRpcTcp6Table->table[i].tct_remoteaddr.s6_bytes,
  1024. g_Cache.pRpcTcp6Table->table[i].tct_remoteport);
  1025. if ((lCompare is 0) and !bNext)
  1026. {
  1027. TraceLeave("LocateTcp6Row");
  1028. return &(g_Cache.pRpcTcp6Table->table[i]);
  1029. }
  1030. if (lCompare < 0)
  1031. {
  1032. if (dwQueryType is GET_NEXT)
  1033. {
  1034. TraceLeave("LocateTcp6Row");
  1035. return &(g_Cache.pRpcTcp6Table->table[i]);
  1036. }
  1037. else
  1038. {
  1039. TraceLeave("LocateTcp6Row");
  1040. return NULL;
  1041. }
  1042. }
  1043. }
  1044. TraceLeave("LocateTcp6Row");
  1045. return NULL;
  1046. }