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

375 lines
7.2 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. mibif.c
  5. Abstract:
  6. The IPX MIB Base and Interface Functions
  7. Author:
  8. Stefan Solomon 03/22/1995
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. /*++
  14. Function: MibGetIpxBase
  15. Descr:
  16. --*/
  17. DWORD
  18. MibGetIpxBase(PIPX_MIB_INDEX mip,
  19. PIPXMIB_BASE BaseEntryp,
  20. PULONG BaseEntrySize)
  21. {
  22. PICB icbp;
  23. PACB acbp;
  24. if((BaseEntryp == NULL) || (*BaseEntrySize < sizeof(IPXMIB_BASE))) {
  25. *BaseEntrySize = sizeof(IPXMIB_BASE);
  26. return ERROR_INSUFFICIENT_BUFFER;
  27. }
  28. ACQUIRE_DATABASE_LOCK;
  29. BaseEntryp->OperState = OPER_STATE_UP;
  30. // Router is Up -> check that we have the internal interface bound to the
  31. // internal adapter.
  32. if((InternalInterfacep == NULL) || (InternalAdapterp == NULL)) {
  33. RELEASE_DATABASE_LOCK;
  34. return ERROR_CAN_NOT_COMPLETE;
  35. }
  36. icbp = InternalInterfacep;
  37. acbp = icbp->acbp;
  38. memcpy(BaseEntryp->PrimaryNetNumber,
  39. acbp->AdapterInfo.Network,
  40. 4);
  41. memcpy(BaseEntryp->Node,
  42. acbp->AdapterInfo.LocalNode,
  43. 6);
  44. GetInterfaceAnsiName(BaseEntryp->SysName, icbp->InterfaceNamep);
  45. BaseEntryp->MaxPathSplits = 1;
  46. BaseEntryp->IfCount = InterfaceCount;
  47. // fill in the dest count
  48. BaseEntryp->DestCount = RtmGetNetworkCount(RTM_PROTOCOL_FAMILY_IPX);
  49. // fill in the services count
  50. BaseEntryp->ServCount = GetServiceCount();
  51. RELEASE_DATABASE_LOCK;
  52. return NO_ERROR;
  53. }
  54. VOID
  55. GetMibInterface(PICB icbp,
  56. PIPX_INTERFACE Ifp);
  57. /*++
  58. Function: MibGetIpxInterface
  59. Descr:
  60. --*/
  61. DWORD
  62. MibGetIpxInterface(PIPX_MIB_INDEX mip,
  63. PIPX_INTERFACE Ifp,
  64. PULONG IfSize)
  65. {
  66. PICB icbp;
  67. if((Ifp == NULL) || (*IfSize < sizeof(IPX_INTERFACE))) {
  68. *IfSize = sizeof(IPX_INTERFACE);
  69. return ERROR_INSUFFICIENT_BUFFER;
  70. }
  71. Ifp->InterfaceIndex = mip->InterfaceTableIndex.InterfaceIndex;
  72. ACQUIRE_DATABASE_LOCK;
  73. if((icbp = GetInterfaceByIndex(Ifp->InterfaceIndex)) == NULL) {
  74. RELEASE_DATABASE_LOCK;
  75. return ERROR_INVALID_PARAMETER;
  76. }
  77. GetMibInterface(icbp, Ifp);
  78. RELEASE_DATABASE_LOCK;
  79. return NO_ERROR;
  80. }
  81. /*++
  82. Function: MibGetFirstIpxInterface
  83. Descr:
  84. --*/
  85. DWORD
  86. MibGetFirstIpxInterface(PIPX_MIB_INDEX mip,
  87. PIPX_INTERFACE Ifp,
  88. PULONG IfSize)
  89. {
  90. PICB icbp;
  91. if((Ifp == NULL) || (*IfSize < sizeof(IPX_INTERFACE))) {
  92. *IfSize = sizeof(IPX_INTERFACE);
  93. return ERROR_INSUFFICIENT_BUFFER;
  94. }
  95. ACQUIRE_DATABASE_LOCK;
  96. if(IsListEmpty(&IndexIfList)) {
  97. RELEASE_DATABASE_LOCK;
  98. return ERROR_CAN_NOT_COMPLETE;
  99. }
  100. icbp = CONTAINING_RECORD(IndexIfList.Flink, ICB, IndexListLinkage);
  101. GetMibInterface(icbp, Ifp);
  102. RELEASE_DATABASE_LOCK;
  103. return NO_ERROR;
  104. }
  105. /*++
  106. Function: MibGetNextIpxInterface
  107. Descr:
  108. --*/
  109. DWORD
  110. MibGetNextIpxInterface(PIPX_MIB_INDEX mip,
  111. PIPX_INTERFACE Ifp,
  112. PULONG IfSize)
  113. {
  114. PICB icbp;
  115. PLIST_ENTRY lep;
  116. if((Ifp == NULL) || (*IfSize < sizeof(IPX_INTERFACE))) {
  117. *IfSize = sizeof(IPX_INTERFACE);
  118. return ERROR_INSUFFICIENT_BUFFER;
  119. }
  120. Ifp->InterfaceIndex = mip->InterfaceTableIndex.InterfaceIndex;
  121. // scan the ordered interface list until we get to this interface or to
  122. // an interface with a higher index (meaning this interface has been removed)
  123. ACQUIRE_DATABASE_LOCK;
  124. lep = IndexIfList.Flink;
  125. while(lep != &IndexIfList) {
  126. icbp = CONTAINING_RECORD(lep, ICB, IndexListLinkage);
  127. if(Ifp->InterfaceIndex == icbp->InterfaceIndex) {
  128. // found, get the next interface and return
  129. if(icbp->IndexListLinkage.Flink == &IndexIfList) {
  130. // this was the last entry in the list, stop here
  131. RELEASE_DATABASE_LOCK;
  132. return ERROR_NO_MORE_ITEMS;
  133. }
  134. icbp = CONTAINING_RECORD(icbp->IndexListLinkage.Flink,
  135. ICB,
  136. IndexListLinkage);
  137. GetMibInterface(icbp, Ifp);
  138. RELEASE_DATABASE_LOCK;
  139. return NO_ERROR;
  140. }
  141. if(Ifp->InterfaceIndex < icbp->InterfaceIndex) {
  142. // the interface has been removed. We return the next interface
  143. // in the index order
  144. GetMibInterface(icbp, Ifp);
  145. RELEASE_DATABASE_LOCK;
  146. return NO_ERROR;
  147. }
  148. else
  149. {
  150. lep = icbp->IndexListLinkage.Flink;
  151. }
  152. }
  153. // didn't find anything
  154. RELEASE_DATABASE_LOCK;
  155. return ERROR_NO_MORE_ITEMS;
  156. }
  157. /*++
  158. Function: MibSetIpxInterface
  159. Descr: The SNMP manager can set the following parameters on an interface:
  160. - AdminState
  161. - NetbiosAccept
  162. - NetbiosDeliver
  163. --*/
  164. DWORD
  165. MibSetIpxInterface(PIPX_MIB_ROW MibRowp)
  166. {
  167. PIPX_INTERFACE Ifp;
  168. FW_IF_INFO FwIfInfo;
  169. PICB icbp;
  170. Ifp = &MibRowp->Interface;
  171. ACQUIRE_DATABASE_LOCK;
  172. if((icbp = GetInterfaceByIndex(Ifp->InterfaceIndex)) == NULL) {
  173. RELEASE_DATABASE_LOCK;
  174. return ERROR_INVALID_PARAMETER;
  175. }
  176. // set the new states in the forwarder
  177. FwIfInfo.NetbiosAccept = Ifp->NetbiosAccept;
  178. FwIfInfo.NetbiosDeliver = Ifp->NetbiosDeliver;
  179. FwSetInterface(icbp->InterfaceIndex, &FwIfInfo);
  180. // if the current admin state doesn't match the new admin state, set the
  181. // new admin state.
  182. if(icbp->AdminState != Ifp->AdminState) {
  183. if(Ifp->AdminState == ADMIN_STATE_ENABLED) {
  184. AdminEnable(icbp);
  185. }
  186. else
  187. {
  188. AdminDisable(icbp);
  189. }
  190. }
  191. RELEASE_DATABASE_LOCK;
  192. return NO_ERROR;
  193. }
  194. /*++
  195. Function: GetMibInterface
  196. Descr: Gets the ipx mib interface data from the router manager
  197. data structures.
  198. Remark: Called only in critical section
  199. --*/
  200. VOID
  201. GetMibInterface(PICB icbp,
  202. PIPX_INTERFACE Ifp)
  203. {
  204. PACB acbp;
  205. FW_IF_INFO FwIfInfo;
  206. Ifp->InterfaceIndex = icbp->InterfaceIndex;
  207. // get the forwarder interface data
  208. FwGetInterface(icbp->InterfaceIndex,
  209. &FwIfInfo,
  210. &Ifp->IfStats);
  211. Ifp->AdminState = icbp->AdminState;
  212. Ifp->IfStats.IfOperState = icbp->OperState;
  213. Ifp->NetbiosAccept = FwIfInfo.NetbiosAccept;
  214. Ifp->NetbiosDeliver = FwIfInfo.NetbiosDeliver;
  215. // fill in the rest from the icb
  216. if(icbp->acbp) {
  217. acbp = icbp->acbp;
  218. Ifp->AdapterIndex = acbp->AdapterIndex;
  219. Ifp->MediaType = acbp->AdapterInfo.NdisMedium;
  220. if (Ifp->IfStats.IfOperState==OPER_STATE_UP) {
  221. memcpy(Ifp->NetNumber, acbp->AdapterInfo.Network, 4);
  222. memcpy(Ifp->MacAddress, acbp->AdapterInfo.LocalNode, 6);
  223. if (acbp->AdapterInfo.LinkSpeed>0) {
  224. ULONGLONG speed = 100i64*acbp->AdapterInfo.LinkSpeed;
  225. if (speed<MAXLONG)
  226. Ifp->Throughput = (ULONG)speed;
  227. else
  228. Ifp->Throughput = MAXLONG;
  229. Ifp->Delay = (ULONG)(8000000i64/speed);
  230. }
  231. else {
  232. Ifp->Delay = 0;
  233. Ifp->Throughput = 0;
  234. }
  235. }
  236. else {
  237. memset(Ifp->NetNumber, 0 ,4);
  238. memset(Ifp->MacAddress, 0, 4);
  239. Ifp->Delay = 0;
  240. Ifp->Throughput = 0;
  241. }
  242. // !!! fill in delay and throughput from link speed
  243. }
  244. else
  245. {
  246. Ifp->AdapterIndex = 0;
  247. Ifp->MediaType = 0;
  248. memset(Ifp->NetNumber, 0 ,4);
  249. memset(Ifp->MacAddress, 0, 4);
  250. Ifp->Delay = 0;
  251. Ifp->Throughput = 0;
  252. }
  253. GetInterfaceAnsiName(Ifp->InterfaceName, icbp->InterfaceNamep);
  254. Ifp->InterfaceType = icbp->MIBInterfaceType;
  255. Ifp->EnableIpxWanNegotiation = icbp->EnableIpxWanNegotiation;
  256. }