BridgeUnix.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. //
  18. // This program is free software; you can redistribute it and/or
  19. // modify it under the terms of the GNU General Public License
  20. // version 2 as published by the Free Software Foundation.
  21. //
  22. // This program is distributed in the hope that it will be useful,
  23. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. // GNU General Public License for more details.
  26. //
  27. // You should have received a copy of the GNU General Public License version 2
  28. // along with this program; if not, write to the Free Software
  29. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  30. //
  31. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  32. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  33. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  34. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  35. // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  36. // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  37. // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  38. //
  39. // THE LICENSE AGREEMENT IS ATTACHED ON THE SOURCE-CODE PACKAGE
  40. // AS "LICENSE.TXT" FILE. READ THE TEXT FILE IN ADVANCE TO USE THE SOFTWARE.
  41. //
  42. //
  43. // THIS SOFTWARE IS DEVELOPED IN JAPAN, AND DISTRIBUTED FROM JAPAN,
  44. // UNDER JAPANESE LAWS. YOU MUST AGREE IN ADVANCE TO USE, COPY, MODIFY,
  45. // MERGE, PUBLISH, DISTRIBUTE, SUBLICENSE, AND/OR SELL COPIES OF THIS
  46. // SOFTWARE, THAT ANY JURIDICAL DISPUTES WHICH ARE CONCERNED TO THIS
  47. // SOFTWARE OR ITS CONTENTS, AGAINST US (SOFTETHER PROJECT, SOFTETHER
  48. // CORPORATION, DAIYUU NOBORI OR OTHER SUPPLIERS), OR ANY JURIDICAL
  49. // DISPUTES AGAINST US WHICH ARE CAUSED BY ANY KIND OF USING, COPYING,
  50. // MODIFYING, MERGING, PUBLISHING, DISTRIBUTING, SUBLICENSING, AND/OR
  51. // SELLING COPIES OF THIS SOFTWARE SHALL BE REGARDED AS BE CONSTRUED AND
  52. // CONTROLLED BY JAPANESE LAWS, AND YOU MUST FURTHER CONSENT TO
  53. // EXCLUSIVE JURISDICTION AND VENUE IN THE COURTS SITTING IN TOKYO,
  54. // JAPAN. YOU MUST WAIVE ALL DEFENSES OF LACK OF PERSONAL JURISDICTION
  55. // AND FORUM NON CONVENIENS. PROCESS MAY BE SERVED ON EITHER PARTY IN
  56. // THE MANNER AUTHORIZED BY APPLICABLE LAW OR COURT RULE.
  57. //
  58. // USE ONLY IN JAPAN. DO NOT USE IT IN OTHER COUNTRIES. IMPORTING THIS
  59. // SOFTWARE INTO OTHER COUNTRIES IS AT YOUR OWN RISK. SOME COUNTRIES
  60. // PROHIBIT ENCRYPTED COMMUNICATIONS. USING THIS SOFTWARE IN OTHER
  61. // COUNTRIES MIGHT BE RESTRICTED.
  62. //
  63. //
  64. // SOURCE CODE CONTRIBUTION
  65. // ------------------------
  66. //
  67. // Your contribution to SoftEther VPN Project is much appreciated.
  68. // Please send patches to us through GitHub.
  69. // Read the SoftEther VPN Patch Acceptance Policy in advance:
  70. // http://www.softether.org/5-download/src/9.patch
  71. //
  72. //
  73. // DEAR SECURITY EXPERTS
  74. // ---------------------
  75. //
  76. // If you find a bug or a security vulnerability please kindly inform us
  77. // about the problem immediately so that we can fix the security problem
  78. // to protect a lot of users around the world as soon as possible.
  79. //
  80. // Our e-mail address for security reports is:
  81. // softether-vpn-security [at] softether.org
  82. //
  83. // Please note that the above e-mail address is not a technical support
  84. // inquiry address. If you need technical assistance, please visit
  85. // http://www.softether.org/ and ask your question on the users forum.
  86. //
  87. // Thank you for your cooperation.
  88. // BridgeUnix.h
  89. // Header of BridgeUnix.c
  90. #ifndef BRIDGEUNIX_H
  91. #define BRIDGEUNIX_H
  92. // Macro
  93. #ifndef SOL_PACKET
  94. #define SOL_PACKET 263
  95. #endif
  96. #ifndef ifr_newname
  97. #define ifr_newname ifr_ifru.ifru_slave
  98. #endif
  99. // Constants
  100. #define UNIX_ETH_TMP_BUFFER_SIZE (2000)
  101. #define SOLARIS_MAXDLBUF (32768)
  102. #define BRIDGE_MAX_QUEUE_SIZE (4096*1500)
  103. // ETH structure
  104. struct ETH
  105. {
  106. char *Name; // Adapter name
  107. char *Title; // Adapter title
  108. CANCEL *Cancel; // Cancel object
  109. int IfIndex; // Index
  110. int Socket; // Socket
  111. UINT InitialMtu; // Initial MTU value
  112. UINT CurrentMtu; // Current MTU value
  113. int SocketBsdIf; // BSD interface operation socket
  114. UCHAR MacAddress[6]; // MAC address
  115. #ifdef BRIDGE_PCAP
  116. void *Pcap; // Pcap descriptor
  117. QUEUE *Queue; // Queue of the relay thread
  118. UINT QueueSize; // Number of bytes in Queue
  119. THREAD *CaptureThread; // Pcap relay thread
  120. #endif // BRIDGE_PCAP
  121. #ifdef BRIDGE_BPF
  122. UINT BufSize; // Buffer size to read the BPF (error for other)
  123. #ifdef BRIDGE_BPF_THREAD
  124. QUEUE *Queue; // Queue of the relay thread
  125. UINT QueueSize; // Number of bytes in Queue
  126. THREAD *CaptureThread; // BPF relay thread
  127. #else // BRIDGE_BPF_THREAD
  128. UCHAR *Buffer; // Buffer to read the BPF
  129. UCHAR *Next;
  130. int Rest;
  131. #endif // BRIDGE_BPF_THREAD
  132. #endif // BRIDGE_BPF
  133. VLAN *Tap; // tap
  134. };
  135. #if defined( BRIDGE_BPF ) || defined( BRIDGE_PCAP )
  136. struct CAPTUREBLOCK{
  137. UINT Size;
  138. UCHAR *Buf;
  139. };
  140. #endif // BRIDGE_BPF
  141. // Function prototype
  142. void InitEth();
  143. void FreeEth();
  144. bool IsEthSupported();
  145. bool IsEthSupportedLinux();
  146. bool IsEthSupportedSolaris();
  147. bool IsEthSupportedPcap();
  148. TOKEN_LIST *GetEthList();
  149. TOKEN_LIST *GetEthListLinux();
  150. TOKEN_LIST *GetEthListSolaris();
  151. TOKEN_LIST *GetEthListPcap();
  152. ETH *OpenEth(char *name, bool local, bool tapmode, char *tapaddr);
  153. ETH *OpenEthLinux(char *name, bool local, bool tapmode, char *tapaddr);
  154. ETH *OpenEthSolaris(char *name, bool local, bool tapmode, char *tapaddr);
  155. ETH *OpenEthPcap(char *name, bool local, bool tapmode, char *tapaddr);
  156. bool ParseUnixEthDeviceName(char *dst_devname, UINT dst_devname_size, UINT *dst_devid, char *src_name);
  157. void CloseEth(ETH *e);
  158. CANCEL *EthGetCancel(ETH *e);
  159. UINT EthGetPacket(ETH *e, void **data);
  160. UINT EthGetPacketLinux(ETH *e, void **data);
  161. UINT EthGetPacketSolaris(ETH *e, void **data);
  162. UINT EthGetPacketPcap(ETH *e, void **data);
  163. UINT EthGetPacketBpf(ETH *e, void **data);
  164. void EthPutPacket(ETH *e, void *data, UINT size);
  165. void EthPutPackets(ETH *e, UINT num, void **datas, UINT *sizes);
  166. UINT EthGetMtu(ETH *e);
  167. bool EthSetMtu(ETH *e, UINT mtu);
  168. bool EthIsChangeMtuSupported(ETH *e);
  169. bool EthGetInterfaceDescriptionUnix(char *name, char *str, UINT size);
  170. bool EthIsInterfaceDescriptionSupportedUnix();
  171. #ifdef UNIX_SOLARIS
  172. // Function prototype for Solaris
  173. bool DlipAttatchRequest(int fd, UINT devid);
  174. bool DlipReceiveAck(int fd);
  175. bool DlipPromiscuous(int fd, UINT level);
  176. bool DlipBindRequest(int fd);
  177. #endif // OS_SOLARIS
  178. int UnixEthOpenRawSocket();
  179. #endif // BRIDGEUNIX_H
  180. // Developed by SoftEther VPN Project at University of Tsukuba in Japan.
  181. // Department of Computer Science has dozens of overly-enthusiastic geeks.
  182. // Join us: http://www.tsukuba.ac.jp/english/admission/