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.

392 lines
6.8 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. mib.c
  5. Abstract:
  6. The MIB handling functions
  7. Author:
  8. Stefan Solomon 03/22/1995
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. #define MIB_CALL_BEGIN {\
  14. ACQUIRE_DATABASE_LOCK;\
  15. if(RouterOperState != OPER_STATE_UP){\
  16. RELEASE_DATABASE_LOCK;\
  17. return ERROR_CAN_NOT_COMPLETE;\
  18. }\
  19. MibRefCounter++;\
  20. RELEASE_DATABASE_LOCK;\
  21. };
  22. #define MIB_CALL_END {\
  23. ACQUIRE_DATABASE_LOCK;\
  24. MibRefCounter--;\
  25. RELEASE_DATABASE_LOCK;\
  26. return rc;\
  27. };
  28. DWORD
  29. MibInvalidFunction(LPVOID p)
  30. {
  31. return ERROR_INVALID_FUNCTION;
  32. }
  33. typedef DWORD (*IPX_MIB_SET_HANDLER)(LPVOID);
  34. typedef DWORD (*IPX_MIB_GET_HANDLER)(LPVOID, LPVOID, PULONG);
  35. IPX_MIB_SET_HANDLER IpxMibCreate[MAX_IPX_MIB_TABLES] = {
  36. MibInvalidFunction, // Create Base
  37. MibInvalidFunction, // CreateInterface
  38. MibInvalidFunction, // Create Route
  39. MibCreateStaticRoute,
  40. MibInvalidFunction, // Create Service
  41. MibCreateStaticService
  42. };
  43. DWORD
  44. MibCreate(ULONG ProtocolId,
  45. ULONG InputDataSize,
  46. PVOID InputData)
  47. {
  48. PIPX_MIB_SET_INPUT_DATA msip;
  49. PRPCB rpcbp;
  50. DWORD rc;
  51. MIB_CALL_BEGIN;
  52. if(ProtocolId == IPX_PROTOCOL_BASE) {
  53. if(InputDataSize != sizeof(IPX_MIB_SET_INPUT_DATA)) {
  54. rc = ERROR_CAN_NOT_COMPLETE;
  55. goto Exit;
  56. }
  57. msip = (PIPX_MIB_SET_INPUT_DATA)InputData;
  58. rc = (*IpxMibCreate[msip->TableId])(&msip->MibRow);
  59. }
  60. else
  61. {
  62. // to be routed to one of our routing protocols
  63. if((rpcbp = GetRoutingProtocolCB(ProtocolId)) == NULL) {
  64. rc = ERROR_CAN_NOT_COMPLETE;
  65. goto Exit;
  66. }
  67. rc = (*rpcbp->RP_MibCreate)(InputDataSize, InputData);
  68. }
  69. Exit:
  70. MIB_CALL_END;
  71. return rc;
  72. }
  73. IPX_MIB_SET_HANDLER IpxMibDelete[MAX_IPX_MIB_TABLES] = {
  74. MibInvalidFunction, // Delete Base
  75. MibInvalidFunction, // DeleteInterface
  76. MibInvalidFunction, // Delete Route
  77. MibDeleteStaticRoute,
  78. MibInvalidFunction, // Delete Service
  79. MibDeleteStaticService
  80. };
  81. DWORD
  82. MibDelete(ULONG ProtocolId,
  83. ULONG InputDataSize,
  84. PVOID InputData)
  85. {
  86. PIPX_MIB_SET_INPUT_DATA msip;
  87. PRPCB rpcbp;
  88. DWORD rc;
  89. MIB_CALL_BEGIN;
  90. if(ProtocolId == IPX_PROTOCOL_BASE) {
  91. if(InputDataSize != sizeof(IPX_MIB_SET_INPUT_DATA)) {
  92. rc = ERROR_CAN_NOT_COMPLETE;
  93. goto Exit;
  94. }
  95. msip = (PIPX_MIB_SET_INPUT_DATA)InputData;
  96. rc = (*IpxMibDelete[msip->TableId])(&msip->MibRow);
  97. }
  98. else
  99. {
  100. // to be routed to one of our routing protocols
  101. if((rpcbp = GetRoutingProtocolCB(ProtocolId)) == NULL) {
  102. rc = ERROR_CAN_NOT_COMPLETE;
  103. goto Exit;
  104. }
  105. rc = (*rpcbp->RP_MibDelete)(InputDataSize, InputData);
  106. }
  107. Exit:
  108. MIB_CALL_END;
  109. return rc;
  110. }
  111. IPX_MIB_SET_HANDLER IpxMibSet[MAX_IPX_MIB_TABLES] = {
  112. MibInvalidFunction, // Set Base
  113. MibSetIpxInterface, // SetInterface
  114. MibInvalidFunction, // Set Route
  115. MibSetStaticRoute,
  116. MibInvalidFunction, // Set Service
  117. MibSetStaticService
  118. };
  119. DWORD
  120. MibSet(ULONG ProtocolId,
  121. ULONG InputDataSize,
  122. PVOID InputData)
  123. {
  124. PIPX_MIB_SET_INPUT_DATA msip;
  125. PRPCB rpcbp;
  126. DWORD rc;
  127. MIB_CALL_BEGIN;
  128. if(ProtocolId == IPX_PROTOCOL_BASE) {
  129. if(InputDataSize != sizeof(IPX_MIB_SET_INPUT_DATA)) {
  130. rc = ERROR_CAN_NOT_COMPLETE;
  131. goto Exit;
  132. }
  133. msip = (PIPX_MIB_SET_INPUT_DATA)InputData;
  134. rc = (*IpxMibSet[msip->TableId])(&msip->MibRow);
  135. }
  136. else
  137. {
  138. // to be routed to one of our routing protocols
  139. if((rpcbp = GetRoutingProtocolCB(ProtocolId)) == NULL) {
  140. rc = ERROR_CAN_NOT_COMPLETE;
  141. goto Exit;
  142. }
  143. rc = (*rpcbp->RP_MibSet)(InputDataSize, InputData);
  144. }
  145. Exit:
  146. MIB_CALL_END;
  147. return rc;
  148. }
  149. IPX_MIB_GET_HANDLER IpxMibGet[MAX_IPX_MIB_TABLES] = {
  150. MibGetIpxBase,
  151. MibGetIpxInterface,
  152. MibGetRoute,
  153. MibGetStaticRoute,
  154. MibGetService,
  155. MibGetStaticService
  156. };
  157. DWORD
  158. MibGet(ULONG ProtocolId,
  159. ULONG InputDataSize,
  160. PVOID InputData,
  161. PULONG OutputDataSize,
  162. PVOID OutputData)
  163. {
  164. PIPX_MIB_GET_INPUT_DATA mgip;
  165. PRPCB rpcbp;
  166. DWORD rc;
  167. MIB_CALL_BEGIN;
  168. if(ProtocolId == IPX_PROTOCOL_BASE) {
  169. if(InputDataSize != sizeof(IPX_MIB_GET_INPUT_DATA)) {
  170. rc = ERROR_CAN_NOT_COMPLETE;
  171. goto Exit;
  172. }
  173. mgip = (PIPX_MIB_GET_INPUT_DATA)InputData;
  174. rc = (*IpxMibGet[mgip->TableId])(&mgip->MibIndex,
  175. OutputData,
  176. OutputDataSize);
  177. }
  178. else
  179. {
  180. // to be demux to one of our routing protocols
  181. if((rpcbp = GetRoutingProtocolCB(ProtocolId)) == NULL) {
  182. rc = ERROR_CAN_NOT_COMPLETE;
  183. goto Exit;
  184. }
  185. rc = (*rpcbp->RP_MibGet)(InputDataSize,
  186. InputData,
  187. OutputDataSize,
  188. OutputData);
  189. }
  190. Exit:
  191. MIB_CALL_END;
  192. return rc;
  193. }
  194. IPX_MIB_GET_HANDLER IpxMibGetFirst[MAX_IPX_MIB_TABLES] = {
  195. MibGetIpxBase,
  196. MibGetFirstIpxInterface,
  197. MibGetFirstRoute,
  198. MibGetFirstStaticRoute,
  199. MibGetFirstService,
  200. MibGetFirstStaticService
  201. };
  202. DWORD
  203. MibGetFirst(ULONG ProtocolId,
  204. ULONG InputDataSize,
  205. PVOID InputData,
  206. PULONG OutputDataSize,
  207. PVOID OutputData)
  208. {
  209. PIPX_MIB_GET_INPUT_DATA mgip;
  210. PRPCB rpcbp;
  211. DWORD rc;
  212. MIB_CALL_BEGIN;
  213. if(ProtocolId == IPX_PROTOCOL_BASE) {
  214. if(InputDataSize != sizeof(IPX_MIB_GET_INPUT_DATA)) {
  215. rc = ERROR_CAN_NOT_COMPLETE;
  216. goto Exit;
  217. }
  218. mgip = (PIPX_MIB_GET_INPUT_DATA)InputData;
  219. rc = (*IpxMibGetFirst[mgip->TableId])(&mgip->MibIndex,
  220. OutputData,
  221. OutputDataSize);
  222. }
  223. else
  224. {
  225. // to be demux to one of our routing protocols
  226. if((rpcbp = GetRoutingProtocolCB(ProtocolId)) == NULL) {
  227. rc = ERROR_CAN_NOT_COMPLETE;
  228. goto Exit;
  229. }
  230. rc = (*rpcbp->RP_MibGetFirst)(InputDataSize,
  231. InputData,
  232. OutputDataSize,
  233. OutputData);
  234. }
  235. Exit:
  236. MIB_CALL_END;
  237. return rc;
  238. }
  239. IPX_MIB_GET_HANDLER IpxMibGetNext[MAX_IPX_MIB_TABLES] = {
  240. MibGetIpxBase,
  241. MibGetNextIpxInterface,
  242. MibGetNextRoute,
  243. MibGetNextStaticRoute,
  244. MibGetNextService,
  245. MibGetNextStaticService
  246. };
  247. DWORD
  248. MibGetNext(ULONG ProtocolId,
  249. ULONG InputDataSize,
  250. PVOID InputData,
  251. PULONG OutputDataSize,
  252. PVOID OutputData)
  253. {
  254. PIPX_MIB_GET_INPUT_DATA mgip;
  255. PRPCB rpcbp;
  256. DWORD rc;
  257. MIB_CALL_BEGIN;
  258. if(ProtocolId == IPX_PROTOCOL_BASE) {
  259. if(InputDataSize != sizeof(IPX_MIB_GET_INPUT_DATA)) {
  260. rc = ERROR_CAN_NOT_COMPLETE;
  261. goto Exit;
  262. }
  263. mgip = (PIPX_MIB_GET_INPUT_DATA)InputData;
  264. rc = (*IpxMibGetNext[mgip->TableId])(&mgip->MibIndex,
  265. OutputData,
  266. OutputDataSize);
  267. }
  268. else
  269. {
  270. // to be demux to one of our routing protocols
  271. if((rpcbp = GetRoutingProtocolCB(ProtocolId)) == NULL) {
  272. rc = ERROR_CAN_NOT_COMPLETE;
  273. goto Exit;
  274. }
  275. rc = (*rpcbp->RP_MibGetNext)(InputDataSize,
  276. InputData,
  277. OutputDataSize,
  278. OutputData);
  279. }
  280. Exit:
  281. MIB_CALL_END;
  282. return rc;
  283. }