EtherLog.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. // SoftEther VPN Source Code - Stable Edition Repository
  2. // Cedar Communication Module
  3. //
  4. // SoftEther VPN Server, Client and Bridge are free software under the Apache License, Version 2.0.
  5. //
  6. // Copyright (c) Daiyuu Nobori.
  7. // Copyright (c) SoftEther VPN Project, University of Tsukuba, Japan.
  8. // Copyright (c) SoftEther Corporation.
  9. // Copyright (c) all contributors on SoftEther VPN project in GitHub.
  10. //
  11. // All Rights Reserved.
  12. //
  13. // http://www.softether.org/
  14. //
  15. // This stable branch is officially managed by Daiyuu Nobori, the owner of SoftEther VPN Project.
  16. // Pull requests should be sent to the Developer Edition Master Repository on https://github.com/SoftEtherVPN/SoftEtherVPN
  17. //
  18. // License: The Apache License, Version 2.0
  19. // https://www.apache.org/licenses/LICENSE-2.0
  20. //
  21. // DISCLAIMER
  22. // ==========
  23. //
  24. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  25. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  26. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  27. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  28. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  29. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. // SOFTWARE.
  31. //
  32. // THIS SOFTWARE IS DEVELOPED IN JAPAN, AND DISTRIBUTED FROM JAPAN, UNDER
  33. // JAPANESE LAWS. YOU MUST AGREE IN ADVANCE TO USE, COPY, MODIFY, MERGE, PUBLISH,
  34. // DISTRIBUTE, SUBLICENSE, AND/OR SELL COPIES OF THIS SOFTWARE, THAT ANY
  35. // JURIDICAL DISPUTES WHICH ARE CONCERNED TO THIS SOFTWARE OR ITS CONTENTS,
  36. // AGAINST US (SOFTETHER PROJECT, SOFTETHER CORPORATION, DAIYUU NOBORI OR OTHER
  37. // SUPPLIERS), OR ANY JURIDICAL DISPUTES AGAINST US WHICH ARE CAUSED BY ANY KIND
  38. // OF USING, COPYING, MODIFYING, MERGING, PUBLISHING, DISTRIBUTING, SUBLICENSING,
  39. // AND/OR SELLING COPIES OF THIS SOFTWARE SHALL BE REGARDED AS BE CONSTRUED AND
  40. // CONTROLLED BY JAPANESE LAWS, AND YOU MUST FURTHER CONSENT TO EXCLUSIVE
  41. // JURISDICTION AND VENUE IN THE COURTS SITTING IN TOKYO, JAPAN. YOU MUST WAIVE
  42. // ALL DEFENSES OF LACK OF PERSONAL JURISDICTION AND FORUM NON CONVENIENS.
  43. // PROCESS MAY BE SERVED ON EITHER PARTY IN THE MANNER AUTHORIZED BY APPLICABLE
  44. // LAW OR COURT RULE.
  45. //
  46. // USE ONLY IN JAPAN. DO NOT USE THIS SOFTWARE IN ANOTHER COUNTRY UNLESS YOU HAVE
  47. // A CONFIRMATION THAT THIS SOFTWARE DOES NOT VIOLATE ANY CRIMINAL LAWS OR CIVIL
  48. // RIGHTS IN THAT PARTICULAR COUNTRY. USING THIS SOFTWARE IN OTHER COUNTRIES IS
  49. // COMPLETELY AT YOUR OWN RISK. THE SOFTETHER VPN PROJECT HAS DEVELOPED AND
  50. // DISTRIBUTED THIS SOFTWARE TO COMPLY ONLY WITH THE JAPANESE LAWS AND EXISTING
  51. // CIVIL RIGHTS INCLUDING PATENTS WHICH ARE SUBJECTS APPLY IN JAPAN. OTHER
  52. // COUNTRIES' LAWS OR CIVIL RIGHTS ARE NONE OF OUR CONCERNS NOR RESPONSIBILITIES.
  53. // WE HAVE NEVER INVESTIGATED ANY CRIMINAL REGULATIONS, CIVIL LAWS OR
  54. // INTELLECTUAL PROPERTY RIGHTS INCLUDING PATENTS IN ANY OF OTHER 200+ COUNTRIES
  55. // AND TERRITORIES. BY NATURE, THERE ARE 200+ REGIONS IN THE WORLD, WITH
  56. // DIFFERENT LAWS. IT IS IMPOSSIBLE TO VERIFY EVERY COUNTRIES' LAWS, REGULATIONS
  57. // AND CIVIL RIGHTS TO MAKE THE SOFTWARE COMPLY WITH ALL COUNTRIES' LAWS BY THE
  58. // PROJECT. EVEN IF YOU WILL BE SUED BY A PRIVATE ENTITY OR BE DAMAGED BY A
  59. // PUBLIC SERVANT IN YOUR COUNTRY, THE DEVELOPERS OF THIS SOFTWARE WILL NEVER BE
  60. // LIABLE TO RECOVER OR COMPENSATE SUCH DAMAGES, CRIMINAL OR CIVIL
  61. // RESPONSIBILITIES. NOTE THAT THIS LINE IS NOT LICENSE RESTRICTION BUT JUST A
  62. // STATEMENT FOR WARNING AND DISCLAIMER.
  63. //
  64. // READ AND UNDERSTAND THE 'WARNING.TXT' FILE BEFORE USING THIS SOFTWARE.
  65. // SOME SOFTWARE PROGRAMS FROM THIRD PARTIES ARE INCLUDED ON THIS SOFTWARE WITH
  66. // LICENSE CONDITIONS WHICH ARE DESCRIBED ON THE 'THIRD_PARTY.TXT' FILE.
  67. //
  68. //
  69. // SOURCE CODE CONTRIBUTION
  70. // ------------------------
  71. //
  72. // Your contribution to SoftEther VPN Project is much appreciated.
  73. // Please send patches to us through GitHub.
  74. // Read the SoftEther VPN Patch Acceptance Policy in advance:
  75. // http://www.softether.org/5-download/src/9.patch
  76. //
  77. //
  78. // DEAR SECURITY EXPERTS
  79. // ---------------------
  80. //
  81. // If you find a bug or a security vulnerability please kindly inform us
  82. // about the problem immediately so that we can fix the security problem
  83. // to protect a lot of users around the world as soon as possible.
  84. //
  85. // Our e-mail address for security reports is:
  86. // softether-vpn-security [at] softether.org
  87. //
  88. // Please note that the above e-mail address is not a technical support
  89. // inquiry address. If you need technical assistance, please visit
  90. // http://www.softether.org/ and ask your question on the users forum.
  91. //
  92. // Thank you for your cooperation.
  93. //
  94. //
  95. // NO MEMORY OR RESOURCE LEAKS
  96. // ---------------------------
  97. //
  98. // The memory-leaks and resource-leaks verification under the stress
  99. // test has been passed before release this source code.
  100. // EtherLog.h
  101. // Header of EtherLog.c
  102. #ifndef ETHERLOG_H
  103. #define ETHERLOG_H
  104. // Whether this is a beta version
  105. #define ELOG_IS_BETA true
  106. // Beta expiration date
  107. #define ELOG_BETA_EXPIRES_YEAR 2008
  108. #define ELOG_BETA_EXPIRES_MONTH 12
  109. #define ELOG_BETA_EXPIRES_DAY 2
  110. // Version information
  111. //#define EL_VER 201
  112. //#define EL_BUILD 1600
  113. //#define EL_BETA 1
  114. #define MAX_LOGGING_QUEUE_LEN 100000
  115. // RPC related
  116. struct RPC_ADD_DEVICE
  117. {
  118. char DeviceName[MAX_SIZE]; // Device name
  119. HUB_LOG LogSetting; // Log settings
  120. bool NoPromiscus; // Without promiscuous mode
  121. };
  122. struct RPC_DELETE_DEVICE
  123. {
  124. char DeviceName[MAX_SIZE]; // Device name
  125. };
  126. struct RPC_ENUM_DEVICE_ITEM
  127. {
  128. char DeviceName[MAX_SIZE]; // Device name
  129. bool Active; // Running flag
  130. };
  131. struct RPC_ENUM_DEVICE
  132. {
  133. UINT NumItem; // Number of items
  134. RPC_ENUM_DEVICE_ITEM *Items; // Items
  135. bool IsLicenseSupported; // Whether the license system is supported
  136. };
  137. // License status of the service
  138. struct RPC_EL_LICENSE_STATUS
  139. {
  140. BOOL Valid; // Enable flag
  141. UINT64 SystemId; // System ID
  142. UINT64 SystemExpires; // System expiration date
  143. };
  144. // Device
  145. struct EL_DEVICE
  146. {
  147. EL *el; // EL
  148. char DeviceName[MAX_SIZE]; // Device name
  149. HUB_LOG LogSetting; // Log settings
  150. THREAD *Thread; // Thread
  151. CANCEL *Cancel1; // Cancel 1
  152. CANCEL *Cancel2; // Cancel 2
  153. volatile bool Halt; // Halting flag
  154. bool Active; // Running flag
  155. bool NoPromiscus; // Without promiscuous mode
  156. LOG *Logger; // Logger
  157. };
  158. // License status
  159. struct EL_LICENSE_STATUS
  160. {
  161. BOOL Valid; // Enable flag
  162. UINT64 SystemId; // System ID
  163. UINT64 Expires; // Expiration date
  164. };
  165. // EtherLogger
  166. struct EL
  167. {
  168. LOCK *lock; // Lock
  169. REF *ref; // Reference counter
  170. CEDAR *Cedar; // Cedar
  171. LIST *DeviceList; // Device list
  172. CFG_RW *CfgRw; // Config R/W
  173. UINT Port; // Port number
  174. LISTENER *Listener; // Listener
  175. UCHAR HashedPassword[SHA1_SIZE]; // Password
  176. LIST *AdminThreadList; // Management thread list
  177. LIST *AdminSockList; // Management socket list
  178. LICENSE_SYSTEM *LicenseSystem; // License system
  179. EL_LICENSE_STATUS *LicenseStatus; // License status
  180. UINT64 AutoDeleteCheckDiskFreeSpaceMin; // Minimum free disk space
  181. ERASER *Eraser; // Eraser
  182. };
  183. // Function prototype
  184. void ElInit();
  185. void ElFree();
  186. void ElStart();
  187. void ElStop();
  188. EL *NewEl();
  189. void ReleaseEl(EL *e);
  190. void CleanupEl(EL *e);
  191. void ElInitConfig(EL *e);
  192. void ElFreeConfig(EL *e);
  193. bool ElLoadConfig(EL *e);
  194. void ElLoadConfigFromFolder(EL *e, FOLDER *root);
  195. void ElSaveConfig(EL *e);
  196. void ElSaveConfigToFolder(EL *e, FOLDER *root);
  197. int ElCompareDevice(void *p1, void *p2);
  198. bool ElAddCaptureDevice(EL *e, char *name, HUB_LOG *log, bool no_promiscus);
  199. bool ElDeleteCaptureDevice(EL *e, char *name);
  200. bool ElSetCaptureDeviceLogSetting(EL *e, char *name, HUB_LOG *log);
  201. void ElCaptureThread(THREAD *thread, void *param);
  202. void ElStartListener(EL *e);
  203. void ElStopListener(EL *e);
  204. void ElListenerProc(THREAD *thread, void *param);
  205. PACK *ElRpcServer(RPC *r, char *name, PACK *p);
  206. void ElCheckLicense(EL_LICENSE_STATUS *st, LICENSE *e);
  207. void ElParseCurrentLicenseStatus(LICENSE_SYSTEM *s, EL_LICENSE_STATUS *st);
  208. bool ElIsBetaExpired();
  209. UINT EtAddDevice(EL *e, RPC_ADD_DEVICE *t);
  210. UINT EtDelDevice(EL *e, RPC_DELETE_DEVICE *t);
  211. UINT EtSetDevice(EL *e, RPC_ADD_DEVICE *t);
  212. UINT EtGetDevice(EL *e, RPC_ADD_DEVICE *t);
  213. UINT EtEnumDevice(EL *e, RPC_ENUM_DEVICE *t);
  214. UINT EtEnumAllDevice(EL *e, RPC_ENUM_DEVICE *t);
  215. UINT EtSetPassword(EL *e, RPC_SET_PASSWORD *t);
  216. UINT EtAddLicenseKey(EL *a, RPC_TEST *t);
  217. UINT EtDelLicenseKey(EL *a, RPC_TEST *t);
  218. UINT EtEnumLicenseKey(EL *a, RPC_ENUM_LICENSE_KEY *t);
  219. UINT EtGetLicenseStatus(EL *a, RPC_EL_LICENSE_STATUS *t);
  220. UINT EtGetBridgeSupport(EL *a, RPC_BRIDGE_SUPPORT *t);
  221. UINT EtRebootServer(EL *a, RPC_TEST *t);
  222. UINT EcAddDevice(RPC *r, RPC_ADD_DEVICE *t);
  223. UINT EcDelDevice(RPC *r, RPC_DELETE_DEVICE *t);
  224. UINT EcSetDevice(RPC *r, RPC_ADD_DEVICE *t);
  225. UINT EcGetDevice(RPC *r, RPC_ADD_DEVICE *t);
  226. UINT EcEnumDevice(RPC *r, RPC_ENUM_DEVICE *t);
  227. UINT EcEnumAllDevice(RPC *r, RPC_ENUM_DEVICE *t);
  228. UINT EcSetPassword(RPC *r, RPC_SET_PASSWORD *t);
  229. UINT EcAddLicenseKey(RPC *r, RPC_TEST *t);
  230. UINT EcDelLicenseKey(RPC *r, RPC_TEST *t);
  231. UINT EcEnumLicenseKey(RPC *r, RPC_ENUM_LICENSE_KEY *t);
  232. UINT EcGetLicenseStatus(RPC *r, RPC_EL_LICENSE_STATUS *t);
  233. UINT EcGetBridgeSupport(RPC *r, RPC_BRIDGE_SUPPORT *t);
  234. UINT EcRebootServer(RPC *r, RPC_TEST *t);
  235. UINT EcConnect(char *host, UINT port, char *password, RPC **rpc);
  236. void EcDisconnect(RPC *rpc);
  237. void InRpcAddDevice(RPC_ADD_DEVICE *t, PACK *p);
  238. void OutRpcAddDevice(PACK *p, RPC_ADD_DEVICE *t);
  239. void InRpcDeleteDevice(RPC_DELETE_DEVICE *t, PACK *p);
  240. void OutRpcDeleteDevice(PACK *p, RPC_DELETE_DEVICE *t);
  241. void InRpcEnumDevice(RPC_ENUM_DEVICE *t, PACK *p);
  242. void OutRpcEnumDevice(PACK *p, RPC_ENUM_DEVICE *t);
  243. void FreeRpcEnumDevice(RPC_ENUM_DEVICE *t);
  244. void InRpcEnumLicenseKey(RPC_ENUM_LICENSE_KEY *t, PACK *p);
  245. void OutRpcEnumLicenseKey(PACK *p, RPC_ENUM_LICENSE_KEY *t);
  246. void FreeRpcEnumLicenseKey(RPC_ENUM_LICENSE_KEY *t);
  247. void InRpcElLicenseStatus(RPC_EL_LICENSE_STATUS *t, PACK *p);
  248. void OutRpcElLicenseStatus(PACK *p, RPC_EL_LICENSE_STATUS *t);
  249. #endif // ETHERLOG_H