EtherLog.h 11 KB

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