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.

342 lines
7.9 KiB

  1. /*******************************************************************/
  2. /* Copyright(c) 1995 Microsoft Corporation */
  3. /*******************************************************************/
  4. //***
  5. //
  6. // Filename: rmif.c
  7. //
  8. // Description: implements the IPXCP i/f with the IPX Router Manager
  9. //
  10. //
  11. // Author: Stefan Solomon (stefans) October 27, 1995.
  12. //
  13. // Revision History:
  14. //
  15. //***
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. extern BOOL WanConfigDbaseInitialized;
  19. // IPX Router Manager Entry Points
  20. DWORD (WINAPI *RmCreateGlobalRoute)(PUCHAR Network);
  21. DWORD (WINAPI *RmAddLocalWkstaDialoutInterface)
  22. (IN LPWSTR InterfaceNamep,
  23. IN LPVOID InterfaceInfop,
  24. IN OUT PULONG InterfaceIndexp);
  25. DWORD (WINAPI *RmDeleteLocalWkstaDialoutInterface)(ULONG InterfaceIndex);
  26. DWORD (WINAPI *RmGetIpxwanInterfaceConfig)
  27. (ULONG InterfaceIndex,
  28. PULONG IpxwanConfigRequired);
  29. BOOL (WINAPI *RmIsRoute)(PUCHAR Network);
  30. DWORD (WINAPI *RmGetInternalNetNumber)(PUCHAR Network);
  31. DWORD (WINAPI *RmUpdateIpxcpConfig)(PIPXCP_ROUTER_CONFIG_PARAMS pParams) = NULL;
  32. // Our Entry Points
  33. VOID
  34. IpxcpRouterStarted(VOID);
  35. VOID
  36. IpxcpRouterStopped(VOID);
  37. // Flag to indicate router state
  38. BOOL RouterStarted;
  39. // [pmay] This will be removed when the router is modified to use MprInfo api's
  40. typedef RTR_INFO_BLOCK_HEADER IPX_INFO_BLOCK_HEADER, *PIPX_INFO_BLOCK_HEADER;
  41. typedef RTR_TOC_ENTRY IPX_TOC_ENTRY, *PIPX_TOC_ENTRY;
  42. //*** Interface Configuration Info for the WORKSTATION_ON_ROUTER_DIALOUT ***
  43. typedef struct _WKSTA_ON_ROUTER_INFO {
  44. IPX_INFO_BLOCK_HEADER header;
  45. IPX_TOC_ENTRY toc[3];
  46. IPX_IF_INFO ipxifinfo;
  47. RIP_IF_CONFIG ripifinfo;
  48. SAP_IF_CONFIG sapifinfo;
  49. IPXWAN_IF_INFO ipxwanifinfo;
  50. } WKSTA_ON_ROUTER_INFO, *PWKSTA_ON_ROUTER_INFO;
  51. WKSTA_ON_ROUTER_INFO WkstaOnRouterInfo;
  52. #define ipxtoc WkstaOnRouterInfo.header.TocEntry[0]
  53. #define riptoc WkstaOnRouterInfo.toc[0]
  54. #define saptoc WkstaOnRouterInfo.toc[1]
  55. #define ipxwantoc WkstaOnRouterInfo.toc[2]
  56. #define ipxinfo WkstaOnRouterInfo.ipxifinfo
  57. #define ripinfo WkstaOnRouterInfo.ripifinfo.RipIfInfo
  58. #define sapinfo WkstaOnRouterInfo.sapifinfo.SapIfInfo
  59. #define ipxwaninfo WkstaOnRouterInfo.ipxwanifinfo
  60. /*++
  61. Function: InitializeRouterManagerIf
  62. Descr:
  63. Remark: Called from process attach
  64. --*/
  65. VOID
  66. InitializeRouterManagerIf(VOID)
  67. {
  68. // init wksta on router info
  69. WkstaOnRouterInfo.header.Version = IPX_ROUTER_VERSION_1;
  70. WkstaOnRouterInfo.header.Size = sizeof(WkstaOnRouterInfo);
  71. WkstaOnRouterInfo.header.TocEntriesCount = 4;
  72. ipxtoc.InfoType = IPX_INTERFACE_INFO_TYPE;
  73. ipxtoc.InfoSize = sizeof(IPX_IF_INFO);
  74. ipxtoc.Count = 1;
  75. ipxtoc.Offset = (ULONG)((PUCHAR)&WkstaOnRouterInfo.ipxifinfo - (PUCHAR)&WkstaOnRouterInfo);
  76. riptoc.InfoType = IPX_PROTOCOL_RIP;
  77. riptoc.InfoSize = sizeof(RIP_IF_CONFIG);
  78. riptoc.Count = 1;
  79. riptoc.Offset = ipxtoc.Offset + sizeof(IPX_IF_INFO);
  80. saptoc.InfoType = IPX_PROTOCOL_SAP;
  81. saptoc.InfoSize = sizeof(SAP_IF_CONFIG);
  82. saptoc.Count = 1;
  83. saptoc.Offset = riptoc.Offset + sizeof(RIP_IF_CONFIG);
  84. ipxwantoc.InfoType = IPXWAN_INTERFACE_INFO_TYPE;
  85. ipxwantoc.InfoSize = sizeof(IPXWAN_IF_INFO);
  86. ipxwantoc.Count = 1;
  87. ipxwantoc.Offset = saptoc.Offset + sizeof(SAP_IF_CONFIG);
  88. ipxinfo.AdminState = ADMIN_STATE_ENABLED;
  89. ipxinfo.NetbiosAccept = ADMIN_STATE_ENABLED;
  90. ipxinfo.NetbiosDeliver = ADMIN_STATE_ENABLED_ONLY_FOR_OPER_STATE_UP;
  91. ripinfo.AdminState = ADMIN_STATE_ENABLED;
  92. ripinfo.UpdateMode = IPX_STANDARD_UPDATE;
  93. ripinfo.PacketType = IPX_STANDARD_PACKET_TYPE;
  94. ripinfo.Supply = ADMIN_STATE_ENABLED;
  95. ripinfo.Listen = ADMIN_STATE_ENABLED;
  96. ripinfo.PeriodicUpdateInterval = 60;
  97. ripinfo.AgeIntervalMultiplier = 3;
  98. sapinfo.AdminState = ADMIN_STATE_DISABLED;
  99. sapinfo.UpdateMode = IPX_NO_UPDATE;
  100. sapinfo.PacketType = IPX_STANDARD_PACKET_TYPE;
  101. sapinfo.Supply = ADMIN_STATE_DISABLED;
  102. sapinfo.Listen = ADMIN_STATE_DISABLED;
  103. sapinfo.PeriodicUpdateInterval = 60;
  104. sapinfo.AgeIntervalMultiplier = 3;
  105. if(GlobalConfig.EnableIpxwanForWorkstationDialout) {
  106. ipxwaninfo.AdminState = ADMIN_STATE_ENABLED;
  107. }
  108. else
  109. {
  110. ipxwaninfo.AdminState = ADMIN_STATE_DISABLED;
  111. }
  112. }
  113. DWORD
  114. IPXCP_BIND_ENTRY_POINT(PIPXCP_INTERFACE IpxcpInterfacep)
  115. {
  116. TraceIpx(RMIF_TRACE, "IpxcpBind: Entered\n");
  117. // Get the IPX Router Manager Entry Points
  118. RmCreateGlobalRoute = IpxcpInterfacep->RmCreateGlobalRoute;
  119. RmAddLocalWkstaDialoutInterface = IpxcpInterfacep->RmAddLocalWkstaDialoutInterface;
  120. RmDeleteLocalWkstaDialoutInterface = IpxcpInterfacep->RmDeleteLocalWkstaDialoutInterface;
  121. RmGetIpxwanInterfaceConfig = IpxcpInterfacep->RmGetIpxwanInterfaceConfig;
  122. RmIsRoute = IpxcpInterfacep->RmIsRoute;
  123. RmGetInternalNetNumber = IpxcpInterfacep->RmGetInternalNetNumber;
  124. RmUpdateIpxcpConfig = IpxcpInterfacep->RmUpdateIpxcpConfig;
  125. // Give it ours
  126. IpxcpInterfacep->IpxcpRouterStarted = IpxcpRouterStarted;
  127. IpxcpInterfacep->IpxcpRouterStopped = IpxcpRouterStopped;
  128. ACQUIRE_DATABASE_LOCK;
  129. IpxcpInterfacep->Params.ThisMachineOnly = GlobalConfig.RParams.ThisMachineOnly;
  130. if(WanConfigDbaseInitialized) {
  131. IpxcpInterfacep->Params.WanNetDatabaseInitialized = TRUE;
  132. IpxcpInterfacep->Params.EnableGlobalWanNet = GlobalConfig.RParams.EnableGlobalWanNet;
  133. if(GlobalConfig.RParams.EnableGlobalWanNet) {
  134. memcpy(IpxcpInterfacep->Params.GlobalWanNet, GlobalConfig.RParams.GlobalWanNet, 4);
  135. }
  136. }
  137. else
  138. {
  139. IpxcpInterfacep->Params.WanNetDatabaseInitialized = FALSE;
  140. IpxcpInterfacep->Params.EnableGlobalWanNet = FALSE;
  141. }
  142. RELEASE_DATABASE_LOCK;
  143. return NO_ERROR;
  144. }
  145. VOID
  146. IpxcpRouterStarted(VOID)
  147. {
  148. TraceIpx(RMIF_TRACE, "IpxcpRouterStarted: Entered\n");
  149. ACQUIRE_DATABASE_LOCK;
  150. RouterStarted = TRUE;
  151. RELEASE_DATABASE_LOCK;
  152. }
  153. VOID
  154. IpxcpRouterStopped(VOID)
  155. {
  156. TraceIpx(RMIF_TRACE, "IpxcpRouterStopped: Entered\n");
  157. ACQUIRE_DATABASE_LOCK;
  158. RouterStarted = FALSE;
  159. RELEASE_DATABASE_LOCK;
  160. }
  161. DWORD
  162. AddLocalWkstaDialoutInterface(PULONG InterfaceIndexp)
  163. {
  164. DWORD rc;
  165. ACQUIRE_DATABASE_LOCK;
  166. if(!RouterStarted) {
  167. RELEASE_DATABASE_LOCK;
  168. return ERROR_CAN_NOT_COMPLETE;
  169. }
  170. rc = (*RmAddLocalWkstaDialoutInterface)(L"LocalWorkstationDialout",
  171. &WkstaOnRouterInfo,
  172. InterfaceIndexp);
  173. RELEASE_DATABASE_LOCK;
  174. return rc;
  175. }
  176. DWORD
  177. DeleteLocalWkstaDialoutInterface(ULONG InterfaceIndex)
  178. {
  179. DWORD rc;
  180. ACQUIRE_DATABASE_LOCK;
  181. if(!RouterStarted) {
  182. RELEASE_DATABASE_LOCK;
  183. return ERROR_CAN_NOT_COMPLETE;
  184. }
  185. rc = (*RmDeleteLocalWkstaDialoutInterface)(InterfaceIndex);
  186. RELEASE_DATABASE_LOCK;
  187. return rc;
  188. }
  189. DWORD
  190. GetIpxwanInterfaceConfig(ULONG InterfaceIndex,
  191. PULONG IpxwanConfigRequiredp)
  192. {
  193. DWORD rc;
  194. ACQUIRE_DATABASE_LOCK;
  195. if(!RouterStarted) {
  196. RELEASE_DATABASE_LOCK;
  197. return ERROR_CAN_NOT_COMPLETE;
  198. }
  199. rc = (*RmGetIpxwanInterfaceConfig)(InterfaceIndex, IpxwanConfigRequiredp);
  200. RELEASE_DATABASE_LOCK;
  201. return rc;
  202. }
  203. BOOL
  204. IsRoute(PUCHAR Network)
  205. {
  206. BOOL rc;
  207. ACQUIRE_DATABASE_LOCK;
  208. if(!RouterStarted) {
  209. RELEASE_DATABASE_LOCK;
  210. return FALSE;
  211. }
  212. rc = (*RmIsRoute)(Network);
  213. RELEASE_DATABASE_LOCK;
  214. return rc;
  215. }
  216. /*++
  217. Function: GetInternalNetNumber
  218. Descr:
  219. --*/
  220. VOID
  221. GetInternalNetNumber(PUCHAR Network)
  222. {
  223. DWORD rc;
  224. ACQUIRE_DATABASE_LOCK;
  225. if(!RouterStarted) {
  226. memcpy(Network, nullnet, 4);
  227. RELEASE_DATABASE_LOCK;
  228. return;
  229. }
  230. rc = RmGetInternalNetNumber(Network);
  231. if(rc != NO_ERROR) {
  232. memcpy(Network, nullnet, 4);
  233. }
  234. RELEASE_DATABASE_LOCK;
  235. }