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.

3875 lines
97 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. mibfuncs.c
  5. Abstract:
  6. Sample subagent instrumentation callbacks.
  7. --*/
  8. #include "precomp.h"
  9. #pragma hdrstop
  10. DWORD
  11. ConnectToRouter();
  12. DWORD
  13. GetGlobalConfigInfo(
  14. OUT PIPRIP_MIB_GET_OUTPUT_DATA * ppimgod,
  15. OUT PDWORD pdwSize
  16. );
  17. DWORD
  18. SetGlobalInfo(
  19. IN AsnAny * objectArray
  20. );
  21. DWORD
  22. UpdatePeerFilterTable(
  23. IN AsnAny * objectArray,
  24. IN DWORD dwOp
  25. );
  26. DWORD
  27. AddPeerFilterEntry(
  28. IN DWORD dwPeerAddr,
  29. IN PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData
  30. );
  31. DWORD
  32. DeletePeerFilterEntry(
  33. IN DWORD dwIndex,
  34. IN PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData
  35. );
  36. DWORD
  37. GetInterfaceInfo(
  38. IN UINT actionId,
  39. IN PIPRIP_MIB_GET_INPUT_DATA pimgidInData,
  40. OUT PIPRIP_MIB_GET_OUTPUT_DATA* ppimgod,
  41. OUT PDWORD pdwOutSize
  42. );
  43. DWORD
  44. ValidateInterfaceConfig(
  45. IN AsnAny * objectArray
  46. );
  47. DWORD
  48. SetInterfaceConfig(
  49. IN AsnAny * objectArray
  50. );
  51. DWORD
  52. UpdateUnicastPeerEntry(
  53. IN AsnAny * objectArray,
  54. IN DWORD dwOp
  55. );
  56. DWORD
  57. AddUnicastPeerEntry(
  58. IN DWORD dwPeer,
  59. IN PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData
  60. );
  61. DWORD
  62. DeleteUnicastPeerEntry(
  63. IN DWORD dwIndex,
  64. IN PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData
  65. );
  66. DWORD
  67. UpdateFilterTable(
  68. IN DWORD dwOp,
  69. IN DWORD dwIfIndex,
  70. IN DWORD dwFiltType,
  71. IN PIPRIP_ROUTE_FILTER pirfFilt
  72. );
  73. DWORD
  74. AddFilterEntry(
  75. IN DWORD dwFiltType,
  76. IN PIPRIP_ROUTE_FILTER pirfFilt,
  77. IN PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData
  78. );
  79. DWORD
  80. DeleteFilterEntry(
  81. IN DWORD dwFiltType,
  82. IN DWORD dwIndex,
  83. IN PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData
  84. );
  85. ///////////////////////////////////////////////////////////////////////////////
  86. // //
  87. // global group (1.3.6.1.4.1.311.1.11.1) //
  88. // //
  89. ///////////////////////////////////////////////////////////////////////////////
  90. UINT
  91. get_global(
  92. UINT actionId,
  93. AsnAny * objectArray,
  94. UINT * errorIndex
  95. )
  96. {
  97. DWORD dwRes = (DWORD) -1,
  98. dwStatSize = 0,
  99. dwConfigSize = 0;
  100. buf_global* pbgBuffer = NULL;
  101. PIPRIP_GLOBAL_STATS pigsGlbStats = NULL;
  102. PIPRIP_GLOBAL_CONFIG pigcGlbConfig = NULL;
  103. PIPRIP_MIB_GET_OUTPUT_DATA pimgodStatData = NULL;
  104. PIPRIP_MIB_GET_OUTPUT_DATA pimgodConfigData = NULL;
  105. IPRIP_MIB_GET_INPUT_DATA imgidInData;
  106. TraceEnter( "get_global" );
  107. switch ( actionId )
  108. {
  109. case MIB_ACTION_GET:
  110. case MIB_ACTION_GETFIRST:
  111. //
  112. // Retrieve global information in 2 parts.
  113. //
  114. //
  115. // First get global stats
  116. //
  117. imgidInData.IMGID_TypeID = IPRIP_GLOBAL_STATS_ID;
  118. RIP_MIB_GET(
  119. &imgidInData,
  120. sizeof( IPRIP_MIB_GET_INPUT_DATA ),
  121. &pimgodStatData,
  122. &dwStatSize,
  123. dwRes
  124. );
  125. if ( dwRes != NO_ERROR )
  126. {
  127. break;
  128. }
  129. //
  130. // Next get global config
  131. //
  132. imgidInData.IMGID_TypeID = IPRIP_GLOBAL_CONFIG_ID;
  133. RIP_MIB_GET(
  134. &imgidInData,
  135. sizeof( IPRIP_MIB_GET_INPUT_DATA ),
  136. &pimgodConfigData,
  137. &dwConfigSize,
  138. dwRes
  139. );
  140. break;
  141. case MIB_ACTION_GETNEXT:
  142. default:
  143. TRACE1( "Wrong Action", actionId );
  144. return MIB_S_INVALID_PARAMETER;
  145. }
  146. //
  147. // if error print error message and free allocations
  148. //
  149. if ( dwRes != NO_ERROR )
  150. {
  151. TraceError( dwRes );
  152. if ( pimgodStatData ) { MprAdminMIBBufferFree ( pimgodStatData ); }
  153. if ( pimgodConfigData ) { MprAdminMIBBufferFree ( pimgodConfigData ); }
  154. return dwRes;
  155. }
  156. //
  157. // Set the return data.
  158. //
  159. //
  160. // Global Stats Data
  161. //
  162. pbgBuffer = (buf_global*) objectArray;
  163. pigsGlbStats = (PIPRIP_GLOBAL_STATS) pimgodStatData-> IMGOD_Buffer;
  164. SetAsnCounter(
  165. &(pbgBuffer-> globalSystemRouteChanges),
  166. pigsGlbStats-> GS_SystemRouteChanges
  167. );
  168. SetAsnCounter(
  169. &(pbgBuffer-> globalTotalResponseSends),
  170. pigsGlbStats-> GS_TotalResponsesSent
  171. );
  172. //
  173. // Global config Data
  174. //
  175. pigcGlbConfig = (PIPRIP_GLOBAL_CONFIG) pimgodConfigData-> IMGOD_Buffer;
  176. SetAsnInteger(
  177. &( pbgBuffer-> globalMaxRecQueueSize ),
  178. pigcGlbConfig-> GC_MaxRecvQueueSize
  179. );
  180. SetAsnInteger(
  181. &( pbgBuffer-> globalMaxSendQueueSize ),
  182. pigcGlbConfig-> GC_MaxSendQueueSize
  183. );
  184. SetAsnTimeTicks(
  185. &( pbgBuffer-> globalMinTriggeredUpdateInterval ),
  186. pigcGlbConfig-> GC_MinTriggeredUpdateInterval
  187. );
  188. SetAsnInteger(
  189. &( pbgBuffer-> globalPeerFilterCount ),
  190. pigcGlbConfig-> GC_PeerFilterCount
  191. );
  192. //
  193. // +1 added to adjust value to enumeration values in asn.
  194. // Enumeration in asn cannot have a value of 0. Causes a warning
  195. // to be generated by the asn compiler.
  196. //
  197. SetAsnInteger(
  198. &(pbgBuffer-> globalLoggingLevel),
  199. pigcGlbConfig-> GC_LoggingLevel + 1
  200. );
  201. SetAsnInteger(
  202. &( pbgBuffer-> globalPeerFilterMode ),
  203. pigcGlbConfig-> GC_PeerFilterMode + 1
  204. );
  205. if ( pimgodStatData ) { MprAdminMIBBufferFree ( pimgodStatData ); }
  206. if ( pimgodConfigData ) { MprAdminMIBBufferFree ( pimgodConfigData ); }
  207. TraceLeave( "get_global" );
  208. return MIB_S_SUCCESS;
  209. }
  210. UINT
  211. set_global(
  212. UINT actionId,
  213. AsnAny * objectArray,
  214. UINT * errorIndex
  215. )
  216. {
  217. DWORD dwRes = MIB_S_SUCCESS,
  218. dwLogLevel = 0,
  219. dwFiltMode = 0;
  220. sav_global* psgBuffer = (sav_global*) objectArray;
  221. switch ( actionId )
  222. {
  223. case MIB_ACTION_VALIDATE :
  224. TraceEnter( " set_global - validate " );
  225. //
  226. // Verify logging level
  227. //
  228. dwLogLevel = GetAsnInteger(
  229. &( psgBuffer-> globalLoggingLevel ),
  230. 0
  231. );
  232. if ( dwLogLevel < d_globalLoggingLevel_none ||
  233. dwLogLevel > d_globalLoggingLevel_information )
  234. {
  235. dwRes = MIB_S_INVALID_PARAMETER;
  236. TRACE1( "Invalid Logging level : %d\n", dwLogLevel );
  237. }
  238. //
  239. // Verify Peer Filter Mode
  240. //
  241. dwFiltMode = GetAsnInteger(
  242. &( psgBuffer-> globalPeerFilterMode ),
  243. 0
  244. );
  245. if ( dwFiltMode < d_globalPeerFilterMode_disable ||
  246. dwFiltMode > d_globalPeerFilterMode_exclude )
  247. {
  248. dwRes = MIB_S_INVALID_PARAMETER;
  249. TRACE1( "Invalid Peer Filter Mode level : %d\n", dwFiltMode );
  250. }
  251. TraceLeave( " set_global - validate " );
  252. break;
  253. case MIB_ACTION_SET :
  254. TraceEnter( " set_global - set " );
  255. dwRes = SetGlobalInfo( objectArray );
  256. TraceLeave( " set_global - set " );
  257. break;
  258. case MIB_ACTION_CLEANUP :
  259. TraceEnter( " set_global - cleanup " );
  260. TraceLeave( " set_global - cleanup " );
  261. break;
  262. default :
  263. TraceEnter( " set_global - Wrong action " );
  264. TraceLeave( " set_global - Wrong Action " );
  265. dwRes = MIB_S_INVALID_PARAMETER;
  266. break;
  267. }
  268. return dwRes;
  269. }
  270. ///////////////////////////////////////////////////////////////////////////////
  271. // //
  272. // globalPeerFilterEntry table (1.3.6.1.4.1.311.1.11.1.9.1) //
  273. // //
  274. ///////////////////////////////////////////////////////////////////////////////
  275. UINT
  276. get_globalPeerFilterEntry(
  277. UINT actionId,
  278. AsnAny * objectArray,
  279. UINT * errorIndex
  280. )
  281. {
  282. DWORD dwRes = (DWORD) -1,
  283. dwCurrentAddr = INADDR_NONE,
  284. dwInd = 0,
  285. dwGetSize = 0,
  286. dwSetSize = 0;
  287. PDWORD pdwAddrTable= NULL;
  288. buf_globalPeerFilterEntry* pbgpfe = NULL;
  289. PIPRIP_GLOBAL_CONFIG pigc = NULL;
  290. PIPRIP_MIB_SET_INPUT_DATA pimsidInData= NULL;
  291. PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData = NULL;
  292. IPRIP_MIB_GET_INPUT_DATA imgidInData;
  293. TraceEnter( "get_globalPeerFilterEntry" );
  294. pbgpfe = (buf_globalPeerFilterEntry*) objectArray;
  295. //
  296. // retrive the peer filter table
  297. //
  298. imgidInData.IMGID_TypeID = IPRIP_GLOBAL_CONFIG_ID;
  299. RIP_MIB_GET(
  300. &imgidInData,
  301. sizeof( IPRIP_MIB_GET_INPUT_DATA ),
  302. &pimgodOutData,
  303. &dwGetSize,
  304. dwRes
  305. );
  306. if ( dwRes != NO_ERROR )
  307. {
  308. TraceError( dwRes );
  309. return dwRes;
  310. }
  311. pigc = (PIPRIP_GLOBAL_CONFIG) pimgodOutData-> IMGOD_Buffer;
  312. if ( !pigc-> GC_PeerFilterCount )
  313. {
  314. TRACE0( "No Peer Entries" );
  315. MprAdminMIBBufferFree( pimgodOutData );
  316. return MIB_S_NO_MORE_ENTRIES;
  317. }
  318. pdwAddrTable = IPRIP_GLOBAL_PEER_FILTER_TABLE( pigc );
  319. //
  320. // Locate current entry in Peer filter table
  321. //
  322. dwCurrentAddr = GetAsnIPAddress( &( pbgpfe-> globalPFAddr ), 0 );
  323. FIND_PEER_ENTRY(
  324. dwCurrentAddr,
  325. pigc-> GC_PeerFilterCount,
  326. pdwAddrTable,
  327. dwInd
  328. );
  329. //
  330. // get requested entry
  331. //
  332. dwRes = MIB_S_SUCCESS;
  333. switch ( actionId )
  334. {
  335. case MIB_ACTION_GET :
  336. //
  337. // This is an idempotent case, since retieving a peer address
  338. // requires the peer address as index.
  339. // It is only useful to verify the presence of a particular peer.
  340. //
  341. if ( dwInd >= pigc-> GC_PeerFilterCount )
  342. {
  343. dwRes = MIB_S_ENTRY_NOT_FOUND;
  344. TRACE0( "Peer Entry not found" );
  345. }
  346. break;
  347. case MIB_ACTION_GETFIRST :
  348. //
  349. // get entry at index 0 (if available )
  350. //
  351. dwInd = 0;
  352. if ( !pigc-> GC_PeerFilterCount )
  353. {
  354. dwRes = MIB_S_ENTRY_NOT_FOUND;
  355. TRACE0( "Peer filter entry not found" );
  356. }
  357. break;
  358. case MIB_ACTION_GETNEXT :
  359. //
  360. // check if entry was found
  361. //
  362. if ( dwInd >= pigc-> GC_PeerFilterCount )
  363. {
  364. dwRes = MIB_S_ENTRY_NOT_FOUND;
  365. TRACE0( "Peer Entry not found " );
  366. break;
  367. }
  368. //
  369. // try and get next
  370. //
  371. dwInd++;
  372. if ( dwInd >= pigc-> GC_PeerFilterCount )
  373. {
  374. dwRes = MIB_S_NO_MORE_ENTRIES;
  375. TRACE0( "No more Peer Entries" );
  376. break;
  377. }
  378. break;
  379. default :
  380. TRACE0( " get_globalPeerFilterEntry - Wrong Action " );
  381. dwRes = MIB_S_INVALID_PARAMETER;
  382. break;
  383. }
  384. //
  385. // set index for next retrieval
  386. //
  387. if ( dwRes == MIB_S_SUCCESS )
  388. {
  389. ForceSetAsnIPAddress(
  390. &( pbgpfe-> globalPFAddr ),
  391. &( pbgpfe-> dwPeerFilterAddr ),
  392. pdwAddrTable[ dwInd ]
  393. );
  394. }
  395. if ( pimgodOutData ) { MprAdminMIBBufferFree( pimgodOutData ); }
  396. TraceLeave( "get_globalPeerFilterEntry" );
  397. return dwRes;
  398. }
  399. UINT
  400. set_globalPeerFilterEntry(
  401. UINT actionId,
  402. AsnAny * objectArray,
  403. UINT * errorIndex
  404. )
  405. {
  406. DWORD dwRes = MIB_S_SUCCESS,
  407. dwAddr = INADDR_NONE,
  408. dwOp = 0;
  409. sav_globalPeerFilterEntry* psgpfe = NULL;
  410. TraceEnter( " set_globalPeerFilterEntry " );
  411. psgpfe = (sav_globalPeerFilterEntry*) objectArray;
  412. switch ( actionId )
  413. {
  414. case MIB_ACTION_VALIDATE :
  415. //
  416. // Verify if the specified IP address is valid.
  417. //
  418. dwAddr = GetAsnIPAddress( &( psgpfe-> globalPFAddr ), INADDR_NONE );
  419. if ( !dwAddr || dwAddr == INADDR_NONE )
  420. {
  421. dwRes = MIB_S_INVALID_PARAMETER;
  422. TRACE0( " Invalid Peer address specified" );
  423. }
  424. //
  425. // Verify operation tag
  426. //
  427. dwRes = GetAsnInteger( &( psgpfe-> globalPFTag ), 0 );
  428. if ( dwRes != d_Tag_create && dwRes != d_Tag_delete )
  429. {
  430. dwRes = MIB_S_INVALID_PARAMETER;
  431. TRACE0( " Invalid Operation specified" );
  432. }
  433. break;
  434. case MIB_ACTION_SET :
  435. dwOp = GetAsnInteger( &( psgpfe-> globalPFTag ), 0 );
  436. dwRes = UpdatePeerFilterTable( objectArray, dwOp );
  437. break;
  438. case MIB_ACTION_CLEANUP :
  439. dwRes = MIB_S_SUCCESS;
  440. break;
  441. default :
  442. dwRes = MIB_S_INVALID_PARAMETER;
  443. TRACE0 ( " set_globalPeerFilterEntry - Wrong Action " );
  444. break;
  445. }
  446. TraceLeave( " set_globalPeerFilterEntry " );
  447. return dwRes;
  448. }
  449. ///////////////////////////////////////////////////////////////////////////////
  450. // //
  451. // interface group (1.3.6.1.4.1.311.1.11.2) //
  452. // //
  453. ///////////////////////////////////////////////////////////////////////////////
  454. ///////////////////////////////////////////////////////////////////////////////
  455. // //
  456. // ifStatsEntry table (1.3.6.1.4.1.311.1.11.2.1.1) //
  457. // //
  458. ///////////////////////////////////////////////////////////////////////////////
  459. UINT
  460. get_ifStatsEntry(
  461. UINT actionId,
  462. AsnAny * objectArray,
  463. UINT * errorIndex
  464. )
  465. {
  466. DWORD dwRes = (DWORD) -1,
  467. dwGetSize = 0,
  468. dwSetSize = 0;
  469. buf_ifStatsEntry * pbifse = NULL;
  470. PIPRIP_IF_STATS piis = NULL;
  471. PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData = NULL;
  472. IPRIP_MIB_GET_INPUT_DATA imgidInData;
  473. TraceEnter( "get_ifStatsEntry" );
  474. //
  475. // Retrieve Specified interface info.
  476. //
  477. pbifse = (buf_ifStatsEntry*) objectArray;
  478. imgidInData.IMGID_TypeID = IPRIP_IF_STATS_ID;
  479. imgidInData.IMGID_IfIndex = GetAsnInteger(
  480. &( pbifse-> ifSEIndex ),
  481. 0
  482. );
  483. //
  484. // When walking the mib using a sequence of getnext operations
  485. // the first getnext operation is translated into a getfirst
  486. // operation.
  487. //
  488. if ( actionId == MIB_ACTION_GETNEXT &&
  489. !imgidInData.IMGID_IfIndex )
  490. {
  491. actionId = MIB_ACTION_GETFIRST;
  492. }
  493. dwRes = GetInterfaceInfo(
  494. actionId,
  495. &imgidInData,
  496. &pimgodOutData,
  497. &dwGetSize
  498. );
  499. if ( dwRes != NO_ERROR )
  500. {
  501. TraceError( dwRes );
  502. return dwRes;
  503. }
  504. //
  505. // Set interface stats in return buffer
  506. //
  507. piis = (PIPRIP_IF_STATS) (pimgodOutData-> IMGOD_Buffer);
  508. SetAsnInteger( &( pbifse-> ifSEState ), piis-> IS_State );
  509. SetAsnCounter( &( pbifse-> ifSESendFailures ), piis-> IS_SendFailures );
  510. SetAsnCounter( &( pbifse-> ifSEReceiveFailures ), piis-> IS_ReceiveFailures );
  511. SetAsnCounter( &( pbifse-> ifSERequestSends ), piis-> IS_RequestsSent );
  512. SetAsnCounter( &( pbifse-> ifSEResponseSends ), piis-> IS_ResponsesSent );
  513. SetAsnCounter(
  514. &( pbifse-> ifSEResponseReceiveds ),
  515. piis-> IS_ResponsesReceived
  516. );
  517. SetAsnCounter(
  518. &( pbifse-> ifSEBadResponsePacketReceiveds ),
  519. piis-> IS_BadResponsePacketsReceived
  520. );
  521. SetAsnCounter(
  522. &( pbifse-> ifSEBadResponseEntriesReceiveds ),
  523. piis-> IS_BadResponseEntriesReceived
  524. );
  525. SetAsnCounter(
  526. &( pbifse-> ifSETriggeredUpdateSends ),
  527. piis-> IS_TriggeredUpdatesSent
  528. );
  529. //
  530. // set index for following getnext operation, (if any)
  531. //
  532. ForceSetAsnInteger(
  533. &( pbifse-> ifSEIndex ),
  534. pimgodOutData-> IMGOD_IfIndex
  535. );
  536. if ( pimgodOutData ) { MprAdminMIBBufferFree( pimgodOutData ); }
  537. TraceLeave( "get_ifStatsEntry" );
  538. return MIB_S_SUCCESS ;
  539. }
  540. ///////////////////////////////////////////////////////////////////////////////
  541. // //
  542. // ifConfigEntry table (1.3.6.1.4.1.311.1.11.2.2.1) //
  543. // //
  544. ///////////////////////////////////////////////////////////////////////////////
  545. UINT
  546. get_ifConfigEntry(
  547. UINT actionId,
  548. AsnAny * objectArray,
  549. UINT * errorIndex
  550. )
  551. {
  552. DWORD dwRes = (DWORD) -1,
  553. dwGetSize = 0;
  554. buf_ifConfigEntry* pbifce = NULL;
  555. PIPRIP_IF_CONFIG piic = NULL;
  556. PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData = NULL;
  557. IPRIP_MIB_GET_INPUT_DATA imgidInData;
  558. BYTE pbAuthKey[ IPRIP_MAX_AUTHKEY_SIZE ];
  559. TraceEnter( " get_ifConfigEntry " );
  560. //
  561. // retrieve interface config.
  562. //
  563. pbifce = (buf_ifConfigEntry*) objectArray;
  564. imgidInData.IMGID_TypeID = IPRIP_IF_CONFIG_ID;
  565. imgidInData.IMGID_IfIndex = GetAsnInteger( &( pbifce-> ifCEIndex ), 0 );
  566. //
  567. // When walking the mib using a sequence of getnext operations
  568. // the first getnext operation is translated into a getfirst
  569. // operation.
  570. //
  571. if ( actionId == MIB_ACTION_GETNEXT &&
  572. !imgidInData.IMGID_IfIndex )
  573. {
  574. actionId = MIB_ACTION_GETFIRST;
  575. }
  576. dwRes = GetInterfaceInfo(
  577. actionId,
  578. &imgidInData,
  579. &pimgodOutData,
  580. &dwGetSize
  581. );
  582. if ( dwRes != NO_ERROR )
  583. {
  584. TraceError( dwRes );
  585. return dwRes;
  586. }
  587. //
  588. // set requiste fields
  589. //
  590. piic = (PIPRIP_IF_CONFIG) (pimgodOutData-> IMGOD_Buffer);
  591. SetAsnInteger( &( pbifce-> ifCEState ), piic-> IC_State );
  592. SetAsnInteger( &( pbifce-> ifCEMetric ), piic-> IC_Metric );
  593. SetAsnInteger( &( pbifce-> ifCEUpdateMode ), piic-> IC_UpdateMode + 1 );
  594. SetAsnInteger( &( pbifce-> ifCEAcceptMode ), piic-> IC_AcceptMode + 1 );
  595. SetAsnInteger( &( pbifce-> ifCEAnnounceMode ), piic-> IC_AnnounceMode + 1 );
  596. SetAsnInteger( &( pbifce-> ifCEProtocolFlags ), piic-> IC_ProtocolFlags );
  597. SetAsnTimeTicks(
  598. &( pbifce-> ifCERouteExpirationInterval ),
  599. piic-> IC_RouteExpirationInterval
  600. );
  601. SetAsnTimeTicks(
  602. &( pbifce-> ifCERouteRemovalInterval ),
  603. piic-> IC_RouteRemovalInterval
  604. );
  605. SetAsnTimeTicks(
  606. &( pbifce-> ifCEFullUpdateInterval ),
  607. piic-> IC_FullUpdateInterval
  608. );
  609. SetAsnInteger(
  610. &( pbifce-> ifCEAuthenticationType ),
  611. piic-> IC_AuthenticationType
  612. );
  613. SetAsnInteger( &( pbifce-> ifCERouteTag ), piic-> IC_RouteTag );
  614. SetAsnInteger(
  615. &( pbifce-> ifCEUnicastPeerMode ),
  616. piic-> IC_UnicastPeerMode + 1
  617. );
  618. SetAsnInteger(
  619. &( pbifce-> ifCEAcceptFilterMode ),
  620. piic-> IC_AcceptFilterMode + 1
  621. );
  622. SetAsnInteger(
  623. &( pbifce-> ifCEAnnounceFilterMode ),
  624. piic-> IC_AnnounceFilterMode + 1
  625. );
  626. SetAsnInteger(
  627. &( pbifce-> ifCEUnicastPeerCount ),
  628. piic-> IC_UnicastPeerCount + 1
  629. );
  630. SetAsnInteger(
  631. &( pbifce-> ifCEAcceptFilterCount ),
  632. piic-> IC_AcceptFilterCount
  633. );
  634. SetAsnInteger(
  635. &( pbifce-> ifCEAnnounceFilterCount ),
  636. piic-> IC_AnnounceFilterCount
  637. );
  638. //
  639. // As per RFC 1724, this field is a write only field.
  640. // Authentication may not be bypassed by reading the key.
  641. // The default value to be returned is a null string.
  642. //
  643. ZeroMemory( pbAuthKey, IPRIP_MAX_AUTHKEY_SIZE );
  644. SetAsnOctetString(
  645. &( pbifce-> ifCEAuthenticationKey ),
  646. pbifce-> pbAuthKey,
  647. pbAuthKey,
  648. IPRIP_MAX_AUTHKEY_SIZE
  649. );
  650. //
  651. // set index for following getnext operation, (if any)
  652. //
  653. ForceSetAsnInteger(
  654. &( pbifce-> ifCEIndex ),
  655. pimgodOutData-> IMGOD_IfIndex
  656. );
  657. if ( pimgodOutData ) { MprAdminMIBBufferFree( pimgodOutData ); }
  658. TraceLeave( " get_ifConfigEntry " );
  659. return MIB_S_SUCCESS;
  660. }
  661. UINT
  662. set_ifConfigEntry(
  663. UINT actionId,
  664. AsnAny * objectArray,
  665. UINT * errorIndex
  666. )
  667. {
  668. DWORD dwRes = (DWORD) -1;
  669. TraceEnter( " set_ifConfigEntry " );
  670. switch ( actionId )
  671. {
  672. case MIB_ACTION_VALIDATE :
  673. dwRes = ValidateInterfaceConfig( objectArray );
  674. break;
  675. case MIB_ACTION_SET :
  676. dwRes = SetInterfaceConfig( objectArray );
  677. break;
  678. case MIB_ACTION_CLEANUP :
  679. dwRes = MIB_S_SUCCESS;
  680. break;
  681. default :
  682. TRACE0( " set_ifConfigEntry - wrong action " );
  683. dwRes = MIB_S_INVALID_PARAMETER;
  684. break;
  685. }
  686. TraceLeave( "set_ifConfigEntry" );
  687. return dwRes ;
  688. }
  689. ///////////////////////////////////////////////////////////////////////////////
  690. // //
  691. // ifUnicastPeersEntry table (1.3.6.1.4.1.311.1.11.2.3.1) //
  692. // //
  693. ///////////////////////////////////////////////////////////////////////////////
  694. UINT
  695. get_ifUnicastPeersEntry(
  696. UINT actionId,
  697. AsnAny * objectArray,
  698. UINT * errorIndex
  699. )
  700. {
  701. DWORD dwRes = (DWORD) -1,
  702. dwGetSize = 0,
  703. dwPeer = INADDR_NONE,
  704. dwInd = (DWORD) -1;
  705. PDWORD pdwAddrTable= NULL;
  706. buf_ifUnicastPeersEntry* pbifupe = NULL;
  707. PIPRIP_IF_CONFIG piic = NULL;
  708. PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData = NULL;
  709. IPRIP_MIB_GET_INPUT_DATA imgidInData;
  710. TraceEnter( " get_ifUnicastPeerEntry " );
  711. //
  712. // retrieve interface config.
  713. //
  714. pbifupe = (buf_ifUnicastPeersEntry*) objectArray;
  715. imgidInData.IMGID_TypeID = IPRIP_IF_CONFIG_ID;
  716. imgidInData.IMGID_IfIndex = GetAsnInteger( &( pbifupe-> ifUPIfIndex ), 0 );
  717. if ( actionId == MIB_ACTION_GETNEXT &&
  718. !imgidInData.IMGID_IfIndex )
  719. {
  720. actionId = MIB_ACTION_GETFIRST;
  721. }
  722. dwRes = GetInterfaceInfo(
  723. actionId,
  724. &imgidInData,
  725. &pimgodOutData,
  726. &dwGetSize
  727. );
  728. if ( dwRes != NO_ERROR )
  729. {
  730. TraceError( dwRes );
  731. return dwRes;
  732. }
  733. //
  734. // Locate peer entry
  735. //
  736. dwPeer = GetAsnIPAddress( &( pbifupe-> ifUPAddress ), 0 );
  737. piic = (PIPRIP_IF_CONFIG) ( pimgodOutData-> IMGOD_Buffer );
  738. pdwAddrTable = IPRIP_IF_UNICAST_PEER_TABLE( piic );
  739. FIND_PEER_ENTRY(
  740. dwPeer,
  741. piic-> IC_UnicastPeerCount,
  742. pdwAddrTable,
  743. dwInd
  744. );
  745. //
  746. // return requested peer entry
  747. //
  748. dwRes = MIB_S_SUCCESS;
  749. switch ( actionId )
  750. {
  751. case MIB_ACTION_GET :
  752. //
  753. // idempotent case. Only possible use is to verify
  754. // specific peer present.
  755. //
  756. if ( dwInd >= piic-> IC_UnicastPeerCount )
  757. {
  758. dwRes = MIB_S_ENTRY_NOT_FOUND;
  759. TRACE0( "Unicast Peer entry not found" );
  760. }
  761. break;
  762. case MIB_ACTION_GETFIRST :
  763. //
  764. // get entry at index 0 if available
  765. //
  766. dwInd = 0;
  767. if ( !piic-> IC_UnicastPeerCount )
  768. {
  769. dwRes = MIB_S_NO_MORE_ENTRIES;
  770. TRACE1(
  771. "No more Peer Entries for interface : %d",
  772. imgidInData.IMGID_IfIndex
  773. );
  774. }
  775. break;
  776. case MIB_ACTION_GETNEXT :
  777. //
  778. // check if entry was found
  779. //
  780. if ( dwInd >= piic-> IC_UnicastPeerCount )
  781. {
  782. dwRes = MIB_S_ENTRY_NOT_FOUND;
  783. TRACE0( "Unicast Peer Entry not found " );
  784. break;
  785. }
  786. //
  787. // try and get next
  788. //
  789. dwInd++;
  790. if ( dwInd >= piic-> IC_UnicastPeerCount )
  791. {
  792. dwRes = MIB_S_NO_MORE_ENTRIES;
  793. TRACE1(
  794. "No more Peer Entries for interface : %d",
  795. imgidInData.IMGID_IfIndex
  796. );
  797. break;
  798. }
  799. break;
  800. default :
  801. TRACE0( " get_globalPeerFilterEntry - Wrong Action " );
  802. dwRes = MIB_S_INVALID_PARAMETER;
  803. break;
  804. }
  805. //
  806. // set index value for next retrieval.
  807. //
  808. if ( dwRes == MIB_S_SUCCESS )
  809. {
  810. ForceSetAsnInteger(
  811. &( pbifupe-> ifUPIfIndex ),
  812. pimgodOutData-> IMGOD_IfIndex
  813. );
  814. ForceSetAsnIPAddress(
  815. &( pbifupe-> ifUPAddress ),
  816. &( pbifupe-> dwUnicastPeerAddr ),
  817. pdwAddrTable[ dwInd ]
  818. );
  819. }
  820. if ( pimgodOutData ) { MprAdminMIBBufferFree( pimgodOutData ); }
  821. TraceLeave( "get_ifUnicastPeersEntry " );
  822. return dwRes;
  823. }
  824. UINT
  825. set_ifUnicastPeersEntry(
  826. UINT actionId,
  827. AsnAny * objectArray,
  828. UINT * errorIndex
  829. )
  830. {
  831. DWORD dwRes = (DWORD) -1,
  832. dwOp = 0,
  833. dwAddr = INADDR_NONE;
  834. sav_ifUnicastPeersEntry* psifupe = NULL;
  835. TraceEnter( " set_ifUnicastPeersEntry " );
  836. psifupe = (sav_ifUnicastPeersEntry*) objectArray;
  837. switch ( actionId )
  838. {
  839. case MIB_ACTION_VALIDATE :
  840. //
  841. // Verify if the specified IP address is valid.
  842. //
  843. dwAddr = GetAsnIPAddress( &( psifupe-> ifUPAddress ), INADDR_NONE );
  844. if ( !dwAddr || dwAddr == INADDR_NONE )
  845. {
  846. dwRes = MIB_S_INVALID_PARAMETER;
  847. TRACE0( " Invalid Peer address specified" );
  848. break;
  849. }
  850. //
  851. // Verify operation tag
  852. //
  853. dwRes = GetAsnInteger( &( psifupe-> ifUPTag ), 0 );
  854. if ( dwRes != d_Tag_create && dwRes != d_Tag_delete )
  855. {
  856. dwRes = MIB_S_INVALID_PARAMETER;
  857. TRACE0( " Invalid Operation specified" );
  858. break;
  859. }
  860. dwRes = MIB_S_SUCCESS;
  861. break;
  862. case MIB_ACTION_SET :
  863. dwOp = GetAsnInteger( &( psifupe-> ifUPTag ), 0 );
  864. dwRes = UpdateUnicastPeerEntry( objectArray, dwOp );
  865. break;
  866. case MIB_ACTION_CLEANUP :
  867. dwRes = MIB_S_SUCCESS;
  868. break;
  869. default :
  870. dwRes = MIB_S_INVALID_PARAMETER;
  871. TRACE0 ( " set_ifUnicastPeersEntry - Wrong Action " );
  872. break;
  873. }
  874. TraceLeave( " set_ifUnicastPeersEntry " );
  875. return dwRes;
  876. }
  877. ///////////////////////////////////////////////////////////////////////////////
  878. // //
  879. // ifAcceptRouteFilterEntry table (1.3.6.1.4.1.311.1.11.2.4.1) //
  880. // //
  881. ///////////////////////////////////////////////////////////////////////////////
  882. UINT
  883. get_ifAcceptRouteFilterEntry(
  884. UINT actionId,
  885. AsnAny * objectArray,
  886. UINT * errorIndex
  887. )
  888. {
  889. DWORD dwRes = (DWORD) -1,
  890. dwIndex = 0,
  891. dwGetSize = 0;
  892. PIPRIP_IF_CONFIG piic = NULL;
  893. PIPRIP_ROUTE_FILTER pFiltTable = NULL;
  894. PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData = NULL;
  895. buf_ifAcceptRouteFilterEntry * pgifRF = NULL;
  896. IPRIP_ROUTE_FILTER irf;
  897. IPRIP_MIB_GET_INPUT_DATA imgidInData;
  898. TraceEnter( "get_ifAcceptRouteFilterEntry" );
  899. //
  900. // retrieve interface Info
  901. //
  902. pgifRF = (buf_ifAcceptRouteFilterEntry*) objectArray;
  903. imgidInData.IMGID_TypeID = IPRIP_IF_CONFIG_ID;
  904. imgidInData.IMGID_IfIndex = GetAsnInteger(
  905. &( pgifRF-> ifAcceptRFIfIndex ),
  906. 0
  907. );
  908. if ( actionId == MIB_ACTION_GETNEXT &&
  909. !imgidInData.IMGID_IfIndex )
  910. {
  911. actionId = MIB_ACTION_GETFIRST;
  912. }
  913. dwRes = GetInterfaceInfo(
  914. actionId,
  915. &imgidInData,
  916. &pimgodOutData,
  917. &dwGetSize
  918. );
  919. if ( dwRes != NO_ERROR )
  920. {
  921. TraceError( dwRes );
  922. return dwRes;
  923. }
  924. //
  925. // Find accept filter
  926. //
  927. irf.RF_LoAddress = GetAsnIPAddress(
  928. &( pgifRF-> ifAcceptRFLoAddress ),
  929. INADDR_NONE
  930. );
  931. irf.RF_HiAddress = GetAsnIPAddress(
  932. &( pgifRF-> ifAcceptRFHiAddress ),
  933. INADDR_NONE
  934. );
  935. piic = (PIPRIP_IF_CONFIG) pimgodOutData-> IMGOD_Buffer;
  936. pFiltTable = IPRIP_IF_ACCEPT_FILTER_TABLE( piic );
  937. FIND_FILTER(
  938. &irf,
  939. piic-> IC_AcceptFilterCount,
  940. pFiltTable,
  941. dwIndex
  942. );
  943. //
  944. // retrieve requested entry
  945. //
  946. dwRes = MIB_S_SUCCESS;
  947. switch ( actionId )
  948. {
  949. case MIB_ACTION_GET :
  950. //
  951. // Idempotent case
  952. //
  953. if ( dwIndex >= piic-> IC_AcceptFilterCount )
  954. {
  955. dwRes = MIB_S_ENTRY_NOT_FOUND;
  956. TRACE0( "Accept filter not found" );
  957. }
  958. break;
  959. case MIB_ACTION_GETFIRST :
  960. dwIndex = 0;
  961. if ( !piic-> IC_AcceptFilterCount )
  962. {
  963. dwRes = MIB_S_ENTRY_NOT_FOUND;
  964. TRACE0( "No Accept filters present " );
  965. }
  966. break;
  967. case MIB_ACTION_GETNEXT :
  968. if ( dwIndex >= piic-> IC_AcceptFilterCount )
  969. {
  970. dwRes = MIB_S_ENTRY_NOT_FOUND;
  971. TRACE0( "No Accept filters present " );
  972. }
  973. dwIndex++;
  974. if ( dwIndex >= piic-> IC_AcceptFilterCount )
  975. {
  976. dwRes = MIB_S_NO_MORE_ENTRIES;
  977. TRACE0( "No More Accept filters present " );
  978. }
  979. break;
  980. default :
  981. dwRes = MIB_S_INVALID_PARAMETER;
  982. TRACE0 ( "get_ifAcceptRouteFilterEntry - Wrong Action " );
  983. break;
  984. }
  985. //
  986. // set index for next retrieveal
  987. //
  988. if ( dwRes == MIB_S_SUCCESS )
  989. {
  990. ForceSetAsnInteger(
  991. &( pgifRF-> ifAcceptRFIfIndex ),
  992. pimgodOutData-> IMGOD_IfIndex
  993. );
  994. ForceSetAsnIPAddress(
  995. &( pgifRF-> ifAcceptRFLoAddress ),
  996. &( pgifRF-> dwFilterLoAddr ),
  997. pFiltTable[ dwIndex ].RF_LoAddress
  998. );
  999. ForceSetAsnIPAddress(
  1000. &( pgifRF-> ifAcceptRFHiAddress ),
  1001. &( pgifRF-> dwFilterHiAddr ),
  1002. pFiltTable[ dwIndex ].RF_HiAddress
  1003. );
  1004. }
  1005. if ( pimgodOutData ) { MprAdminMIBBufferFree( pimgodOutData ); }
  1006. TraceLeave( "get_ifAcceptRouteFilterEntry" );
  1007. return dwRes;
  1008. }
  1009. UINT
  1010. set_ifAcceptRouteFilterEntry(
  1011. UINT actionId,
  1012. AsnAny * objectArray,
  1013. UINT * errorIndex
  1014. )
  1015. {
  1016. DWORD dwRes = (DWORD) -1,
  1017. dwIndex = 0,
  1018. dwTag = 0;
  1019. sav_ifAcceptRouteFilterEntry* psifRF = NULL;
  1020. IPRIP_ROUTE_FILTER irf;
  1021. TraceEnter( "set_ifAcceptRouteFilterEntry" );
  1022. psifRF = (sav_ifAcceptRouteFilterEntry*) objectArray;
  1023. dwIndex = GetAsnInteger(
  1024. &( psifRF-> ifAcceptRFIfIndex ),
  1025. 0
  1026. );
  1027. irf.RF_LoAddress = GetAsnIPAddress(
  1028. &( psifRF-> ifAcceptRFLoAddress ),
  1029. INADDR_NONE
  1030. );
  1031. irf.RF_HiAddress = GetAsnIPAddress(
  1032. &( psifRF-> ifAcceptRFHiAddress ),
  1033. INADDR_NONE
  1034. );
  1035. dwTag = GetAsnInteger(
  1036. &( psifRF-> ifAcceptRFTag ),
  1037. 0
  1038. );
  1039. switch ( actionId )
  1040. {
  1041. case MIB_ACTION_VALIDATE :
  1042. //
  1043. // Check filter ranges are valid address
  1044. //
  1045. if ( !irf.RF_LoAddress || irf.RF_LoAddress == INADDR_NONE ||
  1046. !irf.RF_HiAddress || irf.RF_HiAddress == INADDR_NONE ||
  1047. ( dwTag != d_Tag_create && dwTag != d_Tag_delete ) )
  1048. {
  1049. dwRes = MIB_S_INVALID_PARAMETER;
  1050. TRACE0( "Invalid parameter value " );
  1051. }
  1052. break;
  1053. case MIB_ACTION_SET :
  1054. dwRes = UpdateFilterTable(
  1055. dwTag,
  1056. dwIndex,
  1057. RIP_MIB_ACCEPT_FILTER,
  1058. &irf
  1059. );
  1060. break;
  1061. case MIB_ACTION_CLEANUP :
  1062. dwRes = MIB_S_SUCCESS;
  1063. break;
  1064. default :
  1065. dwRes = MIB_S_INVALID_PARAMETER;
  1066. TRACE0 ( " set_ifAcceptRouteFilterEntry - Wrong Action " );
  1067. break;
  1068. }
  1069. TraceLeave( "set_ifAcceptRouteFilterEntry" );
  1070. return dwRes;
  1071. }
  1072. ///////////////////////////////////////////////////////////////////////////////
  1073. // //
  1074. // ifAnnounceRouteFilterEntry table (1.3.6.1.4.1.311.1.11.2.5.1) //
  1075. // //
  1076. ///////////////////////////////////////////////////////////////////////////////
  1077. UINT
  1078. get_ifAnnounceRouteFilterEntry(
  1079. UINT actionId,
  1080. AsnAny * objectArray,
  1081. UINT * errorIndex
  1082. )
  1083. {
  1084. DWORD dwRes = (DWORD) -1,
  1085. dwIndex = 0,
  1086. dwGetSize = 0;
  1087. IPRIP_ROUTE_FILTER irf;
  1088. IPRIP_MIB_GET_INPUT_DATA imgidInData;
  1089. PIPRIP_IF_CONFIG piic = NULL;
  1090. PIPRIP_ROUTE_FILTER pFiltTable = NULL;
  1091. PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData = NULL;
  1092. buf_ifAnnounceRouteFilterEntry * pgifRF = NULL;
  1093. TraceEnter( "get_ifAnnounceRouteFilterEntry" );
  1094. //
  1095. // retrieve interface Info
  1096. //
  1097. pgifRF = (buf_ifAnnounceRouteFilterEntry*) objectArray;
  1098. imgidInData.IMGID_TypeID = IPRIP_IF_CONFIG_ID;
  1099. imgidInData.IMGID_IfIndex = GetAsnInteger(
  1100. &( pgifRF-> ifAnnounceRFIfIndex ),
  1101. 0
  1102. );
  1103. if ( actionId == MIB_ACTION_GETNEXT &&
  1104. !imgidInData.IMGID_IfIndex )
  1105. {
  1106. actionId = MIB_ACTION_GETFIRST;
  1107. }
  1108. dwRes = GetInterfaceInfo(
  1109. actionId,
  1110. &imgidInData,
  1111. &pimgodOutData,
  1112. &dwGetSize
  1113. );
  1114. if ( dwRes != NO_ERROR )
  1115. {
  1116. TraceError( dwRes );
  1117. return dwRes;
  1118. }
  1119. //
  1120. // find specfied filter
  1121. //
  1122. irf.RF_LoAddress = GetAsnIPAddress(
  1123. &( pgifRF-> ifAnnounceRFLoAddress ),
  1124. INADDR_NONE
  1125. );
  1126. irf.RF_HiAddress = GetAsnIPAddress(
  1127. &( pgifRF-> ifAnnounceRFHiAddress ),
  1128. INADDR_NONE
  1129. );
  1130. piic = (PIPRIP_IF_CONFIG) pimgodOutData-> IMGOD_Buffer;
  1131. pFiltTable = IPRIP_IF_ACCEPT_FILTER_TABLE( piic );
  1132. FIND_FILTER(
  1133. &irf,
  1134. piic-> IC_AnnounceFilterCount,
  1135. pFiltTable,
  1136. dwIndex
  1137. );
  1138. //
  1139. // get filter info.
  1140. //
  1141. dwRes = MIB_S_SUCCESS;
  1142. switch ( actionId )
  1143. {
  1144. case MIB_ACTION_GET :
  1145. //
  1146. // Idempotent case
  1147. //
  1148. if ( dwIndex >= piic-> IC_AnnounceFilterCount )
  1149. {
  1150. dwRes = MIB_S_ENTRY_NOT_FOUND;
  1151. TRACE0( "Announce filter not found" );
  1152. }
  1153. break;
  1154. case MIB_ACTION_GETFIRST :
  1155. dwIndex = 0;
  1156. if ( !piic-> IC_AnnounceFilterCount )
  1157. {
  1158. dwRes = MIB_S_ENTRY_NOT_FOUND;
  1159. TRACE0( "No Announce filters present " );
  1160. }
  1161. break;
  1162. case MIB_ACTION_GETNEXT :
  1163. if ( dwIndex >= piic-> IC_AnnounceFilterCount )
  1164. {
  1165. dwRes = MIB_S_ENTRY_NOT_FOUND;
  1166. TRACE0( "No Announce filters present " );
  1167. }
  1168. dwIndex++;
  1169. if ( dwIndex >= piic-> IC_AnnounceFilterCount )
  1170. {
  1171. dwRes = ERROR_NO_MORE_ITEMS;
  1172. TRACE0( "No More Announce filters present " );
  1173. }
  1174. dwRes = MIB_S_SUCCESS;
  1175. break;
  1176. default :
  1177. dwRes = MIB_S_INVALID_PARAMETER;
  1178. TRACE0 ( "get_ifAnnounceRouteFilterEntry - Wrong Action " );
  1179. break;
  1180. }
  1181. //
  1182. // set up the indices for next retrieval
  1183. //
  1184. if ( dwRes == MIB_S_SUCCESS )
  1185. {
  1186. ForceSetAsnInteger(
  1187. &( pgifRF-> ifAnnounceRFIfIndex ),
  1188. pimgodOutData-> IMGOD_IfIndex
  1189. );
  1190. ForceSetAsnIPAddress(
  1191. &( pgifRF-> ifAnnounceRFLoAddress ),
  1192. &( pgifRF-> dwFilterLoAddr ),
  1193. pFiltTable[ dwIndex ].RF_LoAddress
  1194. );
  1195. ForceSetAsnIPAddress(
  1196. &( pgifRF-> ifAnnounceRFHiAddress ),
  1197. &( pgifRF-> dwFilterHiAddr ),
  1198. pFiltTable[ dwIndex ].RF_HiAddress
  1199. );
  1200. }
  1201. if ( pimgodOutData ) { MprAdminMIBBufferFree( pimgodOutData ); }
  1202. TraceLeave( "get_ifAnnounceRouteFilterEntry" );
  1203. return dwRes;
  1204. }
  1205. UINT
  1206. set_ifAnnounceRouteFilterEntry(
  1207. UINT actionId,
  1208. AsnAny * objectArray,
  1209. UINT * errorIndex
  1210. )
  1211. {
  1212. DWORD dwRes = (DWORD) -1,
  1213. dwIndex = 0,
  1214. dwTag = 0;
  1215. sav_ifAnnounceRouteFilterEntry* psifRF = NULL;
  1216. IPRIP_ROUTE_FILTER irf;
  1217. TraceEnter( "set_ifAnnounceRouteFilterEntry" );
  1218. psifRF = (sav_ifAnnounceRouteFilterEntry*) objectArray;
  1219. dwIndex = GetAsnInteger(
  1220. &( psifRF-> ifAnnounceRFLoAddress ),
  1221. 0
  1222. );
  1223. irf.RF_LoAddress = GetAsnIPAddress(
  1224. &( psifRF-> ifAnnounceRFLoAddress ),
  1225. INADDR_NONE
  1226. );
  1227. irf.RF_HiAddress = GetAsnIPAddress(
  1228. &( psifRF-> ifAnnounceRFHiAddress ),
  1229. INADDR_NONE
  1230. );
  1231. dwTag = GetAsnInteger(
  1232. &( psifRF-> ifAnnounceRFTag ),
  1233. 0
  1234. );
  1235. switch ( actionId )
  1236. {
  1237. case MIB_ACTION_VALIDATE :
  1238. //
  1239. // Check filter ranges are valid address
  1240. //
  1241. if ( !irf.RF_LoAddress || irf.RF_LoAddress == INADDR_NONE ||
  1242. !irf.RF_HiAddress || irf.RF_HiAddress == INADDR_NONE ||
  1243. ( dwTag != d_Tag_create && dwTag != d_Tag_delete ) )
  1244. {
  1245. dwRes = MIB_S_INVALID_PARAMETER;
  1246. TRACE0( "Invalid parameter value " );
  1247. }
  1248. break;
  1249. case MIB_ACTION_SET :
  1250. dwRes = UpdateFilterTable(
  1251. dwTag,
  1252. dwIndex,
  1253. RIP_MIB_ANNOUNCE_FILTER,
  1254. &irf
  1255. );
  1256. break;
  1257. case MIB_ACTION_CLEANUP :
  1258. dwRes = MIB_S_SUCCESS;
  1259. break;
  1260. default :
  1261. dwRes = MIB_S_INVALID_PARAMETER;
  1262. TRACE0 ( " set_ifAnnounceRouteFilterEntry - Wrong Action " );
  1263. break;
  1264. }
  1265. TraceLeave( "set_ifAnnounceRouteFilterEntry" );
  1266. return dwRes;
  1267. }
  1268. ///////////////////////////////////////////////////////////////////////////////
  1269. // //
  1270. // ifBindingEntry table (1.3.6.1.4.1.311.1.11.2.6.1) //
  1271. // //
  1272. ///////////////////////////////////////////////////////////////////////////////
  1273. UINT
  1274. get_ifBindingEntry(
  1275. UINT actionId,
  1276. AsnAny * objectArray,
  1277. UINT * errorIndex
  1278. )
  1279. {
  1280. DWORD dwRes = (DWORD) -1,
  1281. dwGetSize = 0;
  1282. buf_ifBindingEntry* pbifb = NULL;
  1283. PIPRIP_IF_BINDING piib = NULL;
  1284. PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData = NULL;
  1285. IPRIP_MIB_GET_INPUT_DATA imgidInData;
  1286. TraceEnter( " get_ifBindingEntry " );
  1287. //
  1288. // retrieve interface binding info.
  1289. //
  1290. pbifb = (buf_ifBindingEntry*) objectArray;
  1291. imgidInData.IMGID_TypeID = IPRIP_IF_BINDING_ID;
  1292. imgidInData.IMGID_IfIndex = GetAsnInteger(
  1293. &( pbifb-> ifBindingIndex ),
  1294. 0
  1295. );
  1296. if ( actionId == MIB_ACTION_GETNEXT &&
  1297. !imgidInData.IMGID_IfIndex )
  1298. {
  1299. actionId = MIB_ACTION_GETFIRST;
  1300. }
  1301. dwRes = GetInterfaceInfo(
  1302. actionId,
  1303. &imgidInData,
  1304. &pimgodOutData,
  1305. &dwGetSize
  1306. );
  1307. if ( dwRes != NO_ERROR )
  1308. {
  1309. TraceError( dwRes );
  1310. return dwRes;
  1311. }
  1312. //
  1313. // set requiste fields
  1314. //
  1315. piib = (PIPRIP_IF_BINDING) (pimgodOutData-> IMGOD_Buffer);
  1316. SetAsnInteger( &( pbifb-> ifBindingState ), piib-> IB_State + 1 );
  1317. SetAsnCounter( &( pbifb-> ifBindingCounts ), piib-> IB_AddrCount );
  1318. ForceSetAsnInteger(
  1319. &( pbifb-> ifBindingIndex ),
  1320. pimgodOutData-> IMGOD_IfIndex
  1321. );
  1322. if ( pimgodOutData ) { MprAdminMIBBufferFree( pimgodOutData ); }
  1323. TraceLeave( " get_ifBindingEntry " );
  1324. return MIB_S_SUCCESS ;
  1325. }
  1326. ///////////////////////////////////////////////////////////////////////////////
  1327. // //
  1328. // ifAddressEntry table (1.3.6.1.4.1.311.1.11.2.7.1) //
  1329. // //
  1330. ///////////////////////////////////////////////////////////////////////////////
  1331. UINT
  1332. get_ifAddressEntry(
  1333. UINT actionId,
  1334. AsnAny * objectArray,
  1335. UINT * errorIndex
  1336. )
  1337. {
  1338. DWORD dwRes = (DWORD) -1,
  1339. dwIndex = (DWORD) -1,
  1340. dwGetSize = 0;
  1341. buf_ifAddressEntry * pbifae = NULL;
  1342. PIPRIP_IF_BINDING piib = NULL;
  1343. PIPRIP_IP_ADDRESS pia = NULL;
  1344. PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData = NULL;
  1345. IPRIP_IP_ADDRESS ipa;
  1346. IPRIP_MIB_GET_INPUT_DATA imgidInData;
  1347. TraceEnter( " get_ifAddressEntry " );
  1348. //
  1349. // retrieve interface binding info.
  1350. //
  1351. pbifae = (buf_ifAddressEntry*) objectArray;
  1352. imgidInData.IMGID_TypeID = IPRIP_IF_BINDING_ID;
  1353. imgidInData.IMGID_IfIndex = GetAsnInteger(
  1354. &( pbifae-> ifAEIfIndex ),
  1355. 0
  1356. );
  1357. if ( actionId == MIB_ACTION_GETNEXT &&
  1358. !imgidInData.IMGID_IfIndex )
  1359. {
  1360. actionId = MIB_ACTION_GETFIRST;
  1361. }
  1362. dwRes = GetInterfaceInfo(
  1363. actionId,
  1364. &imgidInData,
  1365. &pimgodOutData,
  1366. &dwGetSize
  1367. );
  1368. if ( dwRes != NO_ERROR )
  1369. {
  1370. TraceError( dwRes );
  1371. return dwRes;
  1372. }
  1373. //
  1374. // retrieve IPAddress from IP Address table
  1375. //
  1376. ipa.IA_Address = GetAsnIPAddress(
  1377. &( pbifae-> ifAEAddress),
  1378. INADDR_NONE
  1379. );
  1380. ipa.IA_Netmask = GetAsnIPAddress(
  1381. &( pbifae-> ifAEMask),
  1382. INADDR_NONE
  1383. );
  1384. piib = (PIPRIP_IF_BINDING) pimgodOutData-> IMGOD_Buffer;
  1385. pia = (PIPRIP_IP_ADDRESS) IPRIP_IF_ADDRESS_TABLE( piib );
  1386. FIND_IP_ADDRESS(
  1387. ipa,
  1388. piib-> IB_AddrCount,
  1389. pia,
  1390. dwIndex
  1391. );
  1392. //
  1393. // set appr fields
  1394. //
  1395. dwRes = MIB_S_SUCCESS;
  1396. switch ( actionId )
  1397. {
  1398. case MIB_ACTION_GET :
  1399. //
  1400. // idempotent case. Only possible use is to verify
  1401. // specific peer present.
  1402. //
  1403. if ( dwIndex >= piib-> IB_AddrCount )
  1404. {
  1405. dwRes = MIB_S_ENTRY_NOT_FOUND;
  1406. TRACE0( "IP address entry not found" );
  1407. }
  1408. break;
  1409. case MIB_ACTION_GETFIRST :
  1410. //
  1411. // get entry at index 0 if available
  1412. //
  1413. dwIndex = 0;
  1414. if ( !piib-> IB_AddrCount )
  1415. {
  1416. dwRes = MIB_S_NO_MORE_ENTRIES;
  1417. TRACE1(
  1418. "No more IP address Entries for interface : %d",
  1419. imgidInData.IMGID_IfIndex
  1420. );
  1421. }
  1422. break;
  1423. case MIB_ACTION_GETNEXT :
  1424. //
  1425. // check if entry was found
  1426. //
  1427. if ( dwIndex >= piib-> IB_AddrCount )
  1428. {
  1429. dwRes = MIB_S_ENTRY_NOT_FOUND;
  1430. TRACE0( "IP address Entry not found " );
  1431. break;
  1432. }
  1433. //
  1434. // try and get next
  1435. //
  1436. dwIndex++;
  1437. if ( dwIndex >= piib-> IB_AddrCount )
  1438. {
  1439. dwRes = MIB_S_NO_MORE_ENTRIES;
  1440. TRACE1(
  1441. "No more IP address Entries for interface : %d",
  1442. imgidInData.IMGID_IfIndex
  1443. );
  1444. break;
  1445. }
  1446. dwRes = MIB_S_SUCCESS;
  1447. break;
  1448. default :
  1449. TRACE0( " get_globalPeerFilterEntry - Wrong Action " );
  1450. dwRes = MIB_S_INVALID_PARAMETER;
  1451. break;
  1452. }
  1453. //
  1454. // set index for next retieval
  1455. //
  1456. if ( dwRes == MIB_S_SUCCESS )
  1457. {
  1458. ForceSetAsnInteger(
  1459. &( pbifae-> ifAEIfIndex ),
  1460. pimgodOutData-> IMGOD_IfIndex
  1461. );
  1462. ForceSetAsnIPAddress(
  1463. &( pbifae-> ifAEAddress ),
  1464. &( pbifae-> dwAddress ),
  1465. pia[ dwIndex ].IA_Address
  1466. );
  1467. ForceSetAsnIPAddress(
  1468. &( pbifae-> ifAEMask ),
  1469. &( pbifae-> dwMask ),
  1470. pia[ dwIndex ].IA_Netmask
  1471. );
  1472. }
  1473. if ( pimgodOutData ) { MprAdminMIBBufferFree( pimgodOutData ); }
  1474. TraceLeave( " get_ifAddressEntry " );
  1475. return dwRes;
  1476. }
  1477. ///////////////////////////////////////////////////////////////////////////////
  1478. // //
  1479. // peer group (1.3.6.1.4.1.311.1.11.3) //
  1480. // //
  1481. ///////////////////////////////////////////////////////////////////////////////
  1482. ///////////////////////////////////////////////////////////////////////////////
  1483. // //
  1484. // ifPeerStatsEntry table (1.3.6.1.4.1.311.1.11.3.1.1) //
  1485. // //
  1486. ///////////////////////////////////////////////////////////////////////////////
  1487. UINT
  1488. get_ifPeerStatsEntry(
  1489. UINT actionId,
  1490. AsnAny * objectArray,
  1491. UINT * errorIndex
  1492. )
  1493. {
  1494. DWORD dwRes = (DWORD) -1,
  1495. dwGetSize = 0;
  1496. buf_ifPeerStatsEntry* pbifpse = NULL;
  1497. PIPRIP_PEER_STATS pips = NULL;
  1498. PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData = NULL;
  1499. IPRIP_MIB_GET_INPUT_DATA imgidInData;
  1500. TraceEnter( "get_ifPeerStatsEntry" );
  1501. //
  1502. // retrieve interface config.
  1503. //
  1504. pbifpse = (buf_ifPeerStatsEntry*) objectArray;
  1505. imgidInData.IMGID_TypeID = IPRIP_PEER_STATS_ID;
  1506. imgidInData.IMGID_PeerAddress = (DWORD) GetAsnIPAddress(
  1507. &( pbifpse-> ifPSAddress ),
  1508. 0
  1509. );
  1510. if ( actionId == MIB_ACTION_GETNEXT &&
  1511. !imgidInData.IMGID_PeerAddress )
  1512. {
  1513. actionId = MIB_ACTION_GETFIRST;
  1514. }
  1515. dwRes = GetPeerStatsInfo(
  1516. actionId,
  1517. &imgidInData,
  1518. &pimgodOutData,
  1519. &dwGetSize
  1520. );
  1521. if ( dwRes != NO_ERROR )
  1522. {
  1523. TraceError( dwRes );
  1524. return dwRes;
  1525. }
  1526. //
  1527. // set requiste fields
  1528. //
  1529. pips = (PIPRIP_PEER_STATS) (pimgodOutData-> IMGOD_Buffer);
  1530. SetAsnInteger(
  1531. &( pbifpse-> ifPSLastPeerRouteTag ),
  1532. pips-> PS_LastPeerUpdateTickCount
  1533. );
  1534. SetAsnTimeTicks(
  1535. &( pbifpse-> ifPSLastPeerUpdateTickCount ),
  1536. pips-> PS_LastPeerUpdateTickCount
  1537. );
  1538. SetAsnInteger(
  1539. &( pbifpse-> ifPSLastPeerUpdateVersion ),
  1540. pips-> PS_LastPeerUpdateVersion
  1541. );
  1542. SetAsnCounter(
  1543. &( pbifpse-> ifPSPeerBadResponsePackets ),
  1544. pips-> PS_BadResponsePacketsFromPeer
  1545. );
  1546. SetAsnCounter(
  1547. &( pbifpse-> ifPSPeerBadResponseEntries ),
  1548. pips-> PS_BadResponseEntriesFromPeer
  1549. );
  1550. //
  1551. // Set index for next retrieval
  1552. //
  1553. ForceSetAsnIPAddress(
  1554. &( pbifpse-> ifPSAddress ),
  1555. &( pbifpse-> dwPeerAddr ),
  1556. pimgodOutData-> IMGOD_PeerAddress
  1557. );
  1558. if ( pimgodOutData ) { MprAdminMIBBufferFree( pimgodOutData ); }
  1559. TraceLeave( " get_ifPeerStatsEntry " );
  1560. return MIB_S_SUCCESS ;
  1561. }
  1562. DWORD
  1563. GetGlobalConfigInfo(
  1564. OUT PIPRIP_MIB_GET_OUTPUT_DATA * ppimgod,
  1565. OUT PDWORD pdwSize
  1566. )
  1567. {
  1568. DWORD dwRes = (DWORD) -1;
  1569. PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData = NULL;
  1570. IPRIP_MIB_GET_INPUT_DATA imgidInData;
  1571. do
  1572. {
  1573. //
  1574. // retrieve global config
  1575. //
  1576. imgidInData.IMGID_TypeID = IPRIP_GLOBAL_CONFIG_ID;
  1577. RIP_MIB_GET(
  1578. &imgidInData,
  1579. sizeof( IPRIP_MIB_GET_INPUT_DATA ),
  1580. &pimgodOutData,
  1581. pdwSize,
  1582. dwRes
  1583. );
  1584. if ( dwRes != NO_ERROR )
  1585. {
  1586. TraceError( dwRes );
  1587. break;
  1588. }
  1589. *ppimgod = pimgodOutData;
  1590. } while ( FALSE );
  1591. return dwRes;
  1592. }
  1593. //
  1594. // SetGlobalInfo
  1595. //
  1596. //
  1597. // Sets the global RIP info.
  1598. //
  1599. DWORD
  1600. SetGlobalInfo(
  1601. IN AsnAny * objectArray
  1602. )
  1603. {
  1604. DWORD dwRes = (DWORD) -1,
  1605. dwGetSize = 0,
  1606. dwSetSize = 0;
  1607. sav_global* psg = NULL;
  1608. PIPRIP_GLOBAL_CONFIG pigc = NULL;
  1609. PIPRIP_MIB_SET_INPUT_DATA pimsidInData= NULL;
  1610. PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData = NULL;
  1611. do
  1612. {
  1613. //
  1614. // Retrieve the global config Data first
  1615. //
  1616. dwRes = GetGlobalConfigInfo(
  1617. &pimgodOutData,
  1618. &dwGetSize
  1619. );
  1620. if ( dwRes != NO_ERROR )
  1621. {
  1622. break;
  1623. }
  1624. pigc = (PIPRIP_GLOBAL_CONFIG) pimgodOutData-> IMGOD_Buffer;
  1625. psg = (sav_global*) objectArray;
  1626. //
  1627. // Allocate set info buffer
  1628. //
  1629. dwSetSize = sizeof( IPRIP_MIB_SET_INPUT_DATA ) - 1 +
  1630. IPRIP_GLOBAL_CONFIG_SIZE( pigc );
  1631. pimsidInData =
  1632. (PIPRIP_MIB_SET_INPUT_DATA) RIP_MIB_ALLOC( dwSetSize );
  1633. if ( pimsidInData == NULL )
  1634. {
  1635. dwRes = ERROR_NOT_ENOUGH_MEMORY;
  1636. TRACE0( "SetGlobalData - Mem. alloc failed" );
  1637. break;
  1638. }
  1639. //
  1640. // Set config info fields.
  1641. // if the variable is not specified, we
  1642. // set the field to its previous value i.e. an empty assignment.
  1643. //
  1644. pimsidInData-> IMSID_TypeID = IPRIP_GLOBAL_CONFIG_ID;
  1645. pimsidInData-> IMSID_IfIndex = (DWORD) -1;
  1646. pimsidInData-> IMSID_BufferSize = IPRIP_GLOBAL_CONFIG_SIZE( pigc );
  1647. pigc-> GC_MaxRecvQueueSize = GetAsnInteger(
  1648. &( psg-> globalMaxRecQueueSize ),
  1649. pigc-> GC_MaxRecvQueueSize
  1650. );
  1651. pigc-> GC_MaxSendQueueSize = GetAsnInteger(
  1652. &( psg-> globalMaxSendQueueSize ),
  1653. pigc-> GC_MaxSendQueueSize
  1654. );
  1655. pigc-> GC_MinTriggeredUpdateInterval = GetAsnTimeTicks(
  1656. &( psg-> globalMinTriggeredUpdateInterval ),
  1657. pigc-> GC_MinTriggeredUpdateInterval
  1658. );
  1659. //
  1660. // -1 is subtracted from the enumerated fields to adjust
  1661. // the ASN enumeration values to the actual values.
  1662. // This is required since the enumeration cannot have
  1663. // a zero value as per the ASN compiler, but one of the
  1664. // actual values for the field in the config is a zero.
  1665. //
  1666. // as a caveat, if the enumerated field is not specified in
  1667. // this set operation, to preserve the value of the field
  1668. // in the config, we first increment it. This way on the
  1669. // -1 operation the value is restored.
  1670. //
  1671. pigc-> GC_LoggingLevel++;
  1672. pigc-> GC_LoggingLevel = GetAsnInteger(
  1673. &( psg-> globalLoggingLevel ),
  1674. pigc-> GC_LoggingLevel
  1675. ) - 1;
  1676. pigc-> GC_PeerFilterMode++;
  1677. pigc-> GC_PeerFilterMode = GetAsnInteger(
  1678. &( psg-> globalPeerFilterMode ),
  1679. pigc-> GC_PeerFilterMode
  1680. ) - 1;
  1681. CopyMemory(
  1682. (PVOID) pimsidInData-> IMSID_Buffer,
  1683. (PVOID*) pigc,
  1684. IPRIP_GLOBAL_CONFIG_SIZE( pigc )
  1685. );
  1686. //
  1687. // Save the info. in the MIB
  1688. //
  1689. RIP_MIB_SET(
  1690. pimsidInData,
  1691. dwSetSize,
  1692. dwRes
  1693. );
  1694. if ( dwRes != NO_ERROR )
  1695. {
  1696. TraceError( dwRes );
  1697. break;
  1698. }
  1699. dwRes = MIB_S_SUCCESS;
  1700. } while ( FALSE );
  1701. //
  1702. // Free allocations
  1703. //
  1704. if ( pimgodOutData ) { MprAdminMIBBufferFree( pimgodOutData ); }
  1705. if ( pimsidInData ) { RIP_MIB_FREE( pimsidInData ); }
  1706. return dwRes;
  1707. }
  1708. DWORD
  1709. UpdatePeerFilterTable(
  1710. IN AsnAny * objectArray,
  1711. IN DWORD dwOp
  1712. )
  1713. {
  1714. DWORD dwRes = (DWORD) -1,
  1715. dwInd = 0,
  1716. dwPeerAddr = INADDR_NONE,
  1717. dwGetSize = 0,
  1718. dwSetSize = 0;
  1719. PDWORD pdwAddrTable= 0;
  1720. sav_globalPeerFilterEntry* psgpfe = NULL;
  1721. PIPRIP_GLOBAL_CONFIG pigc = NULL;
  1722. PIPRIP_MIB_SET_INPUT_DATA pimsid = NULL;
  1723. PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData = NULL;
  1724. do
  1725. {
  1726. //
  1727. // Get global info
  1728. //
  1729. dwRes = GetGlobalConfigInfo(
  1730. &pimgodOutData,
  1731. &dwGetSize
  1732. );
  1733. if ( dwRes != NO_ERROR )
  1734. {
  1735. break;
  1736. }
  1737. //
  1738. // Find filter entry
  1739. //
  1740. psgpfe = (sav_globalPeerFilterEntry*) objectArray;
  1741. dwPeerAddr = GetAsnIPAddress(
  1742. &( psgpfe-> globalPFAddr ),
  1743. 0
  1744. );
  1745. pigc = (PIPRIP_GLOBAL_CONFIG) pimgodOutData-> IMGOD_Buffer;
  1746. pdwAddrTable= IPRIP_GLOBAL_PEER_FILTER_TABLE( pigc );
  1747. FIND_PEER_ENTRY(
  1748. dwPeerAddr,
  1749. pigc-> GC_PeerFilterCount,
  1750. pdwAddrTable,
  1751. dwInd
  1752. );
  1753. //
  1754. // if operation is filter add
  1755. //
  1756. if ( dwOp == d_Tag_create )
  1757. {
  1758. //
  1759. // if peer already present, quit
  1760. //
  1761. if ( pigc-> GC_PeerFilterCount &&
  1762. dwInd < pigc-> GC_PeerFilterCount )
  1763. {
  1764. dwRes = MIB_S_SUCCESS;
  1765. break;
  1766. }
  1767. else
  1768. {
  1769. dwRes = AddPeerFilterEntry(
  1770. dwPeerAddr,
  1771. pimgodOutData
  1772. );
  1773. }
  1774. break;
  1775. }
  1776. //
  1777. // operation is filter delete
  1778. //
  1779. //
  1780. // if peer is not present quit.
  1781. //
  1782. if ( !pigc-> GC_PeerFilterCount ||
  1783. dwInd >= pigc-> GC_PeerFilterCount )
  1784. {
  1785. dwRes = MIB_S_SUCCESS;
  1786. break;
  1787. }
  1788. dwRes = DeletePeerFilterEntry(
  1789. dwInd,
  1790. pimgodOutData
  1791. );
  1792. } while ( FALSE );
  1793. if ( pimgodOutData ) { MprAdminMIBBufferFree( pimgodOutData ); }
  1794. return dwRes;
  1795. }
  1796. DWORD
  1797. AddPeerFilterEntry(
  1798. IN DWORD dwPeerAddr,
  1799. IN PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData
  1800. )
  1801. {
  1802. DWORD dwRes = (DWORD) -1,
  1803. dwSetSize = 0;
  1804. PDWORD pdwAddrTable= NULL;
  1805. PIPRIP_GLOBAL_CONFIG pigc = NULL;
  1806. PIPRIP_MIB_SET_INPUT_DATA pimsid = NULL;
  1807. do
  1808. {
  1809. //
  1810. // Peer needs to be added.
  1811. //
  1812. //
  1813. // compute buffer size required
  1814. //
  1815. pigc = (PIPRIP_GLOBAL_CONFIG) pimgodOutData-> IMGOD_Buffer;
  1816. dwSetSize = sizeof( IPRIP_MIB_SET_INPUT_DATA ) - 1 +
  1817. IPRIP_GLOBAL_CONFIG_SIZE( pigc ) + sizeof( DWORD );
  1818. pimsid = (PIPRIP_MIB_SET_INPUT_DATA) RIP_MIB_ALLOC( dwSetSize );
  1819. if ( !pimsid )
  1820. {
  1821. dwRes = ERROR_NOT_ENOUGH_MEMORY;
  1822. TRACE0( "AddPeerFilterEntry - out of memory" );
  1823. break;
  1824. }
  1825. //
  1826. // Add filter
  1827. //
  1828. pimsid-> IMSID_TypeID = IPRIP_GLOBAL_CONFIG_ID;
  1829. pimsid-> IMSID_IfIndex = (DWORD) -1;
  1830. pimsid-> IMSID_BufferSize = IPRIP_GLOBAL_CONFIG_SIZE( pigc ) +
  1831. sizeof( DWORD );
  1832. CopyMemory(
  1833. (PVOID) &( pimsid-> IMSID_Buffer ),
  1834. (VOID *) pigc,
  1835. IPRIP_GLOBAL_CONFIG_SIZE( pigc )
  1836. );
  1837. pigc = (PIPRIP_GLOBAL_CONFIG) pimsid-> IMSID_Buffer;
  1838. pdwAddrTable = IPRIP_GLOBAL_PEER_FILTER_TABLE( pigc );
  1839. pdwAddrTable[ pigc-> GC_PeerFilterCount ] = dwPeerAddr;
  1840. pigc-> GC_PeerFilterCount++;
  1841. //
  1842. // Update MIB
  1843. //
  1844. RIP_MIB_SET(
  1845. pimsid,
  1846. dwSetSize,
  1847. dwRes
  1848. );
  1849. } while ( FALSE );
  1850. if ( pimsid ) { RIP_MIB_FREE( pimsid ); }
  1851. return dwRes;
  1852. }
  1853. DWORD
  1854. DeletePeerFilterEntry(
  1855. IN DWORD dwIndex,
  1856. IN PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData
  1857. )
  1858. {
  1859. DWORD dwRes = (DWORD) -1,
  1860. dwSetSize = 0,
  1861. dwSrc = 0,
  1862. dwDst = 0;
  1863. PDWORD pdwSrcTable = NULL,
  1864. pdwDstTable = NULL;
  1865. PIPRIP_GLOBAL_CONFIG pigc = NULL;
  1866. PIPRIP_MIB_SET_INPUT_DATA pimsid = NULL;
  1867. do
  1868. {
  1869. //
  1870. // Peer needs to be added.
  1871. //
  1872. //
  1873. // compute buffer size required
  1874. //
  1875. pigc = (PIPRIP_GLOBAL_CONFIG) pimgodOutData-> IMGOD_Buffer;
  1876. dwSetSize = sizeof( IPRIP_MIB_SET_INPUT_DATA ) - 1 +
  1877. IPRIP_GLOBAL_CONFIG_SIZE( pigc ) - sizeof( DWORD );
  1878. pimsid = (PIPRIP_MIB_SET_INPUT_DATA) RIP_MIB_ALLOC( dwSetSize );
  1879. if ( !pimsid )
  1880. {
  1881. dwRes = ERROR_NOT_ENOUGH_MEMORY;
  1882. TRACE0( "AddPeerFilterEntry - out of memory" );
  1883. break;
  1884. }
  1885. //
  1886. // Delete filter
  1887. //
  1888. //
  1889. // Copy base global config structure
  1890. //
  1891. pimsid-> IMSID_TypeID = IPRIP_GLOBAL_CONFIG_ID;
  1892. pimsid-> IMSID_IfIndex = (DWORD) -1;
  1893. pimsid-> IMSID_BufferSize = IPRIP_GLOBAL_CONFIG_SIZE( pigc ) -
  1894. sizeof( DWORD );
  1895. CopyMemory(
  1896. (PVOID) &( pimsid-> IMSID_Buffer ),
  1897. (VOID *) pigc,
  1898. sizeof( IPRIP_GLOBAL_CONFIG )
  1899. );
  1900. //
  1901. // Copy peer table. Skip entry to be deleted
  1902. //
  1903. pdwSrcTable = IPRIP_GLOBAL_PEER_FILTER_TABLE( pigc );
  1904. pigc = ( PIPRIP_GLOBAL_CONFIG ) pimsid-> IMSID_Buffer;
  1905. pdwDstTable = IPRIP_GLOBAL_PEER_FILTER_TABLE( pigc );
  1906. DELETE_PEER_ENTRY(
  1907. dwIndex,
  1908. pigc-> GC_PeerFilterCount,
  1909. pdwSrcTable,
  1910. pdwDstTable
  1911. );
  1912. pigc-> GC_PeerFilterCount--;
  1913. //
  1914. // Update MIB
  1915. //
  1916. RIP_MIB_SET(
  1917. pimsid,
  1918. dwSetSize,
  1919. dwRes
  1920. );
  1921. } while ( FALSE );
  1922. if ( pimsid ) { RIP_MIB_FREE( pimsid ); }
  1923. return dwRes;
  1924. }
  1925. DWORD
  1926. GetInterfaceInfo(
  1927. IN UINT actionId,
  1928. IN PIPRIP_MIB_GET_INPUT_DATA pimgidInData,
  1929. OUT PIPRIP_MIB_GET_OUTPUT_DATA* ppimgod,
  1930. OUT PDWORD pdwOutSize
  1931. )
  1932. {
  1933. DWORD dwRes = (DWORD) -1;
  1934. PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData = NULL;
  1935. *ppimgod = NULL;
  1936. switch ( actionId )
  1937. {
  1938. case MIB_ACTION_GET :
  1939. RIP_MIB_GET(
  1940. pimgidInData,
  1941. sizeof( IPRIP_MIB_GET_INPUT_DATA ),
  1942. &pimgodOutData,
  1943. pdwOutSize,
  1944. dwRes
  1945. );
  1946. //
  1947. // ERROR_INVALID_PARAMETER is returned when there is
  1948. // no interface for the specified index.
  1949. //
  1950. if (( dwRes == ERROR_INVALID_PARAMETER ) ||
  1951. ( dwRes == ERROR_NOT_FOUND ))
  1952. {
  1953. dwRes = MIB_S_ENTRY_NOT_FOUND;
  1954. }
  1955. break;
  1956. case MIB_ACTION_GETFIRST :
  1957. RIP_MIB_GETFIRST(
  1958. pimgidInData,
  1959. sizeof( IPRIP_MIB_GET_INPUT_DATA ),
  1960. &pimgodOutData,
  1961. pdwOutSize,
  1962. dwRes
  1963. );
  1964. //
  1965. // ERROR_INVALID_PARAMETER is returned when there is
  1966. // no interface for the specified index.
  1967. //
  1968. if ( dwRes == ERROR_INVALID_PARAMETER )
  1969. {
  1970. dwRes = MIB_S_NO_MORE_ENTRIES;
  1971. }
  1972. break;
  1973. case MIB_ACTION_GETNEXT :
  1974. RIP_MIB_GETNEXT(
  1975. pimgidInData,
  1976. sizeof( IPRIP_MIB_GET_INPUT_DATA ),
  1977. &pimgodOutData,
  1978. pdwOutSize,
  1979. dwRes
  1980. );
  1981. //
  1982. // ERROR_INVALID_PARAMETER is returned when there is
  1983. // no interface for the specified index.
  1984. //
  1985. if ( dwRes == ERROR_INVALID_PARAMETER || pimgodOutData==NULL)
  1986. {
  1987. dwRes = MIB_S_NO_MORE_ENTRIES;
  1988. break;
  1989. }
  1990. //
  1991. // Get Next wraps to the next table at the end of the
  1992. // entries in the current table. To flag the end of a table,
  1993. // check the end of the table.
  1994. //
  1995. if ( pimgidInData-> IMGID_TypeID != pimgodOutData-> IMGOD_TypeID )
  1996. {
  1997. MprAdminMIBBufferFree( pimgodOutData );
  1998. dwRes = MIB_S_NO_MORE_ENTRIES;
  1999. }
  2000. break;
  2001. default :
  2002. dwRes = MIB_S_INVALID_PARAMETER;
  2003. break;
  2004. }
  2005. if ( dwRes == NO_ERROR )
  2006. {
  2007. *ppimgod = pimgodOutData;
  2008. }
  2009. return dwRes;
  2010. }
  2011. DWORD
  2012. ValidateInterfaceConfig(
  2013. IN AsnAny * objectArray
  2014. )
  2015. {
  2016. DWORD dwRes = MIB_S_INVALID_PARAMETER,
  2017. dwMetric = (DWORD) -1,
  2018. dwMode = (DWORD) -1;
  2019. sav_ifConfigEntry* psifce = (sav_ifConfigEntry*) objectArray;
  2020. do
  2021. {
  2022. //
  2023. // verify metric is in [0..16]
  2024. //
  2025. dwMetric = GetAsnInteger( &( psifce-> ifCEMetric ), (DWORD) -1 );
  2026. if ( dwMetric > 16 )
  2027. {
  2028. TRACE1( " Invalid metric (%d) specified ", dwMetric );
  2029. break;
  2030. }
  2031. //
  2032. // verify update, annouce, accept modes
  2033. //
  2034. dwMode = GetAsnInteger( &( psifce-> ifCEUpdateMode ), (DWORD) -1 );
  2035. if ( dwMode != d_ifCEUpdateMode_periodic &&
  2036. dwMode != d_ifCEUpdateMode_demand )
  2037. {
  2038. TRACE1( " Invalid update mode (%d) specified ", dwMode );
  2039. break;
  2040. }
  2041. dwMode = GetAsnInteger( &( psifce-> ifCEAcceptMode ), (DWORD) -1 );
  2042. if ( dwMode < d_ifCEAcceptMode_disable ||
  2043. dwMode > d_ifCEAcceptMode_rip2 )
  2044. {
  2045. TRACE1( " Invalid Accept mode (%d) specified ", dwMode );
  2046. break;
  2047. }
  2048. dwMode = GetAsnInteger( &( psifce-> ifCEAnnounceMode ), (DWORD) -1 );
  2049. if ( dwMode < d_ifCEAnnounceMode_disable ||
  2050. dwMode > d_ifCEAnnounceMode_rip2 )
  2051. {
  2052. TRACE1( " Invalid Announce mode (%d) specified ", dwMode );
  2053. break;
  2054. }
  2055. //
  2056. // Verify protcol flags, authentication type
  2057. //
  2058. dwMode = GetAsnInteger( &( psifce-> ifCEProtocolFlags ), (DWORD) -1 );
  2059. if ( dwMode > MAX_PROTOCOL_FLAG_VALUE )
  2060. {
  2061. TRACE1( " Invalid protocol flags (%d) specified ", dwMode );
  2062. break;
  2063. }
  2064. dwMode = GetAsnInteger(
  2065. &( psifce-> ifCEAuthenticationType ),
  2066. (DWORD) -1
  2067. );
  2068. if ( dwMode < d_ifCEAuthenticationType_noAuthentication ||
  2069. dwMode > d_ifCEAuthenticationType_md5 )
  2070. {
  2071. TRACE1( " Invalid authentication type (%d) specified ", dwMode );
  2072. break;
  2073. }
  2074. //
  2075. // Verify Unicast peer, Announce/Accept filter modes
  2076. //
  2077. dwMode = GetAsnInteger( &( psifce-> ifCEUnicastPeerMode ), (DWORD) -1 );
  2078. if ( dwMode < d_ifCEUnicastPeerMode_disable ||
  2079. dwMode > d_ifCEUnicastPeerMode_peerOnly )
  2080. {
  2081. TRACE1( " Invalid Unicast Peer mode (%d) specified ", dwMode );
  2082. break;
  2083. }
  2084. dwMode = GetAsnInteger(
  2085. &( psifce-> ifCEAcceptFilterMode ),
  2086. (DWORD) -1
  2087. );
  2088. if ( dwMode < d_ifCEAcceptFilterMode_disable ||
  2089. dwMode > d_ifCEAcceptFilterMode_exclude )
  2090. {
  2091. TRACE1( " Invalid Accept Filter mode (%d) specified ", dwMode );
  2092. break;
  2093. }
  2094. dwMode = GetAsnInteger(
  2095. &( psifce-> ifCEAnnounceFilterMode ),
  2096. (DWORD) -1
  2097. );
  2098. if ( dwMode < d_ifCEAnnounceFilterMode_disable ||
  2099. dwMode > d_ifCEAnnounceFilterMode_exclude )
  2100. {
  2101. TRACE1( " Invalid Announce Filter mode (%d) specified ", dwMode );
  2102. break;
  2103. }
  2104. dwRes = MIB_S_SUCCESS;
  2105. } while ( FALSE );
  2106. return dwRes;
  2107. }
  2108. DWORD
  2109. SetInterfaceConfig(
  2110. IN AsnAny * objectArray
  2111. )
  2112. {
  2113. DWORD dwRes = (DWORD) -1,
  2114. dwGetSize = 0,
  2115. dwSetSize = 0;
  2116. sav_ifConfigEntry* psifce = NULL;
  2117. PIPRIP_IF_CONFIG piic = NULL;
  2118. PIPRIP_MIB_SET_INPUT_DATA pimsidInData= NULL;
  2119. PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData = NULL;
  2120. IPRIP_MIB_GET_INPUT_DATA imgidInData;
  2121. do
  2122. {
  2123. //
  2124. // Retrieve existing interface config
  2125. //
  2126. psifce = (sav_ifConfigEntry*) objectArray;
  2127. imgidInData.IMGID_TypeID = IPRIP_IF_CONFIG_ID;
  2128. imgidInData.IMGID_IfIndex = GetAsnInteger(
  2129. &( psifce-> ifCEIndex ),
  2130. (DWORD) -1
  2131. );
  2132. dwRes = GetInterfaceInfo(
  2133. MIB_ACTION_GET,
  2134. &imgidInData,
  2135. &pimgodOutData,
  2136. &dwGetSize
  2137. );
  2138. if ( dwRes != NO_ERROR )
  2139. {
  2140. TraceError( dwRes );
  2141. break;
  2142. }
  2143. //
  2144. // Update fields
  2145. //
  2146. piic = (PIPRIP_IF_CONFIG) (pimgodOutData-> IMGOD_Buffer);
  2147. piic-> IC_Metric = GetAsnInteger(
  2148. &( psifce-> ifCEMetric ),
  2149. piic-> IC_Metric
  2150. );
  2151. piic-> IC_UpdateMode = GetAsnInteger(
  2152. &( psifce-> ifCEUpdateMode ),
  2153. piic-> IC_UpdateMode
  2154. );
  2155. piic-> IC_AcceptMode = GetAsnInteger(
  2156. &( psifce-> ifCEAcceptMode ),
  2157. piic-> IC_AcceptMode
  2158. );
  2159. piic-> IC_AnnounceMode = GetAsnInteger(
  2160. &( psifce-> ifCEAnnounceMode ),
  2161. piic-> IC_AnnounceMode
  2162. );
  2163. piic-> IC_ProtocolFlags = GetAsnInteger(
  2164. &( psifce-> ifCEProtocolFlags ),
  2165. piic-> IC_ProtocolFlags
  2166. );
  2167. piic-> IC_RouteExpirationInterval = GetAsnTimeTicks(
  2168. &( psifce-> ifCERouteExpirationInterval ),
  2169. piic-> IC_RouteExpirationInterval
  2170. );
  2171. piic-> IC_RouteRemovalInterval = GetAsnTimeTicks(
  2172. &( psifce-> ifCERouteRemovalInterval ),
  2173. piic-> IC_RouteRemovalInterval
  2174. );
  2175. piic-> IC_FullUpdateInterval = GetAsnTimeTicks(
  2176. &( psifce-> ifCEFullUpdateInterval ),
  2177. piic-> IC_FullUpdateInterval
  2178. );
  2179. piic-> IC_AuthenticationType = GetAsnInteger(
  2180. &( psifce-> ifCEAuthenticationType ),
  2181. piic-> IC_AuthenticationType
  2182. );
  2183. GetAsnOctetString(
  2184. piic-> IC_AuthenticationKey,
  2185. &( psifce-> ifCEAuthenticationKey )
  2186. );
  2187. piic-> IC_RouteTag = (USHORT) GetAsnInteger(
  2188. &( psifce-> ifCERouteTag ),
  2189. piic-> IC_RouteTag
  2190. );
  2191. piic-> IC_UnicastPeerMode = GetAsnInteger(
  2192. &( psifce-> ifCEUnicastPeerMode ),
  2193. piic-> IC_UnicastPeerMode
  2194. );
  2195. piic-> IC_AcceptFilterMode = GetAsnInteger(
  2196. &( psifce-> ifCEAcceptFilterMode ),
  2197. piic-> IC_AcceptFilterMode
  2198. );
  2199. piic-> IC_AnnounceFilterMode = GetAsnInteger(
  2200. &( psifce-> ifCEAnnounceFilterMode ),
  2201. piic-> IC_AnnounceFilterMode
  2202. );
  2203. //
  2204. // Save inteface config
  2205. //
  2206. dwSetSize = sizeof( IPRIP_MIB_SET_INPUT_DATA) - 1 +
  2207. IPRIP_IF_CONFIG_SIZE( piic );
  2208. pimsidInData = (PIPRIP_MIB_SET_INPUT_DATA) RIP_MIB_ALLOC( dwSetSize );
  2209. if ( !pimsidInData )
  2210. {
  2211. dwRes = ERROR_NOT_ENOUGH_MEMORY;
  2212. TRACE0( " Not enough memory " );
  2213. break;
  2214. }
  2215. pimsidInData-> IMSID_TypeID = IPRIP_IF_CONFIG_ID;
  2216. pimsidInData-> IMSID_IfIndex = imgidInData.IMGID_IfIndex;
  2217. pimsidInData-> IMSID_BufferSize = IPRIP_IF_CONFIG_SIZE( piic );
  2218. CopyMemory(
  2219. pimsidInData-> IMSID_Buffer,
  2220. piic,
  2221. pimsidInData-> IMSID_BufferSize
  2222. );
  2223. RIP_MIB_SET(
  2224. pimsidInData,
  2225. dwSetSize,
  2226. dwRes
  2227. );
  2228. if ( dwRes != NO_ERROR )
  2229. {
  2230. TraceError( dwRes );
  2231. break;
  2232. }
  2233. dwRes = MIB_S_SUCCESS;
  2234. } while ( FALSE );
  2235. if ( pimgodOutData ) { MprAdminMIBBufferFree( pimgodOutData ); }
  2236. if ( pimsidInData ) { RIP_MIB_FREE( pimsidInData ); }
  2237. return dwRes;
  2238. }
  2239. DWORD
  2240. UpdateUnicastPeerEntry(
  2241. IN AsnAny * objectArray,
  2242. IN DWORD dwOp
  2243. )
  2244. {
  2245. DWORD dwRes = (DWORD) -1,
  2246. dwInd = 0,
  2247. dwPeerAddr = INADDR_NONE,
  2248. dwGetSize = 0,
  2249. dwSetSize = 0;
  2250. PDWORD pdwAddrTable= 0;
  2251. sav_ifUnicastPeersEntry * psifupe = NULL;
  2252. PIPRIP_IF_CONFIG piic = NULL;
  2253. PIPRIP_MIB_SET_INPUT_DATA pimsid = NULL;
  2254. PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData = NULL;
  2255. IPRIP_MIB_GET_INPUT_DATA imgidInData;
  2256. do
  2257. {
  2258. //
  2259. // Get interface config info
  2260. //
  2261. psifupe = (sav_ifUnicastPeersEntry*) objectArray;
  2262. imgidInData.IMGID_TypeID = IPRIP_IF_CONFIG_ID;
  2263. imgidInData.IMGID_IfIndex = GetAsnInteger(
  2264. &( psifupe-> ifUPIfIndex ),
  2265. 0
  2266. );
  2267. dwRes = GetInterfaceInfo(
  2268. MIB_ACTION_GET,
  2269. &imgidInData,
  2270. &pimgodOutData,
  2271. &dwGetSize
  2272. );
  2273. if ( dwRes != NO_ERROR )
  2274. {
  2275. TraceError( dwRes );
  2276. break;
  2277. }
  2278. //
  2279. // Find Peer entry
  2280. //
  2281. dwPeerAddr = GetAsnIPAddress( &( psifupe-> ifUPAddress ), 0 );
  2282. piic = (PIPRIP_IF_CONFIG) pimgodOutData-> IMGOD_Buffer;
  2283. pdwAddrTable= IPRIP_IF_UNICAST_PEER_TABLE( piic );
  2284. FIND_PEER_ENTRY(
  2285. dwPeerAddr,
  2286. piic-> IC_UnicastPeerCount,
  2287. pdwAddrTable,
  2288. dwInd
  2289. );
  2290. //
  2291. // if operation is filter add
  2292. //
  2293. if ( dwOp == d_Tag_create )
  2294. {
  2295. //
  2296. // if peer already present, quit
  2297. //
  2298. if ( piic-> IC_UnicastPeerCount &&
  2299. dwInd < piic-> IC_UnicastPeerCount )
  2300. {
  2301. dwRes = MIB_S_SUCCESS;
  2302. break;
  2303. }
  2304. else
  2305. {
  2306. dwRes = AddUnicastPeerEntry(
  2307. dwPeerAddr,
  2308. pimgodOutData
  2309. );
  2310. }
  2311. break;
  2312. }
  2313. //
  2314. // operation is filter delete
  2315. //
  2316. //
  2317. // if peer is not present quit.
  2318. //
  2319. if ( !piic-> IC_UnicastPeerCount ||
  2320. dwInd >= piic-> IC_UnicastPeerCount )
  2321. {
  2322. dwRes = MIB_S_SUCCESS;
  2323. break;
  2324. }
  2325. dwRes = DeleteUnicastPeerEntry(
  2326. dwInd,
  2327. pimgodOutData
  2328. );
  2329. } while ( FALSE );
  2330. if ( pimgodOutData ) { MprAdminMIBBufferFree( pimgodOutData ); }
  2331. return dwRes;
  2332. }
  2333. DWORD
  2334. AddUnicastPeerEntry(
  2335. IN DWORD dwPeer,
  2336. IN PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData
  2337. )
  2338. {
  2339. DWORD dwRes = (DWORD) -1,
  2340. dwSetSize = 0;
  2341. PDWORD pdwAddrTable = NULL;
  2342. PIPRIP_IF_CONFIG piicOld = NULL,
  2343. piicNew = NULL;
  2344. PIPRIP_MIB_SET_INPUT_DATA pimsid = NULL;
  2345. do
  2346. {
  2347. //
  2348. // Allocate new info block
  2349. //
  2350. piicOld = (PIPRIP_IF_CONFIG) pimgodOutData-> IMGOD_Buffer;
  2351. dwSetSize = sizeof( IPRIP_MIB_SET_INPUT_DATA ) - 1 +
  2352. IPRIP_IF_CONFIG_SIZE( piicOld ) + sizeof( DWORD );
  2353. pimsid = (PIPRIP_MIB_SET_INPUT_DATA) RIP_MIB_ALLOC( dwSetSize );
  2354. if ( pimsid == NULL )
  2355. {
  2356. dwRes = ERROR_NOT_ENOUGH_MEMORY;
  2357. TRACE0 ( "Memory allocation failed" );
  2358. break;
  2359. }
  2360. //
  2361. // Add unicast peer
  2362. //
  2363. pimsid-> IMSID_TypeID = IPRIP_IF_CONFIG_ID;
  2364. pimsid-> IMSID_IfIndex = pimgodOutData-> IMGOD_IfIndex;
  2365. pimsid-> IMSID_BufferSize = IPRIP_IF_CONFIG_SIZE( piicOld ) +
  2366. sizeof( DWORD );
  2367. piicNew = (PIPRIP_IF_CONFIG) pimsid-> IMSID_Buffer;
  2368. CopyMemory(
  2369. (PVOID) piicNew,
  2370. (VOID *) piicOld,
  2371. sizeof( IPRIP_IF_CONFIG ) +
  2372. piicOld-> IC_UnicastPeerCount * sizeof( DWORD )
  2373. );
  2374. pdwAddrTable = IPRIP_IF_UNICAST_PEER_TABLE( piicNew );
  2375. pdwAddrTable[ piicNew-> IC_UnicastPeerCount ] = dwPeer;
  2376. piicNew-> IC_UnicastPeerCount++;
  2377. //
  2378. // Copy Filters
  2379. //
  2380. CopyMemory(
  2381. (PVOID) IPRIP_IF_ACCEPT_FILTER_TABLE( piicNew ),
  2382. (VOID *) IPRIP_IF_ACCEPT_FILTER_TABLE( piicOld ),
  2383. piicOld-> IC_AcceptFilterCount * sizeof ( IPRIP_ROUTE_FILTER )
  2384. );
  2385. CopyMemory(
  2386. (PVOID) IPRIP_IF_ANNOUNCE_FILTER_TABLE( piicNew ),
  2387. (VOID *) IPRIP_IF_ANNOUNCE_FILTER_TABLE( piicOld ),
  2388. piicOld-> IC_AnnounceFilterCount * sizeof ( IPRIP_ROUTE_FILTER )
  2389. );
  2390. //
  2391. // Set info. in MIB
  2392. //
  2393. RIP_MIB_SET(
  2394. pimsid,
  2395. dwSetSize,
  2396. dwRes
  2397. );
  2398. } while ( FALSE );
  2399. if ( pimsid ) { RIP_MIB_FREE( pimsid ); }
  2400. return dwRes;
  2401. }
  2402. DWORD
  2403. DeleteUnicastPeerEntry(
  2404. IN DWORD dwIndex,
  2405. IN PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData
  2406. )
  2407. {
  2408. DWORD dwRes = (DWORD) -1,
  2409. dwSetSize = 0;
  2410. PDWORD pdwSrc = NULL,
  2411. pdwDst = NULL;
  2412. PIPRIP_IF_CONFIG piicOld = NULL,
  2413. piicNew = NULL;
  2414. PIPRIP_MIB_SET_INPUT_DATA pimsid = NULL;
  2415. do
  2416. {
  2417. //
  2418. // Compute size of new interface config
  2419. //
  2420. piicOld = (PIPRIP_IF_CONFIG) pimgodOutData-> IMGOD_Buffer;
  2421. dwSetSize = sizeof( IPRIP_MIB_SET_INPUT_DATA ) - 1 +
  2422. IPRIP_IF_CONFIG_SIZE( piicOld ) - sizeof ( DWORD );
  2423. pimsid = (PIPRIP_MIB_SET_INPUT_DATA) RIP_MIB_ALLOC( dwSetSize );
  2424. if ( pimsid == NULL )
  2425. {
  2426. dwRes = ERROR_NOT_ENOUGH_MEMORY;
  2427. TRACE0( "Memory Allocation Failed" );
  2428. break;
  2429. }
  2430. pimsid-> IMSID_TypeID = IPRIP_GLOBAL_CONFIG_ID;
  2431. pimsid-> IMSID_IfIndex = pimgodOutData-> IMGOD_IfIndex;
  2432. pimsid-> IMSID_BufferSize = IPRIP_IF_CONFIG_SIZE( piicOld ) -
  2433. sizeof( DWORD );
  2434. piicNew = (PIPRIP_IF_CONFIG) pimsid-> IMSID_Buffer;
  2435. //
  2436. // Copy base config info.
  2437. //
  2438. CopyMemory(
  2439. (PVOID) piicNew,
  2440. (VOID *) piicOld,
  2441. sizeof( IPRIP_IF_CONFIG )
  2442. );
  2443. //
  2444. // Delete specified peer
  2445. //
  2446. pdwSrc = IPRIP_IF_UNICAST_PEER_TABLE( piicOld );
  2447. pdwDst = IPRIP_IF_UNICAST_PEER_TABLE( piicNew );
  2448. DELETE_PEER_ENTRY(
  2449. dwIndex,
  2450. piicOld-> IC_UnicastPeerCount,
  2451. pdwSrc,
  2452. pdwDst
  2453. );
  2454. piicNew-> IC_UnicastPeerCount--;
  2455. //
  2456. // Copy filters
  2457. //
  2458. CopyMemory(
  2459. (PVOID) IPRIP_IF_ACCEPT_FILTER_TABLE( piicNew ),
  2460. (VOID *) IPRIP_IF_ACCEPT_FILTER_TABLE( piicOld ),
  2461. piicOld-> IC_AcceptFilterCount * sizeof ( IPRIP_ROUTE_FILTER )
  2462. );
  2463. CopyMemory(
  2464. (PVOID) IPRIP_IF_ANNOUNCE_FILTER_TABLE( piicNew ),
  2465. (VOID *) IPRIP_IF_ANNOUNCE_FILTER_TABLE( piicOld ),
  2466. piicOld-> IC_AnnounceFilterCount * sizeof ( IPRIP_ROUTE_FILTER )
  2467. );
  2468. //
  2469. // Set info. in MIB
  2470. //
  2471. RIP_MIB_SET(
  2472. pimsid,
  2473. dwSetSize,
  2474. dwRes
  2475. );
  2476. } while ( FALSE );
  2477. if ( pimsid ) { RIP_MIB_FREE( pimsid ); }
  2478. return dwRes;
  2479. }
  2480. DWORD
  2481. UpdateFilterTable(
  2482. IN DWORD dwOp,
  2483. IN DWORD dwIfIndex,
  2484. IN DWORD dwFiltType,
  2485. IN PIPRIP_ROUTE_FILTER pirfFilt
  2486. )
  2487. {
  2488. DWORD dwRes = (DWORD) -1,
  2489. dwGetSize = 0,
  2490. dwIndex = (DWORD) -1,
  2491. dwCount = 0;
  2492. PIPRIP_IF_CONFIG piic = NULL;
  2493. PIPRIP_ROUTE_FILTER pirfLst = NULL;
  2494. PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData = NULL;
  2495. IPRIP_MIB_GET_INPUT_DATA imgidInData;
  2496. do
  2497. {
  2498. imgidInData.IMGID_TypeID = IPRIP_GLOBAL_CONFIG_ID;
  2499. imgidInData.IMGID_IfIndex = dwIfIndex;
  2500. dwRes = GetInterfaceInfo(
  2501. MIB_ACTION_GET,
  2502. &imgidInData,
  2503. &pimgodOutData,
  2504. &dwGetSize
  2505. );
  2506. if ( dwRes != NO_ERROR )
  2507. {
  2508. TraceError( dwRes );
  2509. break;
  2510. }
  2511. //
  2512. // find filter
  2513. //
  2514. piic = (PIPRIP_IF_CONFIG) pimgodOutData-> IMGOD_Buffer;
  2515. if ( dwFiltType == RIP_MIB_ACCEPT_FILTER )
  2516. {
  2517. dwCount = piic-> IC_AcceptFilterCount;
  2518. pirfLst = IPRIP_IF_ACCEPT_FILTER_TABLE( piic );
  2519. }
  2520. else
  2521. {
  2522. dwCount = piic-> IC_AnnounceFilterCount;
  2523. pirfLst = IPRIP_IF_ANNOUNCE_FILTER_TABLE( piic );
  2524. }
  2525. FIND_FILTER(
  2526. pirfFilt,
  2527. dwCount,
  2528. pirfLst,
  2529. dwIndex
  2530. );
  2531. if ( dwOp == d_Tag_create )
  2532. {
  2533. //
  2534. // check if filter is already present
  2535. //
  2536. if ( dwCount && dwIndex < dwCount )
  2537. {
  2538. dwRes = MIB_S_SUCCESS;
  2539. break;
  2540. }
  2541. dwRes = AddFilterEntry(
  2542. dwFiltType,
  2543. pirfFilt,
  2544. pimgodOutData
  2545. );
  2546. break;
  2547. }
  2548. //
  2549. // Must be a delete operation
  2550. //
  2551. if ( !dwCount || dwIndex >= dwCount )
  2552. {
  2553. dwRes = MIB_S_SUCCESS;
  2554. break;
  2555. }
  2556. dwRes = DeleteFilterEntry(
  2557. dwFiltType,
  2558. dwIndex,
  2559. pimgodOutData
  2560. );
  2561. } while ( FALSE );
  2562. if ( pimgodOutData ) { MprAdminMIBBufferFree( pimgodOutData ); }
  2563. return dwRes;
  2564. }
  2565. DWORD
  2566. AddFilterEntry(
  2567. IN DWORD dwFiltType,
  2568. IN PIPRIP_ROUTE_FILTER pirfFilt,
  2569. IN PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData
  2570. )
  2571. {
  2572. DWORD dwRes = (DWORD) -1,
  2573. dwSetSize = 0,
  2574. dwIndex = (DWORD) -1,
  2575. dwCount = 0;
  2576. PIPRIP_IF_CONFIG piicOld = NULL,
  2577. piicNew = NULL;
  2578. PIPRIP_ROUTE_FILTER pirfLst = NULL;
  2579. PIPRIP_MIB_SET_INPUT_DATA pimsid = NULL;
  2580. do
  2581. {
  2582. //
  2583. // Compute size of new config and allocate block for it.
  2584. //
  2585. piicOld = (PIPRIP_IF_CONFIG) pimgodOutData-> IMGOD_Buffer;
  2586. dwSetSize = sizeof( IPRIP_MIB_SET_INPUT_DATA ) - 1 +
  2587. IPRIP_IF_CONFIG_SIZE( piicOld) +
  2588. sizeof( IPRIP_ROUTE_FILTER );
  2589. pimsid = (PIPRIP_MIB_SET_INPUT_DATA) RIP_MIB_ALLOC( dwSetSize );
  2590. if ( pimsid == NULL )
  2591. {
  2592. dwRes = ERROR_NOT_ENOUGH_MEMORY;
  2593. TRACE0( "Memory Allocation Failed" );
  2594. break;
  2595. }
  2596. //
  2597. // set up the new config block.
  2598. //
  2599. pimsid-> IMSID_TypeID = IPRIP_IF_CONFIG_ID;
  2600. pimsid-> IMSID_IfIndex = pimgodOutData-> IMGOD_IfIndex;
  2601. pimsid-> IMSID_BufferSize = IPRIP_IF_CONFIG_SIZE( piicOld ) +
  2602. sizeof( DWORD );
  2603. piicNew = (PIPRIP_IF_CONFIG) pimsid-> IMSID_Buffer;
  2604. CopyMemory(
  2605. (PVOID) piicNew,
  2606. (VOID *) piicOld,
  2607. sizeof( IPRIP_IF_CONFIG ) +
  2608. piicOld-> IC_UnicastPeerCount * sizeof( DWORD ) +
  2609. piicOld-> IC_AcceptFilterCount * sizeof ( IPRIP_ROUTE_FILTER )
  2610. );
  2611. //
  2612. // if accept filter is being added, added to end of
  2613. // accept fitler table, and copy the annouce filters
  2614. //
  2615. if ( dwFiltType == RIP_MIB_ACCEPT_FILTER )
  2616. {
  2617. pirfLst = IPRIP_IF_ACCEPT_FILTER_TABLE( piicNew );
  2618. pirfLst[ piicNew-> IC_AcceptFilterCount++ ] = *pirfFilt;
  2619. CopyMemory(
  2620. (PVOID) IPRIP_IF_ANNOUNCE_FILTER_TABLE( piicNew ),
  2621. (VOID *) IPRIP_IF_ANNOUNCE_FILTER_TABLE( piicOld ),
  2622. piicNew-> IC_AnnounceFilterCount * sizeof( IPRIP_ROUTE_FILTER )
  2623. );
  2624. }
  2625. else
  2626. {
  2627. CopyMemory(
  2628. (PVOID) IPRIP_IF_ANNOUNCE_FILTER_TABLE( piicNew ),
  2629. (VOID *) IPRIP_IF_ANNOUNCE_FILTER_TABLE( piicOld ),
  2630. piicNew-> IC_AnnounceFilterCount * sizeof( IPRIP_ROUTE_FILTER )
  2631. );
  2632. pirfLst = IPRIP_IF_ANNOUNCE_FILTER_TABLE( piicNew );
  2633. pirfLst[ piicNew-> IC_AnnounceFilterCount++ ] = *pirfFilt;
  2634. }
  2635. //
  2636. // Update the MIB with the new config
  2637. //
  2638. RIP_MIB_SET( pimsid, dwSetSize, dwRes );
  2639. if ( dwRes != NO_ERROR )
  2640. {
  2641. TraceError( dwRes );
  2642. }
  2643. } while ( FALSE );
  2644. if ( pimsid ) { RIP_MIB_FREE( pimsid ); }
  2645. return dwRes;
  2646. }
  2647. DWORD
  2648. DeleteFilterEntry(
  2649. IN DWORD dwFiltType,
  2650. IN DWORD dwIndex,
  2651. IN PIPRIP_MIB_GET_OUTPUT_DATA pimgodOutData
  2652. )
  2653. {
  2654. DWORD dwRes = (DWORD) -1,
  2655. dwSetSize = 0,
  2656. dwCount = 0;
  2657. PIPRIP_IF_CONFIG piicOld = NULL,
  2658. piicNew = NULL;
  2659. PIPRIP_ROUTE_FILTER pirfSrc = NULL,
  2660. pirfDst = NULL;
  2661. PIPRIP_MIB_SET_INPUT_DATA pimsid = NULL;
  2662. do
  2663. {
  2664. //
  2665. // Compute size of new config and allocate block for it.
  2666. //
  2667. piicOld = (PIPRIP_IF_CONFIG) pimgodOutData-> IMGOD_Buffer;
  2668. dwSetSize = sizeof( IPRIP_MIB_SET_INPUT_DATA ) - 1 +
  2669. IPRIP_IF_CONFIG_SIZE( piicOld ) -
  2670. sizeof( IPRIP_ROUTE_FILTER );
  2671. pimsid = (PIPRIP_MIB_SET_INPUT_DATA) RIP_MIB_ALLOC( dwSetSize );
  2672. if ( pimsid == NULL )
  2673. {
  2674. dwRes = ERROR_NOT_ENOUGH_MEMORY;
  2675. TRACE0( "Memory Allocation Failed" );
  2676. break;
  2677. }
  2678. //
  2679. // set up the new config block.
  2680. //
  2681. pimsid-> IMSID_TypeID = IPRIP_IF_CONFIG_ID;
  2682. pimsid-> IMSID_IfIndex = pimgodOutData-> IMGOD_IfIndex;
  2683. pimsid-> IMSID_BufferSize = IPRIP_IF_CONFIG_SIZE( piicOld ) +
  2684. sizeof( DWORD );
  2685. piicNew = (PIPRIP_IF_CONFIG) pimsid-> IMSID_Buffer;
  2686. CopyMemory(
  2687. (PVOID) piicNew,
  2688. (VOID *) piicOld,
  2689. sizeof( IPRIP_IF_CONFIG ) +
  2690. piicOld-> IC_UnicastPeerCount * sizeof( DWORD )
  2691. );
  2692. if ( dwFiltType == RIP_MIB_ACCEPT_FILTER )
  2693. {
  2694. pirfSrc = IPRIP_IF_ACCEPT_FILTER_TABLE( piicOld );
  2695. pirfDst = IPRIP_IF_ACCEPT_FILTER_TABLE( piicNew );
  2696. DELETE_FILTER(
  2697. dwIndex,
  2698. piicOld-> IC_AcceptFilterCount,
  2699. pirfSrc,
  2700. pirfDst
  2701. );
  2702. piicNew-> IC_AcceptFilterCount--;
  2703. CopyMemory(
  2704. (PVOID) IPRIP_IF_ANNOUNCE_FILTER_TABLE( piicNew ),
  2705. (VOID *) IPRIP_IF_ANNOUNCE_FILTER_TABLE( piicOld ),
  2706. piicNew-> IC_AnnounceFilterCount * sizeof( IPRIP_ROUTE_FILTER )
  2707. );
  2708. }
  2709. else
  2710. {
  2711. CopyMemory(
  2712. (PVOID) IPRIP_IF_ACCEPT_FILTER_TABLE( piicNew ),
  2713. (VOID *) IPRIP_IF_ACCEPT_FILTER_TABLE( piicOld ),
  2714. piicNew-> IC_AcceptFilterCount * sizeof( IPRIP_ROUTE_FILTER )
  2715. );
  2716. pirfSrc = IPRIP_IF_ACCEPT_FILTER_TABLE( piicOld );
  2717. pirfDst = IPRIP_IF_ACCEPT_FILTER_TABLE( piicNew );
  2718. DELETE_FILTER(
  2719. dwIndex,
  2720. piicOld-> IC_AnnounceFilterCount,
  2721. pirfSrc,
  2722. pirfDst
  2723. );
  2724. piicNew-> IC_AnnounceFilterCount--;
  2725. }
  2726. RIP_MIB_SET( pimsid, dwSetSize, dwRes );
  2727. if ( dwRes != NO_ERROR )
  2728. {
  2729. TraceError( dwRes );
  2730. }
  2731. } while ( FALSE );
  2732. if ( pimsid ) { RIP_MIB_FREE( pimsid ); }
  2733. return dwRes;
  2734. }
  2735. DWORD
  2736. ConnectToRouter()
  2737. {
  2738. DWORD dwRes = (DWORD) -1;
  2739. EnterCriticalSection( &g_CS );
  2740. do
  2741. {
  2742. MPR_SERVER_HANDLE hTmp;
  2743. if ( g_hMIBServer )
  2744. {
  2745. dwRes = NO_ERROR;
  2746. break;
  2747. }
  2748. dwRes = MprAdminMIBServerConnect( NULL, &hTmp );
  2749. if ( dwRes == NO_ERROR )
  2750. {
  2751. InterlockedExchangePointer(&g_hMIBServer, hTmp );
  2752. }
  2753. else
  2754. {
  2755. TRACE1(
  2756. "Error %d setting up DIM connection to MIB Server\n",
  2757. dwRes
  2758. );
  2759. }
  2760. } while ( FALSE );
  2761. LeaveCriticalSection( &g_CS );
  2762. return dwRes;
  2763. }